I want to monitor traffic inside the simulated node using DCE

242 views
Skip to first unread message

Byoungheon Shin

unread,
Nov 1, 2016, 1:16:38 AM11/1/16
to ns-3-users
Hello,
I want to monitor traffic status in each node created in the DCE-simulated wireless networks.
In other words, I want to run my C++ application which monitors the network traffic of each network interface.

Since one possible option is to run "tcpdump" in a node, I recompiled tcpdump using -fPIC -pie -rdynamic flags, and it seems to be running.
But after running a simple point-to-point simulation, I get stderr of tcpdump as follows:
tcpdump: Can't open raw Bluetooth socket: Invalid argument

My simulation configuration is as follows which almost copies the existing "dce-ping" example in myscripts:

#include "ns3/network-module.h"
#include "ns3/core-module.h"
#include "ns3/internet-module.h"
#include "ns3/dce-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/applications-module.h"
#include "ns3/netanim-module.h"
#include "ns3/constant-position-mobility-model.h"

#ifdef DCE_MPI
#include "ns3/mpi-interface.h"
#endif

using namespace ns3;

void setPos (Ptr<Node> n, int x, int y, int z)
{
   
Ptr<ConstantPositionMobilityModel> loc = CreateObject<ConstantPositionMobilityModel> ();
    n
->AggregateObject (loc);
   
Vector locVec2 (x, y, z);
    loc
->SetPosition (locVec2);
}

void RunIp (Ptr<Node> node, Time at, std::string str)
{
   
DceApplicationHelper process;
   
ApplicationContainer apps;
    process
.SetBinary ("ip");
    process
.SetStackSize (1 << 16);
    process
.ResetArguments ();
    process
.ParseArguments (str.c_str ());
    apps
= process.Install (node);
    apps
.Start (at);
}

void AddAddress (Ptr<Node> node, Time at, const char *name, const char *address)
{
    std
::ostringstream oss;
    oss
<< "-f inet addr add " << address << " dev " << name;
   
RunIp (node, at, oss.str ());
}

std
::string Ipv4AddressToString (Ipv4Address ad)
{
    std
::ostringstream oss;
    ad
.Print (oss);
   
return oss.str ();
}

int main (int argc, char *argv[])
{
  uint32_t systemId
= 0;
  uint32_t systemCount
= 1;
#ifdef DCE_MPI
 
// Distributed simulation setup
 
MpiInterface::Enable (&argc, &argv);
 
GlobalValue::Bind ("SimulatorImplementationType",
                     
StringValue ("ns3::DistributedSimulatorImpl"));
  systemId
= MpiInterface::GetSystemId ();
  systemCount
= MpiInterface::GetSize ();
#endif

  std
::string animFile = "NetAnim.xml";

 
NodeContainer nodes;
 
Ptr<Node> node1 = CreateObject<Node> (0 % systemCount); // Create node1 with system id 0
 
Ptr<Node> node2 = CreateObject<Node> (1 % systemCount); // Create node2 with system id 1
  nodes
.Add (node1);
  nodes
.Add (node2);

 
PointToPointHelper pointToPoint;
  pointToPoint
.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
  pointToPoint
.SetChannelAttribute ("Delay", StringValue ("1ms"));

 
NetDeviceContainer devices;
  devices
= pointToPoint.Install (nodes);

 
DceManagerHelper dceManager;
  dceManager
.SetNetworkStack ("ns3::LinuxSocketFdFactory", "Library", StringValue ("liblinux.so"));

 
LinuxStackHelper stack;
 
Ipv4DceRoutingHelper ipv4RoutingHelper;
  stack
.SetRoutingHelper (ipv4RoutingHelper);
  stack
.Install (nodes);

 
AddAddress (nodes.Get (0), Seconds (0.1), "sim0", "10.1.1.1/8");
 
RunIp (nodes.Get (0), Seconds (0.2), "link set sim0 up arp off");

 
AddAddress (nodes.Get (1), Seconds (0.3), "sim0","10.1.1.2/8");
 
RunIp (nodes.Get (1), Seconds (0.4), "link set sim0 up arp off");

  dceManager
.Install (nodes);

 
DceApplicationHelper dce;
 
ApplicationContainer apps;

  dce
.SetStackSize (1 << 20);

 
if ( systemId == node1->GetSystemId () )
   
{
     
// Launch ping on node 0
      dce
.SetBinary ("tcpdump");
      dce
.ResetArguments ();
      dce
.ResetEnvironment ();
      dce
.AddArgument ("-Nn");
     
//dce.AddArgument ("-b ip");
      dce
.AddArgument ("-tttt");

      apps
= dce.Install (node1);
      apps
.Start (Seconds (1.0));
   
}
 
if ( systemId == node2->GetSystemId ())
   
{
     
// Launch ping on node 1
      dce
.SetBinary ("ping");
      dce
.ResetArguments ();
      dce
.ResetEnvironment ();
      dce
.AddArgument ("-c 10");
      dce
.AddArgument ("-s 1000");
      dce
.AddArgument ("10.1.1.1");

      apps
= dce.Install (node2);
      apps
.Start (Seconds (1.5));
   
}

  setPos
(nodes.Get (0), 1, 10, 0);
  setPos
(nodes.Get (1), 50,10, 0);


 
// Create the animation object and configure for specified output
 
AnimationInterface anim (animFile);

 
//anim.StartAnimation ();
 
Simulator::Stop (Seconds (40.0));
 
Simulator::Run ();
 
Simulator::Destroy ();

#ifdef DCE_MPI
 
MpiInterface::Disable ();
#endif

 
return 0;
}


