TcaController.h

Go to the documentation of this file.
00001 /*
00002  *    Copyright 2005-2006 University of Waterloo
00003  * 
00004  *    Licensed under the Apache License, Version 2.0 (the "License");
00005  *    you may not use this file except in compliance with the License.
00006  *    You may obtain a copy of the License at
00007  * 
00008  *        http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  *    Unless required by applicable law or agreed to in writing, software
00011  *    distributed under the License is distributed on an "AS IS" BASIS,
00012  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  *    See the License for the specific language governing permissions and
00014  *    limitations under the License.
00015  */
00016 
00017 
00018 //#include <stdio.h>
00019 //#include <unistd.h>
00020 //#include <errno.h>
00021 //#include <strings.h>
00022 //#include <stdlib.h>
00023 //#include <sys/time.h>
00024 
00025 #include <string>
00026 //#include "dtn_api.h"
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     // open dtn, initialize class members
00045     bool init(bool tidy);   
00046 
00047     // process incoming bundles
00048     void run();
00049 
00050     // low-level send/recv functions
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     // a more convenient send, using reasonable defaults for most args
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_;      // address to send ask to
00063     std::string             adv_str_;
00064     int                     registry_ttl_;
00065     int                     control_ttl_;
00066 
00067     TcaRegistry             registry_;      // the DHT registry (gateway only)
00068     dtn_handle_t            handle_;
00069     dtn_endpoint_id_t       local_eid_;
00070 
00071     // register an endpoint id with the daemon and bind it to handle_
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);  // experimental
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     // lookup existing registration info for the given endpoint
00113     bool get_registration(const TcaEndpointID& eid, RegRecord& rr);
00114 
00115     // update DHT registry for given endpoint
00116     // link_addr is the link addr of the endpoint's new gateway
00117     bool do_registration(const TcaEndpointID& eid,
00118                          const std::string& link_addr);
00119 
00120     // Testing functions for various parts of the protocol
00121     // These generally send a query bundle, get the response, and check
00122     // that it's correct.
00123 
00124     bool test_all();
00125     
00126     // recv and discard all pending bundles
00127     void eat_bundles(bool verbose = true);
00128 };
00129 
00130 
00131 

Generated on Thu Jun 7 16:56:52 2007 for DTN Reference Implementation by  doxygen 1.5.1