LCOV - code coverage report
Current view: top level - vnsw/agent/oper - vxlan_routing_manager.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 9 32 28.1 %
Date: 2026-08-03 02:19:58 Functions: 4 9 44.4 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2018 Juniper Networks, Inc. All rights reserved.
       3             :  * Copyright (c) 2022 - 2026 Matvey Kraposhin.
       4             :  * Copyright (c) 2024 - 2026 Elena Zizganova.
       5             :  */
       6             : #ifndef __AGENT_OPER_VXLAN_ROUTING_H
       7             : #define __AGENT_OPER_VXLAN_ROUTING_H
       8             : 
       9             : #include <cmn/agent_cmn.h>
      10             : #include <cmn/agent.h>
      11             : #include <oper/oper_db.h>
      12             : #include <base/logging.h>
      13             : 
      14             : class BgpPeer;
      15             : namespace autogen {
      16             :     struct EnetNextHopType;
      17             :     struct NextHopType;
      18             : }
      19             : 
      20             : 
      21             : /// @brief A structure to hold path parameters during
      22             : /// the transfer (routes leaking) of data between VRF instances and tables.
      23             : /// The structure is designed to use references where it is possible.
      24             : struct RouteParameters {
      25             : 
      26             :     /// @brief Constructs RouteParameters object from components
      27           0 :     RouteParameters(const IpAddress& nh_addr,
      28             :         const MacAddress& mac,
      29             :         const VnListType& vns,
      30             :         const SecurityGroupList& sgs,
      31             :         const CommunityList& comms,
      32             :         const TagList& tags,
      33             :         const PathPreference& ppref,
      34             :         const EcmpLoadBalance& ecmp,
      35           0 :         uint64_t seq_n):
      36           0 :         nh_addresses_(1, nh_addr),
      37           0 :         nh_addr_(nh_addresses_.at(0)),
      38           0 :         nh_mac_(mac),
      39           0 :         vn_list_(vns), sg_list_(sgs),
      40           0 :         communities_(comms), tag_list_(tags),
      41           0 :         path_preference_(ppref),
      42           0 :         ecmp_load_balance_(ecmp),
      43           0 :         sequence_number_(seq_n) {
      44           0 :     }
      45             : 
      46             :     /// @brief Copy constructor
      47             :     RouteParameters(const RouteParameters &rp):
      48             :         nh_addresses_(rp.nh_addresses_),
      49             :         nh_addr_(rp.nh_addr_),
      50             :         nh_mac_(rp.nh_mac_),
      51             :         vn_list_(rp.vn_list_), sg_list_(rp.sg_list_),
      52             :         communities_(rp.communities_), tag_list_(rp.tag_list_),
      53             :         path_preference_(rp.path_preference_),
      54             :         ecmp_load_balance_(rp.ecmp_load_balance_),
      55             :         sequence_number_(rp.sequence_number_) {
      56             :     }
      57             : 
      58             :     // template <class ITEM_T
      59             :     // static std::vector<typename ITEM_T> ItemToVector(const ITEM_T& item) {
      60             :     //     return std::vector<ITEM_T>();
      61             :     // }
      62             : 
      63             :     // template<class ITEM_T>
      64             :     // RouteParameters(const ITEM_T& item,
      65             :     //     const VnListType& vns,
      66             :     //     const SecurityGroupList& sgs,
      67             :     //     const TagList& tags,
      68             :     //     const PathPreference& ppref,
      69             :     //     const EcmpLoadBalance& ecmp,
      70             :     //     uint64_t seq_n):
      71             :     //     nh_addr_(nh_addr),
      72             :     //     vn_list_(vns), sg_list_(sgs),
      73             :     //     tag_list_(tags), path_preference_(ppref),
      74             :     //     ecmp_load_balance_(ecmp),
      75             :     //     sequence_number_(seq_n) {
      76             :     // }
      77             : 
      78             :     /// @brief A list of nexthops IP addreses of a composite tunnel.
      79             :     const std::vector<IpAddress> nh_addresses_;
      80             : 
      81             :     /// @brief A nexthop IP address of the tunnel. Contains first IP address
      82             :     /// of nh_addresses_ in case of a composite tunnel.
      83             :     const IpAddress& nh_addr_;
      84             : 
      85             :     /// @brief A nexthop MAC address (usually it is a MAC of the router).
      86             :     const MacAddress& nh_mac_;
      87             : 
      88             :     /// @brief A list of path destination virtual networks used in policy
      89             :     /// lookups.
      90             :     const VnListType& vn_list_;
      91             : 
      92             :     /// @brief A list of security groups.
      93             :     const SecurityGroupList& sg_list_;
      94             : 
      95             :     /// @brief A list of communities.
      96             :     const CommunityList& communities_;
      97             : 
      98             :     /// @brief A list of tags.
      99             :     const TagList& tag_list_;
     100             : 
     101             :     /// @brief A reference to the PathPreference of the path
     102             :     const PathPreference& path_preference_;
     103             : 
     104             :     /// @brief A reference to EcmpLoadBalance of the path
     105             :     const EcmpLoadBalance& ecmp_load_balance_;
     106             : 
     107             :     /// @brief An ID of sequence
     108             :     uint64_t sequence_number_;
     109             : 
     110             : private:
     111             : 
     112             :     /// @brief Disallow default constructor
     113             :     RouteParameters();
     114             : };
     115             : 
     116             : /// @brief This state tracks inet and EVPN table listeners.
     117             : /// It establishes link between inet tables of a bridge VRF instance
     118             : /// from where routes leak and the EVPN table of a routing VRF instance
     119             : /// into which the routes leak, see VxlanRoutingManager and 
     120             : /// VxlanRoutingVrfMapper classes for more information.
     121             : struct VxlanRoutingState : public DBState {
     122             : 
     123             :     /// @brief Construct new instance using the given VxlanRoutingManager and
     124             :     /// VRF instance (VrfEntry).
     125             :     VxlanRoutingState(VxlanRoutingManager *mgr,
     126             :                       VrfEntry *vrf);
     127             : 
     128             :     /// @brief Destroys an instance.
     129             :     virtual ~VxlanRoutingState();
     130             : 
     131             :     /// @brief ID of a listener that tracks changes in the IPv4 Inet
     132             :     /// table of a bridge VRF instance
     133             :     DBTable::ListenerId inet4_id_;
     134             : 
     135             :     /// @brief ID of a listener that tracks changes in the IPv6 Inet
     136             :     /// table of a bridge VRF instance
     137             :     DBTable::ListenerId inet6_id_;
     138             : 
     139             :     /// @brief ID of a listener that tracks changes in the EVPN
     140             :     /// table of a routing VRF instance
     141             :     DBTable::ListenerId evpn_id_;
     142             : 
     143             :     /// @brief A pointer to the IPv4 Inet table of a bridge VRF instance
     144             :     AgentRouteTable *inet4_table_;
     145             : 
     146             :     /// @brief A pointer to the IPv6 Inet table of a bridge VRF instance
     147             :     AgentRouteTable *inet6_table_;
     148             : 
     149             :     /// @brief A pointer to the EVPN table of a routing VRF instance
     150             :     AgentRouteTable *evpn_table_;
     151             : };
     152             : 
     153             : /// @brief This state tracks all virtual machine interfaces (VmInterface)
     154             : /// attached to a Logical Router (LR). It establishes links
     155             : /// between VmInterfaces connected to a LR as
     156             : /// router's ports on behalf of bridge virtual networks (VnEntry),
     157             : /// see VxlanRoutingManager and
     158             : /// VxlanRoutingVrfMapper classes for more information.
     159             : struct VxlanRoutingVnState : public DBState {
     160             : 
     161             :     /// A typedef for a set of pointers to VmInterface.
     162             :     typedef std::set<const VmInterface *> VmiList;
     163             : 
     164             :     /// A typedef for the iterator of VxlanRoutingVnState::VmiList.
     165             :     typedef VmiList::iterator VmiListIter;
     166             : 
     167             :     /// Constructs new instance using VxlanRoutingManager.
     168             :     VxlanRoutingVnState(VxlanRoutingManager *mgr);
     169             : 
     170             :     /// @brief Destroys a VxlanRoutingVnState object.
     171             :     virtual ~VxlanRoutingVnState();
     172             : 
     173             :     /// @brief Adds a VmInterface (LR port) to a Logical Router and connects
     174             :     /// the given VirtualNetwork (to which the VmInterface belongs to) to the
     175             :     /// LR.
     176             :     void AddVmi(const VnEntry *vn, const VmInterface *vmi);
     177             : 
     178             :     /// @brief Deletes the VmInterface from set of connected interfaces
     179             :     ///  and disconnects the given VirtualNetwork from the Logical Router.
     180             :     void DeleteVmi(const VnEntry *vn, const VmInterface *vmi);
     181             : 
     182             :     /// @brief Returns the UUID of the Logical Router.
     183             :     boost::uuids::uuid logical_router_uuid() const;
     184             : 
     185             :     /// @brief A list of VmInterface (router's ports) connected to a Logical
     186             :     /// Router (LR)
     187             :     std::set<const VmInterface *> vmi_list_;
     188             : 
     189             :     /// @brief Returns true when state is associated with a routing
     190             :     /// VirtualNetwork
     191             :     bool is_routing_vn_;
     192             : 
     193             :     /// @brief A  UUID of the Logical Router.
     194             :     boost::uuids::uuid logical_router_uuid_;
     195             : 
     196             :     /// @brief Holds a reference to a VrfEntry when VirtualNetwork's
     197             :     /// reference stored in VrfGet() is null
     198             :     VrfEntryRef vrf_ref_;
     199             : 
     200             :     /// @brief A pointer to the instance of VxlanRoutingManager
     201             :     VxlanRoutingManager *mgr_;
     202             : 
     203             : };
     204             : 
     205             : /// @brief Tracks movement of a VmInterface among LRs. This is used
     206             : /// to associate VmInterface with a LR and a VN, see VxlanRoutingManager and
     207             : /// VxlanRoutingVrfMapper classes for more information.
     208             : struct VxlanRoutingVmiState : public DBState {
     209             : 
     210             :     /// @brief Constructs new instance of VxlanRoutingVmiState
     211             :     VxlanRoutingVmiState();
     212             : 
     213             :     /// @brief Destroys an instance of VxlanRoutingVmiState
     214             :     virtual ~VxlanRoutingVmiState();
     215             : 
     216             :     /// @brief Reference (smart pointer) to the virtual network
     217             :     /// (VirtualNetwork) to which VmInterface belongs to
     218             :     VnEntryRef vn_entry_;
     219             : 
     220             :     /// @brief UUID of the LR to which this VmInterface is connected.
     221             :     boost::uuids::uuid logical_router_uuid_;
     222             : };
     223             : 
     224             : /**
     225             :  * VxlanRoutingRouteWalker
     226             :  * Incarnation of AgentRouteWalker. 
     227             :  * 
     228             :  */
     229             : /// @brief Listens to Inet routes in a bridge VRF instance.
     230             : /// Started when l3vrf is added/deleted or
     231             : /// when a bridge VRF is attached / detached to/from the LR.
     232             : class VxlanRoutingRouteWalker : public AgentRouteWalker {
     233             : public:
     234             : 
     235             :     /// @brief Constructs a new instance using the given name, pointer to
     236             :     /// the VxlanRoutingManager and pointer to the Agent.
     237             :     VxlanRoutingRouteWalker(const std::string &name,
     238             :         VxlanRoutingManager *mgr, Agent *agent);
     239             : 
     240             :     /// @brief Destructs an instance of VxlanRoutingRouteWalker.
     241             :     virtual ~VxlanRoutingRouteWalker();
     242             : 
     243             :     /// @brief Runs route leaking process when L3 VRF instance is added/deleted
     244             :     /// or when a bridge VRF is attached / detached to/from the LR
     245             :     virtual bool RouteWalkNotify(DBTablePartBase *partition, DBEntryBase *e);
     246             : 
     247             : private:
     248             : 
     249             :     /// @brief A pointer to the VxlanRoutingManager instance.
     250             :     VxlanRoutingManager *mgr_;
     251             : 
     252             :     DISALLOW_COPY_AND_ASSIGN(VxlanRoutingRouteWalker);
     253             : };
     254             : 
     255             : 
     256             : /// @brief This class is a storage for operative state of VxLAN logical
     257             : /// routers (LRs) defined via Config logical-router element. It stores:
     258             : /// - a map between a virtual network (VnEntry*) and an LR's UUID, vn_lr_set_;
     259             : /// - a map between an LR's UUID and virtual networks and VRF tables
     260             : /// associated with the LR, lr_vrf_info_map_.
     261             : /// Along with these it has a walker for traversing EVPN tables due to
     262             : /// modification of an LR or associated elements configurative or operative
     263             : /// state.
     264             : /// (If multiple walks get scheduled for an EVPN table then they are
     265             : /// collapsed and only one walk is done).
     266             : /// For more information, refer to VxlanRoutingManager class.
     267             : class VxlanRoutingVrfMapper {
     268             : public:
     269             : 
     270             :     /// @brief The structure holds information about virtual networks
     271             :     /// connected to a logical router (LR)
     272             :     struct RoutedVrfInfo {
     273             : 
     274             :         /// @brief A typedef to store the list of bridge virtual networks
     275             :         /// connected to a LR.
     276             :         typedef std::set<const VnEntry *> BridgeVnList;
     277             : 
     278             :         /// @brief A typedef to store the correspondence between bridge virtual
     279             :         /// network (VirtualNetwork) pointer and a name of it's VRF instance.
     280             :         typedef std::map<const VnEntry *, std::string> BridgeVrfNamesList;
     281             : 
     282             :         /// @brief A type for iterator of the list of bridge virtual networks
     283             :         /// connected to a LR.
     284             :         typedef BridgeVnList::iterator BridgeVnListIter;
     285             : 
     286             :         /// @brief Constructs an instance of RoutedVrfInfo.
     287           0 :         RoutedVrfInfo() : routing_vn_(),
     288           0 :         routing_vrf_(NULL), bridge_vn_list_() {
     289           0 :         }
     290             : 
     291             :         /// @brief Destroys an instance of RoutedVrfInfo.
     292           0 :         virtual ~RoutedVrfInfo() {
     293           0 :         }
     294             : 
     295             :         /// @brief A pointer to the routing virtual network (VirtualNetwork)
     296             :         /// connected to a LR.
     297             :         const VnEntry *routing_vn_;
     298             : 
     299             :         /// @brief A pointer to the routing VRF instance (L3 VRF)
     300             :         /// connected to a LR.
     301             :         VrfEntry *routing_vrf_;
     302             : 
     303             :         /// @brief The list of bridge virtual networks (VirtualNetwork)
     304             :         /// connected to a LR.
     305             :         BridgeVnList bridge_vn_list_;
     306             : 
     307             :         /// @brief The list of bridge virtual networks (VirtualNetwork) names
     308             :         /// connected to a LR.
     309             :         BridgeVrfNamesList bridge_vrf_names_list_;
     310             :     };
     311             : 
     312             :     /// @brief A typedef to store map between Logical router UUID and
     313             :     /// RoutedVrfInfo
     314             :     typedef std::map<boost::uuids::uuid, RoutedVrfInfo> LrVrfInfoMap;
     315             : 
     316             :     /// @brief A typedef for iterator of LrVrfInfoMap
     317             :     typedef LrVrfInfoMap::iterator LrVrfInfoMapIter;
     318             : 
     319             :     /// @brief A typedef to store map between pointer to VirtualNetwork (a
     320             :     /// bridge or routing virtual network connected to some LR) and
     321             :     /// the LR's UUID.
     322             :     typedef std::map<const VnEntry *, boost::uuids::uuid> VnLrSet;
     323             : 
     324             :     /// @brief A typedef for iterator of VnLrSet.
     325             :     typedef VnLrSet::iterator VnLrSetIter;
     326             : 
     327             :     /// @brief A typedef for a storage of all walkers on Inet tables,
     328             :     /// if needed the walk can be restarted
     329             :     /// instead of spawning new one for a table.
     330             :     typedef std::map<const InetUnicastAgentRouteTable *, DBTable::DBTableWalkRef>
     331             :         InetTableWalker;
     332             : 
     333             :     /// @brief Constructs a new instance of VxlanRoutingVrfMapper using
     334             :     /// the given pointer to VxlanRoutingManager.
     335             :     VxlanRoutingVrfMapper(VxlanRoutingManager *mgr);
     336             : 
     337             :     /// @brief Destroys an instance of VxlanRoutingVrfMapper().
     338             :     virtual ~VxlanRoutingVrfMapper();
     339             : 
     340             :     /// @brief Handles completion of route walk in the Inet IPv4 table
     341             :     /// of a bridge VRF instance.
     342             :     void BridgeInet4RouteWalkDone(DBTable::DBTableWalkRef walk_ref,
     343             :                        DBTableBase *partition);
     344             : 
     345             :     /// @brief Handles completion of route walk in an Inet IPv6 table
     346             :     /// of a bridge VRF instance.
     347             :     void BridgeInet6RouteWalkDone(DBTable::DBTableWalkRef walk_ref,
     348             :                        DBTableBase *partition);
     349             : 
     350             :     /// @brief Handles completion of route walk in the EVPN table
     351             :     /// of a routing VRF instance.
     352             :     void RoutingVrfRouteWalkDone(DBTable::DBTableWalkRef walk_ref,
     353             :                                           DBTableBase *partition);
     354             : 
     355             :     /// @brief Attempts to delete the given LR.
     356             :     /// @todo better way to release logical router from lr_vrf_info_map_
     357             :     /// Easier way will be to add logical router in db and trigger delete of this
     358             :     ///via LR delete in same.
     359             :     void TryDeleteLogicalRouter(LrVrfInfoMapIter &it);
     360             : 
     361             :     /// @brief Determines whether object is empty or not.
     362          90 :     bool IsEmpty() const {
     363         180 :         return ((vn_lr_set_.size() == 0) &&
     364         180 :                 (lr_vrf_info_map_.size() == 0));
     365             :     }
     366             : 
     367             : private:
     368             : 
     369             :     /// @brief Allows access to private members for VxlanRoutingManager class.
     370             :     friend class VxlanRoutingManager;
     371             : 
     372             :     /// @brief Walks Inet tables of all bridge VRF instances connected to
     373             :     /// a LR (given in routing_vrf_info parameter).
     374             :     void WalkBridgeVrfs(const RoutedVrfInfo &routing_vrf_info);
     375             : 
     376             :     /// @brief Walks the EVPN table of the routing VRF instance of a given
     377             :     /// LR.
     378             :     void WalkRoutingVrf(const boost::uuids::uuid &lr_uuid,
     379             :         const VnEntry *vn, bool update, bool withdraw);
     380             : 
     381             :     /// @brief Walks the EVPN table of the routing VRF instance of a given
     382             :     /// LR to find and remove external routes from bridge tables.
     383             :     void WalkRoutingVrfRemoveExternalRoutes(
     384             :         const boost::uuids::uuid &lr_uuid, const VnEntry *vn,
     385             :         std::string bridge_vrf_name);
     386             : 
     387             :     /// @brief Walks given Inet tables (IPv4 and IPv6).
     388             :     void WalkBridgeInetTables(InetUnicastAgentRouteTable *inet4,
     389             :         InetUnicastAgentRouteTable *inet6);
     390             : 
     391             :     /// @brief Find the routing VRF instance using a given virtual network.
     392             :     const VrfEntry *GetRoutingVrfUsingVn(const VnEntry *vn);
     393             : 
     394             :     /// @brief Find the routing VRF instance using a given route
     395             :     /// (AgentRoute).
     396             :     const VrfEntry *GetRoutingVrfUsingAgentRoute(const AgentRoute *rt);
     397             : 
     398             :     /// @brief Find the routing VRF instance using a given LR UUID.
     399             :     const VrfEntry *GetRoutingVrfUsingUuid(const boost::uuids::uuid &lr_uuid);
     400             : 
     401             :     /// @brief Find the UUID of the LR using a given route (AgentRoute).
     402             :     const boost::uuids::uuid GetLogicalRouterUuidUsingRoute(const AgentRoute *rt);
     403             : 
     404             :     /// @brief A pointer to the VxlanRoutingManager instance.
     405             :     VxlanRoutingManager *mgr_;
     406             : 
     407             :     /// @brief  The map between Logical router UUID and
     408             :     /// RoutedVrfInfo
     409             :     LrVrfInfoMap lr_vrf_info_map_;
     410             : 
     411             :     /// @brief The map between pointer to VirtualNetwork (a
     412             :     /// bridge or routing virtual network connected to some LR) and
     413             :     /// the LR's UUID.
     414             :     VnLrSet vn_lr_set_;
     415             : 
     416             :     /// @brief The set of walkers for Inet IPv4 tables of bridge VRF instances.
     417             :     InetTableWalker inet4_table_walker_;
     418             : 
     419             :     /// @brief The set of walkers for Inet IPv6 tables of bridge VRF instances.
     420             :     InetTableWalker inet6_table_walker_;
     421             : 
     422             :     DISALLOW_COPY_AND_ASSIGN(VxlanRoutingVrfMapper);
     423             : };
     424             : 
     425             : /// @brief This class manages an operative state of VxLAN logical routers (LR)
     426             : /// defined via Config logical-router element. The operative state include
     427             : /// bonds between LRs, virtual networks, VRFs and corresponding routes which
     428             : /// support connectivity between networks connected to a LR.
     429             : ///
     430             : /// Given a logical router (LR), there is precisely 1 routing virtual network
     431             : /// (VN) and a routing VRF table associated with it and zero or more
     432             : /// bridge VNs (and corresponding VRF tables) whose states are manipulated
     433             : /// by VxlanRoutingManager using routes leaking process.
     434             : /// Routes leaking is a routing tables bi-directional manipulation process
     435             : /// during which:
     436             : /// - new VM interface routes arising in the bridge VRF tables are being
     437             : /// transferred into the routing VRF table associated with the LR (forward
     438             : /// propagation of routes);
     439             : /// - new routes arising in the routing VRF table are redistributed among
     440             : /// the bridge VRF tables associated with the LR (backward propagation of
     441             : /// routes);
     442             : /// - deletion of created routes in the routing or a bridge VRF leads to
     443             : /// the deletion of the corresponding created routes in other VRF tables
     444             : /// associated with the LR.
     445             : ///
     446             : /// In a nutshell, routes leaking is a kind of data synchronization process
     447             : /// between several routing tables.
     448             : ///
     449             : /// A bridge virtual network is a basic element in OpenSDN that manages
     450             : /// network connectivity between several VMs within a broadcast domain.
     451             : /// A routing virtual network is a technical virtual network associated
     452             : /// with a LR and providing connectivity between several bridge virtual
     453             : /// networks attached to (associated with) the LR.
     454             : ///
     455             : /// The information about an LR is loaded into (or unloaded from) the Agent’s
     456             : /// operative DB when the processing of a corresponding IF-MAP node changes
     457             : /// triggers notifications for associated tables: the interfaces tables
     458             : /// (InterfaceTable class), the virtual networks table (VnTable class) and
     459             : /// the VRFs tables (VrfTable class).
     460             : /// The changes to the IF-MAP nodes arise due to such events as a
     461             : /// connection of a virtual network with an LR (or a disconnection of a VN
     462             : /// from an LR), appearance of a first VM connected to an LR via a bridge
     463             : /// network or a destruction of a last VM (connected to an LR) on a hypervisor.
     464             : /// VxlanRoutingManager links these notifications with its member functions:
     465             : /// VxlanRoutingManager::VmiNotify, VxlanRoutingManager::VnNotify
     466             : /// and VxlanRoutingManager::VrfNotify and they are called VmiNotify,
     467             : /// VnNotify and VrfNotify for brevity.
     468             : ///
     469             : /// Due to concurrency mechanisms, these functions can run in various order.
     470             : /// However, only specific order guarantees lack of inconsistencies in the
     471             : /// VxlanRoutingManager data describing state of an LR:
     472             : /// 1. if an LR is being created or updated (e.g., a bridge network is being
     473             : /// attached to it), then the correct notifications processing order is
     474             : /// VmiNotify, VnNotify and VrfNotify, in this case routes leaking functions
     475             : /// which are called by RouteNotify member of VxlanRoutingManager will not
     476             : /// start execution until all information from IF-MAP is not correctly
     477             : /// transferred into the operative DB;
     478             : /// 2. if an LR is being destroyed (or a bridge network is being detached
     479             : /// from it), then the situation is not so obvious, because (a)
     480             : /// on the one hand, VrfNotify should be called first to prevent unexpected
     481             : /// routes leaking from the disconnected or destroyed bridge virtual network,
     482             : /// however this breaks normal event-based mechanism of routes update in
     483             : /// the LR's bridge networks due to changes in the LR's routing network
     484             : /// (since RouteNotify handler will be disconnected) therefore, (b)
     485             : /// the only second viable option is when VnNotify is called first.
     486             : ///
     487             : /// The preferred order of execution for functions VrfNotify, VmiNotoify
     488             : /// and VnNotify cannot be specified explicitly from VxlanRoutingMananger,
     489             : /// since it is controlled by (a) arrival of IF-MAP information on a hypervisor
     490             : /// node from a controller and (b) by policies of Agent's operative DB.
     491             : /// For some cases, the correctness of execution is guaranteed by the order
     492             : /// of IF-MAP nodes processing, in some cases, it is guaranteed by additonal
     493             : /// calls inside VxlanRoutingManager.
     494             : ///
     495             : /// VxlanRoutingManager acts as a kernel module in some sense: it has several
     496             : /// member functions acting as an entry point and providing service to
     497             : /// its caller: an information about the current state of the module,
     498             : /// modification of the internal state, modifiction of external state (routes
     499             : /// advertisement). These entry points are:
     500             : /// - VxlanRoutingManager::VxlanRoutingManager, initializes the module,
     501             : /// modifies only the internal state;
     502             : /// - VxlanRoutingManager::Register: sets/resets handlers for change events in
     503             : /// VmiTable, VrfTable and VnTable, modifies only the internal state;
     504             : /// - VxlanRoutingManager::VmiNotify: links a VN with a VMI connecting the
     505             : /// latter with an LR, modifies the external state (VnEntry and VmInterface
     506             : /// states declared in VxlanRoutingManager) and is called whenever a VMI is
     507             : /// being attached to an LR (or detached from an LR);
     508             : /// - VxlanRoutingManager::VnNotify: establishes (updates) a mapping between
     509             : /// an LR and VNs attached to the LR, initiates traversing of the routing
     510             : /// and bridge VRF tables to copy (leak) routes between them, modifies the
     511             : /// internal and external states and is called whenever a VN is modified;
     512             : /// - VxlanRoutingManager::VrfNotify: links VxlanRoutingManager member
     513             : /// functions with changes in a modified bridge VN and routing VN routing
     514             : /// tables, modifies only the internal state;
     515             : /// - VxlanRoutingManager::RouteNotify: propagates locally-originated routes
     516             : /// (interface or interface composites) from bridge VRF Inet tables into
     517             : ///  the routing VRF Inet table associated previously with an LR;
     518             : /// - VxlanRoutingManager::XmppAdvertiseEvpnRoute: advertises an external
     519             : /// EVPN Type 5 route that came from controller via BGP/XMPP;
     520             : /// - VxlanRoutingManager::IsVxlanAvailable: returns true if VxLAN is
     521             : /// available;
     522             : /// - VxlanRoutingManager::IsRoutingVrf: returns true if the given VRF table
     523             : /// object is a VxLAN routing VRF table.
     524             : ///
     525             : /// The internal state of VxlanRoutingManager is defined by a map between
     526             : /// an LR UUID and virtual networks / VRF tables, associated with this LR.
     527             : /// The map is defined in VxlanRoutingVrfMapper class and stored as
     528             : /// std::map for a pair of {boost::uuids::uuid,
     529             : /// VxlanRoutingVrfMapper::RoutedVrfInfo}, where
     530             : /// VxlanRoutingVrfMapper::RoutedVrfInfo stores:
     531             : /// - a pointer to a VnEntry object containing description of the routing VN
     532             : /// associated with the LR;
     533             : /// - a list of pointers to VnEntry objects containing description of
     534             : /// bridge VNs associated with the LR;
     535             : /// - an array of names of VrfEntry objects containing description of
     536             : /// bridge and routing VRF tables linked with the corresponding VNs.
     537             : /// In addition, VxlanRoutingVrfMapper contains a reverse map, that
     538             : /// determines an LR UUID by a pointer to an VnEntry object, associated
     539             : /// with an LR as a bridge or a routing VN.
     540             : ///
     541             : /// The external state, which is modified by VxlanRoutingManager, is
     542             : /// characterized by:
     543             : /// - VRF tables (inet and EVPN) of bridge and routing virtual networks;
     544             : /// - operative DB entries states (VxlanRoutingVnState, VxlanRoutingVmiState,
     545             : /// VxlanRoutingState) which are associated with a VN, a VRF table or a VMI
     546             : /// to store additional information needed by VxlanRoutingManager.
     547             : ///
     548             : /// Since the aforementioned VxlanRoutingManager entry points are executed
     549             : /// in tasks with the same task code and task data ID (see Task class), their
     550             : /// execution is mutually exclusive, i.e., they cannot run in parallel, but
     551             : /// the order of their execution is not predetermined.
     552             : class VxlanRoutingManager {
     553             : public:
     554             : 
     555             :     /// @brief Constructs instance of the class and links to the Agent class
     556             :     /// instance. Since only one agent class instance works per system process,
     557             :     /// this implies that only one instance of VxlanRoutingManager exists.
     558             :     VxlanRoutingManager(Agent *agent);
     559             : 
     560             :     /// @brief Destroys the VxlanRoutingManager instance.
     561             :     virtual ~VxlanRoutingManager();
     562             : 
     563             :     /// @brief Registers handlers for events associated with changes in
     564             :     /// virtual networks (VnTable class) and VRF instances (VrfTable class).
     565             :     void Register();
     566             : 
     567             :     /// @brief Unregisters handlers for events associated with changes in
     568             :     /// virtual networks (VnTable class) and VRF instances (VrfTable class).
     569             :     void Shutdown();
     570             : 
     571             :     /// @brief A handler for changes (new/update/delete) in a virtual network
     572             :     /// (VnEntry class).
     573             :     void VnNotify(DBTablePartBase *partition, DBEntryBase *e);
     574             : 
     575             :     /// @brief A handler for changes (new/update/delete) in the virtual network
     576             :     /// from a bridge VRF.
     577             :     void BridgeVnNotify(const VnEntry *vn, VxlanRoutingVnState *vn_state);
     578             : 
     579             :     /// @brief A handler for changes (new/update/delete) in the virtual network
     580             :     /// from a routing VRF.
     581             :     void RoutingVnNotify(const VnEntry *vn, VxlanRoutingVnState *vn_state);
     582             : 
     583             :     /// @brief A handler for changes (new/update/delete) in a VRF instance
     584             :     /// (VrfEntry class).
     585             :     void VrfNotify(DBTablePartBase *partition, DBEntryBase *e);
     586             : 
     587             :     /// @brief Handler for changes (new/update/delete) in
     588             :     /// a VMI (VmInterface class).
     589             :     void VmiNotify(DBTablePartBase *partition, DBEntryBase *e);
     590             : 
     591             :     /// @brief Handler for changes (new/update/delete) in a route
     592             :     /// (EVPN or Inet). Main entry point for routes leaking.
     593             :     bool RouteNotify(DBTablePartBase *partition, DBEntryBase *e);
     594             : 
     595             :     /// Routes leaking functions
     596             : 
     597             : private:
     598             : 
     599             :     /// @brief Performs routes leaking between the Inet table of a bridge VRF
     600             :     /// instance and the EVPN table of the routing VRF instance.
     601             :     bool InetRouteNotify(DBTablePartBase *partition, DBEntryBase *e);
     602             : 
     603             :     /// @brief Performs routes leaking between the EVPN table of the routing
     604             :     /// VRF instance and the Inet table of the routing VRF instance.
     605             :     bool EvpnRouteNotify(DBTablePartBase *partition, DBEntryBase *e);
     606             : 
     607             :     /// @brief Removes redundant VrfNH path from a given route. These routes
     608             :     /// might arise with small chance in a bridge VRF inet tables when
     609             :     /// tunnels in the routing VRF instance arrive later then in the bridge VRF
     610             :     /// instance.
     611             :     void ClearRedundantVrfPath(DBEntryBase *e);
     612             : 
     613             :     /// @brief Handles deletion of a route in the EVPN table of the routing
     614             :     /// VRF instance.
     615             :     void WhenBridgeInetIntfWasDeleted(const InetUnicastRouteEntry *inet_rt,
     616             :         const VrfEntry *routing_vrf);
     617             : 
     618             :     /// @brief Handles deletion of a route in the Inet table of the routing
     619             :     /// VRF instance.
     620             :     void WhenRoutingEvpnRouteWasDeleted(const EvpnRouteEntry *routing_evpn_rt,
     621             :         const Peer* delete_from_peer);
     622             : 
     623             : public:
     624             : 
     625             :     /// @brief Deletes a given EVPN route from EVPN table of the routing
     626             :     /// VRF instance
     627             :     bool WithdrawEvpnRouteFromRoutingVrf(const VrfEntry *routing_vrf,
     628             :                                          DBTablePartBase *partition,
     629             :                                          DBEntryBase *e);
     630             : 
     631             :     /// @brief Performs advertisement and deletion of routing routes
     632             :     /// (with VrfNH) in bridge VRF instances. External tunnels and routes
     633             :     /// with a prefix that is not present in bridge VRF instance are
     634             :     /// selected for leaking
     635             :     bool LeakRoutesIntoBridgeTables(DBTablePartBase *partition,
     636             :                                     DBEntryBase *e,
     637             :                                     const boost::uuids::uuid &uuid,
     638             :                                     const VnEntry *vn,
     639             :                                     bool update = false);
     640             : 
     641             :     /// @brief Performs deletion of external routing routes
     642             :     /// (with VrfNH) in bridge VRF instances.
     643             :     bool RemoveRoutesFromRoutingToBridgeVrf(DBTablePartBase *partition,
     644             :                                                DBEntryBase *e,
     645             :                                                const VnEntry *vn,
     646             :                                                std::string bridge_vrf_name);
     647             : 
     648             :     /// @brief Handles routing routes (with VrfNH) update in the routing VRF
     649             :     /// instance.
     650             :     void HandleSubnetRoute(const VrfEntry *vrf, bool bridge_vrf = false);
     651             : 
     652             : private:
     653             : 
     654             :     /// @brief deletes all routes in EVPN table of routing VRF
     655             :     void RoutingVrfDeleteAllRoutes(VrfEntry* rt_vrf);
     656             : 
     657             :     /// @brief Deletes subnet routes (actually, paths with VrfNH) in
     658             :     /// the given bridge VRF. This function is demanded at vn.c:618
     659             :     void DeleteSubnetRoute(const VrfEntry *vrf);
     660             :     // void DeleteSubnetRoute(const VrfEntry *vrf, VnIpam *ipam = NULL);
     661             : 
     662             :     /// @brief Deletes subnet routes from a specified virtual network
     663             :     /// (VirtualNetwork)
     664             :     void DeleteSubnetRoute(const VnEntry *vn,
     665             :         const std::string& vrf_name);
     666             : 
     667             :     /// @brief Delete routes to IPAM, specified by IP prefix and prefix
     668             :     /// length
     669             :     void DeleteIpamRoutes(const VnEntry *vn,
     670             :                           const std::string& vrf_name,
     671             :                           const IpAddress& ipam_prefix,
     672             :                           const uint32_t plen);
     673             : 
     674             :     /// @brief Updates subnet routes (actually, paths with VrfNH) in
     675             :     /// the given bridge VRF
     676             :     void UpdateSubnetRoute(const VrfEntry *vrf,
     677             :                            const VrfEntry *routing_vrf);
     678             : public:
     679             : 
     680             :     /// @brief Updates Sandesh response
     681             :     void FillSandeshInfo(VxlanRoutingResp *resp);
     682             : 
     683             :     /// @brief Returns the ID of the listener to changes in the VnTable
     684          60 :     DBTable::ListenerId vn_listener_id() const {
     685          60 :         return vn_listener_id_;
     686             :     }
     687             : 
     688             :     /// @brief Returns the ID of the listener to changes in the VrfTable
     689             :     DBTable::ListenerId vrf_listener_id() const {
     690             :         return vrf_listener_id_;
     691             :     }
     692             : 
     693             :     /// @brief Returns the ID of the listener to changes in the InterfaceTable
     694             :     DBTable::ListenerId vmi_listener_id() const {
     695             :         return vmi_listener_id_;
     696             :     }
     697             : 
     698             :     /// @brief Returns the map between LR uuids and associated bridge and
     699             :     /// routing VRF instances
     700          90 :     const VxlanRoutingVrfMapper &vrf_mapper() const {
     701          90 :         return vrf_mapper_;
     702             :     }
     703             : 
     704             :     /// @brief Returns a pointer to the AgentRouteWalkerPtr object
     705           2 :     AgentRouteWalker* walker() {
     706           2 :         return walker_.get();
     707             :     }
     708             : 
     709             : private:
     710             : 
     711             :     /// Internal data of this class
     712             : 
     713             :     /// @brief A pointer to the Peer where all interface / composite of
     714             :     /// interfaces routes in routing VRF are linked to.
     715             :     static const Peer *routing_vrf_interface_peer_;
     716             : 
     717             :     /// @brief A pointer to the Peer where all BGP routes are stored
     718             :     static const Peer *routing_vrf_vxlan_bgp_peer_;
     719             : 
     720             :     /// @brief A pointer to the Agent instance.
     721             :     Agent *agent_;
     722             : 
     723             :     /// @brief A pointer to the walker to loop over INET tables
     724             :     /// in bridge VRF instances.
     725             :     AgentRouteWalkerPtr walker_;
     726             : 
     727             :     /// @brief An ID of the listener to changes in VnTable.
     728             :     DBTable::ListenerId vn_listener_id_;
     729             : 
     730             :     /// @brief An ID of the listener to changes in VrfTable.
     731             :     DBTable::ListenerId vrf_listener_id_;
     732             : 
     733             :     /// @brief An ID of the listener to changes in InterfaceTable.
     734             :     DBTable::ListenerId vmi_listener_id_;
     735             : 
     736             :     /// @brief A map between LR uuids and associated bridge and
     737             :     /// routing VRF instances.
     738             :     VxlanRoutingVrfMapper vrf_mapper_;
     739             : 
     740             :     /// @brief An always increasing counter for new paths (used to signal
     741             :     /// controoler about new routes).
     742             :     static uint32_t loc_sequence_;
     743             : 
     744             :     /// Friends declarations
     745             : 
     746             :     /// @brief Allows access to private members for the VxlanRoutingRouteWalker
     747             :     /// class.
     748             :     friend class VxlanRoutingRouteWalker;
     749             : 
     750             :     /// @brief Allows ControllerEcmpRoute to use private members of this class.
     751             :     friend class ControllerEcmpRoute;
     752             : 
     753             :     /// @brief Allows AgentXmppChannel to use private members of this class.
     754             :     friend class AgentXmppChannel;
     755             : 
     756             :     /// @brief Allows access to Xmpp advertisement functions via external class
     757             :     friend class AgentXmppChannelVxlanInterface;
     758             : 
     759             :     /// @brief Allows VxlanRoutingVrfMapper to use private members of
     760             :     /// this class.
     761             :     friend class VxlanRoutingVrfMapper;
     762             : 
     763             :     /// @brief Allows MetadataProxy to use private members of this class.
     764             :     friend class MetadataProxy;
     765             : 
     766             :     /// Auxilliary functions
     767             : 
     768             :     /// @brief Returns new value of a local sequence. Thread safe version
     769             :     static uint32_t GetNewLocalSequence(const AgentPath*);
     770             : 
     771             :     /// @brief Determines whether the address string contains an IPv4 address
     772             :     ///  as substring or not.
     773             :     static bool is_ipv4_string(const std::string& prefix_str);
     774             : 
     775             :     /// @brief Determines whether the address string contains an IPv6 address
     776             :     ///  as substring or not.
     777             :     static bool is_ipv6_string(const std::string& prefix_str);
     778             : 
     779             :     /// @brief Extracts length of IPv4 subnet address from the prefix string.
     780             :     static uint32_t ipv4_prefix_len(const std::string& prefix_str);
     781             : 
     782             :     /// @brief Extracts an IPv4 address string from the prefix string.
     783             :     static std::string ipv4_prefix(const std::string& prefix_str);
     784             : 
     785             :     /// @brief Extracts length of IPv6 subnet address from the prefix string.
     786             :     static uint32_t ipv6_prefix_len(const std::string& prefix_str);
     787             : 
     788             :     /// @brief Extracts an IPv6 address string from the prefix string.
     789             :     static std::string ipv6_prefix(const std::string& prefix_str);
     790             : 
     791             :     /// @brief Checks whether VxLAN routing manager is enabled or not.
     792             :     static bool IsVxlanAvailable(const Agent* agent);
     793             : 
     794             :     /// @brief Finds first occurence of a route with the given prefix (IP
     795             :     /// address and length) in Inet tables of bridge VRF instances connected
     796             :     /// to the given routing VRF instance (LR).
     797             :     std::string GetOriginVn(const VrfEntry* routing_vrf,
     798             :         const IpAddress& ip_addr,
     799             :         const uint8_t& plen);
     800             : 
     801             :     /// @brief Determines whether route prefix in the EVPN route is equal
     802             :     /// to the given pair of prefix IP address and length
     803             :     static bool RoutePrefixIsEqualTo(const EvpnRouteEntry* route,
     804             :         const IpAddress& prefix_ip,
     805             :         const uint32_t prefix_len);
     806             : 
     807             :     /// @brief Determines whether route prefix of the Inet route is equal
     808             :     /// to the given pair of prefix IP address and length
     809             :     static bool RoutePrefixIsEqualTo(const InetUnicastRouteEntry* route,
     810             :         const IpAddress& prefix_ip,
     811             :         const uint32_t prefix_len);
     812             : 
     813             :     /// @brief Determines whether the prefix address and the prefix length
     814             :     /// point to a host route (/32 for IPv4, /128 for IPv6) or
     815             :     /// to a subnet route.
     816             :     static bool IsHostRoute(const IpAddress& prefix_ip, uint32_t prefix_len);
     817             : 
     818             :     /// @brief Determines whether the given EVPN route points to a host or
     819             :     /// a subnet.
     820             :     static bool IsHostRoute(const EvpnRouteEntry *rt);
     821             : 
     822             :     /// @brief Determines whether the given EVPN route is a host one and
     823             :     /// belongs to a subnet of a local bridge VRF. During the search all
     824             :     /// subnets in all bridge VRF instances connected to the LR are traversed.
     825             :     bool IsHostRouteFromLocalSubnet(const EvpnRouteEntry *rt);
     826             : 
     827             :     /// @brief Determines if the given EVPN route has an interface NH or
     828             :     /// a composite of interfaces NH that belongs to the given
     829             :     /// bridge VRF instance.
     830             :     bool IsVrfLocalRoute(EvpnRouteEntry *routing_evpn_rt,
     831             :         VrfEntry *bridge_vrf);
     832             : 
     833             :     /// @brief Determines if the given EVPN route is already present
     834             :     /// in the given VRF
     835             :     bool IsLocalRoute(EvpnRouteEntry *routing_evpn_rt,
     836             :         VrfEntry *bridge_vrf);
     837             : 
     838             :     /// @brief Determines whether the given route has the path with
     839             :     /// a VRF nexthop (VrfNH)
     840             :     static bool HasVrfNexthop(const AgentRoute* rt);
     841             : 
     842             :     /// @brief Determines whether the given EVPN route has at least one path
     843             :     /// originating from BGP/XMPP (has Peer type BGP_PATH)
     844             :     bool HasBgpPeerPath(EvpnRouteEntry *evpn_rt);
     845             : 
     846             :     /// @brief Determines whether the pointer to the VRF instance is of routing
     847             :     ///  type.
     848             :     /// @return true if it is routing, otherwise return value is false.
     849             :     static bool IsRoutingVrf(const VrfEntry* vrf);
     850             : 
     851             :     /// @brief Determines whether the pointer to the VRF instance is of
     852             :     /// bridge type.
     853             :     /// @return true if it is routing, otherwise return value is false.
     854             :     static bool IsBridgeVrf(const VrfEntry* vrf);
     855             : 
     856             :     /// @brief Checks whether the VRF instance with the given name is routing
     857             :     /// or not.
     858             :     /// @return true if this VRF is routing, otherwise return value is false.
     859             :     static bool IsRoutingVrf(const std::string vrf_name, const Agent *agent);
     860             : 
     861             :     /// @brief Finds in the given route the path with a specified Peer type
     862             :     static const AgentPath* FindPathWithGivenPeer(
     863             :         const AgentRoute *inet_rt,
     864             :         const Peer::Type peer_type);
     865             : 
     866             :     /// @brief Finds in the given route the path with a specified Peer type
     867             :     /// and a specified nexthop type
     868             :     static const AgentPath* FindPathWithGivenPeerAndNexthop(
     869             :         const AgentRoute *inet_rt,
     870             :         const Peer::Type peer_type,
     871             :         const NextHop::Type nh_type,
     872             :         bool strict_match = true);
     873             : 
     874             :     /// @brief Finds in the given route the path with the given Peer type
     875             :     /// and interface nexthop (InterfaceNH).
     876             :     static const AgentPath* FindInterfacePathWithGivenPeer(
     877             :         const AgentRoute *inet_rt,
     878             :         const Peer::Type peer_type,
     879             :         bool strict_match = true);
     880             : 
     881             :     /// @brief Finds in the given route the path which has
     882             :     /// the BGP_PEER Peer type and the Interface nexthop type.
     883             :     /// Such path presumably points to BGPaaS advertised route.
     884             :     static const AgentPath *FindInterfacePathWithBgpPeer(
     885             :         const AgentRoute *inet_rt,
     886             :         bool strict_match = true);
     887             : 
     888             :     /// @brief Finds in the given route the path which has the LOCAL_VM_PEER
     889             :     /// peer type and the Interface nexthop type.
     890             :     static const AgentPath *FindInterfacePathWithLocalVmPeer(
     891             :         const AgentRoute *inet_rt,
     892             :         bool strict_match = true);
     893             : 
     894             :     /// @brief Returns the MAC address for the IP of a given
     895             :     /// neighbouring compute
     896             :     static MacAddress NbComputeMac(const Ip4Address& compute_ip,
     897             :         const Agent *agent);
     898             : 
     899             :     /// XMPP Advertising functions
     900             : 
     901             :     /// @brief Allocates and returns a new key for the VxLAN tunnel to
     902             :     /// the given router
     903             :     TunnelNHKey* AllocateTunnelNextHopKey(const IpAddress& dip,
     904             :         const MacAddress& dmac) const;
     905             : 
     906             :     /// @brief Advertises an EVPN route received using XMPP channel
     907             :     void XmppAdvertiseEvpnRoute(const IpAddress& prefix_ip,
     908             :         const int prefix_len, uint32_t vxlan_id, const std::string vrf_name,
     909             :         const RouteParameters& params, const Peer *bgp_peer,
     910             :         const std::vector<std::string> &peer_sources);
     911             : 
     912             :     /// @brief Advertises an Inet route received using XMPP channel
     913             :     void XmppAdvertiseInetRoute(const IpAddress& prefix_ip,
     914             :         const int prefix_len, uint32_t vxlan_id, const std::string vrf_name,
     915             :         const RouteParameters& params, const Peer *bgp_peer);
     916             : 
     917             :     /// @brief Advertises an Inet route received from EVPN table
     918             :     void XmppAdvertiseInetRoute(const IpAddress& prefix_ip,
     919             :         const int prefix_len, const std::string vrf_name,
     920             :         const AgentPath*);
     921             : 
     922             :     /// @brief Advertises in the EVPN table a tunnel route that arrived
     923             :     /// via XMPP channel. Must be called only from XmppAdvertiseInetRoute.
     924             :     void XmppAdvertiseEvpnTunnel(
     925             :         EvpnAgentRouteTable *inet_table, const IpAddress& prefix_ip,
     926             :         const int prefix_len, uint32_t vxlan_id, const std::string vrf_name,
     927             :         const RouteParameters& params, const Peer *bgp_peer);
     928             : 
     929             :     /// @brief Advertises in the EVPN table an interface route that arrived
     930             :     /// via XMPP channel. Must be called only from XmppAdvertiseInetRoute.
     931             :     void XmppAdvertiseEvpnInterface(
     932             :         EvpnAgentRouteTable *inet_table, const IpAddress& prefix_ip,
     933             :         const int prefix_len, uint32_t vxlan_id, const std::string vrf_name,
     934             :         const RouteParameters& params, const Peer *bgp_peer,
     935             :         const std::vector<std::string> &peer_sources);
     936             : 
     937             :     /// @brief Advertises in the Inet table a tunnel route that arrived
     938             :     /// via XMPP channel. Must be called only from XmppAdvertiseInetRoute.
     939             :     void XmppAdvertiseInetTunnel(
     940             :         InetUnicastAgentRouteTable *inet_table, const IpAddress& prefix_ip,
     941             :         const int prefix_len, uint32_t vxlan_id, const std::string vrf_name,
     942             :         const RouteParameters& params, const Peer *bgp_peer);
     943             : 
     944             :     /// @brief Advertises in the Inet table a tunnel route that arrived
     945             :     /// via XMPP channel. Must be called only from XmppAdvertiseInetRoute.
     946             :     void XmppAdvertiseInetTunnel(
     947             :         InetUnicastAgentRouteTable *inet_table, const IpAddress& prefix_ip,
     948             :         const int prefix_len, const std::string vrf_name,
     949             :         const AgentPath* path);
     950             : 
     951             :     /// @brief Advertises in the Inet table an interface route that arrived
     952             :     /// via XMPP channel. Must be called only from XmppAdvertiseInetRoute.
     953             :     void XmppAdvertiseInetInterfaceOrComposite(
     954             :         InetUnicastAgentRouteTable *inet_table, const IpAddress& prefix_ip,
     955             :         const int prefix_len, const std::string vrf_name,
     956             :         const AgentPath* path);
     957             : 
     958             :     /// Templates
     959             : 
     960             :     /// @brief Converts item's (EnetItemType for EVPN / ItemType for Inet)
     961             :     /// nexthops into the list of IP addresses (IpAddress)
     962             :     template <class ItType>
     963             :     static std::vector<IpAddress> ItemNexthopsToVector(ItType *item);
     964             : 
     965             :     /// @brief Adds an interface or a composite of interfaces nexthops to
     966             :     /// the list of components NH keys needed for construction of the
     967             :     /// a mixed composite.
     968             :     template<typename NhType>
     969             :     static void AddInterfaceComponentToList(
     970             :         const std::string& prefix_str,
     971             :         const std::string& vrf_name,
     972             :         const NhType &nh_item,
     973             :         ComponentNHKeyList& comp_nh_list,
     974             :         std::vector<std::string> &peer_sources);
     975             : 
     976             :     template<typename NhType>
     977             :     static void AddBgpaasInterfaceComponentToList(
     978             :         const std::string& vrf_name,
     979             :         const NhType &nh_item,
     980             :         ComponentNHKeyList& comp_nh_list,
     981             :         std::vector<std::string> &peer_sources);
     982             : 
     983             :     /// @brief Finds a route with the given prefix address and len
     984             :     /// in the EVPN table
     985             :     static AgentRoute *FindEvpnOrInetRoute(const Agent *agent,
     986             :         const std::string &vrf_name,
     987             :         const IpAddress &ip_addr,
     988             :         uint32_t prefix_len,
     989             :         const autogen::EnetNextHopType &nh_item);
     990             : 
     991             :     /// @brief Finds a route with the given prefix address and len
     992             :     /// in the Inet table
     993             :     static AgentRoute *FindEvpnOrInetRoute(const Agent *agent,
     994             :         const std::string &vrf_name,
     995             :         const IpAddress &ip_addr,
     996             :         uint32_t prefix_len,
     997             :         const autogen::NextHopType &nh_item);
     998             : 
     999             :     /// Routes copying functions
    1000             : 
    1001             :     /// @brief Deletes interface path specified with IP prefix, prefix
    1002             :     /// length and Peer from the EVPN table.
    1003             :     static void DeleteOldInterfacePath(const IpAddress &prefix_ip,
    1004             :         const uint32_t plen,
    1005             :         const Peer *peer,
    1006             :         EvpnAgentRouteTable *evpn_table);
    1007             : 
    1008             :     /// @brief Copies the path to the prefix address into the EVPN table
    1009             :     /// with the given Peer. The function is used during routes leaking
    1010             :     /// between bridge VRF Inet and routing EVPN tables.
    1011             :     static void CopyInterfacePathToEvpnTable(const AgentPath* path,
    1012             :         const IpAddress &prefix_ip,
    1013             :         const uint32_t plen,
    1014             :         const Peer *peer,
    1015             :         const RouteParameters &params,
    1016             :         EvpnAgentRouteTable *evpn_table);
    1017             : 
    1018             :     /// @brief
    1019             :     static void DeleteOldInterfacePath(const IpAddress &prefix_ip,
    1020             :         const uint32_t plen,
    1021             :         const Peer *peer,
    1022             :         InetUnicastAgentRouteTable *inet_table);
    1023             : 
    1024             :     /// @brief Copies the path to the prefix address into the EVPN table
    1025             :     /// with the given Peer. The function is used during routes leaking
    1026             :     /// between routing VRF EVPN and Inet tables.
    1027             :     void CopyPathToInetTable(const AgentPath* path,
    1028             :         const IpAddress &prefix_ip,
    1029             :         const uint32_t plen,
    1030             :         const Peer *peer,
    1031             :         const RouteParameters &params,
    1032             :         InetUnicastAgentRouteTable *inet_table);
    1033             : 
    1034             :     /// @brief Advertises in an EVPN routing table a BGPaaS route that
    1035             :     /// came from the controller (this routes leaking occurs in the
    1036             :     /// controller).
    1037             :     void XmppAdvertiseEvpnBgpaas(
    1038             :     EvpnAgentRouteTable *evpn_table, const IpAddress& prefix_ip,
    1039             :     const int prefix_len, uint32_t vxlan_id, const std::string vrf_name,
    1040             :     const RouteParameters& params, const Peer *bgp_peer,
    1041             :     const std::vector<std::string> &peer_sources);
    1042             : 
    1043             :     /// @brief Advertises in an EVPN routing table a BGPaaS route
    1044             :     /// with interface path that
    1045             :     /// came from the controller (this routes leaking occurs in the
    1046             :     /// controller).
    1047             :     void XmppAdvertiseEvpnBgpaasInterface(
    1048             :     EvpnAgentRouteTable *evpn_table, const IpAddress& prefix_ip,
    1049             :     const int prefix_len, uint32_t vxlan_id, const std::string vrf_name,
    1050             :     const RouteParameters& params, const Peer *bgp_peer,  const NextHop *nh);
    1051             : 
    1052             :     /// @brief Advertises in an EVPN routing table a BGPaaS route
    1053             :     /// with interface composite path that
    1054             :     /// came from the controller (this routes leaking occurs in the
    1055             :     /// controller).
    1056             :     void XmppAdvertiseEvpnBgpaasComposite(
    1057             :     EvpnAgentRouteTable *evpn_table, const IpAddress& prefix_ip,
    1058             :     const int prefix_len, uint32_t vxlan_id, const std::string vrf_name,
    1059             :     const RouteParameters& params, const Peer *bgp_peer,
    1060             :     ComponentNHKeyList &comp_nh_list);
    1061             : 
    1062             : public:
    1063             : 
    1064             :     /// @brief Prints EVPN table of the given VRF instance.
    1065             :     static void PrintEvpnTable(const VrfEntry* const_vrf);
    1066             : 
    1067             :     /// @brief Prints IPv4 Inet table of the given VRF instance.
    1068             :     static void PrintInetTable(const VrfEntry* const_vrf);
    1069             : 
    1070             :     /// @brief Prints all virtual networks attached to logical routers.
    1071             :     static void ListAttachedVns();
    1072             : 
    1073             :     /// @brief Finds a VRF table (VrfEntry) for the given virtual network (VN).
    1074             :     /// Returns nullptr if no VRF table associated with this VN or there is no
    1075             :     /// VrfEntry having the given name.
    1076           0 :     static inline VrfEntry* VnVrf(const VnEntry *vn, const std::string &vrf_name) {
    1077           0 :         VrfEntry* vrf = nullptr;
    1078           0 :         vrf = vn->GetVrf();
    1079           0 :         if (vrf != nullptr) {
    1080           0 :             return vrf;
    1081             :         }
    1082           0 :         vrf = Agent::GetInstance()->vrf_table()->FindVrfFromName(vrf_name);
    1083           0 :         return vrf;
    1084             :     }
    1085             : 
    1086             :     DISALLOW_COPY_AND_ASSIGN(VxlanRoutingManager);
    1087             : };
    1088             : 
    1089             : #include <oper/vxlan_templates.cc>
    1090             : 
    1091             : #endif

Generated by: LCOV version 1.14