00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _BUNDLE_ROUTEENTRY_H_
00018 #define _BUNDLE_ROUTEENTRY_H_
00019
00020 #include <oasys/debug/Formatter.h>
00021 #include <oasys/serialize/Serialize.h>
00022 #include <oasys/util/StringUtils.h>
00023
00024 #include "bundling/CustodyTimer.h"
00025 #include "bundling/ForwardingInfo.h"
00026 #include "naming/EndpointID.h"
00027 #include "contacts/Link.h"
00028
00029 namespace dtn {
00030
00031 class RouteEntryInfo;
00032
00054 class RouteEntry : public oasys::Formatter,
00055 public oasys::SerializableObject {
00056 public:
00058 typedef ForwardingInfo::action_t action_t;
00059
00061 class DestMatches;
00062 class NextHopMatches;
00063
00067 RouteEntry(const EndpointIDPattern& dest_pattern, const LinkRef& link);
00068
00073 RouteEntry(const EndpointIDPattern& dest_pattern,
00074 const EndpointIDPattern& route_to);
00075
00079 ~RouteEntry();
00080
00084 int parse_options(int argc, const char** argv,
00085 const char** invalidp = NULL);
00086
00090 int format(char* buf, size_t sz) const;
00091
00095 static void dump_header(oasys::StringBuffer* buf,
00096 int dest_eid_width,
00097 int source_eid_width,
00098 int next_hop_width);
00099
00105 void dump(oasys::StringBuffer* buf,
00106 oasys::StringVector* long_strings,
00107 int dest_eid_width,
00108 int source_eid_width,
00109 int next_hop_width) const;
00110
00114 virtual void serialize( oasys::SerializeAction *a );
00115
00117 const EndpointIDPattern& dest_pattern() const { return dest_pattern_; }
00118 const EndpointIDPattern& source_pattern() const { return source_pattern_; }
00119 const LinkRef& link() const { return link_; }
00120 const EndpointIDPattern& route_to() const { return route_to_; }
00121 u_int priority() const { return priority_; }
00122 RouteEntryInfo* info() const { return info_; }
00123 const CustodyTimerSpec& custody_spec() const { return custody_spec_; }
00124
00125 action_t action() const { return static_cast<action_t>(action_); }
00126
00127 const std::string& next_hop_str() const {
00128 return (link() != NULL) ? link()->name_str() : route_to().str();
00129 }
00131
00133 void set_action(action_t action) { action_ = action; }
00134 void set_info(RouteEntryInfo* info) { info_ = info; }
00136
00137 private:
00139 static void append_long_string(oasys::StringBuffer* buf,
00140 oasys::StringVector* long_strings,
00141 int width, const std::string& str);
00142
00143
00145 EndpointIDPattern dest_pattern_;
00146
00148 EndpointIDPattern source_pattern_;
00149
00151 u_int bundle_cos_;
00152
00154 u_int priority_;
00155
00157 LinkRef link_;
00158
00160 EndpointIDPattern route_to_;
00161
00163 u_int32_t action_;
00164
00166 CustodyTimerSpec custody_spec_;
00167
00170 RouteEntryInfo* info_;
00171
00172
00173
00174
00175 };
00176
00180 class RouteEntry::DestMatches {
00181 public:
00182 DestMatches(const EndpointIDPattern& dest) : dest_(dest) {}
00183 bool operator()(RouteEntry* entry) {
00184 return dest_.equals(entry->dest_pattern());
00185 }
00186 EndpointIDPattern dest_;
00187 };
00188
00192 class RouteEntry::NextHopMatches {
00193 public:
00194 NextHopMatches(const LinkRef& link) : link_(link) {}
00195 bool operator()(RouteEntry* entry) {
00196 return link_ == entry->link();
00197 }
00198 LinkRef link_;
00199 };
00200
00204 class RouteEntryInfo {
00205 public:
00206 virtual ~RouteEntryInfo() {}
00207 };
00208
00213 class RouteEntryVec : public std::vector<RouteEntry*> {};
00214
00219 struct RoutePrioritySort {
00220 bool operator() (RouteEntry* a, RouteEntry* b) {
00221 if (a->priority() < b->priority()) return false;
00222 if (a->priority() > b->priority()) return true;
00223 return (a->link()->bytes_queued() <
00224 b->link()->bytes_queued());
00225 }
00226 };
00227
00228 }
00229
00230 #endif