Post on 24-Jul-2020
Part II: Part II: NSNS22 Components and ImplementationComponents and Implementation
Part II: Part II: NSNS22 Components and ImplementationComponents and ImplementationNSNS2 2 Components and ImplementationComponents and ImplementationNSNS2 2 Components and ImplementationComponents and Implementation
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 1ed
pared
Prepa
PPook: T. Iss
yby
at rw
atII: II: andandandandandandand
Tee
s ananananananan
ulya
kul
sariy
a
Issa
Part II: Outline• Nodes and Links• Packets and TimersPackets and Timers• Agents and Applications• Tracing and Debugging
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 2ed
pared
Prepa
PPook: T. Iss
yby Te
at
erwat
cation
eeDebugg
ulya
kul
sariy
a
Issa
Part II: OverviewPart II: OverviewApplication
Source Agent Sink Agent
packetn0 n1
packet
Link: Connecting Nodes
Buffer ManagementAgent:
Packet Creation and
Node: A computer host +
A
Buffer ManagementDestruction
Application: Demand Indication
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 3
A routerpaed
cket
aredD
on: ndicatio
Prepa
PPook: T. Iss
yby
Agent
at
erwatwa
Teeee
ulya
kul
sariy
a
Issa
NodesNodesNodesNodesNodesNodesNodesNodes
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 4ed
pared
Prepa
PPook: T. Iss
yby
at rw
atodeodeodeode
Tee
NodNodNodNod
ulya
kul
sariy
a
Issa
Outline• Overview
Classifier• Classifier• Summaryy
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 5ed
pared
Prepa
PPook: T. Iss
yby
at
erwat
Tee
ulya
kul
sariy
a
Issa
OverviewOverview• Node functionality
R t– Router – Computer Hosts
• Socket = Address ( Layer 3 ) + Port ( Layer 4 )Socket Address ( Layer 3 ) Port ( Layer 4 )• Select the next hop object based on
– Address ( Router ) FTP CBR– Port ( Computer host )
FTP CBR
source
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 6
destination
PPrepook: T. Issed
pared
par
epa
tination
yby
at+ P
erwat) P
ct bas
Teest )
ulya
kul
sariy
a
Issa
Node Architecture
N b h h N b
Node Architecture
• An NsObject which connects an NsObject to– Another NsObject = ( )– More than one NsObject = Classifier
Connector
• Router � Address classifier• Computer host� Port classifierComputer host � Port classifier• Internal mechanism�C / / d h�C++: ~ns/common/node.cc,h
• Route/Port configuration
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 7
� OTcl: ~ns/tcl/lib/ns-node.tcl
PrepPP
ed e
pared/com
/Por
paook: T. Iss
OTcl:y�by
�chanis
at
erwat
ject =Con
Teess clasP
ulya
kul
sariy
aNIss
as an N
Node Architecture• A composite object
• OTcl domain• OTcl domain– entry_ = Connector – classifier = Address classifier
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 8
classifier_ = Address classifier – dmux_ = Port classifier
PPreook: T. Issed
in
aredmain
ry_assifi
ep
assifdmux
by
ulya
kul
sariy
a
Node: Instvars
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 9PPreook: T. Iss
ulya
kul
Node: Instprocsp
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 10PPook: T. Iss
ulya
kul
ariya
Node: Instprocsp
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 11Prepa
PPook: T. Iss
ulya
kul
sariy
a
Node: Instprocsp
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 12ed
pared
Prepa
PPook: T. Iss
ulya
kul
sariy
a
ssa
Node: Instprocsp
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 13PrepPPook: T. Iss
ulya
kul
riya
Outline• Overview
Classifier• Classifier• Summaryy
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 14ed
pared
Prepa
PPook: T. Iss
yby
at
erwat
Tee
ulya
kul
sariy
a
Issa
Classifiers: Internal Mechanism (C++)
C• Connector– A single-target packet forwarderg g p– FW received packets to the attached
NsObject (target_)j g• Classifier
– A multi-target packet forwarderA multi target packet forwarder– Examine packet header and classify the
packetpacket– FW packets in the same category to the
same NsObject
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 15
same NsObject.
P
ed e
aredt
W packame N
Prepa
ook: T. Iss
ame
e
by
gepacke
att for
erwatts to
t_)
Tee
ulya
kul
sariy
asm (C
Issa
rw
Cl ifi E lClassifiers: Examples• Address Classifier• Address Classifier
– Classify packets based on the address• Port Classifier• Port Classifier
– Classify packet based on portFTP CBR
FTP CBR
P t 1 sourcePort 2
Port 1
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 16
destination
PPrepook: T. Issed
pared
parort 2
epa
tination
yby
at
he
erwat
on po
Tee
ulya
kul
sariy
aes
Issa
addr
Classifiers: C++ ImplementationClassifiers: C++ Implementation• Purpose: Internal mechanismPurpose: Internal mechanism• Concept:
1 L k t k t h d1. Look at packet header2. FW pkts with the same categories to
th s NsObj t i th s “sl t”the same NsObject in the same “slot”• C++ Implementation: Class Classifier
slot 1
s 2…
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 17Classifier
ed
paredarere
dreddd
Prepa
PPook: T. Iss
yby yy
at
erwatr
samet i
TeeObjectntati
ulya
kul
tion
sariy
atiosm
Issanism
Classifiers: C++ ImplementationClassifiers: C++ Implementation
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 18P
ed
edred
Prepook: T. Iss
T
ulya
kul
tion
sariy
atio
Classifiers: C++ ImplementationClassifiers: C++ Implementation• C++ Implementation:C Implementation:
– Variables: • slot : Contain NsObjectslot_: Contain NsObject • default_target_: For packets which does
not match any criteriony– Functions:
• recv(p,h): Receive packets(p, ) p• classify(p): Return the slot number which
matches with the packet header• find(p): Return an NsObject installed in
the slot corresponding to p• install(slot NsObject*): Put the NsObject
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 19
• install(slot,NsObject*): Put the NsObject in the slot “slot”pa
red hes
rednd(p):the sloins
Prepa
ook: T. Iss
insin
yR
byy(p): Rwit
at ct
erwatct
or pacterion
Teeei
ulya
kul
tion
sariy
atio
Issa
l fClassifiers::install(slot,NsObject*)• Put “p” in slot [slot]Put p in slot_[slot]
pinstall NsObject
slot_ … …1 2 slot
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 20
Classifier
P
ed
pared
pared
paredslot
Prepa
ook: T. Iss
papaby
t
Tee
ulya
kul
sariy
aject
Issa
Classifiers::find(p)Classifiers::find(p)• Return an NsObject* corresponding j p g
to packet “p” Function classify(p) is defined in fthe derived class
findp
slot_ … …1 2 cl
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 21
Classifier
P
ed
pared
pared
paredslot
Prepa
ook: T. Iss
papabyy
ateerwee
ulya
kul
sariy
a)respo
IssFunc
Classifiers::Classify(p)
• Return the “slot number” corresponding to packet “p”
• Defined in the derived class• Defined in the derived class– HashClassifier– PortClassifier
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 22ed
pared
Prepa
PPook: T. Iss
by yysifier
at ber
erwatacket
eriv
Teederier
ulya
kul
sariy
ay(p)
Issa
”
Classifiers::recv(p h)• recv(p,h)
Classifiers::recv(p,h)(p, )
1. Located NsObject for packet “p” using “find(p)”find(p)
2. Forward the packet to the located NsObjectNsObject
(1)
(2)
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 23PrepPPpa
ook: T. Iss
by
at
p
erwatt to t
Tee
ulya
kul
sariy
a
Issa
acket
Classifiers: OTcl Implementation
• Purpose: Configure a classifier � P t N Obj t i th l t� Put NsObjects in the slots� Retrieve NsObjects� Retrieve NsObjects
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 24
par
Prepa
PPook: T. Iss
at
clath
rwatn the
bjec
Tee
Obje
ulya
kul
sariy
antati
Issa
assi
Cl ifi R CClassifiers: ReCap
• Classifier is a multi-target packet g pforwarder
• Used as• Used as– Router (AddressClassifier)– Host (PortClassifier)
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 25ed
pared
Prepa
PPook: T. Iss
byybyrtClasatarge
erwatg
TeeressC
ulya
kul
sariy
ap
Issa
et
Classifiers: The Simulation• At the Network Configuration phase
D fi l ifi ti it i– Define classification criterion– Configure (put NsObject in slots)
di laccordingly• At the Simulation phase
– Receive packet: recv(p,h)� “classify” the packet py p p�forward the packet the matched NsObject
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 26
j
P
ed ssif
paredorwa
sObj
Prepa
ook: T. Iss
ybypacke”
at
guit
erwatcrit
NsObje
Teeation
ulya
kul
sariy
alatio
Issa
urat
Classifiers: Inheritance Concept
• Function classify(p) is to beFunction classify(p) is to be overridden by the derive classA E l• An Example– Port Classifier– C++ Class PortClassifier
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 27ed
pared
Prepa
PPook: T. Iss
y
e
by
Port
ts to
erwas to
deriv
Tee
ulya
kul
sariy
aConce
Issa
b
Classifiers: Inheritance ConceptClassifiers: Inheritance Concept
• Network Configuration Phase:• Network Configuration Phase:( $ns attach-agent $n0 $udp )
• Simulation Phase:• Simulation Phase:
Destination port number agent
slot_ … …1 2 tClassifier
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 28
1 2 portClassifier
dpa
red
Prepa
PPook: T. Iss
by
at
ud
erwat
Teee:
ulya
kul
cept
sariy
ncep
ase:
IssaPhase
p )
Classifiers: Other Configuration gprocedures
C t d i t l ifi• Create and register classifiers– $ns node – Node::initNode init– Node::mk-default-classifier
R fi i• Route configuration– NS2 runs Dikjstra algorithm for all pairs of nodes– $ns run$ns run– RouteLogic::configure
• Agent attachment – $ns attach-agent $node $agent– Node::attach
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 29
– Node::attach
P
ed
paredttachm
attachode::a
Prepa
ook: T. Iss
Node:yby
configu
at
erwat
Teena algori
ulya
kul
tion
sariy
a
Issa
Summary• Node Functionality
( Router ) and ( Computer Host )– ( Router ) and ( Computer Host )– Consists of connectors and classifiers
• Classifiers– Multi-target connectorMulti target connector– Router � ( Address classifier )
C t h t� ( P t l ifi )– Computer host � ( Port classifier )
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 30d
�
h
paredter h
Prepa
PPook: T. Iss
c
by co
( bAdd
ater H
erwater H
ors a
Teen
ulya
kul
sariy
a
Issa
Related Files/ / d h• ~ns/common/node.h,cc
• ~ns/common/simulator.h,cc• ~ns/routing/route.h,cc
/ /• ~ns/routing/rtmodule.h,cc• ~ns/classifier/classifier.h,cc• ~ns/classifier/classifier-hash.h,cc • ~ns/classifier/classifier-port.h,cc• ~ns/tcl/lib/ns-lib.tcl• ~ns/tcl/lib/ns-node.tclns/tcl/lib/ns node.tcl • ~ns/tcl/lib/ns-route.tcl• ~ns/tcl/lib/ns-rtmodule.tcl
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 31ed
-r
pared
Prepa
PPook: T. Iss
tc
by tc
oute.tcmodul
at
erwat
sh.h,cc
Teeer-port.h
ulya
kul
sariy
a
Issa