8 #include <boost/foreach.hpp>
9 #include <boost/assign/list_of.hpp>
44 using std::ostringstream;
52 bool match_all) : match_all_(match_all) {
55 BOOST_FOREACH(
const string &community,
communities) {
66 vector<string>::iterator it =
92 sort(list.begin(), list.end());
93 if (!includes(list.begin(), list.end(),
101 bool matched =
false;
102 BOOST_FOREACH(uint32_t community, comm->
communities()) {
128 BOOST_FOREACH(uint32_t community, comm->
communities()) {
135 BOOST_FOREACH(uint32_t community, comm->
communities()) {
160 oss <<
"community (all) [ ";
162 oss <<
"community (any) [ ";
169 oss << regex_str <<
",";
171 oss.seekp(-1, oss.cur);
192 bool match_all) : match_all_(match_all) {
195 BOOST_FOREACH(
const string &community,
communities) {
209 vector<string>::iterator it =
235 sort(list.begin(), list.end());
236 if (!includes(list.begin(), list.end(),
244 bool matched =
false;
322 oss <<
"Extcommunity (all) [ ";
324 oss <<
"Extcommunity (any) [ ";
331 oss << regex_str <<
",";
333 oss.seekp(-1, oss.cur);
353 template <
typename T>
355 const string &match_type_str) {
357 if (match_type_str ==
"exact") {
359 }
else if (match_type_str ==
"longer") {
361 }
else if (match_type_str ==
"orlonger") {
362 match_type = ORLONGER;
367 template <
typename T>
370 boost::system::error_code ec;
374 match_list_.push_back(
PrefixMatch(prefix, match_type));
378 sort(match_list_.begin(), match_list_.end());
379 typename PrefixMatchList::iterator it =
380 unique(match_list_.begin(), match_list_.end());
381 match_list_.erase(it, match_list_.end());
384 template <
typename T>
388 template <
typename T>
391 const RouteT *in_route =
dynamic_cast<const RouteT *
>(route);
392 if (in_route == NULL)
394 const PrefixT &prefix = in_route->GetPrefix();
395 BOOST_FOREACH(
const PrefixMatch &prefix_match, match_list_) {
397 if (prefix == prefix_match.
prefix)
399 }
else if (prefix_match.
match_type == LONGER) {
400 if (prefix == prefix_match.
prefix)
402 if (prefix.IsMoreSpecific(prefix_match.
prefix))
404 }
else if (prefix_match.
match_type == ORLONGER) {
405 if (prefix.IsMoreSpecific(prefix_match.
prefix))
412 template <
typename T>
418 template <
typename T>
422 BOOST_FOREACH(
const PrefixMatch &prefix_match, match_list_) {
423 oss <<
" " << prefix_match.
prefix.ToString();
426 }
else if (prefix_match.
match_type == ORLONGER) {
431 oss.seekp(-1, oss.cur);
439 static const map<string, MatchProtocol::MatchProtocolType>
fromString
440 = boost::assign::map_list_of
451 static const map<MatchProtocol::MatchProtocolType, string>
toString
452 = boost::assign::map_list_of
463 static const map<MatchProtocol::MatchProtocolType, BgpPath::PathSource>
475 static const vector<MatchProtocol::MatchProtocolType>
487 map<MatchProtocol::MatchProtocolType, string>::const_iterator it =
492 return "unspecified";
496 const string &protocol) {
497 map<string, MatchProtocol::MatchProtocolType>::const_iterator it =
507 map<MatchProtocol::MatchProtocolType, BgpPath::PathSource>::const_iterator
516 BOOST_FOREACH(
const string &protocol,
protocols) {
526 vector<MatchProtocolType>::iterator it =
551 if (mapped_src == path_src) {
552 if (protocol ==
XMPP && !is_xmpp)
554 if (protocol ==
BGP && (bgpaas || is_xmpp))
556 if (protocol ==
BGPaaS && (!bgpaas || is_xmpp))
568 oss <<
"protocol [ ";
573 oss.seekp(-1, oss.cur);
std::vector< PrefixMatchConfig > PrefixMatchConfigList
const std::string & sub_protocol() const
const Community * community() const
const ExtCommunity * ext_community() const
PathSource GetSource() const
virtual bool IsXmppPeer() const =0
virtual bool IsRouterTypeBGPaaS() const =0
virtual bool IsEqual(const RoutingPolicyMatch &prefix) const
virtual std::string ToString() const
PrefixMatchList match_list_
MatchPrefix(const PrefixMatchConfigList &match_config_list)
virtual bool Match(const BgpRoute *route, const BgpPath *path, const BgpAttr *attr) const
static MatchType GetMatchType(const std::string &match_type_str)
virtual std::string ToString() const
const PathSourceList & protocols() const
virtual bool Match(const BgpRoute *route, const BgpPath *path, const BgpAttr *attr) const
virtual bool IsEqual(const RoutingPolicyMatch &community) const
MatchProtocol(const std::vector< std::string > &protocols)
static bool regex_search(const std::string &input, const regex ®ex)
static bool regex_match(const std::string &input, const regex ®ex)
static PhysicalDevice::ManagementProtocol FromString(const string &proto)
static const map< MatchProtocol::MatchProtocolType, string > toString
static bool IsSubprotocol(MatchProtocol::MatchProtocolType protocol)
static const vector< MatchProtocol::MatchProtocolType > isSubprotocol
static BgpPath::PathSource PathSourceFromMatchProtocol(MatchProtocol::MatchProtocolType src)
static const map< string, MatchProtocol::MatchProtocolType > fromString
static const map< MatchProtocol::MatchProtocolType, BgpPath::PathSource > pathSourceMap
static MatchProtocol::MatchProtocolType MatchProtocolFromString(const string &protocol)
const string MatchProtocolToString(MatchProtocol::MatchProtocolType protocol)
std::string prefix_to_match
std::string prefix_match_type