sim/Node.h
changeset 0 2b3e5ec03512
equal deleted inserted replaced
-1:000000000000 0:2b3e5ec03512
       
     1 /*
       
     2  *    Copyright 2004-2006 Intel Corporation
       
     3  * 
       
     4  *    Licensed under the Apache License, Version 2.0 (the "License");
       
     5  *    you may not use this file except in compliance with the License.
       
     6  *    You may obtain a copy of the License at
       
     7  * 
       
     8  *        http://www.apache.org/licenses/LICENSE-2.0
       
     9  * 
       
    10  *    Unless required by applicable law or agreed to in writing, software
       
    11  *    distributed under the License is distributed on an "AS IS" BASIS,
       
    12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       
    13  *    See the License for the specific language governing permissions and
       
    14  *    limitations under the License.
       
    15  */
       
    16 
       
    17 #ifndef _NODE_H_
       
    18 #define _NODE_H_
       
    19 
       
    20 #include <oasys/debug/DebugUtils.h>
       
    21 #include <oasys/debug/Log.h>
       
    22 #include <oasys/storage/DurableStore.h>
       
    23 
       
    24 #include "SimEventHandler.h"
       
    25 #include "bundling/BundleDaemon.h"
       
    26 #include "storage/DTNStorageConfig.h"
       
    27 #include "storage/BundleStore.h"
       
    28 #include "storage/LinkStore.h"
       
    29 #include "storage/GlobalStore.h"
       
    30 #include "storage/ProphetStore.h"
       
    31 #include "storage/RegistrationStore.h"
       
    32 
       
    33 using namespace dtn;
       
    34 
       
    35 namespace dtn {
       
    36 
       
    37 class ContactManager;
       
    38 
       
    39 }
       
    40 
       
    41 namespace dtnsim {
       
    42 
       
    43 /**
       
    44  * Class representing a node in the simulator (i.e. a router plus
       
    45  * associated links, etc).
       
    46  *
       
    47  * Derives from the core dtn BundleDaemon and whenever an event is
       
    48  * processed that relates to a node, that node is installed as the
       
    49  * BundleDaemon::instance().
       
    50  */
       
    51 class Node : public SimEventHandler, public BundleDaemon {
       
    52 public:
       
    53     /**
       
    54      * Constructor
       
    55      */
       
    56     Node(const char* name);
       
    57 
       
    58     /**
       
    59      * Virtual initialization function.
       
    60      */
       
    61     void do_init();
       
    62 
       
    63     /**
       
    64      * Override of BundleDaemon::event_queue_size since eventq_ is
       
    65      * shadowed to be a simple std::queue instead of a MsgQueue.
       
    66      */
       
    67     size_t event_queue_size()
       
    68     {
       
    69     	return eventq_->size();
       
    70     }
       
    71     
       
    72     /**
       
    73      * Second pass at initialization, called by the simulator once the
       
    74      * whole config has been parsed.
       
    75      */
       
    76     void configure();
       
    77 
       
    78     /**
       
    79      * Destructor
       
    80      */
       
    81     virtual ~Node() {}
       
    82         
       
    83     /**
       
    84      * Virtual post function, overridden in the simulator to use the
       
    85      * modified event queue.
       
    86      */
       
    87     virtual void post_event(BundleEvent* event, bool at_back = true);
       
    88     
       
    89     /**
       
    90      * Virtual function from SimEventHandler
       
    91      */
       
    92     virtual void process(SimEvent *e);
       
    93 
       
    94     /**
       
    95      * Drain and process a bundle event from the queue, if one exists.
       
    96      */
       
    97     bool process_one_bundle_event();
       
    98 
       
    99     /**
       
   100      * Run the given event immediately.
       
   101      */
       
   102     void run_one_event_now(BundleEvent* event);
       
   103 
       
   104     /**
       
   105      * Overridden event handlers from BundleDaemon
       
   106      */
       
   107     void handle_bundle_delivered(BundleDeliveredEvent* event);
       
   108     void handle_bundle_received(BundleReceivedEvent* event);
       
   109     void handle_bundle_transmitted(BundleTransmittedEvent* event);
       
   110     void handle_bundle_expired(BundleExpiredEvent* event);
       
   111     
       
   112     /**
       
   113      * Accessor for name.
       
   114      */
       
   115     const char* name() { return name_.c_str(); }
       
   116     
       
   117     /**
       
   118      * Accessor for router.
       
   119      */
       
   120     BundleRouter* router() { return router_; }
       
   121 
       
   122     /**
       
   123      * Set the node as the "active" node in the simulation. This
       
   124      * swings the static instance_ pointers to point to the node and
       
   125      * its state so all singleton accesses throughout the code will
       
   126      * reference the correct object(s).
       
   127      *
       
   128      * It also sets the node name as the logging prefix in oasys.
       
   129      */
       
   130     void set_active();
       
   131 
       
   132     /**
       
   133      * Return the current active node.
       
   134      */
       
   135     static Node* active_node()
       
   136     {
       
   137         return (Node*)instance_;
       
   138     }
       
   139 
       
   140     /**
       
   141      * Accessor for the storage config at this node.
       
   142      */
       
   143     DTNStorageConfig* storage_config() { return &storage_config_; }
       
   144 
       
   145 protected:
       
   146     const std::string   name_;
       
   147     u_int32_t		next_bundleid_;
       
   148     u_int32_t		next_regid_;
       
   149     std::queue<BundleEvent*>* eventq_;
       
   150     oasys::TimerSystem* timersys_;
       
   151 
       
   152     /// @{ Fake-Durable storage
       
   153     DTNStorageConfig     storage_config_;
       
   154     oasys::DurableStore* store_;
       
   155     BundleStore*         bundle_store_;
       
   156     ProphetStore*        prophet_store_;
       
   157     LinkStore*           link_store_;
       
   158     RegistrationStore*   reg_store_;
       
   159     /// @}
       
   160 };
       
   161 
       
   162 } // namespace dtnsim
       
   163 
       
   164 #endif /* _NODE_H_ */