• Main Page
  • Classes
  • Files
  • File List

/Users/yzchen/ns/ns-allinone-2.33/ns-2.33/mac/smac.h

00001 
00002 /*
00003  * smac.h
00004  * Copyright (C) 2000 by the University of Southern California
00005  * $Id: smac.h,v 1.11 2005/08/25 18:58:07 johnh Exp $
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License,
00009  * version 2, as published by the Free Software Foundation.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License along
00017  * with this program; if not, write to the Free Software Foundation, Inc.,
00018  * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00019  *
00020  *
00021  * The copyright of this module includes the following
00022  * linking-with-specific-other-licenses addition:
00023  *
00024  * In addition, as a special exception, the copyright holders of
00025  * this module give you permission to combine (via static or
00026  * dynamic linking) this module with free software programs or
00027  * libraries that are released under the GNU LGPL and with code
00028  * included in the standard release of ns-2 under the Apache 2.0
00029  * license or under otherwise-compatible licenses with advertising
00030  * requirements (or modified versions of such code, with unchanged
00031  * license).  You may copy and distribute such a system following the
00032  * terms of the GNU GPL for this module and the licenses of the
00033  * other code concerned, provided that you include the source code of
00034  * that other code when and as the GNU GPL requires distribution of
00035  * source code.
00036  *
00037  * Note that people who make modified versions of this module
00038  * are not obligated to grant this special exception for their
00039  * modified versions; it is their choice whether to do so.  The GNU
00040  * General Public License gives permission to release a modified
00041  * version without this exception; this exception also makes it
00042  * possible to release a modified version which carries forward this
00043  * exception.
00044  *
00045  */
00046 
00047 // smac is designed and developed by Wei Ye (SCADDS/ISI)
00048 // and is ported into ns by Padma Haldar, June'02.
00049 // Contributors: Yuan Li
00050 
00051 // This module implements Sensor-MAC
00052 //  See http://www.isi.edu/scadds/papers/smac_infocom.pdf for details
00053 //
00054 // It has the following functions.
00055 //  1) Both virtual and physical carrier sense
00056 //  2) RTS/CTS for hidden terminal problem
00057 //  3) Backoff and retry
00058 //  4) Broadcast packets are sent directly without using RTS/CTS/ACK.
00059 //  5) A long unicast message is divided into multiple TOS_MSG (by upper
00060 //     layer). The RTS/CTS reserves the medium for the entire message.
00061 //     ACK is used for each TOS_MSG for immediate error recovery.
00062 //  6) Node goes to sleep when its neighbor is communicating with another
00063 //     node.
00064 //  7) Each node follows a periodic listen/sleep schedule
00065 //  8.1) At bootup time each node listens for a fixed SYNCPERIOD and then
00066 //     tries to send out a sync packet. It suppresses sending out of sync pkt 
00067 //     if it happens to receive a sync pkt from a neighbor and follows the 
00068 //     neighbor's schedule. 
00069 //  8.2) Or a node can choose its own schecule instead of following others, the
00070 //       schedule start time is user configurable
00071 //  9) Neighbor Discovery: in order to prevent that two neighbors can not
00072 //     find each other due to following complete different schedules, each
00073 //     node periodically listen for a whole period of the SYNCPERIOD
00074 //  10) Duty cycle is user configurable
00075 
00076 //  New features including adaptive listen
00077 //   See http://www.isi.edu/~weiye/pub/smac_ton.pdf
00078  
00079 
00080 #ifndef NS_SMAC
00081 #define NS_SMAC
00082 
00083 //test features described in Journal paper, adaptive listen, etc
00084 //#ifndef JOURNAL_PAPER
00085 //#define JOURNAL_PAPER
00086 //#endif
00087 
00088 #include "mac.h"
00089 #include "mac-802_11.h"
00090 #include "cmu-trace.h"
00091 #include "random.h"
00092 #include "timer-handler.h"
00093 
00094 /* User-adjustable MAC parameters
00095  *--------------------------------
00096  * The default values can be overriden in Each application's Makefile
00097  * SMAC_MAX_NUM_NEIGHB: maximum number of neighbors.
00098  * SMAC_MAX_NUM_SCHED: maximum number of different schedules.
00099  * SMAC_DUTY_CYCLE: duty cycle in percentage. It controls the length of sleep 
00100  *   interval.
00101  * SMAC_RETRY_LIMIT: maximum number of RTS retries for sending a single message.
00102  * SMAC_EXTEND_LIMIT: maximum number of times to extend Tx time when ACK timeout
00103      happens.
00104  */
00105 
00106 #ifndef SMAC_MAX_NUM_NEIGHBORS
00107 #define SMAC_MAX_NUM_NEIGHBORS 20
00108 #endif
00109 
00110 #ifndef SMAC_MAX_NUM_SCHEDULES
00111 #define SMAC_MAX_NUM_SCHEDULES 4
00112 #endif
00113 
00114 #ifndef SMAC_DUTY_CYCLE
00115 #define SMAC_DUTY_CYCLE 10
00116 #endif
00117 
00118 #ifndef SMAC_RETRY_LIMIT
00119 #define SMAC_RETRY_LIMIT 5
00120 #endif
00121 
00122 #ifndef SMAC_EXTEND_LIMIT
00123 #define SMAC_EXTEND_LIMIT 5
00124 #endif
00125 
00126 #ifdef JOURNAL_PAPER
00127 
00128 #ifndef SMAC_UPDATE_NEIGHB_PERIOD
00129 #define SMAC_UPDATE_NEIGHB_PERIOD 50
00130 #endif
00131                                                                                                                                                       
00132 #ifndef GUARDTIME
00133 #define GUARDTIME 0.001
00134 #endif
00135 
00136 #endif
00137                                                                                                                                                            
00138 
00139 /* Internal MAC parameters
00140  *--------------------------
00141  * Do NOT change them unless for tuning S-MAC
00142  * SYNC_CW: number of slots in the sync contention window, must be 2^n - 1 
00143  * DATA_CW: number of slots in the data contention window, must be 2^n - 1
00144  * SYNC_PERIOD: period to send a sync pkt, in cycles.
00145  * SRCH_CYCLES_LONG: # of SYNC periods during which a node performs a neighbor discovery
00146  * SRCH_CYCLES_SHORT: if there is no known neighbor, a node need to seach neighbor more aggressively
00147  */
00148 
00149 #define SYNC_CW 31
00150 #define DATA_CW 63
00151 #define SYNCPERIOD 10
00152 #define SYNCPKTTIME 3         // an adhoc value used for now later shld converge with durSyncPkt_
00153 
00154 #define SRCH_CYCLES_SHORT 3
00155 #define SRCH_CYCLES_LONG 22
00156 
00157 
00158 /* Physical layer parameters
00159  *---------------------------
00160  * Based on the parameters from PHY_RADIO and RADIO_CONTROL
00161  * CLOCK_RES: clock resolution in ms. 
00162  * BANDWIDTH: bandwidth (bit rate) in kbps. Not directly used.
00163  * PRE_PKT_BYTES: number of extra bytes transmitted before each pkt. It equals
00164  *   preamble + start symbol + sync bytes.
00165  * ENCODE_RATIO: output/input ratio of the number of bytes of the encoding
00166  *  scheme. In Manchester encoding, 1-byte input generates 2-byte output.
00167  * PROC_DELAY: processing delay of each packet in physical and MAC layer, in ms
00168  */
00169 
00170 #define CLOCKRES 1       // clock resolution is 1ms
00171 #define BANDWIDTH 20      // kbps =>CHANGE BYTE_TX_TIME WHENEVER BANDWIDTH CHANGES
00172 //#define BYTE_TX_TIME 4/10 // 0.4 ms to tx one byte => changes when bandwidth does
00173 #define PRE_PKT_BYTES 5
00174 #define ENCODE_RATIO 2   /* Manchester encoding has 2x overhead */
00175 #define PROC_DELAY 1
00176 
00177 
00178 
00179 // Note everything is in clockticks (CLOCKRES in ms) for tinyOS
00180 // so we need to convert that to sec for ns
00181 #define CLKTICK2SEC(x)  ((x) * (CLOCKRES / 1.0e3))
00182 #define SEC2CLKTICK(x)  ((x) / (CLOCKRES / 1.0e3))
00183 
00184 
00185 // MAC states
00186 #define SLEEP 0         // radio is turned off, can't Tx or Rx
00187 #define IDLE 1          // radio in Rx mode, and can start Tx
00188 //#define CHOOSE_SCHED 2  // node in boot-up phase, needs to choose a schedule
00189 #define CR_SENSE 2      // medium is free, do it before initiate a Tx
00190 //#define BACKOFF 3       // medium is busy, and cannot Tx
00191 #define WAIT_CTS 3      // sent RTS, waiting for CTS
00192 #define WAIT_DATA 4     // sent CTS, waiting for DATA
00193 #define WAIT_ACK 5      // sent DATA, waiting for ACK
00194 #ifdef JOURNAL_PAPER
00195 #define TX_NEXT_FRAG 6 // send one fragment, waiting for next from upper layer
00196 #else
00197 #define WAIT_NEXTFRAG 6 // send one fragment, waiting for next from upper layer
00198 #endif
00199 
00200 #ifdef JOURNAL_PAPER
00201 #define DATA_SENSE1 7 // received a RTS destined to another node, keep listening until confirm sender gets a CTS or starts tx data
00202 #define DATA_SENSE2 8 // received a RTS destined to another node,and did not receive a RTS, keep listening until timeout or receive data
00203 #define TX_PKT 9 // before sending CTS/DATA/ACK, need to wait for a sifs_ time
00204 #endif
00205 
00206 // how to send the pkt: broadcast or unicast
00207 #define BCASTSYNC 0
00208 #define BCASTDATA 1
00209 #define UNICAST 2
00210 
00211 #ifdef JOURNAL_PAPER
00212 #define UNICAST_ADDR 0
00213 #endif
00214 
00215 // Types of pkt
00216 #define DATA_PKT 0
00217 #define RTS_PKT 1
00218 #define CTS_PKT 2
00219 #define ACK_PKT 3
00220 #define SYNC_PKT 4
00221 
00222 
00223 // radio states for performance measurement
00224 #define RADIO_SLP 0  // radio off
00225 #define RADIO_IDLE 1 // radio idle
00226 #define RADIO_RX 2   // recv'ing mode
00227 #define RADIO_TX 3   // transmitting mode
00228 
00229 
00230 
00231 
00232 /*  sizeof smac datapkt hdr and smac control and sync packets  */
00233 /*  have been hardcoded here to mirror the values in TINY_OS implementation */
00234 /*  The following is the pkt format definitions for tiny_os implementation */
00235 /*  of smac : */
00236 
00237 /*  typedef struct MAC_CTRLPKT_VALS{ */
00238 /*  unsigned char length; */
00239 /*  char type; */
00240 /*  short addr; */
00241 /*  unsigned char group; */
00242 /*  short srcAddr; */
00243 /*  unsigned char duration; */
00244 /*  short crc; */
00245 /*  }; */
00246 
00247 /*  typedef struct MAC_SYNCPKT_VALS{ */
00248 /*  unsigned char length; */
00249 /*  char type; */
00250 /*  short srcAddr; */
00251 /*  short syncNode; */
00252 /*  unsigned char sleepTime;  // my next sleep time from now */
00253 /*  short crc; */
00254 /*  };  */
00255 
00256 /*  struct MSG_VALS{ */
00257 /*  unsigned char length; */
00258 /*  char type; */
00259 /*  short addr; */
00260 /*  unsigned char group; */
00261 /*  short srcAddr; */
00262 /*  unsigned char duration; */
00263 /*  char data[DATA_LENGTH]; */
00264 /*  short crc; */
00265 /*  }; */
00266 
00267 // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
00268 
00269 #define SIZEOF_SMAC_DATAPKT 50  // hdr(10) + payload - fixed size pkts
00270 #define SIZEOF_SMAC_CTRLPKT 10
00271 #define SIZEOF_SMAC_SYNCPKT 9  
00272 
00273 
00274 // Following are the ns definitions of the smac frames
00275 //SYNC PKT 
00276 struct smac_sync_frame { 
00277   int type; 
00278   int length; 
00279   int srcAddr;
00280   //int dstAddr;
00281   int syncNode; 
00282   double sleepTime;  // my next sleep time from now */
00283 #ifdef JOURNAL_PAPER
00284   int state;  // if node has changed schedule
00285 #endif
00286   int crc; 
00287 }; 
00288 
00289 // RTS, CTS, ACK
00290 struct smac_control_frame {
00291   int type;
00292   int length;
00293   int dstAddr;
00294   int srcAddr;
00295   double duration;
00296   int crc;
00297 };
00298 
00299 // DATA 
00300 struct hdr_smac {
00301   int type;
00302   int length;
00303   int dstAddr;
00304   int srcAddr;
00305   double duration;
00306   //char data[DATA_LENGTH];
00307   int crc;
00308 };
00309 
00310 // Used by smac when in sync mode
00311 struct SchedTable { 
00312   int txSync;  // flag indicating need to send sync 
00313   int txData;  // flag indicating need to send data 
00314   int numPeriods; // count for number of periods 
00315 #ifdef JOURNAL_PAPER
00316   int numNodes;  // number of nodes on this schedule
00317   int syncNode;  // the node who initialized this schedule
00318   int chkSched; // flag indicating need to check numNodes
00319 #endif
00320 }; 
00321 
00322 struct NeighbList { 
00323   int nodeId; 
00324   int schedId;
00325 #ifdef JOURNAL_PAPER
00326   int active; //flag indicating the node is active recently
00327   int state; // flag indicating the node has changed schedule
00328 #endif 
00329 }; 
00330 
00331 class SMAC;
00332 
00333 // Timers used in smac
00334 class SmacTimer : public TimerHandler {
00335  public:
00336   SmacTimer(SMAC *a) : TimerHandler() {a_ = a; }
00337   virtual void expire(Event *e) = 0 ;
00338   int busy() ;
00339  protected:
00340   SMAC *a_;
00341 };
00342 
00343 #ifdef JOURNAL_PAPER
00344 // timer for updating neighbors periodically
00345 class SmacUpdateNeighbTimer : public SmacTimer {
00346  public:
00347   SmacUpdateNeighbTimer(SMAC *a) : SmacTimer(a) {}
00348   void expire(Event *e);
00349 };
00350                                                                                                                                                             
00351 // timer for putting nodes back to sleep after Adaptive Listen
00352 class SmacAdaptiveListenTimer : public SmacTimer {
00353  public:
00354   SmacAdaptiveListenTimer(SMAC *a) : SmacTimer(a) {}
00355   void expire(Event *e);
00356 };
00357 #endif
00358 
00359 // Generic timer used for sync, CTS and ACK timeouts
00360 class SmacGeneTimer : public SmacTimer {
00361  public:
00362   SmacGeneTimer(SMAC *a) : SmacTimer(a) {}
00363   void expire(Event *e);
00364 };
00365 
00366 // Receive timer for receiving pkts
00367 class SmacRecvTimer : public SmacTimer {
00368  public:
00369   SmacRecvTimer(SMAC *a) : SmacTimer(a) { stime_ = rtime_ = 0; }
00370   void sched(double duration);
00371   void resched(double time);
00372   void expire(Event *e);
00373   double timeToExpire();
00374  protected:
00375   double stime_;
00376   double rtime_;
00377 };
00378 
00379 // Send timer
00380 class SmacSendTimer : public SmacTimer {
00381  public:
00382   SmacSendTimer(SMAC *a) : SmacTimer(a) {}
00383   void expire(Event *e);
00384 };
00385 
00386 // Nav- indicating if medium is busy or not
00387 class SmacNavTimer : public SmacTimer {
00388  public:
00389   SmacNavTimer(SMAC *a) : SmacTimer(a) {}
00390   void expire(Event *e);
00391 };
00392 
00393 // Neighbor nav - if neighbor is busy or not
00394 // used for data timeout
00395 class SmacNeighNavTimer : public SmacTimer {
00396  public:
00397   SmacNeighNavTimer(SMAC *a) : SmacTimer(a) { stime_ = rtime_ = 0; }
00398   void sched(double duration);
00399   void expire(Event *e);
00400   double timeToExpire();
00401  protected:
00402   double stime_;
00403   double rtime_;
00404 };
00405 
00406 // carrier sense timer
00407 class SmacCsTimer : public SmacTimer {
00408  public:
00409   SmacCsTimer(SMAC *a) : SmacTimer(a) {}
00410   void expire(Event *e);
00411   void checkToCancel();
00412 };
00413 
00414 // synchronisation timer, regulates the sleep/wakeup cycles
00415 class SmacCounterTimer : public SmacTimer { 
00416  public:  
00417   friend class SMAC;
00418   SmacCounterTimer(SMAC *a, int i) : SmacTimer(a) {index_ = i;}
00419   void sched(double t);
00420   void expire(Event *e); 
00421   double timeToSleep();
00422  protected:
00423   int index_;
00424   double value_;
00425   double syncTime_;
00426   double dataTime_;
00427   double listenTime_;
00428   double sleepTime_;
00429   double cycleTime_;
00430   double tts_;
00431   double stime_;
00432 }; 
00433 
00434 
00435 // The smac class
00436 class SMAC : public Mac {
00437   
00438   friend class SmacGeneTimer;
00439   friend class SmacRecvTimer;
00440   friend class SmacSendTimer;
00441   friend class SmacNavTimer;
00442   friend class SmacNeighNavTimer;
00443   friend class SmacCsTimer; 
00444   friend class SmacCounterTimer;
00445 #ifdef JOURNAL_PAPER
00446   friend class SmacUpdateNeighbTimer;
00447   friend class SmacAdaptiveListenTimer;
00448 #endif
00449 
00450  public:
00451   SMAC(void);
00452   ~SMAC() { 
00453     for (int i=0; i< SMAC_MAX_NUM_SCHEDULES; i++) {
00454       delete mhCounter_[i];
00455     }
00456   }
00457   void recv(Packet *p, Handler *h);
00458 
00459  protected:
00460   
00461   // functions for handling timers
00462 #ifdef JOURNAL_PAPER
00463   void handleUpdateNeighbTimer();
00464   void handleAdaptiveListenTimer();
00465 #endif
00466   void handleGeneTimer();
00467   void handleRecvTimer();
00468   void handleSendTimer();
00469   void handleNavTimer();
00470   void handleNeighNavTimer();
00471   void handleCsTimer();
00472   //void handleChkSendTimer();
00473   void handleCounterTimer(int i);
00474 
00475   // Internal MAC parameters
00476   double slotTime_;
00477   double slotTime_sec_;
00478   double difs_;
00479   double sifs_;
00480   double eifs_;
00481   double guardTime_;
00482   double byte_tx_time_;
00483   double dutyCycle_;
00484  
00485  private:
00486   // functions for node schedule folowing sleep-wakeup cycles
00487   void setMySched(Packet *syncpkt);
00488   void sleep();
00489   void wakeup();
00490 
00491 #ifdef JOURNAL_PAPER
00492   // funtions for update neighbors and schedules
00493   void check_schedFlag();
00494   void update_schedTab_neighbList();
00495   void update_myNeighbList();
00496   void update_neighbList();
00497   void checkMySched();
00498   void dump();
00499 #endif
00500 
00501   // functions for handling incoming packets
00502   
00503   void rxMsgDone(Packet* p);
00504   //void rxFragDone(Packet *p);  no frag for now
00505 #ifdef JOURNAL_PAPER
00506   void rxFragDone(Packet *p); 
00507 #endif
00508   void handleRTS(Packet *p);
00509   void handleCTS(Packet *p);
00510   void handleDATA(Packet *p);
00511   void handleACK(Packet *p);
00512   void handleSYNC(Packet *p);
00513 
00514   // functions for handling outgoing packets
00515   
00516   // check for pending data pkt to be tx'ed
00517   // when smac is not following SYNC (sleep-wakeup) cycles.
00518   int checkToSend();               // check if can send, start cs 
00519 
00520   bool chkRadio();         // checks radiostate
00521   void transmit(Packet *p);         // actually transmits packet
00522 
00523   bool sendMsg(Packet *p, Handler *h);
00524   bool bcastMsg(Packet *p);
00525   bool unicastMsg(int n, Packet *p);
00526   //int sendMoreFrag(Packet *p);
00527   
00528   void txMsgDone();
00529   // void txFragDone();
00530 
00531 #ifdef JOURNAL_PAPER
00532   // functions for handling fragmentation
00533   bool txNextFrag(void* data);
00534   void txFragDone();
00535                                                                                                                                                             
00536   // functions for handling adaptive listen
00537   void adaptiveListen();
00538 #endif
00539 
00540   int startBcast();
00541   int startUcast();
00542   
00543   bool sendRTS();
00544   bool sendCTS(double duration);
00545   bool sendDATA();
00546   bool sendACK(double duration);
00547   bool sendSYNC();
00548 
00549   void sentRTS(Packet *p);
00550   void sentCTS(Packet *p);
00551   void sentDATA(Packet *p);
00552   void sentACK(Packet *p);
00553   void sentSYNC(Packet *p);
00554   
00555   // Misc functions
00556   void collision(Packet *p);
00557   void capture(Packet *p);
00558   double txtime(Packet *p);
00559   
00560   void updateNav(double duration);
00561   void updateNeighNav(double duration);
00562 
00563   void mac_log(Packet *p) {
00564     logtarget_->recv(p, (Handler*) 0);
00565   }
00566   
00567   void discard(Packet *p, const char* why);
00568   int drop_RTS(Packet *p, const char* why);
00569   int drop_CTS(Packet *p, const char* why);
00570   int drop_DATA(Packet *p, const char* why);
00571   int drop_SYNC(Packet *p, const char* why);
00572 
00573   // smac methods to set dst, src and hdr_type in pkt hdrs
00574   inline int hdr_dst(char* hdr, int dst = -2) {
00575     struct hdr_smac *sh = (struct hdr_smac *) hdr;
00576     if (dst > -2)
00577       sh->dstAddr = dst;
00578     return sh->dstAddr;
00579   }
00580   inline int hdr_src(char* hdr, int src = -2) {
00581     struct hdr_smac *sh = (struct hdr_smac *) hdr;
00582     if (src > -2)
00583       sh->srcAddr = src;
00584     return sh->srcAddr;
00585   }
00586   inline int hdr_type(char *hdr, u_int16_t type = 0) {
00587     struct hdr_smac *sh = (struct hdr_smac *) hdr;
00588     if (type)
00589       sh->type = type;
00590     return sh->type;
00591   }
00592   
00593   // SMAC internal variables
00594   
00595   NsObject*       logtarget_;
00596   
00597   // Internal states
00598   int  state_;                   // MAC state
00599   int  radioState_;              // state of radio, rx, tx or sleep
00600   int tx_active_;                
00601   int mac_collision_;            
00602   
00603   int sendAddr_;                // node to send data to
00604   int recvAddr_;                // node to receive data from
00605   
00606   double  nav_;         // network allocation vector. nav>0 -> medium busy
00607   double  neighNav_;      // track neighbors' NAV while I'm sending/receiving
00608   
00609   // SMAC Timers
00610 #ifdef JOURNAL_PAPER
00611   SmacUpdateNeighbTimer mhUpdateNeighb_; // timer for updating neighbors periodically
00612   SmacAdaptiveListenTimer mhAdap_; // timer for putting nodes back to sleep after adaptive listen
00613 #endif
00614   SmacNavTimer          mhNav_;         // NAV timer medium is free or not
00615   SmacNeighNavTimer     mhNeighNav_;    // neighbor NAV timer for data timeout
00616   SmacSendTimer         mhSend_;        // incoming packets
00617   SmacRecvTimer         mhRecv_;        // outgoing packets
00618   SmacGeneTimer         mhGene_;        // generic timer used sync/CTS/ACK timeout
00619   SmacCsTimer           mhCS_;          // carrier sense timer
00620   
00621   // array of countertimer, one for each schedule
00622   // counter tracking node's sleep/awake cycle
00623   SmacCounterTimer      *mhCounter_[SMAC_MAX_NUM_SCHEDULES];  
00624 
00625 
00626   int numRetry_;        // number of tries for a data pkt
00627   int numExtend_;      // number of extensions on Tx time when frags are lost
00628 #ifdef JOURNAL_PAPER
00629   int numFrags_;       // number of fragments in this transmission
00630   int succFrags_;      // number of successfully transmitted fragments
00631 #endif
00632   //int numFrags_;       // number of fragments in this transmission
00633   //int succFrags_;      // number of successfully transmitted fragments
00634   int lastRxFrag_;     // keep track of last data fragment recvd to prevent duplicate data
00635 
00636   int howToSend_;               // broadcast or unicast
00637   
00638   double durSyncPkt_;     // duration of sync packet
00639   double durDataPkt_;     // duration of data packet XXX caveat fixed packet size
00640   double durCtrlPkt_;     // duration of control packet
00641   double timeWaitCtrl_;   // set timer to wait for a control packet
00642   
00643   struct SchedTable schedTab_[SMAC_MAX_NUM_SCHEDULES];   // schedule table
00644   struct NeighbList neighbList_[SMAC_MAX_NUM_NEIGHBORS]; // neighbor list
00645 
00646   int mySyncNode_;                                 // nodeid of my synchronizer
00647   
00648   int currSched_;      // current schedule I'm talking to
00649   int numSched_;       // number of different schedules
00650   int numNeighb_;      // number of known neighbors
00651   int numBcast_;       // number of times needed to broadcast a packet
00652   
00653   Packet *dataPkt_;             // outgoing data packet
00654   Packet *pktRx_;               // buffer for incoming pkt
00655   Packet *pktTx_;               // buffer for outgoing pkt
00656 
00657   // flag to check pending data pkt for tx
00658   // when smac is not following SYNC (sleep-wakeup) cycles.
00659   int txData_ ;
00660 
00661   int syncFlag_;  // is set to 1 when SMAC uses sleep-wakeup cycle
00662   int selfConfigFlag_;  // is set to 0 when SMAC uses user configurable schedule start time
00663   double startTime_;  // schedule start time (schedule starts from SYNC period)
00664 
00665   // sleep-wakeup cycle times
00666   double syncTime_;
00667   double dataTime_;
00668   double listenTime_;
00669   double sleepTime_;
00670   double cycleTime_;
00671 
00672 #ifdef JOURNAL_PAPER
00673   int adapTime_;  // time before getting back to sleep when doing adaptive listen
00674   int adaptiveListen_;
00675   int adapSend_;
00676   int txRequest_;
00677   int dataSched_;
00678   int syncSched_;
00679   int sendAddr;
00680                                                                                                                                                             
00681   int schedState_; // schedule state: first, second schedule...
00682                                                                                                                                                             
00683   int globalSchedule_;  // flag indicating if node is in global schedule state
00684                                                                                                                                                             
00685   int updateNeighbList_; // flag indicating if node needs to update neighbor list
00686   char sendSYNCFlag_;    // flag indicating if node has broadcasted SYNC packet or not
00687 #endif
00688 
00689   // neighbor discovery
00690   int searchNeighb_;  // flag indicating if node is in neighbot discovery period
00691   int schedListen_;  // flag indicating if node is in scheduled listen period
00692   int numSync_;  // used to set/clear searchNeighb flag
00693   
00694  protected:
00695   int command(int argc, const char*const* argv);
00696   virtual int initialized() { 
00697     return (netif_ && uptarget_ && downtarget_); 
00698   }
00699 };
00700 
00701 
00702 #endif //NS_SMAC

Generated on Tue Aug 10 2010 16:16:07 for ns-2.33 by  doxygen 1.7.1