31
Part II: Part II: NS NS2 Components and Implementation Components and Implementation Part II: Part II: NS NS2 Components and Implementation Components and Implementation NS NS2 2 Components and Implementation Components and Implementation NS NS2 2 Components and Implementation Components and Implementation Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 1 ed pared Prepa P P ook: T. Iss y by at rwat II: II: and and and and and and and Tee s an an an an an an an ul yakul sariya Issa

Part II: II - UBCteerawat/publications/NS2/W06-Nodes.pdfPart II: NS2 Components and ImplementationComponents and Implementation Textbook: T. Issariyakul and E. Hossain, Introduction

  • Upload
    others

  • View
    11

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Part II: II - UBCteerawat/publications/NS2/W06-Nodes.pdfPart II: NS2 Components and ImplementationComponents and Implementation Textbook: T. Issariyakul and E. Hossain, Introduction

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

Page 2: Part II: II - UBCteerawat/publications/NS2/W06-Nodes.pdfPart II: NS2 Components and ImplementationComponents and Implementation Textbook: T. Issariyakul and E. Hossain, Introduction

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

Page 3: Part II: II - UBCteerawat/publications/NS2/W06-Nodes.pdfPart II: NS2 Components and ImplementationComponents and Implementation Textbook: T. Issariyakul and E. Hossain, Introduction

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

Page 4: Part II: II - UBCteerawat/publications/NS2/W06-Nodes.pdfPart II: NS2 Components and ImplementationComponents and Implementation Textbook: T. Issariyakul and E. Hossain, Introduction

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

Page 5: Part II: II - UBCteerawat/publications/NS2/W06-Nodes.pdfPart II: NS2 Components and ImplementationComponents and Implementation Textbook: T. Issariyakul and E. Hossain, Introduction

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

Page 6: Part II: II - UBCteerawat/publications/NS2/W06-Nodes.pdfPart II: NS2 Components and ImplementationComponents and Implementation Textbook: T. Issariyakul and E. Hossain, Introduction

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

Page 7: Part II: II - UBCteerawat/publications/NS2/W06-Nodes.pdfPart II: NS2 Components and ImplementationComponents and Implementation Textbook: T. Issariyakul and E. Hossain, Introduction

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

Page 8: Part II: II - UBCteerawat/publications/NS2/W06-Nodes.pdfPart II: NS2 Components and ImplementationComponents and Implementation Textbook: T. Issariyakul and E. Hossain, Introduction

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

Page 9: Part II: II - UBCteerawat/publications/NS2/W06-Nodes.pdfPart II: NS2 Components and ImplementationComponents and Implementation Textbook: T. Issariyakul and E. Hossain, Introduction

Node: Instvars

Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 9PPreook: T. Iss

ulya

kul

Page 10: Part II: II - UBCteerawat/publications/NS2/W06-Nodes.pdfPart II: NS2 Components and ImplementationComponents and Implementation Textbook: T. Issariyakul and E. Hossain, Introduction

Node: Instprocsp

Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 10PPook: T. Iss

ulya

kul

ariya

Page 11: Part II: II - UBCteerawat/publications/NS2/W06-Nodes.pdfPart II: NS2 Components and ImplementationComponents and Implementation Textbook: T. Issariyakul and E. Hossain, Introduction

Node: Instprocsp

Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 11Prepa

PPook: T. Iss

ulya

kul

sariy

a

Page 12: Part II: II - UBCteerawat/publications/NS2/W06-Nodes.pdfPart II: NS2 Components and ImplementationComponents and Implementation Textbook: T. Issariyakul and E. Hossain, Introduction

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

Page 13: Part II: II - UBCteerawat/publications/NS2/W06-Nodes.pdfPart II: NS2 Components and ImplementationComponents and Implementation Textbook: T. Issariyakul and E. Hossain, Introduction

Node: Instprocsp

Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 13PrepPPook: T. Iss

ulya

kul

riya

