diff --git a/orchagent/vnetorch.cpp b/orchagent/vnetorch.cpp index a0390f25d22a..b1122f366eff 100644 --- a/orchagent/vnetorch.cpp +++ b/orchagent/vnetorch.cpp @@ -29,6 +29,7 @@ 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; extern PortsOrch *gPortsOrch; extern IntfsOrch *gIntfsOrch; @@ -101,9 +102,13 @@ bool VNetVrfObject::createObj(vector& attrs) for (auto vr_type : vr_cntxt) { - sai_object_id_t router_id; - if (vr_type != VR_TYPE::VR_INVALID && l_fn(router_id)) + sai_object_id_t router_id = gVirtualRouterId; + if (vr_type != VR_TYPE::VR_INVALID) { + if (getScope() != "default") + { + l_fn(router_id); + } SWSS_LOG_DEBUG("VNET vr_type %d router id %" PRIx64 " ", static_cast(vr_type), router_id); vr_ids_.insert(std::pair(vr_type, router_id)); } @@ -1394,6 +1399,7 @@ bool VNetOrch::addOperation(const Request& request) bool peer = false, create = false; uint32_t vni=0; string tunnel; + string scope; for (const auto& name: request.getAttrFieldNames()) { @@ -1417,6 +1423,10 @@ bool VNetOrch::addOperation(const Request& request) { tunnel = request.getAttrString("vxlan_tunnel"); } + else if (name == "scope") + { + scope = request.getAttrString("scope"); + } else { SWSS_LOG_INFO("Unknown attribute: %s", name.c_str()); @@ -1443,7 +1453,7 @@ bool VNetOrch::addOperation(const Request& request) if (it == std::end(vnet_table_)) { - VNetInfo vnet_info = { tunnel, vni, peer_list }; + VNetInfo vnet_info = { tunnel, vni, peer_list, scope }; obj = createObject(vnet_name, vnet_info, attrs); create = true; } @@ -1470,7 +1480,7 @@ bool VNetOrch::addOperation(const Request& request) if (it == std::end(vnet_table_)) { - VNetInfo vnet_info = { tunnel, vni, peer_list }; + VNetInfo vnet_info = { tunnel, vni, peer_list, scope }; obj = createObject(vnet_name, vnet_info, attrs); create = true; } diff --git a/orchagent/vnetorch.h b/orchagent/vnetorch.h index 3055ab92fa7f..a7da8d90fe64 100644 --- a/orchagent/vnetorch.h +++ b/orchagent/vnetorch.h @@ -26,6 +26,7 @@ const request_description_t vnet_request_description = { { "vni", REQ_T_UINT }, { "peer_list", REQ_T_SET }, { "guid", REQ_T_STRING }, + { "scope", REQ_T_STRING }, }, { "vxlan_tunnel", "vni" } // mandatory attributes }; @@ -49,6 +50,7 @@ struct VNetInfo string tunnel; uint32_t vni; set peers; + string scope; }; typedef map vrid_list_t; @@ -73,7 +75,8 @@ class VNetObject VNetObject(const VNetInfo& vnetInfo) : tunnel_(vnetInfo.tunnel), peer_list_(vnetInfo.peers), - vni_(vnetInfo.vni) + vni_(vnetInfo.vni), + scope_(vnetInfo.scope) { } virtual bool updateObj(vector&) = 0; @@ -98,12 +101,18 @@ class VNetObject return vni_; } + string getScope() const + { + return scope_; + } + virtual ~VNetObject() noexcept(false) {}; private: set peer_list_ = {}; string tunnel_; uint32_t vni_; + string scope_; }; struct nextHop diff --git a/tests/test_vnet.py b/tests/test_vnet.py index 2619feeb1ae2..14ead661b91f 100644 --- a/tests/test_vnet.py +++ b/tests/test_vnet.py @@ -291,7 +291,7 @@ def delete_phy_interface(dvs, ifname, ipaddr): time.sleep(2) -def create_vnet_entry(dvs, name, tunnel, vni, peer_list): +def create_vnet_entry(dvs, name, tunnel, vni, peer_list, scope=""): conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) @@ -301,6 +301,9 @@ def create_vnet_entry(dvs, name, tunnel, vni, peer_list): ("peer_list", peer_list), ] + if scope: + attrs.append(('scope', scope)) + # create the VXLAN tunnel Term entry in Config DB create_entry_tbl( conf_db, @@ -520,6 +523,14 @@ def check_vnet_entry(self, dvs, name, peer_list=[]): self.vnet_vr_ids.update(new_vr_ids) self.vr_map[name] = { 'ing':new_vr_ids[0], 'egr':new_vr_ids[1], 'peer':peer_list } + def check_default_vnet_entry(self, dvs, name): + asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) + #Check virtual router objects + assert how_many_entries_exist(asic_db, self.ASIC_VRF_TABLE) == (len(self.vnet_vr_ids)),\ + "Some VR objects are created" + #Mappers for default VNET is created with default VR objects. + self.vr_map[name] = { 'ing':list(self.vnet_vr_ids)[0], 'egr':list(self.vnet_vr_ids)[0], 'peer':[] } + def check_del_vnet_entry(self, dvs, name): # TODO: Implement for VRF VNET return True @@ -567,8 +578,12 @@ def check_router_interface(self, dvs, name, vlan_oid=0): self.routes.update(new_route) def check_del_router_interface(self, dvs, name): - # TODO: Implement for VRF VNET - return True + 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]) + + self.rifs.remove(old_rif[0]) def check_vnet_local_routes(self, dvs, name): asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) @@ -800,6 +815,9 @@ def check_vnet_entry(self, dvs, name, peer_list=[]): 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) @@ -1284,3 +1302,19 @@ def test_vnet_orch_4(self, dvs, testlog): delete_vnet_entry(dvs, 'Vnet3001') vnet_obj.check_del_vnet_entry(dvs, 'Vnet3001') + + ''' + Test 5 - Default VNet test + ''' + def test_vnet_orch_5(self, dvs, testlog): + vnet_obj = self.get_vnet_obj() + + tunnel_name = 'tunnel_5' + + vnet_obj.fetch_exist_entries(dvs) + + create_vxlan_tunnel(dvs, tunnel_name, '8.8.8.8') + create_vnet_entry(dvs, 'Vnet_5', tunnel_name, '4789', "", 'default') + + vnet_obj.check_default_vnet_entry(dvs, 'Vnet_5') + vnet_obj.check_vxlan_tunnel_entry(dvs, tunnel_name, 'Vnet_5', '4789')