@Test public void testCreateSymmetricRenderedPath() throws Exception { final ServiceFunctionPath sfp = createSfp("unit-sfp-02"); final RenderedServicePath rsp = createRsp("unit-rsp-02"); final TenantId tenantId = new TenantId("tenant-02"); final Sgt sourceSgt = new Sgt(1); final Sgt destinationSgt = new Sgt(2); final PolicyConfigurationContext context = new PolicyConfigurationContext(); context.setPolicyMapLocation(getLocation()); PowerMockito.mockStatic(SfcProviderRenderedPathAPI.class); PowerMockito.when(SfcProviderRenderedPathAPI.readRenderedServicePath(rspNameCaptor.capture())).thenReturn(rsp); stub(method(SfcProviderServiceForwarderAPI.class, "readServiceFunctionForwarder")) .toReturn(new ServiceFunctionForwarderBuilder().setName(new SffName("sff-name")).build()); final RenderedServicePath symmetricRenderedPath = ServiceChainingUtil.resolveReversedRenderedServicePath(sfp, tenantId, dataBroker, sourceSgt, destinationSgt, context); assertEquals("unit-sfp-02_plain-tenant-02-gbp-rsp-Reverse", rspNameCaptor.getValue().getValue()); assertEquals(rsp, symmetricRenderedPath); }
public static RenderedServicePath resolveReversedRenderedServicePath(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 RspName reversedRspName = generateReversedRspName(sfp, tenantId); RenderedServicePath reversedRenderedPath = SfcProviderRenderedPathAPI.readRenderedServicePath(reversedRspName); if (reversedRenderedPath == null) { LOG.info("Reversed rendered service path with name {} not found, creating a new one ..", reversedRspName.getValue()); reversedRenderedPath = SfcProviderRenderedPathAPI.createReverseRenderedServicePathEntry(renderedServicePath); LOG.info("Rendered service path {} created", reversedRspName.getValue()); checkRspManagerStatus(reversedRspName, 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)); resolveRemoteSfcComponents(renderedServicePath, context); return reversedRenderedPath; }
ServiceChainingUtil { public static RenderedServicePath resolveReversedRenderedServicePath(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 RspName reversedRspName = generateReversedRspName(sfp, tenantId); RenderedServicePath reversedRenderedPath = SfcProviderRenderedPathAPI.readRenderedServicePath(reversedRspName); if (reversedRenderedPath == null) { LOG.info("Reversed rendered service path with name {} not found, creating a new one ..", reversedRspName.getValue()); reversedRenderedPath = SfcProviderRenderedPathAPI.createReverseRenderedServicePathEntry(renderedServicePath); LOG.info("Rendered service path {} created", reversedRspName.getValue()); checkRspManagerStatus(reversedRspName, 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)); resolveRemoteSfcComponents(renderedServicePath, context); return reversedRenderedPath; } }
ServiceChainingUtil { public static RenderedServicePath resolveReversedRenderedServicePath(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 RspName reversedRspName = generateReversedRspName(sfp, tenantId); RenderedServicePath reversedRenderedPath = SfcProviderRenderedPathAPI.readRenderedServicePath(reversedRspName); if (reversedRenderedPath == null) { LOG.info("Reversed rendered service path with name {} not found, creating a new one ..", reversedRspName.getValue()); reversedRenderedPath = SfcProviderRenderedPathAPI.createReverseRenderedServicePathEntry(renderedServicePath); LOG.info("Rendered service path {} created", reversedRspName.getValue()); checkRspManagerStatus(reversedRspName, 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)); resolveRemoteSfcComponents(renderedServicePath, context); return reversedRenderedPath; } private  ServiceChainingUtil(); }
ServiceChainingUtil { public static RenderedServicePath resolveReversedRenderedServicePath(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 RspName reversedRspName = generateReversedRspName(sfp, tenantId); RenderedServicePath reversedRenderedPath = SfcProviderRenderedPathAPI.readRenderedServicePath(reversedRspName); if (reversedRenderedPath == null) { LOG.info("Reversed rendered service path with name {} not found, creating a new one ..", reversedRspName.getValue()); reversedRenderedPath = SfcProviderRenderedPathAPI.createReverseRenderedServicePathEntry(renderedServicePath); LOG.info("Rendered service path {} created", reversedRspName.getValue()); checkRspManagerStatus(reversedRspName, 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)); resolveRemoteSfcComponents(renderedServicePath, context); return reversedRenderedPath; } 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 { public static RenderedServicePath resolveReversedRenderedServicePath(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 RspName reversedRspName = generateReversedRspName(sfp, tenantId); RenderedServicePath reversedRenderedPath = SfcProviderRenderedPathAPI.readRenderedServicePath(reversedRspName); if (reversedRenderedPath == null) { LOG.info("Reversed rendered service path with name {} not found, creating a new one ..", reversedRspName.getValue()); reversedRenderedPath = SfcProviderRenderedPathAPI.createReverseRenderedServicePathEntry(renderedServicePath); LOG.info("Rendered service path {} created", reversedRspName.getValue()); checkRspManagerStatus(reversedRspName, 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)); resolveRemoteSfcComponents(renderedServicePath, context); return reversedRenderedPath; } 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);  }