LCOV - code coverage report
Current view: top level - vnsw/agent/controller - controller_route_path.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 22 45 48.9 %
Date: 2026-08-03 02:19:58 Functions: 12 25 48.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
       3             :  */
       4             : 
       5             : #ifndef controller_route_path_hpp
       6             : #define controller_route_path_hpp
       7             : 
       8             : #include <cmn/agent_cmn.h>
       9             : #include <cmn/agent.h>
      10             : #include <oper/route_common.h>
      11             : #include <xmpp_enet_types.h>
      12             : #include <xmpp_unicast_types.h>
      13             : 
      14             : //Forward declaration
      15             : class AgentXmppChannel;
      16             : struct AgentRouteData;
      17             : class EcmpLoadBalance;
      18             : class Peer;
      19             : class BgpPeer;
      20             : class TunnelNHKey;
      21             : class TunnelNHData;
      22             : class TunnelType;
      23             : class ControllerVmRoute;
      24             : class LocalVmRoute;
      25             : class InetInterfaceRoute;
      26             : class VlanNhRoute;
      27             : class VNController;
      28             : class ClonedLocalPath;
      29             : class EcmpData;
      30             : 
      31             : /*
      32             :  * Contains all Controller Route data definition.
      33             :  * Currently there are four kind of routes added from controller:
      34             :  * - Remote - Native to controller, derived from ControllerPeerPath
      35             :  * - Local - Derived from LocalVmRoute of agent_path
      36             :  * - Vlan - Derived from VlanNHRoute from agent_path
      37             :  * - Inet Interface - Derived from InetInterfaceRoute from agent_path.
      38             :  *
      39             :  */
      40             : 
      41             : class ControllerPeerPath : public AgentRouteData {
      42             : public:
      43             :     static const uint64_t kInvalidPeerIdentifier = 0xFFFFFFFFFFFFFFFFLL;
      44             :     ControllerPeerPath(const BgpPeer *peer);
      45        1237 :     ~ControllerPeerPath() { }
      46             : 
      47         119 :     virtual bool UpdateRoute(AgentRoute *route) {return false;}
      48             : 
      49             : private:
      50             :     const BgpPeer *peer_;
      51             : };
      52             : 
      53             : /*
      54             :  * Implementation for adding remote route data.
      55             :  */
      56             : class ControllerVmRoute : public ControllerPeerPath {
      57             : public:
      58           9 :     ControllerVmRoute(const BgpPeer *peer, const string &vrf_name,
      59             :                   const Ip4Address &addr, uint32_t label,
      60             :                   const VnListType &dest_vn_list, int bmap,
      61             :                   const SecurityGroupList &sg_list,
      62             :                   const TagList &tag_list,
      63             :                   const PathPreference &path_preference,
      64             :                   DBRequest &req, bool ecmp_suppressed,
      65             :                   const EcmpLoadBalance &ecmp_load_balance,
      66             :                   bool etree_leaf,
      67           9 :                   const MacAddress &rewrite_dmac = MacAddress()) :
      68           9 :         ControllerPeerPath(peer), server_vrf_(vrf_name), tunnel_dest_(addr),
      69           9 :         tunnel_bmap_(bmap), label_(label), dest_vn_list_(dest_vn_list),
      70           9 :         sg_list_(sg_list),tag_list_(tag_list), path_preference_(path_preference),
      71           9 :         ecmp_suppressed_(ecmp_suppressed), ecmp_load_balance_(ecmp_load_balance),
      72          27 :         etree_leaf_(etree_leaf), rewrite_dmac_(rewrite_dmac)
      73             :         {
      74           9 :             nh_req_.Swap(&req);
      75           9 :             tunnel_dest_list_.push_back(addr);
      76           9 :             label_list_.push_back(label);
      77           9 :         }
      78             :     // Data passed in case of delete from BGP peer, to validate
      79             :     // the request at time of processing.
      80         588 :     ControllerVmRoute(const BgpPeer *peer) : ControllerPeerPath(peer) { }
      81          36 :     virtual ~ControllerVmRoute() { }
      82             : 
      83             :     virtual bool AddChangePathExtended(Agent *agent, AgentPath *path,
      84             :                                        const AgentRoute *rt);
      85             :     virtual bool UpdateRoute(AgentRoute *route);
      86           0 :     virtual string ToString() const {return "remote VM";}
      87             :     const SecurityGroupList &sg_list() const {return sg_list_;}
      88             :     const TagList &tag_list() const {return tag_list_;}
      89             :     static ControllerVmRoute *MakeControllerVmRoute(const BgpPeer *peer,
      90             :                                             const string &default_vrf,
      91             :                                             const Ip4Address &router_id,
      92             :                                             const string &vrf_name,
      93             :                                             const Ip4Address &tunnel_dest,
      94             :                                             TunnelType::TypeBmap bmap,
      95             :                                             uint32_t label,
      96             :                                             MacAddress rewrite_dmac,
      97             :                                             const VnListType &dest_vn_list,
      98             :                                             const SecurityGroupList &sg_list,
      99             :                                             const TagList &tag_list,
     100             :                                             const PathPreference &path_preference,
     101             :                                             bool ecmp_suppressed,
     102             :                                             const EcmpLoadBalance &ecmp_load_balance,
     103             :                                             bool etree_leaf);
     104             : 
     105             : private:
     106             :     string server_vrf_;
     107             :     Ip4Address tunnel_dest_;
     108             :     TunnelType::TypeBmap tunnel_bmap_;
     109             :     uint32_t label_;
     110             :     VnListType dest_vn_list_;
     111             :     SecurityGroupList sg_list_;
     112             :     TagList tag_list_;
     113             :     PathPreference path_preference_;
     114             :     DBRequest nh_req_;
     115             :     bool ecmp_suppressed_;
     116             :     EcmpLoadBalance ecmp_load_balance_;
     117             :     bool etree_leaf_;
     118             :     MacAddress rewrite_dmac_;
     119             :     std::vector<IpAddress> tunnel_dest_list_;
     120             :     std::vector<uint32_t> label_list_;
     121             :     DISALLOW_COPY_AND_ASSIGN(ControllerVmRoute);
     122             : };
     123             : 
     124             : class ControllerMplsRoute : public ControllerPeerPath {
     125             : public:
     126           0 :     ControllerMplsRoute(const BgpPeer *peer, const string &vrf_name,
     127             :                   const Ip4Address &addr, uint32_t label,
     128             :                   const VnListType &dest_vn_list, int bmap,
     129             :                   const SecurityGroupList &sg_list,
     130             :                   const TagList &tag_list,
     131             :                   const PathPreference &path_preference,
     132             :                   DBRequest &req, bool ecmp_suppressed,
     133             :                   const EcmpLoadBalance &ecmp_load_balance,
     134             :                   bool etree_leaf,
     135           0 :                   const MacAddress &rewrite_dmac = MacAddress()) :
     136           0 :         ControllerPeerPath(peer), server_vrf_(vrf_name), tunnel_dest_(addr),
     137           0 :         tunnel_bmap_(bmap), label_(label), dest_vn_list_(dest_vn_list),
     138           0 :         sg_list_(sg_list),tag_list_(tag_list), path_preference_(path_preference),
     139           0 :         ecmp_suppressed_(ecmp_suppressed), ecmp_load_balance_(ecmp_load_balance),
     140           0 :         etree_leaf_(etree_leaf), rewrite_dmac_(rewrite_dmac)
     141           0 :         {nh_req_.Swap(&req);}
     142             :     // Data passed in case of delete from BGP peer, to validate
     143             :     // the request at time of processing.
     144             :     ControllerMplsRoute(const BgpPeer *peer) : ControllerPeerPath(peer) { }
     145           0 :     virtual ~ControllerMplsRoute() { }
     146             : 
     147             :     virtual bool AddChangePathExtended(Agent *agent, AgentPath *path,
     148             :                                        const AgentRoute *rt);
     149             :     //virtual bool UpdateRoute(AgentRoute *route);
     150           0 :     virtual string ToString() const {return "remote PE";}
     151             :     const SecurityGroupList &sg_list() const {return sg_list_;}
     152             :     const TagList &tag_list() const {return tag_list_;}
     153             :     static ControllerMplsRoute *MakeControllerMplsRoute(const BgpPeer *peer,
     154             :                                             const string &default_vrf,
     155             :                                             const Ip4Address &router_id,
     156             :                                             const string &vrf_name,
     157             :                                             const Ip4Address &tunnel_dest,
     158             :                                             TunnelType::TypeBmap bmap,
     159             :                                             uint32_t label,
     160             :                                             MacAddress rewrite_dmac,
     161             :                                             const VnListType &dest_vn_list,
     162             :                                             const SecurityGroupList &sg_list,
     163             :                                             const TagList &tag_list,
     164             :                                             const PathPreference &path_preference,
     165             :                                             bool ecmp_suppressed,
     166             :                                             const EcmpLoadBalance &ecmp_load_balance,
     167             :                                             bool etree_leaf);
     168             : 
     169             : private:
     170             :     string server_vrf_;
     171             :     Ip4Address tunnel_dest_;
     172             :     TunnelType::TypeBmap tunnel_bmap_;
     173             :     uint32_t label_;
     174             :     VnListType dest_vn_list_;
     175             :     SecurityGroupList sg_list_;
     176             :     TagList tag_list_;
     177             :     PathPreference path_preference_;
     178             :     DBRequest nh_req_;
     179             :     bool ecmp_suppressed_;
     180             :     EcmpLoadBalance ecmp_load_balance_;
     181             :     bool etree_leaf_;
     182             :     MacAddress rewrite_dmac_;
     183             :     DISALLOW_COPY_AND_ASSIGN(ControllerMplsRoute);
     184             : };
     185             : class ControllerEcmpRoute : public ControllerPeerPath {
     186             : public:
     187             :     static const uint32_t maximum_ecmp_paths = 128;
     188             :     typedef std::list<ClonedLocalPath *> ClonedLocalPathList;
     189             :     typedef ClonedLocalPathList::iterator ClonedLocalPathListIter;
     190             :     //Uses Item to build attributes
     191             :     template <typename TYPE>
     192             :     ControllerEcmpRoute(const BgpPeer *peer,
     193             :                         const VnListType &vn_list,
     194             :                         const EcmpLoadBalance &ecmp_load_balance,
     195             :                         const TagList &tag_list,
     196             :                         const TYPE *item,
     197             :                         const AgentRouteTable *rt_table,
     198             :                         const std::string &prefix_str);
     199             :     //Non item based constructor (Used by UT)
     200             :     ControllerEcmpRoute(const BgpPeer *peer,
     201             :                         const VnListType &vn_list,
     202             :                         const EcmpLoadBalance &ecmp_load_balance,
     203             :                         const TagList &tag_list,
     204             :                         const SecurityGroupList &sg_list,
     205             :                         const PathPreference &path_pref,
     206             :                         TunnelType::TypeBmap tunnel_bmap,
     207             :                         DBRequest &nh_req,
     208             :                         const std::string &prefix_str,
     209             :                         const std::string vrf_name = "");
     210             :     ControllerEcmpRoute(const BgpPeer *peer,
     211             :                         const VnListType &vn_list,
     212             :                         const EcmpLoadBalance &ecmp_load_balance,
     213             :                         const TagList &tag_list,
     214             :                         const SecurityGroupList &sg_list,
     215             :                         const PathPreference &path_pref,
     216             :                         TunnelType::TypeBmap tunnel_bmap,
     217             :                         std::vector<IpAddress> &tunnel_dest_list,
     218             :                         std::vector<uint32_t> &label_list,
     219             :                         const std::string &prefix_str,
     220             :                         const std::string &vrf_name);
     221           2 :     virtual ~ControllerEcmpRoute() { }
     222             :     virtual bool AddChangePathExtended(Agent *agent, AgentPath *path,
     223             :                                        const AgentRoute *rt);
     224           0 :     virtual string ToString() const {return "inet4 ecmp";}
     225             :     bool CopyToPath(AgentPath *path);
     226             :     void BuildNhReq(const string &vrf_name, const autogen::ItemType *item_type,
     227             :                     const VnListType &vn_list);
     228           0 :     ClonedLocalPathList &cloned_local_path_list() {
     229           0 :         return cloned_data_list_;
     230             :     }
     231             : 
     232           1 :     void set_copy_local_path(bool copy_local_path) {
     233           1 :         copy_local_path_ = copy_local_path;
     234           1 :     }
     235             : 
     236             :     DBRequest& nh_req() {
     237             :         return nh_req_;
     238             :     }
     239             : 
     240             :     friend class AgentXmppChannel;
     241             : private:
     242             :     VnListType vn_list_;
     243             :     SecurityGroupList sg_list_;
     244             :     EcmpLoadBalance ecmp_load_balance_;
     245             :     TagList tag_list_;
     246             :     PathPreference path_preference_;
     247             :     TunnelType::TypeBmap tunnel_bmap_;
     248             :     DBRequest nh_req_;
     249             :     ClonedLocalPathList cloned_data_list_;
     250             :     Agent *agent_;
     251             :     bool copy_local_path_;
     252             :     std::vector<IpAddress>tunnel_dest_list_;
     253             :     std::vector<uint32_t>label_list_;
     254             :     string vrf_name_;
     255             :     uint32_t vxlan_id_;
     256             :     DISALLOW_COPY_AND_ASSIGN(ControllerEcmpRoute);
     257             : };
     258             : 
     259             : /*
     260             :  * ClonedLocalPath would be used to pick nexthop from the
     261             :  * local peer, instead of nexthop pointed by mpls label.
     262             :  * Currently it gets used in gateway interface. In case of
     263             :  * gateway interface, label exported by agent would point
     264             :  * to table nexthop, and the prefix route of gateway
     265             :  * interface would point resolve nexthop, so that ARP resolution
     266             :  * can be triggered when packet hits the subnet route.
     267             :  */
     268             : class ClonedLocalPath : public AgentRouteData {
     269             : public:
     270           0 :     ClonedLocalPath(uint32_t label, const VnListType &vn_list,
     271             :                     const SecurityGroupList &sg_list,
     272             :                     const TagList &tag_list,
     273           0 :                     uint64_t sequence_number):
     274             :         AgentRouteData(AgentRouteData::ADD_DEL_CHANGE, false, sequence_number),
     275           0 :         mpls_label_(label), vn_list_(vn_list),
     276           0 :         sg_list_(sg_list), tag_list_(tag_list) {}
     277           0 :     virtual ~ClonedLocalPath() {}
     278             :     virtual bool AddChangePathExtended(Agent *agent, AgentPath *path,
     279             :                                        const AgentRoute *rt);
     280           0 :     virtual std::string ToString() const {
     281           0 :         return "Nexthop cloned from local path";
     282             :     }
     283             : private:
     284             :     uint32_t mpls_label_;
     285             :     const VnListType vn_list_;
     286             :     const SecurityGroupList sg_list_;
     287             :     const TagList tag_list_;
     288             :     DISALLOW_COPY_AND_ASSIGN(ClonedLocalPath);
     289             : };
     290             : 
     291             : /*
     292             :  * stale path is created when no CN server is present.
     293             :  * Last peer going down marks its path as stale and keep route alive, till
     294             :  * anothe CN takes over.
     295             :  * There can be only one stale path as multiple does not make any sense.
     296             :  * (Stale path is to keep traffic flowing).
     297             :  */
     298             : class StalePathData : public AgentRouteData {
     299             : public:
     300          14 :     StalePathData(uint64_t sequence_number) :
     301             :         AgentRouteData(AgentRouteData::ADD_DEL_CHANGE, false,
     302          14 :                        sequence_number) { }
     303          28 :     virtual ~StalePathData() { }
     304             :     virtual bool AddChangePathExtended(Agent *agent, AgentPath *path,
     305             :                                        const AgentRoute *rt);
     306             :     virtual bool CanDeletePath(Agent *agent, AgentPath *path,
     307             :                                const AgentRoute *rt) const;
     308           0 :     virtual std::string ToString() const {
     309           0 :         return "Stale path marking(healdess mode)";
     310             :     }
     311             : 
     312             : private:
     313             :     DISALLOW_COPY_AND_ASSIGN(StalePathData);
     314             : };
     315             : #endif //controller_route_path_hpp

Generated by: LCOV version 1.14