TcaRouter.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 #ifndef _TCA_ROUTER_H_
00040 #define _TCA_ROUTER_H_
00041 
00042 #include "naming/EndpointID.h"
00043 #include "TableBasedRouter.h"
00044 
00045 #define SERVLIB 1
00046 //#include "TcaTypes.h"
00047 #include "TcaEndpointID.h"
00048 #include "TcaControlBundle.h"
00049 
00050 
00051 namespace dtn {
00052 
00053 
00070 class TcaRouter : public TableBasedRouter {
00071 
00072 public:
00073 
00074     enum Role { TCA_MOBILE, TCA_ROUTER, TCA_GATEWAY };
00075 
00076     // Internal bundle-forwarding rule.
00077     // This mostly has to do with how to treat the default route
00078     // (UDR = "Use Default Route").
00079     enum ForwardingRule {
00080         FWD_NEVER,              // do not forward, ever
00081         FWD_UDR_EXCLUSIVELY,    // forward (only) to the default route
00082         FWD_UDR_NEVER,          // fwd to matching, except default route
00083         FWD_UDR_IFNECESSARY,    // fwd to matching, using default route iff
00084                                 // no other matches
00085         FWD_UDR_ALWAYS          // forward to matching, including default route
00086         };  
00087 
00088     TcaRouter(Role role);
00089 
00090 protected:
00091 
00092     Role role_;
00093 
00094     TcaEndpointID admin_app_;   // eid of local admin application
00095     
00096     std::string get_role_str() const;
00097 
00098     // BundleEventHandler functions to handle events important to TCA.
00099     virtual void handle_bundle_received(BundleReceivedEvent* event);
00100     virtual void handle_bundle_transmitted(BundleTransmittedEvent* event);
00101     virtual void handle_contact_up(ContactUpEvent* event);
00102     virtual void handle_contact_down(ContactDownEvent* event);
00103     virtual void handle_link_available(LinkAvailableEvent* event);
00104     virtual void handle_link_unavailable(LinkUnavailableEvent* event);
00105     virtual void handle_shutdown_request(ShutdownRequest* event);
00106 
00107     // fwd function to broadcast a bundle to everybody in the route table
00108     virtual int fwd_to_all(Bundle* bundle);
00109 
00110 
00111     virtual int fwd_to_matching(Bundle* bundle, Link* next_hop = NULL);
00112 
00113     // fwd function with special forwarding rules for default route
00114     // used for forwarding unbound tca bundles and some tca control bundles
00115     virtual int fwd_to_matching_r(Bundle* bundle, Link* next_hop,
00116                                   ForwardingRule fwd_rule);
00117 
00118     bool on_coa_transmitted(Bundle* b, const TcaControlBundle& cb);
00119     bool on_ask_transmitted(Bundle* b, const TcaControlBundle& cb);
00120     bool on_adv_transmitted(Bundle* b, const TcaControlBundle& cb);
00121 
00122     // special control bundle handlers
00123     bool handle_register(Bundle* b);
00124     bool handle_coa(Bundle* b);
00125 
00126     // handle bundle sent to anonymous address
00127     bool handle_anonymous_bundle(Bundle* b);
00128 
00129     bool handle_ask(Bundle* b, const TcaControlBundle& cb);
00130 
00131     // handle control bundles addressed to bundlelayer
00132     bool handle_bl_control_bundle(Bundle* b);
00133 
00134     bool handle_bl_ask(Bundle* b, const TcaControlBundle& cb);
00135     bool handle_get_routes(Bundle* b, const TcaControlBundle& cb);
00136     bool handle_add_route(Bundle* b, const TcaControlBundle& cb);
00137     bool handle_del_route(Bundle* b, const TcaControlBundle& cb);
00138 
00139     // handle regular late-bound tca data bundle
00140     bool handle_tca_unbound_bundle(Bundle* bundle);
00141 
00142     bool on_route_unbound_bundle(Bundle* bundle);
00143     bool on_gate_unbound_bundle(Bundle* bundle);
00144 
00145     // did the bundle originate at this node?
00146     bool is_local_source(Bundle* b);
00147 
00148     ForwardingRule get_forwarding_rule(Bundle* b);
00149 
00150     // create a link entry for the given address
00151     Link* create_link(const std::string& link_addr);
00152 
00153     // create a route entry for the given endpoint pattern, specified link
00154     RouteEntry* create_route(const std::string& pattern, Link* p_link);
00155 
00156     // create a route *and link* if necessary, for the given endpoint pattern,
00157     // given link address
00158     bool create_route(const std::string& pattern,
00159                       const std::string& link_addr);
00160 
00161     // Ultra-simplified helper function to inject a new bundle into
00162     // the works, using defaults for most fields.
00163     // Specify empty src for bundlelayer
00164     bool post_bundle(const EndpointID& src, const EndpointID& dest,
00165                      const std::string& payload);
00166 
00167     // Ultra-simplified helper function to post a wrapped bundle to the
00168     // admin app. This is in lieu of a WrappedBundle class.
00169     bool push_wrapped_bundle(const std::string& code,
00170                              const EndpointID& src,
00171                              const EndpointID& dest,
00172                              const std::string& bsp);
00173 
00174 };
00175 
00176 } // namespace dtn
00177 
00178 #endif /* _TCA_ROUTER_H_ */

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