赞
踩
ps:本文所有文件和目录的默认根目录均为ns-3.29/。
正如在构建点到点拓扑时看到的点到点拓扑和CSMA拓扑助手对象一样,将在本节中看到等效的WiFi拓扑助手。
在examples/tutorial目录中提供了一个示例脚本。此脚本建立在second.cc脚本的基础上,并添加Wi-Fi网络。
该脚本默认拓扑结构如下:
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
n0和n1实现点到点通信(与first.cc中相似),n1~n4是个CSMA有线局域网(与second.cc中相似)。如图左侧所示,我们创建了许多无线STA(station)节点来填充新的10.1.3.0网络,向点到点链接左侧的节点n0添加一个新的网络设备,该点为无线接入点AP。
#include "ns3/core-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/network-module.h"
#include "ns3/applications-module.h"
#include "ns3/mobility-module.h" //移动模块
#include "ns3/csma-module.h" //CSMA模块
#include "ns3/internet-module.h"
#include "ns3/yans-wifi-helper.h" //Wi-Fi模块
#include "ns3/ssid.h" //SSID模块
SSID是Service Set Identifier的缩写,意思是:服务集标识。SSID技术可以将一个无线局域网分为几个需要不同身份验证的子网络,每一个子网络都需要独立的身份验证,只有通过身份验证的用户才可以进入相应的子网络,防止未被授权的用户进入本网络。
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("ThirdScriptExample");
int
main (int argc, char *argv[])
{
…
}
主程序和second.cc一样,通过添加一些命令行参数来启用或禁用日志记录组件以及更改创建的设备数量来启动。
//定义bool变量,用于决定是否开启2个UdpApplication的Logging日志组件,默认true开启 bool verbose = true; uint32_t nCsma = 3;//变量,用于定义csma网络中额外有多少个node,此处为3 uint32_t nWifi = 3;//变量,用于定义wifi网络中有多少个station node,此处为3 bool tracing = false;//若要开启跟踪文件,则需改为true CommandLine cmd;//命令行 cmd.AddValue ("nCsma", "Number of \"extra\" CSMA nodes/devices", nCsma); //“nCsma”参数控制着脚本中CSMA网络中额外节点的数量,其对应的C++同名变量是非整型数nCsma cmd.AddValue ("nWifi", "Number of wifi STA devices", nWifi); //同样地,“nWifi”参数控制着脚本中WIFI网络中STA节点的数量 cmd.AddValue ("verbose", "Tell echo applications to log if true", verbose); //“verbose”参数设置是否开启logging cmd.AddValue ("tracing", "Enable pcap tracing", tracing); cmd.Parse (argc,argv);
18的底层限制是由于网格位置分配器的配置,如果提供的节点超过18个,网格布局将超过边界框。
if (nWifi > 18)
{
std::cout << "nWifi should be 18 or less; otherwise grid layout exceeds the bounding box" << std::endl;
return 1;
}
if (verbose)
{
LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
}
//创建使用P2P链路的两个节点
NodeContainer p2pNodes;
p2pNodes.Create (2);
PointToPointHelper pointToPoint;//PPP信道助手类
//配置PPP信道属性
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));//传输速率属性
pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));//传播迟延属性
//安装P2P网卡到P2P网络节点
NetDeviceContainer p2pDevices;//创建网络设备
p2pDevices = pointToPoint.Install (p2pNodes);//连接节点与信道
//创建csma网络节点
NodeContainer csmaNodes;
csmaNodes.Add (p2pNodes.Get (1));//将P2P的节点1加到CSMA网络中
csmaNodes.Create (nCsma);//再创建额外的3个节点
CsmaHelper csma;//CSMA信道助手类
//设置CSMA传输速率和传播延
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。