Links and Buffer ManagementLinks and Buffer ManagementLinks and Buffer ManagementLinks and Buffer Management
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 1
O liOutline• OverviewOverview• Packet Departure• Buffer Management• Buffer Management• Summary
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 2
Li k d Si l Li kLinks and Simple Links• Connect two nodesConnect two nodes
n0 n1Link
• Consider “Simple Links” Onlyp y• Simple Links models
– Packet transmission time = pkt_size/BWk l– Link propagation delay
– Buffer management Unlike real implementation (buffering is a functionality in
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
mp m ntat n ( uff r ng a funct na ty n routers)
3
Si l Li k A hiSimple Links: Architecture• A stand-alone composite OTcl objectA stand alone composite OTcl object
– head_ = the entry– queue_ = buffering
li k d l kt t s issi ti– link_ = model pkt transmission timeand link propagation delay
– ttl = time to live
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
_ t m t – drophead_ = dropping point
4
Si l Li k A hiSimple Links: Architecture• A stand-alone composite OTcl objectA stand alone composite OTcl object
– enqT_ (+) = Trace pkt entering queue_– deqT_ (-) = Trace pkt leaving queue_
drpT (d) = Trace pkt dropped from queue– drpT_ (d) = Trace pkt dropped from queue_(Buffer overflow)
– rcvT_ (r) = Trace pkt received by
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
the terminating object
5
Si l Li k A hiSimple Links: Architecture• An example of trace fileAn example of trace file
– enqT_ = Trace enqueue, “+”– deqT_ = Trace dequeue, “-”– rcvT = Trace receive “r”
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
rcvT_ Trace receive, r– drpT_ = Trace packet drop, “d”, (Buffer overflow)
6
Si l Li k C iSimple Links: Creation• From the OTcl (e.g., Tcl simulation script)( g p )
– simplex-link: Create a one-directional simple link object– duplex-link: Create two simplex-links in two directions
What are simple-link and duplex-link??
E l s
What are simple-link and duplex-link??( instprocs of class Simulator )
• Examples
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 7
Si l Li kSimplex Links• Instproc simplex-link of class simulatorp p f
– Create a uni-directional SimpleLink object
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 8
SimpleLink: OT l COTcl Constructor
//~ns/tcl/lib/ns-link.tcl SimpleLink instproc init { src dst bw delay q {
lltype "DelayLink"} } {set ns [Simulator instance] set drophead [ne Connector]set drophead_ [new Connector] $drophead_ target [$ns set nullAgent_] set head_ [new Connector] $head target $q
What is the class of drophead_?( C t )$ _ g $q
set queue_ $q... }
( Connector )What is “target” ?( OTcl command )
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 9
q nullAgent
SimpleLink: OT l COTcl Constructor
//~ns/tcl/lib/ns-link.tcl SimpleLink instproc init { src dst bw delay q {
lltype "DelayLink"} } {...set link [ne $llt pe]set link_ [new $lltype] $link_ set bandwidth_ $bw $link_ set delay_ $delay $queue target $link
What is the class of lltype_?( DelayLink)
$q _ g $ _$link_ target [$dst entry] $queue_ drop-target $drophead_ set ttl_ [new TTLChecker] $ttl_ target [$link_ target] $self ttl-drop-trace $link_ target $ttl_ }
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
}
10
O liOutline• OverviewOverview• Packet Departure• Buffer Management• Buffer Management• Summary
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 11
R P k F diRecap: Packet Forwarding• Sending packet *p to node *targetSending packet *p to node *target• Two types of packet forwarding
1 I di t k t f di1. Immediate packet forwarding target->recv(p,h)
l k 2. Delayed packet forwarding schedule(target, p, delay)
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 12
P k D PPacket Departure Process• The amount of time needed to deliver a packet to p
the next node– Actual implementation
• From: A packet enters the router Ap• To: The packet reaches the router B
packetA B
– NS2 implementation• From: A packet enters the Link
A B
• To: A packet leaves the Link• Note: A packet is assumed to be at Node B as soon as it
leaves the Link
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 13
LinkpacketB
P k D PPacket Departure Process• The time consists of The time consists of
1. Packet transmission time– Time a packet spend inside router A
Pkt siz /link sp d– Pkt_size/link_speed
2. Link propagation delay– Start after the entire packet leaves router A– Time the packet spend in the link
A B
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 14
Packet transmission time Link propagation delay
P k D PPacket Departure ProcessLINK
head_
queue_ link_ ttl_dst_
drophead_
• Which components implement the time? ( link ) ( link_ )
• C++ Class = LinkDelay• OTcl Class = DelayLink
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
y
15
C Cl Li kD lC++ Class LinkDelay//~ns/link/delay.hclass LinkDelay : public Connector { public:
LinkDelay(): dynamic_(0), latest_time_(0), itq_(0){ bind b ("band idth " &band idth )bind_bw("bandwidth_", &bandwidth_); bind_time("delay_", &delay_);
} void recv(Packet* p, Handler*); ( p, );inline double txtime(Packet* p) { /* Packet TXT Time */
return (8. * hdr_cmn::access(p)->size() / bandwidth_);}
protected: double bandwidth_; double delay_; PacketQueue* itq ;
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
PacketQueue* itq_; Event intr_; /* In transit */
};
16
Dummy Event
C Cl Li kD lC++ Class LinkDelay
Variable Meaningb d idth Li k s d (i b s)bandwidth_ Link speed (in bps)delay_ Link propagation delay (in seconds)itq_ Contains all packet in the linksintr_ Dummy event
A B
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 17
C Cl Li kD lC++ Class LinkDelay• Function txtime(p)Function txtime(p) Compute Packet transmission time
• Function recv(p,h)– Main packet reception function– Delay the packet reception at the downstream
NsObjectNsObject• Packet transmission time• Link propagation delay
How to delay it? Use ( Scheduler )
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
– How to delay it? Use ( Scheduler )
18
F i Li kD l ( h)Function LinkDelay::recv(p,h)
(1)
(2)
(3)
1. Compute packet transmission time (txt)
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 19
F i Li kD l ( h)Function LinkDelay::recv(p,h)
(1)
(2)
(3)
2. Schedule an event where a packet leave the router invoke h->handle(&intr ) after txt sec.
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
_
20
Q: What is the input argument here?
F i Li kD l ( h)Function LinkDelay::recv(p,h)
(1)
(2)
(3)
3. Schedule an event where the packet arrive at the next node after txt + propagation delay seconds.
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 21
O liOutline• OverviewOverview• Packet Departure• Buffer Management• Buffer Management• Summary
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 22
B ff M O liBuffer Management: Outline• OverviewOverview• Main C++ Classes
Q d Q H dl • Queue and Queue Handler • Callback Mechanism
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 23
B ff MBuffer Management• Buffer: Put incoming packets in the buffer g p
before emitting them out
• Why do need a buffer ? Packet In Packet Out
1
Q: Suppose no buffer what will happen if packet A B
12
Q: Suppose no buffer, what will happen if packet 2 arrives when the router is serving packet 1?
(The packet “2” would be lost.)
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
– Handle burstiness of input traffic
24
B ff MBuffer Management• NS2 implementationNS2 implementation• SimpleLink architecture
• Instvar queueq _– Receive packets,– Hold them until the link is clear, and
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
– Transmit the next packet in queue. 25
C++ Main Classes• C++ Class PacketQueue: a Q
– Model the buffer– Storage, enque, and deque packets
C Cl Q • C++ Class Queue: – Contain PacketQueue – Other functionalities, e.g., user interface, g ,
• C++ Class QueueHandler:– Derived from class Handler
P s D fi d f lt ti f Q bj t– Purpose: Define default action for a Queue object
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 26
Cl P k V i blClass Packet: Variables
…
//~/ns/common/packet.hclass Packet : public Event {
… public: idti h dltpublic:
Packet* next_; static int hdrlen_; …
uid_time_ handler_next_
• The packet supports link list by itself.B d
} uid_time_ handler_next_
• But it needs a manager:• Where the first packet is.• The number of packet in the link list.
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
PacketQueue
27
C++ Class PacketQueue
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 28
C++ Class Queue
kReceiving packets
CallbackMechanism
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 29
B ff M O liBuffer Management: Outline• OverviewOverview• Main C++ Classes
Q d Q H dl • Queue and Queue Handler • Callback Mechanism
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 30
C Cl Q H dlC++ Class QueueHandlerDefine default actionsDefine default actions
Function handle(e) function resume() of the associated Q object
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 31
the associated Queue object
Q d Q H dl• Highly associated
Queue and QueueHandlerHighly associated
• Queue accesses a QueueHandler object using a variable qh_
• QueueHandler accesses a Queue object using a reference to queue_
QueueQueue
queue
QueueHandler
• Now Queue and QueueHandler can invoke
qh_queue_
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
functions of each other.
32
Q d Q H dlQueue and QueueHandler• To associated a Queue object to a To associated a Queue object to a QueueHandler object
• The constructor of Queue: configuring qhhe constructor of Queue conf gur ng q _
//~ns/queue/queue.h class Queue : public Connector { QueueQ p {
...protected:
QueueHandler qh_; ... qh
QueueHandler
};qh_
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 33
Q d Q H dlQueue and QueueHandler• The constructor of class QueueHandler: The constructor of class QueueHandler:
configuring queue_
Queue
QueueHandler
• The connection between Queue
qh_queue_
The connection between Queueand QueueHandler is established
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 34
QueueHandlerQ
• Key functionality = ? ( default actions for a Queue object )
• QueueHandler::handle(Event*)
• Queue::resume() Q () Callback mechanism
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 35
B ff M O liBuffer Management: Outline• OverviewOverview• Main C++ Classes
Q d Q H dl • Queue and Queue Handler • Callback Mechanism
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 36
Callback Mechanism: Overview• Recap: Recap
– NsObject • does not send
T ll th d nstr m bj ct t r c iv• Tell the downstream object to receive– Packets are passed to downstream objects
only. • A signal which passed to an upstream
object is called a callback signalTh i ll d “ llb k h i ”• The process is called “callback mechanism”
• Discussion context: Queue-Link connection
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 37
Queue-Link Connection: Implementation• Main componentsMain components
– The SchedulerPacket: base class = ( Event ) – Packet: base class = ( Event )
– QueueHandler: base class = ( Handler ) Li kD l : P t th p k t in th – LinkDelay: Put the packet in the simulation timeline
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 38
A Queue-Link Connection: ConceptBuffering D lBuffering Delay
target->recv(p &qh )
1. queue_ sends a packet to link_2 i h k
target->recv(p,&qh_)
2. link_ receives the packet 3. queue_ waits until link_ indicate that it receives the
packet4. link_ sends a “callback” signal to queue_ after a certain
delay time5. queue_ realizes that the packet is received
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
p6. Go to 1.
39
Queue-Link Connection: Delay a callback message
//~ns/link/delay.ccvoid LinkDelay::recv(Packet* p Handler* h)void LinkDelay::recv(Packet* p, Handler* h) {
double txt = txtime(p); Scheduler& s = Scheduler::instance(); ();if (dynamic_) { /* See ~ns/link/delay.cc */ } else if (avoidReordering_) { /* See ~ns/link/delay.cc */
}l {else {
s.schedule(target_, p, txt + delay_); (a)}
s sched le(h &intr t t) (b)s.schedule(h, &intr_, txt); (b)} Q: What do (a) and (b) do? When do these actions occur?
a.Send a packet to a downstream objectb Send a callback message to the upstream Q
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
b.Send a callback message to the upstream Queue- Indicate that the packet has left the Queue- Queue can send another packet
40
Queue-Link Connection: Queue blocking mechanism
• How do a queue “wait” for a callback message?H w a q _ wa t f r a ca ac m ag ?• I.E., How do we stop a Queue object from sending
out packets after target->recv(p,&qh_) is t dexecuted.
• Queue blocking mechanism• Queue blocking mechanism– Not caused by buffer being filled– Use the variable blocked_ of class Queue//~ns/queue/queue.h class Queue : public Connector {
... protected:
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 41
int blocked_; int unblock_on_resume_;
};
Queue-Link Connection: Queue blocking mechanism
• Blocked (blocked =1)( _ )– Not being able to send packets– After sending– Waiting for the callback signal from link– Waiting for the callback signal from link_
• Not blocked (blocked_=0)– Able to send packetsp– After receiving the callback signal from link_
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 42
A Queue-Link Connection: ConceptBuffering D lBuffering Delay
Queue::resume()
1. queue_ sends a packet to link_2 i h k
Queue::resume()
2. link_ receives the packet 3. queue_ waits until link_ indicate that it receives the
packet4. link_ sends a “callback” signal to queue_ after a certain
delay time5. queue_ realizes that the packet is received
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
p6. Go to 1.
43
Queue-Link Connection: Main Functions
Function What it does Invoked byFunction What it does Invoked byresume() Reception of a
callback messageAn associated QueueHandler object
recv(p,h) Reception of a packet An upstream object
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 44
Queue-Link Connection: Delay a callback message
//~ns/link/delay.ccvoid LinkDelay::recv(Packet* p, Handler* h) {
double txt = txtime(p); Sched ler& s Sched ler instance()Scheduler& s = Scheduler::instance(); if (dynamic_) { /* See ~ns/link/delay.cc */ } else if (avoidReordering_) { /* See ~ns/link/delay.cc */
}else {
s.schedule(target_, p, txt + delay_); }
s.schedule(h, &intr_, txt);
}
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 45
Callback Mechanism in Queue-Link Interaction
(2) (3) (6)
(5)
target_ -> recv(p,h)
(1) (4)(4)
_
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 46
O liOutline• OverviewOverview• Packet Departure• Buffer Management• Buffer Management
– Queue and QueueHandler– Callback Mechanism– Callback Mechanism
• Summary
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 47
SSummary• Link is a composite OTcl object used to Link is a composite OTcl object used to
connect two nodes
• Class SimpleLink– models buffer management and Link delaymodels buffer management and L nk delay– is created by instrocs simplex-link or duplex-link of class Simulator
– consists of : head_, queue_, link_, ttl_, and drophead_
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 48
SSummary• Packet delay = transmission delay + propagation Packet delay transmission delay propagation
delay
• NS2 Link– C++ Class = LinkDelay– OTclClass = DelayLinkOTclClass DelayLink
• C++ Class LinkDelay– Two main variables: bandwidth_ and delay_. – Function recv(p,h) schedule two events:
• Packet departure from the upstream object
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
Packet departure from the upstream object• Packet arrival at the downstream object
49
SSummary• Queue handle burstiness: Queue handle burstiness Put a packet in queue and sent it out when the transmitter is ready.Cl d • Class Queue and QueueHandler:– Queue: A variable qh_– QueueHandler: A reference variable queue .q _
• Callback Mechanism– Send a message upstream
N ll k t ti i f d i d t – Normally packet reception is performed in a downstream direction.
– E.g., a LinkDelay object sends a message to a Queue to i di t d th t th k t h l ft th
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
indicated that the packet has left the Queue.
50