【发布时间】: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