Nodes as Routers and
Computer Hosts
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
1
Outline
•
•
•
•
•
•
•
Overview
Classifier
P
Port
Classifier
Cl ifi
Hash Classifier
TL Bridge Configuration
Routing
Summary
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
2
O
Overview
i
• Node functionality
– Router
– Computer Hosts
• S
Socket
k t = Address
Add
(L
Layer 3 ) + Port
P t ( Layer
L
4)
FTP
• Select the next hop object based on
CBR
– Address ( Router )
– Port ( Computer host )
FTP
CBR
source
destination
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
3
Node Architecture
• An NsObject which connects an NsObject to
– Another NsObject = ( Connector )
– [[Node]] More than one NsObject
j
= Classifier
• Router Address classifier
• Computer host Port classifier
• Internal mechanism
C++: ~ns/common/node
ns/common/node.cc,h
cc,h
• Route/Port configuration
OTcl
OTcl: ~ns/tcl/lib/ns-node.tcl
ns/tcl/lib/ns node.tcl
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
4
Node Architecture
• A composite
p
object
j
• OTcl domain
– classifier_
– dmux_
d
= Address classifier
= Port classifier
By default, entry_ is the classifier_
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
5
Node Functionalities
• Receive and classify
fy packets
p
– Category 1 Target 1
– Category 2 Target 2
– …
• Two task
– OTcl: Associate categories
g
and targets
g
– C++: Classify packets
• Classification criteria
– Destination address Routing
– Destination port Delivering to transport
layer protocol
– Priorities Scheduling
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
6
OTcl class Node: Instvars
Instvar
Meaning
id_ Node ID
agents_ List of attached transport layer agents
nn_ Total number of nodes
ns_ Simulator
dmux_ Demulitplexer or port classifier
classifier_ The head address classifier
module_list_ List of enabled routing modules
reg_module_ List of registered routing modules
List of routing modules which will be notified of
rtnotif_
route updates
List of routing modules which will be notified of
ptnotif_
port attachment/detachment
hook_assoc_ Sequence of the chain of classifiers
Association of classifiers and routing modules, whose
mod_assoc_ indexes and values are classifiers and the associated
routing modules, respectively.
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
7
Outline
•
•
•
•
•
•
•
Overview
Classifier
P
Port
Classifier
Cl ifi
Hash Classifier
TL Bridge Configuration
Routing
Summary
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
8
Cl ifi
Classifiers:
Overview
O
i
• Mult
Multi-target
target packet forwarder
target1
target2
classifier
l ifi
target3
• Two
w m
main discussions:
u
1. Configuration (i.e., setting classification criteria)
2 Internal mechanism
2.
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
9
Classifier: Internal Mechanism
• Recap: Connector
– A single-target packet forwarder
– How do we send a packet *p to a connector *u ?
u->recv(p,h)
– FW received packets to the attached NsObject
((target
g _))
//~/ns/common/connector.h
class Connector : public NsObject {
...
inline void send(Packet* p, Handler* h){target_->recv(p, h);}
};
//~/ns/common/connector.cc
void Connector::recv(Packet* p, Handler* h){send(p, h);}
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
10
Classifier: Internal Mechanism
• Classifier: Multi
Multi-target
target packet forwarder
• Main mechanism
1 Look at packet header
1.
2. FW pkts with the same categories to the
same NsObject
j
in the same “slot”
classifier
1
2
…
slot_
target1
target2
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
11
Classifiers: C++ Implementation
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
12
Classifiers: C++ Implementation
Function
recv(p,h)
classify(p)
i
Meaning
Receive a packet
R
Return
a matching
hi slot
l number
b for
f
packet *p
Return a matching target for
packet *p
install(slot,p) Put a pointer p to an NsObject in
slot_[slot]
find(p)
clear(slot)
Remove the NsObject installed in
slot [slot]
slot_[slot]
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
13
Classifiers: C++ Implementation
• In principle,
principle 2 main tasks:
1. Configuration:
–
–
Tell classifier how to classify packets
C++ defines interface for OTcl to do so.
2. Internal mechanism: Classify
y packets
p
NsObject
classifier
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
14
Classifiers: C++ Implementation
1 Configuration:
1.
install(slot,p) puts *NSObject in slot_
2. Internal Mechanism
classify(p):
1
2
…
–
slot_
–
Input: packet; Output: slot number
–
find(p):
Input: packet; Output: NsObject*
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
15
Classifiers::install(slot,NsObject*)
p in
• Put an input pointer “*p”
slot_[slot]
2
…
slot_
1
slot
…
p
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
16
Cl ifi
Classifiers::classify(p)
l if ( )
• Return the “slot
slot number
number”
corresponding to packet “*p”
• Implementation in class
Classifier does not make much
sense!!
• Overridden in the derived classes
– HashClassifier
– PortClassifier
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
17
Cl ifi
Classifiers::find(p)
fi d( )
• Return a pointer to an NsObject
corresponding to packet “*p”
1
2
…
- Return the matching slot number
Defined
ned in
n the derived
der ved class
- Def
packet
slot_
Return this
pointer (node)
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
18
Cl ifi
Classifiers::recv(p,h)
( h)
(1)
packet
1
2
…
1. Locate an NsObject
corresponding
di tto packet
k t
“*p” (using “find(p)”)
2. Forward
o wa d the packet to the
located NsObject
slot_
(2)
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
19
Classifiers: OTcl Implementation
• Purpose: Configure a classifier
Put NsObjects in the slots
Retrieve
R t i
NsObject
• These are OTcl commands in file
~ns/classifier/classifier.cc
ns/classifier/classifier cc
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
20
Cl ifi
Classifiers:
Th
The Si
Simulation
l ti
• At the Network Configuration phase
– Define classification criterion
– Configure (put NsObject* in slot_)
accordingly
• At the
th Simulation
Si l ti phase
h
– Receive packet: recv(p,h)
1 ““classify”
1.
l ssif ” the
th packet
k t *p,
* and
d
2. forward the packet the matched
NsObject
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
21
Cl ifi
Classifiers:
2 Main
M i T
Types
• A node acts as
– A computer host
Port classifier PortClassifier
– Router
Address classifier HashClassifier
• 2 Main tasks:
– Configuration
– Internal mechanism
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
22
Outline
•
•
•
•
•
•
•
Overview
Classifier
P
Port
Classifier
Cl ifi
Hash Classifier
TL Bridge Configuration
Routing
Summary
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
23
P
Port
Classifier:
Cl ifi
Overview
O
i
• A computer host
– connects a node to transport layer (TL)
protocol
– may have several attached TL protocol
• Port: Identify which TL protocol should a
packet
k be forwarded to, e.g.,
– Attach FTP to port 65, and
– Attach
Att h CBR to
t portt 66
CBR
FTP
Port65
Port66
Node
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
24
Port Classifier: NS2 Implementation
• Node Configuration
• PortClassifier object = dmux_
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
25
Port Classifier: NS2 Implementation
• NS2 Configuration
• Installer a pointer to
agent of port
– 65 in slot_[65]
– 66 in slot_[66]
– pt
t in
i slot_[pt]
l t [ t]
CBR
FTP
Port65
Port66
Node
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
Port65
Port66
26
Port Classifier: NS2 Implementation
• C
C++ Implementation
• PortClassifier::classify(p)
(1)
(3)
//~ns/classifier/classifier-port.cc
int PortClassifier::classify(Packet *p)
{
hdr ip* iph = hdr
hdr_ip*
hdr_ip::access(p);
ip::access(p);
return iph->dport();
}
(2)
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
27
Outline
•
•
•
•
•
•
•
Overview
Classifier
P
Port
Classifier
Cl ifi
Hash Classifier
TL Bridge Configuration
Routing
Summary
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
28
H h Cl
Hash
Classifier
ifi
• Hash determinitically digests an
input and spits out an output
Input
HASH
(function)
Output
• Same input always hashes to the
p
same output
• Example:
– Encryption: MD5,
MD5 SHA
SHA-256
256
– Look up table
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
29
H h Classifier:
Hash
Cl ifi
Example
E
l
• Look up table: Sequential search takes
long time
• Input = 4 bits
• Output = 4 bits
• Hash
H hf
function
= XOR with 1010
• Much quicker operation
Input
0
1
2
3
4
5
6
Output
10
11
4
9
4
15
12
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
30
H h Cl
Hash
Classifier
ifi
• In NS2: Hash table
Slot
no.
0
1
Flow ID
10
11
SRC
address
dd
2
4
DST
address
dd
3
7
• Input = (hash) key = (fid,src,dst)
(fid src dst)
• Output = (hash) index = slot no.
• Each
E h row = hash
h h record
d
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
31
H h Cl
Hash
Classifier
ifi
• Base C++ class = HashClassifier
• 4 main derived classes:
C++ Class
OTcl Class
D tH hCl
DestHashClassifier
ifi
Classifier/
Cl
ifi /
Hash/Dest
FidHashClassifier
Classifier/
Hash/Fid
Classification
criteria
(d )
(dst)
(fid)
(src,dst)
• Input = (hash) key = (fid,src,dst)
SrcDestFidHashClassifier Classifier/
(
(src,dst,fid)
d t fid)
• Output
O
= (hash)
(h h) iindex
d = slot
l no.
Hash/SrcDestFid
SrcDestHashClassifier
Classifier/
Hash/SrcDest
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
32
D
DestHashClassifier
H hCl ifi
• No need to define function recv(p,h)
recv(p h)
• Define function classify(p):
//~ns/classifier/classifier-hash.cc
//~ns/classifier/classifier-hash
cc
int DestHashClassifier::classify(Packet * p) {
int slot = lookup(p);
Defined in class
if (slot >= 0 && slot <=maxslot
<=maxslot_)
)
H hCl
HashClassifier
ifi
return (slot);
else if (default_ >= 0)
return (default_);
(default );
else return (-1);
}
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
33
Outline
•
•
•
•
•
•
•
Overview
Classifier
P
Port
Classifier
Cl ifi
Hash Classifier
TL Bridge Configuration
Routing
Summary
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
34
C fi
Configuring
i Cl
Classifier
ifi
• Classifier forwards packet to a
predefines categories
Internal mechanism
• How are the categories predefined?
Configuration
f
• TL bridges
g PortClassifier
• Routers DestHashClassifier
• Mainly in OTcl
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
35
C fi
Configuring
i P
PortClassifier
Cl ifi
• Recall: instproc attach-agent of class
Simulator
1.
2.
3.
4.
5.
5.
$ns attach-agent
g
$node $agent
g
$node attach $agent {port “”}
$node add-target $agent $port
$rm attach $agent
g
$port
p
$agent target [[$self node] entry]
[[$self node] demux] install $port $agent
Note: $rm is a routing module stored in the array
ptnotif of $node
ptnotif_
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
36
C fi
Configuring
i P
PortClassifier
Cl ifi
//~ns/tcl/lib/ns-lib.tcl
Si l t
Simulator
i
instproc
t
attach-agent
tt h
t { node
d agent
t } {
$node attach $agent (2)
}
//~ns/tcl/lib/ns-node.tcl
Node instproc attach { agent { port "" } } {
$self instvar agents_ address_ dmux_
...
$self add-target $agent $port (3)
}
Node instproc add-target { agent port } {
$self instvar ptnotif_
foreach m [$self set ptnotif_] {
$m attach $
$
$agent
g
$p
$port
(4)
}
}
//~ns/tcl/lib/ns-rtmodule.tcl
RtModule instproc attach { agent port } {
$agent target [[$self node] entry] (5)
[[$self node] demux] install $port $agent (5)
}
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
37
Configuring PortClassifier
$agent
$
g
target
g
[[$self node]
[[$
] entry]
y]
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
38
Configuring PortClassifier
[[$self node]
[[$
] demux]
] install $p
$port $
$agent
g
2
…
slot_
_
1
slot
…
p
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
39
Configuring
D
DestHashClassifier
H hCl ifi
• Address classifier
• R
Return the
h next hop
h object
bj
for
f a
given destination address
• Routing
Rout ng
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
40
Outline
•
•
•
•
•
•
•
Overview
Classifier
P
Port
Classifier
Cl ifi
Hash Classifier
TL Bridge Configuration
Routing
Summary
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
41
R
Routing
i (O
(Outline)
li )
•
A routing protocol consists of 4 main
components:
–
–
–
–
Routing
g agent:
g
Information collector ((not
being used for static routing)
Route logic: Routing table computation
Cl
Classifier:
ifi
Packet
P k forwarder
f
d (base
(b
on the
h
route logic)
Routing module: The single point of
management for classifiers
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
42
R
Routing
i
• Relationship among routing components
SIMULATOR
attach-agent
attach
agent
rtmodule_, ptnotif_
ROUTING MODULE
new
attach
add-route
register
attach
add-route
NODE
CLASSIFIER
install
ROUTE LOGIC
compute
configure
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
43
R
Route
L
Logic
i
•
•
Compute routing table
How? Based on predefined routing
protocol, e.g.,
–
–
–
•
Agent/rtProto/Static
Agent/rtProto/Manual
Agent/rtProto/DV
C++ and OTcl classes RouteLogic
• Consider Agent/rtProto/Static
–
–
Simulator knows the topology
Let Simulator computes the routing table
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
44
C Cl
C++
Class RouteLogic
R
L i
•
C++ main variables (
(~ns/routing/route
ns/routing/route.*)
)
–
–
•
adj_: Adjacency matrix
route_: routing
g table
C++ main functions
Functions
insert(src,dst)
Meaning
Insert an entry (src,dst) to the
adjacency matrix adj_
adj
compute_routes()
Use adj_ to compute the routing table
and store it in route_
l k
lookup_flat(sid,did)
fl ( id did)
Return
R
t
th forwarding
the
f
di object
bj t for
f a
route from sid to did
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
45
OT l Cl
OTcl
Class R
RouteLogic
L i
• One OTcl main variables
• An array rtprotos_
– iindex
d = The
Th name of
f a routing
ti protocol
t
l
(e.g., Static, Manual)
– value
l = The
Th routing
ti protocol
t
l agentt
• See file ~ns/tcl/lib/ns-route.tcl
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
46
OT l Cl
OTcl
Class R
RouteLogic
L i
• OTcl main functions
Functions
Meaning
register{name,agent}
i t {
t}
Store the
St
th routing
ti protocol
t
l agentt <agent>
t in
i
rtprotos_[<name>]
configure{}
Initialize all its routing protocol in
rtprotos by invoking their instproc initrtprotos_
all{}
lookup{sid,did}
Return the forwarding object for a route from
(
(sid,did)
,
)
compute{}
Invoke the C++ function compute_routes()
In file ~ns/tcl/lib/ns-route.tcl
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
47
OT l Cl
OTcl
Class R
RouteLogic
L i
• Default Routing protocol:
protocol Static
• Instproc configure{}
RouteLogic instproc configure {} {
$self instvar
$se
st a rtprotos
tp otos_
if [info exists rtprotos_] {
foreach proto [array names rtprotos_] {
eval Agent/rtProto/$proto init-all $rtprotos_($proto)
}
} else {
Agent/rtProto/Static init-all
}
}
• If another routing protocol exist, it will be in
charge of route computation, e.g.,
– Set the adj_ of the RouteLogic
– Compute the routing table.
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
48
R
Route
Logic
L i C
Configuration
fi
i
• Setting a routing table
• Start when “ $ns run ” is executed.
• Use
U Dijkstar
Dijk
shortest
h
path
h algorithm
l
i h
for all pairs of nodes
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
49
R
Route
Logic
L i C
Configuration
fi
i
•
Default route logic setup
1.
2.
3
3.
4.
5.
6.
$ns run
[$ns get-routelogic] configure
A
Agent/rtProto/Static
t/ tP t /St ti i
init-all
it ll
$ns compute-routes
$ns compute-flat-routes
set r [$ns get-routelogic]
foreach ln [array names link_] {
$r insert $
$
$srcID $
$dstID [$
[$link_($
($ln)
) cost?]
]
}
$r compute
Go through NS2 codes yourself!!
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
50
R
Routing
i
•
A routing protocol consists of 4 main
components:
–
–
–
–
Routing
g agent:
g
Information collector ((not
being used for static routing)
Route logic: Routing table computation
Cl
Classifier:
ifi
Packet
P k forwarder
f
d (base
(b
on the
h
route logic)
Routing module: The single point of
management for classifiers
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
51
Cl ifi and
Classifier
d Routing
R
i
•
Two main configuration tasks
1. Putting classifiers in Nodes
2. Configuring
g
g the classifiers
•
Configuring the route logic
1. $ns run
…
5. $ns compute-flat-routes
6. … $
$r compute
p
7. $self populate-flat-classifiers [Node set nn_]
8. [C++] Simulator::populate_flat_classifiers()
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
52
C fi
Configuring
i a Cl
Classifier
ifi
//~ns/common/simulator.cc void
Simulator::populate_flat_classifiers() {
A pointer to
...
a RouteLogic
for (int i=0; i<nn_; i++) {
object
for (int j
j=0;
0; j<nn
j<nn_;
; j++) {
if (i != j) {
int nh = -1;
nh = rtobject
j
_->lookup
p_flat(i,
( , j);
if (nh >= 0) {
NsObject *l_head = get_link_head(nodelist_[i],nh);
sprintf(tmp, "%d", j);
nodelist_[i]->add_route(tmp, l_head);
}
}
}
}
}
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
53
C fi
Configuring
i a Cl
Classifier
ifi
//~ns/common/node.cc
void Node::add_route(char *dst, NsObject *target) {
if (rtnotif_)
rtnotif_->add_route(dst, target);
}
A pointer to a RoutingModule object
• We shall discuss the routing module later.
ff
to know that
• For now,, it’s sufficient
“A packet bound to dst should be FW to target”
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
54
P i a Classifier
Putting
Cl ifi in
i a Node
N d
•
Two main configuration tasks
1. Putting classifiers in Nodes
2. Configuring the classifiers
•
From the constructor of class Node
1.
2.
3.
4.
5
5.
6.
7.
7.
$ns node
set node [new Node]
$node init
Q: Why invoking init{} ? What is init{}?
$node mk-default-classifier
$node register
register-module
module [new RtModule/Base]
RtModule/Base register $node
set classifier_ [new Classifier/Hash/Dest/ 32]
$node install-entry RtModule/Base $classifier_
•
Go through the NS2 codes by yourself.
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
55
I
Installing
lli Classifiers
Cl ifi
in
i aN
Node
d
• We can have several classifiers in a node.
node
• This example has 2 classifiers.
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
56
I
Installing
lli Classifiers
Cl ifi
in
i aN
Node
d
• We can have several classifiers in a node.
node
Chain of Classifiers
classifier_
(_o1)
_o2
2
_o3
3
_o4
4
hook_assoc_
Routing
Module
_o5
Routing
Module
_o6
Routing
Module
Routing
Module
_o7
_o8
mod_assoc_
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
57
OTcl class Node: Instvars
Instvar
Meaning
id_ Node ID
agents_ List of attached transport layer agents
nn_
_ Total number of nodes
ns_ Simulator
dmux_ Demulitplexer or port classifier
classifier_ The head address classifier
module_list_ List of enabled routing modules
reg_module_ List of registered routing modules
List of routing modules which will be notified of
rtnotif_
route updates
List of routing modules which will be notified of
ptnotif_
port attachment/detachment
hook_assoc_ Sequence of the chain of classifiers
Association of classifiers and routing modules, whose
mod_assoc_ indexes and values are classifiers and the associated
routing modules, respectively.
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
58
I
Installing
lli Classifiers
Cl ifi
in
i aN
Node
d
• Maintain the head classifier (classifier_)
(classifier )
only.
• Access other classifiers through
classifier_.
Instvar
hook_assoc_
mod_assoc_
Index
Value
A classifier The next
classifier
A classifier The associated
routing module
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
59
I
Installing
lli Classifiers
Cl ifi
in
i aN
Node
d
• Example values
_o1
Routing
Module
_o2
_o3
Routing
Module
_o5
• hook_assoc_[_o1] = _o2
• hook_assoc_[_o2] = _o3
hook assoc [ o3] = _o4
o4
• hook_assoc_[_o3]
Routing
Module
_o6
_o7
•
•
•
•
_o4
Routing
Module
_o8
mod_assoc_[_o1]
mod_assoc_[_o2]
mod_assoc_[_o3]
mod_assoc_[_o4]
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
=
=
=
=
_o5
_o6
_o7
_08
08
60
I
Installing
lli Classifiers
Cl ifi
in
i aN
Node
d
• Three main instprocs:
1. insert-entry{ module clsfr {hook “”}}
a. Associate the classifier clsfr with the routing module
module,
b. Put clsfr as the head classifier,
c. If hook is a number, p
put the next (previously
p
y the head)
classifier in the slot hook of clsfr
d. If hook is “target”, set the target of clsfr to be the next
(previously
p
y the head) classifier
2. install-entry{ module clsfr {hook “”}} (also
destroy the head classifier,
classifier if any)
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
61
I
Installing
lli Classifiers
Cl ifi
in
i aN
Node
d
//~ns/tcl/lib/ns-node.tcl
Node instproc insert-entry { module clsfr {hook ""} } {
$self instvar classifier_ mod_assoc_ hook_assoc_
if { $hook != "" } {
set hook_assoc_($clsfr)
$
$
$classifier_
if { $hook == "target" } {
$clsfr target $classifier_ (d)
} elseif { $hook !
!= "" } {
$clsfr install $hook $classifier_ (c)
}
}
set mod_assoc_($clsfr) $module (a)
set classifier_ $clsfr (b)
}
• Go through instproc install-entry{…} yourself.
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
62
I
Installing
lli Classifiers
Cl ifi
in
i aN
Node
d
3 {install
3.
{install-demux
demux { demux {port “”}}
}}
a. Replace the current dmux_ with the input demux
b If port exists
b.
exists, put the current dmux_
dmux in the slot
port of the input dmux
//~ns/tcl/lib/ns-node.tcl
Node instproc install
install-demux
demux {demux {port ""}
} } {
$self instvar dmux_ address_
if { $dmux_ != "" } {
$self delete-route $dmux_
if { $port != "" } {
$demux install $port $dmux_ (b)
}
}
set
t dmux_
d
$d
$demux
(a)
$self add-route $address_ $dmux_
}
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
63
R
Routing
i
•
A routing protocol consists of 4 main
components:
–
–
–
–
Routing
g agent:
g
Information collector ((not
being used for static routing)
Route logic: Routing table computation
Cl
Classifier:
ifi
Packet
P k forwarder
f
d (base
(b
on the
h
route logic)
Routing module: The single point of
management for classifiers
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
64
M i i
Motivation
• In g
general, we can have several classifiers.
_o1
_o2
_o3
_o4
• Suppose we want to send a common command (e.g., addroute, attach-agent) to all classifiers
– Sequentially access each of classifiers
– Send a command (e.g., add-route) to the accessed classifier
• It would be more convenient if we can have a classifier
manager.
manager
– Send the command to this manager.
– The manager will auto. access and populate the command.
• This
Thi manager is
i called
ll d a “ROUTING MODULE”
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
65
I l
Implementing
i R
Routing
i M
Module
d l
• Objective:
Objective Manage classifiers
• Where do we need to manage it? Node
• Place two “classifier managers” in class Node
Classifier manager
ptnotif_ rtnotif_
((i.e.,
. ., routing
g module)
m
)
Managed
Functionality
TL bridge
Routing
Type of classifiers
Port
Address
Management
Technique
List based Pointer based
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
66
OTcl class Node: Instvars
Instvar
Meaning
id_ Node ID
agents_ List of attached transport layer agents
nn_
_ Total number of nodes
ns_ Simulator
dmux_ Demulitplexer or port classifier
classifier_ The head address classifier
module_list_ List of enabled routing modules
reg_module_ List of registered routing modules
List of routing modules which will be notified of
_
rtnotif_
route updates
List of routing modules which will be notified of
ptnotif_
port attachment/detachment
hook_assoc_ Sequence of the chain of classifiers
Association of classifiers and routing modules, whose
mod_assoc_ indexes and values are classifiers and the associated
routing modules, respectively.
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
67
R
Routing
i M
Module
d l Di
Diagram
rtnotif_
ptnotif_
...
$rtnotif_ add-route
$addr $target
Node
RM
next_rtm_
...
classifier_
RM
RM
next_rtm_
next_rtm_
0
0
classifier_
classifier_
RM
next_rtm_
...
0
classifier_
Agent
foreach m {ptnotif_} {
$m attach $agent $port
}
Agent
PortClassifier
Address
Classifier
Address
classifier
Agent
Agent
Link
PortClassifier
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
68
R
Routing
i M
Module:
d l C
C++
• C++ class RoutingModule,
RoutingModule bound to
• OTcl class RtModule
Add/remove a
routing
g module
*rtm to the chain
//~ns/routing/rtmodule.h
class RoutingModule : public TclObject {
public:
void route_notify(RoutingModule *rtm);
void unreg_route_notify(RoutingModule *rtm);
virtual void add_route(char *dst, NsObject *target);
virtual
i
void
i delete_route(char *dst, NsObject
j
*nullagent);
RoutingModule *next_rtm_;
protected:
Classifier *classifier
classifier_;
;
};
Add/remove a pointer *target into the classifier_
associated with all downstream Routing Module
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
69
R
Routing
i M
Module:
d l C
C++
//~ns/routing/rtmodule.cc
void RoutingModule::route_notify(RoutingModule *rtm) {
if (next_rtm_ != NULL)
next_rtm_->route_notify(rtm);
else
next_rtm_ = rtm;
}
void RoutingModule::add
g
_route(char
(
*dst,
, NsObject
j
*target)
g )
{
if (classifier_)
classifier_->do_install(dst,target);
if (next_rtm_ != NULL)
next_rtm_->add_route(dst, target);
}
• Function add_route(…)
add route(…) eliminate the needs to
1. Get an access to each classifier
2. Invoke do_install(…) for each of them
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
70
R
Routing
i M
Module:
d l OT
OTcll
• Class RtModule bound to the C++ class
RoutingModule
• Two key instvars: next_rtm_,
ne t rtm
classifier_
• Few
F
instprocs:
i
register{node}
route-notify{mod}
add-route{dst,target}
attach{agent port}
attach{agent,port}
unregister{}
un-reg-route-notify{mod}
delete-route{dst,nullagent}
attach-node{node}
attach
node{node}
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
71
Sample Derived Classes
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
72
OTcl class Node: Instvars
Instvar
Meaning
id_ Node ID
agents_ List of attached transport layer agents
nn_
_ Total number of nodes
ns_ Simulator
dmux_ Demulitplexer or port classifier
classifier_ The head address classifier
module_list_ List of enabled routing modules
reg_module_ List of registered routing modules
List of routing modules which will be notified of
_
rtnotif_
route updates
List of routing modules which will be notified of
ptnotif_
port attachment/detachment
hook_assoc_ Sequence of the chain of classifiers
Association of classifiers and routing modules, whose
mod_assoc_ indexes and values are classifiers and the associated
routing modules, respectively.
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
73
Node Instvars
• module_list_ stores the name of enabled routing
g modules.
• Instproc mk-default-classifier registers routing
modules whose name is in the module_list_.
• reg_module_ (associated array)
– Index: Routing module’s name
– Value: Routing module
module’ss instance
• rtnotif_: The head of routing module
• ptnotif_:
t tif : An array of
f routing
r utin module
m dule (for
(f r port
p rt
attachment)
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
74
Related Routing Module Components
This configuration
is created when
a Node is created
“$ node”
“$ns
d ”
module_list_={Base,Mcast}
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
75
N d Obj
Node
Object C
Creation
i
• Suppose we have a node,
node $node,
$node and
a base routing module, $base.
1 At compilation
1.
//~/ns/tcl/lib/ns-node.tcl
Node set module_list_ { Base }
2.
Node Construction: $ns node
21 Node constructor: Node init {}
21.
21-1. set rtnotif_ {}
p
_ {}
21-2. set ptnotif
21-3. $node mk-default-classifier
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
76
N d Obj
Node
Object C
Creation
i
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
77
N d Obj
Node
Object C
Creation
i
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
78
N d Obj
Node
Object C
Creation
i
213. $node mk-default-classifier
213-1. foreach modname [Node set module_list_] {
$node register-module [new RtModule/$modname]
}
2131 [Node instproc register-module { base }]
2131-1 $base $register $node
2131-2 set reg_module_([$base module-name]) $base
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
79
N d Obj
Node
Object C
Creation
i
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
80
N d Obj
Node
Object C
Creation
i
21311 $base $register $node
21311-1 RtModule register $node
23111-2 RtModule/Base register $node
213111
213111-1
213111-2
213111-3
RtModule register $node
$base attach-node $node
$node route-notify $base
$node port-notify $base
2131111
$base attach-node $node (OTcl command)
2131111-1 n_ = (Node*)TclObject::lookup(argv[2]);
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
81
N d Obj
Node
Object C
Creation
i
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
82
N d Obj
Node
Object C
Creation
i
2131112 $node route-notify $base
//~/ns/tcl/lib/ns-node.tcl
Node instproc route-notify { module } {
$self instvar rtnotif_
if {$rtnotif_ == ""} {
set rtnotif_ $module
(2131112-1)
} else {
$rtnotif_ route-notify $module (2131112-2)
}
$module cmd route-notify $self
(2131112-3)
}
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
83
N d Obj
Node
Object C
Creation
i
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
84
N d Obj
Node
Object C
Creation
i
21311122 $rtnotif_ route-notify $module
//~/ns/tcl/lib/ns-rtmodule.tcl
RtModule instproc route-notify { module } {
$self instvar next_rtm_
if {$next_rtm_ == ""} {
Consider
set next_rtm_ $module
RtModule/Mcast
} else {
$next_rtm_ route-notify $module
}
}
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
85
N d Obj
Node
Object C
Creation
i
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
86
N d Obj
Node
Object C
Creation
i
2131112 $node route-notify $base
//~/ns/tcl/lib/ns-node.tcl
Node instproc route-notify { module } {
$self instvar rtnotif_
if {$rtnotif_ == ""} {
set rtnotif_ $module
(2131112-1)
} else {
$rtnotif_ route-notify $module (2131112-2)
}
$module cmd route-notify $self
(2131112-3)
}
What ‘ss difference?
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
87
N d Obj
Node
Object C
Creation
i
2131112-3 $module cmd route-notify $self (OTcl command)
21311123-1 (Class RoutingModule) n_->route_notify(this);
void Node::route_notify(RoutingModule *rtm) {
if (rtnotif_ == NULL)
rtnotif_ = rtm;
else
rtnotif_->route_notify(rtm);
t tif >
t
tif ( t )
}
//~ns/routing/rtmodule.cc
void RoutingModule::route
g
_notify(RoutingModule
y(
g
*rtm)
) {
if (next_rtm_ != NULL)
next_rtm_->route_notify(rtm);
else
next_rtm_ = rtm;
}
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
88
N d Obj
Node
Object C
Creation
i
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
89
N d Obj
Node
Object C
Creation
i
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
90
N d Obj
Node
Object C
Creation
i
21311 $base $register $node
21311-1 RtModule register $node
23111-2 RtModule/Base register $node
213111
213111-1
213111-2
213111-3
RtModule register $node
$base attach-node $node
$node route-notify $base
$node port-notify $base
//~/ns/tcl/lib/ns-node.tcl
Node instproc port-notify { module } {
$self instvar ptnotif_
lappend ptnotif_ $module
}
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
91
N d Obj
Node
Object C
Creation
i
21311 $base $register $node
21311-1 RtModule register $node
23111-2 RtModule/Base register $node
//~/ns/tcl/lib/ns-rtmodule.tcl
RtModule/Base instproc register { node } {
$self next $node
$self instvar classifier_
set classifier_ [new Classifier/Hash/Dest 32]
$classifier_
_ set mask_
_ [AddrParams NodeMask 1]
$classifier_ set shift_ [AddrParams NodeShift 1]
$node install-entry $self $classifier_
}
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
92
N d Obj
Node
Object C
Creation
i
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
93
N d Obj
Node
Object C
Creation
i
21311 $base $register $node
21311-1 RtModule register $node
23111-2 RtModule/Mcast register $node
//~/ns/tcl/lib/ns-rtmodule.tcl
RtModule/Mcast instproc register { node } {
$node set switch_ [new Classifier/Addr]
$node insert-entry $self [$node set switch_] 0
}
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
94
Th Use
The
U of
f Routing
R
i Modules
M d l
• Why is it so complicated?
• Suppose you remove a routing module,
you will have
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
95
Th Use
The
U of
f Routing
R
i Modules
M d l
• Why is it so complicated?
• Suppose you remove a routing module,
you will have
• Isn’t it nice?
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
96
Th Use
The
U of
f Routing
R
i Modules
M d l
• How would you add
add-route/attach
route/attach agent to
the node?
• Access and send commands to each
classifier manually.
fy
you have 10 classifiers
f
f
for each
• What if
node?
you are implementing
p
g dynamic
y
• What if y
routing?
• NOT SCALABLE !!!
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
97
Th Use
The
U of
f Routing
R
i Modules
M d l
• Two routing modules
1. ptnotif_ (List): Control TL bridges
2 rtnotif_
2.
rtnotif (Pointer): Control Routing
• Recall: Agent attachment
– $ns attach-agent $node $udp
//~ns/tcl/lib/ns-node.tcl
Node instproc attach { agent { port "" } } {
if { $dmux_ == "" } {
set dmux_ [new Classifier/Port]
$self add-route $address_ $dmux_
}
$self add-target $agent $port
}
rtnotif_
ptnotif_
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
98
Th Use
The
U of
f Routing
R
i Modules
M d l
//~ns/tcl/lib/ns-lib.tcl
Si l t
Simulator
i
instproc
t
attach-agent
tt h
t { node
d agent
t } {
$node attach $agent (2)
}
//~ns/tcl/lib/ns-node.tcl
Node instproc attach { agent { port "" } } {
$self instvar agents_ address_ dmux_
...
$self add-target $agent $port (3)
}
Node instproc add-target { agent port } {
$self instvar ptnotif_
foreach m [$self set ptnotif_] {
$m attach $
$
$agent
g
$p
$port
Access the demultiplexer
(4)
}
through ptnotif_
}
//~ns/tcl/lib/ns-rtmodule.tcl
RtModule instproc attach { agent port } {
$agent target [[$self node] entry] (5)
[[$self node] demux] install $port $agent (5)
}
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
99
Th Use
The
U of
f Routing
R
i Modules
M d l
//~ns/tcl/lib/ns-node.tcl
Node instproc add-route { dst target } {
$self instvar rtnotif_
if {$rtnotif_ != ""} {
$rtnotif add
$rtnotif_
add-route
ro te $dst $target
}
$self incr-rtgtable-size
}
//~ns/tcl/lib/ns-rtmodule.tcl
Access classifier_
RtModule instproc add-route { dst target } {
through rtnotif_
rtnotif
$self instvar next_rtm_
[$self set classifier_] install $dst $target
if {$next_rtm_ != ""} {
$next rtm add-route
$next_rtm_
add route $dst $target
}
}
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
100
Th Use
The
U of
f Routing
R
i Modules
M d l
//~ns/tcl/lib/ns-node.tcl
Node instproc add-route { dst target } {
$self instvar rtnotif_
if {$rtnotif_ != ""} {
$rtnotif add
$rtnotif_
add-route
ro te $dst $target
}
$self incr-rtgtable-size
}
//~ns/tcl/lib/ns-rtmodule.tcl
Access classifier_
RtModule instproc add-route { dst target } {
through rtnotif_
rtnotif
$self instvar next_rtm_
[$self set classifier_] install $dst $target
if {$next_rtm_ != ""} {
$next rtm add-route
$next_rtm_
add route $dst $target
}
}
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
101
Outline
•
•
•
•
•
•
•
Overview
Classifier
P
Port
Classifier
Cl ifi
Hash Classifier
TL Bridge Configuration
Routing
Summary
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
102
Summary
• Node
N d F
Functionality
ti
lit
– ( Router ) and ( Computer Host )
– Consists of connectors and classifiers
• Classifiers
– Multi-target connector
– Router ( Address classifier )
– Computer host ( Port classifier )
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
103
Summary
• Routing Components
1.
2.
3.
4.
(
(
(
(
Routing agent
Route logic
Classifier
Routing module
)
)
)
)
• Node configuration: 3 main steps
1. Node construction Command:
( $ns node
2. Route configuration Command:
( $ns run
3. TL Bridge configuration Command:
( $ns attach-agent
attach agent $node $agent )
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
)
)
104
© Copyright 2026 Paperzz