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

Generated by: LCOV version 1.14