ns3 modules

Ns3 is a network simulation software, it depends on various in built and third party tools for enablement.
Here are some of the third party modules that can be enabled while running ns3. This is a handy note for such modules.
All these examples were tried on the ~ns-3.24.1/examples/tutorial/third.cc file

1. NetAnim#include "ns3/netanim-module.h"
AnimationInterface anim("third.xml");
anim.SetConstantPosition(csmaNodes.Get(0),1.0,1,0);
anim.SetConstantPosition(csmaNodes.Get(1),2.0,2,0);
anim.SetConstantPosition(csmaNodes.Get(2),3.0,3,0);
anim.SetConstantPosition(csmaNodes.Get(3),4.0,4,0);
anim.SetConstantPosition(wifiApNode.Get(0),5.0,5,0);
anim.SetConstantPosition(wifiStaNodes.Get(0),6.0,1,0);
anim.SetConstantPosition(wifiStaNodes.Get(1),7.0,1,0);
anim.SetConstantPosition(wifiStaNodes.Get(2),8.0,1,0);

Open NetAnim and open the xml file (third.xml in this case). Always prefer to use the inbuilt netanim rather than an installed version of NetAnim.

2. Ascii Trace FilesAsciiTraceHelper ascii;
csma.EnableAsciiAll(ascii.CreateFileStream("thirdcsma.tr"));
phy.EnableAsciiAll(ascii.CreateFileStream("thirdwifi.tr"));

Open the tracefiles using tracemetrics software, see the screenshot below
Tracemetrics
Tracemetrics


3. Pcap files pointToPoint.EnablePcapAll ("third");
 phy.EnablePcap ("third", apDevices.Get (0));
 csma.EnablePcap ("third", csmaDevices.Get (0), true);

Pcap files can be opened using wireshark or tcpdump
$] tcpdump -nn -tt -t file.pcap

4. Trace Metrics    java -jar tracemetrics.jar

Tracemetrics
TraceMetrics

5. Flow Monitor.    #include "ns3/flow-monitor-helper.h"
    // Flow monitor
    Ptr<FlowMonitor> flowMonitor;
    FlowMonitorHelper flowHelper;
    flowMonitor = flowHelper.InstallAll();

    Simulator::Run ();
    flowMonitor->SerializeToXmlFile("thirdflow.xml", true, true);   





The xml file have to be below the Simulator::Run(); and the flowmonitor declaration should be above the Run()

6. Gnuplot
To plot a given file file.data here is the command to plot using Gnuplot
    set terminal png size 600,480
    set output "file.png"
    plot "file.data" using 1:2 with linespoints title "Congestion"
7. xgraph    xgraph file.xg
8. Visualizer     ./waf --run scratch/third --vis
    ./waf --run scratch/third --visualizer
 T S Pradeep Kumar

Operating System for IoT

This slides shows the operating system for Internet of things and it also shows the features of OS.


T S Pradeep Kumar

Enable All interfaces in Wireshark

If you are running Ubuntu or Linux Mint, the wireshark may not list all the interfaces except bluetooth. There is a small workaround for enabling all the interfaces within wireshark

To install wireshark
$ sudo apt-get install wireshark

Checking for all the interfaces
$] ifconfig -a 
eth0      Link encap:Ethernet  HWaddr b4:b5:2f:90:41:98  
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:5528 errors:0 dropped:0 overruns:0 frame:0
          TX packets:5528 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:522095 (522.0 KB)  TX bytes:522095 (522.0 KB)

wlan0     Link encap:Ethernet  HWaddr 68:17:29:15:7f:9d  
          inet addr:192.168.0.103  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::6a17:29ff:fe15:7f9d/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:487713 errors:0 dropped:0 overruns:0 frame:0
          TX packets:336698 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:591668376 (591.6 MB)  TX bytes:41118839 (41.1 MB)

To check the interfaces shown by the dumpcap

$] dumpcap -D -M (following line is the output)
1. bluetooth0 4 network

