From 04cbb1e6d7368bbaeb351841edf6cc9c5352c68d Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Tue, 29 Jun 2021 12:06:50 -0700 Subject: [PATCH 01/33] Update router manager api --- .../route/controller/RouterController.java | 102 +++++++++++++++--- .../route/exception/CanNotFindRouter.java | 20 ++++ .../route/service/Impl/RouterServiceImpl.java | 51 +++++---- .../alcor/route/service/RouterService.java | 6 +- .../futurewei/alcor/route/VpcRouterTests.java | 30 ++++-- 5 files changed, 167 insertions(+), 42 deletions(-) create mode 100644 services/route_manager/src/main/java/com/futurewei/alcor/route/exception/CanNotFindRouter.java diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java index 4d94690d7..548e155dd 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java @@ -22,10 +22,7 @@ free of charge, to any person obtaining a copy of this software and associated d import com.futurewei.alcor.common.logging.Logger; import com.futurewei.alcor.common.logging.LoggerFactory; import com.futurewei.alcor.common.stats.DurationStatistics; -import com.futurewei.alcor.route.exception.CanNotFindVpc; -import com.futurewei.alcor.route.exception.HostRoutesToSubnetIsNull; -import com.futurewei.alcor.route.exception.OwnMultipleSubnetRouteTablesException; -import com.futurewei.alcor.route.exception.VpcNonEmptyException; +import com.futurewei.alcor.route.exception.*; import com.futurewei.alcor.route.service.*; import com.futurewei.alcor.route.utils.RestPreconditionsUtil; import com.futurewei.alcor.route.utils.RouteManagerUtil; @@ -70,7 +67,7 @@ public class RouterController { private RouterToDPMService routerToDPMService; /** - * Get or Create VPC router + * Get VPC router * @param projectid * @param vpcid * @return @@ -80,7 +77,7 @@ public class RouterController { method = GET, value = {"/project/{projectid}/vpcs/{vpcid}/router"}) @DurationStatistics - public RouterWebJson getOrCreateVpcRouter(@PathVariable String projectid, @PathVariable String vpcid) throws Exception { + public RouterWebJson getVpcRouter(@PathVariable String projectid, @PathVariable String vpcid) throws Exception { Router router = null; @@ -89,7 +86,46 @@ public RouterWebJson getOrCreateVpcRouter(@PathVariable String projectid, @PathV RestPreconditionsUtil.verifyParameterNotNullorEmpty(projectid); RestPreconditionsUtil.verifyResourceFound(projectid); - router = this.routerService.getOrCreateVpcRouter(projectid, vpcid); + router = this.routerService.getVpcRouter(projectid, vpcid); + + } catch (ParameterNullOrEmptyException e) { + throw e; + } catch (CanNotFindVpc e) { + logger.log(Level.WARNING, e.getMessage() + " : " + vpcid); + throw e; + } catch (DatabasePersistenceException e) { + throw e; + } + + if (router == null) + { + throw new CanNotFindRouter(); + } + + return new RouterWebJson(router); + } + + /** + * Create VPC router + * @param projectid + * @param vpcid + * @return + * @throws Exception + */ + @RequestMapping( + method = POST, + value = {"/project/{projectid}/vpcs/{vpcid}/router"}) + @DurationStatistics + public RouterWebJson createVpcRouter(@PathVariable String projectid, @PathVariable String vpcid) throws Exception { + + Router router = null; + + try { + RestPreconditionsUtil.verifyParameterNotNullorEmpty(vpcid); + RestPreconditionsUtil.verifyParameterNotNullorEmpty(projectid); + RestPreconditionsUtil.verifyResourceFound(projectid); + + router = this.routerService.createVpcRouter(projectid, vpcid); } catch (ParameterNullOrEmptyException e) { throw e; @@ -139,7 +175,7 @@ public ResponseId deleteVpcRouter(@PathVariable String projectid, @PathVariable } /** - * Get or Create VPC default route table + * Get VPC default route table * @param projectid * @param vpcid * @return @@ -149,7 +185,7 @@ public ResponseId deleteVpcRouter(@PathVariable String projectid, @PathVariable method = GET, value = {"/project/{projectid}/vpcs/{vpcid}/vpcroutetable"}) @DurationStatistics - public RouteTableWebJson getOrCreateVpcRouteTable(@PathVariable String projectid, @PathVariable String vpcid) throws Exception { + public RouteTableWebJson getVpcRouteTable(@PathVariable String projectid, @PathVariable String vpcid) throws Exception { RouteTable routetable = null; @@ -158,7 +194,41 @@ public RouteTableWebJson getOrCreateVpcRouteTable(@PathVariable String projectid RestPreconditionsUtil.verifyParameterNotNullorEmpty(projectid); RestPreconditionsUtil.verifyResourceFound(projectid); - routetable = this.routerService.getOrCreateVpcRouteTable(projectid, vpcid); + routetable = this.routerService.getVpcRouteTable(projectid, vpcid); + + } catch (ParameterNullOrEmptyException e) { + throw e; + } catch (CanNotFindVpc e) { + logger.log(Level.WARNING, e.getMessage() + " : " + vpcid); + throw e; + } catch (DatabasePersistenceException e) { + throw e; + } + + return new RouteTableWebJson(routetable); + } + + /** + * Create VPC default route table + * @param projectid + * @param vpcid + * @return + * @throws Exception + */ + @RequestMapping( + method = POST, + value = {"/project/{projectid}/vpcs/{vpcid}/vpcroutetable"}) + @DurationStatistics + public RouteTableWebJson createVpcRouteTable(@PathVariable String projectid, @PathVariable String vpcid) throws Exception { + + RouteTable routetable = null; + + try { + RestPreconditionsUtil.verifyParameterNotNullorEmpty(vpcid); + RestPreconditionsUtil.verifyParameterNotNullorEmpty(projectid); + RestPreconditionsUtil.verifyResourceFound(projectid); + + routetable = this.routerService.createVpcRouteTable(projectid, vpcid); } catch (ParameterNullOrEmptyException e) { throw e; @@ -217,7 +287,11 @@ public RouteTableWebJson updateVpcRouteTable(@PathVariable String projectid, @Pa newRouteEntry.setRoutes(routes); // find subnets related to this vpc (getVpcRouteTables) - Router router = this.routerService.getOrCreateVpcRouter(projectid, vpcid); + Router router = this.routerService.getVpcRouter(projectid, vpcid); + if (router == null) + { + throw new CanNotFindRouter(); + } List vpcRouteTables = router.getVpcRouteTables(); // sub-level routing rule update @@ -305,7 +379,7 @@ public RouteTableWebJson getVpcRouteTableById(@PathVariable String projectid, @P } /** - * Show Subnet route table or Create Subnet route table + * Show Subnet route table * @param projectid * @param subnetid * @return @@ -315,7 +389,7 @@ public RouteTableWebJson getVpcRouteTableById(@PathVariable String projectid, @P method = GET, value = {"/project/{projectid}/subnets/{subnetid}/routetable"}) @DurationStatistics - public RouteTableWebJson getOrCreateSubnetRouteTable(@PathVariable String projectid, @PathVariable String subnetid) throws Exception { + public RouteTableWebJson getSubnetRouteTable(@PathVariable String projectid, @PathVariable String subnetid) throws Exception { RouteTable routeTable = null; @@ -350,7 +424,7 @@ public RouteTableWebJson getOrCreateSubnetRouteTable(@PathVariable String projec method = POST, value = {"/project/{projectid}/subnets/{subnetid}/routetable"}) @DurationStatistics - public RouteTableWebJson createNeutronSubnetRouteTable(@PathVariable String projectid, @PathVariable String subnetid, @RequestBody RouteTableWebJson resource) throws Exception { + public RouteTableWebJson createSubnetRouteTable(@PathVariable String projectid, @PathVariable String subnetid, @RequestBody RouteTableWebJson resource) throws Exception { RouteTable routeTable = resource.getRoutetable(); diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/exception/CanNotFindRouter.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/exception/CanNotFindRouter.java new file mode 100644 index 000000000..9d67f9a39 --- /dev/null +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/exception/CanNotFindRouter.java @@ -0,0 +1,20 @@ +/* +MIT License +Copyright(c) 2020 Futurewei Cloud + Permission is hereby granted, + free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal in the Software without restriction, + including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the Software, and to permit persons + to whom the Software is furnished to do so, subject to the following conditions: + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ +package com.futurewei.alcor.route.exception; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ResponseStatus; + +@ResponseStatus(code= HttpStatus.NOT_FOUND, reason="can not find router") +public class CanNotFindRouter extends Exception { +} \ No newline at end of file diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java index 230da2ff6..3fb8bcae4 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java @@ -61,14 +61,14 @@ public class RouterServiceImpl implements RouterService { @Override - public Router getOrCreateVpcRouter(String projectId, String vpcId) throws CanNotFindVpc, DatabasePersistenceException, CacheException, OwnMultipleVpcRouterException { + public Router getVpcRouter(String projectId, String vpcId) throws CanNotFindVpc, DatabasePersistenceException, CacheException, OwnMultipleVpcRouterException { Router router = null; // If VPC already has a router, return the router state Map routerMap = null; Map queryParams = new HashMap<>(); Object[] values = new Object[1]; - values[0] = vpcId; + values[0] = "VPC:" + vpcId; queryParams.put("owner", values); routerMap = this.routerDatabaseService.getAllRouters(queryParams); @@ -84,19 +84,19 @@ public Router getOrCreateVpcRouter(String projectId, String vpcId) throws CanNot router = (Router)entry.getValue(); return router; } - } else { - // get vpc entity to create default route table and route route rule - VpcWebJson vpcResponse = this.vpcRouterToVpcService.getVpcWebJson(projectId, vpcId); - VpcEntity vpcEntity = vpcResponse.getNetwork(); - - - // If VPC doesn’t have a router, create a new router, create a VPC routing table and pump-in the VPC default routing rules - router = createDefaultVpcRouter(projectId, vpcEntity); } return router; } + @Override + public Router createVpcRouter(String projectId, String vpcId) throws CanNotFindVpc, DatabasePersistenceException, CacheException, OwnMultipleVpcRouterException { + VpcWebJson vpcResponse = this.vpcRouterToVpcService.getVpcWebJson(projectId, vpcId); + VpcEntity vpcEntity = vpcResponse.getNetwork(); + // If VPC doesn’t have a router, create a new router, create a VPC routing table and pump-in the VPC default routing rules + return createDefaultVpcRouter(projectId, vpcEntity); + } + @Override public Router createDefaultVpcRouter(String projectId, VpcEntity vpcEntity) throws DatabasePersistenceException { String routerId = UUID.randomUUID().toString(); @@ -126,7 +126,7 @@ public Router createDefaultVpcRouter(String projectId, VpcEntity vpcEntity) thro @Override public String deleteVpcRouter(String projectId, String vpcId) throws Exception { - Router router = getOrCreateVpcRouter(projectId, vpcId); + Router router = getVpcRouter(projectId, vpcId); if (router == null) { return null; } @@ -154,11 +154,11 @@ public String deleteVpcRouter(String projectId, String vpcId) throws Exception { } @Override - public RouteTable getOrCreateVpcRouteTable(String projectId, String vpcId) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException { + public RouteTable getVpcRouteTable(String projectId, String vpcId) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException { RouteTable routeTable = null; // Get or create a router for a Vpc - Router router = getOrCreateVpcRouter(projectId, vpcId); + Router router = getVpcRouter(projectId, vpcId); // If VPC has a VPC routing table, return the routing table’s state List vpcRouteTables = router.getVpcRouteTables(); @@ -169,12 +169,19 @@ public RouteTable getOrCreateVpcRouteTable(String projectId, String vpcId) throw } } - // If VPC doesn’t have a VPC routing table, this operation will create a VPC routing table and pump-in the VPC default routing rules. - routeTable = createDefaultVpcRouteTable(projectId, router); - return routeTable; } + @Override + public RouteTable createVpcRouteTable(String projectId, String vpcId) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException { + Router router = getVpcRouter(projectId, vpcId); + if (router == null) + { + return null; + } + return createDefaultVpcRouteTable(projectId, router); + } + @Override public RouteTable createDefaultVpcRouteTable(String projectId, Router router) throws DatabasePersistenceException { String routeTableId = UUID.randomUUID().toString(); @@ -203,7 +210,11 @@ public RouteTable updateVpcRouteTable(String projectId, String vpcId, RouteTable RouteTable inRoutetable = resource.getRoutetable(); // Get or create a router for a Vpc - Router router = getOrCreateVpcRouter(projectId, vpcId); + Router router = getVpcRouter(projectId, vpcId); + if (router == null) + { + return null; + } // check if there is a vpc default routetable List vpcRouteTables = router.getVpcRouteTables(); @@ -265,7 +276,11 @@ public RouteTable getSubnetRouteTable(String projectId, String subnetId) throws // create a subnet route table SubnetWebJson subnetWebJson = this.vpcRouterToSubnetService.getSubnet(projectId, subnetId); String vpcId = subnetWebJson.getSubnet().getVpcId(); - Router router = getOrCreateVpcRouter(projectId, vpcId); + Router router = getVpcRouter(projectId, vpcId); + if (router == null) + { + return null; + } String vpcDefaultRouteTableId = router.getVpcDefaultRouteTableId(); routeTable = this.routeTableDatabaseService.getByRouteTableId(vpcDefaultRouteTableId); diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterService.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterService.java index c42d2a22a..6ae25b7d3 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterService.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterService.java @@ -27,10 +27,12 @@ free of charge, to any person obtaining a copy of this software and associated d public interface RouterService { - public Router getOrCreateVpcRouter (String projectId, String vpcId) throws CanNotFindVpc, DatabasePersistenceException, CacheException, OwnMultipleVpcRouterException; + public Router getVpcRouter (String projectId, String vpcId) throws CanNotFindVpc, DatabasePersistenceException, CacheException, OwnMultipleVpcRouterException; + public Router createVpcRouter (String projectId, String vpcId) throws CanNotFindVpc, DatabasePersistenceException, CacheException, OwnMultipleVpcRouterException; public Router createDefaultVpcRouter (String projectId, VpcEntity vpcEntity) throws DatabasePersistenceException; public String deleteVpcRouter (String projectId, String vpcId) throws Exception; - public RouteTable getOrCreateVpcRouteTable (String projectId, String vpcId) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException; + public RouteTable getVpcRouteTable (String projectId, String vpcId) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException; + public RouteTable createVpcRouteTable(String projectId, String vpcId) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException; public RouteTable createDefaultVpcRouteTable (String projectId, Router router) throws DatabasePersistenceException; public RouteTable updateVpcRouteTable (String projectId, String vpcId, RouteTableWebJson resource) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException, ResourceNotFoundException, ResourcePersistenceException; public List getVpcRouteTables (String projectId, String vpcId) throws CanNotFindVpc; diff --git a/services/route_manager/src/test/java/com/futurewei/alcor/route/VpcRouterTests.java b/services/route_manager/src/test/java/com/futurewei/alcor/route/VpcRouterTests.java index 4409af69c..b801fa6a6 100644 --- a/services/route_manager/src/test/java/com/futurewei/alcor/route/VpcRouterTests.java +++ b/services/route_manager/src/test/java/com/futurewei/alcor/route/VpcRouterTests.java @@ -83,7 +83,7 @@ public class VpcRouterTests { private String subnetRouteTableUri = "/project/" + UnitTestConfig.projectId + "/subnets/" + UnitTestConfig.subnetId + "/routetable"; @Test - public void getOrCreateVpcRouter_alreadyHaveVpcRouter_pass () throws Exception { + public void getVpcRouter_alreadyHaveVpcRouter_pass () throws Exception { Router router = new Router(); router.setId(UnitTestConfig.routerId); @@ -96,7 +96,7 @@ public void getOrCreateVpcRouter_alreadyHaveVpcRouter_pass () throws Exception { } @Test - public void getOrCreateVpcRouter_notHaveVpcRouter_pass () throws Exception { + public void getVpcRouter_notHaveVpcRouter_pass () throws Exception { VpcWebJson vpcWebJson = new VpcWebJson(); VpcEntity vpcEntity = new VpcEntity(); vpcEntity.setId(UnitTestConfig.vpcId); @@ -108,12 +108,11 @@ public void getOrCreateVpcRouter_notHaveVpcRouter_pass () throws Exception { .thenReturn(vpcWebJson); this.mockMvc.perform(get(vpcRouterUri)) .andDo(print()) - .andExpect(status().isOk()) - .andExpect(MockMvcResultMatchers.jsonPath("$.router.name").value(UnitTestConfig.vpcRouterName)); + .andExpect(status().isNotFound()); } @Test - public void getOrCreateVpcRouter_ExistMultipleVpcRouter_notPass () throws Exception { + public void getVpcRouter_ExistMultipleVpcRouter_notPass () throws Exception { Router router1 = new Router(); router1.setId(UnitTestConfig.routerId); Router router2 = new Router(); @@ -188,7 +187,7 @@ public void deleteVpcRouter_VpcRouterContainsSubnetRoutingTables_notPass () thro } @Test - public void getOrCreateVpcRouteTable_pass () throws Exception { + public void getVpcRouteTable_pass () throws Exception { VpcWebJson vpcWebJson = new VpcWebJson(); VpcEntity vpcEntity = new VpcEntity(); vpcEntity.setId(UnitTestConfig.vpcId); @@ -209,6 +208,21 @@ public void getOrCreateVpcRouteTable_pass () throws Exception { .andExpect(MockMvcResultMatchers.jsonPath("$.routetable.id").value(UnitTestConfig.routeTableId)); } + @Test + public void getVpcRouteTable_notpass () throws Exception { + Router router = new Router(); + router.setId(UnitTestConfig.routerId); + router.setVpcRouteTables(new ArrayList<>(){{add(new RouteTable(){{setRouteTableType(RouteTableType.VPC.getRouteTableType());setId(UnitTestConfig.routeTableId);}});}}); + + Mockito.when(routerDatabaseService.getAllRouters(anyMap())) + .thenReturn(new HashMap(){{put(UnitTestConfig.routerId, router);}}); + + this.mockMvc.perform(get(vpcRouteTableUri)) + .andDo(print()) + .andExpect(status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$.routetable.id").value(UnitTestConfig.routeTableId)); + } + @Test public void updateVpcRouteTable_pass () throws Exception { VpcWebJson vpcWebJson = new VpcWebJson(); @@ -290,7 +304,7 @@ public void getVpcRouteTableById_pass () throws Exception { } @Test - public void getOrCreateSubnetRouteTable_pass () throws Exception { + public void getSubnetRouteTable_pass () throws Exception { RouteTable routetable = new RouteTable(); routetable.setId(UnitTestConfig.routeTableId); @@ -303,7 +317,7 @@ public void getOrCreateSubnetRouteTable_pass () throws Exception { } @Test - public void getOrCreateSubnetRouteTable_ExistMultipleSubnetRouteTable_notPass () throws Exception { + public void getSubnetRouteTable_ExistMultipleSubnetRouteTable_notPass () throws Exception { RouteTable routetable1 = new RouteTable(); routetable1.setId(UnitTestConfig.routeTableId); RouteTable routetable2 = new RouteTable(); From 4c100e5cdcde8559f943cd5eca06c054a6fadc77 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Tue, 29 Jun 2021 16:21:28 -0700 Subject: [PATCH 02/33] Update code --- .../route/controller/RouterController.java | 4 +- .../Impl/NeutronRouterServiceImpl.java | 4 +- .../route/service/Impl/RouterServiceImpl.java | 60 ++++++++----------- .../alcor/route/service/RouterService.java | 11 ++-- .../futurewei/alcor/route/VpcRouterTests.java | 20 +++++-- 5 files changed, 48 insertions(+), 51 deletions(-) diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java index 548e155dd..d3fa6dba1 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java @@ -333,7 +333,7 @@ public RouteTableWebJson updateVpcRouteTable(@PathVariable String projectid, @Pa @DurationStatistics public RouteTablesWebJson getVpcRouteTables(@PathVariable String projectid, @PathVariable String vpcid) throws Exception { - List routetables = new ArrayList<>(); + List routetables = null; try { RestPreconditionsUtil.verifyParameterNotNullorEmpty(vpcid); @@ -405,8 +405,6 @@ public RouteTableWebJson getSubnetRouteTable(@PathVariable String projectid, @Pa } catch (OwnMultipleSubnetRouteTablesException e) { logger.log(Level.WARNING, e.getMessage() + " , subnetId: " + subnetid); throw e; - } catch (DatabasePersistenceException e) { - throw e; } return new RouteTableWebJson(routeTable); diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/NeutronRouterServiceImpl.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/NeutronRouterServiceImpl.java index 0ada663b9..28415fb03 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/NeutronRouterServiceImpl.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/NeutronRouterServiceImpl.java @@ -813,9 +813,7 @@ private void PopulateInternalRouterInfo(Router router, Map gwPor RouteTable subnetRouteTable = null; try { subnetRouteTable = this.routerService.getSubnetRouteTable(router.getProjectId(), entry.getValue()); - } catch (CanNotFindSubnet | CacheException | OwnMultipleSubnetRouteTablesException | - DatabasePersistenceException | ResourceNotFoundException | ResourcePersistenceException | - OwnMultipleVpcRouterException | CanNotFindVpc canNotFindSubnet) { + } catch (Exception e) { logger.log(Level.WARNING, "Subnet" + entry.getValue() + "'s routing table is empty!");; } diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java index 3fb8bcae4..2eaf66584 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java @@ -68,7 +68,7 @@ public Router getVpcRouter(String projectId, String vpcId) throws CanNotFindVpc, Map routerMap = null; Map queryParams = new HashMap<>(); Object[] values = new Object[1]; - values[0] = "VPC:" + vpcId; + values[0] = vpcId; queryParams.put("owner", values); routerMap = this.routerDatabaseService.getAllRouters(queryParams); @@ -118,7 +118,7 @@ public Router createDefaultVpcRouter(String projectId, VpcEntity vpcEntity) thro this.routeTableDatabaseService.addRouteTable(routeTable); Router router = new Router(projectId, routerId, "default_vpc_router", "", - null, vpcRouteTables, "VPC:" + owner, ports, projectId, true, null, null, routeTableId); + null, vpcRouteTables, owner, ports, projectId, true, null, null, routeTableId); this.routerDatabaseService.addRouter(router); return router; @@ -154,11 +154,18 @@ public String deleteVpcRouter(String projectId, String vpcId) throws Exception { } @Override - public RouteTable getVpcRouteTable(String projectId, String vpcId) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException { + public RouteTable getVpcRouteTable(String projectId, String vpcId) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException, CanNotFindRouter { RouteTable routeTable = null; - - // Get or create a router for a Vpc - Router router = getVpcRouter(projectId, vpcId); + VpcWebJson vpcResponse = this.vpcRouterToVpcService.getVpcWebJson(projectId, vpcId); + VpcEntity vpcEntity = vpcResponse.getNetwork(); + if (vpcEntity == null) + { + throw new CanNotFindVpc(); + } + Router router = vpcEntity.getRouter(); + if (router == null) { + throw new CanNotFindRouter(); + } // If VPC has a VPC routing table, return the routing table’s state List vpcRouteTables = router.getVpcRouteTables(); @@ -173,11 +180,11 @@ public RouteTable getVpcRouteTable(String projectId, String vpcId) throws Databa } @Override - public RouteTable createVpcRouteTable(String projectId, String vpcId) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException { + public RouteTable createVpcRouteTable(String projectId, String vpcId) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException, CanNotFindRouter { Router router = getVpcRouter(projectId, vpcId); if (router == null) { - return null; + throw new CanNotFindRouter(); } return createDefaultVpcRouteTable(projectId, router); } @@ -205,15 +212,15 @@ public RouteTable createDefaultVpcRouteTable(String projectId, Router router) th } @Override - public RouteTable updateVpcRouteTable(String projectId, String vpcId, RouteTableWebJson resource) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException, ResourceNotFoundException, ResourcePersistenceException { + public RouteTable updateVpcRouteTable(String projectId, String vpcId, RouteTableWebJson resource) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException, ResourceNotFoundException, ResourcePersistenceException, CanNotFindRouter { RouteTable routeTable = null; RouteTable inRoutetable = resource.getRoutetable(); - // Get or create a router for a Vpc + // Get router Router router = getVpcRouter(projectId, vpcId); if (router == null) { - return null; + throw new CanNotFindRouter(); } // check if there is a vpc default routetable @@ -258,7 +265,7 @@ public List getVpcRouteTables(String projectId, String vpcId) throws } @Override - public RouteTable getSubnetRouteTable(String projectId, String subnetId) throws CacheException, OwnMultipleSubnetRouteTablesException, DatabasePersistenceException, ResourceNotFoundException, ResourcePersistenceException, CanNotFindSubnet, OwnMultipleVpcRouterException, CanNotFindVpc { + public RouteTable getSubnetRouteTable(String projectId, String subnetId) throws CacheException, CanNotFindRouteTableByOwner, OwnMultipleSubnetRouteTablesException { RouteTable routeTable = null; Map routeTableMap = null; @@ -268,36 +275,21 @@ public RouteTable getSubnetRouteTable(String projectId, String subnetId) throws queryParams.put("owner", values); routeTableMap = this.routeTableDatabaseService.getAllRouteTables(queryParams); - if (routeTableMap == null) { - routeTableMap = new HashMap<>(); - } - if (routeTableMap.size() == 0) { - // create a subnet route table - SubnetWebJson subnetWebJson = this.vpcRouterToSubnetService.getSubnet(projectId, subnetId); - String vpcId = subnetWebJson.getSubnet().getVpcId(); - Router router = getVpcRouter(projectId, vpcId); - if (router == null) - { - return null; - } + if (routeTableMap == null || routeTableMap.size() == 0) { + throw new CanNotFindRouteTableByOwner(); + } - String vpcDefaultRouteTableId = router.getVpcDefaultRouteTableId(); - routeTable = this.routeTableDatabaseService.getByRouteTableId(vpcDefaultRouteTableId); - return routeTable; - } else if (routeTableMap.size() > 1) { + if (routeTableMap.size() > 1) + { throw new OwnMultipleSubnetRouteTablesException(); - } else { - for (Map.Entry entry : routeTableMap.entrySet()) { - routeTable = (RouteTable)entry.getValue(); - } } - return routeTable; + return routeTableMap.values().stream().findFirst().get(); } @Override - public RouteTable updateSubnetRouteTable(String projectId, String subnetId, UpdateRoutingRuleResponse resource) throws CacheException, DatabasePersistenceException, OwnMultipleSubnetRouteTablesException, CanNotFindVpc, CanNotFindSubnet, ResourceNotFoundException, ResourcePersistenceException, OwnMultipleVpcRouterException { + public RouteTable updateSubnetRouteTable(String projectId, String subnetId, UpdateRoutingRuleResponse resource) throws CacheException, DatabasePersistenceException, OwnMultipleSubnetRouteTablesException, CanNotFindRouteTableByOwner { InternalSubnetRoutingTable inRoutetable = resource.getInternalSubnetRoutingTable(); List inHostRoutes = resource.getHostRouteToSubnet(); // Get or create a router for a Subnet diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterService.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterService.java index 6ae25b7d3..3a71f9420 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterService.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterService.java @@ -20,6 +20,7 @@ free of charge, to any person obtaining a copy of this software and associated d import com.futurewei.alcor.common.exception.ResourceNotFoundException; import com.futurewei.alcor.common.exception.ResourcePersistenceException; import com.futurewei.alcor.route.exception.*; +import com.futurewei.alcor.web.entity.dataplane.MulticastGoalStateByte; import com.futurewei.alcor.web.entity.route.*; import com.futurewei.alcor.web.entity.vpc.VpcEntity; @@ -31,13 +32,13 @@ public interface RouterService { public Router createVpcRouter (String projectId, String vpcId) throws CanNotFindVpc, DatabasePersistenceException, CacheException, OwnMultipleVpcRouterException; public Router createDefaultVpcRouter (String projectId, VpcEntity vpcEntity) throws DatabasePersistenceException; public String deleteVpcRouter (String projectId, String vpcId) throws Exception; - public RouteTable getVpcRouteTable (String projectId, String vpcId) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException; - public RouteTable createVpcRouteTable(String projectId, String vpcId) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException; + public RouteTable getVpcRouteTable (String projectId, String vpcId) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException, CanNotFindRouter; + public RouteTable createVpcRouteTable(String projectId, String vpcId) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException, CanNotFindRouter; public RouteTable createDefaultVpcRouteTable (String projectId, Router router) throws DatabasePersistenceException; - public RouteTable updateVpcRouteTable (String projectId, String vpcId, RouteTableWebJson resource) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException, ResourceNotFoundException, ResourcePersistenceException; + public RouteTable updateVpcRouteTable (String projectId, String vpcId, RouteTableWebJson resource) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException, ResourceNotFoundException, ResourcePersistenceException, CanNotFindRouter; public List getVpcRouteTables (String projectId, String vpcId) throws CanNotFindVpc; - public RouteTable getSubnetRouteTable(String projectId, String subnetId) throws CanNotFindSubnet, CacheException, OwnMultipleSubnetRouteTablesException, DatabasePersistenceException, ResourceNotFoundException, ResourcePersistenceException, OwnMultipleVpcRouterException, CanNotFindVpc; - public RouteTable updateSubnetRouteTable (String projectId, String subnetId, UpdateRoutingRuleResponse resource) throws CacheException, DatabasePersistenceException, OwnMultipleSubnetRouteTablesException, CanNotFindVpc, CanNotFindSubnet, ResourceNotFoundException, ResourcePersistenceException, OwnMultipleVpcRouterException; + public RouteTable getSubnetRouteTable(String projectId, String subnetId) throws CacheException, CanNotFindRouteTableByOwner, OwnMultipleSubnetRouteTablesException; + public RouteTable updateSubnetRouteTable (String projectId, String subnetId, UpdateRoutingRuleResponse resource) throws CacheException, DatabasePersistenceException, OwnMultipleSubnetRouteTablesException, CanNotFindRouteTableByOwner; public String deleteSubnetRouteTable (String projectId, String subnetId) throws Exception; public RouteTable createNeutronSubnetRouteTable(String projectId, String subnetId, RouteTableWebJson resource, List routes) throws DatabasePersistenceException; diff --git a/services/route_manager/src/test/java/com/futurewei/alcor/route/VpcRouterTests.java b/services/route_manager/src/test/java/com/futurewei/alcor/route/VpcRouterTests.java index b801fa6a6..35f6f7c9d 100644 --- a/services/route_manager/src/test/java/com/futurewei/alcor/route/VpcRouterTests.java +++ b/services/route_manager/src/test/java/com/futurewei/alcor/route/VpcRouterTests.java @@ -188,15 +188,16 @@ public void deleteVpcRouter_VpcRouterContainsSubnetRoutingTables_notPass () thro @Test public void getVpcRouteTable_pass () throws Exception { + Router router = new Router(); + router.setId(UnitTestConfig.routerId); + router.setVpcRouteTables(new ArrayList<>(){{add(new RouteTable(){{setRouteTableType(RouteTableType.VPC.getRouteTableType());setId(UnitTestConfig.routeTableId);}});}}); + VpcWebJson vpcWebJson = new VpcWebJson(); VpcEntity vpcEntity = new VpcEntity(); vpcEntity.setId(UnitTestConfig.vpcId); + vpcEntity.setRouter(router); vpcWebJson.setNetwork(vpcEntity); - Router router = new Router(); - router.setId(UnitTestConfig.routerId); - router.setVpcRouteTables(new ArrayList<>(){{add(new RouteTable(){{setRouteTableType(RouteTableType.VPC.getRouteTableType());setId(UnitTestConfig.routeTableId);}});}}); - Mockito.when(routerDatabaseService.getAllRouters(anyMap())) .thenReturn(new HashMap(){{put(UnitTestConfig.routerId, router);}}); Mockito.when(vpcRouterToVpcService.getVpcWebJson(UnitTestConfig.projectId, UnitTestConfig.vpcId)) @@ -210,17 +211,24 @@ public void getVpcRouteTable_pass () throws Exception { @Test public void getVpcRouteTable_notpass () throws Exception { + Router router = new Router(); router.setId(UnitTestConfig.routerId); router.setVpcRouteTables(new ArrayList<>(){{add(new RouteTable(){{setRouteTableType(RouteTableType.VPC.getRouteTableType());setId(UnitTestConfig.routeTableId);}});}}); + VpcWebJson vpcWebJson = new VpcWebJson(); + VpcEntity vpcEntity = new VpcEntity(); + vpcEntity.setId(UnitTestConfig.vpcId); + vpcWebJson.setNetwork(vpcEntity); + Mockito.when(routerDatabaseService.getAllRouters(anyMap())) .thenReturn(new HashMap(){{put(UnitTestConfig.routerId, router);}}); + Mockito.when(vpcRouterToVpcService.getVpcWebJson(UnitTestConfig.projectId, UnitTestConfig.vpcId)) + .thenReturn(vpcWebJson); this.mockMvc.perform(get(vpcRouteTableUri)) .andDo(print()) - .andExpect(status().isOk()) - .andExpect(MockMvcResultMatchers.jsonPath("$.routetable.id").value(UnitTestConfig.routeTableId)); + .andExpect(status().isNotFound()); } @Test From e38bcf902198b4dcea707a159fb8ef2923e49ddd Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Wed, 30 Jun 2021 16:42:53 -0700 Subject: [PATCH 03/33] Update code --- .../futurewei/alcor/route/controller/RouterController.java | 4 ++-- .../futurewei/alcor/route/service/Impl/RouterServiceImpl.java | 4 ++-- .../java/com/futurewei/alcor/route/service/RouterService.java | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java index d3fa6dba1..4c3b5379c 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java @@ -306,7 +306,7 @@ public RouteTableWebJson updateVpcRouteTable(@PathVariable String projectid, @Pa InternalRouterInfo internalRouterInfo = this.neutronRouterService.constructInternalRouterInfo(router.getId(), internalSubnetRoutingTableList); // send InternalRouterInfo contract to DPM -// this.routerToDPMService.sendInternalRouterInfoToDPM(internalRouterInfo); + this.routerToDPMService.sendInternalRouterInfoToDPM(internalRouterInfo); } catch (ParameterNullOrEmptyException e) { throw e; @@ -333,7 +333,7 @@ public RouteTableWebJson updateVpcRouteTable(@PathVariable String projectid, @Pa @DurationStatistics public RouteTablesWebJson getVpcRouteTables(@PathVariable String projectid, @PathVariable String vpcid) throws Exception { - List routetables = null; + List routetables = new ArrayList<>(); try { RestPreconditionsUtil.verifyParameterNotNullorEmpty(vpcid); diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java index 2eaf66584..300dbe516 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java @@ -254,12 +254,12 @@ public RouteTable updateVpcRouteTable(String projectId, String vpcId, RouteTable } @Override - public List getVpcRouteTables(String projectId, String vpcId) throws CanNotFindVpc { + public List getVpcRouteTables(String projectId, String vpcId) throws CanNotFindVpc, CanNotFindRouter { VpcWebJson vpcResponse = this.vpcRouterToVpcService.getVpcWebJson(projectId, vpcId); VpcEntity vpcEntity = vpcResponse.getNetwork(); Router router = vpcEntity.getRouter(); if (router == null) { - return null; + throw new CanNotFindRouter(); } return router.getVpcRouteTables(); } diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterService.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterService.java index 3a71f9420..653d7752c 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterService.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterService.java @@ -36,7 +36,7 @@ public interface RouterService { public RouteTable createVpcRouteTable(String projectId, String vpcId) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException, CanNotFindRouter; public RouteTable createDefaultVpcRouteTable (String projectId, Router router) throws DatabasePersistenceException; public RouteTable updateVpcRouteTable (String projectId, String vpcId, RouteTableWebJson resource) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException, ResourceNotFoundException, ResourcePersistenceException, CanNotFindRouter; - public List getVpcRouteTables (String projectId, String vpcId) throws CanNotFindVpc; + public List getVpcRouteTables (String projectId, String vpcId) throws CanNotFindVpc, CanNotFindRouter; public RouteTable getSubnetRouteTable(String projectId, String subnetId) throws CacheException, CanNotFindRouteTableByOwner, OwnMultipleSubnetRouteTablesException; public RouteTable updateSubnetRouteTable (String projectId, String subnetId, UpdateRoutingRuleResponse resource) throws CacheException, DatabasePersistenceException, OwnMultipleSubnetRouteTablesException, CanNotFindRouteTableByOwner; public String deleteSubnetRouteTable (String projectId, String subnetId) throws Exception; From 067a9886cf8b768314214791a1a57f08366939fa Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Wed, 30 Jun 2021 20:57:39 -0700 Subject: [PATCH 04/33] Update router manager --- .../route/service/Impl/RouterServiceImpl.java | 23 ++++++++++++------- .../alcor/route/service/RouterService.java | 2 +- .../futurewei/alcor/route/VpcRouterTests.java | 17 ++++++++------ 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java index 300dbe516..035f1427c 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java @@ -64,6 +64,8 @@ public class RouterServiceImpl implements RouterService { public Router getVpcRouter(String projectId, String vpcId) throws CanNotFindVpc, DatabasePersistenceException, CacheException, OwnMultipleVpcRouterException { Router router = null; + VpcWebJson vpcResponse = this.vpcRouterToVpcService.getVpcWebJson(projectId, vpcId); + // If VPC already has a router, return the router state Map routerMap = null; Map queryParams = new HashMap<>(); @@ -155,7 +157,6 @@ public String deleteVpcRouter(String projectId, String vpcId) throws Exception { @Override public RouteTable getVpcRouteTable(String projectId, String vpcId) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException, CanNotFindRouter { - RouteTable routeTable = null; VpcWebJson vpcResponse = this.vpcRouterToVpcService.getVpcWebJson(projectId, vpcId); VpcEntity vpcEntity = vpcResponse.getNetwork(); if (vpcEntity == null) @@ -169,23 +170,29 @@ public RouteTable getVpcRouteTable(String projectId, String vpcId) throws Databa // If VPC has a VPC routing table, return the routing table’s state List vpcRouteTables = router.getVpcRouteTables(); - for (RouteTable vpcRouteTable : vpcRouteTables) { - String routeTableType = vpcRouteTable.getRouteTableType(); - if (RouteTableType.VPC.getRouteTableType().equals(routeTableType)) { - return vpcRouteTable; - } + if (vpcRouteTables != null) + { + return vpcRouteTables.stream().filter(vpcRouteTable -> RouteTableType.VPC.getRouteTableType().equals(vpcRouteTable.getRouteTableType())).findFirst().get(); } - return routeTable; + return null; } @Override - public RouteTable createVpcRouteTable(String projectId, String vpcId) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException, CanNotFindRouter { + public RouteTable createVpcRouteTable(String projectId, String vpcId) throws Exception { + Router router = getVpcRouter(projectId, vpcId); if (router == null) { throw new CanNotFindRouter(); } + + String defaultRouteTableId = router.getVpcDefaultRouteTableId(); + if (defaultRouteTableId.isEmpty() || this.routeTableDatabaseService.getByRouteTableId(defaultRouteTableId) != null) + { + throw new RouteTableNotUnique(); + } + return createDefaultVpcRouteTable(projectId, router); } diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterService.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterService.java index 653d7752c..9d01944da 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterService.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterService.java @@ -33,7 +33,7 @@ public interface RouterService { public Router createDefaultVpcRouter (String projectId, VpcEntity vpcEntity) throws DatabasePersistenceException; public String deleteVpcRouter (String projectId, String vpcId) throws Exception; public RouteTable getVpcRouteTable (String projectId, String vpcId) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException, CanNotFindRouter; - public RouteTable createVpcRouteTable(String projectId, String vpcId) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException, CanNotFindRouter; + public RouteTable createVpcRouteTable(String projectId, String vpcId) throws Exception; public RouteTable createDefaultVpcRouteTable (String projectId, Router router) throws DatabasePersistenceException; public RouteTable updateVpcRouteTable (String projectId, String vpcId, RouteTableWebJson resource) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException, ResourceNotFoundException, ResourcePersistenceException, CanNotFindRouter; public List getVpcRouteTables (String projectId, String vpcId) throws CanNotFindVpc, CanNotFindRouter; diff --git a/services/route_manager/src/test/java/com/futurewei/alcor/route/VpcRouterTests.java b/services/route_manager/src/test/java/com/futurewei/alcor/route/VpcRouterTests.java index 35f6f7c9d..f567be2a9 100644 --- a/services/route_manager/src/test/java/com/futurewei/alcor/route/VpcRouterTests.java +++ b/services/route_manager/src/test/java/com/futurewei/alcor/route/VpcRouterTests.java @@ -198,8 +198,6 @@ public void getVpcRouteTable_pass () throws Exception { vpcEntity.setRouter(router); vpcWebJson.setNetwork(vpcEntity); - Mockito.when(routerDatabaseService.getAllRouters(anyMap())) - .thenReturn(new HashMap(){{put(UnitTestConfig.routerId, router);}}); Mockito.when(vpcRouterToVpcService.getVpcWebJson(UnitTestConfig.projectId, UnitTestConfig.vpcId)) .thenReturn(vpcWebJson); @@ -214,21 +212,20 @@ public void getVpcRouteTable_notpass () throws Exception { Router router = new Router(); router.setId(UnitTestConfig.routerId); - router.setVpcRouteTables(new ArrayList<>(){{add(new RouteTable(){{setRouteTableType(RouteTableType.VPC.getRouteTableType());setId(UnitTestConfig.routeTableId);}});}}); VpcWebJson vpcWebJson = new VpcWebJson(); VpcEntity vpcEntity = new VpcEntity(); vpcEntity.setId(UnitTestConfig.vpcId); + vpcEntity.setRouter(router); vpcWebJson.setNetwork(vpcEntity); - Mockito.when(routerDatabaseService.getAllRouters(anyMap())) - .thenReturn(new HashMap(){{put(UnitTestConfig.routerId, router);}}); Mockito.when(vpcRouterToVpcService.getVpcWebJson(UnitTestConfig.projectId, UnitTestConfig.vpcId)) .thenReturn(vpcWebJson); this.mockMvc.perform(get(vpcRouteTableUri)) .andDo(print()) - .andExpect(status().isNotFound()); + .andExpect(status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$.routetable").doesNotExist()); } @Test @@ -286,16 +283,22 @@ public void updateVpcRouteTable_ResourceNotValid_notPass () throws Exception { @Test public void getVpcRouteTables_pass () throws Exception { + Router router = new Router(); + router.setId(UnitTestConfig.routerId); + router.setVpcRouteTables(new ArrayList<>(){{add(new RouteTable(){{setRouteTableType(RouteTableType.VPC.getRouteTableType());setId(UnitTestConfig.routeTableId);}});}}); + VpcWebJson vpcWebJson = new VpcWebJson(); VpcEntity vpcEntity = new VpcEntity(); vpcEntity.setId(UnitTestConfig.vpcId); + vpcEntity.setRouter(router); vpcWebJson.setNetwork(vpcEntity); Mockito.when(vpcRouterToVpcService.getVpcWebJson(UnitTestConfig.projectId, UnitTestConfig.vpcId)) .thenReturn(vpcWebJson); this.mockMvc.perform(get(getVpcRouteTablesUri)) .andDo(print()) - .andExpect(status().isOk()); + .andExpect(status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$.routetables.length()").value(1)); } @Test From dd5dafdeb0959bcc0573de7014647886a048643f Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Thu, 1 Jul 2021 15:04:48 -0700 Subject: [PATCH 05/33] Update router manager --- .../exception/VpcRouterAlreadyExist.java | 23 ++++++++++++++++ .../route/service/Impl/RouterServiceImpl.java | 27 +++++++++---------- .../alcor/route/service/RouterService.java | 4 +-- .../futurewei/alcor/route/VpcRouterTests.java | 4 ++- 4 files changed, 41 insertions(+), 17 deletions(-) create mode 100644 services/route_manager/src/main/java/com/futurewei/alcor/route/exception/VpcRouterAlreadyExist.java diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/exception/VpcRouterAlreadyExist.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/exception/VpcRouterAlreadyExist.java new file mode 100644 index 000000000..404285289 --- /dev/null +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/exception/VpcRouterAlreadyExist.java @@ -0,0 +1,23 @@ +/* +MIT License +Copyright(c) 2020 Futurewei Cloud + + Permission is hereby granted, + free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal in the Software without restriction, + including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the Software, and to permit persons + to whom the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ +package com.futurewei.alcor.route.exception; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ResponseStatus; + +@ResponseStatus(code= HttpStatus.CONFLICT, reason="Vpc router already exist.") +public class VpcRouterAlreadyExist extends Exception { +} diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java index 035f1427c..b4b0e7053 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java @@ -61,11 +61,7 @@ public class RouterServiceImpl implements RouterService { @Override - public Router getVpcRouter(String projectId, String vpcId) throws CanNotFindVpc, DatabasePersistenceException, CacheException, OwnMultipleVpcRouterException { - Router router = null; - - VpcWebJson vpcResponse = this.vpcRouterToVpcService.getVpcWebJson(projectId, vpcId); - + public Router getVpcRouter(String projectId, String vpcId) throws CanNotFindVpc, CacheException, OwnMultipleVpcRouterException, CanNotFindRouter { // If VPC already has a router, return the router state Map routerMap = null; Map queryParams = new HashMap<>(); @@ -75,26 +71,29 @@ public Router getVpcRouter(String projectId, String vpcId) throws CanNotFindVpc, routerMap = this.routerDatabaseService.getAllRouters(queryParams); - if (routerMap == null) { - routerMap = new HashMap<>(); + if (routerMap == null || routerMap.size() == 0) { + throw new CanNotFindRouter(); } if (routerMap.size() > 1) { throw new OwnMultipleVpcRouterException(); - } else if (routerMap.size() == 1) { - for (Map.Entry entry : routerMap.entrySet()) { - router = (Router)entry.getValue(); - return router; - } } + Router router = routerMap.values().stream().findFirst().get(); + return router; } @Override - public Router createVpcRouter(String projectId, String vpcId) throws CanNotFindVpc, DatabasePersistenceException, CacheException, OwnMultipleVpcRouterException { + public Router createVpcRouter(String projectId, String vpcId) throws CanNotFindVpc, DatabasePersistenceException, VpcRouterAlreadyExist { VpcWebJson vpcResponse = this.vpcRouterToVpcService.getVpcWebJson(projectId, vpcId); VpcEntity vpcEntity = vpcResponse.getNetwork(); + + if (vpcEntity.getRouter() != null) + { + throw new VpcRouterAlreadyExist(); + } + // If VPC doesn’t have a router, create a new router, create a VPC routing table and pump-in the VPC default routing rules return createDefaultVpcRouter(projectId, vpcEntity); } @@ -188,7 +187,7 @@ public RouteTable createVpcRouteTable(String projectId, String vpcId) throws Exc } String defaultRouteTableId = router.getVpcDefaultRouteTableId(); - if (defaultRouteTableId.isEmpty() || this.routeTableDatabaseService.getByRouteTableId(defaultRouteTableId) != null) + if (!defaultRouteTableId.isEmpty() && this.routeTableDatabaseService.getByRouteTableId(defaultRouteTableId) != null) { throw new RouteTableNotUnique(); } diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterService.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterService.java index 9d01944da..020647ab6 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterService.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterService.java @@ -28,8 +28,8 @@ free of charge, to any person obtaining a copy of this software and associated d public interface RouterService { - public Router getVpcRouter (String projectId, String vpcId) throws CanNotFindVpc, DatabasePersistenceException, CacheException, OwnMultipleVpcRouterException; - public Router createVpcRouter (String projectId, String vpcId) throws CanNotFindVpc, DatabasePersistenceException, CacheException, OwnMultipleVpcRouterException; + public Router getVpcRouter (String projectId, String vpcId) throws CanNotFindVpc, DatabasePersistenceException, CacheException, OwnMultipleVpcRouterException, CanNotFindRouter; + public Router createVpcRouter (String projectId, String vpcId) throws CanNotFindVpc, DatabasePersistenceException, CacheException, VpcRouterAlreadyExist; public Router createDefaultVpcRouter (String projectId, VpcEntity vpcEntity) throws DatabasePersistenceException; public String deleteVpcRouter (String projectId, String vpcId) throws Exception; public RouteTable getVpcRouteTable (String projectId, String vpcId) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException, CanNotFindRouter; diff --git a/services/route_manager/src/test/java/com/futurewei/alcor/route/VpcRouterTests.java b/services/route_manager/src/test/java/com/futurewei/alcor/route/VpcRouterTests.java index f567be2a9..436869298 100644 --- a/services/route_manager/src/test/java/com/futurewei/alcor/route/VpcRouterTests.java +++ b/services/route_manager/src/test/java/com/futurewei/alcor/route/VpcRouterTests.java @@ -86,13 +86,15 @@ public class VpcRouterTests { public void getVpcRouter_alreadyHaveVpcRouter_pass () throws Exception { Router router = new Router(); router.setId(UnitTestConfig.routerId); + router.setOwner(UnitTestConfig.vpcId); Mockito.when(routerDatabaseService.getAllRouters(anyMap())) .thenReturn(new HashMap(){{put(UnitTestConfig.routerId, router);}}); this.mockMvc.perform(get(vpcRouterUri)) .andDo(print()) .andExpect(status().isOk()) - .andExpect(MockMvcResultMatchers.jsonPath("$.router.id").value(UnitTestConfig.routerId)); + .andExpect(MockMvcResultMatchers.jsonPath("$.router.id").value(UnitTestConfig.routerId)) + .andExpect(MockMvcResultMatchers.jsonPath("$.router.owner").value(UnitTestConfig.vpcId)); } @Test From aa765625d20083bade7e36fcd886e20591b64c8d Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Thu, 1 Jul 2021 17:09:34 -0700 Subject: [PATCH 06/33] Merge router manager service api code --- .../futurewei/alcor/route/controller/RouterController.java | 4 ++-- .../alcor/route/service/Impl/RouterServiceImpl.java | 7 +++---- .../com/futurewei/alcor/route/service/RouterService.java | 2 +- .../com/futurewei/alcor/route/utils/RouteManagerUtil.java | 4 ++-- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java index 4c3b5379c..2fc9ddc65 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java @@ -432,7 +432,7 @@ public RouteTableWebJson createSubnetRouteTable(@PathVariable String projectid, RestPreconditionsUtil.verifyResourceFound(projectid); // check resource - if (!RouteManagerUtil.checkCreateNeutronSubnetRouteTableWebJsonResourceIsValid(resource)) { + if (!RouteManagerUtil.checkCreateSubnetRouteTableWebJsonResourceIsValid(resource)) { throw new ResourceNotValidException("request resource is invalid"); } @@ -450,7 +450,7 @@ public RouteTableWebJson createSubnetRouteTable(@PathVariable String projectid, "0.0.0.0/0", null, 100, null, "192.168.0.1"); routes.add(defaultRoute); - routeTable = this.routerService.createNeutronSubnetRouteTable(projectid, subnetid, resource, routes); + routeTable = this.routerService.createSubnetRouteTable(projectid, subnetid, resource, routes); } catch (ParameterNullOrEmptyException e) { throw e; diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java index b4b0e7053..d8af03973 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java @@ -219,7 +219,6 @@ public RouteTable createDefaultVpcRouteTable(String projectId, Router router) th @Override public RouteTable updateVpcRouteTable(String projectId, String vpcId, RouteTableWebJson resource) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException, ResourceNotFoundException, ResourcePersistenceException, CanNotFindRouter { - RouteTable routeTable = null; RouteTable inRoutetable = resource.getRoutetable(); // Get router @@ -232,7 +231,7 @@ public RouteTable updateVpcRouteTable(String projectId, String vpcId, RouteTable // check if there is a vpc default routetable List vpcRouteTables = router.getVpcRouteTables(); String vpcDefaultRouteTableId = router.getVpcDefaultRouteTableId(); - routeTable = this.routeTableDatabaseService.getByRouteTableId(vpcDefaultRouteTableId); + RouteTable routeTable = this.routeTableDatabaseService.getByRouteTableId(vpcDefaultRouteTableId); if (routeTable == null) { String routeTableId = inRoutetable.getId(); @@ -352,7 +351,7 @@ public String deleteSubnetRouteTable(String projectId, String subnetId) throws E } @Override - public RouteTable createNeutronSubnetRouteTable(String projectId, String subnetId, RouteTableWebJson resource, List routes) throws DatabasePersistenceException { + public RouteTable createSubnetRouteTable(String projectId, String subnetId, RouteTableWebJson resource, List routes) throws DatabasePersistenceException { // configure a new route table RouteTable routeTable = new RouteTable(); @@ -361,7 +360,7 @@ public RouteTable createNeutronSubnetRouteTable(String projectId, String subnetI routeTable.setDescription(""); routeTable.setName("subnet-" + id + "-routetable"); routeTable.setProjectId(projectId); - routeTable.setRouteTableType(RouteTableType.NEUTRON_SUBNET.getRouteTableType()); + routeTable.setRouteTableType(resource.getRoutetable().getRouteTableType()); routeTable.setOwner(subnetId); routeTable.setRouteEntities(routes); diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterService.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterService.java index 020647ab6..2b21311ef 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterService.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterService.java @@ -40,6 +40,6 @@ public interface RouterService { public RouteTable getSubnetRouteTable(String projectId, String subnetId) throws CacheException, CanNotFindRouteTableByOwner, OwnMultipleSubnetRouteTablesException; public RouteTable updateSubnetRouteTable (String projectId, String subnetId, UpdateRoutingRuleResponse resource) throws CacheException, DatabasePersistenceException, OwnMultipleSubnetRouteTablesException, CanNotFindRouteTableByOwner; public String deleteSubnetRouteTable (String projectId, String subnetId) throws Exception; - public RouteTable createNeutronSubnetRouteTable(String projectId, String subnetId, RouteTableWebJson resource, List routes) throws DatabasePersistenceException; + public RouteTable createSubnetRouteTable(String projectId, String subnetId, RouteTableWebJson resource, List routes) throws DatabasePersistenceException; } diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/utils/RouteManagerUtil.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/utils/RouteManagerUtil.java index 5e2db38a4..8d089c3e6 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/utils/RouteManagerUtil.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/utils/RouteManagerUtil.java @@ -158,13 +158,13 @@ public static boolean checkSubnetRouteTableWebJsonResourceIsValid(RouteTableWebJ return true; } - public static boolean checkCreateNeutronSubnetRouteTableWebJsonResourceIsValid(RouteTableWebJson resource) { + public static boolean checkCreateSubnetRouteTableWebJsonResourceIsValid(RouteTableWebJson resource) { if (resource == null) { return false; } RouteTable routetable = resource.getRoutetable(); - if (routetable == null) { + if (routetable == null || routetable.getRouteTableType() == null || routetable.getRouteTableType().trim().isEmpty()) { return false; } From 8ae37db45367ec861508a1ff4c5939ac50b1960a Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Thu, 1 Jul 2021 18:36:40 -0700 Subject: [PATCH 07/33] Fix getVpcRouteTables --- .../futurewei/alcor/route/controller/RouterController.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java index 2fc9ddc65..c55bf8dc1 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java @@ -342,6 +342,11 @@ public RouteTablesWebJson getVpcRouteTables(@PathVariable String projectid, @Pat routetables = this.routerService.getVpcRouteTables(projectid, vpcid); + if (routetables == null) + { + throw new RouterUnavailable(); + } + } catch (Exception e) { throw e; } From f0462ae5cb0fa5dc13d7d34df8079bce1d61ed09 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Thu, 1 Jul 2021 19:00:50 -0700 Subject: [PATCH 08/33] Fix getVpcRouteTable --- .../futurewei/alcor/route/service/Impl/RouterServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java index d8af03973..da8cf818e 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java @@ -171,7 +171,7 @@ public RouteTable getVpcRouteTable(String projectId, String vpcId) throws Databa List vpcRouteTables = router.getVpcRouteTables(); if (vpcRouteTables != null) { - return vpcRouteTables.stream().filter(vpcRouteTable -> RouteTableType.VPC.getRouteTableType().equals(vpcRouteTable.getRouteTableType())).findFirst().get(); + return vpcRouteTables.stream().filter(vpcRouteTable -> RouteTableType.VPC.getRouteTableType().equals(vpcRouteTable.getRouteTableType())).findFirst().orElse(null); } return null; From 976883f581abc7d5128bee0a584c7f07cb519c65 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Tue, 6 Jul 2021 14:18:32 -0700 Subject: [PATCH 09/33] Update RouterController --- .../com/futurewei/alcor/route/controller/RouterController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java index c55bf8dc1..bb7a2dcbb 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java @@ -344,7 +344,7 @@ public RouteTablesWebJson getVpcRouteTables(@PathVariable String projectid, @Pat if (routetables == null) { - throw new RouterUnavailable(); + throw new RouterTableNotExist(); } } catch (Exception e) { From ef7a2d2f366e87b54b5ebf2222bd1ba234d62337 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Tue, 6 Jul 2021 16:13:01 -0700 Subject: [PATCH 10/33] Update code --- .../futurewei/alcor/route/controller/RouterController.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java index bb7a2dcbb..a95af55f4 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java @@ -450,10 +450,6 @@ public RouteTableWebJson createSubnetRouteTable(@PathVariable String projectid, routeEntry.getDestination(), null, 100, null, routeEntry.getNexthop()); routes.add(newRoute); } - String d_uuid = UUID.randomUUID().toString(); - RouteEntry defaultRoute = new RouteEntry(projectid, d_uuid, "default-route-" + d_uuid, "Default Routing Rule", - "0.0.0.0/0", null, 100, null, "192.168.0.1"); - routes.add(defaultRoute); routeTable = this.routerService.createSubnetRouteTable(projectid, subnetid, resource, routes); From 670dcc630dad29b0bfee1d91ea8e7be1461b84b2 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Tue, 29 Jun 2021 16:21:28 -0700 Subject: [PATCH 11/33] Update code --- .../com/futurewei/alcor/route/controller/RouterController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java index 9fdb4f11d..bec3dfce3 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java @@ -334,7 +334,7 @@ public RouteTableWebJson updateVpcRouteTable(@PathVariable String projectid, @Pa @DurationStatistics public RouteTablesWebJson getVpcRouteTables(@PathVariable String projectid, @PathVariable String vpcid) throws Exception { - List routetables = new ArrayList<>(); + List routetables = null; try { RestPreconditionsUtil.verifyParameterNotNullorEmpty(vpcid); From 59a65f0dac6ddf384fbe5332f6d43e0db3ba18a8 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Wed, 30 Jun 2021 16:42:53 -0700 Subject: [PATCH 12/33] Update code --- .../com/futurewei/alcor/route/controller/RouterController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java index bec3dfce3..9fdb4f11d 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java @@ -334,7 +334,7 @@ public RouteTableWebJson updateVpcRouteTable(@PathVariable String projectid, @Pa @DurationStatistics public RouteTablesWebJson getVpcRouteTables(@PathVariable String projectid, @PathVariable String vpcid) throws Exception { - List routetables = null; + List routetables = new ArrayList<>(); try { RestPreconditionsUtil.verifyParameterNotNullorEmpty(vpcid); From 2ba5f1f27ab19c7120a88f473be72f2ba7e51b66 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Mon, 6 Dec 2021 09:36:14 -0800 Subject: [PATCH 13/33] Implement GoalStateV2 cache design in DPM --- .../alcor/dataplane/cache/LocalCacheImpl.java | 9 +- .../dataplane/cache/PortHostInfoCache.java | 73 ++++++ .../dataplane/cache/RouterSubnetsCache.java | 85 +++---- .../dataplane/cache/SubnetPortsCache.java | 72 +++++- .../client/grpc/DataPlaneClientImplV2.java | 1 + .../entity/InternalSubnetRouterMap.java | 41 ++++ .../entity/MulticastGoalStateV2.java | 14 +- .../service/impl/DpmServiceImplV2.java | 40 +++- .../service/impl/NeighborService.java | 217 +++++++++++++++++- .../dataplane/service/impl/RouterService.java | 7 +- .../dataplane/service/impl/SubnetService.java | 41 +++- .../alcor/web/entity/port/PortHostInfo.java | 12 +- .../entity/subnet/InternalSubnetPorts.java | 16 +- 13 files changed, 537 insertions(+), 91 deletions(-) create mode 100644 services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/PortHostInfoCache.java create mode 100644 services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/InternalSubnetRouterMap.java diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/LocalCacheImpl.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/LocalCacheImpl.java index 7aa17161e..f989149bd 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/LocalCacheImpl.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/LocalCacheImpl.java @@ -43,11 +43,15 @@ public class LocalCacheImpl implements LocalCache { @Autowired private SubnetPortsCache subnetPortsCache; + @Autowired + private PortHostInfoCache portHostInfoCache; + @Autowired private NodeInfoCache nodeInfoCache; @Override public void setSubnetPorts(NetworkConfiguration networkConfig) throws Exception { + List portEntities = networkConfig.getPortEntities(); if (portEntities == null) { return; @@ -70,6 +74,7 @@ public void setSubnetPorts(NetworkConfiguration networkConfig) throws Exception portHostInfo.setPortId(portEntity.getId()); portHostInfo.setHostIp(portEntity.getBindingHostIP()); portHostInfo.setHostId(portEntity.getBindingHostId()); + portHostInfo.setSubnetId(subnetId); InternalSubnetPorts subnetPorts = subnetPortsMap.get(subnetId); if (subnetPorts == null) { @@ -85,7 +90,6 @@ public void setSubnetPorts(NetworkConfiguration networkConfig) throws Exception subnetPorts.setVpcId(subnetEntity.getVpcId()); subnetPorts.setTunnelId(subnetEntity.getTunnelId()); subnetPorts.setDhcpEnable(subnetEntity.getDhcpEnable()); - subnetPorts.setPorts(new ArrayList<>()); List routers = networkConfig.getInternalRouterInfos(); if (routers != null && routers.size() > 0) { @@ -106,14 +110,13 @@ public void setSubnetPorts(NetworkConfiguration networkConfig) throws Exception subnetPortsMap.put(subnetId, subnetPorts); } - - subnetPorts.getPorts().add(portHostInfo); } } for (Map.Entry entry: subnetPortsMap.entrySet()) { subnetPortsCache.updateSubnetPorts(entry.getValue()); } + } private InternalSubnetEntity getSubnetEntity(NetworkConfiguration networkConfig, String subnetId) throws Exception { diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/PortHostInfoCache.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/PortHostInfoCache.java new file mode 100644 index 000000000..dcde4fbc9 --- /dev/null +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/PortHostInfoCache.java @@ -0,0 +1,73 @@ +package com.futurewei.alcor.dataplane.cache; + +import com.futurewei.alcor.common.db.CacheException; +import com.futurewei.alcor.common.db.CacheFactory; +import com.futurewei.alcor.common.db.ICache; +import com.futurewei.alcor.web.entity.dataplane.v2.NetworkConfiguration; +import com.futurewei.alcor.web.entity.port.PortHostInfo; +import com.futurewei.alcor.web.entity.subnet.InternalSubnetPorts; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.stereotype.Repository; + +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; + + +@Repository +@ComponentScan(value="com.futurewei.alcor.common.db") +public class PortHostInfoCache { + + + private ICache portHostInfoCache; + private CacheFactory cacheFactory; + + @Autowired + public PortHostInfoCache(CacheFactory cacheFactory) { + this.cacheFactory = cacheFactory; + portHostInfoCache = cacheFactory.getCache(PortHostInfo.class); + } + + public Map getPortHostInfo(NetworkConfiguration networkConfig) { + Map portHostInfoMap = networkConfig + .getPortEntities() + .stream() + .filter(portEntity -> portEntity.getFixedIps().size() > 0) + .flatMap(portEntity -> portEntity.getFixedIps() + .stream() + .filter(fixedIp -> fixedIp != null) + .map(fixedIp -> new PortHostInfo(portEntity.getId() + , fixedIp.getIpAddress() + , portEntity.getMacAddress() + , portEntity.getBindingHostId() + , portEntity.getBindingHostIP() + , fixedIp.getSubnetId()))) + .collect(Collectors.toMap(portHostInfo -> portHostInfo.getSubnetId() + cacheFactory.KEY_DELIMITER + portHostInfo.getPortIp(), Function.identity())); + return portHostInfoMap; + } + + public void updatePortHostInfo(Map portHostInfoMap) throws CacheException { + portHostInfoCache.putAll(portHostInfoMap); + } + + public synchronized Collection getPortHostInfos(String subnetId) throws CacheException { + Map queryParams = new HashMap<>(); + Object[] values = new Object[1]; + values[0] = subnetId; + queryParams.put("subnetId", values); + return portHostInfoCache.getAll(queryParams).values(); + } + + public synchronized PortHostInfo getPortHostInfoByIp(String subnetId, String ip) throws CacheException { + return portHostInfoCache.get(subnetId + cacheFactory.KEY_DELIMITER + ip); + } + + public synchronized void deletePortHostInfo(String subnetId, String portIp) throws CacheException { + portHostInfoCache.remove(subnetId + cacheFactory.KEY_DELIMITER + portIp); + } + +} diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/RouterSubnetsCache.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/RouterSubnetsCache.java index 78fea3d7a..a06303213 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/RouterSubnetsCache.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/RouterSubnetsCache.java @@ -20,89 +20,62 @@ free of charge, to any person obtaining a copy of this software and associated d import com.futurewei.alcor.common.db.ICache; import com.futurewei.alcor.common.db.repo.ICacheRepository; import com.futurewei.alcor.common.stats.DurationStatistics; +import com.futurewei.alcor.dataplane.entity.InternalSubnetRouterMap; import com.futurewei.alcor.dataplane.entity.InternalSubnets; +import com.futurewei.alcor.web.entity.dataplane.v2.NetworkConfiguration; +import com.futurewei.alcor.web.entity.port.PortHostInfo; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.ComponentScan; import org.springframework.stereotype.Repository; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; @Slf4j @Repository @ComponentScan(value="com.futurewei.alcor.common.db") -public class RouterSubnetsCache implements ICacheRepository { +public class RouterSubnetsCache { // The cache is a map(routerId, subnetIds) - private final ICache routerSubnetsCache; + private final ICache routerSubnetsCache; + private CacheFactory cacheFactory; @Autowired public RouterSubnetsCache(CacheFactory cacheFactory) { - this.routerSubnetsCache = cacheFactory.getCache(InternalSubnets.class); + this.cacheFactory = cacheFactory; + this.routerSubnetsCache = cacheFactory.getCache(InternalSubnetRouterMap.class); } @DurationStatistics - public InternalSubnets getRouterSubnets(String routerId) throws CacheException { - return routerSubnetsCache.get(routerId); - } + public synchronized Collection getRouterSubnets(String routerId) throws CacheException { + Map queryParams = new HashMap<>(); + Object[] values = new Object[1]; + values[0] = routerId; + queryParams.put("routerId", values); + return routerSubnetsCache.getAll(queryParams).values(); - @DurationStatistics - public Map getAllSubnets() throws CacheException { - return routerSubnetsCache.getAll(); - } - - @DurationStatistics - public Map getAllSubnets(Map queryParams) throws CacheException { - return routerSubnetsCache.getAll(queryParams); } @DurationStatistics - public synchronized void addVpcSubnets(InternalSubnets subnets) throws CacheException { - routerSubnetsCache.put(subnets.getRouterId(), subnets); + public synchronized Collection updateVpcSubnets(NetworkConfiguration networkConfig) throws CacheException { + Map internalSubnetsMap = networkConfig + .getInternalRouterInfos() + .stream() + .filter(routerInfo -> routerInfo.getRouterConfiguration().getSubnetRoutingTables().size() > 0) + .flatMap(routerInfo -> routerInfo.getRouterConfiguration().getSubnetRoutingTables() + .stream() + .map(routingTable -> new InternalSubnetRouterMap(routerInfo.getRouterConfiguration().getId() + , routingTable.getSubnetId()))) + .collect(Collectors.toMap(routerInfo -> routerInfo.getRouterId() + cacheFactory.KEY_DELIMITER + routerInfo.getSubnetId(), Function.identity())); + routerSubnetsCache.putAll(internalSubnetsMap); + return internalSubnetsMap.values(); } @DurationStatistics - public void updateVpcSubnets(InternalSubnets subnets) throws CacheException { - routerSubnetsCache.put(subnets.getRouterId(), subnets); - } - - @DurationStatistics - public void deleteVpcGatewayInfo(String routerId) throws CacheException { - routerSubnetsCache.remove(routerId); - } - - @Override - public InternalSubnets findItem(String id) throws CacheException { - return routerSubnetsCache.get(id); + public synchronized void deleteVpcGatewayInfo(String routerId, String subnetId) throws CacheException { + routerSubnetsCache.remove(routerId + cacheFactory.KEY_DELIMITER + subnetId); } - @Override - public Map findAllItems() throws CacheException { - return routerSubnetsCache.getAll(); - } - @Override - public Map findAllItems(Map queryParams) throws CacheException { - return routerSubnetsCache.getAll(queryParams); - } - - @Override - public void addItem(InternalSubnets subnets) throws CacheException { - log.debug("Add Subnets {} to Router {}", subnets.toString(), subnets.getRouterId()); - routerSubnetsCache.put(subnets.getRouterId(), subnets); - } - - @Override - public void addItems(List items) throws CacheException { - Map subnetsMap = items.stream().collect(Collectors.toMap(InternalSubnets::getRouterId, Function.identity())); - routerSubnetsCache.putAll(subnetsMap); - } - - @Override - public void deleteItem(String id) throws CacheException { - log.debug("Delete Router {}", id); - routerSubnetsCache.remove(id); - } } diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SubnetPortsCache.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SubnetPortsCache.java index 52f24fd1d..1b1b6390b 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SubnetPortsCache.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SubnetPortsCache.java @@ -18,22 +18,33 @@ free of charge, to any person obtaining a copy of this software and associated d import com.futurewei.alcor.common.db.CacheException; import com.futurewei.alcor.common.db.CacheFactory; import com.futurewei.alcor.common.db.ICache; +import com.futurewei.alcor.common.db.Transaction; import com.futurewei.alcor.common.stats.DurationStatistics; +import com.futurewei.alcor.dataplane.entity.InternalSubnetRouterMap; +import com.futurewei.alcor.dataplane.entity.InternalSubnets; +import com.futurewei.alcor.web.entity.dataplane.v2.NetworkConfiguration; +import com.futurewei.alcor.web.entity.port.PortHostInfo; import com.futurewei.alcor.web.entity.subnet.InternalSubnetPorts; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.ComponentScan; import org.springframework.stereotype.Repository; +import java.util.Collection; +import java.util.HashMap; import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; @Repository @ComponentScan(value="com.futurewei.alcor.common.db") public class SubnetPortsCache { // The cache is a map(subnetId, subnetPorts) private ICache subnetPortsCache; + private CacheFactory cacheFactory; @Autowired public SubnetPortsCache(CacheFactory cacheFactory) { + this.cacheFactory = cacheFactory; subnetPortsCache = cacheFactory.getCache(InternalSubnetPorts.class); } @@ -42,6 +53,15 @@ public InternalSubnetPorts getSubnetPorts(String subnetId) throws CacheException return subnetPortsCache.get(subnetId); } + @DurationStatistics + public Collection getSubnetPortsByRouterId(String routerId) throws CacheException { + Map queryParams = new HashMap<>(); + Object[] values = new Object[1]; + values[0] = routerId; + queryParams.put("routerId", values); + return subnetPortsCache.getAll(queryParams).values(); + } + @DurationStatistics public Map getAllSubnetPorts() throws CacheException { return subnetPortsCache.getAll(); @@ -57,14 +77,64 @@ public synchronized void addSubnetPorts(InternalSubnetPorts internalSubnetPorts) subnetPortsCache.put(internalSubnetPorts.getSubnetId(), internalSubnetPorts); } + @DurationStatistics + public Map getInternalSubnetRouterMap(NetworkConfiguration networkConfig) { + if (networkConfig.getInternalRouterInfos() != null) { + Map internalSubnetsRouterMap = networkConfig + .getInternalRouterInfos() + .stream() + .filter(routerInfo -> routerInfo.getRouterConfiguration().getSubnetRoutingTables().size() > 0) + .flatMap(routerInfo -> routerInfo.getRouterConfiguration().getSubnetRoutingTables() + .stream() + .map(routingTable -> new InternalSubnetRouterMap(routerInfo.getRouterConfiguration().getId() + , routingTable.getSubnetId()))) + .collect(Collectors.toMap(routerInfo -> routerInfo.getSubnetId(), routerInfo -> routerInfo.getRouterId())); + return internalSubnetsRouterMap; + } + return new HashMap<>(); + } + + @DurationStatistics + public Map getSubnetPorts(NetworkConfiguration networkConfig) { + Map internalSubnetsRouterMap = getInternalSubnetRouterMap(networkConfig); + + Map internalSubnetPortsMap = networkConfig + .getSubnets() + .stream() + .filter(subnetEntity -> subnetEntity != null) + .map(subnetEntity -> new InternalSubnetPorts(subnetEntity.getId() + ,subnetEntity.getGatewayPortDetail().getGatewayPortId() + ,subnetEntity.getGatewayIp() + ,subnetEntity.getGatewayPortDetail().getGatewayMacAddress() + ,subnetEntity.getName() + ,subnetEntity.getCidr() + ,subnetEntity.getVpcId() + ,subnetEntity.getTunnelId() + ,subnetEntity.getDhcpEnable() + ,internalSubnetsRouterMap.getOrDefault(subnetEntity.getId(), null)) + ) + .collect(Collectors.toMap(InternalSubnetPorts::getSubnetId, Function.identity())); + + return internalSubnetPortsMap; + } + + @DurationStatistics + public void updateSubnetPorts(Map internalSubnetPortsMap) throws Exception { + subnetPortsCache.putAll(internalSubnetPortsMap); + } + @DurationStatistics public void updateSubnetPorts(InternalSubnetPorts internalSubnetPorts) throws Exception { subnetPortsCache.put(internalSubnetPorts.getSubnetId(), internalSubnetPorts); } @DurationStatistics - public void deleteSubnetPorts(String subnetId) throws Exception { + public synchronized void deleteSubnetPorts(String subnetId) throws Exception { subnetPortsCache.remove(subnetId); } + public Transaction getTransaction() { + return subnetPortsCache.getTransaction(); + } + } diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java index 70eede9a3..c0b47eb80 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java @@ -71,6 +71,7 @@ public List sendGoalStates(List unicastGoalStates) t for (UnicastGoalStateV2 unicastGoalState : unicastGoalStates) { goalStateBuilder = getGoalState(goalStateBuilder, unicastGoalState); } + System.out.println(goalStateBuilder.build()); doSendGoalState(goalStateBuilder.build(), finishLatch, results); if (!finishLatch.await(1, TimeUnit.MINUTES)) { diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/InternalSubnetRouterMap.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/InternalSubnetRouterMap.java new file mode 100644 index 000000000..a14d6f27b --- /dev/null +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/InternalSubnetRouterMap.java @@ -0,0 +1,41 @@ +/* +MIT License +Copyright(c) 2020 Futurewei Cloud + + Permission is hereby granted, + free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal in the Software without restriction, + including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the Software, and to permit persons + to whom the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package com.futurewei.alcor.dataplane.entity; + +public class InternalSubnetRouterMap { + private String routerId; + private String subnetId; + + public InternalSubnetRouterMap() { }; + + public InternalSubnetRouterMap(String routerId, String subnetId) { + this.routerId = routerId; + this.subnetId = subnetId; + } + + public void setRouterId(String routerId) { this.routerId = routerId; } + + public void setSubnetIds(String subnetId) { + this.subnetId = subnetId; + } + + public String getRouterId() { return this.routerId; } + + public String getSubnetId() { + return this.subnetId; + } +} \ No newline at end of file diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/MulticastGoalStateV2.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/MulticastGoalStateV2.java index 6a786455a..a55e0d673 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/MulticastGoalStateV2.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/MulticastGoalStateV2.java @@ -20,10 +20,12 @@ free of charge, to any person obtaining a copy of this software and associated d import com.futurewei.alcor.web.entity.dataplane.MulticastGoalStateByte; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; public class MulticastGoalStateV2 { - private List hostIps; + private Set hostIps; private List vpcIds; private List topics; private List subTopics; @@ -32,26 +34,26 @@ public class MulticastGoalStateV2 { private GoalStateV2.Builder goalStateBuilder; public MulticastGoalStateV2() { - hostIps = new ArrayList<>(); + hostIps = new HashSet<>(); goalStateBuilder = GoalStateV2.newBuilder(); } - public MulticastGoalStateV2(List hostIps, GoalStateV2 goalState) { + public MulticastGoalStateV2(Set hostIps, GoalStateV2 goalState) { this.hostIps = hostIps; this.goalState = goalState; } - public MulticastGoalStateV2(List hostIps, List vpcIds, GoalStateV2 goalState) { + public MulticastGoalStateV2(Set hostIps, List vpcIds, GoalStateV2 goalState) { this.hostIps = hostIps; this.vpcIds = vpcIds; this.goalState = goalState; } - public List getHostIps() { + public Set getHostIps() { return hostIps; } - public void setHostIps(List hostIps) { + public void setHostIps(Set hostIps) { this.hostIps = hostIps; } diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/DpmServiceImplV2.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/DpmServiceImplV2.java index b875652b8..95b9f10e1 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/DpmServiceImplV2.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/DpmServiceImplV2.java @@ -16,10 +16,9 @@ free of charge, to any person obtaining a copy of this software and associated d package com.futurewei.alcor.dataplane.service.impl; import com.futurewei.alcor.common.db.CacheException; +import com.futurewei.alcor.common.db.Transaction; import com.futurewei.alcor.common.tracer.Tracer; -import com.futurewei.alcor.dataplane.cache.LocalCache; -import com.futurewei.alcor.dataplane.cache.SubnetPortsCache; -import com.futurewei.alcor.dataplane.cache.VpcGatewayInfoCache; +import com.futurewei.alcor.dataplane.cache.*; import com.futurewei.alcor.dataplane.client.DataPlaneClient; import com.futurewei.alcor.dataplane.client.ZetaGatewayClient; import com.futurewei.alcor.dataplane.config.Config; @@ -103,6 +102,12 @@ public class DpmServiceImplV2 implements DpmService { @Autowired private RouterService routerService; + @Autowired + private RouterSubnetsCache routerSubnetsCache; + + @Autowired + private PortHostInfoCache portHostInfoCache; + @Autowired private DpmServiceImplV2(Config globalConfig) { this.goalStateMessageVersion = globalConfig.goalStateMessageVersion; @@ -119,13 +124,26 @@ private UnicastGoalStateV2 buildUnicastGoalState(NetworkConfiguration networkCon portService.buildPortState(networkConfig, portEntities, unicastGoalState); } + Map internalSubnetPorts = subnetPortsCache.getSubnetPorts(networkConfig); + Map portHostInfoMap = portHostInfoCache.getPortHostInfo(networkConfig); + synchronized (this) { + try(Transaction tx = subnetPortsCache.getTransaction().start()) { + subnetPortsCache.updateSubnetPorts(internalSubnetPorts); + portHostInfoCache.updatePortHostInfo(portHostInfoMap); + tx.commit(); + } + } + vpcService.buildVpcStates(networkConfig, unicastGoalState); - subnetService.buildSubnetStates(networkConfig, unicastGoalState, multicastGoalState); - neighborService.buildNeighborStates(networkConfig, hostIp, unicastGoalState, multicastGoalState); + subnetService.buildSubnetStates(networkConfig, unicastGoalState); securityGroupService.buildSecurityGroupStates(networkConfig, unicastGoalState); dhcpService.buildDhcpStates(networkConfig, unicastGoalState); - routerService.buildRouterStates(networkConfig, unicastGoalState, multicastGoalState); - patchGoalstateForNeighbor(networkConfig, unicastGoalState); + routerService.buildRouterStates(networkConfig, unicastGoalState); + + neighborService.buildNeighborStatesL2(unicastGoalState, multicastGoalState, networkConfig.getOpType()); + if (networkConfig.getInternalRouterInfos() != null) { + neighborService.buildNeighborStatesL3(networkConfig, unicastGoalState, multicastGoalState, networkConfig.getOpType()); + } unicastGoalState.setGoalState(unicastGoalState.getGoalStateBuilder().build()); unicastGoalState.setGoalStateBuilder(null); @@ -594,8 +612,8 @@ private List processRouterConfiguration(NetworkConfiguration networkConf for (InternalSubnetRoutingTable subnetRoutingTable : subnetRoutingTables) { String subnetId = subnetRoutingTable.getSubnetId(); - InternalSubnetPorts subnetPorts = localCache.getSubnetPorts(subnetId); - if (subnetPorts == null) { + Collection portHostInfos = portHostInfoCache.getPortHostInfos(subnetId); + if (portHostInfos == null) { //throw new SubnetPortsNotFound(); //return new ArrayList<>(); continue; @@ -604,7 +622,7 @@ private List processRouterConfiguration(NetworkConfiguration networkConf subnetRoutingTable.getRoutingRules().forEach(routingRule -> {ips.add(routingRule.getNextHopIp());}); List neighbors = neighborService.getAllNeighbors(ips) ; - for (PortHostInfo portHostInfo : subnetPorts.getPorts()) { + for (PortHostInfo portHostInfo : portHostInfos) { String hostIp = portHostInfo.getHostIp(); UnicastGoalStateV2 unicastGoalState = unicastGoalStateMap.get(hostIp); if (unicastGoalState == null) { @@ -627,7 +645,7 @@ private List processRouterConfiguration(NetworkConfiguration networkConf } } - routerService.buildRouterState(routerInfo, subnetRoutingTable, unicastGoalState, multicastGoalState); + routerService.buildRouterState(routerInfo, subnetRoutingTable, unicastGoalState); subnetService.buildSubnetState(subnetId, unicastGoalState, multicastGoalState); } } diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java index ca8bbbea6..99909e904 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java @@ -15,12 +15,11 @@ free of charge, to any person obtaining a copy of this software and associated d */ package com.futurewei.alcor.dataplane.service.impl; +import com.futurewei.alcor.common.db.CacheException; import com.futurewei.alcor.dataplane.cache.NeighborCache; +import com.futurewei.alcor.dataplane.cache.PortHostInfoCache; import com.futurewei.alcor.dataplane.cache.SubnetPortsCache; -import com.futurewei.alcor.dataplane.entity.MulticastGoalState; -import com.futurewei.alcor.dataplane.entity.MulticastGoalStateV2; -import com.futurewei.alcor.dataplane.entity.UnicastGoalState; -import com.futurewei.alcor.dataplane.entity.UnicastGoalStateV2; +import com.futurewei.alcor.dataplane.entity.*; import com.futurewei.alcor.dataplane.exception.NeighborInfoNotFound; import com.futurewei.alcor.dataplane.exception.PortFixedIpNotFound; import com.futurewei.alcor.schema.*; @@ -35,13 +34,23 @@ free of charge, to any person obtaining a copy of this software and associated d import org.springframework.stereotype.Service; import java.util.*; +import java.util.stream.Collectors; @Service public class NeighborService extends ResourceService { + @Autowired + private PortHostInfoCache portHostInfoCache; + + @Autowired + private SubnetPortsCache subnetPortsCache; + @Autowired private NeighborCache neighborCache; + @Autowired + private SubnetService subnetService; + public Neighbor.NeighborState buildNeighborState(NeighborEntry.NeighborType type, NeighborInfo neighborInfo, Common.OperationType operationType) throws Exception { Neighbor.NeighborConfiguration.Builder neighborConfigBuilder = Neighbor.NeighborConfiguration.newBuilder(); neighborConfigBuilder.setRevisionNumber(FORMAT_REVISION_NUMBER); @@ -69,6 +78,33 @@ public Neighbor.NeighborState buildNeighborState(NeighborEntry.NeighborType type return neighborStateBuilder.build(); } + public Neighbor.NeighborState buildNeighborState(NeighborEntry.NeighborType type, PortHostInfo portHostInfo, Common.OperationType operationType, String vpcId) throws Exception { + Neighbor.NeighborConfiguration.Builder neighborConfigBuilder = Neighbor.NeighborConfiguration.newBuilder(); + neighborConfigBuilder.setRevisionNumber(FORMAT_REVISION_NUMBER); + neighborConfigBuilder.setId(UUID.randomUUID().toString()); // TODO: We are going to need this per latest ACA change + neighborConfigBuilder.setVpcId(vpcId); + //neighborConfigBuilder.setName(); + neighborConfigBuilder.setMacAddress(portHostInfo.getPortMac()); + neighborConfigBuilder.setHostIpAddress(portHostInfo.getHostIp()); + Neighbor.NeighborType neighborType = Neighbor.NeighborType.valueOf(type.getType()); + + //TODO:setNeighborHostDvrMac + //neighborConfigBuilder.setNeighborHostDvrMac(); + Neighbor.NeighborConfiguration.FixedIp.Builder fixedIpBuilder = Neighbor.NeighborConfiguration.FixedIp.newBuilder(); + fixedIpBuilder.setSubnetId(portHostInfo.getSubnetId()); + fixedIpBuilder.setIpAddress(portHostInfo.getPortIp()); + fixedIpBuilder.setNeighborType(neighborType); + neighborConfigBuilder.addFixedIps(fixedIpBuilder.build()); + //TODO:setAllowAddressPairs + //neighborConfigBuilder.setAllowAddressPairs(); + + Neighbor.NeighborState.Builder neighborStateBuilder = Neighbor.NeighborState.newBuilder(); + neighborStateBuilder.setOperationType(operationType); + neighborStateBuilder.setConfiguration(neighborConfigBuilder.build()); + neighborCache.setNeighborState(neighborStateBuilder.build()); + return neighborStateBuilder.build(); + } + private List buildNeighborInfosByPortEntities(NetworkConfiguration networkConfig) { List neighborInfos = new ArrayList<>(); @@ -283,4 +319,177 @@ public List getAllNeighbors (Set ips) throws Exc } return neighbors; } + + public void buildNeighborStatesL2(UnicastGoalStateV2 unicastGoalStateV2, MulticastGoalStateV2 multicastGoalStateV2, Common.OperationType operationType) { + Collection portStates = unicastGoalStateV2.getGoalStateBuilder().getPortStatesMap().values(); + Map neighborStateMap = new TreeMap<>(); + + Set ips = portStates + .stream() + .flatMap(portState -> portState.getConfiguration().getFixedIpsList().stream().map(fixedIp -> fixedIp.getIpAddress())) + .collect(Collectors.toSet()); + + multicastGoalStateV2.getGoalStateBuilder().putAllSubnetStates(unicastGoalStateV2.getGoalStateBuilder().getSubnetStatesMap()); + multicastGoalStateV2.getGoalStateBuilder().putAllRouterStates(unicastGoalStateV2.getGoalStateBuilder().getRouterStatesMap()); + System.out.println("ips"); + for (String ip : ips) { + System.out.println(ip); + } + + + + portStates.parallelStream().forEach(portState -> { + List subnetIds = portState.getConfiguration().getFixedIpsList().stream().map(fixedIp -> fixedIp.getSubnetId()).collect(Collectors.toList()); + System.out.println("subnetIds"); + for (String subnetId : subnetIds) { + System.out.println(subnetId); + } + for (String subnetId : subnetIds) { + try { + Collection portHostInfos = portHostInfoCache.getPortHostInfos(subnetId); + System.out.println("portHostInfos"); + for (PortHostInfo portHostInfo : portHostInfos) { + System.out.println(portHostInfo.getPortIp()); + } + portHostInfos.parallelStream().forEach(portHostInfo -> { + try { + Neighbor.NeighborState neighborState = buildNeighborState(NeighborEntry.NeighborType.L2, portHostInfo, operationType, portState.getConfiguration().getVpcId()); + if (ips.contains(portHostInfo.getPortIp())) { + System.out.println("test"); + multicastGoalStateV2.getGoalStateBuilder().putNeighborStates(neighborState.getConfiguration().getId(), neighborState); + } else { + multicastGoalStateV2.getHostIps().add(portHostInfo.getHostIp()); + neighborStateMap.put(neighborState.getConfiguration().getId(), neighborState); + } + } catch (Exception e) { + e.printStackTrace(); + } + }); + + } catch (CacheException e) { + e.printStackTrace(); + } + } + }); + unicastGoalStateV2.getGoalStateBuilder().putAllNeighborStates(neighborStateMap); + if (multicastGoalStateV2.getHostIps().size() == 0){ + multicastGoalStateV2.getGoalStateBuilder().clear(); + } + } + + public void buildNeighborStatesL3(NetworkConfiguration networkConfiguration, UnicastGoalStateV2 unicastGoalStateV2, MulticastGoalStateV2 multicastGoalStateV2, Common.OperationType operationType) { + Collection portStates = unicastGoalStateV2.getGoalStateBuilder().getPortStatesMap().values(); + Map neighborStateMap = new TreeMap<>(); + Map subnetStateMap = new TreeMap<>(); + Set ips = portStates + .stream() + .flatMap(portState -> portState.getConfiguration().getFixedIpsList().stream().map(fixedIp -> fixedIp.getIpAddress())) + .collect(Collectors.toSet()); + + Set subnetIds = portStates + .stream() + .flatMap(portState -> portState.getConfiguration().getFixedIpsList().stream().map(fixedIp -> fixedIp.getSubnetId())) + .collect(Collectors.toSet()); + + System.out.println("subnetIds"); + for (String subnetId : subnetIds) { + System.out.println(subnetId); + } + + multicastGoalStateV2.getGoalStateBuilder().putAllSubnetStates(unicastGoalStateV2.getGoalStateBuilder().getSubnetStatesMap()); + multicastGoalStateV2.getGoalStateBuilder().putAllRouterStates(unicastGoalStateV2.getGoalStateBuilder().getRouterStatesMap()); + + Set routerIds = subnetPortsCache.getInternalSubnetRouterMap(networkConfiguration).values().stream().collect(Collectors.toSet()); + String vpcid = unicastGoalStateV2.getGoalStateBuilder().getVpcStatesMap().values().stream().map(vpcState -> vpcState.getConfiguration().getId()).findFirst().orElse(null); + routerIds.parallelStream().forEach(routerId -> { + try { + Collection internalSubnetPorts = subnetPortsCache.getSubnetPortsByRouterId(routerId); + System.out.println("Collection"); + for (InternalSubnetPorts internalSubnetPorts1 : internalSubnetPorts) { + System.out.println(internalSubnetPorts1.getSubnetId()); + } + + for (InternalSubnetPorts internalSubnetPort : internalSubnetPorts) { + try { + + Collection portHostInfos = portHostInfoCache.getPortHostInfos(internalSubnetPort.getSubnetId()); + System.out.println("Collection portHostInfos" + internalSubnetPort.getSubnetId()); + for (PortHostInfo portHostInfo : portHostInfos) { + System.out.println(portHostInfo.getHostIp()); + } + portHostInfos.parallelStream().forEach(portHostInfo -> { + try { + Neighbor.NeighborState neighborState = buildNeighborState(NeighborEntry.NeighborType.L3, portHostInfo, operationType, vpcid); + if (subnetIds.contains(internalSubnetPort.getSubnetId()) && ips.contains(portHostInfo.getPortIp())) { + multicastGoalStateV2.getGoalStateBuilder().putNeighborStates(neighborState.getConfiguration().getId(), neighborState); + } else { + multicastGoalStateV2.getHostIps().add(portHostInfo.getHostIp()); + neighborStateMap.put(neighborState.getConfiguration().getId(), neighborState); + subnetStateMap.put(internalSubnetPort.getSubnetId(), subnetService.buildSubnetState(internalSubnetPort.getSubnetId()).build()); + } + if (!unicastGoalStateV2.getGoalStateBuilder().getSubnetStatesMap().containsKey(internalSubnetPort.getSubnetId())){ + System.out.println("Router state: " + internalSubnetPort.getSubnetId()); + Router.RouterConfiguration.SubnetRoutingTable.Builder subnetRoutingTableBuilder = Router.RouterConfiguration.SubnetRoutingTable.newBuilder(); + String subnetId = portHostInfo.getSubnetId(); + subnetRoutingTableBuilder.setSubnetId(subnetId); + Router.RouterConfiguration.Builder routerConfigurationBuilder = unicastGoalStateV2.getGoalStateBuilder().getRouterStatesMap().get(routerId).getConfiguration().toBuilder(); + routerConfigurationBuilder.addSubnetRoutingTables(subnetRoutingTableBuilder.build()); + unicastGoalStateV2.getGoalStateBuilder().putRouterStates(routerId, Router.RouterState.newBuilder().setConfiguration(routerConfigurationBuilder).build()); + } + } catch (Exception e) { + e.printStackTrace(); + } + }); + + } catch (CacheException e) { + e.printStackTrace(); + } + } + } catch (CacheException e) { + e.printStackTrace(); + } + }); + + /* + + portStates.parallelStream().forEach(portState -> { + String routerId = portState.getConfiguration().getFixedIpsList().stream().map(fixedIp -> fixedIp.getSubnetId()).collect(Collectors.toList()).get(0); + Collection internalSubnetPorts = null; + try { + internalSubnetPorts = subnetPortsCache.getSubnetPortsByRouterId(routerId); + for (InternalSubnetPorts internalSubnetPort : internalSubnetPorts) { + try { + Collection portHostInfos = portHostInfoCache.getPortHostInfos(internalSubnetPort.getSubnetId()); + portHostInfos.parallelStream().forEach(portHostInfo -> { + try { + Neighbor.NeighborState neighborState = buildNeighborState(NeighborEntry.NeighborType.L3, portHostInfo, operationType, portState.getConfiguration().getVpcId()); + if (!subnetIds.contains(internalSubnetPort.getSubnetId())) { + multicastGoalStateV2.getHostIps().add(portHostInfo.getHostIp()); + multicastGoalStateV2.getGoalStateBuilder().putAllSubnetStates(unicastGoalStateV2.getGoalStateBuilder().getSubnetStatesMap()); + multicastGoalStateV2.getGoalStateBuilder().putAllRouterStates(unicastGoalStateV2.getGoalStateBuilder().getRouterStatesMap()); + multicastGoalStateV2.getGoalStateBuilder().putNeighborStates(portHostInfo.getPortId(), neighborState); + } else { + neighborStateMap.put(portHostInfo.getPortId(), neighborState); + } + } catch (Exception e) { + e.printStackTrace(); + } + }); + + } catch (CacheException e) { + e.printStackTrace(); + } + } + } catch (CacheException e) { + e.printStackTrace(); + } + }); + + */ + unicastGoalStateV2.getGoalStateBuilder().putAllNeighborStates(neighborStateMap); + unicastGoalStateV2.getGoalStateBuilder().putAllSubnetStates(subnetStateMap); + if (multicastGoalStateV2.getHostIps().size() == 0){ + multicastGoalStateV2.getGoalStateBuilder().clear(); + } + } } diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/RouterService.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/RouterService.java index 4703eae46..b9f8cefb7 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/RouterService.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/RouterService.java @@ -151,7 +151,7 @@ public void buildRouterStates(NetworkConfiguration networkConfig, UnicastGoalSta } } - public void buildRouterState(InternalRouterInfo routerInfo, InternalSubnetRoutingTable subnetRoutingTable, UnicastGoalStateV2 unicastGoalState, MulticastGoalStateV2 multicastGoalState) { + public void buildRouterState(InternalRouterInfo routerInfo, InternalSubnetRoutingTable subnetRoutingTable, UnicastGoalStateV2 unicastGoalState) { Router.RouterConfiguration.SubnetRoutingTable.Builder subnetRoutingTableBuilder = Router.RouterConfiguration.SubnetRoutingTable.newBuilder(); String subnetId = subnetRoutingTable.getSubnetId(); subnetRoutingTableBuilder.setSubnetId(subnetId); @@ -213,10 +213,9 @@ public void buildRouterState(InternalRouterInfo routerInfo, InternalSubnetRoutin routerStateBuilder.setConfiguration(routerConfigBuilder.build()); Router.RouterState routerState = routerStateBuilder.build(); unicastGoalState.getGoalStateBuilder().putRouterStates(routerState.getConfiguration().getId(), routerState); - multicastGoalState.getGoalStateBuilder().putRouterStates(routerState.getConfiguration().getId(), routerState); } - public void buildRouterStates(NetworkConfiguration networkConfig, UnicastGoalStateV2 unicastGoalState, MulticastGoalStateV2 multicastGoalState) throws Exception { + public void buildRouterStates(NetworkConfiguration networkConfig, UnicastGoalStateV2 unicastGoalState) throws Exception { List portStates = new ArrayList(unicastGoalState.getGoalStateBuilder().getPortStatesMap().values()); if (portStates == null || portStates.size() == 0) { return; @@ -247,7 +246,7 @@ public void buildRouterStates(NetworkConfiguration networkConfig, UnicastGoalSta for (InternalSubnetRoutingTable subnetRoutingTable : subnetRoutingTables) { if (subnetId.equals(subnetRoutingTable.getSubnetId())) { - buildRouterState(routerInfo, subnetRoutingTable, unicastGoalState, multicastGoalState); + buildRouterState(routerInfo, subnetRoutingTable, unicastGoalState); break; } } diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/SubnetService.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/SubnetService.java index a3daa2f67..904ca5e5a 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/SubnetService.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/SubnetService.java @@ -120,6 +120,35 @@ public void buildSubnetState (String subnetId, UnicastGoalState unicastGoalState } } + public Subnet.SubnetState.Builder buildSubnetState (String subnetId) throws Exception + { + InternalSubnetPorts subnetEntity = subnetPortsCache.getSubnetPorts(subnetId); + Subnet.SubnetConfiguration.Builder subnetConfigBuilder = Subnet.SubnetConfiguration.newBuilder(); + subnetConfigBuilder.setRevisionNumber(FORMAT_REVISION_NUMBER); + subnetConfigBuilder.setId(subnetId); + subnetConfigBuilder.setNetworkType(Common.NetworkType.VXLAN); + subnetConfigBuilder.setVpcId(subnetEntity.getVpcId()); + subnetConfigBuilder.setName(subnetEntity.getName()); + subnetConfigBuilder.setCidr(subnetEntity.getCidr()); + subnetConfigBuilder.setTunnelId(subnetEntity.getTunnelId()); + + Subnet.SubnetConfiguration.Gateway.Builder gatewayBuilder = Subnet.SubnetConfiguration.Gateway.newBuilder(); + gatewayBuilder.setIpAddress(subnetEntity.getGatewayPortIp()); + gatewayBuilder.setMacAddress(subnetEntity.getGatewayPortMac()); + subnetConfigBuilder.setGateway(gatewayBuilder.build()); + + if (subnetEntity.getDhcpEnable() != null) { + subnetConfigBuilder.setDhcpEnable(true); + } + + // TODO: need to set DNS based on latest contract + + Subnet.SubnetState.Builder subnetStateBuilder = Subnet.SubnetState.newBuilder(); + subnetStateBuilder.setOperationType(Common.OperationType.INFO); + subnetStateBuilder.setConfiguration(subnetConfigBuilder.build()); + return subnetStateBuilder; + } + public void buildSubnetState (String subnetId, UnicastGoalStateV2 unicastGoalState, MulticastGoalStateV2 multicastGoalState) throws Exception { InternalSubnetPorts subnetEntity = subnetPortsCache.getSubnetPorts(subnetId); @@ -227,11 +256,16 @@ private void buildSubnetState(String id, Subnet.SubnetState.Builder subnetStateBuilder = Subnet.SubnetState.newBuilder(); subnetStateBuilder.setOperationType(Common.OperationType.INFO); subnetStateBuilder.setConfiguration(subnetConfigBuilder.build()); - unicastGoalState.getGoalStateBuilder().putSubnetStates(id, subnetStateBuilder.build()); - multicastGoalState.getGoalStateBuilder().putSubnetStates(id, subnetStateBuilder.build()); + if (unicastGoalState != null) { + unicastGoalState.getGoalStateBuilder().putSubnetStates(id, subnetStateBuilder.build()); + } + if (multicastGoalState != null) { + multicastGoalState.getGoalStateBuilder().putSubnetStates(id, subnetStateBuilder.build()); + } + } - public void buildSubnetStates(NetworkConfiguration networkConfig, UnicastGoalStateV2 unicastGoalState, MulticastGoalStateV2 multicastGoalState) throws Exception { + public void buildSubnetStates(NetworkConfiguration networkConfig, UnicastGoalStateV2 unicastGoalState) throws Exception { Map portStateMap = unicastGoalState.getGoalStateBuilder().getPortStatesMap(); List portStates = new ArrayList(portStateMap.values()); if (portStates == null || portStates.size() == 0) { @@ -282,7 +316,6 @@ public void buildSubnetStates(NetworkConfiguration networkConfig, UnicastGoalSta subnetStateBuilder.setConfiguration(subnetConfigBuilder.build()); Subnet.SubnetState subnetState = subnetStateBuilder.build(); unicastGoalState.getGoalStateBuilder().putSubnetStates(subnetState.getConfiguration().getId(), subnetState); - multicastGoalState.getGoalStateBuilder().putSubnetStates(subnetState.getConfiguration().getId(), subnetState); } } } diff --git a/web/src/main/java/com/futurewei/alcor/web/entity/port/PortHostInfo.java b/web/src/main/java/com/futurewei/alcor/web/entity/port/PortHostInfo.java index b8582dec2..9db7413af 100644 --- a/web/src/main/java/com/futurewei/alcor/web/entity/port/PortHostInfo.java +++ b/web/src/main/java/com/futurewei/alcor/web/entity/port/PortHostInfo.java @@ -21,17 +21,19 @@ public class PortHostInfo { private String portMac; private String hostId; private String hostIp; + private String subnetId; public PortHostInfo() { } - public PortHostInfo(String portId, String portIp, String portMac, String hostId, String hostIp) { + public PortHostInfo(String portId, String portIp, String portMac, String hostId, String hostIp, String subnetId) { this.portId = portId; this.portIp = portIp; this.portMac = portMac; this.hostId = hostId; this.hostIp = hostIp; + this.subnetId = subnetId; } public String getPortId() { @@ -73,4 +75,12 @@ public String getHostIp() { public void setHostIp(String hostIp) { this.hostIp = hostIp; } + + public String getSubnetId() { + return subnetId; + } + + public void setSubnetId(String subnetId) { + this.subnetId = subnetId; + } } diff --git a/web/src/main/java/com/futurewei/alcor/web/entity/subnet/InternalSubnetPorts.java b/web/src/main/java/com/futurewei/alcor/web/entity/subnet/InternalSubnetPorts.java index 9f72b846a..7faee5047 100644 --- a/web/src/main/java/com/futurewei/alcor/web/entity/subnet/InternalSubnetPorts.java +++ b/web/src/main/java/com/futurewei/alcor/web/entity/subnet/InternalSubnetPorts.java @@ -36,6 +36,21 @@ public InternalSubnetPorts() { } + public InternalSubnetPorts(String subnetId, String gatewayPortId, String gatewayPortIp, String gatewayPortMac, + String name, String cidr, String vpcId, Long tunnelId, Boolean dhcpEnable, String routerId) { + this.subnetId = subnetId; + this.gatewayPortId = gatewayPortId; + this.gatewayPortIp = gatewayPortIp; + this.gatewayPortMac = gatewayPortMac; + this.name = name; + this.cidr = cidr; + this.vpcId = vpcId; + this.tunnelId = tunnelId; + this.dhcpEnable = dhcpEnable; + this.routerId = routerId; + this.ports = ports; + } + public InternalSubnetPorts(String subnetId, String gatewayPortId, String gatewayPortIp, String gatewayPortMac, String name, String cidr, String vpcId, Long tunnelId, Boolean dhcpEnable, String routerId, List ports) { @@ -49,7 +64,6 @@ public InternalSubnetPorts(String subnetId, String gatewayPortId, String gateway this.tunnelId = tunnelId; this.dhcpEnable = dhcpEnable; this.routerId = routerId; - this.ports = ports; } public String getSubnetId() { From 98f1e69f2e8b76243fb6d78758b3b5541daf1e29 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Mon, 6 Dec 2021 09:37:45 -0800 Subject: [PATCH 14/33] Update code --- .../service/impl/NeighborService.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java index 99909e904..4c7f2b74f 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java @@ -426,15 +426,15 @@ public void buildNeighborStatesL3(NetworkConfiguration networkConfiguration, Uni multicastGoalStateV2.getHostIps().add(portHostInfo.getHostIp()); neighborStateMap.put(neighborState.getConfiguration().getId(), neighborState); subnetStateMap.put(internalSubnetPort.getSubnetId(), subnetService.buildSubnetState(internalSubnetPort.getSubnetId()).build()); - } - if (!unicastGoalStateV2.getGoalStateBuilder().getSubnetStatesMap().containsKey(internalSubnetPort.getSubnetId())){ - System.out.println("Router state: " + internalSubnetPort.getSubnetId()); - Router.RouterConfiguration.SubnetRoutingTable.Builder subnetRoutingTableBuilder = Router.RouterConfiguration.SubnetRoutingTable.newBuilder(); - String subnetId = portHostInfo.getSubnetId(); - subnetRoutingTableBuilder.setSubnetId(subnetId); - Router.RouterConfiguration.Builder routerConfigurationBuilder = unicastGoalStateV2.getGoalStateBuilder().getRouterStatesMap().get(routerId).getConfiguration().toBuilder(); - routerConfigurationBuilder.addSubnetRoutingTables(subnetRoutingTableBuilder.build()); - unicastGoalStateV2.getGoalStateBuilder().putRouterStates(routerId, Router.RouterState.newBuilder().setConfiguration(routerConfigurationBuilder).build()); + if (!unicastGoalStateV2.getGoalStateBuilder().getSubnetStatesMap().containsKey(internalSubnetPort.getSubnetId())){ + System.out.println("Router state: " + internalSubnetPort.getSubnetId()); + Router.RouterConfiguration.SubnetRoutingTable.Builder subnetRoutingTableBuilder = Router.RouterConfiguration.SubnetRoutingTable.newBuilder(); + String subnetId = portHostInfo.getSubnetId(); + subnetRoutingTableBuilder.setSubnetId(subnetId); + Router.RouterConfiguration.Builder routerConfigurationBuilder = unicastGoalStateV2.getGoalStateBuilder().getRouterStatesMap().get(routerId).getConfiguration().toBuilder(); + routerConfigurationBuilder.addSubnetRoutingTables(subnetRoutingTableBuilder.build()); + unicastGoalStateV2.getGoalStateBuilder().putRouterStates(routerId, Router.RouterState.newBuilder().setConfiguration(routerConfigurationBuilder).build()); + } } } catch (Exception e) { e.printStackTrace(); From 397bd471849d954741245304ac705805e6e9e871 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Mon, 6 Dec 2021 14:53:16 -0800 Subject: [PATCH 15/33] Update code --- .../service/impl/DpmServiceImplV2.java | 116 ++---------------- .../service/impl/NeighborService.java | 90 +++++++++----- .../dataplane/service/impl/RouterService.java | 8 +- .../controller/NeutronRouterController.java | 8 +- .../Impl/NeutronRouterServiceImpl.java | 8 +- .../service/Impl/RouterToDPMServiceImpl.java | 10 +- .../route/service/NeutronRouterService.java | 3 +- .../route/service/RouterToDPMService.java | 3 +- 8 files changed, 92 insertions(+), 154 deletions(-) diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/DpmServiceImplV2.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/DpmServiceImplV2.java index 95b9f10e1..e66177657 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/DpmServiceImplV2.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/DpmServiceImplV2.java @@ -142,7 +142,7 @@ private UnicastGoalStateV2 buildUnicastGoalState(NetworkConfiguration networkCon neighborService.buildNeighborStatesL2(unicastGoalState, multicastGoalState, networkConfig.getOpType()); if (networkConfig.getInternalRouterInfos() != null) { - neighborService.buildNeighborStatesL3(networkConfig, unicastGoalState, multicastGoalState, networkConfig.getOpType()); + neighborService.buildNeighborStatesL3(networkConfig, unicastGoalState, multicastGoalState); } unicastGoalState.setGoalState(unicastGoalState.getGoalStateBuilder().build()); @@ -456,126 +456,24 @@ private void rebuildRouterState(Goalstate.GoalStateV2.Builder goalStateBuilder, * @throws Exception Process exceptions and send exceptions */ private List processNeighborConfiguration(NetworkConfiguration networkConfig) throws Exception { - Map neighborInfos = networkConfig.getNeighborInfos(); - Map> neighborTable = networkConfig.getNeighborTable(); - List unicastGoalStates = new ArrayList<>(); + Map unicastGoalStates = new HashMap<>(); MulticastGoalStateV2 multicastGoalState = new MulticastGoalStateV2(); - Map> hostsSubnets = new HashMap<>(); - - if (neighborTable == null || neighborInfos == null) { - throw new NeighborInfoNotFound(); - //return new ArrayList<>(); - } - - Map> hostNeighbors = new HashMap<>(); - for (Map.Entry> entry: neighborTable.entrySet()) { - String portIp = entry.getKey(); - NeighborInfo localInfo = neighborInfos.get(portIp); - if (localInfo == null) { - throw new NeighborInfoNotFound(); - } - - String hostIp = localInfo.getHostIp(); - if (!hostNeighbors.containsKey(hostIp)) { - hostNeighbors.put(hostIp, new ArrayList<>()); - hostsSubnets.put(hostIp, new ArrayList<>()); - } - hostsSubnets.get(hostIp).add(localInfo.getSubnetId()); - - List neighborEntries = entry.getValue(); - for (NeighborEntry neighborEntry: neighborEntries) { - String neighborIp = neighborEntry.getNeighborIp(); - NeighborInfo neighborInfo = neighborInfos.get(neighborIp); - if (neighborInfo == null) { - throw new NeighborInfoNotFound(); - } - if (!Objects.equals(neighborEntry.getNeighborType().name(), "L2")) { - hostNeighbors.get(hostIp).add(neighborInfo); - multicastGoalState.getHostIps().add(neighborInfo.getHostIp()); - } - } - - if (multicastGoalState.getHostIps().size() <= 0) { - // return new ArrayList<>(); - continue; - } - //Add neighborInfo to multicastGoalState - Neighbor.NeighborState neighborState = neighborService.buildNeighborState( - NeighborEntry.NeighborType.L3, localInfo, networkConfig.getOpType()); - multicastGoalState.getGoalStateBuilder().putNeighborStates(neighborState.getConfiguration().getId(), neighborState); - UnicastGoalStateV2 unicastGoalStateTemp = new UnicastGoalStateV2(); - unicastGoalStateTemp.getGoalStateBuilder().putNeighborStates(neighborState.getConfiguration().getId(), neighborState); - patchGoalstateForNeighbor(networkConfig, unicastGoalStateTemp); - if (unicastGoalStateTemp.getGoalStateBuilder().getRouterStatesMap() != null && - unicastGoalStateTemp.getGoalStateBuilder().getRouterStatesMap().size() > 0 ) { - multicastGoalState.getGoalStateBuilder().putAllSubnetStates(unicastGoalStateTemp.getGoalStateBuilder().getSubnetStatesMap()); - } - if (unicastGoalStateTemp.getGoalStateBuilder().getRouterStatesMap() != null && - unicastGoalStateTemp.getGoalStateBuilder().getRouterStatesMap().size() > 0) { - multicastGoalState.getGoalStateBuilder().putAllRouterStates(unicastGoalStateTemp.getGoalStateBuilder().getRouterStatesMap()); - } - } - - boolean patchRouterSubnetStates = false; - for (Map.Entry> entry: hostNeighbors.entrySet()) { - String hostIp = entry.getKey(); - List hostNeighborInfos = entry.getValue(); - - if (hostNeighborInfos.size() <= 0) { - multicastGoalState.getHostIps().add(hostIp); - patchRouterSubnetStates = true; - } - - /** - * At present, there are only L3 neighbors in the neighbor table, - * and the processing of L2 neighbors should be considered in the future. - */ - for (NeighborInfo neighborInfo: hostNeighborInfos) { - Neighbor.NeighborState neighborState = neighborService.buildNeighborState( - NeighborEntry.NeighborType.L3, - neighborInfo, - networkConfig.getOpType()); - - UnicastGoalStateV2 unicastGoalState = new UnicastGoalStateV2(); - //unicastGoalState.setHostIp(neighborInfo.getHostIp()); - unicastGoalState.setHostIp(hostIp); - unicastGoalState.getGoalStateBuilder().putNeighborStates(neighborState.getConfiguration().getId(), neighborState); - - // use unicastGoalStateTemp object to get patchGoalStates for neighborState update - // unicasGoalStateTemp will include subnet_states and a consolidated router_state based on the current neighborState - UnicastGoalStateV2 unicastGoalStateTemp = new UnicastGoalStateV2(); - unicastGoalStateTemp.getGoalStateBuilder().putNeighborStates(neighborState.getConfiguration().getId(), neighborState); - patchGoalstateForNeighbor(networkConfig, unicastGoalStateTemp); - - unicastGoalState.getGoalStateBuilder().putAllSubnetStates(unicastGoalStateTemp.getGoalStateBuilder().getSubnetStatesMap()); - unicastGoalState.getGoalStateBuilder().putAllRouterStates(unicastGoalStateTemp.getGoalStateBuilder().getRouterStatesMap()); - unicastGoalState.getGoalStateBuilder().putAllSubnetStates(multicastGoalState.getGoalStateBuilder().getSubnetStatesMap()); - rebuildRouterState(unicastGoalState.getGoalStateBuilder(), multicastGoalState.getGoalStateBuilder()); - multicastGoalState.getGoalStateBuilder().putAllSubnetStates(unicastGoalStateTemp.getGoalStateBuilder().getSubnetStatesMap()); - rebuildRouterState(multicastGoalState.getGoalStateBuilder(), unicastGoalStateTemp.getGoalStateBuilder()); - unicastGoalStates.add(unicastGoalState); - } - } - - /** - * The flag patchRouterSubnetStates is to fix issue #686 (issue from test scenario 4.5) - */ - if (patchRouterSubnetStates) { - patchGoalstateForRouterSubnet(networkConfig, hostsSubnets, multicastGoalState); + if (networkConfig.getInternalRouterInfos() != null) { + neighborService.buildNeighborStatesL3(networkConfig, unicastGoalStates, multicastGoalState); } multicastGoalState.setGoalState(multicastGoalState.getGoalStateBuilder().build()); multicastGoalState.setGoalStateBuilder(null); - unicastGoalStates.stream().forEach(u -> { + unicastGoalStates.values().stream().forEach(u -> { u.setGoalState(u.getGoalStateBuilder().build()); u.setGoalStateBuilder(null); }); if (USE_PULSAR_CLIENT) { - return pulsarDataPlaneClient.sendGoalStates(unicastGoalStates, multicastGoalState); + return pulsarDataPlaneClient.sendGoalStates(new ArrayList<>(unicastGoalStates.values()), multicastGoalState); } - return grpcDataPlaneClient.sendGoalStates(unicastGoalStates, multicastGoalState); + return grpcDataPlaneClient.sendGoalStates(new ArrayList<>(unicastGoalStates.values()), multicastGoalState); } private List processSecurityGroupConfiguration(NetworkConfiguration networkConfig) throws Exception { diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java index 4c7f2b74f..c9ebd29fb 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java @@ -29,6 +29,8 @@ free of charge, to any person obtaining a copy of this software and associated d import com.futurewei.alcor.web.entity.dataplane.v2.NetworkConfiguration; import com.futurewei.alcor.web.entity.port.PortEntity; import com.futurewei.alcor.web.entity.port.PortHostInfo; +import com.futurewei.alcor.web.entity.route.InternalRouterInfo; +import com.futurewei.alcor.web.entity.route.InternalSubnetRoutingTable; import com.futurewei.alcor.web.entity.subnet.InternalSubnetPorts; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -51,6 +53,9 @@ public class NeighborService extends ResourceService { @Autowired private SubnetService subnetService; + @Autowired + private RouterService routerService; + public Neighbor.NeighborState buildNeighborState(NeighborEntry.NeighborType type, NeighborInfo neighborInfo, Common.OperationType operationType) throws Exception { Neighbor.NeighborConfiguration.Builder neighborConfigBuilder = Neighbor.NeighborConfiguration.newBuilder(); neighborConfigBuilder.setRevisionNumber(FORMAT_REVISION_NUMBER); @@ -377,7 +382,7 @@ public void buildNeighborStatesL2(UnicastGoalStateV2 unicastGoalStateV2, Multica } } - public void buildNeighborStatesL3(NetworkConfiguration networkConfiguration, UnicastGoalStateV2 unicastGoalStateV2, MulticastGoalStateV2 multicastGoalStateV2, Common.OperationType operationType) { + public void buildNeighborStatesL3(NetworkConfiguration networkConfiguration, UnicastGoalStateV2 unicastGoalStateV2, MulticastGoalStateV2 multicastGoalStateV2) { Collection portStates = unicastGoalStateV2.getGoalStateBuilder().getPortStatesMap().values(); Map neighborStateMap = new TreeMap<>(); Map subnetStateMap = new TreeMap<>(); @@ -419,7 +424,7 @@ public void buildNeighborStatesL3(NetworkConfiguration networkConfiguration, Uni } portHostInfos.parallelStream().forEach(portHostInfo -> { try { - Neighbor.NeighborState neighborState = buildNeighborState(NeighborEntry.NeighborType.L3, portHostInfo, operationType, vpcid); + Neighbor.NeighborState neighborState = buildNeighborState(NeighborEntry.NeighborType.L3, portHostInfo, networkConfiguration.getOpType(), vpcid); if (subnetIds.contains(internalSubnetPort.getSubnetId()) && ips.contains(portHostInfo.getPortIp())) { multicastGoalStateV2.getGoalStateBuilder().putNeighborStates(neighborState.getConfiguration().getId(), neighborState); } else { @@ -449,47 +454,68 @@ public void buildNeighborStatesL3(NetworkConfiguration networkConfiguration, Uni e.printStackTrace(); } }); + unicastGoalStateV2.getGoalStateBuilder().putAllNeighborStates(neighborStateMap); + unicastGoalStateV2.getGoalStateBuilder().putAllSubnetStates(subnetStateMap); + if (multicastGoalStateV2.getHostIps().size() == 0){ + multicastGoalStateV2.getGoalStateBuilder().clear(); + } + } - /* - portStates.parallelStream().forEach(portState -> { - String routerId = portState.getConfiguration().getFixedIpsList().stream().map(fixedIp -> fixedIp.getSubnetId()).collect(Collectors.toList()).get(0); - Collection internalSubnetPorts = null; + public void buildNeighborStatesL3(NetworkConfiguration networkConfiguration, Map unicastGoalStates, MulticastGoalStateV2 multicastGoalState) throws CacheException { + String routerId = subnetPortsCache.getInternalSubnetRouterMap(networkConfiguration).values().stream().collect(Collectors.toSet()).stream().findFirst().orElse(""); + Map neighborStateMap = new TreeMap<>(); + Map subnetStateMap = new TreeMap<>(); + Router.RouterConfiguration.Builder routerConfigurationBuilder = Router.RouterConfiguration.newBuilder(); + String subnetId = networkConfiguration.getInternalRouterInfos().stream().flatMap(routerInfo -> + routerInfo.getRouterConfiguration().getSubnetRoutingTables().stream().map(subnetRoutingTable -> subnetRoutingTable.getSubnetId()) + ).collect(Collectors.toSet()).stream().findFirst().orElse(""); + String vpcid = subnetPortsCache.getSubnetPorts(subnetId).getVpcId(); + portHostInfoCache.getPortHostInfos(subnetId) + .forEach(portState -> unicastGoalStates.put(portState.getHostIp(), new UnicastGoalStateV2(portState.getHostIp(), Goalstate.GoalStateV2.newBuilder().build()))); + + Collection internalSubnetPorts = subnetPortsCache.getSubnetPortsByRouterId(routerId); + for (InternalSubnetPorts internalSubnetPort : internalSubnetPorts) { try { - internalSubnetPorts = subnetPortsCache.getSubnetPortsByRouterId(routerId); - for (InternalSubnetPorts internalSubnetPort : internalSubnetPorts) { + Collection portHostInfos = portHostInfoCache.getPortHostInfos(internalSubnetPort.getSubnetId()); + portHostInfos.parallelStream().forEach(portHostInfo -> { try { - Collection portHostInfos = portHostInfoCache.getPortHostInfos(internalSubnetPort.getSubnetId()); - portHostInfos.parallelStream().forEach(portHostInfo -> { - try { - Neighbor.NeighborState neighborState = buildNeighborState(NeighborEntry.NeighborType.L3, portHostInfo, operationType, portState.getConfiguration().getVpcId()); - if (!subnetIds.contains(internalSubnetPort.getSubnetId())) { - multicastGoalStateV2.getHostIps().add(portHostInfo.getHostIp()); - multicastGoalStateV2.getGoalStateBuilder().putAllSubnetStates(unicastGoalStateV2.getGoalStateBuilder().getSubnetStatesMap()); - multicastGoalStateV2.getGoalStateBuilder().putAllRouterStates(unicastGoalStateV2.getGoalStateBuilder().getRouterStatesMap()); - multicastGoalStateV2.getGoalStateBuilder().putNeighborStates(portHostInfo.getPortId(), neighborState); - } else { - neighborStateMap.put(portHostInfo.getPortId(), neighborState); - } - } catch (Exception e) { - e.printStackTrace(); - } - }); + Neighbor.NeighborState neighborState = buildNeighborState(NeighborEntry.NeighborType.L3, portHostInfo, networkConfiguration.getOpType(), vpcid); + if (subnetId.equals(internalSubnetPort.getSubnetId())) { + multicastGoalState.getGoalStateBuilder().putNeighborStates(neighborState.getConfiguration().getId(), neighborState); + multicastGoalState.getGoalStateBuilder().putSubnetStates(subnetId, subnetService.buildSubnetState(subnetId).build()); + InternalSubnetRoutingTable subnetRoutingTableList = networkConfiguration + .getInternalRouterInfos().stream().findFirst().orElse(null).getRouterConfiguration().getSubnetRoutingTables().stream().findFirst().orElse(null); + Router.RouterState.Builder routerStateBuilder = routerService.buildRouterState(networkConfiguration.getInternalRouterInfos().get(0), subnetRoutingTableList); + multicastGoalState.getGoalStateBuilder().putRouterStates(routerId, routerStateBuilder.build()); + } else { + multicastGoalState.getHostIps().add(portHostInfo.getHostIp()); + neighborStateMap.put(neighborState.getConfiguration().getId(), neighborState); + subnetStateMap.put(internalSubnetPort.getSubnetId(), subnetService.buildSubnetState(internalSubnetPort.getSubnetId()).build()); + + System.out.println("Router state: " + internalSubnetPort.getSubnetId()); + Router.RouterConfiguration.SubnetRoutingTable.Builder subnetRoutingTableBuilder = Router.RouterConfiguration.SubnetRoutingTable.newBuilder(); + subnetRoutingTableBuilder.setSubnetId(internalSubnetPort.getSubnetId()); + routerConfigurationBuilder.addSubnetRoutingTables(subnetRoutingTableBuilder.build()); - } catch (CacheException e) { + } + } catch (Exception e) { e.printStackTrace(); } - } + }); + } catch (CacheException e) { e.printStackTrace(); } - }); + } - */ - unicastGoalStateV2.getGoalStateBuilder().putAllNeighborStates(neighborStateMap); - unicastGoalStateV2.getGoalStateBuilder().putAllSubnetStates(subnetStateMap); - if (multicastGoalStateV2.getHostIps().size() == 0){ - multicastGoalStateV2.getGoalStateBuilder().clear(); + for (UnicastGoalStateV2 unicastGoalStateV2 : unicastGoalStates.values()) { + unicastGoalStateV2.getGoalStateBuilder().putAllNeighborStates(neighborStateMap); + unicastGoalStateV2.getGoalStateBuilder().putAllSubnetStates(subnetStateMap); + unicastGoalStateV2.getGoalStateBuilder().putRouterStates(routerId, Router.RouterState.newBuilder().setConfiguration(routerConfigurationBuilder).build()); + } + if (multicastGoalState.getHostIps().size() == 0){ + multicastGoalState.getGoalStateBuilder().clear(); } } } diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/RouterService.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/RouterService.java index b9f8cefb7..994609333 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/RouterService.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/RouterService.java @@ -151,7 +151,7 @@ public void buildRouterStates(NetworkConfiguration networkConfig, UnicastGoalSta } } - public void buildRouterState(InternalRouterInfo routerInfo, InternalSubnetRoutingTable subnetRoutingTable, UnicastGoalStateV2 unicastGoalState) { + public Router.RouterState.Builder buildRouterState(InternalRouterInfo routerInfo, InternalSubnetRoutingTable subnetRoutingTable, UnicastGoalStateV2... unicastGoalState) { Router.RouterConfiguration.SubnetRoutingTable.Builder subnetRoutingTableBuilder = Router.RouterConfiguration.SubnetRoutingTable.newBuilder(); String subnetId = subnetRoutingTable.getSubnetId(); subnetRoutingTableBuilder.setSubnetId(subnetId); @@ -187,7 +187,7 @@ public void buildRouterState(InternalRouterInfo routerInfo, InternalSubnetRoutin List subnetRoutingTablesList = new ArrayList<>(); subnetRoutingTablesList.add(subnetRoutingTableBuilder.build()); - Goalstate.GoalStateV2.Builder goalStateBuilder = unicastGoalState.getGoalStateBuilder(); + Goalstate.GoalStateV2.Builder goalStateBuilder = unicastGoalState[0].getGoalStateBuilder(); List routerStatesBuilders = new ArrayList(goalStateBuilder.getRouterStatesMap().values()); if (routerStatesBuilders != null && routerStatesBuilders.size() > 0) { @@ -212,9 +212,11 @@ public void buildRouterState(InternalRouterInfo routerInfo, InternalSubnetRoutin Router.RouterState.Builder routerStateBuilder = Router.RouterState.newBuilder(); routerStateBuilder.setConfiguration(routerConfigBuilder.build()); Router.RouterState routerState = routerStateBuilder.build(); - unicastGoalState.getGoalStateBuilder().putRouterStates(routerState.getConfiguration().getId(), routerState); + unicastGoalState[0].getGoalStateBuilder().putRouterStates(routerState.getConfiguration().getId(), routerState); + return routerStateBuilder; } + public void buildRouterStates(NetworkConfiguration networkConfig, UnicastGoalStateV2 unicastGoalState) throws Exception { List portStates = new ArrayList(unicastGoalState.getGoalStateBuilder().getPortStatesMap().values()); if (portStates == null || portStates.size() == 0) { diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/NeutronRouterController.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/NeutronRouterController.java index c07047b66..6ab8f1658 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/NeutronRouterController.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/NeutronRouterController.java @@ -322,8 +322,8 @@ public RouterInterfaceResponse addInterfaceToNeutronRouter(@PathVariable String InternalSubnetRoutingTable internalSubnetRoutingTable = updateRoutingRuleResponse.getInternalSubnetRoutingTable(); List internalSubnetRoutingTableList = this.neutronRouterService.constructInternalSubnetRoutingTables(router); internalSubnetRoutingTableList.add(internalSubnetRoutingTable); - InternalRouterInfo internalRouterInfo = this.neutronRouterService.constructInternalRouterInfo(routerid, internalSubnetRoutingTableList); - this.routerToPMService.updateL3Neighbors(projectid, router.getOwner(), subnetId, "add", gatewayPorts, internalRouterInfo); + InternalRouterInfo internalRouterInfo = this.neutronRouterService.constructInternalRouterInfo(routerid, internalSubnetRoutingTableList, OperationType.CREATE); + this.routerToDPMService.sendInternalRouterInfoToDPM(internalRouterInfo, Common.ResourceType.NEIGHBOR); } return routerInterfaceResponse; @@ -373,8 +373,8 @@ public RouterInterfaceResponse removeInterfaceToNeutronRouter(@PathVariable Stri List internalSubnetRoutingTableList = this.neutronRouterService.constructInternalSubnetRoutingTables(router); internalSubnetRoutingTableList.add(internalSubnetRoutingTable); - InternalRouterInfo internalRouterInfo = this.neutronRouterService.constructInternalRouterInfo(routerid, internalSubnetRoutingTableList); - this.routerToPMService.updateL3Neighbors(projectid, router.getOwner(), subnetId, "delete", gatewayPorts, internalRouterInfo); + InternalRouterInfo internalRouterInfo = this.neutronRouterService.constructInternalRouterInfo(routerid, internalSubnetRoutingTableList, OperationType.DELETE); + this.routerToDPMService.sendInternalRouterInfoToDPM(internalRouterInfo, Common.ResourceType.NEIGHBOR); } return routerInterfaceResponse; diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/NeutronRouterServiceImpl.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/NeutronRouterServiceImpl.java index 5da6ce48e..3029c39e8 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/NeutronRouterServiceImpl.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/NeutronRouterServiceImpl.java @@ -660,7 +660,7 @@ public UpdateRoutingRuleResponse updateRoutingRule (String owner, NewRoutesWebRe } @Override - public InternalRouterInfo constructInternalRouterInfo (String routerId, List internalSubnetRoutingTableList) { + public InternalRouterInfo constructInternalRouterInfo (String routerId, List internalSubnetRoutingTableList, OperationType... operationType) { String requestId = UUID.randomUUID().toString(); InternalRouterInfo internalRouterInfo = new InternalRouterInfo(); @@ -675,8 +675,12 @@ public InternalRouterInfo constructInternalRouterInfo (String routerId, List internalRouterInfos = new ArrayList<>(); internalRouterInfos.add(internalRouterInfo); networkConfiguration.setInternalRouterInfos(internalRouterInfos); - networkConfiguration.setRsType(Common.ResourceType.ROUTER); + + if (resourceTypes.length == 0) { + networkConfiguration.setRsType(Common.ResourceType.ROUTER); + } else { + networkConfiguration.setRsType(resourceTypes[0]); + } + switch (internalRouterInfo.getOperationType()) { case CREATE: diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/NeutronRouterService.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/NeutronRouterService.java index 18ce95042..1ac7495de 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/NeutronRouterService.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/NeutronRouterService.java @@ -16,6 +16,7 @@ free of charge, to any person obtaining a copy of this software and associated d package com.futurewei.alcor.route.service; import com.futurewei.alcor.common.db.CacheException; +import com.futurewei.alcor.common.enumClass.OperationType; import com.futurewei.alcor.common.exception.DatabasePersistenceException; import com.futurewei.alcor.common.exception.QueryParamTypeNotSupportException; import com.futurewei.alcor.common.exception.ResourceNotFoundException; @@ -35,7 +36,7 @@ public interface NeutronRouterService { public RoutesToNeutronWebResponse removeRoutesFromNeutronRouter(String routerid, NewRoutesWebRequest requestRouter) throws RouterOrSubnetAndPortNotExistOrNotVisible, ResourceNotFoundException, ResourcePersistenceException, DestinationOrNexthopCanNotBeNull, DatabasePersistenceException; public ConnectedSubnetsWebResponse getConnectedSubnets (String projectId, String vpcId, String subnetId) throws ResourceNotFoundException, ResourcePersistenceException, SubnetNotBindUniquePortId; public UpdateRoutingRuleResponse updateRoutingRule (String owner, NewRoutesWebRequest newRouteEntry, boolean isNeutronOrVPCLevelRoutingRule, boolean isAddOperation) throws DestinationOrNexthopCanNotBeNull, CacheException, CanNotFindRouteTableByOwner, QueryParamTypeNotSupportException, RouteTableNotUnique, DestinationInvalid, DatabasePersistenceException; - public InternalRouterInfo constructInternalRouterInfo (String routerid, List internalSubnetRoutingTableList); + public InternalRouterInfo constructInternalRouterInfo (String routerid, List internalSubnetRoutingTableList, OperationType... operationType); public List constructInternalSubnetRoutingTables (Router router) throws Exception; public List getRouteTablesBySubnetIds (List subnetIds, String projectid) throws Exception; } diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterToDPMService.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterToDPMService.java index 0668ea21b..16f8badc9 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterToDPMService.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterToDPMService.java @@ -15,10 +15,11 @@ free of charge, to any person obtaining a copy of this software and associated d */ package com.futurewei.alcor.route.service; +import com.futurewei.alcor.schema.Common; import com.futurewei.alcor.web.entity.route.InternalRouterInfo; public interface RouterToDPMService { - public void sendInternalRouterInfoToDPM (InternalRouterInfo internalRouterInfo) throws Exception; + public void sendInternalRouterInfoToDPM (InternalRouterInfo internalRouterInfo, Common.ResourceType... resourceTypes) throws Exception; } From 2ec5c127bd2671caa42ee6a7f1b6f6371d60af7e Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Mon, 6 Dec 2021 17:24:47 -0800 Subject: [PATCH 16/33] Update code --- .../dataplane/cache/SubnetPortsCache.java | 19 ++++++++++++ .../entity/InternalSubnetRouterMap.java | 17 +++++++++++ .../dataplane/entity/UnicastGoalStateV2.java | 5 ++++ .../service/impl/DpmServiceImplV2.java | 2 ++ .../service/impl/NeighborService.java | 29 +++++++++++-------- .../dataplane/service/impl/RouterService.java | 4 +++ 6 files changed, 64 insertions(+), 12 deletions(-) diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SubnetPortsCache.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SubnetPortsCache.java index 1b1b6390b..393511231 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SubnetPortsCache.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SubnetPortsCache.java @@ -88,12 +88,31 @@ public Map getInternalSubnetRouterMap(NetworkConfiguration netwo .stream() .map(routingTable -> new InternalSubnetRouterMap(routerInfo.getRouterConfiguration().getId() , routingTable.getSubnetId()))) + .distinct() .collect(Collectors.toMap(routerInfo -> routerInfo.getSubnetId(), routerInfo -> routerInfo.getRouterId())); return internalSubnetsRouterMap; } return new HashMap<>(); } + + + @DurationStatistics + public void attacheRouter(Map subnetIdRouterIdMap) { + subnetIdRouterIdMap + .entrySet() + .forEach(subnetIdRouterId -> { + InternalSubnetPorts internalSubnetPorts = null; + try { + internalSubnetPorts = subnetPortsCache.get(subnetIdRouterId.getKey()); + internalSubnetPorts.setRouterId(subnetIdRouterId.getValue()); + subnetPortsCache.put(subnetIdRouterId.getKey(), internalSubnetPorts); + } catch (CacheException e) { + e.printStackTrace(); + } + }); + } + @DurationStatistics public Map getSubnetPorts(NetworkConfiguration networkConfig) { Map internalSubnetsRouterMap = getInternalSubnetRouterMap(networkConfig); diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/InternalSubnetRouterMap.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/InternalSubnetRouterMap.java index a14d6f27b..375bf1459 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/InternalSubnetRouterMap.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/InternalSubnetRouterMap.java @@ -16,6 +16,8 @@ free of charge, to any person obtaining a copy of this software and associated d package com.futurewei.alcor.dataplane.entity; +import com.futurewei.alcor.web.entity.route.RouteEntry; + public class InternalSubnetRouterMap { private String routerId; private String subnetId; @@ -38,4 +40,19 @@ public void setSubnetIds(String subnetId) { public String getSubnetId() { return this.subnetId; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + //if (!super.equals(o)) return false; + InternalSubnetRouterMap internalSubnetRouterMap = (InternalSubnetRouterMap) o; + return routerId.equals(internalSubnetRouterMap.routerId) && subnetId.equals(internalSubnetRouterMap.subnetId); + } + + @Override + public int hashCode() + { + return 31 * subnetId.hashCode() + routerId.hashCode(); + } } \ No newline at end of file diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/UnicastGoalStateV2.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/UnicastGoalStateV2.java index dd19d7aa3..34a8adb38 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/UnicastGoalStateV2.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/UnicastGoalStateV2.java @@ -37,6 +37,11 @@ public UnicastGoalStateV2(String hostIp, GoalStateV2 goalState) { this.goalState = goalState; } + public UnicastGoalStateV2(String hostIp, GoalStateV2.Builder goalStateBuilder) { + this.hostIp = hostIp; + this.goalStateBuilder = goalStateBuilder; + } + public UnicastGoalStateV2(String hostIp, String vpcId, GoalStateV2 goalState) { this.hostIp = hostIp; this.vpcId = vpcId; diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/DpmServiceImplV2.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/DpmServiceImplV2.java index e66177657..30b8216a2 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/DpmServiceImplV2.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/DpmServiceImplV2.java @@ -456,6 +456,8 @@ private void rebuildRouterState(Goalstate.GoalStateV2.Builder goalStateBuilder, * @throws Exception Process exceptions and send exceptions */ private List processNeighborConfiguration(NetworkConfiguration networkConfig) throws Exception { + Map subnetIdRouterIdMap = subnetPortsCache.getInternalSubnetRouterMap(networkConfig); + subnetPortsCache.attacheRouter(subnetIdRouterIdMap); Map unicastGoalStates = new HashMap<>(); MulticastGoalStateV2 multicastGoalState = new MulticastGoalStateV2(); if (networkConfig.getInternalRouterInfos() != null) { diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java index c9ebd29fb..c747d7961 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java @@ -462,17 +462,17 @@ public void buildNeighborStatesL3(NetworkConfiguration networkConfiguration, Uni } - public void buildNeighborStatesL3(NetworkConfiguration networkConfiguration, Map unicastGoalStates, MulticastGoalStateV2 multicastGoalState) throws CacheException { - String routerId = subnetPortsCache.getInternalSubnetRouterMap(networkConfiguration).values().stream().collect(Collectors.toSet()).stream().findFirst().orElse(""); + public void buildNeighborStatesL3(NetworkConfiguration networkConfiguration, Map unicastGoalStates, MulticastGoalStateV2 multicastGoalState) throws Exception { + String routerId = networkConfiguration.getInternalRouterInfos().get(0).getRouterConfiguration().getId(); Map neighborStateMap = new TreeMap<>(); Map subnetStateMap = new TreeMap<>(); - Router.RouterConfiguration.Builder routerConfigurationBuilder = Router.RouterConfiguration.newBuilder(); + Router.RouterConfiguration.Builder unicastRouterConfigurationBuilder = Router.RouterConfiguration.newBuilder(); String subnetId = networkConfiguration.getInternalRouterInfos().stream().flatMap(routerInfo -> routerInfo.getRouterConfiguration().getSubnetRoutingTables().stream().map(subnetRoutingTable -> subnetRoutingTable.getSubnetId()) ).collect(Collectors.toSet()).stream().findFirst().orElse(""); String vpcid = subnetPortsCache.getSubnetPorts(subnetId).getVpcId(); portHostInfoCache.getPortHostInfos(subnetId) - .forEach(portState -> unicastGoalStates.put(portState.getHostIp(), new UnicastGoalStateV2(portState.getHostIp(), Goalstate.GoalStateV2.newBuilder().build()))); + .forEach(portState -> unicastGoalStates.put(portState.getHostIp(), new UnicastGoalStateV2(portState.getHostIp(), Goalstate.GoalStateV2.newBuilder()))); Collection internalSubnetPorts = subnetPortsCache.getSubnetPortsByRouterId(routerId); for (InternalSubnetPorts internalSubnetPort : internalSubnetPorts) { @@ -483,11 +483,6 @@ public void buildNeighborStatesL3(NetworkConfiguration networkConfiguration, Map Neighbor.NeighborState neighborState = buildNeighborState(NeighborEntry.NeighborType.L3, portHostInfo, networkConfiguration.getOpType(), vpcid); if (subnetId.equals(internalSubnetPort.getSubnetId())) { multicastGoalState.getGoalStateBuilder().putNeighborStates(neighborState.getConfiguration().getId(), neighborState); - multicastGoalState.getGoalStateBuilder().putSubnetStates(subnetId, subnetService.buildSubnetState(subnetId).build()); - InternalSubnetRoutingTable subnetRoutingTableList = networkConfiguration - .getInternalRouterInfos().stream().findFirst().orElse(null).getRouterConfiguration().getSubnetRoutingTables().stream().findFirst().orElse(null); - Router.RouterState.Builder routerStateBuilder = routerService.buildRouterState(networkConfiguration.getInternalRouterInfos().get(0), subnetRoutingTableList); - multicastGoalState.getGoalStateBuilder().putRouterStates(routerId, routerStateBuilder.build()); } else { multicastGoalState.getHostIps().add(portHostInfo.getHostIp()); neighborStateMap.put(neighborState.getConfiguration().getId(), neighborState); @@ -496,7 +491,7 @@ public void buildNeighborStatesL3(NetworkConfiguration networkConfiguration, Map System.out.println("Router state: " + internalSubnetPort.getSubnetId()); Router.RouterConfiguration.SubnetRoutingTable.Builder subnetRoutingTableBuilder = Router.RouterConfiguration.SubnetRoutingTable.newBuilder(); subnetRoutingTableBuilder.setSubnetId(internalSubnetPort.getSubnetId()); - routerConfigurationBuilder.addSubnetRoutingTables(subnetRoutingTableBuilder.build()); + unicastRouterConfigurationBuilder.addSubnetRoutingTables(subnetRoutingTableBuilder.build()); } } catch (Exception e) { @@ -508,11 +503,21 @@ public void buildNeighborStatesL3(NetworkConfiguration networkConfiguration, Map e.printStackTrace(); } } - + if (!multicastGoalState.getGoalStateBuilder().getSubnetStatesMap().containsKey(subnetId)) { + multicastGoalState.getGoalStateBuilder().putSubnetStates(subnetId, subnetService.buildSubnetState(subnetId).build()); + InternalSubnetRoutingTable subnetRoutingTables = + networkConfiguration.getInternalRouterInfos().get(0).getRouterConfiguration().getSubnetRoutingTables().stream().filter(subnetRoutingTable -> subnetRoutingTable.getSubnetId().equals(subnetId)).findFirst().orElse(null); + Router.RouterState.Builder routerStateBuilder = routerService.buildRouterState(networkConfiguration.getInternalRouterInfos().get(0), subnetRoutingTables); + multicastGoalState.getGoalStateBuilder().putRouterStates(routerId, routerStateBuilder.build()); + } + subnetStateMap.put(subnetId, subnetService.buildSubnetState(subnetId).build()); for (UnicastGoalStateV2 unicastGoalStateV2 : unicastGoalStates.values()) { unicastGoalStateV2.getGoalStateBuilder().putAllNeighborStates(neighborStateMap); unicastGoalStateV2.getGoalStateBuilder().putAllSubnetStates(subnetStateMap); - unicastGoalStateV2.getGoalStateBuilder().putRouterStates(routerId, Router.RouterState.newBuilder().setConfiguration(routerConfigurationBuilder).build()); + Router.RouterConfiguration.Builder routerConfigurationBuilder = multicastGoalState.getGoalStateBuilder().getRouterStatesMap().get(routerId).getConfiguration().toBuilder(); + routerConfigurationBuilder.addAllSubnetRoutingTables(unicastRouterConfigurationBuilder.getSubnetRoutingTablesList()); + Router.RouterState.Builder routerStateBuilder = Router.RouterState.newBuilder().setConfiguration(routerConfigurationBuilder.build()); + unicastGoalStateV2.getGoalStateBuilder().putRouterStates(routerId, routerStateBuilder.build()); } if (multicastGoalState.getHostIps().size() == 0){ multicastGoalState.getGoalStateBuilder().clear(); diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/RouterService.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/RouterService.java index 994609333..2720fe1c8 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/RouterService.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/RouterService.java @@ -187,6 +187,10 @@ public Router.RouterState.Builder buildRouterState(InternalRouterInfo routerInfo List subnetRoutingTablesList = new ArrayList<>(); subnetRoutingTablesList.add(subnetRoutingTableBuilder.build()); + if (unicastGoalState.length == 0) { + unicastGoalState = new UnicastGoalStateV2[1]; + unicastGoalState[0] = new UnicastGoalStateV2("", Goalstate.GoalStateV2.newBuilder()); + } Goalstate.GoalStateV2.Builder goalStateBuilder = unicastGoalState[0].getGoalStateBuilder(); List routerStatesBuilders = new ArrayList(goalStateBuilder.getRouterStatesMap().values()); From bc938fd1eae20d01b422034cc78a3bfeb602c4da Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Tue, 7 Dec 2021 13:09:16 -0800 Subject: [PATCH 17/33] Update code --- .../dataplane/cache/SubnetPortsCache.java | 18 -- .../service/impl/DpmServiceImplV2.java | 204 +----------------- .../service/impl/NeighborService.java | 37 +--- .../dataplane/service/impl/SubnetService.java | 5 +- .../processor/DataPlaneProcessor.java | 2 +- .../processor/NeighborProcessor.java | 7 +- .../portmanager/repo/PortRepository.java | 6 +- .../controller/NeutronRouterController.java | 32 ++- .../Impl/NeutronRouterServiceImpl.java | 9 +- .../service/Impl/RouterToDPMServiceImpl.java | 8 +- .../route/service/NeutronRouterService.java | 5 +- .../route/service/RouterToDPMService.java | 4 +- 12 files changed, 57 insertions(+), 280 deletions(-) diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SubnetPortsCache.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SubnetPortsCache.java index 393511231..a60cf2cc7 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SubnetPortsCache.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SubnetPortsCache.java @@ -95,24 +95,6 @@ public Map getInternalSubnetRouterMap(NetworkConfiguration netwo return new HashMap<>(); } - - - @DurationStatistics - public void attacheRouter(Map subnetIdRouterIdMap) { - subnetIdRouterIdMap - .entrySet() - .forEach(subnetIdRouterId -> { - InternalSubnetPorts internalSubnetPorts = null; - try { - internalSubnetPorts = subnetPortsCache.get(subnetIdRouterId.getKey()); - internalSubnetPorts.setRouterId(subnetIdRouterId.getValue()); - subnetPortsCache.put(subnetIdRouterId.getKey(), internalSubnetPorts); - } catch (CacheException e) { - e.printStackTrace(); - } - }); - } - @DurationStatistics public Map getSubnetPorts(NetworkConfiguration networkConfig) { Map internalSubnetsRouterMap = getInternalSubnetRouterMap(networkConfig); diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/DpmServiceImplV2.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/DpmServiceImplV2.java index 30b8216a2..346186aee 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/DpmServiceImplV2.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/DpmServiceImplV2.java @@ -153,86 +153,6 @@ private UnicastGoalStateV2 buildUnicastGoalState(NetworkConfiguration networkCon return unicastGoalState; } - private void patchGoalstateForNeighbor(NetworkConfiguration networkConfig, UnicastGoalStateV2 unicastGoalState) throws CacheException { - Map neighborStatesMap = unicastGoalState.getGoalStateBuilder().getNeighborStatesMap(); - for (Map.Entry neighborStateEntry : neighborStatesMap.entrySet()) { - List fixedIps = neighborStateEntry.getValue().getConfiguration().getFixedIpsList(); - for (Neighbor.NeighborConfiguration.FixedIp fixedIp : fixedIps) { - if (fixedIp != null && fixedIp.getNeighborType().equals(Neighbor.NeighborType.L3)) { - String subnetId = fixedIp.getSubnetId(); - InternalSubnetPorts subnetEntity = subnetPortsCache.getSubnetPorts(subnetId); - if (subnetEntity != null) { - if (unicastGoalState.getGoalStateBuilder().getSubnetStatesMap().entrySet().stream() - .filter(e -> e.getValue().getConfiguration().getId().equals(subnetEntity.getSubnetId())) - .findFirst().orElse(null) == null) { - Subnet.SubnetConfiguration.Builder subnetConfigBuilder = Subnet.SubnetConfiguration.newBuilder(); - subnetConfigBuilder.setRevisionNumber(FORMAT_REVISION_NUMBER); - subnetConfigBuilder.setId(subnetEntity.getSubnetId()); - subnetConfigBuilder.setVpcId(subnetEntity.getVpcId()); - subnetConfigBuilder.setName(subnetEntity.getName()); - subnetConfigBuilder.setCidr(subnetEntity.getCidr()); - subnetConfigBuilder.setTunnelId(subnetEntity.getTunnelId()); - - Subnet.SubnetConfiguration.Gateway.Builder gatewayBuilder = Subnet.SubnetConfiguration.Gateway.newBuilder(); - gatewayBuilder.setIpAddress(subnetEntity.getGatewayPortIp()); - gatewayBuilder.setMacAddress(subnetEntity.getGatewayPortMac()); - subnetConfigBuilder.setGateway(gatewayBuilder.build()); - - if (subnetEntity.getDhcpEnable() != null) { - subnetConfigBuilder.setDhcpEnable(subnetEntity.getDhcpEnable()); - } - - // TODO: need to set DNS based on latest contract - - Subnet.SubnetState.Builder subnetStateBuilder = Subnet.SubnetState.newBuilder(); - subnetStateBuilder.setOperationType(Common.OperationType.INFO); - subnetStateBuilder.setConfiguration(subnetConfigBuilder.build()); - unicastGoalState.getGoalStateBuilder().putSubnetStates(subnetEntity.getSubnetId(), subnetStateBuilder.build()); - - Router.RouterConfiguration.SubnetRoutingTable.Builder subnetRoutingTableBuilder = Router.RouterConfiguration.SubnetRoutingTable.newBuilder(); - subnetRoutingTableBuilder.setSubnetId(subnetEntity.getSubnetId()); - - List subnetRoutingTablesList = new ArrayList<>(); - subnetRoutingTablesList.add(subnetRoutingTableBuilder.build()); - - Goalstate.GoalStateV2.Builder goalStateBuilder = unicastGoalState.getGoalStateBuilder(); - List routerStatesBuilders = new ArrayList<>(goalStateBuilder.getRouterStatesMap().values()); - - if (routerStatesBuilders != null && routerStatesBuilders.size() > 0) { - Router.RouterState routerState = routerStatesBuilders.get(0); - subnetRoutingTablesList.addAll(routerState. - getConfiguration(). - getSubnetRoutingTablesList()); - goalStateBuilder.removeSubnetStates(new ArrayList(goalStateBuilder.getRouterStatesMap().keySet()).get(0)); - } - - String routerId = subnetEntity.getRouterId(); - // If subnet has attached to a router (test scenario #4), we just use the routerId in the subnet. - // Otherwise, we need to get router_state in the networkConfig for test scenario #5. - if (routerId == null) { - List internalRouterInfos = networkConfig.getInternalRouterInfos(); - for (InternalRouterInfo internalRouterInfo : internalRouterInfos) { - routerId = internalRouterInfo.getRouterConfiguration().getId(); - if (routerId != null) break; - } - } - - // Add subnet to router_state - Router.RouterConfiguration.Builder routerConfigBuilder = Router.RouterConfiguration.newBuilder(); - routerConfigBuilder.setRevisionNumber(FORMAT_REVISION_NUMBER); - routerConfigBuilder.setHostDvrMacAddress(HOST_DVR_MAC); - routerConfigBuilder.setId(routerId); - routerConfigBuilder.addAllSubnetRoutingTables(subnetRoutingTablesList); - Router.RouterState.Builder routerStateBuilder = Router.RouterState.newBuilder(); - routerStateBuilder.setConfiguration(routerConfigBuilder.build()); - unicastGoalState.getGoalStateBuilder().putRouterStates(routerId, routerStateBuilder.build()); - } - } - } - } - } - } - private List doCreatePortConfiguration(NetworkConfiguration networkConfig, Map> hostPortEntities, DataPlaneClient dataPlaneClient) throws Exception { @@ -327,126 +247,6 @@ private List processPortConfiguration(NetworkConfiguration networkConfig return statusList; } - private Subnet.SubnetState.Builder constructSubnetState(InternalSubnetPorts subnetEntity) { - Subnet.SubnetState.Builder subnetStateBuilder = Subnet.SubnetState.newBuilder(); - - if (subnetEntity != null) { - Subnet.SubnetConfiguration.Builder subnetConfigBuilder = Subnet.SubnetConfiguration.newBuilder(); - subnetConfigBuilder.setRevisionNumber(FORMAT_REVISION_NUMBER); - subnetConfigBuilder.setId(subnetEntity.getSubnetId()); - subnetConfigBuilder.setVpcId(subnetEntity.getVpcId()); - subnetConfigBuilder.setName(subnetEntity.getName()); - subnetConfigBuilder.setCidr(subnetEntity.getCidr()); - subnetConfigBuilder.setTunnelId(subnetEntity.getTunnelId()); - - Subnet.SubnetConfiguration.Gateway.Builder gatewayBuilder = Subnet.SubnetConfiguration.Gateway.newBuilder(); - gatewayBuilder.setIpAddress(subnetEntity.getGatewayPortIp()); - gatewayBuilder.setMacAddress(subnetEntity.getGatewayPortMac()); - subnetConfigBuilder.setGateway(gatewayBuilder.build()); - - if (subnetEntity.getDhcpEnable() != null) { - subnetConfigBuilder.setDhcpEnable(subnetEntity.getDhcpEnable()); - } - - // TODO: need to set DNS based on latest contract - subnetStateBuilder.setOperationType(Common.OperationType.INFO); - subnetStateBuilder.setConfiguration(subnetConfigBuilder.build()); - } - - return subnetStateBuilder; - } - - private void patchGoalstateForRouterSubnet(NetworkConfiguration networkConfig, Map> hostsSubnets, MulticastGoalStateV2 multicastGoalState) throws CacheException { - for (Map.Entry> entry: hostsSubnets.entrySet()) { - for (String subnetId : entry.getValue()) { - InternalSubnetPorts subnetEntity = subnetPortsCache.getSubnetPorts(subnetId); - if (subnetEntity != null) { - if (multicastGoalState.getGoalStateBuilder().getSubnetStatesMap().values().stream() - .filter(e -> e.getConfiguration().getId().equals(subnetEntity.getSubnetId())) - .findFirst().orElse(null) == null) { - Subnet.SubnetState.Builder subnetStateBuilder = constructSubnetState(subnetEntity); - multicastGoalState.getGoalStateBuilder().putSubnetStates(subnetStateBuilder.getConfiguration().getId(), subnetStateBuilder.build()); - - // Add subnet to router_state - Goalstate.GoalStateV2.Builder goalStateBuilder = multicastGoalState.getGoalStateBuilder(); - Router.RouterState.Builder routerStateBuilder = constructRouterState(networkConfig, subnetEntity, goalStateBuilder); - multicastGoalState.getGoalStateBuilder().putRouterStates(routerStateBuilder.getConfiguration().getId(), routerStateBuilder.build()); - } - } - } - } - } - - private Router.RouterState.Builder constructRouterState(NetworkConfiguration networkConfig, InternalSubnetPorts subnetEntity, Goalstate.GoalStateV2.Builder goalStateBuilder) { - Router.RouterState.Builder routerStateBuilder = Router.RouterState.newBuilder(); - if (subnetEntity != null) { - Router.RouterConfiguration.SubnetRoutingTable.Builder subnetRoutingTableBuilder = Router.RouterConfiguration.SubnetRoutingTable.newBuilder(); - subnetRoutingTableBuilder.setSubnetId(subnetEntity.getSubnetId()); - - List subnetRoutingTablesList = new ArrayList<>(); - subnetRoutingTablesList.add(subnetRoutingTableBuilder.build()); - List routerStatesBuilders = new ArrayList(goalStateBuilder.getRouterStatesMap().values()); - - if (routerStatesBuilders != null && routerStatesBuilders.size() > 0) { - Router.RouterState routerState = routerStatesBuilders.get(0); - subnetRoutingTablesList.addAll(routerState. - getConfiguration(). - getSubnetRoutingTablesList()); - goalStateBuilder.removeSubnetStates(new ArrayList(goalStateBuilder.getRouterStatesMap().keySet()).get(0)); - } - - String routerId = subnetEntity.getRouterId(); - // If subnet has attached to a router (test scenario #4), we just use the routerId in the subnet. - // Otherwise, we need to get router_state in the networkConfig for test scenario #5. - if (routerId == null) { - List internalRouterInfos = networkConfig.getInternalRouterInfos(); - for (InternalRouterInfo internalRouterInfo : internalRouterInfos) { - routerId = internalRouterInfo.getRouterConfiguration().getId(); - if (routerId != null) break; - } - } - Router.RouterConfiguration.Builder routerConfigBuilder = Router.RouterConfiguration.newBuilder(); - routerConfigBuilder.setRevisionNumber(FORMAT_REVISION_NUMBER); - routerConfigBuilder.setHostDvrMacAddress(HOST_DVR_MAC); - routerConfigBuilder.setId(routerId); - routerConfigBuilder.addAllSubnetRoutingTables(subnetRoutingTablesList); - routerStateBuilder.setConfiguration(routerConfigBuilder.build()); - } - return routerStateBuilder; - } - - @Tracer - private void rebuildRouterState(Goalstate.GoalStateV2.Builder goalStateBuilder, Goalstate.GoalStateV2.Builder newGoalState) { - List subnetRoutingTables = new ArrayList<>(); - for (Router.RouterConfiguration.SubnetRoutingTable subnetRoutingTable : newGoalState.getRouterStatesMap().entrySet().iterator().next().getValue().getConfiguration().getSubnetRoutingTablesList()) { - Router.RouterConfiguration.SubnetRoutingTable.Builder subnetRoutingTableBuilder = Router.RouterConfiguration.SubnetRoutingTable.newBuilder(); - subnetRoutingTableBuilder.setSubnetId(subnetRoutingTable.getSubnetId()); - subnetRoutingTables.add(subnetRoutingTableBuilder.build()); - } - - List routerStatesBuilders = new ArrayList(goalStateBuilder.getRouterStatesMap().values()); - if (routerStatesBuilders != null && routerStatesBuilders.size() > 0) { - Router.RouterState routerState = routerStatesBuilders.get(0); - subnetRoutingTables.addAll(routerState. - getConfiguration(). - getSubnetRoutingTablesList()); - String routerId = routerState.getConfiguration().getId(); - String hostDvrMac = routerState.getConfiguration().getHostDvrMacAddress(); - goalStateBuilder.removeSubnetStates(new ArrayList(goalStateBuilder.getRouterStatesMap().keySet()).get(0)); - - Router.RouterConfiguration.Builder routerConfigBuilder = Router.RouterConfiguration.newBuilder(); - routerConfigBuilder.setRevisionNumber(FORMAT_REVISION_NUMBER); - - //TODO: where does the hostDvrMacAddress come from ? - routerConfigBuilder.setHostDvrMacAddress(hostDvrMac); - routerConfigBuilder.setId(routerId); - routerConfigBuilder.addAllSubnetRoutingTables(subnetRoutingTables); - Router.RouterState.Builder routerStateBuilder = Router.RouterState.newBuilder(); - routerStateBuilder.setConfiguration(routerConfigBuilder.build()); - goalStateBuilder.putRouterStates(routerStateBuilder.getConfiguration().getId(), routerStateBuilder.build()); - } - } - /** * This method get neighbor information from NetworkConfiguration, then build one * UnicastGoalState for each host and fill in the neighbor information it needs, @@ -456,8 +256,8 @@ private void rebuildRouterState(Goalstate.GoalStateV2.Builder goalStateBuilder, * @throws Exception Process exceptions and send exceptions */ private List processNeighborConfiguration(NetworkConfiguration networkConfig) throws Exception { - Map subnetIdRouterIdMap = subnetPortsCache.getInternalSubnetRouterMap(networkConfig); - subnetPortsCache.attacheRouter(subnetIdRouterIdMap); + Map internalSubnetPortsMap = subnetPortsCache.getSubnetPorts(networkConfig); + subnetPortsCache.updateSubnetPorts(internalSubnetPortsMap); Map unicastGoalStates = new HashMap<>(); MulticastGoalStateV2 multicastGoalState = new MulticastGoalStateV2(); if (networkConfig.getInternalRouterInfos() != null) { diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java index c747d7961..3e783d70f 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java @@ -336,31 +336,18 @@ public void buildNeighborStatesL2(UnicastGoalStateV2 unicastGoalStateV2, Multica multicastGoalStateV2.getGoalStateBuilder().putAllSubnetStates(unicastGoalStateV2.getGoalStateBuilder().getSubnetStatesMap()); multicastGoalStateV2.getGoalStateBuilder().putAllRouterStates(unicastGoalStateV2.getGoalStateBuilder().getRouterStatesMap()); - System.out.println("ips"); - for (String ip : ips) { - System.out.println(ip); - } - - portStates.parallelStream().forEach(portState -> { List subnetIds = portState.getConfiguration().getFixedIpsList().stream().map(fixedIp -> fixedIp.getSubnetId()).collect(Collectors.toList()); - System.out.println("subnetIds"); - for (String subnetId : subnetIds) { - System.out.println(subnetId); - } + for (String subnetId : subnetIds) { try { Collection portHostInfos = portHostInfoCache.getPortHostInfos(subnetId); - System.out.println("portHostInfos"); - for (PortHostInfo portHostInfo : portHostInfos) { - System.out.println(portHostInfo.getPortIp()); - } + portHostInfos.parallelStream().forEach(portHostInfo -> { try { Neighbor.NeighborState neighborState = buildNeighborState(NeighborEntry.NeighborType.L2, portHostInfo, operationType, portState.getConfiguration().getVpcId()); if (ips.contains(portHostInfo.getPortIp())) { - System.out.println("test"); multicastGoalStateV2.getGoalStateBuilder().putNeighborStates(neighborState.getConfiguration().getId(), neighborState); } else { multicastGoalStateV2.getHostIps().add(portHostInfo.getHostIp()); @@ -396,11 +383,6 @@ public void buildNeighborStatesL3(NetworkConfiguration networkConfiguration, Uni .flatMap(portState -> portState.getConfiguration().getFixedIpsList().stream().map(fixedIp -> fixedIp.getSubnetId())) .collect(Collectors.toSet()); - System.out.println("subnetIds"); - for (String subnetId : subnetIds) { - System.out.println(subnetId); - } - multicastGoalStateV2.getGoalStateBuilder().putAllSubnetStates(unicastGoalStateV2.getGoalStateBuilder().getSubnetStatesMap()); multicastGoalStateV2.getGoalStateBuilder().putAllRouterStates(unicastGoalStateV2.getGoalStateBuilder().getRouterStatesMap()); @@ -409,19 +391,11 @@ public void buildNeighborStatesL3(NetworkConfiguration networkConfiguration, Uni routerIds.parallelStream().forEach(routerId -> { try { Collection internalSubnetPorts = subnetPortsCache.getSubnetPortsByRouterId(routerId); - System.out.println("Collection"); - for (InternalSubnetPorts internalSubnetPorts1 : internalSubnetPorts) { - System.out.println(internalSubnetPorts1.getSubnetId()); - } for (InternalSubnetPorts internalSubnetPort : internalSubnetPorts) { try { Collection portHostInfos = portHostInfoCache.getPortHostInfos(internalSubnetPort.getSubnetId()); - System.out.println("Collection portHostInfos" + internalSubnetPort.getSubnetId()); - for (PortHostInfo portHostInfo : portHostInfos) { - System.out.println(portHostInfo.getHostIp()); - } portHostInfos.parallelStream().forEach(portHostInfo -> { try { Neighbor.NeighborState neighborState = buildNeighborState(NeighborEntry.NeighborType.L3, portHostInfo, networkConfiguration.getOpType(), vpcid); @@ -432,7 +406,6 @@ public void buildNeighborStatesL3(NetworkConfiguration networkConfiguration, Uni neighborStateMap.put(neighborState.getConfiguration().getId(), neighborState); subnetStateMap.put(internalSubnetPort.getSubnetId(), subnetService.buildSubnetState(internalSubnetPort.getSubnetId()).build()); if (!unicastGoalStateV2.getGoalStateBuilder().getSubnetStatesMap().containsKey(internalSubnetPort.getSubnetId())){ - System.out.println("Router state: " + internalSubnetPort.getSubnetId()); Router.RouterConfiguration.SubnetRoutingTable.Builder subnetRoutingTableBuilder = Router.RouterConfiguration.SubnetRoutingTable.newBuilder(); String subnetId = portHostInfo.getSubnetId(); subnetRoutingTableBuilder.setSubnetId(subnetId); @@ -456,9 +429,6 @@ public void buildNeighborStatesL3(NetworkConfiguration networkConfiguration, Uni }); unicastGoalStateV2.getGoalStateBuilder().putAllNeighborStates(neighborStateMap); unicastGoalStateV2.getGoalStateBuilder().putAllSubnetStates(subnetStateMap); - if (multicastGoalStateV2.getHostIps().size() == 0){ - multicastGoalStateV2.getGoalStateBuilder().clear(); - } } @@ -519,8 +489,5 @@ public void buildNeighborStatesL3(NetworkConfiguration networkConfiguration, Map Router.RouterState.Builder routerStateBuilder = Router.RouterState.newBuilder().setConfiguration(routerConfigurationBuilder.build()); unicastGoalStateV2.getGoalStateBuilder().putRouterStates(routerId, routerStateBuilder.build()); } - if (multicastGoalState.getHostIps().size() == 0){ - multicastGoalState.getGoalStateBuilder().clear(); - } } } diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/SubnetService.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/SubnetService.java index 904ca5e5a..0ca943b03 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/SubnetService.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/SubnetService.java @@ -130,8 +130,9 @@ public Subnet.SubnetState.Builder buildSubnetState (String subnetId) throws Exce subnetConfigBuilder.setVpcId(subnetEntity.getVpcId()); subnetConfigBuilder.setName(subnetEntity.getName()); subnetConfigBuilder.setCidr(subnetEntity.getCidr()); - subnetConfigBuilder.setTunnelId(subnetEntity.getTunnelId()); - + if (subnetEntity.getTunnelId() != null) { + subnetConfigBuilder.setTunnelId(subnetEntity.getTunnelId()); + } Subnet.SubnetConfiguration.Gateway.Builder gatewayBuilder = Subnet.SubnetConfiguration.Gateway.newBuilder(); gatewayBuilder.setIpAddress(subnetEntity.getGatewayPortIp()); gatewayBuilder.setMacAddress(subnetEntity.getGatewayPortMac()); diff --git a/services/port_manager/src/main/java/com/futurewei/alcor/portmanager/processor/DataPlaneProcessor.java b/services/port_manager/src/main/java/com/futurewei/alcor/portmanager/processor/DataPlaneProcessor.java index 21b69198d..d35273d56 100644 --- a/services/port_manager/src/main/java/com/futurewei/alcor/portmanager/processor/DataPlaneProcessor.java +++ b/services/port_manager/src/main/java/com/futurewei/alcor/portmanager/processor/DataPlaneProcessor.java @@ -40,7 +40,7 @@ free of charge, to any person obtaining a copy of this software and associated d import java.util.*; @AfterProcessor({FixedIpsProcessor.class, MacProcessor.class, - NeighborProcessor.class, NodeProcessor.class, PortProcessor.class, + NodeProcessor.class, PortProcessor.class, RouterProcessor.class, SecurityGroupProcessor.class, VpcProcessor.class}) public class DataPlaneProcessor extends AbstractProcessor { private static final Logger LOG = LoggerFactory.getLogger(DataPlaneProcessor.class); diff --git a/services/port_manager/src/main/java/com/futurewei/alcor/portmanager/processor/NeighborProcessor.java b/services/port_manager/src/main/java/com/futurewei/alcor/portmanager/processor/NeighborProcessor.java index 0f23b6e78..d66e273a2 100644 --- a/services/port_manager/src/main/java/com/futurewei/alcor/portmanager/processor/NeighborProcessor.java +++ b/services/port_manager/src/main/java/com/futurewei/alcor/portmanager/processor/NeighborProcessor.java @@ -23,8 +23,7 @@ free of charge, to any person obtaining a copy of this software and associated d import java.util.*; import java.util.stream.Collectors; -@AfterProcessor(PortProcessor.class) -public class NeighborProcessor extends AbstractProcessor { +public class NeighborProcessor { private void fetchPortNeighborCallback(IRestRequest request) { Map neighborInfoMap = ((FetchPortNeighborRequest) request).getNeighborInfos(); if (neighborInfoMap == null || neighborInfoMap.size() == 0) { @@ -54,18 +53,16 @@ private void getNeighbors(PortContext context, List portEntities) { fetchPortNeighborRequest, this::fetchPortNeighborCallback); } - @Override + void createProcess(PortContext context) { getNeighbors(context, context.getPortEntities()); } - @Override void updateProcess(PortContext context) { PortEntity portEntity = context.getNewPortEntity(); getNeighbors(context, Collections.singletonList(portEntity)); } - @Override void deleteProcess(PortContext context) { getNeighbors(context, context.getPortEntities()); } diff --git a/services/port_manager/src/main/java/com/futurewei/alcor/portmanager/repo/PortRepository.java b/services/port_manager/src/main/java/com/futurewei/alcor/portmanager/repo/PortRepository.java index de1e1069e..3742101ab 100644 --- a/services/port_manager/src/main/java/com/futurewei/alcor/portmanager/repo/PortRepository.java +++ b/services/port_manager/src/main/java/com/futurewei/alcor/portmanager/repo/PortRepository.java @@ -275,7 +275,7 @@ public synchronized void createPortBulk(List portEntities, Map portEntities, Map neighborInfos) throws Exception { try (Transaction tx = portCache.getTransaction().start()) { portCache.put(newPortEntity.getId(), newPortEntity); - neighborRepository.updateNeighbors(oldPortEntity, neighborInfos); + //neighborRepository.updateNeighbors(oldPortEntity, neighborInfos); subnetPortsRepository.updateSubnetPortIds(oldPortEntity, newPortEntity); tx.commit(); } @@ -295,7 +295,7 @@ public synchronized void updatePort(PortEntity oldPortEntity, PortEntity newPort public synchronized void deletePort(PortEntity portEntity) throws Exception { try (Transaction tx = portCache.getTransaction().start()) { portCache.remove(portEntity.getId()); - neighborRepository.deleteNeighbors(portEntity); + //neighborRepository.deleteNeighbors(portEntity); subnetPortsRepository.deleteSubnetPortIds(portEntity); tx.commit(); } diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/NeutronRouterController.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/NeutronRouterController.java index 6ab8f1658..8bf3d930b 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/NeutronRouterController.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/NeutronRouterController.java @@ -29,8 +29,11 @@ free of charge, to any person obtaining a copy of this software and associated d import com.futurewei.alcor.route.utils.RouteManagerUtil; import com.futurewei.alcor.route.utils.RestPreconditionsUtil; import com.futurewei.alcor.schema.Common; +import com.futurewei.alcor.web.entity.dataplane.InternalSubnetEntity; +import com.futurewei.alcor.web.entity.dataplane.v2.NetworkConfiguration; import com.futurewei.alcor.web.entity.route.*; import com.futurewei.alcor.common.logging.*; +import com.futurewei.alcor.web.entity.subnet.SubnetEntity; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.ComponentScan; @@ -289,8 +292,9 @@ public RouterInterfaceResponse addInterfaceToNeutronRouter(@PathVariable String String portId = resource.getPortId(); String subnetId = resource.getSubnetId(); + SubnetEntity subnetEntity = new SubnetEntity(); - RouterInterfaceResponse routerInterfaceResponse = this.neutronRouterService.addAnInterfaceToNeutronRouter(projectid, portId, subnetId, routerid); + RouterInterfaceResponse routerInterfaceResponse = this.neutronRouterService.addAnInterfaceToNeutronRouter(projectid, portId, subnetId, routerid, subnetEntity); if (subnetId == null) { subnetId = routerInterfaceResponse.getSubnetId(); @@ -323,7 +327,16 @@ public RouterInterfaceResponse addInterfaceToNeutronRouter(@PathVariable String List internalSubnetRoutingTableList = this.neutronRouterService.constructInternalSubnetRoutingTables(router); internalSubnetRoutingTableList.add(internalSubnetRoutingTable); InternalRouterInfo internalRouterInfo = this.neutronRouterService.constructInternalRouterInfo(routerid, internalSubnetRoutingTableList, OperationType.CREATE); - this.routerToDPMService.sendInternalRouterInfoToDPM(internalRouterInfo, Common.ResourceType.NEIGHBOR); + NetworkConfiguration networkConfiguration = new NetworkConfiguration(); + List internalRouterInfos = new ArrayList<>(); + internalRouterInfos.add(internalRouterInfo); + networkConfiguration.setInternalRouterInfos(internalRouterInfos); + List internalSubnetEntities = new ArrayList<>(); + InternalSubnetEntity internalSubnetEntity = new InternalSubnetEntity(subnetEntity, null); + internalSubnetEntities.add(internalSubnetEntity); + networkConfiguration.setSubnets(internalSubnetEntities); + networkConfiguration.setRsType(Common.ResourceType.NEIGHBOR); + this.routerToDPMService.sendInternalRouterInfoToDPM(internalRouterInfo, networkConfiguration); } return routerInterfaceResponse; @@ -342,8 +355,9 @@ public RouterInterfaceResponse removeInterfaceToNeutronRouter(@PathVariable Stri String portId = resource.getPortId(); String subnetId = resource.getSubnetId(); + SubnetEntity subnetEntity = new SubnetEntity(); - RouterInterfaceResponse routerInterfaceResponse = this.neutronRouterService.removeAnInterfaceToNeutronRouter(projectid, portId, subnetId, routerid); + RouterInterfaceResponse routerInterfaceResponse = this.neutronRouterService.removeAnInterfaceToNeutronRouter(projectid, portId, subnetId, routerid, subnetEntity); if (subnetId == null) { subnetId = routerInterfaceResponse.getSubnetId(); @@ -374,7 +388,17 @@ public RouterInterfaceResponse removeInterfaceToNeutronRouter(@PathVariable Stri List internalSubnetRoutingTableList = this.neutronRouterService.constructInternalSubnetRoutingTables(router); internalSubnetRoutingTableList.add(internalSubnetRoutingTable); InternalRouterInfo internalRouterInfo = this.neutronRouterService.constructInternalRouterInfo(routerid, internalSubnetRoutingTableList, OperationType.DELETE); - this.routerToDPMService.sendInternalRouterInfoToDPM(internalRouterInfo, Common.ResourceType.NEIGHBOR); + NetworkConfiguration networkConfiguration = new NetworkConfiguration(); + List internalRouterInfos = new ArrayList<>(); + internalRouterInfos.add(internalRouterInfo); + networkConfiguration.setInternalRouterInfos(internalRouterInfos); + List internalSubnetEntities = new ArrayList<>(); + InternalSubnetEntity internalSubnetEntity = new InternalSubnetEntity(subnetEntity, null); + internalSubnetEntities.add(internalSubnetEntity); + networkConfiguration.setSubnets(internalSubnetEntities); + networkConfiguration.setSubnets(new ArrayList<>()); + networkConfiguration.setRsType(Common.ResourceType.NEIGHBOR); + this.routerToDPMService.sendInternalRouterInfoToDPM(internalRouterInfo, networkConfiguration); } return routerInterfaceResponse; diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/NeutronRouterServiceImpl.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/NeutronRouterServiceImpl.java index 3029c39e8..295bc81ec 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/NeutronRouterServiceImpl.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/NeutronRouterServiceImpl.java @@ -122,7 +122,7 @@ public NeutronRouterWebRequestObject saveRouterAndRouterExtraAttribute(NeutronRo } @Override - public RouterInterfaceResponse addAnInterfaceToNeutronRouter(String projectid, String portId, String subnetId, String routerId) + public RouterInterfaceResponse addAnInterfaceToNeutronRouter(String projectid, String portId, String subnetId, String routerId, SubnetEntity subnetEntity) throws SpecifyBothSubnetIDAndPortID, ResourceNotFoundException, ResourcePersistenceException, RouterUnavailable, DatabasePersistenceException, PortIDIsAlreadyExist, PortIsAlreadyInUse, SubnetNotBindUniquePortId, RouterHasMultipleVPCs { if (portId != null && subnetId != null) { @@ -166,6 +166,7 @@ else if (portId == null && subnetId != null) { } else { return new RouterInterfaceResponse(); } + Router router = this.routerDatabaseService.getByRouterId(routerId); if (router == null) { throw new RouterUnavailable(routerId); @@ -180,7 +181,7 @@ else if (portId == null && subnetId != null) { throw new PortIsAlreadyInUse(); } subnet.setAttachedRouterId(routerId); - + BeanUtils.copyProperties(subnet, subnetEntity); /* In order to make Neutron router compatible with VPC scenario. We only allow subnet's gateways from the same VPC can be attached to router. @@ -239,7 +240,7 @@ else if (portId == null && subnetId != null) { } @Override - public RouterInterfaceResponse removeAnInterfaceToNeutronRouter(String projectid, String portId, String subnetId, String routerId) throws ResourceNotFoundException, ResourcePersistenceException, RouterOrSubnetAndPortNotExistOrNotVisible, AttachedPortsNotMatchPortId, RouterTableNotExist, RouterInterfaceAreUsedByRoutes, SubnetNotBindUniquePortId, DatabasePersistenceException { + public RouterInterfaceResponse removeAnInterfaceToNeutronRouter(String projectid, String portId, String subnetId, String routerId, SubnetEntity subnetEntity) throws ResourceNotFoundException, ResourcePersistenceException, RouterOrSubnetAndPortNotExistOrNotVisible, AttachedPortsNotMatchPortId, RouterTableNotExist, RouterInterfaceAreUsedByRoutes, SubnetNotBindUniquePortId, DatabasePersistenceException { SubnetEntity subnet = null; String projectId = null; String subnetid = null; @@ -292,7 +293,7 @@ public RouterInterfaceResponse removeAnInterfaceToNeutronRouter(String projectid } else { return new RouterInterfaceResponse(); } - + BeanUtils.copyProperties(subnet, subnetEntity); // check if the router or the subnet and port do not exist or are not visible Router router = this.routerDatabaseService.getByRouterId(routerId); if (router == null) { diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterToDPMServiceImpl.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterToDPMServiceImpl.java index 9afb89303..d4bbf6fae 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterToDPMServiceImpl.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterToDPMServiceImpl.java @@ -22,6 +22,7 @@ free of charge, to any person obtaining a copy of this software and associated d import com.futurewei.alcor.web.entity.dataplane.InternalDPMResultList; import com.futurewei.alcor.web.entity.dataplane.v2.NetworkConfiguration; import com.futurewei.alcor.web.entity.route.InternalRouterInfo; +import com.futurewei.alcor.web.entity.subnet.SubnetEntity; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.http.HttpEntity; @@ -44,16 +45,17 @@ public RouterToDPMServiceImpl(RestTemplateBuilder restTemplateBuilder) { } @Override - public void sendInternalRouterInfoToDPM(InternalRouterInfo internalRouterInfo, Common.ResourceType... resourceTypes) throws Exception{ + public void sendInternalRouterInfoToDPM(InternalRouterInfo internalRouterInfo, NetworkConfiguration... networkConfigurations) throws Exception{ NetworkConfiguration networkConfiguration = new NetworkConfiguration(); List internalRouterInfos = new ArrayList<>(); internalRouterInfos.add(internalRouterInfo); networkConfiguration.setInternalRouterInfos(internalRouterInfos); - if (resourceTypes.length == 0) { + if (networkConfigurations.length == 0) { networkConfiguration.setRsType(Common.ResourceType.ROUTER); } else { - networkConfiguration.setRsType(resourceTypes[0]); + networkConfiguration = networkConfigurations[0]; + internalRouterInfo = networkConfiguration.getInternalRouterInfos().get(0); } switch (internalRouterInfo.getOperationType()) diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/NeutronRouterService.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/NeutronRouterService.java index 1ac7495de..4475f3395 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/NeutronRouterService.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/NeutronRouterService.java @@ -23,6 +23,7 @@ free of charge, to any person obtaining a copy of this software and associated d import com.futurewei.alcor.common.exception.ResourcePersistenceException; import com.futurewei.alcor.route.exception.*; import com.futurewei.alcor.web.entity.route.*; +import com.futurewei.alcor.web.entity.subnet.SubnetEntity; import java.util.List; @@ -30,8 +31,8 @@ public interface NeutronRouterService { public NeutronRouterWebRequestObject getNeutronRouter (String routerId) throws ResourceNotFoundException, ResourcePersistenceException, RouterUnavailable; public NeutronRouterWebRequestObject saveRouterAndRouterExtraAttribute (NeutronRouterWebRequestObject neutronRouter) throws NeutronRouterIsNull, DatabasePersistenceException; - public RouterInterfaceResponse addAnInterfaceToNeutronRouter (String projectid, String portId, String subnetId, String routerId) throws SpecifyBothSubnetIDAndPortID, ResourceNotFoundException, ResourcePersistenceException, RouterUnavailable, DatabasePersistenceException, PortIDIsAlreadyExist, PortIsAlreadyInUse, SubnetNotBindUniquePortId, RouterHasMultipleVPCs; - public RouterInterfaceResponse removeAnInterfaceToNeutronRouter (String projectid, String portId, String subnetId, String routerId) throws ResourceNotFoundException, ResourcePersistenceException, RouterOrSubnetAndPortNotExistOrNotVisible, AttachedPortsNotMatchPortId, RouterTableNotExist, RouterInterfaceAreUsedByRoutes, SubnetNotBindUniquePortId, DatabasePersistenceException; + public RouterInterfaceResponse addAnInterfaceToNeutronRouter (String projectid, String portId, String subnetId, String routerId, SubnetEntity subnetEntity) throws SpecifyBothSubnetIDAndPortID, ResourceNotFoundException, ResourcePersistenceException, RouterUnavailable, DatabasePersistenceException, PortIDIsAlreadyExist, PortIsAlreadyInUse, SubnetNotBindUniquePortId, RouterHasMultipleVPCs; + public RouterInterfaceResponse removeAnInterfaceToNeutronRouter (String projectid, String portId, String subnetId, String routerId, SubnetEntity subnetEntity) throws ResourceNotFoundException, ResourcePersistenceException, RouterOrSubnetAndPortNotExistOrNotVisible, AttachedPortsNotMatchPortId, RouterTableNotExist, RouterInterfaceAreUsedByRoutes, SubnetNotBindUniquePortId, DatabasePersistenceException; public RoutesToNeutronWebResponse addRoutesToNeutronRouter (String routerid, NewRoutesWebRequest requestRouter) throws ResourceNotFoundException, ResourcePersistenceException, RouterOrSubnetAndPortNotExistOrNotVisible, DatabasePersistenceException, DestinationOrNexthopCanNotBeNull, DestinationSame; public RoutesToNeutronWebResponse removeRoutesFromNeutronRouter(String routerid, NewRoutesWebRequest requestRouter) throws RouterOrSubnetAndPortNotExistOrNotVisible, ResourceNotFoundException, ResourcePersistenceException, DestinationOrNexthopCanNotBeNull, DatabasePersistenceException; public ConnectedSubnetsWebResponse getConnectedSubnets (String projectId, String vpcId, String subnetId) throws ResourceNotFoundException, ResourcePersistenceException, SubnetNotBindUniquePortId; diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterToDPMService.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterToDPMService.java index 16f8badc9..1ecc356fa 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterToDPMService.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterToDPMService.java @@ -16,10 +16,12 @@ free of charge, to any person obtaining a copy of this software and associated d package com.futurewei.alcor.route.service; import com.futurewei.alcor.schema.Common; +import com.futurewei.alcor.web.entity.dataplane.v2.NetworkConfiguration; import com.futurewei.alcor.web.entity.route.InternalRouterInfo; +import com.futurewei.alcor.web.entity.subnet.SubnetEntity; public interface RouterToDPMService { - public void sendInternalRouterInfoToDPM (InternalRouterInfo internalRouterInfo, Common.ResourceType... resourceTypes) throws Exception; + public void sendInternalRouterInfoToDPM (InternalRouterInfo internalRouterInfo, NetworkConfiguration... networkConfigurations) throws Exception; } From cef9f6577103c7e89be3277a1b4447bc25683718 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Tue, 7 Dec 2021 15:18:49 -0800 Subject: [PATCH 18/33] Update code --- .../dataplane/cache/SubnetPortsCache.java | 44 +++++++++++++------ 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SubnetPortsCache.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SubnetPortsCache.java index a60cf2cc7..7d10fc140 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SubnetPortsCache.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SubnetPortsCache.java @@ -22,6 +22,7 @@ free of charge, to any person obtaining a copy of this software and associated d import com.futurewei.alcor.common.stats.DurationStatistics; import com.futurewei.alcor.dataplane.entity.InternalSubnetRouterMap; import com.futurewei.alcor.dataplane.entity.InternalSubnets; +import com.futurewei.alcor.web.entity.dataplane.InternalSubnetEntity; import com.futurewei.alcor.web.entity.dataplane.v2.NetworkConfiguration; import com.futurewei.alcor.web.entity.port.PortHostInfo; import com.futurewei.alcor.web.entity.subnet.InternalSubnetPorts; @@ -29,9 +30,7 @@ free of charge, to any person obtaining a copy of this software and associated d import org.springframework.context.annotation.ComponentScan; import org.springframework.stereotype.Repository; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; +import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; @@ -98,21 +97,40 @@ public Map getInternalSubnetRouterMap(NetworkConfiguration netwo @DurationStatistics public Map getSubnetPorts(NetworkConfiguration networkConfig) { Map internalSubnetsRouterMap = getInternalSubnetRouterMap(networkConfig); + Set keys = internalSubnetsRouterMap.keySet(); + Map internalSubnetEntityMap = new HashMap<>(); + keys.parallelStream().forEach(key -> { + try { + if (subnetPortsCache.containsKey(key)) { + internalSubnetEntityMap.put(key, subnetPortsCache.get(key)); + } else { + + } + } catch (CacheException e) { + e.printStackTrace(); + } + }); Map internalSubnetPortsMap = networkConfig .getSubnets() .stream() .filter(subnetEntity -> subnetEntity != null) - .map(subnetEntity -> new InternalSubnetPorts(subnetEntity.getId() - ,subnetEntity.getGatewayPortDetail().getGatewayPortId() - ,subnetEntity.getGatewayIp() - ,subnetEntity.getGatewayPortDetail().getGatewayMacAddress() - ,subnetEntity.getName() - ,subnetEntity.getCidr() - ,subnetEntity.getVpcId() - ,subnetEntity.getTunnelId() - ,subnetEntity.getDhcpEnable() - ,internalSubnetsRouterMap.getOrDefault(subnetEntity.getId(), null)) + .map(subnetEntity -> { + InternalSubnetPorts internalSubnetPorts = internalSubnetEntityMap.getOrDefault(subnetEntity.getId(), null); + if (internalSubnetPorts == null) { + internalSubnetPorts = new InternalSubnetPorts(subnetEntity.getId() + ,subnetEntity.getGatewayPortDetail().getGatewayPortId() + ,subnetEntity.getGatewayIp() + ,subnetEntity.getGatewayPortDetail().getGatewayMacAddress() + ,subnetEntity.getName() + ,subnetEntity.getCidr() + ,subnetEntity.getVpcId() + ,subnetEntity.getTunnelId() + ,subnetEntity.getDhcpEnable() + ,internalSubnetsRouterMap.getOrDefault(subnetEntity.getId(), null)); + } + return internalSubnetPorts; + } ) .collect(Collectors.toMap(InternalSubnetPorts::getSubnetId, Function.identity())); From 19e7f0bd32bb2afb800e5162aee8b316f38bf66b Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Tue, 7 Dec 2021 16:11:39 -0800 Subject: [PATCH 19/33] Update code --- .../dataplane/cache/SubnetPortsCache.java | 20 ++++--------------- .../service/impl/NeighborService.java | 4 ++-- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SubnetPortsCache.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SubnetPortsCache.java index 7d10fc140..e62f6c345 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SubnetPortsCache.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SubnetPortsCache.java @@ -53,12 +53,12 @@ public InternalSubnetPorts getSubnetPorts(String subnetId) throws CacheException } @DurationStatistics - public Collection getSubnetPortsByRouterId(String routerId) throws CacheException { + public Map getSubnetPortsByRouterId(String routerId) throws CacheException { Map queryParams = new HashMap<>(); Object[] values = new Object[1]; values[0] = routerId; queryParams.put("routerId", values); - return subnetPortsCache.getAll(queryParams).values(); + return subnetPortsCache.getAll(queryParams); } @DurationStatistics @@ -95,21 +95,9 @@ public Map getInternalSubnetRouterMap(NetworkConfiguration netwo } @DurationStatistics - public Map getSubnetPorts(NetworkConfiguration networkConfig) { + public Map getSubnetPorts(NetworkConfiguration networkConfig) throws CacheException { Map internalSubnetsRouterMap = getInternalSubnetRouterMap(networkConfig); - Set keys = internalSubnetsRouterMap.keySet(); - Map internalSubnetEntityMap = new HashMap<>(); - keys.parallelStream().forEach(key -> { - try { - if (subnetPortsCache.containsKey(key)) { - internalSubnetEntityMap.put(key, subnetPortsCache.get(key)); - } else { - - } - } catch (CacheException e) { - e.printStackTrace(); - } - }); + Map internalSubnetEntityMap = getSubnetPortsByRouterId(internalSubnetsRouterMap.values().stream().findFirst().orElse("")); Map internalSubnetPortsMap = networkConfig .getSubnets() diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java index 3e783d70f..db10a4fca 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java @@ -390,7 +390,7 @@ public void buildNeighborStatesL3(NetworkConfiguration networkConfiguration, Uni String vpcid = unicastGoalStateV2.getGoalStateBuilder().getVpcStatesMap().values().stream().map(vpcState -> vpcState.getConfiguration().getId()).findFirst().orElse(null); routerIds.parallelStream().forEach(routerId -> { try { - Collection internalSubnetPorts = subnetPortsCache.getSubnetPortsByRouterId(routerId); + Collection internalSubnetPorts = subnetPortsCache.getSubnetPortsByRouterId(routerId).values(); for (InternalSubnetPorts internalSubnetPort : internalSubnetPorts) { try { @@ -444,7 +444,7 @@ public void buildNeighborStatesL3(NetworkConfiguration networkConfiguration, Map portHostInfoCache.getPortHostInfos(subnetId) .forEach(portState -> unicastGoalStates.put(portState.getHostIp(), new UnicastGoalStateV2(portState.getHostIp(), Goalstate.GoalStateV2.newBuilder()))); - Collection internalSubnetPorts = subnetPortsCache.getSubnetPortsByRouterId(routerId); + Collection internalSubnetPorts = subnetPortsCache.getSubnetPortsByRouterId(routerId).values(); for (InternalSubnetPorts internalSubnetPort : internalSubnetPorts) { try { Collection portHostInfos = portHostInfoCache.getPortHostInfos(internalSubnetPort.getSubnetId()); From 78e3da2e39296ce5d041a381a3f410ed225a1c9d Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Tue, 7 Dec 2021 18:03:16 -0800 Subject: [PATCH 20/33] Update code --- .../service/impl/NeighborService.java | 26 +++++++++---------- .../dataplane/service/impl/RouterService.java | 2 +- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java index db10a4fca..ae46cc9c8 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java @@ -453,17 +453,15 @@ public void buildNeighborStatesL3(NetworkConfiguration networkConfiguration, Map Neighbor.NeighborState neighborState = buildNeighborState(NeighborEntry.NeighborType.L3, portHostInfo, networkConfiguration.getOpType(), vpcid); if (subnetId.equals(internalSubnetPort.getSubnetId())) { multicastGoalState.getGoalStateBuilder().putNeighborStates(neighborState.getConfiguration().getId(), neighborState); + } else { multicastGoalState.getHostIps().add(portHostInfo.getHostIp()); neighborStateMap.put(neighborState.getConfiguration().getId(), neighborState); subnetStateMap.put(internalSubnetPort.getSubnetId(), subnetService.buildSubnetState(internalSubnetPort.getSubnetId()).build()); - - System.out.println("Router state: " + internalSubnetPort.getSubnetId()); - Router.RouterConfiguration.SubnetRoutingTable.Builder subnetRoutingTableBuilder = Router.RouterConfiguration.SubnetRoutingTable.newBuilder(); - subnetRoutingTableBuilder.setSubnetId(internalSubnetPort.getSubnetId()); - unicastRouterConfigurationBuilder.addSubnetRoutingTables(subnetRoutingTableBuilder.build()); - } + Router.RouterConfiguration.SubnetRoutingTable.Builder subnetRoutingTableBuilder = Router.RouterConfiguration.SubnetRoutingTable.newBuilder(); + subnetRoutingTableBuilder.setSubnetId(internalSubnetPort.getSubnetId()); + unicastRouterConfigurationBuilder.addSubnetRoutingTables(subnetRoutingTableBuilder.build()); } catch (Exception e) { e.printStackTrace(); } @@ -473,14 +471,14 @@ public void buildNeighborStatesL3(NetworkConfiguration networkConfiguration, Map e.printStackTrace(); } } - if (!multicastGoalState.getGoalStateBuilder().getSubnetStatesMap().containsKey(subnetId)) { - multicastGoalState.getGoalStateBuilder().putSubnetStates(subnetId, subnetService.buildSubnetState(subnetId).build()); - InternalSubnetRoutingTable subnetRoutingTables = - networkConfiguration.getInternalRouterInfos().get(0).getRouterConfiguration().getSubnetRoutingTables().stream().filter(subnetRoutingTable -> subnetRoutingTable.getSubnetId().equals(subnetId)).findFirst().orElse(null); - Router.RouterState.Builder routerStateBuilder = routerService.buildRouterState(networkConfiguration.getInternalRouterInfos().get(0), subnetRoutingTables); - multicastGoalState.getGoalStateBuilder().putRouterStates(routerId, routerStateBuilder.build()); - } - subnetStateMap.put(subnetId, subnetService.buildSubnetState(subnetId).build()); + + InternalSubnetRoutingTable subnetRoutingTables = + networkConfiguration.getInternalRouterInfos().get(0).getRouterConfiguration().getSubnetRoutingTables().stream().filter(subnetRoutingTable -> subnetRoutingTable.getSubnetId().equals(subnetId)).findFirst().orElse(null); + multicastGoalState.getGoalStateBuilder().putRouterStates(routerId, routerService.buildRouterState(networkConfiguration.getInternalRouterInfos().get(0), subnetRoutingTables).build()); + + Subnet.SubnetState subnetState = subnetService.buildSubnetState(subnetId).build(); + multicastGoalState.getGoalStateBuilder().putSubnetStates(subnetId, subnetState); + subnetStateMap.put(subnetId, subnetState); for (UnicastGoalStateV2 unicastGoalStateV2 : unicastGoalStates.values()) { unicastGoalStateV2.getGoalStateBuilder().putAllNeighborStates(neighborStateMap); unicastGoalStateV2.getGoalStateBuilder().putAllSubnetStates(subnetStateMap); diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/RouterService.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/RouterService.java index 2720fe1c8..533a1966c 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/RouterService.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/RouterService.java @@ -184,7 +184,7 @@ public Router.RouterState.Builder buildRouterState(InternalRouterInfo routerInfo } } - List subnetRoutingTablesList = new ArrayList<>(); + Set subnetRoutingTablesList = new HashSet<>(); subnetRoutingTablesList.add(subnetRoutingTableBuilder.build()); if (unicastGoalState.length == 0) { From 2a7fa5d3d7ed07383b1343e2db929ee3c063c569 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Tue, 7 Dec 2021 19:36:11 -0800 Subject: [PATCH 21/33] Update code --- .../dataplane/service/impl/NeighborService.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java index ae46cc9c8..d22f52f7f 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java @@ -437,9 +437,7 @@ public void buildNeighborStatesL3(NetworkConfiguration networkConfiguration, Map Map neighborStateMap = new TreeMap<>(); Map subnetStateMap = new TreeMap<>(); Router.RouterConfiguration.Builder unicastRouterConfigurationBuilder = Router.RouterConfiguration.newBuilder(); - String subnetId = networkConfiguration.getInternalRouterInfos().stream().flatMap(routerInfo -> - routerInfo.getRouterConfiguration().getSubnetRoutingTables().stream().map(subnetRoutingTable -> subnetRoutingTable.getSubnetId()) - ).collect(Collectors.toSet()).stream().findFirst().orElse(""); + String subnetId = networkConfiguration.getSubnets().stream().map(subnetEntity -> subnetEntity.getId()).findFirst().orElse(""); String vpcid = subnetPortsCache.getSubnetPorts(subnetId).getVpcId(); portHostInfoCache.getPortHostInfos(subnetId) .forEach(portState -> unicastGoalStates.put(portState.getHostIp(), new UnicastGoalStateV2(portState.getHostIp(), Goalstate.GoalStateV2.newBuilder()))); @@ -458,10 +456,11 @@ public void buildNeighborStatesL3(NetworkConfiguration networkConfiguration, Map multicastGoalState.getHostIps().add(portHostInfo.getHostIp()); neighborStateMap.put(neighborState.getConfiguration().getId(), neighborState); subnetStateMap.put(internalSubnetPort.getSubnetId(), subnetService.buildSubnetState(internalSubnetPort.getSubnetId()).build()); + Router.RouterConfiguration.SubnetRoutingTable.Builder subnetRoutingTableBuilder = Router.RouterConfiguration.SubnetRoutingTable.newBuilder(); + subnetRoutingTableBuilder.setSubnetId(internalSubnetPort.getSubnetId()); + unicastRouterConfigurationBuilder.addSubnetRoutingTables(subnetRoutingTableBuilder.build()); } - Router.RouterConfiguration.SubnetRoutingTable.Builder subnetRoutingTableBuilder = Router.RouterConfiguration.SubnetRoutingTable.newBuilder(); - subnetRoutingTableBuilder.setSubnetId(internalSubnetPort.getSubnetId()); - unicastRouterConfigurationBuilder.addSubnetRoutingTables(subnetRoutingTableBuilder.build()); + } catch (Exception e) { e.printStackTrace(); } @@ -474,8 +473,8 @@ public void buildNeighborStatesL3(NetworkConfiguration networkConfiguration, Map InternalSubnetRoutingTable subnetRoutingTables = networkConfiguration.getInternalRouterInfos().get(0).getRouterConfiguration().getSubnetRoutingTables().stream().filter(subnetRoutingTable -> subnetRoutingTable.getSubnetId().equals(subnetId)).findFirst().orElse(null); - multicastGoalState.getGoalStateBuilder().putRouterStates(routerId, routerService.buildRouterState(networkConfiguration.getInternalRouterInfos().get(0), subnetRoutingTables).build()); - + Router.RouterState routerState = routerService.buildRouterState(networkConfiguration.getInternalRouterInfos().get(0), subnetRoutingTables).build(); + multicastGoalState.getGoalStateBuilder().putRouterStates(routerId, routerState); Subnet.SubnetState subnetState = subnetService.buildSubnetState(subnetId).build(); multicastGoalState.getGoalStateBuilder().putSubnetStates(subnetId, subnetState); subnetStateMap.put(subnetId, subnetState); From 70cd3d842e02e1b55ea682c20d01a2705287abea Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Tue, 7 Dec 2021 20:30:20 -0800 Subject: [PATCH 22/33] Update code --- .../service/impl/NeighborService.java | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java index d22f52f7f..a10a907d1 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java @@ -441,7 +441,7 @@ public void buildNeighborStatesL3(NetworkConfiguration networkConfiguration, Map String vpcid = subnetPortsCache.getSubnetPorts(subnetId).getVpcId(); portHostInfoCache.getPortHostInfos(subnetId) .forEach(portState -> unicastGoalStates.put(portState.getHostIp(), new UnicastGoalStateV2(portState.getHostIp(), Goalstate.GoalStateV2.newBuilder()))); - + Subnet.SubnetState subnetState = subnetService.buildSubnetState(subnetId).build(); Collection internalSubnetPorts = subnetPortsCache.getSubnetPortsByRouterId(routerId).values(); for (InternalSubnetPorts internalSubnetPort : internalSubnetPorts) { try { @@ -451,14 +451,22 @@ public void buildNeighborStatesL3(NetworkConfiguration networkConfiguration, Map Neighbor.NeighborState neighborState = buildNeighborState(NeighborEntry.NeighborType.L3, portHostInfo, networkConfiguration.getOpType(), vpcid); if (subnetId.equals(internalSubnetPort.getSubnetId())) { multicastGoalState.getGoalStateBuilder().putNeighborStates(neighborState.getConfiguration().getId(), neighborState); - + if (!multicastGoalState.getGoalStateBuilder().getSubnetStatesMap().containsKey(subnetId)) { + InternalSubnetRoutingTable subnetRoutingTables = + networkConfiguration.getInternalRouterInfos().get(0).getRouterConfiguration().getSubnetRoutingTables().stream().filter(subnetRoutingTable -> subnetRoutingTable.getSubnetId().equals(subnetId)).findFirst().orElse(null); + Router.RouterState.Builder routerStateBuilder = routerService.buildRouterState(networkConfiguration.getInternalRouterInfos().get(0), subnetRoutingTables); + multicastGoalState.getGoalStateBuilder().putRouterStates(routerId, routerStateBuilder.build()); + multicastGoalState.getGoalStateBuilder().putSubnetStates(subnetId, subnetState); + } } else { multicastGoalState.getHostIps().add(portHostInfo.getHostIp()); neighborStateMap.put(neighborState.getConfiguration().getId(), neighborState); - subnetStateMap.put(internalSubnetPort.getSubnetId(), subnetService.buildSubnetState(internalSubnetPort.getSubnetId()).build()); - Router.RouterConfiguration.SubnetRoutingTable.Builder subnetRoutingTableBuilder = Router.RouterConfiguration.SubnetRoutingTable.newBuilder(); - subnetRoutingTableBuilder.setSubnetId(internalSubnetPort.getSubnetId()); - unicastRouterConfigurationBuilder.addSubnetRoutingTables(subnetRoutingTableBuilder.build()); + if (!subnetStateMap.containsKey(subnetId)) { + Router.RouterConfiguration.SubnetRoutingTable.Builder subnetRoutingTableBuilder = Router.RouterConfiguration.SubnetRoutingTable.newBuilder(); + subnetRoutingTableBuilder.setSubnetId(internalSubnetPort.getSubnetId()); + unicastRouterConfigurationBuilder.addSubnetRoutingTables(subnetRoutingTableBuilder.build()); + subnetStateMap.put(internalSubnetPort.getSubnetId(), subnetService.buildSubnetState(internalSubnetPort.getSubnetId()).build()); + } } } catch (Exception e) { @@ -471,12 +479,6 @@ public void buildNeighborStatesL3(NetworkConfiguration networkConfiguration, Map } } - InternalSubnetRoutingTable subnetRoutingTables = - networkConfiguration.getInternalRouterInfos().get(0).getRouterConfiguration().getSubnetRoutingTables().stream().filter(subnetRoutingTable -> subnetRoutingTable.getSubnetId().equals(subnetId)).findFirst().orElse(null); - Router.RouterState routerState = routerService.buildRouterState(networkConfiguration.getInternalRouterInfos().get(0), subnetRoutingTables).build(); - multicastGoalState.getGoalStateBuilder().putRouterStates(routerId, routerState); - Subnet.SubnetState subnetState = subnetService.buildSubnetState(subnetId).build(); - multicastGoalState.getGoalStateBuilder().putSubnetStates(subnetId, subnetState); subnetStateMap.put(subnetId, subnetState); for (UnicastGoalStateV2 unicastGoalStateV2 : unicastGoalStates.values()) { unicastGoalStateV2.getGoalStateBuilder().putAllNeighborStates(neighborStateMap); From f88ef73a715dec370decbbd52b545f5230c9b0b3 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Wed, 8 Dec 2021 09:10:15 -0800 Subject: [PATCH 23/33] Update code --- .../alcor/dataplane/cache/SubnetPortsCache.java | 17 +++++++++++++++++ .../service/impl/DpmServiceImplV2.java | 2 ++ 2 files changed, 19 insertions(+) diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SubnetPortsCache.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SubnetPortsCache.java index e62f6c345..d0aa7e53b 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SubnetPortsCache.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SubnetPortsCache.java @@ -94,6 +94,23 @@ public Map getInternalSubnetRouterMap(NetworkConfiguration netwo return new HashMap<>(); } + @DurationStatistics + public void attacheRouter(Map subnetIdRouterIdMap) { + subnetIdRouterIdMap + .entrySet() + .forEach(subnetIdRouterId -> { + InternalSubnetPorts internalSubnetPorts = null; + try { + internalSubnetPorts = subnetPortsCache.get(subnetIdRouterId.getKey()); + internalSubnetPorts.setRouterId(subnetIdRouterId.getValue()); + subnetPortsCache.put(subnetIdRouterId.getKey(), internalSubnetPorts); + } catch (CacheException e) { + e.printStackTrace(); + } + }); + } + + @DurationStatistics public Map getSubnetPorts(NetworkConfiguration networkConfig) throws CacheException { Map internalSubnetsRouterMap = getInternalSubnetRouterMap(networkConfig); diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/DpmServiceImplV2.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/DpmServiceImplV2.java index 346186aee..e293921ed 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/DpmServiceImplV2.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/DpmServiceImplV2.java @@ -256,6 +256,8 @@ private List processPortConfiguration(NetworkConfiguration networkConfig * @throws Exception Process exceptions and send exceptions */ private List processNeighborConfiguration(NetworkConfiguration networkConfig) throws Exception { + Map subnetIdRouterIdMap = subnetPortsCache.getInternalSubnetRouterMap(networkConfig); + subnetPortsCache.attacheRouter(subnetIdRouterIdMap); Map internalSubnetPortsMap = subnetPortsCache.getSubnetPorts(networkConfig); subnetPortsCache.updateSubnetPorts(internalSubnetPortsMap); Map unicastGoalStates = new HashMap<>(); From 6d41307dc3b24387a2b250e8da93c8468daeb490 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Wed, 8 Dec 2021 12:53:49 -0800 Subject: [PATCH 24/33] Update code --- .../dataplane/cache/SubnetPortsCache.java | 70 +++++++++---------- .../service/impl/DpmServiceImplV2.java | 2 - .../service/impl/NeighborService.java | 6 ++ 3 files changed, 38 insertions(+), 40 deletions(-) diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SubnetPortsCache.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SubnetPortsCache.java index d0aa7e53b..9d8209c66 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SubnetPortsCache.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SubnetPortsCache.java @@ -26,6 +26,7 @@ free of charge, to any person obtaining a copy of this software and associated d import com.futurewei.alcor.web.entity.dataplane.v2.NetworkConfiguration; import com.futurewei.alcor.web.entity.port.PortHostInfo; import com.futurewei.alcor.web.entity.subnet.InternalSubnetPorts; +import com.futurewei.alcor.web.entity.subnet.SubnetEntity; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.ComponentScan; import org.springframework.stereotype.Repository; @@ -95,50 +96,43 @@ public Map getInternalSubnetRouterMap(NetworkConfiguration netwo } @DurationStatistics - public void attacheRouter(Map subnetIdRouterIdMap) { - subnetIdRouterIdMap - .entrySet() - .forEach(subnetIdRouterId -> { - InternalSubnetPorts internalSubnetPorts = null; - try { - internalSubnetPorts = subnetPortsCache.get(subnetIdRouterId.getKey()); - internalSubnetPorts.setRouterId(subnetIdRouterId.getValue()); - subnetPortsCache.put(subnetIdRouterId.getKey(), internalSubnetPorts); - } catch (CacheException e) { - e.printStackTrace(); - } - }); + public Map attacheRouter(Map subnetIdRouterIdMap) throws CacheException { + Map internalSubnetEntityMap = new TreeMap<>(); + for (Map.Entry subnetIdRouterId : subnetIdRouterIdMap.entrySet()) { + InternalSubnetPorts internalSubnetPorts = null; + try { + if (subnetPortsCache.containsKey(subnetIdRouterId.getKey())) { + internalSubnetPorts = subnetPortsCache.get(subnetIdRouterId.getKey()); + internalSubnetPorts.setRouterId(subnetIdRouterId.getValue()); + internalSubnetEntityMap.put(subnetIdRouterId.getKey(), internalSubnetPorts); + } + } catch (CacheException e) { + e.printStackTrace(); + } + } + + subnetPortsCache.putAll(internalSubnetEntityMap); + return internalSubnetEntityMap; } @DurationStatistics public Map getSubnetPorts(NetworkConfiguration networkConfig) throws CacheException { Map internalSubnetsRouterMap = getInternalSubnetRouterMap(networkConfig); - Map internalSubnetEntityMap = getSubnetPortsByRouterId(internalSubnetsRouterMap.values().stream().findFirst().orElse("")); - - Map internalSubnetPortsMap = networkConfig - .getSubnets() - .stream() - .filter(subnetEntity -> subnetEntity != null) - .map(subnetEntity -> { - InternalSubnetPorts internalSubnetPorts = internalSubnetEntityMap.getOrDefault(subnetEntity.getId(), null); - if (internalSubnetPorts == null) { - internalSubnetPorts = new InternalSubnetPorts(subnetEntity.getId() - ,subnetEntity.getGatewayPortDetail().getGatewayPortId() - ,subnetEntity.getGatewayIp() - ,subnetEntity.getGatewayPortDetail().getGatewayMacAddress() - ,subnetEntity.getName() - ,subnetEntity.getCidr() - ,subnetEntity.getVpcId() - ,subnetEntity.getTunnelId() - ,subnetEntity.getDhcpEnable() - ,internalSubnetsRouterMap.getOrDefault(subnetEntity.getId(), null)); - } - return internalSubnetPorts; - } - ) - .collect(Collectors.toMap(InternalSubnetPorts::getSubnetId, Function.identity())); - + Map internalSubnetPortsMap = new TreeMap<>(); + for (InternalSubnetEntity subnetEntity : networkConfig.getSubnets()) { + InternalSubnetPorts internalSubnetPorts = new InternalSubnetPorts(subnetEntity.getId() + ,subnetEntity.getGatewayPortDetail().getGatewayPortId() + ,subnetEntity.getGatewayIp() + ,subnetEntity.getGatewayPortDetail().getGatewayMacAddress() + ,subnetEntity.getName() + ,subnetEntity.getCidr() + ,subnetEntity.getVpcId() + ,subnetEntity.getTunnelId() + ,subnetEntity.getDhcpEnable() + ,internalSubnetsRouterMap.getOrDefault(subnetEntity.getId(), null)); + internalSubnetPortsMap.put(subnetEntity.getId(), internalSubnetPorts); + } return internalSubnetPortsMap; } diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/DpmServiceImplV2.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/DpmServiceImplV2.java index e293921ed..0271d0500 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/DpmServiceImplV2.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/DpmServiceImplV2.java @@ -258,8 +258,6 @@ private List processPortConfiguration(NetworkConfiguration networkConfig private List processNeighborConfiguration(NetworkConfiguration networkConfig) throws Exception { Map subnetIdRouterIdMap = subnetPortsCache.getInternalSubnetRouterMap(networkConfig); subnetPortsCache.attacheRouter(subnetIdRouterIdMap); - Map internalSubnetPortsMap = subnetPortsCache.getSubnetPorts(networkConfig); - subnetPortsCache.updateSubnetPorts(internalSubnetPortsMap); Map unicastGoalStates = new HashMap<>(); MulticastGoalStateV2 multicastGoalState = new MulticastGoalStateV2(); if (networkConfig.getInternalRouterInfos() != null) { diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java index a10a907d1..d3a8f7e57 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java @@ -437,7 +437,13 @@ public void buildNeighborStatesL3(NetworkConfiguration networkConfiguration, Map Map neighborStateMap = new TreeMap<>(); Map subnetStateMap = new TreeMap<>(); Router.RouterConfiguration.Builder unicastRouterConfigurationBuilder = Router.RouterConfiguration.newBuilder(); + if (networkConfiguration.getSubnets().size() == 0) { + return; + } String subnetId = networkConfiguration.getSubnets().stream().map(subnetEntity -> subnetEntity.getId()).findFirst().orElse(""); + if (subnetPortsCache.getSubnetPorts(subnetId) == null) { + return; + } String vpcid = subnetPortsCache.getSubnetPorts(subnetId).getVpcId(); portHostInfoCache.getPortHostInfos(subnetId) .forEach(portState -> unicastGoalStates.put(portState.getHostIp(), new UnicastGoalStateV2(portState.getHostIp(), Goalstate.GoalStateV2.newBuilder()))); From df72c6726135f84a0ce4d8bb16e10b53f8d402db Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Wed, 8 Dec 2021 15:52:41 -0800 Subject: [PATCH 25/33] Update code --- .../java/com/futurewei/alcor/web/entity/port/PortHostInfo.java | 3 +++ .../futurewei/alcor/web/entity/subnet/InternalSubnetPorts.java | 2 ++ 2 files changed, 5 insertions(+) diff --git a/web/src/main/java/com/futurewei/alcor/web/entity/port/PortHostInfo.java b/web/src/main/java/com/futurewei/alcor/web/entity/port/PortHostInfo.java index 9db7413af..e770cc0fd 100644 --- a/web/src/main/java/com/futurewei/alcor/web/entity/port/PortHostInfo.java +++ b/web/src/main/java/com/futurewei/alcor/web/entity/port/PortHostInfo.java @@ -15,12 +15,15 @@ free of charge, to any person obtaining a copy of this software and associated d */ package com.futurewei.alcor.web.entity.port; +import org.apache.ignite.cache.query.annotations.QuerySqlField; + public class PortHostInfo { private String portId; private String portIp; private String portMac; private String hostId; private String hostIp; + @QuerySqlField(index = true) private String subnetId; public PortHostInfo() { diff --git a/web/src/main/java/com/futurewei/alcor/web/entity/subnet/InternalSubnetPorts.java b/web/src/main/java/com/futurewei/alcor/web/entity/subnet/InternalSubnetPorts.java index 7faee5047..4cb5bb374 100644 --- a/web/src/main/java/com/futurewei/alcor/web/entity/subnet/InternalSubnetPorts.java +++ b/web/src/main/java/com/futurewei/alcor/web/entity/subnet/InternalSubnetPorts.java @@ -16,6 +16,7 @@ free of charge, to any person obtaining a copy of this software and associated d package com.futurewei.alcor.web.entity.subnet; import com.futurewei.alcor.web.entity.port.PortHostInfo; +import org.apache.ignite.cache.query.annotations.QuerySqlField; import java.util.List; @@ -30,6 +31,7 @@ public class InternalSubnetPorts { private Long tunnelId; private Boolean dhcpEnable; private List ports; + @QuerySqlField(index = true) private String routerId; public InternalSubnetPorts() { From 059f949cb82dbc509ad164759b629447fdf2c0e3 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Wed, 8 Dec 2021 16:01:07 -0800 Subject: [PATCH 26/33] Update code --- .../com/futurewei/alcor/dataplane/cache/SubnetPortsCache.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SubnetPortsCache.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SubnetPortsCache.java index 9d8209c66..f39c1ecba 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SubnetPortsCache.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SubnetPortsCache.java @@ -147,7 +147,7 @@ public void updateSubnetPorts(InternalSubnetPorts internalSubnetPorts) throws Ex } @DurationStatistics - public synchronized void deleteSubnetPorts(String subnetId) throws Exception { + public void deleteSubnetPorts(String subnetId) throws Exception { subnetPortsCache.remove(subnetId); } From 276926a372ad44d6fcf457edef7f20c8cd1efb84 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Wed, 8 Dec 2021 16:03:16 -0800 Subject: [PATCH 27/33] Update code --- .../alcor/dataplane/client/grpc/DataPlaneClientImplV2.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java index c0b47eb80..c3a1868da 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java @@ -71,7 +71,7 @@ public List sendGoalStates(List unicastGoalStates) t for (UnicastGoalStateV2 unicastGoalState : unicastGoalStates) { goalStateBuilder = getGoalState(goalStateBuilder, unicastGoalState); } - System.out.println(goalStateBuilder.build()); + doSendGoalState(goalStateBuilder.build(), finishLatch, results); if (!finishLatch.await(1, TimeUnit.MINUTES)) { From 3ca631ff4ddc88fd3c2f8a415c3939a7a5964b33 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Wed, 8 Dec 2021 16:08:13 -0800 Subject: [PATCH 28/33] Update code --- .../futurewei/alcor/dataplane/cache/RouterSubnetsCache.java | 6 +++--- .../alcor/dataplane/client/grpc/DataPlaneClientImplV2.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/RouterSubnetsCache.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/RouterSubnetsCache.java index a06303213..1d96e5ece 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/RouterSubnetsCache.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/RouterSubnetsCache.java @@ -48,7 +48,7 @@ public RouterSubnetsCache(CacheFactory cacheFactory) { } @DurationStatistics - public synchronized Collection getRouterSubnets(String routerId) throws CacheException { + public Collection getRouterSubnets(String routerId) throws CacheException { Map queryParams = new HashMap<>(); Object[] values = new Object[1]; values[0] = routerId; @@ -58,7 +58,7 @@ public synchronized Collection getRouterSubnets(String } @DurationStatistics - public synchronized Collection updateVpcSubnets(NetworkConfiguration networkConfig) throws CacheException { + public Collection updateVpcSubnets(NetworkConfiguration networkConfig) throws CacheException { Map internalSubnetsMap = networkConfig .getInternalRouterInfos() .stream() @@ -73,7 +73,7 @@ public synchronized Collection updateVpcSubnets(Network } @DurationStatistics - public synchronized void deleteVpcGatewayInfo(String routerId, String subnetId) throws CacheException { + public void deleteVpcGatewayInfo(String routerId, String subnetId) throws CacheException { routerSubnetsCache.remove(routerId + cacheFactory.KEY_DELIMITER + subnetId); } diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java index c3a1868da..214aaf7c5 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java @@ -71,7 +71,7 @@ public List sendGoalStates(List unicastGoalStates) t for (UnicastGoalStateV2 unicastGoalState : unicastGoalStates) { goalStateBuilder = getGoalState(goalStateBuilder, unicastGoalState); } - + doSendGoalState(goalStateBuilder.build(), finishLatch, results); if (!finishLatch.await(1, TimeUnit.MINUTES)) { From 367086f35e66e87ba67f50eae11445e2428bd31c Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Wed, 8 Dec 2021 16:18:18 -0800 Subject: [PATCH 29/33] Update code --- .../netwconfigmanager/client/gRPC/GoalStateClientImpl.java | 4 ++-- .../server/grpc/GoalStateProvisionerServer.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/client/gRPC/GoalStateClientImpl.java b/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/client/gRPC/GoalStateClientImpl.java index 02e8de496..316bce9e8 100644 --- a/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/client/gRPC/GoalStateClientImpl.java +++ b/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/client/gRPC/GoalStateClientImpl.java @@ -244,7 +244,7 @@ public void onCompleted() { StreamObserver requestObserver = asyncStub.pushGoalStatesStream(responseObserver); try { Goalstate.GoalStateV2 goalState = hostGoalState.getGoalState(); - logger.log(Level.INFO, "Sending GS to Host " + hostIp + " as follows | " + goalState.toString()); + logger.log(Level.FINE, "Sending GS to Host " + hostIp + " as follows | " + goalState.toString()); requestObserver.onNext(goalState); if (hostGoalState.getGoalState().getNeighborStatesCount() == 1 && monitorHosts.contains(hostIp)) { long sent_gs_time = System.currentTimeMillis(); @@ -252,7 +252,7 @@ public void onCompleted() { // hardcoded) this send goalstate action is probably caused by on-demand workflow, need to record when it // sends this goalState so what we can look into this and the ACA log to see how much time was spent. String neighbor_id = hostGoalState.getGoalState().getNeighborStatesMap().keySet().iterator().next(); - logger.log(Level.INFO, "Sending neighbor ID: " + neighbor_id + " at: " + sent_gs_time); + logger.log(Level.FINE, "Sending neighbor ID: " + neighbor_id + " at: " + sent_gs_time); } } catch (RuntimeException e) { // Cancel RPC diff --git a/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/server/grpc/GoalStateProvisionerServer.java b/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/server/grpc/GoalStateProvisionerServer.java index b7d4a63af..338453a19 100644 --- a/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/server/grpc/GoalStateProvisionerServer.java +++ b/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/server/grpc/GoalStateProvisionerServer.java @@ -146,7 +146,7 @@ public StreamObserver pushGoalStatesStream(final StreamOb @Override public void onNext(Goalstate.GoalStateV2 value) { - logger.log(Level.INFO, "pushGoalStatesStream : receiving GS V2 message " + value.toString()); + logger.log(Level.FINE, "pushGoalStatesStream : receiving GS V2 message " + value.toString()); long start = System.currentTimeMillis(); //store the goal state in cache From 8732c438a124a0b6c4b851de70a40fb738ec1734 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Wed, 8 Dec 2021 16:22:53 -0800 Subject: [PATCH 30/33] Update code --- .../alcor/dataplane/client/grpc/DataPlaneClientImplV2.java | 1 - 1 file changed, 1 deletion(-) diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java index 214aaf7c5..70eede9a3 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java @@ -71,7 +71,6 @@ public List sendGoalStates(List unicastGoalStates) t for (UnicastGoalStateV2 unicastGoalState : unicastGoalStates) { goalStateBuilder = getGoalState(goalStateBuilder, unicastGoalState); } - doSendGoalState(goalStateBuilder.build(), finishLatch, results); if (!finishLatch.await(1, TimeUnit.MINUTES)) { From 43c0c7c42d519e202b1d635c8f38ea8c039a792e Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Wed, 8 Dec 2021 16:25:42 -0800 Subject: [PATCH 31/33] Update code --- .../futurewei/alcor/dataplane/service/impl/NeighborService.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java index d3a8f7e57..216ff31b3 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java @@ -391,10 +391,8 @@ public void buildNeighborStatesL3(NetworkConfiguration networkConfiguration, Uni routerIds.parallelStream().forEach(routerId -> { try { Collection internalSubnetPorts = subnetPortsCache.getSubnetPortsByRouterId(routerId).values(); - for (InternalSubnetPorts internalSubnetPort : internalSubnetPorts) { try { - Collection portHostInfos = portHostInfoCache.getPortHostInfos(internalSubnetPort.getSubnetId()); portHostInfos.parallelStream().forEach(portHostInfo -> { try { From f5b7f75f85a591bde9b5cb7f41cc70627ed1cd3b Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Fri, 10 Dec 2021 14:44:25 -0800 Subject: [PATCH 32/33] Update code --- .../dataplane/cache/PortHostInfoCache.java | 17 ++++++++++-- .../dataplane/cache/SubnetPortsCache.java | 27 +++++++++++-------- .../portmanager/repo/PortRepository.java | 10 ------- 3 files changed, 31 insertions(+), 23 deletions(-) diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/PortHostInfoCache.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/PortHostInfoCache.java index dcde4fbc9..bd55eafd7 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/PortHostInfoCache.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/PortHostInfoCache.java @@ -1,3 +1,18 @@ +/* +MIT License +Copyright(c) 2020 Futurewei Cloud + + Permission is hereby granted, + free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal in the Software without restriction, + including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the Software, and to permit persons + to whom the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ package com.futurewei.alcor.dataplane.cache; import com.futurewei.alcor.common.db.CacheException; @@ -17,12 +32,10 @@ import java.util.function.Function; import java.util.stream.Collectors; - @Repository @ComponentScan(value="com.futurewei.alcor.common.db") public class PortHostInfoCache { - private ICache portHostInfoCache; private CacheFactory cacheFactory; diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SubnetPortsCache.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SubnetPortsCache.java index f39c1ecba..571fa763e 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SubnetPortsCache.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SubnetPortsCache.java @@ -22,6 +22,7 @@ free of charge, to any person obtaining a copy of this software and associated d import com.futurewei.alcor.common.stats.DurationStatistics; import com.futurewei.alcor.dataplane.entity.InternalSubnetRouterMap; import com.futurewei.alcor.dataplane.entity.InternalSubnets; +import com.futurewei.alcor.schema.Subnet; import com.futurewei.alcor.web.entity.dataplane.InternalSubnetEntity; import com.futurewei.alcor.web.entity.dataplane.v2.NetworkConfiguration; import com.futurewei.alcor.web.entity.port.PortHostInfo; @@ -121,21 +122,25 @@ public Map getSubnetPorts(NetworkConfiguration netw Map internalSubnetsRouterMap = getInternalSubnetRouterMap(networkConfig); Map internalSubnetPortsMap = new TreeMap<>(); for (InternalSubnetEntity subnetEntity : networkConfig.getSubnets()) { - InternalSubnetPorts internalSubnetPorts = new InternalSubnetPorts(subnetEntity.getId() - ,subnetEntity.getGatewayPortDetail().getGatewayPortId() - ,subnetEntity.getGatewayIp() - ,subnetEntity.getGatewayPortDetail().getGatewayMacAddress() - ,subnetEntity.getName() - ,subnetEntity.getCidr() - ,subnetEntity.getVpcId() - ,subnetEntity.getTunnelId() - ,subnetEntity.getDhcpEnable() - ,internalSubnetsRouterMap.getOrDefault(subnetEntity.getId(), null)); - internalSubnetPortsMap.put(subnetEntity.getId(), internalSubnetPorts); + internalSubnetPortsMap.put(subnetEntity.getId(), getInternalSubnetPorts(subnetEntity, internalSubnetsRouterMap.getOrDefault(subnetEntity.getId(), null))); } return internalSubnetPortsMap; } + private InternalSubnetPorts getInternalSubnetPorts(InternalSubnetEntity subnetEntity, String routerId) { + InternalSubnetPorts internalSubnetPorts = new InternalSubnetPorts(subnetEntity.getId() + ,subnetEntity.getGatewayPortDetail().getGatewayPortId() + ,subnetEntity.getGatewayIp() + ,subnetEntity.getGatewayPortDetail().getGatewayMacAddress() + ,subnetEntity.getName() + ,subnetEntity.getCidr() + ,subnetEntity.getVpcId() + ,subnetEntity.getTunnelId() + ,subnetEntity.getDhcpEnable() + ,routerId); + return internalSubnetPorts; + } + @DurationStatistics public void updateSubnetPorts(Map internalSubnetPortsMap) throws Exception { subnetPortsCache.putAll(internalSubnetPortsMap); diff --git a/services/port_manager/src/main/java/com/futurewei/alcor/portmanager/repo/PortRepository.java b/services/port_manager/src/main/java/com/futurewei/alcor/portmanager/repo/PortRepository.java index 3742101ab..8bdf0bd1d 100644 --- a/services/port_manager/src/main/java/com/futurewei/alcor/portmanager/repo/PortRepository.java +++ b/services/port_manager/src/main/java/com/futurewei/alcor/portmanager/repo/PortRepository.java @@ -263,19 +263,11 @@ public PortNeighbors getPortNeighbors(Object arg) throws CacheException { @DurationStatistics public synchronized void createPortBulk(List portEntities, Map> neighbors) throws Exception { - portEntities.forEach(item -> { - try { - neighborRepository.addProject(item.getProjectId(), item.getVpcId()); - } catch (CacheException e) { - e.printStackTrace(); - } - }); try (Transaction tx = portCache.getTransaction().start()) { Map portEntityMap = portEntities .stream() .collect(Collectors.toMap(PortEntity::getId, Function.identity())); portCache.putAll(portEntityMap); - //neighborRepository.createNeighbors(portEntities.get(0).getProjectId(), neighbors); subnetPortsRepository.addSubnetPortIds(portEntities); tx.commit(); } @@ -285,7 +277,6 @@ public synchronized void createPortBulk(List portEntities, Map neighborInfos) throws Exception { try (Transaction tx = portCache.getTransaction().start()) { portCache.put(newPortEntity.getId(), newPortEntity); - //neighborRepository.updateNeighbors(oldPortEntity, neighborInfos); subnetPortsRepository.updateSubnetPortIds(oldPortEntity, newPortEntity); tx.commit(); } @@ -295,7 +286,6 @@ public synchronized void updatePort(PortEntity oldPortEntity, PortEntity newPort public synchronized void deletePort(PortEntity portEntity) throws Exception { try (Transaction tx = portCache.getTransaction().start()) { portCache.remove(portEntity.getId()); - //neighborRepository.deleteNeighbors(portEntity); subnetPortsRepository.deleteSubnetPortIds(portEntity); tx.commit(); } From 971bc8322c3e70fc74d4d3fe8f767662eae5fee6 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Fri, 10 Dec 2021 16:04:19 -0800 Subject: [PATCH 33/33] Update code --- .../com/futurewei/alcor/dataplane/cache/PortHostInfoCache.java | 1 + .../com/futurewei/alcor/dataplane/cache/SubnetPortsCache.java | 1 + 2 files changed, 2 insertions(+) diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/PortHostInfoCache.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/PortHostInfoCache.java index bd55eafd7..7c10f54d0 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/PortHostInfoCache.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/PortHostInfoCache.java @@ -72,6 +72,7 @@ public synchronized Collection getPortHostInfos(String subnetId) t Object[] values = new Object[1]; values[0] = subnetId; queryParams.put("subnetId", values); + // Use sql index return portHostInfoCache.getAll(queryParams).values(); } diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SubnetPortsCache.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SubnetPortsCache.java index 571fa763e..33d5bc970 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SubnetPortsCache.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SubnetPortsCache.java @@ -60,6 +60,7 @@ public Map getSubnetPortsByRouterId(String routerId Object[] values = new Object[1]; values[0] = routerId; queryParams.put("routerId", values); + // Use sql index return subnetPortsCache.getAll(queryParams); }