Tracing for Post analysis in ns-3.

What is tracing ?

After running simulation if we want to analyze the behavior of the network we need  to analyze certain events that are occurring. Tracing means noting each and every event happening at every instance of time. Tracing analysis is helpful to provide proof for any new research, experiment. So ns-3 provides following two types of tracing.

1. ASCII tracing

ns-3 provides helper functionality that wraps the low-level tracing system to help you with the details involved in configuring some easily understood packet traces. If you enable this functionality, you will see output in a ASCII files thus the name. For those familiar with ns-2 output, this type of trace is analogous to the out.tr generated by many scripts. Right before the call to Simulator::Run (), add the following lines of code:

 AsciiTraceHelper ascii;
pointToPoint.EnableAsciiAll (ascii.CreateFileStream ("filename.tr"));

Like in many other ns-3 idioms, this code uses a helper object to help create ASCII traces. The second line contains two nested method calls. The inside method, CreateFileStream() uses an unnamed object idiom to create a file stream object on the stack (without an object name) and pass it down to the called method. Well go into this more in the future, but all you have to know at this point is that you are creating an object representing a file named filename.tr and passing it into ns-3. You are telling ns-3 to deal with the lifetime issues of the created object and also to deal with problems caused by a little-known (intentional) limitation of C++ offstream objects relating to copy constructors. The outside call, to EnableAsciiAll(), tells the helper that you want to enable ASCII tracing on all devices in your simulation; and you want the (provided) trace sinks to write out information about packet movement in ASCII format.

 

2. pcap tracing:

The ns-3 device helpers can be used to create trace les in the .pcap format. The acronym pcap (usually written in lower case) stands for packet capture, and is actually an API that includes the definition of a .pcap file format. The most popular program that can read and display this format is Wireshark (formerly called Ethereal).

However, there are many trac trace analyzers that use this packet format. The code used to enable pcap tracing is a one-liner.

pointToPoint.EnablePcapAll (“filename”);

Go ahead and insert this line of code after the ASCII tracing code. Notice that only passed the string is filename, and not filename.pcap or something similar. This is because the parameter is a prefix, not a complete file name. The helper will actually create a trace file for every point-to-point device in the simulation. The file names will be built using the prefix, the node number, the device number and a .pcap suffix. Once you have added the line of code to enable pcap tracing, you can run the script in the usual way:

./waf --run scratch/filename
  1. Reading output with tcpdump

The easiest thing to do at this point will be to use tcpdump to look at the pcap files.

tcpdump -nn -tt -r filename-0-0.pcap
reading from le filename-0-0.pcap, link-type PPP (PPP)
2.000000 IP 10.1.1.1.49153 > 10.1.1.2.9: UDP, length 1024
2.514648 IP 10.1.1.2.9 > 10.1.1.1.49153: UDP, length 1024

tcpdump -nn -tt -r filename-1-0.pcap
reading from le filename-1-0.pcap, link-type PPP (PPP)
2.257324 IP 10.1.1.1.49153 > 10.1.1.2.9: UDP, length 1024
2.257324 IP 10.1.1.2.9 > 10.1.1.1.49153: UDP, length 1024

You can see in the dump of filename-0-0.pcap (the client device) that the echo packet is sent at 2 seconds into the simulation. If you look at the second dump (filename-1-0.pcap) you can see that packet being received at 2.257324 seconds. You see the packet being echoed back at 2.257324 seconds in the second dump, and finally, you see the packet being received back at the client in the first dump at 2.514648 seconds.

      2. Reading output with Wireshark :

If you are unfamiliar with Wireshark, there is a web site available from which you can download programs and documentation. Wireshark is a graphical user interface which can be used for displaying these trace files. If you have Wireshark available, you can open each of the trace files and display the contents as if you had captured the packets using a packet sniffer.

Visit again for more updates thanks…..

Generating Network Animation in ns-3

Generating Network Animation

NetAnim is an offline animator based on the Qt toolkit. It currently animates the simulation using an XML trace file collected during simulation.Following are the certain mandatory steps need to verify to execute animation trace file:

  1. Also include the header [include “ns3/netanim-module.h”] in your test pro-
    gram.
  2. Add the statement “AnimationInterface anim (“animation.xml”);” before Simulator::Run()
  3. After updating the code to see animation first need to start Network Animator. To
    start Network Animtaor (NetAnim) follow these commands :

    
    1. cd ns-allinone-3.21/netanim-3.105/
    2. ./NetAnim

    This command will open the Network Animator. You have to browse the .xml file
    and open it for animation.

Next time we will see tracing options and how to enable them using few lines of code in ns-3.

Visit again for more updates thanks…..

Writing first program in ns-3 with Python.

This is same code as that of c++ but in the python language. To know more C++ code of same program please refer previous post.

import ns.applications
import ns.core
import ns.internet
import ns.network
import ns.point_to_point

