SlideShare una empresa de Scribd logo
1 de 18
Descargar para leer sin conexión
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

Más contenido relacionado

Más de Teerawat Issariyakul

Más 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
 

Último

Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 

Último (20)

Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

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