1 ns-2 introduction mort (richard mortier). 2 credits some of this material is based on,...

52
1 ns-2 ns-2 Introduction Introduction mort mort (Richard Mortier) (Richard Mortier)

Post on 21-Dec-2015

214 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

1

ns-2 ns-2 IntroductionIntroduction

mort mort (Richard Mortier)(Richard Mortier)

Page 2: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

2

CreditsCredits

• Some of this material is based on, Some of this material is based on, variously:variously:– ns-2ns-2 documentation documentation

– UCB UCB ns-2ns-2 tutorial workshop, June 1999 tutorial workshop, June 1999• Kevin Fall, Kannan Varadhan, Polly HuangKevin Fall, Kannan Varadhan, Polly Huang

• Mistakes are my ownMistakes are my own

Page 3: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

3

Disclaimer IDisclaimer I

• ns-2ns-2 is not easy to use correctly is not easy to use correctly– IMO neither C++ nor OTcl are pleasant languages IMO neither C++ nor OTcl are pleasant languages – And neither is improved by smashing them togetherAnd neither is improved by smashing them together– There is much documentation, not all currentThere is much documentation, not all current

• Think long and hard before you use itThink long and hard before you use it– Consider the options carefullyConsider the options carefully

• Real actual running deployment rocks!Real actual running deployment rocks!• Planetlab, emulab, rolling your own testbedPlanetlab, emulab, rolling your own testbed

– ““real” artefactsreal” artefacts• Rolling your own simulatorRolling your own simulator

– ““fake” artefactsfake” artefacts• Using other simulators (SSFNet, OpNet, QualNet, …)Using other simulators (SSFNet, OpNet, QualNet, …)

– Other people’s “fake” artefactsOther people’s “fake” artefacts

• If you must use it, be prepared to think long and If you must use it, be prepared to think long and hard and still be confused…hard and still be confused…

Page 4: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

4

OutlineOutline

• BackgroundBackground

• UsageUsage

• SimulationSimulation

• FundamentalsFundamentals

• InfrastructureInfrastructure

• DebuggingDebugging

Page 5: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

5

OutlineOutline

• BackgroundBackground– Links. Purpose. History. Components. Links. Purpose. History. Components.

Status.Status.

• UsageUsage

• SimulationSimulation

• FundamentalsFundamentals

• InfrastructureInfrastructure

• DebuggingDebugging

Page 6: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

6

Useful linksUseful links

• ns-2ns-2 web page web pagehttp://www.isi.edu/nsnam/ns/http://www.isi.edu/nsnam/ns/

• nam web pagenam web pagehttp://www.isi.edu/nsnam/nam/http://www.isi.edu/nsnam/nam/

• ns-2ns-2 tutorial tutorial [ns-2.29/tutorial/][ns-2.29/tutorial/]http://http://www.isi.edu/nsnam/ns/tutorial/index.htmlwww.isi.edu/nsnam/ns/tutorial/index.html

• ns-2ns-2 workshops workshopshttp://www.isi.edu/nsnam/ns/ns-tutorial/index.htmlhttp://www.isi.edu/nsnam/ns/ns-tutorial/index.html

• ns-2ns-2 manual manualhttp://www.isi.edu/nsnam/ns/ns-documentation.htmlhttp://www.isi.edu/nsnam/ns/ns-documentation.html

Page 7: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

7

ns-2, the Network Simulatorns-2, the Network Simulator

• A A discrete event simulatordiscrete event simulator modelling modelling network protocolsnetwork protocols– Packets, links, queues, protocolsPackets, links, queues, protocols

– Visualizer (Visualizer (NAMNAM))

– Trace playbackTrace playback

– Error modelsError models

• There are alternatives!There are alternatives!– ExperimentationExperimentation

– AnalysisAnalysis

– Other simulatorsOther simulators

detail expense, scale

understanding limited detail

detail within niche niches, limited reuse

Page 8: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

8

HistoryHistory

• 1989: 1989: REALREAL by Keshav by Keshav

• 1995:1995: ns ns by Floyd, McCanne at LBL by Floyd, McCanne at LBL

• 1997: 1997: ns-2ns-2 by the VINT project by the VINT project ((Virtual InterNetwork TestbedVirtual InterNetwork Testbed) at LBL, ) at LBL, Xerox PARC, UCB, USC/ISIXerox PARC, UCB, USC/ISI

• Now: Now: ns-2.29 ns-2.29 maintained at USC/ISImaintained at USC/ISI– ns-2.30ns-2.30 pending release pending release

Page 9: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

9

ComponentsComponents

ns-2.29 extcl

tcl8.4.11

tk8.4.11

tclcl-1.17

otcl-1.11

nam-1.11

doc

ns-tutorial

models

test

lib

…examples

core code

test cases

} C++

}

OTcl

…and, of course, your simulation script!

Page 10: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

10

ComponentsComponents

• ns-2ns-2, the simulator itself, the simulator itself– Specify simulation, generate tracesSpecify simulation, generate traces– Depends on Tcl/Tk, OTcl, TclCLDepends on Tcl/Tk, OTcl, TclCL

