Presentation is loading. Please wait.

Presentation is loading. Please wait.

NS : The Network Simulator

Similar presentations


Presentation on theme: "NS : The Network Simulator"— Presentation transcript:

1 NS : The Network Simulator

2 NS-2 OVERVIEW Working with NS-2 Extending NS-2

3 NS Goals Support networking research and education
Protocol design, traffic studies, etc Protocol comparison Provide a collaborative environment Freely distributed, open source Share code, protocols, models, etc Allow easy comparison of similar protocols Increase confidence in results More people look at models in more situations Experts develop models Multiple levels of detail in one simulator

4 The Network Simulator Event driven simulator for networking research.
For free, not commercial NS-2 is an object oriented simulator, written in C++, with an OTcl (Object Tool Command Language) interpreter as a front-end. Use OTcl: for configuration, setup, and “one-time”' stuff if you can do what you want by manipulating existing C++ objects Use C++: if you are doing anything that requires processing each packet of a flow if you have to change the behaviour of an existing C++ class in ways that weren't anticipated

5 Why Two Languages? Simulator had two distinct requirements
Detailed simulation of Protocol(Run-time speed) Varying parameters or configuration(Change model & rerun) C++ is fast to run but slower to change Otcl runs much slower but can be changed quickly For information about the idea of scripting languages and split-language programming, see John Ousterhout. Scripting: Higher-level programming for the 21st century. IEEE Computer, 31(3):23-30, March 1998. For more information about split level programming for network simulation, see Improving simulation for network research. Technical Report b, University of Southern California, March (revised September 1999).

6 Discrete Event Simulation
Model world as events – simulator has list of events ordered by simulation time – process: take next one, run it, until done – each event happens in an instant of virtual (simulated) time, but takes an arbitrary amount of real time NS uses simple model: single thread of control => no locking or race conditions to worry about (very easy)

7 Discrete Event Example
Consider two nodes Simple t=1, A enqueues pkt on LAN on an Ethernet: queuing t=1.01, LAN dequeues pkt model and triggers B detailed CSMA/CD model t=1.0: A sends pkt to NIC A’s NIC starts carrier sense t=1.005: A’s NIC concludes cs, starts tx t=1.006: B’s NIC begins receiving pkt t=1.01: B’s NIC concludes pkt B’s NIC passes pkt to app

8 NS Protocols Support Wired Networking
Routing: Unicast, Multicast, and Hierarchical Routing etc Transportation: TCP and UDP Traffic sources: web, ftp, telnet, cbr, stochastic Queuing disciplines: drop-tail, RED, FQ, SFQ, DRR QoS: IntServ and Diffserv Wireless Networking Ad hoc routing and mobile IP Directed diffusion, sensor-MAC Satellite Networking Routing and Handoff etc. Infrastructure stats, tracing, error models, etc.

9 NS - Models Traffic models and applications:
Web, FTP, telnet, constant-bit rate(CBR), real audio Transport protocols: Unicast: TCP (Reno,Vegas,FullTcp,TcpSack,..), UDP Multicast: SRM (Scalable Reliable Multicast) For More Information : Routing and queuing: Wired routing, Ad Hoc routing and directed diffusion Queuing protocols: RED(Random Early Drop), drop-tail, .. Physical media: Wired (point-to-point, LANs), wireless (multiple propagation models), satellite

10 Research Using NS Intserv/Diffserv (QoS) Multicast Routing
Reliable multicast Transport TCP Congestion control Application Web caching Multimedia

11 NS - Components Ns, the simulator itself Nam, the network animator
Visualize ns (or other) output Nam editor: GUI interface to generate ns scripts Pre-processing: Traffic and topology generators Post-processing: Simple trace analysis, often in Awk, Perl, or Tcl

