Ethan-J’s
往期整理
  •   历史归档
  •   文章分类
  •   文章标签
English
Ethan
Article
10
Category
5
Tags
3
往期整理
历史归档
文章分类
文章标签
English
WiFi 组网
NS-3 仿真
Post on: 2024-9-26
Last edited: 2025-2-6
Views
开发
type
status
date
slug
summary
tags
category
icon
password

1. NS-3 安装

1.1 安装 NS-3

  1. 下载 NS3
官方提供了多种下载和构建方式Installation guide,这里用 git 下载:
  1. 构建 NS3
  1. 跑案例

1.2 安装可视化工具

NS3 有两种可视化工具:PyVis 和 NetAnim。

1.2.1 PyVis

由于python-bindings 无法在 M1/M2 芯片的 macOS 计算机上运行,跑 ubuntu 虚拟机也不行,macOS 只能用 Netanim 来可视化。对于 linux 系统,可以参考 ns3—可视化工具_ns3可视化-CSDN博客 配置。
notion image

1.2.2 NetAnim

1.2.2.1 安装依赖

MacOS

先切换 Homebrew 的源为国内源,以清华为例
安装 QT5

Ubuntu

需要用 ubuntu 默认源,使用国内源的话很多包找不到。

1.2.2.2 安装 NetAnim

1.2.2.3 NetAnim 示例

以 ns-3.40/src/netanim/examples/wireless-animation.cc 为例,首先需要引用头文件:
在 Run 之前加上如下代码(其中UpdateNodeImage为更新节点图标,需要准备 png 文件,如不需要可以不用更新节点图标):
notion image

官方文档

ns-3: Netanim
ns-3: Wifi Models
ns-3: Mesh Device

2 NS3 组件介绍

2.1 WiFi 模块

34. Wi-Fi Module — Model Library

2.1.1 WIFI 模块架构图

notion image
notion image

2.1.2 WIFI 模块创建方式

