SfcServiceFunctionLoadPathAwareSchedulerAPI extends SfcServiceFunctionSchedulerAPI { @Override public List<SfName> scheduleServiceFunctions(ServiceFunctionChain chain, int serviceIndex, ServiceFunctionPath sfp) { SfName preSfName = null; SfName sfName; List<SfName> sfNameList = new ArrayList<>(); List<SfcServiceFunction> sfcServiceFunctionList = new ArrayList<>(); sfcServiceFunctionList.addAll(chain.getSfcServiceFunction()); SfcProviderGraph sfcProviderGraph = new SfcProviderGraph(); short index = 0; Map<Short, SfName> sfpMapping = getSFPHopSfMapping(sfp); buildTopologyGraph(sfcProviderGraph); for (SfcServiceFunction sfcServiceFunction : sfcServiceFunctionList) { LOG.debug("ServiceFunction name: {}", sfcServiceFunction.getName()); SfName hopSf = sfpMapping.get(index++); if (hopSf != null) { sfNameList.add(hopSf); continue; } ServiceFunctionType serviceFunctionType = SfcProviderServiceTypeAPI.readServiceFunctionType(sfcServiceFunction.getType()); if (serviceFunctionType != null) { List<SftServiceFunctionName> sftServiceFunctionNameList = serviceFunctionType.getSftServiceFunctionName(); if (!sftServiceFunctionNameList.isEmpty()) { sfName = getServiceFunctionByType(serviceFunctionType, preSfName, sfcProviderGraph); if (sfName != null) { sfNameList.add(sfName); preSfName = sfName; LOG.debug("Next Service Function: {}", sfName); } else { LOG.error("Couldn't find a reachable SF for ServiceFunctionType: {}", sfcServiceFunction.getType()); return null; } } else { LOG.debug("No {} Service Function instance", sfcServiceFunction.getName()); return null; } } else { LOG.debug("No {} Service Function type", sfcServiceFunction.getName()); return null; } } return sfNameList; } SfcServiceFunctionLoadPathAwareSchedulerAPI(); @Override List<SfName> scheduleServiceFunctions(ServiceFunctionChain chain, int serviceIndex,
            ServiceFunctionPath sfp);  }
@Test public void testSfcServiceFunctionLoadPathAwareScheduler() { int maxTries; for (ServiceFunction serviceFunction : sfList) { maxTries = 10; ServiceFunction sf2 = null; while (maxTries > 0) { sf2 = SfcProviderServiceFunctionAPI.readServiceFunction(serviceFunction.getName()); maxTries--; if (sf2 != null) { break; } } LOG.debug("SfcServiceFunctionLoadPathAwareSchedulerAPITest: getRead ServiceFunction {} {} times: {}", serviceFunction.getName(), 10 - maxTries, sf2 != null ? "Successful" : "Failed"); assertNotNull("Must be not null", sf2); assertEquals("Must be equal", sf2.getName(), serviceFunction.getName()); assertEquals("Must be equal", sf2.getType(), serviceFunction.getType()); } SfcProviderServiceChainAPI.putServiceFunctionChain(sfChain); ServiceFunctionChain sfc2 = SfcProviderServiceChainAPI.readServiceFunctionChain(sfChain.getName()); assertNotNull("Must be not null", sfc2); assertNotNull("Must be not null", sfChain.getSfcServiceFunction()); assertEquals("Must be equal", sfc2.getSfcServiceFunction(), sfChain.getSfcServiceFunction()); for (SfcServiceFunction sfcServiceFunction : sfChain.getSfcServiceFunction()) { LOG.debug("sfcServiceFunction.name = {}", sfcServiceFunction.getName()); ServiceFunctionType serviceFunctionType = SfcProviderServiceTypeAPI.readServiceFunctionType(sfcServiceFunction.getType()); assertNotNull("Must be not null", serviceFunctionType); } 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(), 4); serviceFunctionType = SfcProviderServiceTypeAPI.readServiceFunctionType(new SftTypeName("dpi")); sftServiceFunctionNameList = serviceFunctionType.getSftServiceFunctionName(); assertNotNull("Must be not null", sftServiceFunctionNameList); assertEquals("Must be equal", sftServiceFunctionNameList.size(), 4); serviceFunctionType = SfcProviderServiceTypeAPI.readServiceFunctionType(new SftTypeName("napt44")); sftServiceFunctionNameList = serviceFunctionType.getSftServiceFunctionName(); assertNotNull("Must be not null", sftServiceFunctionNameList); assertEquals("Must be equal", sftServiceFunctionNameList.size(), 2); 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 < 4; i++) { SfName sfFWName = new SfName(sftFirewallList.get(i).getName()); java.lang.Long cPUUtilization = SfcProviderServiceFunctionAPI.readServiceFunctionDescriptionMonitor(sfFWName) .getMonitoringInfo() .getResourceUtilization() .getCPUUtilization(); assertNotNull(cPUUtilization); LOG.debug("Reading CPU of ServiceFunction {} : {}",sfFWName, cPUUtilization); } for (int i = 0; i < 4; i++) { SfName sfDPIName = new SfName(sftDpiList.get(i).getName()); java.lang.Long cPUUtilization = SfcProviderServiceFunctionAPI.readServiceFunctionDescriptionMonitor(sfDPIName) .getMonitoringInfo() .getResourceUtilization() .getCPUUtilization(); assertNotNull(cPUUtilization); LOG.debug("Reading CPU of ServiceFunction {} : {}",sfDPIName, cPUUtilization); } for (int i = 0; i < 2; i++) { SfName sfNATName = new SfName(sftNapt44List.get(i).getName()); java.lang.Long cPUUtilization = SfcProviderServiceFunctionAPI.readServiceFunctionDescriptionMonitor(sfNATName) .getMonitoringInfo() .getResourceUtilization() .getCPUUtilization(); assertNotNull(cPUUtilization); LOG.debug("Reading CPU of ServiceFunction {} : {}", sfNATName, cPUUtilization); } ServiceFunction sfHop0 = SfcProviderServiceFunctionAPI.readServiceFunction(serviceFunctionNameArrayList.get(0)); ServiceFunction sfHop1 = SfcProviderServiceFunctionAPI.readServiceFunction(serviceFunctionNameArrayList.get(1)); ServiceFunction sfHop2 = SfcProviderServiceFunctionAPI.readServiceFunction(serviceFunctionNameArrayList.get(2)); assertNotNull("Must be not null", sfHop0); assertEquals("Must be equal", sfHop0.getName().getValue(), "fw_2"); assertNotNull("Must be not null", sfHop1); assertEquals("Must be equal", sfHop1.getName().getValue(), "dpi_1"); assertNotNull("Must be not null", sfHop2); assertEquals("Must be equal", sfHop2.getName().getValue(), "nat_3"); LOG.debug("The rendered service path for chain : {} => {} => {}", sfHop0.getName(), sfHop1.getName(), sfHop2.getName()); }
@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); LOG.debug("{} => {}", serviceFunctionNameArrayList.get(0).getValue(),serviceFunctionNameArrayList.get(1).getValue()); assertEquals("fw_2", 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); LOG.debug("{} => {}", serviceFunctionNameArrayList.get(0).getValue(),serviceFunctionNameArrayList.get(1).getValue()); assertEquals("hop-dpi-0", serviceFunctionNameArrayList.get(0).getValue()); assertEquals("hop-dpi-1", serviceFunctionNameArrayList.get(1).getValue()); }