00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef _ECLMODULE_H_
00017 #define _ECLMODULE_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 <semaphore.h>
00026 #include <string>
00027 #include <list>
00028 #include <ext/hash_map>
00029
00030 #include <oasys/thread/Thread.h>
00031 #include <oasys/thread/Mutex.h>
00032 #include <oasys/thread/MsgQueue.h>
00033 #include <oasys/io/TCPClient.h>
00034 #include <oasys/serialize/XercesXMLSerialize.h>
00035
00036 #include "ExternalConvergenceLayer.h"
00037 #include "CLEventHandler.h"
00038 #include "clevent.h"
00039
00040 #define POST_MESSAGE(module_ptr, message_name, message) do { \
00041 cl_message* container = new cl_message(); \
00042 container->message_name(message); \
00043 module_ptr->post_message(container); \
00044 } while (false);
00045
00046 namespace dtn {
00047
00048 using __gnu_cxx::hash_multimap;
00049 using __gnu_cxx::hash;
00050
00051
00057 class ECLModule : public CLInfo,
00058 public CLEventHandler,
00059 public oasys::Thread {
00060
00061
00062 friend class ExternalConvergenceLayer;
00063
00064 public:
00073 ECLModule(int fd, in_addr_t remote_addr, u_int16_t remote_port,
00074 ExternalConvergenceLayer& cl);
00075 virtual ~ECLModule();
00076
00077 virtual void run();
00078
00079
00085 void post_message(cl_message* message);
00086
00087
00094 void take_resource(ECLResource* resource);
00095
00111 void shutdown();
00112
00127 ECLInterfaceResource* remove_interface(const std::string& name);
00128
00129
00133 const std::string& name() const { return name_; }
00134
00135 protected:
00136 void handle(const cla_add_request& message);
00137 void handle(const cla_delete_request& message);
00138 void handle(const cla_params_set_event& message);
00139 void handle(const interface_created_event& message);
00140 void handle(const interface_reconfigured_event& message);
00141 void handle(const eid_reachable_event& message);
00142 void handle(const link_created_event& message);
00143 void handle(const link_opened_event& message);
00144 void handle(const link_closed_event& message);
00145 void handle(const link_state_changed_event& message);
00146 void handle(const link_deleted_event& message);
00147 void handle(const link_attribute_changed_event& message);
00148 void handle(const link_add_reachable_event& message);
00149 void handle(const contact_attribute_changed_event& message);
00150 void handle(const bundle_transmitted_event& message);
00151 void handle(const bundle_canceled_event& message);
00152 void handle(const bundle_receive_started_event& message);
00153 void handle(const bundle_received_event& message);
00154 void handle(const report_eid_reachable& message);
00155 void handle(const report_link_attributes& message);
00156 void handle(const report_interface_attributes& message);
00157 void handle(const report_cla_parameters& message);
00158
00161 void take_resources();
00162
00165 bool link_exists(const std::string& name) const;
00166
00167 private:
00169 static const size_t READ_BUFFER_SIZE = 256;
00170
00173 static const size_t MAX_BUNDLE_IN_MEMORY = (256 * 1024);
00174
00189 void read_bundle_file(const std::string& location, const std::string& peer_eid);
00190
00200 void read_cycle();
00201
00212 int send_message(const cl_message* message);
00213
00223 int prepare_bundle_to_send(cl_message* message);
00224
00225
00243 void bundle_send_failed(ECLLinkResource* link_resource,
00244 Bundle* bundle,
00245 bool erase_from_list);
00246
00253 ECLInterfaceResource* get_interface(const std::string& name) const;
00254
00255
00262 ECLLinkResource* get_link(const std::string& name) const;
00263
00264
00282 ECLLinkResource* create_discovered_link(const std::string& peer_eid,
00283 const std::string& nexthop,
00284 const std::string& link_name);
00285
00295 void cleanup();
00296
00297 static void update_contact_attributes(const contact_attributes& attributes,
00298 const ContactRef& contact);
00299
00301 std::string name_;
00302
00304 std::string bundle_in_path_;
00305
00307 std::string bundle_out_path_;
00308
00311 bool was_shutdown_;
00312
00314 char read_buffer_[READ_BUFFER_SIZE];
00315
00317 std::vector<char> msg_buffer_;
00318
00320 ExternalConvergenceLayer& cl_;
00321
00323 struct IncomingBundleRecord {
00324 std::string location;
00325 std::string peer_eid;
00326 };
00327
00330 std::list<IncomingBundleRecord> incoming_bundle_list_;
00331
00333 std::list<ECLInterfaceResource*> iface_list_;
00334
00336 oasys::Mutex iface_list_lock_;
00337
00339 LinkHashMap link_list_;
00340
00344 mutable sem_t link_list_sem_;
00345
00347 oasys::TCPClient socket_;
00348
00350 oasys::MsgQueue<cl_message*> message_queue_;
00351
00353 oasys::XercesXMLUnmarshal parser_;
00354 };
00355
00356 }
00357
00358 #endif // XERCES_C_ENABLED && EXTERNAL_CL_ENABLED
00359 #endif // _ECLMODULE_H_