日期:2014-05-16  浏览次数:21169 次

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