Scheduling-Dispatching     Mechanism       Ns2Ultimate.com              by      Teerawat Issariyakul         January 2011
RecapNS2 is a discrete-event simulator, where actions are associated with eventsrather than time. An event in a discrete-e...
NS2 is a discrete-event simulator, where actions are associated with events                                     Recap rath...
Recap: Insert an EventPut an event *e on the timeline at “delay”second infuture, and associated the event with a handler “...
RecapT execute actions associated with an event *e owhich is stored at time “t” seconds in future                         ...
Still,Very Abstract, Right?
What’s in This SlideshowScheduling-dispatching mechanismUse an example: Delayed packet forwarding Handler ➠ NsObject Event...
objects are events, handlers, the Scheduler, and the Simulator.•   Helper objects do not explicitly participate in packet ...
Scheduling-Dispatching- From within its function recv(p,h)   void LinkDelay::recv(Packet* p, Handler* h)   {     Scheduler...
5.1.2 C++ Class Hierarchy    Scheduling-Dispatching                       This section gives an overview of C++ class hier...
Scheduling-Dispatching NS2 is a discrete-event simulator, where actions are associated with events rather than time. An ev...
Scheduling-Dispatching    Step 3: Dispatch the event//~ns/common/scheduler.ccvoid Scheduler::run(){                       ...
Scheduling-Dispatching    From within “dispatch(p,p->time)”        //~ns/common/scheduler.cc        void Scheduler::dispat...
related objects were discussed in Chapter 4. The packet-related objects will   be discussed in Chapter 8. The main helper ...
Scheduling-DispatchingAgain, the type of p->handler_ isNsObject*.So is the definition of function handle(p) inthis case   ...
Scheduling-DispatchingHere is the definition of function handle(p) inclass NsObject      //~/ns/common/object.cc      void...
of delayed packet forwarding, while Program 5.6 shows the details of functions    schedule(h,e,delay) as well as dispatch(...
For more         information          about NS2                   Please see                   this book                 f...
Upcoming SlideShare
Loading in...5
×

An Example of Scheduling-Dispatching Mechanism--Delayed Packet Reception

21,075

Published on

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
21,075
On Slideshare
0
From Embeds
0
Number of Embeds
8
Actions
Shares
0
Downloads
66
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "An Example of Scheduling-Dispatching Mechanism--Delayed Packet Reception"

  1. 1. Scheduling-Dispatching Mechanism Ns2Ultimate.com by Teerawat Issariyakul January 2011
  2. 2. RecapNS2 is a discrete-event simulator, where actions are associated with eventsrather than time. An event in a discrete-event simulator consists of executiontime, a set of actions, and a reference to the next event (Fig. 4.1). These eventsconnect is an event-driven chain of events on the simulation timeline NS2 to each other and form a simulation(e.g., that in Fig. 4.1). Unlike a time-driven simulator, in an event-drivensimulator, time between a pair of simulation timeline constant. When Put eventseventsthe events does executed from left to right (i.e., on in the chain are not need to bethe simulation starts,chronologically).1 In the next section, we will discuss the simulation concept ofNS2. In Sections 4.2, 4.3,the 4.4, we lineexplain take actions when Move along and time will and the details of classes Eventand Handler, class Scheduler, and class Simulator, respectively. Finally, we confronting an eventsummarize this chapter in Section 4.6. insert Event5 create event event time = 3.7 Action5 Event1 Event2 Event3 Event4 time = 0.9 time = 2.2 time = 5 time = 6.8 Action1 Action2 Action3 Action4 Time (second) 1 2 3 4 5 6 7Fig. 4.1. A sample chain of events in a discrete-event simulation. Each event con-tains execution time and a reference to the next event. In this figure, Event1 creates www.ns2ultimate.comand inserts Event5 after Event2 (the execution time of Event 5 is at 3.7 second).
  3. 3. NS2 is a discrete-event simulator, where actions are associated with events Recap rather than time. An event in a discrete-event simulator consists of execution time, a set of actions, and a reference to the next event (Fig. 4.1). These events connect to each other and form a chain of events on the simulation timeline (e.g., that in Fig. 4.1). Unlike a time-driven simulator, in an event-driven simulator, time between a pair of events does not need to be constant. When the simulation starts, events in the chain are executed from left to right (i.e.,• An event indicates what happens chronologically).1 In the next section, we will discuss the simulation concept of NS2. In Sections 4.2, 4.3, and 4.4, we will explain the details of classes Event• A handler indicates what to do and Handler, class Scheduler, and class Simulator, respectively. Finally, we summarize this chapter in Section 4.6. insert Event5 create event event time = 3.7 Action5 Event1 Event2 Event3 Event4 time = 0.9 time = 2.2 time = 5 time = 6.8 Action1 Action2 Action3 Action4 Time (second) 1 2 3 4 5 6 7 Fig. 4.1. A sample chain of events in a discrete-event simulation. Each event con- Handler Handler Handler Handler Handler tains execution time and a reference to the next event. In this figure, Event1 creates 1 2 4 and inserts Event5 after Event2 (the execution 3 5 time of Event 5 is at 3.7 second). www.ns2ultimate.com
  4. 4. Recap: Insert an EventPut an event *e on the timeline at “delay”second infuture, and associated the event with a handler “*h”. Scheduler s& = Scheduler::instance(); s.schedule(h,e,delay); Call here h e associated Handler Event Delay x current time www.ns2ultimate.com
  5. 5. RecapT execute actions associated with an event *e owhich is stored at time “t” seconds in future h e dispatch(e,t) Handler Event The function dispatch(e,t) executes default actions defined in the function handler(e) of x t the Handler *h. www.ns2ultimate.com
  6. 6. Still,Very Abstract, Right?
  7. 7. What’s in This SlideshowScheduling-dispatching mechanismUse an example: Delayed packet forwarding Handler ➠ NsObject Event ➠ PacketHow to receive a packet t seconds in the future. www.ns2ultimate.com
  8. 8. objects are events, handlers, the Scheduler, and the Simulator.• Helper objects do not explicitly participate in packet forwarding. However, they implicitly help to complete the simulation. For example, a routing module calculates routes from a source to a destination, while network address identifies each of the network objects. Scheduling-Dispatching In this chapter, we focus only on network objects. Note that, the simulation-related objects were discussed in Chapter 4. The packet-related objects willbe discussed in Chapter 8. The main helper objects will be discussed inChapter 15.5.1.2 C++ Class Hierarchy Step 1: Schedule an eventThis section gives an overview of C++ class hierarchies. The entire hierarchyconsists of over 100 C++ classes and struct data types. Here, we only show - Focus on class LinkDelaya part of the hierarchy (in Fig. 5.1). The readers are referred to [18] for thecomplete class hierarchy. OTcl Interface Default Action TclObject Handler Simulator PacketQueue NsObject AtHandler QueueHandler RoutingModule Network Component Classifier Connector LanRouter class LinkDelay : public Connector { Uni-directional Point-to- ... point Object Connector }; Queue Agent ErrorModel LinkDelay TraceFig. 5.1. A part of NS2 C++ class hierarchy (this chapter emphasizes on classesin boxes with thick solid lines). www.ns2ultimate.com
  9. 9. Scheduling-Dispatching- From within its function recv(p,h) void LinkDelay::recv(Packet* p, Handler* h) { Scheduler& s = Scheduler::instance(); s.schedule(target_, p, txt + delay_); } Call here associated Handler Event txt _ + delay_ x current time www.ns2ultimate.com
  10. 10. 5.1.2 C++ Class Hierarchy Scheduling-Dispatching This section gives an overview of C++ class hierarchies. The entire consists of over 100 C++ classes and struct data types. Here, we o a part of the hierarchy (in Fig. 5.1). The readers are referred to [1 complete class hierarchy. The type of target_ is Function handle(p)OTcl Interface is Default Action NsObject* defined in the class TclObject Handler NsObject Simulator PacketQueue NsObject AtHandler QueueH RoutingModule target_ is defined at the base Network Component class (i.e., Connector): Classifier Connector LanRouteclass Connector : public NsObject { Uni-directional Point-to- ... point Object Connector NsObject* target_;}; Queue Agent ErrorModel LinkDelay Trac Fig. 5.1. A part of NS2 C++ class hierarchy (this chapter emphasizes in boxes with thick solid lines). www.ns2ultimate.com
  11. 11. Scheduling-Dispatching NS2 is a discrete-event simulator, where actions are associated with events rather than time. An event in a discrete-event simulator consists of execution time, a set of actions, and a reference to the next event (Fig. 4.1). These events connect to each other and form a chain of events on the simulation timeline (e.g., that in Fig. 4.1). Unlike a time-driven simulator, in an event-driven simulator, time between a pair of events does not need to be constant. When Step 2: the simulation starts, events in the chain are executed from left to right (i.e., chronologically).1 In the next section, we will discuss the simulation concept of NS2. In Sections 4.2, 4.3, and 4.4, we will explain the details of classes EventThe Scheduler Move forward in time and Handler, class Scheduler, and class Simulator, respectively. Finally, we summarize this chapter in Section 4.6. insert Event5 create event event time = 3.7 Action5 Event1 Event2 Event3 Event4 time = 0.9 time = 2.2 time = 5 time = 6.8 Action1 Action2 Action3 Action4 Time (second) 1 2 3 4 5 6 7 MoveA forward events in athe next event. In this figure,Each event con- Fig. 4.1. sample chain of in time and execute events tains execution time and a reference to discrete-event simulation. Event1 creates and inserts Event5 after Event2 (the execution time of Event 5 is at 3.7 second). www.ns2ultimate.com
  12. 12. Scheduling-Dispatching Step 3: Dispatch the event//~ns/common/scheduler.ccvoid Scheduler::run(){ take the next event from instance_ = this; Event *p; the timeline and store the while (!halted_ && (p = deque())) { dispatch(p, p->time_); pointer to the retrieved }} event in the variable p Event: time_ 7 NsObject (LinkDelay::*target_): handler_x www.ns2ultimate.com
  13. 13. Scheduling-Dispatching From within “dispatch(p,p->time)” //~ns/common/scheduler.cc void Scheduler::dispatch(Event* p, double t){ clock_ = t; p->uid_ = -p->uid_; p->handler_->handle(p); } Executed handle(p) associated with this Event: handler time_ 7 NsObject handler_ (LinkDelay::*target_):x www.ns2ultimate.com
  14. 14. related objects were discussed in Chapter 4. The packet-related objects will be discussed in Chapter 8. The main helper objects will be discussed in Chapter 15.Scheduling-Dispatching 5.1.2 C++ Class Hierarchy This section gives an overview of C++ class hierarchies. The entire hierarchy consists of over 100 C++ classes and struct data types. Here, we only show a part of the hierarchy (in Fig. 5.1). The readers are referred to [18] for theFunction handle( p) is defined in the class complete class hierarchy.NsObject OTcl Interface Default Action TclObject Handler Simulator PacketQueue NsObject AtHandler QueueHandler RoutingModule Network Component Again, the type of Classifier Connector LanRouter NsObjecttarget_ is *NsObject (LinkDelay::*target_) Uni-directional Point-to- point Object Connector Queue Agent ErrorModel LinkDelay Trace www.ns2ultimate.com Fig. 5.1. A part of NS2 C++ class hierarchy (this chapter emphasizes on classes
  15. 15. Scheduling-DispatchingAgain, the type of p->handler_ isNsObject*.So is the definition of function handle(p) inthis case //~ns/common/scheduler.cc void Scheduler::dispatch(Event* p, double t){ clock_ = t; p->uid_ = -p->uid_; p->handler_->handle(p); } www.ns2ultimate.com
  16. 16. Scheduling-DispatchingHere is the definition of function handle(p) inclass NsObject //~/ns/common/object.cc void NsObject::handle(Event* e) { recv((Packet*)e); }which is simply to receive a packet www.ns2ultimate.com
  17. 17. of delayed packet forwarding, while Program 5.6 shows the details of functions schedule(h,e,delay) as well as dispatch(p,t) of class Scheduler. When “schedule(target_, p, d)” is invoked, function schedule (...) casts packet *p and the NsObject *target_ into Event andWhen putting together, they become a Handler objects, respectively (Line 1 of Program 5.6). Line 5 of Program 5.6 associates packet *p with the NsObject *target_. Lines 6-7 insert packet *p into the simulation timeline at the appropriate time. At the firing time,delayed packet forwarding mechanism the event (*p) is dispatched (Lines 9-14). The Scheduler invokes function handle(p) of the handler associated with event *p. In this case, the associated Step 1: Schedule Step 2: Move fw. Step 3: Dispatch Fig. 5.4. Delayed packet forwarding www.ns2ultimate.com
  18. 18. For more information about NS2 Please see this book from SpringerT. Issaraiyakul and E. Hossain, “Introduction to Network Simulator NS2”, Second Edition,Springer 2011, or visit www.ns2ultimate.com
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×