Page 14: Part II: II - UBCteerawat/publications/NS2/W06-Nodes.pdfPart II: NS2 Components and ImplementationComponents and Implementation Textbook: T. Issariyakul and E. Hossain, Introduction

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

Page 15: Part II: II - UBCteerawat/publications/NS2/W06-Nodes.pdfPart II: NS2 Components and ImplementationComponents and Implementation Textbook: T. Issariyakul and E. Hossain, Introduction

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

Page 16: Part II: II - UBCteerawat/publications/NS2/W06-Nodes.pdfPart II: NS2 Components and ImplementationComponents and Implementation Textbook: T. Issariyakul and E. Hossain, Introduction

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

Page 17: Part II: II - UBCteerawat/publications/NS2/W06-Nodes.pdfPart II: NS2 Components and ImplementationComponents and Implementation Textbook: T. Issariyakul and E. Hossain, Introduction

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

Page 18: Part II: II - UBCteerawat/publications/NS2/W06-Nodes.pdfPart II: NS2 Components and ImplementationComponents and Implementation Textbook: T. Issariyakul and E. Hossain, Introduction

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

Page 19: Part II: II - UBCteerawat/publications/NS2/W06-Nodes.pdfPart II: NS2 Components and ImplementationComponents and Implementation Textbook: T. Issariyakul and E. Hossain, Introduction

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

Page 20: Part II: II - UBCteerawat/publications/NS2/W06-Nodes.pdfPart II: NS2 Components and ImplementationComponents and Implementation Textbook: T. Issariyakul and E. Hossain, Introduction

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

Page 21: Part II: II - UBCteerawat/publications/NS2/W06-Nodes.pdfPart II: NS2 Components and ImplementationComponents and Implementation Textbook: T. Issariyakul and E. Hossain, Introduction

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

Page 22: Part II: II - UBCteerawat/publications/NS2/W06-Nodes.pdfPart II: NS2 Components and ImplementationComponents and Implementation Textbook: T. Issariyakul and E. Hossain, Introduction

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

Page 23: Part II: II - UBCteerawat/publications/NS2/W06-Nodes.pdfPart II: NS2 Components and ImplementationComponents and Implementation Textbook: T. Issariyakul and E. Hossain, Introduction

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

Page 24: Part II: II - UBCteerawat/publications/NS2/W06-Nodes.pdfPart II: NS2 Components and ImplementationComponents and Implementation Textbook: T. Issariyakul and E. Hossain, Introduction

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

Page 25: Part II: II - UBCteerawat/publications/NS2/W06-Nodes.pdfPart II: NS2 Components and ImplementationComponents and Implementation Textbook: T. Issariyakul and E. Hossain, Introduction

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

Page 26: Part II: II - UBCteerawat/publications/NS2/W06-Nodes.pdfPart II: NS2 Components and ImplementationComponents and Implementation Textbook: T. Issariyakul and E. Hossain, Introduction

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

Page 27: Part II: II - UBCteerawat/publications/NS2/W06-Nodes.pdfPart II: NS2 Components and ImplementationComponents and Implementation Textbook: T. Issariyakul and E. Hossain, Introduction

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

Page 28: Part II: II - UBCteerawat/publications/NS2/W06-Nodes.pdfPart II: NS2 Components and ImplementationComponents and Implementation Textbook: T. Issariyakul and E. Hossain, Introduction

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 )

Page 29: Part II: II - UBCteerawat/publications/NS2/W06-Nodes.pdfPart II: NS2 Components and ImplementationComponents and Implementation Textbook: T. Issariyakul and E. Hossain, Introduction

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

Page 30: Part II: II - UBCteerawat/publications/NS2/W06-Nodes.pdfPart II: NS2 Components and ImplementationComponents and Implementation Textbook: T. Issariyakul and E. Hossain, Introduction

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

Page 31: Part II: II - UBCteerawat/publications/NS2/W06-Nodes.pdfPart II: NS2 Components and ImplementationComponents and Implementation Textbook: T. Issariyakul and E. Hossain, Introduction

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