VANET 简单 CBR 应用程序,无输出(空 pcap 文件)?

VANET simple CBR application, no output (empty pcap files)?

我有问题.. 我想模拟一个 VANET 网络(只有两个节点),它使用 OnOffApplication(为了模拟视频流流量) 我尝试了以下代码,没有出现错误,但是 pcap 文件是空的?根本没有发送数据包。有什么建议吗?

  int main (int argc, char *argv[])
  {
  std::string phyMode ("OfdmRate6MbpsBW10MHz");


  bool verbose = false;
  NodeContainer c;
  c.Create (2);

  // The below set of helpers will help us to put together the wifi NICs we want
  YansWifiPhyHelper wifiPhy =  YansWifiPhyHelper::Default ();
  YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
  Ptr<YansWifiChannel> channel = wifiChannel.Create ();
  wifiPhy.SetChannel (channel);
  // ns-3 supports generate a pcap trace
  wifiPhy.SetPcapDataLinkType (WifiPhyHelper::DLT_IEEE802_11);
  NqosWaveMacHelper wifi80211pMac = NqosWaveMacHelper::Default ();
  Wifi80211pHelper wifi80211p = Wifi80211pHelper::Default ();
  if (verbose)
    {
      wifi80211p.EnableLogComponents ();      // Turn on all Wifi 802.11p logging
    }

  wifi80211p.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
                                      "DataMode",StringValue (phyMode),
                                      "ControlMode",StringValue (phyMode));
  NetDeviceContainer devices = wifi80211p.Install (wifiPhy, wifi80211pMac, c);

  // Tracing
  wifiPhy.EnablePcap ("wave-simple-80211p", devices);

  MobilityHelper mobility;
  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
  positionAlloc->Add (Vector (0.0, 0.0, 0.0));
  positionAlloc->Add (Vector (5.0, 0.0, 0.0));
  mobility.SetPositionAllocator (positionAlloc);
  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
  mobility.Install (c);

  InternetStackHelper internet;
  internet.Install (c);


  Address serverAddress;
  Ipv4AddressHelper ipv4;
  NS_LOG_INFO ("Assign IP Addresses.");
  ipv4.SetBase ("192.168.1.0", "255.255.255.0");
  Ipv4InterfaceContainer i = ipv4.Assign (devices);
  serverAddress = Address (i.GetAddress (1));


 // Create router nodes, initialize routing database and set up the routing
  // tables in the nodes.
  Ipv4GlobalRoutingHelper::PopulateRoutingTables ();

  // Create the OnOff application to send UDP datagrams of size
  // 210 bytes at a rate of 448 Kb/s
  NS_LOG_INFO ("Create Applications.");
  uint16_t port = 9;   // Discard port (RFC 863)
  OnOffHelper onoff ("ns3::UdpSocketFactory", 
                     Address (InetSocketAddress (i.GetAddress (0), port)));
  onoff.SetConstantRate (DataRate ("448kb/s"));
  ApplicationContainer apps = onoff.Install (c.Get (0));
  apps.Start (Seconds (1.0));
  apps.Stop (Seconds (10.0));

  // Create a packet sink to receive these packets
  PacketSinkHelper sink ("ns3::UdpSocketFactory",
                         Address (InetSocketAddress (i.GetAddress(1), port)));
  apps = sink.Install (c.Get (1));
  apps.Start (Seconds (1.0));
  apps.Stop (Seconds (10.0));


  AsciiTraceHelper ascii;
  wifiPhy.EnableAsciiAll (ascii.CreateFileStream ("simple-global-routing.tr"));
  wifiPhy.EnablePcapAll ("simple-global-routing");

  // // Flow Monitor
  // FlowMonitorHelper flowmonHelper;
  // if (enableFlowMonitor)
    // {
      // flowmonHelper.InstallAll ();
    // }

  NS_LOG_INFO ("Run Simulation.");
  Simulator::Stop (Seconds (11));
  Simulator::Run ();
  NS_LOG_INFO ("Done.");


NS_LOG_INFO ("Done.");
  Simulator::Destroy ();


  return 0;
}

我应该怎么做?

问题仅在于您选择使用 OnOffHelperPacketSinkHelperApplicationContainer 寻址不同节点的方式 以包含您案例中的两个节点。

OnOffHelper onoff ("ns3::UdpSocketFactory", 
                     Address (InetSocketAddress (i.GetAddress (0), port)));
  onoff.SetConstantRate (DataRate ("448kb/s"));
  ApplicationContainer apps = onoff.Install (c.Get (0));
  apps.Start (Seconds (1.0));
  apps.Stop (Seconds (10.0));

  // Create a packet sink to receive these packets
  PacketSinkHelper sink ("ns3::UdpSocketFactory",
                         Address (InetSocketAddress (i.GetAddress(1), port)));
  apps = sink.Install (c.Get (1));

在这种情况下,station 1: 192.16.1.1 是源,station 2: 192.16.1.2 是汇。但是你自己使用了 ip 地址和端口 (Address (InetSocketAddress (i.GetAddress(0), port) 和地址 (InetSocketAddress (i.GetAddress(1), 端口))。它应该是

OnOffHelper onoff ("ns3::UdpSocketFactory", 
                         Address (InetSocketAddress (i.GetAddress (1), port)));
      onoff.SetConstantRate (DataRate ("448kb/s"));
      ApplicationContainer apps = onoff.Install (c.Get (0));
      apps.Start (Seconds (1.0));
      apps.Stop (Seconds (10.0));


      PacketSinkHelper sink ("ns3::UdpSocketFactory",
                             Address (InetSocketAddress (i.GetAddress(0), port)));
      apps = sink.Install (c.Get (1));

反之亦然。实际上,您可以通过激活流监视器来查看发生了什么,并且现在还创建了 pcap 文件。