Skip to main content

Posts

NS2 course on Udemy

Hello everyone!
I have published a course on Network Simulation using NS2 on Udemy. It covers all the basics and advanced concepts in details.

Get a 40% discount through below coupon. Click the link to directly apply the coupon.
https://www.udemy.com/network-simulation-using-ns2/?couponCode=INSTA_50

It covers below topics:

1. Introduction and installation of NS2
2. Introduction to TCL and OTcl
3. Writing wired and wireless scripts
4. Utilities like, cbrgen, setdest and Bonnmotion
5. Introduction and code review of AODV and DSR protocol
6. Cloning of an existing protocol
7. Trust management and Performance analysis
8. Automation of performance analysis using Bash scripting
9.Graph plotting using GNUPLOT

Recent posts

How to print Routing table of each node in NS2

You need to pass node id as an argument to this method.
e.g. in aodv.cc withing rt_resolve() method,

rt_print(0);

This will print node 0's routing table at that time with file name as node_0.

void AODV::rt_print(nsaddr_t node_id)
{
    FILE * tmpFile;
    char tmpFileName[50] = "node_";
    char tmp[10] = "";
    sprintf(tmp,"%d",node_id);
    strcat(tmpFileName,tmp);   
    tmpFile = fopen(tmpFileName, "w");

    aodv_rt_entry *rt;   

    for (rt = rtable.head(); rt; rt = rt->rt_link.le_next)
    {

        fprintf(
            tmpFile,
            "Node Id:%i Current time:%.4lf Destination:%i Next hop:%i No. of hops:%i Seq. No.:%i Route expire:%f Flags:%.4lf %d \n",
            node_id, CURRENT_TIME, rt->rt_dst, rt->rt_nexthop, rt->rt_hops,rt->rt_seqno, rt->rt_expire, rt->rt_flags);
    }

    fclose(tmpFile);
}




All the Best!

How to add trust table in NS2.

I am assuming AODV protocol. In rtable.cc add below code


trust_entry::trust_entry()
{
   //Initialize as per your need.
}
trust_entry::~trust_entry()
{
//Deconstruct as per your need.
}

trust_entry* trust_store::trust_lookup(
nsaddr_t node_id)
{
     trust_entry *rp = trusthead.lh_first;
     for (; rp; rp = rp->trust_link.le_next) {
             if (rp->node_id == node_id)
                 break;
     }
    return rp;
}
void trust_store::trust_delete(
nsaddr_t node_id)
{
    trust_entry *rp = trust_lookup(node_id);

    if (rp)
    {
        LIST_REMOVE(rp, trust_link);
        delete rp;
    }

}

trust_entry*
trust_store::trust_insert(
nsaddr_t node_id, nsaddr_t prev_node,nsaddr_t next_node,int32_t trust_value)
{
    trust_entry *rp;
    //assert(tr_lookup(dst_seq_no) == 0);
    rp = new trust_entry;
    assert(rp);
    rp->node_id = node_id;
    rp->prev_node = prev_node;
    rp->next_node = next_node;
    rp->trust_value = trust_value;
    LIST_INSERT_HEAD(&trusthead, rp, trust_link);
    r…

How to debug NS2 using gdb

1) Extract  NS2 tar file.
2) Modify Makefile.in from ns-allinone2.34/ns2.34/

1. change CCOPT = @V_CCOPT@ to CCOPT = @V_CCOPT@ -g  2. add -DNDEBUG -DDEBUG to the end of DEFINE = -DTCP_DELAY_BIND_ALL -DNO_TK @V_DEFINE@ @V_DEFINES@ @DEFS at -DNS_DIFFUSION -DSMAC_NO_SYNC -DCPP_NAMESPACE=@CPP_NAMESPACE at -DUSE_SINGLE_ADDRESS_SPACE -Drng_test 
that is: 
DEFINE = -DTCP_DELAY_BIND_ALL -DNO_TK @V_DEFINE@ @V_DEFINES@ @DEFS at -DNS_DIFFUSION -DSMAC_NO_SYNC -DCPP_NAMESPACE=@CPP_NAMESPACE at -DUSE_SINGLE_ADDRESS_SPACE -Drng_test -DNDEBUG -DDEBUG 
now browse to .../ns-allinone/ns2.3x and run ./configure and after that "make clean" and then "make"
2) Open terminal and type in "gdb ns"
3)then " run tcl_file_name"

If there are errors gdb will stop at respective location.

Runtime packet loss calculation in NS2

Hello friend, here I am going to present a method to calculate the runtime packet loss. I am going to show this using ns2 2.34 and AODV.
      Sometime we require packet loss to calculate trust value (in case of Trust Based protocols where it is done by no. of packets sent - no. of packets received).
       I am going to show the calculation for a particular pair of nodes.
Steps involved:-


A) We will have to add a node as a malicious node which will drop the packets
     intentionally. You can add a malicious node using this link.

B) Second, we'll set the AODV in promiscuous mode, where every node will
     listen to its neighbors.


1) We need to modify in total 3 files to set AODV in promiscuous mode, so it's
    good to take a backup of it.
    Files are:
ns-allinone-2.34/ns-2.34/aodv/aodv.ccns-allinone-2.34/ns-2.34/aodv/aodv.hns-allinone-2.34/ns-2.34/tcl/lib/ns-mobilenode.tcl 2) Open the file ns-allinone-2.34/ns-2.34/aodv/aodv.h in your favorite editor
    and make the cha…

How to color nodes in NS2

You can color the nodes in NS2. It is bit tricky to color them in a wireless network. We can do this by following code.

set node0 [$ns node]
$node0 color "blue"
$ns at 0.0 "$node0 color blue"