NS2 PROGRAMMING GUIDE

     NS2 Programming Guide support helps you to code for your project, assignments, lab cycles and research work.  We have started our service with an initial effort of top experts from the world; today we are renowned to say that we have created 1000+ experts with the help of our guidance and support. NS2 is one of the major and popular simulators used in the midst of scholars and researchers. It is obvious that learning NS2 will uplift your career and performance. Then why you are thinking still, take your mobile and click our numbers.

You can also approach us through our online guidance service to get 24/7 experts aid. If you want to learn programming guide completely, don’t waste your time by taking a course in NS2, just have a session with our experts and feel the difference.

NS-2 PROGRAMMING-GUIDE

     NS2 Programming guide is one of the major services focused by us, with the help of our top experts and developers. Everyone can work on theoretical part; but only few can work on implementation part. We feel that students must be good enough in both the parts to make their project effective and proficient. This is the reason we offer, practical explanation for our every work, we undertake.

We provide complete tutoring service through online for the beginners to learn NS2 and work on it.  We follow project based learning approach, where you can learn to code in NS2 along with your project or assignments. To make you clear with the basic coding in NS2, we have provided few basic concepts and command in NS2 below. If you need any other information about NS2, you can refer our other articles in this page.

Learn to program in NS2

NS2 [Network simulator 2] is used to simulate the behavior of Networks by creating network topologies and log events.

Languages used to code in NS2
  • C++[For the purpose of programming]
  • TCL-Tool command language[For the purpose of scripting]

Basic commands in NS-2

To begin the Simulation:

            $ns Run

NS 2 Simulation starts with the command:

        Set ns [new simulator]

This is the first line used in TCL script, which is used to declare a new variable “ns” using the Set command.

Commands for Trace and NAM files:

Both these files are used to output files. Trace files are used to store the simulation data and NAM files are used to visualize the overall result.

To open the trace file:

                         Set tracefile1 [open out. tr w]

                          $ ns trace-all $trace file 1

To open the NAM file:

                     Set namfile[open out. nam w]

                    $ ns namtrace-all $namfile

        These both commands are used to create and open trace files in NS2 using TCL script. Nam files and trace files are not called using by using their names; it is called by using pointers like tracefile1 and Namfile used in the above syntax.

To create a link or node in NS2:

             Set n1[$ns node]

To create a link, use the following example syntax,

   $ns duplex link $n1 $n2 10Mb 100ms Droptail

To create a random variable in NS2

Set MyRng1[new RNG]

$MyRng2 seed2

Various distributions are used to create random variables in NS2. We can use pareto, Constant, uniform or exponential distribution.

To terminate the program:

Use “Finish”  procedure to terminate the overall program

Proc finish {} {

             Global ns tracefile2 namfile

                   $ns flush trace

                 Close tracefile2

                 Close Namfile

                  Exec nam out.nam &

                   Exit}

To terminate a program in a specific time use:

$ns at 126.0 “Finish”

These all provides an overview of NS2 guide. These are the basic syntax and commands used in NS-2 programming, which is used to write a complete code in NS-2. We have provided this content here for students to first learn some basics of NS-2.  In case, you wish to learn advanced programming concepts in NS2, you can approach us through our online tutoring service. We also offer our complete guidance for students to undertake a project, assignment or research in NS2. For better understanding about NS2 programming, we have provided few code examples in NS2 below. These are specific code for particular concept, to write a complete program for your projects or assignments, aid help from our experts through online. They will teach you step by step procedure to implement your project completely.

Sample programs in NS2

Example 1: Spectrum Decision

proc SpectrumData {} {

FILE* fd;

for (int i=0; i<MAX_CHANNELS; i++)  {

int channel;

float bandwidth;

float per;

fscanf(fd,”%d %f %f”,&channel,&bandwidth,&per);

if (IO_SPECTRUM_DEBUG)

fprintf(channel, bandwidth, per);

spectrum_table_[channel].bandwidth=bandwidth;

spectrum_table_[channel].per=per;

}

fclose(fd);

}

proc command {} {

if(argc == 3) {

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

read_spectrum_file((char*)argv[2]);

return TCL_OK;

}}

return TCL_OK;

}

proc SpectrumDecision {} {

decision_policy_=DECISION_POLICY_ALWAYS_SWITCH;

spectrum_policy_=SWITCH;

smanager_=sm;

double USRPValue;

bool switch_decision;

switch(decision_policy_) {

case DECISION_POLICY_PROBABILISTIC_SWITCH:

USRPValue=USRP::uniform();

if (USRPValue < THRESHOLD_SWITCH)

switch_decision=true;

else

switch_decision=false;

break;

case DECISION_POLICY_ALWAYS_SWITCH:

switch_decision=true;

break;

default:

switch_decision=true;

break;

}

return switch_decision;

}

Example 2: Spectrum Allocation

proc receiver {}{

double active=false;

double TX_POWER=0.2818;

for (int i=0; (i< number_pu_); i++){

if ((pu_data[i].main_channel==channel) && (distance_receiver(x,y,i) < pu_data[i].radius) ){

active=check_active(timeNow,txtime,i);

if (active){

interference_power_+=((TX_POWER * pow(1.5,4))/(pow(distance_receiver(x,y,i),4))) * txtime;

interference_events_++;

}}}}

proc USRP_channel {} {

int channel=((int)(USRP::uniform()*MAX_CHANNELS))+1;

if (channel >= MAX_CHANNELS)

channel = MAX_CHANNELS-1;

return channel;

}

proc decideSpectrum {}{

int next_channel;

switch(decision_policy_){

case USRP_SWITCH:

next_channel=((int)(USRP::uniform()*MAX_CHANNELS))+1;

if (next_channel >= MAX_CHANNELS)

next_channel = MAX_CHANNELS-1;

break;

case SWITCH:

next_channel=(current_channel+1) % MAX_CHANNELS;

if (next_channel ==0)

next_channel++;

break;}

for (int i=0; i<MAX_NODES; i++) {

int channel=get_USRP_channel();

repository_table[i].recv_channel= channel;}

for (int node=0; node<MAX_NODES; node++)

for (int channel=0; channel< MAX_CHANNELS; channel++)

repository_table_sender[node][channel].active=false;

return next_channel;}

      Hope you are contented with our information, if you feel to have more information approach us through online or by making one call to us. We provide complete support for NS-2 programming to make you hassle free regarding your projects, assignments and research work.

FEEL OUR GUIDANCE…………

KNOW OUR VALUE………………

AND LEARN TO CODE IN NS2…………………………