From 62e6c5a4d7dc9aeae74d5350e95bd7908203e09b Mon Sep 17 00:00:00 2001 From: Volodymyr Samotiy Date: Wed, 4 Nov 2020 19:11:49 +0200 Subject: [PATCH] [bitmap_vnet] Remove BMTOR implementation (#1494) Because BMTOR implementation is deprecated and now VRF is used instead Signed-off-by: Volodymyr Samotiy --- orchagent/orchdaemon.cpp | 10 +- orchagent/saihelper.cpp | 3 - orchagent/vnetorch.cpp | 1095 ------------------------------------- orchagent/vnetorch.h | 112 ---- tests/test_vnet.py | 281 ---------- tests/test_vnet_bitmap.py | 33 -- 6 files changed, 2 insertions(+), 1532 deletions(-) delete mode 100644 tests/test_vnet_bitmap.py diff --git a/orchagent/orchdaemon.cpp b/orchagent/orchdaemon.cpp index a37469aa5520..2a06c5595234 100644 --- a/orchagent/orchdaemon.cpp +++ b/orchagent/orchdaemon.cpp @@ -103,14 +103,8 @@ bool OrchDaemon::init() }; VNetOrch *vnet_orch; - if (platform == MLNX_PLATFORM_SUBSTRING) - { - vnet_orch = new VNetOrch(m_applDb, APP_VNET_TABLE_NAME, VNET_EXEC::VNET_EXEC_BRIDGE); - } - else - { - vnet_orch = new VNetOrch(m_applDb, APP_VNET_TABLE_NAME); - } + vnet_orch = new VNetOrch(m_applDb, APP_VNET_TABLE_NAME); + gDirectory.set(vnet_orch); VNetCfgRouteOrch *cfg_vnet_rt_orch = new VNetCfgRouteOrch(m_configDb, m_applDb, cfg_vnet_tables); gDirectory.set(cfg_vnet_rt_orch); diff --git a/orchagent/saihelper.cpp b/orchagent/saihelper.cpp index a776ca701d3b..70fc0a9495f4 100644 --- a/orchagent/saihelper.cpp +++ b/orchagent/saihelper.cpp @@ -47,7 +47,6 @@ sai_acl_api_t* sai_acl_api; sai_mirror_api_t* sai_mirror_api; sai_fdb_api_t* sai_fdb_api; sai_dtel_api_t* sai_dtel_api; -sai_bmtor_api_t* sai_bmtor_api; sai_samplepacket_api_t* sai_samplepacket_api; sai_debug_counter_api_t* sai_debug_counter_api; sai_nat_api_t* sai_nat_api; @@ -166,7 +165,6 @@ void initSaiApi() sai_api_query(SAI_API_SCHEDULER_GROUP, (void **)&sai_scheduler_group_api); sai_api_query(SAI_API_ACL, (void **)&sai_acl_api); sai_api_query(SAI_API_DTEL, (void **)&sai_dtel_api); - sai_api_query((sai_api_t)SAI_API_BMTOR, (void **)&sai_bmtor_api); sai_api_query(SAI_API_SAMPLEPACKET, (void **)&sai_samplepacket_api); sai_api_query(SAI_API_DEBUG_COUNTER, (void **)&sai_debug_counter_api); sai_api_query(SAI_API_NAT, (void **)&sai_nat_api); @@ -195,7 +193,6 @@ void initSaiApi() sai_log_set(SAI_API_SCHEDULER_GROUP, SAI_LOG_LEVEL_NOTICE); sai_log_set(SAI_API_ACL, SAI_LOG_LEVEL_NOTICE); sai_log_set(SAI_API_DTEL, SAI_LOG_LEVEL_NOTICE); - sai_log_set((sai_api_t)SAI_API_BMTOR, SAI_LOG_LEVEL_NOTICE); sai_log_set(SAI_API_SAMPLEPACKET, SAI_LOG_LEVEL_NOTICE); sai_log_set(SAI_API_DEBUG_COUNTER, SAI_LOG_LEVEL_NOTICE); sai_log_set((sai_api_t)SAI_API_NAT, SAI_LOG_LEVEL_NOTICE); diff --git a/orchagent/vnetorch.cpp b/orchagent/vnetorch.cpp index e24f31841ac6..efc60d22c256 100644 --- a/orchagent/vnetorch.cpp +++ b/orchagent/vnetorch.cpp @@ -28,7 +28,6 @@ extern sai_router_interface_api_t* sai_router_intfs_api; extern sai_fdb_api_t* sai_fdb_api; extern sai_neighbor_api_t* sai_neighbor_api; extern sai_next_hop_api_t* sai_next_hop_api; -extern sai_bmtor_api_t* sai_bmtor_api; extern sai_object_id_t gSwitchId; extern sai_object_id_t gVirtualRouterId; extern Directory gDirectory; @@ -316,1005 +315,6 @@ VNetVrfObject::~VNetVrfObject() SWSS_LOG_INFO("VNET '%s' deleted ", vnet_name_.c_str()); } -/* - * Bitmap based VNET class definition - */ -std::bitset VNetBitmapObject::vnetBitmap_; -std::bitset VNetBitmapObject::tunnelOffsets_; -std::bitset VNetBitmapObject::tunnelIdOffsets_; -map VNetBitmapObject::vnetIds_; -map VNetBitmapObject::bridgeInfoMap_; -map, VnetNeighInfo> VNetBitmapObject::neighInfoMap_; -map, TunnelEndpointInfo> VNetBitmapObject::endpointMap_; - -VNetBitmapObject::VNetBitmapObject(const std::string& vnet, const VNetInfo& vnetInfo, - vector& attrs) : VNetObject(vnetInfo) -{ - SWSS_LOG_ENTER(); - - vnet_id_ = getFreeBitmapId(vnet); - vnet_name_ = vnet; - - setVniInfo(vnetInfo.vni); -} - -bool VNetBitmapObject::updateObj(vector&) -{ - SWSS_LOG_ENTER(); - - return false; -} - -uint32_t VNetBitmapObject::getFreeBitmapId(const string& vnet) -{ - SWSS_LOG_ENTER(); - - for (uint32_t i = 0; i < vnetBitmap_.size(); i++) - { - uint32_t id = 1 << i; - if (vnetBitmap_[i] == false) - { - vnetBitmap_[i] = true; - vnetIds_.emplace(vnet, id); - return id; - } - } - - return 0; -} - -uint32_t VNetBitmapObject::getBitmapId(const string& vnet) -{ - SWSS_LOG_ENTER(); - - if (vnetIds_.find(vnet) == vnetIds_.end()) - { - return 0; - } - - return vnetIds_[vnet]; -} - -void VNetBitmapObject::recycleBitmapId(const string& vnet) -{ - SWSS_LOG_ENTER(); - - uint32_t id = getBitmapId(vnet); - if (id) - { - vnetBitmap_ &= ~id; - vnetIds_.erase(vnet); - } -} - -uint32_t VNetBitmapObject::getFreeTunnelRouteTableOffset(IpPrefix ipPfx) -{ - SWSS_LOG_ENTER(); - - uint32_t offsetStart = VNET_ROUTE_FULL_MASK_OFFSET_MAX + 1; - uint32_t offsetEnd = tunnelOffsets_.size(); - - if (ipPfx.isFullMask()) - { - offsetStart = 0; - offsetEnd = VNET_ROUTE_FULL_MASK_OFFSET_MAX; - } - - for (uint32_t i = offsetStart; i < offsetEnd; i++) - { - if (tunnelOffsets_[i] == false) - { - tunnelOffsets_[i] = true; - return i; - } - } - - return -1; -} - -void VNetBitmapObject::recycleTunnelRouteTableOffset(uint32_t offset) -{ - SWSS_LOG_ENTER(); - - tunnelOffsets_[offset] = false; -} - -uint16_t VNetBitmapObject::getFreeTunnelId() -{ - SWSS_LOG_ENTER(); - - for (uint16_t i = 1; i < tunnelIdOffsets_.size(); i++) - { - if (tunnelIdOffsets_[i] == false) - { - tunnelIdOffsets_[i] = true; - return i; - } - } - - return 0; -} - -void VNetBitmapObject::recycleTunnelId(uint16_t offset) -{ - SWSS_LOG_ENTER(); - - tunnelIdOffsets_[offset] = false; -} - -VnetBridgeInfo VNetBitmapObject::getBridgeInfoByVni(uint32_t vni, string tunnelName) -{ - SWSS_LOG_ENTER(); - - if (bridgeInfoMap_.find(vni) != bridgeInfoMap_.end()) - { - bridgeInfoMap_.at(vni).use_count++; - - return std::move(bridgeInfoMap_.at(vni)); - } - - sai_status_t status; - VnetBridgeInfo info; - sai_attribute_t attr; - vector bridge_attrs; - attr.id = SAI_BRIDGE_ATTR_TYPE; - attr.value.s32 = SAI_BRIDGE_TYPE_1D; - bridge_attrs.push_back(attr); - - status = sai_bridge_api->create_bridge( - &info.bridge_id, - gSwitchId, - (uint32_t)bridge_attrs.size(), - bridge_attrs.data()); - if (status != SAI_STATUS_SUCCESS) - { - SWSS_LOG_ERROR("Failed to create bridge for vni %u", vni); - throw std::runtime_error("vni creation failed"); - } - - vector rif_attrs; - - attr.id = SAI_ROUTER_INTERFACE_ATTR_VIRTUAL_ROUTER_ID; - attr.value.oid = gVirtualRouterId; - rif_attrs.push_back(attr); - - attr.id = SAI_ROUTER_INTERFACE_ATTR_SRC_MAC_ADDRESS; - memcpy(attr.value.mac, gMacAddress.getMac(), sizeof(sai_mac_t)); - rif_attrs.push_back(attr); - - attr.id = SAI_ROUTER_INTERFACE_ATTR_TYPE; - attr.value.s32 = SAI_ROUTER_INTERFACE_TYPE_BRIDGE; - rif_attrs.push_back(attr); - - attr.id = SAI_ROUTER_INTERFACE_ATTR_BRIDGE_ID; - attr.value.oid = info.bridge_id; - rif_attrs.push_back(attr); - - attr.id = SAI_ROUTER_INTERFACE_ATTR_MTU; - attr.value.u32 = VNET_BITMAP_RIF_MTU; - rif_attrs.push_back(attr); - - status = sai_router_intfs_api->create_router_interface( - &info.rif_id, - gSwitchId, - (uint32_t)rif_attrs.size(), - rif_attrs.data()); - if (status != SAI_STATUS_SUCCESS) - { - SWSS_LOG_ERROR("Failed to create rif for vni %u", vni); - throw std::runtime_error("vni creation failed"); - } - - vector bpr_attrs; - - attr.id = SAI_BRIDGE_PORT_ATTR_TYPE; - attr.value.s32 = SAI_BRIDGE_PORT_TYPE_1D_ROUTER; - bpr_attrs.push_back(attr); - - attr.id = SAI_BRIDGE_PORT_ATTR_RIF_ID; - attr.value.oid = info.rif_id; - bpr_attrs.push_back(attr); - - attr.id = SAI_BRIDGE_PORT_ATTR_BRIDGE_ID; - attr.value.oid = info.bridge_id; - bpr_attrs.push_back(attr); - - attr.id = SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE; - attr.value.s32 = SAI_BRIDGE_PORT_FDB_LEARNING_MODE_DISABLE; - bpr_attrs.push_back(attr); - - status = sai_bridge_api->create_bridge_port( - &info.bridge_port_rif_id, - gSwitchId, - (uint32_t)bpr_attrs.size(), - bpr_attrs.data()); - if (status != SAI_STATUS_SUCCESS) - { - SWSS_LOG_ERROR("Failed to create rif bridge port for vni %u", vni); - throw std::runtime_error("vni creation failed"); - } - - vector bpt_attrs; - auto* vxlan_orch = gDirectory.get(); - auto *tunnel = vxlan_orch->getVxlanTunnel(tunnelName); - - if (!tunnel->isActive()) - { - tunnel->createTunnel(MAP_T::BRIDGE_TO_VNI, MAP_T::VNI_TO_BRIDGE, VXLAN_ENCAP_TTL); - } - - attr.id = SAI_BRIDGE_PORT_ATTR_TYPE; - attr.value.s32 = SAI_BRIDGE_PORT_TYPE_TUNNEL; - bpt_attrs.push_back(attr); - - attr.id = SAI_BRIDGE_PORT_ATTR_BRIDGE_ID; - attr.value.oid = info.bridge_id; - bpt_attrs.push_back(attr); - - attr.id = SAI_BRIDGE_PORT_ATTR_ADMIN_STATE; - attr.value.booldata = true; - bpt_attrs.push_back(attr); - - attr.id = SAI_BRIDGE_PORT_ATTR_TUNNEL_ID; - attr.value.oid = tunnel->getTunnelId(); - bpt_attrs.push_back(attr); - - attr.id = SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE; - attr.value.s32 = SAI_BRIDGE_PORT_FDB_LEARNING_MODE_DISABLE; - bpt_attrs.push_back(attr); - - status = sai_bridge_api->create_bridge_port( - &info.bridge_port_tunnel_id, - gSwitchId, - (uint32_t)bpt_attrs.size(), - bpt_attrs.data()); - if (status != SAI_STATUS_SUCCESS) - { - SWSS_LOG_ERROR("Failed to create tunnel bridge port for vni %u", vni); - throw std::runtime_error("vni creation failed"); - } - - // FIXME: Use "createVxlanTunnelMap()" for tunnel mapper creation - auto tunnelEncapMapperEntry = tunnel->addEncapMapperEntry(info.bridge_id, vni); - tunnel->insertMapperEntry(tunnelEncapMapperEntry, SAI_NULL_OBJECT_ID, vni); - - info.use_count = 1; - bridgeInfoMap_.emplace(vni, info); - - return std::move(info); -} - -bool VNetBitmapObject::clearBridgeInfoByVni(uint32_t vni, string tunnelName) -{ - if (bridgeInfoMap_.find(vni) == bridgeInfoMap_.end()) - { - SWSS_LOG_ERROR("Bridge info doesn't exist for VNI %u", vni); - return false; - } - - auto& bridgeInfo = bridgeInfoMap_.at(vni); - if (bridgeInfo.use_count > 1) - { - bridgeInfo.use_count--; - } - else - { - auto vxlan_orch = gDirectory.get(); - if (!vxlan_orch->removeVxlanTunnelMap(tunnelName, vni)) - { - return false; - } - - sai_status_t status; - - status = sai_bridge_api->remove_bridge_port(bridgeInfo.bridge_port_tunnel_id); - if (status != SAI_STATUS_SUCCESS) - { - SWSS_LOG_ERROR("Failed to remove tunnel bridge port for VNI %u, SAI rc: %d", vni, status); - return false; - } - - status = sai_bridge_api->remove_bridge_port(bridgeInfo.bridge_port_rif_id); - if (status != SAI_STATUS_SUCCESS) - { - SWSS_LOG_ERROR("Failed to remove RIF bridge port for VNI %u, SAI rc: %d", vni, status); - return false; - } - - status = sai_router_intfs_api->remove_router_interface(bridgeInfo.rif_id); - if (status != SAI_STATUS_SUCCESS) - { - SWSS_LOG_ERROR("Failed to remove RIF for VNI %u, SAI rc: %d",vni, status); - return false; - } - - status = sai_bridge_api->remove_bridge(bridgeInfo.bridge_id); - if (status != SAI_STATUS_SUCCESS) - { - SWSS_LOG_ERROR("Failed to remove bridge for VNI %u, SAI rc: %d", vni, status); - return false; - } - - bridgeInfoMap_.erase(vni); - } - - return true; -} - -bool VNetBitmapObject::clearNeighInfo(MacAddress mac, sai_object_id_t bridge) -{ - auto macBridge = make_tuple(mac, bridge); - - if (neighInfoMap_.find(macBridge) == neighInfoMap_.end()) - { - SWSS_LOG_ERROR("VNET neighbor doesn't exist"); - return false; - } - - if (neighInfoMap_.at(macBridge).use_count > 1) - { - neighInfoMap_.at(macBridge).use_count--; - } - else - { - sai_status_t status; - - status = sai_neighbor_api->remove_neighbor_entry(&neighInfoMap_.at(macBridge).neigh_entry); - if (status != SAI_STATUS_SUCCESS) - { - SWSS_LOG_ERROR("Failed to remove neighbor entry, SAI rc: %d", status); - return false; - } - - status = sai_fdb_api->remove_fdb_entry(&neighInfoMap_.at(macBridge).fdb_entry); - if (status != SAI_STATUS_SUCCESS) - { - SWSS_LOG_ERROR("Failed to remove FDB entry, SAI rc: %d", status); - return false; - } - - neighInfoMap_.erase(macBridge); - } - - return true; -} - -void VNetBitmapObject::setVniInfo(uint32_t vni) -{ - sai_attribute_t attr; - vector vnet_attrs; - auto info = getBridgeInfoByVni(getVni(), getTunnelName()); - - attr.id = SAI_TABLE_BITMAP_CLASSIFICATION_ENTRY_ATTR_ACTION; - attr.value.s32 = SAI_TABLE_BITMAP_CLASSIFICATION_ENTRY_ACTION_SET_METADATA; - vnet_attrs.push_back(attr); - - attr.id = SAI_TABLE_BITMAP_CLASSIFICATION_ENTRY_ATTR_ROUTER_INTERFACE_KEY; - attr.value.oid = info.rif_id; - vnet_attrs.push_back(attr); - - attr.id = SAI_TABLE_BITMAP_CLASSIFICATION_ENTRY_ATTR_IN_RIF_METADATA; - attr.value.u32 = vnet_id_; - vnet_attrs.push_back(attr); - - sai_status_t status = sai_bmtor_api->create_table_bitmap_classification_entry( - &vnetTableEntryId_, - gSwitchId, - (uint32_t)vnet_attrs.size(), - vnet_attrs.data()); - - if (status != SAI_STATUS_SUCCESS) - { - SWSS_LOG_ERROR("Failed to create VNET table entry, SAI rc: %d", status); - throw std::runtime_error("VNet interface creation failed"); - } -} - -bool VNetBitmapObject::addIntf(const string& alias, const IpPrefix *prefix) -{ - SWSS_LOG_ENTER(); - - sai_attribute_t attr; - vector vnet_attrs; - vector route_attrs; - sai_status_t status; - uint32_t peerBitmap = vnet_id_; - - if (prefix && !prefix->isV4()) - { - return false; - } - - for (const auto& vnet : getPeerList()) - { - uint32_t id = getBitmapId(vnet); - if (id == 0) - { - SWSS_LOG_WARN("Peer vnet %s not ready", vnet.c_str()); - return false; - } - peerBitmap |= id; - } - - if (gIntfsOrch->getSyncdIntfses().find(alias) == gIntfsOrch->getSyncdIntfses().end()) - { - if (intfMap_.find(alias) != intfMap_.end()) - { - SWSS_LOG_ERROR("VNET '%s' interface '%s' already exists", getVnetName().c_str(), alias.c_str()); - return false; - } - - if (!gIntfsOrch->setIntf(alias, gVirtualRouterId, nullptr)) - { - return false; - } - - VnetIntfInfo intfInfo; - - attr.id = SAI_TABLE_BITMAP_CLASSIFICATION_ENTRY_ATTR_ACTION; - attr.value.s32 = SAI_TABLE_BITMAP_CLASSIFICATION_ENTRY_ACTION_SET_METADATA; - vnet_attrs.push_back(attr); - - attr.id = SAI_TABLE_BITMAP_CLASSIFICATION_ENTRY_ATTR_ROUTER_INTERFACE_KEY; - attr.value.oid = gIntfsOrch->getRouterIntfsId(alias); - vnet_attrs.push_back(attr); - - attr.id = SAI_TABLE_BITMAP_CLASSIFICATION_ENTRY_ATTR_IN_RIF_METADATA; - attr.value.u32 = vnet_id_; - vnet_attrs.push_back(attr); - - status = sai_bmtor_api->create_table_bitmap_classification_entry( - &intfInfo.vnetTableEntryId, - gSwitchId, - (uint32_t)vnet_attrs.size(), - vnet_attrs.data()); - - if (status != SAI_STATUS_SUCCESS) - { - SWSS_LOG_ERROR("Failed to create VNET table entry, SAI rc: %d", status); - throw std::runtime_error("VNet interface creation failed"); - } - - intfMap_.emplace(alias, intfInfo); - } - - if (prefix && gIntfsOrch->updateSyncdIntfPfx(alias, *prefix)) - { - gIntfsOrch->addIp2MeRoute(gVirtualRouterId, *prefix); - } - - return true; -} - -bool VNetBitmapObject::removeIntf(const string& alias, const IpPrefix *prefix) -{ - SWSS_LOG_ENTER(); - - sai_status_t status; - - if (intfMap_.find(alias) == intfMap_.end()) - { - SWSS_LOG_ERROR("VNET '%s' interface '%s' doesn't exist", getVnetName().c_str(), alias.c_str()); - return false; - } - - auto& intf = intfMap_.at(alias); - - if (prefix && gIntfsOrch->updateSyncdIntfPfx(alias, *prefix, false)) - { - gIntfsOrch->removeIp2MeRoute(gVirtualRouterId, *prefix); - } - - status = sai_bmtor_api->remove_table_bitmap_classification_entry(intf.vnetTableEntryId); - if (status != SAI_STATUS_SUCCESS) - { - SWSS_LOG_ERROR("Failed to remove VNET table entry, SAI rc: %d", status); - throw std::runtime_error("VNET interface removal failed"); - } - - if (!prefix) - { - intfMap_.erase(alias); - - if (!gIntfsOrch->removeIntf(alias, gVirtualRouterId, nullptr)) - { - return false; - } - } - - return true; -} - -uint32_t VNetBitmapObject::getFreeNeighbor(void) -{ - static set neighbors; - - for (uint32_t i = 0; i < VNET_NEIGHBOR_MAX; i++) - { - if (neighbors.count(i) == 0) - { - neighbors.insert(i); - return i; - } - } - - SWSS_LOG_ERROR("No neighbors left"); - throw std::runtime_error("VNet route creation failed"); -} - -bool VNetBitmapObject::addTunnelRoute(IpPrefix& ipPrefix, tunnelEndpoint& endp) -{ - SWSS_LOG_ENTER(); - - sai_status_t status; - sai_attribute_t attr; - auto& peer_list = getPeerList(); - auto bInfo = getBridgeInfoByVni(endp.vni == 0 ? getVni() : endp.vni, getTunnelName()); - uint32_t peerBitmap = vnet_id_; - MacAddress mac = endp.mac ? endp.mac : gVxlanMacAddress; - TunnelRouteInfo tunnelRouteInfo; - sai_ip_address_t underlayAddr; - copy(underlayAddr, endp.ip); - - if (tunnelRouteMap_.find(ipPrefix) != tunnelRouteMap_.end()) - { - SWSS_LOG_WARN("VNET tunnel route %s exists", ipPrefix.to_string().c_str()); - return true; - } - - VNetOrch* vnet_orch = gDirectory.get(); - for (auto peer : peer_list) - { - if (!vnet_orch->isVnetExists(peer)) - { - SWSS_LOG_INFO("Peer VNET %s not yet created", peer.c_str()); - return false; - } - peerBitmap |= getBitmapId(peer); - } - - auto macBridge = make_tuple(mac, bInfo.bridge_id); - if (neighInfoMap_.find(macBridge) == neighInfoMap_.end()) - { - VnetNeighInfo neighInfo; - - /* FDB entry to the tunnel */ - vector fdb_attrs; - neighInfo.fdb_entry.switch_id = gSwitchId; - mac.getMac(neighInfo.fdb_entry.mac_address); - neighInfo.fdb_entry.bv_id = bInfo.bridge_id; - - attr.id = SAI_FDB_ENTRY_ATTR_TYPE; - attr.value.s32 = SAI_FDB_ENTRY_TYPE_STATIC; - fdb_attrs.push_back(attr); - - attr.id = SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID; - attr.value.oid = bInfo.bridge_port_rif_id; - fdb_attrs.push_back(attr); - - attr.id = SAI_FDB_ENTRY_ATTR_PACKET_ACTION; - attr.value.s32 = SAI_PACKET_ACTION_FORWARD; - fdb_attrs.push_back(attr); - - status = sai_fdb_api->create_fdb_entry( - &neighInfo.fdb_entry, - (uint32_t)fdb_attrs.size(), - fdb_attrs.data()); - if (status != SAI_STATUS_SUCCESS) - { - SWSS_LOG_ERROR("Failed to create fdb entry for tunnel, SAI rc: %d", status); - throw std::runtime_error("VNet route creation failed"); - } - - /* Fake neighbor */ - neighInfo.neigh_entry.switch_id = gSwitchId; - neighInfo.neigh_entry.rif_id = bInfo.rif_id; - neighInfo.neigh_entry.ip_address.addr_family = SAI_IP_ADDR_FAMILY_IPV4; - neighInfo.neigh_entry.ip_address.addr.ip4 = htonl(getFreeNeighbor()); - - vector n_attrs; - attr.id = SAI_NEIGHBOR_ENTRY_ATTR_DST_MAC_ADDRESS; - mac.getMac(attr.value.mac); - n_attrs.push_back(attr); - - status = sai_neighbor_api->create_neighbor_entry( - &neighInfo.neigh_entry, - (uint32_t)n_attrs.size(), - n_attrs.data()); - if (status != SAI_STATUS_SUCCESS) - { - SWSS_LOG_ERROR("Failed to create neighbor entry for tunnel, SAI rc: %d", status); - throw std::runtime_error("VNet route creation failed"); - } - - neighInfo.use_count = 1; - neighInfoMap_.emplace(macBridge, neighInfo); - } - else - { - neighInfoMap_.at(macBridge).use_count++; - } - - /* Nexthop */ - vector nh_attrs; - - attr.id = SAI_NEXT_HOP_ATTR_TYPE; - attr.value.s32 = SAI_NEXT_HOP_TYPE_IP; - nh_attrs.push_back(attr); - - attr.id = SAI_NEXT_HOP_ATTR_IP; - attr.value.ipaddr = neighInfoMap_.at(macBridge).neigh_entry.ip_address; - nh_attrs.push_back(attr); - - attr.id = SAI_NEXT_HOP_ATTR_ROUTER_INTERFACE_ID; - attr.value.oid = bInfo.rif_id; - nh_attrs.push_back(attr); - - status = sai_next_hop_api->create_next_hop( - &tunnelRouteInfo.nexthopId, - gSwitchId, - (uint32_t)nh_attrs.size(), - nh_attrs.data()); - if (status != SAI_STATUS_SUCCESS) - { - SWSS_LOG_ERROR("Failed to create nexthop for tunnel, SAI rc: %d", status); - throw std::runtime_error("VNet route creation failed"); - } - - /* Tunnel endpoint */ - VxlanTunnelOrch* vxlan_orch = gDirectory.get(); - auto *tunnel = vxlan_orch->getVxlanTunnel(getTunnelName()); - auto endpoint = make_tuple(endp.ip, tunnel->getTunnelId()); - uint16_t tunnelIndex = 0; - TunnelEndpointInfo endpointInfo; - if (endpointMap_.find(endpoint) == endpointMap_.end()) - { - tunnelIndex = getFreeTunnelId(); - vector vxlan_attrs; - - attr.id = SAI_TABLE_META_TUNNEL_ENTRY_ATTR_ACTION; - attr.value.s32 = SAI_TABLE_META_TUNNEL_ENTRY_ACTION_TUNNEL_ENCAP; - vxlan_attrs.push_back(attr); - - attr.id = SAI_TABLE_META_TUNNEL_ENTRY_ATTR_METADATA_KEY; - attr.value.u16 = tunnelIndex; - vxlan_attrs.push_back(attr); - - attr.id = SAI_TABLE_META_TUNNEL_ENTRY_ATTR_UNDERLAY_DIP; - attr.value.ipaddr = underlayAddr; - vxlan_attrs.push_back(attr); - - attr.id = SAI_TABLE_META_TUNNEL_ENTRY_ATTR_TUNNEL_ID; - attr.value.oid = tunnel->getTunnelId(); - vxlan_attrs.push_back(attr); - - status = sai_bmtor_api->create_table_meta_tunnel_entry( - &endpointInfo.metaTunnelEntryId, - gSwitchId, - (uint32_t)vxlan_attrs.size(), - vxlan_attrs.data()); - - if (status != SAI_STATUS_SUCCESS) - { - SWSS_LOG_ERROR("Failed to create L3 VXLAN entry, SAI rc: %d", status); - throw std::runtime_error("VNet route creation failed"); - } - - endpointInfo.tunnelIndex = tunnelIndex; - endpointInfo.use_count = 1; - endpointMap_.emplace(endpoint, endpointInfo); - } - else - { - tunnelIndex = endpointMap_.at(endpoint).tunnelIndex; - endpointMap_.at(endpoint).use_count++; - } - - /* Tunnel route */ - vector tr_attrs; - sai_ip_prefix_t pfx; - copy(pfx, ipPrefix); - - attr.id = SAI_TABLE_BITMAP_ROUTER_ENTRY_ATTR_ACTION; - attr.value.s32 = SAI_TABLE_BITMAP_ROUTER_ENTRY_ACTION_TO_NEXTHOP; - tr_attrs.push_back(attr); - - tunnelRouteInfo.offset = getFreeTunnelRouteTableOffset(ipPrefix); - attr.id = SAI_TABLE_BITMAP_ROUTER_ENTRY_ATTR_PRIORITY; - attr.value.u32 = tunnelRouteInfo.offset; - tr_attrs.push_back(attr); - - attr.id = SAI_TABLE_BITMAP_ROUTER_ENTRY_ATTR_IN_RIF_METADATA_KEY; - attr.value.u64 = 0; - tr_attrs.push_back(attr); - - attr.id = SAI_TABLE_BITMAP_ROUTER_ENTRY_ATTR_IN_RIF_METADATA_MASK; - attr.value.u64 = ~peerBitmap; - tr_attrs.push_back(attr); - - attr.id = SAI_TABLE_BITMAP_ROUTER_ENTRY_ATTR_DST_IP_KEY; - attr.value.ipprefix = pfx; - tr_attrs.push_back(attr); - - attr.id = SAI_TABLE_BITMAP_ROUTER_ENTRY_ATTR_NEXT_HOP; - attr.value.oid = tunnelRouteInfo.nexthopId; - tr_attrs.push_back(attr); - - attr.id = SAI_TABLE_BITMAP_ROUTER_ENTRY_ATTR_TUNNEL_INDEX; - attr.value.u16 = tunnelIndex; - tr_attrs.push_back(attr); - - status = sai_bmtor_api->create_table_bitmap_router_entry( - &tunnelRouteInfo.tunnelRouteTableEntryId, - gSwitchId, - (uint32_t)tr_attrs.size(), - tr_attrs.data()); - - if (status != SAI_STATUS_SUCCESS) - { - SWSS_LOG_ERROR("Failed to create local VNET route entry, SAI rc: %d", status); - throw std::runtime_error("VNet route creation failed"); - } - - tunnelRouteInfo.vni = endp.vni == 0 ? getVni() : endp.vni; - tunnelRouteInfo.mac = mac; - tunnelRouteInfo.ip = endp.ip; - tunnelRouteInfo.tunnelId = tunnel->getTunnelId(); - tunnelRouteMap_.emplace(ipPrefix, tunnelRouteInfo); - - return true; -} - -bool VNetBitmapObject::removeTunnelRoute(IpPrefix& ipPrefix) -{ - SWSS_LOG_ENTER(); - - if (tunnelRouteMap_.find(ipPrefix) == tunnelRouteMap_.end()) - { - SWSS_LOG_WARN("VNET tunnel route %s doesn't exist", ipPrefix.to_string().c_str()); - return true; - } - - auto tunnelRouteInfo = tunnelRouteMap_.at(ipPrefix); - - if (bridgeInfoMap_.find(tunnelRouteInfo.vni) == bridgeInfoMap_.end()) - { - SWSS_LOG_ERROR("VNET bridge doesn't exist for tunnel route %s", ipPrefix.to_string().c_str()); - throw std::runtime_error("VNET tunnel route removal failed"); - } - - auto bridgeInfo = bridgeInfoMap_.at(tunnelRouteInfo.vni); - auto macBridge = make_tuple(tunnelRouteInfo.mac, bridgeInfo.bridge_id); - - if (neighInfoMap_.find(macBridge) == neighInfoMap_.end()) - { - SWSS_LOG_ERROR("VNET neighbor doesn't exist for tunnel route %s", ipPrefix.to_string().c_str()); - throw std::runtime_error("VNET tunnel route removal failed"); - } - - auto endpoint = make_tuple(tunnelRouteInfo.ip, tunnelRouteInfo.tunnelId); - - if (endpointMap_.find(endpoint) == endpointMap_.end()) - { - SWSS_LOG_ERROR("Tunnel endpoint doesn't exist for tunnel route %s", ipPrefix.to_string().c_str()); - throw std::runtime_error("VNET tunnel route removal failed"); - } - - auto& endpointInfo = endpointMap_.at(endpoint); - - sai_status_t status; - - status = sai_bmtor_api->remove_table_bitmap_router_entry(tunnelRouteInfo.tunnelRouteTableEntryId); - if (status != SAI_STATUS_SUCCESS) - { - SWSS_LOG_ERROR("Failed to remove VNET tunnel route entry, SAI rc: %d", status); - throw std::runtime_error("VNET tunnel route removal failed"); - } - - if (endpointInfo.use_count > 1) - { - endpointInfo.use_count--; - } - else - { - status = sai_bmtor_api->remove_table_meta_tunnel_entry(endpointInfo.metaTunnelEntryId); - if (status != SAI_STATUS_SUCCESS) - { - SWSS_LOG_ERROR("Failed to remove meta tunnel entry for VNET tunnel route, SAI rc: %d", status); - throw std::runtime_error("VNET tunnel route removal failed"); - } - - recycleTunnelId(endpointInfo.tunnelIndex); - endpointMap_.erase(endpoint); - } - - status = sai_next_hop_api->remove_next_hop(tunnelRouteInfo.nexthopId); - if (status != SAI_STATUS_SUCCESS) - { - SWSS_LOG_ERROR("Failed to remove nexthop entry for VNET tunnel route, SAI rc: %d", status); - throw std::runtime_error("VNET tunnel route removal failed"); - } - - if (!clearNeighInfo(tunnelRouteInfo.mac, bridgeInfo.bridge_id)) - { - throw std::runtime_error("VNET tunnel route removal failed"); - } - - if (!clearBridgeInfoByVni(tunnelRouteInfo.vni, getTunnelName())) - { - throw std::runtime_error("VNET tunnel route removal failed"); - } - - recycleTunnelRouteTableOffset(tunnelRouteInfo.offset); - tunnelRouteMap_.erase(ipPrefix); - - return true; -} - -bool VNetBitmapObject::addRoute(IpPrefix& ipPrefix, nextHop& nh) -{ - SWSS_LOG_ENTER(); - - sai_status_t status; - sai_attribute_t attr; - vector attrs; - sai_ip_prefix_t pfx; - sai_object_id_t nh_id = SAI_NULL_OBJECT_ID; - uint32_t peerBitmap = vnet_id_; - Port port; - RouteInfo routeInfo; - - if (routeMap_.find(ipPrefix) != routeMap_.end()) - { - SWSS_LOG_WARN("VNET route %s exists", ipPrefix.to_string().c_str()); - return true; - } - - bool is_subnet = (!nh.ips.getSize() || nh.ips.contains("0.0.0.0")) ? true : false; - - if (is_subnet && (!gPortsOrch->getPort(nh.ifname, port) || (port.m_rif_id == SAI_NULL_OBJECT_ID))) - { - SWSS_LOG_WARN("Port/RIF %s doesn't exist", nh.ifname.c_str()); - return false; - } - - for (const auto& vnet : getPeerList()) - { - uint32_t id = getBitmapId(vnet); - if (id == 0) - { - SWSS_LOG_WARN("Peer vnet %s not ready", vnet.c_str()); - return false; - } - peerBitmap |= id; - } - - /* Local route */ - copy(pfx, ipPrefix); - - if (is_subnet) - { - attr.id = SAI_TABLE_BITMAP_ROUTER_ENTRY_ATTR_ACTION; - attr.value.s32 = SAI_TABLE_BITMAP_ROUTER_ENTRY_ACTION_TO_LOCAL; - attrs.push_back(attr); - - attr.id = SAI_TABLE_BITMAP_ROUTER_ENTRY_ATTR_ROUTER_INTERFACE; - attr.value.oid = port.m_rif_id; - attrs.push_back(attr); - } - else if (nh.ips.getSize() == 1) - { - NextHopKey nexthop(nh.ips.to_string(), nh.ifname); - if (gNeighOrch->hasNextHop(nexthop)) - { - nh_id = gNeighOrch->getNextHopId(nexthop); - } - else - { - SWSS_LOG_INFO("Failed to get next hop %s for %s", - nexthop.to_string().c_str(), ipPrefix.to_string().c_str()); - return false; - } - - attr.id = SAI_TABLE_BITMAP_ROUTER_ENTRY_ATTR_ACTION; - attr.value.s32 = SAI_TABLE_BITMAP_ROUTER_ENTRY_ACTION_TO_NEXTHOP; - attrs.push_back(attr); - - attr.id = SAI_TABLE_BITMAP_ROUTER_ENTRY_ATTR_NEXT_HOP; - attr.value.oid = nh_id; - attrs.push_back(attr); - - attr.id = SAI_TABLE_BITMAP_ROUTER_ENTRY_ATTR_TUNNEL_INDEX; - attr.value.u16 = 0; - attrs.push_back(attr); - - } - else - { - /* FIXME - Handle ECMP routes */ - SWSS_LOG_WARN("VNET ECMP NHs not implemented for '%s'", ipPrefix.to_string().c_str()); - return true; - } - - routeInfo.offset = getFreeTunnelRouteTableOffset(ipPrefix); - attr.id = SAI_TABLE_BITMAP_ROUTER_ENTRY_ATTR_PRIORITY; - attr.value.u32 = routeInfo.offset; - attrs.push_back(attr); - - attr.id = SAI_TABLE_BITMAP_ROUTER_ENTRY_ATTR_IN_RIF_METADATA_KEY; - attr.value.u64 = 0; - attrs.push_back(attr); - - attr.id = SAI_TABLE_BITMAP_ROUTER_ENTRY_ATTR_IN_RIF_METADATA_MASK; - attr.value.u64 = ~peerBitmap; - attrs.push_back(attr); - - attr.id = SAI_TABLE_BITMAP_ROUTER_ENTRY_ATTR_DST_IP_KEY; - attr.value.ipprefix = pfx; - attrs.push_back(attr); - - status = sai_bmtor_api->create_table_bitmap_router_entry( - &routeInfo.routeTableEntryId, - gSwitchId, - (uint32_t)attrs.size(), - attrs.data()); - - if (status != SAI_STATUS_SUCCESS) - { - SWSS_LOG_ERROR("Failed to create local VNET route entry, SAI rc: %d", status); - throw std::runtime_error("VNet route creation failed"); - } - - routeMap_.emplace(ipPrefix, routeInfo); - - return true; -} - -bool VNetBitmapObject::removeRoute(IpPrefix& ipPrefix) -{ - SWSS_LOG_ENTER(); - - if (routeMap_.find(ipPrefix) == routeMap_.end()) - { - SWSS_LOG_WARN("VNET route %s doesn't exist", ipPrefix.to_string().c_str()); - return true; - } - - sai_status_t status = sai_bmtor_api->remove_table_bitmap_router_entry(routeMap_.at(ipPrefix).routeTableEntryId); - if (status != SAI_STATUS_SUCCESS) - { - SWSS_LOG_ERROR("Failed to remove VNET route entry, SAI rc: %d", status); - throw std::runtime_error("VNET route removal failed"); - } - - recycleTunnelRouteTableOffset(routeMap_.at(ipPrefix).offset); - - routeMap_.erase(ipPrefix); - - return true; -} - -VNetBitmapObject::~VNetBitmapObject() -{ - sai_status_t status; - - status = sai_bmtor_api->remove_table_bitmap_classification_entry(vnetTableEntryId_); - if (status != SAI_STATUS_SUCCESS) - { - SWSS_LOG_ERROR("Failed to remove VNET '%s' table entry, SAI rc: %d", getVnetName().c_str(), status); - throw std::runtime_error("VNET removal failed"); - } - - if (!clearBridgeInfoByVni(getVni(), getTunnelName())) - { - throw std::runtime_error("VNET removal failed"); - } - - recycleBitmapId(getVnetName()); - - SWSS_LOG_INFO("VNET '%s' deleted ", getVnetName().c_str()); -} - /* * VNet Orch class definitions */ @@ -1359,11 +359,6 @@ bool VNetOrch::setIntf(const string& alias, const string name, const IpPrefix *p return gIntfsOrch->setIntf(alias, vrf_id, prefix, adminUp, mtu); } - else - { - auto *vnet_obj = getTypePtr(name); - return vnet_obj->addIntf(alias, prefix); - } return false; } @@ -1385,11 +380,6 @@ bool VNetOrch::delIntf(const string& alias, const string name, const IpPrefix *p return gIntfsOrch->removeIntf(alias, vrf_id, prefix); } - else - { - auto *vnet_obj = getTypePtr(name); - return vnet_obj->removeIntf(alias, prefix); - } return true; } @@ -1478,23 +468,6 @@ bool VNetOrch::addOperation(const Request& request) SWSS_LOG_NOTICE("VNET '%s' already exists ", vnet_name.c_str()); } } - else - { - VxlanTunnelOrch* vxlan_orch = gDirectory.get(); - - if (!vxlan_orch->isTunnelExists(tunnel)) - { - SWSS_LOG_WARN("Vxlan tunnel '%s' doesn't exist", tunnel.c_str()); - return false; - } - - if (it == std::end(vnet_table_)) - { - VNetInfo vnet_info = { tunnel, vni, peer_list, scope }; - obj = createObject(vnet_name, vnet_info, attrs); - create = true; - } - } if (create) { @@ -1557,16 +530,6 @@ bool VNetOrch::delOperation(const Request& request) return false; } } - else - { - auto vnet_obj = dynamic_cast(it->second.get()); - - if (vnet_obj->getRouteCount()) - { - SWSS_LOG_ERROR("VNET '%s': Routes are still present", vnet_name.c_str()); - return false; - } - } } catch(std::runtime_error& _) { @@ -1839,56 +802,6 @@ bool VNetRouteOrch::doRouteTask(const string& vnet, IpPrefix& ipP return true; } -template<> -bool VNetRouteOrch::doRouteTask(const string& vnet, IpPrefix& ipPrefix, tunnelEndpoint& endp, string& op) -{ - SWSS_LOG_ENTER(); - - if (!vnet_orch_->isVnetExists(vnet)) - { - SWSS_LOG_WARN("VNET %s doesn't exist", vnet.c_str()); - return (op == DEL_COMMAND) ? true : false; - } - - auto *vnet_obj = vnet_orch_->getTypePtr(vnet); - - if (op == SET_COMMAND) - { - return vnet_obj->addTunnelRoute(ipPrefix, endp); - } - else - { - return vnet_obj->removeTunnelRoute(ipPrefix); - } - - return true; -} - -template<> -bool VNetRouteOrch::doRouteTask(const string& vnet, IpPrefix& ipPrefix, nextHop& nh, string& op) -{ - SWSS_LOG_ENTER(); - - if (!vnet_orch_->isVnetExists(vnet)) - { - SWSS_LOG_WARN("VNET %s doesn't exist", vnet.c_str()); - return (op == DEL_COMMAND) ? true : false; - } - - auto *vnet_obj = vnet_orch_->getTypePtr(vnet); - - if (op == SET_COMMAND) - { - return vnet_obj->addRoute(ipPrefix, nh); - } - else - { - return vnet_obj->removeRoute(ipPrefix); - } - - return true; -} - bool VNetRouteOrch::handleRoutes(const Request& request) { SWSS_LOG_ENTER(); @@ -1935,10 +848,6 @@ bool VNetRouteOrch::handleRoutes(const Request& request) { return doRouteTask(vnet_name, ip_pfx, nh, op); } - else - { - return doRouteTask(vnet_name, ip_pfx, nh, op); - } return true; } @@ -2170,10 +1079,6 @@ bool VNetRouteOrch::handleTunnel(const Request& request) { return doRouteTask(vnet_name, ip_pfx, endp, op); } - else - { - return doRouteTask(vnet_name, ip_pfx, endp, op); - } return true; } diff --git a/orchagent/vnetorch.h b/orchagent/vnetorch.h index 6d24bb5201bd..2ca48ec3a0e3 100644 --- a/orchagent/vnetorch.h +++ b/orchagent/vnetorch.h @@ -188,118 +188,6 @@ class VNetVrfObject : public VNetObject RouteMap routes_; }; -struct VnetBridgeInfo -{ - sai_object_id_t bridge_id; - sai_object_id_t bridge_port_rif_id; - sai_object_id_t bridge_port_tunnel_id; - sai_object_id_t rif_id; - uint32_t use_count; -}; - -struct VnetNeighInfo -{ - sai_fdb_entry_t fdb_entry; - sai_neighbor_entry_t neigh_entry; - uint32_t use_count; -}; - -struct TunnelRouteInfo -{ - sai_object_id_t tunnelRouteTableEntryId; - sai_object_id_t nexthopId; - sai_object_id_t tunnelId; - uint32_t vni; - MacAddress mac; - IpAddress ip; - uint32_t offset; -}; - -struct RouteInfo -{ - sai_object_id_t routeTableEntryId; - uint32_t offset; -}; - -struct VnetIntfInfo -{ - sai_object_id_t vnetTableEntryId; -}; - - -struct TunnelEndpointInfo -{ - sai_object_id_t metaTunnelEntryId; - uint16_t tunnelIndex; - uint32_t use_count; -}; - -class VNetBitmapObject: public VNetObject -{ -public: - VNetBitmapObject(const string& vnet, const VNetInfo& vnetInfo, vector& attrs); - - bool addIntf(const string& alias, const IpPrefix *prefix); - bool removeIntf(const string& alias, const IpPrefix *prefix); - - bool addTunnelRoute(IpPrefix& ipPrefix, tunnelEndpoint& endp); - bool removeTunnelRoute(IpPrefix& ipPrefix); - - bool addRoute(IpPrefix& ipPrefix, nextHop& nh); - bool removeRoute(IpPrefix& ipPrefix); - - void setVniInfo(uint32_t vni); - - bool updateObj(vector&); - - size_t getRouteCount() const - { - return (routeMap_.size() + tunnelRouteMap_.size()); - } - - string getVnetName() const - { - return vnet_name_; - } - - ~VNetBitmapObject(); - -private: - static uint32_t getFreeBitmapId(const string& name); - static uint32_t getBitmapId(const string& name); - static void recycleBitmapId(const string& name); - - static uint32_t getFreeTunnelRouteTableOffset(IpPrefix ipPfx); - static void recycleTunnelRouteTableOffset(uint32_t offset); - - static uint16_t getFreeTunnelId(); - - static void recycleTunnelId(uint16_t offset); - - static VnetBridgeInfo getBridgeInfoByVni(uint32_t vni, string tunnelName); - static bool clearBridgeInfoByVni(uint32_t vni, string tunnelName); - - static bool clearNeighInfo(MacAddress mac, sai_object_id_t bridge); - - static uint32_t getFreeNeighbor(void); - - static std::bitset vnetBitmap_; - static map vnetIds_; - static std::bitset tunnelOffsets_; - static std::bitset tunnelIdOffsets_; - static map bridgeInfoMap_; - static map, VnetNeighInfo> neighInfoMap_; - static map, TunnelEndpointInfo> endpointMap_; - - map routeMap_; - map tunnelRouteMap_; - map intfMap_; - - uint32_t vnet_id_; - string vnet_name_; - sai_object_id_t vnetTableEntryId_; -}; - typedef std::unique_ptr VNetObject_T; typedef std::unordered_map VNetTable; diff --git a/tests/test_vnet.py b/tests/test_vnet.py index e2025d33b5b3..94be6e9cba7a 100644 --- a/tests/test_vnet.py +++ b/tests/test_vnet.py @@ -693,287 +693,6 @@ def check_del_vnet_routes(self, dvs, name): return True -''' -Implements "check" APIs for the "bitmap" VNET feature. -These APIs provide functionality to verify whether specified config is correcly applied to ASIC_DB. -Such object should be passed to the test class, so it can use valid APIs to check whether config is applied. -''' -class VnetBitmapVxlanTunnel(object): - - ASIC_TUNNEL_TABLE = "ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL" - ASIC_TUNNEL_MAP = "ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP" - ASIC_TUNNEL_MAP_ENTRY = "ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP_ENTRY" - ASIC_TUNNEL_TERM_ENTRY = "ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_TERM_TABLE_ENTRY" - ASIC_RIF_TABLE = "ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE" - ASIC_NEXT_HOP = "ASIC_STATE:SAI_OBJECT_TYPE_NEXT_HOP" - ASIC_BITMAP_CLASS_ENTRY = "ASIC_STATE:SAI_OBJECT_TYPE_TABLE_BITMAP_CLASSIFICATION_ENTRY" - ASIC_BITMAP_ROUTER_ENTRY = "ASIC_STATE:SAI_OBJECT_TYPE_TABLE_BITMAP_ROUTER_ENTRY" - ASIC_FDB_ENTRY = "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY" - ASIC_NEIGH_ENTRY = "ASIC_STATE:SAI_OBJECT_TYPE_NEIGHBOR_ENTRY" - ASIC_VLAN_TABLE = "ASIC_STATE:SAI_OBJECT_TYPE_VLAN" - - tunnel_map_ids = set() - tunnel_map_entry_ids = set() - tunnel_ids = set() - tunnel_term_ids = set() - vnet_bitmap_class_ids = set() - vnet_bitmap_route_ids = set() - tunnel_map_map = {} - vnet_map = {} - vnet_mac_vni_list = [] - - _loopback_id = 0 - _def_vr_id = 0 - _switch_mac = None - - @property - def loopback_id(self): - return type(self)._loopback_id - - @loopback_id.setter - def loopback_id(self, val): - type(self)._loopback_id = val - - @property - def def_vr_id(self): - return type(self)._def_vr_id - - @def_vr_id.setter - def def_vr_id(self, val): - type(self)._def_vr_id = val - - @property - def switch_mac(self): - return type(self)._switch_mac - - @switch_mac.setter - def switch_mac(self, val): - type(self)._switch_mac = val - - def fetch_exist_entries(self, dvs): - self.tunnel_ids = get_exist_entries(dvs, self.ASIC_TUNNEL_TABLE) - self.tunnel_map_ids = get_exist_entries(dvs, self.ASIC_TUNNEL_MAP) - self.tunnel_map_entry_ids = get_exist_entries(dvs, self.ASIC_TUNNEL_MAP_ENTRY) - self.tunnel_term_ids = get_exist_entries(dvs, self.ASIC_TUNNEL_TERM_ENTRY) - self.vnet_bitmap_class_ids = get_exist_entries(dvs, self.ASIC_BITMAP_CLASS_ENTRY) - self.vnet_bitmap_route_ids = get_exist_entries(dvs, self.ASIC_BITMAP_ROUTER_ENTRY) - self.rifs = get_exist_entries(dvs, self.ASIC_RIF_TABLE) - self.nhops = get_exist_entries(dvs, self.ASIC_NEXT_HOP) - self.fdbs = get_exist_entries(dvs, self.ASIC_FDB_ENTRY) - self.neighs = get_exist_entries(dvs, self.ASIC_NEIGH_ENTRY) - - if not self.loopback_id: - self.loopback_id = get_lo(dvs) - - if not self.def_vr_id: - self.def_vr_id = get_default_vr_id(dvs) - - if self.switch_mac is None: - self.switch_mac = get_switch_mac(dvs) - - def check_vxlan_tunnel(self, dvs, tunnel_name, src_ip): - asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) - - tunnel_map_id = get_created_entries(asic_db, self.ASIC_TUNNEL_MAP, self.tunnel_map_ids, 2) - tunnel_id = get_created_entry(asic_db, self.ASIC_TUNNEL_TABLE, self.tunnel_ids) - tunnel_term_id = get_created_entry(asic_db, self.ASIC_TUNNEL_TERM_ENTRY, self.tunnel_term_ids) - - assert how_many_entries_exist(asic_db, self.ASIC_TUNNEL_MAP) == (len(self.tunnel_map_ids) + 2),\ - "The TUNNEL_MAP wasn't created" - assert how_many_entries_exist(asic_db, self.ASIC_TUNNEL_MAP_ENTRY) == len(self.tunnel_map_entry_ids),\ - "The TUNNEL_MAP_ENTRY is created" - assert how_many_entries_exist(asic_db, self.ASIC_TUNNEL_TABLE) == (len(self.tunnel_ids) + 1),\ - "The TUNNEL wasn't created" - assert how_many_entries_exist(asic_db, self.ASIC_TUNNEL_TERM_ENTRY) == (len(self.tunnel_term_ids) + 1),\ - "The TUNNEL_TERM_TABLE_ENTRY wasn't created" - - expected_attrs = { 'SAI_TUNNEL_MAP_ATTR_TYPE': 'SAI_TUNNEL_MAP_TYPE_VNI_TO_BRIDGE_IF' } - check_object(asic_db, self.ASIC_TUNNEL_MAP, tunnel_map_id[0], expected_attrs) - - expected_attrs = { 'SAI_TUNNEL_MAP_ATTR_TYPE': 'SAI_TUNNEL_MAP_TYPE_BRIDGE_IF_TO_VNI' } - check_object(asic_db, self.ASIC_TUNNEL_MAP, tunnel_map_id[1], expected_attrs) - - expected_attrs = { - 'SAI_TUNNEL_ATTR_TYPE': 'SAI_TUNNEL_TYPE_VXLAN', - 'SAI_TUNNEL_ATTR_UNDERLAY_INTERFACE': self.loopback_id, - 'SAI_TUNNEL_ATTR_DECAP_MAPPERS': '1:%s' % tunnel_map_id[0], - 'SAI_TUNNEL_ATTR_ENCAP_MAPPERS': '1:%s' % tunnel_map_id[1], - 'SAI_TUNNEL_ATTR_ENCAP_SRC_IP': src_ip, - } - check_object(asic_db, self.ASIC_TUNNEL_TABLE, tunnel_id, expected_attrs) - - expected_attrs = { - 'SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_TYPE': 'SAI_TUNNEL_TERM_TABLE_ENTRY_TYPE_P2MP', - 'SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_VR_ID': self.def_vr_id, - 'SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_DST_IP': src_ip, - 'SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_TUNNEL_TYPE': 'SAI_TUNNEL_TYPE_VXLAN', - 'SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_ACTION_TUNNEL_ID': tunnel_id, - } - check_object(asic_db, self.ASIC_TUNNEL_TERM_ENTRY, tunnel_term_id, expected_attrs) - - self.tunnel_map_ids.update(tunnel_map_id) - self.tunnel_ids.add(tunnel_id) - self.tunnel_term_ids.add(tunnel_term_id) - self.tunnel_map_map[tunnel_name] = tunnel_map_id - - def check_vxlan_tunnel_entry(self, dvs, tunnel_name, vnet_name, vni_id): - asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) - app_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) - - time.sleep(2) - - if (self.tunnel_map_map.get(tunnel_name) is None): - tunnel_map_id = get_created_entries(asic_db, self.ASIC_TUNNEL_MAP, self.tunnel_map_ids, 2) - else: - tunnel_map_id = self.tunnel_map_map[tunnel_name] - - tunnel_map_entry_id = get_created_entries(asic_db, self.ASIC_TUNNEL_MAP_ENTRY, self.tunnel_map_entry_ids, 1) - - assert how_many_entries_exist(asic_db, self.ASIC_TUNNEL_MAP_ENTRY) == (len(self.tunnel_map_entry_ids) + 1),\ - "The TUNNEL_MAP_ENTRY is created too early" - - expected_attrs = { - 'SAI_TUNNEL_MAP_ENTRY_ATTR_TUNNEL_MAP_TYPE': 'SAI_TUNNEL_MAP_TYPE_BRIDGE_IF_TO_VNI', - 'SAI_TUNNEL_MAP_ENTRY_ATTR_TUNNEL_MAP': tunnel_map_id[1], - 'SAI_TUNNEL_MAP_ENTRY_ATTR_VNI_ID_VALUE': vni_id, - } - check_object(asic_db, self.ASIC_TUNNEL_MAP_ENTRY, tunnel_map_entry_id[0], expected_attrs) - - self.tunnel_map_entry_ids.update(tunnel_map_entry_id) - self.vnet_map[vnet_name].update({'vni':vni_id}) - - def check_vnet_entry(self, dvs, name, peer_list=[]): - asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) - assert how_many_entries_exist(asic_db, self.ASIC_BITMAP_CLASS_ENTRY) == (len(self.vnet_bitmap_class_ids) + 1),\ - "The bitmap class object is not created" - - new_bitmap_class_id = get_created_entries(asic_db, self.ASIC_BITMAP_CLASS_ENTRY, self.vnet_bitmap_class_ids, 1) - - self.vnet_bitmap_class_ids.update(new_bitmap_class_id) - self.rifs = get_exist_entries(dvs, self.ASIC_RIF_TABLE) - self.vnet_map.update({name:{}}) - - def check_default_vnet_entry(self, dvs, name): - return self.check_vnet_entry(dvs, name) - - def check_del_vnet_entry(self, dvs, name): - asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) - - old_bitmap_class_id = get_deleted_entries(asic_db, self.ASIC_BITMAP_CLASS_ENTRY, self.vnet_bitmap_class_ids, 1) - check_deleted_object(asic_db, self.ASIC_BITMAP_CLASS_ENTRY, old_bitmap_class_id[0]) - - self.vnet_bitmap_class_ids.remove(old_bitmap_class_id[0]) - - def check_router_interface(self, dvs, intf_name, name, vlan_oid=0): - asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) - - expected_attrs = { - "SAI_ROUTER_INTERFACE_ATTR_VIRTUAL_ROUTER_ID": self.def_vr_id, - "SAI_ROUTER_INTERFACE_ATTR_SRC_MAC_ADDRESS": self.switch_mac, - "SAI_ROUTER_INTERFACE_ATTR_MTU": "9100", - } - - if vlan_oid: - expected_attrs.update({'SAI_ROUTER_INTERFACE_ATTR_TYPE': 'SAI_ROUTER_INTERFACE_TYPE_VLAN'}) - expected_attrs.update({'SAI_ROUTER_INTERFACE_ATTR_VLAN_ID': vlan_oid}) - expected_attrs.update({'SAI_VLAN_ATTR_BROADCAST_FLOOD_CONTROL_TYPE': 'SAI_VLAN_FLOOD_CONTROL_TYPE_NONE'}) - else: - expected_attrs.update({'SAI_ROUTER_INTERFACE_ATTR_TYPE': 'SAI_ROUTER_INTERFACE_TYPE_PORT'}) - - new_rif = get_created_entry(asic_db, self.ASIC_RIF_TABLE, self.rifs) - check_object(asic_db, self.ASIC_RIF_TABLE, new_rif, expected_attrs) - - new_bitmap_class_id = get_created_entries(asic_db, self.ASIC_BITMAP_CLASS_ENTRY, self.vnet_bitmap_class_ids, 1) - - if vlan_oid: - expected_attr = { 'SAI_VLAN_ATTR_BROADCAST_FLOOD_CONTROL_TYPE': 'SAI_VLAN_FLOOD_CONTROL_TYPE_NONE' } - check_object(asic_db, self.ASIC_VLAN_TABLE, vlan_oid, expected_attr) - - check_linux_intf_arp_proxy(dvs, intf_name) - - self.rifs.add(new_rif) - self.vnet_bitmap_class_ids.update(new_bitmap_class_id) - - def check_del_router_interface(self, dvs, name): - asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) - - old_rif = get_deleted_entries(asic_db, self.ASIC_RIF_TABLE, self.rifs, 1) - check_deleted_object(asic_db, self.ASIC_RIF_TABLE, old_rif[0]) - - old_bitmap_class_id = get_deleted_entries(asic_db, self.ASIC_BITMAP_CLASS_ENTRY, self.vnet_bitmap_class_ids, 1) - check_deleted_object(asic_db, self.ASIC_BITMAP_CLASS_ENTRY, old_bitmap_class_id[0]) - - self.rifs.remove(old_rif[0]) - self.vnet_bitmap_class_ids.remove(old_bitmap_class_id[0]) - - def check_vnet_local_routes(self, dvs, name): - asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) - - expected_attr = { - "SAI_TABLE_BITMAP_ROUTER_ENTRY_ATTR_ACTION": "SAI_TABLE_BITMAP_ROUTER_ENTRY_ACTION_TO_LOCAL" - } - - new_bitmap_route = get_created_entries(asic_db, self.ASIC_BITMAP_ROUTER_ENTRY, self.vnet_bitmap_route_ids, 1) - check_object(asic_db, self.ASIC_BITMAP_ROUTER_ENTRY, new_bitmap_route[0], expected_attr) - - self.vnet_bitmap_route_ids.update(new_bitmap_route) - - def check_del_vnet_local_routes(self, dvs, name): - asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) - - old_bitmap_route = get_deleted_entries(asic_db, self.ASIC_BITMAP_ROUTER_ENTRY, self.vnet_bitmap_route_ids, 1) - check_deleted_object(asic_db, self.ASIC_BITMAP_ROUTER_ENTRY, old_bitmap_route[0]) - - self.vnet_bitmap_route_ids.remove(old_bitmap_route[0]) - - def check_vnet_routes(self, dvs, name, endpoint, tunnel, mac="", vni=0): - asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) - - _vni = str(vni) if vni != 0 else self.vnet_map[name]['vni'] - - if (mac,_vni) not in self.vnet_mac_vni_list: - new_fdbs = get_all_created_entries(asic_db, self.ASIC_FDB_ENTRY, self.fdbs) - - expected_attrs = { - "SAI_FDB_ENTRY_ATTR_TYPE": "SAI_FDB_ENTRY_TYPE_STATIC", - "SAI_FDB_ENTRY_ATTR_ENDPOINT_IP": endpoint - } - - new_fdb = next(iter([fdb for fdb in new_fdbs if (mac if mac != "" else "00:00:00:00:00:00") in fdb]), None) - assert new_fdb, "Wrong number of created FDB entries." - - check_object(asic_db, self.ASIC_FDB_ENTRY, new_fdb, expected_attrs) - - self.fdbs.add(new_fdb) - self.vnet_mac_vni_list.append((mac,_vni)) - - new_neigh = get_created_entry(asic_db, self.ASIC_NEIGH_ENTRY, self.neighs) - - expected_attrs = { "SAI_NEIGHBOR_ENTRY_ATTR_DST_MAC_ADDRESS": mac if mac != "" else "00:00:00:00:00:00" } - check_object(asic_db, self.ASIC_NEIGH_ENTRY, new_neigh, expected_attrs) - - self.neighs.add(new_neigh) - - new_nh = get_created_entry(asic_db, self.ASIC_NEXT_HOP, self.nhops) - - expected_attrs = { "SAI_TABLE_BITMAP_ROUTER_ENTRY_ATTR_ACTION": "SAI_TABLE_BITMAP_ROUTER_ENTRY_ACTION_TO_NEXTHOP" } - - new_bitmap_route = get_created_entries(asic_db, self.ASIC_BITMAP_ROUTER_ENTRY, self.vnet_bitmap_route_ids, 1) - check_object(asic_db, self.ASIC_BITMAP_ROUTER_ENTRY, new_bitmap_route[0], expected_attrs) - - self.nhops.add(new_nh) - self.vnet_bitmap_route_ids.update(new_bitmap_route) - - - def check_del_vnet_routes(self, dvs, name): - asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) - - old_bitmap_route = get_deleted_entries(asic_db, self.ASIC_BITMAP_ROUTER_ENTRY, self.vnet_bitmap_route_ids, 1) - check_deleted_object(asic_db, self.ASIC_BITMAP_ROUTER_ENTRY, old_bitmap_route[0]) - - self.vnet_bitmap_route_ids.remove(old_bitmap_route[0]) - - class TestVnetOrch(object): def get_vnet_obj(self): diff --git a/tests/test_vnet_bitmap.py b/tests/test_vnet_bitmap.py deleted file mode 100644 index 94a28c70194e..000000000000 --- a/tests/test_vnet_bitmap.py +++ /dev/null @@ -1,33 +0,0 @@ -import time -import pytest - -import test_vnet as vnet - -from swsscommon import swsscommon - - -# Define fake platform for "DVS" fixture, so it will set "platform" environment variable for "orchagent". -# It is needed in order to enable platform specific "orchagent" code for testing "bitmap" VNET implementation. -DVS_FAKE_PLATFORM = "mellanox" - - -''' -Provides test cases for the "bitmap" VNET implementation. -Test cases are inherited from "test_vnet.py::TestVnetOrch" since they are the same for both "legacy" and "bitmap" implementation. -Difference between these two implementations is in set SAI attributes, so different values should be checked in ASIC_DB. -This class should override "get_vnet_obj()" method in order to return object with appropriate implementation of "check" APIs. -''' -class TestVnetBitmapOrch(vnet.TestVnetOrch): - - ''' - Returns specific VNET object with the appropriate implementation of "check" APIs for the "bitmap" VNET. - Test cases use these "check" APIs in order to verify whether correct config is applied to ASIC_DB. - ''' - def get_vnet_obj(self): - return vnet.VnetBitmapVxlanTunnel() - - -# Add Dummy always-pass test at end as workaroud -# for issue when Flaky fail on final test it invokes module tear-down before retrying -def test_nonflaky_dummy(): - pass