SfcProviderRenderedPathAPI { protected static RenderedServicePath createRenderedServicePathEntry(ServiceFunctionPath serviceFunctionPath, CreateRenderedPathInput createRenderedPathInput, SfcServiceFunctionSchedulerAPI scheduler) { printTraceStart(LOG); long pathId; int serviceIndex; RenderedServicePath ret = null; ContextHeaderAllocationType1 contextHeaderAllocationType1 = createRenderedPathInput.getContextHeaderAllocationType1(); if (contextHeaderAllocationType1 != null) { Class<? extends DataContainer> contextHeaderAllocationType1ImplementedInterface = contextHeaderAllocationType1.getImplementedInterface(); if (contextHeaderAllocationType1ImplementedInterface.equals(VxlanClassifier.class)) { LOG.debug("ok"); } } ServiceFunctionChain serviceFunctionChain; SfcName serviceFunctionChainName = serviceFunctionPath.getServiceChainName(); serviceFunctionChain = serviceFunctionChainName != null ? SfcProviderServiceChainAPI .readServiceFunctionChain(serviceFunctionChainName) : null; if (serviceFunctionChain == null) { LOG.error("ServiceFunctionChain name for Path {} not provided", serviceFunctionPath.getName()); return null; } RenderedServicePathBuilder renderedServicePathBuilder = new RenderedServicePathBuilder(); serviceIndex = MAX_STARTING_INDEX; List<String> sfgNameList = SfcProviderServiceFunctionGroupAPI.getSfgNameList(serviceFunctionChain); List<SfName> sfNameList = scheduler.scheduleServiceFunctions(serviceFunctionChain, serviceIndex, serviceFunctionPath); if (sfNameList == null && sfgNameList == null) { LOG.warn("createRenderedServicePathEntry scheduler.scheduleServiceFunctions() returned null list"); return null; } List<RenderedServicePathHop> renderedServicePathHopArrayList = createRenderedServicePathHopList(sfNameList, sfgNameList, serviceIndex); if (renderedServicePathHopArrayList == null) { LOG.warn("createRenderedServicePathEntry createRenderedServicePathHopList returned null list"); return null; } if (serviceFunctionPath.getPathId() == null) { pathId = SfcServicePathId.check_and_allocate_pathid(); } else { pathId = SfcServicePathId.check_and_allocate_pathid(serviceFunctionPath.getPathId()); } if (pathId == -1) { LOG.error("{}: Failed to allocate path-id: {}", Thread.currentThread().getStackTrace()[1], pathId); return null; } renderedServicePathBuilder.setRenderedServicePathHop(renderedServicePathHopArrayList); if (createRenderedPathInput.getName() == null || createRenderedPathInput.getName().isEmpty()) { if (serviceFunctionPath.getName() != null) { renderedServicePathBuilder .setName(new RspName(serviceFunctionPath.getName().getValue() + "-Path-" + pathId)); } else { LOG.error("{}: Failed to set RSP Name as it was null and SFP Name was null.", Thread.currentThread().getStackTrace()[1]); return null; } } else { renderedServicePathBuilder.setName(new RspName(createRenderedPathInput.getName())); } renderedServicePathBuilder.setPathId(pathId); renderedServicePathBuilder.setStartingIndex((short) MAX_STARTING_INDEX); renderedServicePathBuilder.setServiceChainName(serviceFunctionChainName); renderedServicePathBuilder.setParentServiceFunctionPath(serviceFunctionPath.getName()); renderedServicePathBuilder.setContextMetadata(serviceFunctionPath.getContextMetadata()); renderedServicePathBuilder.setVariableMetadata(serviceFunctionPath.getVariableMetadata()); if (serviceFunctionPath.getTransportType() == null) { renderedServicePathBuilder.setTransportType(VxlanGpe.class); } else { renderedServicePathBuilder.setTransportType(serviceFunctionPath.getTransportType()); } renderedServicePathBuilder.setSfcEncapsulation( serviceFunctionPath.getSfcEncapsulation() != null ? serviceFunctionPath.getSfcEncapsulation() : renderedServicePathBuilder.getTransportType().equals(VxlanGpe.class) ? Nsh.class : Transport.class); RenderedServicePathKey renderedServicePathKey = new RenderedServicePathKey(renderedServicePathBuilder.getName()); InstanceIdentifier<RenderedServicePath> rspIID; rspIID = InstanceIdentifier.builder(RenderedServicePaths.class) .child(RenderedServicePath.class, renderedServicePathKey) .build(); RenderedServicePath renderedServicePath = renderedServicePathBuilder.build(); if (SfcDataStoreAPI.writeMergeTransactionAPI(rspIID, renderedServicePath, LogicalDatastoreType.OPERATIONAL)) { ret = renderedServicePath; } else { LOG.error("{}: Failed to create Rendered Service Path: {}", Thread.currentThread().getStackTrace()[1], serviceFunctionPath.getName()); } printTraceStop(LOG); return ret; }  static RenderedServicePath createRenderedServicePathAndState(ServiceFunctionPath createdServiceFunctionPath,
            CreateRenderedPathInput createRenderedPathInput, SfcServiceFunctionSchedulerAPI scheduler); static RenderedServicePath createRenderedServicePathAndState(ServiceFunctionPath createdServiceFunctionPath,
            CreateRenderedPathInput createRenderedPathInput); static RenderedServicePath createSymmetricRenderedServicePathAndState(
            RenderedServicePath renderedServicePath); static RenderedServicePath createReverseRenderedServicePathEntry(RenderedServicePath renderedServicePath); static RspName generateReversedPathName(RspName rspName); static RspName getReversedRspName(RspName rspName); static RenderedServicePath readRenderedServicePath(RspName rspName); static boolean deleteRenderedServicePaths(List<RspName> servicePaths); static boolean deleteRenderedServicePathsAndStates(List<RspName> rspNames); static boolean deleteRenderedServicePath(RspName renderedServicePathName); static RenderedServicePathFirstHop readRenderedServicePathFirstHop(RspName rspName); static RenderedServicePathFirstHop readRspFirstHopBySftList(
            Class<? extends ServiceFunctionSchedulerTypeIdentity> serviceFunctionSchedulerType,
            List<SftTypeName> serviceFunctionTypeList); static boolean setSymmetricPathId(RenderedServicePath renderedServicePath, long pathId); static boolean isChainSymmetric(ServiceFunctionPath sfp, RenderedServicePath rsp); static String createRenderedIoamPath(String sysName); static boolean deleteRenderedIoamPath(String renderedIoamPathName);  }
