00001 // GENERAL PUBLIC LICENSE AGREEMENT 00002 // 00003 // PLEASE READ THIS DOCUMENT CAREFULLY BEFORE UTILIZING THE PROGRAM 00004 // 00005 // BY UTILIZING THIS PROGRAM, YOU AGREE TO BECOME BOUND BY THE TERMS OF 00006 // THIS LICENSE. IF YOU DO NOT AGREE TO THE TERMS OF THIS LICENSE, DO 00007 // NOT USE THIS PROGRAM OR ANY PORTION THEREOF IN ANY FORM OR MANNER. 00008 // 00009 // This Program is licensed, not sold to you by GEORGIA TECH RESEARCH 00010 // CORPORATION ("GTRC"), owner of all code and accompanying documentation 00011 // (hereinafter "Program"), for use only under the terms of this License, 00012 // and GTRC reserves any rights not expressly granted to you. 00013 // 00014 // 1. This License allows you to: 00015 // 00016 // (a) make copies and distribute copies of the Program's source code 00017 // provide that any such copy clearly displays any and all appropriate 00018 // copyright notices and disclaimer of warranty as set forth in Article 5 00019 // and 6 of this License. All notices that refer to this License and to 00020 // the absence of any warranty must be kept intact at all times. A copy 00021 // of this License must accompany any and all copies of the Program 00022 // distributed to third parties. 00023 // 00024 // A fee may be charged to cover the cost associated with the physical 00025 // act of transferring a copy to a third party. At no time shall the 00026 // program be sold for commercial gain either alone or incorporated with 00027 // other program(s) without entering into a separate agreement with GTRC. 00028 // 00029 // 00030 // (b) modify the original copy or copies of the Program or any portion 00031 // thereof ("Modification(s)"). Modifications may be copied and 00032 // distributed under the terms and conditions as set forth above, 00033 // provided the following conditions are met: 00034 // 00035 // i) any and all modified files must be affixed with prominent 00036 // notices that you have changed the files and the date that the changes 00037 // occurred. 00038 // 00039 // ii) any work that you distribute, publish, or make available, that 00040 // in whole or in part contains portions of the Program or derivative 00041 // work thereof, must be licensed at no charge to all third parties under 00042 // the terms of this License. 00043 // 00044 // iii) if the modified program normally reads commands interactively 00045 // when run, you must cause it, when started running for such interactive 00046 // use in the most ordinary way, to display and/or print an announcement 00047 // with all appropriate copyright notices and disclaimer of warranty as 00048 // set forth in Article 5 and 6 of this License to be clearly displayed. 00049 // In addition, you must provide reasonable access to this License to the 00050 // user. 00051 // 00052 // Any portion of a Modification that can be reasonably considered 00053 // independent of the Program and separate work in and of itself is not 00054 // subject to the terms and conditions set forth in this License as long 00055 // as it is not distributed with the Program or any portion thereof. 00056 // 00057 // 00058 // 2. This License further allows you to copy and distribute the Program 00059 // or a work based on it, as set forth in Article 1 Section b in 00060 // object code or executable form under the terms of Article 1 above 00061 // provided that you also either: 00062 // 00063 // i) accompany it with complete corresponding machine-readable source 00064 // code, which must be distributed under the terms of Article 1, on a 00065 // medium customarily used for software interchange; or, 00066 // 00067 // ii) accompany it with a written offer, valid for no less than three 00068 // (3) years from the time of distribution, to give any third party, for 00069 // no consideration greater than the cost of physical transfer, a 00070 // complete machine-readable copy of the corresponding source code, to be 00071 // distributed under the terms of Article 1 on a medium customarily used 00072 // for software interchange; or, 00073 // 00074 // 00075 // 3. Export Law Assurance. 00076 // 00077 // You agree that the Software will not be shipped, transferred or 00078 // exported, directly into any country prohibited by the United States 00079 // Export Administration Act and the regulations thereunder nor will be 00080 // used for any purpose prohibited by the Act. 00081 // 00082 // 4. Termination. 00083 // 00084 // If at anytime you are unable to comply with any portion of this 00085 // License you must immediately cease use of the Program and all 00086 // distribution activities involving the Program or any portion thereof. 00087 // 00088 // 00089 // 5. Disclaimer of Warranties and Limitation on Liability. 00090 // 00091 // YOU ACCEPT THE PROGRAM ON AN "AS IS" BASIS. GTRC MAKES NO WARRANTY 00092 // THAT ALL ERRORS CAN BE OR HAVE BEEN ELIMINATED FROM PROGRAM. GTRC 00093 // SHALL NOT BE RESPONSIBLE FOR LOSSES OF ANY KIND RESULTING FROM THE USE 00094 // OF PROGRAM AND ITS ACCOMPANYING DOCUMENT(S), AND CAN IN NO WAY PROVIDE 00095 // COMPENSATION FOR ANY LOSSES SUSTAINED, INCLUDING BUT NOT LIMITED TO 00096 // ANY OBLIGATION, LIABILITY, RIGHT, CLAIM OR REMEDY FOR TORT, OR FOR ANY 00097 // ACTUAL OR ALLEGED INFRINGEMENT OF PATENTS, COPYRIGHTS, TRADE SECRETS, 00098 // OR SIMILAR RIGHTS OF THIRD PARTIES, NOR ANY BUSINESS EXPENSE, MACHINE 00099 // DOWNTIME OR DAMAGES CAUSED TO YOU BY ANY DEFICIENCY, DEFECT OR ERROR 00100 // IN PROGRAM OR MALFUNCTION THEREOF, NOR ANY INCIDENTAL OR CONSEQUENTIAL 00101 // DAMAGES, HOWEVER CAUSED. GTRC DISCLAIMS ALL WARRANTIES, BOTH EXPRESS 00102 // AND IMPLIED RESPECTING THE USE AND OPERATION OF PROGRAM AND ITS 00103 // ACCOMPANYING DOCUMENTATION, INCLUDING ALL IMPLIED WARRANTIES OF 00104 // MERCHANTABILITY AND FITNESS FOR PARTICULAR PURPOSE AND ANY IMPLIED 00105 // WARRANTY ARISING FROM COURSE OF PERFORMANCE, COURSE OF DEALING OR 00106 // USAGE OF TRADE. GTRC MAKES NO WARRANTY THAT PROGRAM IS ADEQUATELY OR 00107 // COMPLETELY DESCRIBED IN, OR BEHAVES IN ACCORDANCE WITH ANY 00108 // ACCOMPANYING DOCUMENTATION. THE USER OF PROGRAM IS EXPECTED TO MAKE 00109 // THE FINAL EVALUATION OF PROGRAM'S USEFULNESS IN USER'S OWN 00110 // ENVIRONMENT. 00111 // 00112 // GTRC represents that, to the best of its knowledge, the software 00113 // furnished hereunder does not infringe any copyright or patent. 00114 // 00115 // GTRC shall have no obligation for support or maintenance of Program. 00116 // 00117 // 6. Copyright Notice. 00118 // 00119 // THE SOFTWARE AND ACCOMPANYING DOCUMENTATION ARE COPYRIGHTED WITH ALL 00120 // RIGHTS RESERVED BY GTRC. UNDER UNITED STATES COPYRIGHT LAWS, THE 00121 // SOFTWARE AND ITS ACCOMPANYING DOCUMENTATION MAY NOT BE COPIED EXCEPT 00122 // AS GRANTED HEREIN. 00123 // 00124 // You acknowledge that GTRC is the sole owner of Program, including all 00125 // copyrights subsisting therein. Any and all copies or partial copies 00126 // of Program made by you shall bear the copyright notice set forth below 00127 // and affixed to the original version or such other notice as GTRC shall 00128 // designate. Such notice shall also be affixed to all improvements or 00129 // enhancements of Program made by you or portions thereof in such a 00130 // manner and location as to give reasonable notice of GTRC's copyright 00131 // as set forth in Article 1. 00132 // 00133 // Said copyright notice shall read as follows: 00134 // 00135 // Copyright 2004 00136 // Dr. George F. Riley 00137 // Georgia Tech Research Corporation 00138 // Atlanta, Georgia 30332-0415 00139 // All Rights Reserved 00140 // 00141 // $Id: simulator.h 456 2006-01-20 17:37:47Z riley $ 00142 00143 00144 00145 // Georgia Tech Network Simulator - Simulator class 00146 // George F. Riley. Georgia Tech Spring 2002 00147 00148 #ifndef __simulator_h__ 00149 #define __simulator_h__ 00150 00151 #include <iostream> 00152 #include <map> 00153 #include <set> 00154 #include <list> 00155 #include <vector> 00156 #include <string> 00157 #include <math.h> 00158 #include <fstream> 00159 00160 //#define CTRLFIFO true 00161 00162 #include "common-defs.h" 00163 #include "object.h" 00164 #include "handler.h" 00165 #include "event.h" 00166 #include "timer.h" 00167 #include "location.h" 00168 #include "rng.h" 00169 00170 // For testing, include scheduler.h..remove later 00171 #include "scheduler.h" 00172 00173 class Interface; 00174 class Node; 00175 class NotifyHandler; 00176 00177 class QTWindow; 00178 class QCanvas; 00179 // Define a callback for custom animation background 00180 typedef void(*CustomBackground_t)(QCanvas*); 00181 00182 typedef void (*ProgressHook_t)(Time_t); 00183 typedef std::vector<ProgressHook_t> PHVec_t; // List of progress callbacks 00184 typedef std::vector<std::string> StringVec_t; // Vector of strings 00185 00186 00187 // Definen a callback for "Node Selected" (mouse click) on animation 00188 typedef void (*NodeSelected_t)(Node*); 00189 00190 const double DegreesToMeters = 111319.5; // Degrees of latitude to meters 00191 const double DegreesToRadians = (2.0 * M_PI) / 360.0; 00192 00193 typedef enum{ 00194 CIRCLES = 1, 00195 DIRECTED_ARR = 2, 00196 }ANIMATE_WIRELESS_TX_FORM; 00197 00198 class SimulatorEvent : public Event { 00199 public: 00200 typedef enum { HALT, DELETE_OBJECT, NOTIFY, 00201 NODE_DOWN, NODE_UP, 00202 BASEBAND_TX, 00203 INTERFACE_DOWN, INTERFACE_UP } SimulatorEvent_t; 00204 SimulatorEvent() 00205 : object(nil), c(nil), node(nil), iFace(nil) { } 00206 SimulatorEvent(Event_t ev) 00207 : Event(ev), object(nil), c(nil), node(nil), iFace(nil) { } 00208 virtual ~SimulatorEvent() { } 00209 public: 00210 Object* object; 00211 void* c; 00212 Node* node; 00213 Interface* iFace; 00214 }; 00215 00216 class EventPair { 00217 public: 00218 EventPair() : time(0.0), event(nil) { } 00219 EventPair(Time_t t, Event* e) : time(t), event(e) { } 00220 public: 00221 Time_t time; 00222 Event* event; 00223 }; 00224 00225 #ifndef __scheduler_h__ 00226 class KeyPair { 00227 public: 00228 KeyPair(Time_t t, SimulatorUid_t u) : time(t), uid(u) { } 00229 public: 00230 Time_t time; 00231 SimulatorUid_t uid; 00232 }; 00233 00234 // Definitions for event list managemet 00235 typedef std::pair<Time_t,SimulatorUid_t> KeyPair_t; // The key for the map 00236 //typedef std::pair<Time_t,Event*> EventPair_t; // For non-sorted ev lists (obsolete) 00237 class key_less 00238 { 00239 public: 00240 key_less() { } 00241 bool operator()(const KeyPair& l, const KeyPair& r) const { 00242 return (l.time < r.time || 00243 l.time == r.time && l.uid < r.uid); 00244 //bool operator()(const KeyPair& l, const KeyPair& r) const { 00245 //if (l.time > r.time) return false; 00246 //if (l.time < r.time) return true; 00247 //return (l.uid < r.uid); 00248 } 00249 }; 00250 00251 class event_less 00252 { 00253 public: 00254 event_less() { } 00255 inline bool operator()(Event* const & l, const Event* const & r) const { 00256 return (l->Time() < r->Time() || 00257 l->Time() == r->Time() && l->uid < r->uid); 00258 } 00259 }; 00260 00261 // Define a sorted event list (EventMap_t) and fifo list (EventDeq_t) 00262 //typedef std::map<KeyPair, Event*, std::less<KeyPair> > EventMap_t; 00263 #endif 00264 typedef std::map<KeyPair, Event*, key_less> EventMap_t; 00265 //typedef std::set<Event*, event_less> EventSet_t; 00266 typedef std::list<EventPair > EventList_t; 00267 00268 class ProgressTimer : public Timer { 00269 public: 00270 virtual void Timeout(TimerEvent*); // Override the timeout method 00271 }; 00272 00273 class ProgressEvent : public TimerEvent { 00274 public: 00275 ProgressEvent(Time_t i) 00276 : TimerEvent(), interval(i) { } 00277 public: 00278 Time_t interval; 00279 }; 00280 00281 //Doc:ClassXRef 00282 class Simulator : public Handler { 00283 //Doc:Class Class {\tt Simulator} defines the simulator object required for 00284 //Doc:Class all \GTNS\ simulations. The simulator object controlls all 00285 //Doc:Class actions once the simulation has started executing. Each 00286 //Doc:Class \GTNS\ simulation should declare a single {\tt Simulator} object, 00287 //Doc:Class usually as a local variable in the {\tt main} program. 00288 public: 00289 friend class ProgressTimer; // Allow timer access to "ProgressResched" 00290 //Doc:Method 00291 Simulator(); 00292 //Doc:Desc The constructor for the {\tt Simulator} object takes no 00293 //Doc:Desc arguments unless using the distibuted simulation feature of 00294 //Doc:Desc \GTNS. 00295 00296 virtual ~Simulator(); 00297 public: 00298 //Doc:Method 00299 virtual void Handle(Event*, Time_t); 00300 //Doc:Desc The Simulator class is a subclass of {\tt Handler}, 00301 //Doc:Desc since the simulator object must handle events, specificaly 00302 //Doc:Desc the progress events and the halt event. 00303 //Doc:Arg1 A pointer to the event being handled. 00304 //Doc:Arg2 The current simulation time. 00305 00306 #ifdef MOVED_TO_SCHEDULER 00307 //Doc:Method 00308 virtual void Cancel(Event*); // cancel event 00309 //Doc:Desc Cancels a pending event. 00310 //Doc:Arg1 A pointer to the event to be canceled. When scheduling events 00311 //Doc:Arg1 that will later be canceled, a pointer to the event must 00312 //Doc:Arg1 be retained to allow cancellation. 00313 00314 //Doc:Method 00315 virtual void Schedule(Event*); // schedule event 00316 //Doc:Desc Schedules a new event. The simulation time for the 00317 //Doc:Desc event must be stored in the event class, member 00318 //Doc:Desc {\tt time}, by the caller prior to calling Schedule. The 00319 //Doc:Desc handler for the event is caller, which must be a subclass 00320 //Doc:Desc of {\tt Handler} 00321 //Doc:Arg1 A pointer to the event being scheduled. 00322 00323 //Doc:Method 00324 virtual void Schedule(Event*, Time_t); // schedule event 00325 //Doc:Desc Schedules a new event. The simulation time for the 00326 //Doc:Desc event is specified in the argument list and will 00327 //Doc:Desc be stored in the event class, member {\tt time}, 00328 //Doc:Desc by this method. The 00329 //Doc:Desc handler for the event must be already specified 00330 //Doc:Desc in the passed {\tt Event}. 00331 //Doc:Arg1 A pointer to the event being scheduled. 00332 //Doc:Arg2 A amount of time {\em in the future} for this event. 00333 //Doc:Arg2 Note the time is a relative time from the current simulation 00334 //Doc:Arg2 time. The actual time for the event is computed by adding the 00335 //Doc:Arg2 current simulation time to the value specified. 00336 00337 //Doc:Method 00338 virtual void Schedule(Event*, Time_t, Handler*); 00339 //Doc:Desc Schedules a new event. The simulation time for the 00340 //Doc:Desc event is specified in the argument list and will 00341 //Doc:Desc be stored in the event class, member {\tt time}, 00342 //Doc:Desc by this method. The 00343 //Doc:Desc handler for the event is also specified in the 00344 //Doc:Desc argument list. 00345 //Doc:Arg1 A pointer to the event being scheduled. 00346 //Doc:Arg2 A amount of time {\em in the future} for this event. 00347 //Doc:Arg2 Note the time is a relative time from the current simulation 00348 //Doc:Arg2 time. The actual time for the event is computed by adding the 00349 //Doc:Arg2 current simulation time to the value specified. 00350 //Doc:Arg3 A pointer to any object that is a subclass of class 00351 //Doc:Arg3 {\tt Handler}, specifying the event handler for this event. 00352 00353 //Doc:Method 00354 virtual void Schedule(Event*, Time_t, Handler&); 00355 //Doc:Desc Schedules a new event. The simulation time for the 00356 //Doc:Desc event is specified in the argument list and will 00357 //Doc:Desc be stored in the event class, member {\tt time}, 00358 //Doc:Desc by this method. The 00359 //Doc:Desc handler for the event is also specified in the 00360 //Doc:Desc argument list. 00361 //Doc:Arg1 A pointer to the event being scheduled. 00362 //Doc:Arg2 A amount of time {\em in the future} for this event. 00363 //Doc:Arg2 Note the time is a relative time from the current simulation 00364 //Doc:Arg2 time. The actual time for the event is computed by adding the 00365 //Doc:Arg2 current simulation time to the value specified. 00366 //Doc:Arg3 A reference to any object that is a subclass of class 00367 //Doc:Arg3 {\tt Handler}, specifying the event handler for this event. 00368 00369 // Schedule an "early" event (use STL hint at beginning of queue) 00370 // Not documented in manual at this point. 00371 virtual void ScheduleEarly(Event*, Time_t, Handler*); 00372 #endif 00373 00374 //Doc:Method 00375 Scheduler* SetScheduler(const Scheduler&); 00376 //Doc:Desc Specify which even scheduler is desired 00377 //Doc:Arg1 Temporary object of desired scheduler class. 00378 //Doc:Arg1 This is copied and set as the default scheduler. 00379 00380 //Doc:Method 00381 virtual void Progress(Time_t); //Print debug progress message 00382 //Doc:Desc Request a progress message be printed on {\tt stdout} 00383 //Doc:Desc periodically. 00384 //Doc:Desc The message is printed either by a \GTNS\ supplied progress 00385 //Doc:Desc method, 00386 //Doc:Desc or by a method supplied using the {\tt ProgressHook} method of 00387 //Doc:Desc class {\tt Simulator } 00388 //Doc:Arg1 The progress interval, specified in seconds. 00389 //Doc:Arg1 Note that this specifies 00390 //Doc:Arg1 the progress method is called periodically in 00391 //Doc:Arg1 {\em Simulation Time}, 00392 //Doc:Arg1 not in wall--clock time. 00393 00394 //Doc:Method 00395 virtual SimulatorEvent* NodeDownAt(Node*, const Random&); 00396 //Doc:Desc Schedule a node failure at a specified time. 00397 //Doc:Arg1 Node to fail. 00398 //Doc:Arg2 A random variable specifying time to fail. 00399 //Doc:Return Scheduled event (in case caller wants to cancel) 00400 00401 //Doc:Method 00402 virtual SimulatorEvent* NodeUpAt(Node*, const Random&); 00403 //Doc:Desc Schedule a node recovery at a specified time. 00404 //Doc:Arg1 Node to recover 00405 //Doc:Arg2 A random variable specifying time to recover 00406 //Doc:Return Scheduled event (in case caller wants to cancel) 00407 00408 //Doc:Method 00409 virtual SimulatorEvent* InterfaceDownAt(Interface*, const Random&); 00410 //Doc:Desc Schedule a node failure at a specified time. 00411 //Doc:Arg1 Interface to fail. 00412 //Doc:Arg2 A random variable specifying time to fail. 00413 //Doc:Return Scheduled event (in case caller wants to cancel) 00414 00415 //Doc:Method 00416 virtual SimulatorEvent* InterfaceUpAt(Interface*, const Random&); 00417 //Doc:Desc Schedule a node recovery at a specified time. 00418 //Doc:Arg1 Interface to recover 00419 //Doc:Arg2 A random variable specifying time to recover 00420 //Doc:Return Scheduled event (in case caller wants to cancel) 00421 00422 #ifdef MOVED_TO_SCHEDULER 00423 //Doc:Method 00424 virtual Event* DeQueue(); // get next event 00425 //Doc:Desc Removes the earliest pending event from the event queue 00426 //Doc:Desc and returns a pointer to it. 00427 //Doc:Return A pointer to the earliest pending event in the 00428 //Doc:Return event queue. 00429 00430 //Doc:Method 00431 virtual Event* PeekEvent(); // Peek at next event (do not remove) 00432 //Doc:Desc Returns a pointer to the earliest pending event in the event 00433 //Doc:Desc queue, but does not remove it from the queue. 00434 //Doc:Return A pointer to the earliest pending event in the 00435 //Doc:Return event queue. 00436 #endif 00437 00438 //Doc:Method 00439 void PrintStats(); // Print debug statistics 00440 //Doc:Desc Prints some fairly detailed statistics about the simulation. 00441 //Doc:Desc Normally would be called only after the 00442 //Doc:Desc {\tt Run} method has exited and the simulation has completed. 00443 00444 //Doc:Method 00445 void CommonRunInit(); // Common code prior to Run() 00446 //Doc:Desc Prevents code duplication in Simulator::Run and 00447 //Doc:Desc DistributedSimulator::Run(); 00448 00449 //Doc:Method 00450 virtual bool DistributedSim() {return false; } 00451 //Doc:Desc Query if distributed sim (overridden by DistributedSimulator) 00452 //Doc:Return Always false here. 00453 00454 //Doc:Method 00455 virtual void Run(); // Begin processing events 00456 //Doc:Desc Initiates the simulation. The {\tt Run} method should be 00457 //Doc:Desc called after all the topology and data flow information 00458 //Doc:Desc has been defined. {\tt Run} will start processing events, 00459 //Doc:Desc and will continue until the {\em Stop} event is processed, 00460 //Doc:Desc the {\tt Halt()} method is called, or until the event 00461 //Doc:Desc list becomes empty. 00462 00463 //Doc:Method 00464 void StopAt(Time_t t); // Schedule Halt event at future time 00465 //Doc:Desc Schedules a {\tt Stop} event at the specified time. This 00466 //Doc:Desc will cause the {\tt Run()} method to exit at the specified 00467 //Doc:Desc time, even if there are more pending unprocessed events. 00468 //Doc:Arg1 The simulation time to schedule the {\tt Stop} event. 00469 00470 //Doc:Method 00471 void Halt(); // Stop processing and exit 00472 //Doc:Desc Immediately stops processing events and causes the {\tt Run()} 00473 //Doc:Desc method to exit. 00474 00475 //Doc:Method 00476 void Silent(bool s) { silent = s; } 00477 //Doc:Desc Set silent mode on or off When silent, the simulator produces 00478 //Doc:Desc no printed information on stdout. 00479 //Doc:Arg1 true if silent mode desired. 00480 00481 //Doc:Method 00482 void Name(const std::string&); 00483 //Doc:Desc Specify a name for this simulation. 00484 //Doc:Desc Used by to http web interface 00485 //Doc:Desc to identify the simulation. 00486 //Doc:Arg1 Name for this simulation 00487 00488 //Doc:Method 00489 void DeleteObject(Object*); // Schedule a delete object event 00490 //Doc:Desc Schedules an event at the current simulation time which deletes 00491 //Doc:Desc the specified {\tt Object}. Sometimes, a \GTNS\ object will 00492 //Doc:Desc determine that it is no longer needed, but a {\em C++} object 00493 //Doc:Desc cannot delete itself. This allows an object to schedule its own 00494 //Doc:Desc deletion. 00495 //Doc:Arg1 A pointer to the object to be deleted. 00496 00497 //Doc:Method 00498 void ProgressHook(ProgressHook_t); // Add a progress callback 00499 //Doc:Desc Specifies a subroutine to call each time a {\tt Progress} event 00500 //Doc:Desc is processed. The {\tt Process} events are scheduled 00501 //Doc:Desc periodically, at an interval specified by the {\tt Progress} 00502 //Doc:Desc method. The {\tt ProgressHook} method must be a static 00503 //Doc:Desc method, and must have a single {\tt Time_t} argument and return 00504 //Doc:Desc {\tt void}. When the {\tt ProgressHook} method is called 00505 //Doc:Desc the argument passed is the current simulation time. 00506 //Doc:Arg1 The static method to call on each {\tt Progress} interval. 00507 00508 //Doc:Method 00509 void AddNotify(NotifyHandler*, Time_t, void*); 00510 //Doc:Desc Call a notification at the specified time in the future 00511 //Doc:Arg1 NotifyHandler object to call 00512 //Doc:Arg2 Time in future. 00513 //Doc:Arg3 Pointer to pass to the notifier. 00514 00515 00516 // CleanupOnExit is used to delete all nodes when Simulator destructed 00517 // This is just for debugging memory leaks 00518 //Doc:Method 00519 void CleanupOnExit(bool c = true) { cleanUp = c;} 00520 //Doc:Desc Specifies that the {\tt Simulator} object should clean up 00521 //Doc:Desc all allocated memory objects when destructed. This would 00522 //Doc:Desc normally be used when debugging the simulator, to help 00523 //Doc:Desc locate memory leaks. 00524 //Doc:Arg1 A boolean specifying whether the {\tt Simulator} object 00525 //Doc:Arg1 should cleanup when destructed. 00526 00527 //Doc:Method 00528 void TopologyChanged(bool); 00529 //Doc:Desc Notify the simulator that a topology change has occured. 00530 //Doc:Arg1 True if node or interface UP, false if DOWN 00531 00532 bool IsScheduled(Event*);// Debug...see if event is scheduled 00533 00534 // QTWindow interface 00535 00536 //Doc:Method 00537 QTWindow* GetQTWindow() { return qtWin; } 00538 //Doc:Desc Returns a pointer to the QT Window object 00539 //Doc:Return Pointer to the QT Window object 00540 00541 //Doc:Method 00542 void DisplayTopology(); // Show the topology using qt window 00543 //Doc:Desc Causes a graphical animation window to be opened with a visual 00544 //Doc:Desc display of the topology. 00545 00546 //Doc:Method 00547 void DisplayTopologyAndReturn(); // Show the topology using qt window 00548 //Doc:Desc Causes a graphical animation window to be opened with a visual 00549 //Doc:Desc display of the topology. Returns immediately. 00550 00551 //Doc:Method 00552 void UpdateTopology(); 00553 //Doc:Desc Causes the existing animiation window to update the state 00554 //Doc:Desc of all animated objects. 00555 00556 // Start the animation at a specific time 00557 //Doc:Method 00558 void StartAnimation(Time_t, bool = true, bool = false); 00559 //Doc:Desc Starts an animation on at the specified time. 00560 //Doc:Arg1 The time to start the animation. 00561 //Doc:Arg2 {\tt True} if the animation should initially be paused. 00562 //Doc:Arg3 {\tt True} if the animation should use the full screen. 00563 00564 00565 //Doc:Method 00566 void StopAnimation(Time_t); // Stop and close the animation window 00567 //Doc:Desc Stops the animiation and closes the animation window 00568 //Doc:Desc at the specified time. 00569 //Doc:Arg1 The time to stop the animation. 00570 00571 //Doc:Method 00572 void PauseAnimation(Time_t); // Pause the animation window 00573 //Doc:Desc Pauses the animiation 00574 //Doc:Desc at the specified time. 00575 //Doc:Arg1 The time to pause the animation. 00576 00577 //Doc:Method 00578 void AnimationUpdateInterval(Time_t);// Initial animation update interval 00579 //Doc:Desc Specifies the initial update interval for the animation display. 00580 //Doc:Desc The update interval is adjustable via a slider on the animation 00581 //Doc:Desc window. 00582 //Doc:Arg1 The simulation time between animation updates. 00583 // Statistics 00584 00585 //Doc:Method 00586 void AnimateWirelessTx(bool a, ANIMATE_WIRELESS_TX_FORM wirelessTxForm = CIRCLES); 00587 //Doc:Desc Specify detailed animiation of wireless transmissions 00588 //Doc:Arg1 true if wireless animation desired 00589 //Doc:Arg2 Default is CIRCLES. Can be specified to be DIRECTED ARROWS. 00590 00591 //Doc:Method 00592 bool AnimateWirelessTx(); 00593 //Doc:Desc Determine if wireless transmit animation selected 00594 //Doc:Return true if wireless animation selected. 00595 00596 //Doc:Method 00597 ANIMATE_WIRELESS_TX_FORM AnimateWirelessTxForm(); 00598 //Doc:Desc Determine the wireless transmit animation form selected 00599 //Doc:Return wireless animation form selected. 00600 00601 //Doc:Method 00602 void AnimateBasebandTx(Time_t when, bool a); 00603 //Doc:Desc Specify detailed animiation of Bluetoth transmissions 00604 //Doc:Arg1 time to start Bluetooth Tx animation 00605 //Doc:Arg2 true if Bluetooth animation desired 00606 00607 //Doc:Method 00608 bool AnimateBasebandTx(); 00609 //Doc:Desc Determine if Bluetooth transmit animation selected 00610 //Doc:Return true if Bluetooth animation selected. 00611 00612 //Doc:Method 00613 bool BasebandTxStart(); 00614 //Doc:Desc Determine if Bluetooth transmit animation started 00615 //Doc:Return true if Bluetooth animation started. 00616 00617 //Doc:Method 00618 void PauseOnWirelessTx(bool p) { pauseWirelessTx = p;} 00619 //Doc:Desc The wireless transmit animations are usually fast, 00620 //Doc:Desc and can easily 00621 //Doc:Desc be missed. Setting TRUE will pause the animation on each 00622 //Doc:Desc transmit, to allow a pause--based stepping through 00623 //Doc:Desc the tranmissions for debugging. 00624 //Doc:Arg1 TRUE if pause before each wireless transmit is desired. 00625 00626 //Doc:Method 00627 bool PauseOnWirelessTx() { return pauseWirelessTx; } 00628 //Doc:Desc Query of pauseOnWirelessTransmit is set. Used by qtwindow.cc. 00629 //Doc:Return TRUE if pause on wireless transmit set. 00630 00631 //Doc:Method 00632 bool AddBackgroundMap(const std::string&, 00633 const RectRegion& = RectRegion()); 00634 //Doc:Desc Add background map lines from the specified map file. The 00635 //Doc:Desc maps can be either in the CIA World Databank II format, 00636 //Doc:Desc or a simple file of lat/lon coordinates with a single 00637 //Doc:Desc header line specifying the number of points. The CIA 00638 //Doc:Desc database files are available on the GTNetS web page. 00639 //Doc:Arg1 Name of map database file. 00640 //Doc:Arg2 Bounding Region 00641 //Doc:Return True if successfully loaded 00642 00643 bool AddBackgroundMap(const StringVec_t&, 00644 const RectRegion& = RectRegion()); 00645 //Doc:Desc Add background map lines from the specified map files. The 00646 //Doc:Desc maps can be either in the CIA World Databank II format, 00647 //Doc:Desc or a simple file of lat/lon coordinates with a single 00648 //Doc:Desc header line specifying the number of points. The CIA 00649 //Doc:Desc database files are available on the GTNetS web page. 00650 //Doc:Arg1 Vector of map file names 00651 //Doc:Arg2 Bounding Region 00652 //Doc:Return True if successfully loaded 00653 00654 //Doc:Method 00655 bool PlaybackTraceFile(const char*); 00656 //Doc:Desc GTNetS can animate a previously run simulation, from the trace 00657 //Doc:Desc file logged by that simulation. The topology MUST be identical 00658 //Doc:Desc to that of the original simulation. 00659 //Doc:Arg1 Trace file name 00660 //Doc:Return True if trace file successfully opened 00661 00662 //Doc:Method 00663 bool StartPlayback(); 00664 //Doc:Desc Starts a trace file playback animation 00665 //Doc:Return True if successful. 00666 00667 //Doc:Method 00668 void CustomBackground(CustomBackground_t); 00669 //Doc:Desc Specifies a custom background callback 00670 //Doc:Arg1 Pointer to custom background callback function 00671 00672 //Doc:Method 00673 void NodeSelectedCallback(NodeSelected_t); 00674 //Doc:Desc Specifies a method to call when nodes are selected 00675 //Doc:Desc on the animation 00676 //Doc:Desc display. 00677 //Doc:Arg1 Callback function pointer. 00678 00679 //Doc:Method 00680 void EnableAnimationRecorder(bool); 00681 //Doc:Desc Enables or Disables the recorder icon on the animation display. 00682 //Doc:Desc Recording takes huge amounts of disk space, so we only 00683 //Doc:Desc enable this when requested. 00684 //Doc:Arg1 True if recorder icon enabled. 00685 00686 //Doc:Method 00687 void RecorderMPEGSpeedup(Mult_t); 00688 //Doc:Desc When recording the MPEG file, the normal frame rate is 25fps. 00689 //Doc:Desc However, in a network simulation, this means 40ms 00690 //Doc:Desc between frames, and is much too long to make a 00691 //Doc:Desc meaningful simulation animation. Specifying the speedup 00692 //Doc:Desc increases the frames per second rate by the specified 00693 //Doc:Desc value. For example, a speedup of 10.0 (the default value) 00694 //Doc:Desc will result in 250 fps. 00695 //Doc:Arg1 Desired animation recorder speedup. 00696 00697 //Doc:Method 00698 void EnableHTTPServer(); 00699 //Doc:Desc GTNetS has an optional HTTP interface to query the 00700 //Doc:Desc state of the simulation. Enabling this causes a 00701 //Doc:Desc separate thread to be spawned that will service 00702 //Doc:Desc HTTP request on port 8081. (If port 8081 00703 //Doc:Desc is not availble, consecutive ports are tried until 00704 //Doc:Desc one is found. 00705 00706 private: 00707 // Used internally by the Playback 00708 void FillEventsFromTrace(Time_t); 00709 00710 public: 00711 00712 // Various statistics 00713 //Doc:Method 00714 Time_t SetupTime(); // Wall clock time for initializatoin 00715 //Doc:Desc Returns the amount of wall clock (CPU) time used to initialize 00716 //Doc:Desc the simulation. This includes all actions from the start of 00717 //Doc:Desc the {\tt main} function and the call to {\tt Simulator::Run()}. 00718 //Doc:Return The CPU time used to initialize the simulation. 00719 00720 //Doc:Method 00721 Time_t RouteTime(); // Wall clock time for route computations 00722 //Doc:Desc Returns the amount of wall clock (CPU) time used to calculate 00723 //Doc:Desc routing information for the simulation. 00724 //Doc:Return The CPU time used to calculate routing information. 00725 00726 //Doc:Method 00727 Time_t RunTime(); // Wall clock time for Run() 00728 //Doc:Desc Returns the amount of wall clock (CPU) time used by 00729 //Doc:Desc the event processing phase of the simulation. 00730 //Doc:Return The CPU time used to by the event processing. 00731 00732 //Doc:Method 00733 Time_t TotalTime(); // Total time of execution 00734 //Doc:Desc Returns the amount of wall clock (CPU) time used by 00735 //Doc:Desc the simulation. 00736 //Doc:Return The CPU time used to by the entire simulation. 00737 #ifdef MOVED_TO_SCHEDULER 00738 //Doc:Method 00739 Count_t TotalEventsProcessed() { return totevp;} // Events processed 00740 //Doc:Desc Returns the count of total events processed by the simulation. 00741 //Doc:Return The total number of events processed. 00742 00743 //Doc:Method 00744 Count_t TotalEventsScheduled() { return totevs;} // Events scheduled 00745 //Doc:Desc Returns the count of total events scheduled by the simulation. 00746 //Doc:Return The total number of events scheduled. 00747 00748 //Doc:Method 00749 Count_t EventListSize() { return eventList.size();} // Number pending events 00750 //Doc:Desc Returns the current size of the event list, which is the 00751 //Doc:Desc number of scheduled, but unprocessed, events. 00752 //Doc:Return The current size of the pending events list. 00753 #endif 00754 00755 // X-Y Positions 00756 //Doc:Method 00757 void AmimationRegion(const Location&, const Location&); 00758 //Doc:Desc Specifies the lower left and upper right corner for the 00759 //Doc:Desc animation display. 00760 //Doc:Arg1 Lower left corner 00761 //Doc:Arg1 Upper right corner. 00762 00763 //Doc:Method 00764 void NewLocation(Meters_t, Meters_t); // Set new x/y location 00765 //Doc:Desc Informs the animation processor of a new location. 00766 //Doc:Desc Will expand the AnimationRegion (See above) if needed. 00767 //Doc:Arg1 x-coordinate 00768 //Doc:Arg2 y-coordinate 00769 00770 //Doc:Method 00771 void NewLocation(const Location&); // Set new x/y location 00772 //Doc:Desc Informs the animation processor of a new location. 00773 //Doc:Desc Will expand the AnimationRegion (See above) if needed. 00774 //Doc:Arg1 x-y location to add. 00775 00776 Meters_t SmallestX(); // Get the smallest X coordinate 00777 Meters_t SmallestY(); // Get the smallest Y coordinate 00778 Meters_t LargestX(); // Get the smallest X coordinate 00779 Meters_t LargestY(); // Get the smallest Y coordinate 00780 bool HasMobility() { return hasMobility;} // True if mobility enabled 00781 void HasMobility(bool m) { hasMobility = m;} 00782 00783 protected: 00784 virtual void ProgressResched(Time_t); 00785 Time_t GetSec(); // Get CPU time used (rounded to seconds) 00786 00787 bool ProcessOneMap(std::string, const RectRegion&, 00788 LocationVecVec_t&); 00789 RectRegion FindBoundingBox(LocationVecVec_t&); 00790 00791 public: 00792 bool verbose; // True if verbose debug 00793 unsigned long verbosemod; // Mod factor for verbosity 00794 bool cleanUp; // Cleanup on delete 00795 Time_t lastTopologyChange; // Time of last failure or recovery 00796 bool supercomputerInterconnect; // True if modeling SC/IC 00797 protected: 00798 Time_t simtime; // Current Simulation Time 00799 //EventMap_t eventList; // The actual event list (moved to scheduler) 00800 //EventSet_t eventList; // The actual event list 00801 public: 00802 #ifdef MOVED_TO_SCHEDULER 00803 //Doc:Member 00804 Count_t totevs; // Total events scheduled (debug) 00805 //Doc:Desc Count of the total number of events that have been scheduled 00806 00807 //Doc:Member 00808 Count_t totrm; // Total events removed (debug) 00809 //Doc:Desc Count of the total number of events that have been removed 00810 00811 //Doc:Member 00812 Count_t totevp; // Total events processed (debug) 00813 //Doc:Desc Count of the total number of event processed 00814 00815 //Doc:Member 00816 Count_t totevc; // Total events cancelled (debug) 00817 //Doc:Desc Count of total number of event cancelled 00818 00819 //Doc:Member 00820 Count_t evlSize; // Number of events in list 00821 //Doc:Desc Current size of pending event list 00822 00823 Count_t maxSize; 00824 #endif 00825 // EventMap_t::iterator hint; // Hint for insertions (right after prior) 00826 bool silent; // True if no printouts from Simulator 00827 bool halted; // True if halted 00828 protected: 00829 SimulatorUid_t uid; // Current UID 00830 Time_t progressInterval; // Interval for progress messages 00831 bool serverEnabled; // True if HTTP server enabled 00832 public: 00833 ProgressEvent* progressEvent; // Pending progress event (if any); 00834 protected: 00835 ProgressTimer progressTimer; // Progress timer 00836 Time_t startRouteTime; // CPU time used before Route computations 00837 Time_t startRunTime; // CPU time used before the "Run" call 00838 00839 QTWindow* qtWin; // qt display window 00840 bool animate; // True if animation active 00841 bool playbackAnimate; // True if animate from trace file 00842 std::ifstream playbackFile; // Input stream for playback file 00843 bool animateWirelessTx;// True if wireless tx animation desired 00844 ANIMATE_WIRELESS_TX_FORM animateWirelessTxForm; // Specifies if wireless tx animation is in the form of circles or directed arrows 00845 bool animateBasebandTx;// True if Bluetooth tx animation desired 00846 bool basebandTxStart; // True if Bluetooth tx animation started 00847 bool pauseWirelessTx; // True if pause on wireless transmit 00848 bool haltEventSched; // True if the halt event is scheduled 00849 00850 // Location min/max 00851 Meters_t smallestX; 00852 Meters_t smallestY; 00853 Meters_t largestX; 00854 Meters_t largestY; 00855 bool firstLocation; // True if first call to set location 00856 bool hasMobility; // True if any mobility models used 00857 public: 00858 static Simulator* instance; 00859 static PHVec_t progressHooks; // List of callbacks on progress 00860 static RectRegion boundingBox; // Min/Max X/Y positions 00861 static std::string simName; // Name of this simulation for display 00862 static CustomBackground_t pCustomBackground; // Custom background callback 00863 static NodeSelected_t pNodeSelected; // Node selected callback 00864 static bool recorderEnabled;// True if animation recorder icon enabled 00865 static Mult_t recorderSpeedup;// Animation recorder speedup rate 00866 00867 #ifdef CTRLFIFO 00868 static std::string name; 00869 static int sockfd; 00870 static void io_signal_handler(int); 00871 static void toBlock(int); 00872 static void toUnblock(int); 00873 #endif 00874 00875 //Doc:Method 00876 static Time_t Now(); // Returns current time (0 if no instance) 00877 //Doc:Desc Returns the current simulation time. 00878 //Doc:Return The current simulation time. 00879 00880 //Doc:Method 00881 static Size_t ReportMemoryUsage(); // Memory usage in bytes 00882 //Doc:Desc Returns the total amount of memory (bytes) used by the 00883 //Doc:Desc simulation. 00884 //Doc:Return The total number of memory bytes used by the simulation. 00885 00886 //Doc:Method 00887 static Size_t ReportMemoryUsageMB();// Memory usage in megabytes 00888 //Doc:Desc Returns the total amount of memory (MegaBbytes) used by the 00889 //Doc:Desc simulation. 00890 //Doc:Return The total number of memory MegaBytes used by the simulation. 00891 }; 00892 00893 #endif 00894 00895
1.3.9.1