Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

mac-802_11.h

Go to the documentation of this file.
00001 /* -*-  Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*-
00002  *
00003  * Copyright (c) 1997 Regents of the University of California.
00004  * All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  * 1. Redistributions of source code must retain the above copyright
00010  *    notice, this list of conditions and the following disclaimer.
00011  * 2. Redistributions in binary form must reproduce the above copyright
00012  *    notice, this list of conditions and the following disclaimer in the
00013  *    documentation and/or other materials provided with the distribution.
00014  * 3. All advertising materials mentioning features or use of this software
00015  *    must display the following acknowledgement:
00016  *      This product includes software developed by the Computer Systems
00017  *      Engineering Group at Lawrence Berkeley Laboratory.
00018  * 4. Neither the name of the University nor of the Laboratory may be used
00019  *    to endorse or promote products derived from this software without
00020  *    specific prior written permission.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00023  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00024  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00025  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00026  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
00027  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00028  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00029  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00031  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00032  * SUCH DAMAGE.
00033  *
00034  * $Header: /nfs/jade/vint/CVSROOT/ns-2/mac/mac-802_11.h,v 1.20 2002/03/14 01:12:53 haldar Exp $
00035  *
00036  * Ported from CMU/Monarch's code, nov'98 -Padma.
00037  * wireless-mac-802_11.h
00038  */
00039 
00040 #ifndef ns_mac_80211_h
00041 #define ns_mac_80211_h
00042 
00043 #include "mac-timers.h"
00044 #include "marshall.h"
00045 
00046 #define GET_ETHER_TYPE(x)               GET2BYTE((x))
00047 #define SET_ETHER_TYPE(x,y)            {u_int16_t t = (y); STORE2BYTE(x,&t);}
00048 
00049 /* ======================================================================
00050    Frame Formats
00051    ====================================================================== */
00052 
00053 #define MAC_ProtocolVersion     0x00
00054 
00055 #define MAC_Type_Management     0x00
00056 #define MAC_Type_Control        0x01
00057 #define MAC_Type_Data           0x02
00058 #define MAC_Type_Reserved       0x03
00059 
00060 #define MAC_Subtype_RTS         0x0B
00061 #define MAC_Subtype_CTS         0x0C
00062 #define MAC_Subtype_ACK         0x0D
00063 #define MAC_Subtype_Data        0x00
00064 
00065 struct frame_control {
00066         u_char          fc_subtype              : 4;
00067         u_char          fc_type                 : 2;
00068         u_char          fc_protocol_version     : 2;
00069 
00070         u_char          fc_order                : 1;
00071         u_char          fc_wep                  : 1;
00072         u_char          fc_more_data            : 1;
00073         u_char          fc_pwr_mgt              : 1;
00074         u_char          fc_retry                : 1;
00075         u_char          fc_more_frag            : 1;
00076         u_char          fc_from_ds              : 1;
00077         u_char          fc_to_ds                : 1;
00078 };
00079 
00080 struct rts_frame {
00081         struct frame_control    rf_fc;
00082         u_int16_t               rf_duration;
00083         u_char                  rf_ra[ETHER_ADDR_LEN];
00084         u_char                  rf_ta[ETHER_ADDR_LEN];
00085         u_char                  rf_fcs[ETHER_FCS_LEN];
00086 };
00087 
00088 struct cts_frame {
00089         struct frame_control    cf_fc;
00090         u_int16_t               cf_duration;
00091         u_char                  cf_ra[ETHER_ADDR_LEN];
00092         u_char                  cf_fcs[ETHER_FCS_LEN];
00093 };
00094 
00095 struct ack_frame {
00096         struct frame_control    af_fc;
00097         u_int16_t               af_duration;
00098         u_char                  af_ra[ETHER_ADDR_LEN];
00099         u_char                  af_fcs[ETHER_FCS_LEN];
00100 };
00101 
00102 // XXX This header does not have its header access function because it shares
00103 // the same header space with hdr_mac.
00104 struct hdr_mac802_11 {
00105         struct frame_control    dh_fc;
00106         u_int16_t               dh_duration;
00107         u_char                  dh_da[ETHER_ADDR_LEN];
00108         u_char                  dh_sa[ETHER_ADDR_LEN];
00109         u_char                  dh_bssid[ETHER_ADDR_LEN];
00110         u_int16_t               dh_scontrol;
00111         u_char                  dh_body[0]; // XXX Non-ANSI
00112 };
00113 
00114 
00115 /* ======================================================================
00116    Definitions
00117    ====================================================================== */
00118 
00119 #define PLCP_HDR_LEN                            \
00120         ((phymib_->PreambleLength >> 3) +        \
00121          (phymib_->PLCPHeaderLength >> 3))
00122 
00123 #define ETHER_HDR_LEN11                         \
00124         (PLCP_HDR_LEN +                         \
00125          sizeof(struct hdr_mac802_11) +         \
00126          ETHER_FCS_LEN)
00127 
00128 #define ETHER_RTS_LEN                           \
00129         (PLCP_HDR_LEN +                         \
00130          sizeof(struct rts_frame))
00131 
00132 #define ETHER_CTS_LEN                           \
00133          (PLCP_HDR_LEN +                        \
00134          sizeof(struct cts_frame))
00135 
00136 #define ETHER_ACK_LEN                           \
00137          (PLCP_HDR_LEN +                        \
00138          sizeof(struct ack_frame))
00139 
00140 /*
00141  * IEEE 802.11 Spec, section 15.3.2
00142  *      - default values for the DSSS PHY MIB
00143  */
00144 #define DSSS_CWMin                      31
00145 #define DSSS_CWMax                      1023
00146 #define DSSS_SlotTime                   0.000020        // 20us
00147 #define DSSS_CCATime                    0.000015        // 15us
00148 #define DSSS_RxTxTurnaroundTime         0.000005        // 5us
00149 #define DSSS_SIFSTime                   0.000010        // 10us
00150 #define DSSS_PreambleLength             144             // 144 bits
00151 #define DSSS_PLCPHeaderLength           48              // 48 bits
00152 #define DSSS_PLCPDataRate               1.0e6           // 1Mbps
00153 
00154 /* Must account for propagation delays added by the channel model when
00155  * calculating tx timeouts (as set in tcl/lan/ns-mac.tcl).
00156  *   -- Gavin Holland, March 2002
00157  */
00158 #define DSSS_MaxPropagationDelay        0.000002        // 2us   XXXX
00159 
00160 class PHY_MIB {
00161 public:
00162         u_int32_t       CWMin;
00163         u_int32_t       CWMax;
00164         double          SlotTime;
00165         double          CCATime;
00166         double          RxTxTurnaroundTime;
00167         double          SIFSTime;
00168         u_int32_t       PreambleLength;
00169         u_int32_t       PLCPHeaderLength;
00170         double          PLCPDataRate;
00171 };
00172 
00173 
00174 /*
00175  * IEEE 802.11 Spec, section 11.4.4.2
00176  *      - default values for the MAC Attributes
00177  */
00178 //#define MAC_RTSThreshold              3000            // bytes
00179 #define MAC_RTSThreshold                0               // bytes
00180 #define MAC_ShortRetryLimit             7               // retransmittions
00181 #define MAC_LongRetryLimit              4               // retransmissions
00182 #define MAC_FragmentationThreshold      2346            // bytes
00183 #define MAC_MaxTransmitMSDULifetime     512             // time units
00184 #define MAC_MaxReceiveLifetime          512             // time units
00185 
00186 class MAC_MIB {
00187 public:
00188         //              MACAddress;
00189         //              GroupAddresses;
00190         u_int32_t       RTSThreshold;
00191         u_int32_t       ShortRetryLimit;
00192         u_int32_t       LongRetryLimit;
00193         u_int32_t       FragmentationThreshold;
00194         u_int32_t       MaxTransmitMSDULifetime;
00195         u_int32_t       MaxReceiveLifetime;
00196         //              ManufacturerID;
00197         //              ProductID;
00198 
00199         u_int32_t       TransmittedFragmentCount;
00200         u_int32_t       MulticastTransmittedFrameCount;
00201         u_int32_t       FailedCount;    
00202         u_int32_t       RetryCount;
00203         u_int32_t       MultipleRetryCount;
00204         u_int32_t       FrameDuplicateCount;
00205         u_int32_t       RTSSuccessCount;
00206         u_int32_t       RTSFailureCount;
00207         u_int32_t       ACKFailureCount;
00208         u_int32_t       ReceivedFragmentCount;
00209         u_int32_t       MulticastReceivedFrameCount;
00210         u_int32_t       FCSErrorCount;
00211 };
00212 
00213 
00214 /* ======================================================================
00215    The following destination class is used for duplicate detection.
00216    ====================================================================== */
00217 class Host {
00218 public:
00219         LIST_ENTRY(Host) link;
00220         u_int32_t       index;
00221         u_int32_t       seqno;
00222 };
00223 
00224 
00225 /* ======================================================================
00226    The actual 802.11 MAC class.
00227    ====================================================================== */
00228 class Mac802_11 : public Mac {
00229         friend class DeferTimer;
00230         friend class BackoffTimer;
00231         friend class IFTimer;
00232         friend class NavTimer;
00233         friend class RxTimer;
00234         friend class TxTimer;
00235 public:
00236         Mac802_11(PHY_MIB* p, MAC_MIB *m);
00237         void            recv(Packet *p, Handler *h);
00238         inline int      hdr_dst(char* hdr, int dst = -2);
00239         inline int      hdr_src(char* hdr, int src = -2);
00240         inline int      hdr_type(char* hdr, u_int16_t type = 0);
00241 
00242 protected:
00243         void    backoffHandler(void);
00244         void    deferHandler(void);
00245         void    navHandler(void);
00246         void    recvHandler(void);
00247         void    sendHandler(void);
00248         void    txHandler(void);
00249 
00250 private:
00251         int             command(int argc, const char*const* argv);
00252 
00253         /*
00254          * Called by the timers.
00255          */
00256         void            recv_timer(void);
00257         void            send_timer(void);
00258         int             check_pktCTRL();
00259         int             check_pktRTS();
00260         int             check_pktTx();
00261 
00262         /*
00263          * Packet Transmission Functions.
00264          */
00265         void    send(Packet *p, Handler *h);
00266         void    sendRTS(int dst);
00267         void    sendCTS(int dst, double duration);
00268         void    sendACK(int dst);
00269         void    sendDATA(Packet *p);
00270         void    RetransmitRTS();
00271         void    RetransmitDATA();
00272 
00273         /*
00274          * Packet Reception Functions.
00275          */
00276         void    recvRTS(Packet *p);
00277         void    recvCTS(Packet *p);
00278         void    recvACK(Packet *p);
00279         void    recvDATA(Packet *p);
00280 
00281         void            capture(Packet *p);
00282         void            collision(Packet *p);
00283         void            discard(Packet *p, const char* why);
00284         void            rx_resume(void);
00285         void            tx_resume(void);
00286 
00287         inline int      is_idle(void);
00288 
00289         /*
00290          * Debugging Functions.
00291          */
00292         void            trace_pkt(Packet *p);
00293         void            dump(char* fname);
00294 
00295         inline int initialized() {
00296                 return (phymib_ && macmib_ && cache_ && logtarget_ && 
00297                         Mac::initialized());
00298         }
00299         void mac_log(Packet *p) {
00300                 logtarget_->recv(p, (Handler*) 0);
00301         }
00302         double txtime(Packet *p);
00303         double txtime(double psz, double drt);
00304         double txtime(int bytes) { /* clobber inherited txtime() */ abort(); }
00305 
00306         inline void inc_cw() {
00307                 cw_ = (cw_ << 1) + 1;
00308                 if(cw_ > phymib_->CWMax)
00309                         cw_ = phymib_->CWMax;
00310         }
00311         inline void rst_cw() { cw_ = phymib_->CWMin; }
00312         inline double sec(double t) { return(t *= 1.0e-6); }
00313         inline u_int16_t usec(double t) {
00314                 u_int16_t us = (u_int16_t)floor((t *= 1e6) + 0.5);
00315                 /* u_int16_t us = (u_int16_t)rint(t *= 1e6); */
00316                 return us;
00317         }
00318         inline void set_nav(u_int16_t us) {
00319                 double now = Scheduler::instance().clock();
00320                 double t = us * 1e-6;
00321 
00322                 if((now + t) > nav_) {
00323                         nav_ = now + t;
00324                         if(mhNav_.busy())
00325                                 mhNav_.stop();
00326                         mhNav_.start(t);
00327                 }
00328         }
00329 
00330 protected:
00331         PHY_MIB         *phymib_;
00332         MAC_MIB         *macmib_;
00333 
00334 private:
00335         double          basicRate_;
00336         double          dataRate_;
00337         
00338         /*
00339          * Mac Timers
00340          */
00341         IFTimer         mhIF_;          // interface timer
00342         NavTimer        mhNav_;         // NAV timer
00343         RxTimer         mhRecv_;                // incoming packets
00344         TxTimer         mhSend_;                // outgoing packets
00345 
00346         DeferTimer      mhDefer_;       // defer timer
00347         BackoffTimer    mhBackoff_;     // backoff timer
00348 
00349         /* ============================================================
00350            Internal MAC State
00351            ============================================================ */
00352         double          nav_;           // Network Allocation Vector
00353 
00354         MacState        rx_state_;      // incoming state (MAC_RECV or MAC_IDLE)
00355         MacState        tx_state_;      // outgoint state
00356         int             tx_active_;     // transmitter is ACTIVE
00357 
00358         Packet          *pktRTS_;       // outgoing RTS packet
00359         Packet          *pktCTRL_;      // outgoing non-RTS packet
00360 
00361         u_int32_t       cw_;            // Contention Window
00362         u_int32_t       ssrc_;          // STA Short Retry Count
00363         u_int32_t       slrc_;          // STA Long Retry Count
00364         double          sifs_;          // Short Interface Space
00365         double          pifs_;          // PCF Interframe Space
00366         double          difs_;          // DCF Interframe Space
00367         double          eifs_;          // Extended Interframe Space
00368         double          tx_sifs_;
00369         double          tx_pifs_;
00370         double          tx_difs_;
00371 
00372         int             min_frame_len_;
00373 
00374         NsObject*       logtarget_;
00375 
00376         /* ============================================================
00377            Duplicate Detection state
00378            ============================================================ */
00379         u_int16_t       sta_seqno_;     // next seqno that I'll use
00380         int             cache_node_count_;
00381         Host            *cache_;
00382 };
00383 
00384 #endif /* __mac_80211_h__ */
00385 

Generated on Tue Apr 20 12:14:23 2004 for NS2.26SourcesOriginal by doxygen 1.3.3