SlideShare une entreprise Scribd logo
1  sur  18
Télécharger pour lire hors ligne
Scheduling-Dispatching
     Mechanism
       Ns2Ultimate.com
              by
      Teerawat Issariyakul


         January 2011
Recap
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 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-driven
simulator, 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 be
the simulation starts,
chronologically).1 In the next section, we will discuss the simulation concept of
NS2. In Sections 4.2, 4.3,the 4.4, we lineexplain take actions when
        Move along and time will and the details of classes Event
and Handler, class Scheduler, and class Simulator, respectively. Finally, we
        confronting an event
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-
tains execution time and a reference to the next event. In this figure, Event1 creates
                                                                            www.ns2ultimate.com
and inserts Event5 after Event2 (the execution time of Event 5 is at 3.7 second).
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
Recap: Insert an Event
Put an event *e on the timeline at “delay”second in
future, 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
Recap
T execute actions associated with an event *e
 o
which 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
Still,
Very Abstract, Right?
What’s in This Slideshow

Scheduling-dispatching mechanism
Use an example: Delayed packet forwarding
 Handler ➠ NsObject
 Event ➠ Packet
How to receive a packet t seconds in the future.



                                       www.ns2ultimate.com
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 will
be discussed in Chapter 8. The main helper objects will be discussed in
Chapter 15.

5.1.2 C++ Class Hierarchy
            Step 1: Schedule an event
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

         - Focus on class LinkDelay
a part of the hierarchy (in Fig. 5.1). The readers are referred to [18] for the
complete 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          Trace

Fig. 5.1. A part of NS2 C++ class hierarchy (this chapter emphasizes on classes
in boxes with thick solid lines).
                                                                                                        www.ns2ultimate.com
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
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                   LanRoute
class 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
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 Event

The 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
Scheduling-Dispatching
    Step 3: Dispatch the event
//~ns/common/scheduler.cc
void 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
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
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 the
Function 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
                                                                            NsObject
target_ 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
Scheduling-Dispatching
Again, the type of p->handler_ is
NsObject*.
So is the definition of function handle(p) in
this 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
Scheduling-Dispatching

Here is the definition of function handle(p) in
class NsObject
      //~/ns/common/object.cc
      void NsObject::handle(Event* e)
      {
          recv((Packet*)e);
      }


which is simply to receive a packet


                                        www.ns2ultimate.com
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 and
When 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
For more
         information
          about NS2
                   Please see
                   this book
                 from Springer


T. Issaraiyakul and E. Hossain, “Introduction to Network Simulator NS2”, Second Edition,
Springer 2011, or visit www.ns2ultimate.com

Contenu connexe

Plus de Teerawat Issariyakul

Plus de Teerawat Issariyakul (7)

Basic Packet Forwarding in NS2
Basic Packet Forwarding in NS2Basic Packet Forwarding in NS2
Basic Packet Forwarding in NS2
 
NS2 Object Construction
NS2 Object ConstructionNS2 Object Construction
NS2 Object Construction
 
NS2 Shadow Object Construction
NS2 Shadow Object ConstructionNS2 Shadow Object Construction
NS2 Shadow Object Construction
 
20100712-OTcl Command -- Getting Started
20100712-OTcl Command -- Getting Started20100712-OTcl Command -- Getting Started
20100712-OTcl Command -- Getting Started
 
NS2: Binding C++ and OTcl variables
NS2: Binding C++ and OTcl variablesNS2: Binding C++ and OTcl variables
NS2: Binding C++ and OTcl variables
 
NS2 Classifiers
NS2 ClassifiersNS2 Classifiers
NS2 Classifiers
 
Ns-2.35 Installation
Ns-2.35 InstallationNs-2.35 Installation
Ns-2.35 Installation
 

Dernier

Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 

Dernier (20)

Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 

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

  • 1. Scheduling-Dispatching Mechanism Ns2Ultimate.com by Teerawat Issariyakul January 2011
  • 2. Recap 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 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-driven simulator, 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 be the simulation starts, chronologically).1 In the next section, we will discuss the simulation concept of NS2. In Sections 4.2, 4.3,the 4.4, we lineexplain take actions when Move along and time will and the details of classes Event and Handler, class Scheduler, and class Simulator, respectively. Finally, we confronting an event 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- tains execution time and a reference to the next event. In this figure, Event1 creates www.ns2ultimate.com and inserts Event5 after Event2 (the execution time of Event 5 is at 3.7 second).
  • 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. Recap: Insert an Event Put an event *e on the timeline at “delay”second in future, 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. Recap T execute actions associated with an event *e o which 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
  • 7. What’s in This Slideshow Scheduling-dispatching mechanism Use an example: Delayed packet forwarding Handler ➠ NsObject Event ➠ Packet How to receive a packet t seconds in the future. www.ns2ultimate.com
  • 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 will be discussed in Chapter 8. The main helper objects will be discussed in Chapter 15. 5.1.2 C++ Class Hierarchy Step 1: Schedule an event 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 - Focus on class LinkDelay a part of the hierarchy (in Fig. 5.1). The readers are referred to [18] for the complete 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 Trace Fig. 5.1. A part of NS2 C++ class hierarchy (this chapter emphasizes on classes in boxes with thick solid lines). www.ns2ultimate.com
  • 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. 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 LanRoute class 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. 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 Event The 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. Scheduling-Dispatching Step 3: Dispatch the event //~ns/common/scheduler.cc void 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. 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. 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 the Function 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 NsObject target_ 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. Scheduling-Dispatching Again, the type of p->handler_ is NsObject*. So is the definition of function handle(p) in this 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. Scheduling-Dispatching Here is the definition of function handle(p) in class NsObject //~/ns/common/object.cc void NsObject::handle(Event* e) { recv((Packet*)e); } which is simply to receive a packet www.ns2ultimate.com
  • 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 and When 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. For more information about NS2 Please see this book from Springer T. Issaraiyakul and E. Hossain, “Introduction to Network Simulator NS2”, Second Edition, Springer 2011, or visit www.ns2ultimate.com