Download presentation
Presentation is loading. Please wait.
1
1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: http://networks.cs.ucdavis.edu/~lijian/289I/
2
2 Agenda What Is NS? Elements of Simulation NS Architecture NS Internals Summary
3
3 What is NS Discrete event simulator Packet-level Protocol stack -Link layer and up for wired networks; -Physical layer and up for wireless networks Wired and wireless(both local and satellite) Detour
4
4 History and Status Now part of VINT(Virtual InterNet Testbed) project -Columbia NEST --> UCB REAL --> NS-1 --> NS-2 Users from approximately -600 institutes -50 countries Releases -Periodic releases (currently 2.1b9, April 2002) -Nightly snapshots (probably compiles and works, but “unstable”) -Available from: USC/ISI, UC Berkeley, UK mirror
5
5 Platforms Most UNIX and UNIX-like systems FreeBSD or *BSD Linux Sun Solaris HP, SGI Window 95/98/NT -Some work, some does not (Emulation only for FreeBSD for now)
6
6 Functionality of NS Wired world -Point-to-point link, LAN -Unicast/multicast routing -Transport -Application layer Wireless -Mobile IP -Ad hoc routing Tracing, visualization, various utilities
7
7 Visualization Tools nam-1 (Network AniMator Version 1) -Packet-level animation -Well supported by ns xgraph -Conversion from ns trace to xgraph format
8
8 Getting Started NS official site: -http://www.isi.edu/nsnam/ns/http://www.isi.edu/nsnam/ns/ A painless tutorial by Marc Greis: -http://www.isi.edu/nsnam/ns/tutorial/index.htmlhttp://www.isi.edu/nsnam/ns/tutorial/index.html Another good tutorial from WPI -http://nile.wpi.edu/NS/http://nile.wpi.edu/NS/
9
9 Getting Help & Reference Building NS -http://www.isi.edu/nsnam/ns/ns-build.htmlhttp://www.isi.edu/nsnam/ns/ns-build.html NS user mailing list -http://mailman.isi.edu/mailman/listinfo/ns-usershttp://mailman.isi.edu/mailman/listinfo/ns-users NS manual -http://www.isi.edu/nsnam/ns/ns-documentation.htmlhttp://www.isi.edu/nsnam/ns/ns-documentation.html
10
10 Agenda What Is NS? Elements of Simulation NS Architecture NS Internals Summary
11
11 Elements of Simulation Create the event scheduler [Turn on tracing] Create network Setup routing [Insert errors] Create traffic Start simulation Post-process trace Detour
12
12 Creating Event Scheduler Create event scheduler -set ns [new Simulator] Schedule events -$ns at - : any legitimate ns/tcl commands Start scheduler -$ns run
13
13 Tracing Trace packets on all links -$ns trace-all [open test.out w] -- -- + 1 0 2 cbr 210 ------- 0 0.0 3.1 0 0 - 1 0 2 cbr 210 ------- 0 0.0 3.1 0 0 r 1.00234 0 2 cbr 210 ------- 0 0.0 3.1 0 0 Trace packets on all links in nam-1 format -$ns namtrace-all [open test.nam w] Turn on tracing on specific links -$ns trace-queue $n0 $n1 -$ns namtrace-queue $n0 $n1 Must appear immediately after creating scheduler
14
14 Creating Network Nodes -set n0 [$ns node] -set n1 [$ns node] Links and queuing -$ns duplex-link $n0 $n1 - : DropTail, RED, CBQ, FQ, SFQ, DRR
15
15 Creating Network: LAN LAN -$ns make-lan - : LL - : Queue/DropTail, - : MAC/802_3 - : Channel
16
16 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
17
17 Network Dynamics Link failures -Hooks in routing module to reflect routing changes Four models $ns rtmodel Trace $n0 $n1 $ns rtmodel Exponential { } $n0 $n1 $ns rtmodel Deterministic { } $n0 $n1 $ns rtmodel-at up|down $n0 $n1 Parameter list [ ] [ ]
18
18 Setup Routing Unicast -$ns rtproto - : Static, Session, DV, cost, multi-path Multicast -$ns multicast (right after [new Simulator]) -$ns mrtproto - : CtrMcast, DM, ST, BST
19
19 Creating Connection: UDP or TCP UDP -set udp [new Agent/UDP] -set null [new Agent/Null] -$ns attach-agent $n0 $udp -$ns attach-agent $n1 $null -$ns connect $udp $null TCP -set tcp [new Agent/TCP] -set tcpsink [new Agent/TCPSink] -$ns attach-agent $n0 $tcp -$ns attach-agent $n1 $tcpsink -$ns connect $tcp $tcpsink
20
20 Creating Traffic: On Top of UDP CBR -set src [new Application/Traffic/CBR] Exponential or Pareto on-off -set src [new Application/Traffic/Exponential] -set src [new Application/Traffic/Pareto]
21
21 Creating Traffic: On Top of TCP FTP -set ftp [new Application/FTP] -$ftp attach-agent $tcp Telnet -set telnet [new Application/Telnet] -$telnet attach-agent $tcp
22
22 Creating Traffic: Trace Driven Trace driven -set tfile [new Tracefile] -$tfile filename -set src [new Application/Traffic/Trace] -$src attach-tracefile $tfile : -Binary format (native!) -inter-packet time (msec) and packet size (byte)
23
23 Application-Level Simulation Features -Build on top of existing transport protocol -Transmit user data, e.g., HTTP header Two different solutions -TCP: Application/TcpApp -UDP: Agent/Message
24
24 Agenda Detour ends. What Is NS? Elements of Simulation NS Architecture NS Internals Summary
25
25 NS Architecture Object-oriented (C++, OTcl) Scalability + Extensibility -Control/”data” separation -Split C++/OTcl object Modular approach -Fine-grained object composition Detour ends.
26
26 C++/OTcl Split Objects C++ OTcl Pure C++ objects Pure OTcl objects C++/OTcl split objects NS 100K 70K
27
27 C++/OTcl Linkage
28
28 TclObject: Hierarchy and Shadowing TclObject Agent Agent/TCP Agent/TCP OTcl shadow object _o123 Agent/TCP C++ object *tcp TclObject Agent TcpAgent OTcl class hierarchy C++ class hierarchy
29
29 The Merit of OTcl Program size, complexity C/C++ OTcl Smoothly adjust the granularity of scripting to balance extensibility and performance With complete compatibility with existing simulation scripts high low split objects
30
30 Scalability vs Flexibility It’s tempting to write all-OTcl simulation -Benefit: quick prototyping -Cost: memory + runtime Solution -Control the granularity of your split object by migrating methods from OTcl to C++
31
31 Object Granularity Tips Functionality -Per-packet processing C++ -Hooks, frequently changing code OTcl Data management -Complex/large data structure C++ -One-time configuration variables OTcl
32
32 Agenda What Is NS? Elements of Simulation NS Architecture NS Internals Summary
33
33 NS Internals Discrete event scheduler Network topology Routing Transport Packet flow Packet format Application
34
34 Discrete Event Scheduler time_, uid_, next_, handler_ head_ -> Three types of schedulers -List: simple linked list, order-preserving, O(N) -Heap: O(logN) -Calendar: hash-based, fastest, O(1) handler_ -> handle() time_, uid_, next_, handler_ reschedule insert
35
35 Network Topology: Node n0n1 Addr Classifier Port Classifier classifier_ dmux_ entry_ Node entry Unicast Node Multicast Classifier classifier_ dmux_ entry_ Node entry Multicast Node multiclassifier_
36
36 Network Topology: Link n0n1 enqT_queue_deqT_ drophead_ drpT_ link_ttl_ n1 entry_ head_ tracing simplex link duplex link
37
37 Routing n0n1 Addr Classifier Port Classifier classifier_ dmux_ entry_ Node entry 0 1 enqT_queue_deqT_ drophead_drpT_ link_ttl_ n1 entry _ head_
38
38 Routing (con’t) n0n1 Addr Classifier Port Classifier classifier_ dmux_ entry_ 0 1 Addr Classifier Port Classifier classifier_ dmux_ entry_ 1 0 Link n0-n1 Link n1-n0
39
39 Transport 0 1 n0n1 Addr Classifier Port Classifier classifier_ dmux_ entry_ 0 Agent/TCP agents_ Addr Classifier Port Classifier classifier_ dmux_ entry_ 1 0 Link n0-n1 Link n1-n0 0 Agent/TCPSink agents_ dst_=1.0 dst_=0.0
40
40 Application: Traffic Generator 0 1 n0n1 Addr Classifier Port Classifier classifier_ dmux_ entry_ 0 Agent/TCP agents_ Addr Classifier Port Classifier classifier_ dmux_ entry_ 1 0 Link n0-n1 Link n1-n0 0 Agent/TCPSink agents_ dst_=1.0 dst_=0.0 Application/FTP
41
41 Plumbing: Packet Flow 0 1 n0n1 Addr Classifier Port Classifier entry_ 0 Agent/TCP Addr Classifier Port Classifier entry_ 1 0 Link n0-n1 Link n1-n0 0 Agent/TCPSink dst_=1.0 dst_=0.0 Application/FTP
42
42 Packet Format header data ip header tcp header rtp header trace header cmn header... ts_ ptype_ uid_ size_ iface_
43
43 Abstract the Real Wireless World Packet headers Mobile node Wireless channel Forwarding and routing Visualization
44
44 Wireless Packet Format header data ts_ ptype_ uid_ size_ iface_ IP header...... cmn header LL MAC 802_11...... ARP Wireless headers
45
45 Mobile Node Abstraction Location -Coordinates (x,y,z) Movement -Speed, direction, starting/ending location, time...
46
46 Portrait of A Mobile Node Node ARP Propagation and antenna models MobileNode LL MAC PHY LL CHANNEL LL MAC PHY Classifier: Forwarding Agent: Protocol Entity Node Entry LL: Link layer object IFQ: Interface queue MAC: Mac object PHY: Net interface protocol agent routing agent addr classifier port classifier 255 IFQ defaulttarget_
47
47 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 -Collision is handled at individual receiver -O(N 2 ) messages grid keeper
48
48 Agenda What Is NS? Elements of Simulation NS Architecture NS Internals Summary
49
49 Summary What can we do with NS? Architectural overview of NS -split C++/OTcl Object Inside NS -node, link, routing, tcp, app, wireless extension -how it works
50
50 References http://www.isi.edu/nsnam/dist/ns-workshop00-new/ http://www.isi.edu/nsnam/ns/
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.