May 27, 2013

Xgraph in NS2

 

One part of the ns-allinone package is 'xgraph', a plotting program which can be used to create graphic representations of simulation results. In this section, I will show you a simple way how you can create output files in your Tcl scripts which can be used as data sets for xgraph. On the way there, I will also show you how to use traffic generators.
A note: The technique I present here is one of many possible ways to create output files suitable for xgraph. If you think there is a technique which is superior in terms of understandablity (which is what I aim for in this tutorial), please let me know.


First of all, we create the following topology:
 
Nam snap shot
 
The following piece of code should look familiar to you by now if you read the first sections of this tutorial.



set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]

$ns duplex-link $n0 $n3 1Mb 100ms DropTail
$ns duplex-link $n1 $n3 1Mb 100ms DropTail
$ns duplex-link $n2 $n3 1Mb 100ms DropTail
$ns duplex-link $n3 $n4 1Mb 100ms DropTail


May 22, 2013

NS2 installation using Ubuntu Software Center

There is an absolute easy way to install ns2 (network simulator) by using the easiest technique available on ubuntu. 
Let us install ns2 in a very nice and easy way. Ubuntu Software Center provides with ease to install different softwares by wizard.

Here is how it is done.

Open “Ubuntu Software Center” as hightlighted in the below figure.



Now, in the search box on the top right corner. Write ns2 and press enter.


You will see the package. Hit install button and it will install ns2. Ofcourse, internet connectivity is must :)
Similarly, you can install nam(network animator) by following the same procedure. Just enter "nam" in the search box and hit enter.

Install the first package that you see. And there you go, you have installed ns2 and nam .  You can always install it using terminal simply by writing the following command.

sudo apt-get install ns2 nam xgraph


Remember, when you do the same in Ubuntu 13.04, it will not show you the desired ns2 package. And you will have to install it manually. I guess this is only available for 12.04 version. So, there is another way available if you want to install ns2 in that version.

This could be resolved by applying the following command.


sudo apt-get update


When the update is completed, go and run the command to install ns2 , nam and xgraph. If you want an easy way out to install Ubuntu using windows. Please click here.

 

May 21, 2013

Dynamic Nodes generation and traffic flow in ns2

Here is the code for dynamically creating nodes and create traffic flow dynamically using protocol.


#Create a simulator object
set ns [new Simulator]

#Tell the simulator to use dynamic routing
$ns rtproto DV

#Open the nam trace file
set nf [open out.nam w]
$ns namtrace-all $nf


#Define a 'finish' procedure
proc finish {} {
        global ns nf
        $ns flush-trace
#Close the trace file
        close $nf
#Execute nam on the trace file
        exec nam out.nam &
        exit 0
}

#Create seven nodes
for {set i 0} {$i < 7} {incr i} {
        set n($i) [$ns node]
}


#Create links between the nodes
for {set i 0} {$i < 7} {incr i} {
        $ns duplex-link $n($i) $n([expr ($i+1)%7]) 1Mb 10ms DropTail
}

#Create a UDP agent and attach it to node n(0)
set udp0 [new Agent/UDP]
$ns attach-agent $n(0) $udp0

# Create a CBR traffic source and attach it to udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0

C program to Read From a File

#include <stdio.h> #include <stdlib.h> void main() {     FILE *fptr;     char filename[15];     char ch;   ...