|
INET Framework for OMNeT++/OMNEST
|
00001 // 00002 // Copyright (C) 2006 Andras Varga and Levente M�sz�ros 00003 // 00004 // This program is free software; you can redistribute it and/or 00005 // modify it under the terms of the GNU Lesser General Public License 00006 // as published by the Free Software Foundation; either version 2 00007 // of the License, or (at your option) any later version. 00008 // 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU Lesser General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU Lesser General Public License 00015 // along with this program; if not, see <http://www.gnu.org/licenses/>. 00016 // 00017 00018 #ifndef IEEE_80211_MAC_H 00019 #define IEEE_80211_MAC_H 00020 00021 // uncomment this if you do not want to log state machine transitions 00022 #define FSM_DEBUG 00023 00024 #include <list> 00025 #include "WirelessMacBase.h" 00026 #include "IPassiveQueue.h" 00027 #include "Ieee80211Frame_m.h" 00028 #include "Ieee80211Consts.h" 00029 #include "NotificationBoard.h" 00030 #include "RadioState.h" 00031 #include "FSMA.h" 00032 00054 class INET_API Ieee80211Mac : public WirelessMacBase, public INotifiable 00055 { 00056 typedef std::list<Ieee80211DataOrMgmtFrame*> Ieee80211DataOrMgmtFrameList; 00057 00061 struct Ieee80211ASFTuple 00062 { 00063 MACAddress address; 00064 int sequenceNumber; 00065 int fragmentNumber; 00066 }; 00067 00068 typedef std::list<Ieee80211ASFTuple*> Ieee80211ASFTupleList; 00069 00070 protected: 00077 MACAddress address; 00078 00080 double bitrate; 00081 00083 double basicBitrate; 00084 00086 int maxQueueSize; 00087 00092 int rtsThreshold; 00093 00105 int transmissionLimit; 00106 00108 int cwMinData; 00109 00111 int cwMinBroadcast; 00112 00114 static const int fragmentationThreshold = 2346; 00116 00117 public: 00123 // don't forget to keep synchronized the C++ enum and the runtime enum definition 00125 enum State { 00126 IDLE, 00127 DEFER, 00128 WAITDIFS, 00129 BACKOFF, 00130 WAITACK, 00131 WAITBROADCAST, 00132 WAITCTS, 00133 WAITSIFS, 00134 RECEIVE, 00135 }; 00136 protected: 00137 cFSM fsm; 00138 00139 public: 00141 enum Mode { 00142 DCF, 00143 PCF, 00144 }; 00145 protected: 00146 Mode mode; 00147 00149 int sequenceNumber; 00150 00156 bool lastReceiveFailed; 00157 00159 bool backoff; 00160 00162 bool nav; 00163 00165 simtime_t backoffPeriod; 00166 00171 int retryCounter; 00172 00174 RadioState::State radioState; 00175 00177 Ieee80211DataOrMgmtFrameList transmissionQueue; 00178 00184 Ieee80211ASFTupleList asfTuplesList; 00185 00187 IPassiveQueue *queueModule; 00188 00193 cMessage *pendingRadioConfigMsg; 00195 00196 protected: 00200 cMessage *endSIFS; 00201 00203 cMessage *endDIFS; 00204 00206 cMessage *endBackoff; 00207 00209 cMessage *endTimeout; 00210 00212 cMessage *endReserve; 00213 00215 cMessage *mediumStateChange; 00217 00218 protected: 00221 long numRetry; 00222 long numSentWithoutRetry; 00223 long numGivenUp; 00224 long numCollision; 00225 long numSent; 00226 long numReceived; 00227 long numSentBroadcast; 00228 long numReceivedBroadcast; 00229 cOutVector stateVector; 00230 cOutVector radioStateVector; 00232 00233 public: 00238 Ieee80211Mac(); 00239 virtual ~Ieee80211Mac(); 00241 00242 protected: 00248 virtual int numInitStages() const {return 2;} 00249 virtual void initialize(int); 00250 virtual void registerInterface(); 00251 virtual void initializeQueueModule(); 00253 00254 protected: 00261 virtual void receiveChangeNotification(int category, const cPolymorphic * details); 00262 00264 virtual void handleCommand(cMessage *msg); 00265 00267 virtual void handleSelfMsg(cMessage *msg); 00268 00270 virtual void handleUpperMsg(cPacket *msg); 00271 00273 virtual void handleLowerMsg(cPacket *msg); 00274 00276 virtual void handleWithFSM(cMessage *msg); 00278 00279 protected: 00285 virtual simtime_t getSIFS(); 00286 virtual simtime_t getSlotTime(); 00287 virtual simtime_t getDIFS(); 00288 virtual simtime_t getEIFS(); 00289 virtual simtime_t getPIFS(); 00290 virtual simtime_t computeBackoffPeriod(Ieee80211Frame *msg, int r); 00292 00293 protected: 00299 virtual void scheduleSIFSPeriod(Ieee80211Frame *frame); 00300 00301 virtual void scheduleDIFSPeriod(); 00302 virtual void cancelDIFSPeriod(); 00303 00304 virtual void scheduleDataTimeoutPeriod(Ieee80211DataOrMgmtFrame *frame); 00305 virtual void scheduleBroadcastTimeoutPeriod(Ieee80211DataOrMgmtFrame *frame); 00306 virtual void cancelTimeoutPeriod(); 00307 00308 virtual void scheduleCTSTimeoutPeriod(); 00309 00311 virtual void scheduleReservePeriod(Ieee80211Frame *frame); 00312 00314 virtual void invalidateBackoffPeriod(); 00315 virtual bool isInvalidBackoffPeriod(); 00316 virtual void generateBackoffPeriod(); 00317 virtual void decreaseBackoffPeriod(); 00318 virtual void scheduleBackoffPeriod(); 00319 virtual void cancelBackoffPeriod(); 00321 00322 protected: 00327 virtual void sendACKFrameOnEndSIFS(); 00328 virtual void sendACKFrame(Ieee80211DataOrMgmtFrame *frame); 00329 virtual void sendRTSFrame(Ieee80211DataOrMgmtFrame *frameToSend); 00330 virtual void sendCTSFrameOnEndSIFS(); 00331 virtual void sendCTSFrame(Ieee80211RTSFrame *rtsFrame); 00332 virtual void sendDataFrameOnEndSIFS(Ieee80211DataOrMgmtFrame *frameToSend); 00333 virtual void sendDataFrame(Ieee80211DataOrMgmtFrame *frameToSend); 00334 virtual void sendBroadcastFrame(Ieee80211DataOrMgmtFrame *frameToSend); 00336 00337 protected: 00342 virtual Ieee80211DataOrMgmtFrame *buildDataFrame(Ieee80211DataOrMgmtFrame *frameToSend); 00343 virtual Ieee80211ACKFrame *buildACKFrame(Ieee80211DataOrMgmtFrame *frameToACK); 00344 virtual Ieee80211RTSFrame *buildRTSFrame(Ieee80211DataOrMgmtFrame *frameToSend); 00345 virtual Ieee80211CTSFrame *buildCTSFrame(Ieee80211RTSFrame *rtsFrame); 00346 virtual Ieee80211DataOrMgmtFrame *buildBroadcastFrame(Ieee80211DataOrMgmtFrame *frameToSend); 00348 00353 virtual Ieee80211Frame *setBasicBitrate(Ieee80211Frame *frame); 00354 00355 protected: 00360 virtual void finishCurrentTransmission(); 00361 virtual void giveUpCurrentTransmission(); 00362 virtual void retryCurrentTransmission(); 00363 00365 virtual void sendDownPendingRadioConfigMsg(); 00366 00368 virtual void setMode(Mode mode); 00369 00371 virtual Ieee80211DataOrMgmtFrame *getCurrentTransmission(); 00372 00374 virtual void resetStateVariables(); 00375 00378 virtual bool isMediumStateChange(cMessage *msg); 00379 00381 virtual bool isMediumFree(); 00382 00384 virtual bool isBroadcast(Ieee80211Frame *msg); 00385 00387 virtual bool isForUs(Ieee80211Frame *msg); 00388 00390 virtual bool isDataOrMgmtFrame(Ieee80211Frame *frame); 00391 00393 virtual Ieee80211Frame *getFrameReceivedBeforeSIFS(); 00394 00396 virtual void popTransmissionQueue(); 00397 00403 virtual double computeFrameDuration(Ieee80211Frame *msg); 00404 virtual double computeFrameDuration(int bits, double bitrate); 00405 00407 virtual void logState(); 00408 00410 const char *modeName(int mode); 00412 }; 00413 00414 #endif 00415