00001 /* 00002 * Copyright 2007 Baylor University 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 _PROPHET_CONTROLLER_H_ 00018 #define _PROPHET_CONTROLLER_H_ 00019 00020 #include <string> 00021 #include <list> 00022 00023 #include "Link.h" 00024 #include "Bundle.h" 00025 #include "Alarm.h" 00026 #include "Oracle.h" 00027 #include "BundleCore.h" 00028 #include "Encounter.h" 00029 00030 namespace prophet 00031 { 00032 00033 class Controller : public Oracle, 00034 public ExpirationHandler 00035 { 00036 public: 00037 typedef std::list<Encounter*> List; 00038 00042 Controller(BundleCore* core, Repository* repository, 00043 ProphetParams* params); 00044 00048 virtual ~Controller(); 00049 00053 void new_neighbor(const Link* link); 00054 00058 void neighbor_gone(const Link* link); 00059 00063 bool accept_bundle(const Bundle* bundle); 00064 00068 void handle_bundle_received(const Bundle* b, const Link* link); 00069 00073 void handle_bundle_transmitted(const Bundle* b, const Link* link); 00074 00078 void ack(const Bundle* b); 00079 00083 void set_queue_policy(); 00084 00089 void set_hello_interval(); 00090 00095 void set_max_route(); 00096 00100 void shutdown(); 00101 00103 const ProphetParams* params() const { return params_; } 00104 Stats* stats() { return &stats_; } 00105 Table* nodes() { return &nodes_; } 00106 AckList* acks() { return &acks_; } 00107 BundleCore* core() { return core_; } 00109 00111 const List::const_iterator begin() const { return list_.begin(); } 00112 const List::const_iterator end() const { return list_.end(); } 00114 00116 size_t size() { return list_.size(); } 00117 bool empty() { return list_.empty(); } 00119 00123 void handle_timeout(); 00124 00125 protected: 00126 00130 bool find(const Link* link, List::iterator& i); 00131 00135 bool is_prophet_control(const Bundle* b) const; 00136 00137 BundleCore* core_; 00138 ProphetParams* params_; 00139 Stats stats_; 00140 u_int max_route_; 00141 Table nodes_; 00142 AckList acks_; 00143 u_int16_t next_instance_; 00144 00145 Alarm* alarm_; 00146 u_int timeout_; 00147 00148 Repository* repository_; 00149 List list_; 00150 }; // class Controller 00151 00152 }; // namespace prophet 00153 00154 #endif // _PROPHET_CONTROLLER_H_