• namnam, the network animator, the network animator– Animate traces from simulationAnimate traces from simulation– GUI for constructing simple simulationsGUI for constructing simple simulations

• Pre-processingPre-processing– Traffic, topology generationTraffic, topology generation

• Post-processingPost-processing– Analyse trace output with Analyse trace output with awkawk, etc, etc

Page 11: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

11

StatusStatus

• ns-2.29ns-2.29, October 2005, October 2005– ~230 kLOC C/C++, ~150 kLOC Tcl/OTcl~230 kLOC C/C++, ~150 kLOC Tcl/OTcl– ~100 test suites and 100+ examples ~100 test suites and 100+ examples – ~400 pages of ns manual ~400 pages of ns manual

• Platform supportPlatform support– FreeBSD, Linux, Solaris, Windows, MacFreeBSD, Linux, Solaris, Windows, Mac

• User baseUser base– >1k institutes (50 countries), >10k users>1k institutes (50 countries), >10k users– ~300 posts/month to ~300 posts/month to [email protected]@isi.edu– [email protected]@mash.cs.berkeley.edu

[email protected]@mash.cs.berkeley.edu• subscribe ns-users subscribe ns-users yourname@addressyourname@address

Page 12: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

12

OutlineOutline

• BackgroundBackground

• UsageUsage– Process. Split object model. Languages. Process. Split object model. Languages.

Tcl/OTcl. Linkage. Tcl/OTcl. Linkage.

• SimulationSimulation

• FundamentalsFundamentals

• InfrastructureInfrastructure

• DebuggingDebugging

Page 13: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

13

Using Using nsns

Simulation model

Define problem

Post-processresults

Executesimulation

Extendsimulator

Page 14: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

14

Using Using nsns

• Create simulationCreate simulation– Describe network, protocols, sources, sinks Describe network, protocols, sources, sinks – Interface via OTcl which controls C++Interface via OTcl which controls C++

• Execute simulationExecute simulation– Simulator maintains event list (packet list), executes Simulator maintains event list (packet list), executes

next event (packet), repeats until donenext event (packet), repeats until done– Events happen instantly in Events happen instantly in virtual timevirtual time but could take but could take

arbitrarily long arbitrarily long real timereal time– Single thread of control, no locking, races, etcSingle thread of control, no locking, races, etc

• Post-process resultsPost-process results– Scripts (awk, perl, python) to process text outputScripts (awk, perl, python) to process text output– No standard library but some available on webNo standard library but some available on web

Page 15: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

15

Split Object ModelSplit Object Model

• Split Object Model with shared class hierarchySplit Object Model with shared class hierarchy– Control (OTcl) Control (OTcl) vs. vs. Data (C++) Data (C++)

• TclCL provides ‘glue library’ to “easily” share functions, variables, etcTclCL provides ‘glue library’ to “easily” share functions, variables, etc– OTcl into C++: OTcl into C++: command(), tcl.result()command(), tcl.result()– C++ into OTcl: C++ into OTcl: tcl.eval()tcl.eval()

• Not all classes are mirrored exactlyNot all classes are mirrored exactly

OTcl C++

OTcl script describing simulation

Tcl

CL

Page 16: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

16

LanguagesLanguages

• C++ for C++ for datadata– Per-packet processing, the core of Per-packet processing, the core of nsns

– Fast to run, detailed, complete controlFast to run, detailed, complete control

• OTcl for OTcl for controlcontrol– Simulation descriptionSimulation description

– Periodic or triggered actionsPeriodic or triggered actions

– Manipulating existing C++ objectsManipulating existing C++ objects

– Faster to write and changeFaster to write and change» (a matter of opinion)(a matter of opinion)

Page 17: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

17

Basic TclBasic Tcl

# Variables:# Variables:setset x 10 x 10set set xxputsputs “x is $x” “x is $x”

# Functions and expressions:# Functions and expressions:setset y [pow x 2] y [pow x 2]setset y [expr x*x] y [expr x*x]

# Control flow:# Control flow:ifif {$x > 0} { {$x > 0} { returnreturn $x } $x } elseelse { {

returnreturn [expr -$x] } [expr -$x] }whilewhile { $x > 0 } { { $x > 0 } {

putsputs $x $xincrincr x –1 x –1

}}for for {{set set i 0} {$i<10} {i 0} {$i<10} {incr incr i} {i} {

puts puts “$\i == $i”“$\i == $i”}}

# Procedures:# Procedures:

procproc pow {x n} { pow {x n} {

ifif {$n == 1} { {$n == 1} { returnreturn $x } $x }

setset part [ part [powpow x [ x [exprexpr $n-1]] $n-1]]

returnreturn [ [exprexpr $x*$part] $x*$part]

}}

# Files:# Files:

setset file [ file [open “open “nstrace.txt” w]nstrace.txt” w]

set set line [line [gets gets $file]$file]

puts –nonewline puts –nonewline $file “hello!”$file “hello!”

close close $file$file

Page 18: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

18

Basic OTclBasic OTcl

Class Person

# constructor:Person instproc init {age} {

