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

toaz.info-troubleshooting-lte-ran-nokia-pr_5a9f9e698001cd6b88c6d8628b5e7dc6.pdf
toaz.info-troubleshooting-lte-ran-nokia-pr_5a9f9e698001cd6b88c6d8628b5e7dc6.pdftoaz.info-troubleshooting-lte-ran-nokia-pr_5a9f9e698001cd6b88c6d8628b5e7dc6.pdf
toaz.info-troubleshooting-lte-ran-nokia-pr_5a9f9e698001cd6b88c6d8628b5e7dc6.pdf
sehat maruli
 

Tendances (12)

3GPP SON Series: Minimization of Drive Testing (MDT)
3GPP SON Series: Minimization of Drive Testing (MDT)3GPP SON Series: Minimization of Drive Testing (MDT)
3GPP SON Series: Minimization of Drive Testing (MDT)
 
Deploying deep learning models with Docker and Kubernetes
Deploying deep learning models with Docker and KubernetesDeploying deep learning models with Docker and Kubernetes
Deploying deep learning models with Docker and Kubernetes
 
Data hiding using image interpolation
Data hiding using image interpolationData hiding using image interpolation
Data hiding using image interpolation
 
Hsdpa principles
Hsdpa principlesHsdpa principles
Hsdpa principles
 
FreeRTOS
FreeRTOSFreeRTOS
FreeRTOS
 
[데브루키] Color space gamma correction
[데브루키] Color space gamma correction[데브루키] Color space gamma correction
[데브루키] Color space gamma correction
 
Rach procedure in lte
Rach procedure in lteRach procedure in lte
Rach procedure in lte
 
Lte throughput
Lte throughputLte throughput
Lte throughput
 
Mini project title prime number generator
Mini project title prime number generatorMini project title prime number generator
Mini project title prime number generator
 
toaz.info-troubleshooting-lte-ran-nokia-pr_5a9f9e698001cd6b88c6d8628b5e7dc6.pdf
toaz.info-troubleshooting-lte-ran-nokia-pr_5a9f9e698001cd6b88c6d8628b5e7dc6.pdftoaz.info-troubleshooting-lte-ran-nokia-pr_5a9f9e698001cd6b88c6d8628b5e7dc6.pdf
toaz.info-troubleshooting-lte-ran-nokia-pr_5a9f9e698001cd6b88c6d8628b5e7dc6.pdf
 
Best,worst,average case .17581556 045
Best,worst,average case .17581556 045Best,worst,average case .17581556 045
Best,worst,average case .17581556 045
 
Springer link 이용매뉴얼
Springer link 이용매뉴얼Springer link 이용매뉴얼
Springer link 이용매뉴얼
 

Similaire à NS2: Events and Handlers

Event and signal driven programming
Event and signal driven programmingEvent and signal driven programming
Event and signal driven programming
Elizabeth Smith
 
The Power Of Event Chapter 7
The Power Of Event Chapter 7The Power Of Event Chapter 7
The Power Of Event Chapter 7
Woojin 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 2012
Elizabeth Smith
 
【第一季第二期】Dive into javascript event
【第一季第二期】Dive into javascript event【第一季第二期】Dive into javascript event
【第一季第二期】Dive into javascript event
tbosstraining
 
Foundations and methods of stochastic simulation
Foundations and methods of stochastic simulationFoundations and methods of stochastic simulation
Foundations and methods of stochastic simulation
Springer
 
The Power Of Event Chapter 5
The Power Of Event Chapter 5The Power Of Event Chapter 5
The Power Of Event Chapter 5
Woojin Joe
 
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
dickonsondorris
 

Similaire à NS2: Events and Handlers (20)

NS2--Event Scheduler
NS2--Event SchedulerNS2--Event Scheduler
NS2--Event Scheduler
 
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
 

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

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Dernier (20)

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
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
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
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
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
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptx
 
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 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
 
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...
 

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