diff --git a/orchagent/vxlanorch.cpp b/orchagent/vxlanorch.cpp index 7850727bd273..1995675fdd15 100644 --- a/orchagent/vxlanorch.cpp +++ b/orchagent/vxlanorch.cpp @@ -494,67 +494,6 @@ VxlanTunnel::~VxlanTunnel() src_creation_, false); } -bool VxlanTunnel::createTunnel(MAP_T encap, MAP_T decap, uint8_t encap_ttl) -{ - try - { - VxlanTunnelOrch* tunnel_orch = gDirectory.get(); - sai_ip_address_t ips, ipd, *ip=nullptr; - uint8_t mapper_list = 0; - swss::copy(ips, src_ip_); - - // Only a single mapper type is created - - if (decap == MAP_T::VNI_TO_BRIDGE) - { - TUNNELMAP_SET_BRIDGE(mapper_list); - } - else if (decap == MAP_T::VNI_TO_VLAN_ID) - { - TUNNELMAP_SET_VLAN(mapper_list); - } - else - { - TUNNELMAP_SET_VRF(mapper_list); - } - - createMapperHw(mapper_list, (encap == MAP_T::MAP_TO_INVALID) ? - TUNNEL_MAP_USE_DECAP_ONLY: TUNNEL_MAP_USE_DEDICATED_ENCAP_DECAP); - - if (encap != MAP_T::MAP_TO_INVALID) - { - ip = &ips; - } - - ids_.tunnel_id = create_tunnel(&ids_, ip, NULL, gUnderlayIfId, false, encap_ttl); - - if (ids_.tunnel_id != SAI_NULL_OBJECT_ID) - { - tunnel_orch->addTunnelToFlexCounter(ids_.tunnel_id, tunnel_name_); - } - - ip = nullptr; - if (!dst_ip_.isZero()) - { - swss::copy(ipd, dst_ip_); - ip = &ipd; - } - - ids_.tunnel_term_id = create_tunnel_termination(ids_.tunnel_id, ips, ip, gVirtualRouterId); - active_ = true; - tunnel_map_ = { encap, decap }; - } - catch (const std::runtime_error& error) - { - SWSS_LOG_ERROR("Error creating tunnel %s: %s", tunnel_name_.c_str(), error.what()); - // FIXME: add code to remove already created objects - return false; - } - - SWSS_LOG_NOTICE("Vxlan tunnel '%s' was created", tunnel_name_.c_str()); - return true; -} - sai_object_id_t VxlanTunnel::addEncapMapperEntry(sai_object_id_t obj, uint32_t vni, tunnel_map_type_t type) { const auto encap_id = getEncapMapId(type); @@ -1924,20 +1863,18 @@ bool VxlanTunnel::isTunnelReferenced() Port tunnelPort; bool dip_tunnels_used = tunnel_orch->isDipTunnelsSupported(); - ret = gPortsOrch->getPort(port_tunnel_name, tunnelPort); - if (!ret) - { - SWSS_LOG_ERROR("Get port failed for source vtep %s", port_tunnel_name.c_str()); - return false; - } - - if (dip_tunnels_used) { return (getDipTunnelCnt() != 0); } else { + ret = gPortsOrch->getPort(port_tunnel_name, tunnelPort); + if (!ret) + { + SWSS_LOG_ERROR("Get port failed for source vtep %s", port_tunnel_name.c_str()); + return false; + } if (tunnelPort.m_fdb_count != 0) { return true; @@ -2013,19 +1950,21 @@ bool VxlanTunnelMapOrch::addOperation(const Request& request) if (!tunnel_obj->isActive()) { //@Todo, currently only decap mapper is allowed - //tunnel_obj->createTunnel(MAP_T::MAP_TO_INVALID, MAP_T::VNI_TO_VLAN_ID); uint8_t mapper_list = 0; TUNNELMAP_SET_VLAN(mapper_list); TUNNELMAP_SET_VRF(mapper_list); tunnel_obj->createTunnelHw(mapper_list,TUNNEL_MAP_USE_DEDICATED_ENCAP_DECAP); - Port tunPort; - auto src_vtep = tunnel_obj->getSrcIP().to_string(); - if (!tunnel_orch->getTunnelPort(src_vtep, tunPort, true)) + if (!tunnel_orch->isDipTunnelsSupported()) { - auto port_tunnel_name = tunnel_orch->getTunnelPortName(src_vtep, true); - gPortsOrch->addTunnel(port_tunnel_name, tunnel_obj->getTunnelId(), false); - gPortsOrch->getPort(port_tunnel_name,tunPort); - gPortsOrch->addBridgePort(tunPort); + Port tunPort; + auto src_vtep = tunnel_obj->getSrcIP().to_string(); + if (!tunnel_orch->getTunnelPort(src_vtep, tunPort, true)) + { + auto port_tunnel_name = tunnel_orch->getTunnelPortName(src_vtep, true); + gPortsOrch->addTunnel(port_tunnel_name, tunnel_obj->getTunnelId(), false); + gPortsOrch->getPort(port_tunnel_name,tunPort); + gPortsOrch->addBridgePort(tunPort); + } } } @@ -2117,26 +2056,27 @@ bool VxlanTunnelMapOrch::delOperation(const Request& request) auto port_tunnel_name = tunnel_orch->getTunnelPortName(src_vtep, true); bool ret; - ret = gPortsOrch->getPort(port_tunnel_name, tunnelPort); // If there are Dynamic DIP Tunnels referring to this SIP Tunnel // then mark it as pending for delete. if (!tunnel_obj->isTunnelReferenced()) { - if (!ret) + if (!tunnel_orch->isDipTunnelsSupported()) { - SWSS_LOG_ERROR("Get port failed for source vtep %s", port_tunnel_name.c_str()); - return true; + ret = gPortsOrch->getPort(port_tunnel_name, tunnelPort); + if (!ret) + { + SWSS_LOG_ERROR("Get port failed for source vtep %s", port_tunnel_name.c_str()); + return true; + } + ret = gPortsOrch->removeBridgePort(tunnelPort); + if (!ret) + { + SWSS_LOG_ERROR("Remove Bridge port failed for source vtep = %s fdbcount = %d", + port_tunnel_name.c_str(), tunnelPort.m_fdb_count); + return true; + } + gPortsOrch->removeTunnel(tunnelPort); } - ret = gPortsOrch->removeBridgePort(tunnelPort); - if (!ret) - { - SWSS_LOG_ERROR("Remove Bridge port failed for source vtep = %s fdbcount = %d", - port_tunnel_name.c_str(), tunnelPort.m_fdb_count); - return true; - } - - gPortsOrch->removeTunnel(tunnelPort); - uint8_t mapper_list=0; TUNNELMAP_SET_VLAN(mapper_list); TUNNELMAP_SET_VRF(mapper_list); @@ -2152,6 +2092,7 @@ bool VxlanTunnelMapOrch::delOperation(const Request& request) } else { + gPortsOrch->getPort(port_tunnel_name, tunnelPort); SWSS_LOG_WARN("Postponing the SIP Tunnel HW deletion Remote reference count = %d", gPortsOrch->getBridgePortReferenceCount(tunnelPort)); } @@ -2218,7 +2159,22 @@ bool VxlanVrfMapOrch::addOperation(const Request& request) { if (!tunnel_obj->isActive()) { - tunnel_obj->createTunnel(MAP_T::VRID_TO_VNI, MAP_T::VNI_TO_VRID); + uint8_t mapper_list = 0; + TUNNELMAP_SET_VLAN(mapper_list); + TUNNELMAP_SET_VRF(mapper_list); + tunnel_obj->createTunnelHw(mapper_list,TUNNEL_MAP_USE_DEDICATED_ENCAP_DECAP); + if (!tunnel_orch->isDipTunnelsSupported()) + { + Port tunPort; + auto src_vtep = tunnel_obj->getSrcIP().to_string(); + if (!tunnel_orch->getTunnelPort(src_vtep, tunPort, true)) + { + auto port_tunnel_name = tunnel_orch->getTunnelPortName(src_vtep, true); + gPortsOrch->addTunnel(port_tunnel_name, tunnel_obj->getTunnelId(), false); + gPortsOrch->getPort(port_tunnel_name,tunPort); + gPortsOrch->addBridgePort(tunPort); + } + } } vrf_id = vrf_orch->getVRFid(vrf_name); } diff --git a/orchagent/vxlanorch.h b/orchagent/vxlanorch.h index 0b56e76faa56..9529a86ce78a 100644 --- a/orchagent/vxlanorch.h +++ b/orchagent/vxlanorch.h @@ -37,7 +37,7 @@ typedef enum #define IS_TUNNELMAP_SET_BRIDGE(x) ((x)& (1< 0, "Bridgeport entry not created" - assert len(ret) == 1, "More than 1 bridgeport entry created" - self.bridgeport_map[src_ip] = ret[0] + if not ignore_bp: + expected_bridgeport_attributes = { + 'SAI_BRIDGE_PORT_ATTR_TYPE': 'SAI_BRIDGE_PORT_TYPE_TUNNEL', + 'SAI_BRIDGE_PORT_ATTR_TUNNEL_ID': tunnel_id, + 'SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE': 'SAI_BRIDGE_PORT_FDB_LEARNING_MODE_DISABLE', + 'SAI_BRIDGE_PORT_ATTR_ADMIN_STATE': 'true', + } + ret = self.helper.get_key_with_attr(asic_db, self.ASIC_BRIDGE_PORT, expected_bridgeport_attributes) + assert len(ret) > 0, "Bridgeport entry not created" + assert len(ret) == 1, "More than 1 bridgeport entry created" + self.bridgeport_map[src_ip] = ret[0] + self.tunnel_map_ids.update(tunnel_map_id) self.tunnel_ids.add(tunnel_id) self.tunnel_term_ids.add(tunnel_term_id) @@ -797,37 +798,33 @@ def check_vxlan_tunnel_entry(self, dvs, tunnel_name, vnet_name, vni_id): def check_vxlan_tunnel_vrf_map_entry(self, dvs, tunnel_name, vrf_name, vni_id): asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) - if (self.tunnel_map_map.get(tunnel_name) is None): - tunnel_map_id = self.helper.get_created_entries(asic_db, self.ASIC_TUNNEL_MAP, self.tunnel_map_ids, 4) - else: - tunnel_map_id = self.tunnel_map_map[tunnel_name] - tunnel_map_entry_id = self.helper.get_created_entries(asic_db, self.ASIC_TUNNEL_MAP_ENTRY, self.tunnel_map_entry_ids, 3) # check that the vxlan tunnel termination are there assert self.helper.how_many_entries_exist(asic_db, self.ASIC_TUNNEL_MAP_ENTRY) == (len(self.tunnel_map_entry_ids) + 3), "The TUNNEL_MAP_ENTRY is created too early" - self.helper.check_object(asic_db, self.ASIC_TUNNEL_MAP_ENTRY, tunnel_map_entry_id[1], + ret = self.helper.get_key_with_attr(asic_db, self.ASIC_TUNNEL_MAP_ENTRY, { 'SAI_TUNNEL_MAP_ENTRY_ATTR_TUNNEL_MAP_TYPE': 'SAI_TUNNEL_MAP_TYPE_VIRTUAL_ROUTER_ID_TO_VNI', - 'SAI_TUNNEL_MAP_ENTRY_ATTR_TUNNEL_MAP': tunnel_map_id[3], 'SAI_TUNNEL_MAP_ENTRY_ATTR_VIRTUAL_ROUTER_ID_KEY': self.vr_map[vrf_name].get('ing'), 'SAI_TUNNEL_MAP_ENTRY_ATTR_VNI_ID_VALUE': vni_id, } ) - self.tunnel_map_vrf_entry_ids.update(tunnel_map_entry_id[1]) + assert len(ret) == 1, "Invalid number of tunnel map entries for SAI_TUNNEL_MAP_TYPE_VIRTUAL_ROUTER_ID_TO_VNI" + + self.tunnel_map_vrf_entry_ids.update(ret[0]) - self.helper.check_object(asic_db, self.ASIC_TUNNEL_MAP_ENTRY, tunnel_map_entry_id[2], + ret = self.helper.get_key_with_attr(asic_db, self.ASIC_TUNNEL_MAP_ENTRY, { 'SAI_TUNNEL_MAP_ENTRY_ATTR_TUNNEL_MAP_TYPE': 'SAI_TUNNEL_MAP_TYPE_VNI_TO_VIRTUAL_ROUTER_ID', - 'SAI_TUNNEL_MAP_ENTRY_ATTR_TUNNEL_MAP': tunnel_map_id[2], 'SAI_TUNNEL_MAP_ENTRY_ATTR_VNI_ID_KEY': vni_id, 'SAI_TUNNEL_MAP_ENTRY_ATTR_VIRTUAL_ROUTER_ID_VALUE': self.vr_map[vrf_name].get('egr'), } ) - self.tunnel_map_vrf_entry_ids.update(tunnel_map_entry_id[2]) + assert len(ret) == 1, "Invalid number of tunnel map entries for SAI_TUNNEL_MAP_TYPE_VNI_TO_VIRTUAL_ROUTER_ID" + self.tunnel_map_vrf_entry_ids.update(ret[0]) self.tunnel_map_entry_ids.update(tunnel_map_entry_id) def check_vxlan_tunnel_vrf_map_entry_remove(self, dvs, tunnel_name, vrf_name, vni_id): diff --git a/tests/test_evpn_l3_vxlan_p2mp.py b/tests/test_evpn_l3_vxlan_p2mp.py index c704cb3788fe..1bff4cce1e14 100644 --- a/tests/test_evpn_l3_vxlan_p2mp.py +++ b/tests/test_evpn_l3_vxlan_p2mp.py @@ -37,12 +37,12 @@ def test_sip_tunnel_vrf_vni_map(self, dvs, testlog): vxlan_obj.create_vxlan_tunnel(dvs, tunnel_name, '6.6.6.6') vxlan_obj.create_evpn_nvo(dvs, 'nvo1', tunnel_name) - print ("\tCreate Vlan-VNI map and VRF-VNI map") - vxlan_obj.create_vxlan_tunnel_map(dvs, tunnel_name, map_name, '1000', 'Vlan100') - vxlan_obj.create_vrf(dvs, "Vrf-RED") vxlan_obj.create_vxlan_vrf_tunnel_map(dvs, 'Vrf-RED', '1000') + print ("\tCreate Vlan-VNI map and VRF-VNI map") + vxlan_obj.create_vxlan_tunnel_map(dvs, tunnel_name, map_name, '1000', 'Vlan100') + print ("\tTesting VRF-VNI map in APP DB") vlanlist = ['100'] vnilist = ['1000'] @@ -67,7 +67,7 @@ def test_sip_tunnel_vrf_vni_map(self, dvs, testlog): helper.check_object(self.pdb, "VXLAN_VRF_TABLE", "%s:%s" % (tunnel_name, vrf_map_name), exp_attr1) print ("\tTesting SIP Tunnel Creation") - vxlan_obj.check_vxlan_sip_tunnel(dvs, tunnel_name, '6.6.6.6', vlanlist, vnilist) + vxlan_obj.check_vxlan_sip_tunnel(dvs, tunnel_name, '6.6.6.6', vlanlist, vnilist, ignore_bp=False) print ("\tTesting Tunnel Vlan VNI Map Entry") vxlan_obj.check_vxlan_tunnel_map_entry(dvs, tunnel_name, vlanlist, vnilist) @@ -88,7 +88,7 @@ def test_sip_tunnel_vrf_vni_map(self, dvs, testlog): vxlan_obj.remove_vxlan_tunnel(dvs, tunnel_name) vxlan_obj.remove_evpn_nvo(dvs, 'nvo1') time.sleep(2) - vxlan_obj.check_vxlan_sip_tunnel_delete(dvs, tunnel_name, '6.6.6.6') + vxlan_obj.check_vxlan_sip_tunnel_delete(dvs, tunnel_name, '6.6.6.6', ignore_bp=False) vxlan_obj.remove_vlan(dvs, "100") @@ -141,7 +141,7 @@ def test_prefix_route_create_remote_endpoint(self, dvs, testlog): helper.check_object(self.pdb, "VXLAN_VRF_TABLE", "%s:%s" % (tunnel_name, vrf_map_name), exp_attr1) print ("\tTesting SIP Tunnel Creation") - vxlan_obj.check_vxlan_sip_tunnel(dvs, tunnel_name, '6.6.6.6', vlanlist, vnilist) + vxlan_obj.check_vxlan_sip_tunnel(dvs, tunnel_name, '6.6.6.6', vlanlist, vnilist, ignore_bp=False) print ("\tTesting Tunnel Vlan Map Entry") vxlan_obj.check_vxlan_tunnel_map_entry(dvs, tunnel_name, vlanlist, vnilist) @@ -179,7 +179,7 @@ def test_prefix_route_create_remote_endpoint(self, dvs, testlog): vxlan_obj.remove_vxlan_tunnel(dvs, tunnel_name) vxlan_obj.remove_evpn_nvo(dvs, 'nvo1') time.sleep(2) - vxlan_obj.check_vxlan_sip_tunnel_delete(dvs, tunnel_name, '6.6.6.6') + vxlan_obj.check_vxlan_sip_tunnel_delete(dvs, tunnel_name, '6.6.6.6', ignore_bp=False) vxlan_obj.remove_vrf(dvs, "Vrf-RED") vxlan_obj.remove_vlan_member(dvs, "100", "Ethernet24") vxlan_obj.remove_vlan(dvs, "100") @@ -233,7 +233,7 @@ def test_remote_ipv4_routes(self, dvs, testlog): helper.check_object(self.pdb, "VXLAN_VRF_TABLE", "%s:%s" % (tunnel_name, vrf_map_name), exp_attr1) print ("\tTesting SIP Tunnel Creation") - vxlan_obj.check_vxlan_sip_tunnel(dvs, tunnel_name, '6.6.6.6', vlanlist, vnilist) + vxlan_obj.check_vxlan_sip_tunnel(dvs, tunnel_name, '6.6.6.6', vlanlist, vnilist, ignore_bp=False) print ("\tTesting Tunnel Vlan Map Entry") vxlan_obj.check_vxlan_tunnel_map_entry(dvs, tunnel_name, vlanlist, vnilist) @@ -380,7 +380,7 @@ def test_remote_ipv4_routes(self, dvs, testlog): vxlan_obj.remove_vxlan_tunnel(dvs, tunnel_name) vxlan_obj.remove_evpn_nvo(dvs, 'nvo1') time.sleep(2) - vxlan_obj.check_vxlan_sip_tunnel_delete(dvs, tunnel_name, '6.6.6.6') + vxlan_obj.check_vxlan_sip_tunnel_delete(dvs, tunnel_name, '6.6.6.6', ignore_bp=False) vxlan_obj.remove_vrf(dvs, "Vrf-RED") vxlan_obj.remove_vlan_member(dvs, "100", "Ethernet24") vxlan_obj.remove_vlan(dvs, "100") @@ -436,7 +436,7 @@ def test_remote_ipv6_routes(self, dvs, testlog): helper.check_object(self.pdb, "VXLAN_VRF_TABLE", "%s:%s" % (tunnel_name, vrf_map_name), exp_attr1) print ("\tTesting SIP Tunnel Creation") - vxlan_obj.check_vxlan_sip_tunnel(dvs, tunnel_name, '6.6.6.6', vlanlist, vnilist) + vxlan_obj.check_vxlan_sip_tunnel(dvs, tunnel_name, '6.6.6.6', vlanlist, vnilist, ignore_bp=False) print ("\tTesting Tunnel Vlan Map Entry") vxlan_obj.check_vxlan_tunnel_map_entry(dvs, tunnel_name, vlanlist, vnilist) @@ -584,7 +584,7 @@ def test_remote_ipv6_routes(self, dvs, testlog): vxlan_obj.remove_vxlan_tunnel(dvs, tunnel_name) vxlan_obj.remove_evpn_nvo(dvs, 'nvo1') time.sleep(2) - vxlan_obj.check_vxlan_sip_tunnel_delete(dvs, tunnel_name, '6.6.6.6') + vxlan_obj.check_vxlan_sip_tunnel_delete(dvs, tunnel_name, '6.6.6.6', ignore_bp=False) vxlan_obj.remove_vrf(dvs, "Vrf-RED") vxlan_obj.remove_vlan_member(dvs, "100", "Ethernet24") vxlan_obj.remove_vlan(dvs, "100") diff --git a/tests/test_evpn_tunnel_p2mp.py b/tests/test_evpn_tunnel_p2mp.py index f2b3e62ceaa4..22f12f0beb3f 100644 --- a/tests/test_evpn_tunnel_p2mp.py +++ b/tests/test_evpn_tunnel_p2mp.py @@ -30,7 +30,7 @@ def test_p2mp_tunnel(self, dvs, testlog): vnilist = ['1000', '1001', '1002'] print("Testing SIP Tunnel Creation") - vxlan_obj.check_vxlan_sip_tunnel(dvs, tunnel_name, '6.6.6.6', vlanlist, vnilist) + vxlan_obj.check_vxlan_sip_tunnel(dvs, tunnel_name, '6.6.6.6', vlanlist, vnilist, ignore_bp=False) print("Testing Tunnel Map Entry") vxlan_obj.check_vxlan_tunnel_map_entry(dvs, tunnel_name, vlanlist, vnilist) @@ -43,7 +43,7 @@ def test_p2mp_tunnel(self, dvs, testlog): print("Testing SIP Tunnel Deletion") vxlan_obj.remove_vxlan_tunnel(dvs, tunnel_name) - vxlan_obj.check_vxlan_sip_tunnel_delete(dvs, tunnel_name, '6.6.6.6') + vxlan_obj.check_vxlan_sip_tunnel_delete(dvs, tunnel_name, '6.6.6.6', ignore_bp=False) # Test 2 - Vlan extension Tests def test_vlan_extension(self, dvs, testlog): @@ -62,7 +62,7 @@ def test_vlan_extension(self, dvs, testlog): vxlan_obj.create_vxlan_tunnel_map(dvs, tunnel_name, map_name_1, '1001', 'Vlan101') vxlan_obj.create_vxlan_tunnel_map(dvs, tunnel_name, map_name_2, '1002', 'Vlan102') - vxlan_obj.check_vxlan_sip_tunnel(dvs, tunnel_name, '6.6.6.6', vlanlist, vnilist) + vxlan_obj.check_vxlan_sip_tunnel(dvs, tunnel_name, '6.6.6.6', vlanlist, vnilist, ignore_bp=False) vxlan_obj.check_vxlan_tunnel_map_entry(dvs, tunnel_name, vlanlist, vnilist) vxlan_obj.create_evpn_nvo(dvs, 'nvo1', tunnel_name) @@ -121,4 +121,4 @@ def test_vlan_extension(self, dvs, testlog): print("Testing SIP Tunnel Deletion") vxlan_obj.remove_evpn_nvo(dvs, 'nvo1') vxlan_obj.remove_vxlan_tunnel(dvs, tunnel_name) - vxlan_obj.check_vxlan_sip_tunnel_delete(dvs, tunnel_name, '6.6.6.6') + vxlan_obj.check_vxlan_sip_tunnel_delete(dvs, tunnel_name, '6.6.6.6', ignore_bp=False)