【问题标题】:VANET simple CBR application, no output (empty pcap files)?VANET 简单 CBR 应用程序,没有输出(空 pcap 文件)?
【发布时间】:2019-11-05 09:55:23
【问题描述】:

我有问题.. 我想模拟一个使用 OnOffApplication 的 VANET 网络(只有两个节点)(为了模拟视频流流量) 我尝试了以下代码,没有出现错误,但是 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;
}

我应该怎么做?

【问题讨论】:

  • 您好,如果可以包含标头以便快速测试它,这将对使用 ns3 的同行有所帮助。谢谢。

标签: c++ simulation ns-3


【解决方案1】:

问题仅在于您选择使用 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 地址和端口(@98​​7654323@ 和地址(InetSocketAddress (i.GetAddress(1), port))。它应该是

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

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

【讨论】:

  • 非常感谢,我在一天前找到了解决方案.. 就是问题所在。再次感谢先生。
  • 没问题。您介意投票与答案相同吗?
  • 当然,这是我能做的最小的事情。非常感谢先生。
  • 你能检查一下这个问题吗(你可能知道答案):stackoverflow.com/questions/58792744/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-11-15
  • 2019-03-03
  • 1970-01-01
  • 1970-01-01
  • 2014-06-06
  • 2020-01-16
  • 1970-01-01
相关资源
最近更新 更多