$self instvar age_set age_ $age

}

# method:Person instproc greet {} {

$self instvar age_puts “age $age_: Hello!”

}

# subclass:# subclass:

ClassClass Child - Child -superclasssuperclass PersonPerson

Child Child instprocinstproc greet {} { greet {} {

$$selfself instvarinstvar age_ age_

putsputs “age $age_ kid: “age $age_ kid: Wassup!”Wassup!”

}}

setset a [ a [newnew Person 45] Person 45]

setset b [ b [newnew Child 15] Child 15]

$a greet$a greet

$b greet$b greet

Page 19: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

19

Disclaimer IIDisclaimer II

• The following 3The following 3 slides are insaneslides are insane• This is all insaneThis is all insane• Until you grok this, you will go insaneUntil you grok this, you will go insane• Go with the flowGo with the flow

• ……or, this is very messy and not the way or, this is very messy and not the way one would do it now given half a chance, one would do it now given half a chance, but it’s roughly what isbut it’s roughly what is– Consider the benefits of a modern language Consider the benefits of a modern language

with a good typesystem, reflection, etcwith a good typesystem, reflection, etc• For more detail, Use The Source For more detail, Use The Source

Page 20: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

20

C++/OTcl Linkage (Ch.3, p.18)C++/OTcl Linkage (Ch.3, p.18)

• OTcl creates objects in the simulatorOTcl creates objects in the simulator– Objects are Objects are sharedshared between OTcl and C++ by default between OTcl and C++ by default– Access the OTcl interpreter via Access the OTcl interpreter via class Tclclass Tcl– Tcl &tcl = Tcl::instance();Tcl &tcl = Tcl::instance();

tcl.eval(…); tcl.evalc(“”); tcl.evalf(“”,…);tcl.eval(…); tcl.evalc(“”); tcl.evalf(“”,…);tcl.result(…); res = tcl.result();tcl.result(…); res = tcl.result();

– ns2ns2 also keeps hashtable of every TclObject also keeps hashtable of every TclObjecttcl.enter()/.lookup()/.remove()tcl.enter()/.lookup()/.remove()

• Variables are, by default, Variables are, by default, unsharedunshared– PurePure C++ or OTcl variables C++ or OTcl variables– Bindings can be established by the compiled constructerBindings can be established by the compiled constructer

bind(); bind_delay();bind(); bind_delay();{ { bind(“rtt_”, &t_rtt_); t_rtt_ = 10; }bind(“rtt_”, &t_rtt_); t_rtt_ = 10; }

Evaluate strings in interpreter

Return results to interpreter Access results from interpreter

Couple C++ object instance variable t_rtt_ with OTcl object instance variable rtt_

Page 21: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

21

C++/OTcl LinkageC++/OTcl Linkage

• Commands and methodsCommands and methods– For all For all TclObjectTclObject, , ns ns creates creates cmd{}cmd{} instance instance

procedure to access compiled methodsprocedure to access compiled methods

– Consider Consider $o distance? <agentaddr>$o distance? <agentaddr>• Invokes Invokes distance?{}distance?{} instance procedureinstance procedure of of $o$o

– If this doesn’t exist, call parent If this doesn’t exist, call parent TclObjectTclObject unknown{}unknown{} method method

– ……which calls which calls $o cmd distance? <agentaddr>$o cmd distance? <agentaddr>

– ……which calls C++ which calls C++ <T>::command() <T>::command() methodmethod

Page 22: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

22

structstruct hdr_ping { hdr_ping {charchar ret; ret; doubledouble send_time; send_time; doubledouble rcv_time; rcv_time; intint seq; seq;

static intstatic int offset_; // required by PacketHeaderManager offset_; // required by PacketHeaderManagerinline static intinline static int& offset() { & offset() { returnreturn offset_; } offset_; }inline staticinline static hdr_ping* access( hdr_ping* access(const const Packet* p) { Packet* p) { returnreturn (hdr_ping*) p->access(offset_); } (hdr_ping*) p->access(offset_); }

};};classclass PingAgent : PingAgent : publicpublic Agent { Agent {publicpublic::

PingAgent();PingAgent();intint seq; // a send sequence number like in real ping seq; // a send sequence number like in real pingvirtual virtual intint command( command(intint argc, argc, constconst charchar**constconst* argv);* argv);virtual virtual voidvoid recv(Packet*, Handler*); recv(Packet*, Handler*);

};};

PingAgent::PingAgent() : Agent(PT_PING), seq(0) { bind("packetSize_", &size_); }PingAgent::PingAgent() : Agent(PT_PING), seq(0) { bind("packetSize_", &size_); }

