10 #include <xmpp_enet_types.h>
11 #include <xmpp_unicast_types.h>
32 for (uint32_t i=0; i < comp_nh_count; i++) {
36 if (c_nh->
GetType() == nh_type &&
41 if (c_nh->
GetType() != nh_type &&
64 return (prefix_str.find(
".") != std::string::npos);
68 return (prefix_str.find(
":") != std::string::npos) &&
73 const std::string::size_type slash_pos = prefix_str.rfind(
"/");
74 if (slash_pos == std::string::npos) {
77 const std::string len_str = prefix_str.substr(slash_pos + 1);
78 uint32_t prefix_len = 0;
79 std::istringstream(len_str) >> prefix_len;
80 return std::min(uint32_t(32), prefix_len);
84 std::string::size_type first_dot_pos = 0;
85 std::string::size_type last_colon_pos =
86 prefix_str.rfind(
":");
87 std::string::size_type slash_pos = prefix_str.rfind(
"/");
88 std::string ip_str =
"0.0.0.0";
89 if ((first_dot_pos = prefix_str.find(
".")) != std::string::npos) {
90 if (first_dot_pos - last_colon_pos >= 2 &&
91 first_dot_pos - last_colon_pos <= 4) {
92 ip_str = prefix_str.substr(last_colon_pos + 1);
94 if (last_colon_pos == string::npos) {
97 if (slash_pos != string::npos) {
98 ip_str = ip_str.substr(0, slash_pos);
105 const std::string::size_type slash_pos = prefix_str.rfind(
"/");
106 if (slash_pos == std::string::npos) {
109 const std::string len_str = prefix_str.substr(slash_pos + 1);
110 uint32_t prefix_len = 0;
111 std::istringstream(len_str) >> prefix_len;
112 return std::min(uint32_t(128), prefix_len);
116 const std::string zero_mac_str =
"00:00:00:00:00:00";
117 const std::string::size_type mac_pos = prefix_str.find(zero_mac_str);
118 std::string ip_str = prefix_str;
120 if (mac_pos != std::string::npos) {
121 ip_str = prefix_str.substr(mac_pos + zero_mac_str.size() + 1);
124 const std::string::size_type slash_pos = ip_str.rfind(
"/");
125 if (slash_pos != std::string::npos) {
126 ip_str = ip_str.substr(0, slash_pos);
128 if (ip_str.find(
":") == std::string::npos) {
139 if (vxlan_rt_mgr == NULL) {
147 const uint8_t& plen) {
149 std::string origin_vn =
"";
150 if (routing_vrf->
vn()) {
156 if (it_vrf ==
nullptr) {
161 origin_vn = bridge_vn_entry->GetName();
172 const uint32_t prefix_len) {
183 const uint32_t prefix_len) {
193 if (prefix_ip.is_v4() && prefix_len == 32)
195 if (prefix_ip.is_v6() && prefix_len == 128)
201 if (evpn_rt != NULL) {
208 if(rt->
vrf() == NULL || rt->
vrf()->
vn() == NULL){
209 LOG(ERROR,
"Error in VxlanRoutingManager::IsHostRouteFromLocalSubnet"
210 <<
", vrf == NULL || vrf()->vn() == NULL");
211 assert(rt->
vrf() && rt->
vrf()->
vn());
220 if (lr_uuid == boost::uuids::nil_uuid()) {
229 const VnEntry *bridge_vn = NULL;
232 while (it_br != bridge_vns.end()) {
234 const std::vector<VnIpam> &VnIpams = bridge_vn->
GetVnIpam();
235 for (uint32_t j=0; j < VnIpams.size(); j++) {
257 (inet_table->
FindLPM(local_vm_route_key));
267 for (Route::PathList::const_iterator it = path_list.begin();
268 it != path_list.end(); ++it) {
270 dynamic_cast<const AgentPath*
>(it.operator->());
283 for (Route::PathList::const_iterator it = path_list.begin();
284 it != path_list.end(); ++it) {
286 dynamic_cast<const AgentPath*
>(it.operator->());
288 path->
peer() != NULL &&
297 return vrf && vrf->
vn() &&
318 return vrf && vrf->
vn() &&
324 const Agent* agent) {
330 if (vxlan_rt_mgr == NULL) {
335 if (vrf_cand == NULL) {
348 for (Route::PathList::const_iterator it = path_list.begin();
349 it != path_list.end(); ++it) {
351 dynamic_cast<const AgentPath*
>(it.operator->());
370 for (Route::PathList::const_iterator it = path_list.begin();
371 it != path_list.end(); ++it) {
373 dynamic_cast<const AgentPath*
>(it.operator->());
377 path->
peer() != NULL &&
414 const Agent *agent) {
418 router_rt = underlay_vrf->
GetUcRoute(compute_ip);
419 if (router_rt != NULL &&
427 compute_mac = *(tunl_nh->
GetDmac());
436 const std::string &vrf_name,
438 unsigned int prefix_len,
439 const autogen::EnetNextHopType &nh_item) {
441 const unsigned int ethernet_tag = 0;
458 const std::string &vrf_name,
460 unsigned int prefix_len,
461 const autogen::NextHopType &nh_item) {
465 if (vrf_entry == NULL)
470 if (inet_tbl == NULL)
478 (inet_tbl->
FindLPM(local_vm_route_key));
487 const std::string& vrf_name) {
491 if(orig_key == NULL) {
492 LOG(ERROR,
"Error in InitializeNhRequest"
493 <<
", orig_key == NULL");
494 assert(orig_key != NULL);
497 nh_req.
key.reset(orig_key);
501 if(intf_orig_key == NULL) {
502 LOG(ERROR,
"Error in InitializeNhRequest"
503 <<
", intf_orig_key == NULL");
504 assert(intf_orig_key != NULL);
513 LOG(ERROR,
"Error in InitializeNhRequest"
514 <<
", Wrong NH type:" << path_nh->
GetType());
601 req.
data.reset(loc_rt_ptr);
614 std::stringstream prefix_str;
615 prefix_str << prefix_ip.to_string();
618 std::string vrf_name = evpn_table->
vrf_name();
657 const std::string& origin_vn
690 evpn_table, old_path);
703 if (path_nh == NULL) {
716 prefix_ip, plen, nh_req, peer, path, evpn_table);
719 prefix_ip, plen, nh_req, peer, path, evpn_table);
736 prefix_ip, plen,
false);
743 inet_table, old_path);
755 if (path_nh == NULL || inet_table == NULL || peer == NULL) {
766 std::string origin_vn =
"";
772 inet_table, origin_vn);
777 if (const_vrf == NULL) {
778 std::cout<<
"VxlanRoutingManager::PrintEvpnTable"
786 if (evpn_table == NULL) {
787 std::cout<<
"VxlanRoutingManager::PrintEvpnTable"
788 <<
", NULL EVPN tbl ptr"
796 std::cout <<
"Evpn Type 5 table:" << std::endl;
798 std::cout <<
"Evpn Type 2 table:" << std::endl;
803 <<
", path count = " << path_list.size()
806 for (Route::PathList::const_iterator it = path_list.begin();
807 it != path_list.end(); ++it) {
809 dynamic_cast<const AgentPath*
>(it.operator->());
821 std::cout<<
" n components="
835 if (const_vrf == NULL) {
836 std::cout<<
"VxlanRoutingManager::PrintInetTable"
844 if (inet_table == NULL) {
845 std::cout<<
"VxlanRoutingManager::PrintInetTable"
846 <<
", NULL Inet tbl ptr"
853 std::cout <<
"Inet table:" << std::endl;
858 <<
", path count = " << path_list.size() << std::endl;
859 for (Route::PathList::const_iterator it = path_list.begin();
860 it != path_list.end(); ++it) {
862 dynamic_cast<const AgentPath*
>(it.operator->());
870 <<
", nh ptr = " << path->
nexthop()
871 <<
", pt ptr = " << path
892 std::cout<<
"VxlanRoutingManager::ListAttachedVns agent == NULL"<<std::endl;
896 if (vxlan_rt_mgr == NULL) {
897 std::cout<<
"VxlanRoutingManager::ListAttachedVns rt mgr = NULL"<<std::endl;
902 for(VxlanRoutingVrfMapper::LrVrfInfoMap::iterator it = lr_vrf_info_map.begin();
903 it != lr_vrf_info_map.end(); it++) {
904 std::cout <<
"VxlanRoutingManager::ListAttachedVns, "
906 << (*it).second.routing_vrf_->GetName()
908 std::cout <<
"VxlanRoutingManager::ListAttachedVns, "
910 << (*it).second.bridge_vn_list_.size()
913 (*it).second.bridge_vn_list_;
914 for(VxlanRoutingVrfMapper::RoutedVrfInfo::BridgeVnList::iterator it_br = reg_br.begin();
915 it_br != reg_br.end(); it_br++) {
917 std::cout<<
"VxlanRoutingManager::ListAttachedVns, "
918 <<
"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 an operative state of VxLAN logical routers (LR) defined via Config logical-router...
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).
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...
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.
This class is a storage for operative state of VxLAN logical routers (LRs) defined via Config logical...
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.
BridgeVrfNamesList bridge_vrf_names_list_
The list of bridge virtual networks (VirtualNetwork) names 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)