TCL/OTCLhttp://www.mathcs.emory.edu/~cheung/Courses/... Visualizing Network Activities in NS The Network Animator (NAM) Tool The Network Animator (nam) is a completely separate program that is distributed with the NS simulator This program is named nam and it shows the progression of the packets through the network. The nam program reads an input file (containing the packet transmission events) and draw the network events graphically. Running NAM nam is a UNIX program and it is run as a command line. Example: UNIX>> nam nam.input nam.input is the file that contains network events The key to making the animation input file is to tell NS to output network events into a file for nam to use. It's very simple... Make NS output network event information for NAM Do the following: 1. Create an output file 2. Activate the NAM trace feature in NS before running the simulation (this will tell NS to write NAM events outputs to the output file) 3. Close output file at the end of the simulation run Then you can run nam with the output file (as input file for nam) Here is an example of code in Tcl to achieve this: # (1) Create the trace file set namfile [open out.nam w] # (2) Tell NS to write NAM network events to this trace file $ns namtrace-all $namfile # ################################################ # (3) Close output file at the end of the simulation run proc finish {} { global ns namfile $ns flush-trace close $namfile exec nam out.nam & exit 0 } ;# flush trace files ;# close trace file ;# OPTIONAL: run NAM from inside the NS simulation Example Program: (Reno code with NAM) 1 of 3 04/02/2011 08:39 PM Example Program: (Reno code with NAM . you can press a "re-layout" button in NAM to make NAM re-arrange the nodes. down left-up. right-down Examples: $ns duplex-link-op $n0 $n1 orient left Make link n0-n1 orient to left $ns duplex-link-op $n0 $n1 orient left-down Make link n0-n1 orient to left-down $ns duplex-link-op $n0 $n1 orient left-up Make link n0-n1 orient to left-up $ns duplex-link-op $n0 $n1 orient right Make link n0-n1 orient to right $ns duplex-link-op $n0 $n1 orient right-down Make link n0-n1 orient to right-down $ns duplex-link-op $n0 $n1 orient right-up Make link n0-n1 orient to right-up NOTE: if things do not look good...nam to see a nicer network animation 2 of 3 04/02/2011 08:39 PM .nam" as output When it finishes. Run the program using ns Reno1-nam.mathcs..emory.tcl.positioned nicely) Prog file: click here Run the program using ns Reno1-nam-2. The nodes and links are placed very awkwardly All packets (from all flows) are colored black We can change some parameters in the animation from inside NS ! Placing Nodes to make NAM animations look good We can manipulate the placement of nodes through the $ns duplex-link-op (or $ns simplexlink-op) method on an existing link (to suggest a "direction"): left. right up. Making a better animation The output does not look very good.. it will produce "out.nam" as output When it finishes. it will produce "out...nam to see the packets flow. left-down right-up.tcl.edu/~cheung/Courses/..TCL/OTCL Prog file: click here http://www. run: nam out. run: nam out. 3 of 3 04/02/2011 08:39 PM . For example. Coloring Packets from different sources Each TCP (or UDP) agent has a built-in flow id variable named Each packet from a flow will have this given You can assign a value to the fid_ fid_ fid_ value... When NAM is run.nam to see blue packets.mathcs..tcl. Example Program: (Reno code with NAM ..TCL/OTCL http://www. The different colors can highlight which packets are being dropped.. it will produce "out. of a TCP/UDP agent using the set command: $tcp1 set fid_ 234 You can "color" packets from a given TCP/UDP agent by assigning a color to a certain flow id value. these packets will be colored blue. if you want packets that has fid_ = 234 colored blue.nam" as output When it finishes.emory..positioned nicely) Prog file: click here Run the program using ns Reno1-nam-3.edu/~cheung/Courses/. run: nam out. then use: $ns color 234 blue This set the color of the packets of flow 234 to blue.