BMacLayer.h

00001 //
00002 // This program is free software: you can redistribute it and/or modify
00003 // it under the terms of the GNU Lesser General Public License as published by
00004 // the Free Software Foundation, either version 3 of the License, or
00005 // (at your option) any later version.
00006 // 
00007 // This program is distributed in the hope that it will be useful,
00008 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00009 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010 // GNU Lesser General Public License for more details.
00011 // 
00012 // You should have received a copy of the GNU Lesser General Public License
00013 // along with this program.  If not, see http://www.gnu.org/licenses/.
00014 // 
00015 
00016 #ifndef BMACLAYER_H_
00017 #define BMACLAYER_H_
00018 
00019 #include <string>
00020 #include <sstream>
00021 #include <vector>
00022 #include <list>
00023 #include "BaseMacLayer.h"
00024 #include <DroppedPacket.h>
00025 #include <MacPkt_m.h>
00026 
00056 class  BMacLayer : public BaseMacLayer
00057 {
00058   public:
00059   virtual ~BMacLayer();
00060 
00062     virtual void initialize(int);
00063 
00065     virtual void finish();
00066 
00068     virtual void handleLowerMsg(cMessage*);
00069 
00071     virtual void handleUpperMsg(cMessage*);
00072 
00074     virtual void handleSelfMsg(cMessage*);
00075 
00077     virtual void handleLowerControl(cMessage *msg);
00078 
00079   protected:
00080     typedef std::list<MacPkt*> MacQueue;
00081 
00084     MacQueue macQueue;
00085 
00088   long nbTxDataPackets;
00089   long nbTxPreambles;
00090   long nbRxDataPackets;
00091   long nbRxPreambles;
00092   long nbMissedAcks;
00093   long nbRecvdAcks;
00094   long nbDroppedDataPackets;
00095   long nbTxAcks;
00118   enum States {
00119     INIT, //0
00120     SLEEP,  //1
00121     CCA,  //2
00122     SEND_PREAMBLE,  //3
00123     WAIT_DATA,    //4
00124     SEND_DATA,    //5
00125     WAIT_TX_DATA_OVER,  //6
00126     WAIT_ACK,   //7
00127     SEND_ACK,   //8
00128     WAIT_ACK_TX   //9
00129     };
00131   States macState;
00132 
00135   enum TYPES {
00136     // packet types
00137     BMAC_PREAMBLE = 191,
00138     BMAC_DATA,
00139     BMAC_ACK,
00140     // self message types
00141     BMAC_RESEND_DATA,
00142     BMAC_ACK_TIMEOUT,
00143     BMAC_START_BMAC,
00144     BMAC_WAKE_UP,
00145     BMAC_SEND_ACK,
00146     BMAC_CCA_TIMEOUT,
00147     BMAC_ACK_TX_OVER,
00148     BMAC_SEND_PREAMBLE,
00149     BMAC_STOP_PREAMBLES,
00150     BMAC_DATA_TX_OVER,
00151     BMAC_DATA_TIMEOUT
00152   };
00153 
00154   // messages used in the FSM
00155   cMessage *resend_data;
00156   cMessage *ack_timeout;
00157   cMessage *start_bmac;
00158   cMessage *wakeup;
00159   cMessage *send_ack;
00160   cMessage *cca_timeout;
00161   cMessage *ack_tx_over;
00162   cMessage *send_preamble;
00163   cMessage *stop_preambles;
00164   cMessage *data_tx_over;
00165   cMessage *data_timeout;
00166 
00169   int lastDataPktSrcAddr;
00170   int lastDataPktDestAddr;
00171   int txAttempts;
00176   DroppedPacket droppedPacket;
00177 
00179   int catDroppedPacket;
00180 
00182   int nicId;
00183 
00185   double queueLength;
00193   bool animation;
00195   double slotDuration;
00197   double bitrate;
00199   double headerLength;
00201   double checkInterval;
00203   double txPower;
00205   bool useMacAcks;
00208   int maxTxAttempts;
00210   bool stats;
00211 
00213   enum BMAC_COLORS {
00214     GREEN = 1,
00215     BLUE = 2,
00216     RED = 3,
00217     BLACK = 4,
00218     YELLOW = 5
00219   };
00220 
00222   void changeDisplayColor(BMAC_COLORS color);
00223 
00225   void sendDataPacket();
00226 
00228   void sendMacAck();
00229 
00231   void sendPreamble();
00232 
00234   void attachSignal(MacPkt *macPkt);
00235 
00237   bool addToQueue(cMessage * msg);
00238 };
00239 
00240 #endif /* BMACLAYER_H_ */