I want to trace the dumbbell topology with the flow monitor on NS-3.29

78 views
Skip to first unread message

nanashi shitake

unread,
Jan 10, 2020, 8:22:31 PM1/10/20
to ns-3-users
Hi, I'm Japanese and write this post in Google Translate

I would like to create a dumbbell topology using PointToPointDumbbellHelper and evaluate TCP performance using BulkSendHelper. I want to output the result with FlowMonitor, but the result was not output with FlowMonitor.
I checked the data transmission and reception using Netanim, and it seemed to be working properly.
I don't know the cause. Please lend your help.

/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */


#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/internet-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/point-to-point-layout-module.h"
#include "ns3/applications-module.h"
#include "ns3/flow-monitor-helper.h"
#include "ns3/flow-monitor-module.h"
#include "ns3/netanim-module.h"


#define NET_MASK   "255.255.255.0"
#define NET_ADD1   "10.1.1.0"
#define NET_ADD2   "10.2.1.0"
#define NET_ADD3   "10.3.1.0"


using namespace ns3;


NS_LOG_COMPONENT_DEFINE
("TcpDumbbellIncrease");


int
main
(int argc, char *argv[])
{
  uint32_t nLeaf
= 1;
 
double simTime = 10.1;
 
//std::string animFile = "dumbbell-animation.xml";


 
CommandLine cmd;
  cmd
.AddValue ("nLeaf", "PointToPointDumbbell network leafs number.", nLeaf);
  cmd
.Parse (argc, argv);


 
// Create the point-to-point link helper
 
PointToPointHelper p2pRouter;
  p2pRouter
.SetDeviceAttribute ("DataRate", DataRateValue (DataRate ("10Mb/s")));
  p2pRouter
.SetChannelAttribute ("Delay", TimeValue (Seconds (0.001)));
 
PointToPointHelper p2pLeaf;
  p2pLeaf
.SetDeviceAttribute ("DataRate", DataRateValue (DataRate ("10Mb/s")));
  p2pLeaf
.SetChannelAttribute ("Delay", TimeValue (Seconds (0.001)));
 
 
PointToPointDumbbellHelper net (nLeaf, p2pLeaf, nLeaf, p2pLeaf, p2pRouter);


 
// Install Stack
 
InternetStackHelper stack;
  net
.InstallStack (stack);


 
// Assign IP Addresses
  net
.AssignIpv4Addresses (Ipv4AddressHelper (NET_ADD1, NET_MASK),
                           
Ipv4AddressHelper (NET_ADD2, NET_MASK),
                           
Ipv4AddressHelper (NET_ADD3, NET_MASK));


 
/*for(uint32_t v = 0; v < nLeaf; ++v)
    {
      std::cout << "IP:" << net.GetLeftIpv4Address(v) << "\n";
    }
  */

 
// install tcp source app on all left side nodes and sink app on all right side nodes
  uint32_t sinkPort
= 8080;
 
ApplicationContainer sourceApps;
 
ApplicationContainer sinkApps;
 
AddressValue remoteAddress;
 
BulkSendHelper ftp ("ns3::TcpSocketFactory", Address());
 
PacketSinkHelper sink ("ns3::TcpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), sinkPort));
 
for(uint32_t u = 0; u < nLeaf; ++u)
   
{
      remoteAddress
.Set (InetSocketAddress (net.GetRightIpv4Address (u), sinkPort));
      ftp
.SetAttribute ("Remote", remoteAddress);
      sourceApps
.Add (ftp.Install (net.GetLeft (u)));
      sinkApps
.Add (sink.Install (net.GetRight (u)));
   
}
  sinkApps
.Start (Seconds (0.0));
  sinkApps
.Stop (Seconds (simTime));
  sourceApps
.Start (Seconds (0.1));
  sourceApps
.Stop (Seconds (simTime));
 
 
/*
  // Set the bounding box for animation
  net.BoundingBox (1, 1, 100, 100);
 
  // Create the animation object and configure for specified output
  AnimationInterface anim (animFile);
  anim.EnablePacketMetadata (); // Optional
  anim.EnableIpv4L3ProtocolCounters (Seconds (0), Seconds (simTime)); // Optional
   
  // Set up the actual simulation
  Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
 
  Simulator::Run ();
  std::cout << "Animation Trace file created:" << animFile.c_str ()<< std::endl;
  Simulator::Destroy ();
  return 0;
  */

 
 
FlowMonitorHelper flowmon;
 
Ptr<FlowMonitor> monitor = flowmon.InstallAll ();


 
Simulator::Stop(Seconds(simTime));
 
Simulator::Run();


  monitor
->CheckForLostPackets ();
 
Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier> (flowmon.GetClassifier ());
 
FlowMonitor::FlowStatsContainer 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 Packets: " << i->second.txPackets << "\n";
      std
::cout << "  Tx Bytes:   " << i->second.txBytes << "\n";
      std
::cout << "  TxOffered:  " << i->second.txBytes * 8.0 / (simTime) / 1000 / 1000  << " Mbps\n";
      std
::cout << "  Rx Packets: " << i->second.rxPackets << "\n";
      std
::cout << "  Rx Bytes:   " << i->second.rxBytes << "\n";
      std
::cout << "  Throughput: " << i->second.rxBytes * 8.0 / (simTime) / 1000 / 1000  << " Mbps\n";
   
}


 
Simulator::Destroy();
 
return 0;
}



nanashi shitake

unread,
Jan 12, 2020, 10:18:52 PM1/12/20
to ns-3-users
Was self resolved!
I just added this next.
...

sourceApps
.Stop (Seconds (simTime))

Ipv4GlobalRoutingHelper :: PopulateRoutingTables ();

...


2020年1月11日土曜日 10時22分31秒 UTC+9 nanashi shitake:
Reply all
Reply to author
Forward
0 new messages