00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _DTLSR_ROUTER_H_
00018 #define _DTLSR_ROUTER_H_
00019
00020 #include "DTLSR.h"
00021 #include "DTLSRConfig.h"
00022
00023 #include "BundleRouter.h"
00024 #include "MultiGraph.h"
00025 #include "TableBasedRouter.h"
00026 #include "RouteEntry.h"
00027 #include "reg/Registration.h"
00028
00029 namespace dtn {
00030
00037 class DTLSRRouter : public TableBasedRouter {
00038 public:
00040 DTLSRRouter();
00041
00043 void initialize();
00044 void get_routing_state(oasys::StringBuffer* buf);
00045 bool can_delete_bundle(const BundleRef& bundle);
00046 void delete_bundle(const BundleRef& bundle);
00048
00050 void handle_bundle_received(BundleReceivedEvent* e);
00051 void handle_bundle_expired(BundleExpiredEvent* e);
00052 void handle_contact_up(ContactUpEvent* e);
00053 void handle_contact_down(ContactDownEvent* e);
00054 void handle_link_created(LinkCreatedEvent* e);
00055 void handle_link_deleted(LinkDeletedEvent* e);
00056 void handle_registration_added(RegistrationAddedEvent* event);
00058
00059 protected:
00061 class NodeInfo;
00062 class EdgeInfo;
00063 typedef MultiGraph<NodeInfo, EdgeInfo> RoutingGraph;
00064 friend class oasys::InlineFormatter<EdgeInfo>;
00065 class CostWeightFn;
00066 class DelayWeightFn;
00067 class EstimatedDelayWeightFn;
00068 typedef DTLSR::LinkParams LinkParams;
00069 typedef DTLSR::LinkState LinkState;
00070 typedef DTLSR::LinkStateVec LinkStateVec;
00071 typedef DTLSR::LSA LSA;
00073
00074
00076 struct NodeInfo {
00077 NodeInfo()
00078 : last_lsa_seqno_(0),
00079 last_lsa_creation_ts_(0),
00080 last_eida_seqno_(0) {}
00081
00082 u_int32_t last_lsa_seqno_;
00083 u_int32_t last_lsa_creation_ts_;
00084
00085 u_int32_t last_eida_seqno_;
00086
00087
00088 };
00089
00090
00092 struct EdgeInfo {
00093 EdgeInfo(const std::string& id)
00094 : id_(id), params_(), is_registration_(false) {}
00095 EdgeInfo(const std::string& id, const LinkParams& params)
00096 : id_(id), params_(params), is_registration_(false) {}
00097
00098 bool operator==(const EdgeInfo& other) const {
00099 return id_ == other.id_;
00100 }
00101
00102 std::string id_;
00103 LinkParams params_;
00104 oasys::Time last_update_;
00105 bool is_registration_;
00106 };
00107
00108
00110 struct RouteInfo : public RouteEntryInfo {
00111 RouteInfo(RoutingGraph::Edge* e) : edge_(e) {}
00112 RoutingGraph::Edge* edge_;
00113 };
00114
00115
00117 class Reg : public Registration {
00118 public:
00119 Reg(DTLSRRouter* router, const EndpointIDPattern& eid);
00120 void deliver_bundle(Bundle* bundle);
00121 protected:
00122 DTLSRRouter* router_;
00123 };
00124
00125
00126 class TransmitLSATimer : public oasys::Timer {
00127 public:
00128 TransmitLSATimer(DTLSRRouter* router)
00129 : router_(router), interval_(0) {}
00130 void timeout(const struct timeval& now);
00131 void set_interval(int interval) { interval_ = interval; }
00132
00133 protected:
00134 DTLSRRouter* router_;
00135 int interval_;
00136 };
00137
00139 const DTLSRConfig* config() { return DTLSRConfig::instance(); }
00140 void generate_link_state(LinkState* ls,
00141 RoutingGraph::Edge* e,
00142 const LinkRef& link);
00143 bool update_current_lsa(RoutingGraph::Node* node,
00144 Bundle* bundle, u_int32_t seqno);
00145 void schedule_lsa();
00146 void send_lsa();
00147 void handle_lsa(Bundle* bundle, LSA* lsa);
00148 void handle_lsa_expired(Bundle* bundle);
00149 void drop_all_links(const EndpointID& source);
00150 static bool is_dynamic_route(RouteEntry* entry);
00151
00152 void remove_edge(RoutingGraph::Edge* edge);
00153 void adjust_uptime(RoutingGraph::Edge* edge);
00154
00155 bool time_to_age_routes();
00156 void invalidate_routes();
00157 void recompute_routes();
00159
00160
00162 const char* announce_tag_;
00163
00165 EndpointID announce_eid_;
00166
00168 RoutingGraph graph_;
00169 RoutingGraph::Node* local_node_;
00170 RoutingGraph::WeightFn* weight_fn_;
00171
00177 BundleList current_lsas_;
00178
00180 Reg* reg_;
00181
00183 TransmitLSATimer periodic_lsa_timer_;
00184
00187 TransmitLSATimer delayed_lsa_timer_;
00188
00190 oasys::Time last_lsa_transmit_;
00191
00193 oasys::Time last_update_;
00194 };
00195
00196 }
00197
00198 #endif