import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.opendaylight.yang.gen.v1.urn.intel.params.xml.ns.yang.sfc.sfst.rev150312.ServiceFunctionSchedulerTypeIdentity;
import org.opendaylight.yang.gen.v1.urn.intel.params.xml.ns.yang.sfc.sfst.rev150312.Random;
import org.opendaylight.yang.gen.v1.urn.intel.params.xml.ns.yang.sfc.sfst.rev150312.RoundRobin;
import org.opendaylight.yang.gen.v1.urn.intel.params.xml.ns.yang.sfc.sfst.rev150312.LoadBalance;
private static final int MAX_STARTING_INDEX = 255;
private static AtomicInteger numCreatedPath = new AtomicInteger(0);
private static final OpendaylightSfc ODL_SFC = OpendaylightSfc.getOpendaylightSfcObj();
+ private static SfcServiceFunctionSchedulerAPI defaultScheduler;
+
static final Comparator<SfcServiceFunction> SF_ORDER =
new Comparator<SfcServiceFunction>() {
public int compare(SfcServiceFunction e1, SfcServiceFunction e2) {
}
};
- private SfcServiceFunctionSchedulerAPI scheduler;
-
- private void initServiceFunctionScheduler()
- {
- java.lang.Class<? extends org.opendaylight.yang.gen.v1.urn.intel.params.xml.ns.yang.sfc.sfst.rev150312.ServiceFunctionSchedulerTypeIdentity> serviceFunctionSchedulerType;
-
- try {
- serviceFunctionSchedulerType = SfcProviderScheduleTypeAPI
- .readEnabledServiceFunctionScheduleTypeEntryExecutor().getType();
- } catch (Exception e) {
- serviceFunctionSchedulerType = Random.class;
- }
+ private static SfcServiceFunctionSchedulerAPI getServiceFunctionScheduler(Class<? extends ServiceFunctionSchedulerTypeIdentity> serviceFunctionSchedulerType) {
+ SfcServiceFunctionSchedulerAPI scheduler;
if (serviceFunctionSchedulerType == RoundRobin.class) {
scheduler = new SfcServiceFunctionRoundRobinSchedulerAPI();
} else {
scheduler = new SfcServiceFunctionRandomSchedulerAPI();
}
+ return scheduler;
+ }
+
+ private void initDefaultServiceFunctionScheduler()
+ {
+ java.lang.Class<? extends ServiceFunctionSchedulerTypeIdentity> serviceFunctionSchedulerType;
+
+ try {
+ serviceFunctionSchedulerType = SfcProviderScheduleTypeAPI
+ .readEnabledServiceFunctionScheduleTypeEntryExecutor().getType();
+ } catch (Exception e) {
+ serviceFunctionSchedulerType = Random.class;
+ }
+ defaultScheduler = getServiceFunctionScheduler(serviceFunctionSchedulerType);
LOG.info("Selected SF Schdedule Type: {}", serviceFunctionSchedulerType);
}
SfcProviderRenderedPathAPI(Object[] params, String m) {
super(params, m);
- initServiceFunctionScheduler();
+ initDefaultServiceFunctionScheduler();
}
SfcProviderRenderedPathAPI(Object[] params, Class[] paramsTypes, String m) {
super(params, paramsTypes, m);
- initServiceFunctionScheduler();
+ initDefaultServiceFunctionScheduler();
}
this.createRenderedServicePathEntry(serviceFunctionPath);
}*/
- public static RenderedServicePath createRenderedServicePathEntryExecutor(ServiceFunctionPath serviceFunctionPath,
- CreateRenderedPathInput createRenderedPathInput) {
+ public static RenderedServicePath createRenderedServicePathEntryExecutor(ServiceFunctionPath serviceFunctionPath, CreateRenderedPathInput createRenderedPathInput, SfcServiceFunctionSchedulerAPI scheduler) {
RenderedServicePath ret = null;
- Object[] servicePathObj = {serviceFunctionPath, createRenderedPathInput};
- Class[] servicePathClass = {ServiceFunctionPath.class, CreateRenderedPathInput.class};
+ Object[] servicePathObj = {serviceFunctionPath, createRenderedPathInput, scheduler};
+ Class[] servicePathClass = {ServiceFunctionPath.class, CreateRenderedPathInput.class, SfcServiceFunctionSchedulerAPI.class};
SfcProviderRenderedPathAPI sfcProviderRenderedPathAPI = SfcProviderRenderedPathAPI
.getCreateRenderedServicePathEntryAPI(servicePathObj, servicePathClass);
Future futureCreateRSP = ODL_SFC.getExecutor().submit(sfcProviderRenderedPathAPI);
/**
* Creates a RSP and all the associated operational state based on the
- * given service function path
+ * given service function path and scheduler
*
* <p>
* @param createdServiceFunctionPath Service Function Path
- * @return Created RSP or null
+ * @param createRenderedPathInput CreateRenderedPathInput object
+ * @param scheduler SfcServiceFunctionSchedulerAPI object
+ * @return RenderedServicePath Created RSP or null
*/
- public static RenderedServicePath createRenderedServicePathAndState(ServiceFunctionPath createdServiceFunctionPath,
- CreateRenderedPathInput createRenderedPathInput) {
-
- RenderedServicePath renderedServicePath;
+ public static RenderedServicePath createRenderedServicePathAndState(ServiceFunctionPath createdServiceFunctionPath, CreateRenderedPathInput createRenderedPathInput, SfcServiceFunctionSchedulerAPI scheduler) {
+ RenderedServicePath renderedServicePath = null;
boolean rspSuccessful = false;
boolean addPathToSffStateSuccessful = false;
boolean addPathToSfStateSuccessful = false;
boolean addPathtoSfpStateSuccessful = false;
+ if (scheduler == null) {//Fall back to defaultScheduler
+ scheduler = defaultScheduler;
+ }
+
// Create RSP
if ((renderedServicePath = SfcProviderRenderedPathAPI
- .createRenderedServicePathEntryExecutor(createdServiceFunctionPath, createRenderedPathInput)) != null) {
+ .createRenderedServicePathEntryExecutor(createdServiceFunctionPath, createRenderedPathInput, scheduler)) != null) {
rspSuccessful = true;
} else {
LOG.error("Could not create RSP. System state inconsistent. Deleting and add SFP {} back",
createdServiceFunctionPath.getName());
}
+
// Add Path name to SFF operational state
if (rspSuccessful && SfcProviderServiceForwarderAPI
.addPathToServiceForwarderStateExecutor(renderedServicePath)) {
addPathToSffStateSuccessful = true;
} else {
- SfcProviderRenderedPathAPI.deleteRenderedServicePathExecutor(renderedServicePath.getName());
+ if (renderedServicePath != null) {
+ SfcProviderRenderedPathAPI.deleteRenderedServicePathExecutor(renderedServicePath.getName());
+ }
}
// Add Path to SF operational state
} else {
SfcProviderServiceForwarderAPI
.deletePathFromServiceForwarderStateExecutor(createdServiceFunctionPath);
- SfcProviderRenderedPathAPI.deleteRenderedServicePathExecutor(renderedServicePath.getName());
-
+ if (renderedServicePath != null) {
+ SfcProviderRenderedPathAPI.deleteRenderedServicePathExecutor(renderedServicePath.getName());
+ }
}
+
// Add RSP to SFP operational state
if (addPathToSfStateSuccessful &&
SfcProviderServicePathAPI.addRenderedPathToServicePathStateExecutor
SfcProviderServiceFunctionAPI.deleteServicePathFromServiceFunctionStateExecutor(createdServiceFunctionPath.getName());
SfcProviderServiceForwarderAPI
.deletePathFromServiceForwarderStateExecutor(createdServiceFunctionPath);
- SfcProviderRenderedPathAPI.deleteRenderedServicePathExecutor(renderedServicePath.getName());
+ if (renderedServicePath != null) {
+ SfcProviderRenderedPathAPI.deleteRenderedServicePathExecutor(renderedServicePath.getName());
+ }
+ }
+ if (renderedServicePath == null) {
+ LOG.error("Failed to create RSP for SFP {}", createdServiceFunctionPath.getName());
+ } else {
+ LOG.info("Create RSP {} for SFP {} successfully", renderedServicePath.getName(), createdServiceFunctionPath.getName());
}
return renderedServicePath;
}
+ /**
+ * Creates a RSP and all the associated operational state based on the
+ * given service function path
+ *
+ * <p>
+ * @param createdServiceFunctionPath Service Function Path
+ * @param createRenderedPathInput CreateRenderedPathInput object
+ * @return RenderedServicePath Created RSP or null
+ */
+ public static RenderedServicePath createRenderedServicePathAndState(ServiceFunctionPath createdServiceFunctionPath, CreateRenderedPathInput createRenderedPathInput) {
+ return createRenderedServicePathAndState(createdServiceFunctionPath, createRenderedPathInput, defaultScheduler);
+ }
+
/**
* Create a Symmetric Path and all the associated operational state based on the
* given rendered service path
/**
* Create a Rendered Path and all the associated operational state based on the
- * given rendered service path
+ * given rendered service path and scheduler
*
* <p>
* @param serviceFunctionPath RSP Object
- * @return Nothing.
+ * @param createRenderedPathInput CreateRenderedPathInput object
+ * @param scheduler SfcServiceFunctionSchedulerAPI object
+ * @return RenderedServicePath
*/
- protected RenderedServicePath createRenderedServicePathEntry (ServiceFunctionPath serviceFunctionPath,
- CreateRenderedPathInput createRenderedPathInput) {
+ protected RenderedServicePath createRenderedServicePathEntry (ServiceFunctionPath serviceFunctionPath, CreateRenderedPathInput createRenderedPathInput, SfcServiceFunctionSchedulerAPI scheduler) {
printTraceStart(LOG);
RenderedServicePath renderedServicePath =
renderedServicePathBuilder.build();
+
if (SfcDataStoreAPI.writeMergeTransactionAPI(rspIID, renderedServicePath, LogicalDatastoreType.OPERATIONAL)) {
ret = renderedServicePath;
} else {
return ret;
}
+ /**
+ * Create a Rendered Path and all the associated operational state based on the
+ * given rendered service path
+ *
+ * <p>
+ * @param serviceFunctionPath RSP Object
+ * @param createRenderedPathInput CreateRenderedPathInput object
+ * @return RenderedServicePath
+ */
+ protected RenderedServicePath createRenderedServicePathEntry (ServiceFunctionPath serviceFunctionPath, CreateRenderedPathInput createRenderedPathInput) {
+ return createRenderedServicePathEntry(serviceFunctionPath, createRenderedPathInput, defaultScheduler);
+ }
+
private List<String> getSfgNameList(ServiceFunctionChain serviceFunctionChain) {
List<String> ret = new ArrayList<String>();
List<SfcServiceFunction> sfcServiceFunction = serviceFunctionChain.getSfcServiceFunction();
* @param serviceFunctionTypeList ServiceFunctionTypeIdentity list
* @return RenderedServicePathFirstHop.
*/
- public static RenderedServicePathFirstHop readRspFirstHopBySftList(List<Class<? extends ServiceFunctionTypeIdentity>> serviceFunctionTypeList) {
+ public static RenderedServicePathFirstHop readRspFirstHopBySftList(Class<? extends ServiceFunctionSchedulerTypeIdentity> serviceFunctionSchedulerType, List<Class<? extends ServiceFunctionTypeIdentity>> serviceFunctionTypeList) {
int i;
String serviceTypeName;
Class serviceFunctionType = null;
ServiceFunctionChain serviceFunctionChain = null;
boolean ret = false;
RenderedServicePathFirstHop firstHop = null;
+ SfcServiceFunctionSchedulerAPI scheduler;
printTraceStart(LOG);
+ scheduler = getServiceFunctionScheduler(serviceFunctionSchedulerType);
/* Build sfcName, pathName and ServiceFunction list */
for (i = 0; i < serviceFunctionTypeList.size(); i++) {
createRenderedPathInputBuilder.setSymmetric(serviceFunctionPath.isSymmetric());
renderedServicePath = SfcProviderRenderedPathAPI.createRenderedServicePathAndState(serviceFunctionPath,
- createRenderedPathInputBuilder.build());
+ createRenderedPathInputBuilder.build(), scheduler);
if (renderedServicePath == null) {
LOG.error("Failed to create RenderedServicePath for ServiceFunctionPath: {}", pathName);
return null;
private static final String SFC_NAME = "unittest-chain-1";
private static final String SFP_NAME = "unittest-sfp-1";
private static final Logger LOG = LoggerFactory.getLogger(SfcProviderServiceChainAPITest.class);
+ private static final String[] sfNames = {"unittest-fw-1", "unittest-dpi-1", "unittest-napt-1", "unittest-http-header-enrichment-1", "unittest-qos-1"};
private String[] SFF_NAMES = {"SFF1", "SFF2", "SFF3", "SFF4", "SFF5"};
private String[][] TO_SFF_NAMES =
{{"SFF2", "SFF5"}, {"SFF3", "SFF1"}, {"SFF4", "SFF2"}, {"SFF5", "SFF3"}, {"SFF1", "SFF4"}};
private String[] SFF_LOCATOR_IP =
{"196.168.66.101", "196.168.66.102", "196.168.66.103", "196.168.66.104", "196.168.66.105"};
+ private List<ServiceFunction> sfList = new ArrayList<>();
+ private static final String rspName = "unittest-rsp-1";
private DataBroker dataBroker;
private ExecutorService executor;
private OpendaylightSfc opendaylightSfc = new OpendaylightSfc();
private ServiceFunctionPathBuilder serviceFunctionPathBuilder;
private RenderedServicePath testRenderedServicePath;
private SfcProviderRenderedPathAPI sfcProviderRenderedPathAPI;
- private List<ServiceFunction> sfList = new ArrayList<>();
private Object[] params;
@Before
Thread.sleep(1000); // Wait for real delete
// Create Service Functions
- final String[] sfNames = {"unittest-fw-1", "unittest-dpi-1", "unittest-napt-1", "unittest-http-header-enrichment-1", "unittest-qos-1"};
final IpAddress[] ipMgmtAddress = new IpAddress[sfNames.length];
final IpAddress[] locatorIpAddress = new IpAddress[sfNames.length];
SfDataPlaneLocator[] sfDataPlaneLocator = new SfDataPlaneLocator[sfNames.length];
SfcProviderServicePathAPI.readServiceFunctionPathExecutor(SFP_NAME);
assertNotNull("Must be not null", serviceFunctionPath);
+ /* Can't create RSP if we don't do these cleanups, don't know why */
+ SfcProviderServiceFunctionAPI.deleteServicePathFromServiceFunctionStateExecutor(SFP_NAME);
+ SfcProviderServiceForwarderAPI.deletePathFromServiceForwarderStateExecutor(serviceFunctionPath);
+ SfcProviderServicePathAPI.deleteServicePathStateExecutor(SFP_NAME);
+ SfcProviderRenderedPathAPI.deleteRenderedServicePathExecutor(rspName);
+ for (int i = 0; i < SFF_NAMES.length; i++) {
+ SfcProviderServiceForwarderAPI.deleteServiceFunctionForwarderStateExecutor(SFF_NAMES[i]);
+ }
+ for (int i = 0; i < sfNames.length; i++) {
+ SfcProviderServiceFunctionAPI.deleteServiceFunctionStateExecutor(sfNames[i]);
+ }
+
/* Create RenderedServicePath and reverse RenderedServicePath */
RenderedServicePath renderedServicePath = null;
RenderedServicePath revRenderedServicePath = null;
CreateRenderedPathInputBuilder createRenderedPathInputBuilder = new CreateRenderedPathInputBuilder();
+ createRenderedPathInputBuilder.setName(rspName);
createRenderedPathInputBuilder.setSymmetric(serviceFunctionPath.isSymmetric());
try {
renderedServicePath = SfcProviderRenderedPathAPI.createRenderedServicePathAndState(serviceFunctionPath, createRenderedPathInputBuilder.build());
- } catch (NullPointerException e) {
+ } catch (Exception e) {
e.printStackTrace();
}
assertNotNull("Must be not null", renderedServicePath);
assertEquals("sftList size should be 5", sftList.size(), 5);
RenderedServicePathFirstHop firstHop = null;
try {
- firstHop = SfcProviderRenderedPathAPI.readRspFirstHopBySftList(sftList);
+ firstHop = SfcProviderRenderedPathAPI.readRspFirstHopBySftList(null, sftList);
} catch (NullPointerException e) {
e.printStackTrace();
}
@Test
public void testCreateRenderedServicePathHopList() throws ExecutionException, InterruptedException {
- final String[] sfNames = {"unittest-fw-1", "unittest-dpi-1", "unittest-napt-1"};
- List<String> sfNameList = Arrays.asList(sfNames);
+ final String[] tmpSfNames = {"unittest-fw-1", "unittest-dpi-1", "unittest-napt-1"};
+ List<String> sfNameList = Arrays.asList(tmpSfNames);
final int startingIndex = 255;
Object[] parameters = {};
SfcProviderServiceFunctionAPI.deleteServiceFunctionStateExecutor("unittest-fw-1");
SfcProviderServicePathAPI.deleteServicePathStateExecutor(SFP_NAME);
- final String rspName = "unittest-rsp";
-
ServiceFunctionPath serviceFunctionPath =
SfcProviderServicePathAPI.readServiceFunctionPathExecutor(SFP_NAME);
assertNotNull("Must be not null", serviceFunctionPath);