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)
268 WalkBridgeInetTables(inet4_table, inet6_table);
277 if (it != vn_lr_set_.end()) {
278 return GetRoutingVrfUsingUuid(it->second);
285 return GetRoutingVrfUsingUuid(GetLogicalRouterUuidUsingRoute(rt));
291 if (it != lr_vrf_info_map_.end()) {
299 using boost::uuids::nil_uuid;
312 GetAgentDBEntryState(mgr_->vn_listener_id()));
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) {
351 RegisterWalker(static_cast<AgentRouteWalker *>(
walker_.get()));
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 == NULL) {
550 if (evpn_table == NULL) {
556 const std::string vrf_name = rt_vrf->
GetName();
557 const uint32_t ethernet_tag = 0;
565 c_entry = dynamic_cast<EvpnRouteEntry *>
580 vrf_name, prefix_ip, plen, NULL);
592 vrf_name, prefix_ip, plen, NULL);
599 bool withdraw =
false;
625 if (routing_info_it->second.routing_vn_ == vn) {
629 routing_info_it->second.routing_vn_ = NULL;
630 routing_info_it->second.routing_vrf_ = NULL;
744 vn_state->
AddVmi(vn, vmi);
766 const std::string& vrf_name,
768 const uint32_t plen) {
769 if (vn == NULL || vrf_name == std::string(
""))
775 lr_it->second == boost::uuids::nil_uuid())
792 (*it)->GetVrf()->GetInetUnicastRouteTable(ipam_prefix)->
794 ipam_prefix, plen, NULL);
800 if (vn == NULL || vrf_name == std::string(
""))
802 std::vector<VnIpam> bridge_vn_ipam = vn->
GetVnIpam();
804 if (bridge_vn_ipam.size() == 0)
810 lr_it->second == boost::uuids::nil_uuid())
827 for (std::vector<VnIpam>::iterator ipam_itr = bridge_vn_ipam.begin();
828 ipam_itr < bridge_vn_ipam.end(); ipam_itr++) {
829 (*it)->GetVrf()->GetInetUnicastRouteTable(ipam_itr->ip_prefix)->
831 ipam_itr->GetSubnetAddress(), ipam_itr->plen, NULL);
833 std::vector<VnIpam> vn_ipam = (*it)->GetVnIpam();
835 if (vn_ipam.size() == 0) {
839 for (std::vector<VnIpam>::iterator vn_ipam_itr = vn_ipam.begin();
840 vn_ipam_itr < vn_ipam.end(); vn_ipam_itr++) {
842 vrf_name, vn_ipam_itr->GetSubnetAddress(),
843 vn_ipam_itr->plen, NULL);
858 if (!bridge_vrf->
vn())
861 std::vector<VnIpam> bridge_vn_ipam = bridge_vrf->
vn()->
GetVnIpam();
863 if (bridge_vn_ipam.size() == 0)
870 lr_it->second == boost::uuids::nil_uuid())
882 if (bridge_vrf->
vn() == *it) {
887 for (std::vector<VnIpam>::iterator ipam_itr = bridge_vn_ipam.begin();
888 ipam_itr < bridge_vn_ipam.end(); ipam_itr++) {
892 (*it)->GetVrf()->GetInetUnicastRouteTable(ipam_itr->ip_prefix)->
893 AddEvpnRoutingRoute(ipam_itr->ip_prefix, ipam_itr->plen, routing_vrf,
905 std::vector<VnIpam> vn_ipam = (*it)->GetVnIpam();
906 for (std::vector<VnIpam>::iterator vn_ipam_itr = vn_ipam.begin();
907 vn_ipam_itr != vn_ipam.end(); vn_ipam_itr++) {
913 AddEvpnRoutingRoute(vn_ipam_itr->ip_prefix, vn_ipam_itr->plen, routing_vrf,
934 std::vector<VxlanRoutingMap> vr_map;
936 VxlanRoutingMap vxlan_routing_map;
937 vxlan_routing_map.set_logical_router_uuid(
UuidToString(it1->first));
938 vxlan_routing_map.set_routing_vrf(it1->second.routing_vrf_->
940 vxlan_routing_map.set_parent_routing_vn(it1->second.routing_vn_->
943 it1->second.bridge_vn_list_.begin();
944 while (it2 != it1->second.bridge_vn_list_.end()) {
945 VxlanRoutingBridgeVrf bridge_vrf;
946 if ((*it2)->GetVrf()) {
947 bridge_vrf.set_bridge_vrf((*it2)->GetVrf()->GetName());
949 bridge_vrf.set_bridge_vn((*it2)->GetName());
950 vxlan_routing_map.bridge_vrfs.push_back(bridge_vrf);
953 vr_map.push_back(vxlan_routing_map);
956 resp->set_vr_map(vr_map);
959 void VxlanRoutingReq::HandleRequest()
const {
960 VxlanRoutingResp *resp =
new VxlanRoutingResp();
964 if (vxlan_routing_mgr) {
965 resp->set_context(context());
968 resp->set_more(
false);
const std::string & GetName() const
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 ...
void VrfNotify(DBTablePartBase *partition, DBEntryBase *e)
A handler for changes (new/update/delete) in a VRF instance (VrfEntry class).
VnEntry * GetNonConstVn() const
virtual ~VxlanRoutingManager()
Destroys the VxlanRoutingManager instance.
const Peer * local_vm_export_peer() const
static Agent * GetInstance()
VxlanRoutingVnState(VxlanRoutingManager *mgr)
Constructs new instance using VxlanRoutingManager.
virtual DBEntryBase * GetFirst()=0
AgentRouteTable * GetEvpnRouteTable() const
VxlanRoutingVmiState()
Constructs new instance of VxlanRoutingVmiState.
DBTable::ListenerId vrf_listener_id_
An ID of the listener to changes in VrfTable.
std::set< const VmInterface * > vmi_list_
A list of VmInterface (router's ports) connected to a Logical Router (LR)
LrVrfInfoMap::iterator LrVrfInfoMapIter
A typedef for iterator of LrVrfInfoMap.
void set_lr_vrf(const VrfEntry *vrf)
BridgeVnList bridge_vn_list_
The list of bridge virtual networks (VirtualNetwork) connected to a LR.
void RoutingVrfRouteWalkDone(DBTable::DBTableWalkRef walk_ref, DBTableBase *partition)
Handles completion of route walk in the EVPN table of a routing VRF instance.
VmInterface::DeviceType device_type() const
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...
void SetState(DBTableBase *tbl_base, ListenerId listener, DBState *state)
void DeleteVmi(const VnEntry *vn, const VmInterface *vmi)
Deletes the VmInterface from set of connected interfaces and disconnects the given VirtualNetwork fro...
boost::asio::ip::address IpAddress
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)
const Peer * vxlan_bgp_peer() const
std::vector< int > SecurityGroupList
std::unique_ptr< DBRequestData > data
InetUnicastAgentRouteTable * GetInet4UnicastRouteTable() const
void HandleSubnetRoute(const VrfEntry *vrf, bool bridge_vrf=false)
Handles routing routes (with VrfNH) update in the routing VRF instance.
bool WithdrawEvpnRouteFromRoutingVrf(const VrfEntry *routing_vrf, DBTablePartBase *partition, DBEntryBase *e)
Deletes a given EVPN route from EVPN table of the routing VRF instance.
const boost::uuids::uuid GetLogicalRouterUuidUsingRoute(const AgentRoute *rt)
Find the UUID of the LR using a given route (AgentRoute).
InterfaceTable * interface_table() const
VnTable * vn_table() const
virtual DBEntryBase * GetNext(const DBEntryBase *)=0
const VrfEntry * GetRoutingVrfUsingAgentRoute(const AgentRoute *rt)
Find the routing VRF instance using a given route (AgentRoute).
InetUnicastAgentRouteTable * GetInet6UnicastRouteTable() const
const string & GetName() const
static std::string UuidToString(const boost::uuids::uuid &id)
InetTableWalker inet6_table_walker_
The set of walkers for Inet IPv6 tables of bridge VRF instances.
const VrfEntry * GetRoutingVrfUsingUuid(const boost::uuids::uuid &lr_uuid)
Find the routing VRF instance using a given LR UUID.
const boost::uuids::uuid & logical_router_uuid() const
VxlanRoutingManager * vxlan_routing_manager() const
Base class for all Route entries in agent.
const VrfEntry * GetRoutingVrfUsingVn(const VnEntry *vn)
Find the routing VRF instance using a given virtual network.
void UpdateSubnetRoute(const VrfEntry *vrf, const VrfEntry *routing_vrf)
Updates subnet routes (actually, paths with VrfNH) in the given bridge VRF.
VrfEntryRef vrf_ref_
Holds a reference to a VrfEntry when VirtualNetwork's reference stored in VrfGet() is null...
void Unregister(ListenerId listener)
const VnEntry * routing_vn_
A pointer to the routing virtual network (VirtualNetwork) connected to a LR.
const VrfEntry * routing_vrf_
A pointer to the routing VRF instance (L3 VRF) connected to a LR.
VnEntryRef vn_entry_
Reference (smart pointer) to the virtual network (VirtualNetwork) to which VmInterface belongs to...
VxlanRoutingManager * mgr_
A pointer to the VxlanRoutingManager instance.
DBTable::ListenerId vmi_listener_id_
An ID of the listener to changes in InterfaceTable.
DBState * GetAgentDBEntryState(int listener_id)
ListenerId Register(ChangeCallback callback, const std::string &name="unspecified")
const std::string & fabric_vrf_name() const
This class manages routes leaking between bridge VRF instances and the routing VRF instance...
void WalkAgain(DBTableWalkRef walk)
VrfEntry * vrf_entry() const
Agent * agent_
A pointer to the Agent instance.
VxlanRoutingManager * mgr_
A pointer to the instance of VxlanRoutingManager.
static bool IsRoutingVrf(const VrfEntry *vrf)
Determines whether the pointer to the VRF instance is of routing type.
VnLrSet vn_lr_set_
The map between pointer to VirtualNetwork (a bridge or routing virtual network connected to some LR) ...
VmiList::iterator VmiListIter
A typedef for the iterator of VxlanRoutingVnState::VmiList.
virtual ~VxlanRoutingRouteWalker()
Destructs an instance of VxlanRoutingRouteWalker.
AgentRouteWalkerManager * agent_route_walk_manager() const
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...
bool RouteNotify(DBTablePartBase *partition, DBEntryBase *e)
Handler for changes (new/update/delete) in a route (EVPN or Inet). Main entry point for routes leakin...
InetUnicastAgentRouteTable * GetInetUnicastRouteTable(const IpAddress &addr) const
std::unique_ptr< DBRequestKey > key
bool vxlan_routing_vn() const
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 ~VxlanRoutingVmiState()
Destroys an instance of VxlanRoutingVmiState.
void VnNotify(DBTablePartBase *partition, DBEntryBase *e)
A handler for changes (new/update/delete) in a virtual network (VnEntry class).
virtual ~VxlanRoutingState()
Destroys an instance.
boost::uuids::uuid logical_router_uuid_
UUID of the LR to which this VmInterface is connected.
const std::vector< VnIpam > & GetVnIpam() const
boost::uuids::uuid logical_router_uuid() const
Returns the UUID of the Logical Router.
const std::string & name() const
std::vector< std::string > CommunityList
void FillSandeshInfo(VxlanRoutingResp *resp)
Updates Sandesh response.
void Register()
Registers handlers for events associated with changes in virtual networks (VnTable class) and VRF ins...
std::set< std::string > VnListType
static void DeleteReq(const Peer *peer, const string &vrf_name, const IpAddress &addr, uint8_t plen, AgentRouteData *data)
void ClearState(DBTableBase *tbl_base, ListenerId listener)
void BridgeInet6RouteWalkDone(DBTable::DBTableWalkRef walk_ref, DBTableBase *partition)
Handles completion of route walk in an Inet IPv6 table of a bridge VRF instance.
Tracks movement of a VmInterface amongth LRs. This is used to associate VmInterface with a LR and a V...
virtual const PrefixType & prefix_address() const
Returns the value of a stored prefix address (IPv4, IPv6 or MAC address)
VxlanRoutingManager(Agent *agent)
Constructs instance of the class and links to the Agent class instance. Since only one agent class in...
VrfTable * vrf_table() const
virtual DBTablePartBase * GetTablePartition(const DBRequestKey *key)
void WalkBridgeInetTables(InetUnicastAgentRouteTable *inet4, InetUnicastAgentRouteTable *inet6)
Walks given Inet tables (IPv4 and IPv6).
void TryDeleteLogicalRouter(LrVrfInfoMapIter &it)
Attempts to delete the given LR.
BridgeVrfNamesList bridge_vrf_names_list_
The list of bridge virtual networks (VirtualNetwork) names connected to a LR.
const boost::uuids::uuid & logical_router_uuid() const
VrfEntry * GetVrf() const
uint8_t prefix_length() const
!
void BridgeInet4RouteWalkDone(DBTable::DBTableWalkRef walk_ref, DBTableBase *partition)
Handles completion of route walk in the Inet IPv4 table of a bridge VRF instance. ...
VmInterface::VmiType vmi_type() const
uint32_t vxlan_id() const
VxlanRoutingVrfMapper vrf_mapper_
A map between LR uuids and associated bridge and routing VRF instances.
void UpdateLogicalRouterUuid(const VnEntry *vn, VxlanRoutingVnState *vn_state)
#define LOG(_Level, _Msg)
bool InetRouteNotify(DBTablePartBase *partition, DBEntryBase *e)
Routes leaking functions.
This state tracks all virtual machine interfaces (VmInterface) attached to a Logical Router (LR)...
The structure holds information about virtual networks connected to a logical router (LR) ...
VxlanRoutingVrfMapper(VxlanRoutingManager *mgr)
Constructs a new instance of VxlanRoutingVrfMapper using the given pointer to VxlanRoutingManager.
This state tracks inet and evpn table listeners. The state establishes link between Inet tables of a ...
void Shutdown()
Unregisters handlers for events associated with changes in virtual networks (VnTable class) and VRF i...
DBTablePartBase * get_table_partition() const
virtual ~VxlanRoutingVrfMapper()
Destroys an instance of VxlanRoutingVrfMapper().
boost::intrusive_ptr< DBTableWalk > DBTableWalkRef
BridgeVnList::iterator BridgeVnListIter
A type for iterator of the list of bridge virtual networks connected to a LR.
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.
LrVrfInfoMap lr_vrf_info_map_
The map between Logical router UUID and RoutedVrfInfo.
void VmiNotify(DBTablePartBase *partition, DBEntryBase *e)
Handler for changes (new/update/delete) in a VMI (VmInterface class).
InetTableWalker inet4_table_walker_
The set of walkers for Inet IPv4 tables of bridge VRF instances.
bool is_routing_vn_
Returns true when state is associated with a routing VirtualNetwork.
static const Peer * routing_vrf_interface_peer_
Internal data of this class.
void RoutingVrfDeleteAllRoutes(VrfEntry *rt_vrf)
deletes all routes in EVPN table of routing VRF
void DeleteSubnetRoute(const VrfEntry *vrf)
Deletes subnet routes (actually, paths with VrfNH) in the given bridge VRF. This function is demanded...
friend class VxlanRoutingRouteWalker
Friends declarations.
VxlanRoutingManager * mgr_
A pointer to the VxlanRoutingManager instance.
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. External tunnels and routes with a prefix that is not present in bridge VRF instance are selected for leaking.
AgentRouteWalkerPtr walker_
A pointer to the walker to loop over INET tables in bridge VRF instances.
virtual ~VxlanRoutingVnState()
Destroys a VxlanRoutingVnState object.
void RoutingVnNotify(const VnEntry *vn, VxlanRoutingVnState *vn_state)
A handler for changes (new/update/delete) in the virtual network from a routing VRF.
static const Peer * routing_vrf_vxlan_bgp_peer_
A pointer to the Peer where all BGP routes are stored.
DBTable::ListenerId vn_listener_id_
An ID of the listener to changes in VnTable.
void BridgeVnNotify(const VnEntry *vn, VxlanRoutingVnState *vn_state)
A handler for changes (new/update/delete) in the virtual network from a bridge VRF.
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)...
boost::uuids::uuid logical_router_uuid_
A UUID of the Logical Router.
void set_routing_vrf(bool val)
const Peer * evpn_routing_peer() const
std::vector< int > TagList
VnLrSet::iterator VnLrSetIter
A typedef for iterator of VnLrSet.
VxlanRoutingState(VxlanRoutingManager *mgr, VrfEntry *vrf)
Construct new instance using the given VxlanRoutingManager and VRF instance (VrfEntry).
const std::string & fabric_policy_vrf_name() const