Enable the following commands in linux to make it work.
$] sudo groupadd wireshark$] sudo usermod -a -G wireshark $USER$] sudo chgrp wireshark /usr/bin/dumpcap$] sudo setcap cap_net_raw,cap_net_admin=eip /usr/bin/dumpcap

$] dumpcap -D -M (following is the output)
dumpcap
dumpcap

T S Pradeep Kumar

IOT - CoAP implementation in Contiki OS

Constrained Application Protocol (CoAP) is a lightweight http protocol that reads and controls the sensors deployed for IoT.
It has actions like get, post, put, delete, observe, discover.

This coap can be accessed similar like http, For ex: to access a particular mote (Sensor) with IPv6 like this
coap://[aaaa::212:7402:2:202]
The above line will fetch the sensor boards peripherals and one can control from the browser itself. Firefox has a Cu plugin to enable CoAP within the browser. CoAP is already available for all the devices like IOS, Android, Windows, Linux, Mac, etc,

So here is an example in contiki that shows how to use this coap based application using a border router.


Step 1: Contiki Selection

Open instant Contiki (Which runs on VMWare or Virtual Box)

Open Cooja from the Desktop directly or Open the Terminal and give the following steps

$] cd /home/user/contiki-2.7/tools/cooja
$] ant run 
If you want to simulate huge number of nodes then 
$] ant run_bigmem


Step 2: Selecting Border router

File - New Simulation -> Enter Simulation Name (Leave the defaults as it is ) and then Click "Create"

Click Add Motes -> Select Sky Mote

In the firmware, Select the following path /home/user/contiki-2.7/examples/ipv6/rpl-border-router/border-router.c
Click -> Compile (or Clean and then Compile), once compilation is over, Click Create motes and select the number of motes (1 in this case).


Step 3: Selecting the Er Example Server

Click Add Motes -> Sky Motes 
In the firmware, select the following path /home/user/er-rest-example/er-example-server.c 
Click Compile -> after compilation, click create motes and select the number of motes (2 in this case)

Step 4: Run the Simulation 

In the Simulation Control window, you can press the Start button to start the simulation. Since this application is deployed with IpV6 for all the nodes, it can be seen from the simulation that all the motes have the ipv6 addresses like this
mote 1: aaaa::212:7401:1:101 for Border router

A bridge has to be made between the border router and the other motes, to enable the bridge, Right Click Border Router Node -> Mote tools for Sky 1 ->  Serial Socket (SERVER) 


Step 5: Bridge the Border Router

Open a new terminal and select the path as given below

$] cd /home/user/examples/ipv6/rpl-border-router/
$] make connect-router-cooja 
It will ask to input the super user password, after you input, the ipv6 addresses will be assigned to the motes.
You may ping it using a new terminal, with the command "ping6 aaaa::212:7402:2:202"

Step 6: Read the sensors

You can read the sensors using the ipv6 addresses by opening the firefox browser.
Open the browser and input the following addresses in a new tab

coap://[aaaa::212:7402:2:202] or any other sensor mote
Refer the images given below
CoAP
CoAP 

CoAP
CoAP
The above two images shows firefox browser with cu plugin to open the ipv6 address and read the sensor values. In the first picture the toggle value 1 for Red LED is sent from the browser by selecting the POST button (OutGoing), Upon receiving the RED LED is glowing in the Mote that indicates that the node is accepting the inputs remotely. 

Thus coAP is very handy when deals with the motes attributes. You may refer the following video for exact explanation of CoAP in Contiki



T S Pradeep Kumar

IOT - Border Router in Contiki OS

This post shows the introduction of Border router in Contiki OS. Border router or edge router is connected to internet when the other sensor nodes are reporting the data via the border router.
Implementation of this router is provided by all IOT operating systems.
Using this border router, how to transmit data to the internet, how neighbours are understood and how the routes are computed.
This example shows the implementation of Border router in Contiki OS

OS Used: Contiki 2.7
Simulator : Pooja

Step 1: Contiki Selection

Open Instant Contiki (Which runs on VMWare or Virtual Box)
Open Cooja from the Desktop directly or Open the Terminal and give the following steps

