SlideShare ist ein Scribd-Unternehmen logo
1 von 15
Event Driven Simulation:
     The Concept
        Ns2Ultimate.com
               by
       Teerawat Issariyakul


         October 2011
Time Driven Simulation
12       1 Simulation of Computer Networks

                         2                     4
                    a                                                  6
                                                                           time
     0                              3              b   c   5

             Fig. 1.3. Clock advancement in a time-driven simulation
          Stop and observer the system after
          FIXED INTERVAL (∆)
    Fig. 1.3 shows the basic idea behind time advancement in a time-driven
simulation. The curved arrows represent such advances, and a, b, and c
mark the occurrences of events. During the ïŹrst interval, no event occurs.
          Events (e.g, a, b,c) are assumed to
The second interval contains event a, which is not handled until the end of
the interval.

          happen at the end of each interval
    Time interval (∆) is an important parameter of time-driven simulation.
While a large interval can lead to loss of information, a small interval can
cause unnecessary waste of computational eïŹ€ort. Suppose, in Fig. 1.3, events
          Implementation using “for loop”
b and c in the ïŹfth interval are packet arrival and departure events, respec-
tively. Since these two events are considered to occur exactly at the end of
the interval (i.e., at 5∆), the system state would be as if there is no packet
                                                                   www.ns2ultimate.com
arrival or departure events during [4∆, 5∆]. This is considered a loss of in-
Time Driven Simulation
         Implementation using for loop

            for t=0 to 100{
               Execute the events
            }
12        1 Simulation of Computer Networks

                          2                     4
                     a                                                  6
                                                                            time
     0                               3              b   c   5

              Fig. 1.3. Clock advancement in a time-driven simulation


     Fig. 1.3 shows the basic idea behind time advancement in www.ns2ultimate.com
                                                              a time-driven
‱ At the execution, an event may induce one or more events. The induced
  events are stamped with the time when the event occurs, and again stored
  in the event list. The timestamp of the induced events must not be less
  than the simulation clock. This is to ensure that the simulation would


Event Driven Simulation
  never go backward in time.
‱ An event-driven simulation starts with a set of initial events in the event
  list. It runs until the list is empty or another stopping criterion is satisïŹed.


                                                                   To the next event


                                                                              time
   0          a                               b               c

           Fig. 1.4. Clock advancement in an event-driven simulation


   Fig. 1.4 shows a graphical representation of event-driven simulation. Here,

 Move from one event to the next
events a, b, and c are executed in order. The time gap between any pair of
events is not ïŹxed. The simulation advances from one event to another, as
opposed to one interval to another in time-driven simulation. In event-driven

 NOT every fixed interval
simulation, programmers do not have to worry about optimizing time interval.
Example 1.2 Program 1.4.2 shows the skeleton of a typical event-driven
simulation program. Lines 1 and 2 initialize the system state variables and
the event list, respectively. Line 3 speciïŹes a stopping criterion. Lines 4–6 are
                         How do we implement it?
executed as along as Line 3 returns true. Within this loop, the event whose
timestamp is smallest is retrieved, executed, and removed from the list. Then,
                       We can’t use the for loop!
the simulation clock is set to the time associated with the retrieved event.



1.5 A Simulation Example: A Single-Channel Queuing
System                                           www.ns2ultimate.com
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


Event Driven Simulation
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.,
chronologically).1 In the next section, we will discuss the simulation concept of

   We can use pointers and create
NS2. In Sections 4.2, 4.3, and 4.4, we will explain the details of classes Event
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


                      A Chain of Event
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 ïŹgure, Event1 creates
and inserts Event5 after Event2 (the execution time of Event 5 is at 3.7 second).




                                                                            www.ns2ultimate.com
Implementation of Discrete-Event Simulation
    in NS2
 Characteristics of Event Driven
                              Simulation
An event has a pointer to the next event.
    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
    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
    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-
    tains execution time and a reference to the next event. In this ïŹgure, Event1 creates
    and inserts Event5 after Event2 (the execution time of Event 5 is at 3.7 second).
                                                                                      www.ns2ultimate.com
Implementation of Discrete-Event Simulation
    in NS2
 Characteristics of Event Driven
                              Simulation
An event has a pointer to the next event.
    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

