NS3-WIFI模块架构与使用

NS3 模块架构

wifi部分的组织架构图如下所示,
在这里插入图片描述
下面对图中所示的若干个重要类的实现及其功能进行简要介绍[1]

  • WiFiNetDevice: 该类与node类类似,都不具备任何协议行为,该类是 Wi-Fi网络设备与上层协议通信的接口。可以将其看作网络层与 WifiMac之间的通信接口。
  • WifiMac: Wi-Fi协议的 MAC层实现。支持功能包括关联(association)、探测(probe)、信标(beacon)、分组重传、RTS与CTS消息等。
  • RemoteStationManager:速率控制(rate control),根据网络环境选择最佳数据速率(data rate)。
  • WifiPhy: Wi-Fi协议的物理层实现。支持功能包括计算发射功率、传输延迟、接收功率阈值等。
  • Channel:模拟Wi-Fi信道,也属于物理层的一部分。结合传播(propagation)和移动(mobility)模型,Channel负责计算一个分组的接收功率、传播延迟等变量。

src文件功能简析

// AMPDU stands for Aggregated MAC Protocol Data Unit
    // 头文件
    // crc, sig, length 域
ampdu-subframe-header.cc
ampdu-tag.cc
    // ack 相关的报文头
ctrl-headers.cc
    

    // The 16-bit Capability Information field (Figure 4-24) is used in Beacon transmissions to advertise the network's capabilities.
capability-information.cc
    
    // The ErpInformation Information Element
erp-information.cc
    
    // wifi 误差模型的接口
error-rate-model.cc
    // The HT Capabilities section provides the MCS values which are supported by the wireless network。
    // 无线网络 MCS 相关
ht-capabilities.cc
ht-operations.cc
    
    // handles interference calculations
    // 例如 snr,
interference-helper.cc
    // 连接请求与连接回复 的报文头部管理
	// 调用 ssid, vht, dsss等文件
mgt-headers.cc
    
	// MAC Protocol Data Unit
    // 帧聚合方式
    // MDPU包含了MAC层头部以及MSDU。
mpdu-aggregator.cc
mpdu-standard-aggregator.cc
msdu-aggregator.cc
msdu-standard-aggregator.cc
    
    // dsss modulation
nist-error-rate-model.cc
    // 块确认的管理部分
originator-block-ack-agreement.cc
    
    // 块确认的等待部分
qos-blocked-destinations.cc
    // 各种配置参数
qos-utils.cc
    
random-stream.cc
    // 信噪比相关
    // 由 mac-low.h 调用
snr-tag.cc
    
	 // association response.
    // 连接状态的查询与回复
status-code.cc
	// 
    //  The IEEE 802.11 SSID Information Element
ssid.cc
    
	 // 重要类, 定义了一系列类似于枚举变量 的浮点数列
    // all Information Element IDs 代表了, 802.11 -2007 中的所有所需元素
    // 例如, IE_SSID
wifi-information-element.cc
    // Information element vector
wifi-information-element-vector.cc
    
    // 所有mac协议的基类
    // 封装了下层DCA, EDCA等机制。封装了各种high mac机制
wifi-mac.cc
	// 不同的wifi 模式
    // class RegularWifiMac : public WifiMac
    // 封装了各种功能
regular-wifi-mac.cc
	// 
adhoc-wifi-mac.cc
    // 封装了 探测, 信息队列等功能。
sta-wifi-mac.cc
    // class ApWifiMac : public RegularWifiMac
    // 提供了连接, 断开, 认证。等基本服务
    // basic service set. BSS
ap-wifi-mac.cc    

	// mac层机制实现
    // 重传, rts/cts探测机制
dca-txop.cc
    // 分布式协同功能
dcf.cc
    // trace dcf 的状态
dcf-state.cc
    // Enhanced Distributed Channel Access
    // edca 机制相关设置
edca-parameter-set.cc
    // low mac, txop相关控制
edca-txop-n.cc
    // control how a packet is transmitted.
    // 封装了: 块确认,
mac-low.cc
    // duplicate detection and recomposition of fragments.
mac-rx-middle.cc
    // sequence numbering of IEEE 802.11 data frames
mac-tx-middle.cc
    
    // mac header
wifi-mac-header.cc
    // extern template class
    // 报文排队模块,由 high mac 发送至 txop
    // 记录报文开始准备发送的时间
    // 
wifi-mac-queue.cc
    // Implements the IEEE 802.11 MAC trailer
wifi-mac-trailer.cc
    
    //  represent a single transmission mode
    // 有一个int数代表。
wifi-mode.cc
    
    // This class holds together ns3::Channel, ns3::WifiPhy,
    // ns3::WifiMac, and, ns3::WifiRemoteStationManager.
wifi-net-device.cc

    // 帧交换管理器
    // 块确认机制
    // 
block-ack-agreement.cc
block-ack-cache.cc
block-ack-manager.cc    
    
    
    //  A WiFi radio energy model.
    // 物理层一般都有一个listen类
    // listen类监听manager给出的信息
wifi-radio-energy-model.cc
    
    // manager 部分
    // AARF Rate control algorithm
aarfcd-wifi-manager.cc
aarf-wifi-manager.cc
    // AMRR Rate control algorithm
amrr-wifi-manager.cc
    // APARF Power and rate control algorithm
aparf-wifi-manager.cc
    // ARF Rate control algorithm
