SfcServiceFunctionRandomSchedulerAPI extends SfcServiceFunctionSchedulerAPI { @Override public List<SfName> scheduleServiceFunctions(ServiceFunctionChain chain, int serviceIndex, ServiceFunctionPath sfp) { List<SfName> sfNameList = new ArrayList<>(); List<SfcServiceFunction> sfcServiceFunctionList = new ArrayList<>(); sfcServiceFunctionList.addAll(chain.getSfcServiceFunction()); short index = 0; Map<Short, SfName> sfpMapping = getSFPHopSfMapping(sfp); for (SfcServiceFunction sfcServiceFunction : sfcServiceFunctionList) { LOG.info("ServiceFunction name: {}", sfcServiceFunction.getName()); SfName hopSf = sfpMapping.get(index++); if (hopSf != null) { sfNameList.add(hopSf); continue; } ServiceFunctionType serviceFunctionType; serviceFunctionType = SfcProviderServiceTypeAPI.readServiceFunctionType(sfcServiceFunction.getType()); if (serviceFunctionType != null) { List<SftServiceFunctionName> sftServiceFunctionNameList = serviceFunctionType.getSftServiceFunctionName(); if (!sftServiceFunctionNameList.isEmpty()) { SfName sfName = getServiceFunctionByType(serviceFunctionType); LOG.info("sfName {} for serviceFunctionType {}", sfName, serviceFunctionType.getType()); sfNameList.add(sfName); } else { LOG.error("Could not create path because there are no configured SFs of type: {}", sfcServiceFunction.getType()); return null; } } else { LOG.error("Could not create path because there are no configured SFs of type: {}", sfcServiceFunction.getType()); return null; } } return sfNameList; } SfcServiceFunctionRandomSchedulerAPI(); @Override List<SfName> scheduleServiceFunctions(ServiceFunctionChain chain, int serviceIndex,
            ServiceFunctionPath sfp);  }
@Test public void testServiceFunctionRandomScheduler() { List<SfName> result = scheduler.scheduleServiceFunctions(createServiceFunctionChain(), 255, createServiceFunctionPath()); List<SfName> serviceFunctions = new ArrayList<>(); serviceFunctions.add(SF_NAME1); serviceFunctions.add(SF_NAME2); serviceFunctions.add(SF_NAME3); assertNotNull("Must be not null", result); assertTrue("Must be equal", result.containsAll(serviceFunctions)); }
@Test public void testServiceFunctionRandomScheduler1() { ServiceFunctionPathBuilder serviceFunctionPathBuilder = new ServiceFunctionPathBuilder(); List<SfName> result = scheduler.scheduleServiceFunctions(createServiceFunctionChain(), 255, serviceFunctionPathBuilder.build()); assertNull("Must be null", result); boolean transactionSuccessful = writeTypes(true); assertTrue("Must be true", transactionSuccessful); result = scheduler.scheduleServiceFunctions(createServiceFunctionChain(), 255, serviceFunctionPathBuilder.build()); assertTrue("Must be true", result.contains(null)); transactionSuccessful = writeServiceFunction("Firewall", true); assertTrue("Must be true", transactionSuccessful); transactionSuccessful = writeServiceFunction("Dpi", true); assertTrue("Must be true", transactionSuccessful); transactionSuccessful = writeServiceFunction("Qos", true); assertTrue("Must be true", transactionSuccessful); result = scheduler.scheduleServiceFunctions(createServiceFunctionChain(), 255, serviceFunctionPathBuilder.build()); List<SfName> serviceFunctionTypes = new ArrayList<>(); serviceFunctionTypes.add(new SfName(SF_NAME_BASE + "Firewall")); serviceFunctionTypes.add(new SfName(SF_NAME_BASE + "Dpi")); serviceFunctionTypes.add(new SfName(SF_NAME_BASE + "Qos")); assertNotNull("Must not be null", result); assertTrue("Must be true", result.containsAll(serviceFunctionTypes)); transactionSuccessful = writeServiceFunction("Firewall", false); assertTrue("Must be true", transactionSuccessful); transactionSuccessful = writeServiceFunction("Dpi", false); assertTrue("Must be true", transactionSuccessful); transactionSuccessful = writeServiceFunction("Qos", false); assertTrue("Must be true", transactionSuccessful); transactionSuccessful = writeTypes(false); assertTrue("Must be true", transactionSuccessful); }