12 Other Network Simulators
OPNET ( • Commercial Software • Support Windows and Unix • Graphical Interface • Not free GloMoSim ( • Simulation environment for wireless network • Scalable to support thousands of nodes • Using layered approach to build different simulation layers • Free for educational users

13 Help & Resources Ns is not a polished and finished product but the result of an on-going effort of research and development. Supporting OS: FreeBSD, Linux, SunOS, and Solaris, (Windows) Getting Start NS main web page: Tutorials: NS Manual: NS Installation Problems, Bug Fixes, and Help Source tree courtesy of Shailesh Hingole

14 Working with NS-2

15 Install NS-2 • Download software package from:
Easy installation way: all at once • The latest version is 2.1b9a released on July 3, It contains - Tkrelease 8.3.2 - Otcl release 1.0a8 - TclCL release 1.0b12 - Tcl release 8.3.2 - Ns release 2.1b9a - Nam release 1.0a11a - Xgraph version 12 - CWebversion 3.4g - SGB version 1.0 - Gt-itm gt-itm and sgb2ns 1.1 - Zlib version 1.1.3

16 NS Directory Structure
ns-allinone Tcl8.0 TK8.0 OTcl tclcl ns-2 nam-1 tcl ... C++ code ex test lib mcast ... examples validation tests OTcl code

17 Running NS-2 Program

18 Running simulations with ns
Compile the simulator core (“ns”) Write a simulation script in Otcl e.g. my-test.tcl Running the simulator e.g. ns my-test.tcl

19 Writing a Simulation script
Create the event scheduler [Turn on tracing] Create network Setup routing [Insert errors] Create transport connection Create traffic Transmit application-level data

20 Creating Event Scheduler
Create event scheduler set ns_ [new Simulator] Schedule events $ns_ at <time> <event> <event>: any legitimate ns/tcl commands e.g : “$ftp start” Start scheduler $ns_ run

21 Tracing Trace packets on all links $ns_ trace-all [open test.out w]
Must appear immediately after creating scheduler Turn on tracing on specific links $ns_ trace-queue $n0 $n1 <event> <time> <from> <to> <pkt> <pkt> <flags> <fid> type size <src> <dst> <seq> <uid> cbr cbr r cbr r : receive (at Node); d : Drop ( At Queue) + : enqueue(At Queue); - : Dequeue(At Queue)

22 Creating Network Point-to-Point Network
Defining Nodes set n0 [$ns node] set n1 [$ns node] Connecting Nodes $ns_ <linktype> $n0 $n1 <bandwidth> <delay> <queuetype> <linktype> : simplex-link, duplex-link <queuetype>: DropTail, RED, CBQ, FQ, SFQ, DRR LAN(‘cau PP can’t capture sharing & contentation properties of LAN) $ns_ make-lan “$n0 $n1” $bw $delay LL Queue/DropTail Mac/Csma/Cd

23 Setup Routes Unicast $ns_ rtproto <type> <list of Nodes>
<type> : Static, Session, DV(Dynamic), Manual, etc.(Default is Static) <list of Nodes> : Nodes to run this protocol(Default is all Nodes) Cost Assignment $ns_ cost $n0 $n1 10 MultiPath Routing Node set multipath_ 1 // All Nodes $n1 set multipath_ 1 // only Node 1 Multicast $ns_ multicast (right after [new simulator]) $ns_ mrtproto <type> <type> : CtrMcast, DM(dense Model), ST(shared Tree Model) & BST(Bi-directional Shared Tree Model)

24 Inserting Errors Creating Error Module
set loss_module [new ErrorModel] $loss_module set rate_ 0.01 $loss_module unit pkt $loss_module ranvar [new RandomVariable/Uniform] $loss_module drop-target [new Agent/Null] Inserting Error Module $ns_ lossmodel $loss_module $n0 $n1

25 Creating Connection TCP set newtcp [new Agent/TCP]
[$newtcp set window_ 20] set newtcpsink [new Agent/TCPSink] $ns attach-agent $n0 $newtcp $ns attach-agent $n1 $newtcpsink $ns connect $newtcp $newtcpsink UDP similar replace tcpsink & TCPSink by null & NULL Note : Not all TCP implementations can be used as SOURCE / SINK

26 Creating Traffic: On Top of TCP
FTP set ftp [new Application/FTP] $ftp attach-agent $newtcp Telnet set telnet [new Application/Telnet] $telnet attach-agent $newtcp CBR, Exponential, Pareto set src [new Application/Traffic/CBR]

27 Summary: Generic Script Structure
#set ns [new Simulator] # [Turn on tracing] # Create topology # Setup packet loss, link dynamics # Create routing agents # Create: # - multicast groups # - protocol agents # - application and/or setup traffic sources # Post-processing procs # Start simulation

28 Network Topology: Node
Addr Classifier Port Classifier classifier_ dmux_ entry_ Node entry Multicast Classifier classifier_ dmux_ entry_ Node entry Multicast Node multiclassifier_ Unicast Node Classifier : Address, Multicast, Multipath, Hash

29 Network Topology: Link
duplex link enqT_ queue_ deqT_ drophead_ drpT_ link_ ttl_ n1 entry_ head_ tracing simplex link

30 Routing n0 n1 1 Addr Classifier Port Classifier classifier_ dmux_
entry_ Node entry enqT_ queue_ deqT_ drophead_ drpT_ link_ ttl_ n1 entry_ head_ 1

31 Routing (con’t) n0 n1 1 1 Addr Classifier Port Classifier classifier_
dmux_ entry_ Addr Classifier Port Classifier classifier_ dmux_ entry_ 1 1 Link n0-n1 Link n1-n0

32 Transport n0 n1 1 1 Port Classifier Port Classifier dst_=1.0 dst_=0.0
Addr Classifier Agent/TCP agents_ Addr Classifier Agent/TCPSink agents_ 1 1 dmux_ dmux_ Link n0-n1 entry_ entry_ classifier_ classifier_ Link n1-n0

33 Application: Traffic Generator
Port Classifier Application/FTP Port Classifier dst_=1.0 dst_=0.0 Addr Classifier Agent/TCP Addr Classifier Agent/TCPSink agents_ agents_ 1 1 dmux_ dmux_ Link n0-n1 entry_ entry_ classifier_ classifier_ Link n1-n0

34 Packet Flow n0 n1 1 1 Port Classifier Application/FTP Port Classifier
dst_=1.0 dst_=0.0 Addr Classifier Agent/TCP Addr Classifier Agent/TCPSink 1 1 Link n0-n1 entry_ entry_ Link n1-n0

35 Wireless Simulation MobileNode inherits from Node object.
MobileNode = Node + ability to move + receive/transmit signals from a wireless channel. No link object is used Ad-hoc routing protocols DSDV, AODV, TORA, DSR Different network stack for channel access Supports movement / traffic scenarios Movement is always flat (z=0)

36 Ad Hoc Routing – An Example
Scenario 2 mobile nodes moving within 500mX500m flat topology using DSDV ad hoc routing protocol TCP traffic

37 An Example – Step 1 # Define Global Variables # create simulator
set ns_ [new Simulator] # create a topology in a 500m x 500m area set topo [new Topography] $topo load_flatgrid

38 Example : Two Mobile Node establish a TCP session
between them over a 500x500 grid.

39 An Example – Step 2 # Define standard ns/nam trace # ns trace
set tracefd [open demo.tr w] $ns_ trace-all $tracefd # nam trace set namtrace [open demo.nam w] $ns_ namtrace-all-wireless $namtrace

40 An Example – Step 3 # Create God set god [create-god 2]
God: store an array of the smallest number of hops required to reach one node to an other Optimal case against which to compare routing protocol performance Automatically generated by scenario file

41 An Example – Step 4 # Define how a mobile node should be created
$ns_ node-config \ -adhocRouting DSDV \ -llType LL \ -macType Mac/802_11 \ -ifqLen 50 \ -ifqType Queue/DropTail/PriQueue \ -antType Antenna/OmniAntenna \ -propType Propagation/TwoRayGround \ -phyType Phy/WirelessPhy \ -channelType Channel/WirelessChannel \ -topoInstance $topo -agentTrace ON \ -routerTrace OFF \ -macTrace OFF

42 An Example – Step 5 Single Node
# Create a mobile node, attach it to the channel set node_(0) [$ns_ node] # disable random motion $node_(0) random-motion 0 Set of Nodes Use “for” loop to create 2 or more nodes: for {set i < 0} {$i < 2} {incr i} { set node_($i) [$ns_ node] $node_($i) random-motion 0 }

43 An Example – Step 6 # Define node movement model
source movement-scenario-files # Define traffic model source traffic-scenario-files

44 Scenario Generator: Movement
Mobile Movement Generator setdest -n <num_of_nodes> -p <pausetime> -s <maxspeed> -t <simtime> -x <maxx> -y <maxy> Source: ns-2.1b9/indep-utils/cmu-scen-gen/setdest/ Random movement $node start

45 An Example – Step 6 Node Movement $node_(0) set X_ 200.00
$node_(0) set Y_ $node_(1) set Y_ $node_(0) set Z_ $node_(1) set Z_ $ns_ at 10 $node_(0) setdest $ns_ at 12 $node_(1) setdest Always test your changes/debug with a small set of nodes like above

46 Scenario Generator: Traffic
Generating traffic pattern files CBR traffic ns cbrgen.tcl [-type cbf|tcp] [-nn nodes] [-seed seed] [-mc connections] [-rate rate] TCP traffic ns tcpgen.tcl [-nn nodes] [-seed seed] Source: ns-2.1b9/indep-utils/cmu-scen-gen/

47 A Traffic Scenario set newtcp [new Agent/TCP] [$newtcp set window_ 20]
set newtcpsink [newAgent/TCPSink] $ns attach-agent $node_(0) $newtcp $ns attach-agent $node_(1) $newtcpsink Set app [new Application/FTP] $app_(0) attach-agent $newtcp $ns_ connect $newtcp $newtcpsink $newtcpsink listen $ns_ at 5.00 "$app_(0) start"

48 An Example – Step 7 # Define node initial position in nam
for {set i 0} {$i < 2 } { incr i} { $ns_ initial_node_position $node($i) 20 } set val_(stop) 50.0 # Tell ns/nam the simulation stop time for { set i 0} { $i < 2} {incr I} { $ns_ at $val(stop).0 “$node_($I) reset”; $ns_ at $val_(stop).0001 “stop” $ns_ at $val_(stop).0002 “$ns_ halt” proc stop { } { global ns_ tracefd close $tracefd # Start your simulation $ns_ run

49 Internals: Relevant Components

50 Mobile Node

51 Mobile Node : Components
Link Layer Same as LAN, but with a separate ARP module Sends queries to ARP ARP Resolves IP address to hardware(MAC) address Broadcasts ARP query Interface Queue Gives priority to routing protocols packets Has packet filtering capacity MAC 802.11 RTS/CTS/DATA/ACK for unicast Sends DATA directly for broadcast SMAC (work under progress)

52 Mobile Node : Components
Network Interface (PHY) Used by mobile node to access channel Stamps outgoing pkts with meta-data Interface with radio/antenna models Radio Propagation Model Friss-space model – attenuation at near distance Two-ray ground reflection model for far distance Shadowing model – probabilistic Antenna Omni-directional, unity gain Wireless Channel Duplicate packets to all mobile nodes attached to the Channel except the sender It is the receiver’s responsibility to decide if it will Accept the packet

53 SMAC SMAC – MAC designed for sensor networks
Similar RTS/CTS/DATA/ACK like Additional sleep-wakeup cycles Reduces energy consumptions during idle phases Much in development

54 Energy Extension Node is energy-aware
Define node by adding new options: $ns_ node-config \ -energyModel $energymodel \ -initialEnergy \ -txPower 0.6 \ -rxPower 0.2

55 A Brief on MobileIP Support
Developed by Sun Require a different Node structure than the MobileNode Co-exists with wired world in ns Standard MobileIP Home Agent, Foreign Agent, MobileHosts… Example tcl/ex/wired-cum-wireless.tcl

56 A Brief on Satellite Networking
Developed by Tom Henderson (UCB) Supported models Geostationary satellites: bent-pipe and processing-payload Low-Earth-Orbit satellites Example: tcl/ex/sat-*.tcl Much in-development

57 Extending NS-2

58 Class Hierarchy in ns(Partial)
TclObject NsObject Connector Classifier Queue Delay Agent Trace AddrClassifier McastClasifier DropTail RED TCP Enq Deq Drop Reno SACK

59 Creating New Components
Extending ns in Otcl source your changes in your simulation scripts Extending ns in C++ Change Makefile (if created new files) make depend recompile

60 Two Imp. Tcl files ns-default.tcl: The default values for configurable parameters for various network components are located here. Since most of network components are implemented in C++, the configurable parameters are actually C++ variables made available to OTcl via an OTcl linkage function, bind(C++_variable_name, OTcl_variable_name). ns-packet.tcl: The packet header format initialization implementation is located here. When you create a new packet header, you should register the header in this file to make the packet header initialization process to include your header into the header stack format and give you the offset of your header in the stack.

61 Extending NS in C++ Decide position in class hierarchy
i.e., which class to derive from? Create new packet header (if necessary) Create C++ class, fill in methods Define OTcl linkage (if any) Write OTcl code (if any) Build (and debug)

62 Adding New Classes variables procedures New Class otcl New Class
bind() command() otcl TclClass() New Class variables procedures C++

63 New Packet Header Enable Tracing(packet.h)
enum packet_t { PT_TCP, …, PT_<NewName1>, PT_NTYPE // This must be Last one } class p_info { ….. name_[PT_<NewName1>] = “<NewName2>”; name_[PT_NTYPE] = “undefined”; Register New Header (tcl/lib/ns-packet.tcl) foreach prot { { common off_cmn_ } …. { <NewName2> off_<NewName3>_ }

64 TclObject::bind() Link C++ member variables to OTcl object variables
TcpAgent::TcpAgent() { bind(“window_”, &wnd_); … … } OTcl set tcp [new Agent/TCP] $tcp set window_ 200

65 Initialization of Bound Variables
Initialization through OTcl class variables Agent/TCP set window_ 50 Do all initialization of bound variables in ~ns/lib/ns-default.tcl Otherwise a warning will be issued when the shadow object is created

66 TclObject::command()
OTcl space no such procedure $tcp advance TclObject::unknown{} $tcp cmd advance C++ space TcpAgent::command() Yes match “advance”? No process and return Invoke parent: return Agent::command()

67 Calling C++ functions from Otcl
int TcpAgent::command(int argc,const char*const* argv) { if (argc == 3) { if (strcmp(argv[1], “advance”) == 0) { int newseq = atoi(argv[2]); …… return(TCL_OK); } return (Agent::command(argc, argv); OTcl set tcp [new Agent/TCP] $tcp advance 10

68 Calling Otcl functions from C++
Agent/TCP instproc advance {num} { set window_ [expr $window_ + $num] return $window_ } C++ Tcl& tcl=Tcl::instance(); //obtain a ref. to the class Tcl instance char *result; tcl.evalf(“%s advance %d”, name_, size); result = tcl.result(); wnd_ = atoi(result);

69 Credit CMU UC Berkeley Sun Microsystem Inc. USC/ISI

70 Installing NS-2.1b9 Download may take a long time, so I have kept a copy of it on topaz under /usr/work/mkumar. If you have login for cs server, you can access it by using as src Sun/Linux Error Message : tclsh/namespace : Invalid command/command not found Soln. : touch ~tcl8.3.2/generic/tclStubInit.c Error Message On Linux: common/tclAppInit.cc:103: parse error before `::‘ Soln. edit ns-2.1b9/common/tclAppInit.cc put a space or two between the colons on that line.  It will end up looking like this:       asm volatile ("fldcw %0" :  : "m" (cw)); Error Message On Sun Machines : gcc: pic: No such file or directory (and/or) gcc: unrecognized option `-K' Soln. Line 139 in otcl-1.0a8/configure.in, line 17 in otcl-1.0a8/Makefile.in & Line 4266/4273 in otcl-1.0a8/configure Replace "-K pic” by “-fpic”


Download ppt "NS : The Network Simulator"

Similar presentations


Ads by Google