iec00 internal
TRANSCRIPT
-
7/31/2019 Iec00 Internal
1/57
1
Part II: ns Internals
-
7/31/2019 Iec00 Internal
2/57
USC INFORMATION SCIENCES INSTITUTE 2
Outline
Fundamental conceptSplit object: C++/OTcl linkage
PlumbingWiredWireless
Scaling
-
7/31/2019 Iec00 Internal
3/57
USC INFORMATION SCIENCES INSTITUTE 3
OTcl and C++: The Duality
C++ OTcl
Pure C++objects
Pure OTcl
objects
C++/OTcl split objects
ns
-
7/31/2019 Iec00 Internal
4/57
USC INFORMATION SCIENCES INSTITUTE 4
C++/OTcl LinkageRoot of ns-2 object hierarchy
bind(): link variable values betweenC++ and OTclTclObject
command(): link OTcl methods to C++implementations
TclClass Create and initialize TclObjects
Tcl C++ methods to access Tcl interpreter
TclCommand Standalone global commands
EmbeddedTcl ns script initialization
-
7/31/2019 Iec00 Internal
5/57
USC INFORMATION SCIENCES INSTITUTE 5
TclObject
Basic hierarchy in ns for split objectsMirrored in both C++ and OTclExampleset tcp [new Agent/TCP]$tcp set packetSize_ 1024$tcp advanceby 5000
-
7/31/2019 Iec00 Internal
6/57
USC INFORMATION SCIENCES INSTITUTE 6
TclObject: Hierarchy and Shadowing
TclObject
Agent
Agent/TCP
Agent/TCP OTclshadow object
_o123 Agent/TCP C++
object
*tcp
TclObject
Agent
TcpAgent
OTcl classhierarchy
C++ classhierarchy
-
7/31/2019 Iec00 Internal
7/57
USC INFORMATION SCIENCES INSTITUTE 7
TclObject::bind()
Link C++ member variables to OTcl objectvariables
C++TcpAgent::TcpAgent() {bind( window_ , &wnd_);
}
bind_time(), bind_bool(), bind_bw()OTclset tcp [new Agent/TCP]$tcp set window_ 200
-
7/31/2019 Iec00 Internal
8/57
USC INFORMATION SCIENCES INSTITUTE 8
Initialization of Bound Variables
Initialization through OTcl classvariables
Agent/TCP set window_ 50Do all initialization of bound variables in~ns/lib/ns-default.tcl
Otherwise a warning will be issued whenthe shadow object is created
-
7/31/2019 Iec00 Internal
9/57
USC INFORMATION SCIENCES INSTITUTE 9
Implementation of Bound Variables
Class InstVarOne object per bound variable expensive!
InstVarInt, InstVarReal, Created by TclObject::bind()
Create instance variable in OTcl stack
Enable trap read/write to OTcl variable usingTcl_TraceVar()
Connect to C++ variable in the trap
-
7/31/2019 Iec00 Internal
10/57
USC INFORMATION SCIENCES INSTITUTE 10
TclObject::command()
Implement OTcl methods in C++Trap point: OTcl method cmd{}Send all arguments after cmd{} call toTclObject::command()
-
7/31/2019 Iec00 Internal
11/57
USC INFORMATION SCIENCES INSTITUTE 11
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);
}
-
7/31/2019 Iec00 Internal
12/57
USC INFORMATION SCIENCES INSTITUTE 12
TclObject::command()
$tcp send TclObject::unknown{} $tcp cmd sendno suchprocedure
TcpAgent::command()
match send?
Invoke parent:return Agent::command()
process and return
Yes No
OTcl space
C++ space
-
7/31/2019 Iec00 Internal
13/57
USC INFORMATION SCIENCES INSTITUTE 13
TclObject: Creation and Deletion
Global procedures: new{}, delete{}Exampleset tcp [new Agent/TCP] delete $tcp
-
7/31/2019 Iec00 Internal
14/57
USC INFORMATION SCIENCES INSTITUTE 14
C++
OTcl
TclObject: Creation and Deletion
invoke parentconstructor
Agent/TCPconstructor
parentconstructor
invoke parentconstructor
TclObjectconstructor
create C++object
AgentTCPconstructor
invoke parentconstructor
invoke parentconstructor
parent (Agent)
constructor
do nothing,return
TclObject (C++)
constructor
bind variablesand return
bind variablesand return
create OTclshadow objectcompleteinitializationcompleteinitialization which C++object to create? TclClass
-
7/31/2019 Iec00 Internal
15/57
USC INFORMATION SCIENCES INSTITUTE 15
TclClass
TclObject
Agent
Agent/TCP
TclObject
Agent
TcpAgent
NsObject ??
OTclC++ mirroringStatic class TcpClass : public TclClass {public:
TcpClass() : TclClass( Agent/TCP ) {}
TclObject* create(int, const char*const*) {return (new TcpAgent ());}
} class_tcp;
-
7/31/2019 Iec00 Internal
16/57
USC INFORMATION SCIENCES INSTITUTE 16
TclClass: Mechanism
Initialization at runtime startup
SplitObject::register{}Create and registerOTcl class Agent/TCP
TclClass::init()
for each staticallydefined TclClass
TcpClass::bind()
e.g.
Agent/TCP::create-shadow{}TclClass::create_shadow()
-
7/31/2019 Iec00 Internal
17/57
USC INFORMATION SCIENCES INSTITUTE 17
Class Tcl
Singleton class with a handle to Tclinterpreter
UsageInvoke OTcl procedureObtain OTcl evaluation results
Pass a result string to OTclReturn success/failure code to OTcl
-
7/31/2019 Iec00 Internal
18/57
USC INFORMATION SCIENCES INSTITUTE 18
Class TclTcl& 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;
}
-
7/31/2019 Iec00 Internal
19/57
USC INFORMATION SCIENCES INSTITUTE 19
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());
}
-
7/31/2019 Iec00 Internal
20/57
USC INFORMATION SCIENCES INSTITUTE 20
EmbeddedTcl
Pre-load OTcl scripts at ns runtime startupRecursively load ~ns/tcl/lib/ns-lib.tcl:source ns-autoconf.tcl
source ns-address.tclsource ns-node.tcl.......
Load everything into a single C++ string
Execute this string at runtime startupTcl::init(): load ~tclcl/tcl-object.tclTcl_AppInit(): load ~ns/tcl/lib/ns-lib.tcl
-
7/31/2019 Iec00 Internal
21/57
USC INFORMATION SCIENCES INSTITUTE 21
EmbeddedTcl
How it workstcl2c++ : provided by TclCL, converts tcl
scripts into a C++ static character arrayMakefile.in:
tclsh8.0 bin/tcl-expand.tcl tcl/lib/ns-lib.tcl | tcl2c++ et_ns_lib >gen/ns_tcl.cc
-
7/31/2019 Iec00 Internal
22/57
USC INFORMATION SCIENCES INSTITUTE 22
Summary
TclObjectUnified interpreted (OTcl) and compiled(C++) class hierarchiesSeamless access (procedure call andvariable access) between OTcl and C++
TclClassThe mechanism that makes TclObject work
Tcl: primitives to access Tcl interpreter
-
7/31/2019 Iec00 Internal
23/57
USC INFORMATION SCIENCES INSTITUTE 23
Outline
Fundamental conceptSplit object
PlumbingWired worldWireless world
Scaling
-
7/31/2019 Iec00 Internal
24/57
USC INFORMATION SCIENCES INSTITUTE 24
ns Internals
Discrete event schedulerNetwork topologyRoutingTransportPacket flowPacket format
Application
-
7/31/2019 Iec00 Internal
25/57
USC INFORMATION SCIENCES INSTITUTE 25
Discrete Event Schedulertime_, uid_, next_, handler_
head_ ->head_ ->
Three types of schedulersList: simple linked list, order-preserving, O(N)Heap: O(logN)Calendar: hash-based, fastest, O(1)
handler_ -> handle()
time_, uid_, next_, handler_
reschedule
insert
-
7/31/2019 Iec00 Internal
26/57
USC INFORMATION SCIENCES INSTITUTE 26
Network Topology: Node
n0 n1
AddrClassifier
PortClassifier
classifier_
dmux_
entry_
Node entry
UnicastNode
MulticastClassifier
classifier_
dmux_
entry_
Node entry
MulticastNode
multiclassifier_
-
7/31/2019 Iec00 Internal
27/57
USC INFORMATION SCIENCES INSTITUTE 27
Network Topology: Link
n0 n1
enqT_ queue_ deqT_
drophead_ drpT_
link_ ttl_
n1entry_ head_
tracing simplex link
duplex link
-
7/31/2019 Iec00 Internal
28/57
USC INFORMATION SCIENCES INSTITUTE 28
Routing
n0 n1
AddrClassifier
PortClassifier
classifier_
dmux_
entry_
Node entry 01 enqT_ queue_ deqT_
drophead_ drpT_
link_ ttl_
n1entry
_
head_
-
7/31/2019 Iec00 Internal
29/57
USC INFORMATION SCIENCES INSTITUTE 29
Routing (cont)
n0 n1
AddrClassifier
PortClassifier
classifier_
dmux_
entry_
01
AddrClassifier
PortClassifier
classifier_
dmux_
entry_
10
Link n0-n1
Link n1-n0
-
7/31/2019 Iec00 Internal
30/57
USC INFORMATION SCIENCES INSTITUTE 30
Transport
01
n0 n1
AddrClassifier
PortClassifier
classifier_
dmux_
entry_
0 Agent/TCPagents_
AddrClassifier
PortClassifier
classifier_
dmux_
entry_
10
Link n0-n1
Link n1-n0
0 Agent/TCPSink agents_
dst_=1.0 dst_=0.0
-
7/31/2019 Iec00 Internal
31/57
USC INFORMATION SCIENCES INSTITUTE 31
Application: Traffic Generator
01
n0 n1
AddrClassifier
PortClassifier
classifier_
dmux_
entry_
0 Agent/TCPagents_
AddrClassifier
PortClassifier
classifier_
dmux_
entry_
10
Link n0-n1
Link n1-n0
0 Agent/TCPSink agents_
dst_=1.0 dst_=0.0 Application/FTP
-
7/31/2019 Iec00 Internal
32/57
USC INFORMATION SCIENCES INSTITUTE 32
Plumbing: Packet Flow
01
n0 n1
AddrClassifier
PortClassifier
entry_
0 Agent/TCP AddrClassifier
PortClassifier
entry_
10
Link n0-n1
Link n1-n0
0 Agent/TCPSink dst_=1.0 dst_=0.0
Application/FTP
-
7/31/2019 Iec00 Internal
33/57
USC INFORMATION SCIENCES INSTITUTE 33
Packet Format
header
dataip header
tcp header
rtp header
trace header
cmn header
...
ts_
ptype_
uid_
size_
iface_
-
7/31/2019 Iec00 Internal
34/57
USC INFORMATION SCIENCES INSTITUTE 34
Outline
Fundamental conceptSplit object
PlumbingWired worldWireless world
ns scaling
-
7/31/2019 Iec00 Internal
35/57
USC INFORMATION SCIENCES INSTITUTE 35
Abstract the Real World
Packet headersMobile node
Wireless channelForwarding and routing
Visualization
-
7/31/2019 Iec00 Internal
36/57
USC INFORMATION SCIENCES INSTITUTE 36
Wireless Packet Format
header
data
ts_
ptype_
uid_
size_
iface_
IP header
......
cmn header
LL
MAC 802_11
......
ARP
wirelessheaders
-
7/31/2019 Iec00 Internal
37/57
USC INFORMATION SCIENCES INSTITUTE 37
Mobile Node Abstraction
LocationCoordinates (x,y,z)
MovementSpeed, direction, starting/ending location,time ...
-
7/31/2019 Iec00 Internal
38/57
USC INFORMATION SCIENCES INSTITUTE 38
Portrait of A Mobile NodeNode
ARP
Propagationand antennamodels
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
protocolagent
routing
agent
addr
classifier
portclassifier
255
IFQIFQ
defaulttarget_
-
7/31/2019 Iec00 Internal
39/57
USC INFORMATION SCIENCES INSTITUTE 39
Mobile Node: Components
Link LayerSame as LAN, but with a separate ARP module
Interface queueGive priority to routing protocol packetsMac Layer
IEEE 802.11RTS/CTS/DATA/ACK for all unicast packetsDATA for all broadcast packets
-
7/31/2019 Iec00 Internal
40/57
USC INFORMATION SCIENCES INSTITUTE 40
Mobile Node: Components
Network interface (PHY)Parameters based on Direct Sequence SpreadSpectrum (WaveLan)
Interface with: antenna and propagation modelsUpdate energy: transmission and reception
Radio Propagation ModelFriss-space attenuation(1/r 2) at near distanceTwo-ray Ground (1/r 4) at far distance
AntennaOmni-directional, unity-gain
-
7/31/2019 Iec00 Internal
41/57
USC INFORMATION SCIENCES INSTITUTE 41
Wireless Channel
Duplicate packets to all mobile nodesattached to the channel except the
senderIt is the receivers responsibility todecide if it will accept the packet
Collision is handled at individual receiverO(N2) messages grid keeper
-
7/31/2019 Iec00 Internal
42/57
USC INFORMATION SCIENCES INSTITUTE 42
Grid-keeper: An Optimization
-
7/31/2019 Iec00 Internal
43/57
USC INFORMATION SCIENCES INSTITUTE 43
Outline
Fundamental conceptSplit object
PlumbingWired worldWireless world
ns scaling
-
7/31/2019 Iec00 Internal
44/57
USC INFORMATION SCIENCES INSTITUTE 44
ns Scaling
Limitations to simulation sizeMemory
Run timeSolutions
Abstraction
Fine-tuning (next session)
-
7/31/2019 Iec00 Internal
45/57
USC INFORMATION SCIENCES INSTITUTE 45
0
20406080
100
120140160180
0 100 200 300 400 500 600
Number of Nodes (degree ~ 1.77)
M e m o r y i n
M B
Memory Footprint of ns
Dense Mode
128MB
430
-
7/31/2019 Iec00 Internal
46/57
USC INFORMATION SCIENCES INSTITUTE 46
1
10
100
1000
10000
0 200 400 600
Number of Nodes (degree ~ 1.77)
U s e r
T i m e
i n
S e c
Run Time of ns
Dense Mode
-
7/31/2019 Iec00 Internal
47/57
USC INFORMATION SCIENCES INSTITUTE 47
Culprit: Details, Details
Dense mode tries to capture packet-level behavior
Prunes, Joins, Lets abstract it out
Centralized multicast
SessionSim
-
7/31/2019 Iec00 Internal
48/57
USC INFORMATION SCIENCES INSTITUTE 48
Centralized Multicast
s
n1 n2
n3 n4 n5
Centralized Multicast
Dense Mode Multicast
s
n1 n2
n3 n4 n5
RouteComputation
Unit
receiverdataprune
source
-
7/31/2019 Iec00 Internal
49/57
USC INFORMATION SCIENCES INSTITUTE 49
Centralized Multicast
Usage$ns mrtproto CtrMcast
LimitationNo exact dynamic behavior, e.g., routingconvergence timeDoes not mean to replace DM
-
7/31/2019 Iec00 Internal
50/57
USC INFORMATION SCIENCES INSTITUTE 50
Further Abstraction
Remove all intermediate nodes and links
Do not model:Detailed queueingDetailed packet delivery
ns Object Sizes
Multicast Node 6KB
Duplex link 14KB
-
7/31/2019 Iec00 Internal
51/57
USC INFORMATION SCIENCES INSTITUTE 51
SessionSim
ReplicationDelayTTL
Session Helper:
Session Multicast
Detailed Packet Distribution
s
n1 n2
n3 n4 n5
receiverdata
sourcen4 n2
s
-
7/31/2019 Iec00 Internal
52/57
USC INFORMATION SCIENCES INSTITUTE 52
SessionSim
Usageset ns [new SessionSim]
instead of set ns [new Simulator]
Limitation
Distorted end-to-end delayPacket loss due to congestion
-
7/31/2019 Iec00 Internal
53/57
USC INFORMATION SCIENCES INSTITUTE 53
Memory Footprint of ns
020406080
100120140160180
0 100 200 300 400 500 600
Number of Nodes (degree ~ 1.77)
M e m o r y
i n
M B
Dense Mode
Centralized Multicast
SessionSim
-
7/31/2019 Iec00 Internal
54/57
USC INFORMATION SCIENCES INSTITUTE 54
Run Time of ns
1
10
100
1000
10000
0 100 200 300 400 500 600
Number of Nodes (degree ~ 1.77)
U s e r
T i m e
i n S e c
Dense ModeCentralized
Multicast
SessionSim
-
7/31/2019 Iec00 Internal
55/57
USC INFORMATION SCIENCES INSTITUTE 55
Distortion of Centralized Multicast
# Packets in transit
0246
81012
0 0.5 1 1.5 2
Time (in sec)
# o
f p a c k e
t s i n t r a n s i
tDMCtrMcast
-
7/31/2019 Iec00 Internal
56/57
USC INFORMATION SCIENCES INSTITUTE 56
Distortion of SessionSimMean (Diff in E-E Delay)
0
0.02
0.04
0.06
0.08
0.1
0 20 40 60 80 100
Number of Sessions
S e c o n
d s
-
7/31/2019 Iec00 Internal
57/57
Footnotes
My sim still uses too much memory?Or
I want large detailed simulation, e.g.,Web traffic pattern?
Fine-tune your simulatorWell cover it this afternoon