SlideShare une entreprise Scribd logo
1  sur  17
Events and Handlers

     Ns2Ultimate.com
            by
    Teerawat Issariyakul


       October 2011
Events
Dictionary: A thing that happens
NS2: A thing which we are interested in
simulation
NS2 has two types of events
1. Packet reception event
2. At event: T execution
              cl

                                 www.ns2ultimate.com
When NS2 Uses Events
Things to happen in future
    Packet reception event at future time
    At event: T execution in future
               cl
Examples:
    A packet will arrive at 0.9 sec.
    Execute “$ftp start” at 6.8 sec.

       $ns at 0.05 “$ftp start”
       $ns at 60.0 “$ftp stop”
       $ns 61 “finish”
                                            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
  time, a set of actions, and a reference to the next event (Fig. 4.1). These events

            Chain of 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
NS2 lines up events in a sequential manner
  and Handler, class Scheduler, and class Simulator, respectively. Finally, we
  summarize this chapter in Section 4.6.
(like a chain)
                        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

At run time, it executes discrete-event in the chain con-
 Fig. 4.1. A sample chain of events in a events simulation. Each event
  tains execution time and a reference to the next event. In this figure, Event1 creates
one by one, sequentially
  and inserts Event5 after Event2 (the execution time of Event 5 is at 3.7 second).




                                                                       www.ns2ultimate.com
