@ns3中多信道的选择
信道选择操作
在ns3中,mesh设备支持多信道技术。mesh设备选择特定编号的信道操作如下:
1. NodeContainer c;
2. //NodeCache存储有NodeId、RadioId(接口Id)
3. NodeCache nodeCache;
4.
5. uint16_t nodeId = nodeCache.getNodeId();
6. Ptr<Node> node = c.Get(nodeId);
7. Ptr<MeshPointDevice> mp = node->GetDevice(0); //单个节点对应单个设备
8. uint16_t radioId = nodeCache.getRadioId();
9. Ptr<WifiNetDevice> interface = mp->GetInterface(radioId);
10. Ptr<MeshWifiInterfaceMac> mac = interface.GetMac();
11. mac.SwitchFrequencyChannel(nodeCache.getChannelId());
802.11a标准下可用信道的数目
我们可以看到信道的选择是基于channelId的,那么不同channelId对应怎么样的信道呢?我们可以src/wifi/model/wifi-phy.cc找到答案。
在wifi-phy.cc的第53-152行,我们可以看到一个列表,元项包含两个元素,第一个为(channelId,wifi_standard),另一个为(channel_frequency,channel_width)。
根据此表我们可得
Channel_width/MHz | Channel_num |
---|---|
10 | 7 |
20 | 42 |
40 | 14 |
80 | 7 |
160 | 3 |
total | 75 |
上表标题左侧为信道带宽,右侧为该信道带宽下所拥有的信道数目。
在mesh网络中,我们一般选择WIFI_PHY_STANDARD_80211a作为wifi_standand,该标准在wifi-phy.cc中对应的是WIFI_PHY_STANDARD_UNSPECIFIED。
在wifi-phy.cc中,我们可以查到其配置wifi_standand的代码如下:
1. void
2. WifiPhy::ConfigureDefaultsForStandard (WifiPhyStandard standard)
3. {
4. NS_LOG_FUNCTION (this << standard);
5. switch (standard)
6. {
7. case WIFI_PHY_STANDARD_80211a:
8. SetChannelWidth (20);
9. SetFrequency (5180);
10. // Channel number should be aligned by SetFrequency () to 36
11. NS_ASSERT (GetChannelNumber () == 36);
12. break;
13. ...
14. }
15. }
从WIFI_PHY_STANDARD_80211a的配置条件中,我们可知该标准的带宽为20MHz。
最终可知,WIFI_PHY_STANDARD_80211a可用的多信道有42个,如下所示:
1. uint32_t channel_num_80211a[42] = {
2. 1,2,3,4,5,6,7,8,9,10,11,12,13
3. 36,40,44,48,52,56,60,64,
4. 100,104,108,112,116,120,124,128,132,136,140,144,
5. 149,153,157,161,165,169,173,177,181};