?? mac-802_11.cc~
字號:
/* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- * * EDCF/HCF module extension for ns-2.1b9a * Referred to P802_11E-D4_0.doc * By Antonio Annese - antonio1979[at]libero.it * * G.Boggia, P.Camarda, A.Grieco, S.Mascolo * Dipartimento di Elettrotecnica ed Elettronica, Politecnico di Bari * Via Orabona,4 - 70125 BARI, Italy * July, 2003 * Copyright (c) 2003 Politecnico di Bari, Italy. * All rights reserved. * * ParaQ module extension for ns-2.1b9 * by Fabio A. Favia [faz(at)lugbari.org] * July, 2004 * * Copyright (c) 2004 Politecnico di Bari, Italy. * 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 and binary code must contain * the above copyright notice, this list of conditions and the following * disclaimer. * * 2. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed at Politecnico di Bari, Italy * * 3. The name of the University may not be used to endorse or promote * products derived from this software without specific prior written * permission. * POLITECNICO DI BARI, ITALY, MAKES NO REPRESENTATIONS * CONCERNING EITHER THE MERCHANTABILITY OF THIS SOFTWARE OR THE * SUITABILITY OF THIS SOFTWARE FOR ANY PARTICULAR PURPOSE. The software * is provided "as is" without express or implied warranty of any kind. * * * 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: /nfs/jade/vint/CVSROOT/ns-2/mac/mac-802_11.cc,v 1.40 2002/06/06 22:54:42 haldar Exp $ * * Ported from CMU/Monarch's code, nov'98 -Padma. */#include "delay.h"#include "connector.h"#include "packet.h"#include "random.h"#include "mobilenode.h"// #define DEBUG 99#include "arp.h"#include "ll.h"#include "mac.h"#include "mac-timers.h"#include "mac-802_11.h"#include "cmu-trace.h"// XXX Can't we make these macros inline methods? Otherwise why should we have// inline methods at all??#define CHECK_BACKOFF_TIMER() \{ \ for (int temp_i=0; temp_i<=7; temp_i++) { \ if(is_idle(temp_i) && mhBackoff_[temp_i].paused()) \ mhBackoff_[temp_i].resume(aifs_[temp_i]); \ if(! is_idle(temp_i) && mhBackoff_[temp_i].busy() && ! mhBackoff_[temp_i].paused()) \ mhBackoff_[temp_i].pause(); \ } \}#define TRANSMIT(p, t) \{ \ tx_active_ = 1; \ \ /* \ * If I'm transmitting without doing CS, such as when \ * sending an ACK, any incoming packet will be "missed" \ * and hence, must be discarded. \ */ \ if(rx_state_ != MAC_IDLE) { \ struct hdr_mac802_11 *dh = HDR_MAC802_11(p); \ \ assert(dh->dh_fc.fc_type == MAC_Type_Control); \ assert(dh->dh_fc.fc_subtype == MAC_Subtype_ACK); \ \ assert(pktRx_); \ struct hdr_cmn *ch = HDR_CMN(pktRx_); \ \ ch->error() = 1; /* force packet discard */ \ } \ \ /* \ * pass the packet on the "interface" which will in turn \ * place the packet on the channel. \ * \ * NOTE: a handler is passed along so that the Network \ * Interface can distinguish between incoming and \ * outgoing packets. \ */ \ downtarget_->recv(p->copy(), this); \ \ mhSend_.start(t); \ \ mhIF_.start(txtime(p)); \ \}// hdr_mac802_11 *t_mh = HDR_MAC802_11(p); \// for(int i=0; i<=7; i++) if(i!=tc_) set_nav(usec(txtime(p))+t_mh->dh_duration,i);\//} // the last two lines handle the Virtual Station of EDCF#define SET_RX_STATE(x) \{ \ rx_state_ = (x); \ CHECK_BACKOFF_TIMER(); \}#define SET_TX_STATE(x) \{ \ tx_state_ = (x); \ CHECK_BACKOFF_TIMER(); \}/* ====================================================================== Global Variables ====================================================================== */static PHY_MIB PMIB ={ DSSS_CWMin, DSSS_CWMax, DSSS_SlotTime, DSSS_CCATime, DSSS_RxTxTurnaroundTime, DSSS_SIFSTime, DSSS_PLCPPreambleLength, DSSS_PLCPHeaderLength, DSSS_PLCPPreambleRate, DSSS_PLCPHeaderRate};static MAC_MIB MMIB ={ MAC_RTSThreshold, MAC_ShortRetryLimit, MAC_LongRetryLimit, MAC_FragmentationThreshold, MAC_MaxTransmitMSDULifetime, MAC_MaxReceiveLifetime, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};/* ====================================================================== TCL Hooks for the simulator ====================================================================== */static class Mac802_11Class : public TclClass {public: Mac802_11Class() : TclClass("Mac/802_11") {} TclObject* create(int, const char*const*) { return (new Mac802_11(&PMIB, &MMIB)); }} class_mac802_11;/* ====================================================================== Mac Class Functions ====================================================================== */Mac802_11::Mac802_11(PHY_MIB *p, MAC_MIB *m) : Mac(), mhIF_(this), mhRecv_(this), mhSend_(this), mhBeacon_(this), mhScheduler_(this), mhPSPoll_(this){ macmib_ = m; phymib_ = p; tx_state_ = rx_state_ = MAC_IDLE; tx_active_ = 0; pktRTS_ = 0; pktCTRL_ = 0; //cw_ = phymib_->CWMin; ssrc_ = slrc_ = 0; sifs_ = phymib_->SIFSTime; pifs_ = sifs_ + phymib_->SlotTime; difs_ = sifs_ + 2*phymib_->SlotTime; // see (802.11-1999, 9.2.10) eifs_ = sifs_ + (8 * ETHER_ACK_LEN / phymib_->PLCPPreambleRate) + difs_; tx_sifs_ = sifs_ - phymib_->RxTxTurnaroundTime; tx_pifs_ = tx_sifs_ + phymib_->SlotTime; tx_difs_ = tx_sifs_ + 2 * phymib_->SlotTime; sta_seqno_ = 1; cache_ = 0; cache_node_count_ = 0; // EDCF initialization QoSPriQueue_=0; for (int i=0; i<=7; i++) { nav_[i] = 0.0; mhNav_[i].initNavTimer(this); mhNav_[i].n_tc_=i; mhBackoff_[i].initBackoffTimer(this, p->SlotTime); mhBackoff_[i].b_tc_=i; mhDefer_[i].initDeferTimer(this, p->SlotTime); mhDefer_[i].d_tc_=i; QoScallback_[i]=(Handler*) 0; pktQoSTx_[i]=0; aifs_[i]=difs_; CWMin_[i]=phymib_->CWMin; CWMax_[i]=phymib_->CWMax; PF_[i]=2; // In draft 4.0 the Persistence Factor is ALWAYS = 2 EDCF_TXOP_[i]=0.0; // 0 -> Allowed transmission of only 1 data frame (in EDCF) rst_cw(i); } /* // AC 3 (Draft 4.0 default) High priority CWMin_[0]=((phymib_->CWMin+1)/4)-1; CWMax_[0]=((phymib_->CWMin+1)/2)-1; rst_cw(0); aifs_[0]=1*phymib_->SlotTime+phymib_->SIFSTime; CWMin_[1]=((phymib_->CWMin+1)/4)-1; CWMax_[1]=((phymib_->CWMin+1)/2)-1; rst_cw(1); aifs_[1]=1*phymib_->SlotTime+phymib_->SIFSTime; // AC 2 (Draft 4.0 default) CWMin_[2]=((phymib_->CWMin+1)/2)-1; CWMax_[2]=phymib_->CWMin; rst_cw(2); aifs_[2]=1*phymib_->SlotTime+phymib_->SIFSTime; CWMin_[3]=((phymib_->CWMin+1)/2)-1; CWMax_[3]=phymib_->CWMin; rst_cw(3); aifs_[3]=1*phymib_->SlotTime+phymib_->SIFSTime; // AC 1 (Draft 4.0 default) CWMin_[4]=phymib_->CWMin; CWMax_[4]=phymib_->CWMax; rst_cw(4); aifs_[4]=1*phymib_->SlotTime+phymib_->SIFSTime; CWMin_[5]=phymib_->CWMin; CWMax_[5]=phymib_->CWMax; rst_cw(5); aifs_[5]=1*phymib_->SlotTime+phymib_->SIFSTime; // AC 0 (Draft 4.0 default) Low priority CWMin_[6]=phymib_->CWMin; CWMax_[6]=phymib_->CWMax; rst_cw(6); aifs_[6]=2*phymib_->SlotTime+phymib_->SIFSTime; CWMin_[7]=phymib_->CWMin; CWMax_[7]=phymib_->CWMax; rst_cw(7); aifs_[7]=2*phymib_->SlotTime+phymib_->SIFSTime;*///@@ FaZ // // Work Around per essere compliant al draft 6 // // AC_VO {0,1} ; AC_VI {2,3} ; AC_BE {6,7} ; AC_BK {4,5} // // ----------------------------------------------------> // PRIORITA' // AC_VO CWMin_[0]=((phymib_->CWMin+1)/4)-1; CWMax_[0]=((phymib_->CWMin+1)/2)-1; rst_cw(0); aifs_[0]=2*phymib_->SlotTime+phymib_->SIFSTime; CWMin_[1]=((phymib_->CWMin+1)/4)-1; CWMax_[1]=((phymib_->CWMin+1)/2)-1; rst_cw(1); aifs_[1]=2*phymib_->SlotTime+phymib_->SIFSTime; // AC_VI CWMin_[2]=((phymib_->CWMin+1)/2)-1; CWMax_[2]=phymib_->CWMin; rst_cw(2); aifs_[2]=2*phymib_->SlotTime+phymib_->SIFSTime; CWMin_[3]=((phymib_->CWMin+1)/2)-1; CWMax_[3]=phymib_->CWMin; rst_cw(3); aifs_[3]=2*phymib_->SlotTime+phymib_->SIFSTime; // AC_BK CWMin_[4]=phymib_->CWMin; CWMax_[4]=phymib_->CWMax; rst_cw(4); aifs_[4]=7*phymib_->SlotTime+phymib_->SIFSTime; CWMin_[5]=phymib_->CWMin; CWMax_[5]=phymib_->CWMax; rst_cw(5); aifs_[5]=7*phymib_->SlotTime+phymib_->SIFSTime; // AC_BE CWMin_[6]=phymib_->CWMin; CWMax_[6]=phymib_->CWMax; rst_cw(6); aifs_[6]=3*phymib_->SlotTime+phymib_->SIFSTime; CWMin_[7]=phymib_->CWMin; CWMax_[7]=phymib_->CWMax; rst_cw(7); aifs_[7]=3*phymib_->SlotTime+phymib_->SIFSTime; //@ FaZ//@@ FaZ/* // // Queste sono quelle corrette ma bisogna investigare sulla TC_DEFAULT che non va :/ // // AC_BK (Draft 6.0) CWMin_[1]=phymib_->CWMin; CWMax_[1]=phymib_->CWMax; rst_cw(1); aifs_[1]=7*phymib_->SlotTime+phymib_->SIFSTime; CWMin_[2]=phymib_->CWMin; CWMax_[2]=phymib_->CWMax; rst_cw(2); aifs_[2]=7*phymib_->SlotTime+phymib_->SIFSTime; // AC_BE (Draft 6.0 default) CWMin_[0]=phymib_->CWMin; CWMax_[0]=phymib_->CWMax; rst_cw(0); aifs_[0]=3*phymib_->SlotTime+phymib_->SIFSTime; CWMin_[3]=phymib_->CWMin; CWMax_[3]=phymib_->CWMax; rst_cw(3); aifs_[3]=3*phymib_->SlotTime+phymib_->SIFSTime; // AC_VI (Draft 6.0) CWMin_[4]=((phymib_->CWMin+1)/2)-1; CWMax_[4]=phymib_->CWMin; rst_cw(4); aifs_[4]=2*phymib_->SlotTime+phymib_->SIFSTime; CWMin_[5]=((phymib_->CWMin+1)/2)-1; CWMax_[5]=phymib_->CWMin; rst_cw(5); aifs_[5]=2*phymib_->SlotTime+phymib_->SIFSTime; // AC_VO (Draft 6.0) CWMin_[6]=((phymib_->CWMin+1)/4)-1; CWMax_[6]=((phymib_->CWMin+1)/2)-1; rst_cw(6); aifs_[6]=2*phymib_->SlotTime+phymib_->SIFSTime; CWMin_[7]=((phymib_->CWMin+1)/4)-1; CWMax_[7]=((phymib_->CWMin+1)/2)-1; rst_cw(7); aifs_[7]=2*phymib_->SlotTime+phymib_->SIFSTime;//@ FaZ*/ tc_=TC_DEFAULT_; if (index_==0) for (int i=0; i<=7; i++) { printf(" EDCF TC %d settings: aifs=%f, CWMin=%d, CWMax=%d, (PF=%f, EDCF_TXOP=%f not implemented)\n",i,aifs_[i],CWMin_[i],CWMax_[i],PF_[i],EDCF_TXOP_[i]); } // HCF initialization HC_=0; pktBeacon_ = 0; btbs_=0; Tcfp_=0; Tsf_=0; TBTT_=0.0; ptbs_=0; TXOP_=0.0; pktQoSPoll_ = 0; pktQoSNull_ = 0; ESTA_=0; nop=-1; logdelays_=NULL; logstatistics_=NULL; es_=0; sched=0; // Default is BCGM //bind_bool("EnableScheduler",&es_); maximum_assigned_txop=0; maximum_reassigned_txop=0; maximum_superframe_usage=0.0; maximum_superframe_reusage=0.0; max_txop_number=0; //@@ FaZ n_ps_sta=0; nopsp=0; sch_el_resume=0; ps_beacon=0; gotosleep_after_ack=0; use_psEDCA=0; use_only_psEDCA=0; is_first_sch_el=0; dont_use_sch_el=0; no_pre_poll=0; use_wa_first_schel=0; dont_go_sleep_after_null=0;//@ FaZ // chk if basic/data rates are set // otherwise use bandwidth_ as default; Tcl& tcl = Tcl::instance(); tcl.evalf("Mac/802_11 set basicRate_"); if (strcmp(tcl.result(), "0") != 0) bind_bw("basicRate_", &basicRate_); else basicRate_ = bandwidth_; tcl.evalf("Mac/802_11 set dataRate_"); if (strcmp(tcl.result(), "0") != 0)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -