00001 /* 00002 * Copyright 2004-2006 Intel Corporation 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef _NODE_H_ 00018 #define _NODE_H_ 00019 00020 #include <oasys/debug/DebugUtils.h> 00021 #include <oasys/debug/Log.h> 00022 #include <oasys/storage/DurableStore.h> 00023 00024 #include "SimEventHandler.h" 00025 #include "bundling/BundleDaemon.h" 00026 #include "storage/DTNStorageConfig.h" 00027 #include "storage/BundleStore.h" 00028 #include "storage/LinkStore.h" 00029 #include "storage/GlobalStore.h" 00030 #include "storage/ProphetStore.h" 00031 #include "storage/RegistrationStore.h" 00032 00033 using namespace dtn; 00034 00035 namespace dtn { 00036 00037 class ContactManager; 00038 00039 } 00040 00041 namespace dtnsim { 00042 00051 class Node : public SimEventHandler, public BundleDaemon { 00052 public: 00056 Node(const char* name); 00057 00061 void do_init(); 00062 00067 size_t event_queue_size() 00068 { 00069 return eventq_->size(); 00070 } 00071 00076 void configure(); 00077 00081 virtual ~Node() {} 00082 00087 virtual void post_event(BundleEvent* event, bool at_back = true); 00088 00092 virtual void process(SimEvent *e); 00093 00097 bool process_one_bundle_event(); 00098 00102 void run_one_event_now(BundleEvent* event); 00103 00107 void handle_bundle_delivered(BundleDeliveredEvent* event); 00108 void handle_bundle_received(BundleReceivedEvent* event); 00109 void handle_bundle_transmitted(BundleTransmittedEvent* event); 00110 void handle_bundle_expired(BundleExpiredEvent* event); 00111 00115 const char* name() { return name_.c_str(); } 00116 00120 BundleRouter* router() { return router_; } 00121 00130 void set_active(); 00131 00135 static Node* active_node() 00136 { 00137 return (Node*)instance_; 00138 } 00139 00143 DTNStorageConfig* storage_config() { return &storage_config_; } 00144 00145 protected: 00146 const std::string name_; 00147 u_int32_t next_bundleid_; 00148 u_int32_t next_regid_; 00149 std::queue<BundleEvent*>* eventq_; 00150 oasys::TimerSystem* timersys_; 00151 00153 DTNStorageConfig storage_config_; 00154 oasys::DurableStore* store_; 00155 BundleStore* bundle_store_; 00156 ProphetStore* prophet_store_; 00157 LinkStore* link_store_; 00158 RegistrationStore* reg_store_; 00160 }; 00161 00162 } // namespace dtnsim 00163 00164 #endif /* _NODE_H_ */