当前位置:  技术问答>linux和unix

ns3仿真ad hoc代码出错

    来源: 互联网  发布时间:2017-04-25

    本文导语:  int main (int argc, char *argv[]) {   LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);   LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);   NodeContainer adHocNodes;   adHocNodes.Create (30);   //配置物理层和信道,都使用...

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;
}

|
不知道啊!!

    
 
 

您可能感兴趣的文章:

 
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。












  • 相关文章推荐


  • 站内导航:


    特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

    ©2012-2021,