Beginning ns-2
Download
Report
Transcript Beginning ns-2
2nd European ns-2 Workshop
Day 2
Polly Huang
ETH Zurich
http://www.tik.ee.ethz.ch/~huang
18 & 19 April
1
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
2
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
3
tcl Interpreter With Extensions
Event
Scheduler
otcl
tcl8.0
Network
Component
tclcl
ns-2
4
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]
5
Basic ns-2: Covered
•
•
•
•
•
•
wired & wireless
unicast & multicast
TCP & UDP
errors & network dynamics
ns & nam tracing
application-level support
6
Basic ns-2: Also But...
•
•
•
•
mobile IP
satellite
DiffServ
emulation
7
Outline for This Morning
• ns-2 Internal
• Making changes
• New components
– in otcl
– otcl and C++ Linkage
– in C++
• Debugging
8
ns-2 Internals
•
•
•
•
•
•
•
Discrete Event Scheduler
Network Topology
Routing
Transport
Application
Packet Flow
Packet Format
9
Discrete Event Scheduler
time_, uid_, next_, handler_
head_ ->
head_ ->
handler_ -> handle()
insert
time_, uid_, next_, handler_
10
Network Topology - Node
n0
Port
Classifier
Addr
Classifier
Node entry
dmux_
entry_
n1
Unicast
Node
Multicast
Node classifier_
Node entry
entry_
classifier_
dmux_
Multicast
Classifier
multiclassifier_
11
Network Topology - Link
n0
n1
n1
entry_
head_
enqT_
queue_
drophead_
deqT_
link_
ttl_
drpT_
12
Routing
n0
n1
Port
Classifier
Addr
Classifier
Node entry
entry_
0
1
classifier_
dmux_
n1
entry_
head_
enqT_
queue_
drophead_
deqT_
link_
ttl_
drpT_
13
Routing (cont.)
n0
n1
Port
Classifier
Port
Classifier
Addr
Classifier
entry_
0
1
Addr
Classifier
dmux_
Link n0-n1
entry_
classifier_
1
0
dmux_
classifier_
Link n1-n0
14
Transport
n0
n1
Port
Classifier
Addr
Classifier
entry_
0
1
0
dmux_
dst_addr_=1
dst_port_=0
Port
Classifier
Addr
Classifier
Agent/TCP
agents_
Link n0-n1
entry_
classifier_
1
0
0
dst_addr_=0
dst_port_=0
Agent/TCPSink
agents_
dmux_
classifier_
Link n1-n0
15
Application
n0
n1
Port
Classifier
Addr
Classifier
entry_
0
1
0
dmux_
dst_addr_=1
dst_port_=0
Application/FTP
Port
Classifier
Addr
Classifier
Agent/TCP
agents_
Link n0-n1
entry_
classifier_
1
0
0
dst_addr_=0
dst_port_=0
Agent/TCPSink
agents_
dmux_
classifier_
Link n1-n0
16
Packet Flow
n0
n1
Port
Classifier
Addr
Classifier
entry_
0
1
0
dst_addr_=1
dst_port_=0
Application/FTP
Port
Classifier
Addr
Classifier
Agent/TCP
Link n0-n1
entry_
0
dst_addr_=0
dst_port_=0
Agent/TCPSink
1
0
Link n1-n0
17
Packet Format
cmn header
header
data
ts_
ptype_
ip header
uid_
tcp header
size_
rtp header
iface_
trace header
...
18
ns-2 Wireless Internal
• Packet headers
• Mobile node
• Wireless channel
19
Wireless Packet Format
cmn header
header
data
IP header
......
LL
MAC 802_11
ARP
ts_
ptype_
uid_
size_
iface_
wireless
headers
......
20
Portrait of A Mobile Node
Node
port
classifier
Classifier: Forwarding
protocol
agent
Agent: Protocol Entity
255
addr
defaulttarget_
classifier
LL
routing
agent
ARP
IFQ
Node Entry
LL
IFQ
IFQ: Interface queue
MAC
MAC: Mac object
PHY
PHY: Net interface
MAC
PHY
MobileNode
Propagation
and antenna
models
LL: Link layer object
CHANNEL
21
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
22
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
23
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
24
Grid-keeper: An Optimization
25
Outline for This Morning
• ns-2 Internal
• Making changes
• New components
– in otcl
– otcl and C++ Linkage
– in C++
• debugging
26
Making Changes
• In otcl space
– source
– recompile
• in C++ space
– recompile
27
Adding New Components
• in otcl
• otcl and C++ linkage
• in C++
28
New Component Purely in otcl
• Additional <new_stuff>.tcl file
• source <new_stuff>.tcl
• Adding new files
– change Makefile (NS_TCL_LIB), tcl/lib/nslib.tcl
– recompile
29
Example: Agent/Message
C
n2
cross
traffic
n0
128Kb, 50ms
10Mb, 1ms
S
n3
n4
C
n5
R
n1
10Mb, 1ms
msg agent
30
Agent/Message
pkt: 64 bytes
of arbitrary
string
Receiver-side
processing
S
R
•
•
•
•
A UDP agent (without UDP header)
Up to 64 bytes user message
Good for fast prototyping a simple idea
Usage requires extending ns functionality
31
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"
}
32
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"
}
33
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”
}
34
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
35
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
36
Agent/Message: Step 6
• Routing
# Packet loss produced by queueing
# Routing protocol: let’s run distance vector
$ns rtproto DV
37
Agent/Message: Step 7
• Cross traffic
set
$ns
set
$ns
$ns
udp0 [new Agent/UDP]
attach-agent $n(2) $udp0
null0 [new Agent/NULL]
attach-agent $n(4) $null0
connect $udp0 $null0
set exp0 [new Application/Traffic/Exponential]
$exp0 set rate_ 128k
$exp0 attach-agent $udp0
$ns at 1.0 “$exp0 start”
38
Agent/Message: Step 8
• Message agents
set sdr [new Sender]
$sdr set packetSize_ 1000
set rcvr [new Receiver]
$rcvr set packetSize_ 40
$ns
$ns
$ns
$ns
$ns
attach $n(3) $sdr
attach $n(5) $rcvr
connect $sdr $rcvr
connect $rcvr $sdr
at 1.1 “$sdr send-next”
39
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
}
40
Agent/Message: Result
• Example output
> ./ns msg.tcl
Receiver gets seq
Sender gets ack 0
Receiver gets seq
Sender gets ack 1
Receiver gets seq
Sender gets ack 2
Receiver gets seq
Sender gets ack 3
Receiver gets seq
Sender gets ack 4
Receiver gets seq
0 from
from 1
1 from
from 1
2 from
from 1
3 from
from 1
4 from
from 1
5 from
0
0
0
0
0
0
41
Add Your Changes into ns
ns-allinone
Tcl8.0
TK8.0
OTcl
tclcl
...
tcl
ex
examples
test
validation tests
mysrc
msg.tcl
ns-2
lib
nam-1
C++ code
mcast
...
OTcl code
42
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
43
Extending ns in C++
• Adding code in <new_stuff>.{cc,h} files
– Change Makefile
– make depend
– recompile
44
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)
45
Important Basics
• class hierarchy
• otcl and C++ linkage
46
Class Hierarchy
TclObject
NsObject
Connector
Queue
Delay Agent
DropTail RED
TCP
Reno
Classifier
Trace
AddrClassifier McastClasifier
Enq Deq
Drop
SACK
47
otcl and C++: The Duality
Pure OTcl
objects
Pure C++
objects
C++/OTcl split objects
C++
OTcl
ns
48
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 TclObject’s
C++ methods to access Tcl interpreter
TclCommand Standalone global commands
EmbeddedTcl ns script initialization
49
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
50
TclObject: Hierarchy and Shadowing
TclObject otcl class
hierarchy
C++ class
hierarchy
TclObject
Agent
Agent
Agent/TCP
TcpAgent
_o123
Agent/TCP otcl
shadow object
*tcp
Agent/TCP C++
object
51
TclObject::bind()
• Link C++ member variables to otcl object
variables
• C++
TcpAgent::TcpAgent() {
bind(“window_”, &wnd_);
… …
}
– bind_time(), bind_bool(), bind_bw()
• otcl
set tcp [new Agent/TCP]
$tcp set window_ 200
52
Initialization of Bound Variables
• Initialization through otcl class variables
Agent/TCP set window_ 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
53
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()
– Connect to C++ variable in the trap
54
TclObject::command()
• Implement otcl methods in C++
• Trap point: otcl method cmd{}
• Send all arguments after cmd{} call to
TclObject::command()
55
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);
}
56
TclObject::command()
$tcp send
OTcl space
no such
procedure
TclObject::unknown{}
$tcp cmd send
C++ space
TcpAgent::command()
Yes
process and return
match
“send”?
No
Invoke parent:
return Agent::command()
57
TclObject: Creation and Deletion
• Global procedures: new{}, delete{}
• Example
set tcp [new Agent/TCP]
…
delete $tcp
58
TclObject: Creation and Deletion
Agent/TCP
constructor
invoke parent
constructor
complete
initialization
parent
constructor
invoke parent
constructor
complete
which
C++
initialization
object
to create?
TclObject
constructor
create C++
object
create OTcl
shadow object
– TclClass
TclObject (C++)
constructor
parent (Agent)
constructor
AgentTCP
constructor
do nothing,
return
invoke parent
constructor
bind variables
and return
invoke parent
constructor
bind variables
and return
OTcl
C++
59
TclClass
C++
TclObject
NsObject
Agent
TcpAgent
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
60
TclClass: Mechanism
• Initialization at runtime startup
TcpClass::bind()
TclClass::init()
for each statically
defined TclClass
e.g.
SplitObject::register{}
Create and register
otcl class Agent/TCP
Agent/TCP::create-shadow{}
TclClass::create_shadow()
61
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
62
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;
}
63
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());
}
64
EmbeddedTcl
• Pre-load otcl scripts at ns runtime startup
– Recursively load ~ns/tcl/lib/ns-lib.tcl:
source ns-autoconf.tcl
source ns-address.tcl
source ns-node.tcl
.......
– Load everything into a single C++ string
– Execute this string at runtime startup
• Tcl::init(): load ~tclcl/tcl-object.tcl
• Tcl_AppInit(): load ~ns/tcl/lib/ns-lib.tcl
65
EmbeddedTcl
• How it works
– tcl2c++: provided by TclCL, converts tcl
scripts into a C++ static character array
– Makefile.in:
tclsh8.0 bin/tcl-expand.tcl tcl/lib/nslib.tcl | tcl2c++ et_ns_lib >
gen/ns_tcl.cc
66
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
67
Creating New Components
• new agent, old packet headers
• new agent, new packet header
68
New Agent, Old Header
• TCP jump start
– Wide-open transmission window at the
beginning
– From cwnd_ += 1 To cwnd_ = MAXWIN_
69
TCP Jump Start – Step 1
TclObject
NsObject
Connector
Queue
Delay Agent
DropTail RED
TCP
Reno
SACK
Classifier
Trace
AddrClassifier McastClasifier
Enq Deq
Drop
JS
70
TCP Jump Start – Step 2
• New file: tcp-js.h
class JSTCPAgent : public TcpAgent {
public:
virtual void set_initial_window() {
cwnd_ = MAXWIN_;
}
private:
int MAXWIN_;
};
71
TCP Jump Start – Step 3
• New file: tcp-js.cc
static JSTcpClass : public TclClass {
public:
JSTcpClass() : TclClass("Agent/TCP/JS") {}
TclObject* create(int, const char*const*) {
return (new JSTcpAgent());
}
};
JSTcpAgent::JSTcpAgent() {
bind(“MAXWIN_”, MAXWIN_);
}
72
New Agent, New Header
• Example: Agent/Message
– New packet header for 64-byte message
– New transport agent to process this new header
73
New Packet Header
•
•
•
•
Create new header structure
Enable tracing support of new header
Create static class for otcl linkage (packet.h)
Enable new header in otcl (tcl/lib/nspacket.tcl)
• This does not apply when you add a new
field into an existing header!
74
How Packet Header Works
Packet
PacketHeader/Common
next_
hdrlen_
bits_
size determined
at simulator
startup time
(PacketHeaderManager)
size determined
hdr_cmn
at compile time PacketHeader/IP
size determined
at compile time
size determined
at compile time
hdr_ip
PacketHeader/TCP
hdr_tcp
……
75
New Packet Header – Step 1
• Create header structure
struct hdr_msg {
char msg_[64];
static int offset_;
inline static int& offset() { return offset_; }
inline static hdr_msg* access(Packet* p) {
return (hdr_msg*) p->access(offset_);
}
/* per-field member functions */
char* msg() { return (msg_); }
int maxmsg() { return (sizeof(msg_)); }
};
76
New Packet Header – Step 2
• PacketHeader/Message
static class MessageHeaderClass :
public PacketHeaderClass {
public:
MessageHeaderClass() :
PacketHeaderClass("PacketHeader/Message",
sizeof(hdr_msg)) {
bind_offset(&hdr_msg::offset_);
}
} class_msghdr;
77
New Packet Header – Step 3
• Enable tracing (packet.h):
enum packet_t {
PT_TCP,
…,
PT_MESSAGE,
PT_NTYPE // This MUST be the LAST one
};
class p_info {
……
name_[PT_MESSAGE] = “message”;
name_[PT_NTYPE]= "undefined";
……
};
78
New Packet Header – Step 4
• Register new header (tcl/lib/ns-packet.tcl)
foreach pair {
{ Common off_cmn_ }
…
{ Message off_msg_ }
}
79
Packet Header: Caution
• Some old code, e.g.:
RtpAgent::RtpAgent() {
……
bind(“off_rtp_”, &off_rtp);
}
……
hdr_rtp* rh = (hdr_rtp*)p->access(off_rtp_);
• Don’t follow this example!
80
Agent/Message – Step 1
TclObject
NsObject
Connector
Queue
Delay Agent
DropTail RED
TCP
Reno
Classifier
Trace
AddrClassifier McastClasifier
Message Enq Deq
Drop
SACK
81
Agent/Message – Step 2
• C++ class definition
// Standard split object declaration
static …
class MessageAgent : public Agent {
public:
MessageAgent() : Agent(PT_MESSAGE) {}
virtual int command(int argc, const char*const*
argv);
virtual void recv(Packet*, Handler*);
};
82
Agent/Message – Step 3
• Packet processing: send
int MessageAgent::command(int, const char*const* argv)
{
Tcl& tcl = Tcl::instance();
if (strcmp(argv[1], "send") == 0) {
Packet* pkt = allocpkt();
hdr_msg* mh = hdr_msg::access(pkt);
// We ignore message size check...
strcpy(mh->msg(), argv[2]);
send(pkt, 0);
return (TCL_OK);
}
return (Agent::command(argc, argv));
}
83
Agent/Message – Step 4
• Packet processing: receive
void MessageAgent::recv(Packet* pkt, Handler*)
{
hdr_msg* mh = hdr_msg::access(pkt);
// OTcl callback
char wrk[128];
sprintf(wrk, "%s recv {%s}", name(), mh->msg());
Tcl& tcl = Tcl::instance();
tcl.eval(wrk);
Packet::free(pkt);
}
84
Outline for This Morning
• ns-2 Internal
• Making changes
• New components
– in otcl
– otcl and C++ Linkage
– in C++
• debugging
85
My ns dumps otcl scripts!
– Find the last 10-20 lines of the dump
– Is the error related to “_o4 cmd …” ?
• Check your command()
– Otherwise, check the otcl script pointed by the
error message
86
Debugging
• printf() and puts “”
• gdb
• tcl debugger
–
–
–
–
–
http://expect.nist.gov/tcl-debug/
place debug 1 at the appropriate location
trap to debugger from the script
single stepping through lines of codes
examine data and code using Tcl-ish commands
87
C++/otcl Debugging
• Usual technique
– Break inside command()
– Cannot examine states inside otcl!
• Solution
– Execute tcl-debug inside gdb
88
C++/otcl Debugging
(gdb) call Tcl::instance().eval(“debug 1”)
15: lappend auto_path $dbg_library
dbg15.3> w
*0: application
15: lappend auto_path $dbg_library
dbg15.4> Simulator info instances
_o1
dbg15.5> _o1 now
0
dbg15.6> # and other fun stuff
dbg15.7> c
(gdb) where
#0 0x102218 in write()
......
89
Memory Debugging in ns
• Purify
• Gray Watson’s dmalloc library
–
–
–
–
http://www.dmalloc.com
make distclean
./configure --with-dmalloc=<dmalloc_path>
Analyze results: dmalloc_summarize
90
dmalloc: Usage
• Turn on dmalloc
– alias dmalloc ’eval ‘\dmalloc –C \!*`’
– dmalloc -l log low
• dmalloc_summarize ns < logfile
– ns must be in current directory
– itemize how much memory is allocated in each
function
91
Memory Leaks
• Purify or dmalloc, but be careful about split
objects:
for {set i 0} {$i < 500} {incr i} {
set a [new RandomVariable/Constant]
}
– It leaks memory, but can’t be detected!
• Solution
– Explicitly delete EVERY split object that was
new-ed
92
Memory Conservation Tips
• Avoid trace-all
• Use arrays for a sequence of variables
– Instead of n$i, say n($i)
• Avoid OTcl temporary variables
• Use dynamic binding
– delay_bind() instead of bind()
– See object.{h,cc}
93
Scalability vs Flexibility
• It’s tempting to write all-otcl simulation
– Benefit: quick prototyping
– Cost: memory + runtime
• Solution
– Control the granularity of your split object by
migrating methods from otcl to C++
94
The Merit of OTcl
high
Program size, complexity
low
OTcl
C/C++
split objects
• Smoothly adjust the granularity of scripting to
balance extensibility and performance
• With complete compatibility with existing
simulation scripts
95
Object Granularity Tips
• Functionality
– Per-packet processing C++
– Hooks, frequently changing code otcl
• Data management
– Complex/large data structure C++
– One-time configuration variables otcl
96
97
Case Studies
• Network Layer: Network Interface (packet
labeler)
• Transport Layer: TCP Jump Start
• Application Layer: Message agent (ping)
98
Case 1: Network Layer
• Network Interface - Packet Labeler
n0
n1
NetworkInterface A
n2
NetworkInterface B
99
Class Hierarchy
TclObject
NsObject
Network
Interface
Queue
Connector
Delay Agent
DropTail RED
TCP
Classifier
Trace
AddrClassifier McastClasifier
Enq Dnq Drop
Reno SACK
100
Network Interface Labeler
• class NetworkInterface
– NetworkInterface()
– recv(pkt)
NetworkInterface
networkinterface
• pkt->iface() = label_
– send(pkt)
• target->recv(pkt)
– command()
command(): label
otcl
C++
• label argv {label_ = argv}
set iface [new networkinteface]
$iface label A
• TclClass(“networkinterface”)
101
Case 2: Transport Layer
• TCP Jump Start
– from cwnd += 1
– to cwnd = maxwin
102
Class Hierarchy
TclObject
NsObject
Connector
Queue
Delay Agent
DropTail RED
TCP
Reno SACK
Classifier
Trace
AddrClassifier McastClasifier
Enq Dnq Drop
JS
103
TCP Jump Start
• class JSTcpAgent
– openwin()
– slowdown()
• TclClass(“Agent/TCP/JS”)
104
Case 3: Application Layer
• Message sender (ping)
Message Sender
Message Sender
n0
n1
n2
105
Class Hierarchy
TclObject
NsObject
Connector
Queue
Delay Agent
DropTail RED
TCP
Reno SACK
Classifier
Trace
AddrClassifier McastClasifier
Enq Dnq Drop
MessageAgent
106
Message Sender
• class MessageAgent
–
–
–
–
MessageAgent()
recv()
send()
command()
• send {send()}
MessageAgent
Agent/Message
command(): send
C++
• TclClass(“Agent/Message”)
otcl
set msg [new Agent/Message]
$msg send
107