OpenSDN source code
vxlan_routing_manager.h
Go to the documentation of this file.
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 
25 
27  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  uint64_t seq_n):
36  nh_addresses_(1, nh_addr),
37  nh_addr_(nh_addresses_.at(0)),
38  nh_mac_(mac),
39  vn_list_(vns), sg_list_(sgs),
40  communities_(comms), tag_list_(tags),
41  path_preference_(ppref),
42  ecmp_load_balance_(ecmp),
43  sequence_number_(seq_n) {
44  }
45 
49  nh_addr_(rp.nh_addr_),
50  nh_mac_(rp.nh_mac_),
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 
79  const std::vector<IpAddress> nh_addresses_;
80 
84 
87 
91 
94 
97 
100 
103 
106 
109 
110 private:
111 
114 };
115 
121 struct VxlanRoutingState : public DBState {
122 
126  VrfEntry *vrf);
127 
129  virtual ~VxlanRoutingState();
130 
134 
138 
142 
145 
148 
151 };
152 
159 struct VxlanRoutingVnState : public DBState {
160 
162  typedef std::set<const VmInterface *> VmiList;
163 
165  typedef VmiList::iterator VmiListIter;
166 
169 
171  virtual ~VxlanRoutingVnState();
172 
176  void AddVmi(const VnEntry *vn, const VmInterface *vmi);
177 
180  void DeleteVmi(const VnEntry *vn, const VmInterface *vmi);
181 
184 
187  std::set<const VmInterface *> vmi_list_;
188 
192 
195 
199 
202 
203 };
204 
208 struct VxlanRoutingVmiState : public DBState {
209 
212 
214  virtual ~VxlanRoutingVmiState();
215 
219 
222 };
223 
233 public:
234 
237  VxlanRoutingRouteWalker(const std::string &name,
239 
241  virtual ~VxlanRoutingRouteWalker();
242 
245  virtual bool RouteWalkNotify(DBTablePartBase *partition, DBEntryBase *e);
246 
247 private:
248 
251 
253 };
254 
255 
268 public:
269 
272  struct RoutedVrfInfo {
273 
276  typedef std::set<const VnEntry *> BridgeVnList;
277 
280  typedef std::map<const VnEntry *, std::string> BridgeVrfNamesList;
281 
284  typedef BridgeVnList::iterator BridgeVnListIter;
285 
288  routing_vrf_(NULL), bridge_vn_list_() {
289  }
290 
292  virtual ~RoutedVrfInfo() {
293  }
294 
298 
302 
306 
310  };
311 
314  typedef std::map<boost::uuids::uuid, RoutedVrfInfo> LrVrfInfoMap;
315 
317  typedef LrVrfInfoMap::iterator LrVrfInfoMapIter;
318 
322  typedef std::map<const VnEntry *, boost::uuids::uuid> VnLrSet;
323 
325  typedef VnLrSet::iterator VnLrSetIter;
326 
330  typedef std::map<const InetUnicastAgentRouteTable *, DBTable::DBTableWalkRef>
332 
336 
338  virtual ~VxlanRoutingVrfMapper();
339 
343  DBTableBase *partition);
344 
348  DBTableBase *partition);
349 
353  DBTableBase *partition);
354 
360 
362  bool IsEmpty() const {
363  return ((vn_lr_set_.size() == 0) &&
364  (lr_vrf_info_map_.size() == 0));
365  }
366 
367 private:
368 
370  friend class VxlanRoutingManager;
371 
374  void WalkBridgeVrfs(const RoutedVrfInfo &routing_vrf_info);
375 
378  void WalkRoutingVrf(const boost::uuids::uuid &lr_uuid,
379  const VnEntry *vn, bool update, bool withdraw);
380 
384  const boost::uuids::uuid &lr_uuid, const VnEntry *vn,
385  std::string bridge_vrf_name);
386 
390 
392  const VrfEntry *GetRoutingVrfUsingVn(const VnEntry *vn);
393 
397 
399  const VrfEntry *GetRoutingVrfUsingUuid(const boost::uuids::uuid &lr_uuid);
400 
403 
406 
410 
415 
418 
421 
423 };
424 
553 public:
554 
558  VxlanRoutingManager(Agent *agent);
559 
561  virtual ~VxlanRoutingManager();
562 
565  void Register();
566 
569  void Shutdown();
570 
573  void VnNotify(DBTablePartBase *partition, DBEntryBase *e);
574 
577  void BridgeVnNotify(const VnEntry *vn, VxlanRoutingVnState *vn_state);
578 
581  void RoutingVnNotify(const VnEntry *vn, VxlanRoutingVnState *vn_state);
582 
585  void VrfNotify(DBTablePartBase *partition, DBEntryBase *e);
586 
589  void VmiNotify(DBTablePartBase *partition, DBEntryBase *e);
590 
593  bool RouteNotify(DBTablePartBase *partition, DBEntryBase *e);
594 
596 
597 private:
598 
601  bool InetRouteNotify(DBTablePartBase *partition, DBEntryBase *e);
602 
605  bool EvpnRouteNotify(DBTablePartBase *partition, DBEntryBase *e);
606 
612 
616  const VrfEntry *routing_vrf);
617 
620  void WhenRoutingEvpnRouteWasDeleted(const EvpnRouteEntry *routing_evpn_rt,
621  const Peer* delete_from_peer);
622 
623 public:
624 
627  bool WithdrawEvpnRouteFromRoutingVrf(const VrfEntry *routing_vrf,
628  DBTablePartBase *partition,
629  DBEntryBase *e);
630 
636  DBEntryBase *e,
637  const boost::uuids::uuid &uuid,
638  const VnEntry *vn,
639  bool update = false);
640 
644  DBEntryBase *e,
645  const VnEntry *vn,
646  std::string bridge_vrf_name);
647 
650  void HandleSubnetRoute(const VrfEntry *vrf, bool bridge_vrf = false);
651 
652 private:
653 
655  void RoutingVrfDeleteAllRoutes(VrfEntry* rt_vrf);
656 
659  void DeleteSubnetRoute(const VrfEntry *vrf);
660  // void DeleteSubnetRoute(const VrfEntry *vrf, VnIpam *ipam = NULL);
661 
664  void DeleteSubnetRoute(const VnEntry *vn,
665  const std::string& vrf_name);
666 
669  void DeleteIpamRoutes(const VnEntry *vn,
670  const std::string& vrf_name,
671  const IpAddress& ipam_prefix,
672  const uint32_t plen);
673 
676  void UpdateSubnetRoute(const VrfEntry *vrf,
677  const VrfEntry *routing_vrf);
678 public:
679 
681  void FillSandeshInfo(VxlanRoutingResp *resp);
682 
685  return vn_listener_id_;
686  }
687 
690  return vrf_listener_id_;
691  }
692 
695  return vmi_listener_id_;
696  }
697 
701  return vrf_mapper_;
702  }
703 
706  return walker_.get();
707  }
708 
709 private:
710 
712 
716 
719 
722 
726 
729 
732 
735 
739 
742  static uint32_t loc_sequence_;
743 
745 
749 
751  friend class ControllerEcmpRoute;
752 
754  friend class AgentXmppChannel;
755 
758 
761  friend class VxlanRoutingVrfMapper;
762 
764  friend class MetadataProxy;
765 
767 
769  static uint32_t GetNewLocalSequence(const AgentPath*);
770 
773  static bool is_ipv4_string(const std::string& prefix_str);
774 
777  static bool is_ipv6_string(const std::string& prefix_str);
778 
780  static uint32_t ipv4_prefix_len(const std::string& prefix_str);
781 
783  static std::string ipv4_prefix(const std::string& prefix_str);
784 
786  static uint32_t ipv6_prefix_len(const std::string& prefix_str);
787 
789  static std::string ipv6_prefix(const std::string& prefix_str);
790 
792  static bool IsVxlanAvailable(const Agent* agent);
793 
797  std::string GetOriginVn(const VrfEntry* routing_vrf,
798  const IpAddress& ip_addr,
799  const uint8_t& plen);
800 
803  static bool RoutePrefixIsEqualTo(const EvpnRouteEntry* route,
804  const IpAddress& prefix_ip,
805  const uint32_t prefix_len);
806 
809  static bool RoutePrefixIsEqualTo(const InetUnicastRouteEntry* route,
810  const IpAddress& prefix_ip,
811  const uint32_t prefix_len);
812 
816  static bool IsHostRoute(const IpAddress& prefix_ip, uint32_t prefix_len);
817 
820  static bool IsHostRoute(const EvpnRouteEntry *rt);
821 
826 
830  bool IsVrfLocalRoute(EvpnRouteEntry *routing_evpn_rt,
831  VrfEntry *bridge_vrf);
832 
835  bool IsLocalRoute(EvpnRouteEntry *routing_evpn_rt,
836  VrfEntry *bridge_vrf);
837 
840  static bool HasVrfNexthop(const AgentRoute* rt);
841 
844  bool HasBgpPeerPath(EvpnRouteEntry *evpn_rt);
845 
849  static bool IsRoutingVrf(const VrfEntry* vrf);
850 
854  static bool IsBridgeVrf(const VrfEntry* vrf);
855 
859  static bool IsRoutingVrf(const std::string vrf_name, const Agent *agent);
860 
862  static const AgentPath* FindPathWithGivenPeer(
863  const AgentRoute *inet_rt,
864  const Peer::Type peer_type);
865 
869  const AgentRoute *inet_rt,
870  const Peer::Type peer_type,
871  const NextHop::Type nh_type,
872  bool strict_match = true);
873 
877  const AgentRoute *inet_rt,
878  const Peer::Type peer_type,
879  bool strict_match = true);
880 
885  const AgentRoute *inet_rt,
886  bool strict_match = true);
887 
891  const AgentRoute *inet_rt,
892  bool strict_match = true);
893 
896  static MacAddress NbComputeMac(const Ip4Address& compute_ip,
897  const Agent *agent);
898 
900 
904  const MacAddress& dmac) const;
905 
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 
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 
918  void XmppAdvertiseInetRoute(const IpAddress& prefix_ip,
919  const int prefix_len, const std::string vrf_name,
920  const AgentPath*);
921 
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 
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 
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 
947  InetUnicastAgentRouteTable *inet_table, const IpAddress& prefix_ip,
948  const int prefix_len, const std::string vrf_name,
949  const AgentPath* path);
950 
954  InetUnicastAgentRouteTable *inet_table, const IpAddress& prefix_ip,
955  const int prefix_len, const std::string vrf_name,
956  const AgentPath* path);
957 
959 
962  template <class ItType>
963  static std::vector<IpAddress> ItemNexthopsToVector(ItType *item);
964 
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>
978  const std::string& vrf_name,
979  const NhType &nh_item,
980  ComponentNHKeyList& comp_nh_list,
981  std::vector<std::string> &peer_sources);
982 
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 
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 
1000 
1003  static void DeleteOldInterfacePath(const IpAddress &prefix_ip,
1004  const uint32_t plen,
1005  const Peer *peer,
1006  EvpnAgentRouteTable *evpn_table);
1007 
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 
1019  static void DeleteOldInterfacePath(const IpAddress &prefix_ip,
1020  const uint32_t plen,
1021  const Peer *peer,
1022  InetUnicastAgentRouteTable *inet_table);
1023 
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 
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 
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 
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 
1065  static void PrintEvpnTable(const VrfEntry* const_vrf);
1066 
1068  static void PrintInetTable(const VrfEntry* const_vrf);
1069 
1071  static void ListAttachedVns();
1072 
1076  static inline VrfEntry* VnVrf(const VnEntry *vn, const std::string &vrf_name) {
1077  VrfEntry* vrf = nullptr;
1078  vrf = vn->GetVrf();
1079  if (vrf != nullptr) {
1080  return vrf;
1081  }
1082  vrf = Agent::GetInstance()->vrf_table()->FindVrfFromName(vrf_name);
1083  return vrf;
1084  }
1085 
1087 };
1088 
1089 #include <oper/vxlan_templates.cc>
1090 
1091 #endif
boost::asio::ip::address IpAddress
Definition: address.h:13
boost::asio::ip::address_v4 Ip4Address
Definition: address.h:14
std::vector< uint64_t > TagList
Definition: agent.h:202
std::vector< int > SecurityGroupList
Definition: agent.h:201
std::set< std::string > VnListType
Definition: agent.h:212
boost::intrusive_ptr< VnEntry > VnEntryRef
Definition: agent.h:68
boost::intrusive_ptr< AgentRouteWalker > AgentRouteWalkerPtr
std::vector< std::string > CommunityList
Definition: bgp_config.h:347
Agent supports multiple route tables - Inet-unicast (IPv4/IPv6), Inet-multicast, bridge,...
Definition: agent_route.h:109
AgentRouteWalkerManager * mgr()
Agent * agent() const
Base class for all Route entries in agent.
Definition: agent_route.h:224
Definition: agent.h:360
VrfTable * vrf_table() const
Definition: agent.h:487
static Agent * GetInstance()
Definition: agent.h:438
int ListenerId
Definition: db_table.h:62
boost::intrusive_ptr< DBTableWalk > DBTableWalkRef
Definition: db_table.h:169
Definition: peer.h:44
Type
Definition: peer.h:48
Definition: vn.h:151
VrfEntry * GetVrf() const
Definition: vn.h:170
Definition: vrf.h:89
VrfEntry * FindVrfFromName(const string &name)
Definition: vrf.cc:873
This class manages an operative state of VxLAN logical routers (LR) defined via Config logical-router...
static void ListAttachedVns()
Prints all virtual networks attached to logical routers.
void DeleteIpamRoutes(const VnEntry *vn, const std::string &vrf_name, const IpAddress &ipam_prefix, const uint32_t plen)
Delete routes to IPAM, specified by IP prefix and prefix length.
bool LeakRoutesIntoBridgeTables(DBTablePartBase *partition, DBEntryBase *e, const boost::uuids::uuid &uuid, const VnEntry *vn, bool update=false)
Performs advertisement and deletion of routing routes (with VrfNH) in bridge VRF instances....
static void AddBgpaasInterfaceComponentToList(const std::string &vrf_name, const NhType &nh_item, ComponentNHKeyList &comp_nh_list, std::vector< std::string > &peer_sources)
static void CopyInterfacePathToEvpnTable(const AgentPath *path, const IpAddress &prefix_ip, const uint32_t plen, const Peer *peer, const RouteParameters &params, EvpnAgentRouteTable *evpn_table)
Copies the path to the prefix address into the EVPN table with the given Peer. The function is used d...
bool RouteNotify(DBTablePartBase *partition, DBEntryBase *e)
Handler for changes (new/update/delete) in a route (EVPN or Inet). Main entry point for routes leakin...
void VnNotify(DBTablePartBase *partition, DBEntryBase *e)
A handler for changes (new/update/delete) in a virtual network (VnEntry class).
static bool RoutePrefixIsEqualTo(const EvpnRouteEntry *route, const IpAddress &prefix_ip, const uint32_t prefix_len)
Determines whether route prefix in the EVPN route is equal to the given pair of prefix IP address and...
void XmppAdvertiseInetInterfaceOrComposite(InetUnicastAgentRouteTable *inet_table, const IpAddress &prefix_ip, const int prefix_len, const std::string vrf_name, const AgentPath *path)
Advertises in the Inet table an interface route that arrived via XMPP channel. Must be called only fr...
void HandleSubnetRoute(const VrfEntry *vrf, bool bridge_vrf=false)
Handles routing routes (with VrfNH) update in the routing VRF instance.
bool HasBgpPeerPath(EvpnRouteEntry *evpn_rt)
Determines whether the given EVPN route has at least one path originating from BGP/XMPP (has Peer typ...
static bool IsVxlanAvailable(const Agent *agent)
Checks whether VxLAN routing manager is enabled or not.
const VxlanRoutingVrfMapper & vrf_mapper() const
Returns the map between LR uuids and associated bridge and routing VRF instances.
friend class AgentXmppChannelVxlanInterface
Allows access to Xmpp advertisement functions via external class.
static bool is_ipv4_string(const std::string &prefix_str)
Determines whether the address string contains an IPv4 address as substring or not.
void ClearRedundantVrfPath(DBEntryBase *e)
Removes redundant VrfNH path from a given route. These routes might arise with small chance in a brid...
static uint32_t loc_sequence_
An always increasing counter for new paths (used to signal controoler about new routes).
void BridgeVnNotify(const VnEntry *vn, VxlanRoutingVnState *vn_state)
A handler for changes (new/update/delete) in the virtual network from a bridge VRF.
void VmiNotify(DBTablePartBase *partition, DBEntryBase *e)
Handler for changes (new/update/delete) in a VMI (VmInterface class).
void RoutingVnNotify(const VnEntry *vn, VxlanRoutingVnState *vn_state)
A handler for changes (new/update/delete) in the virtual network from a routing VRF.
static bool IsHostRoute(const IpAddress &prefix_ip, uint32_t prefix_len)
Determines whether the prefix address and the prefix length point to a host route (/32 for IPv4,...
DBTable::ListenerId vrf_listener_id_
An ID of the listener to changes in VrfTable.
static AgentRoute * FindEvpnOrInetRoute(const Agent *agent, const std::string &vrf_name, const IpAddress &ip_addr, uint32_t prefix_len, const autogen::EnetNextHopType &nh_item)
Finds a route with the given prefix address and len in the EVPN table.
static const AgentPath * FindPathWithGivenPeer(const AgentRoute *inet_rt, const Peer::Type peer_type)
Finds in the given route the path with a specified Peer type.
static AgentRoute * FindEvpnOrInetRoute(const Agent *agent, const std::string &vrf_name, const IpAddress &ip_addr, uint32_t prefix_len, const autogen::NextHopType &nh_item)
Finds a route with the given prefix address and len in the Inet table.
static std::string ipv6_prefix(const std::string &prefix_str)
Extracts an IPv6 address string from the prefix string.
bool EvpnRouteNotify(DBTablePartBase *partition, DBEntryBase *e)
Performs routes leaking between the EVPN table of the routing VRF instance and the Inet table of the ...
std::string GetOriginVn(const VrfEntry *routing_vrf, const IpAddress &ip_addr, const uint8_t &plen)
Finds first occurence of a route with the given prefix (IP address and length) in Inet tables of brid...
DBTable::ListenerId vn_listener_id() const
Returns the ID of the listener to changes in the VnTable.
static const AgentPath * FindInterfacePathWithLocalVmPeer(const AgentRoute *inet_rt, bool strict_match=true)
Finds in the given route the path which has the LOCAL_VM_PEER peer type and the Interface nexthop typ...
void XmppAdvertiseEvpnBgpaasInterface(EvpnAgentRouteTable *evpn_table, const IpAddress &prefix_ip, const int prefix_len, uint32_t vxlan_id, const std::string vrf_name, const RouteParameters &params, const Peer *bgp_peer, const NextHop *nh)
Advertises in an EVPN routing table a BGPaaS route with interface path that came from the controller ...
void UpdateSubnetRoute(const VrfEntry *vrf, const VrfEntry *routing_vrf)
Updates subnet routes (actually, paths with VrfNH) in the given bridge VRF.
DBTable::ListenerId vmi_listener_id() const
Returns the ID of the listener to changes in the InterfaceTable.
void XmppAdvertiseEvpnRoute(const IpAddress &prefix_ip, const int prefix_len, uint32_t vxlan_id, const std::string vrf_name, const RouteParameters &params, const Peer *bgp_peer, const std::vector< std::string > &peer_sources)
Advertises an EVPN route received using XMPP channel.
void XmppAdvertiseInetTunnel(InetUnicastAgentRouteTable *inet_table, const IpAddress &prefix_ip, const int prefix_len, uint32_t vxlan_id, const std::string vrf_name, const RouteParameters &params, const Peer *bgp_peer)
Advertises in the Inet table a tunnel route that arrived via XMPP channel. Must be called only from X...
DISALLOW_COPY_AND_ASSIGN(VxlanRoutingManager)
static uint32_t GetNewLocalSequence(const AgentPath *)
Auxilliary functions.
bool WithdrawEvpnRouteFromRoutingVrf(const VrfEntry *routing_vrf, DBTablePartBase *partition, DBEntryBase *e)
Deletes a given EVPN route from EVPN table of the routing VRF instance.
DBTable::ListenerId vrf_listener_id() const
Returns the ID of the listener to changes in the VrfTable.
static const Peer * routing_vrf_interface_peer_
Internal data of this class.
static bool IsBridgeVrf(const VrfEntry *vrf)
Determines whether the pointer to the VRF instance is of bridge type.
static bool HasVrfNexthop(const AgentRoute *rt)
Determines whether the given route has the path with a VRF nexthop (VrfNH)
bool IsLocalRoute(EvpnRouteEntry *routing_evpn_rt, VrfEntry *bridge_vrf)
Determines if the given EVPN route is already present in the given VRF.
void XmppAdvertiseEvpnTunnel(EvpnAgentRouteTable *inet_table, const IpAddress &prefix_ip, const int prefix_len, uint32_t vxlan_id, const std::string vrf_name, const RouteParameters &params, const Peer *bgp_peer)
Advertises in the EVPN table a tunnel route that arrived via XMPP channel. Must be called only from X...
void Shutdown()
Unregisters handlers for events associated with changes in virtual networks (VnTable class) and VRF i...
static const Peer * routing_vrf_vxlan_bgp_peer_
A pointer to the Peer where all BGP routes are stored.
void Register()
Registers handlers for events associated with changes in virtual networks (VnTable class) and VRF ins...
static std::vector< IpAddress > ItemNexthopsToVector(ItType *item)
Templates.
static const AgentPath * FindPathWithGivenPeerAndNexthop(const AgentRoute *inet_rt, const Peer::Type peer_type, const NextHop::Type nh_type, bool strict_match=true)
Finds in the given route the path with a specified Peer type and a specified nexthop type.
void WhenBridgeInetIntfWasDeleted(const InetUnicastRouteEntry *inet_rt, const VrfEntry *routing_vrf)
Handles deletion of a route in the EVPN table of the routing VRF instance.
void XmppAdvertiseEvpnBgpaasComposite(EvpnAgentRouteTable *evpn_table, const IpAddress &prefix_ip, const int prefix_len, uint32_t vxlan_id, const std::string vrf_name, const RouteParameters &params, const Peer *bgp_peer, ComponentNHKeyList &comp_nh_list)
Advertises in an EVPN routing table a BGPaaS route with interface composite path that came from the c...
static void PrintEvpnTable(const VrfEntry *const_vrf)
Prints EVPN table of the given VRF instance.
TunnelNHKey * AllocateTunnelNextHopKey(const IpAddress &dip, const MacAddress &dmac) const
XMPP Advertising functions.
bool IsHostRouteFromLocalSubnet(const EvpnRouteEntry *rt)
Determines whether the given EVPN route is a host one and belongs to a subnet of a local bridge VRF....
static bool IsRoutingVrf(const VrfEntry *vrf)
Determines whether the pointer to the VRF instance is of routing type.
static uint32_t ipv4_prefix_len(const std::string &prefix_str)
Extracts length of IPv4 subnet address from the prefix string.
static MacAddress NbComputeMac(const Ip4Address &compute_ip, const Agent *agent)
Returns the MAC address for the IP of a given neighbouring compute.
void VrfNotify(DBTablePartBase *partition, DBEntryBase *e)
A handler for changes (new/update/delete) in a VRF instance (VrfEntry class).
Agent * agent_
A pointer to the Agent instance.
void CopyPathToInetTable(const AgentPath *path, const IpAddress &prefix_ip, const uint32_t plen, const Peer *peer, const RouteParameters &params, InetUnicastAgentRouteTable *inet_table)
Copies the path to the prefix address into the EVPN table with the given Peer. The function is used d...
static const AgentPath * FindInterfacePathWithGivenPeer(const AgentRoute *inet_rt, const Peer::Type peer_type, bool strict_match=true)
Finds in the given route the path with the given Peer type and interface nexthop (InterfaceNH).
DBTable::ListenerId vn_listener_id_
An ID of the listener to changes in VnTable.
static VrfEntry * VnVrf(const VnEntry *vn, const std::string &vrf_name)
Finds a VRF table (VrfEntry) for the given virtual network (VN). Returns nullptr if no VRF table asso...
void DeleteSubnetRoute(const VrfEntry *vrf)
Deletes subnet routes (actually, paths with VrfNH) in the given bridge VRF. This function is demanded...
void XmppAdvertiseEvpnInterface(EvpnAgentRouteTable *inet_table, const IpAddress &prefix_ip, const int prefix_len, uint32_t vxlan_id, const std::string vrf_name, const RouteParameters &params, const Peer *bgp_peer, const std::vector< std::string > &peer_sources)
Advertises in the EVPN table an interface route that arrived via XMPP channel. Must be called only fr...
static void AddInterfaceComponentToList(const std::string &prefix_str, const std::string &vrf_name, const NhType &nh_item, ComponentNHKeyList &comp_nh_list, std::vector< std::string > &peer_sources)
Adds an interface or a composite of interfaces nexthops to the list of components NH keys needed for ...
AgentRouteWalkerPtr walker_
A pointer to the walker to loop over INET tables in bridge VRF instances.
void XmppAdvertiseEvpnBgpaas(EvpnAgentRouteTable *evpn_table, const IpAddress &prefix_ip, const int prefix_len, uint32_t vxlan_id, const std::string vrf_name, const RouteParameters &params, const Peer *bgp_peer, const std::vector< std::string > &peer_sources)
Advertises in an EVPN routing table a BGPaaS route that came from the controller (this routes leaking...
AgentRouteWalker * walker()
Returns a pointer to the AgentRouteWalkerPtr object.
bool IsVrfLocalRoute(EvpnRouteEntry *routing_evpn_rt, VrfEntry *bridge_vrf)
Determines if the given EVPN route has an interface NH or a composite of interfaces NH that belongs t...
VxlanRoutingManager(Agent *agent)
Constructs instance of the class and links to the Agent class instance. Since only one agent class in...
virtual ~VxlanRoutingManager()
Destroys the VxlanRoutingManager instance.
static const AgentPath * FindInterfacePathWithBgpPeer(const AgentRoute *inet_rt, bool strict_match=true)
Finds in the given route the path which has the BGP_PEER Peer type and the Interface nexthop type....
void XmppAdvertiseInetRoute(const IpAddress &prefix_ip, const int prefix_len, uint32_t vxlan_id, const std::string vrf_name, const RouteParameters &params, const Peer *bgp_peer)
Advertises an Inet route received using XMPP channel.
static bool is_ipv6_string(const std::string &prefix_str)
Determines whether the address string contains an IPv6 address as substring or not.
bool RemoveRoutesFromRoutingToBridgeVrf(DBTablePartBase *partition, DBEntryBase *e, const VnEntry *vn, std::string bridge_vrf_name)
Performs deletion of external routing routes (with VrfNH) in bridge VRF instances.
static std::string ipv4_prefix(const std::string &prefix_str)
Extracts an IPv4 address string from the prefix string.
static void PrintInetTable(const VrfEntry *const_vrf)
Prints IPv4 Inet table of the given VRF instance.
static uint32_t ipv6_prefix_len(const std::string &prefix_str)
Extracts length of IPv6 subnet address from the prefix string.
void RoutingVrfDeleteAllRoutes(VrfEntry *rt_vrf)
deletes all routes in EVPN table of routing VRF
bool InetRouteNotify(DBTablePartBase *partition, DBEntryBase *e)
Routes leaking functions.
VxlanRoutingVrfMapper vrf_mapper_
A map between LR uuids and associated bridge and routing VRF instances.
void FillSandeshInfo(VxlanRoutingResp *resp)
Updates Sandesh response.
DBTable::ListenerId vmi_listener_id_
An ID of the listener to changes in InterfaceTable.
static void DeleteOldInterfacePath(const IpAddress &prefix_ip, const uint32_t plen, const Peer *peer, EvpnAgentRouteTable *evpn_table)
Routes copying functions.
void WhenRoutingEvpnRouteWasDeleted(const EvpnRouteEntry *routing_evpn_rt, const Peer *delete_from_peer)
Handles deletion of a route in the Inet table of the routing VRF instance.
Listens to Inet routes in a bridge VRF instance. Started when l3vrf is added/deleted or when a bridge...
VxlanRoutingRouteWalker(const std::string &name, VxlanRoutingManager *mgr, Agent *agent)
Constructs a new instance using the given name, pointer to the VxlanRoutingManager and pointer to the...
VxlanRoutingManager * mgr_
A pointer to the VxlanRoutingManager instance.
DISALLOW_COPY_AND_ASSIGN(VxlanRoutingRouteWalker)
virtual ~VxlanRoutingRouteWalker()
Destructs an instance of VxlanRoutingRouteWalker.
virtual bool RouteWalkNotify(DBTablePartBase *partition, DBEntryBase *e)
Runs route leaking process when L3 VRF instance is added/deleted or when a bridge VRF is attached / d...
This class is a storage for operative state of VxLAN logical routers (LRs) defined via Config logical...
LrVrfInfoMap::iterator LrVrfInfoMapIter
A typedef for iterator of LrVrfInfoMap.
const VrfEntry * GetRoutingVrfUsingUuid(const boost::uuids::uuid &lr_uuid)
Find the routing VRF instance using a given LR UUID.
void WalkBridgeVrfs(const RoutedVrfInfo &routing_vrf_info)
Walks Inet tables of all bridge VRF instances connected to a LR (given in routing_vrf_info parameter)...
DISALLOW_COPY_AND_ASSIGN(VxlanRoutingVrfMapper)
InetTableWalker inet4_table_walker_
The set of walkers for Inet IPv4 tables of bridge VRF instances.
LrVrfInfoMap lr_vrf_info_map_
The map between Logical router UUID and RoutedVrfInfo.
void TryDeleteLogicalRouter(LrVrfInfoMapIter &it)
Attempts to delete the given LR.
std::map< const VnEntry *, boost::uuids::uuid > VnLrSet
A typedef to store map between pointer to VirtualNetwork (a bridge or routing virtual network connect...
const boost::uuids::uuid GetLogicalRouterUuidUsingRoute(const AgentRoute *rt)
Find the UUID of the LR using a given route (AgentRoute).
void BridgeInet6RouteWalkDone(DBTable::DBTableWalkRef walk_ref, DBTableBase *partition)
Handles completion of route walk in an Inet IPv6 table of a bridge VRF instance.
const VrfEntry * GetRoutingVrfUsingAgentRoute(const AgentRoute *rt)
Find the routing VRF instance using a given route (AgentRoute).
void WalkRoutingVrfRemoveExternalRoutes(const boost::uuids::uuid &lr_uuid, const VnEntry *vn, std::string bridge_vrf_name)
Walks the EVPN table of the routing VRF instance of a given LR to find and remove external routes fro...
const VrfEntry * GetRoutingVrfUsingVn(const VnEntry *vn)
Find the routing VRF instance using a given virtual network.
VnLrSet vn_lr_set_
The map between pointer to VirtualNetwork (a bridge or routing virtual network connected to some LR) ...
void RoutingVrfRouteWalkDone(DBTable::DBTableWalkRef walk_ref, DBTableBase *partition)
Handles completion of route walk in the EVPN table of a routing VRF instance.
InetTableWalker inet6_table_walker_
The set of walkers for Inet IPv6 tables of bridge VRF instances.
VxlanRoutingVrfMapper(VxlanRoutingManager *mgr)
Constructs a new instance of VxlanRoutingVrfMapper using the given pointer to VxlanRoutingManager.
void BridgeInet4RouteWalkDone(DBTable::DBTableWalkRef walk_ref, DBTableBase *partition)
Handles completion of route walk in the Inet IPv4 table of a bridge VRF instance.
std::map< boost::uuids::uuid, RoutedVrfInfo > LrVrfInfoMap
A typedef to store map between Logical router UUID and RoutedVrfInfo.
void WalkRoutingVrf(const boost::uuids::uuid &lr_uuid, const VnEntry *vn, bool update, bool withdraw)
Walks the EVPN table of the routing VRF instance of a given LR.
virtual ~VxlanRoutingVrfMapper()
Destroys an instance of VxlanRoutingVrfMapper().
VxlanRoutingManager * mgr_
A pointer to the VxlanRoutingManager instance.
void WalkBridgeInetTables(InetUnicastAgentRouteTable *inet4, InetUnicastAgentRouteTable *inet6)
Walks given Inet tables (IPv4 and IPv6).
std::map< const InetUnicastAgentRouteTable *, DBTable::DBTableWalkRef > InetTableWalker
A typedef for a storage of all walkers on Inet tables, if needed the walk can be restarted instead of...
VnLrSet::iterator VnLrSetIter
A typedef for iterator of VnLrSet.
bool IsEmpty() const
Determines whether object is empty or not.
std::vector< ComponentNHKeyPtr > ComponentNHKeyList
Definition: nexthop.h:1641
A structure to hold path parameters during the transfer (routes leaking) of data between VRF instance...
const EcmpLoadBalance & ecmp_load_balance_
A reference to EcmpLoadBalance of the path.
RouteParameters(const IpAddress &nh_addr, const MacAddress &mac, const VnListType &vns, const SecurityGroupList &sgs, const CommunityList &comms, const TagList &tags, const PathPreference &ppref, const EcmpLoadBalance &ecmp, uint64_t seq_n)
Constructs RouteParameters object from components.
const MacAddress & nh_mac_
A nexthop MAC address (usually it is a MAC of the router).
RouteParameters()
Disallow default constructor.
const IpAddress & nh_addr_
A nexthop IP address of the tunnel. Contains first IP address of nh_addresses_ in case of a composite...
const TagList & tag_list_
A list of tags.
RouteParameters(const RouteParameters &rp)
Copy constructor.
const PathPreference & path_preference_
A reference to the PathPreference of the path.
uint64_t sequence_number_
An ID of sequence.
const CommunityList & communities_
A list of communities.
const SecurityGroupList & sg_list_
A list of security groups.
const std::vector< IpAddress > nh_addresses_
A list of nexthops IP addreses of a composite tunnel.
const VnListType & vn_list_
A list of path destination virtual networks used in policy lookups.
This state tracks inet and EVPN table listeners. It establishes link between inet tables of a bridge ...
AgentRouteTable * inet6_table_
A pointer to the IPv6 Inet table of a bridge VRF instance.
AgentRouteTable * inet4_table_
A pointer to the IPv4 Inet table of a bridge VRF instance.
AgentRouteTable * evpn_table_
A pointer to the EVPN table of a routing VRF instance.
VxlanRoutingState(VxlanRoutingManager *mgr, VrfEntry *vrf)
Construct new instance using the given VxlanRoutingManager and VRF instance (VrfEntry).
DBTable::ListenerId inet4_id_
ID of a listener that tracks changes in the IPv4 Inet table of a bridge VRF instance.
virtual ~VxlanRoutingState()
Destroys an instance.
DBTable::ListenerId evpn_id_
ID of a listener that tracks changes in the EVPN table of a routing VRF instance.
DBTable::ListenerId inet6_id_
ID of a listener that tracks changes in the IPv6 Inet table of a bridge VRF instance.
Tracks movement of a VmInterface among LRs. This is used to associate VmInterface with a LR and a VN,...
VnEntryRef vn_entry_
Reference (smart pointer) to the virtual network (VirtualNetwork) to which VmInterface belongs to.
virtual ~VxlanRoutingVmiState()
Destroys an instance of VxlanRoutingVmiState.
boost::uuids::uuid logical_router_uuid_
UUID of the LR to which this VmInterface is connected.
VxlanRoutingVmiState()
Constructs new instance of VxlanRoutingVmiState.
This state tracks all virtual machine interfaces (VmInterface) attached to a Logical Router (LR)....
std::set< const VmInterface * > VmiList
A typedef for a set of pointers to VmInterface.
VrfEntryRef vrf_ref_
Holds a reference to a VrfEntry when VirtualNetwork's reference stored in VrfGet() is null.
bool is_routing_vn_
Returns true when state is associated with a routing VirtualNetwork.
boost::uuids::uuid logical_router_uuid() const
Returns the UUID of the Logical Router.
void AddVmi(const VnEntry *vn, const VmInterface *vmi)
Adds a VmInterface (LR port) to a Logical Router and connects the given VirtualNetwork (to which the ...
VxlanRoutingManager * mgr_
A pointer to the instance of VxlanRoutingManager.
VxlanRoutingVnState(VxlanRoutingManager *mgr)
Constructs new instance using VxlanRoutingManager.
void DeleteVmi(const VnEntry *vn, const VmInterface *vmi)
Deletes the VmInterface from set of connected interfaces and disconnects the given VirtualNetwork fro...
virtual ~VxlanRoutingVnState()
Destroys a VxlanRoutingVnState object.
VmiList::iterator VmiListIter
A typedef for the iterator of VxlanRoutingVnState::VmiList.
boost::uuids::uuid logical_router_uuid_
A UUID of the Logical Router.
std::set< const VmInterface * > vmi_list_
A list of VmInterface (router's ports) connected to a Logical Router (LR)
The structure holds information about virtual networks connected to a logical router (LR)
std::set< const VnEntry * > BridgeVnList
A typedef to store the list of bridge virtual networks connected to a LR.
BridgeVnList::iterator BridgeVnListIter
A type for iterator of the list of bridge virtual networks connected to a LR.
BridgeVnList bridge_vn_list_
The list of bridge virtual networks (VirtualNetwork) connected to a LR.
BridgeVrfNamesList bridge_vrf_names_list_
The list of bridge virtual networks (VirtualNetwork) names connected to a LR.
const VnEntry * routing_vn_
A pointer to the routing virtual network (VirtualNetwork) connected to a LR.
VrfEntry * routing_vrf_
A pointer to the routing VRF instance (L3 VRF) connected to a LR.
virtual ~RoutedVrfInfo()
Destroys an instance of RoutedVrfInfo.
RoutedVrfInfo()
Constructs an instance of RoutedVrfInfo.
std::map< const VnEntry *, std::string > BridgeVrfNamesList
A typedef to store the correspondence between bridge virtual network (VirtualNetwork) pointer and a n...
boost::uuids::uuid uuid