|
1 /* |
|
2 * Copyright 2005-2006 University of Waterloo |
|
3 * |
|
4 * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 * you may not use this file except in compliance with the License. |
|
6 * You may obtain a copy of the License at |
|
7 * |
|
8 * http://www.apache.org/licenses/LICENSE-2.0 |
|
9 * |
|
10 * Unless required by applicable law or agreed to in writing, software |
|
11 * distributed under the License is distributed on an "AS IS" BASIS, |
|
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 * See the License for the specific language governing permissions and |
|
14 * limitations under the License. |
|
15 */ |
|
16 |
|
17 |
|
18 //#include <stdio.h> |
|
19 //#include <unistd.h> |
|
20 //#include <errno.h> |
|
21 //#include <strings.h> |
|
22 //#include <stdlib.h> |
|
23 //#include <sys/time.h> |
|
24 |
|
25 #include <string> |
|
26 //#include "dtn_api.h" |
|
27 #include "TcaEndpointID.h" |
|
28 #include "../../servlib/routing/TcaControlBundle.h" |
|
29 #include "TcaRegistry.h" |
|
30 |
|
31 |
|
32 class TcaController |
|
33 { |
|
34 public: |
|
35 |
|
36 enum Role { TCA_MOBILE, TCA_ROUTER, TCA_GATEWAY }; |
|
37 |
|
38 TcaController(Role role, const std::string& link_id, |
|
39 const std::string& ask_addr, const std::string& adv_str, |
|
40 int registry_ttl, int control_ttl); |
|
41 |
|
42 virtual ~TcaController(); |
|
43 |
|
44 // open dtn, initialize class members |
|
45 bool init(bool tidy); |
|
46 |
|
47 // process incoming bundles |
|
48 void run(); |
|
49 |
|
50 // low-level send/recv functions |
|
51 bool send_bundle(const dtn_bundle_spec_t& spec, const std::string& payload); |
|
52 bool recv_bundle(dtn_bundle_spec_t& spec, std::string& payload, |
|
53 unsigned int timeout=0); |
|
54 |
|
55 // a more convenient send, using reasonable defaults for most args |
|
56 bool send_bundle(const std::string& dest, const std::string& payload); |
|
57 |
|
58 protected: |
|
59 |
|
60 Role role_; |
|
61 std::string link_id_; |
|
62 std::string ask_addr_; // address to send ask to |
|
63 std::string adv_str_; |
|
64 int registry_ttl_; |
|
65 int control_ttl_; |
|
66 |
|
67 TcaRegistry registry_; // the DHT registry (gateway only) |
|
68 dtn_handle_t handle_; |
|
69 dtn_endpoint_id_t local_eid_; |
|
70 |
|
71 // register an endpoint id with the daemon and bind it to handle_ |
|
72 bool dtn_reg(dtn_endpoint_id_t& eid, dtn_reg_id_t& id); |
|
73 |
|
74 bool handle_bundle_received(const dtn_bundle_spec_t& spec, |
|
75 const std::string& payload); |
|
76 |
|
77 bool handle_reg_received(const dtn_bundle_spec_t& spec, |
|
78 const dtn::TcaControlBundle& cb); |
|
79 bool route_reg(const dtn_bundle_spec_t& spec, const dtn::TcaControlBundle& cb); |
|
80 bool gate_reg(const dtn_bundle_spec_t& spec, const dtn::TcaControlBundle& cb); |
|
81 |
|
82 bool handle_unb(const dtn_bundle_spec_t& spec, const dtn::TcaControlBundle& cb); |
|
83 |
|
84 bool handle_coa_sent(const dtn_bundle_spec_t& spec, |
|
85 const dtn::TcaControlBundle& cb); |
|
86 |
|
87 bool handle_link_announce(const dtn_bundle_spec_t& spec, |
|
88 const dtn::TcaControlBundle& cb); |
|
89 |
|
90 bool handle_ask(const dtn_bundle_spec_t& spec, const dtn::TcaControlBundle& cb); |
|
91 |
|
92 bool handle_ask_received(const dtn_bundle_spec_t& spec, |
|
93 const dtn::TcaControlBundle& cb); |
|
94 |
|
95 bool handle_ask_sent(const dtn_bundle_spec_t& spec, |
|
96 const dtn::TcaControlBundle& cb); |
|
97 |
|
98 bool handle_adv(const dtn_bundle_spec_t& spec, const dtn::TcaControlBundle& cb); |
|
99 |
|
100 bool handle_adv_sent(const dtn_bundle_spec_t& spec, |
|
101 const dtn::TcaControlBundle& cb); |
|
102 |
|
103 bool handle_routes(const dtn_bundle_spec_t& spec, |
|
104 const dtn::TcaControlBundle& cb); |
|
105 |
|
106 bool ask(const std::string& link); // experimental |
|
107 bool get_routes(); |
|
108 bool add_route(const std::string& route_pattern, const std::string& link); |
|
109 bool del_route(const std::string& route_pattern); |
|
110 |
|
111 |
|
112 // lookup existing registration info for the given endpoint |
|
113 bool get_registration(const TcaEndpointID& eid, RegRecord& rr); |
|
114 |
|
115 // update DHT registry for given endpoint |
|
116 // link_addr is the link addr of the endpoint's new gateway |
|
117 bool do_registration(const TcaEndpointID& eid, |
|
118 const std::string& link_addr); |
|
119 |
|
120 // Testing functions for various parts of the protocol |
|
121 // These generally send a query bundle, get the response, and check |
|
122 // that it's correct. |
|
123 |
|
124 bool test_all(); |
|
125 |
|
126 // recv and discard all pending bundles |
|
127 void eat_bundles(bool verbose = true); |
|
128 }; |
|
129 |
|
130 |
|
131 |