1.07k likes | 1.08k Views
Join the 2nd European ns-2 workshop for in-depth learning on ns-2 fundamentals, making changes, extending ns-2 with new components, and case studies. Learn about wired and wireless networks, TCP, UDP, network dynamics, and more. Don't miss out on this opportunity to explore advanced topics in ns-2!
E N D
2nd European ns-2 WorkshopDay 2 Polly Huang ETH Zurich http://www.tik.ee.ethz.ch/~huang 18 & 19 April
Schedule: Yesterday 9-9.50 overview/intro/essential/getting started 10-10.50 tcl/otcl/ns-2 fundamentals 11-11.50 examples - TCP, RED, multicast, web, wireless Lunch break 1.30-2.20 lab 1 setup/running examples 2.30-3.20 lab 2 tcl/otcl exercises 3.30-4.20 lab 3 simple ns-2 exercise 4.30-5.00 discussion/feedback
Schedule: Today 9-9.50 recap/wired internal 10-10.50 wireless internal/making changes 11-11.50 extending ns-2/case studies Lunch break 1.30-2.20 lab 4 intermediate ns-2 exercise 2.30-3.20 lab 5 getting data you want 3.30-4.20 lab 6 advanced topic (TBD) 4.30-5.00 discussion/feedback
Event Scheduler ns-2 tclcl Network Component otcl tcl Interpreter With Extensions tcl8.0
Example Script n0 n1 set ns [new Simulator] set n0 [$ns node] set n1 [$ns node] set ftp [new Application/FTP] $ftp attach-agent $tcp $ns at 0.2 "$ftp start" $ns at 1.2 ”exit" $ns run $ns duplex-link $n0 $n1 1.5Mb 10ms DropTail set tcp [$ns create-connection TCP $n0 TCPSink $n1 0]
Basic ns-2: Covered wired & wireless unicast & multicast TCP & UDP errors & network dynamics ns & nam tracing application-level support
Basic ns-2: Also But... • mobile IP • satellite • DiffServ • emulation
Outline for This Morning • ns-2 Internal • Making changes • New components • in otcl • otcl and C++ Linkage • in C++ • Debugging
ns-2 Internals • Discrete Event Scheduler • Network Topology • Routing • Transport • Application • Packet Flow • Packet Format
Discrete Event Scheduler time_, uid_, next_, handler_ head_ -> head_ -> handler_ -> handle() insert time_, uid_, next_, handler_
n0 n1 Port Classifier Multicast Node dmux_ Addr Classifier classifier_ Node entry Node entry dmux_ entry_ entry_ Multicast Classifier classifier_ multiclassifier_ Network Topology - Node Unicast Node
n0 n1 n1 entry_ head_ enqT_ queue_ deqT_ link_ ttl_ drophead_ drpT_ Network Topology - Link
n0 n1 Port Classifier Addr Classifier n1 entry_ Node entry 0 head_ dmux_ enqT_ queue_ deqT_ link_ ttl_ 1 entry_ classifier_ drophead_ drpT_ Routing
n0 n1 Port Classifier Port Classifier Addr Classifier Addr Classifier 0 1 dmux_ dmux_ 1 0 entry_ entry_ classifier_ classifier_ Link n1-n0 Routing (cont.) Link n0-n1
dst_addr_=0 dst_port_=0 dst_addr_=1 dst_port_=0 Agent/TCPSink Agent/TCP agents_ 1 0 1 0 Transport n0 n1 Port Classifier Port Classifier Addr Classifier Addr Classifier 0 0 agents_ dmux_ dmux_ Link n0-n1 entry_ entry_ classifier_ classifier_ Link n1-n0
dst_addr_=0 dst_port_=0 dst_addr_=1 dst_port_=0 0 1 1 0 Application n0 n1 Port Classifier Port Classifier Application/FTP Addr Classifier Addr Classifier Agent/TCPSink Agent/TCP 0 0 agents_ agents_ dmux_ dmux_ Link n0-n1 entry_ entry_ classifier_ classifier_ Link n1-n0
dst_addr_=0 dst_port_=0 dst_addr_=1 dst_port_=0 0 1 1 0 Packet Flow n0 n1 Port Classifier Port Classifier Application/FTP Addr Classifier Addr Classifier Agent/TCPSink Agent/TCP 0 0 Link n0-n1 entry_ entry_ Link n1-n0
ts_ cmn header ptype_ ip header uid_ tcp header size_ rtp header iface_ trace header ... Packet Format header data
ns-2 Wireless Internal Packet headers Mobile node Wireless channel
ts_ cmn header ptype_ IP header uid_ ...... size_ LL wireless headers iface_ MAC 802_11 ARP ...... Wireless Packet Format header data
Classifier: Forwarding Agent: Protocol Entity Node Entry LL: Link layer object IFQ: Interface queue MAC: Mac object PHY: Net interface Portrait of A Mobile Node port classifier Node protocol agent 255 routing agent addr classifier defaulttarget_ ARP LL LL LL IFQ IFQ MAC MAC Propagation and antenna models PHY PHY MobileNode CHANNEL
Mobile Node: Layer 2 • Link Layer • Same as LAN, but with a separate ARP module • Interface queue • Give priority to routing protocol packets • Mac Layer • IEEE 802.11 • RTS/CTS/DATA/ACK for all unicast packets • DATA for all broadcast packets
Mobile Node: Layer 1 • Network interface (PHY) • Parameters based on Direct Sequence Spread Spectrum (WaveLan) • Interface with: antenna and propagation models • Update energy: transmission and reception • Radio Propagation Model • Friss-space attenuation(1/r2) at near distance • Two-ray Ground (1/r4) at far distance • 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 • Collision is handled at individual receiver • O(N2) messages grid keeper
Outline for This Morning • ns-2 Internal • Making changes • New components • in otcl • otcl and C++ Linkage • in C++ • debugging
Making Changes • In otcl space • source • recompile • in C++ space • recompile
Adding New Components • in otcl • otcl and C++ linkage • in C++
New Component Purely in otcl • Additional <new_stuff>.tcl file • source <new_stuff>.tcl • Adding new files • change Makefile (NS_TCL_LIB), tcl/lib/ns- lib.tcl • recompile
C S C R cross traffic msg agent Example: Agent/Message n2 n4 128Kb, 50ms n0 n1 10Mb, 1ms 10Mb, 1ms n3 n5
Agent/Message pkt: 64 bytes of arbitrary string Receiver-side processing • A UDP agent (without UDP header) • Up to 64 bytes user message • Good for fast prototyping a simple idea • Usage requires extending ns functionality S R
Agent/Message: Step 1 • Define sender class Sender –superclass Agent/Message # Message format: “Addr Op SeqNo” Sender instproc send-next {} { $self instvar seq_ agent_addr_ $self send “$agent_addr_ send $seq_” incr seq_ global ns $ns at [expr [$ns now]+0.1] "$self send-next" }
Agent/Message: Step 2 • Define sender packet processing Sender instproc recv msg { $self instvar agent_addr_ set sdr [lindex $msg 0] set seq [lindex $msg 2] puts "Sender gets ack $seq from $sdr" }
Agent/Message: Step 3 • Define receiver packet processing Class Receiver –superclass Agent/Message Receiver instproc recv msg { $self instvar agent_addr_ set sdr [lindex $msg 0] set seq [lindex $msg 2] puts “Receiver gets seq $seq from $sdr” $self send “$addr_ ack $seq” }
Agent/Message: Step 4 • Scheduler and tracing # Create scheduler set ns [new Simulator] # Turn on Tracing set fd [new “message.nam” w] $ns namtrace-all $fd
Agent/Message: Step 5 • Topology for {set i 0} {$i < 6} {incr i} { set n($i) [$ns node] } $ns duplex-link $n(0) $n(1) 128kb 50ms DropTail $ns duplex-link $n(1) $n(4) 10Mb 1ms DropTail $ns duplex-link $n(1) $n(5) 10Mb 1ms DropTail $ns duplex-link $n(0) $n(2) 10Mb 1ms DropTail $ns duplex-link $n(0) $n(3) 10Mb 1ms DropTail $ns queue-limit $n(0) $n(1) 5 $ns queue-limit $n(1) $n(0) 5
Agent/Message: Step 6 • Routing # Packet loss produced by queueing # Routing protocol: let’s run distance vector $ns rtproto DV
Agent/Message: Step 7 • Cross traffic set udp0 [new Agent/UDP] $ns attach-agent $n(2) $udp0 set null0 [new Agent/NULL] $ns attach-agent $n(4) $null0 $ns connect $udp0 $null0 set exp0 [new Application/Traffic/Exponential] $exp0 set rate_ 128k $exp0 attach-agent $udp0 $ns at 1.0 “$exp0 start”
Agent/Message: Step 8 • Message agents set sdr [new Sender] $sdr set packetSize_ 1000 set rcvr [new Receiver] $rcvr set packetSize_ 40 $ns attach $n(3) $sdr $ns attach $n(5) $rcvr $ns connect $sdr $rcvr $ns connect $rcvr $sdr $ns at 1.1 “$sdr send-next”
Agent/Message: Step 9 • End-of-simulation wrapper (as usual) $ns at 2.0 finish proc finish {} { global ns fd $ns flush-trace close $fd exit 0 }
Agent/Message: Result • Example output > ./ns msg.tcl Receiver gets seq 0 from 0 Sender gets ack 0 from 1 Receiver gets seq 1 from 0 Sender gets ack 1 from 1 Receiver gets seq 2 from 0 Sender gets ack 2 from 1 Receiver gets seq 3 from 0 Sender gets ack 3 from 1 Receiver gets seq 4 from 0 Sender gets ack 4 from 1 Receiver gets seq 5 from 0
Add Your Changes into ns ns-allinone Tcl8.0 TK8.0 OTcl tclcl ns-2 nam-1 C++ code ... tcl mcast lib ... ex test mysrc examples msg.tcl validation tests OTcl code
Add Your Change into ns • tcl/lib/ns-lib.tcl Class Simulator … source ../mysrc/msg.tcl • Makefile NS_TCL_LIB = \ tcl/mysrc/msg.tcl \ … • Or: change Makefile.in, make distclean, then ./configure --enable-debug
Extending ns in C++ • Adding code in <new_stuff>.{cc,h} files • Change Makefile • make depend • recompile
Guidelines • 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)
Important Basics • class hierarchy • otcl and C++ linkage
Class Hierarchy TclObject NsObject Connector Classifier Queue Delay Agent Trace AddrClassifier McastClasifier DropTail RED TCP Enq Deq Drop Reno SACK
otcl and C++: The Duality Pure OTcl objects Pure C++ objects C++/OTcl split objects C++ OTcl ns
TclObject • Basic hierarchy in ns for split objects • Mirrored in both C++ and otcl • Example set tcp [new Agent/TCP] $tcp set packetSize_ 1024 $tcp advanceby 5000