首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > UNIXLINUX >

ns3仿真ad hoc代码失误

2013-09-24 
ns3仿真ad hoc代码出错intmain (int argc, char *argv[]){LogComponentEnable (UdpEchoClientApplication

ns3仿真ad hoc代码出错
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;
} ns3
[解决办法]
不知道啊!!

热点排行