00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef _EXTERNAL_CONVERGENCE_LAYER_H_
00017 #define _EXTERNAL_CONVERGENCE_LAYER_H_
00018
00019 #ifndef DTN_CONFIG_STATE
00020 #error "MUST INCLUDE dtn-config.h before including this file"
00021 #endif
00022
00023 #if defined(XERCES_C_ENABLED) && defined(EXTERNAL_CL_ENABLED)
00024
00025 #include <string>
00026 #include <list>
00027 #include <ext/hash_map>
00028
00029 #include <oasys/thread/Thread.h>
00030 #include <oasys/thread/Mutex.h>
00031 #include <oasys/io/TCPServer.h>
00032
00033 #include "ConvergenceLayer.h"
00034 #include "clevent.h"
00035 #include "bundling/BundleList.h"
00036 #include "bundling/BundleEvent.h"
00037 #include "contacts/NamedAttribute.h"
00038
00039 class dtn::clmessage::bundle_attributes;
00040 class dtn::clmessage::link_config_parameters;
00041
00042 namespace dtn {
00043
00044 using __gnu_cxx::hash_multimap;
00045 using __gnu_cxx::hash;
00046
00047 class Interface;
00048 class Contact;
00049 class ECLModule;
00050
00051 typedef ::xsd::cxx::tree::sequence<clmessage::key_value_pair> KeyValueSequence;
00052
00060 class ECLResource : public CLInfo {
00061 public:
00062 virtual ~ECLResource() {
00063 delete create_message_;
00064 }
00065
00067 std::string protocol_;
00068
00071 clmessage::cl_message* create_message_;
00072
00075 ECLModule* module_;
00076
00077 oasys::Mutex lock_;
00078
00079 bool should_delete_;
00080
00081 protected:
00082 ECLResource(std::string p, clmessage::cl_message* create) :
00083 lock_("ECLResource") {
00084 protocol_ = p;
00085 create_message_ = create;
00086 module_ = NULL;
00087 should_delete_ = true;
00088 }
00089 };
00090
00091
00094 class ECLInterfaceResource : public ECLResource {
00095 public:
00096 ECLInterfaceResource(std::string p, clmessage::cl_message* create,
00097 Interface* i) : ECLResource(p, create) {
00098 interface_ = i;
00099 }
00100
00101 Interface* interface_;
00102 };
00103
00104
00107 class ECLLinkResource : public ECLResource {
00108 public:
00109 ECLLinkResource(std::string p, clmessage::cl_message* create,
00110 const LinkRef& l, bool disc);
00111
00113 LinkRef link_;
00114
00118 Link::state_t known_state_;
00119
00121 bool is_discovered_;
00122
00123
00129 void add_outgoing_bundle(Bundle* bundle);
00130
00131
00139 BundleRef get_outgoing_bundle(clmessage::bundle_attributes bundle_attribs);
00140
00141 bool has_outgoing_bundle(Bundle* bundle);
00142
00143
00148 bool erase_outgoing_bundle(Bundle* bundle);
00149
00150
00155 BundleList& get_bundle_set();
00156
00159 void set_high_water_mark(int high_water_mark) {
00160 high_water_mark_ = high_water_mark;
00161 }
00162
00168 bool high_water_mark_crossed(int queued_bytes) const {
00169 return (high_water_mark_ > 0 && queued_bytes >= high_water_mark_);
00170 }
00171
00174 void set_low_water_mark(int low_water_mark) {
00175 low_water_mark_ = low_water_mark;
00176 }
00177
00183 bool low_water_mark_crossed(int queued_bytes) const {
00184 return (queued_bytes <= low_water_mark_);
00185 }
00186
00187 private:
00189 BundleList outgoing_bundles_;
00190
00192 int high_water_mark_;
00193
00195 int low_water_mark_;
00196 };
00197
00198
00201 struct StringHash {
00202 size_t operator()(std::string s) const {
00203 size_t h = 0;
00204 for (unsigned i = 0; i < s.length(); ++i)
00205 h = h * 5 + s[i];
00206
00207 return h;
00208 }
00209 };
00210
00211 typedef hash_multimap<std::string, ECLLinkResource*, StringHash>
00212 LinkHashMap;
00213
00214
00229 class ExternalConvergenceLayer : public ConvergenceLayer {
00230 public:
00231 ExternalConvergenceLayer();
00232 ~ExternalConvergenceLayer();
00233
00239 void start();
00240
00241 bool set_cla_parameters(AttributeVector ¶ms);
00242 bool set_interface_defaults(int argc, const char* argv[],
00243 const char** invalidp);
00244 bool interface_up(Interface* iface, int argc, const char* argv[]);
00245 bool interface_down(Interface* iface);
00246 void dump_interface(Interface* iface, oasys::StringBuffer* buf);
00247 bool set_link_defaults(int argc, const char* argv[], const char** invalidp);
00248 bool init_link(const LinkRef& link, int argc, const char* argv[]);
00249 void delete_link(const LinkRef& link);
00250 void dump_link(const LinkRef& link, oasys::StringBuffer* buf);
00251 bool reconfigure_link(const LinkRef& link, int argc, const char* argv[]);
00252 void reconfigure_link(const LinkRef& link, AttributeVector& params);
00253 bool open_contact(const ContactRef& contact);
00254 bool close_contact(const ContactRef& contact);
00255 void bundle_queued(const LinkRef& link, const BundleRef& bundle);
00256 void cancel_bundle(const LinkRef& link, const BundleRef& bundle);
00257 bool is_queued(const LinkRef& link, Bundle* bundle);
00258 void is_eid_reachable(const std::string& query_id, Interface* iface,
00259 const std::string& endpoint);
00260 void query_link_attributes(const std::string& query_id,const LinkRef& link,
00261 const AttributeNameVector& attributes);
00262 void query_iface_attributes(const std::string& query_id, Interface* iface,
00263 const AttributeNameVector& attributes);
00264 void query_cla_parameters(const std::string& query_id,
00265 const AttributeNameVector& parameters);
00266 void shutdown();
00267
00268
00281 std::list<ECLResource*> take_resources(std::string protocol);
00282
00283
00289 void give_resources(std::list<ECLInterfaceResource*>& list);
00290
00291
00297 void give_resources(LinkHashMap& list);
00298
00299
00305 void delete_resource(ECLResource* resource);
00306
00307
00310 void add_module(ECLModule* module);
00311
00312
00315 void remove_module(ECLModule* module);
00316
00317
00324 ECLModule* get_module(const std::string& protocol);
00325
00328 static std::string schema_;
00329
00330 static bool client_validation_;
00331
00334 static in_addr_t server_addr_;
00335
00338 static u_int16_t server_port_;
00339
00340 static bool create_discovered_links_;
00341
00342 static bool discovered_prev_hop_header_;
00343
00346 static xml_schema::namespace_infomap namespace_map_;
00347
00348
00351 oasys::Mutex global_resource_lock_;
00352
00353
00354 private:
00362 class Listener : public oasys::TCPServerThread {
00363 public:
00364 Listener(ExternalConvergenceLayer& cl);
00365 virtual ~Listener();
00366
00367 void start();
00368 virtual void accepted(int fd, in_addr_t addr, u_int16_t port);
00369
00370 private:
00372 ExternalConvergenceLayer& cl_;
00373 };
00374
00375
00378 void add_resource(ECLResource* resource);
00379
00390 void build_param_sequence(int argc, const char* argv[],
00391 KeyValueSequence& param_sequence);
00392
00398 void fill_bundle_attributes(const BundleRef& bundle,
00399 clmessage::bundle_attributes& attribs);
00400
00402 std::list<ECLModule*> module_list_;
00403
00405 oasys::Mutex module_mutex_;
00406
00408 std::list<ECLResource*> resource_list_;
00409
00411 oasys::Mutex resource_mutex_;
00412
00414 Listener listener_;
00415 };
00416
00417
00421 class XMLConvert {
00422 public:
00423 static clmessage::linkTypeType convert_link_type(Link::link_type_t type);
00424 static Link::link_type_t convert_link_type(clmessage::linkTypeType type);
00425
00426 static Link::state_t convert_link_state(clmessage::linkStateType state);
00427
00428 static ContactEvent::reason_t convert_link_reason(
00429 clmessage::linkReasonType reason);
00430 };
00431
00432 }
00433
00434 #endif // XERCES_C_ENABLED && EXTERNAL_CL_ENABLED
00435 #endif // _EXTERNAL_CONVERGENCE_LAYER_H_
00436