INET Framework for OMNeT++/OMNEST
Mac80211.h
Go to the documentation of this file.
00001 /* -*- mode:c++ -*- ********************************************************
00002  * file:        Mac80211.h
00003  *
00004  * author:      David Raguin/Marc L�bbers
00005  *
00006  * copyright:   (C) 2004 Telecommunication Networks Group (TKN) at
00007  *              Technische Universitaet Berlin, Germany.
00008  *
00009  *              This program is free software; you can redistribute it
00010  *              and/or modify it under the terms of the GNU General Public
00011  *              License as published by the Free Software Foundation; either
00012  *              version 2 of the License, or (at your option) any later
00013  *              version.
00014  *              For further information see file COPYING
00015  *              in the top level directory
00016  ***************************************************************************
00017  * part of:     framework implementation developed by tkn
00018  **************************************************************************/
00019 
00020 
00021 #ifndef MAC_80211_H
00022 #define MAC_80211_H
00023 
00024 #include <list>
00025 #include "WirelessMacBase.h"
00026 #include "Mac80211Pkt_m.h"
00027 #include "Consts80211.h"
00028 #include "NotificationBoard.h"
00029 #include "RadioState.h"
00030 
00031 
00040 class INET_API Mac80211 : public WirelessMacBase, public INotifiable
00041 {
00042     typedef std::list<Mac80211Pkt*> MacPktList;
00043 
00045     enum timerType {
00046       TIMEOUT,
00047       NAV,
00048       CONTENTION,
00049       END_TRANSMISSION,
00050       END_SIFS
00051     };
00052 
00054     enum State {
00055       WFDATA = 0, // waiting for data packet
00056       QUIET = 1,  // waiting for the communication between two other nodes to end
00057       IDLE = 2,   // no packet to send, no packet receiving
00058       CONTEND = 3,// contention state (battle for the channel)
00059       WFCTS = 4,  // RTS sent, waiting for CTS
00060       WFACK = 5,  // DATA packet sent, waiting for ACK
00061       BUSY = 6    // during transmission of an ACK or a BROADCAST packet
00062     };
00063 
00064   public:
00065     Mac80211();
00066     virtual ~Mac80211();
00067 
00068   protected:
00070     virtual int numInitStages() const {return 2;}
00071     virtual void initialize(int);
00072 
00074     virtual void registerInterface();
00075 
00076   protected:
00078     virtual void receiveChangeNotification(int category, const cPolymorphic *details);
00079 
00081     virtual void handleSelfMsg(cMessage*);
00082 
00084     virtual void handleUpperMsg(cPacket*);
00085 
00087     virtual void handleCommand(cMessage*);
00088 
00090     virtual void handleLowerMsg(cPacket*);
00091 
00093     virtual void handleEndContentionTimer();
00095     virtual void handleMsgNotForMe(Mac80211Pkt*);
00097     virtual void handleMsgForMe(Mac80211Pkt*);
00098     // ** @brief handle a Broadcast message*/
00099     virtual void handleBroadcastMsg(Mac80211Pkt*);
00100 
00102     virtual void handleEndTransmissionTimer();
00103 
00105     virtual void handleEndSifsTimer();
00107     virtual void handleTimeoutTimer();
00110     virtual void handleNavTimer();
00111 
00112     virtual void handleRTSframe(Mac80211Pkt*);
00113 
00114     virtual void handleDATAframe(Mac80211Pkt*);
00115 
00116     virtual void handleACKframe(Mac80211Pkt*);
00117 
00118     virtual void handleCTSframe(Mac80211Pkt*);
00119 
00121     virtual void sendDATAframe();
00122 
00124     virtual void sendACKframe(Mac80211Pkt*);
00125 
00127     virtual void sendCTSframe(Mac80211Pkt*);
00128 
00130     virtual void sendRTSframe();
00131 
00133     virtual void sendBROADCASTframe();
00134 
00136     virtual Mac80211Pkt* encapsMsg(cPacket *netw);
00137 
00139     virtual void decapsulateAndSendUp(Mac80211Pkt *frame);
00140 
00142     virtual Mac80211Pkt* buildDATAframe();
00143 
00145     virtual Mac80211Pkt* buildACKframe(Mac80211Pkt*);
00146 
00148     virtual Mac80211Pkt* buildCTSframe(Mac80211Pkt*);
00149 
00151     virtual Mac80211Pkt* buildRTSframe();
00152 
00154     virtual Mac80211Pkt* buildBROADCASTframe();
00155 
00157     virtual void beginNewCycle();
00158 
00160     virtual simtime_t computeBackoff();
00161 
00163     virtual int computeContentionWindow();
00164 
00166     virtual void testMaxAttempts();
00167 
00169     virtual simtime_t computeTimeout(_802_11frameType type, simtime_t last_frame_duration);
00170 
00172     virtual simtime_t computePacketDuration(int bits);
00173 
00175     static const char *stateName(State state);
00176 
00178     static const char *timerTypeName(int type);
00179 
00181     static const char *pktTypeName(int type);
00182 
00184     virtual void setState(State state);
00185 
00186   protected:
00188     MACAddress myMacAddr;
00189 
00190     // TIMERS:
00191 
00194     cMessage* timeout;
00195 
00198     cMessage* nav;
00199 
00201     cMessage* contention;
00202 
00205     cMessage* endTransmission;
00206 
00208     cMessage* endSifs;
00209 
00211     simtime_t EIFS;
00212 
00214     simtime_t BW;
00215 
00217     State state;
00218 
00220     RadioState::State radioState;
00221 
00224     int maxQueueSize;
00225 
00227     bool nextIsBroadcast;
00228 
00230     MacPktList fromUpperLayer;
00231 
00233     int retryCounter;
00234 
00237     bool tryWithoutBackoff;
00238 
00240     bool rtsCts;
00241 
00244     simtime_t delta;
00245 
00248     double bitrate;
00249 
00251     int broadcastBackoff;
00252 };
00253 
00254 #endif
00255