00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _TABLE_BASED_ROUTER_H_
00018 #define _TABLE_BASED_ROUTER_H_
00019
00020 #include <oasys/util/StringUtils.h>
00021
00022 #include "BundleRouter.h"
00023 #include "RouterInfo.h"
00024 #include "bundling/BundleInfoCache.h"
00025 #include "reg/Registration.h"
00026 #include "session/SessionTable.h"
00027
00028 namespace dtn {
00029
00030 class BundleList;
00031 class RouteEntryVec;
00032 class RouteTable;
00033
00038 class TableBasedRouter : public BundleRouter {
00039 protected:
00044 TableBasedRouter(const char* classname, const std::string& name);
00045
00049 virtual ~TableBasedRouter();
00050
00056 virtual void handle_event(BundleEvent* event);
00057
00059 virtual void handle_bundle_received(BundleReceivedEvent* event);
00060 virtual void handle_bundle_transmitted(BundleTransmittedEvent* event);
00061 virtual void handle_bundle_cancelled(BundleSendCancelledEvent* event);
00062 virtual void handle_route_add(RouteAddEvent* event);
00063 virtual void handle_route_del(RouteDelEvent* event);
00064 virtual void handle_contact_up(ContactUpEvent* event);
00065 virtual void handle_contact_down(ContactDownEvent* event);
00066 virtual void handle_link_available(LinkAvailableEvent* event);
00067 virtual void handle_link_created(LinkCreatedEvent* event);
00068 virtual void handle_link_deleted(LinkDeletedEvent* event);
00069 virtual void handle_custody_timeout(CustodyTimeoutEvent* event);
00070 virtual void handle_registration_added(RegistrationAddedEvent* event);
00071 virtual void handle_registration_removed(RegistrationRemovedEvent* event);
00072 virtual void handle_registration_expired(RegistrationExpiredEvent* event);
00074
00075
00077 Session* get_session_for_bundle(Bundle* bundle);
00078 bool add_bundle_to_session(Bundle* bundle, Session* session);
00079 bool subscribe_to_session(int action, Session* session);
00080
00081 bool find_session_upstream(Session* session);
00082 void reroute_all_sessions();
00083
00084 bool handle_session_bundle(BundleReceivedEvent* event);
00085 void add_subscriber(Session* session,
00086 const EndpointID& peer,
00087 const SequenceID& known_seqid);
00089
00093 void get_routing_state(oasys::StringBuffer* buf);
00094
00098 void tcl_dump_state(oasys::StringBuffer* buf);
00099
00103 void add_route(RouteEntry *entry);
00104
00108 void del_route(const EndpointIDPattern& id);
00109
00113 void handle_changed_routes();
00114
00118 virtual bool fwd_to_nexthop(Bundle* bundle, RouteEntry* route);
00119
00127 virtual bool should_fwd(const Bundle* bundle, RouteEntry* route);
00128
00139 virtual int route_bundle(Bundle* bundle);
00140
00146 virtual void sort_routes(Bundle* bundle, RouteEntryVec* routes);
00147
00156 virtual void check_next_hop(const LinkRef& next_hop);
00157
00161 virtual void reroute_all_bundles();
00162
00167 virtual void recompute_routes();
00168
00173 void add_nexthop_route(const LinkRef& link);
00174
00178 bool can_delete_bundle(const BundleRef& bundle);
00179
00183 void delete_bundle(const BundleRef& bundle);
00184
00188 void remove_from_deferred(const BundleRef& bundle, int actions);
00189
00191 BundleInfoCache reception_cache_;
00192
00194 RouteTable* route_table_;
00195
00197 SessionTable sessions_;
00198
00200 RegistrationList session_custodians_;
00201
00204 class RerouteTimer : public oasys::Timer {
00205 public:
00206 RerouteTimer(TableBasedRouter* router, const LinkRef& link)
00207 : router_(router), link_(link) {}
00208 virtual ~RerouteTimer() {}
00209
00210 void timeout(const struct timeval& now);
00211
00212 protected:
00213 TableBasedRouter* router_;
00214 LinkRef link_;
00215 };
00216
00217 friend class RerouteTimer;
00218
00220 void reroute_bundles(const LinkRef& link);
00221
00223 typedef oasys::StringMap<RerouteTimer*> RerouteTimerMap;
00224 RerouteTimerMap reroute_timers_;
00225
00228 class DeferredList : public RouterInfo, public oasys::Logger {
00229 public:
00230 DeferredList(const char* logpath, const LinkRef& link);
00231
00233 BundleList* list() { return &list_; }
00234
00237 const ForwardingInfo& info(const BundleRef& bundle);
00238
00241 bool find(const BundleRef& bundle, ForwardingInfo* info);
00242
00244 bool add(const BundleRef& bundle, const ForwardingInfo& info);
00245
00248 bool del(const BundleRef& bundle);
00249
00251 void dump_stats(oasys::StringBuffer* buf);
00252
00253 protected:
00254 typedef std::map<u_int32_t, ForwardingInfo> InfoMap;
00255 BundleList list_;
00256 InfoMap info_;
00257 size_t count_;
00258 };
00259
00261 DeferredList* deferred_list(const LinkRef& link);
00262
00264 class ResubscribeTimer : public oasys::Timer {
00265 public:
00266 ResubscribeTimer(TableBasedRouter* router, Session* session);
00267 virtual void timeout(const struct timeval& now);
00268
00269 TableBasedRouter* router_;
00270 Session* session_;
00271 };
00272 };
00273
00274 }
00275
00276 #endif