arf-wifi-manager.cc
    // Manages all block ack agreements for an originator station.
block-ack-manager.cc
    // CARA rate control algorithm
cara-wifi-manager.cc
    // use constant rates for data and RTS transmissions
constant-rate-wifi-manager.cc
    // Manage a set of ns3::DcfState
dcf-manager.cc
    // 速率控制
ideal-wifi-manager.cc
    // MinstrelHt is a rate adaptation algorithm for high-throughput
minstrel-ht-wifi-manager.cc
    // Minstrel Rate Control Algorithm
minstrel-wifi-manager.cc
    // rate control algorithm 
onoe-wifi-manager.cc
    // PARF Rate control algorithm
parf-wifi-manager.cc
    // Robust Rate Adaptation Algorithm
    // 鲁棒性的 速率算法
rraa-wifi-manager.cc
    // Tid independent remote station statistics
    // A struct that holds information about each remote station.
wifi-remote-station-manager.cc
    
    // 定义了报文类型
    // 供给调用
wifi-channel.cc
    // 信息发送相关信息
    // 包括, txPowerDbm, power amplifier efficiency(ETA), 电压等信息 
wifi-tx-current-model.cc
    // tx-vector
    // 发送消息设置信息的容器之类的?
    // 内部包括了 wifi 模式,前缀码
    // 
wifi-tx-vector.cc
    
    // 各种噪声模型
    // 802.11 PHY layer model
wifi-phy.cc
wifi-phy-state-helper.cc
wifi-phy-tag.cc
    // 前缀码,The type of preamble to be used by an IEEE 802.11 transmission
    // 代表不同的报文, 如:
    // long, short, 初始802.11 DSSS以及802.11b中才有的概念
    // HT_MF, HT_GF.
    // HE_SU, HE_ER_SU
wifi-preamble.h

        // The Extended Supported Rates Information Element
supported-rates.cc    
    // VHT is the PHY for 802.11ac/WiFi 5. So VHT refers to 802.11ac.
    // The VHT Operation Information Element
vht-capabilities.cc
vht-operation.cc
    
    //  an implementation of DSSS error rate model
    // DSSS: Direct sequence spread spectrum 
dsss-error-rate-model.cc
dsss-parameter-set.cc
    // 两种物理层
    // spectrum模拟信号的频率分解的同时可以
    // 在一个信道上不仅仿真wifi还可以加个蓝牙 zigbee等同频协议
spectrum-wifi-phy.cc
wifi-spectrum-phy-interface.cc
wifi-spectrum-signal-parameters.cc

    
    // yans是基本的物理层功能,仿真的对象就是包的错误率
yans-error-rate-model.cc
yans-wifi-channel.cc
yans-wifi-phy.cc

脚本编写与简析

选取ns3的aodv.cc作为示例脚本

  WifiHelper wifi;

// 设置两个助手类, 为MAC, PHY的安装提供帮助
  WifiMacHelper wifiMac;
  YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
  // 为wifiPhy设置相关信道(yansWifiChannel)
  YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
  wifiPhy.SetChannel (wifiChannel.Create ());
  
  Ssid ssid = Ssid ("wifi-default");
  // 速率控制
  wifi.SetRemoteStationManager ("ns3::ArfWifiManager");
  // setup stas.
  wifiMac.SetType ("ns3::StaWifiMac",
                   "Ssid", SsidValue (ssid));
                   
  staDevs = wifi.Install (wifiPhy, wifiMac, stas);
  // setup ap.
  wifiMac.SetType("ns3::AdhocWifiMac");
   // wifi助手类提供将phy,mac相关参数绑定到节点上的函数
  wifi.Install (wifiPhy, wifiMac, ap);

物理层的其他可用类如下
在这里插入图片描述
wifi的可用模式有AP,STA,ADHOC等, 可以用WiFiMacHelper的SetType()函数指定

mac.setType("ns3::StaWifiMac", ...);
mac.setType("ns3::ApWifiMac", ...);
mac.setType("ns3::AdhocWifiMac", ...);

设置协议栈。该过程指定路由协以及相关的IP地址

  // 协议栈
  NS_LOG_INFO("STACK INSTALL");
  AodvHelper aodv;
  
  // you can configure AODV attributes here using aodv.Set(name, value)
  InternetStackHelper stack;
  stack.SetRoutingHelper(aodv); // has effect on the next Install ()
  stack.Install(nodes);
  // ip地址分配
  Ipv4AddressHelper address;
  address.SetBase("10.0.0.0", "255.0.0.0");
  // 如果想要更加灵活的分配地址,可以使用迭代器对devices中的所有元素进行单独操作
  interfaces = address.Assign(devices);

应用层协议

  NS_LOG_INFO("APP INSTALL");
  // 指定了ping的对象
  V4PingHelper ping(interfaces.GetAddress(size - 1));\
  // 所有helper都有类似的对于typeid中参数设置的成员函数
  ping.SetAttribute("Verbose", BooleanValue(true));
    // 该部分设置了ping程序的执行方
  ApplicationContainer p = ping.Install(nodes.Get(0));
  p.Start(Seconds(0));
  p.Stop(Seconds(totalTime) - Seconds(0.001));

在这里插入图片描述

参考文献

[1] 周迪之.开源网络模拟器ns­3架构与实践[M].机械工业出版社,2018,115­128

  • 5
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ko no 辉夜 da

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值