LCOV - code coverage report
Current view: top level - bgp - bgp_path.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 55 55 100.0 %
Date: 2026-06-22 02:21:21 Functions: 38 38 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
       3             :  */
       4             : 
       5             : #ifndef SRC_BGP_BGP_PATH_H_
       6             : #define SRC_BGP_BGP_PATH_H_
       7             : 
       8             : #include <string>
       9             : #include <vector>
      10             : 
      11             : #include "base/util.h"
      12             : #include "route/path.h"
      13             : #include "bgp/bgp_attr.h"
      14             : 
      15             : class BgpTable;
      16             : class BgpRoute;
      17             : class IPeer;
      18             : 
      19             : class BgpPath : public Path {
      20             : public:
      21             :     enum PathFlag {
      22             :         AsPathLooped = 1 << 0,
      23             :         NoNeighborAs = 1 << 1,
      24             :         Stale = 1 << 2,
      25             :         NoTunnelEncap = 1 << 3,
      26             :         OriginatorIdLooped = 1 << 4,
      27             :         ResolveNexthop = 1 << 5,
      28             :         ResolvedPath = 1 << 6,
      29             :         RoutingPolicyReject = 1 << 7,
      30             :         LlgrStale = 1 << 8,
      31             :         ClusterListLooped = 1 << 9,
      32             :         AliasedPath = 1 << 10,
      33             :         CheckGlobalErmVpnRoute = 1 << 11,
      34             :     };
      35             : 
      36             :     // Ordered in the ascending order of path preference
      37             :     enum PathSource {
      38             :         None = 0,
      39             :         BGP_XMPP = 1,
      40             :         ServiceChain = 2,
      41             :         StaticRoute = 3,
      42             :         Aggregate = 4,
      43             :         Local = 5
      44             :     };
      45             : 
      46             :     static const uint32_t INFEASIBLE_MASK = (AsPathLooped |
      47             :         NoNeighborAs | NoTunnelEncap | OriginatorIdLooped | ResolveNexthop |
      48             :         RoutingPolicyReject | ClusterListLooped | CheckGlobalErmVpnRoute);
      49             : 
      50             :     static std::string PathIdString(uint32_t path_id);
      51             : 
      52             :     BgpPath(const IPeer *peer, uint32_t path_id, PathSource src,
      53             :             const BgpAttrPtr ptr, uint32_t flags, uint32_t label,
      54             :             uint32_t l3_label = 0);
      55             :     BgpPath(const IPeer *peer, PathSource src, const BgpAttrPtr attr,
      56             :             uint32_t flags, uint32_t label, uint32_t l3_label = 0);
      57             :     BgpPath(uint32_t path_id, PathSource src, const BgpAttrPtr attr,
      58             :             uint32_t flags = 0, uint32_t label = 0, uint32_t l3_label = 0);
      59             :     BgpPath(PathSource src, const BgpAttrPtr attr,
      60             :             uint32_t flags = 0, uint32_t label = 0, uint32_t l3_label = 0);
      61     1354849 :     virtual ~BgpPath() {
      62     1354849 :     }
      63             : 
      64             :     void AddExtCommunitySubCluster(uint32_t subcluster_id);
      65             : 
      66             :     RouteDistinguisher GetSourceRouteDistinguisher() const;
      67             : 
      68      723546 :     bool IsVrfOriginated() const {
      69      723546 :         if (IsReplicated())
      70      408851 :             return false;
      71      314697 :         if (source_ != Aggregate && source_ != BGP_XMPP && source_ != Local)
      72        1967 :             return false;
      73      312730 :         return true;
      74             :     }
      75             : 
      76     7290158 :     IPeer *GetPeer() { return const_cast<IPeer *>(peer_); }
      77     2188360 :     const IPeer *GetPeer() const { return peer_; }
      78     5241546 :     const uint32_t GetPathId() const { return path_id_; }
      79             : 
      80             :     void UpdatePeerRefCount(int count, Address::Family family) const;
      81             : 
      82      712029 :     void SetAttr(const BgpAttrPtr attr, const BgpAttrPtr original_attr) {
      83      712029 :         attr_ = attr;
      84      712024 :         original_attr_ = original_attr;
      85      712035 :     }
      86             : 
      87     5761498 :     const BgpAttr *GetAttr() const { return attr_.get(); }
      88     2316626 :     const BgpAttr *GetOriginalAttr() const { return original_attr_.get(); }
      89     1948002 :     uint32_t GetLabel() const { return label_; }
      90      891144 :     uint32_t GetL3Label() const { return l3_label_; }
      91     1656529 :     virtual bool IsReplicated() const { return false; }
      92    14618788 :     bool IsFeasible() const { return ((flags_ & INFEASIBLE_MASK) == 0); }
      93             : 
      94        3053 :     bool IsResolutionFeasible() const {
      95        3053 :         return ((flags_ & (INFEASIBLE_MASK & ~ResolveNexthop)) == 0);
      96             :     }
      97             : 
      98     5057160 :     bool IsAliased() const { return ((flags_ & AliasedPath) != 0); }
      99      950927 :     bool IsResolved() const { return ((flags_ & ResolvedPath) != 0); }
     100    10649704 :     uint32_t GetFlags() const { return flags_; }
     101             :     std::vector<std::string> GetFlagsStringList() const;
     102             : 
     103    11592559 :     PathSource GetSource() const { return source_; }
     104             :     std::string GetSourceString(bool combine_bgp_and_xmpp = false) const;
     105             : 
     106             :     // Check if the path is stale
     107     3739028 :     bool IsStale() const { return ((flags_ & Stale) != 0); }
     108             : 
     109             :     // Check if the path is stale
     110     8548130 :     bool IsLlgrStale() const { return ((flags_ & LlgrStale) != 0); }
     111             : 
     112             :     // Mark a path as rejected by Routing policy
     113          19 :     void SetPolicyReject() { flags_ |= RoutingPolicyReject; }
     114             : 
     115             :     // Reset a path as active from Routing Policy
     116           3 :     void ResetPolicyReject() { flags_ &= ~RoutingPolicyReject; }
     117             : 
     118      448393 :     bool IsPolicyReject() const {
     119      448393 :         return ((flags_ & RoutingPolicyReject) != 0);
     120             :     }
     121             : 
     122             :     // Mark a path as stale
     123           5 :     void SetStale() { flags_ |= Stale; }
     124             : 
     125             :     // Reset a path as active (not stale)
     126        3139 :     void ResetStale() { flags_ &= ~Stale; }
     127             : 
     128             :     // Mark/Reset a path as needing resolution
     129         106 :     void SetResolveNextHop() { flags_ |= ResolveNexthop; }
     130             :     void ResetResolveNextHop() { flags_ &= ~ResolveNexthop; }
     131             : 
     132          26 :     void SetLlgrStale() { flags_ |= LlgrStale; }
     133          16 :     void ResetLlgrStale() { flags_ &= ~LlgrStale; }
     134             : 
     135     1140776 :     bool NeedsResolution() const { return ((flags_ & ResolveNexthop) != 0); }
     136      515999 :     bool CheckErmVpn() const {
     137      515999 :         return ((flags_ & CheckGlobalErmVpnRoute) != 0);
     138             :     }
     139         626 :     void ResetCheckErmVpn() { flags_ &= ~CheckGlobalErmVpnRoute; }
     140         178 :     void SetCheckErmVpn() { flags_ |= CheckGlobalErmVpnRoute; }
     141             : 
     142             :     virtual std::string ToString() const;
     143             : 
     144             :     // Select one path over other
     145             :     int PathCompare(const BgpPath &rhs, bool allow_ecmp) const;
     146             :     bool PathSameNeighborAs(const BgpPath &rhs) const;
     147             : 
     148             : private:
     149             :     const IPeer *peer_;
     150             :     const uint32_t path_id_;
     151             :     const PathSource source_;
     152             :     // Attribute for the BgpPath. If routing policy updates the path attribute,
     153             :     // this member contains the attribute after policy update
     154             :     BgpAttrPtr attr_;
     155             :     // Original path attribute before applying routing policy
     156             :     BgpAttrPtr original_attr_;
     157             :     uint32_t flags_;
     158             :     uint32_t label_;
     159             :     uint32_t l3_label_;
     160             : };
     161             : 
     162             : class BgpSecondaryPath : public BgpPath {
     163             : public:
     164             :     BgpSecondaryPath(const IPeer *peer, uint32_t path_id, PathSource src,
     165             :                      const BgpAttrPtr attr, uint32_t flags, uint32_t label,
     166             :                      uint32_t l3_label = 0);
     167             : 
     168     3609947 :     virtual bool IsReplicated() const {
     169     3609947 :         return true;
     170             :     }
     171             : 
     172      579556 :     void SetReplicateInfo(const BgpTable *table, const BgpRoute *rt) {
     173      579556 :         src_table_ = table;
     174      579556 :         src_entry_ = rt;
     175      579556 :     }
     176             : 
     177     1158878 :     virtual ~BgpSecondaryPath() {
     178     1158878 :     }
     179             : 
     180             :     RouteDistinguisher GetPrimaryRouteDistinguisher() const;
     181             : 
     182       17236 :     const BgpTable *src_table() const {
     183       17236 :         return src_table_;
     184             :     }
     185             : 
     186     1817514 :     const BgpRoute *src_rt() const {
     187     1817514 :         return src_entry_;
     188             :     }
     189             : 
     190             : private:
     191             :     const BgpTable *src_table_;
     192             :     const BgpRoute *src_entry_;
     193             : 
     194             :     DISALLOW_COPY_AND_ASSIGN(BgpSecondaryPath);
     195             : };
     196             : 
     197             : #endif  // SRC_BGP_BGP_PATH_H_

Generated by: LCOV version 1.14