From 0fbddcb83a4a3f79da8ba01d593f4064f0ce26ac Mon Sep 17 00:00:00 2001 From: Othmar Gsenger Date: Wed, 27 Feb 2008 21:25:34 +0000 Subject: added mux support and routing table --- routingTable.cpp | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) (limited to 'routingTable.cpp') diff --git a/routingTable.cpp b/routingTable.cpp index a6e0917..29302fb 100644 --- a/routingTable.cpp +++ b/routingTable.cpp @@ -27,7 +27,7 @@ * distribution); if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - +#include "networkPrefix.h" #include "threadUtils.hpp" #include "datatypes.h" @@ -56,22 +56,36 @@ RoutingTable::~RoutingTable() { } -void RoutingTable::addRoute(const NetworkPrefix & ,u_int16_t ) +void RoutingTable::addRoute(const NetworkPrefix & pref,u_int16_t mux ) { Lock lock(mutex_); + + + std::pair ret = routes_.insert(RoutingMap::value_type(pref,mux)); + if(!ret.second) + { + routes_.erase(ret.first); + routes_.insert(RoutingMap::value_type(pref,mux)); + } +} + -// std::pair ret = connections_.insert(ConnectionMap::value_type(mux, conn)); -// if(!ret.second) -// { -// connections_.erase(ret.first); -// connections_.insert(ConnectionMap::value_type(mux, conn)); -// } +void RoutingTable::delRoute(const NetworkPrefix & pref ) +{ + Lock lock(mutex_); + + routes_.erase(routes_.find(pref)); } -u_int16_t RoutingTable::getRoute(const NetworkAddress &) +u_int16_t RoutingTable::getRoute(const NetworkAddress & addr) { Lock lock(mutex_); - RoutingMap::iterator it = routes_.begin(); + NetworkPrefix prefix(addr); + prefix.setNetworkPrefixLength(32); + RoutingMap::iterator it = routes_.lower_bound(prefix); + it--; + if (it!=routes_.end()) + return it->second; return 0; } -- cgit v1.2.3