• Main Page
  • Classes
  • Files
  • File List

/Users/yzchen/ns/ns-allinone-2.33/ns-2.33/mac/mac-802_3.h

00001 #ifndef __mac_802_3_h__
00002 #define __mac_802_3_h__
00003 
00004 #include <assert.h>
00005 #include "mac.h"
00006 
00007 #define min(x, y)       ((x) < (y) ? (x) : (y))
00008 #define ETHER_HDR_LEN           ((ETHER_ADDR_LEN << 1) + ETHER_TYPE_LEN)
00009 
00010 /*
00011  10Mbps:
00012 #define IEEE_8023_SLOT          0.000051200     // 512 bit times
00013 #define IEEE_8023_IFS           0.000009600     // 9.6us interframe spacing
00014  100Mbps:
00015 #define IEEE_8023_SLOT                0.0000051200    //512 bit time
00016 #define IEEE_8023_IFS                 0.0000009600    //0.96us interframe spacing
00017 */
00018 #define IEEE_8023_SLOT_BITS             512.0 //when we divide these by the bandwidth
00019 #define IEEE_8023_IFS_BITS               96.0 //we'll have what we want
00020 
00021 #define IEEE_8023_ALIMIT        16              // attempt limit
00022 #define IEEE_8023_BLIMIT        10              // backoff limit
00023 #define IEEE_8023_JAMSIZE       32              // bits
00024 #define IEEE_8023_MAXFRAME      1518            // bytes
00025 #define IEEE_8023_MINFRAME      64              // bytes
00026 #define INVALID_UID             -1              // Used for mac level traces
00027 #define INVALID_TIME            -1
00028 
00029 /* ======================================================================
00030    Handler Functions
00031    ====================================================================== */
00032 class Mac802_3;
00033 
00034 class MacHandler : public Handler {
00035 public:
00036         MacHandler(Mac802_3* m) :  callback(0), mac(m), busy_(false) {}
00037         virtual void handle(Event *e) = 0;
00038         virtual inline void cancel();
00039         bool busy(void) { return busy_; }
00040         double expire(void) { return intr.time_; }
00041 protected:
00042         Handler         *callback;
00043         Mac802_3        *mac;
00044         Event           intr;
00045         bool            busy_;
00046 };
00047 
00048 
00049 class Mac8023HandlerSend : public MacHandler {
00050  public:
00051         Mac8023HandlerSend(Mac802_3* m) : MacHandler(m), p_(0) {}
00052         void handle(Event*);
00053         void schedule(const Packet *p, double t);
00054         void cancel();
00055         const Packet *packet() const { return p_; }
00056  protected:
00057         const Packet *p_;
00058 };
00059 
00060 class MacHandlerRecv : public MacHandler {
00061 public:
00062         MacHandlerRecv(Mac802_3* m) : MacHandler(m), p_(0) {}
00063         void handle(Event*);
00064         void schedule(Packet *p, double t);
00065         virtual void cancel();
00066 private:
00067         Packet *p_;
00068 };
00069 
00070 class MacHandlerRetx : public MacHandler {
00071  public:
00072         MacHandlerRetx(Mac802_3* m) : MacHandler(m), p_(0), try_(1) {}
00073         void reset() {
00074                 // before calling reset, you MUST free or drop p_
00075                 if (busy_) cancel();
00076                 try_= 1;
00077                 p_= 0;
00078         }
00079         void handle(Event*);
00080         bool schedule(double delta=0.0);
00081         void cancel();
00082         void free() { 
00083                 if (p_) {
00084                         Packet::free(p_);
00085                         p_= 0;
00086                 }
00087         }
00088         Packet* packet() const { return p_; }
00089         void packet(Packet *p) { p_= p; }
00090 private:
00091         Packet *p_;
00092         int try_;
00093 };
00094                 
00095 class MacHandlerIFS : public MacHandler {
00096  public:
00097         MacHandlerIFS(Mac802_3* m) : MacHandler(m) {}
00098         void handle (Event*); 
00099         void schedule(double t);
00100         void cancel();
00101 };
00102 
00103 
00104 /* ======================================================================
00105    MAC data structure
00106    ====================================================================== */
00107 class Mac802_3 : public Mac {
00108         friend class MacHandler;
00109         friend class MacHandlerRecv;
00110         friend class Mac8023HandlerSend;
00111         friend class MacHandlerRetx;
00112         friend class MacHandlerIFS;
00113  public:
00114         Mac802_3();
00115 
00116         void recv(Packet* p, Handler* h) {
00117                 BiConnector::recv(p, h);
00118         }
00119 
00120  protected:
00121         void sendDown(Packet* p, Handler* h);
00122         void sendUp(Packet* p, Handler* h);
00123         /*
00124         inline int      hdr_dst(char* hdr, u_int32_t dst = -2);
00125         inline int      hdr_src(char* hdr, u_int32_t src = -2);
00126         inline int      hdr_type(char* hdr, u_int16_t type = 0);
00127         */
00128         
00129         void            recv_complete(Packet *p);
00130         virtual void    resume();
00131 
00132         //protected:
00133         virtual void    transmit(Packet* p);
00134         int trace_;      // To turn on MAC level collision traces 
00135 private:
00136         //void          send(Packet *p, Handler *h);
00137         void            collision(Packet *p);
00138 
00139         //int           pktTxcnt;
00140 
00141         MacHandlerRecv  mhRecv_;
00142         MacHandlerRetx  mhRetx_;
00143         MacHandlerIFS   mhIFS_;
00144         Mac8023HandlerSend      mhSend_;
00145         
00146 };
00147 
00148 
00149 #endif /* __mac_802_3_h__ */

Generated on Tue Aug 10 2010 16:16:07 for ns-2.33 by  doxygen 1.7.1