intint PingAgent::command(int argc, const char*const* argv) { PingAgent::command(int argc, const char*const* argv) {ifif (argc == 2) { (argc == 2) {

ifif (strcmp(argv[1], "send") == 0) { (strcmp(argv[1], "send") == 0) {Packet* pkt = allocpkt();Packet* pkt = allocpkt();hdr_ping* hdr = hdr_ping::access(pkt);hdr_ping* hdr = hdr_ping::access(pkt);hdr->ret = 0;hdr->ret = 0; hdr->seq = seq++;hdr->seq = seq++;hdr->send_time = Scheduler::instance().clock();hdr->send_time = Scheduler::instance().clock();send(pkt, 0); // Agent::send()send(pkt, 0); // Agent::send()returnreturn (TCL_OK); (TCL_OK);

} } else ifelse if { /* etc */ } { /* etc */ } elseelse { /* etc */ } { /* etc */ }}}returnreturn (Agent::command(argc, argv)); (Agent::command(argc, argv));

}}

Header management

C++/OTcl LinkageC++/OTcl Linkage

Constructor, with bound variable

send method invoked in simulation; result returned

Page 23: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

23

OutlineOutline

• BackgroundBackground

• UsageUsage

• SimulationSimulation– Model. Class hierarchy.Model. Class hierarchy.

• FundamentalsFundamentals

• InfrastructureInfrastructure

• DebuggingDebugging

Page 24: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

24

App1

Agent1

App2

Agent2

Node

From Network to SimulationFrom Network to Simulation

Application, Agent & Node

LinkNode

App1

Agent1

App2

Agent2

Node

App1

Agent1

App2

Agent2

Node

App1

Agent1

App2

Agent2

Node

Node Node Node

Link

Link

Link Link

Link

Link

Link

Link

App1

Agent1

App2

Agent2

Node

App1

Agent1

App2

Agent2

Node

Page 25: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

25

Class Hierarchy (partial)Class Hierarchy (partial)

TclObject

NsObject

Connector Classifier

Queue Delay Agent Trace

Enq Deq Drop

AddressClassifier

TCP

SACKReno

DropTail RED• Table of n slots each pointing to a TclObject• classify() identifies destination slot for packet• AddressClassifier, PortClassifier found within Nodes

• Receive packets and transmit to target_ • Basis for Agents and Links (~Queue + Delay)

Page 26: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

26

OutlineOutline

• BackgroundBackground

• UsageUsage

• SimulationSimulation

• FundamentalsFundamentals– Applications. Agents. Nodes. Links. Applications. Agents. Nodes. Links.

Packets. A simple topology.Packets. A simple topology.

• InfrastructureInfrastructure

• DebuggingDebugging

Page 27: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

27

ComponentsComponents

• Four major typesFour major types– ApplicationApplication

• Communication instigatorCommunication instigator

– AgentAgent• Packet generator/consumerPacket generator/consumer

– NodeNode• Addressable entityAddressable entity

– LinkLink• Set of queuesSet of queues

Page 28: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

28

Applications (Ch.36, p.323)Applications (Ch.36, p.323)

• Poke the Poke the agent agent to which they’re attachedto which they’re attached– Introduction of Introduction of ProcessProcess class class

• C.f. documentation! C.f. documentation!

– Models any entity that is capable of receiving, Models any entity that is capable of receiving, requesting or processing datarequesting or processing data

• Two basic types:Two basic types:– class Process : public TclObjectclass Process : public TclObject

[ns-2.29/common/ns-process.h][ns-2.29/common/ns-process.h]

– class class ApplicationApplication : public Process : public Process [ns-2.29/apps/app.h][ns-2.29/apps/app.h]

– class class TrafficGeneratorTrafficGenerator : public Application : public Application [ns-2.29/tools/trafgen.h][ns-2.29/tools/trafgen.h]

Page 29: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

29

ApplicationsApplications

• ApplicationApplication– Assumes attached to a TCPAgentAssumes attached to a TCPAgent– start(), stop(), send(), recv()start(), stop(), send(), recv()– E.g. E.g. class class TelnetAppTelnetApp

[ns-2.20/apps/telnet.h][ns-2.20/apps/telnet.h]• Schedule Schedule agent_->sendmsg()agent_->sendmsg() calls based on calls based on

exponential interarrival timerexponential interarrival timer

• TrafficGeneratorTrafficGenerator– Assumes attached to a UDPAgentAssumes attached to a UDPAgent– init(), next_interval()init(), next_interval()– E.g. E.g. class class POO_TrafficPOO_Traffic

[ns-2.29/tools/pareto.cc][ns-2.29/tools/pareto.cc]• Schedule bursts of packets (Pareto on-off source)Schedule bursts of packets (Pareto on-off source)

Page 30: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

30

Agents (Ch.31, p.279)Agents (Ch.31, p.279)

• TCP/UDP stacksTCP/UDP stacks– timeout()timeout(),, send() send(), etc, etc

• Allocate and schedule packetsAllocate and schedule packets

– recv()recv(), etc, etc• Callback to Callback to app_app_ to notify of data to notify of data

• Subtype of Subtype of ConnectorConnector– class class AgentAgent : public Connector : public Connector

[ns-2.29/common/agent.h, [ns-2.29/common/agent.h, …/tcl/lib/ns-agent.tcl]…/tcl/lib/ns-agent.tcl]

– class class TcpAgentTcpAgent : public Agent : public Agent• class class FullTcpAgentFullTcpAgent : public TcpAgent : public TcpAgent