@SuppressWarnings("static-access") @Test public void testCreateRenderedServicePathEntryUnsuccessful() throws Exception { setupSfc(); CreateRenderedPathInputBuilder createRenderedPathInputBuilder = new CreateRenderedPathInputBuilder(); ServiceFunctionPathBuilder serviceFunctionPathBuilder = new ServiceFunctionPathBuilder(); SfcProviderRenderedPathAPI sfcProviderRenderedPathAPI = new SfcProviderRenderedPathAPI(); RenderedServicePath testRenderedServicePath; serviceFunctionPathBuilder.setServiceChainName(null); serviceFunctionPathBuilder = new ServiceFunctionPathBuilder(); SfcServiceFunctionSchedulerAPI testScheduler = new SfcServiceFunctionRandomSchedulerAPI(); serviceFunctionPathBuilder.setServiceChainName(SFC_NAME); testRenderedServicePath = sfcProviderRenderedPathAPI.createRenderedServicePathEntry( serviceFunctionPathBuilder.build(), createRenderedPathInputBuilder.build(), testScheduler); assertNull("Must be null", testRenderedServicePath); }
@SuppressWarnings("static-access") @Test public void testCreateRenderedServicePathEntryUnsuccessful1() throws Exception { setupSfc(); CreateRenderedPathInputBuilder createRenderedPathInputBuilder = new CreateRenderedPathInputBuilder(); ServiceFunctionPathBuilder serviceFunctionPathBuilder = new ServiceFunctionPathBuilder(); SfcProviderRenderedPathAPI sfcProviderRenderedPathAPI = new SfcProviderRenderedPathAPI(); SfcServiceFunctionSchedulerAPI testScheduler = new SfcServiceFunctionRandomSchedulerAPI(); RenderedServicePath testRenderedServicePath; serviceFunctionPathBuilder.setServiceChainName(SFC_NAME); testRenderedServicePath = sfcProviderRenderedPathAPI.createRenderedServicePathEntry( serviceFunctionPathBuilder.build(), createRenderedPathInputBuilder.build(), testScheduler); assertNull("Must be null", testRenderedServicePath); }
@Test public void testCreateRenderedServicePathEntryUnsuccessful2() throws Exception { setupSfc(); CreateRenderedPathInputBuilder createRenderedPathInputBuilder = new CreateRenderedPathInputBuilder(); ServiceFunctionPathBuilder serviceFunctionPathBuilder = new ServiceFunctionPathBuilder(); SfcServiceFunctionSchedulerAPI testScheduler = new SfcServiceFunctionRandomSchedulerAPI(); createRenderedPathInputBuilder.setName(RSP_NAME.getValue()); serviceFunctionPathBuilder.setServiceChainName(SFC_NAME); serviceFunctionPathBuilder.setTransportType(Mpls.class); RenderedServicePath testRenderedServicePath = SfcProviderRenderedPathAPI.createRenderedServicePathEntry( serviceFunctionPathBuilder.build(), createRenderedPathInputBuilder.build(), testScheduler); assertNull("Must be null", testRenderedServicePath); }
@Test public void testCreateRenderedServicePathEntrySuccessful() throws Exception { init(); CreateRenderedPathInputBuilder createRenderedPathInputBuilder = new CreateRenderedPathInputBuilder(); ServiceFunctionPathBuilder serviceFunctionPathBuilder = new ServiceFunctionPathBuilder(); SfcServiceFunctionSchedulerAPI testScheduler = new SfcServiceFunctionRandomSchedulerAPI(); createRenderedPathInputBuilder.setName(null); serviceFunctionPathBuilder.setServiceChainName(SFC_NAME); serviceFunctionPathBuilder.setTransportType(Mac.class); serviceFunctionPathBuilder.setSfcEncapsulation(Transport.class); serviceFunctionPathBuilder.setContextMetadata("CMD"); serviceFunctionPathBuilder.setVariableMetadata("VMD"); serviceFunctionPathBuilder.setName(SFP_NAME); RenderedServicePath testRenderedServicePath = SfcProviderRenderedPathAPI.createRenderedServicePathEntry( serviceFunctionPathBuilder.build(), createRenderedPathInputBuilder.build(), testScheduler); assertNotNull("Must not be null", testRenderedServicePath); assertEquals("Must be equal", testRenderedServicePath.getServiceChainName(), SFC_NAME); assertEquals("Must be equal", testRenderedServicePath.getTransportType(), Mac.class); assertEquals("Must be equal", testRenderedServicePath.getSfcEncapsulation(), Transport.class); assertEquals("Must be equal", testRenderedServicePath.getContextMetadata(), "CMD"); assertEquals("Must be equal", testRenderedServicePath.getVariableMetadata(), "VMD"); }
@Test public void testCreateRenderedServicePathEntrySuccessfulDefaults() throws Exception { init(); CreateRenderedPathInputBuilder createRenderedPathInputBuilder = new CreateRenderedPathInputBuilder(); ServiceFunctionPathBuilder serviceFunctionPathBuilder = new ServiceFunctionPathBuilder(); SfcServiceFunctionSchedulerAPI testScheduler = new SfcServiceFunctionRandomSchedulerAPI(); RenderedServicePath testRenderedServicePath; createRenderedPathInputBuilder.setName(null); serviceFunctionPathBuilder.setServiceChainName(SFC_NAME); serviceFunctionPathBuilder.setContextMetadata("CMD"); serviceFunctionPathBuilder.setVariableMetadata("VMD"); serviceFunctionPathBuilder.setName(SFP_NAME); testRenderedServicePath = SfcProviderRenderedPathAPI.createRenderedServicePathEntry( serviceFunctionPathBuilder.build(), createRenderedPathInputBuilder.build(), testScheduler); assertNotNull("Must not be null", testRenderedServicePath); assertEquals("Must be equal", testRenderedServicePath.getServiceChainName(), SFC_NAME); assertEquals("Must be equal", testRenderedServicePath.getTransportType(), VxlanGpe.class); assertEquals("Must be equal", testRenderedServicePath.getSfcEncapsulation(), Nsh.class); assertEquals("Must be equal", testRenderedServicePath.getContextMetadata(), "CMD"); assertEquals("Must be equal", testRenderedServicePath.getVariableMetadata(), "VMD"); }