7 #include <boost/uuid/uuid_io.hpp>
31 std::string nm4 = std::string(
"vxlan_lstnr.") + inet4_table_->
name();
32 std::string nm6 = std::string(
"vxlan_lstnr.") + inet6_table_->name();
33 std::string nme = std::string(
"vxlan_lstnr.") + evpn_table_->name();
35 inet4_id_ = inet4_table_->
38 inet6_id_ = inet6_table_->
41 evpn_id_ = evpn_table_->
47 evpn_table_->Unregister(evpn_id_);
48 inet4_table_->Unregister(inet4_id_);
49 inet6_table_->Unregister(inet6_id_);
53 vmi_list_(), is_routing_vn_(false),
54 logical_router_uuid_(
boost::uuids::nil_uuid()), mgr_(mgr) {
62 LOG(ERROR,
"Error in VxlanRoutingManager::AddVmi"
63 <<
", vmi->logical_router_uuid() == boost::uuids::nil_uuid()");
88 vn_entry_(NULL), logical_router_uuid_(
boost::uuids::nil_uuid()) {
96 return boost::uuids::nil_uuid();
98 return (*(
vmi_list_.begin()))->logical_router_uuid();
127 mgr_(mgr), lr_vrf_info_map_(), vn_lr_set_(),
128 inet4_table_walker_(), inet6_table_walker_() {
142 walk_ref = inet4_table->
149 walk_ref = it->second;
160 walk_ref = inet6_table->
167 walk_ref = it->second;
176 const VnEntry *vn,
bool update,
bool withdraw) {
177 if (lr_uuid == boost::uuids::nil_uuid())
189 if (bridge_vrf && routing_vrf) {
194 walk_ref = inet4_table->
195 AllocWalker(boost::bind(
197 mgr_, routing_vrf, _1, _2),
203 walk_ref = inet6_table->
204 AllocWalker(boost::bind(
206 mgr_, routing_vrf, _1, _2),
222 walk_ref = evpn_table->
224 mgr_, _1, _2, lr_uuid, vn, update),
233 if (walk_ref.get() != NULL)
234 (
static_cast<DBTable *
>(partition))->ReleaseWalker(walk_ref);
243 LOG(ERROR,
"Error in VxlanRoutingManager::BridgeInet4RouteWalkDone"
244 <<
", it == inet4_table_walker_.end()");
256 LOG(ERROR,
"Error in VxlanRoutingManager::BridgeInet6RouteWalkDone"
257 <<
", it == inet6_table_walker_.end()");
266 std::string bridge_vrf_name) {
267 if (lr_uuid == boost::uuids::nil_uuid())
275 if (routing_vrf !=
nullptr) {
280 if (evpn_table ==
nullptr) {
284 walk_ref = evpn_table->
285 AllocWalker(boost::bind(
287 mgr_, _1, _2, vn, bridge_vrf_name),
310 if (!inet4_table || !inet6_table)
336 return it->second.routing_vrf_;
343 using boost::uuids::nil_uuid;
357 if ((vn_state == NULL) || (vn_state->
vmi_list_.size() == 0)) {
367 if ((it->second.routing_vrf_ == NULL) &&
368 (it->second.bridge_vn_list_.size() == 0)) {
380 agent_(agent), walker_(), vn_listener_id_(),
381 vrf_listener_id_(), vmi_listener_id_(), vrf_mapper_(this) {
432 if (vn->
IsDeleted() && vn_state != NULL) {
472 using boost::uuids::nil_uuid;
479 while (it != vn_state->
vmi_list_.end()) {
481 if ((*it)->logical_router_uuid() != nil_uuid()) {
497 using boost::uuids::nil_uuid;
507 bool withdraw =
false;
512 if (vn->
IsDeleted() || (vn_vrf ==
nullptr)) {
536 routing_info_it->second.bridge_vn_list_.find(vn);
537 std::string vrf_name =
"";
538 if (routing_info_it->second.bridge_vrf_names_list_.count(vn) == 1) {
539 vrf_name = routing_info_it->second.bridge_vrf_names_list_.at(vn);
542 if (br_it != routing_info_it->second.bridge_vn_list_.end()) {
544 routing_info_it->second.bridge_vn_list_.erase(br_it);
545 routing_info_it->second.bridge_vrf_names_list_.erase(vn);
578 if (update || withdraw) {
581 GetInet4UnicastRouteTable());
584 GetInet6UnicastRouteTable());
585 if (inet4_table && inet6_table) {
593 if (rt_vrf ==
nullptr) {
600 if (evpn_table ==
nullptr) {
606 const std::string vrf_name = rt_vrf->
GetName();
607 const uint32_t ethernet_tag = 0;
609 while (c_entry !=
nullptr) {
613 const Peer *rt_active_peer =
nullptr;
615 if (rt_active_path !=
nullptr)
616 rt_active_peer = rt_active_path->
peer();
627 vrf_name, prefix_ip, plen,
630 vrf_name, prefix_ip, plen,
633 if ((rt_active_peer !=
nullptr) &&
644 for (
auto &path_ref : path_list) {
662 bool withdraw =
false;
688 if (routing_info_it->second.routing_vn_ == vn) {
690 routing_info_it->second.routing_vrf_);
693 routing_info_it->second.routing_vn_ =
nullptr;
694 routing_info_it->second.routing_vrf_ =
nullptr;
808 vn_state->
AddVmi(vn, vmi);
830 const std::string& vrf_name,
832 const uint32_t plen) {
833 if (vn == NULL || vrf_name == std::string(
""))
839 lr_it->second == boost::uuids::nil_uuid())
849 if (vn == bridge_vn_entry) {
854 if (it_vrf ==
nullptr) {
860 ipam_prefix, plen, NULL);
865 if (vn == NULL || vrf_name == std::string(
""))
867 std::vector<VnIpam> bridge_vn_ipam = vn->
GetVnIpam();
869 if (bridge_vn_ipam.size() == 0)
875 lr_it->second == boost::uuids::nil_uuid())
885 if (vn == bridge_vn_entry) {
889 for (
auto br_ipam : bridge_vn_ipam) {
891 if (it_vrf ==
nullptr) {
897 br_ipam.GetSubnetAddress(), br_ipam.plen, NULL);
900 std::vector<VnIpam> vn_ipam = bridge_vn_entry->GetVnIpam();
902 if (vn_ipam.size() == 0) {
905 for (
auto br_vn_ipam : vn_ipam) {
907 vrf_name, br_vn_ipam.GetSubnetAddress(),
908 br_vn_ipam.plen, NULL);
922 if (!bridge_vrf->
vn())
925 std::vector<VnIpam> bridge_vn_ipam = bridge_vrf->
vn()->
GetVnIpam();
927 if (bridge_vn_ipam.size() == 0)
934 lr_it->second == boost::uuids::nil_uuid())
946 if (bridge_vrf->
vn() == *it) {
951 for (std::vector<VnIpam>::iterator ipam_itr = bridge_vn_ipam.begin();
952 ipam_itr < bridge_vn_ipam.end(); ipam_itr++) {
957 if (it_vrf ==
nullptr) {
961 AddEvpnRoutingRouteReq(ipam_itr->ip_prefix, ipam_itr->plen, routing_vrf,
973 std::vector<VnIpam> vn_ipam = (*it)->GetVnIpam();
974 for (std::vector<VnIpam>::iterator vn_ipam_itr = vn_ipam.begin();
975 vn_ipam_itr != vn_ipam.end(); vn_ipam_itr++) {
981 AddEvpnRoutingRouteReq(vn_ipam_itr->ip_prefix, vn_ipam_itr->plen, routing_vrf,
1002 std::vector<VxlanRoutingMap> vr_map;
1004 VxlanRoutingMap vxlan_routing_map;
1005 vxlan_routing_map.set_logical_router_uuid(
UuidToString(it1->first));
1006 vxlan_routing_map.set_routing_vrf(it1->second.routing_vrf_->
1008 vxlan_routing_map.set_parent_routing_vn(it1->second.routing_vn_->
1011 it1->second.bridge_vn_list_.begin();
1012 while (it2 != it1->second.bridge_vn_list_.end()) {
1013 VxlanRoutingBridgeVrf bridge_vrf;
1014 if ((*it2)->GetVrf()) {
1015 bridge_vrf.set_bridge_vrf((*it2)->GetVrf()->GetName());
1017 bridge_vrf.set_bridge_vn((*it2)->GetName());
1018 vxlan_routing_map.bridge_vrfs.push_back(bridge_vrf);
1021 vr_map.push_back(vxlan_routing_map);
1024 resp->set_vr_map(vr_map);
1027 void VxlanRoutingReq::HandleRequest()
const {
1028 VxlanRoutingResp *resp =
new VxlanRoutingResp();
1032 if (vxlan_routing_mgr) {
1033 resp->set_context(context());
1036 resp->set_more(
false);
boost::asio::ip::address IpAddress
std::vector< uint64_t > TagList
std::vector< int > SecurityGroupList
std::set< std::string > VnListType
std::vector< std::string > CommunityList
DBState * GetAgentDBEntryState(int listener_id)
const Peer * peer() const
virtual const PrefixType & prefix_address() const
Returns the value of a stored prefix address (IPv4, IPv6 or MAC address)
VrfEntry * vrf_entry() const
Base class for all Route entries in agent.
const AgentPath * GetActivePath() const
InterfaceTable * interface_table() const
const std::string & fabric_policy_vrf_name() const
VrfTable * vrf_table() const
const Peer * local_vm_export_peer() const
const Peer * vxlan_bgp_peer() const
const Peer * evpn_routing_peer() const
VnTable * vn_table() const
static Agent * GetInstance()
const std::string & fabric_vrf_name() const
void ClearState(DBTableBase *tbl_base, ListenerId listener)
DBTablePartBase * get_table_partition() const
void SetState(DBTableBase *tbl_base, ListenerId listener, DBState *state)
ListenerId Register(ChangeCallback callback, const std::string &name="unspecified")
void Unregister(ListenerId listener)
const std::string & name() const
virtual DBEntryBase * GetNext(const DBEntryBase *)=0
virtual DBEntryBase * GetFirst()=0
void WalkAgain(DBTableWalkRef walk)
virtual DBTablePartBase * GetTablePartition(const DBRequestKey *key)
boost::intrusive_ptr< DBTableWalk > DBTableWalkRef
static void DeleteReq(const Peer *peer, const std::string &vrf_name, const MacAddress &mac, const IpAddress &ip_addr, uint32_t plen, uint32_t ethernet_tag, AgentRouteData *data)
uint8_t prefix_length() const
!
static void DeleteReq(const Peer *peer, const string &vrf_name, const IpAddress &addr, uint8_t plen, AgentRouteData *data)
const boost::uuids::uuid & logical_router_uuid() const
VxlanRoutingManager * vxlan_routing_manager() const
AgentRouteWalkerManager * agent_route_walk_manager() const
const Type GetType() const
const PathList & GetPathList() const
VmInterface::VmiType vmi_type() const
VnEntry * GetNonConstVn() const
VmInterface::DeviceType device_type() const
void set_lr_vrf(const VrfEntry *vrf)
const std::vector< VnIpam > & GetVnIpam() const
VrfEntry * GetVrf() const
const boost::uuids::uuid & logical_router_uuid() const
bool vxlan_routing_vn() const
const string & GetName() const
void set_routing_vrf(bool val)
InetUnicastAgentRouteTable * GetInet4UnicastRouteTable() const
InetUnicastAgentRouteTable * GetInet6UnicastRouteTable() const
InetUnicastAgentRouteTable * GetInetUnicastRouteTable(const IpAddress &addr) const
AgentRouteTable * GetEvpnRouteTable() const
uint32_t vxlan_id() const
This class manages an operative state of VxLAN logical routers (LR) defined via Config logical-router...
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....
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).
void HandleSubnetRoute(const VrfEntry *vrf, bool bridge_vrf=false)
Handles routing routes (with VrfNH) update in the routing VRF instance.
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.
DBTable::ListenerId vrf_listener_id_
An ID of the listener to changes in VrfTable.
DBTable::ListenerId vn_listener_id() const
Returns the ID of the listener to changes in the VnTable.
void UpdateSubnetRoute(const VrfEntry *vrf, const VrfEntry *routing_vrf)
Updates subnet routes (actually, paths with VrfNH) in the given bridge VRF.
bool WithdrawEvpnRouteFromRoutingVrf(const VrfEntry *routing_vrf, DBTablePartBase *partition, DBEntryBase *e)
Deletes a given EVPN route from EVPN table of the routing VRF instance.
static const Peer * routing_vrf_interface_peer_
Internal data of this class.
void Shutdown()
Unregisters handlers for events associated with changes in virtual networks (VnTable class) and VRF i...
friend class VxlanRoutingRouteWalker
Friends declarations.
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 bool IsRoutingVrf(const VrfEntry *vrf)
Determines whether the pointer to the VRF instance is of routing type.
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.
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...
AgentRouteWalkerPtr walker_
A pointer to the walker to loop over INET tables in bridge VRF instances.
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.
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.
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.
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.
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...
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)...
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.
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.
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).
VnLrSet::iterator VnLrSetIter
A typedef for iterator of VnLrSet.
#define LOG(_Level, _Msg)
static std::string UuidToString(const boost::uuids::uuid &id)
std::unique_ptr< DBRequestKey > key
std::unique_ptr< DBRequestData > data
This state tracks inet and EVPN table listeners. It establishes link between inet tables of a bridge ...
VxlanRoutingState(VxlanRoutingManager *mgr, VrfEntry *vrf)
Construct new instance using the given VxlanRoutingManager and VRF instance (VrfEntry).
virtual ~VxlanRoutingState()
Destroys an 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)....
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)
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.
void UpdateLogicalRouterUuid(const VnEntry *vn, VxlanRoutingVnState *vn_state)