Nodes as Routers and Nodes as Routers and Nodes as Routers and Nodes as Routers and Nodes as Routers and Nodes as Routers and Computer Hosts Computer Hosts
Nodes as Routers and Nodes as Routers and Computer Hosts Computer Hosts
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 1
Outline• OverviewOverview• Classifier
P Cl ifi• Port Classifier• Hash Classifier• TL Bridge Configuration• RoutingRouting• Summary
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 2
O iOverview• Node functionalityNode functionality
– Router – Computer Hosts
S k t Add ( L 3 ) P t ( L 4 )• Socket = Address ( Layer 3 ) + Port ( Layer 4 )• Select the next hop object based on
– Address ( Router )FTP CBR
Address ( Router )– Port ( Computer host )
FTP CBR
source
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
destination
3
Node Architecture• An NsObject which connects an NsObject toAn NsObject which connects an NsObject to
– Another NsObject = ( )– [Node] More than one NsObject = Classifier
Connector[ ] j
• Router Address classifier• Computer host Port classifierComputer host Port classifier• Internal mechanismC++: ~ns/common/node cc,hC++: ns/common/node.cc,h
• Route/Port configuration OTcl: ~ns/tcl/lib/ns-node.tcl
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
OTcl ns/tcl/lib/ns node.tcl
4
Node Architecture• A composite objectp j
• OTcl domain– classifier_ = Address classifier
d Port classifier
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
– dmux_ = Port classifierBy default, entry_ is the classifier_
5
Node Functionalities• Receive and classify packetsfy p
– Category 1 Target 1– Category 2 Target 2–– …
• Two task– OTcl: Associate categories and targetsg g– C++: Classify packets
• Classification criteria– Destination address Routing– Destination address Routing– Destination port Delivering to transport
layer protocolPriorities Scheduling
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
– Priorities Scheduling
6
OTcl class Node: InstvarsInstvar Meaning
id_ Node ID agents_ List of attached transport layer agents
nn_ Total number of nodesns_ 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
rtnotifList of routing modules which will be notified ofroute updates
_route updates
ptnotif_List of routing modules which will be notified of port attachment/detachment
hook_assoc_ Sequence of the chain of classifiers
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
mod_assoc_Association of classifiers and routing modules, whoseindexes and values are classifiers and the associatedrouting modules, respectively.
7
Outline• OverviewOverview• Classifier
P Cl ifi• Port Classifier• Hash Classifier• TL Bridge Configuration• RoutingRouting• Summary
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 8
Cl ifi O iClassifiers: Overview• Multi-target packet forwarderMult target packet forwarder
target1
target2
l ifi
• Two main discussions:target3
classifier
w m u1. Configuration (i.e., setting classification criteria)2 Internal mechanism
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
2. Internal mechanism
9
Classifier: Internal Mechanism• Recap: ConnectorRecap: 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.hclass Connector : public NsObject {
... inline void send(Packet* p, Handler* h){target_->recv(p, h);}
};
//~/ns/common/connector.ccvoid 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-target packet forwarderClassifier: Multi target packet forwarder• Main mechanism1 Look at packet header1. Look at packet header2.FW pkts with the same categories to the
same NsObject in the same “slot”j
target1
21
…slot_
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
target2classifier
11
Classifiers: C++ Implementation
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 12
Classifiers: C++ Implementation
Function Meaningrecv(p,h) Receive a packet
i R hi l b f classify(p) Return a matching slot number for packet *p
find(p) Return a matching target for find(p) Return a matching target for packet *p
install(slot,p) Put a pointer p to an NsObject in slot_[slot]
clear(slot) Remove the NsObject installed in slot [slot]
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
slot_[slot]
13
• In principle 2 main tasks:Classifiers: C++ ImplementationIn principle, 2 main tasks:
1. Configuration: – Tell classifier how to classify packetsTell classifier how to classify packets– C++ defines interface for OTcl to do so.
2. Internal mechanism: Classify packetsy pNsObject
classifier
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 14
1 Configuration: Classifiers: C++ Implementation
1. Configuration: – install(slot,p) puts *NSObject in slot_
2. Internal Mechanism– classify(p):
2
1
slot
_
classify(p): 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*)• Put an input pointer “*p” in Put an input pointer p in
slot_[slot]
2
1
_ …
slot
slot
…
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
…
p
16
Cl ifi l if ( )• Return the “slot number”
Classifiers::classify(p)Return the slot number corresponding to packet “*p”Implementation in class • Implementation in class Classifier does not make much sense!!sense!!
• Overridden in the derived classes– HashClassifier– PortClassifier
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 17
Cl ifi fi d( )Classifiers::find(p)• Return a pointer to an NsObjectReturn a pointer to an NsObject
corresponding to packet “*p”
Return this pointer (node)
- Return the matching slot number- Defined in the derived class 2
1
slot
_
pointer (node)
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
Def ned n the der ved class …
packet
18
Cl ifi ( h)Classifiers::recv(p,h)
(1)
(2)
1. Locate an NsObjectdi t k t corresponding to packet
“*p” (using “find(p)”)2. Forward the packet to the 2
1
slot
_Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
2. o wa d the packet to the located NsObject
…
packet
19
Classifiers: OTcl Implementation• Purpose: Configure a classifier Purpose: Configure a classifier Put NsObjects in the slots R t i Retrieve NsObject
• These are OTcl commands in file ns/classifier/classifier cc
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
~ns/classifier/classifier.cc
20
Cl ifi Th Si l tiClassifiers: The Simulation• At the Network Configuration phase
– Define classification criterion– Configure (put NsObject* in slot_)
accordinglyAt th Si l ti h• At the Simulation phase– Receive packet: recv(p,h)
1 “ l ssif ” th k t * d 1. “classify” the packet *p, and 2. forward the packet the matched NsObject
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
NsObject
21
Cl ifi 2 M i TClassifiers: 2 Main Types• A node acts as A node acts as
– A computer host Port classifier PortClassifier
– RouterAddress classifier HashClassifier
• 2 Main tasks:– Configuration– Internal mechanism
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 22
Outline• OverviewOverview• Classifier
P Cl ifi• Port Classifier• Hash Classifier• TL Bridge Configuration• RoutingRouting• Summary
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 23
P Cl ifi O iPort Classifier: Overview• A computer host A computer host
– connects a node to transport layer (TL) protocol
– may have several attached TL protocol• Port: Identify which TL protocol should a
k packet be forwarded to, e.g., – Attach FTP to port 65, and
Att h CBR t t 66FTPCBR
– Attach CBR to port 66Port65Port66
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
Node
24
Port Classifier: NS2 Implementation• Node ConfigurationNode Configuration
• PortClassifier object = dmux_
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 25
• NS2 ConfigurationPort Classifier: NS2 Implementation
NS2 Configuration• Installer a pointer to
agent of portagent of port– 65 in slot_[65]– 66 in slot_[66]
t i l t [ t]– pt in slot_[pt]
FTPCBR
Port65Port66 Port65
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
Node Port66
26
• C++ Implementation
Port Classifier: NS2 ImplementationC Implementation
• PortClassifier::classify(p)(1)
(3)//~ns/classifier/classifier-port.ccint PortClassifier::classify(Packet *p){
hdr ip* iph = hdr ip::access(p);
(3)
hdr_ip* iph = hdr_ip::access(p);return iph->dport();
}
(2)
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
(2)
27
Outline• OverviewOverview• Classifier
P Cl ifi• Port Classifier• Hash Classifier• TL Bridge Configuration• RoutingRouting• Summary
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 28
H h Cl ifiHash Classifier• Hash determinitically digests an Hash determinitically digests an
input and spits out an outputHASH
(function)Input Output
• Same input always hashes to the same outputp
• Example: – Encryption: MD5 SHA-256
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
Encryption: MD5, SHA 256– Look up table
29
H h Cl ifi E lHash Classifier: Example• Look up table: Sequential search takes Look up table: Sequential search takes
long time• Input = 4 bits
Input Output0 10Input = 4 bits
• Output = 4 bitsH h f
0 101 11
• Hash function = XOR with 1010
2 43 9
• Much quicker operation 4 45 15
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
6 1230
H h Cl ifiHash Classifier• In NS2: Hash tableIn NS2: Hash table
Slot Flow ID SRC dd
DST ddno. address address
0 10 2 3
• Input = (hash) key = (fid src dst)
1 11 4 7
Input = (hash) key = (fid,src,dst)• Output = (hash) index = slot no.
E h h h dTextbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
• Each row = hash record31
H h Cl ifiHash Classifier• Base C++ class = HashClassifierBase C++ class = HashClassifier• 4 main derived classes:
C++ Class OTcl Class Classification criteria
D tH hCl ifi Cl ifi / (d )DestHashClassifier Classifier/Hash/Dest
(dst)
FidHashClassifier Classifier/Hash/Fid
(fid)
• Input = (hash) key = (fid,src,dst)O (h h) i d l
Hash/Fid
SrcDestHashClassifier Classifier/Hash/SrcDest
(src,dst)
SrcDestFidHashClassifier Classifier/ ( d t fid)
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
• Output = (hash) index = slot no.SrcDestFidHashClassifier Classifier/Hash/SrcDestFid
(src,dst,fid)
32
D H hCl ifiDestHashClassifier• No need to define function recv(p h)No need to define function recv(p,h)• Define function classify(p)://~ns/classifier/classifier-hash cc//~ns/classifier/classifier-hash.ccint DestHashClassifier::classify(Packet * p) {
int slot = lookup(p); if (slot >= 0 && slot <=maxslot )
Defined in classH hCl ifiif (slot >= 0 && slot <=maxslot_)
return (slot); else if (default_ >= 0)
return (default );
HashClassifier
return (default_); else return (-1);
}
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 33
Outline• OverviewOverview• Classifier
P Cl ifi• Port Classifier• Hash Classifier• TL Bridge Configuration• RoutingRouting• Summary
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 34
C fi i Cl ifiConfiguring Classifier• Classifier forwards packet to a Classifier forwards packet to a
predefines categories Internal mechanism Internal mechanism
• How are the categories predefined?f Configuration
• TL bridges PortClassifierg• Routers DestHashClassifier
• Mainly in OTcl
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
• Mainly in OTcl
35
C fi i P Cl ifiConfiguring PortClassifier• Recall: instproc attach-agent of class Recall: instproc attach-agent of class Simulator
1. $ns attach-agent $node $agentg g2. $node attach $agent {port “”}3. $node add-target $agent $port4. $rm attach $agent $portg p5. $agent target [[$self node] entry]5. [[$self node] demux] install $port $agent
Note: $rm is a routing module stored in the array ptnotif of $node
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
ptnotif_ of $node
36
C fi i P Cl ifiConfiguring PortClassifier//~ns/tcl/lib/ns-lib.tcl Si l t i t tt h t { d t } {Simulator instproc attach-agent { node agent } {
$node attach $agent } //~ns/tcl/lib/ns-node.tcl
(2)
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 $port (4)$ $ g $p}
} //~ns/tcl/lib/ns-rtmodule.tcl RtModule instproc attach { agent port } {
$agent target [[$self node] entry]
(4)
(5)
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
$agent target [[$self node] entry] [[$self node] demux] install $port $agent
}
(5)(5)
37
Configuring PortClassifier$agent target [[$self node] entry]$ g g [[$ ] y]
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 38
Configuring PortClassifier[[$self node] demux] install $port $agent[[$ ] ] $p $ g
2
1
_ …
slot
_slot
…
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
…
p
39
Configuring D H hCl ifiDestHashClassifier
• Address classifierAddress classifier
R h h bj f • Return the next hop object for a given destination address
• RoutingRout ng
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 40
Outline• OverviewOverview• Classifier
P Cl ifi• Port Classifier• Hash Classifier• TL Bridge Configuration• RoutingRouting• Summary
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 41
R i (O li )• A routing protocol consists of 4 main
Routing (Outline)A routing protocol consists of 4 main components:
– Routing agent: Information collector (not g g (being used for static routing)
– Route logic: Routing table computationCl ifi P k f d (b h – Classifier: Packet forwarder (base on the route logic)
– Routing module: The single point of Routing module: The single point of management for classifiers
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 42
R iRouting• Relationship among routing componentsRelationship among routing components
attach-agent SIMULATORattach agent
NODE
CLASSIFIERROUTING MODULErtmodule_, ptnotif_
newattachadd-route
installregisterattachadd-route
computeconfigure
ROUTE LOGIC
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 43
R L i• Compute routing table
Route LogicCompute routing table
• How? Based on predefined routing protocol, e.g.,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
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
– Let Simulator computes the routing table
44
C Cl R L i• C++ main variables (~ns/routing/route *)
C++ Class RouteLogicC++ main variables ( ns/routing/route. )
– adj_: Adjacency matrix– route : routing table_ g
• C++ main functionsFunctions Meaninginsert(src,dst) Insert an entry (src,dst) to the
adjacency matrix adjadjacency matrix adj_compute_routes() Use adj_ to compute the routing table
and store it in route_l k fl ( id did) R t th f di bj t f
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
lookup_flat(sid,did) Return the forwarding object for a route from sid to did
45
OT l Cl R L i• One OTcl main variables
OTcl Class RouteLogicOne OTcl main variables
• An array rtprotos_i d Th f ti t l – index = The name of a routing protocol (e.g., Static, Manual)
l Th ti t l t– value = The routing protocol agent• 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 R L i• OTcl main functions
OTcl Class RouteLogicOTcl main functions
Functions Meaningi t { t} St th ti t l t t i register{name,agent} Store the routing protocol agent <agent> in
rtprotos_[<name>]
configure{} Initialize all its routing protocol inrtprotos by invoking their instproc init-rtprotos_ by invoking their instproc init-all{}
lookup{sid,did} Return the forwarding object for a route from (sid,did)( , )
compute{} Invoke the C++ function compute_routes()
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
In file ~ns/tcl/lib/ns-route.tcl
47
OT l Cl R L i• Default Routing protocol: Static
OTcl Class RouteLogicDefault Routing protocol Static
• Instproc configure{}RouteLogic instproc configure {} {
$self instvar rtprotos $se st a 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.,
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
– Set the adj_ of the RouteLogic– Compute the routing table.
48
R L i C fi iRoute Logic Configuration• Setting a routing tableSetting a routing table• Start when “ $ns run ” is executed.
U Dijk h h l i h • Use Dijkstar shortest path algorithm for all pairs of nodes
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 49
R L i C fi iRoute Logic Configuration• Default route logic setupDefault route logic setup1. $ns run2. [$ns get-routelogic] configure3 A t/ tP t /St ti i it ll3. Agent/rtProto/Static init-all4. $ns compute-routes5. $ns compute-flat-routes6. 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.
Go through NS2 codes yourself!!
50
R i• A routing protocol consists of 4 main
RoutingA routing protocol consists of 4 main components:
– Routing agent: Information collector (not g g (being used for static routing)
– Route logic: Routing table computationCl ifi P k f d (b h – Classifier: Packet forwarder (base on the route logic)
– Routing module: The single point of 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 d R i• Two main configuration tasks
Classifier and RoutingTwo main configuration tasks
1. Putting classifiers in Nodes2. Configuring the classifiers g g
• Configuring the route logic1. $ns run
…5. $ns compute-flat-routes6. … $r compute$ p7. $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 i Cl ifi//~ns/common/simulator.cc void
Configuring a ClassifierSimulator::populate_flat_classifiers() {
... for (int i=0; i<nn_; i++) {
for (int j 0; j<nn ; j++) {
A pointer to a RouteLogicobject
for (int j=0; j<nn_; j++) { if (i != j) {
int nh = -1; nh = rtobject ->lookup flat(i, j); j _ p_ ( , 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 i Cl ifi//~ns/common/node.cc
Configuring a Classifiervoid 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.• For now, it’s sufficient to know that, ff“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 Cl ifi i N d• Two main configuration tasks
Putting a Classifier in a Node• Two main configuration tasks
1. Putting classifiers in Nodes2. Configuring the classifiers 2. Configuring the classifiers
• From the constructor of class Node1. $ns node2. set node [new Node]3. $node init4. $node mk-default-classifier5 $node register-module [new RtModule/Base]
Q: Why invoking init{} ? What is init{}?
5. $node register module [new RtModule/Base]6. RtModule/Base register $node7. set classifier_ [new Classifier/Hash/Dest/ 32]7. $node install-entry RtModule/Base $classifier_
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
• Go through the NS2 codes by yourself.55
I lli Cl ifi i N d• We can have several classifiers in a node
Installing Classifiers in a Node• We can have several classifiers in a node.
• This example has 2 classifiers.
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 56
I lli Cl ifi i N d• We can have several classifiers in a node
Installing Classifiers in a Node• We can have several classifiers in a node. Chain of Classifiers
classifier2 3 4
_(_o1) _o2 _o3 _o4
hook_assoc_
Routing Routing Routing Routing mod_assoc_
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
RoutingModule
RoutingModule
RoutingModule
RoutingModule
_o5 _o6 _o7 _o857
OTcl class Node: InstvarsInstvar 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 classifiermodule_list_ List of enabled routing modules reg_module_ List of registered routing modules
rtnotifList of routing modules which will be notified ofroute updates
_route updates
ptnotif_List of routing modules which will be notified of port attachment/detachment
hook_assoc_ Sequence of the chain of classifiers
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
mod_assoc_Association of classifiers and routing modules, whoseindexes and values are classifiers and the associatedrouting modules, respectively.
58
I lli Cl ifi i N d• Maintain the head classifier (classifier )
Installing Classifiers in a NodeMaintain the head classifier (classifier_) only.
• Access other classifiers through Access other classifiers through classifier_.
Instvar Index Valuehook_assoc_ A classifier The next
classifiermod_assoc_ A classifier The associated
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
routing module
59
I lli Cl ifi i N d• Example values
Installing Classifiers in a Node• Example values
_o1 _o2 _o3 _o4
Routing Routing Routing RoutingRoutingModule
RoutingModule
RoutingModule
RoutingModule
_o5 _o6 _o7 _o8
• mod_assoc_[_o1] = _o5• mod_assoc_[_o2] = _o6• mod_assoc_[_o3] = _o7
08
• hook_assoc_[_o1] = _o2• hook_assoc_[_o2] = _o3• hook assoc [ o3] = o4
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
• mod_assoc_[_o4] = _08hook_assoc_[_o3] _o4
60
I lli Cl ifi i N d• Three main instprocs:
Installing Classifiers in a NodeThree 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, put the next (previously the head) p p y
classifier in the slot hook of clsfrd. If hook is “target”, set the target of clsfr to be the next
(previously the head) classifierp y
2. install-entry{ module clsfr {hook “”}} (also destroy the head classifier if any)
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
destroy the head classifier, if any)
61
I lli Cl ifi i N d//~ns/tcl/lib/ns-node.tcl
Installing Classifiers in a NodeNode 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_ } elseif { $hook != "" } {
(d)} elseif { $hook ! } {
$clsfr install $hook $classifier_}
}
(c)
set mod_assoc_($clsfr) $module set classifier_ $clsfr
}
(a)(b)
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
• Go through instproc install-entry{…} yourself.
62
I lli Cl ifi i N d3 {install-demux { demux {port “”}}
Installing Classifiers in a Node3. {install demux { demux {port }}
a. Replace the current dmux_ with the input demuxb If port exists put the current dmux in the slot b. If port exists, put the current dmux_ in the slot
port of the input dmux//~ns/tcl/lib/ns-node.tclNode instproc install-demux {demux {port ""} } {Node instproc install demux {demux {port } } {
$self instvar dmux_ address_if { $dmux_ != "" } {
$self delete-route $dmux_if { $port != "" } {if { $port != } {
$demux install $port $dmux_}
}t d $d (a)
(b)
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
set dmux_ $demux$self add-route $address_ $dmux_
}
(a)
63
R i• A routing protocol consists of 4 main
RoutingA routing protocol consists of 4 main components:
– Routing agent: Information collector (not g g (being used for static routing)
– Route logic: Routing table computationCl ifi P k f d (b h – Classifier: Packet forwarder (base on the route logic)
– Routing module: The single point of 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 iMotivation• In general, we can have several classifiers.g
_o1 _o2 _o3 _o4
• Suppose we want to send a common command (e.g., add-route, attach-agent) to all classifiers
Sequentially access each of 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 managermanager.– Send the command to this manager.– The manager will auto. access and populate the command.
Thi i ll d “ROUTING MODULE”
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
• This manager is called a “ROUTING MODULE”
65
I l i R i M d lImplementing Routing Module• Objective: Manage classifiersObjective Manage classifiers• Where do we need to manage it? Node• Place two “classifier managers” in class Node
Classifier manager (i.e., routing module) ptnotif_ rtnotif_( . ., g m )Managed Functionality TL bridge Routing
Type of classifiers Port AddressManagement List based Pointer based
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
Technique List based Pointer based
66
OTcl class Node: InstvarsInstvar 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 classifiermodule_list_ List of enabled routing modules reg_module_ List of registered routing modules
rtnotif_List of routing modules which will be notified ofroute updates
_route updates
ptnotif_List of routing modules which will be notified of port attachment/detachment
hook_assoc_ Sequence of the chain of classifiers
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
mod_assoc_Association of classifiers and routing modules, whoseindexes and values are classifiers and the associatedrouting modules, respectively.
67
R i M d l DiRouting Module Diagramrtnotif_ ptnotif_
...
Node$rtnotif_ add-route
$addr $target
next_rtm_
RM
0next_rtm_
RM
... 0next_rtm_
RM
0next_rtm_
RM
...
Agent
classifier_ classifier_ classifier_ classifier_
foreach m {ptnotif_} {$m attach $agent $portAgent
Agent
AddressClassifier
Addressclassifier
PortClassifier
Agent
$m attach $agent $port}
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
Link
Classifier classifier
Agent
PortClassifier
68
R i M d l CRouting Module: C++• C++ class RoutingModule bound toC++ class RoutingModule, bound to• OTcl class RtModule Add/remove a
routing module //~ns/routing/rtmodule.hclass RoutingModule : public TclObject { public:
g*rtm to the chain
void route_notify(RoutingModule *rtm); void unreg_route_notify(RoutingModule *rtm); virtual void add_route(char *dst, NsObject *target); i i jvirtual void delete_route(char *dst, NsObject *nullagent);
RoutingModule *next_rtm_; protected:
Classifier *classifier ;
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
Classifier classifier_; }; Add/remove a pointer *target into the classifier_
associated with all downstream Routing Module69
R i M d l CRouting Module: C++//~ns/routing/rtmodule.cc void RoutingModule::route_notify(RoutingModule *rtm) {
if (next_rtm_ != NULL) next_rtm_->route_notify(rtm);
elseelse next_rtm_ = rtm;
} void RoutingModule::add route(char *dst, NsObject *target) g _ ( , j g ){
if (classifier_) classifier_->do_install(dst,target);
if (next_rtm_ != NULL) next_rtm_->add_route(dst, target);
}• Function add route(…) eliminate the needs to
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
Function add_route(…) eliminate the needs to 1. Get an access to each classifier2. Invoke do_install(…) for each of them
70
R i M d l OT lRouting Module: OTcl• Class RtModule bound to the C++ class Class RtModule bound to the C++ class RoutingModule
• Two key instvars: ne t rtm • Two key instvars: next_rtm_, classifier_
F i • Few instprocs:
register{node} unregister{}register{node} unregister{}route-notify{mod} un-reg-route-notify{mod}add-route{dst,target} delete-route{dst,nullagent}attach{agent port} attach-node{node}
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
attach{agent,port} attach node{node}
71
Sample Derived Classes
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 72
OTcl class Node: InstvarsInstvar 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 classifiermodule_list_ List of enabled routing modules reg_module_ List of registered routing modules
rtnotif_List of routing modules which will be notified ofroute updates
_route updates
ptnotif_List of routing modules which will be notified of port attachment/detachment
hook_assoc_ Sequence of the chain of classifiers
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
mod_assoc_Association of classifiers and routing modules, whoseindexes and values are classifiers and the associatedrouting modules, respectively.
73
Node Instvars• module list stores the name of enabled routing modules._ _ g• 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’s instance– Value: Routing module s instance
• rtnotif_: The head of routing modulet tif : An array f r utin m dule (f r p rt • ptnotif_: An array of routing module (for port
attachment)
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 74
Related Routing Module ComponentsThis configurationis created when a Node is created“$ d ”“$ns node”
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
module_list_={Base,Mcast}
75
N d Obj C iNode Object Creation• Suppose we have a node $node and Suppose we have a node, $node, and
a base routing module, $base. 1 At compilation1. At compilation//~/ns/tcl/lib/ns-node.tclNode set module_list_ { Base }
2. Node Construction: $ns node21 Node constructor: Node init {}21. Node constructor: Node init {}21-1. set rtnotif_ {}21-2. set ptnotif {}
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
p _ {}
21-3. $node mk-default-classifier
76
N d Obj C iNode Object Creation
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 77
N d Obj C iNode Object Creation
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 78
N d Obj C iNode Object Creation213. $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 $node2131-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 C iNode Object Creation
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 80
N d Obj C iNode Object Creation21311 $base $register $node21311-1 RtModule register $node23111-2 RtModule/Base register $node
213111 RtModule register $node213111-1 $base attach-node $node213111-2 $node route-notify $base213111-3 $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 C iNode Object Creation
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 82
N d Obj C iNode Object Creation2131112 $node route-notify $base//~/ns/tcl/lib/ns-node.tclNode 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 C iNode Object Creation
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 84
N d Obj C iNode Object Creation21311122 $rtnotif_ route-notify $module //~/ns/tcl/lib/ns-rtmodule.tclRtModule instproc route-notify { module } {
$self instvar next_rtm_ if {$next_rtm_ == ""} {
set next_rtm_ $module} else {
Consider RtModule/Mcast
$next_rtm_ route-notify $module}
}
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 85
N d Obj C iNode Object Creation
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 86
N d Obj C iNode Object Creation2131112 $node route-notify $base//~/ns/tcl/lib/ns-node.tclNode 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 ‘s difference?
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
What s difference?
87
N d Obj C iNode Object Creation2131112-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
t tif > t tif ( t )rtnotif_->route_notify(rtm);}//~ns/routing/rtmodule.cc void RoutingModule::route notify(RoutingModule *rtm) { g _ y( g ) {
if (next_rtm_ != NULL) next_rtm_->route_notify(rtm);
else
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
next_rtm_ = rtm; }
88
N d Obj C iNode Object Creation
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 89
N d Obj C iNode Object Creation
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 90
N d Obj C iNode Object Creation21311 $base $register $node21311-1 RtModule register $node23111-2 RtModule/Base register $node
213111 RtModule register $node213111-1 $base attach-node $node213111-2 $node route-notify $base213111-3 $node port-notify $base
//~/ns/tcl/lib/ns-node.tclNode 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 C iNode Object Creation21311 $base $register $node21311-1 RtModule register $node23111-2 RtModule/Base register $node
//~/ns/tcl/lib/ns-rtmodule.tclRtModule/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 C iNode Object Creation
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 93
N d Obj C iNode Object Creation21311 $base $register $node21311-1 RtModule register $node23111-2 RtModule/Mcast register $node
//~/ns/tcl/lib/ns-rtmodule.tclRtModule/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 U f R i M d lThe Use of Routing Modules• Why is it so complicated? Why is it so complicated? • Suppose you remove a routing module,
you will have you will have
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 95
Th U f R i M d l• Why is it so complicated? The Use of Routing ModulesWhy is it so complicated?
• Suppose you remove a routing module, you will haveyou will have
• Isn’t it nice?
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 96
Th U f R i M d l• How would you add-route/attach agent to
The Use of Routing ModulesHow would you add route/attach agent to the node?
• Access and send commands to each Access and send commands to each classifier manually.
• What if you have 10 classifiers for each f y f fnode?
• What if you are implementing dynamic y p g yrouting?
• NOT SCALABLE !!!
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 97
Th U f R i M d l• Two routing modules The Use of Routing ModulesTwo routing modules 1. ptnotif_ (List): Control TL bridges2 rtnotif (Pointer): Control Routing2. rtnotif_ (Pointer): Control Routing
• Recall: Agent attachment– $ns attach-agent $node $udp
//~ns/tcl/lib/ns-node.tclNode instproc attach { agent { port "" } } {
if { $dmux_ == "" } { set dmux_ [new Classifier/Port] $self add-route $address_ $dmux_
}
rtnotif_
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
} $self add-target $agent $port
}ptnotif_
98
Th U f R i M d l//~ns/tcl/lib/ns-lib.tcl Si l t i t tt h t { d t } {
The Use of Routing ModulesSimulator instproc attach-agent { node agent } {
$node attach $agent } //~ns/tcl/lib/ns-node.tcl
(2)
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 $port (4)Access the demultiplexer $ $ g $p}
} //~ns/tcl/lib/ns-rtmodule.tcl RtModule instproc attach { agent port } {
$agent target [[$self node] entry]
(4)
(5)
Access the demultiplexer through ptnotif_
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
$agent target [[$self node] entry] [[$self node] demux] install $port $agent
}
(5)(5)
99
Th U f R i M d l//~ns/tcl/lib/ns-node.tcl
The Use of Routing ModulesNode instproc add-route { dst target } {
$self instvar rtnotif_ if {$rtnotif_ != ""} {
$rtnotif add ro te $dst $target$rtnotif_ add-route $dst $target } $self incr-rtgtable-size
} }
//~ns/tcl/lib/ns-rtmodule.tclRtModule instproc add-route { dst target } { Access classifier_
through rtnotif$self instvar next_rtm_ [$self set classifier_] install $dst $targetif {$next_rtm_ != ""} {
$next rtm add route $dst $target
through rtnotif_
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
$next_rtm_ add-route $dst $target}
}
100
Th U f R i M d l//~ns/tcl/lib/ns-node.tcl
The Use of Routing ModulesNode instproc add-route { dst target } {
$self instvar rtnotif_ if {$rtnotif_ != ""} {
$rtnotif add ro te $dst $target$rtnotif_ add-route $dst $target } $self incr-rtgtable-size
} }
//~ns/tcl/lib/ns-rtmodule.tclRtModule instproc add-route { dst target } { Access classifier_
through rtnotif$self instvar next_rtm_ [$self set classifier_] install $dst $targetif {$next_rtm_ != ""} {
$next rtm add route $dst $target
through rtnotif_
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
$next_rtm_ add-route $dst $target}
}
101
Outline• OverviewOverview• Classifier
P Cl ifi• Port Classifier• Hash Classifier• TL Bridge Configuration• RoutingRouting• Summary
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 102
SummaryN d F ti lit • Node Functionality – ( 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• Routing Components
1. ( Routing agent )2. ( Route logic )3. ( Classifier )4. ( Routing module )
• Node configuration: 3 main steps1. Node construction Command: ( $ns node )2. Route configuration Command: ( $ns run )3. TL Bridge configuration Command:
( $ns attach-agent $node $agent )
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
( $ns attach agent $node $agent )
104