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
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 #include <string>
00047
00048 #include "TcaEndpointID.h"
00049 #include "../../servlib/routing/TcaControlBundle.h"
00050 #include "TcaRegistry.h"
00051
00052
00053 class TcaController
00054 {
00055 public:
00056
00057 enum Role { TCA_MOBILE, TCA_ROUTER, TCA_GATEWAY };
00058
00059 TcaController(Role role, const std::string& link_id,
00060 const std::string& ask_addr, const std::string& adv_str,
00061 int registry_ttl, int control_ttl);
00062
00063 virtual ~TcaController();
00064
00065
00066 bool init(bool tidy);
00067
00068
00069 void run();
00070
00071
00072 bool send_bundle(const dtn_bundle_spec_t& spec, const std::string& payload);
00073 bool recv_bundle(dtn_bundle_spec_t& spec, std::string& payload,
00074 unsigned int timeout=0);
00075
00076
00077 bool send_bundle(const std::string& dest, const std::string& payload);
00078
00079 protected:
00080
00081 Role role_;
00082 std::string link_id_;
00083 std::string ask_addr_;
00084 std::string adv_str_;
00085 int registry_ttl_;
00086 int control_ttl_;
00087
00088 TcaRegistry registry_;
00089 dtn_handle_t handle_;
00090 dtn_endpoint_id_t local_eid_;
00091
00092
00093 bool dtn_reg(dtn_endpoint_id_t& eid, dtn_reg_id_t& id);
00094
00095 bool handle_bundle_received(const dtn_bundle_spec_t& spec,
00096 const std::string& payload);
00097
00098 bool handle_reg_received(const dtn_bundle_spec_t& spec,
00099 const TcaControlBundle& cb);
00100 bool route_reg(const dtn_bundle_spec_t& spec, const TcaControlBundle& cb);
00101 bool gate_reg(const dtn_bundle_spec_t& spec, const TcaControlBundle& cb);
00102
00103 bool handle_unb(const dtn_bundle_spec_t& spec, const TcaControlBundle& cb);
00104
00105 bool handle_coa_sent(const dtn_bundle_spec_t& spec,
00106 const TcaControlBundle& cb);
00107
00108 bool handle_link_announce(const dtn_bundle_spec_t& spec,
00109 const TcaControlBundle& cb);
00110
00111 bool handle_ask(const dtn_bundle_spec_t& spec, const TcaControlBundle& cb);
00112
00113 bool handle_ask_received(const dtn_bundle_spec_t& spec,
00114 const TcaControlBundle& cb);
00115
00116 bool handle_ask_sent(const dtn_bundle_spec_t& spec,
00117 const TcaControlBundle& cb);
00118
00119 bool handle_adv(const dtn_bundle_spec_t& spec, const TcaControlBundle& cb);
00120
00121 bool handle_adv_sent(const dtn_bundle_spec_t& spec,
00122 const TcaControlBundle& cb);
00123
00124 bool handle_routes(const dtn_bundle_spec_t& spec,
00125 const TcaControlBundle& cb);
00126
00127 bool ask(const std::string& link);
00128 bool get_routes();
00129 bool add_route(const std::string& route_pattern, const std::string& link);
00130 bool del_route(const std::string& route_pattern);
00131
00132
00133
00134 bool get_registration(const TcaEndpointID& eid, RegRecord& rr);
00135
00136
00137
00138 bool do_registration(const TcaEndpointID& eid,
00139 const std::string& link_addr);
00140
00141
00142
00143
00144
00145 bool test_all();
00146
00147
00148 void eat_bundles(bool verbose = true);
00149 };
00150
00151
00152