LMacLayer.h

00001 /*
00002  *  LMACLayer.cc
00003  *  LMAC for MF 2.02, omnetpp 3.4
00004  *
00005  *  Created by Anna Förster on 10/10/08.
00006  *  Copyright 2008 Universita della Svizzera Italiana. All rights reserved.
00007  *
00008  *  Converted to MiXiM by Kapourniotis Theodoros
00009  *
00010  */
00011 
00012 #ifndef LMAC_LAYER_H
00013 #define LMAC_LAYER_H
00014 
00015 #include <list>
00016 #include <DroppedPacket.h>
00017 #include <BaseMacLayer.h>
00018 #include <Blackboard.h>
00019 #include "LMacPkt_m.h"
00020 #include <SimpleAddress.h>
00021 
00022 #include "MacToPhyControlInfo.h"
00023 #include <BaseArp.h>
00024 #include <BaseConnectionManager.h>
00025 #include <NetwToMacControlInfo.h>
00026 
00027 
00066 class  LMacLayer : public BaseMacLayer
00067 {
00068   public:
00070   virtual ~LMacLayer();
00071 
00073     virtual void initialize(int);
00074 
00076     virtual void finish();
00077 
00079     virtual void handleLowerMsg(cMessage*);
00080 
00082     virtual void handleUpperMsg(cMessage*);
00083 
00085     virtual void handleSelfMsg(cMessage*);
00086 
00088     virtual void handleLowerControl(cMessage *msg);
00089 
00091     virtual MacPkt* encapsMsg(cMessage*);
00092   
00093 
00094   protected:
00095     typedef std::list<LMacPkt*> MacQueue;
00096     
00109     enum States {
00110       INIT,
00111     SLEEP,
00112         CCA,
00113         WAIT_CONTROL,
00114         WAIT_DATA,
00115         SEND_CONTROL,
00116         SEND_DATA
00117     };
00118   
00119   enum TYPES {
00120     LMAC_CONTROL=167,
00121     LMAC_TIMEOUT=168,
00122     LMAC_WAKEUP=169,
00123     LMAC_SEND_DATA=170,
00124     LMAC_SETUP_PHASE_END=171,
00125     LMAC_CHECK_CHANNEL=172,
00126     LMAC_SOMEBODY=173,
00127     LMAC_DATA=174,
00128     LMAC_START_LMAC=175,
00129     LMAC_SEND_CONTROL=176
00130   };
00131   
00133   static const int LMAC_NO_RECEIVER;
00134   
00136   bool SETUP_PHASE;
00137   
00139   cOutVector* slotChange;
00140   
00142     States macState;
00143     
00145     Radio::RadioState radioState;
00146   
00148     int catRadioState;
00149   
00151     int catIndication;
00152 
00153 
00155     double slotDuration;
00157   double controlDuration;
00159   int mySlot;
00161   int numSlots;
00163   int currSlot;
00165   short occSlotsDirect[64];
00167   short occSlotsAway[64];
00169   int reservedMobileSlots;
00170 
00171     
00174     MacQueue macQueue;
00175     
00177     unsigned queueLength;
00178     
00179   cMessage* wakeup;
00180   cMessage* timeout;
00181   cMessage* sendData;
00182   cMessage* initChecker;
00183   cMessage* checkChannel;
00184   cMessage* start_lmac;
00185   cMessage* send_control;
00186     
00188     double bitrate;
00189 
00191   void findNewSlot();
00192   
00194     DroppedPacket droppedPacket;
00195     
00197     int catDroppedPacket;
00198     
00200     int nicId;
00201     
00203   void attachSignal(MacPkt *macPkt);
00204 
00206   double txPower;
00207 
00208 
00209 };
00210 
00211 #endif
00212