Because I am still a beginner of ns-3, I don't know what I should additionally configure the simulation environment.
Or if there is another easier way to monitor traffic of each interface in each node, please let me know.
Any suggestions will be highly appreciated.

Best Regards,

-- Byoungheon

Matt Anonyme

unread,
Nov 1, 2016, 1:16:15 PM11/1/16
to ns-3-users
ns3 is capable of exporting programmatically packets seen on an interface to a pcap format, you don't need to run tcpdump. There are DCE exemples in doing that.
Also the name of interfaces to use tcpdump for instance could be a problem. I had done sthg to improve that but don't remember if it got merged.

Byoungheon Shin

unread,
Nov 2, 2016, 2:30:00 AM11/2/16
to ns-3-users
Yes, ns-3 can generate pcap files for the simulation. But is it possible to use such output file for the simulated nodes?

I need to use real-time traffic information in the C++ application. For example, the C++ application monitors the amount of bandwidth occupation for all flows passing through each node.
So, the goal is to run a "QoS-aware routing protocol" written in C++ as a user-space application.

In the real-world, implementation, I could achieve this by parsing tcpdump output (just plain text, not actually pcap) for network monitoring, "ip route" for changing routes, "tc" for limiting bandwidth.
And I just wanted to reuse them in the DCE.

If this seems inefficient, is there another options to use that?
Regards,


2016년 11월 2일 수요일 오전 2시 16분 15초 UTC+9, Matt Anonyme 님의 말:

Matt Anonyme

unread,
Nov 2, 2016, 3:18:09 PM11/2/16
to ns-3-users
Even if you can make it work I don't think this is an efficient way. Can't you query statistics from the host ? like with netlink or parsing the output of some linux utility ?

Andreas Pantelopoulos

unread,
Jun 7, 2017, 1:34:04 PM6/7/17
to ns-3-users
Hello, 

I am trying also to capture packets with libpcap in DCE. Did you manage to find a solution ?

Andreas

Byoungheon Shin

unread,
Jun 8, 2017, 12:43:26 AM6/8/17
to ns-3-users
No, I couldn't find solution due to my time limit of the research.
Instead of DCE, I just implement all features using ns-3 libraries in the fully simulated environment of ns-3.

2017년 6월 8일 목요일 오전 2시 34분 4초 UTC+9, Andreas Pantelopoulos 님의 말:

Andreas Pantelopoulos

unread,
Jun 8, 2017, 10:25:06 AM6/8/17
to ns-3-users
Hello,

Thanks for the prompt answer. In the end did you manage to capture packets from physical interfaces with the use of ns3 libraries or you ditched the attempt at all ?

Andreas

Byoungheon Shin

unread,
Jun 9, 2017, 3:58:29 AM6/9/17
to ns-3-users
I created my own packet monitoring code (a function) which accepts two parameters: Ptr<Socket> and Ptr<MyNS3Packet>, and the MyNS3Packet is just my custom class for indicating a "data packet (src, src port, dst, dst port, data)".

#ifndef SCRATCH_MY_NS3_PACKET_H_
#define SCRATCH_MY_NS3_PACKET_H_

#include "ns3/object.h"
#include "ns3/ipv4-address.h"

class MyNS3Packet : public ns3::Object
{
private:
ns3::Ipv4Address src;
int appSrcPort;
ns3::Ipv4Address dst;
int appDstPort;
std::string msg;

public:
MyNS3Packet(ns3::Ipv4Address src, int appSrcPort, ns3::Ipv4Address dst, int appDstPort, std::string msg);
MyNS3Packet();
virtual ~MyNS3Packet();
ns3::Ipv4Address getSrc() const;
void setSrc(ns3::Ipv4Address src);
ns3::Ipv4Address getDst() const;
void setDst(ns3::Ipv4Address dst);
const std::string getMsg() const;
void setMsg(const std::string msg);
const std::string serialize();
static ns3::Ptr<MyNS3Packet> parse(std::string str);
int getAppDstPort() const;
void setAppDstPort(int appDstPort);
int getAppSrcPort() const;
void setAppSrcPort(int appSrcPort);
const int getPktSize() const;
};

#endif

In the function for monitoring packets, a Ptr<Packet> is created and sent via Ptr<Socket> and I just store every packet information from the MyNS3Packet.
This wouldn't be a good solution, but at least I could manage which flow (src, srcport, dst, dstport, TCP or UDP) generates how many packets in a certain period.
Hope this could help you.

-Byoungheon


2017년 6월 8일 목요일 오후 11시 25분 6초 UTC+9, Andreas Pantelopoulos 님의 말:
Reply all
Reply to author
Forward
0 new messages