LCOV - code coverage report
Current view: top level - bgp/routing-policy - routing_policy_match.cc (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 0 296 0.0 %
Date: 2026-09-28 02:13:17 Functions: 0 41 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2015 Juniper Networks, Inc. All rights reserved.
       3             :  */
       4             : 
       5             : #include "bgp/routing-policy/routing_policy_match.h"
       6             : 
       7             : #include <boost/foreach.hpp>
       8             : #include <boost/assign/list_of.hpp>
       9             : 
      10             : #include <algorithm>
      11             : #include <map>
      12             : #include <sstream>
      13             : #include <vector>
      14             : 
      15             : #include "bgp/ipeer.h"
      16             : #include "bgp/bgp_attr.h"
      17             : #include "bgp/bgp_path.h"
      18             : #include "bgp/extended-community/default_gateway.h"
      19             : #include "bgp/extended-community/es_import.h"
      20             : #include "bgp/extended-community/esi_label.h"
      21             : #include "bgp/extended-community/etree.h"
      22             : #include "bgp/extended-community/load_balance.h"
      23             : #include "bgp/extended-community/mac_mobility.h"
      24             : #include "bgp/extended-community/router_mac.h"
      25             : #include "bgp/extended-community/site_of_origin.h"
      26             : #include "bgp/extended-community/source_as.h"
      27             : #include "bgp/extended-community/tag.h"
      28             : #include "bgp/extended-community/vrf_route_import.h"
      29             : #include "bgp/origin-vn/origin_vn.h"
      30             : #include "bgp/routing-instance/routepath_replicator.h"
      31             : #include "bgp/routing-instance/routing_instance.h"
      32             : #include "bgp/rtarget/rtarget_address.h"
      33             : #include "bgp/security_group/security_group.h"
      34             : #include "bgp/tunnel_encap/tunnel_encap.h"
      35             : #include "net/community_type.h"
      36             : 
      37             : 
      38             : using contrail::regex;
      39             : using contrail::regex_match;
      40             : using contrail::regex_search;
      41             : using std::includes;
      42             : using std::map;
      43             : using std::ostringstream;
      44             : using std::sort;
      45             : using std::string;
      46             : using std::unique;
      47             : using std::vector;
      48             : using std::find;
      49             : 
      50           0 : MatchCommunity::MatchCommunity(const vector<string> &communities,
      51           0 :     bool match_all) : match_all_(match_all) {
      52             :     // Assume that the each community string that doesn't correspond to a
      53             :     // community name or value is a regex string.
      54           0 :     BOOST_FOREACH(const string &community, communities) {
      55           0 :         uint32_t value = CommunityType::CommunityFromString(community);
      56           0 :         if (value) {
      57           0 :             to_match_.insert(value);
      58             :         } else {
      59           0 :             to_match_regex_strings_.push_back(community);
      60             :         }
      61             :     }
      62             : 
      63             :     // Sort and uniquify the vector of regex strings.
      64           0 :     sort(to_match_regex_strings_.begin(), to_match_regex_strings_.end());
      65             :     vector<string>::iterator it =
      66           0 :         unique(to_match_regex_strings_.begin(), to_match_regex_strings_.end());
      67           0 :     to_match_regex_strings_.erase(it, to_match_regex_strings_.end());
      68             : 
      69             :     // Build a vector of regexs corresponding to the regex strings.
      70           0 :     BOOST_FOREACH(string regex_str, regex_strings()) {
      71           0 :         to_match_regexs_.push_back(regex(regex_str));
      72           0 :     }
      73           0 : }
      74             : 
      75           0 : MatchCommunity::~MatchCommunity() {
      76           0 : }
      77             : 
      78             : //
      79             : // Return true if all community strings (normal or regex) are matched by the
      80             : // community values in the BgpAttr.
      81             : //
      82           0 : bool MatchCommunity::MatchAll(const BgpAttr *attr) const {
      83             :     // Bail if there's no community values in the BgpAttr.
      84           0 :     const Community *comm = attr->community();
      85           0 :     if (!comm)
      86           0 :         return false;
      87             : 
      88             :     // Make sure that all non-regex communities in this MatchCommunity are
      89             :     // present in the BgpAttr.
      90           0 :     vector<uint32_t> list = comm->communities();
      91           0 :     sort(list.begin(), list.end());
      92           0 :     if (!includes(list.begin(), list.end(),
      93           0 :         communities().begin(), communities().end())) {
      94           0 :         return false;
      95             :     }
      96             : 
      97             :     // Make sure that each regex in this MatchCommunity is matched by one
      98             :     // of the communities in the BgpAttr.
      99           0 :     BOOST_FOREACH(const regex &match_expr, regexs()) {
     100           0 :         bool matched = false;
     101           0 :         BOOST_FOREACH(uint32_t community, comm->communities()) {
     102           0 :             string community_str = CommunityType::CommunityToString(community);
     103           0 :             if (regex_match(community_str, match_expr)) {
     104           0 :                 matched = true;
     105           0 :                 break;
     106             :             }
     107           0 :         }
     108           0 :         if (!matched)
     109           0 :             return false;
     110             :     }
     111             : 
     112           0 :     return true;
     113           0 : }
     114             : 
     115             : //
     116             : // Return true if any community strings (normal or regex) is matched by the
     117             : // community values in the BgpAttr.
     118             : //
     119           0 : bool MatchCommunity::MatchAny(const BgpAttr *attr) const {
     120             :     // Bail if there's no community values in the BgpAttr.
     121           0 :     const Community *comm = attr->community();
     122           0 :     if (!comm)
     123           0 :         return false;
     124             : 
     125             :     // Check if any of the community values in the BgpAttr matches one of
     126             :     // the normal community strings.
     127           0 :     BOOST_FOREACH(uint32_t community, comm->communities()) {
     128           0 :         if (communities().find(community) != communities().end())
     129           0 :             return true;
     130             :     }
     131             : 
     132             :     // Check if any of the community values in the BgpAttr matches one of
     133             :     // the community regexs.
     134           0 :     BOOST_FOREACH(uint32_t community, comm->communities()) {
     135           0 :         string community_str = CommunityType::CommunityToString(community);
     136           0 :         BOOST_FOREACH(const regex &match_expr, regexs()) {
     137           0 :             if (regex_match(community_str, match_expr))
     138           0 :                 return true;
     139             :         }
     140           0 :     }
     141             : 
     142           0 :     return false;
     143             : }
     144             : 
     145             : //
     146             : // Return true if the BgpPath matches this MatchCommunity.
     147             : //
     148           0 : bool MatchCommunity::Match(const BgpRoute *route, const BgpPath *path,
     149             :                            const BgpAttr *attr) const {
     150           0 :     return (match_all_ ? MatchAll(attr) : MatchAny(attr));
     151             : }
     152             : 
     153             : //
     154             : // Return string representation of this MatchCommunity.
     155             : //
     156           0 : string MatchCommunity::ToString() const {
     157           0 :     ostringstream oss;
     158           0 :     if (match_all_) {
     159           0 :         oss << "community (all) [ ";
     160             :     } else {
     161           0 :         oss << "community (any) [ ";
     162             :     }
     163           0 :     BOOST_FOREACH(uint32_t community, communities()) {
     164           0 :         string name = CommunityType::CommunityToString(community);
     165           0 :         oss << name << ",";
     166           0 :     }
     167           0 :     BOOST_FOREACH(string regex_str, regex_strings()) {
     168           0 :         oss << regex_str << ",";
     169           0 :     }
     170           0 :     oss.seekp(-1, oss.cur);
     171           0 :     oss << " ]";
     172           0 :     return oss.str();
     173           0 : }
     174             : 
     175             : //
     176             : // Return true if this MatchCommunity is equal to the one supplied.
     177             : //
     178           0 : bool MatchCommunity::IsEqual(const RoutingPolicyMatch &community) const {
     179             :     const MatchCommunity in_community =
     180           0 :         static_cast<const MatchCommunity &>(community);
     181           0 :     if (match_all() != in_community.match_all())
     182           0 :         return false;
     183           0 :     if (communities() != in_community.communities())
     184           0 :         return false;
     185           0 :     if (regex_strings() != in_community.regex_strings())
     186           0 :         return false;
     187           0 :     return true;
     188           0 : }
     189             : 
     190           0 : MatchExtCommunity::MatchExtCommunity(const vector<string> &communities,
     191           0 :     bool match_all) : match_all_(match_all) {
     192             :     // Assume that the each community string that doesn't correspond to a
     193             :     // community name or value is a regex string.
     194           0 :     BOOST_FOREACH(const string &community, communities) {
     195             :         const ExtCommunity::ExtCommunityList list =
     196           0 :             ExtCommunity::ExtCommunityFromString(community);
     197           0 :         if (list.size()) {
     198           0 :             if(!Find(list[0]))
     199           0 :                 to_match_.push_back(list[0]);
     200             :         } else {
     201           0 :             to_match_regex_strings_.push_back(community);
     202             :         }
     203           0 :     }
     204             : 
     205             :     // Sort and uniquify the vector of regex strings.
     206           0 :     sort(to_match_.begin(), to_match_.end());
     207           0 :     sort(to_match_regex_strings_.begin(), to_match_regex_strings_.end());
     208             :     vector<string>::iterator it =
     209           0 :         unique(to_match_regex_strings_.begin(), to_match_regex_strings_.end());
     210           0 :     to_match_regex_strings_.erase(it, to_match_regex_strings_.end());
     211             : 
     212             :     // Build a vector of regexs corresponding to the regex strings.
     213           0 :     BOOST_FOREACH(string regex_str, regex_strings()) {
     214           0 :         to_match_regexs_.push_back(regex(regex_str));
     215           0 :     }
     216           0 : }
     217             : 
     218           0 : MatchExtCommunity::~MatchExtCommunity() {
     219           0 : }
     220             : 
     221             : //
     222             : // Return true if all community strings (normal or regex) are matched by the
     223             : // community values in the BgpAttr.
     224             : //
     225           0 : bool MatchExtCommunity::MatchAll(const BgpAttr *attr) const {
     226             :     // Bail if there's no community values in the BgpAttr.
     227           0 :     const ExtCommunity *comm = attr->ext_community();
     228           0 :     if (!comm)
     229           0 :         return false;
     230             : 
     231             :     // Make sure that all non-regex communities in this MatchExtCommunity are
     232             :     // present in the BgpAttr.
     233           0 :     ExtCommunity::ExtCommunityList list = comm->communities();
     234           0 :     sort(list.begin(), list.end());
     235           0 :     if (!includes(list.begin(), list.end(),
     236           0 :         communities().begin(), communities().end())) {
     237           0 :         return false;
     238             :     }
     239             : 
     240             :     // Make sure that each regex in this MatchExtCommunity is matched by one
     241             :     // of the communities in the BgpAttr.
     242           0 :     BOOST_FOREACH(const regex &match_expr, regexs()) {
     243           0 :         bool matched = false;
     244           0 :         BOOST_FOREACH(ExtCommunity::ExtCommunityValue community,
     245             :                       comm->communities()) {
     246           0 :             string community_str = ExtCommunity::ToString(community);
     247           0 :             if (regex_match(community_str, match_expr)) {
     248           0 :                 matched = true;
     249           0 :                 break;
     250             :             }
     251           0 :             community_str = ExtCommunity::ToHexString(community);
     252           0 :             if (regex_match(community_str, match_expr)) {
     253           0 :                 matched = true;
     254           0 :                 break;
     255             :             }
     256           0 :         }
     257           0 :         if (!matched)
     258           0 :             return false;
     259             :     }
     260             : 
     261           0 :     return true;
     262           0 : }
     263             : 
     264           0 : bool MatchExtCommunity::Find(const ExtCommunity::ExtCommunityValue &community)
     265             :                             const {
     266           0 :     return (std::find(communities().begin(), communities().end(), community) !=
     267           0 :             communities().end());
     268             : }
     269             : 
     270             : //
     271             : // Return true if any community strings (normal or regex) is matched by the
     272             : // community values in the BgpAttr.
     273             : //
     274           0 : bool MatchExtCommunity::MatchAny(const BgpAttr *attr) const {
     275             :     // Bail if there's no community values in the BgpAttr.
     276           0 :     const ExtCommunity *comm = attr->ext_community();
     277           0 :     if (!comm)
     278           0 :         return false;
     279             : 
     280             :     // Check if any of the community values in the BgpAttr matches one of
     281             :     // the normal community strings.
     282           0 :     BOOST_FOREACH(ExtCommunity::ExtCommunityValue community,
     283             :                   comm->communities()) {
     284           0 :         if (Find(community))
     285           0 :             return true;
     286             :     }
     287             : 
     288             :     // Check if any of the community values in the BgpAttr matches one of
     289             :     // the community regexs.
     290           0 :     BOOST_FOREACH(ExtCommunity::ExtCommunityValue community,
     291             :                   comm->communities()) {
     292           0 :         string community_str = ExtCommunity::ToString(community);
     293           0 :         BOOST_FOREACH(const regex &match_expr, regexs()) {
     294           0 :             if (regex_match(community_str, match_expr))
     295           0 :                 return true;
     296             :         }
     297           0 :         community_str = ExtCommunity::ToHexString(community);
     298           0 :         BOOST_FOREACH(const regex &match_expr, regexs()) {
     299           0 :             if (regex_match(community_str, match_expr))
     300           0 :                 return true;
     301             :         }
     302           0 :     }
     303             : 
     304           0 :     return false;
     305             : }
     306             : 
     307             : //
     308             : // Return true if the BgpPath matches this MatchExtCommunity.
     309             : //
     310           0 : bool MatchExtCommunity::Match(const BgpRoute *route, const BgpPath *path,
     311             :                               const BgpAttr *attr) const {
     312           0 :     return (match_all_ ? MatchAll(attr) : MatchAny(attr));
     313             : }
     314             : 
     315             : //
     316             : // Return string representation of this MatchExtCommunity.
     317             : //
     318           0 : string MatchExtCommunity::ToString() const {
     319           0 :     ostringstream oss;
     320           0 :     if (match_all_) {
     321           0 :         oss << "Extcommunity (all) [ ";
     322             :     } else {
     323           0 :         oss << "Extcommunity (any) [ ";
     324             :     }
     325           0 :     BOOST_FOREACH(ExtCommunity::ExtCommunityValue community, communities()) {
     326           0 :         string name = ExtCommunity::ToString(community);
     327           0 :         oss << name << ",";
     328           0 :     }
     329           0 :     BOOST_FOREACH(string regex_str, regex_strings()) {
     330           0 :         oss << regex_str << ",";
     331           0 :     }
     332           0 :     oss.seekp(-1, oss.cur);
     333           0 :     oss << " ]";
     334           0 :     return oss.str();
     335           0 : }
     336             : 
     337             : //
     338             : // Return true if this MatchExtCommunity is equal to the one supplied.
     339             : //
     340           0 : bool MatchExtCommunity::IsEqual(const RoutingPolicyMatch &community) const {
     341             :     const MatchExtCommunity in_community =
     342           0 :         static_cast<const MatchExtCommunity &>(community);
     343           0 :     if (match_all() != in_community.match_all())
     344           0 :         return false;
     345           0 :     if (communities() != in_community.communities())
     346           0 :         return false;
     347           0 :     if (regex_strings() != in_community.regex_strings())
     348           0 :         return false;
     349           0 :     return true;
     350           0 : }
     351             : 
     352             : template <typename T>
     353           0 : typename MatchPrefix<T>::MatchType MatchPrefix<T>::GetMatchType(
     354             :     const string &match_type_str) {
     355           0 :     MatchType match_type = EXACT;
     356           0 :     if (match_type_str == "exact") {
     357           0 :         match_type = EXACT;
     358           0 :     } else if (match_type_str == "longer") {
     359           0 :         match_type = LONGER;
     360           0 :     } else if (match_type_str == "orlonger") {
     361           0 :         match_type = ORLONGER;
     362             :     }
     363           0 :     return match_type;
     364             : }
     365             : 
     366             : template <typename T>
     367           0 : MatchPrefix<T>::MatchPrefix(const PrefixMatchConfigList &match_config_list) {
     368           0 :     BOOST_FOREACH(const PrefixMatchConfig &match_config, match_config_list) {
     369           0 :         boost::system::error_code ec;
     370           0 :         PrefixT prefix = PrefixT::FromString(match_config.prefix_to_match, &ec);
     371             :         MatchType match_type =
     372           0 :             MatchPrefix<T>::GetMatchType(match_config.prefix_match_type);
     373           0 :         match_list_.push_back(PrefixMatch(prefix, match_type));
     374             :     }
     375             : 
     376             :     // Sort and uniquify the vector of PrefixMatch elements.
     377           0 :     sort(match_list_.begin(), match_list_.end());
     378             :     typename PrefixMatchList::iterator it =
     379           0 :         unique(match_list_.begin(), match_list_.end());
     380           0 :     match_list_.erase(it, match_list_.end());
     381           0 : }
     382             : 
     383             : template <typename T>
     384           0 : MatchPrefix<T>::~MatchPrefix() {
     385           0 : }
     386             : 
     387             : template <typename T>
     388           0 : bool MatchPrefix<T>::Match(const BgpRoute *route, const BgpPath *path,
     389             :                            const BgpAttr *attr) const {
     390           0 :     const RouteT *in_route = dynamic_cast<const RouteT *>(route);
     391           0 :     if (in_route == NULL)
     392           0 :         return false;
     393           0 :     const PrefixT &prefix = in_route->GetPrefix();
     394           0 :     BOOST_FOREACH(const PrefixMatch &prefix_match, match_list_) {
     395           0 :         if (prefix_match.match_type == EXACT) {
     396           0 :             if (prefix == prefix_match.prefix)
     397           0 :                 return true;
     398           0 :         } else if (prefix_match.match_type == LONGER) {
     399           0 :             if (prefix == prefix_match.prefix)
     400           0 :                 continue;
     401           0 :             if (prefix.IsMoreSpecific(prefix_match.prefix))
     402           0 :                 return true;
     403           0 :         } else if (prefix_match.match_type == ORLONGER) {
     404           0 :             if (prefix.IsMoreSpecific(prefix_match.prefix))
     405           0 :                 return true;
     406             :         }
     407             :     }
     408           0 :     return false;
     409             : }
     410             : 
     411             : template <typename T>
     412           0 : bool MatchPrefix<T>::IsEqual(const RoutingPolicyMatch &prefix) const {
     413           0 :     const MatchPrefix in_prefix = static_cast<const MatchPrefix&>(prefix);
     414           0 :     return (in_prefix.match_list_ == match_list_);
     415           0 : }
     416             : 
     417             : template <typename T>
     418           0 : string MatchPrefix<T>::ToString() const {
     419           0 :     ostringstream oss;
     420           0 :     oss << "prefix [";
     421           0 :     BOOST_FOREACH(const PrefixMatch &prefix_match, match_list_) {
     422           0 :         oss << " " << prefix_match.prefix.ToString();
     423           0 :         if  (prefix_match.match_type == LONGER) {
     424           0 :             oss << " longer";
     425           0 :         } else if  (prefix_match.match_type == ORLONGER) {
     426           0 :             oss << " orlonger";
     427             :         }
     428           0 :         oss << ",";
     429             :     }
     430           0 :     oss.seekp(-1, oss.cur);
     431           0 :     oss << " ]";
     432           0 :     return oss.str();
     433           0 : }
     434             : 
     435             : template class MatchPrefix<PrefixMatchInet>;
     436             : template class MatchPrefix<PrefixMatchInet6>;
     437             : 
     438             : static const map<string, MatchProtocol::MatchProtocolType> fromString
     439             :   = boost::assign::map_list_of
     440             :     ("bgp", MatchProtocol::BGP)
     441             :     ("xmpp", MatchProtocol::XMPP)
     442             :     ("static", MatchProtocol::StaticRoute)
     443             :     ("service-chain", MatchProtocol::ServiceChainRoute)
     444             :     ("aggregate", MatchProtocol::AggregateRoute)
     445             :     ("interface", MatchProtocol::Interface)
     446             :     ("interface-static", MatchProtocol::InterfaceStatic)
     447             :     ("service-interface", MatchProtocol::ServiceInterface)
     448             :     ("bgpaas", MatchProtocol::BGPaaS);
     449             : 
     450             : static const map<MatchProtocol::MatchProtocolType, string> toString
     451             :   = boost::assign::map_list_of
     452             :     (MatchProtocol::BGP, "bgp")
     453             :     (MatchProtocol::XMPP, "xmpp")
     454             :     (MatchProtocol::StaticRoute, "static")
     455             :     (MatchProtocol::ServiceChainRoute, "service-chain")
     456             :     (MatchProtocol::AggregateRoute, "aggregate")
     457             :     (MatchProtocol::Interface, "interface")
     458             :     (MatchProtocol::InterfaceStatic, "interface-static")
     459             :     (MatchProtocol::ServiceInterface, "service-interface")
     460             :     (MatchProtocol::BGPaaS, "bgpaas");
     461             : 
     462             : static const map<MatchProtocol::MatchProtocolType, BgpPath::PathSource>
     463             :     pathSourceMap = boost::assign::map_list_of
     464             :     (MatchProtocol::BGP, BgpPath::BGP_XMPP)
     465             :     (MatchProtocol::XMPP, BgpPath::BGP_XMPP)
     466             :     (MatchProtocol::StaticRoute, BgpPath::StaticRoute)
     467             :     (MatchProtocol::ServiceChainRoute, BgpPath::ServiceChain)
     468             :     (MatchProtocol::AggregateRoute, BgpPath::Aggregate)
     469             :     (MatchProtocol::Interface, BgpPath::BGP_XMPP)
     470             :     (MatchProtocol::InterfaceStatic, BgpPath::BGP_XMPP)
     471             :     (MatchProtocol::ServiceInterface, BgpPath::BGP_XMPP)
     472             :     (MatchProtocol::BGPaaS, BgpPath::BGP_XMPP);
     473             : 
     474             : static const vector<MatchProtocol::MatchProtocolType>
     475             :     isSubprotocol = boost::assign::list_of(MatchProtocol::Interface)
     476             :                                           (MatchProtocol::InterfaceStatic)
     477             :                                           (MatchProtocol::ServiceInterface)
     478             :                                           (MatchProtocol::StaticRoute);
     479             : 
     480           0 : static bool IsSubprotocol(MatchProtocol::MatchProtocolType protocol) {
     481           0 :     return (find(isSubprotocol.begin(), isSubprotocol.end(), protocol) !=
     482           0 :             isSubprotocol.end());
     483             : }
     484             : 
     485           0 : const string MatchProtocolToString(MatchProtocol::MatchProtocolType protocol) {
     486             :     map<MatchProtocol::MatchProtocolType, string>::const_iterator it =
     487           0 :         toString.find(protocol);
     488           0 :     if (it != toString.end()) {
     489           0 :         return it->second;
     490             :     }
     491           0 :     return "unspecified";
     492             : }
     493             : 
     494           0 : static MatchProtocol::MatchProtocolType MatchProtocolFromString(
     495             :     const string &protocol) {
     496             :     map<string, MatchProtocol::MatchProtocolType>::const_iterator it =
     497           0 :         fromString.find(protocol);
     498           0 :     if (it != fromString.end()) {
     499           0 :         return it->second;
     500             :     }
     501           0 :     return MatchProtocol::Unspecified;
     502             : }
     503             : 
     504           0 : static BgpPath::PathSource PathSourceFromMatchProtocol(
     505             :     MatchProtocol::MatchProtocolType src) {
     506             :     map<MatchProtocol::MatchProtocolType, BgpPath::PathSource>::const_iterator
     507           0 :         it = pathSourceMap.find(src);
     508           0 :     if (it != pathSourceMap.end()) {
     509           0 :         return it->second;
     510             :     }
     511           0 :     return BgpPath::None;
     512             : }
     513             : 
     514           0 : MatchProtocol::MatchProtocol(const vector<string> &protocols) {
     515           0 :     BOOST_FOREACH(const string &protocol, protocols) {
     516           0 :         MatchProtocolType value = MatchProtocolFromString(protocol);
     517             :         // Ignore invalid protocol values.
     518           0 :         if (value == Unspecified)
     519           0 :             continue;
     520           0 :         to_match_.push_back(value);
     521             :     }
     522             : 
     523             :     // Sort and uniquify the vector match protocols.
     524           0 :     sort(to_match_.begin(), to_match_.end());
     525             :     vector<MatchProtocolType>::iterator it =
     526           0 :         unique(to_match_.begin(), to_match_.end());
     527           0 :     to_match_.erase(it, to_match_.end());
     528           0 : }
     529             : 
     530           0 : MatchProtocol::~MatchProtocol() {
     531           0 : }
     532             : 
     533           0 : bool MatchProtocol::Match(const BgpRoute *route, const BgpPath *path,
     534             :                            const BgpAttr *attr) const {
     535           0 :     BgpPath::PathSource path_src = path->GetSource();
     536           0 :     bool is_xmpp = path->GetPeer() ? path->GetPeer()->IsXmppPeer() : false;
     537           0 :     bool bgpaas = path->GetPeer() ? path->GetPeer()->IsRouterTypeBGPaaS() : false;
     538           0 :     BOOST_FOREACH(MatchProtocolType protocol, protocols()) {
     539           0 :         if (IsSubprotocol(protocol)) {
     540             :             // Check only if matching protocol is subprotocol
     541           0 :             if (attr && !attr->sub_protocol().empty()) {
     542           0 :                 std::string matchps = MatchProtocolToString(protocol);
     543           0 :                 if (matchps.compare(attr->sub_protocol()) == 0)
     544           0 :                     return true;
     545           0 :             }
     546             :         } else {
     547             :             BgpPath::PathSource mapped_src =
     548           0 :                                 PathSourceFromMatchProtocol(protocol);
     549           0 :             if (mapped_src != BgpPath::None) {
     550           0 :                 if (mapped_src == path_src) {
     551           0 :                     if (protocol == XMPP && !is_xmpp)
     552           0 :                         continue;
     553           0 :                     if (protocol == BGP && (bgpaas || is_xmpp))
     554           0 :                         continue;
     555           0 :                     if (protocol == BGPaaS && (!bgpaas || is_xmpp))
     556           0 :                         continue;
     557           0 :                     return true;
     558             :                 }
     559             :             }
     560             :         }
     561             :     }
     562           0 :     return false;
     563             : }
     564             : 
     565           0 : string MatchProtocol::ToString() const {
     566           0 :     ostringstream oss;
     567           0 :     oss << "protocol [ ";
     568           0 :     BOOST_FOREACH(MatchProtocolType protocol, protocols()) {
     569           0 :         string name = MatchProtocolToString(protocol);
     570           0 :         oss << name << ",";
     571           0 :     }
     572           0 :     oss.seekp(-1, oss.cur);
     573           0 :     oss << " ]";
     574           0 :     return oss.str();
     575           0 : }
     576             : 
     577           0 : bool MatchProtocol::IsEqual(const RoutingPolicyMatch &protocol) const {
     578             :     const MatchProtocol in_protocol =
     579           0 :         static_cast<const MatchProtocol&>(protocol);
     580           0 :     return (protocols() == in_protocol.protocols());
     581           0 : }

Generated by: LCOV version 1.14