@Test public void testCreateRenderedPath() throws Exception { final String sfcNameValue = "123"; final ServiceFunctionPath sfp = createSfp(sfcNameValue); final TenantId tenantId = new TenantId("unit-tenant-01"); final Sgt sourceSgt = new Sgt(1); final Sgt destinationSgt = new Sgt(2); final PolicyConfigurationContext context = new PolicyConfigurationContext(); context.setPolicyMapLocation(getLocation()); final RenderedServicePath rsp = createRsp("unit-rsp-01"); PowerMockito.mockStatic(SfcProviderRenderedPathAPI.class); PowerMockito.when(SfcProviderRenderedPathAPI.readRenderedServicePath(rspNameCaptor.capture())).thenReturn(rsp); final RenderedServicePath renderedPath = ServiceChainingUtil.resolveRenderedServicePath(sfp, tenantId, dataBroker, sourceSgt, destinationSgt, context); assertEquals("123_plain-unit-tenant-01-gbp-rsp", rspNameCaptor.getValue().getValue()); assertEquals(rsp, renderedPath); }
static RenderedServicePath resolveRenderedServicePath(final ServiceFunctionPath sfp, final TenantId tenantId, final DataBroker dataBroker, final Sgt sourceSgt, final Sgt destinationSgt, final PolicyConfigurationContext context) { final RspName rspName = generateRspName(sfp, tenantId); RenderedServicePath renderedServicePath = SfcProviderRenderedPathAPI.readRenderedServicePath(rspName); if (renderedServicePath == null) { LOG.info("Rendered service path with name {} not found, creating a new one ..", rspName.getValue()); final CreateRenderedPathInput input = new CreateRenderedPathInputBuilder() .setParentServiceFunctionPath(sfp.getName().getValue()) .setName(rspName.getValue()) .setSymmetric(sfp.isSymmetric()) .build(); renderedServicePath = SfcProviderRenderedPathAPI.createRenderedServicePathAndState(sfp, input); LOG.info("Rendered service path {} created", rspName.getValue()); checkRspManagerStatus(rspName, dataBroker); } final String classMapName = generateClassMapName(sourceSgt.getValue(), destinationSgt.getValue()); final Match match = createSecurityGroupMatch(sourceSgt.getValue(), destinationSgt.getValue()); final ClassMap classMap = createClassMap(classMapName, match); final Class policyMapEntry = createPolicyMapEntry(classMapName, renderedServicePath, ActionCase.CHAIN); boolean cmResult = PolicyWriterUtil.writeClassMap(classMap, context.getPolicyMapLocation()); context.setFutureResult(Futures.immediateCheckedFuture(cmResult)); boolean pmeResult = PolicyWriterUtil.writePolicyMapEntry(policyMapEntry, context.getPolicyMapLocation()); context.setFutureResult(Futures.immediateCheckedFuture(pmeResult)); return renderedServicePath; }
ServiceChainingUtil { static RenderedServicePath resolveRenderedServicePath(final ServiceFunctionPath sfp, final TenantId tenantId, final DataBroker dataBroker, final Sgt sourceSgt, final Sgt destinationSgt, final PolicyConfigurationContext context) { final RspName rspName = generateRspName(sfp, tenantId); RenderedServicePath renderedServicePath = SfcProviderRenderedPathAPI.readRenderedServicePath(rspName); if (renderedServicePath == null) { LOG.info("Rendered service path with name {} not found, creating a new one ..", rspName.getValue()); final CreateRenderedPathInput input = new CreateRenderedPathInputBuilder() .setParentServiceFunctionPath(sfp.getName().getValue()) .setName(rspName.getValue()) .setSymmetric(sfp.isSymmetric()) .build(); renderedServicePath = SfcProviderRenderedPathAPI.createRenderedServicePathAndState(sfp, input); LOG.info("Rendered service path {} created", rspName.getValue()); checkRspManagerStatus(rspName, dataBroker); } final String classMapName = generateClassMapName(sourceSgt.getValue(), destinationSgt.getValue()); final Match match = createSecurityGroupMatch(sourceSgt.getValue(), destinationSgt.getValue()); final ClassMap classMap = createClassMap(classMapName, match); final Class policyMapEntry = createPolicyMapEntry(classMapName, renderedServicePath, ActionCase.CHAIN); boolean cmResult = PolicyWriterUtil.writeClassMap(classMap, context.getPolicyMapLocation()); context.setFutureResult(Futures.immediateCheckedFuture(cmResult)); boolean pmeResult = PolicyWriterUtil.writePolicyMapEntry(policyMapEntry, context.getPolicyMapLocation()); context.setFutureResult(Futures.immediateCheckedFuture(pmeResult)); return renderedServicePath; } }
ServiceChainingUtil { static RenderedServicePath resolveRenderedServicePath(final ServiceFunctionPath sfp, final TenantId tenantId, final DataBroker dataBroker, final Sgt sourceSgt, final Sgt destinationSgt, final PolicyConfigurationContext context) { final RspName rspName = generateRspName(sfp, tenantId); RenderedServicePath renderedServicePath = SfcProviderRenderedPathAPI.readRenderedServicePath(rspName); if (renderedServicePath == null) { LOG.info("Rendered service path with name {} not found, creating a new one ..", rspName.getValue()); final CreateRenderedPathInput input = new CreateRenderedPathInputBuilder() .setParentServiceFunctionPath(sfp.getName().getValue()) .setName(rspName.getValue()) .setSymmetric(sfp.isSymmetric()) .build(); renderedServicePath = SfcProviderRenderedPathAPI.createRenderedServicePathAndState(sfp, input); LOG.info("Rendered service path {} created", rspName.getValue()); checkRspManagerStatus(rspName, dataBroker); } final String classMapName = generateClassMapName(sourceSgt.getValue(), destinationSgt.getValue()); final Match match = createSecurityGroupMatch(sourceSgt.getValue(), destinationSgt.getValue()); final ClassMap classMap = createClassMap(classMapName, match); final Class policyMapEntry = createPolicyMapEntry(classMapName, renderedServicePath, ActionCase.CHAIN); boolean cmResult = PolicyWriterUtil.writeClassMap(classMap, context.getPolicyMapLocation()); context.setFutureResult(Futures.immediateCheckedFuture(cmResult)); boolean pmeResult = PolicyWriterUtil.writePolicyMapEntry(policyMapEntry, context.getPolicyMapLocation()); context.setFutureResult(Futures.immediateCheckedFuture(pmeResult)); return renderedServicePath; } private  ServiceChainingUtil(); }
ServiceChainingUtil { static RenderedServicePath resolveRenderedServicePath(final ServiceFunctionPath sfp, final TenantId tenantId, final DataBroker dataBroker, final Sgt sourceSgt, final Sgt destinationSgt, final PolicyConfigurationContext context) { final RspName rspName = generateRspName(sfp, tenantId); RenderedServicePath renderedServicePath = SfcProviderRenderedPathAPI.readRenderedServicePath(rspName); if (renderedServicePath == null) { LOG.info("Rendered service path with name {} not found, creating a new one ..", rspName.getValue()); final CreateRenderedPathInput input = new CreateRenderedPathInputBuilder() .setParentServiceFunctionPath(sfp.getName().getValue()) .setName(rspName.getValue()) .setSymmetric(sfp.isSymmetric()) .build(); renderedServicePath = SfcProviderRenderedPathAPI.createRenderedServicePathAndState(sfp, input); LOG.info("Rendered service path {} created", rspName.getValue()); checkRspManagerStatus(rspName, dataBroker); } final String classMapName = generateClassMapName(sourceSgt.getValue(), destinationSgt.getValue()); final Match match = createSecurityGroupMatch(sourceSgt.getValue(), destinationSgt.getValue()); final ClassMap classMap = createClassMap(classMapName, match); final Class policyMapEntry = createPolicyMapEntry(classMapName, renderedServicePath, ActionCase.CHAIN); boolean cmResult = PolicyWriterUtil.writeClassMap(classMap, context.getPolicyMapLocation()); context.setFutureResult(Futures.immediateCheckedFuture(cmResult)); boolean pmeResult = PolicyWriterUtil.writePolicyMapEntry(policyMapEntry, context.getPolicyMapLocation()); context.setFutureResult(Futures.immediateCheckedFuture(pmeResult)); return renderedServicePath; } private  ServiceChainingUtil(); static boolean resolveRemoteSfcComponents(final RenderedServicePath renderedServicePath,
                                                      final PolicyConfigurationContext context); static RenderedServicePath resolveReversedRenderedServicePath(final ServiceFunctionPath sfp, final TenantId tenantId,
                                                                          final DataBroker dataBroker, final Sgt sourceSgt,
                                                                          final Sgt destinationSgt, final PolicyConfigurationContext context); @VisibleForTesting static void setTimeout(long value); }
