SfcServiceFunctionLoadBalanceSchedulerAPI 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()); Map<Short, SfName> sfpMapping = getSFPHopSfMapping(sfp); short index = 0; for (SfcServiceFunction sfcServiceFunction : sfcServiceFunctionList) { LOG.debug("SfcServiceFunctionLoadBalanceSchedulerAPI 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); 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; } SfcServiceFunctionLoadBalanceSchedulerAPI(); @Override List<SfName> scheduleServiceFunctions(ServiceFunctionChain chain, int serviceIndex,
            ServiceFunctionPath sfp);  }
@Test public void testServiceFunctionLoadBalanceScheduler() { SfcProviderServiceChainAPI.putServiceFunctionChain(sfChain); ServiceFunctionChain sfc2 = SfcProviderServiceChainAPI.readServiceFunctionChain(sfChain.getName()); assertNotNull("Must be not null", sfc2); assertEquals("Must be equal", sfc2.getSfcServiceFunction(), sfChain.getSfcServiceFunction()); ServiceFunctionType serviceFunctionType; List<SftServiceFunctionName> sftServiceFunctionNameList; serviceFunctionType = SfcProviderServiceTypeAPI.readServiceFunctionType(new SftTypeName("firewall")); sftServiceFunctionNameList = serviceFunctionType.getSftServiceFunctionName(); assertNotNull("Must be not null", sftServiceFunctionNameList); assertEquals("Must be equal", sftServiceFunctionNameList.size(), 3); serviceFunctionType = SfcProviderServiceTypeAPI.readServiceFunctionType(new SftTypeName("dpi")); sftServiceFunctionNameList = serviceFunctionType.getSftServiceFunctionName(); assertNotNull("Must be not null", sftServiceFunctionNameList); assertEquals("Must be equal", sftServiceFunctionNameList.size(), 3); serviceFunctionType = SfcProviderServiceTypeAPI.readServiceFunctionType(new SftTypeName("napt44")); sftServiceFunctionNameList = serviceFunctionType.getSftServiceFunctionName(); assertNotNull("Must be not null", sftServiceFunctionNameList); assertEquals("Must be equal", sftServiceFunctionNameList.size(), 3); int serviceIndex = 255; serviceFunctionType = SfcProviderServiceTypeAPI.readServiceFunctionType(new SftTypeName("firewall")); List<SftServiceFunctionName> sftFirewallList = serviceFunctionType.getSftServiceFunctionName(); serviceFunctionType = SfcProviderServiceTypeAPI.readServiceFunctionType(new SftTypeName("dpi")); List<SftServiceFunctionName> sftDpiList = serviceFunctionType.getSftServiceFunctionName(); serviceFunctionType = SfcProviderServiceTypeAPI.readServiceFunctionType(new SftTypeName("napt44")); List<SftServiceFunctionName> sftNapt44List = serviceFunctionType.getSftServiceFunctionName(); List<SfName> serviceFunctionNameArrayList = scheduler.scheduleServiceFunctions(sfChain, serviceIndex, sfPath); assertNotNull("Must be not null", serviceFunctionNameArrayList); for (int i = 0; i < 3; i++) { SfName sfFWName = new SfName(sftFirewallList.get(i).getName()); java.lang.Long cPUUtilization = SfcProviderServiceFunctionAPI.readServiceFunctionDescriptionMonitor(sfFWName) .getMonitoringInfo() .getResourceUtilization() .getCPUUtilization(); assertNotNull(cPUUtilization); } for (int i = 0; i < 3; i++) { SfName sfDPIName = new SfName(sftDpiList.get(i).getName()); java.lang.Long cPUUtilization = SfcProviderServiceFunctionAPI.readServiceFunctionDescriptionMonitor(sfDPIName) .getMonitoringInfo() .getResourceUtilization() .getCPUUtilization(); assertNotNull(cPUUtilization); } for (int i = 0; i < 3; i++) { SfName sfNATName = new SfName(sftNapt44List.get(i).getName()); java.lang.Long cPUUtilization = SfcProviderServiceFunctionAPI.readServiceFunctionDescriptionMonitor(sfNATName) .getMonitoringInfo() .getResourceUtilization() .getCPUUtilization(); assertNotNull(cPUUtilization); } assertEquals("Must be equal", serviceFunctionNameArrayList.get(0).getValue(), "simple_fw_100"); assertEquals("Must be equal", serviceFunctionNameArrayList.get(1).getValue(), "simple_dpi_120"); assertEquals("Must be equal", serviceFunctionNameArrayList.get(2).getValue(), "simple_nat_100"); }
@Test public void loadBalance__OverrideSingleHop() { Long pathId = 1L; ServiceFunctionPathBuilder serviceFunctionPathBuilder = new ServiceFunctionPathBuilder(); serviceFunctionPathBuilder.setKey(new ServiceFunctionPathKey(new SfpName("key"))); serviceFunctionPathBuilder.setPathId(pathId); serviceFunctionPathBuilder.setServiceChainName(sfChain.getName()); List<ServicePathHop> sphs = new ArrayList<>(); sphs.add(buildSFHop(new SffName("SFF2"), new SfName("hop-dpi"), (short) 1)); serviceFunctionPathBuilder.setServicePathHop(sphs); ServiceFunctionPath sfp = serviceFunctionPathBuilder.build(); List<SfName> serviceFunctionNameArrayList = scheduler.scheduleServiceFunctions(sfChain, 1, sfp); assertEquals("simple_fw_100", serviceFunctionNameArrayList.get(0).getValue()); assertEquals("hop-dpi", serviceFunctionNameArrayList.get(1).getValue()); }
@Test public void loadBalance__OverrideAllHops() { Long pathId = 1L; ServiceFunctionPathBuilder serviceFunctionPathBuilder = new ServiceFunctionPathBuilder(); serviceFunctionPathBuilder.setKey(new ServiceFunctionPathKey(new SfpName("key"))); serviceFunctionPathBuilder.setPathId(pathId); serviceFunctionPathBuilder.setServiceChainName(sfChain.getName()); List<ServicePathHop> sphs = new ArrayList<>(); sphs.add(buildSFHop(new SffName("SFF2"), new SfName("hop-dpi-0"), (short) 0)); sphs.add(buildSFHop(new SffName("SFF2"), new SfName("hop-dpi-1"), (short) 1)); serviceFunctionPathBuilder.setServicePathHop(sphs); ServiceFunctionPath sfp = serviceFunctionPathBuilder.build(); List<SfName> serviceFunctionNameArrayList = scheduler.scheduleServiceFunctions(sfChain, 1, sfp); assertEquals("hop-dpi-0", serviceFunctionNameArrayList.get(0).getValue()); assertEquals("hop-dpi-1", serviceFunctionNameArrayList.get(1).getValue()); }