Event Driven Simulation: The Concept

8,984 views
8,845 views

Published on

Published in: Technology, Education
1 Comment
4 Likes
Statistics
Notes
No Downloads
Views
Total views
8,984
On SlideShare
0
From Embeds
0
Number of Embeds
3,933
Actions
Shares
0
Downloads
194
Comments
1
Likes
4
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Event Driven Simulation: The Concept

    1. 1. Event Driven Simulation: The Concept Ns2Ultimate.com by Teerawat Issariyakul October 2011
    2. 2. Time Driven Simulation12 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-drivensimulation. The curved arrows represent such advances, and a, b, and cmark the occurrences of events. During the first interval, no event occurs. Events (e.g, a, b,c) are assumed toThe second interval contains event a, which is not handled until the end ofthe 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 cancause unnecessary waste of computational effort. Suppose, in Fig. 1.3, events Implementation using “for loop”b and c in the fifth interval are packet arrival and departure events, respec-tively. Since these two events are considered to occur exactly at the end ofthe interval (i.e., at 5∆), the system state would be as if there is no packet www.ns2ultimate.comarrival or departure events during [4∆, 5∆]. This is considered a loss of in-
    3. 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. 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 wouldEvent 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 satisfied. 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 nextevents a, b, and c are executed in order. The time gap between any pair ofevents is not fixed. The simulation advances from one event to another, asopposed to one interval to another in time-driven simulation. In event-driven NOT every fixed intervalsimulation, programmers do not have to worry about optimizing time interval.Example 1.2 Program 1.4.2 shows the skeleton of a typical event-drivensimulation program. Lines 1 and 2 initialize the system state variables andthe event list, respectively. Line 3 specifies 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 whosetimestamp 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 QueuingSystem www.ns2ultimate.com
    5. 5. NS2 is a discrete-event simulator, where actions are associated with eventsrather than time. An event in a discrete-event simulator consists of executionEvent Driven Simulationtime, a set of actions, and a reference to the next event (Fig. 4.1). These eventsconnect 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-drivensimulator, time between a pair of events does not need to be constant. Whenthe 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 createNS2. In Sections 4.2, 4.3, and 4.4, we will explain the details of classes Eventand Handler, class Scheduler, and class Simulator, respectively. Finally, wesummarize 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 EventFig. 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 createsand inserts Event5 after Event2 (the execution time of Event 5 is at 3.7 second). www.ns2ultimate.com
    6. 6. Implementation of Discrete-Event Simulation in NS2 Characteristics of Event Driven SimulationAn 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 figure, Event1 creates and inserts Event5 after Event2 (the execution time of Event 5 is at 3.7 second). www.ns2ultimate.com
    7. 7. Implementation of Discrete-Event Simulation in NS2 Characteristics of Event Driven SimulationAn 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 timelineAn 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 figure, Event1 creates and inserts Event5 after Event2 (the execution time of Event 5 is at 3.7 second). www.ns2ultimate.com
    8. 8. Implementation of Discrete-Event Simulation in NS2 Characteristics of Event Driven SimulationAn 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 timelineAn 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 figure, Event1 creates and inserts Event5 after Event2 (the execution time of Event 5 is at 3.7 second). www.ns2ultimate.com
    9. 9. Implementation of Discrete-Event Simulation in NS2Main Components of Event Driven SimulationEvents 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 figure, Event1 creates and inserts Event5 after Event2 (the execution time of Event 5 is at 3.7 second). www.ns2ultimate.com
    10. 10. Implementation of Discrete-Event Simulation in NS2Main Components of Event Driven SimulationEvents 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 timelineSimulation 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 figure, Event1 creates and inserts Event5 after Event2 (the execution time of Event 5 is at 3.7 second). www.ns2ultimate.com
    11. 11. Implementation of Discrete-Event Simulation in NS2Main Components of Event Driven SimulationEvents 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 timelineSimulation 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 ofScheduler 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 figure, Event1 creates and inserts Event5 after Event2 (the execution time of Event 5 is at 3.7 second). www.ns2ultimate.com
    12. 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 figure, 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. 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 figure, 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. 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 figure, 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. 15. For more information about Please see this book from SpringerT. Issaraiyakul and E. Hossain, “Introduction to Network Simulator NS2”, Springer 2009or visit www.ns2ultimate.com

    ×