SfcProviderRpc implements ServiceFunctionService, ServiceFunctionChainService, RenderedServicePathService,
        ServicePathIdService, RenderedIoamPathService { @Override public Future<RpcResult<CreateRenderedPathOutput>> createRenderedPath( CreateRenderedPathInput createRenderedPathInput) { ServiceFunctionPath createdServiceFunctionPath; RenderedServicePath renderedServicePath; RenderedServicePath revRenderedServicePath; CreateRenderedPathOutputBuilder createRenderedPathOutputBuilder = new CreateRenderedPathOutputBuilder(); RpcResult<CreateRenderedPathOutput> rpcResult; RspName retRspName = null; createdServiceFunctionPath = SfcProviderServicePathAPI .readServiceFunctionPath(new SfpName(createRenderedPathInput.getParentServiceFunctionPath())); if (createdServiceFunctionPath != null) { renderedServicePath = SfcProviderRenderedPathAPI .createRenderedServicePathAndState(createdServiceFunctionPath, createRenderedPathInput); if (renderedServicePath != null) { retRspName = renderedServicePath.getName(); createRenderedPathOutputBuilder.setName(retRspName.getValue()); rpcResult = RpcResultBuilder.success(createRenderedPathOutputBuilder.build()).build(); if (SfcProviderRenderedPathAPI.isChainSymmetric(createdServiceFunctionPath, renderedServicePath)) { revRenderedServicePath = SfcProviderRenderedPathAPI.createSymmetricRenderedServicePathAndState(renderedServicePath); if (revRenderedServicePath == null) { LOG.error("Failed to create symmetric service path: {}"); } else { SfcProviderRenderedPathAPI.setSymmetricPathId(renderedServicePath, revRenderedServicePath.getPathId()); } } } else { rpcResult = RpcResultBuilder.<CreateRenderedPathOutput>failed() .withError(ErrorType.APPLICATION, "Failed to create RSP") .build(); } } else { rpcResult = RpcResultBuilder.<CreateRenderedPathOutput>failed() .withError(ErrorType.APPLICATION, "Service Function Path does not exist") .build(); } return Futures.immediateFuture(rpcResult); }  static SfcProviderRpc getSfcProviderRpc(); void setDataProvider(DataBroker r); static void setDataProviderAux(DataBroker r); @Override Future<RpcResult<Void>> deleteAllServiceFunction(); @Override Future<RpcResult<Void>> deleteServiceFunction(DeleteServiceFunctionInput input); @Override Future<RpcResult<Void>> putServiceFunction(PutServiceFunctionInput input); @Override Future<RpcResult<ReadServiceFunctionOutput>> readServiceFunction(ReadServiceFunctionInput input); @Override Future<RpcResult<InstantiateServiceFunctionChainOutput>> instantiateServiceFunctionChain(
            InstantiateServiceFunctionChainInput input); @Override Future<RpcResult<Void>> putServiceFunctionChains(PutServiceFunctionChainsInput input); @Override Future<RpcResult<CreateRenderedPathOutput>> createRenderedPath(
            CreateRenderedPathInput createRenderedPathInput); @Override Future<RpcResult<DeleteRenderedPathOutput>> deleteRenderedPath(DeleteRenderedPathInput input); @Override Future<RpcResult<ReadRenderedServicePathFirstHopOutput>> readRenderedServicePathFirstHop(
            ReadRenderedServicePathFirstHopInput input); @Override Future<RpcResult<ReadRspFirstHopBySftListOutput>> readRspFirstHopBySftList(
            ReadRspFirstHopBySftListInput input); @Override Future<RpcResult<TraceRenderedServicePathOutput>> traceRenderedServicePath(
            TraceRenderedServicePathInput input); @Override Future<RpcResult<ReservePathIdRangeOutput>> reservePathIdRange(ReservePathIdRangeInput input); @Override Future<RpcResult<ReadPathIdOutput>> readPathId(ReadPathIdInput input); @Override Future<RpcResult<AllocatePathIdOutput>> allocatePathId(AllocatePathIdInput input); @Override Future<RpcResult<DeletePathIdOutput>> deletePathId(DeletePathIdInput input); @Override Future<RpcResult<SetGenerationAlgorithmOutput>> setGenerationAlgorithm(SetGenerationAlgorithmInput input); @Override Future<RpcResult<CreateIoamPathOutput>> createIoamPath(final CreateIoamPathInput input); @Override Future<RpcResult<DeleteIoamPathOutput>> deleteIoamPath(DeleteIoamPathInput input);  }
