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 &&
53 const Interface *
interface = intf_nh->GetInterface();
80 for (uint32_t i=0; i < n_comps; i++) {
95 tbb::mutex::scoped_lock lock(
mutex_);
105 return (prefix_str.find(
".") != std::string::npos);
109 return (prefix_str.find(
":") != std::string::npos) &&
114 const std::string::size_type slash_pos = prefix_str.rfind(
"/");
115 if (slash_pos == std::string::npos) {
118 const std::string len_str = prefix_str.substr(slash_pos + 1);
119 uint32_t prefix_len = 0;
120 std::istringstream(len_str) >> prefix_len;
121 return std::min(uint32_t(32), prefix_len);
125 std::string::size_type first_dot_pos = 0;
126 std::string::size_type last_colon_pos =
127 prefix_str.rfind(
":");
128 std::string::size_type slash_pos = prefix_str.rfind(
"/");
129 std::string ip_str =
"0.0.0.0";
130 if ((first_dot_pos = prefix_str.find(
".")) != std::string::npos) {
131 if (first_dot_pos - last_colon_pos >= 2 &&
132 first_dot_pos - last_colon_pos <= 4) {
133 ip_str = prefix_str.substr(last_colon_pos + 1);
135 if (last_colon_pos == string::npos) {
138 if (slash_pos != string::npos) {
139 ip_str = ip_str.substr(0, slash_pos);
146 const std::string::size_type slash_pos = prefix_str.rfind(
"/");
147 if (slash_pos == std::string::npos) {
150 const std::string len_str = prefix_str.substr(slash_pos + 1);
151 uint32_t prefix_len = 0;
152 std::istringstream(len_str) >> prefix_len;
153 return std::min(uint32_t(128), prefix_len);
157 const std::string zero_mac_str =
"00:00:00:00:00:00";
158 const std::string::size_type mac_pos = prefix_str.find(zero_mac_str);
159 std::string ip_str = prefix_str;
161 if (mac_pos != std::string::npos) {
162 ip_str = prefix_str.substr(mac_pos + zero_mac_str.size() + 1);
165 const std::string::size_type slash_pos = ip_str.rfind(
"/");
166 if (slash_pos != std::string::npos) {
167 ip_str = ip_str.substr(0, slash_pos);
169 if (ip_str.find(
":") == std::string::npos) {
180 if (vxlan_rt_mgr == NULL) {
188 const uint8_t& plen) {
190 std::string origin_vn =
"";
191 if (routing_vrf->
vn()) {
199 (*it)->GetVrf()->GetUcRoute(ip_addr);
201 origin_vn = (*it)->GetName();
213 const uint32_t prefix_len) {
224 const uint32_t prefix_len) {
234 if (prefix_ip.is_v4() && prefix_len == 32)
236 if (prefix_ip.is_v6() && prefix_len == 128)
242 if (evpn_rt != NULL) {
249 if(rt->
vrf() == NULL || rt->
vrf()->
vn() == NULL){
250 LOG(ERROR,
"Error in VxlanRoutingManager::IsHostRouteFromLocalSubnet"
251 <<
", vrf == NULL || vrf()->vn() == NULL");
252 assert(rt->
vrf() && rt->
vrf()->
vn());
261 if (lr_uuid == boost::uuids::nil_uuid()) {
270 const VnEntry *bridge_vn = NULL;
273 while (it_br != bridge_vns.end()) {
275 const std::vector<VnIpam> &VnIpams = bridge_vn->
GetVnIpam();
276 for (uint32_t j=0; j < VnIpams.size(); j++) {
298 (inet_table->FindLPM(local_vm_route_key));
308 for (Route::PathList::const_iterator it = path_list.begin();
309 it != path_list.end(); ++it) {
311 dynamic_cast<const AgentPath*
>(it.operator->());
324 for (Route::PathList::const_iterator it = path_list.begin();
325 it != path_list.end(); ++it) {
327 dynamic_cast<const AgentPath*
>(it.operator->());
329 path->
peer() != NULL &&
338 return vrf && vrf->
vn() &&
359 return vrf && vrf->
vn() &&
365 const Agent* agent) {
371 if (vxlan_rt_mgr == NULL) {
376 if (vrf_cand == NULL) {
389 for (Route::PathList::const_iterator it = path_list.begin();
390 it != path_list.end(); ++it) {
392 dynamic_cast<const AgentPath*
>(it.operator->());
411 for (Route::PathList::const_iterator it = path_list.begin();
412 it != path_list.end(); ++it) {
414 dynamic_cast<const AgentPath*
>(it.operator->());
418 path->
peer() != NULL &&
457 if (inet_rt == NULL) {
462 if (bgp_cand_path == NULL) {
466 return bgp_cand_path;
469 return bgp_cand_path;
475 const std::string& vrf_name,
479 nh_req.
key.reset(orig_key);
489 uint32_t prefix_len,
const AgentPath* path,
491 if (!path || !path->
nexthop()) {
506 const std::string& vrf_name = evpn_table->
vrf_name();
513 prefix_ip, prefix_len, 0);
520 if (prev_path && prev_path->
nexthop() &&
526 const bool comp_nh_policy =
false;
533 const NextHop *first_intf_nh = NULL;
534 for (uint32_t i=0; i < components.size(); i++) {
535 if (components[i].
get() &&
536 components[i]->nh() &&
538 if (first_intf_nh == NULL) {
539 first_intf_nh = components[i]->nh();
543 nh_key =
static_cast<NextHopKey *
>(key.release());
545 std::unique_ptr<const NextHopKey> nh_key_ptr(nh_key);
548 new_comp_nh_list.push_back(component_nh_key);
551 if (new_comp_nh_list.size() < 1) {
556 }
else if (new_comp_nh_list.size() == 1) {
563 uint32_t n_nulls = 0;
565 for (uint32_t i_null=0; i_null < n_nulls; i_null++) {
567 new_comp_nh_list.push_back(component_nh_key);
572 comp_nh_policy, new_comp_nh_list, vrf_name);
579 nh_req.
key.reset(new_comp_nh_key);
588 const Agent *agent) {
592 router_rt = underlay_vrf->
GetUcRoute(compute_ip);
593 if (router_rt != NULL &&
601 compute_mac = *(tunl_nh->
GetDmac());
610 const std::string &vrf_name,
612 unsigned int prefix_len,
613 const autogen::EnetNextHopType &nh_item) {
615 const unsigned int ethernet_tag = 0;
632 const std::string &vrf_name,
634 unsigned int prefix_len,
635 const autogen::NextHopType &nh_item) {
639 if (vrf_entry == NULL)
644 if (inet_tbl == NULL)
652 (inet_tbl->
FindLPM(local_vm_route_key));
661 const std::string& vrf_name) {
665 if(orig_key == NULL) {
666 LOG(ERROR,
"Error in InitializeNhRequest"
667 <<
", orig_key == NULL");
668 assert(orig_key != NULL);
671 nh_req.
key.reset(orig_key);
675 if(intf_orig_key == NULL) {
676 LOG(ERROR,
"Error in InitializeNhRequest"
677 <<
", intf_orig_key == NULL");
678 assert(intf_orig_key != NULL);
687 LOG(ERROR,
"Error in InitializeNhRequest"
688 <<
", Wrong NH type:" << path_nh->
GetType());
775 req.
data.reset(loc_rt_ptr);
788 std::stringstream prefix_str;
789 prefix_str << prefix_ip.to_string();
792 std::string vrf_name = evpn_table->
vrf_name();
831 const std::string& origin_vn
864 evpn_table, old_path);
877 if (path_nh == NULL) {
890 prefix_ip, plen, nh_req, peer, path, evpn_table);
893 prefix_ip, plen, nh_req, peer, path, evpn_table);
910 prefix_ip, plen,
false);
914 AgentPath *old_path = rt_entry->FindPath(peer);
916 rt_entry->DeletePathFromPeer(rt_entry->get_table_partition(),
917 inet_table, old_path);
929 if (path_nh == NULL || inet_table == NULL || peer == NULL) {
940 std::string origin_vn =
"";
946 inet_table, origin_vn);
951 if (const_vrf == NULL) {
952 std::cout<<
"VxlanRoutingManager::PrintEvpnTable"
960 if (evpn_table == NULL) {
961 std::cout<<
"VxlanRoutingManager::PrintEvpnTable"
962 <<
", NULL EVPN tbl ptr"
970 std::cout <<
"Evpn Type 5 table:" << std::endl;
972 std::cout <<
"Evpn Type 2 table:" << std::endl;
977 <<
", path count = " << path_list.size()
980 for (Route::PathList::const_iterator it = path_list.begin();
981 it != path_list.end(); ++it) {
983 dynamic_cast<const AgentPath*
>(it.operator->());
995 std::cout<<
" n components="
1001 c_entry = dynamic_cast<EvpnRouteEntry *>
1009 if (const_vrf == NULL) {
1010 std::cout<<
"VxlanRoutingManager::PrintInetTable"
1018 if (inet_table == NULL) {
1019 std::cout<<
"VxlanRoutingManager::PrintInetTable"
1020 <<
", NULL Inet tbl ptr"
1027 std::cout <<
"Inet table:" << std::endl;
1032 <<
", path count = " << path_list.size() << std::endl;
1033 for (Route::PathList::const_iterator it = path_list.begin();
1034 it != path_list.end(); ++it) {
1036 dynamic_cast<const AgentPath*
>(it.operator->());
1044 <<
", nh ptr = " << path->
nexthop()
1045 <<
", pt ptr = " << path
1056 c_entry = dynamic_cast<InetUnicastRouteEntry *>
1065 if (agent == NULL) {
1066 std::cout<<
"VxlanRoutingManager::ListAttachedVns agent == NULL"<<std::endl;
1070 if (vxlan_rt_mgr == NULL) {
1071 std::cout<<
"VxlanRoutingManager::ListAttachedVns rt mgr = NULL"<<std::endl;
1076 for(VxlanRoutingVrfMapper::LrVrfInfoMap::iterator it = lr_vrf_info_map.begin();
1077 it != lr_vrf_info_map.end(); it++) {
1078 std::cout <<
"VxlanRoutingManager::ListAttachedVns, "
1080 << (*it).second.routing_vrf_->GetName()
1082 std::cout <<
"VxlanRoutingManager::ListAttachedVns, "
1084 << (*it).second.bridge_vn_list_.size()
1087 (*it).second.bridge_vn_list_;
1088 for(VxlanRoutingVrfMapper::RoutedVrfInfo::BridgeVnList::iterator it_br = reg_br.begin();
1089 it_br != reg_br.end(); it_br++) {
1091 std::cout<<
"VxlanRoutingManager::ListAttachedVns, "
1092 <<
"br VN = " << (*it_br)->GetName()
const std::string & GetName() const
void AddType5Route(const Peer *peer, const std::string &vrf_name, const IpAddress &ip_addr, uint32_t ethernet_tag, EvpnRoutingData *data, uint8_t plen=0)
uint8_t prefix_length() const
!
const Interface * GetInterface() const
EvpnRouteEntry * FindRoute(const MacAddress &mac, const IpAddress &ip_addr, uint32_t plen, uint32_t ethernet_tag)
const TagList & tag_list_
A list of tags.
const VnListType & dest_vn_list() const
static void AdvertiseLocalRoute(const IpAddress &prefix_ip, const uint32_t plen, DBRequest &nh_req, const Peer *peer, const RouteParameters ¶ms, EvpnAgentRouteTable *evpn_table)
const std::string & vrf_name() const
static Agent * GetInstance()
void set_flags(uint8_t flags)
virtual DBEntryBase * GetFirst()=0
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 uint32_t ipv4_prefix_len(const std::string &prefix_str)
Extracts length of IPv4 subnet address from the prefix string.
const TagList & tag_list() const
const PathPreference & path_preference() const
InetUnicastRouteEntry * FindLPM(const IpAddress &ip)
bool force_policy() const
const IpAddress subnet_service_ip() const
AgentRouteTable * GetEvpnRouteTable() const
VrfEntry * FindVrfFromName(const string &name)
static bool IsBridgeVrf(const VrfEntry *vrf)
Determines whether the pointer to the VRF instance is of bridge type.
static bool IsBGPaaSCompositeNextHop(const Agent *agent, const NextHop *nh)
const AgentPath * FindBGPaaSPath(const InetUnicastRouteEntry *rt)
Finds in the given route the path that was announced using BGPaaS. It is expected that this path has ...
void AddClonedLocalPathReq(const Peer *peer, const string &vrf_name, const MacAddress &mac, const IpAddress &ip_addr, uint32_t ethernet_tag, ClonedLocalPath *data)
static std::string ipv4_prefix(const std::string &prefix_str)
Extracts an IPv4 address string from the prefix string.
std::set< const VnEntry * > BridgeVnList
A typedef to store the list of bridge virtual networks connected to a LR.
static MacAddress NbComputeMac(const Ip4Address &compute_ip, const Agent *agent)
Returns the MAC address for the IP of a given neighbouring compute.
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...
BridgeVnList bridge_vn_list_
The list of bridge virtual networks (VirtualNetwork) connected to a LR.
boost::asio::ip::address IpAddress
VrfEntry * fabric_policy_vrf() const
std::unique_ptr< DBRequestData > data
InetUnicastAgentRouteTable * GetInet4UnicastRouteTable() const
const boost::uuids::uuid GetLogicalRouterUuidUsingRoute(const AgentRoute *rt)
Find the UUID of the LR using a given route (AgentRoute).
bool Enqueue(DBRequest *req)
void DeletePathFromPeer(DBTablePartBase *part, AgentRouteTable *table, AgentPath *path)
virtual DBEntryBase * GetNext(const DBEntryBase *)=0
const VxlanRoutingVrfMapper & vrf_mapper() const
Returns the map between LR uuids and associated bridge and routing VRF instances. ...
void set_loc_sequence(uint32_t loc_sequence)
boost::shared_ptr< const ComponentNHKey > ComponentNHKeyPtr
const string & GetName() const
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.
A structure to hold path parameters during the transfer (routes leaking) of data between VRF instance...
virtual std::string ToString() const
static bool is_ipv4_string(const std::string &prefix_str)
Determines whether the address string contains an IPv4 address as substring or not.
VxlanRoutingManager * vxlan_routing_manager() const
std::unique_ptr< DBRequestKey > KeyPtr
The class is used to store following information:
Base class for all Route entries in agent.
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).
const SecurityGroupList & sg_list_
A list of security groups.
std::vector< ComponentNHKeyPtr > ComponentNHKeyList
uint32_t ethernet_tag() const
static void PrintEvpnTable(const VrfEntry *const_vrf)
Prints EVPN table of the given VRF instance.
std::map< boost::uuids::uuid, RoutedVrfInfo > LrVrfInfoMap
A typedef to store map between Logical router UUID and RoutedVrfInfo.
void AdvertiseBGPaaSRoute(const IpAddress &prefix_ip, uint32_t prefix_len, const AgentPath *path, EvpnAgentRouteTable *evpn_table)
Advertises BGPaaS interface path in the routing VRF instance by selecting corresponding path componen...
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...
This class manages routes leaking between bridge VRF instances and the routing VRF instance...
const Type GetType() const
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...
NextHop * nexthop() const
boost::intrusive::list< Path, PathListMember > PathList
BgpAsAService * bgp_as_a_service() const
VrfEntry * vrf_entry() const
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.
Agent * agent_
A pointer to the Agent instance.
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="")
static bool is_ipv6_string(const std::string &prefix_str)
Determines whether the address string contains an IPv6 address as substring or not.
static bool IsRoutingVrf(const VrfEntry *vrf)
Determines whether the pointer to the VRF instance is of routing type.
KeyPtr GetDBRequestKey() const
const VnListType & vn_list_
A list of path destination virtual networks used in policy lookups.
static uint32_t GetNewLocalSequence(const AgentPath *)
Auxilliary functions.
uint32_t sequence() const
InetUnicastAgentRouteTable * GetInetUnicastRouteTable(const IpAddress &addr) const
boost::asio::ip::address_v6 Ip6Address
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...
std::unique_ptr< DBRequestKey > key
bool vxlan_routing_vn() const
bool is_health_check_service() const
const Peer * peer() const
uint64_t sequence_number() const
const ComponentNHList & component_nh_list() const
ClonedLocalPathList & cloned_local_path_list()
const std::vector< VnIpam > & GetVnIpam() const
static uint32_t loc_sequence_
An always increasing counter for new paths (used to signal controoler about new routes).
static bool InitializeNhRequest(const NextHop *path_nh, DBRequest &nh_req, const std::string &vrf_name)
bool HasBgpPeerPath(EvpnRouteEntry *evpn_rt)
Determines whether the given EVPN route has at least one path originating from BGP/XMPP (has Peer typ...
virtual KeyPtr GetDBRequestKey() const =0
virtual const PrefixType & prefix_address() const
Returns the value of a stored prefix address (IPv4, IPv6 or MAC address)
boost::asio::ip::address_v4 Ip4Address
static void PrintInetTable(const VrfEntry *const_vrf)
Prints IPv4 Inet table of the given VRF instance.
static const uint32_t kInvalidLabel
const PathPreference & path_preference_
A reference to the PathPreference of the path.
VrfTable * vrf_table() const
const Ip4Address & primary_ip_addr() const
virtual DBTablePartBase * GetTablePartition(const DBRequestKey *key)
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...
const boost::uuids::uuid & logical_router_uuid() const
uint8_t prefix_length() const
!
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...
uint32_t vxlan_id() const
ClonedLocalPathList::iterator ClonedLocalPathListIter
VxlanRoutingVrfMapper vrf_mapper_
A map between LR uuids and associated bridge and routing VRF instances.
const Ip6Address & primary_ip6_addr() const
size_t ComponentNHCount() const
static uint32_t ipv6_prefix_len(const std::string &prefix_str)
Extracts length of IPv6 subnet address from the prefix string.
static bool IsVxlanAvailable(const Agent *agent)
Checks whether VxLAN routing manager is enabled or not.
const CommunityList & communities_
A list of communities.
static void AdvertiseInterfaceBgpRoute(const IpAddress &prefix_ip, const uint32_t plen, DBRequest &nh_req, const Peer *peer, const AgentPath *path, EvpnAgentRouteTable *evpn_table)
void MakeInterfaceNextHopReq(const NextHop *path_nh, const std::string &vrf_name, DBRequest &nh_req)
bool Reorder(Agent *agent, uint32_t label, const NextHop *nh)
#define LOG(_Level, _Msg)
static void DeleteOldInterfacePath(const IpAddress &prefix_ip, const uint32_t plen, const Peer *peer, EvpnAgentRouteTable *evpn_table)
Routes copying functions.
The structure holds information about virtual networks connected to a logical router (LR) ...
static void AdvertiseCompositeInterfaceBgpRoute(const IpAddress &prefix_ip, const uint32_t plen, DBRequest &nh_req, const Peer *peer, const AgentPath *path, EvpnAgentRouteTable *evpn_table)
std::vector< ComponentNHPtr > ComponentNHList
static void ListAttachedVns()
Prints all virtual networks attached to logical routers.
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 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...
DBTablePartBase * get_table_partition() const
static bool HasVrfNexthop(const AgentRoute *rt)
Determines whether the given route has the path with a VRF nexthop (VrfNH)
const uint8_t & flags() const
const NextHop * GetNH(uint32_t idx) const
BridgeVnList::iterator BridgeVnListIter
A type for iterator of the list of bridge virtual networks connected to a LR.
LrVrfInfoMap lr_vrf_info_map_
The map between Logical router UUID and RoutedVrfInfo.
static const Peer * routing_vrf_interface_peer_
Internal data of this class.
const MacAddress * GetDmac() const
InetUnicastRouteEntry * GetUcRoute(const IpAddress &addr) const
static bool IsBGPaaSInterfaceNextHop(const Agent *agent, const NextHop *nh)
virtual AgentPath * FindPath(const Peer *peer) const
const CommunityList & communities() const
const EcmpLoadBalance & ecmp_load_balance_
A reference to EcmpLoadBalance of the path.
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 std::string ipv6_prefix(const std::string &prefix_str)
Extracts an IPv6 address string from the prefix string.
static TypeBmap VxlanType()
InetUnicastRouteEntry * FindRouteUsingKey(InetUnicastRouteEntry &key)
const SecurityGroupList & sg_list() const
uint32_t vxlan_id() const
static bool IsGivenTypeCompositeNextHop(const NextHop *nh, NextHop::Type nh_type, bool strict_match=true)
const EcmpLoadBalance & ecmp_load_balance() const
void set_tunnel_bmap(TunnelType::TypeBmap bmap)
const Peer * evpn_routing_peer() const
const PathList & GetPathList() const
const MplsLabel * mpls_label() const
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)