8 #include <boost/assign/list_of.hpp>
9 #include <boost/foreach.hpp>
45 server_delete_ref_(this, server->
deleter()),
75 policy = BgpStaticObjectFactory::Create<RoutingPolicy>(
88 if (policy && policy->
deleted()) {
107 if (policy && policy->
deleted()) {
109 }
else if (!policy) {
124 const std::string name = policy->
name();
145 std::scoped_lock lock(
mutex_);
146 BOOST_FOREACH(RoutingInstance::RouteTableList::value_type &entry,
158 return (*policy)(route, path, attr);
176 bool sort_and_notify =
false;
178 for (Route::PathList::iterator it = route->
GetPathList().begin();
181 uint32_t old_flags = path->
GetFlags();
184 if ((sort_and_notify ==
false) &&
186 sort_and_notify =
true;
190 if (sort_and_notify) {
204 std::scoped_lock lock(
mutex_);
205 bool update_policy =
false;
207 if (oper_list->size() != cfg_list.size())
208 update_policy =
true;
210 RoutingPolicyAttachList::iterator oper_it = oper_list->begin(), oper_next;
211 RoutingPolicyConfigList::const_iterator config_it = cfg_list.begin();
212 while (oper_it != oper_list->end() &&
213 config_it != cfg_list.end()) {
216 if (oper_it->first->name() == config_it->routing_policy_) {
217 if (oper_it->second != oper_it->first->generation()) {
219 oper_it->second = oper_it->first->generation();
220 update_policy =
true;
230 *oper_it = std::make_pair(policy, policy->
generation());
233 update_policy =
true;
241 for (oper_next = oper_it; oper_it != oper_list->end();
242 oper_it = oper_next) {
245 oper_list->erase(oper_it);
246 update_policy =
true;
248 for (; config_it != cfg_list.end(); ++config_it) {
252 oper_list->push_back(std::make_pair(policy, policy->
generation()));
254 update_policy =
true;
257 return update_policy;
308 : name_(name), server_(server), mgr_(mgr), config_(config),
310 manager_delete_ref_(this, mgr->
deleter()), generation_(0) {
327 matches.push_back(community);
334 matches.push_back(ext_community);
340 matches.push_back(protocol);
348 boost::system::error_code ec;
352 if (ec.value() == 0) {
353 inet_prefix_list.push_back(match);
357 if (ec.value() == 0) {
358 inet6_prefix_list.push_back(match);
362 if (!inet_prefix_list.empty()) {
364 matches.push_back(prefix);
366 if (!inet6_prefix_list.empty()) {
368 matches.push_back(prefix);
375 actions.push_back(action);
378 actions.push_back(action);
381 actions.push_back(action);
387 actions.push_back(expand_aspath);
393 actions.push_back(set_comm);
399 actions.push_back(remove_comm);
405 actions.push_back(add_comm);
411 actions.push_back(set_comm);
417 actions.push_back(remove_comm);
423 actions.push_back(add_comm);
429 actions.push_back(local_pref);
435 actions.push_back(med);
439 if (!actions.empty() || !matches.empty()) {
441 ret_term->set_actions(actions);
442 ret_term->set_matches(matches);
466 bool update_policy =
false;
468 update_policy =
true;
470 RoutingPolicyTermList::iterator oper_it =
terms()->begin(), oper_next;
471 BgpRoutingPolicyConfig::RoutingPolicyTermList::const_iterator
475 if (**oper_it == *term) {
481 update_policy =
true;
489 for (oper_next = oper_it; oper_it !=
terms()->end(); oper_it = oper_next) {
491 terms()->erase(oper_it);
492 update_policy =
true;
494 for (; config_it !=
config_->
terms().end(); ++config_it) {
498 update_policy =
true;
546 bool terminal = term->terminal();
547 bool matched = term->ApplyTerm(route, path, attr);
548 if (matched && terminal) {
549 return std::make_pair(terminal,
550 (*term->actions().begin())->accept());
553 return std::make_pair(
false,
true);
566 return (*
actions().begin())->terminal();
574 if (!(*
match)(route, path, attr)) {
610 for (MatchList::const_iterator rhs_matches_cit = rhs.
matches().begin(),
611 lhs_matches_cit =
matches().begin();
612 lhs_matches_cit !=
matches().end();
613 lhs_matches_cit++, rhs_matches_cit++) {
614 if (**rhs_matches_cit != **lhs_matches_cit)
619 for (ActionList::const_iterator lhs_actions_cit =
actions().begin(),
620 rhs_actions_cit = rhs.
actions().begin();
621 lhs_actions_cit !=
actions().end();
622 lhs_actions_cit++, rhs_actions_cit++) {
623 if (**rhs_actions_cit != **lhs_actions_cit)
boost::system::error_code Inet6PrefixParse(const string &str, Ip6Address *addr, int *plen)
boost::system::error_code Ip4PrefixParse(const string &str, Ip4Address *addr, int *plen)
boost::asio::ip::address_v6 Ip6Address
boost::asio::ip::address_v4 Ip4Address
std::vector< RoutingPolicyAttachInfo > RoutingPolicyConfigList
std::list< RoutingPolicyInfo > RoutingPolicyAttachList
std::vector< PrefixMatchConfig > PrefixMatchConfigList
virtual const BgpRoutingPolicyConfig * FindRoutingPolicy(const std::string &name) const =0
uint32_t GetFlags() const
const BgpAttr * GetAttr() const
const std::string & name() const
const RoutingPolicyTermList & terms() const
BgpConfigManager * config_manager()
RoutingInstance * routing_instance()
static bool PathSelection(const Path &path1, const Path &path2)
virtual bool IsRoutingPolicySupported() const
void Notify(DBEntryBase *entry)
void WalkAgain(DBTableWalkRef walk)
DBTableWalkRef AllocWalker(WalkFn walk_fn, WalkCompleteFn walk_complete)
void WalkTable(DBTableWalkRef walk)
void ReleaseWalker(DBTableWalkRef &walk)
boost::intrusive_ptr< DBTableWalk > DBTableWalkRef
void Reset(LifetimeActor *actor)
std::vector< RoutingPolicyMatch * > MatchList
std::vector< RoutingPolicyAction * > ActionList
autogen::PolicyAction action
bool operator==(const PolicyTerm &term) const
const MatchList & matches() const
const ActionList & actions() const
bool ApplyTerm(const BgpRoute *route, const BgpPath *path, BgpAttr *attr) const
autogen::PolicyMatch match
void Sort(Compare compare, const Path *prev_front)
const PathList & GetPathList() const
const Path * front() const
bool ProcessRoutingPolicy(const BgpRoute *route, BgpPath *path) const
RouteTableList & GetTables()
RoutingPolicyMgr * manager_
virtual bool MayDelete() const
DeleteActor(RoutingPolicyMgr *manager)
void DestroyRoutingPolicy(RoutingPolicy *policy)
bool EvaluateRoutingPolicy(DBTablePartBase *root, DBEntryBase *entry)
void UpdateRoutingPolicy(const BgpRoutingPolicyConfig *config)
bool UpdateRoutingPolicyList(const RoutingPolicyConfigList &cfg_list, RoutingPolicyAttachList *oper_list)
RoutingPolicyWalkRequests routing_policy_sync_
void ApplyRoutingPolicy(RoutingInstance *instance)
LifetimeRef< RoutingPolicyMgr > server_delete_ref_
RoutingPolicyList routing_policies_
boost::scoped_ptr< DeleteActor > deleter_
RoutingPolicy::PolicyResult ExecuteRoutingPolicy(const RoutingPolicy *policy, const BgpRoute *route, const BgpPath *path, BgpAttr *attr) const
void RequestWalk(BgpTable *table)
void WalkDone(DBTableBase *dbtable)
virtual RoutingPolicy * CreateRoutingPolicy(const BgpRoutingPolicyConfig *config)
virtual ~RoutingPolicyMgr()
virtual void DeleteRoutingPolicy(const std::string &name)
RoutingPolicyMgr(BgpServer *server)
RoutingPolicy * GetRoutingPolicy(const std::string &name)
LifetimeActor * deleter()
DeleteActor(BgpServer *server, RoutingPolicy *parent)
virtual bool MayDelete() const
const std::string & name() const
RoutingPolicyTermList * terms()
uint32_t generation() const
void UpdateConfig(const BgpRoutingPolicyConfig *config)
LifetimeActor * deleter()
PolicyTermPtr BuildTerm(const RoutingPolicyTermConfig &term)
const BgpRoutingPolicyConfig * config_
PolicyResult operator()(const BgpRoute *route, const BgpPath *path, BgpAttr *attr) const
RoutingPolicyTermList terms_
void add_term(PolicyTermPtr term)
RoutingPolicy(std::string name, BgpServer *server, RoutingPolicyMgr *mgr, const BgpRoutingPolicyConfig *config)
std::pair< bool, bool > PolicyResult
std::atomic< uint32_t > refcount_
boost::shared_ptr< PolicyTerm > PolicyTermPtr
boost::scoped_ptr< DeleteActor > deleter_
static ExtCommunityPtr UpdateExtCommunity(BgpServer *server, const RoutingInstance *rtinstance, const ExtCommunity *ext_community, const ExtCommunity::ExtCommunityList &export_list)
MatchPrefix< PrefixMatchInet6 > MatchPrefixInet6
MatchPrefix< PrefixMatchInet > MatchPrefixInet
SandeshTraceBufferPtr SandeshTraceBufferCreate(const std::string &buf_name, size_t buf_size, bool trace_enable=true)
CommunityList ext_community_set
CommunityList ext_community_add
CommunityList community_set
CommunityList community_remove
CommunityList ext_community_remove
CommunityList community_add
std::string prefix_to_match
ProtocolList protocols_match
CommunityList community_match
PrefixMatchConfigList prefixes_to_match
CommunityList ext_community_match
bool ext_community_match_all
RoutingPolicyMatchConfig match
RoutingPolicyActionConfig action
#define CHECK_CONCURRENCY(...)
void STLDeleteValues(Container *container)