Существует простая модель передачи данных.FlowMonitor не показывает статистику, но файлы PyViz и трассировки показывают это
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
#include <iostream>
#include <fstream>
#include <string>
#include <cassert>
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/csma-module.h"
#include "ns3/internet-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/applications-module.h"
#include "ns3/ipv4-global-routing-helper.h"
#include "ns3/flow-monitor-module.h"
//
// Network Topology
//
// n0 (source)
// |
// |
// |
// |
// |
// -------------------n1 n2 n3--------n4 n5 n6 (sink)
// point-to-point | | | | | |
// 10.1.1.0 ================== ==========
// LAN 10.1.2.0 LAN 10.1.3.0
// (CSMA subnet 1) (CSMA subnet 2)
using namespace ns3;
int main (int argc, char *argv[])
{
Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (700));
Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("1000000"));
CommandLine cmd;
cmd.Parse(argc,argv);
NodeContainer p2pNodes;
p2pNodes.Create(2);
NodeContainer csmaNodesSubNetOne;
csmaNodesSubNetOne.Add(p2pNodes.Get(1));
csmaNodesSubNetOne.Create(2);
NodeContainer csmaNodesSubNetTwo;
csmaNodesSubNetTwo.Add(csmaNodesSubNetOne.Get(2));
csmaNodesSubNetTwo.Create(2);
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute("DataRate", StringValue ("100Mbps"));
pointToPoint.SetDeviceAttribute("Mtu", UintegerValue(1000));
pointToPoint.SetChannelAttribute("Delay", TimeValue (NanoSeconds (6560)));
NetDeviceContainer p2pDevices;
p2pDevices = pointToPoint.Install(p2pNodes);
CsmaHelper csmaHelperSubNetOne;
csmaHelperSubNetOne.SetChannelAttribute("DataRate", StringValue ("100Mbps"));
csmaHelperSubNetOne.SetChannelAttribute("Delay", TimeValue (NanoSeconds (6560)));
csmaHelperSubNetOne.SetDeviceAttribute("Mtu", UintegerValue(1000));
NetDeviceContainer csmaDevicesSubNetOne;
csmaDevicesSubNetOne = csmaHelperSubNetOne.Install(csmaNodesSubNetOne);
CsmaHelper csmaHelperSubNetTwo;
csmaHelperSubNetTwo.SetChannelAttribute("DataRate", StringValue ("100Mbps"));
csmaHelperSubNetTwo.SetChannelAttribute("Delay", TimeValue (NanoSeconds (6560)));
csmaHelperSubNetTwo.SetDeviceAttribute("Mtu", UintegerValue(1000));
NetDeviceContainer csmaDevicesSubNetTwo;
csmaDevicesSubNetTwo = csmaHelperSubNetTwo.Install(csmaNodesSubNetTwo);
InternetStackHelper internetStackHelper;
internetStackHelper.Install(p2pNodes.Get(0));
internetStackHelper.Install(csmaNodesSubNetOne.Get(0));
internetStackHelper.Install(csmaNodesSubNetOne.Get(1));
internetStackHelper.Install(csmaNodesSubNetTwo.Get(0));
internetStackHelper.Install(csmaNodesSubNetTwo.Get(1));
internetStackHelper.Install(csmaNodesSubNetTwo.Get(2));
Ipv4AddressHelper address;
address.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer p2pInterfaces;
p2pInterfaces = address.Assign (p2pDevices);
address.SetBase ("10.1.2.0", "255.255.255.0");
Ipv4InterfaceContainer csmaInterfacesSubNetOne;
csmaInterfacesSubNetOne = address.Assign (csmaDevicesSubNetOne);
address.SetBase ("10.1.3.0", "255.255.255.0");
Ipv4InterfaceContainer csmaInterfacesSubNetTwo;
csmaInterfacesSubNetTwo = address.Assign (csmaDevicesSubNetTwo);
InetSocketAddress dst = InetSocketAddress (csmaInterfacesSubNetTwo.GetAddress (2));
OnOffHelper onoff = OnOffHelper ("ns3::Ipv4RawSocketFactory", dst);
ApplicationContainer apps = onoff.Install(p2pNodes.Get(0));
apps.Start (Seconds (2.0));
apps.Stop (Seconds (10.0));
PacketSinkHelper sink = PacketSinkHelper ("ns3::Ipv4RawSocketFactory", dst);
apps = sink.Install (csmaNodesSubNetTwo.Get(2));
apps.Start (Seconds (1.0));
apps.Stop (Seconds (10.0));
Ipv4GlobalRoutingHelper::PopulateRoutingTables();
csmaHelperSubNetTwo.EnablePcap ("sniffer", csmaDevicesSubNetTwo.Get (1), true);
AsciiTraceHelper ascii;
csmaHelperSubNetTwo.EnableAsciiAll(ascii.CreateFileStream("receiver-trace.tr"));
Simulator::Stop (Seconds (11));
FlowMonitorHelper flowmon;
Ptr<FlowMonitor> monitor = flowmon.InstallAll();
monitor = flowmon.GetMonitor();
Simulator::Run();
monitor->CheckForLostPackets();
Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier> (flowmon.GetClassifier());
std::map<FlowId, FlowMonitor::FlowStats> stats = monitor->GetFlowStats();
for(std::map<FlowId, FlowMonitor::FlowStats>::const_iterator i = stats.begin(); i != stats.end(); ++i)
{
Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow (i->first);
std::cout << " Flow " << i->first << " (" << t.sourceAddress << " -> " << t.destinationAddress << ")\n";
std::cout << " Tx Bytes: " << i->second.txBytes << "\n";
std::cout << " Rx Bytes: " << i->second.rxBytes << "\n";
std::cout << " Throughput: " << i->second.rxBytes * 8.0/10.0/1024/1024 << " Mbps\n";
}
monitor->SerializeToXmlFile("serialize-stat.flowmon", true, true);
Simulator::Destroy();
return 0;
}
Я могу построить и запустить эту модель и увидеть результаты в PyViz.
Также в PyViz я вижу статистику для приемника узла.
Файл трассировки содержит данные. Вот одна строка из большого файла трассировки.
...
r 3.00585 /NodeList/5/DeviceList/0/$ns3::CsmaNetDevice/MacRx ns3::EthernetHeader (length/type=0x800, source=00:00:00:00:00:06, destination=00:00:00:00:00:08) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 62 id 0 protocol 0 offset (bytes) 0 flags [none] length: 720 10.1.1.1 > 10.1.3.3) Payload (size=700) ns3::EthernetTrailer (fcs=0)
...
Я могу проанализировать этот файл трассы, используя AWK.
[[email protected] ns-3.16]# awk '{print $2 ", " $28}' receiver-trace.tr >grab.dat
[[email protected] ns-3.16]# cat grab.dat
...
3.00578, 720
3.00578, 720
3.00585, 720
3.01126, 720
3.01126, 720
3.01133, 720
3.01133, 720
3.01133, 720
3.0114, 720
3.01686, 720
3.01686, 720
3.01693, 720
3.01693, 720
3.01693, 720
3.017, 720
3.02246, 720
...
Но FlowMonitor ничего не показывает, и файл XML не имеет никакой полезной информации.
<?xml version="1.0" ?>
<FlowMonitor>
<FlowStats>
</FlowStats>
<Ipv4FlowClassifier>
</Ipv4FlowClassifier>
<FlowProbes>
<FlowProbe index="0">
</FlowProbe>
<FlowProbe index="1">
</FlowProbe>
<FlowProbe index="2">
</FlowProbe>
<FlowProbe index="3">
</FlowProbe>
<FlowProbe index="4">
</FlowProbe>
<FlowProbe index="5">
</FlowProbe>
</FlowProbes>
</FlowMonitor>
В чем может быть причина?