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

Generated by: LCOV version 1.14