模块
必须
可选
NodeContainer
NodeContainer wifiStaNode; wifiStaNode.Create(10); NodeContainer wifiApNode; wifiApNode.Create(1);
ㅤ
WifiChannel
YansWifiChannelHelper channel = YansWifiChannelHelper::Default();
ㅤ
WifiPhy
YansWifiPhyHelper phy = YansWifiPhyHelper::Default(); phy.SetChannel(channel.Create());
pcap 跟踪:YansWifiPhyHelper::SetPcapDataLinkType(enum SupportedPcapDataLinkTypes dlt)MIMO 天线、空间流 配置:wifiPhyHelper.Set(“Antennas”, UintegerValue(4)); wifiPhyHelper.Set(“MaxSupportedTxSpatialStreams”, UintegerValue(4)); wifiPhyHelper.Set(“MaxSupportedRxSpatialStreams”, UintegerValue(4));信道、带宽、频率、主 20MHz 配置:TupleValue<UintegerValue, UintegerValue, EnumValue, UintegerValue> value; value.Set(WifiPhy::ChannelTuple {38, 40, WIFI_PHY_BAND_5GHZ, 0}); wifiPhyHelper.Set(“ChannelSettings”, value);全局默认信道配置:Config::SetDefault(“ns3::WifiPhy::ChannelSettings”, StringValue(“{38, 40, BAND_5GHZ, 0}”));
Wifi
WifiHelper wifi; wifi.SetStandard(WIFI_STANDARD_80211ax);
固定速率模式:wifi.SetRemoteStationManager(“ns3::ConstantRateWifiManager”, </font>“DataMode”, StringValue(“HeMcs11”), “ControlMode”, StringValue(“HeMcs0”));OBSS PD:wifi.SetObssPdAlgorithm(“ns3::ConstantObssPdAlgorithm”, “ObssPdLevel”, DoubleValue(-72.0));默认应答策略选择器wifi.SetAckPolicySelectorForAc(AC_BE, “ns3::ConstantWifiAckPolicySelector”, “BaThreshold”, DoubleValue(0.5));
Ssid
Ssid ssid = Ssid(“ns3-wifi”);
ㅤ
WifiMac
WifiMacHelper mac;
DL/UL OFDMAwifiMacHelper.SetMultiUserScheduler(“ns3::RrMultiUserScheduler”, “EnableUlOfdma”, BooleanValue(true), “EnableBsrp”, BooleanValue(false));
NetDeviceContainer
NetDeviceContainer wifiStaDevices; NetDeviceContainer wifiApDevice; mac.SetType(“ns3::StaWifiMac”, “Ssid”, SsidValue(ssid), “ActiveProbing”, BooleanValue(false)); wifiStaDevices = wifi.Install(phy, mac, wifiStaNodes); mac.SetType(“ns3::ApWifiMac”, “Ssid”, SsidValue(ssid)); wifiApDevice = wifi.Install(phy, mac, wifiApNode);
APmac.SetType(“ns3::ApWifiMac”, “Ssid”, SsidValue(ssid), “QosSupported”, BooleanValue(true), “BeaconGeneration”, BooleanValue(true), “BeaconInterval”, TimeValue(Seconds(2.5)));STAmac.SetType(“ns3::StaWifiMac”, “Ssid”, SsidValue(ssid), “VO_MaxAmpduSize”, UintegerValue(65535), “BE_MaxAmsduSize”, UintegerValue(7935), “ActiveProbing”, BooleanValue(false));
Mobility
Ptr positionAlloc = CreateObject(); positionAlloc->Add(Vector(0.0, 0.0, 0.0)); mobility.SetPositionAllocator(positionAlloc); mobility.SetMobilityModel(“ns3::ConstantPositionMobilityModel”); mobility.Install(c);
ㅤ
其他
ㅤ
Short GI 支持:Ptr nd = wifiStaDevices.Get(0); Ptr wnd = nd->GetObject(); Ptr htConfiguration = wnd->GetHtConfiguration(); htConfiguration->SetShortGuardIntervalSupported(true);或者Config::Set(“/NodeList//DeviceList//$ns3::WifiNetDevice/HtConfiguration/ShortGuardIntervalSupported”, BooleanValue(true));

2.1.3 错误率模型

WiFi 模块有四种错误率模型:
1. ns3::TableBasedErrorRateModel: 用于OFDM模式,并复用ns3::DsssErrorRateModel用于802.11b模式。这是802.11n/ac/ax的默认选项。
2. ns3::YansErrorRateModel: 用于OFDM模式,并复用ns3::DsssErrorRateModel用于802.11b模式。这是802.11a/g的默认选项。
3. ns3::DsssErrorRateModel: 包含用于802.11b模式的模型。802.11b 1 Mbps和2 Mbps的错误模型基于经典的调制分析。如果安装了GNU科学库(GSL),则使用[pursley2009]的5.5 Mbps和11 Mbps用于CCK调制;否则,使用备用的基于MATLAB的CCK模型的结果。
  1. ns3::NistErrorRateModel
    1. : 用于OFDM模式,并复用ns3::DsssErrorRateModel用于802.11b模式。
其中,ns3::TableBasedErrorRateModel现在是 ns-3 用于 802.11n/ac/ax 的默认选项,而 ns3::YansErrorRateModel 是 ns-3 用于 802.11a/g 的默认选项。
与基于错误边界的分析错误模型不同,ns3::TableBasedErrorRateModel 包含了用于 AWGN 信道的端到端链路模拟表格(PER vs SNR)。由于生成所有所需的数据包大小和输入 SNR 的查找表是不可行的,我们采用了 IEEE P802.11 TGax [porat2016] 的建议,该建议提出使用 BCC FEC 编码通过推断两个参考长度的结果来估算任何所需数据包长度的 PER:分别是 32(所有长度小于 400)字节和 1458(所有长度大于或等于 400)字节。在 LDPC FEC 编码的情况下,IEEE P802.11 TGax 建议使用单个参考长度。因此,我们为每种调制和编码方案提供了两个用于 BCC 的表和一个用于 LDPC 的表,这些表是使用可靠且公开可用的商业链路模拟器(MATLAB WLAN 工具箱)生成的。请注意,BCC 表限于 MCS 9。对于更高的 MCS,模型将回退到使用 YANS 分析模型。
验证场景设置如下:
● 理想的信道和完美的信道估计。
● 完美的数据包同步和检测。
● 不考虑相位跟踪、相位校正、相位噪声、载频频偏、功率放大器非线性等。
● 模拟链路上的多个数据包以获得 PER,需要的数据包数量是通过考虑到估计错误与真实值的比率应在 10% 以内,概率为 0.95 来计算的。对于每个 SNR 值,模拟运行直到模拟了总共 40000 个数据包
获得的结果与 TGax 曲线非常接近,如图所示,表格基础的 OFDM 错误模型与 TGax 结果的比较。
notion image

2.1.4 WiFi 干扰

开发仿真脚本过程中,涉及 WiFi 干扰遇到的以下几个问题,已和 ns3 开发者求证:
● 要引入 WiFi 干扰的计算,多个 AP 必须使用同一 SpectrumWifiPhy/SpectrumChannel;
● 使用同一 SpectrumWifiPhy/SpectrumChannel 时,Global Routing 无法正常工作,需要使用 Nix-vector Routing 来配置路由;
● 在不引入非 WiFi 干扰源时, SpectrumWifiPhy 可视为等同于 YansWifiPhy;
notion image

2.1.5 传播模型

28. Propagation — Model Library
● Cost231PropagationLossModel
● FixedRssLossModel
● FriisPropagationLossModel
● ItuR1411LosPropagationLossModel
● ItuR1411NlosOverRooftopPropagationLossModel
● JakesPropagationLossModel
● Kun2600MhzPropagationLossModel
● LogDistancePropagationLossModel
● MatrixPropagationLossModel
● NakagamiPropagationLossModel
● OkumuraHataPropagationLossModel
● RandomPropagationLossModel
● RangePropagationLossModel
● ThreeLogDistancePropagationLossModel
● TwoRayGroundPropagationLossModel
● ThreeGppPropagationLossModel

3 江南村仿真脚本

3.1 拓扑可视化

notion image

3.2 参数介绍

3.3 运行示例

  • Author:Ethan
  • URL:https://zheyu.ink/article/ns-3
  • Copyright:All articles in this blog, except for special statements, adopt BY-NC-SA agreement. Please indicate the source!
Relate Posts
RAG
Wi-Fi 自组网方案调研
系统日志接入
空口抓包Redmi AX6 OpenWRT 刷机
Loading...
Catalog
0%
1. NS-3 安装1.1 安装 NS-31.2 安装可视化工具1.2.1 PyVis1.2.2 NetAnim1.2.2.1 安装依赖MacOSUbuntu1.2.2.2 安装 NetAnim1.2.2.3 NetAnim 示例官方文档2 NS3 组件介绍2.1 WiFi 模块2.1.1 WIFI 模块架构图2.1.2 WIFI 模块创建方式2.1.3 错误率模型2.1.4 WiFi 干扰2.1.5 传播模型3 江南村仿真脚本3.1 拓扑可视化3.2 参数介绍3.3 运行示例
Ethan
Ethan
一个博客
Article
10
Category
5
Tags
3
Latest posts
ai-hedge-fund 各 Agent 处理逻辑
ai-hedge-fund 各 Agent 处理逻辑
2025-3-24
NS-3 仿真
NS-3 仿真
2025-2-6
付鹏《2024 年终回顾和 2025 年展望 —— 对冲风险 VS 软着陆》
付鹏《2024 年终回顾和 2025 年展望 —— 对冲风险 VS 软着陆》
2024-12-2
RAG
RAG
2024-9-26
系统日志接入
系统日志接入
2024-9-26
Redmi AX6 OpenWRT 刷机
Redmi AX6 OpenWRT 刷机
2024-9-26
Announcement
 
 
Catalog
0%
1. NS-3 安装1.1 安装 NS-31.2 安装可视化工具1.2.1 PyVis1.2.2 NetAnim1.2.2.1 安装依赖MacOSUbuntu1.2.2.2 安装 NetAnim1.2.2.3 NetAnim 示例官方文档2 NS3 组件介绍2.1 WiFi 模块2.1.1 WIFI 模块架构图2.1.2 WIFI 模块创建方式2.1.3 错误率模型2.1.4 WiFi 干扰2.1.5 传播模型3 江南村仿真脚本3.1 拓扑可视化3.2 参数介绍3.3 运行示例
2024-2025 Ethan.

Ethan-J’s | 一个博客

Powered by NotionNext 4.7.2.