– class class UdpAgentUdpAgent : public Agent : public Agent

Page 31: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

31

Nodes (Ch.5, p.44)Nodes (Ch.5, p.44)

entry_classifier_

Agent

Agent

Agent

agents_

Link

Link

dmux_

• Node, LanNode, etc derived Node, LanNode, etc derived from ParentNode from ParentNode [ns-2.29/common/{parentnode,node}.h][ns-2.29/common/{parentnode,node}.h]

• Addressable entity Addressable entity built from classifiers built from classifiers

– Distributes incoming Distributes incoming data to agents data to agents

– Distributes outgoing Distributes outgoing data to linksdata to links

• Simplest unicast case Simplest unicast case has address and port has address and port classifiers, others may classifiers, others may have morehave more

Page 32: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

32

Links (Ch.6, p.62)Links (Ch.6, p.62)

• An OTcl amalgam of C++ objectsAn OTcl amalgam of C++ objects [ns-2.29/tcl/lib/ns-link.tcl][ns-2.29/tcl/lib/ns-link.tcl]– class class SimpleLinkSimpleLink –superclass Link –superclass Link– Simulator instproc Simulator instproc duplex-linkduplex-link { n1 n2 bw delay type args } { n1 n2 bw delay type args }

• More complex links may have complex More complex links may have complex linklink delay/bw characteristics… delay/bw characteristics…[ns-2.29/link/delay.h][ns-2.29/link/delay.h]– class class LinkDelayLinkDelay : public Connector : public Connector

• ……and multiple and multiple queue_queue_ elements elements [ns-2.29/queue/{queue.h,red.h,…}][ns-2.29/queue/{queue.h,red.h,…}]– class class QueueQueue : public Connector : public Connector– class class RedQueue RedQueue : public Queue: public Queue

head_ enqT_ queue_ deqT_ link_ ttl_

drophead_

rcvT_

drpT_

Tracing

Page 33: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

33

LinksLinks

n0 n1

head_ enqT_ queue_ deqT_ link_ ttl_

drophead_

rcvT_

drpT_

$ns duplex-link $n0 $n1 5Mb 2ms DropTail

Tracing

Page 34: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

34

Packets Packets (Ch.12, p.115)(Ch.12, p.115)

next_

hdrlen_

data_

bits_IP header

TCP header

RTP header

next_

hdrlen_

data_

bits_

Packet

access(int)bits()

accessdata() userdata()

Page 35: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

35

PacketsPackets

• Derived from base Derived from base class Eventclass Event– Other derived class is Other derived class is at-eventat-event (OTcl) (OTcl)

• Packets are set of headers plus dataPackets are set of headers plus data» foreach cl [ PacketHeader info subclass ] { puts "$cl [$cl set hdrlen_]" }foreach cl [ PacketHeader info subclass ] { puts "$cl [$cl set hdrlen_]" }

– Default is to includeDefault is to include all headers all headers ofof all types all types inin all packets, all packets, giving giving >3kB >3kB per-packet!per-packet!

• Turn off unnecessary headers Turn off unnecessary headers beforebefore creating creating simulator object (simulator object (commoncommon always required) always required)

» foreach cl [PacketHeader info subclass] { puts $cl }foreach cl [PacketHeader info subclass] { puts $cl }

– remove-packet-header AODV ARP …remove-packet-header AODV ARP …, or, or– remove-all-packet-headersremove-all-packet-headers

add-packet-header IP TCP …add-packet-header IP TCP …

% foreach cl [ PacketHeader info subclass ] { puts "$cl [$cl set hdrlen_]" }% foreach cl [ PacketHeader info subclass ] { puts "$cl [$cl set hdrlen_]" }

PacketHeader/LRWPAN 216PacketHeader/LRWPAN 216

PacketHeader/XCP 64PacketHeader/XCP 64

PacketHeader/Lms 56PacketHeader/Lms 56

PacketHeader/PGM 16PacketHeader/PGM 16

PacketHeader/PGM_SPM 8PacketHeader/PGM_SPM 8

PacketHeader/PGM_NAK 16PacketHeader/PGM_NAK 16

PacketHeader/Pushback 4PacketHeader/Pushback 4

PacketHeader/NV 8PacketHeader/NV 8

PacketHeader/LDP 40PacketHeader/LDP 40

PacketHeader/MPLS 20PacketHeader/MPLS 20

PacketHeader/rtProtoLS 8PacketHeader/rtProtoLS 8

PacketHeader/Ping 32PacketHeader/Ping 32

PacketHeader/TFRC 56PacketHeader/TFRC 56

PacketHeader/TFRC_ACK 64PacketHeader/TFRC_ACK 64

PacketHeader/Diffusion 192PacketHeader/Diffusion 192

PacketHeader/RAP 24PacketHeader/RAP 24

PacketHeader/AODV 808PacketHeader/AODV 808

PacketHeader/SR 720PacketHeader/SR 720

PacketHeader/TORA 32PacketHeader/TORA 32

PacketHeader/IMEP 512PacketHeader/IMEP 512

PacketHeader/ARP 32PacketHeader/ARP 32

