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

Generated by: LCOV version 1.14