mmac-csma.h

Go to the documentation of this file.
00001 /* -*- Mode:C++ -*- */
00002 
00003 /*
00004  * Copyright (c) 2008 Regents of the SIGNET lab, University of Padova.
00005  * All rights reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions
00009  * are met:
00010  * 1. Redistributions of source code must retain the above copyright
00011  *    notice, this list of conditions and the following disclaimer.
00012  * 2. Redistributions in binary form must reproduce the above copyright
00013  *    notice, this list of conditions and the following disclaimer in the
00014  *    documentation and/or other materials provided with the distribution.
00015  * 3. Neither the name of the University of Padova (SIGNET lab) nor the 
00016  *    names of its contributors may be used to endorse or promote products 
00017  *    derived from this software without specific prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
00020  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 
00021  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
00022  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 
00023  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
00024  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
00025  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
00026  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
00027  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
00028  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
00029  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00030  */
00031 
00032 
00044 #ifndef MMAC_CSMA_H 
00045 #define MMAC_CSMA_H
00046 
00047 #include<module.h>
00048 #include<mmac.h>
00049 #include<timer-handler.h>
00050 #include<queue>
00051 
00052 
00053 
00054 extern packet_t PT_MMAC_ACK;
00055 
00056 class MMacCsma;
00057 
00058 enum TIMER_STATUS{
00059   STATUS_STOPPED = 1,
00060   STATUS_RUNNING,
00061   STATUS_FROZEN
00062 };
00063 
00064 
00065 class Backoff_Timer : public TimerHandler
00066 {
00067 public:
00068   Backoff_Timer(MMacCsma *m);
00069   void start(double duration);
00070   void freeze();
00071   void defrost();
00072   bool isFrozen();
00073   
00074 protected:
00075   virtual void expire(Event *e);
00076   MMacCsma* mac;
00077   enum TIMER_STATUS status;
00078   double start_time;
00079   double left_duration;
00080 };
00081 
00082 class Ack_Timer : public TimerHandler
00083 {
00084 public:
00085   Ack_Timer(MMacCsma *m);
00086   void start(double duration);
00087   void stop();
00088   bool isExpired();
00089         
00090 protected:
00091   virtual void expire(Event *e);
00092   MMacCsma* mac;
00093   enum TIMER_STATUS status;
00094 };
00095 
00096 
00097 
00098 
00099 enum MMAC_CSMA_STATE {
00100   STATE_IDLE = 0,
00101   STATE_RX_DATA,
00102   STATE_TX_ACK,
00103   STATE_CHK_PENDING_PKT,
00104   STATE_CHK_FROZEN_BACKOFF,
00105   STATE_BACKOFF,
00106   STATE_FREEZE_BACKOFF,
00107   STATE_TX_DATA,
00108   STATE_START_ACK_TIMEOUT,
00109   STATE_WAIT_ACK,
00110   STATE_RX_ACK,
00111   STATE_CHK_ACK_TIMEOUT_EXPIRED,
00112   STATE_TX_SUCCESSFUL,
00113   STATE_TX_FAILED,
00114   NUM_MMAC_CSMA_STATES
00115 };
00116 
00117 
00118 class MMacCsma : public MMac
00119 {
00120 public: 
00121   MMacCsma();
00122   
00123 protected:
00124 
00125   // events
00126   virtual void recvFromUpperLayers(Packet* p);
00127   virtual void Phy2MacEndTx(const Packet* p);
00128   virtual void Phy2MacStartRx(const Packet* p);
00129   virtual void Phy2MacEndRx(Packet* p);
00130   virtual void recvData4Me(Packet* p);
00131   virtual void recvAck4Me(Packet* p);
00132   virtual void recvWhateverElse(Packet* p);
00133 
00134 public:
00135   virtual void AckTimeout();
00136   virtual void BackoffEnded();
00137 
00138 protected:
00139 
00140   // actions to be performed when entering a given state
00141 
00142   virtual void enterState_IDLE();
00143   virtual void enterState_RX_DATA();
00144   virtual void enterState_TX_ACK(int macSA_of_data_pkt);
00145   virtual void enterState_CHK_PENDING_PKT();
00146   virtual void enterState_CHK_FROZEN_BACKOFF();
00147   virtual void enterState_BACKOFF();
00148   virtual void enterState_FREEZE_BACKOFF();
00149   virtual void enterState_TX_DATA();
00150   virtual void enterState_START_ACK_TIMEOUT();
00151   virtual void enterState_WAIT_ACK();
00152   virtual void enterState_RX_ACK();
00153   virtual void enterState_CHK_ACK_TIMEOUT_EXPIRED();
00154   virtual void enterState_TX_SUCCESSFUL();
00155   virtual void enterState_TX_FAILED();
00156 
00157   void setState(enum MMAC_CSMA_STATE s);
00158 
00159   enum MMAC_CSMA_STATE state;
00160 
00161 
00162   // status info to be kept across different states -- we try to have
00163   // as few of these variables as possible, since they complicate the
00164   // design of the protocol
00165   bool PendingPacket();
00166   bool FrozenBackoff();
00167   bool AckTimeoutExpired();
00168   const Packet* PktRx;
00169   Packet* PktTx;
00170   std::queue<Packet*> Q;   
00171   int ConsecutiveFailedTxAttempts;
00172   
00173   // timers
00174   Backoff_Timer backoff_timer;
00175   Ack_Timer ack_timer;
00176 
00177   // other stuff  
00178   int HeaderSize_; 
00179   double BaseBackoffTime_;
00180   double AckTimeout_;
00181 
00182   int debug_states_;
00183 
00184   static int uidcnt;
00185 
00186 };
00187 
00188 
00189 
00190 
00191 #endif /* MMAC_CSMA_H */

Generated on Wed Nov 26 15:47:28 2008 for NS-MIRACLE library by  doxygen 1.5.2