ns.core.LogComponentEnable("UdpEchoClientApplication",ns.core.LOG_LEVEL_INFO)
ns.core.LogComponentEnable("UdpEchoServerApplication", ns.core.LOG_LEVEL_INFO)

nodes= ns.network.NodeContainer()
nodes.create(2)

pointToPoint = ns.point_to_point.PointToPointHelper()
pointToPoint.SetDeviceAttribute ("DataRate",ns.core.StringValue ("5Mbps"))
pointToPoint.SetChannelAttribute ("Delay", ns.core.StringValue ("2ms"))

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

address=ns.internet.IPV4AddressHelper()
address.SetBase (ns.network.IPV$Address("10.1.1.0"), ns.network.IPV4Mask("255.255.255.0"))

interfaces = address.Assign(devices);

echoserver = ns.applications.UdpEchoServerHelper(9)

serverApps = echoServer.Install(nodes.Get(1))
serverApps.Start(ns.core.Seconds(1.0))
serverApps.Stop.(ns.core.Seconds(10.0))

echoClient = ns.applications.UdpEchoClientHelper(interfaces.GetAddress(1),9)
echoClient.SetAttribute("MaxPackets",ns.core.UintegerValue(1))
echoClient.SetAttribute("Interval",ns.core.TimeValue(ns.core.Seconds(1.0))
echoClient.SetAttribute("PacketSize",ns.core.UintegerValue(1024))

ClientApps = echoClient.Install(nodes.Get(0))
ClientApps.Start(ns.core.Seconds(2.0))
ClientApps.Stop(ns.core.Seconds(10.0))

ns.core.Simulator.Run()
ns.core.Simulator.Destroy()



Save above file as first.py only in ns-allinone-3.21/ns-3.21/scratch folder. To run file go to ns-3.21 prompt and use command :

./waf pyrun scratch/first.py

Upto now we have seen programs in C++ and python . Next post onwards we will see how to do post processing of these programs.

Hope it will help you, visit again for more updates.

Thank You……….

Writing first program in ns-3 with C++.

To write program in ns-3 we can choose either c++ or python language. All the code of
ns-3 was written in c++ so it is more convenient to write program in c++. Python language is also supported by ns-3 but there is need of python wrappers for certain modules and there is need to develop such wrappers for particular module. Some of the wrappers are available so best way to go with c++ language.

If you haven’t installed ns-3 please go through this link –> Network simulator-3 [ns-3]
Open text editor and write below code. Save it in ns-allinone-3.21/ns-3.21/scratch
folder.

Following is the c++ file for UDP echo client-server program.

 

#include "ns3/network-module.h"
#include "ns3/internet-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/applications-module.h"
#include "ns3/netanim-module.h"
#include "ns3/mobility-module.h"
using namespace ns3;
NS LOG COMPONENT DEFINE("FirstScriptExample");
int main (int argc, char *argv[ ]) f
Time::SetResolution (Time::NS);
LogComponentEnable ("UdpEchoClientApplication", LOG LEVEL INFO);
LogComponentEnable ("UdpEchoServerApplication", LOG LEVEL INFO);
NodeContainer nodes;
nodes.Create (2);
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
NetDeviceContainer devices;
devices = pointToPoint.Install (nodes);
InternetStackHelper stack;
stack.Install (nodes);
Ipv4AddressHelper address;
address.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer interfaces = address.Assign (devices);
UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));
UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9);
echoClient.SetAttribute ("MaxPackets", UintegerValue (4));
echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));
clientApps.Start (Seconds (2.0));
clientApps.Stop (Seconds (10.0));
MobilityHelper mobility;
mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
mobility.Install(nodes);
AnimationInterface::SetBoundry(0,0,70,70);
AnimationInterface anim("first.xml");
AnimationInterface::SetConstantPosition (nodes.Get(0),10,25);
AnimationInterface::SetConstantPosition (nodes.Get(1),40,25);
anim.EnablePacketMetadata(true);
Simulator::Run ();
Simulator::Destroy ();
return 0;

Save above file as first.cc only in scratch folder. To run file  first goto ns-3.21 prompt(First command shown below) and use command :

cd ns-allinone-3.21/ns-3.21/
./waf run scratch/first

(Note: All the files should be kept in scratch folder else it will not going to run.)

Thats all … You will show some output on terminal .

On next post i will show same program in python language then we will look ahead for post processing.

Visit again, Thank you.

 

All basics of IoT

Hello, I have updated Internet of Things [IoT] page on my site. In this page you will find following content, Please have a look :

1.What is Internet of Things [IoT]

2 .Reasons for making IoT so powerful  :

3. Top companies working on IoT :

4. List of open source tools for making IoT applications:

5. Introduction to Contiki OS

6. Installing Contiki OS on VMware :

7. Introducing Cooja simulator

8. “Hello world ” first IoT program program in Cooja simulator.

Hope it will help you,

Please visit again for more updates ….

Thanks..