PacketHeader/MIP 32PacketHeader/MIP 32

PacketHeader/IPinIP 4PacketHeader/IPinIP 4

PacketHeader/LL 32PacketHeader/LL 32

PacketHeader/Mac 40PacketHeader/Mac 40

PacketHeader/Encap 4PacketHeader/Encap 4

PacketHeader/HttpInval 4PacketHeader/HttpInval 4

PacketHeader/MFTP 64PacketHeader/MFTP 64

PacketHeader/SRMEXT 8PacketHeader/SRMEXT 8

PacketHeader/SRM 16PacketHeader/SRM 16

PacketHeader/aSRM 8PacketHeader/aSRM 8

PacketHeader/mcastCtrl 20PacketHeader/mcastCtrl 20

PacketHeader/CtrMcast 12PacketHeader/CtrMcast 12

PacketHeader/rtProtoDV 4PacketHeader/rtProtoDV 4

PacketHeader/GAF 8PacketHeader/GAF 8

PacketHeader/Snoop 24PacketHeader/Snoop 24

PacketHeader/SCTP 8PacketHeader/SCTP 8

PacketHeader/TCPA 16PacketHeader/TCPA 16

PacketHeader/TCP 80PacketHeader/TCP 80

PacketHeader/IVS 32PacketHeader/IVS 32

PacketHeader/RTP 12PacketHeader/RTP 12

PacketHeader/Message 64PacketHeader/Message 64

PacketHeader/Resv 16PacketHeader/Resv 16

PacketHeader/TCP_QS 12PacketHeader/TCP_QS 12

PacketHeader/UMP 16PacketHeader/UMP 16

PacketHeader/Src_rt 76PacketHeader/Src_rt 76

PacketHeader/IP 28PacketHeader/IP 28

PacketHeader/Common 104PacketHeader/Common 104

PacketHeader/Flags 9PacketHeader/Flags 9

Page 36: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

36

A Simple TopologyA Simple Topology

n0 n1

head_ enqT_ queue_ deqT_ link_ ttl_

drophead_

rcvT_

drpT_

Application

Linkn1 – n0

AgentAgent

01

10

0 0

Page 37: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

37

OutlineOutline

• BackgroundBackground

• UsageUsage

• SimulationSimulation

• FundamentalsFundamentals

• InfrastructureInfrastructure– Addressing. Routing. Dynamics. Maths. Addressing. Routing. Dynamics. Maths.

Tracing.Tracing.

• DebuggingDebugging

Page 38: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

38

Addressing (Ch.15, p.140)Addressing (Ch.15, p.140)

• Two modes: Two modes: defaultdefault and and hierarchicalhierarchical[ns-2.29/tcl/lib/ns-address.tcl][ns-2.29/tcl/lib/ns-address.tcl]

– Default: 32 bits address, 32 bits port, 1 bit Default: 32 bits address, 32 bits port, 1 bit multicastmulticast

– Hierarchical: Hierarchical: defaultdefault and and specificspecific• Default: 3 levels, 10/11/11 bits per levelDefault: 3 levels, 10/11/11 bits per level

• Specific:Specific:$ns set-address-format hierarchical <nlevels> <bits in level1>+$ns set-address-format hierarchical <nlevels> <bits in level1>+

• Nodes are automatically assigned Nodes are automatically assigned addressesaddresses– But if you want to generate e.g. simulations But if you want to generate e.g. simulations

with subnet structure, do it yourselfwith subnet structure, do it yourself

Page 39: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

39

Routing (Ch.27, p.243; Ch.30, p.274)Routing (Ch.27, p.243; Ch.30, p.274)

• Links have assigned weightsLinks have assigned weights– Default to 1Default to 1

• $ns cost $n0 $n1 $cost$ns cost $n0 $n1 $cost

• Three supported types:Three supported types:– StaticStatic

• Simple Dijkstra, computed at start-of-daySimple Dijkstra, computed at start-of-day

– SessionSession• Simple Dijkstra, computed at each topology changeSimple Dijkstra, computed at each topology change

– Distance Vector (DV)Distance Vector (DV)• RIP-like: periodic & triggered updates, split horizon, RIP-like: periodic & triggered updates, split horizon,

poison reversepoison reverse

– Link state “highly experimental”Link state “highly experimental”[ns-2.29/linkstate/][ns-2.29/linkstate/]

Page 40: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

40

RoutingRouting

• For dynamic (“session”) routing, need For dynamic (“session”) routing, need a failure model: there are foura failure model: there are four– $ns rtmodel Trace <config_file> $n0 $n1$ns rtmodel Trace <config_file> $n0 $n1

– $ns rtmodel Exponential {<params>} $n0 $n1$ns rtmodel Exponential {<params>} $n0 $n1

– $ns rtmodel Deterministic {<params>} $n0 $n1$ns rtmodel Deterministic {<params>} $n0 $n1

– $ns rtmodel-at <time> up|down $n0 $n1$ns rtmodel-at <time> up|down $n0 $n1

• You can also define your ownYou can also define your own

Page 41: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

41