(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: Chain of Events
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          Packet
                                     Event5
        create
        event
                      event
                                   time 1 3.7
                                         =
                                      departs
                                     Action5

     Event1
      Packet       Event2
                    Packet                       Event3             Event4
                                                                     Packet
   time 1= 0.9   time 2 2.2
                       =                        time “…”
                                                  print = 5       time 3 6.8
                                                                        =
      arrives
     Action1        arrives
                   Action2                      Action3              arrives
                                                                    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
What Do You Do
when you see an
   EVENT?
YouTake ACTIONS!
     using
  “HANDLER”
Events and Handlers

                           Event             Handler

    Indicate          What happened         What to do

                  - Pointer to the next
                  event                   Default actions
Main components - Pointer to the handler to do when the
                  - Time when the event    event occurs
                  occurs



                                              www.ns2ultimate.com
Classes Event and Handler
//~/ns/common/scheduler.h
class Event {
public:
     Event* next_;        /* a pointer to the next event*/
     Event* prev_;        /* a pointer to the previous event*/
     Handler* handler_;   /* handler which contains associated action */
     double time_;        /* time at which event is execute */
     scheduler_uid_t uid_;    /* unique ID of the event */
     Event() : time_(0), uid_(0) {}
};


//~/ns/common/scheduler.h
class Handler {
public:
     virtual ~Handler () {}
     virtual void handle(Event* e) = 0; /* default action is defined
                                           here */
};


                                                                 www.ns2ultimate.com
Class Event
Class Event has 4 main variables
- next_: A pointer to the next event	
- handler_: A pointer to the Handler
- time_: Time 	 	   	
- uid_: Unique ID
Class Handler defines the default action
associated wit the event in its function handle(e)

                                         www.ns2ultimate.com
Event and Handler
handler    handle(){        handle(){     handler
             <actions>        <actions>
           }                }




          handler_ next_   handler_   next_


event        uid_ time_       uid_ time_      event




                                          www.ns2ultimate.com
Handler
 What kind of actions?
//~/ns/common/scheduler.h
class Handler {
public:
     virtual ~Handler () {}   Pure virtual function
     virtual void handle(Event* e) = 0; /* default action is defined
                                           here */
};


 Default action
      -   Pure virtual
      -   T be defined in the derived classes
           o


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


                  NS2 Hierarchy
Chapter 15.

5.1.2 C++ Class Hierarchy

This section gives an overview of C++ class hierarchies. The entire hierarchy
consistsClass 100 C++ classes thestruct data types. of all Network
        of over Handler is and based class Here, we only show
a part of the hierarchy (in Fig. 5.1). The readers are referred to [18] for the
complete class Object, e.g., queue, agent, link delay.
               hierarchy.


                  OTcl Interface                                     Default Action


                                  TclObject                Handler



     Simulator                PacketQueue      NsObject      AtHandler       QueueHandler

           RoutingModule
                                                      Network Component


                 Classifier                    Connector                    LanRouter


                          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
Chapter 15.

             5.1.2 C++ Class Hierarchy


                   NS2 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
             complete class hierarchy.


                                OTcl Interface                                     Default Action


                                                TclObject                Handler



                   Simulator                PacketQueue      NsObject      AtHandler       QueueHandler

                         RoutingModule
                                                                    Network Component
  Let’s focus on
class NsObject (all            Classifier                    Connector                    LanRouter


network objects)                        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
NsObject
So the default action (i.e., function handle(e)) is
also defined here:
              //~/ns/common/object.cc
              void NsObject::handle(Event* e)
              {
                  recv((Packet*)e);
              }


  -   Take a pointer to a packet as an input
  -   Default action = receive the packet.
  -   See [ here ] for the details of packet reception

                                                www.ns2ultimate.com
Next Step?

Let’s talk about how NS2 form a chain of
          events ➠ Scheduler



         (In The Next Post)
For more
         information
          about NS2
                  Please see
                   this book
                 from Springer



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

Contenu connexe

Tendances

Tuning android for low ram devices
Tuning android for low ram devicesTuning android for low ram devices
Tuning android for low ram devicesDroidcon Berlin
 
User Story as UX Method
User Story as UX MethodUser Story as UX Method
User Story as UX MethodПрофсоUX
 
Asynchronous Programming FTW! 2 (with AnyEvent)
Asynchronous Programming FTW! 2 (with AnyEvent)Asynchronous Programming FTW! 2 (with AnyEvent)
Asynchronous Programming FTW! 2 (with AnyEvent)xSawyer
 
Kanban in 4 easy steps
Kanban in 4 easy steps Kanban in 4 easy steps
Kanban in 4 easy steps Shore Labs
 
Forense memoria windows_sandro_suffert_2009_2010
Forense memoria windows_sandro_suffert_2009_2010Forense memoria windows_sandro_suffert_2009_2010
Forense memoria windows_sandro_suffert_2009_2010Sandro Suffert
 
Project ACRN Device Passthrough Introduction
Project ACRN Device Passthrough IntroductionProject ACRN Device Passthrough Introduction
Project ACRN Device Passthrough IntroductionProject ACRN
 
Scrum metodología ágil para tus proyectos
Scrum metodología ágil para tus proyectosScrum metodología ágil para tus proyectos
Scrum metodología ágil para tus proyectosBarCamp Cochabamba
 
Reconnaissance of Virtio: What’s new and how it’s all connected?
Reconnaissance of Virtio: What’s new and how it’s all connected?Reconnaissance of Virtio: What’s new and how it’s all connected?
Reconnaissance of Virtio: What’s new and how it’s all connected?Samsung Open Source Group
 
Taylor Wicksell and Tom Gianos at SpringOne Platform 2019
Taylor Wicksell and Tom Gianos at SpringOne Platform 2019Taylor Wicksell and Tom Gianos at SpringOne Platform 2019
Taylor Wicksell and Tom Gianos at SpringOne Platform 2019VMware Tanzu
 
Project ACRN Device Model architecture introduction
Project ACRN Device Model architecture introductionProject ACRN Device Model architecture introduction
Project ACRN Device Model architecture introductionProject ACRN
 
Function Level Analysis of Linux NVMe Driver
Function Level Analysis of Linux NVMe DriverFunction Level Analysis of Linux NVMe Driver
Function Level Analysis of Linux NVMe Driver인구 강
 
Cpu scheduling
Cpu schedulingCpu scheduling
Cpu schedulingpiku das
 
Working With Legacy Code
Working With Legacy CodeWorking With Legacy Code
Working With Legacy CodeAndrea Polci
 
Case Study on agile scrum methodology on shopping cart
Case Study on agile scrum methodology on shopping cartCase Study on agile scrum methodology on shopping cart
Case Study on agile scrum methodology on shopping cartAbdullah Raza
 

Tendances (20)

Tuning android for low ram devices
Tuning android for low ram devicesTuning android for low ram devices
Tuning android for low ram devices
 
An Introduction to kanban
An Introduction to kanbanAn Introduction to kanban
An Introduction to kanban
 
User Story as UX Method
User Story as UX MethodUser Story as UX Method
User Story as UX Method
 
Kanban Basics
Kanban BasicsKanban Basics
Kanban Basics
 
Asynchronous Programming FTW! 2 (with AnyEvent)
Asynchronous Programming FTW! 2 (with AnyEvent)Asynchronous Programming FTW! 2 (with AnyEvent)
Asynchronous Programming FTW! 2 (with AnyEvent)
 
Kanban in 4 easy steps
Kanban in 4 easy steps Kanban in 4 easy steps
Kanban in 4 easy steps
 
Forense memoria windows_sandro_suffert_2009_2010
Forense memoria windows_sandro_suffert_2009_2010Forense memoria windows_sandro_suffert_2009_2010
Forense memoria windows_sandro_suffert_2009_2010
 
Project ACRN Device Passthrough Introduction
Project ACRN Device Passthrough IntroductionProject ACRN Device Passthrough Introduction
Project ACRN Device Passthrough Introduction
 
Scrum metodología ágil para tus proyectos
Scrum metodología ágil para tus proyectosScrum metodología ágil para tus proyectos
Scrum metodología ágil para tus proyectos
 
Linux scheduler
Linux schedulerLinux scheduler
Linux scheduler
 
Reconnaissance of Virtio: What’s new and how it’s all connected?
Reconnaissance of Virtio: What’s new and how it’s all connected?Reconnaissance of Virtio: What’s new and how it’s all connected?
Reconnaissance of Virtio: What’s new and how it’s all connected?
 
Taylor Wicksell and Tom Gianos at SpringOne Platform 2019
Taylor Wicksell and Tom Gianos at SpringOne Platform 2019Taylor Wicksell and Tom Gianos at SpringOne Platform 2019
Taylor Wicksell and Tom Gianos at SpringOne Platform 2019
 
Project ACRN Device Model architecture introduction
Project ACRN Device Model architecture introductionProject ACRN Device Model architecture introduction
Project ACRN Device Model architecture introduction
 
Function Level Analysis of Linux NVMe Driver
Function Level Analysis of Linux NVMe DriverFunction Level Analysis of Linux NVMe Driver
Function Level Analysis of Linux NVMe Driver
 
Cpu scheduling
Cpu schedulingCpu scheduling
Cpu scheduling
 
Working With Legacy Code
Working With Legacy CodeWorking With Legacy Code
Working With Legacy Code
 
Virtual memory
Virtual memoryVirtual memory
Virtual memory
 
Case Study on agile scrum methodology on shopping cart
Case Study on agile scrum methodology on shopping cartCase Study on agile scrum methodology on shopping cart
Case Study on agile scrum methodology on shopping cart
 
Building Custom PHP Extensions
Building Custom PHP ExtensionsBuilding Custom PHP Extensions
Building Custom PHP Extensions
 
Semaphore
SemaphoreSemaphore
Semaphore
 

Similaire à NS2: Events and Handlers

Node.js Event Loop & EventEmitter
Node.js Event Loop & EventEmitterNode.js Event Loop & EventEmitter
Node.js Event Loop & EventEmitterSimen Li
 
360|Flex Greenthreading In Flex
360|Flex Greenthreading In Flex360|Flex Greenthreading In Flex
360|Flex Greenthreading In FlexHuyen Tue Dao
 
Event and signal driven programming
Event and signal driven programmingEvent and signal driven programming
Event and signal driven programmingElizabeth Smith
 
Anatomy of an action
Anatomy of an actionAnatomy of an action
Anatomy of an actionGordon Chung
 
The Power Of Event Chapter 7
The Power Of Event Chapter 7The Power Of Event Chapter 7
The Power Of Event Chapter 7Woojin Joe
 
Event and Signal Driven Programming Zendcon 2012
Event and Signal Driven Programming Zendcon 2012Event and Signal Driven Programming Zendcon 2012
Event and Signal Driven Programming Zendcon 2012Elizabeth Smith
 
【第一季第二期】Dive into javascript event
【第一季第二期】Dive into javascript event【第一季第二期】Dive into javascript event
【第一季第二期】Dive into javascript eventtbosstraining
 
Foundations and methods of stochastic simulation
Foundations and methods of stochastic simulationFoundations and methods of stochastic simulation
Foundations and methods of stochastic simulationSpringer
 
The Power Of Event Chapter 5
The Power Of Event Chapter 5The Power Of Event Chapter 5
The Power Of Event Chapter 5Woojin Joe
 
Dive into javascript event
Dive into javascript eventDive into javascript event
Dive into javascript eventGoddy Zhao
 
Bucks County Tech Meetup: node.js introduction
Bucks County Tech Meetup: node.js introductionBucks County Tech Meetup: node.js introduction
Bucks County Tech Meetup: node.js introductiondshkolnikov
 
20051019 automating regression testing for evolving gui software
20051019 automating regression testing for evolving gui software20051019 automating regression testing for evolving gui software
20051019 automating regression testing for evolving gui softwareWill Shen
 
Unit 2 Modeling of Programs A function maps inputs to out.docx
Unit 2 Modeling of Programs A function maps inputs to out.docxUnit 2 Modeling of Programs A function maps inputs to out.docx
Unit 2 Modeling of Programs A function maps inputs to out.docxdickonsondorris
 
«Gevent — быть или не быть?» Александр Мокров, Positive Technologies
«Gevent — быть или не быть?» Александр Мокров, Positive Technologies«Gevent — быть или не быть?» Александр Мокров, Positive Technologies
«Gevent — быть или не быть?» Александр Мокров, Positive Technologiesit-people
 
Fine grain process control 2nd nov
Fine grain process control 2nd novFine grain process control 2nd nov
Fine grain process control 2nd novSurendraGangarapu1
 
Running a Scalable And Reliable Symfony2 Application in Cloud (Symfony Sweden...
Running a Scalable And Reliable Symfony2 Application in Cloud (Symfony Sweden...Running a Scalable And Reliable Symfony2 Application in Cloud (Symfony Sweden...
Running a Scalable And Reliable Symfony2 Application in Cloud (Symfony Sweden...Ville Mattila
 

Similaire à NS2: Events and Handlers (20)

Dynamic UID
Dynamic UIDDynamic UID
Dynamic UID
 
Node.js Event Loop & EventEmitter
Node.js Event Loop & EventEmitterNode.js Event Loop & EventEmitter
Node.js Event Loop & EventEmitter
 
360|Flex Greenthreading In Flex
360|Flex Greenthreading In Flex360|Flex Greenthreading In Flex
360|Flex Greenthreading In Flex
 
Event and signal driven programming
Event and signal driven programmingEvent and signal driven programming
Event and signal driven programming
 
Anatomy of an action
Anatomy of an actionAnatomy of an action
Anatomy of an action
 
The Power Of Event Chapter 7
The Power Of Event Chapter 7The Power Of Event Chapter 7
The Power Of Event Chapter 7
 
Event and Signal Driven Programming Zendcon 2012
Event and Signal Driven Programming Zendcon 2012Event and Signal Driven Programming Zendcon 2012
Event and Signal Driven Programming Zendcon 2012
 
JavaScript for real men
JavaScript for real menJavaScript for real men
JavaScript for real men
 
【第一季第二期】Dive into javascript event
【第一季第二期】Dive into javascript event【第一季第二期】Dive into javascript event
【第一季第二期】Dive into javascript event
 
Foundations and methods of stochastic simulation
Foundations and methods of stochastic simulationFoundations and methods of stochastic simulation
Foundations and methods of stochastic simulation
 
The Power Of Event Chapter 5
The Power Of Event Chapter 5The Power Of Event Chapter 5
The Power Of Event Chapter 5
 
Dive into javascript event
Dive into javascript eventDive into javascript event
Dive into javascript event
 
Bucks County Tech Meetup: node.js introduction
Bucks County Tech Meetup: node.js introductionBucks County Tech Meetup: node.js introduction
Bucks County Tech Meetup: node.js introduction
 
20051019 automating regression testing for evolving gui software
20051019 automating regression testing for evolving gui software20051019 automating regression testing for evolving gui software
20051019 automating regression testing for evolving gui software
 
Unit 2 Modeling of Programs A function maps inputs to out.docx
Unit 2 Modeling of Programs A function maps inputs to out.docxUnit 2 Modeling of Programs A function maps inputs to out.docx
Unit 2 Modeling of Programs A function maps inputs to out.docx
 
Ns2 by khan
Ns2 by khan Ns2 by khan
Ns2 by khan
 
Gevent be or not to be
Gevent be or not to beGevent be or not to be
Gevent be or not to be
 
«Gevent — быть или не быть?» Александр Мокров, Positive Technologies
«Gevent — быть или не быть?» Александр Мокров, Positive Technologies«Gevent — быть или не быть?» Александр Мокров, Positive Technologies
«Gevent — быть или не быть?» Александр Мокров, Positive Technologies
 
Fine grain process control 2nd nov
Fine grain process control 2nd novFine grain process control 2nd nov
Fine grain process control 2nd nov
 
Running a Scalable And Reliable Symfony2 Application in Cloud (Symfony Sweden...
Running a Scalable And Reliable Symfony2 Application in Cloud (Symfony Sweden...Running a Scalable And Reliable Symfony2 Application in Cloud (Symfony Sweden...
Running a Scalable And Reliable Symfony2 Application in Cloud (Symfony Sweden...
 

Plus de Teerawat Issariyakul

Plus de Teerawat Issariyakul (12)

Trump-Style Negotiation: Powerful Strategies and Tactics for Mastering Every ...
Trump-Style Negotiation: Powerful Strategies and Tactics for Mastering Every ...Trump-Style Negotiation: Powerful Strategies and Tactics for Mastering Every ...
Trump-Style Negotiation: Powerful Strategies and Tactics for Mastering Every ...
 
Intelligent entrepreneurs by Bill Murphy Jr.
Intelligent entrepreneurs by Bill Murphy Jr.Intelligent entrepreneurs by Bill Murphy Jr.
Intelligent entrepreneurs by Bill Murphy Jr.
 
20111126 ns2 installation
20111126 ns2 installation20111126 ns2 installation
20111126 ns2 installation
 
20111107 ns2-required cygwinpkg
20111107 ns2-required cygwinpkg20111107 ns2-required cygwinpkg
20111107 ns2-required cygwinpkg
 
packet destruction in NS2
packet destruction in NS2packet destruction in NS2
packet destruction in NS2
 
Basic Packet Forwarding in NS2
Basic Packet Forwarding in NS2Basic Packet Forwarding in NS2
Basic Packet Forwarding in NS2
 
NS2 Object Construction
NS2 Object ConstructionNS2 Object Construction
NS2 Object Construction
 
NS2 Shadow Object Construction
NS2 Shadow Object ConstructionNS2 Shadow Object Construction
NS2 Shadow Object Construction
 
20100712-OTcl Command -- Getting Started
20100712-OTcl Command -- Getting Started20100712-OTcl Command -- Getting Started
20100712-OTcl Command -- Getting Started
 
NS2: Binding C++ and OTcl variables
NS2: Binding C++ and OTcl variablesNS2: Binding C++ and OTcl variables
NS2: Binding C++ and OTcl variables
 
NS2 Classifiers
NS2 ClassifiersNS2 Classifiers
NS2 Classifiers
 
Ns-2.35 Installation
Ns-2.35 InstallationNs-2.35 Installation
Ns-2.35 Installation
 

Dernier

How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxcallscotland1987
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdfssuserdda66b
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 

Dernier (20)

How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 

NS2: Events and Handlers

  • 1. Events and Handlers Ns2Ultimate.com by Teerawat Issariyakul October 2011
  • 2. Events Dictionary: A thing that happens NS2: A thing which we are interested in simulation NS2 has two types of events 1. Packet reception event 2. At event: T execution cl www.ns2ultimate.com
  • 3. When NS2 Uses Events Things to happen in future Packet reception event at future time At event: T execution in future cl Examples: A packet will arrive at 0.9 sec. Execute “$ftp start” at 6.8 sec. $ns at 0.05 “$ftp start” $ns at 60.0 “$ftp stop” $ns 61 “finish” www.ns2ultimate.com
  • 4. 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 Chain of 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 NS2 lines up events in a sequential manner and Handler, class Scheduler, and class Simulator, respectively. Finally, we summarize this chapter in Section 4.6. (like a chain) 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 At run time, it executes discrete-event in the chain con- Fig. 4.1. A sample chain of events in a events simulation. Each event tains execution time and a reference to the next event. In this figure, Event1 creates one by one, sequentially and inserts Event5 after Event2 (the execution time of Event 5 is at 3.7 second). www.ns2ultimate.com
  • 5. (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: Chain of Events 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 Packet Event5 create event event time 1 3.7 = departs Action5 Event1 Packet Event2 Packet Event3 Event4 Packet time 1= 0.9 time 2 2.2 = time “…” print = 5 time 3 6.8 = arrives Action1 arrives Action2 Action3 arrives 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
  • 6. What Do You Do when you see an EVENT?
  • 7. YouTake ACTIONS! using “HANDLER”
  • 8. Events and Handlers Event Handler Indicate What happened What to do - Pointer to the next event Default actions Main components - Pointer to the handler to do when the - Time when the event event occurs occurs www.ns2ultimate.com
  • 9. Classes Event and Handler //~/ns/common/scheduler.h class Event { public: Event* next_; /* a pointer to the next event*/ Event* prev_; /* a pointer to the previous event*/ Handler* handler_; /* handler which contains associated action */ double time_; /* time at which event is execute */ scheduler_uid_t uid_; /* unique ID of the event */ Event() : time_(0), uid_(0) {} }; //~/ns/common/scheduler.h class Handler { public: virtual ~Handler () {} virtual void handle(Event* e) = 0; /* default action is defined here */ }; www.ns2ultimate.com
  • 10. Class Event Class Event has 4 main variables - next_: A pointer to the next event - handler_: A pointer to the Handler - time_: Time - uid_: Unique ID Class Handler defines the default action associated wit the event in its function handle(e) www.ns2ultimate.com
  • 11. Event and Handler handler handle(){ handle(){ handler <actions> <actions> } } handler_ next_ handler_ next_ event uid_ time_ uid_ time_ event www.ns2ultimate.com
  • 12. Handler What kind of actions? //~/ns/common/scheduler.h class Handler { public: virtual ~Handler () {} Pure virtual function virtual void handle(Event* e) = 0; /* default action is defined here */ }; Default action - Pure virtual - T be defined in the derived classes o www.ns2ultimate.com
  • 13. 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 NS2 Hierarchy Chapter 15. 5.1.2 C++ Class Hierarchy This section gives an overview of C++ class hierarchies. The entire hierarchy consistsClass 100 C++ classes thestruct data types. of all Network of over Handler is and based class Here, we only show a part of the hierarchy (in Fig. 5.1). The readers are referred to [18] for the complete class Object, e.g., queue, agent, link delay. hierarchy. OTcl Interface Default Action TclObject Handler Simulator PacketQueue NsObject AtHandler QueueHandler RoutingModule Network Component Classifier Connector LanRouter 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
  • 14. Chapter 15. 5.1.2 C++ Class Hierarchy NS2 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 complete class hierarchy. OTcl Interface Default Action TclObject Handler Simulator PacketQueue NsObject AtHandler QueueHandler RoutingModule Network Component Let’s focus on class NsObject (all Classifier Connector LanRouter network objects) 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
  • 15. NsObject So the default action (i.e., function handle(e)) is also defined here: //~/ns/common/object.cc void NsObject::handle(Event* e) { recv((Packet*)e); } - Take a pointer to a packet as an input - Default action = receive the packet. - See [ here ] for the details of packet reception www.ns2ultimate.com
  • 16. Next Step? Let’s talk about how NS2 form a chain of events ➠ Scheduler (In The Next Post)
  • 17. For more information about NS2 Please see this book from Springer T. Issaraiyakul and E. Hossain, “Introduction to Network Simulator NS2”, Springer 2009 or visit www.ns2ultimate.com

Notes de l'éditeur

  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
  16. \n
  17. \n