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 "BasicLayer.h"
00026 #include "Mac80211Pkt_m.h"
00027 #include "Consts80211.h"
00028 #include "RadioState.h"
00029 #include "Bitrate.h"
00030 #include <ActiveChannel.h>
00031 #include "SingleChannelRadio.h"
00032 #include <MediumIndication.h>
00033
00042 class Mac80211 : public BasicLayer
00043 {
00044 protected:
00045 typedef std::list<Mac80211Pkt*> MacPktList;
00046
00048 enum timerType {
00049 TIMEOUT,
00050 NAV,
00051 CONTENTION,
00052 END_SIFS
00053 };
00054
00056 enum State {
00057 WFDATA = 0,
00058 QUIET = 1,
00059 IDLE = 2,
00060 CONTEND = 3,
00061 WFCTS = 4,
00062 WFACK = 5,
00063 BUSY = 6
00064 };
00065
00066 struct NeighborEntry {
00067 int address;
00068 int fsc;
00069 simtime_t age;
00070 double bitrate;
00071 };
00072
00073 typedef std::list<NeighborEntry> NeighborList;
00074
00075 public:
00076 Module_Class_Members(Mac80211, BasicLayer, 0);
00077
00078 virtual void initialize(int);
00079 virtual void finish();
00080
00081 protected:
00083 virtual void receiveBBItem(int category, const BBItem *details, int scopeModuleId);
00084
00086 virtual void handleSelfMsg(cMessage*);
00087
00089 virtual void handleUpperMsg(cMessage*);
00090
00092 virtual void handleLowerMsg(cMessage*);
00093
00095 virtual void handleLowerControl(cMessage*);
00096
00098 virtual void handleEndContentionTimer();
00099
00101 void handleMsgNotForMe(cMessage *af, double duration);
00103 void handleMsgForMe(Mac80211Pkt*);
00104
00105 void handleBroadcastMsg(Mac80211Pkt*);
00106
00108 void handleEndTransmission();
00109
00111 void handleEndSifsTimer();
00113 void handleTimeoutTimer();
00116 void handleNavTimer();
00117
00118 void handleRTSframe(Mac80211Pkt*);
00119
00120 void handleDATAframe(Mac80211Pkt*);
00121
00122 void handleACKframe(Mac80211Pkt*);
00123
00124 void handleCTSframe(Mac80211Pkt*);
00125
00127 virtual void sendDATAframe(Mac80211Pkt*);
00128
00130 void sendACKframe(Mac80211Pkt*);
00131
00133 void sendCTSframe(Mac80211Pkt*);
00134
00136 virtual void sendRTSframe();
00137
00139 void sendBROADCASTframe();
00140
00142 Mac80211Pkt* encapsMsg(cMessage *netw);
00143
00145 cMessage* decapsMsg(Mac80211Pkt *frame);
00146
00148 virtual void beginNewCycle();
00149
00151 double backoff();
00152
00154 int contentionWindow();
00155
00157 void testMaxAttempts();
00158
00160 double timeOut(frameType_802_11 type, double br);
00161
00163 double packetDuration(double bits, double br);
00164
00166 const char *stateName(State state);
00167
00169 void setState(State state);
00170
00172 bool rtsCts(Mac80211Pkt* m) {
00173 return m->length() - MAC80211_HEADER_LENGTH > rtsCtsThreshold;
00174 }
00175
00177 void suspendContention();
00178
00180 double retrieveBitrate(int destAddress);
00181
00183 void addNeighbor(Mac80211Pkt *af);
00184
00186 NeighborList::iterator findNeighbor(int id) {
00187 NeighborList::iterator it;
00188 for(it = neighbors.begin(); it != neighbors.end(); ++it) {
00189 if(it->address == id) break;
00190 }
00191 return it;
00192 }
00193
00195 NeighborList::iterator findOldestNeighbor() {
00196 NeighborList::iterator it = neighbors.begin();
00197 NeighborList::iterator oldIt = neighbors.begin();
00198 simtime_t age = it->age;
00199 for(; it != neighbors.end(); ++it) {
00200 if(it->age < age) {
00201 age = it->age;
00202 oldIt = it;
00203 }
00204 }
00205 return oldIt;
00206 }
00207
00208 protected:
00212 int myMacAddr;
00213
00214
00215
00218 cMessage* timeout;
00219
00222 cMessage* nav;
00223
00225 cMessage* contention;
00226
00228 cMessage* endSifs;
00229
00231 State state;
00232
00234 RadioState::States radioState;
00236 int catRadioState;
00237
00239 MediumIndication::States medium;
00240
00242 int catMedium;
00243
00249 double defaultBitrate;
00250
00253 double bitrate;
00255 int catBitrate;
00257 bool autoBitrate;
00259 std::vector<double> snrThresholds;
00260
00262 SingleChannelRadio* radio;
00263
00266 unsigned queueLength;
00267
00269 bool nextIsBroadcast;
00270
00272 MacPktList fromUpperLayer;
00273
00279 unsigned longRetryCounter;
00280
00282 unsigned shortRetryCounter;
00283
00288 simtime_t remainingBackoff;
00289
00291 int rtsCtsThreshold;
00292
00295 double delta;
00296
00298 unsigned neighborhoodCacheSize;
00300 simtime_t neighborhoodCacheMaxAge;
00301
00302 NeighborList neighbors;
00303
00305 bool switching;
00306
00308 int fsc;
00309 };
00310
00311 #endif