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

Generated on Thu Jun 7 12:54:29 2007 for DTN Reference Implementation by  doxygen 1.5.1