@Test public void createRenderedPathTest() throws Exception { init(); ServiceFunctionPath serviceFunctionPath = SfcProviderServicePathAPI.readServiceFunctionPath(SFP_NAME); assertNotNull("Must be not null", serviceFunctionPath); CreateRenderedPathInputBuilder createRenderedPathInputBuilder = new CreateRenderedPathInputBuilder(); createRenderedPathInputBuilder.setName(RSP_NAME.getValue()) .setParentServiceFunctionPath(SFP_NAME.getValue()) .setSymmetric(true); CreateRenderedPathInput createRenderedPathInput = createRenderedPathInputBuilder.build(); SfcProviderRenderedPathAPI.createRenderedServicePathAndState(serviceFunctionPath, createRenderedPathInput); List<SffServicePath> sffServicePathList = SfcProviderServiceForwarderAPI.readSffState(SFF_NAMES.get(0)); assertNotNull("Must be not null", sffServicePathList); assertEquals(sffServicePathList.get(0).getName().getValue(), RSP_NAME.getValue()); List<SfServicePath> sfServicePathList = SfcProviderServiceFunctionAPI.readServiceFunctionState(new SfName("unittest-fw-1")); assertEquals(sfServicePathList.get(0).getName().getValue(), RSP_NAME.getValue()); List<SfpRenderedServicePath> sfpRenderedServicePathList = SfcProviderServicePathAPI.readServicePathState(SFP_NAME); assertEquals(sfpRenderedServicePathList.get(0).getName().getValue(), RSP_NAME.getValue()); ServiceFunctionClassifierBuilder serviceFunctionClassifierBuilder = new ServiceFunctionClassifierBuilder(); serviceFunctionClassifierBuilder.setName(SFP_NAME.getValue()); ServiceFunctionClassifier serviceFunctionClassifier = serviceFunctionClassifierBuilder.build(); InstanceIdentifier<ServiceFunctionClassifier> sclIID; ServiceFunctionClassifierKey serviceFunctionKey = new ServiceFunctionClassifierKey(SFP_NAME.getValue()); sclIID = InstanceIdentifier.builder(ServiceFunctionClassifiers.class) .child(ServiceFunctionClassifier.class, serviceFunctionKey) .build(); SfcDataStoreAPI.writePutTransactionAPI(sclIID, serviceFunctionClassifier, LogicalDatastoreType.CONFIGURATION); Future<RpcResult<CreateRenderedPathOutput>> result = sfcProviderRpc.createRenderedPath(createRenderedPathInput); assertNotNull(result); assertNotNull(result.get()); assertNotNull(result.get().getResult()); assertTrue(result.get().getErrors().isEmpty()); assertTrue(result.get().isSuccessful()); RenderedServicePath renderedServicePath = SfcProviderRenderedPathAPI.readRenderedServicePath(RSP_NAME); assertEquals(renderedServicePath.getName(), RSP_NAME); assertEquals(5, renderedServicePath.getRenderedServicePathHop().size()); assertHop(0, new SffName("SFF1"), renderedServicePath.getRenderedServicePathHop().get(0)); assertHop(1, new SffName("SFF2"), renderedServicePath.getRenderedServicePathHop().get(1)); ServiceFunctionClassifier serviceFunctionClassifierFromDataStore = SfcDataStoreAPI.readTransactionAPI(sclIID, LogicalDatastoreType.CONFIGURATION); assertEquals(SFP_NAME.getValue(), serviceFunctionClassifierFromDataStore.getName()); }
@Test public void createSymmetricRenderedPathTest() throws Exception { initWithTypes(true); ServiceFunctionPath sfp = SfcProviderServicePathAPI.readServiceFunctionPath(pathNames.get(0)); assertTrue("Must be true", createServiceFunctionPath(pathNames.get(0), SFC_NAME, null)); sfp = SfcProviderServicePathAPI.readServiceFunctionPath(pathNames.get(0)); assertNotNull("SFP cant be null", sfp); CreateRenderedPathInputBuilder createRenderedPathInputBuilder = new CreateRenderedPathInputBuilder(); createRenderedPathInputBuilder.setName(RSP_NAME.getValue()) .setParentServiceFunctionPath(pathNames.get(0).getValue()); CreateRenderedPathInput createRenderedPathInput = createRenderedPathInputBuilder.build(); Future<RpcResult<CreateRenderedPathOutput>> futureTask = sfcProviderRpc.createRenderedPath(createRenderedPathInput); RpcResult<CreateRenderedPathOutput> rpcResult = null; try { rpcResult = futureTask.get(); assertTrue("Must be true", rpcResult.isSuccessful()); } catch (InterruptedException | ExecutionException e) { LOG.warn("failed to ....", e); } RenderedServicePath createdRsp = null; if (rpcResult != null) { createdRsp = SfcProviderRenderedPathAPI.readRenderedServicePath(new RspName(rpcResult.getResult().getName())); } assertNotNull("Must not be null", createdRsp); assertNotNull("RSP is symmetric", createdRsp.getSymmetricPathId()); }
@Test public void testMultipleRsp() { List<SfName> firewallSfs = new ArrayList<>(); List<SfName> dpiSfs = new ArrayList<>(); List<SfName> qosSfs = new ArrayList<>(); List<SfName> napt44Sfs = new ArrayList<>(); List<SfName> chainSf1 = new ArrayList<>(); List<SfName> chainSf2 = new ArrayList<>(); List<SfName> chainSf3 = new ArrayList<>(); List<SfName> multipleRspSfNames = new ArrayList<SfName>() { private static final long serialVersionUID = 1L; { add(new SfName("sf1")); add(new SfName("sf2")); add(new SfName("sf3")); add(new SfName("sf4")); add(new SfName("sf5")); add(new SfName("sf6")); add(new SfName("sf7")); add(new SfName("sf8")); } }; Future<RpcResult<CreateRenderedPathOutput>> futureTask1, futureTask2, futureTask3; RpcResult<CreateRenderedPathOutput> rpcResult1 = null, rpcResult2 = null, rpcResult3 = null; RenderedServicePath createdRsp1 = null, createdRsp2 = null, createdRsp3 = null; assertTrue("Must be true", createServiceFunctionForwarder(sffNames.get(0), sffDplNames.get(0))); assertTrue("Must be true", createServiceFunctionForwarder(sffNames.get(1), sffDplNames.get(1))); assertTrue("Must be true", createServiceFunctionForwarder(sffNames.get(2), sffDplNames.get(2))); assertTrue("Must be true", createServiceFunctionForwarder(sffNames.get(3), sffDplNames.get(3))); assertTrue("Must be true", createServiceFunction(multipleRspSfNames.get(0), new SftTypeName("firewall"), sfDplNames.get(0), sffNames.get(0))); assertTrue("Must be true", createServiceFunction(multipleRspSfNames.get(1), new SftTypeName("dpi"), sfDplNames.get(1), sffNames.get(0))); assertTrue("Must be true", createServiceFunction(multipleRspSfNames.get(2), new SftTypeName("qos"), sfDplNames.get(2), sffNames.get(1))); assertTrue("Must be true", createServiceFunction(multipleRspSfNames.get(3), new SftTypeName("napt44"), sfDplNames.get(3), sffNames.get(1))); assertTrue("Must be true", createServiceFunction(multipleRspSfNames.get(4), new SftTypeName("firewall"), sfDplNames.get(4), sffNames.get(2))); assertTrue("Must be true", createServiceFunction(multipleRspSfNames.get(5), new SftTypeName("dpi"), sfDplNames.get(5), sffNames.get(2))); assertTrue("Must be true", createServiceFunction(multipleRspSfNames.get(6), new SftTypeName("qos"), sfDplNames.get(6), sffNames.get(3))); assertTrue("Must be true", createServiceFunction(multipleRspSfNames.get(7), new SftTypeName("firewall"), sfDplNames.get(7), sffNames.get(3))); firewallSfs.add(multipleRspSfNames.get(0)); firewallSfs.add(multipleRspSfNames.get(4)); firewallSfs.add(multipleRspSfNames.get(7)); dpiSfs.add(multipleRspSfNames.get(1)); dpiSfs.add(multipleRspSfNames.get(5)); qosSfs.add(multipleRspSfNames.get(2)); qosSfs.add(multipleRspSfNames.get(6)); napt44Sfs.add(multipleRspSfNames.get(3)); assertTrue("Must be true", createServiceFunctionType(new SftTypeName("firewall"), firewallSfs)); assertTrue("Must be true", createServiceFunctionType(new SftTypeName("dpi"), dpiSfs)); assertTrue("Must be true", createServiceFunctionType(new SftTypeName("qos"), qosSfs)); assertTrue("Must be true", createServiceFunctionType(new SftTypeName("napt44"), napt44Sfs)); assertTrue("Must be true", createServiceFunctionGroup(groupNames.get(0), firewallSfs, new SftTypeName("firewall"))); assertTrue("Must be true", createServiceFunctionGroup(groupNames.get(1), dpiSfs, new SftTypeName("dpi"))); assertTrue("Must be true", createServiceFunctionGroup(groupNames.get(2), qosSfs, new SftTypeName("qos"))); assertTrue("Must be true", createServiceFunctionGroup(groupNames.get(3), qosSfs, new SftTypeName("napt44"))); chainSf1.add(multipleRspSfNames.get(0)); chainSf1.add(multipleRspSfNames.get(1)); chainSf1.add(multipleRspSfNames.get(2)); chainSf1.add(multipleRspSfNames.get(3)); assertTrue("Must be true", createServiceFunctionChain(chainNames.get(0), chainSf1)); assertTrue("Must be true", createServiceFunctionPath(pathNames.get(0), chainNames.get(0), false)); chainSf2.add(multipleRspSfNames.get(4)); chainSf2.add(multipleRspSfNames.get(5)); chainSf2.add(multipleRspSfNames.get(6)); chainSf2.add(multipleRspSfNames.get(7)); assertTrue("Must be true", createServiceFunctionChain(chainNames.get(1), chainSf2)); assertTrue("Must be true", createServiceFunctionPath(pathNames.get(1), chainNames.get(1), false)); for (SfName sfName : multipleRspSfNames) { chainSf3.add(sfName); } assertTrue("Must be true", createServiceFunctionChain(chainNames.get(2), chainSf3)); assertTrue("Must be true", createServiceFunctionPath(pathNames.get(2), chainNames.get(2), true)); futureTask1 = sfcProviderRpc.createRenderedPath(createRenderedPathInput(pathNames.get(0).getValue())); futureTask2 = sfcProviderRpc.createRenderedPath(createRenderedPathInput(pathNames.get(1).getValue())); futureTask3 = sfcProviderRpc.createRenderedPath(createRenderedPathInput(pathNames.get(2).getValue())); try { rpcResult1 = futureTask1.get(); assertTrue("Must be true", rpcResult1.isSuccessful()); rpcResult2 = futureTask2.get(); assertTrue("Must be true", rpcResult2.isSuccessful()); rpcResult3 = futureTask3.get(); assertTrue("Must be true", rpcResult3.isSuccessful()); } catch (InterruptedException | ExecutionException e) { LOG.warn("failed to ....", e); } if (rpcResult1 != null) { createdRsp1 = SfcProviderRenderedPathAPI.readRenderedServicePath(new RspName(rpcResult1.getResult().getName())); } if (rpcResult2 != null) { createdRsp2 = SfcProviderRenderedPathAPI.readRenderedServicePath(new RspName(rpcResult2.getResult().getName())); } if (rpcResult3 != null) { createdRsp3 = SfcProviderRenderedPathAPI.readRenderedServicePath(new RspName(rpcResult3.getResult().getName())); } assertNotNull("Must not be null", createdRsp1); assertNotNull("Must not be null", createdRsp2); assertNotNull("Must not be null", createdRsp3); assertEquals("Must be equal", createdRsp1.getRenderedServicePathHop().size(), 4); assertEquals("Must be equal", createdRsp2.getRenderedServicePathHop().size(), 4); assertEquals("Must be equal", createdRsp3.getRenderedServicePathHop().size(), 8); ServiceFunctionPath serviceFunctionPath1 = SfcProviderServicePathAPI.readServiceFunctionPath(pathNames.get(0)); assertNotNull("Must not be null", serviceFunctionPath1); assertFalse("Must be false", serviceFunctionPath1.isSymmetric()); assertNull("RSP1 is not symmetric", createdRsp1.getSymmetricPathId()); ServiceFunctionPath serviceFunctionPath2 = SfcProviderServicePathAPI.readServiceFunctionPath(pathNames.get(1)); assertNotNull("Must not be null", serviceFunctionPath2); assertFalse("Must be false", serviceFunctionPath2.isSymmetric()); assertNull("RSP2 is not symmetric", createdRsp2.getSymmetricPathId()); ServiceFunctionPath serviceFunctionPath3 = SfcProviderServicePathAPI.readServiceFunctionPath(pathNames.get(2)); assertNotNull("Must not be null", serviceFunctionPath3); assertTrue("Must be true", serviceFunctionPath3.isSymmetric()); assertNotNull("RSP3 is symmetric", createdRsp3.getSymmetricPathId()); }