Académique Documents
Professionnel Documents
Culture Documents
Outline
Fundamental concept
Plumbing
Wired Wireless
Scaling
C++ ns
USC INFORMATION SCIENCES INSTITUTE
OTcl
3
C++/OTcl Linkage
Root of ns-2 object hierarchy TclObject bind(): link variable values between C++ and OTcl command(): link OTcl methods to C++ implementations TclClass Tcl Create and initialize TclObjects C++ methods to access Tcl interpreter
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
Agent
Agent/TCP _o123
Agent/TCP OTcl shadow object
USC INFORMATION SCIENCES INSTITUTE
TcpAgent *tcp
Agent/TCP C++ object
6
TclObject::bind()
Link C++ member variables to OTcl object variables C++
TcpAgent::TcpAgent() {
bind(window_, &wnd_);
OTcl
set tcp [new Agent/TCP] $tcp set window_ 200
USC INFORMATION SCIENCES INSTITUTE
One object per bound variable expensive! InstVarInt, InstVarReal, Create instance variable in OTcl stack Enable trap read/write to OTcl variable using
Tcl_TraceVar()
Created by TclObject::bind()
TclObject::command()
Implement OTcl methods in C++ Trap point: OTcl method cmd{} Send all arguments after cmd{} call to TclObject::command()
10
TclObject::command()
OTcl
set tcp [new Agent/TCP] $tcp advance 10
C++
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); }
USC INFORMATION SCIENCES INSTITUTE
11
TclObject::command()
$tcp send
no such procedure
Yes
match send?
No
13
TclClass
OTcl C++
parent (Agent) constructor invoke parent constructor bind variables and return
14
TclClass
C++ TclObject mirroring OTcl Static class TcpClass : public TclClass { public: TclObject TcpClass() : TclClass(Agent/TCP) {} TclObject* create(int, const char*const*) { return (new TcpAgent()); ?? } } class_tcp; Agent Agent/TCP
15
NsObject
Agent TcpAgent
TclClass: Mechanism
Initialization at runtime startup
TcpClass::bind() TclClass::init() for each statically defined TclClass
e.g.
Agent/TCP::create-shadow{} TclClass::create_shadow()
16
Class Tcl
Singleton class with a handle to Tcl interpreter Usage
Invoke OTcl procedure Obtain OTcl evaluation results Pass a result string to OTcl Return success/failure code to OTcl
17
Class Tcl
Tcl& tcl = Tcl::instance(); if (argc == 2) { if (strcmp(argv[1], now) == 0) { tcl.resultf(%g, clock()); return TCL_OK; } tcl.error(command not found); return TCL_ERROR; } else if (argc == 3) { tcl.eval(argv[2]); clock_ = atof(tcl.result()); return TCL_OK; }
USC INFORMATION SCIENCES INSTITUTE
18
Class TclCommand
C++ implementation of global OTcl commands
class RandomCommand : public TclCommand { public: RandomCommand() : TclCommand("ns-random") {} virtual int command(int argc, const char*const* argv); }; int RandomCommand::command(int argc, const char*const* argv) { Tcl& tcl = Tcl::instance(); if (argc == 1) { sprintf(tcl.buffer(), "%u", Random::random()); tcl.result(tcl.buffer()); }
USC INFORMATION SCIENCES INSTITUTE
19
EmbeddedTcl
Pre-load OTcl scripts at ns runtime startup
Load everything into a single C++ string Execute this string at runtime startup Tcl::init(): load ~tclcl/tcl-object.tcl
20
EmbeddedTcl
How it works
21
Summary
TclObject
Unified interpreted (OTcl) and compiled (C++) class hierarchies Seamless access (procedure call and variable access) between OTcl and C++ The mechanism that makes TclObject work
TclClass
22
Outline
Fundamental concept
Split object
Plumbing
Scaling
23
ns Internals
Discrete event scheduler Network topology Routing Transport Packet flow Packet format Application
USC INFORMATION SCIENCES INSTITUTE
24
insert
List: simple linked list, order-preserving, O(N) Heap: O(logN) Calendar: hash-based, fastest, O(1)
25
n1
Unicast Node
dmux_
dmux_
26
head_
enqT_ tracing
queue_
drophead_
deqT_
drpT_
link_
n1 entry_
27
Routing
n0
Port Classifier
n1
Addr Classifier
Node entry
entry_
0 1
classifier_
dmux_
n1 entry _
28
Routing (cont)
n0
Port Classifier
n1
Port Classifier
Addr Classifier
Addr Classifier
dmux_ Link n0-n1
entry_
0 1
classifier_
entry_
1 0
classifier_
dmux_
Link n1-n0
29
Transport
n0
Port Classifier dst_=1.0 Agent/TCP agents_ Link n0-n1
n1
Port Classifier dst_=0.0 Agent/TCPSink agents_
Addr Classifier
0
dmux_
Addr Classifier
0
dmux_
entry_
0 1
classifier_
entry_
1 0
classifier_
Link n1-n0
30
n1
Application/FTP dst_=1.0
Agent/TCP agents_ Link n0-n1 Port Classifier dst_=0.0 Agent/TCPSink agents_
Addr Classifier
0
dmux_
Addr Classifier
0
dmux_
entry_
0 1
classifier_
entry_
1 0
classifier_
Link n1-n0
31
n1
Application/FTP dst_=1.0
Agent/TCP Port Classifier dst_=0.0 Agent/TCPSink
Addr Classifier
Addr Classifier
Link n0-n1
entry_
0 1
entry_
1 0
Link n1-n0
32
Packet Format
cmn header header data ip header tcp header rtp header trace header ...
USC INFORMATION SCIENCES INSTITUTE
ts_ ptype_
uid_
size_
iface_
33
Outline
Fundamental concept
Split object
Plumbing
ns scaling
34
35
ts_
ptype_ uid_ size_ iface_ wireless headers
......
LL MAC 802_11 ARP ......
36
Coordinates (x,y,z)
Movement
37
Classifier: Forwarding
LL
IFQ MAC PHY
ARP
LL: Link layer object IFQ: Interface queue MAC: Mac object PHY: Net interface
38
IFQ
MobileNode
CHANNEL
USC INFORMATION SCIENCES INSTITUTE
MAC PHY
Interface queue
Mac Layer
39
Parameters based on Direct Sequence Spread Spectrum (WaveLan) Interface with: antenna and propagation models Update energy: transmission and reception Friss-space attenuation(1/r2) at near distance Two-ray Ground (1/r4) at far distance Omni-directional, unity-gain
40
Antenna
Wireless Channel
Duplicate packets to all mobile nodes attached to the channel except the sender It is the receivers responsibility to decide if it will accept the packet
41
Grid-keeper: An Optimization
42
Outline
Fundamental concept
Split object
Plumbing
ns scaling
43
ns Scaling
Limitations to simulation size
Solutions
44
Memory Footprint of ns
180 160 140 120 100 80 60 40 20 0 0
430
Memory in MB
128MB
Dense Mode
100
200
300
400
500
600
45
Run Time of ns
10000
Dense Mode
46
47
Centralized Multicast
Dense Mode Multicast s
n1 n2
Route Computation Unit
s
n1 n2
n4
n5 n3
n4
n5
Centralized Multicast
48
Centralized Multicast
Usage $ns mrtproto CtrMcast
Limitation
No exact dynamic behavior, e.g., routing convergence time Does not mean to replace DM
49
Further Abstraction
ns Object Sizes
Multicast Node Duplex link 6KB 14KB
SessionSim
Detailed Packet Distribution s
n1 n2
s
Session Helper: Replication Delay TTL n4 n2
n3
n4
n5
Session Multicast
51
SessionSim
Usage
set ns [new SessionSim] instead of set ns [new Simulator]
Limitation
Memory Footprint of ns
180 160 140 120 100 80 60 40 20 0 0 100 200
Dense Mode
Memory in MB
Run Time of ns
10000
600
54
# of packets in transit
DM CtrMcast
55
Distortion of SessionSim
Mean (Diff in E-E Delay) 0.1 0.08
Seconds
56
Footnotes
My sim still uses too much memory? Or I want large detailed simulation, e.g., Web traffic pattern? Fine-tune your simulator