SlideShare a Scribd company logo
1 of 26
Dynamic of Unique ID

      Ns2Ultimate.com
             by
     Teerawat Issariyakul


        January 2011
Recap
NS2 is a discrete-event simulator, where actions are associated with events
rather than time. An event in a discrete-event simulator consists of execution
time, a set of actions, and a reference to the next event (Fig. 4.1). These events
connect to each other and form a chain of events on the simulation timeline
Schedule = Put an event on the simulation
(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
time line
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
Dispatch = Execute the 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
Recap
• Attributes of Event
     handler    handle(){        handle(){     handler
                  <actions>        <actions>
                }                }




               handler_ next_   handler_   next_


      event       uid_ time_       uid_ time_      event




   How do we assign a unique ID (i.e., uid_) to the event?


                                                       www.ns2ultimate.com
Recap
• Attributes of Event
     handler    handle(){        handle(){     handler
                  <actions>        <actions>
                }                }




               handler_ next_   handler_   next_


      event       uid_ time_       uid_ time_      event




                       Using the Scheduler


                                                       www.ns2ultimate.com
Recap: Function schedule(h,e,delay)

Put an event *e on the timeline at “delay”second in
future, and associated the event with a handler “*h”.
                  Scheduler s& = Scheduler::instance();
                  s.schedule(h,e,delay);
      Call here                h                 e

                                    associated
                          Handler                Event

                               Delay
                  x
          current time

                                                     www.ns2ultimate.com
Recap: Function schedule(h,e,delay)
//~ns/common/scheduler.cc

void Scheduler::schedule(Handler* h, Event* e, double delay)
{

    < CHECKING FOR ERRORS >

    e->uid_ = uid_++;
    e->handler_ = h;              1. Increment the local variable uid_
    double t = clock_ + delay;    2. Assigned the incremented value
    e->time_ = t;
                                    as the unique ID of the event
    insert(e);
}

                 Scheduler                    Event
                              assign to
                 uid_                             uid_


                                                         www.ns2ultimate.com
So, NS2 has two type of unique
  IDs: Global Unique ID and
            Event
T T
    wo ypes of UID
Global UID
  The variable uid_ of the Scheduler
  One and only one for a simulation
Event UID or Local UID
  The variable uid_ of an event
  Every event has its own uid_

                                 www.ns2ultimate.com
Global UID and Event UID
Simulation: In function Schedule(…)
                                   Event
                                            Event UID:
                   assign to         uid_
                                            - Unique to each
   Scheduler                                event
   uid_            assign to       Event
                                     uid_   - Many events in
                       assign to            a simulation ➠
                                   Event    Many local UID
    Global UID:                      uid_   in a simulation

     Unique to the
      simulation


                                                    www.ns2ultimate.com
Global UID and Event UID
Simulation: In function Schedule(…)
                                        //~ns/common/scheduler.cc
                               Event
                                 uid_   void Scheduler::schedule
               assign to
                                        (Handler* h, Event* e,
   Scheduler                            double delay){

   uid_        assign to       Event        Event UID is always a
                                 uid_      positive new number
                                          ...
                   assign to              e->uid_ = uid_++;
                                          e->handler_ = h;
                               Event      double t = clock_ +
                                 uid_   delay;
                                          e->time_ = t;

                                            insert(e);
                                        }

                                                         www.ns2ultimate.com
Event UID
Simulation: In function dispatch(…)
         Event
     x     uid_              //~ns/common/scheduler.cc
                             void Scheduler::dispatch(Event*
                             p, double t){
                 Reversing
                                 clock_ = t;
                 the sign
                                 p->uid_ = -p->uid_;

                                 p->handler_->handle(p);
     Event
                             }
    -x    uid_



                                                       www.ns2ultimate.com
84
              Dynamic of Event UID
       4 Implementation of Discrete-Event Simulation in NS2

schedule(...) and dispatch(...) functions. The sign toggling mechanism
of unique ID ensures that events will be scheduled and dispatched properly. If
a scheduled UIDis nota certain event changes its value like
         A event of dispatched, or is dispatched twice, its unique ID will
be positive, and an attempt to schedule this undispatched event will cause an
         this           (a positive
error (Lines 5 and 6 in Program 4.7).
                          new value)




                     –2


                             (reversing
Fig. 4.2. Dynamics of Event unique ID (uid) : Take a positive value from
                            the sign)
Scheduler::uid when being scheduled, and invert the sign when being dispatched.
Increment upon schedule and inversion of sign upon dispatch.
                                                                    www.ns2ultimate.com
T key questions
 wo


1. Why is the “event UID” changes its value
  like this?
2. What if the dynamic is different?




                                       www.ns2ultimate.com
Dynamic of Event UID

It is a UID protection mechanism.
But before going further, let’s ask
another basic question:


            WHAT IS AN EVENT?



                                      www.ns2ultimate.com
EVENTS
        NS2 has several type of events
        Let’s focus on packet reception events

                                 Event



       ...       AtEvent                       Packet        ...
                                Packet reception events
Source: http://www-rp.lip6.fr/ns-doc/ns226-doc/html/hierarchy.htm

                                                           www.ns2ultimate.com
Packet Reception Event
                 Packet

                  uid_
Time where the
  packet is      time_
   received
                 handler_
                            a pointer to
                              node 2

     Node 1                            Node 2


                                       www.ns2ultimate.com
Packet Event Reuse
One packet could be passed among
several Nodes

          Event/
          Packet

         2 uid_
           time_

           handler_



Node 1                Node 2     Node 3

                               www.ns2ultimate.com
Packet Event Reuse
NS2 does not create a new event every time it forwards a
packet.
It
     Changes the event UID, and
     passes the same packet to the next object
                                         Event/
                                         Packet

                                       6 uid_
                                          time_

                                          handler_


 Node 1                   Node 2                       Node 3

                                                     www.ns2ultimate.com
An example of packet forwarding
                                                  time
                0                    5.1
2
    Instance 1:
                             Event/          Event/
     A packet with UID       Packet          Packet
     “2” is scheduled to
                            2 uid_         6 uid_
     arrived at Node 2 at
                            1.2 time_      5.1 time_
     “0” s.
                               handler_       handler_




          Node 1             Node 2          Node 3

                                           www.ns2ultimate.com
An example of packet forwarding
                                               time
          1.2               5.1
2
                Instance 2:               Event/
                                          Packet
                 A packet with UID
                 “6” is scheduled to    6 uid_
                 arrived at Node 3 at   5.1 time_
                 “5.1” s.                  handler_




     Node 1           Node 2              Node 3

                                        www.ns2ultimate.com
84     4 Implementation of Discrete-Event Simulation in NS2
     An example of packetThe sign toggling mechanism
     schedule(...) and dispatch(...) functions.
                                                forwarding
     of unique ID ensures that events will be scheduled and dispatched properly. If
     a scheduled event is not dispatched, or is dispatched twice, its unique ID will
     be positive, and an attempt to schedule this undispatched event will cause an
     error (Lines 5 and 6 in Program 4.7).




                          –2


         t=0:
    Fig. 4.2. Dynamics of Event unique ID (uid) : Take a positive value from
  NS2 schedules being scheduled, and invert the sign when being dispatched.
    Scheduler::uid when                    t=1.2:
packet reception at and inversion of sign upon dispatch.
    Increment upon schedule        packet is received
  node 2 at 1.2 s                       at node 2
     4.3.6 Scheduling-Dispatching Mechanism
                                                                   www.ns2ultimate.com
84     4 Implementation of Discrete-Event Simulation in NS2
 An example of packetThe sign toggling mechanism
 schedule(...) and dispatch(...) functions.
                                            forwarding
  of unique ID ensures that events will be scheduled and dispatched properly. If
  a scheduled event is not dispatched, or already decided at “t=5” that
                                 We’ve is dispatched twice, its unique ID will
  be positive, and an attempt to schedule this undispatched event will cause an
                                the packet will be received at “t=5.1”.
  error (Lines 5 and 6 in Program 4.7).
                                    So nothing can happen here.




                       –2

          t=5:
   NS2 schedules                                                 t=5.1:
 Fig. 4.2. Dynamics of Event unique ID (uid) : Take a positive value from
packet reception being scheduled, and invert the signpacket is received
 Scheduler::uid when
                       atand inversion of sign upon dispatch. being dispatched.
 Increment upon schedule
                                                         when

   node 3 at 5.1 s                                            at node 3
  4.3.6 Scheduling-Dispatching Mechanism
                                                                www.ns2ultimate.com
An example of packet forwarding
                 We’ve already decided at “t=5” that
                 the packet will be received at “t=5.1”.
                    So nothing can happen here.


                     HOW DO WE KNOW THAT
                    NOTHING WILL HAPPEN AT
                         THESE PERIODS?
    WE USE

“THE SIGN”
  OF EVENT UID
                                         www.ns2ultimate.com
The Sign of the Event UID
 Positive (+):
     The event is scheduled but not yet dispatched
     Do not reschedule here. Otherwise, you will see the
     following error message on the screen

          Scheduler: Event UID not valid!

 Negative (-):
     The event has been dispatched.
     It is now ready to be scheduled again.


                                                www.ns2ultimate.com
Protection Mechanism
From within the function schedule(…),
NS2 checks for the error
  if (e->uid_ > 0) {
     printf("Scheduler: Event UID not valid!nn");
     abort();
  }



which will show an error message if the
event UID is positive.


                                             www.ns2ultimate.com
For more
         information
          about NS2
                   Please see
                   this book
                 from Springer


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

More Related Content

Similar to Dynamic UID

Asynchronous JS in Odoo
Asynchronous JS in OdooAsynchronous JS in Odoo
Asynchronous JS in OdooOdoo
 
CQRS and Event Sourcing in a Symfony application
CQRS and Event Sourcing in a Symfony applicationCQRS and Event Sourcing in a Symfony application
CQRS and Event Sourcing in a Symfony applicationSamuel ROZE
 
Nagios Conference 2012 - Dave Josephsen - Stop Being Lazy
Nagios Conference 2012 - Dave Josephsen - Stop Being LazyNagios Conference 2012 - Dave Josephsen - Stop Being Lazy
Nagios Conference 2012 - Dave Josephsen - Stop Being LazyNagios
 
Modify the Time classattached to be able to work with Date.pdf
Modify the Time classattached to be able to work with Date.pdfModify the Time classattached to be able to work with Date.pdf
Modify the Time classattached to be able to work with Date.pdfaaseletronics2013
 
Javascript #8 : événements
Javascript #8 : événementsJavascript #8 : événements
Javascript #8 : événementsJean Michel
 
EventBus for Android
EventBus for AndroidEventBus for Android
EventBus for Androidgreenrobot
 
Architecture components, Константин Марс, TeamLead, Senior Developer, DataArt
Architecture components, Константин Марс, TeamLead, Senior Developer, DataArtArchitecture components, Константин Марс, TeamLead, Senior Developer, DataArt
Architecture components, Константин Марс, TeamLead, Senior Developer, DataArtAlina Vilk
 
How to make friends python with win32 api
How to make friends python with win32 apiHow to make friends python with win32 api
How to make friends python with win32 apiOpen-IT
 
Introduction to CQRS and Event Sourcing
Introduction to CQRS and Event SourcingIntroduction to CQRS and Event Sourcing
Introduction to CQRS and Event SourcingSamuel ROZE
 
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
 
How to Develop Your Own Simulators for Discrete-Event Systems
How to Develop Your Own Simulators for Discrete-Event SystemsHow to Develop Your Own Simulators for Discrete-Event Systems
How to Develop Your Own Simulators for Discrete-Event SystemsDonghun Kang
 
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
 
Deceptive simplicity of async and await
Deceptive simplicity of async and awaitDeceptive simplicity of async and await
Deceptive simplicity of async and awaitAndrei Marukovich
 

Similar to Dynamic UID (20)

Predictable Java af Anders P Ravn, CISS og Hans Søndergaard, ViaUC
Predictable Java af Anders P Ravn, CISS og Hans Søndergaard, ViaUCPredictable Java af Anders P Ravn, CISS og Hans Søndergaard, ViaUC
Predictable Java af Anders P Ravn, CISS og Hans Søndergaard, ViaUC
 
Asynchronous JS in Odoo
Asynchronous JS in OdooAsynchronous JS in Odoo
Asynchronous JS in Odoo
 
CQRS and Event Sourcing in a Symfony application
CQRS and Event Sourcing in a Symfony applicationCQRS and Event Sourcing in a Symfony application
CQRS and Event Sourcing in a Symfony application
 
Nagios Conference 2012 - Dave Josephsen - Stop Being Lazy
Nagios Conference 2012 - Dave Josephsen - Stop Being LazyNagios Conference 2012 - Dave Josephsen - Stop Being Lazy
Nagios Conference 2012 - Dave Josephsen - Stop Being Lazy
 
Modify the Time classattached to be able to work with Date.pdf
Modify the Time classattached to be able to work with Date.pdfModify the Time classattached to be able to work with Date.pdf
Modify the Time classattached to be able to work with Date.pdf
 
Javascript #8 : événements
Javascript #8 : événementsJavascript #8 : événements
Javascript #8 : événements
 
Qt Widgets In Depth
Qt Widgets In DepthQt Widgets In Depth
Qt Widgets In Depth
 
Qt Widget In-Depth
Qt Widget In-DepthQt Widget In-Depth
Qt Widget In-Depth
 
EventBus for Android
EventBus for AndroidEventBus for Android
EventBus for Android
 
Architecture components, Константин Марс, TeamLead, Senior Developer, DataArt
Architecture components, Константин Марс, TeamLead, Senior Developer, DataArtArchitecture components, Константин Марс, TeamLead, Senior Developer, DataArt
Architecture components, Константин Марс, TeamLead, Senior Developer, DataArt
 
How to make friends python with win32 api
How to make friends python with win32 apiHow to make friends python with win32 api
How to make friends python with win32 api
 
Introduction to CQRS and Event Sourcing
Introduction to CQRS and Event SourcingIntroduction to CQRS and Event Sourcing
Introduction to CQRS and Event Sourcing
 
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
 
Java-Events
Java-EventsJava-Events
Java-Events
 
How to Develop Your Own Simulators for Discrete-Event Systems
How to Develop Your Own Simulators for Discrete-Event SystemsHow to Develop Your Own Simulators for Discrete-Event Systems
How to Develop Your Own Simulators for Discrete-Event Systems
 
dSS API by example
dSS API by exampledSS API by example
dSS API by example
 
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...
 
Deceptive simplicity of async and await
Deceptive simplicity of async and awaitDeceptive simplicity of async and await
Deceptive simplicity of async and await
 
Awt event
Awt eventAwt event
Awt event
 
Javascript Browser Events.pdf
Javascript Browser Events.pdfJavascript Browser Events.pdf
Javascript Browser Events.pdf
 

More from Teerawat Issariyakul

More from Teerawat Issariyakul (11)

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

Recently uploaded

SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
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
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
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
 
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
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging 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 MenDelhi Call girls
 
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
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
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
 

Recently uploaded (20)

SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
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...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
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
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
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
 
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
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
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
 
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
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
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
 

Dynamic UID

  • 1. Dynamic of Unique ID Ns2Ultimate.com by Teerawat Issariyakul January 2011
  • 2. Recap NS2 is a discrete-event simulator, where actions are associated with events rather than time. An event in a discrete-event simulator consists of execution time, a set of actions, and a reference to the next event (Fig. 4.1). These events connect to each other and form a chain of events on the simulation timeline Schedule = Put an event on the simulation (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 time line 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 Dispatch = Execute the 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
  • 3. Recap • Attributes of Event handler handle(){ handle(){ handler <actions> <actions> } } handler_ next_ handler_ next_ event uid_ time_ uid_ time_ event How do we assign a unique ID (i.e., uid_) to the event? www.ns2ultimate.com
  • 4. Recap • Attributes of Event handler handle(){ handle(){ handler <actions> <actions> } } handler_ next_ handler_ next_ event uid_ time_ uid_ time_ event Using the Scheduler www.ns2ultimate.com
  • 5. Recap: Function schedule(h,e,delay) Put an event *e on the timeline at “delay”second in future, and associated the event with a handler “*h”. Scheduler s& = Scheduler::instance(); s.schedule(h,e,delay); Call here h e associated Handler Event Delay x current time www.ns2ultimate.com
  • 6. Recap: Function schedule(h,e,delay) //~ns/common/scheduler.cc void Scheduler::schedule(Handler* h, Event* e, double delay) { < CHECKING FOR ERRORS > e->uid_ = uid_++; e->handler_ = h; 1. Increment the local variable uid_ double t = clock_ + delay; 2. Assigned the incremented value e->time_ = t; as the unique ID of the event insert(e); } Scheduler Event assign to uid_ uid_ www.ns2ultimate.com
  • 7. So, NS2 has two type of unique IDs: Global Unique ID and Event
  • 8. T T wo ypes of UID Global UID The variable uid_ of the Scheduler One and only one for a simulation Event UID or Local UID The variable uid_ of an event Every event has its own uid_ www.ns2ultimate.com
  • 9. Global UID and Event UID Simulation: In function Schedule(…) Event Event UID: assign to uid_ - Unique to each Scheduler event uid_ assign to Event uid_ - Many events in assign to a simulation ➠ Event Many local UID Global UID: uid_ in a simulation Unique to the simulation www.ns2ultimate.com
  • 10. Global UID and Event UID Simulation: In function Schedule(…) //~ns/common/scheduler.cc Event uid_ void Scheduler::schedule assign to (Handler* h, Event* e, Scheduler double delay){ uid_ assign to Event Event UID is always a uid_ positive new number ... assign to e->uid_ = uid_++; e->handler_ = h; Event double t = clock_ + uid_ delay; e->time_ = t; insert(e); } www.ns2ultimate.com
  • 11. Event UID Simulation: In function dispatch(…) Event x uid_ //~ns/common/scheduler.cc void Scheduler::dispatch(Event* p, double t){ Reversing clock_ = t; the sign p->uid_ = -p->uid_; p->handler_->handle(p); Event } -x uid_ www.ns2ultimate.com
  • 12. 84 Dynamic of Event UID 4 Implementation of Discrete-Event Simulation in NS2 schedule(...) and dispatch(...) functions. The sign toggling mechanism of unique ID ensures that events will be scheduled and dispatched properly. If a scheduled UIDis nota certain event changes its value like A event of dispatched, or is dispatched twice, its unique ID will be positive, and an attempt to schedule this undispatched event will cause an this (a positive error (Lines 5 and 6 in Program 4.7). new value) –2 (reversing Fig. 4.2. Dynamics of Event unique ID (uid) : Take a positive value from the sign) Scheduler::uid when being scheduled, and invert the sign when being dispatched. Increment upon schedule and inversion of sign upon dispatch. www.ns2ultimate.com
  • 13. T key questions wo 1. Why is the “event UID” changes its value like this? 2. What if the dynamic is different? www.ns2ultimate.com
  • 14. Dynamic of Event UID It is a UID protection mechanism. But before going further, let’s ask another basic question: WHAT IS AN EVENT? www.ns2ultimate.com
  • 15. EVENTS NS2 has several type of events Let’s focus on packet reception events Event ... AtEvent Packet ... Packet reception events Source: http://www-rp.lip6.fr/ns-doc/ns226-doc/html/hierarchy.htm www.ns2ultimate.com
  • 16. Packet Reception Event Packet uid_ Time where the packet is time_ received handler_ a pointer to node 2 Node 1 Node 2 www.ns2ultimate.com
  • 17. Packet Event Reuse One packet could be passed among several Nodes Event/ Packet 2 uid_ time_ handler_ Node 1 Node 2 Node 3 www.ns2ultimate.com
  • 18. Packet Event Reuse NS2 does not create a new event every time it forwards a packet. It Changes the event UID, and passes the same packet to the next object Event/ Packet 6 uid_ time_ handler_ Node 1 Node 2 Node 3 www.ns2ultimate.com
  • 19. An example of packet forwarding time 0 5.1 2 Instance 1: Event/ Event/ A packet with UID Packet Packet “2” is scheduled to 2 uid_ 6 uid_ arrived at Node 2 at 1.2 time_ 5.1 time_ “0” s. handler_ handler_ Node 1 Node 2 Node 3 www.ns2ultimate.com
  • 20. An example of packet forwarding time 1.2 5.1 2 Instance 2: Event/ Packet A packet with UID “6” is scheduled to 6 uid_ arrived at Node 3 at 5.1 time_ “5.1” s. handler_ Node 1 Node 2 Node 3 www.ns2ultimate.com
  • 21. 84 4 Implementation of Discrete-Event Simulation in NS2 An example of packetThe sign toggling mechanism schedule(...) and dispatch(...) functions. forwarding of unique ID ensures that events will be scheduled and dispatched properly. If a scheduled event is not dispatched, or is dispatched twice, its unique ID will be positive, and an attempt to schedule this undispatched event will cause an error (Lines 5 and 6 in Program 4.7). –2 t=0: Fig. 4.2. Dynamics of Event unique ID (uid) : Take a positive value from NS2 schedules being scheduled, and invert the sign when being dispatched. Scheduler::uid when t=1.2: packet reception at and inversion of sign upon dispatch. Increment upon schedule packet is received node 2 at 1.2 s at node 2 4.3.6 Scheduling-Dispatching Mechanism www.ns2ultimate.com
  • 22. 84 4 Implementation of Discrete-Event Simulation in NS2 An example of packetThe sign toggling mechanism schedule(...) and dispatch(...) functions. forwarding of unique ID ensures that events will be scheduled and dispatched properly. If a scheduled event is not dispatched, or already decided at “t=5” that We’ve is dispatched twice, its unique ID will be positive, and an attempt to schedule this undispatched event will cause an the packet will be received at “t=5.1”. error (Lines 5 and 6 in Program 4.7). So nothing can happen here. –2 t=5: NS2 schedules t=5.1: Fig. 4.2. Dynamics of Event unique ID (uid) : Take a positive value from packet reception being scheduled, and invert the signpacket is received Scheduler::uid when atand inversion of sign upon dispatch. being dispatched. Increment upon schedule when node 3 at 5.1 s at node 3 4.3.6 Scheduling-Dispatching Mechanism www.ns2ultimate.com
  • 23. An example of packet forwarding We’ve already decided at “t=5” that the packet will be received at “t=5.1”. So nothing can happen here. HOW DO WE KNOW THAT NOTHING WILL HAPPEN AT THESE PERIODS? WE USE “THE SIGN” OF EVENT UID www.ns2ultimate.com
  • 24. The Sign of the Event UID Positive (+): The event is scheduled but not yet dispatched Do not reschedule here. Otherwise, you will see the following error message on the screen Scheduler: Event UID not valid! Negative (-): The event has been dispatched. It is now ready to be scheduled again. www.ns2ultimate.com
  • 25. Protection Mechanism From within the function schedule(…), NS2 checks for the error if (e->uid_ > 0) { printf("Scheduler: Event UID not valid!nn"); abort(); } which will show an error message if the event UID is positive. www.ns2ultimate.com
  • 26. For more information about NS2 Please see this book from Springer T. Issaraiyakul and E. Hossain, “Introduction to Network Simulator NS2”, Second Edition, Springer 2011, or visit www.ns2ultimate.com

Editor's Notes

  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
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n