submitFuture.checkedGet();
ret = true;
} catch (TransactionCommitFailedException e) {
- LOG.error("Transaction failed. Message: {}", e.getMessage());
+ LOG.error("deleteTransactionAPI: Transaction failed. Message: {}", e.getMessage());
ret = false;
}
return ret;
submitFuture.checkedGet();
ret = true;
} catch (TransactionCommitFailedException e) {
- LOG.error("Transaction failed. Message: {}", e.getMessage());
+ LOG.error("writeMergeTransactionAPI: Transaction failed. Message: {}", e.getMessage());
ret = false;
}
return ret;
submitFuture.checkedGet();
ret = true;
} catch (TransactionCommitFailedException e) {
- LOG.error("Transaction failed. Message: {}", e.getMessage());
+ LOG.error("writePutTransactionAPI: Transaction failed. Message: {}", e.getMessage());
ret = false;
}
return ret;
private SfcServiceFunctionSchedulerAPI scheduler;
- private void initServiceFuntionScheduler()
+ private void initServiceFunctionScheduler()
{
java.lang.Class<? extends org.opendaylight.yang.gen.v1.urn.intel.params.xml.ns.yang.sfc.sfst.rev150312.ServiceFunctionSchedulerTypeIdentity> serviceFunctionSchedulerType;
SfcProviderRenderedPathAPI(Object[] params, String m) {
super(params, m);
- initServiceFuntionScheduler();
+ initServiceFunctionScheduler();
}
SfcProviderRenderedPathAPI(Object[] params, Class[] paramsTypes, String m) {
super(params, paramsTypes, m);
- initServiceFuntionScheduler();
+ initServiceFunctionScheduler();
}
serviceIndex = MAX_STARTING_INDEX;
List<String> sfgNameList = getSfgNameList(serviceFunctionChain);
- List<String> sfNameList = scheduler.scheduleServiceFuntions(serviceFunctionChain, serviceIndex);
+ List<String> sfNameList = scheduler.scheduleServiceFunctions(serviceFunctionChain, serviceIndex);
if(sfNameList == null && sfgNameList == null) {
- LOG.warn("createRenderedServicePathEntry scheduler.scheduleServiceFuntions() returned null list");
+ LOG.warn("createRenderedServicePathEntry scheduler.scheduleServiceFunctions() returned null list");
return null;
}
List<RenderedServicePathHop> renderedServicePathHopArrayList = createRenderedServicePathHopList(sfNameList, sfgNameList, serviceIndex);
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sft.rev140701.service.function.types.service.function.type.SftServiceFunctionName;
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sf.rev140701.service.functions.ServiceFunction;
import org.opendaylight.yang.gen.v1.urn.intel.params.xml.ns.yang.sfc.sfst.rev150312.LoadBalance;
+import org.opendaylight.yang.gen.v1.urn.intel.params.xml.ns.sf.desc.mon.rev141201.service.functions.state.service.function.state.SfcSfDescMon;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
}
private String getServiceFunctionByType(ServiceFunctionType serviceFunctionType) {
+ boolean ret = false;
List<SftServiceFunctionName> sftServiceFunctionNameList = serviceFunctionType.getSftServiceFunctionName();
- String sftServiceFunctionName = sftServiceFunctionNameList.get(0).getName();
+ String sfName = null;
+ String sftServiceFunctionName = null;
+ java.lang.Long preCPUUtilization = java.lang.Long.MAX_VALUE;
- ServiceFunction serviceFunction = SfcProviderServiceFunctionAPI.readServiceFunctionExecutor(sftServiceFunctionName);
- if (!SfcProviderServiceFunctionAPI.putServiceFunctionMonitorExecutor(serviceFunction)){
- LOG.error("Put monitor information to Data Store failed! serviceFunction: {}", serviceFunction.getName());
- }
+ for (SftServiceFunctionName curSftServiceFunctionName : sftServiceFunctionNameList){
+ sfName = curSftServiceFunctionName.getName();
- if (SfcProviderServiceFunctionAPI.readServiceFunctionDescriptionMonitorExecutor(sftServiceFunctionName) != null){
- java.lang.Long preCPUUtilization = SfcProviderServiceFunctionAPI.readServiceFunctionDescriptionMonitorExecutor(sftServiceFunctionName)
- .getMonitoringInfo()
- .getResourceUtilization()
- .getCPUUtilization();
-
- for (SftServiceFunctionName curSftServiceFunctionName : sftServiceFunctionNameList){
- java.lang.Long curCPUUtilization = SfcProviderServiceFunctionAPI.readServiceFunctionDescriptionMonitorExecutor(curSftServiceFunctionName.getName())
- .getMonitoringInfo()
- .getResourceUtilization()
- .getCPUUtilization();
-
- if (preCPUUtilization > curCPUUtilization){
- preCPUUtilization = curCPUUtilization;
- sftServiceFunctionName = curSftServiceFunctionName.getName();
- }
+ /* Check next one if curSftServiceFunctionName doesn't exist */
+ ServiceFunction serviceFunction = SfcProviderServiceFunctionAPI.readServiceFunctionExecutor(sfName);
+ if (serviceFunction == null) {
+ LOG.error("ServiceFunction {} doesn't exist", sfName);
+ continue;
+ }
+
+ /* Update ServiceFunctionMonitor information */
+ ret = SfcProviderServiceFunctionAPI.putServiceFunctionMonitorExecutor(serviceFunction);
+ if (ret == false) {
+ LOG.error("Put monitor information to Data Store failed! serviceFunction: {}", sfName);
+ }
+
+ /* Read ServiceFunctionMonitor information */
+ SfcSfDescMon sfcSfDescMon = SfcProviderServiceFunctionAPI.readServiceFunctionDescriptionMonitorExecutor(sfName);
+ if (sfcSfDescMon == null) {
+ sftServiceFunctionName = sfName;
+ LOG.error("Read monitor information from Data Store failed! serviceFunction: {}", sfName);
+ // Use sfName if no sfcSfDescMon is available
+ break;
+ }
+
+ java.lang.Long curCPUUtilization = sfcSfDescMon.getMonitoringInfo().getResourceUtilization().getCPUUtilization();
+
+ if (preCPUUtilization > curCPUUtilization){
+ preCPUUtilization = curCPUUtilization;
+ sftServiceFunctionName = sfName;
}
}
+
+ if (sftServiceFunctionName == null) {
+ LOG.error("Failed to get one available ServiceFunction for {}", serviceFunctionType.getType().getSimpleName());
+ }
+
return sftServiceFunctionName;
}
- public List<String> scheduleServiceFuntions(ServiceFunctionChain chain, int serviceIndex) {
+ public List<String> scheduleServiceFunctions(ServiceFunctionChain chain, int serviceIndex) {
List<String> sfNameList = new ArrayList<>();
List<SfcServiceFunction> sfcServiceFunctionList = new ArrayList<>();
sfcServiceFunctionList.addAll(chain.getSfcServiceFunction());
package org.opendaylight.sfc.provider.api;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sf.rev140701.service.functions.ServiceFunction;
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfc.rev140701.service.function.chain.grouping.ServiceFunctionChain;
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfc.rev140701.service.function.chain.grouping.service.function.chain.SfcServiceFunction;
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sft.rev140701.service.function.types.ServiceFunctionType;
private String getServiceFunctionByType(ServiceFunctionType serviceFunctionType) {
List<SftServiceFunctionName> sftServiceFunctionNameList = serviceFunctionType.getSftServiceFunctionName();
+ int maxTries = sftServiceFunctionNameList.size();
Random rad = new Random();
+ ServiceFunction serviceFunction = null;
+ String serviceFunctionName = null;
+ int start = rad.nextInt(sftServiceFunctionNameList.size());
- return sftServiceFunctionNameList.get(rad.nextInt(sftServiceFunctionNameList.size())).getName();
+ while (maxTries > 0) {
+ serviceFunctionName = sftServiceFunctionNameList.get(start).getName();
+ serviceFunction = SfcProviderServiceFunctionAPI.readServiceFunctionExecutor(serviceFunctionName);
+ if (serviceFunction != null) {
+ break;
+ } else {
+ LOG.debug("ServiceFunction {} doesn't exist", serviceFunctionName);
+ maxTries--;
+ serviceFunctionName = null;
+ start = (start + 1) % sftServiceFunctionNameList.size();
+ }
+ }
+ if (serviceFunctionName == null) {
+ LOG.error("Could not find an existing ServiceFunction for {}", serviceFunctionType.getType().getSimpleName());
+ }
+ return serviceFunctionName;
}
- public List<String> scheduleServiceFuntions(ServiceFunctionChain chain, int serviceIndex) {
+ public List<String> scheduleServiceFunctions(ServiceFunctionChain chain, int serviceIndex) {
List<String> sfNameList = new ArrayList<>();
List<SfcServiceFunction> sfcServiceFunctionList = new ArrayList<>();
sfcServiceFunctionList.addAll(chain.getSfcServiceFunction());
return sftServiceFunctionName.getName();
}
- public List<String> scheduleServiceFuntions(ServiceFunctionChain chain, int serviceIndex) {
+ public List<String> scheduleServiceFunctions(ServiceFunctionChain chain, int serviceIndex) {
List<String> sfNameList = new ArrayList<>();
List<SfcServiceFunction> sfcServiceFunctionList = new ArrayList<>();
sfcServiceFunctionList.addAll(chain.getSfcServiceFunction());
this.sfcServiceFunctionSchedulerType = schedulerType;
}
- abstract public List<String> scheduleServiceFuntions(ServiceFunctionChain chain, int serviceIndex);
+ abstract public List<String> scheduleServiceFunctions(ServiceFunctionChain chain, int serviceIndex);
}
private String getServiceFunctionByType(ServiceFunctionType serviceFunctionType, String preSfName, SfcProviderGraph sfcProviderGraph) {
String sfcProviderTopologyNodeName = null;
List<SftServiceFunctionName> sftServiceFunctionNameList = serviceFunctionType.getSftServiceFunctionName();
+ int maxTries = sftServiceFunctionNameList.size();
/* Return null if sftServiceFunctionNameList is empty */
if (sftServiceFunctionNameList.size() == 0) {
if (preSfName == null) {
/* Randomly find one instance of serviceFunctionType */
Random rad = new Random();
- sfcProviderTopologyNodeName = sftServiceFunctionNameList.get(rad.nextInt(sftServiceFunctionNameList.size())).getName();
+ int start = rad.nextInt(sftServiceFunctionNameList.size());
+ SfcProviderTopologyNode firstHopNode = null;
+ while (maxTries > 0) {
+ sfcProviderTopologyNodeName = sftServiceFunctionNameList.get(start).getName();
+ firstHopNode = sfcProviderGraph.getNode(sfcProviderTopologyNodeName);
+ if (firstHopNode != null) {
+ break;
+ } else {
+ LOG.debug("ServiceFunction {} doesn't exist", sfcProviderTopologyNodeName);
+ sfcProviderTopologyNodeName = null;
+ start = (start + 1) % sftServiceFunctionNameList.size();
+ maxTries--;
+ }
+ }
LOG.debug("The first ServiceFunction name: {}", sfcProviderTopologyNodeName);
return sfcProviderTopologyNodeName; //The first hop
}
sfcProviderTopologyNodeName = null;
for (SftServiceFunctionName sftServiceFunctionName : sftServiceFunctionNameList) {
String curSfName = sftServiceFunctionName.getName();
+ SfcProviderTopologyNode curSfcProviderTopologyNode = sfcProviderGraph.getNode(curSfName);
+ if (curSfcProviderTopologyNode == null) {
+ // curSfName doesn't exist in sfcProviderGraph, so skip it
+ continue;
+ }
List<SfcProviderTopologyNode> sfcProviderTopologyNodeList = sfcProviderGraph.getShortestPath(preSfName, curSfName);
length = sfcProviderTopologyNodeList.size();
if (length <= 1) {
* <p>
* @param chain Service Function Chain to render
* @param serviceIndex Not used currently
- * @return List<String> Service Funtion name list in the shortest path
+ * @return List<String> Service Function name list in the shortest path
*/
- public List<String> scheduleServiceFuntions(ServiceFunctionChain chain, int serviceIndex) {
+ public List<String> scheduleServiceFunctions(ServiceFunctionChain chain, int serviceIndex) {
String preSfName = null;
String sfName = null;
List<String> sfNameList = new ArrayList<>();
preSfName = sfName;
LOG.debug("Next Service Function: {}", sfName);
} else {
- LOG.error("Couldn't find a reachable SF for ServiceFuntionType: {}", sfcServiceFunction.getType());
+ LOG.error("Couldn't find a reachable SF for ServiceFunctionType: {}", sfcServiceFunction.getType());
return null;
}
} else {
executor.submit(SfcProviderServiceTypeAPI.getDeleteAll(new Object[]{}, new Class[]{}));
executor.submit(SfcProviderServiceChainAPI.getDeleteAll(new Object[]{}, new Class[]{}));
executor.submit(SfcProviderServicePathAPI.getDeleteAll(new Object[]{}, new Class[]{}));
+ 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"};
sfsBuilder.setServiceFunction(sfList);
executor.submit(SfcProviderServiceFunctionAPI.getPutAll(new Object[]{sfsBuilder.build()}, new Class[]{ServiceFunctions.class})).get();
+ Thread.sleep(1000); // Wait they are really created
// Create ServiceFunctionTypeEntry for all ServiceFunctions
for (ServiceFunction serviceFunction : sfList) {
ServiceFunctionForwarder sff = sffBuilder.build();
executor.submit(SfcProviderServiceForwarderAPI.getPut(new Object[]{sff}, new Class[]{ServiceFunctionForwarder.class})).get();
}
+ Thread.sleep(1000); // Wait they are really created
}
@After
CreateRenderedPathInputBuilder createRenderedPathInputBuilder = new CreateRenderedPathInputBuilder();
createRenderedPathInputBuilder.setSymmetric(serviceFunctionPath.isSymmetric());
- renderedServicePath = SfcProviderRenderedPathAPI.createRenderedServicePathAndState(serviceFunctionPath, createRenderedPathInputBuilder.build());
+ try {
+ renderedServicePath = SfcProviderRenderedPathAPI.createRenderedServicePathAndState(serviceFunctionPath, createRenderedPathInputBuilder.build());
+ } catch (NullPointerException e) {
+ e.printStackTrace();
+ }
assertNotNull("Must be not null", renderedServicePath);
- revRenderedServicePath = SfcProviderRenderedPathAPI.createSymmetricRenderedServicePathAndState(renderedServicePath);
+ try {
+ revRenderedServicePath = SfcProviderRenderedPathAPI.createSymmetricRenderedServicePathAndState(renderedServicePath);
+ } catch (NullPointerException e) {
+ e.printStackTrace();
+ }
assertNotNull("Must be not null", revRenderedServicePath);
RenderedServicePathFirstHop firstHop;
sftList.add(HttpHeaderEnrichment.class);
sftList.add(Qos.class);
assertEquals("sftList size should be 5", sftList.size(), 5);
- RenderedServicePathFirstHop firstHop = SfcProviderRenderedPathAPI.readRspFirstHopBySftList(sftList);
+ RenderedServicePathFirstHop firstHop = null;
+ try {
+ firstHop = SfcProviderRenderedPathAPI.readRspFirstHopBySftList(sftList);
+ } catch (NullPointerException e) {
+ e.printStackTrace();
+ }
assertNotNull("Must be not null", firstHop);
LOG.debug("First hop IP: {}, port: {}", firstHop.getIp().toString(), firstHop.getPort());
assertEquals("Must be equal", firstHop.getIp(), new IpAddress(new Ipv4Address(SFF_LOCATOR_IP[0])));
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
DataBroker dataBroker;
ExecutorService executor;
OpendaylightSfc opendaylightSfc = new OpendaylightSfc();
+ private static final Logger LOG = LoggerFactory.getLogger(SfcProviderServiceChainAPITest.class);
List<SfDataPlaneLocator> sfDPLList = new ArrayList<>();
List<ServiceFunction> sfList = new ArrayList<>();
opendaylightSfc.setDataProvider(dataBroker);
executor = opendaylightSfc.getExecutor();
+ /* Delete all the content in SFC data store before unit test */
+ int maxTries = 10;
+ ServiceFunctionType serviceFunctionType;
+ List<SftServiceFunctionName> sftServiceFunctionNameList;
+ boolean emptyFlag = true;
+ while (maxTries > 0) {
+ emptyFlag = true;
+ executor.submit(SfcProviderServicePathAPI.getDeleteAll(new Object[]{}, new Class[]{}));
+ executor.submit(SfcProviderServiceChainAPI.getDeleteAll(new Object[]{}, new Class[]{}));
+ executor.submit(SfcProviderServiceTypeAPI.getDeleteAll(new Object[]{}, new Class[]{}));
+ executor.submit(SfcProviderServiceFunctionAPI.getDeleteAll(new Object[]{}, new Class[]{}));
+ executor.submit(SfcProviderServiceForwarderAPI.getDeleteAll(new Object[]{}, new Class[]{}));
+ Thread.sleep(1000); //Wait for real delete
+
+ serviceFunctionType = SfcProviderServiceTypeAPI.readServiceFunctionTypeExecutor(Firewall.class);
+ if (serviceFunctionType != null) {
+ sftServiceFunctionNameList = serviceFunctionType.getSftServiceFunctionName();
+ if (sftServiceFunctionNameList.size() != 0) {
+ emptyFlag = false;
+ }
+ }
+
+ serviceFunctionType = SfcProviderServiceTypeAPI.readServiceFunctionTypeExecutor(Dpi.class);
+ if (serviceFunctionType != null) {
+ sftServiceFunctionNameList = serviceFunctionType.getSftServiceFunctionName();
+ if (sftServiceFunctionNameList.size() != 0) {
+ emptyFlag = false;
+ }
+ }
+
+ serviceFunctionType = SfcProviderServiceTypeAPI.readServiceFunctionTypeExecutor(Napt44.class);
+ if (serviceFunctionType != null) {
+ sftServiceFunctionNameList = serviceFunctionType.getSftServiceFunctionName();
+ if (sftServiceFunctionNameList.size() != 0) {
+ emptyFlag = false;
+ }
+ }
+
+ maxTries--;
+ if (emptyFlag == true) {
+ break;
+ }
+ }
+ LOG.debug("Empty SFC data store {} times: {}", 10 - maxTries, emptyFlag ? "Successful" : "Failed");
+
String sfcName = "loadbalance-unittest-chain-1";
List<SfcServiceFunction> sfcServiceFunctionList = new ArrayList<>();
sfcServiceFunctionList.add(new SfcServiceFunctionBuilder()
sfsBuilder.setServiceFunction(sfList);
executor.submit(SfcProviderServiceFunctionAPI.getPutAll
(new Object[]{sfsBuilder.build()}, new Class[]{ServiceFunctions.class})).get();
+ //Wait a while in order to ensure they are really created
+ Thread.sleep(1000);
+
+ for (ServiceFunction serviceFunction: sfList) {
+ SfcProviderServiceTypeAPI.createServiceFunctionTypeEntryExecutor(serviceFunction);
+ }
+
+ /* Ensure all the ServiceFunctions in sfList are indeed created */
+ for (ServiceFunction serviceFunction : sfList) {
+ maxTries = 10;
+ ServiceFunction sf2 = null;
+ while (maxTries > 0) {
+ Object[] parameters2 = {serviceFunction.getName()};
+ Class[] parameterTypes2 = {String.class};
+ Object result = executor.submit(SfcProviderServiceFunctionAPI
+ .getRead(parameters2, parameterTypes2)).get();
+ sf2 = (ServiceFunction) result;
+ maxTries--;
+ if (sf2 != null) {
+ break;
+ }
+ Thread.sleep(1000);
+ }
+ LOG.debug("SfcServiceFunctionLoadBalanceSchedulerAPITest: getRead ServiceFunction {} {} times: {}", serviceFunction.getName(), 10 - maxTries, (sf2 == null) ? "Failed" : "Successful");
+ }
+
// set CPUUtilization for SF
String sfNameFW = "simple_fw_";
for (int i=100; i<130; i=i+10){
public void after() {
executor.submit(SfcProviderServicePathAPI.getDeleteAll(new Object[]{}, new Class[]{}));
executor.submit(SfcProviderServiceChainAPI.getDeleteAll(new Object[]{}, new Class[]{}));
+ executor.submit(SfcProviderServiceTypeAPI.getDeleteAll(new Object[]{}, new Class[]{}));
executor.submit(SfcProviderServiceFunctionAPI.getDeleteAll(new Object[]{}, new Class[]{}));
}
@Test
public void testServiceFunctionLoadBalanceScheduler() throws ExecutionException, InterruptedException {
-
- dataBroker = getDataBroker();
- opendaylightSfc.setDataProvider(dataBroker);
- executor = opendaylightSfc.getExecutor();
-
- for (ServiceFunction serviceFuntion : sfList) {
- Object[] parameters2 = {serviceFuntion.getName()};
- Class[] parameterTypes2 = {String.class};
- Object result = executor.submit(SfcProviderServiceFunctionAPI
- .getRead(parameters2, parameterTypes2)).get();
- ServiceFunction sf2 = (ServiceFunction) result;
-
- assertNotNull("Must be not null", sf2);
- assertEquals("Must be equal", sf2.getName(), serviceFuntion.getName());
- assertEquals("Must be equal", sf2.getType(), serviceFuntion.getType());
- }
-
Object[] sfcParameters = {sfChain};
Class[] sfcParameterTypes = {ServiceFunctionChain.class};
executor.submit(SfcProviderServiceChainAPI
assertNotNull("Must be not null", sfc2);
assertEquals("Must be equal", sfc2.getSfcServiceFunction(), sfChain.getSfcServiceFunction());
- for (ServiceFunction serviceFunction: sfList) {
- SfcProviderServiceTypeAPI.createServiceFunctionTypeEntryExecutor(serviceFunction);
- }
-
ServiceFunctionType serviceFunctionType;
List<SftServiceFunctionName> sftServiceFunctionNameList;
List<SftServiceFunctionName> sftNapt44List = serviceFunctionType.getSftServiceFunctionName();
SfcServiceFunctionSchedulerAPI scheduler = new SfcServiceFunctionLoadBalanceSchedulerAPI();
- List<String> serviceFunctionNameArrayList = scheduler.scheduleServiceFuntions(sfChain, serviceIndex);
+ List<String> serviceFunctionNameArrayList = scheduler.scheduleServiceFunctions(sfChain, serviceIndex);
assertNotNull("Must be not null", serviceFunctionNameArrayList);
for (int i=0; i<3; i++){
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
-public class SfcServiceFuntionSchedulerAPITest extends AbstractDataBrokerTest {
+public class SfcServiceFunctionSchedulerAPITest extends AbstractDataBrokerTest {
DataBroker dataBroker;
ExecutorService executor;
OpendaylightSfc opendaylightSfc = new OpendaylightSfc();
+ private static final Logger LOG = LoggerFactory.getLogger(SfcServiceFunctionSchedulerAPITest.class);
List<SfDataPlaneLocator> sfDPLList = new ArrayList<>();
List<ServiceFunction> sfList = new ArrayList<>();
opendaylightSfc.setDataProvider(dataBroker);
executor = opendaylightSfc.getExecutor();
+ /* Delete all the content in SFC data store before unit test */
+ int maxTries = 10;
+ ServiceFunctionType serviceFunctionType;
+ List<SftServiceFunctionName> sftServiceFunctionNameList;
+ boolean emptyFlag = true;
+ while (maxTries > 0) {
+ emptyFlag = true;
+ executor.submit(SfcProviderServicePathAPI.getDeleteAll(new Object[]{}, new Class[]{}));
+ executor.submit(SfcProviderServiceChainAPI.getDeleteAll(new Object[]{}, new Class[]{}));
+ executor.submit(SfcProviderServiceTypeAPI.getDeleteAll(new Object[]{}, new Class[]{}));
+ executor.submit(SfcProviderServiceFunctionAPI.getDeleteAll(new Object[]{}, new Class[]{}));
+ executor.submit(SfcProviderServiceForwarderAPI.getDeleteAll(new Object[]{}, new Class[]{}));
+ Thread.sleep(1000); //Wait for real delete
+
+ serviceFunctionType = SfcProviderServiceTypeAPI.readServiceFunctionTypeExecutor(Firewall.class);
+ if (serviceFunctionType != null) {
+ sftServiceFunctionNameList = serviceFunctionType.getSftServiceFunctionName();
+ if (sftServiceFunctionNameList.size() != 0) {
+ emptyFlag = false;
+ }
+ }
+
+ serviceFunctionType = SfcProviderServiceTypeAPI.readServiceFunctionTypeExecutor(Dpi.class);
+ if (serviceFunctionType != null) {
+ sftServiceFunctionNameList = serviceFunctionType.getSftServiceFunctionName();
+ if (sftServiceFunctionNameList.size() != 0) {
+ emptyFlag = false;
+ }
+ }
+
+ serviceFunctionType = SfcProviderServiceTypeAPI.readServiceFunctionTypeExecutor(Napt44.class);
+ if (serviceFunctionType != null) {
+ sftServiceFunctionNameList = serviceFunctionType.getSftServiceFunctionName();
+ if (sftServiceFunctionNameList.size() != 0) {
+ emptyFlag = false;
+ }
+ }
+
+ maxTries--;
+ if (emptyFlag == true) {
+ break;
+ }
+ }
+ LOG.debug("Empty SFC data store {} times: {}", 10 - maxTries, emptyFlag ? "Successful" : "Failed");
String sfcName = "unittest-sched-chain-1";
List<SfcServiceFunction> sfcServiceFunctionList = new ArrayList<>();
sfcServiceFunctionList.add(new SfcServiceFunctionBuilder()
sfList.add(SimpleTestEntityBuilder.buildServiceFunction("simple_nat_120", Napt44.class,
new IpAddress(new Ipv4Address("192.168.120.103")), sfDPLList.get(2), Boolean.FALSE));
+ ServiceFunctionsBuilder sfsBuilder = new ServiceFunctionsBuilder();
+ sfsBuilder.setServiceFunction(sfList);
+ executor.submit(SfcProviderServiceFunctionAPI.getPutAll
+ (new Object[]{sfsBuilder.build()}, new Class[]{ServiceFunctions.class})).get();
+ Thread.sleep(1000); //Wait they are really created
+
+ for (ServiceFunction serviceFunction: sfList) {
+ SfcProviderServiceTypeAPI.createServiceFunctionTypeEntryExecutor(serviceFunction);
+ }
+
+ Object[] sfcParameters = {sfChain};
+ Class[] sfcParameterTypes = {ServiceFunctionChain.class};
+ executor.submit(SfcProviderServiceChainAPI
+ .getPut(sfcParameters, sfcParameterTypes)).get();
+ Thread.sleep(1000); //Wait it is really created
}
@After
@Test
public void testBasicEnvSetup() throws ExecutionException, InterruptedException {
-
- ServiceFunctionsBuilder sfsBuilder = new ServiceFunctionsBuilder();
- sfsBuilder.setServiceFunction(sfList);
- executor.submit(SfcProviderServiceFunctionAPI.getPutAll
- (new Object[]{sfsBuilder.build()}, new Class[]{ServiceFunctions.class})).get();
- for (ServiceFunction serviceFuntion : sfList) {
- Object[] parameters2 = {serviceFuntion.getName()};
- Class[] parameterTypes2 = {String.class};
- Object result = executor.submit(SfcProviderServiceFunctionAPI
+ int maxTries = 10;
+ for (ServiceFunction serviceFunction : sfList) {
+ maxTries = 10;
+ ServiceFunction sf2 = null;
+ while (maxTries > 0) {
+ Object[] parameters2 = {serviceFunction.getName()};
+ Class[] parameterTypes2 = {String.class};
+ Object result = executor.submit(SfcProviderServiceFunctionAPI
.getRead(parameters2, parameterTypes2)).get();
- ServiceFunction sf2 = (ServiceFunction) result;
-
+ sf2 = (ServiceFunction) result;
+ maxTries--;
+ if (sf2 != null) {
+ break;
+ }
+ Thread.sleep(1000);
+ }
+ LOG.debug("SfcServiceFunctionSchedulerAPITest: getRead ServiceFunction {} {} times: {}", serviceFunction.getName(), 10 - maxTries, (sf2 != null) ? "Successful" : "Failed");
assertNotNull("Must be not null", sf2);
- assertEquals("Must be equal", sf2.getName(), serviceFuntion.getName());
- assertEquals("Must be equal", sf2.getType(), serviceFuntion.getType());
+ assertEquals("Must be equal", sf2.getName(), serviceFunction.getName());
+ assertEquals("Must be equal", sf2.getType(), serviceFunction.getType());
}
- Object[] sfcParameters = {sfChain};
- Class[] sfcParameterTypes = {ServiceFunctionChain.class};
- executor.submit(SfcProviderServiceChainAPI
- .getPut(sfcParameters, sfcParameterTypes)).get();
-
Object[] parameters2 = {sfChain.getName()};
Class[] parameterTypes2 = {String.class};
Object result = executor.submit(SfcProviderServiceChainAPI
assertNotNull("Must be not null", sfc2);
assertEquals("Must be equal", sfc2.getSfcServiceFunction(), sfChain.getSfcServiceFunction());
- for (ServiceFunction serviceFunction: sfList) {
- SfcProviderServiceTypeAPI.createServiceFunctionTypeEntryExecutor(serviceFunction);
- }
-
ServiceFunctionType serviceFunctionType;
List<SftServiceFunctionName> sftServiceFunctionNameList;
serviceFunctionType = SfcProviderServiceTypeAPI.readServiceFunctionTypeExecutor(Firewall.class);
sftServiceFunctionNameList = serviceFunctionType.getSftServiceFunctionName();
assertNotNull("Must be not null", sftServiceFunctionNameList);
+ for (SftServiceFunctionName sftServiceFunctionName : sftServiceFunctionNameList) {
+ LOG.debug("sftServiceFunctionName: {}", sftServiceFunctionName.getName());
+ }
assertEquals("Must be equal", sftServiceFunctionNameList.size(), 3);
serviceFunctionType = SfcProviderServiceTypeAPI.readServiceFunctionTypeExecutor(Dpi.class);
@Test
public void testServiceFunctionRandomScheduler() throws ExecutionException, InterruptedException {
-
- ServiceFunctionsBuilder sfsBuilder = new ServiceFunctionsBuilder();
- sfsBuilder.setServiceFunction(sfList);
- executor.submit(SfcProviderServiceFunctionAPI.getPutAll
- (new Object[]{sfsBuilder.build()}, new Class[]{ServiceFunctions.class})).get();
-
- Object[] sfcParameters = {sfChain};
- Class[] sfcParameterTypes = {ServiceFunctionChain.class};
- executor.submit(SfcProviderServiceChainAPI
- .getPut(sfcParameters, sfcParameterTypes)).get();
-
- for (ServiceFunction serviceFunction: sfList) {
- SfcProviderServiceTypeAPI.createServiceFunctionTypeEntryExecutor(serviceFunction);
- }
-
int serviceIndex = 255;
SfcServiceFunctionSchedulerAPI scheduler = new SfcServiceFunctionRandomSchedulerAPI();
List<String> serviceFunctionNameArrayList =
- scheduler.scheduleServiceFuntions(sfChain, serviceIndex);
+ scheduler.scheduleServiceFunctions(sfChain, serviceIndex);
assertNotNull("Must be not null", serviceFunctionNameArrayList);
- ServiceFunction serviceFunction = SfcProviderServiceFunctionAPI
- .readServiceFunctionExecutor(serviceFunctionNameArrayList.get(0));
+ ServiceFunction serviceFunction = SfcProviderServiceFunctionAPI.readServiceFunctionExecutor(serviceFunctionNameArrayList.get(0));
+ assertNotNull("Must be not null", serviceFunction);
assertEquals("Must be equal", serviceFunction.getType(), Firewall.class);
assertNotEquals("Must be not equal", serviceFunction.getType(), Dpi.class);
@Test
public void testServiceFunctionRoundRobinScheduler() throws ExecutionException, InterruptedException {
-
- ServiceFunctionsBuilder sfsBuilder = new ServiceFunctionsBuilder();
- sfsBuilder.setServiceFunction(sfList);
- executor.submit(SfcProviderServiceFunctionAPI.getPutAll
- (new Object[]{sfsBuilder.build()}, new Class[]{ServiceFunctions.class})).get();
-
- Object[] sfcParameters = {sfChain};
- Class[] sfcParameterTypes = {ServiceFunctionChain.class};
- executor.submit(SfcProviderServiceChainAPI
- .getPut(sfcParameters, sfcParameterTypes)).get();
-
- for (ServiceFunction serviceFunction: sfList) {
- SfcProviderServiceTypeAPI.createServiceFunctionTypeEntryExecutor(serviceFunction);
- }
-
int serviceIndex = 255;
SfcServiceFunctionSchedulerAPI scheduler = new SfcServiceFunctionRoundRobinSchedulerAPI();
List<String> serviceFunctionNameArrayList;
List<SftServiceFunctionName> sftNapt44List = serviceFunctionType.getSftServiceFunctionName();
/* First round */
- serviceFunctionNameArrayList = scheduler.scheduleServiceFuntions(sfChain, serviceIndex);
+ serviceFunctionNameArrayList = scheduler.scheduleServiceFunctions(sfChain, serviceIndex);
assertNotNull("Must be not null", serviceFunctionNameArrayList);
assertEquals("Must be equal", serviceFunctionNameArrayList.get(0), sftFirewallList.get(0).getName());
assertEquals("Must be equal", serviceFunctionNameArrayList.get(1), sftDpiList.get(0).getName());
assertEquals("Must be equal", serviceFunctionNameArrayList.get(2), sftNapt44List.get(0).getName());
- serviceFunctionNameArrayList = scheduler.scheduleServiceFuntions(sfChain, serviceIndex);
+ serviceFunctionNameArrayList = scheduler.scheduleServiceFunctions(sfChain, serviceIndex);
assertNotNull("Must be not null", serviceFunctionNameArrayList);
assertEquals("Must be equal", serviceFunctionNameArrayList.get(0), sftFirewallList.get(1).getName());
assertEquals("Must be equal", serviceFunctionNameArrayList.get(1), sftDpiList.get(1).getName());
assertEquals("Must be equal", serviceFunctionNameArrayList.get(2), sftNapt44List.get(1).getName());
- serviceFunctionNameArrayList = scheduler.scheduleServiceFuntions(sfChain, serviceIndex);
+ serviceFunctionNameArrayList = scheduler.scheduleServiceFunctions(sfChain, serviceIndex);
assertNotNull("Must be not null", serviceFunctionNameArrayList);
assertEquals("Must be equal", serviceFunctionNameArrayList.get(0), sftFirewallList.get(2).getName());
assertEquals("Must be equal", serviceFunctionNameArrayList.get(1), sftDpiList.get(2).getName());
assertEquals("Must be equal", serviceFunctionNameArrayList.get(2), sftNapt44List.get(2).getName());
/* Second round */
- serviceFunctionNameArrayList = scheduler.scheduleServiceFuntions(sfChain, serviceIndex);
+ serviceFunctionNameArrayList = scheduler.scheduleServiceFunctions(sfChain, serviceIndex);
assertNotNull("Must be not null", serviceFunctionNameArrayList);
assertEquals("Must be equal", serviceFunctionNameArrayList.get(0), sftFirewallList.get(0).getName());
assertEquals("Must be equal", serviceFunctionNameArrayList.get(1), sftDpiList.get(0).getName());
executor.submit(SfcProviderServiceFunctionAPI.getDeleteAll(new Object[]{}, new Class[]{}));
executor.submit(SfcProviderServiceForwarderAPI.getDeleteAll(new Object[]{}, new Class[]{}));
executor.submit(SfcProviderServiceTypeAPI.getDeleteAll(new Object[]{}, new Class[]{}));
+ Thread.sleep(1000); // Wait for real delete
//build SFs
final String[] LOCATOR_IP_ADDRESS =
sfsBuilder.setServiceFunction(sfList);
executor.submit(SfcProviderServiceFunctionAPI.getPutAll
(new Object[]{sfsBuilder.build()}, new Class[]{ServiceFunctions.class})).get();
+ Thread.sleep(1000); // Wait they are really created
String sfcName = "ShortestPath-unittest-chain-1";
List<SfcServiceFunction> sfcServiceFunctionList = new ArrayList<>();
ServiceFunctionForwarder sff = sffBuilder.build();
executor.submit(SfcProviderServiceForwarderAPI.getPut(new Object[]{sff}, new Class[]{ServiceFunctionForwarder.class})).get();
}
+ Thread.sleep(1000); // Wait they are really created
}
@After
dataBroker = getDataBroker();
opendaylightSfc.setDataProvider(dataBroker);
executor = opendaylightSfc.getExecutor();
+ int maxTries = 10;
/* Must create ServiceFunctionType first */
for (ServiceFunction serviceFunction : sfList) {
}
for (ServiceFunction serviceFunction : sfList) {
- Object[] parameters2 = {serviceFunction.getName()};
- Class[] parameterTypes2 = {String.class};
- Object result = executor.submit(SfcProviderServiceFunctionAPI
+ maxTries = 10;
+ ServiceFunction sf2 = null;
+ while (maxTries > 0) {
+ Object[] parameters2 = {serviceFunction.getName()};
+ Class[] parameterTypes2 = {String.class};
+ Object result = executor.submit(SfcProviderServiceFunctionAPI
.getRead(parameters2, parameterTypes2)).get();
- ServiceFunction sf2 = (ServiceFunction) result;
-
- LOG.debug("read ServiceFunction {}", serviceFunction.getName());
+ sf2 = (ServiceFunction) result;
+ maxTries--;
+ if (sf2 != null) {
+ break;
+ }
+ Thread.sleep(1000);
+ }
+ LOG.debug("SfcServiceFunctionShortestPathSchedulerAPITest: 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());
int serviceIndex = 255;
SfcServiceFunctionShortestPathSchedulerAPI scheduler = new SfcServiceFunctionShortestPathSchedulerAPI();
- List<String> serviceFunctionNameArrayList = scheduler.scheduleServiceFuntions(sfChain, serviceIndex);
+ List<String> serviceFunctionNameArrayList = scheduler.scheduleServiceFunctions(sfChain, serviceIndex);
assertNotNull("Must be not null", serviceFunctionNameArrayList);
Object[] parametersHop = {serviceFunctionNameArrayList.get(0)};