1 Part II: ns Internals. USC INFORMATION SCIENCES INSTITUTE 2 Outline Fundamental concept Split...
-
Upload
annabelle-arnold -
Category
Documents
-
view
213 -
download
0
Transcript of 1 Part II: ns Internals. USC INFORMATION SCIENCES INSTITUTE 2 Outline Fundamental concept Split...
11
Part II: ns Internals
22USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
Outline
Fundamental concept Split object: C++/OTcl linkage
Plumbing Wired Wireless
Scaling
33USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
OTcl and C++: The Duality
C++ OTcl
Pure C++objects
Pure OTclobjects
C++/OTcl split objects
ns
44USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
C++/OTcl LinkageRoot of ns-2 object hierarchy
bind(): link variable values between C++ and OTcl TclObject
command(): link OTcl methods to C++ implementations
TclClass Create and initialize TclObject’s
Tcl C++ methods to access Tcl interpreter
TclCommand Standalone global commands
EmbeddedTcl ns script initialization
55USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
TclObject
Basic hierarchy in ns for split objectsMirrored in both C++ and OTclExampleset tcp [new Agent/TCP]set tcp [new Agent/TCP]
$tcp set packetSize_ 1024$tcp set packetSize_ 1024
$tcp advanceby 5000$tcp advanceby 5000
66USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
TclObject: Hierarchy and Shadowing
TclObject
Agent
Agent/TCP
Agent/TCP OTcl shadow object
_o123Agent/TCP C++
object
*tcp
TclObject
Agent
TcpAgent
OTcl classhierarchy
C++ classhierarchy
77USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
TclObject::bind()
Link C++ member variables to OTcl object variablesC++TcpAgent::TcpAgent() {
bind(“window_”, &wnd_);… …
} bind_time(), bind_bool(), bind_bw()
OTclset tcp [new Agent/TCP]set tcp [new Agent/TCP]$tcp set window_ 200$tcp set window_ 200
88USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
Initialization of Bound Variables
Initialization through OTcl class variablesAgent/TCP set Agent/TCP set window_window_ 50 50
Do all initialization of bound variables in ~ns/lib/ns-default.tcl Otherwise a warning will be issued
when the shadow object is created
99USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
Implementation of Bound Variables
Class InstVar One object per bound variable –
expensive! InstVarInt, InstVarReal, …
Created by TclObject::bind() Create instance variable in OTcl stack Enable trap read/write to OTcl variable
using Tcl_TraceVar()Tcl_TraceVar() Connect to C++ variable in the trap
1010USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
TclObject::command()
Implement OTcl methods in C++Trap point: OTcl method cmd{}Send all arguments after cmd{} call to TclObject::command()
1111USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
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);}
1212USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
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
1313USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
TclObject: Creation and Deletion
Global procedures: new{}, delete{}Exampleset tcp [new Agent/TCP]set tcp [new Agent/TCP]
……
delete $tcpdelete $tcp
1414USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
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 object
complete initialization
complete initialization
which C++ object to create? – TclClass
1515USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
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;
Static class TcpClass : public TclClass {public:
TcpClass() : TclClass(“Agent/TCP”) {}TclObject* create(int, const char*const*) {
return (new TcpAgent());}
} class_tcp;
1616USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
TclClass: Mechanism
Initialization at runtime startup
SplitObject::register{} Create and register OTcl class Agent/TCP
TclClass::init()
for each staticallydefined TclClass
TcpClass::bind()
e.g.
Agent/TCP::create-shadow{} TclClass::create_shadow()
1717USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
Class Tcl
Singleton class with a handle to Tcl interpreterUsage Invoke OTcl procedure Obtain OTcl evaluation results Pass a result string to OTcl Return success/failure code to OTcl
1818USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
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;
}
1919USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
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()); }
2020USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
EmbeddedTcl
Pre-load OTcl scripts at ns runtime startup Recursively load ~ns/tcl/lib/ns-lib.tcl:~ns/tcl/lib/ns-lib.tcl:
source ns-autoconf.tclsource ns-autoconf.tclsource ns-address.tclsource ns-address.tclsource ns-node.tclsource ns-node.tcl....... .......
Load everything into a single C++ string Execute this string at runtime startup
Tcl::init(): load ~tclcl/tcl-object.tcl~tclcl/tcl-object.tcl
Tcl_AppInit(): load ~ns/tcl/lib/ns-lib.tcl~ns/tcl/lib/ns-lib.tcl
2121USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
EmbeddedTcl
How it works tcl2c++tcl2c++: provided by TclCL, converts
tcl scripts into a C++ static character array
Makefile.in:tclsh8.0 bin/tcl-expand.tcl tcl/lib/ns-tclsh8.0 bin/tcl-expand.tcl tcl/lib/ns-lib.tcl | tcl2c++ et_ns_lib > lib.tcl | tcl2c++ et_ns_lib > gen/ns_tcl.ccgen/ns_tcl.cc
2222USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
Summary
TclObject Unified interpreted (OTcl) and compiled
(C++) class hierarchies Seamless access (procedure call and
variable access) between OTcl and C++
TclClass The mechanism that makes TclObject
work
Tcl: primitives to access Tcl interpreter
2323USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
Outline
Fundamental concept Split object
Plumbing Wired world Wireless world
Scaling
2424USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
ns Internals
Discrete event schedulerNetwork topologyRoutingTransportPacket flowPacket formatApplication
2525USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
Discrete Event Scheduler
time_, uid_, next_, handler_
head_ ->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
2626USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
Network Topology: Node
n0 n1
Addr Classifier
Port Classifier
classifier_
dmux_
entry_
Node entry
Unicast Node
Multicast Classifier
classifier_
dmux_
entry_
Node entry
Multicast Node
multiclassifier_
2727USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
Network Topology: Link
n0 n1
enqT_ queue_ deqT_
drophead_ drpT_
link_ ttl_
n1 entry_
head_
tracing simplex link
duplex link
2828USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
Routing
n0 n1
Addr Classifier
Port Classifier
classifier_
dmux_
entry_
Node entry 0
1 enqT_ queue_ deqT_
drophead_ drpT_
link_ ttl_
n1 entry_
head_
2929USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
Routing (con’t)
n0 n1
Addr Classifier
Port Classifier
classifier_
dmux_
entry_
0
1
Addr Classifier
Port Classifier
classifier_
dmux_
entry_
1
0Link n0-n1
Link n1-n0
3030USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
Transport
0
1
n0 n1
Addr Classifier
Port Classifier
classifier_
dmux_
entry_
0 Agent/TCP
agents_
Addr Classifier
Port Classifier
classifier_
dmux_
entry_
1
0Link n0-n1
Link n1-n0
0 Agent/TCPSinkagents_
dst_=1.0 dst_=0.0
3131USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
Application: Traffic Generator
0
1
n0 n1
Addr Classifier
Port Classifier
classifier_
dmux_
entry_
0 Agent/TCP
agents_
Addr Classifier
Port Classifier
classifier_
dmux_
entry_
1
0Link n0-n1
Link n1-n0
0 Agent/TCPSink
agents_
dst_=1.0 dst_=0.0Application/FTP
3232USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
Plumbing: Packet Flow
0
1
n0 n1
Addr Classifier
Port Classifier
entry_
0 Agent/TCP Addr Classifier
Port Classifier
entry_
1
0Link n0-n1
Link n1-n0
0 Agent/TCPSink
dst_=1.0 dst_=0.0Application/FTP
3333USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
Packet Format
header
dataip header
tcp header
rtp header
trace header
cmn header
...
ts_
ptype_
uid_
size_
iface_
3434USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
Outline
Fundamental concept Split object
Plumbing Wired world Wireless world
ns scaling
3535USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
Abstract the Real World
Packet headersMobile nodeWireless channelForwarding and routingVisualization
3636USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
Wireless Packet Format
header
data
ts_
ptype_
uid_
size_
iface_
IP header
......
cmn header
LL
MAC 802_11
......
ARP
wireless headers
3737USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
Mobile Node Abstraction
Location Coordinates (x,y,z)
Movement Speed, direction, starting/ending
location, time ...
3838USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
Portrait of A Mobile NodeNode
ARP
Propagation and antenna models MobileNode
LL
MAC
PHY
LL
CHANNEL
LL
MAC
PHY
Classifier: Forwarding
Agent: Protocol EntityNode Entry
LL: Link layer object
IFQ: Interface queue
MAC: Mac object
PHY: Net interface
protocolagent
routingagent
addrclassifier
portclassifier
255
IFQIFQ
defaulttarget_
3939USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
Mobile Node: Components
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
4040USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
Mobile Node: Components
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
4141USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
Wireless Channel
Duplicate packets to all mobile nodes attached to the channel except the senderIt is the receiver’s responsibility to decide if it will accept the packet Collision is handled at individual
receiver O(N2) messages grid keeper
4242USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
Grid-keeper: An Optimization
4343USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
Outline
Fundamental concept Split object
Plumbing Wired world Wireless world
ns scaling
4444USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
ns Scaling
Limitations to simulation size Memory Run time
Solutions Abstraction Fine-tuning (next session)
4545USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
020406080
100120140160180
0 100 200 300 400 500 600
Number of Nodes (degree ~ 1.77)
Mem
ory
in M
BMemory Footprint of ns
Dense Mode
128MB
430
4646USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
1
10
100
1000
10000
0 200 400 600
Number of Nodes (degree ~ 1.77)
Use
r Tim
e in
Sec
Run Time of ns
Dense Mode
4747USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
Culprit: Details, Details
Dense mode tries to capture packet-level behavior Prunes, Joins, …
Let’s abstract it out Centralized multicast SessionSim
4848USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
Centralized Multicast
s
n1 n2
n3 n4 n5
Centralized Multicast
Dense Mode Multicast
s
n1 n2n2
n3 n4n4 n5
RouteComputatio
nUnit
receiver
data
prune
source
4949USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
Centralized Multicast
Usage
$ns mrtproto CtrMcast$ns mrtproto CtrMcast
Limitation No exact dynamic behavior, e.g.,
routing convergence time Does not mean to replace DM
5050USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
Further Abstraction
Remove all intermediate nodes and linksDo not model: Detailed queueing Detailed packet delivery
ns Object Sizes
Multicast Node 6KB
Duplex link 14KB
5151USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
SessionSim
ReplicationDelayTTL
Session Helper:
Session Multicast
Detailed Packet Distribution
s
n1 n2n2
n3 n4n4 n5
receiver
data
sourcen4n4 n2n2
s
5252USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
SessionSim
Usageset ns [new SessionSim]set ns [new SessionSim]
instead of
set ns [new Simulator]set ns [new Simulator]
Limitation Distorted end-to-end delay Packet loss due to congestion
5353USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
Memory Footprint of ns
020406080
100120140160180
0 100 200 300 400 500 600
Number of Nodes (degree ~ 1.77)
Mem
ory
in M
B
Dense Mode
Centralized Multicast
SessionSim
5454USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
Run Time of ns
1
10
100
1000
10000
0 100 200 300 400 500 600
Number of Nodes (degree ~ 1.77)
Use
r Tim
e in
Sec
Dense ModeCentralized Multicast
SessionSim
5555USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
Distortion of Centralized Multicast
# Packets in transit
0
2
4
6
8
10
12
0 0.5 1 1.5 2
Time (in sec)
# o
f pa
cket
s in
tra
nsit
DM
CtrMcast
5656USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
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
Seco
nds
5757USC INFORMATION SCIENCES INSTITUTEUSC INFORMATION SCIENCES INSTITUTE
Footnotes
My sim still uses too much memory? OrI want large detailed simulation, e.g., Web traffic pattern?
Fine-tune your simulator We’ll cover it this afternoon