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)
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_
tbb::atomic< uint32_t > refcount_
void add_term(PolicyTermPtr term)
RoutingPolicy(std::string name, BgpServer *server, RoutingPolicyMgr *mgr, const BgpRoutingPolicyConfig *config)
std::pair< bool, bool > PolicyResult
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)