$] cd /home/user/contiki-2.7/tools/cooja
$] ant run 
If you want to simulate huge number of nodes then 
$] ant run_bigmem

Step 2: Selecting Border router

File - New Simulation -> Enter Simulation Name (Leave the defaults as it is ) and then Click "Create"

Click Add Motes -> Select Sky Mote

In the Firmware, Select the following path /home/user/contiki-2.7/examples/ipv6/rpl-border-router/border-router.c
Click -> Compile (or Clean and then Compile), once compilation is over, Click Create motes and select the number of motes (1 in this case)

Step 3: Create WebSense Nodes (Sky Websense)

Click Add Motes -> Select Sky Mote
In the Firmware Settings, Select /home/user/contiki-2.7/examples/ipv6/sky-websense/sky-websense.c
Click Clean and then Compile. After the compilation is over, Click Create and Select the required number of nodes (5 in this case)

So there are totally 6 motes (5 Websense motes and 1 border router mote). see Fig 1 Below. It shows one green coloured mote called border router and other yellow coloured motes 5 in numbers.
Fig 1 - Cooja Simulator

Step 4: Run the Simulation 

In the Simulation Control window, you can press the Start button to start the simulation. Since this application is deployed with IpV6 for all the nodes, it can be seen from the simulation that all the motes have the ipv6 addresses like this
mote 1: aaaa::212:7401:1:101 for Border router

A bridge has to be made between the border router and the other motes, to enable the bridge,
Right Click Border Router Node -> Mote tools for Sky 1 ->  Serial Socket (SERVER) 

Step 5: Bridge the Border Router

Open a new terminal and select the path as given below

$] cd /home/user/examples/ipv6/rpl-border-router/
$] make connect-router-cooja 
It will ask to input the super user password, after you input, the ipv6 addresses will be assigned to the motes.
You may ping it using a new terminal, with the command "ping6 aaaa::212:7402:2:202"

Step 6: Read the sensors
You can read the sensors using the ipv6 addresses by opening the firefox browser.
Open the browser and input the following addresses in a new tab

http://[aaaa::212:7401:1:101]
This will print the neighbours and routes from the border router

http://[aaaa::212:7402:2:202]
This will print the sensor readings like temperature and light as per the corresponding values.
See Fig 2 and Fig 3
WebSense
WebSense Node
Border Router
Border Router
 This example shows the connectivity of various motes with the border router.
for detailed explanation, you may look the youtube video.


T S Pradeep Kumar

NS2 projects with Source Code


Before shedding huge money for projects,  please go through the links which has source code along with how to execute the project.
The following projects are either taken from another website or from a open source hub and all the works are compatible with ns-2.35. It is a individual work done by me (T S Pradeep Kumar). For some projects, i lost the source code or its misplaced, but all these posts have detailed explanation that tells how to install these projects.  Also the source codes are provided from a google drive link.
(If any one have a source code and dont know to compile, please send it to me through my google+ link, I will compile for you and let you know the results).

This posts is suitable for PG students, Research scholars and Graduate students.


  1. Aqua Sim in NS2
  2. LEACH Protocol Installation
  3. Security Protocol as a packet (Agent/Security_packet)
  4. Adding a new agent and application in ns2
  5. AntNet (Ant colony Algorithm in ns2)
  6. SUMO and MOVE Example traffic Simulation (Do it yourself exercise, but a video is available)
  7. Routing Table printing in DSDV Protocol
  8. Routing table printing in AODV protocol
  9. Printing the Congestion window for TCP protocol
  10. TORA protocol in NS2
  11. Green Cloud Simulator in ns2
  12. Printing the Antenna threshold in propagation modes in ns2
  13. OLSR Protocol in NS2
  14. Mannasim - A Sensor network simulator in ns2
  15. AWK Scripts for performance calculation
  16. Energy Model in NS2
  17. Finding the node position, velocity and speed of the node while using AODV protocol
  18. Promiscuous mode in AODV 
These works takes more time and to support my effort, kindly donate me


T S Pradeep Kumar