LCOV - code coverage report
Current view: top level - vnsw/agent/oper - evpn_route.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 30 39 76.9 %
Date: 2026-06-11 01:56:02 Functions: 19 26 73.1 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
       3             :  */
       4             : 
       5             : #ifndef vnsw_evpn_route_hpp
       6             : #define vnsw_evpn_route_hpp
       7             : 
       8             : class EvpnRoutingData;
       9             : 
      10             : //////////////////////////////////////////////////////////////////
      11             : //  EVPN
      12             : /////////////////////////////////////////////////////////////////
      13             : class EvpnAgentRouteTable : public AgentRouteTable {
      14             : public:
      15          10 :     EvpnAgentRouteTable(DB *db, const std::string &name) :
      16          10 :         AgentRouteTable(db, name) {
      17          10 :     }
      18          20 :     virtual ~EvpnAgentRouteTable() { }
      19             : 
      20           0 :     virtual std::string GetTableName() const {return "EvpnAgentRouteTable";}
      21         164 :     virtual Agent::RouteTableType GetTableType() const {
      22         164 :         return Agent::EVPN;
      23             :     }
      24             :     static uint32_t ComputeHostIpPlen(const IpAddress &addr);
      25             :     virtual AgentSandeshPtr GetAgentSandesh(const AgentSandeshArguments *args,
      26             :                                             const std::string &context);
      27             : 
      28             :     static DBTableBase *CreateTable(DB *db, const std::string &name);
      29             : 
      30             :     //Add routines
      31             :     void AddOvsPeerMulticastRouteReq(const Peer* peer,
      32             :                                      uint32_t vxlan_id,
      33             :                                      const std::string &vn_name,
      34             :                                      Ip4Address vtep,
      35             :                                      Ip4Address tor_ip);
      36             :     void AddOvsPeerMulticastRoute(const Peer* peer,
      37             :                                   uint32_t vxlan_id,
      38             :                                   const std::string &vn_name,
      39             :                                   Ip4Address vtep,
      40             :                                   Ip4Address tor_ip,
      41             :                                   bool ha_stale);
      42             :     void AddReceiveRouteReq(const Peer *peer, const std::string &vrf_name,
      43             :                             uint32_t label, const MacAddress &mac,
      44             :                             const IpAddress &ip_addr, uint32_t ethernet_tag,
      45             :                             const std::string &vn_name,
      46             :                             const PathPreference &pref);
      47             :     void AddReceiveRoute(const Peer *peer, const std::string &vrf_name,
      48             :                          uint32_t label, const MacAddress &mac,
      49             :                          const IpAddress &ip_addr, uint32_t ethernet_tag,
      50             :                          const std::string &vn_name,
      51             :                          const PathPreference &pref);
      52             :     void AddControllerReceiveRouteReq(const Peer *peer,
      53             :                          const std::string &vrf_name,
      54             :                          uint32_t label, const MacAddress &mac,
      55             :                          const IpAddress &ip_addr, uint32_t ethernet_tag,
      56             :                          const std::string &vn_name,
      57             :                          const PathPreference &pref,
      58             :                          uint64_t sequence_number);
      59             :     void AddLocalVmRouteReq(const Peer *peer,
      60             :                             const std::string &vrf_name,
      61             :                             const MacAddress &mac,
      62             :                             const IpAddress &ip_addr,
      63             :                             uint32_t ethernet_tag,
      64             :                             LocalVmRoute *data);
      65             :     void AddLocalVmRoute(const Peer *peer, const std::string &vrf_name,
      66             :                          const MacAddress &mac, const VmInterface *intf,
      67             :                          const IpAddress &ip, uint32_t label,
      68             :                          const std::string &vn_name,
      69             :                          const SecurityGroupList &sg_id_list,
      70             :                          const TagList &tag_id_list,
      71             :                          const PathPreference &path_pref,
      72             :                          uint32_t ethernet_tag,
      73             :                          bool etree_leaf,
      74             :                          const std::string &interface_name);
      75             : 
      76             :     void AddLocalVmRouteReq(const Peer *peer, const std::string &vrf_name,
      77             :                          const MacAddress &mac, const VmInterface *intf,
      78             :                          const IpAddress &ip, uint32_t label,
      79             :                          const std::string &vn_name,
      80             :                          const SecurityGroupList &sg_id_list,
      81             :                          const TagList &tag_id_list,
      82             :                          const PathPreference &path_pref,
      83             :                          uint32_t ethernet_tag,
      84             :                          bool etree_leaf);
      85             : 
      86             :     void AddClonedLocalPathReq(const Peer *peer,
      87             :                                const string &vrf_name,
      88             :                                const MacAddress &mac,
      89             :                                const IpAddress &ip_addr,
      90             :                                uint32_t ethernet_tag,
      91             :                                ClonedLocalPath *data);
      92             : 
      93             :     static void ResyncVmRoute(const Peer *peer,
      94             :                               const string &vrf_name,
      95             :                               const MacAddress &mac,
      96             :                               const IpAddress &ip_addr,
      97             :                               uint32_t ethernet_tag,
      98             :                               AgentRouteData *data);
      99             :     static void AddRemoteVmRouteReq(const Peer *peer,
     100             :                                     const std::string &vrf_name,
     101             :                                     const MacAddress &mac,
     102             :                                     const IpAddress &ip_addr,
     103             :                                     uint32_t plen,
     104             :                                     uint32_t ethernet_tag,
     105             :                                     AgentRouteData *data);
     106             :     static void AddRemoteVmRoute(const Peer *peer,
     107             :                                  const std::string &vrf_name,
     108             :                                  const MacAddress &mac,
     109             :                                  const IpAddress &ip_addr,
     110             :                                  uint32_t plen,
     111             :                                  uint32_t ethernet_tag,
     112             :                                  AgentRouteData *data);
     113             :     void AddType5Route(const Peer *peer,
     114             :                        const std::string &vrf_name,
     115             :                        const IpAddress &ip_addr,
     116             :                        uint32_t ethernet_tag,
     117             :                        EvpnRoutingData *data,
     118             :                        uint8_t plen = 0);
     119             : 
     120             :     //Delete routines
     121             :     void DeleteOvsPeerMulticastRouteReq(const Peer *peer,
     122             :                                         uint32_t vxlan_id,
     123             :                                         const Ip4Address &tor_ip);
     124             :     void DeleteOvsPeerMulticastRoute(const Peer *peer,
     125             :                                      uint32_t vxlan_id,
     126             :                                      const Ip4Address &tor_ip);
     127             :     void DelLocalVmRoute(const Peer *peer, const std::string &vrf_name,
     128             :                          const MacAddress &mac, const VmInterface *intf,
     129             :                          const IpAddress &ip, uint32_t ethernet_tag);
     130             :     static void DeleteReq(const Peer *peer, const std::string &vrf_name,
     131             :                           const MacAddress &mac, const IpAddress &ip_addr,
     132             :                           uint32_t plen, uint32_t ethernet_tag,
     133             :                           AgentRouteData *data);
     134             :     static void Delete(const Peer *peer, const std::string &vrf_name,
     135             :                        const MacAddress &mac, const IpAddress &ip_addr,
     136             :                        uint32_t ethernet_tag);
     137             :     static void DeleteType5Req(const Peer *peer, const std::string &vrf_name,
     138             :                                const MacAddress &mac, const IpAddress &ip_addr,
     139             :                                uint32_t plen, uint32_t ethernet_tag);
     140             :     EvpnRouteEntry *FindRoute(const MacAddress &mac, const IpAddress &ip_addr,
     141             :                               uint32_t plen, uint32_t ethernet_tag);
     142             :     EvpnRouteEntry *FindRouteNoLock(const MacAddress &mac,
     143             :                                     const IpAddress &ip_addr,
     144             :                                     uint32_t plen,
     145             :                                     uint32_t ethernet_tag);
     146             :     static EvpnRouteEntry *FindRoute(const Agent *agent,
     147             :                                        const std::string &vrf_name,
     148             :                                        const MacAddress &mac,
     149             :                                        const IpAddress &ip_addr,
     150             :                                        uint32_t plen,
     151             :                                        uint32_t ethernet_tag);
     152             : 
     153             : private:
     154             :     DISALLOW_COPY_AND_ASSIGN(EvpnAgentRouteTable);
     155             :     void AddOvsPeerMulticastRouteInternal(const Peer* peer,
     156             :                                           uint32_t vxlan_id,
     157             :                                           const std::string &vn_name,
     158             :                                           Ip4Address vtep,
     159             :                                           Ip4Address tor_ip,
     160             :                                           bool enqueue,
     161             :                                           bool ha_stale);
     162             :     void DeleteOvsPeerMulticastRouteInternal(const Peer *peer,
     163             :                                              uint32_t vxlan_id,
     164             :                                              const Ip4Address &tor_ip,
     165             :                                              bool enqueue);
     166             : 
     167             : };
     168             : 
     169             : class EvpnRouteEntry : public AgentRoute,
     170             :     public AgentRoutePrefix<IpAddress> {
     171             : public:
     172             :     EvpnRouteEntry(VrfEntry *vrf,
     173             :                    const MacAddress &mac,
     174             :                    const IpAddress &ip_addr,
     175             :                    uint8_t plen,
     176             :                    uint32_t ethernet_tag,
     177             :                    bool is_multicast);
     178         322 :     virtual ~EvpnRouteEntry() { }
     179             : 
     180             :     virtual int CompareTo(const Route &rhs) const;
     181             :     virtual std::string ToString() const;
     182           0 :     virtual void UpdateDependantRoutes() { }
     183           0 :     virtual void UpdateNH() { }
     184             :     virtual KeyPtr GetDBRequestKey() const;
     185             :     virtual void SetKey(const DBRequestKey *key);
     186         166 :     virtual const std::string GetAddressString() const {
     187         166 :         return mac_.ToString();
     188             :     }
     189           0 :     virtual const std::string GetSourceAddressString() const {
     190           0 :         return (MacAddress::kZeroMac).ToString();
     191             :     }
     192         254 :     virtual Agent::RouteTableType GetTableType() const {
     193         254 :         return Agent::EVPN;
     194             :     }
     195             :     virtual bool DBEntrySandesh(Sandesh *sresp, bool stale) const;
     196             :     virtual uint32_t GetActiveLabel() const;
     197             :     virtual bool ReComputePathDeletion(AgentPath *path);
     198             : 
     199         438 :     bool IsType5() const {
     200         438 :         return mac_.IsZero();
     201             :     }
     202          75 :     bool IsType2() const {
     203          75 :         return !IsType5();
     204             :     }
     205         348 :     const MacAddress &mac() const {return mac_;}
     206             :     ///! @brief The length of EVPN Type2 / Type5 prefix IP address
     207        1539 :     uint8_t prefix_length() const {return prefix_length_;}
     208         276 :     uint32_t ethernet_tag() const {return ethernet_tag_;}
     209             :     void set_publish_to_bridge_route_table(bool publish_to_bridge_route_table) {
     210             :         publish_to_bridge_route_table_ = publish_to_bridge_route_table;
     211             :     }
     212          75 :     bool publish_to_bridge_route_table() const {
     213          75 :         return publish_to_bridge_route_table_;
     214             :     }
     215             :     void set_publish_to_inet_route_table(bool publish_to_inet_route_table) {
     216             :         publish_to_inet_route_table_ = publish_to_inet_route_table;
     217             :     }
     218          75 :     bool publish_to_inet_route_table() const {
     219          75 :         if (is_multicast())
     220           0 :             return false;
     221          75 :         return publish_to_inet_route_table_;
     222             :     }
     223             :     const AgentPath *FindOvsPath() const;
     224             : 
     225             :     virtual void UpdateDerivedRoutes(AgentRouteTable *table,
     226             :                                      const AgentPath *path,
     227             :                                      bool active_path_changed);
     228             :     virtual void DeleteDerivedRoutes(AgentRouteTable *table);
     229             : private:
     230             : 
     231             :     MacAddress mac_;
     232             :     uint32_t ethernet_tag_;
     233             :     bool publish_to_inet_route_table_;
     234             :     bool publish_to_bridge_route_table_;
     235             :     DISALLOW_COPY_AND_ASSIGN(EvpnRouteEntry);
     236             : };
     237             : 
     238             : class EvpnRouteKey : public AgentRouteKey {
     239             : public:
     240         132 :     EvpnRouteKey(const Peer *peer, const std::string &vrf_name,
     241             :                  const MacAddress &mac, const IpAddress &ip_addr,
     242         132 :                  uint32_t plen, uint32_t ethernet_tag) :
     243         132 :         AgentRouteKey(peer, vrf_name), dmac_(mac), ip_addr_(ip_addr),
     244         132 :         plen_(plen), ethernet_tag_(ethernet_tag) {
     245         132 :     }
     246             : 
     247         241 :     virtual ~EvpnRouteKey() { }
     248             : 
     249             :     virtual AgentRoute *AllocRouteEntry(VrfEntry *vrf, bool is_multicast) const;
     250         131 :     virtual Agent::RouteTableType GetRouteTableType() { return Agent::EVPN; }
     251             :     virtual std::string ToString() const;
     252             :     virtual EvpnRouteKey *Clone() const;
     253           0 :     const MacAddress &GetMac() const { return dmac_;}
     254           0 :     const IpAddress &ip_addr() const { return ip_addr_;}
     255           0 :     uint32_t ethernet_tag() const {return ethernet_tag_;}
     256             : 
     257             : private:
     258             :     MacAddress dmac_;
     259             :     IpAddress ip_addr_;
     260             :     uint32_t plen_;
     261             :     //ethernet_tag is the segment identifier for VXLAN. In control node its used
     262             :     //as a key however for forwarding only MAC is used as a key.
     263             :     //To handle this ethernet_tag is sent as part of key for all remote routes
     264             :     //which in turn is used to create a seperate path for same peer and
     265             :     //mac.
     266             :     uint32_t ethernet_tag_;
     267             :     DISALLOW_COPY_AND_ASSIGN(EvpnRouteKey);
     268             : };
     269             : 
     270             : #endif // vnsw_evpn_route_hpp

Generated by: LCOV version 1.14