TcaController.h

Go to the documentation of this file.
00001 /*
00002  * IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By
00003  * downloading, copying, installing or using the software you agree to
00004  * this license. If you do not agree to this license, do not download,
00005  * install, copy or use the software.
00006  * 
00007  * University of Waterloo Open Source License
00008  * 
00009  * Copyright (c) 2005 University of Waterloo. All rights reserved. 
00010  * 
00011  * Redistribution and use in source and binary forms, with or without
00012  * modification, are permitted provided that the following conditions are
00013  * met:
00014  * 
00015  *   Redistributions of source code must retain the above copyright
00016  *   notice, this list of conditions and the following disclaimer.
00017  * 
00018  *   Redistributions in binary form must reproduce the above copyright
00019  *   notice, this list of conditions and the following disclaimer in the
00020  *   documentation and/or other materials provided with the distribution.
00021  *  
00022  *   Neither the name of the University of Waterloo nor the names of its
00023  *   contributors may be used to endorse or promote products derived from
00024  *   this software without specific prior written permission.
00025  *  
00026  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00027  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00028  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00029  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY
00030  * OF WATERLOO OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00031  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00032  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
00033  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00034  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
00035  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00036  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037  */
00038 
00039 //#include <stdio.h>
00040 //#include <unistd.h>
00041 //#include <errno.h>
00042 //#include <strings.h>
00043 //#include <stdlib.h>
00044 //#include <sys/time.h>
00045 
00046 #include <string>
00047 //#include "dtn_api.h"
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     // open dtn, initialize class members
00066     bool init(bool tidy);   
00067 
00068     // process incoming bundles
00069     void run();
00070 
00071     // low-level send/recv functions
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     // a more convenient send, using reasonable defaults for most args
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_;      // address to send ask to
00084     std::string             adv_str_;
00085     int                     registry_ttl_;
00086     int                     control_ttl_;
00087 
00088     TcaRegistry             registry_;      // the DHT registry (gateway only)
00089     dtn_handle_t            handle_;
00090     dtn_endpoint_id_t       local_eid_;
00091 
00092     // register an endpoint id with the daemon and bind it to handle_
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);  // experimental
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     // lookup existing registration info for the given endpoint
00134     bool get_registration(const TcaEndpointID& eid, RegRecord& rr);
00135 
00136     // update DHT registry for given endpoint
00137     // link_addr is the link addr of the endpoint's new gateway
00138     bool do_registration(const TcaEndpointID& eid,
00139                          const std::string& link_addr);
00140 
00141     // Testing functions for various parts of the protocol
00142     // These generally send a query bundle, get the response, and check
00143     // that it's correct.
00144 
00145     bool test_all();
00146     
00147     // recv and discard all pending bundles
00148     void eat_bundles(bool verbose = true);
00149 };
00150 
00151 
00152 

Generated on Fri Dec 22 14:48:00 2006 for DTN Reference Implementation by  doxygen 1.5.1