00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef MAC_80211_H
00022 #define MAC_80211_H
00023
00024 #include <list>
00025 #include <BaseMacLayer.h>
00026 #include <Mac80211Pkt_m.h>
00027 #include <Consts80211.h>
00028 #include <ChannelSenseRequest_m.h>
00029
00039 class Mac80211 : public BaseMacLayer
00040 {
00041 public:
00042
00044 enum Mac80211MessageKinds {
00045
00046 RTS = LAST_BASE_MAC_MESSAGE_KIND,
00047 CTS,
00048 ACK,
00049 DATA,
00050 BROADCAST,
00051 LAST_MAC_80211_MESSAGE_KIND
00052 };
00053 protected:
00055 typedef std::list<Mac80211Pkt*> MacPktList;
00056
00058 enum timerType {
00059 TIMEOUT,
00060 NAV
00061 };
00062
00064 enum State {
00065 WFDATA = 0,
00066 QUIET = 1,
00067 IDLE = 2,
00068 CONTEND = 3,
00069 WFCTS = 4,
00070 WFACK = 5,
00071 BUSY = 6
00072 };
00073
00075 struct NeighborEntry {
00077 int address;
00078 int fsc;
00079 simtime_t age;
00080 double bitrate;
00081 };
00082
00084 typedef std::list<NeighborEntry> NeighborList;
00085
00086 public:
00087 virtual ~Mac80211();
00088
00089 virtual void initialize(int);
00090 virtual void finish();
00091
00092 protected:
00093
00095 virtual void handleSelfMsg(cMessage*);
00096
00098 virtual void handleUpperMsg(cMessage* msg);
00099
00101 virtual void handleLowerMsg(cMessage*);
00102
00104 virtual void handleLowerControl(cMessage*);
00105
00106
00108
00109
00111 virtual void handleEndContentionTimer();
00112
00114 void handleMsgNotForMe(cMessage *af, simtime_t duration);
00116 void handleMsgForMe(Mac80211Pkt*);
00117
00118 void handleBroadcastMsg(Mac80211Pkt*);
00119
00121 void handleEndTransmission();
00122
00124 void handleEndSifsTimer();
00126 void handleTimeoutTimer();
00129 void handleNavTimer();
00130
00131 void handleRTSframe(Mac80211Pkt*);
00132
00133 void handleDATAframe(Mac80211Pkt*);
00134
00135 void handleACKframe(Mac80211Pkt*);
00136
00137 void handleCTSframe(Mac80211Pkt*);
00138
00139 void dataTransmissionFailed();
00140
00141 void rtsTransmissionFailed();
00142
00144 virtual void sendDATAframe(Mac80211Pkt*);
00145
00147 void sendACKframe(Mac80211Pkt*);
00148
00150 void sendCTSframe(Mac80211Pkt*);
00151
00153 virtual void sendRTSframe();
00154
00156 void sendBROADCASTframe();
00157
00159 Mac80211Pkt* encapsMsg(cPacket *netw);
00160
00162 cMessage* decapsMsg(Mac80211Pkt *frame);
00163
00165 virtual void beginNewCycle();
00166
00168 simtime_t backoff(bool rtscts = true);
00169
00171 void testMaxAttempts();
00172
00174 simtime_t timeOut(Mac80211MessageKinds type, double br);
00175
00177 simtime_t packetDuration(double bits, double br);
00178
00180 const char *stateName(State state);
00181
00183 void setState(State state);
00184
00186 bool rtsCts(Mac80211Pkt* m) {
00187 return m->getBitLength() - MAC80211_HEADER_LENGTH > rtsCtsThreshold;
00188 }
00189
00191 void suspendContention();
00192
00194 double retrieveBitrate(int destAddress);
00195
00197 void addNeighbor(Mac80211Pkt *af);
00198
00200 NeighborList::iterator findNeighbor(int id) {
00201 NeighborList::iterator it;
00202 for(it = neighbors.begin(); it != neighbors.end(); ++it) {
00203 if(it->address == id) break;
00204 }
00205 return it;
00206 }
00207
00209 NeighborList::iterator findOldestNeighbor() {
00210 NeighborList::iterator it = neighbors.begin();
00211 NeighborList::iterator oldIt = neighbors.begin();
00212 simtime_t age = it->age;
00213 for(; it != neighbors.end(); ++it) {
00214 if(it->age < age) {
00215 age = it->age;
00216 oldIt = it;
00217 }
00218 }
00219 return oldIt;
00220 }
00221
00222
00229 void senseChannelWhileIdle(simtime_t duration);
00230
00234 Signal* createSignal(simtime_t start, simtime_t length, double power, double bitrate);
00235
00236 protected:
00237
00238
00239
00242 cMessage* timeout;
00243
00246 cMessage* nav;
00247
00249 ChannelSenseRequest* contention;
00250
00252 ChannelSenseRequest* endSifs;
00253
00257 simtime_t chSenseStart;
00258
00260 State state;
00261
00267 double defaultBitrate;
00268
00270 double txPower;
00271
00273 double centerFreq;
00274
00276 double bitrate;
00278 int catBitrate;
00280 bool autoBitrate;
00282 std::vector<double> snrThresholds;
00283
00286 unsigned queueLength;
00287
00289 bool nextIsBroadcast;
00290
00292 MacPktList fromUpperLayer;
00293
00299 unsigned longRetryCounter;
00300
00302 unsigned shortRetryCounter;
00303
00307 simtime_t remainingBackoff;
00308
00312 simtime_t currentIFS;
00313
00315 int rtsCtsThreshold;
00316
00319 simtime_t delta;
00320
00322 unsigned neighborhoodCacheSize;
00324 simtime_t neighborhoodCacheMaxAge;
00325
00327 NeighborList neighbors;
00328
00330 bool switching;
00331
00333 int fsc;
00334 };
00335
00336 #endif