7 #include <boost/assign/list_of.hpp>
8 #include <boost/foreach.hpp>
44 server_delete_ref_(this, server->
deleter()),
74 policy = BgpStaticObjectFactory::Create<RoutingPolicy>(
87 if (policy && policy->
deleted()) {
106 if (policy && policy->
deleted()) {
108 }
else if (!policy) {
123 const std::string name = policy->
name();
144 tbb::mutex::scoped_lock lock(
mutex_);
145 BOOST_FOREACH(RoutingInstance::RouteTableList::value_type &entry,
157 return (*policy)(route, path, attr);
175 bool sort_and_notify =
false;
177 for (Route::PathList::iterator it = route->
GetPathList().begin();
180 uint32_t old_flags = path->
GetFlags();
183 if ((sort_and_notify ==
false) &&
185 sort_and_notify =
true;
189 if (sort_and_notify) {
203 tbb::mutex::scoped_lock lock(
mutex_);
204 bool update_policy =
false;
206 if (oper_list->size() != cfg_list.size())
207 update_policy =
true;
209 RoutingPolicyAttachList::iterator oper_it = oper_list->begin(), oper_next;
210 RoutingPolicyConfigList::const_iterator config_it = cfg_list.begin();
211 while (oper_it != oper_list->end() &&
212 config_it != cfg_list.end()) {
215 if (oper_it->first->name() == config_it->routing_policy_) {
216 if (oper_it->second != oper_it->first->generation()) {
218 oper_it->second = oper_it->first->generation();
219 update_policy =
true;
229 *oper_it = std::make_pair(policy, policy->
generation());
232 update_policy =
true;
240 for (oper_next = oper_it; oper_it != oper_list->end();
241 oper_it = oper_next) {
244 oper_list->erase(oper_it);
245 update_policy =
true;
247 for (; config_it != cfg_list.end(); ++config_it) {
251 oper_list->push_back(std::make_pair(policy, policy->
generation()));
253 update_policy =
true;
256 return update_policy;
307 : name_(name), server_(server), mgr_(mgr), config_(config),
309 manager_delete_ref_(this, mgr->
deleter()), generation_(0) {
326 matches.push_back(community);
333 matches.push_back(ext_community);
339 matches.push_back(protocol);
347 boost::system::error_code ec;
351 if (ec.value() == 0) {
352 inet_prefix_list.push_back(match);
356 if (ec.value() == 0) {
357 inet6_prefix_list.push_back(match);
361 if (!inet_prefix_list.empty()) {
363 matches.push_back(prefix);
365 if (!inet6_prefix_list.empty()) {
367 matches.push_back(prefix);
374 actions.push_back(action);
377 actions.push_back(action);
380 actions.push_back(action);
386 actions.push_back(expand_aspath);
392 actions.push_back(set_comm);
398 actions.push_back(remove_comm);
404 actions.push_back(add_comm);
410 actions.push_back(set_comm);
416 actions.push_back(remove_comm);
422 actions.push_back(add_comm);
428 actions.push_back(local_pref);
434 actions.push_back(med);
438 if (!actions.empty() || !matches.empty()) {
440 ret_term->set_actions(actions);
441 ret_term->set_matches(matches);
465 bool update_policy =
false;
467 update_policy =
true;
469 RoutingPolicyTermList::iterator oper_it =
terms()->begin(), oper_next;
470 BgpRoutingPolicyConfig::RoutingPolicyTermList::const_iterator
474 if (**oper_it == *term) {
480 update_policy =
true;
488 for (oper_next = oper_it; oper_it !=
terms()->end(); oper_it = oper_next) {
490 terms()->erase(oper_it);
491 update_policy =
true;
493 for (; config_it !=
config_->
terms().end(); ++config_it) {
497 update_policy =
true;
545 bool terminal = term->terminal();
546 bool matched = term->ApplyTerm(route, path, attr);
547 if (matched && terminal) {
548 return std::make_pair(terminal,
549 (*term->actions().begin())->accept());
552 return std::make_pair(
false,
true);
565 return (*
actions().begin())->terminal();
573 if (!(*match)(route, path, attr)) {
609 for (MatchList::const_iterator rhs_matches_cit = rhs.
matches().begin(),
610 lhs_matches_cit =
matches().begin();
611 lhs_matches_cit !=
matches().end();
612 lhs_matches_cit++, rhs_matches_cit++) {
613 if (**rhs_matches_cit != **lhs_matches_cit)
618 for (ActionList::const_iterator lhs_actions_cit =
actions().begin(),
619 rhs_actions_cit = rhs.
actions().begin();
620 lhs_actions_cit !=
actions().end();
621 lhs_actions_cit++, rhs_actions_cit++) {
622 if (**rhs_actions_cit != **lhs_actions_cit)
virtual ~RoutingPolicyMgr()
RoutingPolicyTermList terms_
virtual bool MayDelete() const
bool ext_community_match_all
PolicyResult operator()(const BgpRoute *route, const BgpPath *path, BgpAttr *attr) const
RoutingPolicyTermList * terms()
void DestroyRoutingPolicy(RoutingPolicy *policy)
void Sort(Compare compare, const Path *prev_front)
void STLDeleteValues(Container *container)
void WalkTable(DBTableWalkRef walk)
boost::system::error_code Ip4PrefixParse(const string &str, Ip4Address *addr, int *plen)
autogen::PolicyMatch match
const BgpRoutingPolicyConfig * config_
RoutingPolicy * GetRoutingPolicy(const std::string &name)
bool UpdateRoutingPolicyList(const RoutingPolicyConfigList &cfg_list, RoutingPolicyAttachList *oper_list)
RoutingInstance * routing_instance()
PrefixMatchConfigList prefixes_to_match
boost::scoped_ptr< DeleteActor > deleter_
CommunityList community_match
virtual void DeleteRoutingPolicy(const std::string &name)
DBTableWalkRef AllocWalker(WalkFn walk_fn, WalkCompleteFn walk_complete)
PolicyTermPtr BuildTerm(const RoutingPolicyTermConfig &term)
boost::scoped_ptr< DeleteActor > deleter_
boost::shared_ptr< PolicyTerm > PolicyTermPtr
CommunityList ext_community_remove
LifetimeActor * deleter()
std::string prefix_to_match
uint32_t GetFlags() const
LifetimeActor * deleter()
virtual bool accept() const =0
void ReleaseWalker(DBTableWalkRef &walk)
ProtocolList protocols_match
bool operator==(const PolicyTerm &term) const
CommunityList community_remove
RoutingPolicyActionConfig action
RouteTableList & GetTables()
void WalkAgain(DBTableWalkRef walk)
const std::string & name() const
void RequestWalk(BgpTable *table)
const ActionList & actions() const
virtual bool IsRoutingPolicySupported() const
DeleteActor(RoutingPolicyMgr *manager)
virtual const BgpRoutingPolicyConfig * FindRoutingPolicy(const std::string &name) const =0
void Reset(LifetimeActor *actor)
std::vector< PrefixMatchConfig > PrefixMatchConfigList
BgpConfigManager * config_manager()
boost::asio::ip::address_v6 Ip6Address
void WalkDone(DBTableBase *dbtable)
virtual bool terminal() const =0
RoutingPolicy::PolicyResult ExecuteRoutingPolicy(const RoutingPolicy *policy, const BgpRoute *route, const BgpPath *path, BgpAttr *attr) const
MatchPrefix< PrefixMatchInet > MatchPrefixInet
#define CHECK_CONCURRENCY(...)
std::vector< RoutingPolicyAttachInfo > RoutingPolicyConfigList
RoutingPolicy(std::string name, BgpServer *server, RoutingPolicyMgr *mgr, const BgpRoutingPolicyConfig *config)
CommunityList community_add
LifetimeRef< RoutingPolicyMgr > server_delete_ref_
RoutingPolicyMatchConfig match
const MatchList & matches() const
CommunityList ext_community_set
void UpdateRoutingPolicy(const BgpRoutingPolicyConfig *config)
std::pair< bool, bool > PolicyResult
bool ProcessRoutingPolicy(const BgpRoute *route, BgpPath *path) const
boost::asio::ip::address_v4 Ip4Address
std::vector< RoutingPolicyAction * > ActionList
virtual RoutingPolicy * CreateRoutingPolicy(const BgpRoutingPolicyConfig *config)
const Path * front() const
static ExtCommunityPtr UpdateExtCommunity(BgpServer *server, const RoutingInstance *rtinstance, const ExtCommunity *ext_community, const ExtCommunity::ExtCommunityList &export_list)
uint32_t generation() const
static bool PathSelection(const Path &path1, const Path &path2)
std::list< RoutingPolicyInfo > RoutingPolicyAttachList
boost::system::error_code Inet6PrefixParse(const string &str, Ip6Address *addr, int *plen)
const BgpAttr * GetAttr() const
bool EvaluateRoutingPolicy(DBTablePartBase *root, DBEntryBase *entry)
std::vector< RoutingPolicyMatch * > MatchList
virtual bool MayDelete() const
CommunityList ext_community_match
bool ApplyTerm(const BgpRoute *route, const BgpPath *path, BgpAttr *attr) const
RoutingPolicyMgr * manager_
DeleteActor(BgpServer *server, RoutingPolicy *parent)
boost::intrusive_ptr< DBTableWalk > DBTableWalkRef
void Notify(DBEntryBase *entry)
RoutingPolicyMgr(BgpServer *server)
void UpdateConfig(const BgpRoutingPolicyConfig *config)
MatchPrefix< PrefixMatchInet6 > MatchPrefixInet6
CommunityList community_set
CommunityList ext_community_add
autogen::PolicyAction action
tbb::atomic< uint32_t > refcount_
void add_term(PolicyTermPtr term)
void ApplyRoutingPolicy(RoutingInstance *instance)
const std::string & name() const
RoutingPolicyWalkRequests routing_policy_sync_
SandeshTraceBufferPtr SandeshTraceBufferCreate(const std::string &buf_name, size_t buf_size, bool trace_enable=true)
RoutingPolicyList routing_policies_
const PathList & GetPathList() const
const RoutingPolicyTermList & terms() const