NS3仿真—WIFI无线网络:third脚本
简介:
使用NS3搭建一个无线网络,模拟一个包含点对点(ppp)和CSMA有线网络,以及WIFI无线网络的混合场景。
要把执行的third.cc文件复制到scratch目录中
third源文件存放在ns-allinone-3.31/ns-3.31/examples/tutorial/third.cc
cp examples/tutorial/third.cc scratch/third.cc
执行third.cc
sudo ./waf
运行third.cc协议
sudo ./waf --run scratch/third
使用Netnaim实现仿真
在third.cc中增加一个头文件
#include "ns3/netanim-module.h"
生成文件名为third.xml的xml格式的追踪文件
在脚本程序的Simulator::Run()代码前添加如下代码
AnimationInterface anim("third.xml");
使用一下命令打开third.cc的源文件
sudo vim third.cc
使用waf来执行脚本
sudo ./waf
运行该脚本
sudo ./waf --run scratch/third
运行成功以后,在ns-3目录中会生成third.xml文件
运行NetAnim,读取XML数据
进入NetAnim目录,执行以下命令
cd ns-allinone-3.31
cd netanim-3.108
在netanim-3.108目录下运行
./NetAnim
可以看到以下界面
单击打开文件按钮,打开third.xml文件
#include "ns3/core-module.h" //core模块
#include "ns3/point-to-point-module.h"//point-to-point模块
#include "ns3/network-module.h"//network模块
#include "ns3/applications-module.h"//applications模块
#include "ns3/mobility-module.h" //移动模块
#include "ns3/csma-module.h" //CSMA模块
#include "ns3/internet-module.h" //internet模块
#include "ns3/yans-wifi-helper.h" //wifi模块
#include "ns3/ssid.h"
// Default Network Topology
//
// Wifi 10.1.3.0
// AP
// * * * *
// | | | | 10.1.1.0
// n5 n6 n7 n0 -------------- n1 n2 n3 n4
// point-to-point | | | |
// ================
// LAN 10.1.2.0
using namespace ns3;
//打印辅助信息
NS_LOG_COMPONENT_DEFINE ("ThirdScriptExample");
int
main (int argc, char *argv[])
{