• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
NS2: Events and Handlers
 

NS2: Events and Handlers

on

  • 10,302 views

 

Statistics

Views

Total Views
10,302
Views on SlideShare
2,948
Embed Views
7,354

Actions

Likes
1
Downloads
0
Comments
0

7 Embeds 7,354

http://www.ns2ultimate.com 6915
http://ns2ultimate.tumblr.com 430
http://webcache.googleusercontent.com 3
http://translate.googleusercontent.com 3
http://www.ns2ultimate.com&_=1358410570390 HTTP 1
http://www.ns2ultimate.com&_=1330504681687 HTTP 1
http://www.ns2ultimate.com&_=1343640731889 HTTP 1
More...

Accessibility

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

NS2: Events and Handlers NS2: Events and Handlers Presentation Transcript

  • Events and Handlers Ns2Ultimate.com by Teerawat Issariyakul October 2011
  • EventsDictionary: A thing that happensNS2: A thing which we are interested insimulationNS2 has two types of events1. Packet reception event2. At event: T execution cl www.ns2ultimate.com
  • When NS2 Uses EventsThings to happen in future Packet reception event at future time At event: T execution in future clExamples: 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 EventNS2 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 7At 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 createsone 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-drivensimulator, time between a pair of events does not need to be constant. Whenthe simulation starts, events in the chain are executed from left to right (i.e., Example: Chain of Eventschronologically).1 In the next section, we will discuss the simulation concept ofNS2. In Sections 4.2, 4.3, and 4.4, we will explain the details of classes Eventand Handler, class Scheduler, and class Simulator, respectively. Finally, wesummarize this chapter in Section 4.6. insert 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 7Fig. 4.1. A sample chain of events in a discrete-event simulation. Each event con-tains execution time and a reference to the next event. In this figure, Event1 createsand inserts Event5 after Event2 (the execution time of Event 5 is at 3.7 second). www.ns2ultimate.com
  • What Do You Dowhen 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 actionsMain 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.hclass 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.hclass Handler {public: virtual ~Handler () {} virtual void handle(Event* e) = 0; /* default action is defined here */}; www.ns2ultimate.com
  • Class EventClass Event has 4 main variables- next_: A pointer to the next event - handler_: A pointer to the Handler- time_: Time - uid_: Unique IDClass Handler defines the default actionassociated wit the event in its function handle(e) www.ns2ultimate.com
  • Event and Handlerhandler 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.hclass 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 willbe discussed in Chapter 8. The main helper objects will be discussed in NS2 HierarchyChapter 15.5.1.2 C++ Class HierarchyThis section gives an overview of C++ class hierarchies. The entire hierarchyconsistsClass 100 C++ classes thestruct data types. of all Network of over Handler is and based class Here, we only showa part of the hierarchy (in Fig. 5.1). The readers are referred to [18] for thecomplete 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 TraceFig. 5.1. A part of NS2 C++ class hierarchy (this chapter emphasizes on classesin 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 onclass NsObject (all Classifier Connector LanRouternetwork 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
  • NsObjectSo the default action (i.e., function handle(e)) isalso 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 SpringerT. Issaraiyakul and E. Hossain, “Introduction to Network Simulator NS2”, Springer 2009or visit www.ns2ultimate.com