📄 mac-802_11.h
字号:
/* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- * * Copyright (c) 1997 Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the Computer Systems * Engineering Group at Lawrence Berkeley Laboratory. * 4. Neither the name of the University nor of the Laboratory may be used * to endorse or promote products derived from this software without * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $Header: /cvsroot/nsnam/ns-2/mac/mac-802_11.h,v 1.27 2006/02/22 13:25:43 mahrenho Exp $ * * Ported from CMU/Monarch's code, nov'98 -Padma. * wireless-mac-802_11.h */#ifndef ns_mac_80211_h#define ns_mac_80211_h// Added by Sushmita to support event tracing (singal@nunki.usc.edu)#include "address.h"#include "ip.h"#include "mac-timers.h"#include "marshall.h"#include <math.h>#include <stddef.h>class EventTrace;#define GET_ETHER_TYPE(x) GET2BYTE((x))#define SET_ETHER_TYPE(x,y) {u_int16_t t = (y); STORE2BYTE(x,&t);}/* ====================================================================== Frame Formats ====================================================================== */#define MAC_ProtocolVersion 0x00#define MAC_Type_Management 0x00#define MAC_Type_Control 0x01#define MAC_Type_Data 0x02#define MAC_Type_Reserved 0x03#define MAC_Subtype_RTS 0x0B#define MAC_Subtype_CTS 0x0C#define MAC_Subtype_ACK 0x0D#define MAC_Subtype_Data 0x00struct frame_control { u_char fc_subtype : 4; u_char fc_type : 2; u_char fc_protocol_version : 2; u_char fc_order : 1; u_char fc_wep : 1; u_char fc_more_data : 1; u_char fc_pwr_mgt : 1; u_char fc_retry : 1; u_char fc_more_frag : 1; u_char fc_from_ds : 1; u_char fc_to_ds : 1;};struct rts_frame { struct frame_control rf_fc; u_int16_t rf_duration; u_char rf_ra[ETHER_ADDR_LEN]; u_char rf_ta[ETHER_ADDR_LEN]; u_char rf_fcs[ETHER_FCS_LEN];};struct cts_frame { struct frame_control cf_fc; u_int16_t cf_duration; u_char cf_ra[ETHER_ADDR_LEN]; u_char cf_fcs[ETHER_FCS_LEN];};struct ack_frame { struct frame_control af_fc; u_int16_t af_duration; u_char af_ra[ETHER_ADDR_LEN]; u_char af_fcs[ETHER_FCS_LEN];};// XXX This header does not have its header access function because it shares// the same header space with hdr_mac.struct hdr_mac802_11 { struct frame_control dh_fc; u_int16_t dh_duration; u_char dh_ra[ETHER_ADDR_LEN]; u_char dh_ta[ETHER_ADDR_LEN]; u_char dh_3a[ETHER_ADDR_LEN]; u_int16_t dh_scontrol; u_char dh_body[1]; // size of 1 for ANSI compatibility};// VIVEK_ARF// ARF Algorithm details obtained from//// ftp://ftp.inria.fr/INRIA/publication/publi-pdf/RR/RR-5208.pdf//// IEEE 802.11 Rate Adaptation: A Practical Approach// Mathieu Lacage, Hossein Manshaei, Thierry Turletti//// Description of ARF on pg 4.//// Specifically, the original ARF algorithm decreases the current// rate and starts a timer when two consecutive transmissions fail in a row. When either the// timer expires or the number of successfully received per-packet acknowledgements reaches// 10, the transmission rate is increased to a higher data rate and the timer is reset. When the// rate is increased, the first transmission after the rate increase (commonly referred to as the// probing transmission or probing packet) must succeed or the rate is immediately decreased// and the timer is restarted rather than trying the higher rate a second time.// DATA Structures used for ARF://// The following entry is maintained by a node for each of its// neighbors. Each entry contains information about the current rate// (and req SINR of that rate) used to comm. with that nhbr node.// It also contains additional info for ARF algostruct ARF_info { int MAC_ID; // MAC Address of this node int rate_index; // Index in a look up table of rate and SINR int num_success;// No. of consecutive successful tx int num_failed ;// No. of consecutive lost tx int timer; // Timer: Total pkts (succ/fail) after which to incr rate int probing_tx; // Next tx is a probe int algorithm; // ARF or AARF int success_thresh;//AARF: Dynamic threshold on num_success};#define dBtomW(x) pow(10.0,((x)/10.0)) //dB to mW#define mWtodB(x) 10.0*log10((x)) //mW to dB#define ARF_TIMEOUT 15 // rate increase after timeout#define ARF_SUCCESS_THRESHOLD 10 // rate increase after 10 pkt tx sccssfly#define ARF_FAILURE_THRESHOLD 2 // rate decrease after 2 pkts lost#define NUM_DISCRETE_RATES 8 // 8 discrete data rates of 802.11a/g#define MAX_AARF_SUCCESS_THRESHOLD 50// AARF: Dynamic threshold cannot be above this#define AUTO_RATE_NONE 0#define AUTO_RATE_ARF 1#define AUTO_RATE_AARF 2// VIVEK CUMULATIVE INTERFERENCE MODULE#define MAXNHBR 40#define CPTHRESH_BASIC dBtomW(6.02) // 11a/g#define DATA_RATE_DEFAULT 6000000.0 // 11a/g#define DEFAULT_NOISE_POWER -120.0 // -90dBm// VIVEK CUMULATIVE INTERFERENCE MODULE// VIVEK_ARF/* ====================================================================== Definitions ====================================================================== *//* Must account for propagation delays added by the channel model when * calculating tx timeouts (as set in tcl/lan/ns-mac.tcl). * -- Gavin Holland, March 2002 */#define DSSS_MaxPropagationDelay 0.000004 // 2us XXXX// #define DSSS_MaxPropagationDelay 0.000002 // 2us XXXX// VIVEK_NEW// With shadowing, sometimes nodes that are very// far apart can still communicate.. Set this to be large enough.// 2us corresponds to 600m. To be safe, set it to 4us.class PHY_MIB {public: PHY_MIB(Mac802_11 *parent); inline u_int32_t getCWMin() { return(CWMin); } inline u_int32_t getCWMax() { return(CWMax); } inline double getSlotTime() { return(SlotTime); } inline double getSIFS() { return(SIFSTime); } inline double getPIFS() { return(SIFSTime + SlotTime); } inline double getDIFS() { return(SIFSTime + 2 * SlotTime); } inline double getEIFS() { // see (802.11-1999, 9.2.10) return(SIFSTime + getDIFS() + (8 * getACKlen())/PLCPDataRate); } inline u_int32_t getPreambleLength() { return(PreambleLength); } inline double getPLCPDataRate() { return(PLCPDataRate); } inline u_int32_t getPLCPhdrLen() { return((PreambleLength + PLCPHeaderLength) >> 3); } inline u_int32_t getHdrLen11() { return(getPLCPhdrLen() + offsetof(struct hdr_mac802_11, dh_body[0]) + ETHER_FCS_LEN); } inline u_int32_t getRTSlen() { return(getPLCPhdrLen() + sizeof(struct rts_frame)); } inline u_int32_t getCTSlen() { return(getPLCPhdrLen() + sizeof(struct cts_frame)); } inline u_int32_t getACKlen() { return(getPLCPhdrLen() + sizeof(struct ack_frame)); } private: u_int32_t CWMin; u_int32_t CWMax; double SlotTime; double SIFSTime; u_int32_t PreambleLength; u_int32_t PLCPHeaderLength; double PLCPDataRate;};/* * IEEE 802.11 Spec, section 11.4.4.2 * - default values for the MAC Attributes */#define MAC_FragmentationThreshold 2346 // bytes#define MAC_MaxTransmitMSDULifetime 512 // time units#define MAC_MaxReceiveLifetime 512 // time unitsclass MAC_MIB {public: MAC_MIB(Mac802_11 *parent);private: u_int32_t RTSThreshold; u_int32_t ShortRetryLimit; u_int32_t LongRetryLimit;public: u_int32_t FailedCount; u_int32_t RTSFailureCount; u_int32_t ACKFailureCount; public: inline u_int32_t getRTSThreshold() { return(RTSThreshold);} inline u_int32_t getShortRetryLimit() { return(ShortRetryLimit);} inline u_int32_t getLongRetryLimit() { return(LongRetryLimit);}};/* ====================================================================== The following destination class is used for duplicate detection. ====================================================================== */class Host {public: LIST_ENTRY(Host) link; u_int32_t index; u_int32_t seqno;};/* ====================================================================== The actual 802.11 MAC class. ====================================================================== */class Mac802_11 : public Mac { friend class DeferTimer; friend class BackoffTimer; friend class IFTimer; friend class NavTimer; friend class RxTimer; friend class TxTimer;public: Mac802_11(); void recv(Packet *p, Handler *h); inline int hdr_dst(char* hdr, int dst = -2); inline int hdr_src(char* hdr, int src = -2); inline int hdr_type(char* hdr, u_int16_t type = 0); inline int bss_id() { return bss_id_; } // Added by Sushmita to support event tracing void trace_event(char *, Packet *); EventTrace *et_;protected: void backoffHandler(void); void deferHandler(void); void navHandler(void); void recvHandler(void); void sendHandler(void); void txHandler(void);private: int command(int argc, const char*const* argv); /* In support of bug fix described at * http://www.dei.unipd.it/wdyn/?IDsezione=2435 */ int bugFix_timer_; /* * Called by the timers. */ void recv_timer(void); void send_timer(void); int check_pktCTRL(); int check_pktRTS(); int check_pktTx(); /* * Packet Transmission Functions. */ void send(Packet *p, Handler *h); void sendRTS(int dst); void sendCTS(int dst, double duration); void sendACK(int dst); void sendDATA(Packet *p); void RetransmitRTS(); void RetransmitDATA(); /* * Packet Reception Functions. */ void recvRTS(Packet *p); void recvCTS(Packet *p); void recvACK(Packet *p); void recvDATA(Packet *p); void capture(Packet *p); void collision(Packet *p); void discard(Packet *p, const char* why); void rx_resume(void); void tx_resume(void); inline int is_idle(void); // VIVEK_ARF void ARF_success(int index); void ARF_timer_expired(int index); void ARF_decr_rate(int index); int ARF_find_index(u_char* macaddr); void ARF_update_txtime(Packet *p, int index); /* * Debugging Functions. */ void trace_pkt(Packet *p); void dump(char* fname); inline int initialized() { return (cache_ && logtarget_ && Mac::initialized()); } inline void mac_log(Packet *p) { logtarget_->recv(p, (Handler*) 0); } double txtime(Packet *p); double txtime(double psz, double drt); double txtime(int bytes) { /* clobber inherited txtime() */ abort(); return 0;} inline void transmit(Packet *p, double timeout); inline void checkBackoffTimer(void); inline void postBackoff(int pri); inline void setRxState(MacState newState); inline void setTxState(MacState newState); inline void inc_cw() { cw_ = (cw_ << 1) + 1; if(cw_ > phymib_.getCWMax()) cw_ = phymib_.getCWMax(); } inline void rst_cw() { cw_ = phymib_.getCWMin(); } inline double sec(double t) { return(t *= 1.0e-6); } inline u_int16_t usec(double t) { u_int16_t us = (u_int16_t)floor((t *= 1e6) + 0.5); return us; } inline void set_nav(u_int16_t us) { double now = Scheduler::instance().clock(); double t = us * 1e-6; if((now + t) > nav_) { nav_ = now + t; if(mhNav_.busy()) mhNav_.stop(); mhNav_.start(t); } }protected: PHY_MIB phymib_; MAC_MIB macmib_; /* the macaddr of my AP in BSS mode; for IBSS mode * this is set to a reserved value IBSS_ID - the * MAC_BROADCAST reserved value can be used for this * purpose */ int bss_id_; enum {IBSS_ID=MAC_BROADCAST};private: double basicRate_; double dataRate_;// VIVEK MULTI-RATE, MULTI-SINR MODULE// int IdNhbr_[MAXNHBR];// double dataRateNhbr_[MAXNHBR];// double CPThreshNhbr_[MAXNHBR]; int counter_; double noise_;// VIVEK MULTI-RATE, MULTI-SINR MODULE// VIVEK_ARF struct ARF_info ARF_Entry[MAXNHBR];// VIVEK_ARF /* * Mac Timers */ IFTimer mhIF_; // interface timer NavTimer mhNav_; // NAV timer RxTimer mhRecv_; // incoming packets TxTimer mhSend_; // outgoing packets DeferTimer mhDefer_; // defer timer BackoffTimer mhBackoff_; // backoff timer /* ============================================================ Internal MAC State ============================================================ */ double nav_; // Network Allocation Vector MacState rx_state_; // incoming state (MAC_RECV or MAC_IDLE) MacState tx_state_; // outgoint state int tx_active_; // transmitter is ACTIVE Packet *eotPacket_; // copy for eot callback Packet *pktRTS_; // outgoing RTS packet Packet *pktCTRL_; // outgoing non-RTS packet u_int32_t cw_; // Contention Window u_int32_t ssrc_; // STA Short Retry Count u_int32_t slrc_; // STA Long Retry Count int min_frame_len_; NsObject* logtarget_; NsObject* EOTtarget_; // given a copy of packet at TX end /* ============================================================ Duplicate Detection state ============================================================ */ u_int16_t sta_seqno_; // next seqno that I'll use int cache_node_count_; Host *cache_;};#endif /* __mac_80211_h__ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -