Skip to content

Commit

Permalink
Templatize code to sync static route config and oper state
Browse files Browse the repository at this point in the history
Change-Id: I16c135f4b9e759eb271e8ed098e4bee14f081f3d
Partial-Bug: 1548570
  • Loading branch information
Nischal Sheth committed Feb 23, 2016
1 parent 0ac65de commit 997f71a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 34 deletions.
69 changes: 35 additions & 34 deletions src/bgp/routing-instance/static_route.cc
Expand Up @@ -10,6 +10,7 @@
#include <string>
#include <vector>

#include "base/map_util.h"
#include "base/task_annotations.h"
#include "base/task_trigger.h"
#include "bgp/bgp_config.h"
Expand Down Expand Up @@ -797,42 +798,16 @@ bool CompareStaticRouteConfig(const StaticRouteConfig &lhs,
template <typename T>
void StaticRouteMgr<T>::UpdateStaticRouteConfig() {
CHECK_CONCURRENCY("bgp::Config");
typedef BgpInstanceConfig::StaticRouteList StaticRouteList;
StaticRouteList static_route_list =
StaticRouteConfigList config_list =
routing_instance()->config()->static_routes(GetFamily());
sort(config_list.begin(), config_list.end(), CompareStaticRouteConfig);

sort(static_route_list.begin(), static_route_list.end(),
CompareStaticRouteConfig);

StaticRouteList::const_iterator static_route_cfg_it =
static_route_list.begin();
typename StaticRouteMap::iterator oper_it = static_route_map_.begin();

while ((static_route_cfg_it != static_route_list.end()) &&
(oper_it != static_route_map_.end())) {
AddressT address = this->GetAddress(static_route_cfg_it->address);
PrefixT static_route_prefix(
address, static_route_cfg_it->prefix_length);
if (static_route_prefix < oper_it->first) {
LocateStaticRoutePrefix(*static_route_cfg_it);
static_route_cfg_it++;
} else if (static_route_prefix > oper_it->first) {
RemoveStaticRoutePrefix(oper_it->first);
oper_it++;
} else {
LocateStaticRoutePrefix(*static_route_cfg_it);
static_route_cfg_it++;
oper_it++;
}
}

for (; oper_it != static_route_map_.end(); oper_it++) {
RemoveStaticRoutePrefix(oper_it->first);
}
for (; static_route_cfg_it != static_route_list.end();
static_route_cfg_it++) {
LocateStaticRoutePrefix(*static_route_cfg_it);
}
map_difference(&static_route_map_,
config_list.begin(), config_list.end(),
boost::bind(&StaticRouteMgr<T>::CompareStaticRoute, this, _1, _2),
boost::bind(&StaticRouteMgr<T>::AddStaticRoute, this, _1),
boost::bind(&StaticRouteMgr<T>::DelStaticRoute, this, _1),
boost::bind(&StaticRouteMgr<T>::UpdateStaticRoute, this, _1, _2));
}

template <typename T>
Expand All @@ -844,6 +819,32 @@ void StaticRouteMgr<T>::FlushStaticRouteConfig() {
}
}

template <typename T>
int StaticRouteMgr<T>::CompareStaticRoute(
typename StaticRouteMap::iterator loc,
StaticRouteConfigList::iterator it) {
AddressT address = this->GetAddress(it->address);
PrefixT prefix(address, it->prefix_length);
KEY_COMPARE(loc->first, prefix);
return 0;
}

template <typename T>
void StaticRouteMgr<T>::AddStaticRoute(StaticRouteConfigList::iterator it) {
LocateStaticRoutePrefix(*it);
}

template <typename T>
void StaticRouteMgr<T>::DelStaticRoute(typename StaticRouteMap::iterator loc) {
RemoveStaticRoutePrefix(loc->first);
}

template <typename T>
void StaticRouteMgr<T>::UpdateStaticRoute(typename StaticRouteMap::iterator loc,
StaticRouteConfigList::iterator it) {
LocateStaticRoutePrefix(*it);
}

template <typename T>
void StaticRouteMgr<T>::NotifyAllRoutes() {
CHECK_CONCURRENCY("bgp::Config");
Expand Down
9 changes: 9 additions & 0 deletions src/bgp/routing-instance/static_route.h
Expand Up @@ -12,6 +12,7 @@

#include "base/queue_task.h"
#include "bgp/bgp_condition_listener.h"
#include "bgp/bgp_config.h"
#include "bgp/inet/inet_route.h"
#include "bgp/inet6/inet6_route.h"

Expand Down Expand Up @@ -95,11 +96,19 @@ class StaticRouteMgr : public IStaticRouteMgr {

private:
template <typename U> friend class StaticRouteTest;
typedef BgpInstanceConfig::StaticRouteList StaticRouteConfigList;

// All static route related actions are performed in the context
// of this task. This task has exclusion with db::DBTable task.
static int static_route_task_id_;

int CompareStaticRoute(typename StaticRouteMap::iterator loc,
StaticRouteConfigList::iterator it);
void AddStaticRoute(StaticRouteConfigList::iterator it);
void DelStaticRoute(typename StaticRouteMap::iterator loc);
void UpdateStaticRoute(typename StaticRouteMap::iterator loc,
StaticRouteConfigList::iterator it);

void LocateStaticRoutePrefix(const StaticRouteConfig &cfg);
void RemoveStaticRoutePrefix(const PrefixT &static_route);
void StopStaticRouteDone(BgpTable *table, ConditionMatch *info);
Expand Down

0 comments on commit 997f71a

Please sign in to comment.