Maths (Ch.23, p.213)Maths (Ch.23, p.213)

• Support classes Support classes [ns-2.29/tools/][ns-2.29/tools/]

• class class IntegratorIntegrator– Simple linear interpolation integratorSimple linear interpolation integrator

• class class SamplesSamples– Tracks set of sample points (count, sum, sumTracks set of sample points (count, sum, sum22, mean, var), mean, var)

• class class RandomRandom, , <type>RandomVariable<type>RandomVariable– Wrapper around RNGWrapper around RNG– Uniform, exponential, pareto, normal, lognormal generatorsUniform, exponential, pareto, normal, lognormal generators

• class class RNGRNG– Implementation of pseudo-random number generator with a Implementation of pseudo-random number generator with a

period of 2period of 23131-2-2– MRG32k3a proposed in P. L’Ecuyer, “MRG32k3a proposed in P. L’Ecuyer, “Good parameters and Good parameters and

implementations for combined multiple recursive implementations for combined multiple recursive random number generatorsrandom number generators,” ,” Operations Research, Operations Research, 47(1):159—164, 1999.47(1):159—164, 1999.

» (possibly; documentation and rng.h disagree on this point)(possibly; documentation and rng.h disagree on this point)

Page 42: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

42

Tracing (Ch.24, p.223)Tracing (Ch.24, p.223)

• Packet tracing and event tracingPacket tracing and event tracing– Objects that are inserted between nodesObjects that are inserted between nodes

– Insert from OTcl using Insert from OTcl using trace{}trace{} method method• $ns trace-all $file$ns trace-all $file, or, or• [$ns link $n0 $n1] trace $file[$ns link $n0 $n1] trace $file

• MonitoringMonitoring– Record counters of interest for all Record counters of interest for all

packets or on a per-flow basispackets or on a per-flow basis

• ……or roll your ownor roll your own

Page 43: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

43

TracingTracing

• nsns and and nam nam trace file formatstrace file formats– nsns also supports also supports show_tcphdr_show_tcphdr_ variable controlling variable controlling

display of TCP flagsdisplay of TCP flags

• nsns format format

• Enque [+], dequeue [-], receive [r], drop [d]Enque [+], dequeue [-], receive [r], drop [d]• Types are Types are • Flags are Flags are

– ECN-CE [E], -ECT [N], -CE [C], -CWR [A]; plusECN-CE [E], -ECT [N], -CE [C], -CWR [A]; plus– priority [P] and TCP fast start [F]priority [P] and TCP fast start [F]

opop tsts prevhopprevhop nexthopnexthop typtypee

sizesize flagsflags flowidflowid srcsrc dstdst seqnoseqno pktidpktid

++ 1.1021.102 00 11 tcptcp 4040 –––––––––––– 00 0.00.0 1.01.0 11 11

• Enque [+], dequeue [-], receive [r], drop [d]Enque [+], dequeue [-], receive [r], drop [d]• Types are Types are • Flags are Flags are

– ECN-CE [E], -ECT [N], -CE [C], -CWR [A]; plusECN-CE [E], -ECT [N], -CE [C], -CWR [A]; plus– priority [P] and TCP fast start [F]priority [P] and TCP fast start [F]

Page 44: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

44

OutlineOutline

• BackgroundBackground

• UsageUsage

• SimulationSimulation

• FundamentalsFundamentals

• InfrastructureInfrastructure• DebuggingDebugging

Page 45: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

45

Debugging (Ch.22, p.208)Debugging (Ch.22, p.208)

• Split object model is a PITASplit object model is a PITA• Use Use Don Lib’s Tcl DebuggerDon Lib’s Tcl Debugger and and gdbgdb

– See the See the ns-2 ns-2 documentation for detailsdocumentation for details– Use Use call Tcl::instance().eval() call Tcl::instance().eval() to to

bounce between C++ and OTclbounce between C++ and OTcl– $ns gen-map{}$ns gen-map{}, prints all objects, prints all objects

• Memory debugging is probably the Memory debugging is probably the biggest issuebiggest issue– Use Use dmallocdmalloc

Page 46: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

46

DebuggingDebugging

• OTcl leaks: it does OTcl leaks: it does notnot garbage collect garbage collect– set ns [new Simulator]set ns [new Simulator]

for {set i 0} {$i < 500} {incr i} {for {set i 0} {$i < 500} {incr i} {set a [new RandomGenerator/Constant]set a [new RandomGenerator/Constant]

}}

– This will generate ~500 objectsThis will generate ~500 objects– Free things yourself (Free things yourself (delete $adelete $a))

• ConservationConservation– Avoid Avoid $ns trace-all $f$ns trace-all $f

• Allocates trace objects on all links, 14kB/linkAllocates trace objects on all links, 14kB/link

– Remove unnecessary packet headersRemove unnecessary packet headers– Use arrays for sequencesUse arrays for sequences– Avoid naming objects unnecessarilyAvoid naming objects unnecessarily– Use Use delay_bind()delay_bind() rather than rather than bind()bind() in C++ objects in C++ objects

Page 47: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

47

DebuggingDebugging