An event can induce new events
    (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.,
    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
    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-
    tains execution time and a reference to the next event. In this ïŹgure, Event1 creates
    and inserts Event5 after Event2 (the execution time of Event 5 is at 3.7 second).
                                                                                      www.ns2ultimate.com
Implementation of Discrete-Event Simulation
    in NS2
 Characteristics of Event Driven
                              Simulation
An event has a pointer to the next event.
    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

An event can induce new events
    (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.,
    chronologically).1 In the next section, we will discuss the simulation concept of
  by using the “insert event” instruction
    NS2. In Sections 4.2, 4.3, and 4.4, we will explain the details of classes Event
    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-
    tains execution time and a reference to the next event. In this ïŹgure, Event1 creates
    and inserts Event5 after Event2 (the execution time of Event 5 is at 3.7 second).
                                                                                      www.ns2ultimate.com
Implementation of Discrete-Event Simulation
   in NS2
Main Components of Event Driven
                             Simulation
Events and Handlers
   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
   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
   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-
   tains execution time and a reference to the next event. In this ïŹgure, Event1 creates
   and inserts Event5 after Event2 (the execution time of Event 5 is at 3.7 second).
                                                                                     www.ns2ultimate.com
Implementation of Discrete-Event Simulation
    in NS2
Main Components of Event Driven
                              Simulation
Events and Handlers
    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

Simulation time line
    (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.,
    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
    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-
    tains execution time and a reference to the next event. In this ïŹgure, Event1 creates
    and inserts Event5 after Event2 (the execution time of Event 5 is at 3.7 second).
                                                                                      www.ns2ultimate.com
Implementation of Discrete-Event Simulation
    in NS2
Main Components of Event Driven
                              Simulation
Events and Handlers
    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

Simulation time line
    (e.g., that in Fig. 4.1). Unlike a time-driven simulator, in an event-driven
                                                                           Scheduler:
    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.,
                                                      - Supervises simulation
    chronologically).1 In the next section, we will discuss the simulation concept of
Scheduler
    NS2. In Sections 4.2, 4.3, and 4.4, we will explain the details of classes Event
                                                      - Keep track of simulation (virtual) time
    and Handler, class Scheduler, and class Simulator, respectively. Finally, we
    summarize this chapter in Section 4.6.
                                                           - Insert/delete events
                          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 ïŹgure, Event1 creates
    and inserts Event5 after Event2 (the execution time of Event 5 is at 3.7 second).
                                                                                      www.ns2ultimate.com
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.,


      Example Implementation
           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
           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-

1. Prior to the simulation: Create 4 events
           tains execution time and a reference to the next event. In this ïŹgure, Event1 creates
           and inserts Event5 after Event2 (the execution time of Event 5 is at 3.7 second).




            1
                By execution, we mean taking actions associated with an event.


           T. Issariyakul, E. Hossain, Introduction to Network Simulator NS2,
           DOI: 10.1007/978-0-387-71760-9 4, c Springer Science+Business Media, LLC 2009




                                                                                               www.ns2ultimate.com
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.,


      Example Implementation
             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
             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-

1. Prior to the simulation: Create 4 events
             tains execution time and a reference to the next event. In this ïŹgure, Event1 creates
             and inserts Event5 after Event2 (the execution time of Event 5 is at 3.7 second).

2. Main loop: Go to the first event
    2.1 Execute the event
    2.2 Go to the next event
             1
                 By execution, we mean taking actions associated with an event.



    2.3 Go back to (2.1) until no more events are in the chain of
             T. Issariyakul, E. Hossain, Introduction to Network Simulator NS2,
             DOI: 10.1007/978-0-387-71760-9 4, c Springer Science+Business Media, LLC 2009


    events
                                                                                                www.ns2ultimate.com
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.,


      Example Implementation
           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
           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-
                                                           1. Prior to the simulation: Create 4 events
           tains execution time and a reference to the next event. In this ïŹgure, Event1 creates
           and inserts Event5 after Event2 (the execution 2. Main EventGo to the first event
                                                           time of loop: 5 is at 3.7 second).
                                                                        2.1 Execute the event
                                                                        2.2 Go to the next event
                                                                        2.3 Go back to (2.1) until no more events are in the
                                                                        chain of events
            1
                By execution, we mean taking actions associated with an event.
2.1.1. Event 1 induce Event 5 at t =3.7 s
           T. Issariyakul, E. Hossain, Introduction to Network Simulator NS2,

2.1.2 The scheduler moves to the next event (i.e., Event 2)
           DOI: 10.1007/978-0-387-71760-9 4, c Springer Science+Business Media, LLC 2009




                                                                                                   www.ns2ultimate.com
For more
  information about

                  Please see
                   this book
                from Springer


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

Weitere Àhnliche Inhalte

Mehr von Teerawat Issariyakul

Mehr von 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
 

KĂŒrzlich hochgeladen

Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
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
 
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
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
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
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
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
 

KĂŒrzlich hochgeladen (20)

Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
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
 
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
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
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
 

Event Driven Simulation: The Concept

  • 1. Event Driven Simulation: The Concept Ns2Ultimate.com by Teerawat Issariyakul October 2011
  • 2. Time Driven Simulation 12 1 Simulation of Computer Networks 2 4 a 6 time 0 3 b c 5 Fig. 1.3. Clock advancement in a time-driven simulation Stop and observer the system after FIXED INTERVAL (∆) Fig. 1.3 shows the basic idea behind time advancement in a time-driven simulation. The curved arrows represent such advances, and a, b, and c mark the occurrences of events. During the ïŹrst interval, no event occurs. Events (e.g, a, b,c) are assumed to The second interval contains event a, which is not handled until the end of the interval. happen at the end of each interval Time interval (∆) is an important parameter of time-driven simulation. While a large interval can lead to loss of information, a small interval can cause unnecessary waste of computational eïŹ€ort. Suppose, in Fig. 1.3, events Implementation using “for loop” b and c in the ïŹfth interval are packet arrival and departure events, respec- tively. Since these two events are considered to occur exactly at the end of the interval (i.e., at 5∆), the system state would be as if there is no packet www.ns2ultimate.com arrival or departure events during [4∆, 5∆]. This is considered a loss of in-
  • 3. Time Driven Simulation Implementation using for loop for t=0 to 100{ Execute the events } 12 1 Simulation of Computer Networks 2 4 a 6 time 0 3 b c 5 Fig. 1.3. Clock advancement in a time-driven simulation Fig. 1.3 shows the basic idea behind time advancement in www.ns2ultimate.com a time-driven
  • 4. ‱ At the execution, an event may induce one or more events. The induced events are stamped with the time when the event occurs, and again stored in the event list. The timestamp of the induced events must not be less than the simulation clock. This is to ensure that the simulation would Event Driven Simulation never go backward in time. ‱ An event-driven simulation starts with a set of initial events in the event list. It runs until the list is empty or another stopping criterion is satisïŹed. To the next event time 0 a b c Fig. 1.4. Clock advancement in an event-driven simulation Fig. 1.4 shows a graphical representation of event-driven simulation. Here, Move from one event to the next events a, b, and c are executed in order. The time gap between any pair of events is not ïŹxed. The simulation advances from one event to another, as opposed to one interval to another in time-driven simulation. In event-driven NOT every fixed interval simulation, programmers do not have to worry about optimizing time interval. Example 1.2 Program 1.4.2 shows the skeleton of a typical event-driven simulation program. Lines 1 and 2 initialize the system state variables and the event list, respectively. Line 3 speciïŹes a stopping criterion. Lines 4–6 are How do we implement it? executed as along as Line 3 returns true. Within this loop, the event whose timestamp is smallest is retrieved, executed, and removed from the list. Then, We can’t use the for loop! the simulation clock is set to the time associated with the retrieved event. 1.5 A Simulation Example: A Single-Channel Queuing System www.ns2ultimate.com
  • 5. 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 Event Driven Simulation 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., chronologically).1 In the next section, we will discuss the simulation concept of We can use pointers and create NS2. In Sections 4.2, 4.3, and 4.4, we will explain the details of classes Event 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 A Chain of Event 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 ïŹgure, Event1 creates and inserts Event5 after Event2 (the execution time of Event 5 is at 3.7 second). www.ns2ultimate.com
  • 6. Implementation of Discrete-Event Simulation in NS2 Characteristics of Event Driven Simulation An event has a pointer to the next event. 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 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 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- tains execution time and a reference to the next event. In this ïŹgure, Event1 creates and inserts Event5 after Event2 (the execution time of Event 5 is at 3.7 second). www.ns2ultimate.com
  • 7. Implementation of Discrete-Event Simulation in NS2 Characteristics of Event Driven Simulation An event has a pointer to the next event. 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 An event can induce new events (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., 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 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- tains execution time and a reference to the next event. In this ïŹgure, Event1 creates and inserts Event5 after Event2 (the execution time of Event 5 is at 3.7 second). www.ns2ultimate.com
  • 8. Implementation of Discrete-Event Simulation in NS2 Characteristics of Event Driven Simulation An event has a pointer to the next event. 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 An event can induce new events (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., chronologically).1 In the next section, we will discuss the simulation concept of by using the “insert event” instruction NS2. In Sections 4.2, 4.3, and 4.4, we will explain the details of classes Event 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- tains execution time and a reference to the next event. In this ïŹgure, Event1 creates and inserts Event5 after Event2 (the execution time of Event 5 is at 3.7 second). www.ns2ultimate.com
  • 9. Implementation of Discrete-Event Simulation in NS2 Main Components of Event Driven Simulation Events and Handlers 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 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 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- tains execution time and a reference to the next event. In this ïŹgure, Event1 creates and inserts Event5 after Event2 (the execution time of Event 5 is at 3.7 second). www.ns2ultimate.com
  • 10. Implementation of Discrete-Event Simulation in NS2 Main Components of Event Driven Simulation Events and Handlers 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 Simulation time line (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., 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 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- tains execution time and a reference to the next event. In this ïŹgure, Event1 creates and inserts Event5 after Event2 (the execution time of Event 5 is at 3.7 second). www.ns2ultimate.com
  • 11. Implementation of Discrete-Event Simulation in NS2 Main Components of Event Driven Simulation Events and Handlers 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 Simulation time line (e.g., that in Fig. 4.1). Unlike a time-driven simulator, in an event-driven Scheduler: 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., - Supervises simulation chronologically).1 In the next section, we will discuss the simulation concept of Scheduler NS2. In Sections 4.2, 4.3, and 4.4, we will explain the details of classes Event - Keep track of simulation (virtual) time and Handler, class Scheduler, and class Simulator, respectively. Finally, we summarize this chapter in Section 4.6. - Insert/delete events 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 ïŹgure, Event1 creates and inserts Event5 after Event2 (the execution time of Event 5 is at 3.7 second). www.ns2ultimate.com
  • 12. 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., Example Implementation 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 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- 1. Prior to the simulation: Create 4 events tains execution time and a reference to the next event. In this ïŹgure, Event1 creates and inserts Event5 after Event2 (the execution time of Event 5 is at 3.7 second). 1 By execution, we mean taking actions associated with an event. T. Issariyakul, E. Hossain, Introduction to Network Simulator NS2, DOI: 10.1007/978-0-387-71760-9 4, c Springer Science+Business Media, LLC 2009 www.ns2ultimate.com
  • 13. 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., Example Implementation 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 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- 1. Prior to the simulation: Create 4 events tains execution time and a reference to the next event. In this ïŹgure, Event1 creates and inserts Event5 after Event2 (the execution time of Event 5 is at 3.7 second). 2. Main loop: Go to the first event 2.1 Execute the event 2.2 Go to the next event 1 By execution, we mean taking actions associated with an event. 2.3 Go back to (2.1) until no more events are in the chain of T. Issariyakul, E. Hossain, Introduction to Network Simulator NS2, DOI: 10.1007/978-0-387-71760-9 4, c Springer Science+Business Media, LLC 2009 events www.ns2ultimate.com
  • 14. 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., Example Implementation 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 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- 1. Prior to the simulation: Create 4 events tains execution time and a reference to the next event. In this ïŹgure, Event1 creates and inserts Event5 after Event2 (the execution 2. Main EventGo to the first event time of loop: 5 is at 3.7 second). 2.1 Execute the event 2.2 Go to the next event 2.3 Go back to (2.1) until no more events are in the chain of events 1 By execution, we mean taking actions associated with an event. 2.1.1. Event 1 induce Event 5 at t =3.7 s T. Issariyakul, E. Hossain, Introduction to Network Simulator NS2, 2.1.2 The scheduler moves to the next event (i.e., Event 2) DOI: 10.1007/978-0-387-71760-9 4, c Springer Science+Business Media, LLC 2009 www.ns2ultimate.com
  • 15. For more information about Please see this book from Springer T. Issaraiyakul and E. Hossain, “Introduction to Network Simulator NS2”, Springer 2009 or visit www.ns2ultimate.com

Hinweis der Redaktion

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n