问题描述
使用针对802.11的ns-3进行网络仿真时,会生成一个pcap文件。我能够使用WireShark从该pcap文件中过滤有关rts,cts和ack的所有信息。但是我需要使用流监视器模块(从生成的XML文件中)提取相同的信息。但是我找不到任何办法。是否可以使用流量监控器获取该信息?
我的代码类似于ns-allinone-3.31 / ns-3.31 / examples / wireless / wifi-tcp.cc文件,但启用了rts / cts并添加了流量监视器。
#include "ns3/command-line.h"
#include "ns3/config.h"
#include "ns3/string.h"
#include "ns3/log.h"
#include "ns3/yans-wifi-helper.h"
#include "ns3/ssid.h"
#include "ns3/mobility-helper.h"
#include "ns3/on-off-helper.h"
#include "ns3/yans-wifi-channel.h"
#include "ns3/mobility-model.h"
#include "ns3/packet-sink.h"
#include "ns3/packet-sink-helper.h"
#include "ns3/tcp-westwood.h"
#include "ns3/internet-stack-helper.h"
#include "ns3/ipv4-address-helper.h"
#include "ns3/ipv4-global-routing-helper.h"
#include "ns3/flow-monitor.h"
#include "ns3/flow-monitor-module.h"
NS_LOG_COMPONENT_DEFINE ("wifi-tcp");
using namespace ns3;
Ptr<PacketSink> sink; /* Pointer to the packet sink application */
uint64_t lastTotalRx = 0; /* The value of the last total received bytes */
void
CalculateThroughput ()
{
Time Now = Simulator::Now (); /* Return the simulator's virtual time. */
double cur = (sink->GetTotalRx () - lastTotalRx) * (double) 8 / 1e5; /* Convert Application RX Packets to MBits. */
std::cout << Now.GetSeconds () << "s: \t" << cur << " Mbit/s" << std::endl;
lastTotalRx = sink->GetTotalRx ();
Simulator::Schedule (MilliSeconds (100),&CalculateThroughput);
}
int
main (int argc,char *argv[])
{
uint32_t payloadSize = 1472; /* Transport layer payload size in bytes. */
std::string datarate = "100Mbps"; /* Application layer datarate. */
std::string tcpVariant = "TcpNeWreno"; /* TCP variant type. */
std::string phyRate = "HtMcs7"; /* Physical layer bitrate. */
double simulationTime = 10; /* Simulation time in seconds. */
bool pcapTracing = true; /* PCAP Tracing is enabled or not. */
/* Command line argument parser setup. */
CommandLine cmd (__FILE__);
cmd.AddValue ("payloadSize","Payload size in bytes",payloadSize);
cmd.AddValue ("datarate","Application data ate",datarate);
cmd.AddValue ("tcpVariant","Transport protocol to use: TcpNeWreno,"
"TcpHybla,TcpHighSpeed,TcpHtcp,TcpVegas,Tcpscalable,TcpVeno,"
"TcpBic,Tcpyeah,TcpIllinois,TcpWestwood,TcpWestwoodplus,TcpLedbat ",tcpVariant);
cmd.AddValue ("phyRate","Physical layer bitrate",phyRate);
cmd.AddValue ("simulationTime","Simulation time in seconds",simulationTime);
cmd.AddValue ("pcap","Enable/disable PCAP Tracing",pcapTracing);
cmd.Parse (argc,argv);
tcpVariant = std::string ("ns3::") + tcpVariant;
// Select TCP variant
if (tcpVariant.compare ("ns3::TcpWestwoodplus") == 0)
{
// TcpWestwoodplus is not an actual TypeId name; we need TcpWestwood here
Config::SetDefault ("ns3::TcpL4Protocol::SocketType",TypeIdValue (TcpWestwood::GetTypeId ()));
// the default protocol type in ns3::TcpWestwood is WESTWOOD
Config::SetDefault ("ns3::TcpWestwood::ProtocolType",EnumValue (TcpWestwood::WESTWOOdplUS));
}
else
{
TypeId tcpTid;
NS_ABORT_MSG_UNLESS (TypeId::LookupByNameFailSafe (tcpVariant,&tcpTid),"TypeId " << tcpVariant << " not found");
Config::SetDefault ("ns3::TcpL4Protocol::SocketType",TypeIdValue (TypeId::LookupByName (tcpVariant)));
}
/* Configure TCP Options */
std::string RtsCtsThreshold="256";
std::string FragmentationThreshold="1000";
Config::SetDefault("ns3::WifiRemoteStationManager::RtsCtsThreshold",StringValue(RtsCtsThreshold));
Config::SetDefault("ns3::WifiRemoteStationManager::FragmentationThreshold",StringValue(FragmentationThreshold));
Config::SetDefault ("ns3::Tcpsocket::SegmentSize",UintegerValue (payloadSize));
WifiMacHelper wifiMac;
WifiHelper wifiHelper;
wifiHelper.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ);
/* Set up Legacy Channel */
YansWifiChannelHelper wifiChannel;
wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
wifiChannel.AddPropagationLoss ("ns3::FriisPropagationLossModel","Frequency",DoubleValue (5e9));
/* Setup Physical Layer */
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
wifiPhy.SetChannel (wifiChannel.Create ());
wifiPhy.SetErrorRateModel ("ns3::YansErrorRateModel");
wifiHelper.SetRemoteStationManager ("ns3::ConstantRateWifiManager","DataMode",StringValue (phyRate),"ControlMode",StringValue ("HtMcs0"));
NodeContainer networkNodes;
networkNodes.Create (2);
Ptr<Node> apWifiNode = networkNodes.Get (0);
Ptr<Node> staWifiNode = networkNodes.Get (1);
/* Configure AP */
Ssid ssid = Ssid ("network");
wifiMac.SetType ("ns3::ApWifiMac","Ssid",SsidValue (ssid));
NetDeviceContainer apDevice;
apDevice = wifiHelper.Install (wifiPhy,wifiMac,apWifiNode);
/* Configure STA */
wifiMac.SetType ("ns3::StaWifiMac",SsidValue (ssid));
NetDeviceContainer staDevices;
staDevices = wifiHelper.Install (wifiPhy,staWifiNode);
/* mobility model */
mobilityHelper mobility;
Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
positionAlloc->Add (Vector (0.0,0.0,0.0));
positionAlloc->Add (Vector (1.0,1.0,0.0));
mobility.SetPositionAllocator (positionAlloc);
mobility.SetmobilityModel ("ns3::ConstantPositionmobilityModel");
mobility.Install (apWifiNode);
mobility.Install (staWifiNode);
/* Internet stack */
InternetStackHelper stack;
stack.Install (networkNodes);
Ipv4AddressHelper address;
address.SetBase ("10.0.0.0","255.255.255.0");
Ipv4InterfaceContainer apInterface;
apInterface = address.Assign (apDevice);
Ipv4InterfaceContainer staInterface;
staInterface = address.Assign (staDevices);
/* Populate routing table */
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
/* Install TCP Receiver on the access point */
PacketSinkHelper sinkHelper ("ns3::TcpsocketFactory",InetSocketAddress (Ipv4Address::GetAny (),9));
ApplicationContainer sinkApp = sinkHelper.Install (apWifiNode);
sink = StaticCast<PacketSink> (sinkApp.Get (0));
/* Install TCP/UDP Transmitter on the station */
OnOffhelper server ("ns3::TcpsocketFactory",(InetSocketAddress (apInterface.GetAddress (0),9)));
server.SetAttribute ("PacketSize",UintegerValue (payloadSize));
server.SetAttribute ("OnTime",StringValue ("ns3::ConstantRandomVariable[Constant=1]"));
server.SetAttribute ("OffTime",StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
server.SetAttribute ("Datarate",DatarateValue (Datarate (datarate)));
ApplicationContainer serverApp = server.Install (staWifiNode);
// Flow monitor
Ptr<FlowMonitor> flowMonitor;
FlowMonitorHelper flowHelper;
flowMonitor = flowHelper.InstallAll();
/* Start Applications */
sinkApp.Start (Seconds (0.0));
serverApp.Start (Seconds (1.0));
Simulator::Schedule (Seconds (1.1),&CalculateThroughput);
/* Enable Traces */
if (pcapTracing)
{
wifiPhy.SetPcapDataLinkType (WifiPhyHelper::DLT_IEEE802_11_RAdio);
wifiPhy.EnablePcap ("Accesspoint",apDevice);
wifiPhy.EnablePcap ("Station",staDevices);
}
/* Start Simulation */
Simulator::Stop (Seconds (simulationTime + 1));
Simulator::Run ();
flowMonitor->SerializetoXmlFile("1.xml",true,true);
double averageThroughput = ((sink->GetTotalRx () * 8) / (1e6 * simulationTime));
Simulator::Destroy ();
if (averageThroughput < 50)
{
NS_LOG_ERROR ("Obtained throughput is not in the expected boundaries!");
exit (1);
}
std::cout << "\nAverage throughput: " << averageThroughput << " Mbit/s" << std::endl;
return 0;
}
预先感谢:)
解决方法
包含控制帧(rts / cts / ack)的
802.11 pcap是链路层。 流监视器是用于传输层的,因此您无法真正获得它的数据。
您可以使用wireshark / tshark从pcap中提取所需的数据。或者也许尝试pyshark从python脚本中做到这一点。