⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smac.h

📁 在ns2中仿真无线传感器网络mac层协议的代码smac
💻 H
📖 第 1 页 / 共 2 页
字号:
 public:  SmacAdaptiveListenTimer(SMAC *a) : SmacTimer(a) {}  void expire(Event *e);};#endif// Generic timer used for sync, CTS and ACK timeoutsclass SmacGeneTimer : public SmacTimer { public:  SmacGeneTimer(SMAC *a) : SmacTimer(a) {}  void expire(Event *e);};// Receive timer for receiving pktsclass SmacRecvTimer : public SmacTimer { public:  SmacRecvTimer(SMAC *a) : SmacTimer(a) { stime_ = rtime_ = 0; }  void sched(double duration);  void resched(double time);  void expire(Event *e);  double timeToExpire(); protected:  double stime_;  double rtime_;};// Send timerclass SmacSendTimer : public SmacTimer { public:  SmacSendTimer(SMAC *a) : SmacTimer(a) {}  void expire(Event *e);};// Nav- indicating if medium is busy or notclass SmacNavTimer : public SmacTimer { public:  SmacNavTimer(SMAC *a) : SmacTimer(a) {}  void expire(Event *e);};// Neighbor nav - if neighbor is busy or not// used for data timeoutclass SmacNeighNavTimer : public SmacTimer { public:  SmacNeighNavTimer(SMAC *a) : SmacTimer(a) { stime_ = rtime_ = 0; }  void sched(double duration);  void expire(Event *e);  double timeToExpire(); protected:  double stime_;  double rtime_;};// carrier sense timerclass SmacCsTimer : public SmacTimer { public:  SmacCsTimer(SMAC *a) : SmacTimer(a) {}  void expire(Event *e);  void checkToCancel();};// synchronisation timer, regulates the sleep/wakeup cyclesclass SmacCounterTimer : public SmacTimer {  public:    friend class SMAC;  SmacCounterTimer(SMAC *a, int i) : SmacTimer(a) {index_ = i;}  void sched(double t);  void expire(Event *e);   double timeToSleep(); protected:  int index_;  double value_;  double syncTime_;  double dataTime_;  double listenTime_;  double sleepTime_;  double cycleTime_;  double tts_;  double stime_;}; // The smac classclass SMAC : public Mac {    friend class SmacGeneTimer;  friend class SmacRecvTimer;  friend class SmacSendTimer;  friend class SmacNavTimer;  friend class SmacNeighNavTimer;  friend class SmacCsTimer;   friend class SmacCounterTimer;#ifdef JOURNAL_PAPER  friend class SmacUpdateNeighbTimer;  friend class SmacAdaptiveListenTimer;#endif public:  SMAC(void);  ~SMAC() {     for (int i=0; i< SMAC_MAX_NUM_SCHEDULES; i++) {      delete mhCounter_[i];    }  }  void recv(Packet *p, Handler *h); protected:    // functions for handling timers#ifdef JOURNAL_PAPER  void handleUpdateNeighbTimer();  void handleAdaptiveListenTimer();#endif  void handleGeneTimer();  void handleRecvTimer();  void handleSendTimer();  void handleNavTimer();  void handleNeighNavTimer();  void handleCsTimer();  //void handleChkSendTimer();  void handleCounterTimer(int i);  // Internal MAC parameters  double slotTime_;  double slotTime_sec_;  double difs_;  double sifs_;  double eifs_;  double guardTime_;  double byte_tx_time_;  double dutyCycle_;  private:  // functions for node schedule folowing sleep-wakeup cycles  void setMySched(Packet *syncpkt);  void sleep();  void wakeup();#ifdef JOURNAL_PAPER  // funtions for update neighbors and schedules  void check_schedFlag();  void update_schedTab_neighbList();  void update_myNeighbList();  void update_neighbList();  void checkMySched();  void dump();#endif  // functions for handling incoming packets    void rxMsgDone(Packet* p);  //void rxFragDone(Packet *p);  no frag for now#ifdef JOURNAL_PAPER  void rxFragDone(Packet *p); #endif  void handleRTS(Packet *p);  void handleCTS(Packet *p);  void handleDATA(Packet *p);  void handleACK(Packet *p);  void handleSYNC(Packet *p);  // functions for handling outgoing packets    // check for pending data pkt to be tx'ed  // when smac is not following SYNC (sleep-wakeup) cycles.  int checkToSend();               // check if can send, start cs   bool chkRadio();         // checks radiostate  void transmit(Packet *p);         // actually transmits packet  bool sendMsg(Packet *p, Handler *h);  bool bcastMsg(Packet *p);  bool unicastMsg(int n, Packet *p);  //int sendMoreFrag(Packet *p);    void txMsgDone();  // void txFragDone();#ifdef JOURNAL_PAPER  // functions for handling fragmentation  bool txNextFrag(void* data);  void txFragDone();                                                                                                                                                              // functions for handling adaptive listen  void adaptiveListen();#endif  int startBcast();  int startUcast();    bool sendRTS();  bool sendCTS(double duration);  bool sendDATA();  bool sendACK(double duration);  bool sendSYNC();  void sentRTS(Packet *p);  void sentCTS(Packet *p);  void sentDATA(Packet *p);  void sentACK(Packet *p);  void sentSYNC(Packet *p);    // Misc functions  void collision(Packet *p);  void capture(Packet *p);  double txtime(Packet *p);    void updateNav(double duration);  void updateNeighNav(double duration);  void mac_log(Packet *p) {    logtarget_->recv(p, (Handler*) 0);  }    void discard(Packet *p, const char* why);  int drop_RTS(Packet *p, const char* why);  int drop_CTS(Packet *p, const char* why);  int drop_DATA(Packet *p, const char* why);  int drop_SYNC(Packet *p, const char* why);  // smac methods to set dst, src and hdr_type in pkt hdrs  inline int hdr_dst(char* hdr, int dst = -2) {    struct hdr_smac *sh = (struct hdr_smac *) hdr;    if (dst > -2)      sh->dstAddr = dst;    return sh->dstAddr;  }  inline int hdr_src(char* hdr, int src = -2) {    struct hdr_smac *sh = (struct hdr_smac *) hdr;    if (src > -2)      sh->srcAddr = src;    return sh->srcAddr;  }  inline int hdr_type(char *hdr, u_int16_t type = 0) {    struct hdr_smac *sh = (struct hdr_smac *) hdr;    if (type)      sh->type = type;    return sh->type;  }    // SMAC internal variables    NsObject*       logtarget_;    // Internal states  int  state_;                   // MAC state  int  radioState_;              // state of radio, rx, tx or sleep  int tx_active_;                  int mac_collision_;                int sendAddr_;		// node to send data to  int recvAddr_;		// node to receive data from    double  nav_;	        // network allocation vector. nav>0 -> medium busy  double  neighNav_;      // track neighbors' NAV while I'm sending/receiving    // SMAC Timers#ifdef JOURNAL_PAPER  SmacUpdateNeighbTimer mhUpdateNeighb_; // timer for updating neighbors periodically  SmacAdaptiveListenTimer mhAdap_; // timer for putting nodes back to sleep after adaptive listen#endif  SmacNavTimer	        mhNav_;		// NAV timer medium is free or not  SmacNeighNavTimer     mhNeighNav_;    // neighbor NAV timer for data timeout  SmacSendTimer		mhSend_;	// incoming packets  SmacRecvTimer         mhRecv_;        // outgoing packets  SmacGeneTimer         mhGene_;        // generic timer used sync/CTS/ACK timeout  SmacCsTimer           mhCS_;          // carrier sense timer    // array of countertimer, one for each schedule  // counter tracking node's sleep/awake cycle  SmacCounterTimer      *mhCounter_[SMAC_MAX_NUM_SCHEDULES];    int numRetry_;	// number of tries for a data pkt  int numExtend_;      // number of extensions on Tx time when frags are lost#ifdef JOURNAL_PAPER  int numFrags_;       // number of fragments in this transmission  int succFrags_;      // number of successfully transmitted fragments#endif  //int numFrags_;       // number of fragments in this transmission  //int succFrags_;      // number of successfully transmitted fragments  int lastRxFrag_;     // keep track of last data fragment recvd to prevent duplicate data  int howToSend_;		// broadcast or unicast    double durSyncPkt_;     // duration of sync packet  double durDataPkt_;     // duration of data packet XXX caveat fixed packet size  double durCtrlPkt_;     // duration of control packet  double timeWaitCtrl_;   // set timer to wait for a control packet    struct SchedTable schedTab_[SMAC_MAX_NUM_SCHEDULES];   // schedule table  struct NeighbList neighbList_[SMAC_MAX_NUM_NEIGHBORS]; // neighbor list  int mySyncNode_;                                 // nodeid of my synchronizer    int currSched_;      // current schedule I'm talking to  int numSched_;       // number of different schedules  int numNeighb_;      // number of known neighbors  int numBcast_;       // number of times needed to broadcast a packet    Packet *dataPkt_;		// outgoing data packet  Packet *pktRx_;               // buffer for incoming pkt  Packet *pktTx_;               // buffer for outgoing pkt  // flag to check pending data pkt for tx  // when smac is not following SYNC (sleep-wakeup) cycles.  int txData_ ;  int syncFlag_;  // is set to 1 when SMAC uses sleep-wakeup cycle  int selfConfigFlag_;  // is set to 0 when SMAC uses user configurable schedule start time  double startTime_;  // schedule start time (schedule starts from SYNC period)  // sleep-wakeup cycle times  double syncTime_;  double dataTime_;  double listenTime_;  double sleepTime_;  double cycleTime_;#ifdef JOURNAL_PAPER  int adapTime_;  // time before getting back to sleep when doing adaptive listen  int adaptiveListen_;  int adapSend_;  int txRequest_;  int dataSched_;  int syncSched_;  int sendAddr;                                                                                                                                                              int schedState_; // schedule state: first, second schedule...                                                                                                                                                              int globalSchedule_;  // flag indicating if node is in global schedule state                                                                                                                                                              int updateNeighbList_; // flag indicating if node needs to update neighbor list  char sendSYNCFlag_;    // flag indicating if node has broadcasted SYNC packet or not#endif  // neighbor discovery  int searchNeighb_;  // flag indicating if node is in neighbot discovery period  int schedListen_;  // flag indicating if node is in scheduled listen period  int numSync_;  // used to set/clear searchNeighb flag   protected:  int command(int argc, const char*const* argv);  virtual int initialized() {     return (netif_ && uptarget_ && downtarget_);   }};#endif //NS_SMAC

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -