5 #include <boost/uuid/uuid_io.hpp>
29 std::string nm4 = std::string(
"vxlan_lstnr.") + inet4_table_->
name();
30 std::string nm6 = std::string(
"vxlan_lstnr.") + inet6_table_->name();
31 std::string nme = std::string(
"vxlan_lstnr.") + evpn_table_->name();
33 inet4_id_ = inet4_table_->
36 inet6_id_ = inet6_table_->
39 evpn_id_ = evpn_table_->
45 evpn_table_->Unregister(evpn_id_);
46 inet4_table_->Unregister(inet4_id_);
47 inet6_table_->Unregister(inet6_id_);
51 vmi_list_(), is_routing_vn_(false),
52 logical_router_uuid_(
boost::uuids::nil_uuid()), mgr_(mgr) {
60 LOG(ERROR,
"Error in VxlanRoutingManager::AddVmi"
61 <<
", vmi->logical_router_uuid() == boost::uuids::nil_uuid()");
86 vn_entry_(NULL), logical_router_uuid_(
boost::uuids::nil_uuid()) {
94 return boost::uuids::nil_uuid();
96 return (*(
vmi_list_.begin()))->logical_router_uuid();
125 mgr_(mgr), lr_vrf_info_map_(), vn_lr_set_(),
126 inet4_table_walker_(), inet6_table_walker_() {
140 walk_ref = inet4_table->
147 walk_ref = it->second;
158 walk_ref = inet6_table->
165 walk_ref = it->second;
174 const VnEntry *vn,
bool update,
bool withdraw) {
175 if (lr_uuid == boost::uuids::nil_uuid())
184 if (bridge_vrf && routing_vrf) {
192 walk_ref = evpn_table->
194 mgr_, routing_vrf, _1, _2),
208 walk_ref = evpn_table->
210 mgr_, _1, _2, lr_uuid, vn, update),
219 if (walk_ref.get() != NULL)
220 (
static_cast<DBTable *
>(partition))->ReleaseWalker(walk_ref);
229 LOG(ERROR,
"Error in VxlanRoutingManager::BridgeInet4RouteWalkDone"
230 <<
", it == inet4_table_walker_.end()");
242 LOG(ERROR,
"Error in VxlanRoutingManager::BridgeInet6RouteWalkDone"
243 <<
", it == inet6_table_walker_.end()");
266 if (!inet4_table || !inet6_table)
292 return it->second.routing_vrf_;
299 using boost::uuids::nil_uuid;
313 if ((vn_state == NULL) || (vn_state->
vmi_list_.size() == 0)) {
323 if ((it->second.routing_vrf_ == NULL) &&
324 (it->second.bridge_vn_list_.size() == 0)) {
336 agent_(agent), walker_(), vn_listener_id_(),
337 vrf_listener_id_(), vmi_listener_id_(), vrf_mapper_(this) {
388 if (vn->
IsDeleted() && vn_state != NULL) {
428 using boost::uuids::nil_uuid;
435 while (it != vn_state->
vmi_list_.end()) {
437 if ((*it)->logical_router_uuid() != nil_uuid()) {
453 using boost::uuids::nil_uuid;
462 bool withdraw =
false;
491 routing_info_it->second.bridge_vn_list_.find(vn);
492 std::string vrf_name =
"";
493 if (routing_info_it->second.bridge_vrf_names_list_.count(vn) == 1) {
494 vrf_name = routing_info_it->second.bridge_vrf_names_list_.at(vn);
497 if (br_it != routing_info_it->second.bridge_vn_list_.end()) {
499 routing_info_it->second.bridge_vn_list_.erase(br_it);
500 routing_info_it->second.bridge_vrf_names_list_.erase(vn);
528 if (update || withdraw) {
531 GetInet4UnicastRouteTable());
534 GetInet6UnicastRouteTable());
535 if (inet4_table && inet6_table) {
543 if (rt_vrf ==
nullptr) {
550 if (evpn_table ==
nullptr) {
556 const std::string vrf_name = rt_vrf->
GetName();
557 const uint32_t ethernet_tag = 0;
559 while (c_entry !=
nullptr) {
563 const Peer *rt_active_peer = rt_active_path->
peer();
575 vrf_name, prefix_ip, plen,
578 vrf_name, prefix_ip, plen,
591 for (
auto &path_ref : path_list) {
609 bool withdraw =
false;
635 if (routing_info_it->second.routing_vn_ == vn) {
637 routing_info_it->second.routing_vrf_);
640 routing_info_it->second.routing_vn_ =
nullptr;
641 routing_info_it->second.routing_vrf_ =
nullptr;
755 vn_state->
AddVmi(vn, vmi);
777 const std::string& vrf_name,
779 const uint32_t plen) {
780 if (vn == NULL || vrf_name == std::string(
""))
786 lr_it->second == boost::uuids::nil_uuid())
803 (*it)->GetVrf()->GetInetUnicastRouteTable(ipam_prefix)->
805 ipam_prefix, plen, NULL);
811 if (vn == NULL || vrf_name == std::string(
""))
813 std::vector<VnIpam> bridge_vn_ipam = vn->
GetVnIpam();
815 if (bridge_vn_ipam.size() == 0)
821 lr_it->second == boost::uuids::nil_uuid())
838 for (std::vector<VnIpam>::iterator ipam_itr = bridge_vn_ipam.begin();
839 ipam_itr < bridge_vn_ipam.end(); ipam_itr++) {
840 (*it)->GetVrf()->GetInetUnicastRouteTable(ipam_itr->ip_prefix)->
842 ipam_itr->GetSubnetAddress(), ipam_itr->plen, NULL);
844 std::vector<VnIpam> vn_ipam = (*it)->GetVnIpam();
846 if (vn_ipam.size() == 0) {
850 for (std::vector<VnIpam>::iterator vn_ipam_itr = vn_ipam.begin();
851 vn_ipam_itr < vn_ipam.end(); vn_ipam_itr++) {
853 vrf_name, vn_ipam_itr->GetSubnetAddress(),
854 vn_ipam_itr->plen, NULL);
869 if (!bridge_vrf->
vn())
872 std::vector<VnIpam> bridge_vn_ipam = bridge_vrf->
vn()->
GetVnIpam();
874 if (bridge_vn_ipam.size() == 0)
881 lr_it->second == boost::uuids::nil_uuid())
893 if (bridge_vrf->
vn() == *it) {
898 for (std::vector<VnIpam>::iterator ipam_itr = bridge_vn_ipam.begin();
899 ipam_itr < bridge_vn_ipam.end(); ipam_itr++) {
903 (*it)->GetVrf()->GetInetUnicastRouteTable(ipam_itr->ip_prefix)->
904 AddEvpnRoutingRoute(ipam_itr->ip_prefix, ipam_itr->plen, routing_vrf,
916 std::vector<VnIpam> vn_ipam = (*it)->GetVnIpam();
917 for (std::vector<VnIpam>::iterator vn_ipam_itr = vn_ipam.begin();
918 vn_ipam_itr != vn_ipam.end(); vn_ipam_itr++) {
924 AddEvpnRoutingRoute(vn_ipam_itr->ip_prefix, vn_ipam_itr->plen, routing_vrf,
945 std::vector<VxlanRoutingMap> vr_map;
947 VxlanRoutingMap vxlan_routing_map;
948 vxlan_routing_map.set_logical_router_uuid(
UuidToString(it1->first));
949 vxlan_routing_map.set_routing_vrf(it1->second.routing_vrf_->
951 vxlan_routing_map.set_parent_routing_vn(it1->second.routing_vn_->
954 it1->second.bridge_vn_list_.begin();
955 while (it2 != it1->second.bridge_vn_list_.end()) {
956 VxlanRoutingBridgeVrf bridge_vrf;
957 if ((*it2)->GetVrf()) {
958 bridge_vrf.set_bridge_vrf((*it2)->GetVrf()->GetName());
960 bridge_vrf.set_bridge_vn((*it2)->GetName());
961 vxlan_routing_map.bridge_vrfs.push_back(bridge_vrf);
964 vr_map.push_back(vxlan_routing_map);
967 resp->set_vr_map(vr_map);
970 void VxlanRoutingReq::HandleRequest()
const {
971 VxlanRoutingResp *resp =
new VxlanRoutingResp();
975 if (vxlan_routing_mgr) {
976 resp->set_context(context());
979 resp->set_more(
false);
boost::asio::ip::address IpAddress
std::vector< int > 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 std::string & GetName() 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 routes leaking between bridge VRF instances and the routing VRF instance....
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.
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.
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).
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. The state establishes link between Inet tables of a ...
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 amongth LRs. This is used to associate VmInterface with a LR and a V...
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)