00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _BUNDLE_ROUTETABLE_H_
00018 #define _BUNDLE_ROUTETABLE_H_
00019
00020 #include <set>
00021 #include <oasys/debug/Log.h>
00022 #include <oasys/util/StringBuffer.h>
00023 #include <oasys/util/StringUtils.h>
00024 #include <oasys/serialize/Serialize.h>
00025
00026 #include "RouteEntry.h"
00027
00028 namespace dtn {
00029
00034 class RouteTable : public oasys::Logger {
00035 public:
00039 RouteTable(const std::string& router_name);
00040
00044 virtual ~RouteTable();
00045
00049 bool add_entry(RouteEntry* entry);
00050
00054 bool del_entry(const EndpointIDPattern& dest, const LinkRef& next_hop);
00055
00059 template<typename Predicate>
00060 size_t del_matching_entries(Predicate test);
00061
00067 size_t del_entries(const EndpointIDPattern& dest);
00068
00074 size_t del_entries_for_nexthop(const LinkRef& next_hop);
00075
00079 void clear();
00080
00088 size_t get_matching(const EndpointID& eid, const LinkRef& next_hop,
00089 RouteEntryVec* entry_vec) const;
00090
00096 size_t get_matching(const EndpointID& eid,
00097 RouteEntryVec* entry_vec) const
00098 {
00099 LinkRef link("RouteTable::get_matching: null");
00100 return get_matching(eid, link, entry_vec);
00101 }
00102
00106 void dump(oasys::StringBuffer* buf) const;
00107
00111 int size() { return route_table_.size(); }
00112
00117 const RouteEntryVec *route_table();
00118
00122 oasys::Lock* lock() { return &lock_; }
00123
00124 protected:
00126 size_t get_matching_helper(const EndpointID& eid,
00127 const LinkRef& next_hop,
00128 RouteEntryVec* entry_vec,
00129 bool* loop,
00130 int level) const;
00131
00133 RouteEntryVec route_table_;
00134
00138 mutable oasys::SpinLock lock_;
00139 };
00140
00141
00142 template <typename Predicate>
00143 inline size_t
00144 RouteTable::del_matching_entries(Predicate pred)
00145 {
00146 oasys::ScopeLock l(&lock_, "RouteTable::del_matching_entries");
00147
00148
00149
00150 bool found = false;
00151 for (RouteEntryVec::iterator iter = route_table_.begin();
00152 iter != route_table_.end(); ++iter)
00153 {
00154 if (pred(*iter)) {
00155 found = true;
00156 delete *iter;
00157 *iter = NULL;
00158 }
00159 }
00160
00161
00162 if (!found)
00163 return 0;
00164
00165 size_t old_size = route_table_.size();
00166
00167
00168
00169 RouteEntryVec::iterator new_end =
00170 std::remove_if(route_table_.begin(), route_table_.end(),
00171 std::bind2nd(std::equal_to<RouteEntry*>(), 0));
00172 route_table_.erase(new_end, route_table_.end());
00173
00174 return old_size - route_table_.size();
00175 }
00176
00177 }
00178
00179 #endif