• OTcl leaks: it does OTcl leaks: it does notnot garbage collect garbage collect– set ns [new Simulator]set ns [new Simulator]

for {set i 0} {$i < 500} {incr i} {for {set i 0} {$i < 500} {incr i} {set a [new RandomGenerator/Constant]set a [new RandomGenerator/Constant]

}}

– This will generate ~500 objectsThis will generate ~500 objects– Free things yourself (Free things yourself (delete $adelete $a))

• ConservationConservation– Avoid Avoid $ns trace-all $f$ns trace-all $f– Remove unnecessary packet headersRemove unnecessary packet headers

• Reduces from ~3kB/packet to ~100B/packetReduces from ~3kB/packet to ~100B/packet

– Use arrays for sequencesUse arrays for sequences– Avoid naming objects unnecessarilyAvoid naming objects unnecessarily– Use Use delay_bind()delay_bind() rather than rather than bind()bind() in C++ objects in C++ objects

Page 48: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

48

DebuggingDebugging

• OTcl leaks: it does OTcl leaks: it does notnot garbage collect garbage collect– set ns [new Simulator]set ns [new Simulator]

for {set i 0} {$i < 500} {incr i} {for {set i 0} {$i < 500} {incr i} {set a [new RandomGenerator/Constant]set a [new RandomGenerator/Constant]

}}

– This will generate ~500 objectsThis will generate ~500 objects– Free things yourself (Free things yourself (delete $adelete $a))

• ConservationConservation– Avoid Avoid $ns trace-all $f$ns trace-all $f – Remove unnecessary packet headersRemove unnecessary packet headers– Use arrays for sequencesUse arrays for sequences

• for {set i 0} {$i<500} {incr i} {set n$1 [$ns node]}for {set i 0} {$i<500} {incr i} {set n$1 [$ns node]} vs.vs.for {set i 0} {$i<500} {incr i} {set n($1) [$ns node]}for {set i 0} {$i<500} {incr i} {set n($1) [$ns node]}

• Saves ~40B/variableSaves ~40B/variable– Avoid naming objects unnecessarilyAvoid naming objects unnecessarily– Use Use delay_bind()delay_bind() rather than rather than bind()bind() in C++ objects in C++ objects

Page 49: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

49

DebuggingDebugging

• OTcl leaks: it does OTcl leaks: it does notnot garbage collect garbage collect– set ns [new Simulator]set ns [new Simulator]

for {set i 0} {$i < 500} {incr i} {for {set i 0} {$i < 500} {incr i} {set a [new RandomGenerator/Constant]set a [new RandomGenerator/Constant]

}}

– This will generate ~500 objectsThis will generate ~500 objects– Free things yourself (Free things yourself (delete $adelete $a))

• ConservationConservation– Avoid Avoid $ns trace-all $f$ns trace-all $f– Remove unnecessary packet headersRemove unnecessary packet headers– Use arrays for sequencesUse arrays for sequences– Avoid naming objects unnecessarilyAvoid naming objects unnecessarily

• Saves ~80B/variableSaves ~80B/variable

– Use Use delay_bind()delay_bind() rather than rather than bind()bind() in C++ objects in C++ objects

Page 50: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

50

DebuggingDebugging

• OTcl leaks: it does OTcl leaks: it does notnot garbage collect garbage collect– set ns [new Simulator]set ns [new Simulator]

for {set i 0} {$i < 500} {incr i} {for {set i 0} {$i < 500} {incr i} {set a [new RandomGenerator/Constant]set a [new RandomGenerator/Constant]

}}

– This will generate ~500 objectsThis will generate ~500 objects– Free things yourself (Free things yourself (delete $adelete $a))

• ConservationConservation– Avoid Avoid $ns trace-all $f$ns trace-all $f– Remove unnecessary packet headersRemove unnecessary packet headers– Use arrays for sequencesUse arrays for sequences– Avoid naming objects unnecessarilyAvoid naming objects unnecessarily– Use Use delay_bind()delay_bind() rather than rather than bind()bind() in C++ objects in C++ objects

• Changes memory requirements to per-class rather than Changes memory requirements to per-class rather than per-instanceper-instance

Page 51: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

51

SummarySummary

• BackgroundBackground– Links. Purpose. History. Components. Status.Links. Purpose. History. Components. Status.

• UsageUsage– Process. Split object model. Languages. Tcl/OTcl. Process. Split object model. Languages. Tcl/OTcl.

Linkage.Linkage.

• SimulationSimulation– Model. Class hierarchy.Model. Class hierarchy.

• FundamentalsFundamentals– Applications. Agents. Nodes. Links. Packets. A simple Applications. Agents. Nodes. Links. Packets. A simple

topology.topology.

• InfrastructureInfrastructure– Addressing. Routing. Dynamics. Maths. Tracing.Addressing. Routing. Dynamics. Maths. Tracing.

• DebuggingDebugging

Page 52: 1 ns-2 Introduction mort (Richard Mortier). 2 Credits Some of this material is based on, variously:Some of this material is based on, variously: –ns-2

52

Thank YouThank You