00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <string>
00026
00027 #include "TcaEndpointID.h"
00028 #include "../../servlib/routing/TcaControlBundle.h"
00029 #include "TcaRegistry.h"
00030
00031
00032 class TcaController
00033 {
00034 public:
00035
00036 enum Role { TCA_MOBILE, TCA_ROUTER, TCA_GATEWAY };
00037
00038 TcaController(Role role, const std::string& link_id,
00039 const std::string& ask_addr, const std::string& adv_str,
00040 int registry_ttl, int control_ttl);
00041
00042 virtual ~TcaController();
00043
00044
00045 bool init(bool tidy);
00046
00047
00048 void run();
00049
00050
00051 bool send_bundle(const dtn_bundle_spec_t& spec, const std::string& payload);
00052 bool recv_bundle(dtn_bundle_spec_t& spec, std::string& payload,
00053 unsigned int timeout=0);
00054
00055
00056 bool send_bundle(const std::string& dest, const std::string& payload);
00057
00058 protected:
00059
00060 Role role_;
00061 std::string link_id_;
00062 std::string ask_addr_;
00063 std::string adv_str_;
00064 int registry_ttl_;
00065 int control_ttl_;
00066
00067 TcaRegistry registry_;
00068 dtn_handle_t handle_;
00069 dtn_endpoint_id_t local_eid_;
00070
00071
00072 bool dtn_reg(dtn_endpoint_id_t& eid, dtn_reg_id_t& id);
00073
00074 bool handle_bundle_received(const dtn_bundle_spec_t& spec,
00075 const std::string& payload);
00076
00077 bool handle_reg_received(const dtn_bundle_spec_t& spec,
00078 const dtn::TcaControlBundle& cb);
00079 bool route_reg(const dtn_bundle_spec_t& spec, const dtn::TcaControlBundle& cb);
00080 bool gate_reg(const dtn_bundle_spec_t& spec, const dtn::TcaControlBundle& cb);
00081
00082 bool handle_unb(const dtn_bundle_spec_t& spec, const dtn::TcaControlBundle& cb);
00083
00084 bool handle_coa_sent(const dtn_bundle_spec_t& spec,
00085 const dtn::TcaControlBundle& cb);
00086
00087 bool handle_link_announce(const dtn_bundle_spec_t& spec,
00088 const dtn::TcaControlBundle& cb);
00089
00090 bool handle_ask(const dtn_bundle_spec_t& spec, const dtn::TcaControlBundle& cb);
00091
00092 bool handle_ask_received(const dtn_bundle_spec_t& spec,
00093 const dtn::TcaControlBundle& cb);
00094
00095 bool handle_ask_sent(const dtn_bundle_spec_t& spec,
00096 const dtn::TcaControlBundle& cb);
00097
00098 bool handle_adv(const dtn_bundle_spec_t& spec, const dtn::TcaControlBundle& cb);
00099
00100 bool handle_adv_sent(const dtn_bundle_spec_t& spec,
00101 const dtn::TcaControlBundle& cb);
00102
00103 bool handle_routes(const dtn_bundle_spec_t& spec,
00104 const dtn::TcaControlBundle& cb);
00105
00106 bool ask(const std::string& link);
00107 bool get_routes();
00108 bool add_route(const std::string& route_pattern, const std::string& link);
00109 bool del_route(const std::string& route_pattern);
00110
00111
00112
00113 bool get_registration(const TcaEndpointID& eid, RegRecord& rr);
00114
00115
00116
00117 bool do_registration(const TcaEndpointID& eid,
00118 const std::string& link_addr);
00119
00120
00121
00122
00123
00124 bool test_all();
00125
00126
00127 void eat_bundles(bool verbose = true);
00128 };
00129
00130
00131