7 #include <boost/foreach.hpp>
8 #include <boost/assign/list_of.hpp>
43 using std::ostringstream;
51 bool match_all) : match_all_(match_all) {
54 BOOST_FOREACH(
const string &community, communities) {
65 vector<string>::iterator it =
91 sort(list.begin(), list.end());
92 if (!includes(list.begin(), list.end(),
100 bool matched =
false;
101 BOOST_FOREACH(uint32_t community, comm->
communities()) {
127 BOOST_FOREACH(uint32_t community, comm->
communities()) {
134 BOOST_FOREACH(uint32_t community, comm->
communities()) {
159 oss <<
"community (all) [ ";
161 oss <<
"community (any) [ ";
168 oss << regex_str <<
",";
170 oss.seekp(-1, oss.cur);
191 bool match_all) : match_all_(match_all) {
194 BOOST_FOREACH(
const string &community, communities) {
208 vector<string>::iterator it =
234 sort(list.begin(), list.end());
235 if (!includes(list.begin(), list.end(),
243 bool matched =
false;
321 oss <<
"Extcommunity (all) [ ";
323 oss <<
"Extcommunity (any) [ ";
330 oss << regex_str <<
",";
332 oss.seekp(-1, oss.cur);
352 template <
typename T>
354 const string &match_type_str) {
356 if (match_type_str ==
"exact") {
358 }
else if (match_type_str ==
"longer") {
360 }
else if (match_type_str ==
"orlonger") {
361 match_type = ORLONGER;
366 template <
typename T>
369 boost::system::error_code ec;
373 match_list_.push_back(
PrefixMatch(prefix, match_type));
377 sort(match_list_.begin(), match_list_.end());
378 typename PrefixMatchList::iterator it =
379 unique(match_list_.begin(), match_list_.end());
380 match_list_.erase(it, match_list_.end());
383 template <
typename T>
387 template <
typename T>
390 const RouteT *in_route =
dynamic_cast<const RouteT *
>(route);
391 if (in_route == NULL)
393 const PrefixT &prefix = in_route->GetPrefix();
394 BOOST_FOREACH(
const PrefixMatch &prefix_match, match_list_) {
396 if (prefix == prefix_match.
prefix)
398 }
else if (prefix_match.
match_type == LONGER) {
399 if (prefix == prefix_match.
prefix)
401 if (prefix.IsMoreSpecific(prefix_match.
prefix))
403 }
else if (prefix_match.
match_type == ORLONGER) {
404 if (prefix.IsMoreSpecific(prefix_match.
prefix))
411 template <
typename T>
417 template <
typename T>
421 BOOST_FOREACH(
const PrefixMatch &prefix_match, match_list_) {
422 oss <<
" " << prefix_match.
prefix.ToString();
425 }
else if (prefix_match.
match_type == ORLONGER) {
430 oss.seekp(-1, oss.cur);
438 static const map<string, MatchProtocol::MatchProtocolType>
fromString
439 = boost::assign::map_list_of
450 static const map<MatchProtocol::MatchProtocolType, string>
toString
451 = boost::assign::map_list_of
462 static const map<MatchProtocol::MatchProtocolType, BgpPath::PathSource>
474 static const vector<MatchProtocol::MatchProtocolType>
486 map<MatchProtocol::MatchProtocolType, string>::const_iterator it =
491 return "unspecified";
495 const string &protocol) {
496 map<string, MatchProtocol::MatchProtocolType>::const_iterator it =
506 map<MatchProtocol::MatchProtocolType, BgpPath::PathSource>::const_iterator
515 BOOST_FOREACH(
const string &protocol, protocols) {
525 vector<MatchProtocolType>::iterator it =
550 if (mapped_src == path_src) {
551 if (protocol ==
XMPP && !is_xmpp)
553 if (protocol ==
BGP && (bgpaas || is_xmpp))
555 if (protocol ==
BGPaaS && (!bgpaas || is_xmpp))
567 oss <<
"protocol [ ";
572 oss.seekp(-1, oss.cur);
const Community * community() const
virtual bool IsEqual(const RoutingPolicyMatch &community) const
static const map< string, MatchProtocol::MatchProtocolType > fromString
virtual bool IsXmppPeer() const =0
virtual bool Match(const BgpRoute *route, const BgpPath *path, const BgpAttr *attr) const
static const map< MatchProtocol::MatchProtocolType, string > toString
static MatchProtocol::MatchProtocolType MatchProtocolFromString(const string &protocol)
static const vector< MatchProtocol::MatchProtocolType > isSubprotocol
virtual bool IsRouterTypeBGPaaS() const =0
MatchProtocol(const std::vector< std::string > &protocols)
std::string prefix_to_match
virtual bool Match(const BgpRoute *route, const BgpPath *path, const BgpAttr *attr) const
virtual std::string ToString() const
virtual std::string ToString() const
static bool regex_match(const std::string &input, const regex ®ex)
const std::string & sub_protocol() const
PathSource GetSource() const
std::vector< PrefixMatchConfig > PrefixMatchConfigList
static BgpPath::PathSource PathSourceFromMatchProtocol(MatchProtocol::MatchProtocolType src)
std::string prefix_match_type
PrefixMatchList match_list_
const string MatchProtocolToString(MatchProtocol::MatchProtocolType protocol)
static bool IsSubprotocol(MatchProtocol::MatchProtocolType protocol)
static bool regex_search(const std::string &input, const regex ®ex)
const PathSourceList & protocols() const
const ExtCommunity * ext_community() const
virtual bool IsEqual(const RoutingPolicyMatch &prefix) const
static const map< MatchProtocol::MatchProtocolType, BgpPath::PathSource > pathSourceMap
MatchPrefix(const PrefixMatchConfigList &match_config_list)
static PhysicalDevice::ManagementProtocol FromString(const string &proto)
static MatchType GetMatchType(const std::string &match_type_str)