ns3-model-library.pdf wifi-model 翻譯
wifi-model
33.1 Design Documentation
ns3 節(jié)點(diǎn)(nodes)能夠包含一系列網(wǎng)絡(luò)設(shè)備(NetDevice)對(duì)象旨袒,就像實(shí)際的計(jì)算機(jī)包含單獨(dú)的接口卡一樣洛勉,例如丈秩,以太網(wǎng)卡,WiFi一也,藍(lán)牙等。這一章描述ns3的WifiNetDevice和相關(guān)的模型喉脖。通過添加WifiNetDevice對(duì)象到ns3的節(jié)點(diǎn)(nodes)中椰苟,它就可以創(chuàng)建基于802.11的基礎(chǔ)設(shè)施和adhoc網(wǎng)絡(luò)模型。
33.1.1 Overview of the model
WifiNetDevice模型是一個(gè)基于IEEE802.11標(biāo)準(zhǔn)的無線網(wǎng)絡(luò)接口控制器树叽。我們將會(huì)更加詳細(xì)的看到它的細(xì)節(jié)舆蝴,但只是簡(jiǎn)略的細(xì)節(jié),ns3提供了802.11模型的這些方面:
基本的802.11 DCF(Distributed coordination function)基礎(chǔ)設(shè)施和adhoc模式
802.11a 802.11b 802.11g 802.11n(包括2.4和5GHz帶寬) 和802.11ac物理層
延伸與802.11n的MSDU aggregation and MPDU aggregation 题诵,同時(shí)支持兩種聚合的結(jié)合
延伸于802.11e的QoS-based EDCA and queueing
使用不同的傳播損耗模型和傳播延遲模型的能力洁仗,請(qǐng)參見章(Propagation)傳播獲取更多細(xì)節(jié)
不同的速率控制算法,包括Aarf,Arf,Cara,Onoe,Rraa,ConstantRate,Minstrel
802.11s(mesh),該協(xié)議在其他章節(jié)有描述
在ns3中提供的一系列802.11模型提供了一個(gè)精確的802.11規(guī)范的MAC層性锭,并提供了802.11a/b/g/n/ac規(guī)范的不那么慢的PHY層模型赠潦。
在ns3,節(jié)點(diǎn)可以在不同的信道上有不同的WifiNetDevices草冈,同時(shí)WifiNetDevices可以與其他的設(shè)備類型共存她奥;這消除了在ns2中結(jié)構(gòu)的限制。然而怎棱,現(xiàn)在哩俭,還不存在交叉信道干擾或耦合的模型。
WifiNetDevices的源碼在目錄src/wifi下拳恋。
代碼的實(shí)現(xiàn)是模塊化的凡资,大約提供了四個(gè)級(jí)別的模型:
1.PHY layer models
2.MAC low models: they implement DCF and EDCAF
3.MAC high models:they implement the MAC-level beacon generation, probing, and association state machines
4.可以被MAC low models使用的Rate control algorithms
下面,我們介紹每一層的概述谬运。關(guān)于更多的細(xì)節(jié)稍候會(huì)討論讳苦。
MAC high models
現(xiàn)在已有三個(gè)MAC high models带膜,該模型提供了三個(gè)無線拓?fù)湓?non-mesh,mesh equivalent,都是ns3::RegularWifiMac的子類,不再這里討論它):Access Point(AP)(ns3::ApWifiMac),non-AP Station(STA)(ns3::StaWifiMac),和獨(dú)立于基礎(chǔ)服務(wù)設(shè)備的STA(ns3::AdhocWifiMac).
三種模型中最簡(jiǎn)單的是ns3::AdhocWifiMac,它實(shí)現(xiàn)了無任何種類的信標(biāo)的產(chǎn)生鸳谜,探測(cè)和關(guān)聯(lián)的WIFI MAC膝藕。
The ns3::StaWifiMac class implements an active probing and association state machine that handles automatic re-association whenever too many beacons are missed. Finally, ns3::ApWifiMac implements an AP that generates periodic beacons, and that accepts every attempt to associate.
這三種MAC high models共享同一個(gè)父類ns3::RegularWifiMac,它暴露出MAC配置的幾個(gè)屬性:QosSupported屬性,允許配置802.11e/WMM-STYPE QOS支持咐扭;HtSupported屬性芭挽,允許配置802.11n高吞吐量形式;VhtSupported屬性蝗肪,允許配置802.11ac更高吞吐量樣式支持袜爪。
MAC low layer
MAC low layer分為以下三個(gè)組件:
1. ns3::MacLow 該類管理 RTS/CTS/DATA/ACK交互。
2. ns3::DcfManager和ns3::DcfState,實(shí)現(xiàn)了DCF和EDCAF功能薛闪。
3. ns3::DcaTxop和ns3::EdcaTxopN,用于處理在需要的情況下的包隊(duì)列辛馆,包分組,包重傳等豁延。The ns3::DcaTxop object is used high MACs that are not QoS-enabled,and for transmission of frames (e.g., of type Management) that the standard says should access the medium using the DCF. ns3::EdcaTxopN is is used by QoS-enabled high MACs and also performs 802.11n-style MSDU aggregation.
Rate control algorithms
有幾種MAC low layer使用的rate control algorithms.完整的可以使用的速率控制算法將會(huì)在一個(gè)單獨(dú)的一節(jié)中提供昙篙。
PHY layer models
PHY層是在ns3::WifiPhy類中單獨(dú)實(shí)現(xiàn)的。物理層模型的實(shí)現(xiàn)的完整的描述是在論文:Yet Another Network Simulator中诱咏,基于802.11b的可用的結(jié)果的驗(yàn)證報(bào)告在techinical report中苔可。
33.1.2 The WifiChannel and WifiPhy models
無線信道wifichannel可以使用一組ns3::WifiNetDevice網(wǎng)絡(luò)接口連接在一起。ns3::WifiPhy對(duì)象是在wifinetdevice中的袋狞,用于接收從信道接收的數(shù)據(jù)比特焚辅。對(duì)于信道的傳播模型,可以使用傳播模塊苟鸯;詳見Propagation一節(jié)同蜻。
本節(jié)總結(jié)了誤碼率計(jì)算的描述,該誤碼率在論文中把在802.11a協(xié)議中的前向糾錯(cuò)考慮了進(jìn)去早处,并描述了一個(gè)包是否被成功接收所實(shí)現(xiàn)的算法埃仪。請(qǐng)參閱“Yet Another Network Simulator”的更多細(xì)節(jié)。
PHY層的狀態(tài)會(huì)是下面五種其中的一種:
- TX:the PHY is currently transmitting a signal on behalf of its associated MAC(phy層正在發(fā)送與之關(guān)聯(lián)的MAC的信號(hào))
- RX:the PHY is synchronized on a signal and is waiting until it has received its last bit to forward it to the MAC.(phy已經(jīng)同步了信號(hào)陕赃,正在等待止到接收到最后一個(gè)比特位卵蛉,然后轉(zhuǎn)發(fā)到MAC層)
- IDLE:the PHY is not in the TX, RX, or CCA BUSY states.(PHY層空閑)
- CCA Busy:the PHY is not in TX or RX state but the measured energy is higher than the energy detection threshold.(PHY不在TX,RX狀態(tài)么库,但是測(cè)得的能量高于能量探測(cè)閾值)
- SLEEP:the PHY is in a power save mode and cannot send nor receive frames.(PHY處于節(jié)能狀態(tài)傻丝,不發(fā)送也不接收)
當(dāng)PHY不是IDLE狀態(tài)時(shí)(也就是說,另外的更早的包已經(jīng)在接收器中同步了诉儒,或者他自己在發(fā)送數(shù)據(jù))葡缰,一個(gè)新的包的第一個(gè)比特位被接收,此時(shí),接收的包將被丟棄泛释。否則滤愕,如果PHY處于IDLE或者CCA Busy狀態(tài),我們計(jì)算這個(gè)新的信號(hào)的第一位比特的接收能量怜校,并于能量探測(cè)閾值進(jìn)行比較(as defined by the Clear Channel Assessment function mode 1)间影。如果包的能量高,PHY則轉(zhuǎn)移狀態(tài)到RX茄茁,并且當(dāng)包的最后一個(gè)比特位被接收時(shí)發(fā)起一個(gè)事件魂贬。否則,PHY停留在IDLE或者CCA Busy狀態(tài)裙顽,并丟棄這個(gè)包付燥。
The energy of the received signal is assumed to be zero outside of the reception interval of packet k and is calculated from the transmission power with a path-loss propagation model in the reception interval. where the path loss expo-nent, n, is chosen equal to 3, the reference distance, d 0 is choosen equal to 1.0m and the reference energy is based on a Friis propagation model.
When the last bit of the packet upon which the PHY is synchronized is received, we need to calculate the probability that the packet is received with any error to decide whether or not the packet on which we were synchronized could be successfully received or not: a random number is drawn from a uniform distribution and is compared against the probability of error.
To evaluate the probability of error, we start from the piecewise linear functions shown in Figure SNIR function over time. and calculate the SNIR function.
從SNIR funtion,我們可以派生出計(jì)算用于傳輸?shù)恼{(diào)制和解調(diào)的誤碼率BER和誤包率PER愈犹。請(qǐng)參考[pei80211ofdm], [pei80211b], [lacage2006yans],[Haccoun] and [Frenger] 以了解更多的可用的BER/PER模型的細(xì)節(jié).
WifiChannel configuration
WifiChannel的實(shí)現(xiàn)使用了傳播損耗模型和傳播延時(shí)模型键科,這兩個(gè)模型在ns3的Propagation模塊中有提供。
33.1.3 The MAC model
802.11分布式協(xié)調(diào)功能(DCF)是用來計(jì)算當(dāng)授予訪問傳輸介質(zhì)的時(shí)候漩怎。如果我們使用一個(gè)經(jīng)過每一個(gè)時(shí)隙的周期性的定時(shí)器勋颖,那么實(shí)現(xiàn)DCF將會(huì)特別的容易,我們選擇使用在【ji2004sslswn】所描述的方法扬卷,回退時(shí)間無論是否需要牙言,都是延時(shí)計(jì)算的酸钦,盡管聲稱這比簡(jiǎn)單的周期定時(shí)器方法具備更好地性能怪得。
DCF程序的回退在【ieee80211】的9.2.5.2節(jié)中描述的。
- 無論由物理層或者虛擬CS機(jī)制所指示的發(fā)現(xiàn)媒質(zhì)忙卑硫,回退程序應(yīng)為STA調(diào)用來傳送一個(gè)幀徒恋。
- 即使沒有另外傳輸任務(wù)在當(dāng)前隊(duì)列中,A backoff procedure shall be performed immediately after the end of every transmission with the More Frag-ments bit set to 0 of an MPDU of type Data, Management, or Control with subtype PS-Poll
總之欢伏,如果隊(duì)列空入挣,一個(gè)新到的包應(yīng)該在信道感知空閑DIFS后,馬上被傳輸硝拧。如果隊(duì)列不空径筏,并且在一個(gè)成功的MPDU之后沒有更多的分組,節(jié)點(diǎn)應(yīng)該開始回退定時(shí)器障陶。
一些用戶觀察到滋恬,802.11MAC與空隊(duì)列的空閑信道將會(huì)馬上發(fā)送達(dá)到該模型的第一幀,而無須等待DIFS或者回退抱究,并想知道這是否合規(guī)恢氯。根據(jù)協(xié)議標(biāo)準(zhǔn),“The backoff procedure shall be invoked for a STA to transfer a frame when finding the medium busy as indicated by either the physical or virtual CS mechanism.”因此在這種情況下,媒介并不能發(fā)現(xiàn)在當(dāng)前忙勋拟,站點(diǎn)將會(huì)馬上傳輸勋磕。
更高層的MAC功能的實(shí)現(xiàn)是在一系列C++類中,功能:
? packet fragmentation and defragmentation,
? use of the RTS/CTS protocol,
? rate control algorithm,
? connection and disconnection to and from an Access Point,
? the MAC transmission queue,
? beacon generation,
? MSDU aggregation,
? etc.
33.1.4 Rate control algorithms
多種速率控制算法在ns3中是可用的敢靡。一些速率控制算法是用在真實(shí)設(shè)備中的實(shí)際算法挂滓;其他一些算法是在文獻(xiàn)中找到的。下面的速率控制算法是在MAC low layer中使用的:
真實(shí)設(shè)備中的算法有:
ArfWifiManager(WifiHelper的默認(rèn)算法)【Automatic Rate Fallback(ARF) algorithm 自動(dòng)速率回退算法 1997年】
OnoeWifiManager
ConstantRateWifiManager
MinstrelWifiManager
文獻(xiàn)中的算法:
IdealWifiManager
AarfWifiManager【2004年】
AmrrWifiManager
CaraWifiManager
RraaWifiManager【2006年】
AarfcdWifiManager
ParfWifiManager
AparfWifiManager
ConstantRateWifiManager
該算法對(duì)每一個(gè)包使用相同的傳輸模式醋安。用戶可以設(shè)置對(duì)于所有“unicast”包的期望的“DataMode”和所有“request”控制包的“ControlMode”(例如RTS).
控制響應(yīng)幀(比如CTS杂彭,ACK)的傳輸參數(shù)的選擇規(guī)則在802.11標(biāo)準(zhǔn)中是相當(dāng)清晰的。ns3遵從了這樣的標(biāo)準(zhǔn)和從一系列正常速率或者強(qiáng)制性速率選擇作為控制響應(yīng)幀的速率的選擇性吓揪。這就意味著亲怠,即使ConstantRateWifiManager被使用,控制響應(yīng)幀也可能使用不同的速率進(jìn)行發(fā)送柠辞。
ConstantRateWifiManager的ControlMode屬性僅僅別用與RTS幀团秽。CTS和ACK幀的速率是根據(jù)802.11標(biāo)準(zhǔn)進(jìn)行選擇的。然而叭首,用戶仍然可以手動(dòng)添加WifiMode到基本的速率中习勤,這將允許控制響應(yīng)幀以其他的速率進(jìn)行發(fā)送。請(qǐng)參考project wiki進(jìn)一步了解這是如何實(shí)現(xiàn)的焙格。
可用的屬性有:
DataMode:(默認(rèn)WifiMode::OfdmRate6Mbps)specify a mode for all non-unicast packets
ControlMode:(默認(rèn)WifiMode::OfdmRate6Mbps)specify a mode for all ‘request’ control packets
IdealWifiManager
這個(gè)速率控制算法根據(jù)前一個(gè)包的發(fā)送的信噪比SNR來選擇最好的模式图毕。考慮節(jié)點(diǎn)A發(fā)送單播包到節(jié)點(diǎn)B眷唉。當(dāng)B成功接收到從A發(fā)送的包時(shí)予颤,B記錄所接受的包的SNR到ns3::SnrTag,然后,添加標(biāo)簽到ACK并返回給A冬阳。通過這樣做蛤虐,A能夠了解發(fā)送到B的包的信噪比SNR,并使用一種帶寬之外的機(jī)制(因此算法名字就是“ideal”)肝陪。然后A使用SNR從一個(gè)一系列SNR閾值中選擇一個(gè)傳輸模式驳庭,而這個(gè)閾值是從目標(biāo)BER和特定模式的SNR/BER曲線構(gòu)建的。
可以的屬性有:
BerThreshold(默認(rèn)10e-6):The maximum Bit Error Rate that is used to calculate the SNR threshold for each mode.最大誤碼率氯窍,用于計(jì)算每種模式的SNR閾值饲常。
MinstrelWifiManager
該算法是源于madwifi 工程的速率控制算法。它是當(dāng)前LInux內(nèi)核默認(rèn)的速率控制算法狼讨。
Minstrel跟蹤每個(gè)成功發(fā)送可用速率幀的概率贝淤。然后通過乘以速率的概率計(jì)算期望的吞吐量。這種方法被選擇用于確保不會(huì)選擇最低速率而趨向于最高速率(盡管最低速率具有更高的概率)熊楼。
在monstrel中霹娄,大致10%的傳輸是在所謂的lookaround rate發(fā)送的能犯。lookaround rate的目標(biāo)就是迫使minstrel嘗試使用比當(dāng)前速率更高的速率。
更多關(guān)于minstrel的細(xì)節(jié)犬耻,請(qǐng)看【linuxminstrel】踩晶。
IEEE 802.11 標(biāo)準(zhǔn)在物理層支持利用多種速率進(jìn)行傳輸,但是并未規(guī)定速率選擇策略枕磁。速率自適應(yīng)的速率選擇算法核心是及時(shí)獲取能夠?qū)崟r(shí)反映信道狀態(tài)的信息渡蜻。
目前獲取信道信息的方法主要有兩大類:
1. 信道物理信息直接獲取。 比如獲取信噪比SNR计济,接受信號(hào)強(qiáng)度茸苇,誤碼率BER
2. 基于統(tǒng)計(jì)的方法.
目前的速率自適應(yīng)可分為以下4類:
利用傳送幀連續(xù)的成功和失敗次數(shù)來估計(jì)信道質(zhì)量。比如ARF算法沦寂,如果連續(xù)沒有收到兩個(gè)ACK学密,則降低一檔速率,發(fā)送下面的數(shù)據(jù)并啟動(dòng)一個(gè)定時(shí)器传藏;如果連續(xù)收到10個(gè)幀或者定時(shí)器時(shí)間到腻暮,則提高發(fā)送速率。缺點(diǎn):連續(xù)成功或失敗的次數(shù)很難及時(shí)適應(yīng)信道的快速變化毯侦。
利用物理層指標(biāo)(如SNIR,RSS)估計(jì)信道質(zhì)量哭靖。缺點(diǎn):已有文獻(xiàn)證明SNIR,RSS等指標(biāo)和丟幀率并沒有很強(qiáng)的對(duì)應(yīng)關(guān)系,而且基于跨層的設(shè)計(jì)思想在實(shí)際應(yīng)用中存在困難侈离。
每隔一段時(shí)間以不同速率發(fā)送一個(gè)或者一些試探幀试幽,用來估計(jì)不同數(shù)量在信道中的表現(xiàn)。這種方法提高了對(duì)其他速率的實(shí)時(shí)估計(jì)能力卦碾,但是因?yàn)椴荒馨l(fā)送過多的試探幀铺坞,導(dǎo)致個(gè)別試探幀的成敗決定了速率選擇,容易造成誤判蔗坯。如SampleRate康震。
利用近一段時(shí)間的數(shù)據(jù)幀的統(tǒng)計(jì)特征來決定發(fā)送速率燎含。比如RRAA宾濒。RRAA在一段時(shí)間(窗口)內(nèi)統(tǒng)計(jì)丟幀率等信息,并將其與相應(yīng)的門限進(jìn)行比較屏箍。這種方法屏蔽了因?yàn)殡S機(jī)丟幀而導(dǎo)致的誤判绘梦,如果窗口選擇合適,能夠?qū)π诺雷兓鞒黾皶r(shí)反應(yīng)赴魁。
內(nèi)容來源:http://blog.csdn.net/forsiny/article/details/4805783
33.1.5 Modifying wifi model
在性能研究的時(shí)候卸奉,更改默認(rèn)的wifi模式是普通的任務(wù)之一。在這一節(jié)颖御,我們提供了如何更改默認(rèn)的wifi模式的概述榄棵。依賴于你的目的,通常的任務(wù)是(排序不分先后):
1.通過更改wifi-mac-header..完成創(chuàng)建或者更改默認(rèn)的WIFI幀/頭
2.MAC low更改。例如疹鳄,處理新的/更改的 控制幀(考慮RTS/CTS/ACK/Block ACK)拧略,更改成兩路/四路交互。用戶通常更改mac-low.來完成這個(gè)任務(wù)瘪弓〉媲控制幀的處理效果是在MacLow:ReceiveOk.
3.WIFI隊(duì)列管理。文件dca-txop.和edca-txop-n.是對(duì)這個(gè)任務(wù)有幫助的腺怯。
4.信道接入管理袱饭。用戶應(yīng)該更改文件dcf-manager.*,該文件授權(quán)訪問DcaTxop和EdcaTxopN.
5.被WIFI遠(yuǎn)程站點(diǎn)管理器所處理的分組和RTS閾值。注意:wifi remote station manager簡(jiǎn)單的指示fragmentation和RTS是否需要呛占。當(dāng)RTS/CTS被MacLow處理時(shí)虑乖,F(xiàn)ragmentation被DcaTxop或者EdcaTxopN所處理
6.更改或者添加新的速率控制算法,可以通過創(chuàng)建一個(gè)新的WIFI remote station manager類或者更改一個(gè)存在的類完成晾虑。
33.1.6 Note on the current implementation
? 802.11g does not support 9 microseconds slot
? PHY_RXSTART is not supported
? 802.11e TXOP is not supported
? 802.11n MIMO is not supported
? 802.11n/ac MIMO is not supported
? 802.11n/ac beamforming is not supported
? PLCP preamble reception is not modeled
? BSSBasicRateSet for 802.11b has been assumed to be 1-2 Mbit/s
? BSSBasicRateSet for 802.11a/g has been assumed to be 6-12-24 Mbit/s
? cases where RTS/CTS and ACK are transmitted using HT formats are not supported
? Only ConstantRateWifiManager is supported by 802.11n or 802.11ac
33.2 User Documentation
33.2.1 Using the WifiNetDevice
實(shí)現(xiàn)提供了模塊化决左,使得WifiNetDevice具備強(qiáng)大的低級(jí)別的配置,但復(fù)雜走贪》鹈停基于這個(gè)原因,我們提供了一些幫助類以一種簡(jiǎn)單的方式完成一些普通的操作坠狡,同時(shí)提供了ns3的屬性系統(tǒng)來控制底層模型的參數(shù)继找。
使用底層ns3 API和期望添加一個(gè)WifiNetDevice到節(jié)點(diǎn)上,必須創(chuàng)建一個(gè)WifiNetDevice實(shí)例逃沿,和許多構(gòu)成的對(duì)象婴渡,以一種合適的方式綁定在一起(WifiNetDevice為未來的可擴(kuò)展性,在某種程度上已經(jīng)非常模塊化)凯亮。在底層api边臼,這需要大約20行代碼(請(qǐng)看ns3::WifiHelper::Install,ns3::YansWifiPhyHelper::Create).在某些點(diǎn),一個(gè)信道WifiChannel必須被創(chuàng)建假消,也包含了一些構(gòu)成的對(duì)象(請(qǐng)看ns3::YansWifiChannelHelper::Create)柠并。
然而,一些可用的幫助類可以使用富拗,如果愿意使用默認(rèn)值的話,添加設(shè)備和信道只用幾行代碼就能完成臼予。當(dāng)然也可以使用額外的api允許通過屬性系統(tǒng)來改變默認(rèn)值。經(jīng)常使用的屬性值在Attributes節(jié)中已經(jīng)列出來了啃沪。腳本examples/wireless可以瀏覽看看這是怎么做的粘拾。接下來,我們描述創(chuàng)建一個(gè)WifiNetDevice從底層(WifiChannel)到設(shè)備層(WifiNetDevice)的通常的步驟创千。
為了創(chuàng)建一個(gè)WifiNetDevice缰雇,用戶主要需要配置五步:
- 配置WifiChannel:WifiChannel關(guān)系到信號(hào)在相同的信道上從一個(gè)設(shè)備到另一個(gè)設(shè)備入偷。WifiChannel主要的配置是傳播損耗模型和傳播延時(shí)模型。
- 配置WifiPhy:WifiPhy關(guān)系到從WifiChannel發(fā)送和接收無線信號(hào)械哟。這里盯串,WifiPhy依賴于接收的信號(hào)的強(qiáng)度和噪聲決定每一幀是否被成功解碼。所以戒良,WifiPhy的主要配置是誤碼率模型体捏,該模型就是最后計(jì)算基于信號(hào)的成功解碼幀的概率。
- 配置WifiMac:這一步更多的是與the architecture and device level有關(guān)糯崎。用戶配置wifi architecture(例如adhoc or ap-sta)和是否支持Qos(802.11e)几缭,HT(802.11n),VHT(802.11ac)特性沃呢。
- 創(chuàng)建WifiDevice:在這一步年栓,用戶配置期望的wifi標(biāo)準(zhǔn)(例如802.11b,802.11g,802.11a,802.11n or 802.11ac)和速率控制算法稍途。
- 配置mobility:最后独柑,mobility模型通常需要在WifiNetDevice可用之前配置抖拦。
YansWifiChannelHelper
YansWifiChannelHelper具有一個(gè)不同尋常的名字息楔。讀者可能會(huì)疑惑為什么使用這樣的名字。該模型是從yans simulator提取出來的叠聋,名字也是引用自它壹粟。該幫助類可以創(chuàng)建一個(gè)帶有默認(rèn)傳播損耗模型(PropagationLoss)和傳播延時(shí)模型(PropagationDelay)的WifiChannel愕乎。
用戶所使用的經(jīng)典代碼如下:
YansWifiChannelHelper wifiChannelHelper = YansWifiChannelHelper::Default ();
Ptr<WifiChannel> wifiChannel = wifiChannelHelper.Create ();
特別的是崎坊,默認(rèn)的信道模型使用的是3的指數(shù)的信道模型备禀,所用的傳播時(shí)延等于一個(gè)常數(shù)值,就是光速(ns3::ConstantSpeedPropagationDelayModel)奈揍,所用的傳播損耗是基于一個(gè)默認(rèn)的log distance model(ns3::LogDistancePropagationLossModel)曲尸。請(qǐng)注意,默認(rèn)的log distance model is configured with a reference loss of 46.6777 dB at reference distance of 1m男翰。The reference loss of 46.6777 dB was calculated using Friis propagation loss model at 5.15 GHz.The reference loss 模型如果使用802.11b,802.11g,802.11n(由于它們工作在2.4GHZ)必須被改變另患。
注意上面在創(chuàng)建一個(gè)幫助對(duì)象和一個(gè)實(shí)際的仿真對(duì)象的區(qū)別。在ns3中蛾绎,幫助對(duì)象(僅僅用于幫助APP)是在棧(它們可以使用new操作符創(chuàng)建和使用deleted銷毀)中創(chuàng)建的昆箕。然而,實(shí)際的ns3對(duì)象繼承自ns3::Object類秘通,并且分配一個(gè)智能指針为严。如果你不熟悉智能指針敛熬,請(qǐng)參看ns3-manual中關(guān)于ns3 object model一章的內(nèi)容肺稀。
下面的兩個(gè)方法在配置YansWifiChannelHelper是有用的:
? YansWifiChannelHelper::AddPropagationLoss adds a PropagationLossModel to a chain of PropagationLossModel
? YansWifiChannelHelper::SetPropagationDelay sets a PropagationDelayModel
YansWifiPhyHelper
物理層設(shè)備(基類ns3::WifiPhy)在ns3中是與ns3::WifiChannel相連接的。我們需要為YansWifiChannel創(chuàng)建合適的WifiPhy對(duì)象应民。這里YansWifiPhyHelper就可以勝任這個(gè)工作话原。
YansWifiPhyHelper類配置了一個(gè)對(duì)象工廠來創(chuàng)建一個(gè)YansWifiPhy實(shí)例夕吻,并添加一些其他的對(duì)象到該實(shí)例中,包括可能補(bǔ)充的ErrorRateModel誤碼率模型和指向MobilityModel移動(dòng)模型的指針繁仁。典型的用戶代碼如下:
YansWifiPhyHelper wifiPhyHelper = YansWifiPhyHelper::Default ();
wifiPhyHelper.SetChannel (wifiChannel);
YansWifiPhyHelper默認(rèn)配置NistErrorRateModel(ns3::NistErrorRateModel)誤碼率模型涉馅。你可以使用YansWifiPhyHelper::SetErrorRateModel方法更改誤碼率模型。
可選的是黄虱,如果pcap跟蹤記錄是需要的話稚矿,用戶可以使用下面的代碼使得pcap跟蹤可用:
YansWifiPhyHelper::SetPcapDataLinkType (enum SupportedPcapDataLinkTypes dlt)
ns3支持802.11的RadioTap和Prism軌跡擴(kuò)展。
注意捻浦,我們還沒有實(shí)際創(chuàng)建一個(gè)WifiPhy對(duì)象晤揣;我們只是準(zhǔn)備了告訴YansWifiPhyHelper與之連接的信道。Phy對(duì)象會(huì)在下一步創(chuàng)建朱灿。
802.11n/ac PHY層可以使用長800ns或者短400ns的OFDM guard intervals昧识。為了配置這個(gè)參數(shù),可以使用下面的一行的代碼(這個(gè)例子中盗扒,使用的是short guard interval的支持):
wifiPhyHelper.Set ("ShortGuardEnabled", BooleanValue(true));
更多的是跪楞,802.11提供了一種可選的模式(GreenField mode)來減少preamble durations(前沿持續(xù)時(shí)間),并且這也是唯一一種與802.11n設(shè)備兼容的模式侣灶〉榧溃可以使用下面的代碼啟用這種模式:
wifiPhyHelper.Set ("GreenfieldEnabled",BooleanValue(true));
802.11nPHY層可以支持20(默認(rèn))或者40MHZ信道帶寬,802.11ac PHY層可以使用20褥影,40淋叶,80(默認(rèn)),160MHZ信道帶寬伪阶。由于信道帶寬值被WifiHelper::SetStandard重寫煞檩,可以使用下面Config::Set代碼在安裝后進(jìn)行配置:
WifiHelper wifi = WifiHelper::Default ();
wifi.SetStandard (WIFI_PHY_STANDARD_80211ac);
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode",
StringValue("VHtMcs9"), "ControlMode",StringValue("VHtMcs9"));
VhtWifiMacHelper mac = VhtWifiMacHelper::Default ();
//Install PHY and MAC
Ssid ssid = Ssid ("ns3-wifi");
mac.SetType ("ns3::StaWifiMac",
"Ssid", SsidValue (ssid),
"ActiveProbing", BooleanValue (false));
NetDeviceContainer staDevice;
staDevice = wifi.Install (phy, mac, wifiStaNode);
mac.SetType ("ns3::ApWifiMac",
"Ssid", SsidValue (ssid));
NetDeviceContainer apDevice;
apDevice = wifi.Install (phy, mac, wifiApNode);
//Once install is done, we overwrite the channel width value
//(一旦安裝之后,我們可以重寫信道帶寬)
Config::Set ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/ChannelWidth", UintegerValue (160));
WifiMacHelper
下一步是配置MAC模型栅贴。我們使用WifiMacHelper來完成斟湃。WifiMacHelper可以完成MAC low 模型和MAC high模型。用戶必須決定采用哪種模型:802.11/WMM-style Qos 檐薯, 802.11n-style Hight throughput(HT)凝赛,802.11ac-style Very High throughput(VHT)
NqosWifiMacHelper and QosWifiMacHelper
ns3::NqosWifiMacHelper和ns3::QosWifiMacHelper均可以配置一個(gè)對(duì)象工廠來創(chuàng)建一個(gè)ns3::WifiMac實(shí)例。它們用來配置像MAC類型的參數(shù)坛缕。
前者ns3::NqosWifiMacHelper不支持以下類型的MAC實(shí)例的創(chuàng)建:802.11e/WMM-style QoS墓猎,802.11n-style High throughput (HT),802.11ac-style Very High throughput (VHT)赚楚。
例如下面的用戶代碼配置了一個(gè)不支持QOs和HT的MAC類型實(shí)例毙沾,并且沒有AP,僅有STA的一個(gè)基礎(chǔ)設(shè)施網(wǎng)絡(luò)宠页,SSID設(shè)置為ns-3-ssid:
NqosWifiMacHelper wifiMacHelper = NqosWifiMacHelper::Default ();
Ssid ssid = Ssid ("ns-3-ssid");
wifiMacHelper.SetType ("ns3::StaWifiMac",
"Ssid", SsidValue (ssid),
"ActiveProbing", BooleanValue (false));
可以使用ns3::QosWifiMacHelper來代替ns3::NqosWifiMacHelper來創(chuàng)建一個(gè)支持Qos的MAC實(shí)例左胞。
下面的代碼使用ns3::QosWifiMacHelper創(chuàng)建了一個(gè)支持Qos的AP:
QosWifiMacHelper wifiMacHelper = QosWifiMacHelper::Default ();
wifiMacHelper.SetType ("ns3::ApWifiMac",
"Ssid", SsidValue (ssid),
"BeaconGeneration", BooleanValue (true),
"BeaconInterval", TimeValue (Seconds (2.5)));
支持Qos的MAC模型可以工作在流量屬于四種不同訪問策略下:AC_VO 語音流寇仓,AC_VI 視頻流,AC_BE 盡最大努力流烤宙,AC_BK后臺(tái)流遍烦。為了使MAC為MSDU決定一個(gè)合適的AC,轉(zhuǎn)發(fā)到這些MAC層的包應(yīng)該被使用一個(gè)TID(traffic id)的ns3::QosTag標(biāo)記躺枕,否則該包將被屬于AC_BE策略服猪。
為了創(chuàng)建一個(gè)ad-hoc MAC實(shí)例,簡(jiǎn)單的使用ns3::AdhocWifiMac代替ns3::StaWifiMac和ns3::ApWifiMac即可拐云。
HtWifiMacHelper
ns3::HtWifiMacHelper配置一個(gè)對(duì)象工廠來創(chuàng)建一個(gè)ns3::WifiMac實(shí)例蔓姚。它用于支持創(chuàng)建802.11n-style High throughput (HT) 和支持QoS類型的MAC實(shí)例。特別的慨丐,該對(duì)象也可以用來設(shè)置:
1. 為了使用802.11n MSDU聚合特性坡脐,為特定的訪問策略AC設(shè)置MSDU聚合
2. 可以設(shè)置像threshold(閾值)(塊ACK機(jī)制應(yīng)該被使用的包的數(shù)量)的塊ACK參數(shù)和閑置超時(shí)。
例如房揭,下面的代碼配置了一個(gè)HT MAC备闲,不支持AP,支持STA捅暴,QOS保證恬砂,聚合AC_VO,和AC_BE的塊ACK,這樣的基礎(chǔ)設(shè)施網(wǎng)絡(luò)蓬痒,它的AP的SSID為ns-3-ssid:
HtWifiMacHelper wifiMacHelper = HtWifiMacHelper::Default ();
Ssid ssid = Ssid ("ns-3-ssid");
wifiMacHelper.SetType ("ns3::StaWifiMac",
"Ssid", SsidValue (ssid),
"ActiveProbing", BooleanValue (false));
wifiMacHelper.SetMsduAggregatorForAc (AC_VO, "ns3::MsduStandardAggregator",
"MaxAmsduSize", UintegerValue (3839));
wifiMacHelper.SetBlockAckThresholdForAc (AC_BE, 10);
wifiMacHelper.SetBlockAckInactivityTimeoutForAc (AC_BE, 5);
這個(gè)對(duì)象也可以使用ns3::QosWifiMacHelper以相同的方式進(jìn)行設(shè)置泻骤。
VhtWifiMacHelper
ns3::VhtWifiMacHelper配置一個(gè)對(duì)象工廠來創(chuàng)建一個(gè)ns3::WifiMac實(shí)例。用于支持創(chuàng)建以下類型的MAC實(shí)例:802.11ac-style Very High throughput (VHT) 和支持 QoS保證梧奢。這個(gè)對(duì)象與HtWifiMacHelper很相似狱掂。
WifiHelper
我們現(xiàn)在準(zhǔn)備創(chuàng)建WifiNetDevices.首先,讓我們創(chuàng)建一個(gè)默認(rèn)設(shè)置的WifiHelper:
WifiHelper wifiHelper = WifiHelper::Default ();
這一步都做了什么呢亲轨?它默認(rèn)設(shè)置802.11aWIFI標(biāo)準(zhǔn)趋惨,和設(shè)置ns3::ArfWifiManager作為RemoteStationManager。你可以通過調(diào)用WifiHelper::SetRemoteStationManager方法改變RemoteStationManager惦蚊。為了改變采用的wifi標(biāo)準(zhǔn)器虾,可以調(diào)用WifiHelper::SetStandard方法來設(shè)置想要的標(biāo)準(zhǔn)。
現(xiàn)在蹦锋,讓我們使用上面所描述的對(duì)象wifiPhyHelper和wifiMacHelper兆沙,安裝到在一系列節(jié)點(diǎn)“c”上的WifiNetDevices:
NetDeviceContainer wifiContainer = WifiHelper::Install (wifiPhyHelper, wifiMacHelper, c);
這樣就創(chuàng)建了一個(gè)WifiNetDevice,它包含WifiRemoteStationManager,WifiMac,WifiPhy(連接到匹配的WifiChannel上的)莉掂。
WifiHelper::SetStandard方法設(shè)置了定義在已選的標(biāo)準(zhǔn)版本中的可變的默認(rèn)的定時(shí)參數(shù)葛圃,可重寫已經(jīng)存在的或者已經(jīng)配置過的值。為了改變已經(jīng)給WifiHelper::SetStandard重寫的參數(shù),應(yīng)該在安裝后使用Config::Set來配置:
WifiHelper wifi = WifiHelper::Default ();
wifi.SetStandard (WIFI_PHY_STANDARD_80211n_2_4GHZ);
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode",
StringValue("HtMcs7"), "ControlMode",StringValue("HtMcs7"));
HtWifiMacHelper mac = HtWifiMacHelper::Default ();
//Install PHY and MAC
Ssid ssid = Ssid ("ns3-wifi");
mac.SetType ("ns3::StaWifiMac",
"Ssid", SsidValue (ssid),
"ActiveProbing", BooleanValue (false));
NetDeviceContainer staDevice;
staDevice = wifi.Install (phy, mac, wifiStaNode);
mac.SetType ("ns3::ApWifiMac",
"Ssid", SsidValue (ssid));
NetDeviceContainer apDevice;
apDevice = wifi.Install (phy, mac, wifiApNode);
//Once install is done, we overwrite the standard timing values
Config::Set ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/Slot", TimeValue (MicroSeconds (slot))
Config::Set ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/Sifs", TimeValue (MicroSeconds (sifs))
Config::Set ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/AckTimeout", TimeValue (MicroSeconds (
Config::Set ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/CtsTimeout", TimeValue (MicroSeconds (
Config::Set ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/Rifs", TimeValue (MicroSeconds (rifs))
Config::Set ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/BasicBlockAckTimeout", TimeValue (Micr
Config::Set ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/CompressedBlockAckTimeout", TimeValue
有許多ns3屬性可以被上面的helpers對(duì)象使用來改變默認(rèn)的行為装悲,例子腳本程序展示了如何改變默認(rèn)行為昏鹃。
Mobility configuration
最后尚氛,一個(gè)移動(dòng)模型必須在wifi device上進(jìn)行配置诀诊。移動(dòng)模型被用于計(jì)算傳播損耗和傳播時(shí)延。在下一節(jié)中提供了兩個(gè)例子阅嘶。用戶可以引用Mobility模塊一章獲取更多細(xì)節(jié)属瓣。
Example configuration
我們提供了兩個(gè)典型的配置wifi網(wǎng)絡(luò)的例子程序-一個(gè)例子程序使用adhoc網(wǎng)絡(luò),一個(gè)例子程序使用基礎(chǔ)設(shè)施網(wǎng)絡(luò)讯柔。兩個(gè)例子程序在examples/wireless目錄(wifi-simple-adhoc.cc 和 wifi-simple-infra.cc)抡蛙。鼓勵(lì)用戶學(xué)習(xí)examples/wireless目錄下的例子。
AdHoc WifiNetDevice configuration
在這個(gè)例子中魂迄,我們創(chuàng)建了兩個(gè)adhoc節(jié)點(diǎn)粗截,配置了802.11a wifi設(shè)備。我們使用ns3::ConstantSpeedPropagationDelayModel作為傳播延時(shí)模型捣炬,使用帶有3的指數(shù)的ns3::LogDistancePropagationLossModel作為傳播損耗模型熊昌。兩個(gè)設(shè)備都配置12Mbps固定速率的ConstantRateWifiManager。最后湿酸,我們使用ns3::ListPositionAllocator手動(dòng)放置節(jié)點(diǎn)位置:
std::string phyMode ("OfdmRate12Mbps");
NodeContainer c;
c.Create (2);
WifiHelper wifi;
wifi.SetStandard (WIFI_PHY_STANDARD_80211a);
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
// ns-3 supports RadioTap and Prism tracing extensions for 802.11
wifiPhy.SetPcapDataLinkType (YansWifiPhyHelper::DLT_IEEE802_11_RADIO);
YansWifiChannelHelper wifiChannel;
wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
wifiChannel.AddPropagationLoss ("ns3::LogDistancePropagationLossModel",
"Exponent", DoubleValue (3.0));
wifiPhy.SetChannel (wifiChannel.Create ());
// Add a non-QoS upper mac, and disable rate control (i.e. ConstantRateWifiManager)
NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
"DataMode",StringValue (phyMode),
"ControlMode",StringValue (phyMode));
// Set it to adhoc mode
wifiMac.SetType ("ns3::AdhocWifiMac");
NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, c);
// Configure mobility
MobilityHelper mobility;
Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
positionAlloc->Add (Vector (0.0, 0.0, 0.0));
positionAlloc->Add (Vector (5.0, 0.0, 0.0));
mobility.SetPositionAllocator (positionAlloc);
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install (c);
// other set up (e.g. InternetStack, Application)Infrastructure (access point and clients)
// WifiNetDevice configuration
這是一個(gè)典型的代碼婿屹,展示了用戶如何配置一個(gè)接入點(diǎn)AP和一系列客戶端。在這個(gè)例子中推溃,我們創(chuàng)建一個(gè)接入點(diǎn)和兩個(gè)客戶端昂利。每一個(gè)節(jié)點(diǎn)配置802.11bwifi設(shè)備:
std::string phyMode ("DsssRate1Mbps");
NodeContainer ap;
ap.Create (1);
NodeContainer sta;
sta.Create (2);
WifiHelper wifi;
wifi.SetStandard (WIFI_PHY_STANDARD_80211b);
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
// ns-3 supports RadioTap and Prism tracing extensions for 802.11
wifiPhy.SetPcapDataLinkType (YansWifiPhyHelper::DLT_IEEE802_11_RADIO);
YansWifiChannelHelper wifiChannel;
// reference loss must be changed since 802.11b is operating at 2.4GHz
wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
wifiChannel.AddPropagationLoss ("ns3::LogDistancePropagationLossModel",
"Exponent", DoubleValue (3.0),
"ReferenceLoss", DoubleValue (40.0459));
wifiPhy.SetChannel (wifiChannel.Create ());
// Add a non-QoS upper mac, and disable rate control
NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
"DataMode",StringValue (phyMode),
"ControlMode",StringValue (phyMode));
// Setup the rest of the upper mac
Ssid ssid = Ssid ("wifi-default");
// setup ap.
wifiMac.SetType ("ns3::ApWifiMac",
"Ssid", SsidValue (ssid));
NetDeviceContainer apDevice = wifi.Install (wifiPhy, wifiMac, ap);
NetDeviceContainer devices = apDevice;
// setup sta.
wifiMac.SetType ("ns3::StaWifiMac",
"Ssid", SsidValue (ssid),
"ActiveProbing", BooleanValue (false));
NetDeviceContainer staDevice = wifi.Install (wifiPhy, wifiMac, sta);
devices.Add (staDevice);
// Configure mobility
MobilityHelper mobility;
Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
positionAlloc->Add (Vector (0.0, 0.0, 0.0));
positionAlloc->Add (Vector (5.0, 0.0, 0.0));
positionAlloc->Add (Vector (0.0, 5.0, 0.0));
mobility.SetPositionAllocator (positionAlloc);
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install (ap);
mobility.Install (sta);
// other set up (e.g. InternetStack, Application)
33.2.2 Note on the current implementation
? 802.11g supports a default of long slot time (20 microseconds)
? PHY_RXSTART is not supported
? 802.11e TXOP is not supported
? 802.11n/ac MIMO is not supported
? 802.11n/ac beamforming is not supported
? PLCP preamble reception is not modeled
? BSSBasicRateSet for 802.11b has been assumed to be 1-2 Mbit/s
? BSSBasicRateSet for 802.11a/g has been assumed to be 6-12-24 Mbit/s
? cases where RTS/CTS and ACK are transmitted using HT formats are not supported
? Only ConstantRateWifiManager is supported by 802.11n or 802.11ac