ns2 tutorial CSCI 5931 Network Security Instructor Dr









![Example : TCP n 0 set ns [new Simulator] set n 0 [$ns node] Example : TCP n 0 set ns [new Simulator] set n 0 [$ns node]](https://slidetodoc.com/presentation_image_h/77823bd149899478538293162a64ab0d/image-10.jpg)
![Script to start nam set nf [open out. nam w] $ns namtrace-all $nf proc Script to start nam set nf [open out. nam w] $ns namtrace-all $nf proc](https://slidetodoc.com/presentation_image_h/77823bd149899478538293162a64ab0d/image-11.jpg)

![References [1] slides by John Heidemann http: //sce. cl. uh. edu/yang/teaching/csci 5931 net. Security. References [1] slides by John Heidemann http: //sce. cl. uh. edu/yang/teaching/csci 5931 net. Security.](https://slidetodoc.com/presentation_image_h/77823bd149899478538293162a64ab0d/image-13.jpg)
- Slides: 13
ns-2 tutorial CSCI 5931 Network Security Instructor : Dr. T. Andrew Yang Karthik Sadasivam Banuprasad Samudrala
Introduction n n Ns-2 is a discrete event simulator targeted at network research focused on modeling network protocols n n n wired, wireless, satellite TCP, UDP, multicast, unicast web, telnet, ftp ad hoc routing, sensor networks infrastructure: stats, tracing, error models, etc
Goals of ns n support networking research and education n protocol design, traffic studies, etc. protocol comparison provide a collaborative environment n freely distributed, open source n n n allow easy comparision of similar protocols increase confidence in results n n share code, protocols, models, etc. models provide useful results in several situations multiple levels of detail in one simulator
ns status n n platforms: basically all Unix and Windows size: about 200 k loc each C++ and Tcl, 350 page manual user-base: >1 k institutions, >10 k users releases about every 6 months, plus daily snapshots
Components of ns n n ns, the simulator itself nam, the Network Ani. Mator n n n pre-processing: n n visualize ns (or other) output GUI input simple ns scenarios traffic and topology generators post-processing: n simple trace analysis, often in Awk, Perl, or Tcl
ns Software Structure: C++ and Otcl n n Uses two languages C++ for packet-processing n n OTcl for control n n fast to run, detailed, complete control simulation setup, configuration, occasional actions fast to write and change pros: trade-off running vs. writing speed, powerful/documented config language cons: two languages to learn and debug in
o. Tcl and C++: The Duality C++ otcl n n OTcl (object variant of Tcl) and C++ share class hierarchy Tcl. CL is glue library that makes it easy to share functions, variables, etc.
Installation and documentation n http: //www. isi. edu/nsnam/ns/ n n download ns-allinone includes Tcl, OTcl, Tcl. CL, ns, nam, etc. mailing list: ns-users@isi. edu documentation (see url above) n n Marc Gries tutorial ns manual
Steps to set up the simulation n n n Initialize the simulator Define files for output (tracing) Set up the topology Set up the “agents” Set up the traffic between the nodes Start the simulation Analyze the trace files to compute the parameters of interest
Example : TCP n 0 set ns [new Simulator] set n 0 [$ns node] set n 1 [$ns node] $ns duplex-link $n 0 $n 1 1. 5 Mb 10 ms Drop. Tail set tcp [new Agent/TCP] set tcpsink [new Agent/TCPSink] $ns attach-agent $n 0 $tcp $ns attach-agent $n 1 $tcpsink $ns connect $tcpsink n 1 set ftp [new Application/FTP] $ftp attach-agent $tcp $ns at 0. 2 "$ftp start" $ns at 1. 2 ”exit" $ns run
Script to start nam set nf [open out. nam w] $ns namtrace-all $nf proc finish {} { global ns nf $ns flush-trace close $nf exec nam out. nam & exit 0 } # your code goes in here $ns at 12. 0 "finish" # 12. 0 is the simulation time in secs
Screenshots Project B. 1 Project B. 2
References [1] slides by John Heidemann http: //sce. cl. uh. edu/yang/teaching/csci 5931 net. Security. Spr 05/johnh_cl ass_slides_sp 2003. ppt [2] ns 2 website: http: //www. isi. edu/nsnam/ns [3] ns-2 Tutorial: http: //www. isi. edu/nsnam/ns/tutorial/nsindex. html [4] Tcl/Tk tutorial : http: //hegel. ittc. ukans. edu/topics/tcltk/tutorialnoplugin/