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())
186 if (bridge_vrf && routing_vrf) {
191 walk_ref = inet4_table->
192 AllocWalker(boost::bind(
194 mgr_, routing_vrf, _1, _2),
200 walk_ref = inet6_table->
201 AllocWalker(boost::bind(
203 mgr_, routing_vrf, _1, _2),
219 walk_ref = evpn_table->
221 mgr_, _1, _2, lr_uuid, vn, update),
230 if (walk_ref.get() != NULL)
231 (
static_cast<DBTable *
>(partition))->ReleaseWalker(walk_ref);
240 LOG(ERROR,
"Error in VxlanRoutingManager::BridgeInet4RouteWalkDone"
241 <<
", it == inet4_table_walker_.end()");
253 LOG(ERROR,
"Error in VxlanRoutingManager::BridgeInet6RouteWalkDone"
254 <<
", it == inet6_table_walker_.end()");
277 if (!inet4_table || !inet6_table)
303 return it->second.routing_vrf_;
310 using boost::uuids::nil_uuid;
324 if ((vn_state == NULL) || (vn_state->
vmi_list_.size() == 0)) {
334 if ((it->second.routing_vrf_ == NULL) &&
335 (it->second.bridge_vn_list_.size() == 0)) {
347 agent_(agent), walker_(), vn_listener_id_(),
348 vrf_listener_id_(), vmi_listener_id_(), vrf_mapper_(this) {
399 if (vn->
IsDeleted() && vn_state != NULL) {
439 using boost::uuids::nil_uuid;
446 while (it != vn_state->
vmi_list_.end()) {
448 if ((*it)->logical_router_uuid() != nil_uuid()) {
464 using boost::uuids::nil_uuid;
473 bool withdraw =
false;
502 routing_info_it->second.bridge_vn_list_.find(vn);
503 std::string vrf_name =
"";
504 if (routing_info_it->second.bridge_vrf_names_list_.count(vn) == 1) {
505 vrf_name = routing_info_it->second.bridge_vrf_names_list_.at(vn);
508 if (br_it != routing_info_it->second.bridge_vn_list_.end()) {
510 routing_info_it->second.bridge_vn_list_.erase(br_it);
511 routing_info_it->second.bridge_vrf_names_list_.erase(vn);
539 if (update || withdraw) {
542 GetInet4UnicastRouteTable());
545 GetInet6UnicastRouteTable());
546 if (inet4_table && inet6_table) {
554 if (rt_vrf ==
nullptr) {
561 if (evpn_table ==
nullptr) {
567 const std::string vrf_name = rt_vrf->
GetName();
568 const uint32_t ethernet_tag = 0;
570 while (c_entry !=
nullptr) {
574 const Peer *rt_active_peer = rt_active_path->
peer();
586 vrf_name, prefix_ip, plen,
589 vrf_name, prefix_ip, plen,
602 for (
auto &path_ref : path_list) {
620 bool withdraw =
false;
646 if (routing_info_it->second.routing_vn_ == vn) {
648 routing_info_it->second.routing_vrf_);
651 routing_info_it->second.routing_vn_ =
nullptr;
652 routing_info_it->second.routing_vrf_ =
nullptr;
766 vn_state->
AddVmi(vn, vmi);
788 const std::string& vrf_name,
790 const uint32_t plen) {
791 if (vn == NULL || vrf_name == std::string(
""))
797 lr_it->second == boost::uuids::nil_uuid())
814 (*it)->GetVrf()->GetInetUnicastRouteTable(ipam_prefix)->
816 ipam_prefix, plen, NULL);
822 if (vn == NULL || vrf_name == std::string(
""))
824 std::vector<VnIpam> bridge_vn_ipam = vn->
GetVnIpam();
826 if (bridge_vn_ipam.size() == 0)
832 lr_it->second == boost::uuids::nil_uuid())
849 for (std::vector<VnIpam>::iterator ipam_itr = bridge_vn_ipam.begin();
850 ipam_itr < bridge_vn_ipam.end(); ipam_itr++) {
851 std::string it_vrf_name =
"";
854 if (it_vrf_name != std::string(
"")) {
856 it_vrf_name, ipam_itr->GetSubnetAddress(),
861 std::vector<VnIpam> vn_ipam = (*it)->GetVnIpam();
863 if (vn_ipam.size() == 0) {
867 for (std::vector<VnIpam>::iterator vn_ipam_itr = vn_ipam.begin();
868 vn_ipam_itr < vn_ipam.end(); vn_ipam_itr++) {
870 vrf_name, vn_ipam_itr->GetSubnetAddress(),
871 vn_ipam_itr->plen, NULL);
886 if (!bridge_vrf->
vn())
889 std::vector<VnIpam> bridge_vn_ipam = bridge_vrf->
vn()->
GetVnIpam();
891 if (bridge_vn_ipam.size() == 0)
898 lr_it->second == boost::uuids::nil_uuid())
910 if (bridge_vrf->
vn() == *it) {
915 for (std::vector<VnIpam>::iterator ipam_itr = bridge_vn_ipam.begin();
916 ipam_itr < bridge_vn_ipam.end(); ipam_itr++) {
920 (*it)->GetVrf()->GetInetUnicastRouteTable(ipam_itr->ip_prefix)->
921 AddEvpnRoutingRoute(ipam_itr->ip_prefix, ipam_itr->plen, routing_vrf,
933 std::vector<VnIpam> vn_ipam = (*it)->GetVnIpam();
934 for (std::vector<VnIpam>::iterator vn_ipam_itr = vn_ipam.begin();
935 vn_ipam_itr != vn_ipam.end(); vn_ipam_itr++) {
941 AddEvpnRoutingRouteReq(vn_ipam_itr->ip_prefix, vn_ipam_itr->plen, routing_vrf,
962 std::vector<VxlanRoutingMap> vr_map;
964 VxlanRoutingMap vxlan_routing_map;
965 vxlan_routing_map.set_logical_router_uuid(
UuidToString(it1->first));
966 vxlan_routing_map.set_routing_vrf(it1->second.routing_vrf_->
968 vxlan_routing_map.set_parent_routing_vn(it1->second.routing_vn_->
971 it1->second.bridge_vn_list_.begin();
972 while (it2 != it1->second.bridge_vn_list_.end()) {
973 VxlanRoutingBridgeVrf bridge_vrf;
974 if ((*it2)->GetVrf()) {
975 bridge_vrf.set_bridge_vrf((*it2)->GetVrf()->GetName());
977 bridge_vrf.set_bridge_vn((*it2)->GetName());
978 vxlan_routing_map.bridge_vrfs.push_back(bridge_vrf);
981 vr_map.push_back(vxlan_routing_map);
984 resp->set_vr_map(vr_map);
987 void VxlanRoutingReq::HandleRequest()
const {
988 VxlanRoutingResp *resp =
new VxlanRoutingResp();
992 if (vxlan_routing_mgr) {
993 resp->set_context(context());
996 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 Delete(const Peer *peer, const string &vrf_name, const IpAddress &addr, uint8_t plen)
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)