ns3仿真ad hoc代码出错

yuxiaolong360 2013-09-04 09:16:14
int
main (int argc, char *argv[])
{
LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);

NodeContainer adHocNodes;
adHocNodes.Create (30);
//配置物理层和信道,都使用默认值。
YansWifiPhyHelper wifiPhy;
wifiPhy= YansWifiPhyHelper::Default ();
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
wifiPhy.SetChannel (wifiChannel.Create ());
//物理拓扑层配置完后,关注 MAC 层,选择的是 AdHocWifiMac.
WifiHelper wifi;
wifi.SetMac ("ns3::AdHocWifiMac");--->出错了
wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager","DataMode",StringValue("wifia-**mbs"));//告诉拓扑使用的速率控制算法的类型,这里使用的是恒定速率是**Mbs的算法。
//网络设备 所有的参数全部配置完后,可以调用 Install 来安装 adHoc 网络设备。
NetDeviceContainer adHocDevices = wifi.Install (wifiPhy, mac, adHocNodes);
InternetStackHelper internet; //使用InternetStack 拓扑来添加栈。
internet.Install (adHocNodes);

//Ipv4 地址分配 使用 Ipv4AddressHelper 来分配 IP 地址给设备接口。
Ipv4AddressHelper address;
address.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer adHocInterfaces;
adHocInterfaces = address.Assign (adHocDevices);

//移动场景 初始点的位置
MobilityHelper mobility;
mobility.SetPositionAllocator ("ns3::GridPositionAllocator","MinX", DoubleValue (0.0),"MinY", DoubleValue (0.0),"DeltaX", DoubleValue (5.0),"DeltaY", DoubleValue (5.0),"GridWidth", UintegerValue (10),"LayoutType", StringValue ("RowFirst"));

//告诉他们该怎样移动
mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel","Bounds", RectangleValue(Rectangle(-500, 500, -500, 500)));

//用 MobilityHelper 加载 mobility model 到 Ad Hoc 节点上
mobility.Install (adHocNodes);

//路由协议 AODV
NS_LOG_INFO ("Enabling AODV routing on all adHoc nodes");
AodvHelper aodv;
aodv.Install (adHocNodes);--->出错了

//创建 TCP 接收机
uint16_t port = 9999;
OnOffHelper onoff1 ("ns3::TcpSocketFactory",Address(InetSocketAddress (adHocInterfaces.GetAddress (0), port)));
onoff1.SetAttribute ("OnTime", RandomVariableValue(ConstantVariable (1)));
onoff1.SetAttribute ("OffTime", RandomVariableValue(ConstantVariable (0)));

//
ApplicationContainer apps1 = onoff1.Install (adHocNodes);

//开始产生和停止 traffic
apps1.Start (Seconds (1.0));
apps1.Stop (Seconds (500.0));

//采用 PacketSink 拓扑器
PacketSinkHelper sink ("ns3::TcpSocketFactory", InetSocketAddress
(Ipv4Address::GetAny (), port));
apps1 = sink.Install (adHocNodes.Get (0));
apps1.Start (Seconds (0.0));
apps1.Stop (Seconds (500.0));

//
NS_LOG_INFO ("Configure Tracing.");

//生成 trace 文件 输出为 ASCII 的 trace 文件
std::ofstream ascii;
ascii.open("adHoc_30node_test.tr");
YansWifiPhyHelper::EnableAsciiAll (ascii);--->出错了
MobilityHelper::EnableAsciiAll (ascii);--->出错了
YansWifiPhyHelper::EnablePcapAll ("adHoc_30node_test");
//Simulator 模拟
NS_LOG_INFO ("Run Simulation.");
Simulator::Stop (Seconds (500.0));
Simulator::Run ();
Simulator::Destroy ();

return 0;
}
...全文
225 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
1213333 2013-09-21
  • 打赏
  • 举报
回复
不知道啊!!

23,120

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