-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUniboCGRBundleRouterVECCHIO.h
246 lines (196 loc) · 7.88 KB
/
UniboCGRBundleRouterVECCHIO.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#ifndef _UNIBO_CGR_BUNDLE_ROUTER_H_
#define _UNIBO_CGR_BUNDLE_ROUTER_H_
#include <oasys/util/StringUtils.h>
#include "BundleRouter.h"
#include "RouterInfo.h"
#include "uniboCGR/interface_unibocgr_dtn2.h"
#include "bundling/BundleInfoCache.h"
#include "reg/Registration.h"
#include "session/SessionTable.h"
namespace dtn {
class BundleList;
class RouteEntryVec;
/**
* This is a class that implements UniboCGR's Bundle Routing
*/
class UniboCGRBundleRouter : public BundleRouter {
public:
/**
* Constructor -- public
*/
UniboCGRBundleRouter(const char* classname, const std::string& name);
/**
* Destructor.
*/
virtual ~UniboCGRBundleRouter();
virtual void shutdown();
/**
* Event handler overridden from BundleRouter / BundleEventHandler
* that dispatches to the type specific handlers where
* appropriate.
*/
virtual void handle_event(BundleEvent* event);
/// @{ Event handlers
virtual void handle_bundle_received(BundleReceivedEvent* event);
virtual void handle_bundle_transmitted(BundleTransmittedEvent* event);
virtual void handle_bundle_cancelled(BundleSendCancelledEvent* event);
virtual void handle_link_available(LinkAvailableEvent* event);
virtual void handle_link_created(LinkCreatedEvent* event);
virtual void handle_link_deleted(LinkDeletedEvent* event);
virtual void handle_link_check_deferred(LinkCheckDeferredEvent* event);
virtual void handle_custody_timeout(CustodyTimeoutEvent* event);
virtual void handle_registration_added(RegistrationAddedEvent* event);
virtual void handle_registration_removed(RegistrationRemovedEvent* event);
virtual void handle_registration_expired(RegistrationExpiredEvent* event);
/// @}
/// @{ Session management helper functions
Session* get_session_for_bundle(Bundle* bundle);
bool add_bundle_to_session(Bundle* bundle, Session* session);
bool subscribe_to_session(int action, Session* session);
bool find_session_upstream(Session* session);
void reroute_all_sessions();
bool handle_session_bundle(BundleReceivedEvent* event);
void add_subscriber(Session* session,
const EndpointID& peer,
const SequenceID& known_seqid);
/// @}
/**
* Dump the routing state.
*/
void get_routing_state(oasys::StringBuffer* buf);
/**
* Update forwarding state due to changed routes.
*/
void handle_changed_routes();
/**
* Try to forward a bundle to a next hop route.
*/
virtual bool fwd_to_nexthop(Bundle* bundle, RouteEntry* route);
/**
* Check if the bundle should be forwarded to the given next hop.
* Reasons why it would not be forwarded include that it was
* already transmitted or is currently in flight on the link, or
* that the route indicates ForwardingInfo::FORWARD_ACTION and it
* is already in flight on another route.
*/
virtual bool should_fwd(const Bundle* bundle, RouteEntry* route);
/**
* Call the CGR to find matches. If a match
* is found, call fwd_to_nexthop on it.
* Set skip_check_next_hop to true to skip the call to
* check_next_hop().
*
* @param bundle the bundle to forward
*
* Returns the number of links on which the bundle was queued
* i.e. the number of matching entries found bu the CGR.
*/
virtual int route_bundle(Bundle* bundle, bool skip_check_next_hop=false);
/**
* Once a vector of matching routes has been found, sort the
* vector. The default uses the route priority, breaking ties by
* using the number of bytes queued.
*/
virtual void sort_routes(Bundle* bundle, RouteEntryVec* routes);
/**
* Called when the next hop link is available for transmission
* (i.e. either when it first arrives and the contact is brought
* up or when a bundle is completed and it's no longer busy).
*
* Loops through the bundle list and calls fwd_to_matching on all
* bundles.
*/
virtual void check_next_hop(const LinkRef& next_hop);
/**
* Go through all known bundles in the system and try to re-route them.
*/
virtual void reroute_all_bundles();
/**
* Generic hook in response to the command line indication that we
* should reroute all bundles.
*/
virtual void recompute_routes();
/**
* When new links are added or opened, and if we're configured to
* add nexthop routes, try to add a new route for the given link.
* Set skip_changed_routes to true to skip the call to
* handle_changed_routes if the initiating method is going to call it.
*/
void add_nexthop_route(const LinkRef& link, bool skip_changed_routes=false);
/**
* Hook to ask the router if the bundle can be deleted.
*/
bool can_delete_bundle(const BundleRef& bundle);
/**
* Hook to tell the router that the bundle should be deleted.
*/
void delete_bundle(const BundleRef& bundle);
/**
* Remove matching deferred transmission entries.
*/
void remove_from_deferred(const BundleRef& bundle, int actions);
/// Cache to check for duplicates and to implement a simple RPF check
BundleInfoCache reception_cache_;
/// The routing table
//RouteTable* route_table_;
/// Session state management table
SessionTable sessions_;
/// Vector of session custodian registrations
RegistrationList session_custodians_;
/// Timer class used to cancel transmission on down links after
/// waiting for them to potentially reopen
class RerouteTimer : public oasys::Timer {
public:
RerouteTimer(UniboCGRBundleRouter* router, const LinkRef& link)
: router_(router), link_(link) {}
virtual ~RerouteTimer() {}
void timeout(const struct timeval& now);
protected:
UniboCGRBundleRouter* router_;
LinkRef link_;
};
friend class RerouteTimer;
/// Helper function for rerouting
void reroute_bundles(const LinkRef& link);
/// Table of reroute timers, indexed by the link name
typedef oasys::StringMap<RerouteTimer*> RerouteTimerMap;
RerouteTimerMap reroute_timers_;
/// Per-link class used to store deferred transmission bundles
/// that helps cache route computations
class DeferredList : public RouterInfo, public oasys::Logger {
public:
DeferredList(const char* logpath, const LinkRef& link);
/// Accessor for the bundle list
BundleList* list() { return &list_; }
/// Accessor for the forwarding info associated with the
/// bundle, which must be on the list
const ForwardingInfo& info(const BundleRef& bundle);
/// Check if the bundle is on the list. If so, return its
/// forwarding info.
bool find(const BundleRef& bundle, ForwardingInfo* info);
/// Add a new bundle/info pair to the deferred list
bool add(const BundleRef& bundle, const ForwardingInfo& info);
/// Remove the bundle and its associated forwarding info from
/// the list
bool del(const BundleRef& bundle);
/// Print out the stats, called from Link::dump_stats
void dump_stats(oasys::StringBuffer* buf);
protected:
typedef std::map<bundleid_t, ForwardingInfo> InfoMap;
BundleList list_;
InfoMap info_;
size_t count_;
};
/// Helper accessor to return the deferred queue for a link
DeferredList* deferred_list(const LinkRef& link);
/// Timer class used to periodically refresh subscriptions
class ResubscribeTimer : public oasys::Timer {
public:
ResubscribeTimer(UniboCGRBundleRouter* router, Session* session);
virtual void timeout(const struct timeval& now);
UniboCGRBundleRouter* router_;
Session* session_;
};
};
} // namespace dtn
#endif /* _UNIBO_CGR_BUNDLE_ROUTER_H_ */