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()");
281 if (!inet4_table || !inet6_table)
307 return it->second.routing_vrf_;
314 using boost::uuids::nil_uuid;
328 if ((vn_state == NULL) || (vn_state->
vmi_list_.size() == 0)) {
338 if ((it->second.routing_vrf_ == NULL) &&
339 (it->second.bridge_vn_list_.size() == 0)) {
351 agent_(agent), walker_(), vn_listener_id_(),
352 vrf_listener_id_(), vmi_listener_id_(), vrf_mapper_(this) {
403 if (vn->
IsDeleted() && vn_state != NULL) {
443 using boost::uuids::nil_uuid;
450 while (it != vn_state->
vmi_list_.end()) {
452 if ((*it)->logical_router_uuid() != nil_uuid()) {
468 using boost::uuids::nil_uuid;
477 bool withdraw =
false;
506 routing_info_it->second.bridge_vn_list_.find(vn);
507 std::string vrf_name =
"";
508 if (routing_info_it->second.bridge_vrf_names_list_.count(vn) == 1) {
509 vrf_name = routing_info_it->second.bridge_vrf_names_list_.at(vn);
512 if (br_it != routing_info_it->second.bridge_vn_list_.end()) {
514 routing_info_it->second.bridge_vn_list_.erase(br_it);
515 routing_info_it->second.bridge_vrf_names_list_.erase(vn);
546 if (update || withdraw) {
549 GetInet4UnicastRouteTable());
552 GetInet6UnicastRouteTable());
553 if (inet4_table && inet6_table) {
561 if (rt_vrf ==
nullptr) {
568 if (evpn_table ==
nullptr) {
574 const std::string vrf_name = rt_vrf->
GetName();
575 const uint32_t ethernet_tag = 0;
577 while (c_entry !=
nullptr) {
581 const Peer *rt_active_peer =
nullptr;
583 if (rt_active_path !=
nullptr)
584 rt_active_peer = rt_active_path->
peer();
595 vrf_name, prefix_ip, plen,
598 vrf_name, prefix_ip, plen,
601 if ((rt_active_peer !=
nullptr) &&
612 for (
auto &path_ref : path_list) {
630 bool withdraw =
false;
656 if (routing_info_it->second.routing_vn_ == vn) {
658 routing_info_it->second.routing_vrf_);
661 routing_info_it->second.routing_vn_ =
nullptr;
662 routing_info_it->second.routing_vrf_ =
nullptr;
776 vn_state->
AddVmi(vn, vmi);
798 const std::string& vrf_name,
800 const uint32_t plen) {
801 if (vn == NULL || vrf_name == std::string(
""))
807 lr_it->second == boost::uuids::nil_uuid())
817 if (vn == bridge_vn_entry) {
822 if (it_vrf ==
nullptr) {
828 ipam_prefix, plen, NULL);
833 if (vn == NULL || vrf_name == std::string(
""))
835 std::vector<VnIpam> bridge_vn_ipam = vn->
GetVnIpam();
837 if (bridge_vn_ipam.size() == 0)
843 lr_it->second == boost::uuids::nil_uuid())
853 if (vn == bridge_vn_entry) {
857 for (
auto br_ipam : bridge_vn_ipam) {
859 if (it_vrf ==
nullptr) {
865 br_ipam.GetSubnetAddress(), br_ipam.plen, NULL);
868 std::vector<VnIpam> vn_ipam = bridge_vn_entry->GetVnIpam();
870 if (vn_ipam.size() == 0) {
873 for (
auto br_vn_ipam : vn_ipam) {
875 vrf_name, br_vn_ipam.GetSubnetAddress(),
876 br_vn_ipam.plen, NULL);
890 if (!bridge_vrf->
vn())
893 std::vector<VnIpam> bridge_vn_ipam = bridge_vrf->
vn()->
GetVnIpam();
895 if (bridge_vn_ipam.size() == 0)
902 lr_it->second == boost::uuids::nil_uuid())
914 if (bridge_vrf->
vn() == *it) {
919 for (std::vector<VnIpam>::iterator ipam_itr = bridge_vn_ipam.begin();
920 ipam_itr < bridge_vn_ipam.end(); ipam_itr++) {
925 if (it_vrf ==
nullptr) {
929 AddEvpnRoutingRoute(ipam_itr->ip_prefix, ipam_itr->plen, routing_vrf,
941 std::vector<VnIpam> vn_ipam = (*it)->GetVnIpam();
942 for (std::vector<VnIpam>::iterator vn_ipam_itr = vn_ipam.begin();
943 vn_ipam_itr != vn_ipam.end(); vn_ipam_itr++) {
949 AddEvpnRoutingRouteReq(vn_ipam_itr->ip_prefix, vn_ipam_itr->plen, routing_vrf,
970 std::vector<VxlanRoutingMap> vr_map;
972 VxlanRoutingMap vxlan_routing_map;
973 vxlan_routing_map.set_logical_router_uuid(
UuidToString(it1->first));
974 vxlan_routing_map.set_routing_vrf(it1->second.routing_vrf_->
976 vxlan_routing_map.set_parent_routing_vn(it1->second.routing_vn_->
979 it1->second.bridge_vn_list_.begin();
980 while (it2 != it1->second.bridge_vn_list_.end()) {
981 VxlanRoutingBridgeVrf bridge_vrf;
982 if ((*it2)->GetVrf()) {
983 bridge_vrf.set_bridge_vrf((*it2)->GetVrf()->GetName());
985 bridge_vrf.set_bridge_vn((*it2)->GetName());
986 vxlan_routing_map.bridge_vrfs.push_back(bridge_vrf);
989 vr_map.push_back(vxlan_routing_map);
992 resp->set_vr_map(vr_map);
995 void VxlanRoutingReq::HandleRequest()
const {
996 VxlanRoutingResp *resp =
new VxlanRoutingResp();
1000 if (vxlan_routing_mgr) {
1001 resp->set_context(context());
1004 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 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.
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. 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)