Skip to main content

Posts

Showing posts with the label ns2

Traffic Flow on Nodes in NS2

Traffic Flow on Nodes in NS2 In this tutorial, we are going to create some nodes and then enable the flow of traffic on those nodes. There are two ways to flow the traffic i.e. through TCP and UDP. We will use both in this tutorial.   #Create a simulator object set ns [new Simulator] #Define different colors for data flows (for NAM) $ns color 1 Blue $ns color 2 Red $ns color 3 Black #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 NAM trace file         close $nf         #Execute NAM on the trace file         exec nam out.nam &         exit 0 } #Create four nodes set n0 [$ns node] set n1 [$ns node] set n2...

Tcl and OTcl Tutorial For NS2 variables and arrays

Tcl and OTcl Tutorial For NS2 variables and arrays Variables and arrays Defining a variable in Tcl is very simple: set var1 1 set var2 "Tcl Variable 2" The variables can be referenced by prefixing the variable name with a $. For example to print the above variables, we can use puts "var1=$var1, var2=$var2" Any situation in which you require that the value of the variable be used is one in which the $ prefix should be added to the variable name. In some situations, it is necessary to use the variable name directly. For example incr var1 can be used to increment var1. I guess you can think of it as the difference between call-by-reference and call-by-value: in the former case you use the variable name on its own, while in the latter you prefix it with a $. An alternative is to assign the results of a function to a variable. This can be done as follows: set var3 [expr 5*10] This sets the variable var3 to the result of calling the  expr  function with the parameter  5*1...

TOUR DE NS2 REVEALING SECRETS BEHIND COMMAND MAKE AND MAKEFILE

TOUR DE NS2 REVEALING SECRETS BEHIND COMMAND MAKE AND MAKEFILE Friends, We are decided to introduce a new segment in our blog named as " ToUr De Ns2 " to get you more familiar with ns2 directories, folders and commands that we used in the ns2. We hope it gives you all a deep knowledge in ns2. We need all your supports and prayers. Comments and new ideas are welcomed. Now we are going to have a deep look in command make . We all know that ns2 is a research tool. So all of the researchers are tried to customize files or to add new C++ modules in ns2 directory. During this time, it is necessary to recompile all the files that related or depend with it. So we need an effective command for recompilation of all files because manual recompilation is not possible. For that we here use a UNIX utility tool called as " make ". This command has a significant role in development process. It keeps track of all the files created throughout the development process. By keeping track...

Tcl and OTcl Tutorial for NS2 Program to find Factorial

Tcl and OTcl Tutorial for NS2 Program to find Factorial  Fractorial Computation:  tcl script to obtain the value of 10! = 10 * 9 * ... * 1. get factorial.tcl and run the script; write a function to compute 2^x, test your answer. Execute the script as: $ tclsh lab1a.tcl or $ ns lab1a.tcl ################################################################################ #filename : factorial.tcl # define function to compute Factorial X! proc Factorial {x} {     # define variable     set result 1         # for loop     for {set i 1} {$i <= $x} {incr i} { set result [expr $result * $i]     }         # return computation result     return $result } ############################################################################# # define function to compute 2^x proc 2pow {x} {     # define variable     set result 1         # for loop   ...

Tcl and OTcl Tutorial For NS2 Loops and Conditional Statements

Tcl and OTcl Tutorial For NS2 Loops and Conditional Statements For loops For loops are very useful in ns and can be used in conjunction with arrays to easily create larger network topologies. To generate 100 nodes, the following code can be used: for {set i 0}{$i < 100}{incr i} {     set n($i) [$ns node] } While loops These are very similar to for loops. The syntax is set i 0 while {$i < 10} {     set n($i) [new Node]     incr i } If statements If statements are very simple if {$i < 10} {     puts "i is less than 10" } if {$var2 == "Tcl Variable 2"} {     puts "var2 = Tcl Variable 2" } download  file  now

Traffic pattern based performance comparison of two reactive routing protocols for Ad hoc networks using NS2

Traffic pattern based performance comparison of two reactive routing protocols for Ad hoc networks using NS2 Ad hoc networks are characterized by wireless connectivity, continuous changing topology, distributed operations and ease of deployment. Routing in Ad hoc networks is a challenge due to mobility and thus is a current area of research. We compare two reactive routing protocols by considering multiple performance metrics to bring out their relative merits. Both DSR and AODV share similar on demand behavior, but the protocols internal mechanism leads to significant performance differences. We have analyzed the performance of protocols by varying network load, mobility and type of traffic (CBR, TCP). A detailed simulation has been done using NS2. We consider packet delivery fraction, normalized routing load, average delay, routing overhead, and packet loss as metrics for performance analysis of these protocols. The TCL code is available here : Click here download  file  now

TOUR DE NS2 REVEALING PROGRAMMING STYLE

TOUR DE NS2 REVEALING PROGRAMMING STYLE Friends, Today we are going to have a look in why we run ns2 program as "ns program.tcl"? Before that we have to go through basic C++ programmings in ns2.Consider a basic C++ instruction only program i .e for example; we are considering a program to calculate time taken for a packet travel from uppermost node to lower most node with the time taken to travel packet between each nodes (t) are constant (say t=1ms) and the number of nodes as n. (say n=10). And we have to find out overall time taken to reach packet to lowermost node. The C++ program new.cc is given below and after compiling we get a executable file " new ". //new.cc main(){ float time = 0 , t = 1; int i, n = 10;  for(i = 1; i < n; i++) time = time+i ; printf("Overall time is  %f seconds. ",time); } Now we execute the program from terminal, we can see the following results; >> ./new Overall time is 10.0 seconds. But this programming style is not ...

Tcl and OTcl Tutorial For NS2 Procedures

Tcl and OTcl Tutorial For NS2 Procedures Procedures Procedures are an essential component of Tcl and can be used to make programming ns simpler. As in any functional programming language, procedures can be used for repetitive tasks, or simply to logically break down the tasks in the program. Procedures are defined in Tcl as follows: proc proc1 {} {     puts "in procedure proc1" } This defines a procedure that takes no parameters and prints out "in procedure proc1". To call this procedure proc1 can be used. A procedure with parameters can be defined as follows: proc proc2 {parameter1} {     puts "the value of parameter1 is $parameter1" } This procedure can be invoked as follows: proc2 10 A procedure that returns a value can be defined as follows: proc proc3 {min max} {     set randomvar [rand $min $max]     return $randomvar } This procedure generates a random variable and returns it to the calling function. This can be invoked ...