4 #include <xmpp_enet_types.h>
5 #include <xmpp_unicast_types.h>
26 for (uint32_t i=0; i < comp_nh_count; i++) {
30 if (c_nh->
GetType() == nh_type &&
35 if (c_nh->
GetType() != nh_type &&
49 tbb::mutex::scoped_lock lock(
mutex_);
59 return (prefix_str.find(
".") != std::string::npos);
63 return (prefix_str.find(
":") != std::string::npos) &&
68 const std::string::size_type slash_pos = prefix_str.rfind(
"/");
69 if (slash_pos == std::string::npos) {
72 const std::string len_str = prefix_str.substr(slash_pos + 1);
73 uint32_t prefix_len = 0;
74 std::istringstream(len_str) >> prefix_len;
75 return std::min(uint32_t(32), prefix_len);
79 std::string::size_type first_dot_pos = 0;
80 std::string::size_type last_colon_pos =
81 prefix_str.rfind(
":");
82 std::string::size_type slash_pos = prefix_str.rfind(
"/");
83 std::string ip_str =
"0.0.0.0";
84 if ((first_dot_pos = prefix_str.find(
".")) != std::string::npos) {
85 if (first_dot_pos - last_colon_pos >= 2 &&
86 first_dot_pos - last_colon_pos <= 4) {
87 ip_str = prefix_str.substr(last_colon_pos + 1);
89 if (last_colon_pos == string::npos) {
92 if (slash_pos != string::npos) {
93 ip_str = ip_str.substr(0, slash_pos);
100 const std::string::size_type slash_pos = prefix_str.rfind(
"/");
101 if (slash_pos == std::string::npos) {
104 const std::string len_str = prefix_str.substr(slash_pos + 1);
105 uint32_t prefix_len = 0;
106 std::istringstream(len_str) >> prefix_len;
107 return std::min(uint32_t(128), prefix_len);
111 const std::string zero_mac_str =
"00:00:00:00:00:00";
112 const std::string::size_type mac_pos = prefix_str.find(zero_mac_str);
113 std::string ip_str = prefix_str;
115 if (mac_pos != std::string::npos) {
116 ip_str = prefix_str.substr(mac_pos + zero_mac_str.size() + 1);
119 const std::string::size_type slash_pos = ip_str.rfind(
"/");
120 if (slash_pos != std::string::npos) {
121 ip_str = ip_str.substr(0, slash_pos);
123 if (ip_str.find(
":") == std::string::npos) {
134 if (vxlan_rt_mgr == NULL) {
142 const uint8_t& plen) {
144 std::string origin_vn =
"";
145 if (routing_vrf->
vn()) {
153 (*it)->GetVrf()->GetUcRoute(ip_addr);
155 origin_vn = (*it)->GetName();
167 const uint32_t prefix_len) {
178 const uint32_t prefix_len) {
188 if (prefix_ip.is_v4() && prefix_len == 32)
190 if (prefix_ip.is_v6() && prefix_len == 128)
196 if (evpn_rt != NULL) {
203 if(rt->
vrf() == NULL || rt->
vrf()->
vn() == NULL){
204 LOG(ERROR,
"Error in VxlanRoutingManager::IsHostRouteFromLocalSubnet"
205 <<
", vrf == NULL || vrf()->vn() == NULL");
206 assert(rt->
vrf() && rt->
vrf()->
vn());
215 if (lr_uuid == boost::uuids::nil_uuid()) {
224 const VnEntry *bridge_vn = NULL;
227 while (it_br != bridge_vns.end()) {
229 const std::vector<VnIpam> &VnIpams = bridge_vn->
GetVnIpam();
230 for (uint32_t j=0; j < VnIpams.size(); j++) {
252 (inet_table->
FindLPM(local_vm_route_key));
262 for (Route::PathList::const_iterator it = path_list.begin();
263 it != path_list.end(); ++it) {
265 dynamic_cast<const AgentPath*
>(it.operator->());
278 for (Route::PathList::const_iterator it = path_list.begin();
279 it != path_list.end(); ++it) {
281 dynamic_cast<const AgentPath*
>(it.operator->());
283 path->
peer() != NULL &&
292 return vrf && vrf->
vn() &&
313 return vrf && vrf->
vn() &&
319 const Agent* agent) {
325 if (vxlan_rt_mgr == NULL) {
330 if (vrf_cand == NULL) {
343 for (Route::PathList::const_iterator it = path_list.begin();
344 it != path_list.end(); ++it) {
346 dynamic_cast<const AgentPath*
>(it.operator->());
365 for (Route::PathList::const_iterator it = path_list.begin();
366 it != path_list.end(); ++it) {
368 dynamic_cast<const AgentPath*
>(it.operator->());
372 path->
peer() != NULL &&
409 const Agent *agent) {
413 router_rt = underlay_vrf->
GetUcRoute(compute_ip);
414 if (router_rt != NULL &&
422 compute_mac = *(tunl_nh->
GetDmac());
431 const std::string &vrf_name,
433 unsigned int prefix_len,
434 const autogen::EnetNextHopType &nh_item) {
436 const unsigned int ethernet_tag = 0;
453 const std::string &vrf_name,
455 unsigned int prefix_len,
456 const autogen::NextHopType &nh_item) {
460 if (vrf_entry == NULL)
465 if (inet_tbl == NULL)
473 (inet_tbl->
FindLPM(local_vm_route_key));
482 const std::string& vrf_name) {
486 if(orig_key == NULL) {
487 LOG(ERROR,
"Error in InitializeNhRequest"
488 <<
", orig_key == NULL");
489 assert(orig_key != NULL);
492 nh_req.
key.reset(orig_key);
496 if(intf_orig_key == NULL) {
497 LOG(ERROR,
"Error in InitializeNhRequest"
498 <<
", intf_orig_key == NULL");
499 assert(intf_orig_key != NULL);
508 LOG(ERROR,
"Error in InitializeNhRequest"
509 <<
", Wrong NH type:" << path_nh->
GetType());
596 req.
data.reset(loc_rt_ptr);
609 std::stringstream prefix_str;
610 prefix_str << prefix_ip.to_string();
613 std::string vrf_name = evpn_table->
vrf_name();
652 const std::string& origin_vn
685 evpn_table, old_path);
698 if (path_nh == NULL) {
711 prefix_ip, plen, nh_req, peer, path, evpn_table);
714 prefix_ip, plen, nh_req, peer, path, evpn_table);
731 prefix_ip, plen,
false);
738 inet_table, old_path);
750 if (path_nh == NULL || inet_table == NULL || peer == NULL) {
761 std::string origin_vn =
"";
767 inet_table, origin_vn);
772 if (const_vrf == NULL) {
773 std::cout<<
"VxlanRoutingManager::PrintEvpnTable"
781 if (evpn_table == NULL) {
782 std::cout<<
"VxlanRoutingManager::PrintEvpnTable"
783 <<
", NULL EVPN tbl ptr"
791 std::cout <<
"Evpn Type 5 table:" << std::endl;
793 std::cout <<
"Evpn Type 2 table:" << std::endl;
798 <<
", path count = " << path_list.size()
801 for (Route::PathList::const_iterator it = path_list.begin();
802 it != path_list.end(); ++it) {
804 dynamic_cast<const AgentPath*
>(it.operator->());
816 std::cout<<
" n components="
830 if (const_vrf == NULL) {
831 std::cout<<
"VxlanRoutingManager::PrintInetTable"
839 if (inet_table == NULL) {
840 std::cout<<
"VxlanRoutingManager::PrintInetTable"
841 <<
", NULL Inet tbl ptr"
848 std::cout <<
"Inet table:" << std::endl;
853 <<
", path count = " << path_list.size() << std::endl;
854 for (Route::PathList::const_iterator it = path_list.begin();
855 it != path_list.end(); ++it) {
857 dynamic_cast<const AgentPath*
>(it.operator->());
865 <<
", nh ptr = " << path->
nexthop()
866 <<
", pt ptr = " << path
887 std::cout<<
"VxlanRoutingManager::ListAttachedVns agent == NULL"<<std::endl;
891 if (vxlan_rt_mgr == NULL) {
892 std::cout<<
"VxlanRoutingManager::ListAttachedVns rt mgr = NULL"<<std::endl;
897 for(VxlanRoutingVrfMapper::LrVrfInfoMap::iterator it = lr_vrf_info_map.begin();
898 it != lr_vrf_info_map.end(); it++) {
899 std::cout <<
"VxlanRoutingManager::ListAttachedVns, "
901 << (*it).second.routing_vrf_->GetName()
903 std::cout <<
"VxlanRoutingManager::ListAttachedVns, "
905 << (*it).second.bridge_vn_list_.size()
908 (*it).second.bridge_vn_list_;
909 for(VxlanRoutingVrfMapper::RoutedVrfInfo::BridgeVnList::iterator it_br = reg_br.begin();
910 it_br != reg_br.end(); it_br++) {
912 std::cout<<
"VxlanRoutingManager::ListAttachedVns, "
913 <<
"br VN = " << (*it_br)->GetName()
boost::asio::ip::address IpAddress
boost::asio::ip::address_v4 Ip4Address
bool is_health_check_service() const
uint32_t sequence() const
const VnListType & dest_vn_list() const
NextHop * nexthop() const
const EcmpLoadBalance & ecmp_load_balance() const
const PathPreference & path_preference() const
const SecurityGroupList & sg_list() const
uint32_t vxlan_id() const
const Peer * peer() const
bool force_policy() const
const TagList & tag_list() const
const IpAddress subnet_service_ip() const
const CommunityList & communities() const
virtual const PrefixType & prefix_address() const
Returns the value of a stored prefix address (IPv4, IPv6 or MAC address)
const std::string & vrf_name() const
VrfEntry * vrf_entry() const
Base class for all Route entries in agent.
void DeletePathFromPeer(DBTablePartBase *part, AgentRouteTable *table, AgentPath *path)
virtual AgentPath * FindPath(const Peer *peer) const
VrfTable * vrf_table() const
VrfEntry * fabric_policy_vrf() const
const Peer * evpn_routing_peer() const
static Agent * GetInstance()
size_t ComponentNHCount() const
const NextHop * GetNH(uint32_t idx) const
ClonedLocalPathList::iterator ClonedLocalPathListIter
ClonedLocalPathList & cloned_local_path_list()
std::unique_ptr< DBRequestKey > KeyPtr
virtual KeyPtr GetDBRequestKey() const =0
DBTablePartBase * get_table_partition() const
bool Enqueue(DBRequest *req)
virtual DBEntryBase * GetNext(const DBEntryBase *)=0
virtual DBEntryBase * GetFirst()=0
virtual DBTablePartBase * GetTablePartition(const DBRequestKey *key)
void AddClonedLocalPathReq(const Peer *peer, const string &vrf_name, const MacAddress &mac, const IpAddress &ip_addr, uint32_t ethernet_tag, ClonedLocalPath *data)
EvpnRouteEntry * FindRoute(const MacAddress &mac, const IpAddress &ip_addr, uint32_t plen, uint32_t ethernet_tag)
static void AddRemoteVmRouteReq(const Peer *peer, const std::string &vrf_name, const MacAddress &mac, const IpAddress &ip_addr, uint32_t plen, uint32_t ethernet_tag, AgentRouteData *data)
void AddType5Route(const Peer *peer, const std::string &vrf_name, const IpAddress &ip_addr, uint32_t ethernet_tag, EvpnRoutingData *data, uint8_t plen=0)
uint32_t ethernet_tag() const
uint8_t prefix_length() const
!
void AddEvpnRoutingRoute(const IpAddress &ip_addr, uint8_t plen, const VrfEntry *vrf, const Peer *peer, const SecurityGroupList &sg_list, const CommunityList &communities, const PathPreference &path_preference, const EcmpLoadBalance &ecmp_load_balance, const TagList &tag_list, DBRequest &nh_req, uint32_t vxlan_id, const VnListType &vn_list, const std::string &origin_vn="")
InetUnicastRouteEntry * FindRouteUsingKey(InetUnicastRouteEntry &key)
InetUnicastRouteEntry * FindLPM(const IpAddress &ip)
uint8_t prefix_length() const
!
void set_flags(uint8_t flags)
const uint8_t & flags() const
const Interface * GetInterface() const
void set_tunnel_bmap(TunnelType::TypeBmap bmap)
static const uint32_t kInvalidLabel
virtual std::string ToString() const
VxlanRoutingManager * vxlan_routing_manager() const
const Type GetType() const
const std::string & GetName() const
const PathList & GetPathList() const
boost::intrusive::list< Path, PathListMember > PathList
const MacAddress * GetDmac() const
static TypeBmap VxlanType()
KeyPtr GetDBRequestKey() const
const std::vector< VnIpam > & GetVnIpam() const
const boost::uuids::uuid & logical_router_uuid() const
bool vxlan_routing_vn() const
const string & GetName() const
InetUnicastRouteEntry * GetUcRoute(const IpAddress &addr) const
InetUnicastAgentRouteTable * GetInet4UnicastRouteTable() const
InetUnicastAgentRouteTable * GetInetUnicastRouteTable(const IpAddress &addr) const
AgentRouteTable * GetEvpnRouteTable() const
uint32_t vxlan_id() const
VrfEntry * FindVrfFromName(const string &name)
This class manages routes leaking between bridge VRF instances and the routing VRF instance....
static void ListAttachedVns()
Prints all virtual networks attached to logical routers.
static void CopyInterfacePathToEvpnTable(const AgentPath *path, const IpAddress &prefix_ip, const uint32_t plen, const Peer *peer, const RouteParameters ¶ms, EvpnAgentRouteTable *evpn_table)
Copies the path to the prefix address into the EVPN table with the given Peer. The function is used d...
static bool RoutePrefixIsEqualTo(const EvpnRouteEntry *route, const IpAddress &prefix_ip, const uint32_t prefix_len)
Determines whether route prefix in the EVPN route is equal to the given pair of prefix IP address and...
bool HasBgpPeerPath(EvpnRouteEntry *evpn_rt)
Determines whether the given EVPN route has at least one path originating from BGP/XMPP (has Peer typ...
static bool IsVxlanAvailable(const Agent *agent)
Checks whether VxLAN routing manager is enabled or not.
const VxlanRoutingVrfMapper & vrf_mapper() const
Returns the map between LR uuids and associated bridge and routing VRF instances.
static bool is_ipv4_string(const std::string &prefix_str)
Determines whether the address string contains an IPv4 address as substring or not.
static uint32_t loc_sequence_
An always increasing counter for new paths (used to signal controoler about new routes).
static bool IsHostRoute(const IpAddress &prefix_ip, uint32_t prefix_len)
Determines whether the prefix address and the prefix length point to a host route (/32 for IPv4,...
static AgentRoute * FindEvpnOrInetRoute(const Agent *agent, const std::string &vrf_name, const IpAddress &ip_addr, uint32_t prefix_len, const autogen::EnetNextHopType &nh_item)
Finds a route with the given prefix address and len in the EVPN table.
static const AgentPath * FindPathWithGivenPeer(const AgentRoute *inet_rt, const Peer::Type peer_type)
Finds in the given route the path with a specified Peer type.
static std::string ipv6_prefix(const std::string &prefix_str)
Extracts an IPv6 address string from the prefix string.
std::string GetOriginVn(const VrfEntry *routing_vrf, const IpAddress &ip_addr, const uint8_t &plen)
Finds first occurence of a route with the given prefix (IP address and length) in Inet tables of brid...
static const AgentPath * FindInterfacePathWithLocalVmPeer(const AgentRoute *inet_rt, bool strict_match=true)
Finds in the given route the path which has the LOCAL_VM_PEER peer type and the Interface nexthop typ...
static uint32_t GetNewLocalSequence(const AgentPath *)
Auxilliary functions.
static const Peer * routing_vrf_interface_peer_
Internal data of this class.
static bool IsBridgeVrf(const VrfEntry *vrf)
Determines whether the pointer to the VRF instance is of bridge type.
static bool HasVrfNexthop(const AgentRoute *rt)
Determines whether the given route has the path with a VRF nexthop (VrfNH)
static const AgentPath * FindPathWithGivenPeerAndNexthop(const AgentRoute *inet_rt, const Peer::Type peer_type, const NextHop::Type nh_type, bool strict_match=true)
Finds in the given route the path with a specified Peer type and a specified nexthop type.
static void PrintEvpnTable(const VrfEntry *const_vrf)
Prints EVPN table of the given VRF instance.
bool IsHostRouteFromLocalSubnet(const EvpnRouteEntry *rt)
Determines whether the given EVPN route is a host one and belongs to a subnet of a local bridge VRF....
static bool IsRoutingVrf(const VrfEntry *vrf)
Determines whether the pointer to the VRF instance is of routing type.
static uint32_t ipv4_prefix_len(const std::string &prefix_str)
Extracts length of IPv4 subnet address from the prefix string.
static MacAddress NbComputeMac(const Ip4Address &compute_ip, const Agent *agent)
Returns the MAC address for the IP of a given neighbouring compute.
Agent * agent_
A pointer to the Agent instance.
void CopyPathToInetTable(const AgentPath *path, const IpAddress &prefix_ip, const uint32_t plen, const Peer *peer, const RouteParameters ¶ms, InetUnicastAgentRouteTable *inet_table)
Copies the path to the prefix address into the EVPN table with the given Peer. The function is used d...
static const AgentPath * FindInterfacePathWithGivenPeer(const AgentRoute *inet_rt, const Peer::Type peer_type, bool strict_match=true)
Finds in the given route the path with the given Peer type and interface nexthop (InterfaceNH).
bool IsVrfLocalRoute(EvpnRouteEntry *routing_evpn_rt, VrfEntry *bridge_vrf)
Determines if the given EVPN route has an interface NH or a composite of interfaces NH that belongs t...
static const AgentPath * FindInterfacePathWithBgpPeer(const AgentRoute *inet_rt, bool strict_match=true)
Finds in the given route the path which has the BGP_PEER Peer type and the Interface nexthop type....
static bool is_ipv6_string(const std::string &prefix_str)
Determines whether the address string contains an IPv6 address as substring or not.
static std::string ipv4_prefix(const std::string &prefix_str)
Extracts an IPv4 address string from the prefix string.
static void PrintInetTable(const VrfEntry *const_vrf)
Prints IPv4 Inet table of the given VRF instance.
static uint32_t ipv6_prefix_len(const std::string &prefix_str)
Extracts length of IPv6 subnet address from the prefix string.
VxlanRoutingVrfMapper vrf_mapper_
A map between LR uuids and associated bridge and routing VRF instances.
static void DeleteOldInterfacePath(const IpAddress &prefix_ip, const uint32_t plen, const Peer *peer, EvpnAgentRouteTable *evpn_table)
Routes copying functions.
The class is used to store following information:
LrVrfInfoMap lr_vrf_info_map_
The map between Logical router UUID and RoutedVrfInfo.
const boost::uuids::uuid GetLogicalRouterUuidUsingRoute(const AgentRoute *rt)
Find the UUID of the LR using a given route (AgentRoute).
std::map< boost::uuids::uuid, RoutedVrfInfo > LrVrfInfoMap
A typedef to store map between Logical router UUID and RoutedVrfInfo.
#define LOG(_Level, _Msg)
std::unique_ptr< DBRequestKey > key
std::unique_ptr< DBRequestData > data
A structure to hold path parameters during the transfer (routes leaking) of data between VRF instance...
const EcmpLoadBalance & ecmp_load_balance_
A reference to EcmpLoadBalance of the path.
const TagList & tag_list_
A list of tags.
const PathPreference & path_preference_
A reference to the PathPreference of the path.
const CommunityList & communities_
A list of communities.
const SecurityGroupList & sg_list_
A list of security groups.
const VnListType & vn_list_
A list of path destination virtual networks used in policy lookups.
The structure holds information about virtual networks connected to a logical router (LR)
std::set< const VnEntry * > BridgeVnList
A typedef to store the list of bridge virtual networks connected to a 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.
static void AdvertiseInterfaceBgpRoute(const IpAddress &prefix_ip, const uint32_t plen, DBRequest &nh_req, const Peer *peer, const AgentPath *path, EvpnAgentRouteTable *evpn_table)
static bool IsGivenTypeCompositeNextHop(const NextHop *nh, NextHop::Type nh_type, bool strict_match=true)
static bool InitializeNhRequest(const NextHop *path_nh, DBRequest &nh_req, const std::string &vrf_name)
static void AdvertiseCompositeInterfaceBgpRoute(const IpAddress &prefix_ip, const uint32_t plen, DBRequest &nh_req, const Peer *peer, const AgentPath *path, EvpnAgentRouteTable *evpn_table)
static void AdvertiseLocalRoute(const IpAddress &prefix_ip, const uint32_t plen, DBRequest &nh_req, const Peer *peer, const RouteParameters ¶ms, EvpnAgentRouteTable *evpn_table)