NS2 LAB PROGRAMS

      NS2 Lab Programs teaches you about the basics of Ns2 programming. Framing a concept is easy but the most difficult part is implementation. Once we learn to program a simulation tool than we can easily explore the world of simulation. Ns2 simulator is one of the best simulation tool used for major development in all research areas. It can use for both wired and wireless networks. To learn about Ns2 programming, we need to know how the simulator works, how it creates simulated objects, how it analysis the behavior of simulate object and the overall network operation.

Few topics where Ns2 can be worked are

  • Performance evaluation of routing protocols in ad-hoc networks
  • Power aware routing in sensor networks
  • QOS metrics in wireless adhoc and sensor networks etc
Major tools used for Ns2 simulators are
  • OTCL
  • NAM
  • X-Graph
  • Trace Graph
  • C++ and AWK
NS-2 LAB-PROGRAMS

      Ns2 Lab programs provide by us will give an insight about how an Ns2 program will run and how it is used. Let’s first see, how Ns2 simulator works in Wired and Wireless networks. In both the network, we start the simulation by creating a trace file and NAM file. Initially we define instantiate the class simulator using the keyword “new” and using the SET command.

set ns [new Simulator]

setntrace [open 1.tr w]

$ns trace-all $ntrace

set file2 [open out.nam w]

$ns namtrace-all $file2

Here, “out.tr” creates a data trace file and a NAM visualization trace file which is used later as “out.nam” during the final output. This is the basic step involve in every program that we write in Ns2. Now, lets see few basic examples:

Example code for LEACH protocol

Here the code is given for Leach protocol i.e how a cluster is formed using sending and receiving process. The following code explains about receiving process in Ns2 simulation.

void A-LEACH::recv(int link_dst, int data_size, char* meta_data, int sender)

{

if (! enableRecv_)

return;

Tcl& tcl = Tcl::instance();

tcl.evalf(“%s recv %d %d %d %s”, name_, link_dst, sender, data_size, meta_data);

}

If the message is received, next process is Cluster head updation which is coded as:

void A-LEACH::recv(char* ch_index)

{

if (! enableRecv_)

return;

Tcl& tcl = Tcl::instance();

tcl.evalf(“%s recv %s”, name_, ch_index);

}

void A-LEACH::resume()

{

if (! enableResume_)

return;

Tcl& tcl = Tcl::instance();

tcl.evalf(“%s resume”, name_);

}

Identifying Malicious node in LEACH protocol

Leach protocol can identify the malicious node in the network by comparing the argument passed during sending and receiving process.

proc malicious {} {

if(strcmp(argv[1], “task”) == 0) {

MAL1= index;

sprintf(“malicious %d”, MAL1);

return TCL_OK;

}

Program for Genetic Algorithm – Cross over process

for ( mem = 0; mem < POPSIZE; ++mem )

{

x = ( rand ( ) % 1000 ) / 1000.0;

if ( x < PXOVER )

{

++first;

if ( first % 2 == 0 )

{

Xover ( one, mem );

}

else

{

one = mem;

}

     We have given you few example programs that have been develop by us. It will give an idea of how to code in Ns2. We have best developers with us to code any concept in Ns2. We hire developers with basic qualification which includes certification courses in their respective domain. Our developers  basically 10+ years experienced and have versatile knowledge. To know more about Ns2 programs, you can contact us any time. Its better to learn practical implementation of a project than to stick on to concept. It’s our challenge that we can make you, an expert for the future world.