ServiceChainingUtil { static RenderedServicePath resolveRenderedServicePath(final ServiceFunctionPath sfp, final TenantId tenantId, final DataBroker dataBroker, final Sgt sourceSgt, final Sgt destinationSgt, final PolicyConfigurationContext context) { final RspName rspName = generateRspName(sfp, tenantId); RenderedServicePath renderedServicePath = SfcProviderRenderedPathAPI.readRenderedServicePath(rspName); if (renderedServicePath == null) { LOG.info("Rendered service path with name {} not found, creating a new one ..", rspName.getValue()); final CreateRenderedPathInput input = new CreateRenderedPathInputBuilder() .setParentServiceFunctionPath(sfp.getName().getValue()) .setName(rspName.getValue()) .setSymmetric(sfp.isSymmetric()) .build(); renderedServicePath = SfcProviderRenderedPathAPI.createRenderedServicePathAndState(sfp, input); LOG.info("Rendered service path {} created", rspName.getValue()); checkRspManagerStatus(rspName, dataBroker); } final String classMapName = generateClassMapName(sourceSgt.getValue(), destinationSgt.getValue()); final Match match = createSecurityGroupMatch(sourceSgt.getValue(), destinationSgt.getValue()); final ClassMap classMap = createClassMap(classMapName, match); final Class policyMapEntry = createPolicyMapEntry(classMapName, renderedServicePath, ActionCase.CHAIN); boolean cmResult = PolicyWriterUtil.writeClassMap(classMap, context.getPolicyMapLocation()); context.setFutureResult(Futures.immediateCheckedFuture(cmResult)); boolean pmeResult = PolicyWriterUtil.writePolicyMapEntry(policyMapEntry, context.getPolicyMapLocation()); context.setFutureResult(Futures.immediateCheckedFuture(pmeResult)); return renderedServicePath; } private  ServiceChainingUtil(); static boolean resolveRemoteSfcComponents(final RenderedServicePath renderedServicePath,
                                                      final PolicyConfigurationContext context); static RenderedServicePath resolveReversedRenderedServicePath(final ServiceFunctionPath sfp, final TenantId tenantId,
                                                                          final DataBroker dataBroker, final Sgt sourceSgt,
                                                                          final Sgt destinationSgt, final PolicyConfigurationContext context); @VisibleForTesting static void setTimeout(long value);  }