import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
final SfcProviderRpc sfcProviderRpc = new SfcProviderRpc();
- SfcProviderSfpDataListener sfcProviderSfpDataListener = new SfcProviderSfpDataListener();
SfcProviderSnDataListener sfcProviderSnDataListener = new SfcProviderSnDataListener();
final ListenerRegistration<DataChangeListener> snDataChangeListenerRegistration =
dataBrokerService.registerDataChangeListener(LogicalDatastoreType.CONFIGURATION,
OpendaylightSfc.snIID, sfcProviderSnDataListener, DataBroker.DataChangeScope.SUBTREE );
- // ServiceFunctionPath
- //final ListenerRegistration<DataChangeListener> sfpDataChangeListenerRegistration =
- // dataBrokerService.registerDataChangeListener(LogicalDatastoreType.CONFIGURATION,
- // OpendaylightSfc.sfpIID, sfcProviderSfpDataListener, DataBroker.DataChangeScope.SUBTREE );
-
-
//ServiceFunctionForwarder
SfcProviderSffDataListener sfcProviderSffDataListener = new SfcProviderSffDataListener();
final ListenerRegistration<DataChangeListener> sffDataChangeListenerRegistration =
dataBrokerService.registerDataChangeListener( LogicalDatastoreType.CONFIGURATION,
OpendaylightSfc.sfpEntryIID, sfcProviderSfpEntryDataListener, DataBroker.DataChangeScope.BASE );
- // ServiceFunctions
- //SfcProviderSfsDataListener sfcProviderSfsDataListener = new SfcProviderSfsDataListener();
- //final ListenerRegistration<DataChangeListener> sfsDataChangeListenerRegistration =
- // dataBrokerService.registerDataChangeListener( OpendaylightSfc.sfsIID, sfcProviderSfsDataListener);
-
- // ServiceFunctionChains
- //SfcProviderSfcDataListener sfcProviderSfcDataListener = new SfcProviderSfcDataListener();
- //final ListenerRegistration<DataChangeListener> sfcDataChangeListenerRegistration =
- // dataBrokerService.registerDataChangeListener( OpendaylightSfc.sfcIID, sfcProviderSfcDataListener );
-
final BindingAwareBroker.RpcRegistration<ServiceFunctionService> sfRpcRegistration =
getRpcRegistryDependency()
final class AutoCloseableSfc implements AutoCloseable {
@Override
- public void close() throws Exception {
+ public void close() {
sfEntryDataChangeListenerRegistration.close();
- //sfsDataChangeListenerRegistration.close();
sfcEntryDataChangeListenerRegistration.close();
sfpEntryDataChangeListenerRegistration.close();
snDataChangeListenerRegistration.close();
- //sfpDataChangeListenerRegistration.close();
- //sfcDataChangeListenerRegistration.close();
sffDataChangeListenerRegistration.close();
sfRpcRegistration.close();
sfcRpcRegistration.close();
snRpcRegistration.close();
- //runtimeReg.close();
- opendaylightSfc.close();
- LOG.info("SFC provider (instance {}) torn down.", this);
+ try
+ {
+ opendaylightSfc.close();
+ } catch (ExecutionException | InterruptedException e)
+ {
+ LOG.error("\nFailed to close SFC Provider (instance {}) " +
+ "cleanly", this);
+ }
+
+
+ LOG.info("SFC provider (instance {}) torn down", this);
}
}
*/
package org.opendaylight.sfc.provider;
-import com.google.common.util.concurrent.Futures;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.common.api.data.AsyncReadWriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.sal.common.util.Rpcs;
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sf.rev140701.ServiceFunctions;
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.ServiceFunctionChains;
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sft.rev140701.ServiceFunctionTypes;
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sn.rev140701.ServiceNodes;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.common.RpcError;
-import org.opendaylight.yangtools.yang.common.RpcResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.Collections;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-
-//import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
/**
* This the main SFC Provider class. It is instantiated from the
protected DataBroker dataProvider;
private static OpendaylightSfc opendaylightSfcObj;
- private Future<RpcResult<Void>> currentTask;
-
public OpendaylightSfc() {
executor = Executors.newFixedThreadPool(4);
opendaylightSfcObj = this;
}
- private Future<RpcResult<Void>> inProgressError() {
- RpcResult<Void> result = Rpcs.<Void> getRpcResult(false, null, Collections.<RpcError> emptySet());
- return Futures.immediateFuture(result);
- }
-
public void setDataProvider(DataBroker salDataProvider) {
this.dataProvider = salDataProvider;
}
package org.opendaylight.sfc.provider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
*/
abstract public class SfcProviderAbstractRestAPI implements Runnable {
protected static final OpendaylightSfc odlSfc = OpendaylightSfc.getOpendaylightSfcObj();
- protected String methodName = null;
- protected Object[] parameters;
- protected Class[] parameterTypes;
+ private static final Logger LOG = LoggerFactory.getLogger
+ (SfcProviderAbstractRestAPI.class);
+ private String methodName = null;
+ private Object[] parameters;
+
+ public String getMethodName()
+ {
+ return methodName;
+ }
+
+ public void setMethodName(String methodName)
+ {
+ this.methodName = methodName;
+ }
+
+ public Object[] getParameters()
+ {
+ return parameters;
+ }
+
+ public void setParameters(Object[] parameters)
+ {
+ this.parameters = Arrays.copyOf(parameters, parameters.length);
+ }
+
+ public Class[] getParameterTypes()
+ {
+ return parameterTypes;
+ }
+
+ public void setParameterTypes(Class[] parameterTypes)
+ {
+ this.parameterTypes = Arrays.copyOf(parameterTypes, parameterTypes.length);
+ }
+
+ private Class[] parameterTypes;
protected SfcProviderAbstractRestAPI(Object[] params, Class[] paramsTypes, String m) {
- this.methodName = m;
+ setMethodName(m);
this.parameters = new Object[params.length];
this.parameterTypes = new Class[params.length];
- this.parameters = Arrays.copyOf(params, params.length);
- this.parameterTypes = Arrays.copyOf(paramsTypes, paramsTypes.length);
+ setParameters(params);
+ setParameterTypes(paramsTypes);
}
@Override
public void run() {
if (methodName != null) {
Class<?> c = this.getClass();
- Method method = null;
+ Method method;
try {
method = c.getDeclaredMethod(methodName, parameterTypes);
method.invoke(this, parameters);
} catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
- e.printStackTrace();
+ LOG.error("\nFailed to find proper REST method: {}",
+ e.getMessage());
}
}
}
package org.opendaylight.sfc.provider;
+import org.slf4j.Logger;
+
/**
- * This class is used to control unit test coding and debugging
+ * This class is used to for debugging
*
* Example:
*
*/
public final class SfcProviderDebug {
- public static boolean ON = false;
+
+ private SfcProviderDebug()
+ {
+ }
+
+ private static boolean on = false;
+ private static String traceStart = "####### Start: {}";
+ private static String traceStop = "####### Stop: {}";
+
+ public static void setON(boolean on)
+ {
+ SfcProviderDebug.on = on;
+ }
+
+ public static boolean isOn()
+ {
+ return on;
+ }
+
+ public static String getTraceStart()
+ {
+ return traceStart;
+ }
+
+ public static void setTraceStart(String traceStart)
+ {
+ SfcProviderDebug.traceStart = traceStart;
+ }
+
+ public static String getTraceStop()
+ {
+ return traceStop;
+ }
+
+ public static void setTraceStop(String traceStop)
+ {
+ SfcProviderDebug.traceStop = traceStop;
+ }
+
+ public static void printTraceStart(Logger log)
+ {
+ log.debug(traceStart, Thread.currentThread().getStackTrace()[1]);
+ }
+ public static void printTraceStop(Logger log)
+ {
+ log.debug(traceStop, Thread.currentThread().getStackTrace()[1]);
+ }
+
}
\ No newline at end of file
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
+import com.sun.jersey.api.client.UniformInterfaceException;
import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.api.client.config.DefaultClientConfig;
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sff.rev140701.ServiceFunctionForwarders;
public class SfcProviderRestAPI extends SfcProviderAbstractRestAPI {
private static final Logger LOG = LoggerFactory.getLogger(SfcProviderRestAPI.class);
+ private static final String ACCEPT = "application/json";
+ private static final String HTTP_ERROR_MSG = "Failed : HTTP error code : ";
SfcProviderRestAPI (Object[] params, Class[] paramsTypes, String m) {
super(params, paramsTypes, m);
ClientResponse getClientResponse = client
.resource("http://localhost:8080/restconf/config/service-function-forwarder:service-function-forwarders/")
- .accept("application/json")
+ .accept(ACCEPT)
.get(ClientResponse.class);
+ if (getClientResponse.getStatus() != 200) {
+ throw new UniformInterfaceException(HTTP_ERROR_MSG
+ + getClientResponse.getStatus(),
+ getClientResponse);
+ }
String jsonOutput = getClientResponse.getEntity(String.class);
getClientResponse.close();
- ClientResponse putClientRemoteResponse= client
- .resource("http://localhost:5000/paths").type("application/json")
+ ClientResponse putClientRemoteResponse;
+
+ putClientRemoteResponse = client
+ .resource("http://localhost:5000/paths").type(ACCEPT)
.put(ClientResponse.class, jsonOutput);
+
+ if (putClientRemoteResponse.getStatus() != 200) {
+ throw new UniformInterfaceException(HTTP_ERROR_MSG
+ + putClientRemoteResponse.getStatus(),
+ putClientRemoteResponse);
+ }
+
putClientRemoteResponse.close();
ClientResponse putClientLocalResponse= client
- .resource("http://localhost:5000/paths").type("application/json")
+ .resource("http://localhost:5000/paths").type(ACCEPT)
.put(ClientResponse.class, jsonOutput);
+ if (putClientLocalResponse.getStatus() != 200) {
+ throw new UniformInterfaceException(HTTP_ERROR_MSG
+ + putClientLocalResponse.getStatus(),
+ putClientLocalResponse);
+ }
putClientLocalResponse.close();
}
ClientResponse getClientResponse = client
.resource("http://localhost:8080/restconf/config/service-function-path:service-function-paths/")
- .accept("application/json")
+ .accept(ACCEPT)
.get(ClientResponse.class);
+ if (getClientResponse.getStatus() != 200) {
+ throw new UniformInterfaceException(HTTP_ERROR_MSG
+ + getClientResponse.getStatus(),
+ getClientResponse);
+ }
+ /*
String jsonOutput = getClientResponse.getEntity(String.class);
getClientResponse.close();
-
- /*
ClientResponse putClientRemoteResponse= client
.resource("http://31.133.132.41:5000/paths").type("application/json")
.put(ClientResponse.class, jsonOutput);
import com.google.common.base.Optional;
import com.google.common.util.concurrent.Futures;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
+import static org.opendaylight.sfc.provider.SfcProviderDebug.printTraceStart;
+import static org.opendaylight.sfc.provider.SfcProviderDebug.printTraceStop;
+
/**
* This class holds all RPCs methods for SFC Provider.
private static final Logger LOG = LoggerFactory
.getLogger(SfcProviderRpc.class);
private OpendaylightSfc odlSfc = OpendaylightSfc.getOpendaylightSfcObj();
- private SfcProviderRpc sfcRpcObj;
+ private DataBroker dataBroker = odlSfc.getDataProvider();
- /*
- public SfcProviderRpc () {
- this.sfcRpcObj = this;
- }
- */
public static SfcProviderRpc getSfcProviderRpc() {
return new SfcProviderRpc();
}
- private ServiceFunctions buildServiceFunctions(List<ServiceFunction> list) {
-
- ServiceFunctionsBuilder builder = new ServiceFunctionsBuilder();
- builder.setServiceFunction(list);
- return builder.build();
- }
-
@Override
public Future<RpcResult<Void>> putServiceFunction(PutServiceFunctionInput input) {
- LOG.info("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStart(LOG);
LOG.info("\n####### Input: " + input);
- if (odlSfc.dataProvider != null) {
+ if (dataBroker != null) {
// Data PLane Locator
List<SfDataPlaneLocator> sfDataPlaneLocatorList = input.getSfDataPlaneLocator();
.setKey(sfkey).setIpMgmtAddress(input.getIpMgmtAddress())
.setSfDataPlaneLocator(sfDataPlaneLocatorList).build();
- InstanceIdentifier<ServiceFunction> sfEntryIID = InstanceIdentifier.builder(ServiceFunctions.class).
+ InstanceIdentifier<ServiceFunction> sfEntryIID =
+ InstanceIdentifier.builder(ServiceFunctions.class).
child(ServiceFunction.class, sf.getKey()).toInstance();
- WriteTransaction writeTx = odlSfc.dataProvider.newWriteOnlyTransaction();
+ WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction();
writeTx.merge(LogicalDatastoreType.CONFIGURATION,
sfEntryIID, sf);
writeTx.commit();
} else {
LOG.warn("\n####### Data Provider is NULL : {}", Thread.currentThread().getStackTrace()[1]);
}
- LOG.info("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
return Futures.immediateFuture(Rpcs.<Void>getRpcResult(true,
Collections.<RpcError>emptySet()));
}
@Override
public Future<RpcResult<ReadServiceFunctionOutput>> readServiceFunction(ReadServiceFunctionInput input) {
- LOG.info("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStart(LOG);
LOG.info("Input: " + input);
- if (odlSfc.dataProvider != null) {
- String name = input.getName();
+ if (dataBroker != null) {
ServiceFunctionKey sfkey = new ServiceFunctionKey(input.getName());
InstanceIdentifier<ServiceFunction> sfIID;
sfIID = InstanceIdentifier.builder(ServiceFunctions.class).
child(ServiceFunction.class, sfkey).toInstance();
- ReadOnlyTransaction readTx = odlSfc.dataProvider.newReadOnlyTransaction();
+ ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction();
Optional<ServiceFunction> dataObject = null;
try {
dataObject = readTx.read(LogicalDatastoreType.CONFIGURATION, sfIID).get();
} catch (InterruptedException | ExecutionException e) {
- e.printStackTrace();
+ LOG.debug("Failed to readServiceFunction : {}",
+ e.getMessage());
}
if (dataObject instanceof ServiceFunction) {
- LOG.info("readServiceFunction Success: {}", ((ServiceFunction) dataObject).getName());
+ LOG.debug("readServiceFunction Success: {}",
+ ((ServiceFunction) dataObject).getName());
ServiceFunction serviceFunction = (ServiceFunction) dataObject;
ReadServiceFunctionOutput readServiceFunctionOutput = null;
ReadServiceFunctionOutputBuilder outputBuilder = new ReadServiceFunctionOutputBuilder();
.setIpMgmtAddress(serviceFunction.getIpMgmtAddress())
.setType(serviceFunction.getType());
readServiceFunctionOutput = outputBuilder.build();
- LOG.info("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
return Futures.immediateFuture(Rpcs.<ReadServiceFunctionOutput>
getRpcResult(true, readServiceFunctionOutput, Collections.<RpcError>emptySet()));
}
- LOG.info("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
return Futures.immediateFuture(Rpcs.<ReadServiceFunctionOutput>getRpcResult(true, null, Collections.<RpcError>emptySet()));
} else {
- LOG.warn("dataProvider is null");
- LOG.info("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ LOG.warn("\n####### Data Provider is NULL : {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
return Futures.immediateFuture(Rpcs.<ReadServiceFunctionOutput>getRpcResult(true, null, Collections.<RpcError>emptySet()));
}
}
@Override
public Future<RpcResult<Void>> deleteAllServiceFunction() {
- LOG.info("\n########## Start: {}", Thread.currentThread().getStackTrace()[1]);
- if (odlSfc.dataProvider != null) {
-
- WriteTransaction writeTx = odlSfc.dataProvider.newWriteOnlyTransaction();
+ printTraceStart(LOG);
+ if (dataBroker != null) {
+ WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction();
writeTx.delete(LogicalDatastoreType.CONFIGURATION,
OpendaylightSfc.sfsIID);
writeTx.commit();
-
} else {
- LOG.warn("dataProvider is null");
+ LOG.warn("\n####### Data Provider is NULL : {}", Thread.currentThread().getStackTrace()[1]);
}
- LOG.info("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
return Futures.immediateFuture(Rpcs.<Void>getRpcResult(true,
Collections.<RpcError>emptySet()));
}
@Override
public Future<RpcResult<Void>> deleteServiceFunction(DeleteServiceFunctionInput input) {
- LOG.info("\n########## Start: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStart(LOG);
LOG.info("Input: " + input);
- if (odlSfc.dataProvider != null) {
+ if (dataBroker != null) {
- ReadOnlyTransaction readTx = odlSfc.dataProvider.newReadOnlyTransaction();
+ ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction();
Optional<ServiceFunctions> dataObject = null;
try {
dataObject = readTx.read(LogicalDatastoreType.CONFIGURATION, OpendaylightSfc.sfsIID).get();
} catch (InterruptedException | ExecutionException e) {
- e.printStackTrace();
+ LOG.error("Failed to deleteServiceFunction");
+ return Futures.immediateFuture(Rpcs.<Void>getRpcResult(true,
+ Collections.<RpcError>emptySet()));
}
if (dataObject instanceof ServiceFunctions) {
sfIID = InstanceIdentifier.builder(ServiceFunctions.class).
child(ServiceFunction.class, sfkey).toInstance();
- WriteTransaction writeTx = odlSfc.dataProvider.newWriteOnlyTransaction();
+ WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction();
writeTx.delete(LogicalDatastoreType.CONFIGURATION,
sfIID);
writeTx.commit();
}
-
-
-
} else {
- LOG.warn("dataProvider is null");
+ LOG.warn("\n####### Data Provider is NULL : {}", Thread.currentThread().getStackTrace()[1]);
}
- LOG.info("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
return Futures.immediateFuture(Rpcs.<Void>getRpcResult(true,
Collections.<RpcError>emptySet()));
}
@Override
public Future<RpcResult<Void>> putServiceFunctionChains(PutServiceFunctionChainsInput input) {
- LOG.info("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStart(LOG);
ServiceFunctionChainsBuilder builder = new ServiceFunctionChainsBuilder();
builder = builder.setServiceFunctionChain(input.getServiceFunctionChain());
-
ServiceFunctionChains sfcs = builder.build();
- if (odlSfc.dataProvider != null) {
- WriteTransaction writeTx = odlSfc.dataProvider.newWriteOnlyTransaction();
+ if (dataBroker != null) {
+ WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction();
writeTx.merge(LogicalDatastoreType.CONFIGURATION,
OpendaylightSfc.sfcIID, sfcs, true);
writeTx.commit();
-
} else {
- LOG.warn("dataProvider is null");
+ LOG.warn("\n####### Data Provider is NULL : {}", Thread.currentThread().getStackTrace()[1]);
}
return Futures.immediateFuture(Rpcs.<Void>getRpcResult(true,
Collections.<RpcError>emptySet()));
@Override
public Future<RpcResult<Void>> putServiceNode(PutServiceNodeInput input) {
- LOG.info("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStart(LOG);
LOG.info("\n####### Input: " + input);
- if (odlSfc.dataProvider != null) {
+ if (dataBroker != null) {
ServiceNodeKey snKey = new ServiceNodeKey(input.getName());
ServiceNodeBuilder builder = new ServiceNodeBuilder();
ServiceNode sn = builder.setKey(snKey)
InstanceIdentifier<ServiceNode> snEntryIID = InstanceIdentifier.builder(ServiceNodes.class).
child(ServiceNode.class, sn.getKey()).toInstance();
- WriteTransaction writeTx = odlSfc.dataProvider.newWriteOnlyTransaction();
+ WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction();
writeTx.merge(LogicalDatastoreType.CONFIGURATION,
snEntryIID, sn, true);
writeTx.commit();
} else {
LOG.warn("\n####### Data Provider is NULL : {}", Thread.currentThread().getStackTrace()[1]);
}
- LOG.info("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
return Futures.immediateFuture(Rpcs.<Void>getRpcResult(true,
Collections.<RpcError>emptySet()));
}
@Override
public Future<RpcResult<InstantiateServiceFunctionChainOutput>> instantiateServiceFunctionChain(InstantiateServiceFunctionChainInput input) {
- if (odlSfc.dataProvider != null) {
+ if (dataBroker != null) {
ServiceFunctionChain chain = findServiceFunctionChain(input.getName());
if (chain != null) {
List<SfcServiceFunction> sfRefList = chain.getSfcServiceFunction();
- LOG.info("\n********** sfRefList ***********\n" + sfRefList);
+ LOG.debug("\n********** sfRefList ***********\n" + sfRefList);
if (sfRefList != null && sfRefList.size() > 0) {
ServiceFunctionPathBuilder pathBuilder = new ServiceFunctionPathBuilder();
Random rand = new Random(); // temporarily
for (SfcServiceFunction ref : sfRefList) {
List<ServicePathHop> instanceList = findInstancesByType(ref.getType());
- LOG.info("\n********** instanceList ***********\n" + instanceList);
+ LOG.debug("\n********** instanceList ***********\n" +
+ instanceList);
if (instanceList != null && instanceList.size() > 0) {
// select instance
// for now, takes an element randomly
ServiceFunctionPaths paths = buildServiceFunctionPaths(list);
- WriteTransaction writeTx = odlSfc.dataProvider.newWriteOnlyTransaction();
+ WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction();
writeTx.merge(LogicalDatastoreType.CONFIGURATION,
OpendaylightSfc.sfpIID, paths, true);
writeTx.commit();
}
} else {
- LOG.warn("\n####### dataProvider is null");
+ LOG.warn("\n####### Data Provider is NULL : {}", Thread.currentThread().getStackTrace()[1]);
}
return Futures.immediateFuture(Rpcs.<InstantiateServiceFunctionChainOutput>getRpcResult(false,
Collections.<RpcError>emptySet()));
.child(ServiceFunctionChain.class, key)
.toInstance();
- ReadOnlyTransaction readTx = odlSfc.dataProvider.newReadOnlyTransaction();
+ ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction();
Optional<ServiceFunctionChain> dataObject = null;
try {
dataObject = readTx.read(LogicalDatastoreType.CONFIGURATION, iid).get();
+ if (dataObject != null) {
+ return dataObject.get();
+ } else {
+ LOG.error("\nFailed to findServiceFunctionChain");
+ return null;
+ }
} catch (InterruptedException | ExecutionException e) {
- e.printStackTrace();
- }
-
- if (dataObject.get() instanceof ServiceFunctionChain) {
- return dataObject.get();
- } else {
- throw new IllegalStateException("Wrong dataObject instance (expected ServiceFunctionChain).");
- }
-
- }
-
- // TODO this is duplicated in SFCSftMapper (and used only there, not here; better to DRY
- private ServiceFunction findServiceFunction(String name) {
- ServiceFunctionKey key = new ServiceFunctionKey(name);
- InstanceIdentifier<ServiceFunction> iid =
- InstanceIdentifier.builder(ServiceFunctions.class)
- .child(ServiceFunction.class, key)
- .toInstance();
-
- ReadOnlyTransaction readTx = odlSfc.dataProvider.newReadOnlyTransaction();
- Optional<ServiceFunction> dataObject = null;
- try {
- dataObject = readTx.read(LogicalDatastoreType.CONFIGURATION, iid).get();
- } catch (InterruptedException | ExecutionException e) {
- e.printStackTrace();
- }
-
- if (dataObject.get() instanceof ServiceFunction) {
- return dataObject.get();
- } else {
- throw new IllegalStateException("Wrong dataObject instance (expected ServiceFunction).");
+ LOG.error("\nFailed to findServiceFunctionChain: {}", e.getMessage());
+ return null;
}
}
SfcSftMapper mapper = new SfcSftMapper(odlSfc);
List<ServiceFunction> sfList = mapper.getSfList(sfType);
- short hop_count = 0;
+ short hopCount = 0;
for(ServiceFunction sf : sfList){
ServicePathHopBuilder builder = new ServicePathHopBuilder();
- ret.add(builder.setHopNumber(hop_count)
+ ret.add(builder.setHopNumber(hopCount)
.setServiceFunctionName(sf.getName())
.setServiceFunctionForwarder(sf.getSfDataPlaneLocator()
.get(0).getServiceFunctionForwarder())
.build());
- hop_count++;
+ hopCount++;
}
return ret;
}
import java.util.Map;
import java.util.Set;
+import static org.opendaylight.sfc.provider.SfcProviderDebug.printTraceStart;
+import static org.opendaylight.sfc.provider.SfcProviderDebug.printTraceStop;
+
/**
* This class gets called whenever there is a change to
public void onDataChanged(
final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change ) {
- LOG.debug("\n########## Start: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStart(LOG);
+
+ // SF ORIGINAL
Map<InstanceIdentifier<?>, DataObject> dataOriginalDataObject = change.getOriginalData();
for (Map.Entry<InstanceIdentifier<?>, DataObject> entry : dataOriginalDataObject.entrySet()) {
odlSfc.executor.submit(SfcProviderServiceTypeAPI
.getDeleteServiceFunctionFromServiceType(serviceTypeObj, serviceTypeClass));
- //Object[] sfParams = {originalServiceFunction};
- //Class[] sfParamsTypes = {ServiceFunction.class};
- //odlSfc.executor.execute(SfcProviderServiceForwarderAPI
- // .getDeleteServiceFunctionFromForwarder(sfParams, sfParamsTypes ));
-
Object[] functionParams = {originalServiceFunction};
Class[] functionParamsTypes = {ServiceFunction.class};
odlSfc.executor.submit(SfcProviderServiceTypeAPI
.getCreateServiceFunctionToServiceType(serviceTypeObj, serviceTypeClass));
- //Object[] sfParams = {createdServiceFunction};
- //Class[] sfParamsTypes = {ServiceFunction.class};
- //odlSfc.executor.execute(SfcProviderServiceForwarderAPI
- // .getCreateServiceForwarderAPI(sfParams, sfParamsTypes));
LOG.debug("\n########## getCreatedConfigurationData {} {}",
createdServiceFunction.getType(), createdServiceFunction.getName());
}
Object[] sfParams = {updatedServiceFunction};
Class[] sfParamsTypes = {ServiceFunction.class};
- //odlSfc.executor.execute(SfcProviderServiceForwarderAPI
- // .getUpdateServiceForwarderAPI(sfParams, sfParamsTypes ));
odlSfc.executor.submit(SfcProviderServicePathAPI
.getUpdateServicePathContainingFunction(sfParams, sfParamsTypes));
}
}
- // Debug and Unit Test. We trigger the unit test code by adding a service function to the datastore.
- if (SfcProviderDebug.ON) {
- SfcProviderDebug.ON = false;
- SfcProviderUnitTest.sfcProviderUnitTest(SfcProviderRpc.getSfcProviderRpc());
- }
-
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
}
}
import java.util.List;
import java.util.Map;
+import static org.opendaylight.sfc.provider.SfcProviderDebug.printTraceStart;
+import static org.opendaylight.sfc.provider.SfcProviderDebug.printTraceStop;
+
/**
* This class gets called whenever there is a change to
public void onDataChanged(
final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change ) {
- LOG.info("\n########## Start: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStart(LOG);
Map<InstanceIdentifier<?>, DataObject> dataUpdatedConfigurationObject = change.getUpdatedData();
- LOG.info("\n########## getUpdatedConfigurationData");
for (Map.Entry<InstanceIdentifier<?>, DataObject> entry : dataUpdatedConfigurationObject.entrySet())
{
if( entry.getValue() instanceof ServiceFunctionChains) {
ServiceFunctionChains updatedServiceFunctionChains = (ServiceFunctionChains) entry.getValue();
- List<ServiceFunctionChain> serviceFunctionChainList = updatedServiceFunctionChains.getServiceFunctionChain();
+ List<ServiceFunctionChain> serviceFunctionChainList =
+ updatedServiceFunctionChains.getServiceFunctionChain();
for (ServiceFunctionChain serviceFunctionChain : serviceFunctionChainList) {
- LOG.info("\n########## Updated ServiceFunctionChain name: {}", serviceFunctionChain.getName());
- List<SfcServiceFunction> SfcServiceFunctionList = serviceFunctionChain.getSfcServiceFunction();
- for (SfcServiceFunction sfcServiceFunction : SfcServiceFunctionList) {
- LOG.info("\n########## Updated ServiceFunction name: {}", sfcServiceFunction.getName());
+ LOG.debug("\n########## Updated ServiceFunctionChain: " +
+ "{}", serviceFunctionChain.getName());
+ List<SfcServiceFunction> sfcServiceFunctionList =
+ serviceFunctionChain.getSfcServiceFunction();
+ for (SfcServiceFunction sfcServiceFunction : sfcServiceFunctionList) {
+ LOG.debug("\n########## Updated ServiceFunction::" +
+ " {}", sfcServiceFunction.getName());
}
}
}
}
Map<InstanceIdentifier<?>, DataObject> dataOriginalConfigurationObject = change.getOriginalData();
- LOG.info("\n########## getOriginalConfigurationData");
for (Map.Entry<InstanceIdentifier<?>, DataObject> entry : dataOriginalConfigurationObject.entrySet())
{
if( entry.getValue() instanceof ServiceFunctionChains) {
ServiceFunctionChains originalServiceFunctionChains = (ServiceFunctionChains) entry.getValue();
- List<ServiceFunctionChain> serviceFunctionChainList = originalServiceFunctionChains.getServiceFunctionChain();
+ List<ServiceFunctionChain> serviceFunctionChainList =
+ originalServiceFunctionChains.getServiceFunctionChain();
for (ServiceFunctionChain serviceFunctionChain : serviceFunctionChainList) {
- LOG.info("\n########## Original ServiceFunctionChain name: {}", serviceFunctionChain.getName());
- List<SfcServiceFunction> SfcServiceFunctionList = serviceFunctionChain.getSfcServiceFunction();
- for (SfcServiceFunction sfcServiceFunction : SfcServiceFunctionList) {
- LOG.info("\n########## Original ServiceFunction name: {}", sfcServiceFunction.getName());
+ LOG.debug("\n########## Original ServiceFunctionChain: " +
+ "{}", serviceFunctionChain.getName());
+ List<SfcServiceFunction> sfcServiceFunctionList =
+ serviceFunctionChain.getSfcServiceFunction();
+ for (SfcServiceFunction sfcServiceFunction : sfcServiceFunctionList) {
+ LOG.debug("\n########## Original ServiceFunction: " +
+ "{}", sfcServiceFunction.getName());
}
}
}
}
Map<InstanceIdentifier<?>, DataObject> dataCreatedConfigurationObject = change.getCreatedData();
- LOG.info("\n########## getCreatedConfigurationData");
for (Map.Entry<InstanceIdentifier<?>, DataObject> entry : dataCreatedConfigurationObject.entrySet())
{
if( entry.getValue() instanceof ServiceFunctionChains) {
ServiceFunctionChains createdServiceFunctionChains = (ServiceFunctionChains) entry.getValue();
- List<ServiceFunctionChain> serviceFunctionChainList = createdServiceFunctionChains.getServiceFunctionChain();
+ List<ServiceFunctionChain> serviceFunctionChainList =
+ createdServiceFunctionChains.getServiceFunctionChain();
for (ServiceFunctionChain serviceFunctionChain : serviceFunctionChainList) {
- LOG.info("\n########## Created ServiceFunctionChain name: {}", serviceFunctionChain.getName());
- List<SfcServiceFunction> SfcServiceFunctionList = serviceFunctionChain.getSfcServiceFunction();
- for (SfcServiceFunction sfcServiceFunction : SfcServiceFunctionList) {
- LOG.info("\n########## Created ServiceFunction name: {}", sfcServiceFunction.getName());
+ LOG.debug("\n########## Created ServiceFunctionChain: " +
+ "{}", serviceFunctionChain.getName());
+ List<SfcServiceFunction> sfcServiceFunctionList =
+ serviceFunctionChain.getSfcServiceFunction();
+ for (SfcServiceFunction sfcServiceFunction : sfcServiceFunctionList) {
+ LOG.debug("\n########## Created ServiceFunction: " +
+ " {}", sfcServiceFunction.getName());
}
}
}
}
-
- LOG.info("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
}
}
import java.util.Map;
import java.util.Set;
+import static org.opendaylight.sfc.provider.SfcProviderDebug.printTraceStart;
+import static org.opendaylight.sfc.provider.SfcProviderDebug.printTraceStop;
+
/**
* This class gets called whenever there is a change to
* a Service Function Chain list entry, i.e.,
public void onDataChanged(
final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change ) {
- LOG.debug("\n########## Start: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStart(LOG);
Map<InstanceIdentifier<?>, DataObject> dataOriginalConfigurationObject = change.getOriginalData();
if( entry.getValue() instanceof ServiceFunctionChain) {
ServiceFunctionChain originalServiceFunctionChain = (ServiceFunctionChain) entry.getValue();
LOG.debug("\n########## Original ServiceFunctionChain name: {}", originalServiceFunctionChain.getName());
- List<SfcServiceFunction> SfcServiceFunctionList = originalServiceFunctionChain.getSfcServiceFunction();
- for (SfcServiceFunction sfcServiceFunction : SfcServiceFunctionList) {
+ List<SfcServiceFunction> sfcServiceFunctionList =
+ originalServiceFunctionChain.getSfcServiceFunction();
+ for (SfcServiceFunction sfcServiceFunction : sfcServiceFunctionList) {
LOG.debug("\n########## Original ServiceFunction name: {}", sfcServiceFunction.getName());
}
Class[] serviceChainClass = {ServiceFunctionChain.class};
odlSfc.executor.submit(SfcProviderServiceChainAPI
.getAddChainToChainState(serviceChainObj, serviceChainClass));
- List<SfcServiceFunction> SfcServiceFunctionList = createdServiceFunctionChain.getSfcServiceFunction();
- for (SfcServiceFunction sfcServiceFunction : SfcServiceFunctionList) {
+ List<SfcServiceFunction> sfcServiceFunctionList = createdServiceFunctionChain.getSfcServiceFunction();
+ for (SfcServiceFunction sfcServiceFunction : sfcServiceFunctionList) {
LOG.debug("\n########## Attached ServiceFunction name: {}", sfcServiceFunction.getName());
}
}
}
-
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
}
public class SfcProviderSfsDataListener implements DataChangeListener {
private static final Logger LOG = LoggerFactory.getLogger(SfcProviderSfsDataListener.class);
- private OpendaylightSfc odlSfc = OpendaylightSfc.getOpendaylightSfcObj();
@Override
public void onDataChanged(
package org.opendaylight.sfc.provider;
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sf.rev140701.*;
-import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfc.rev140701.*;
-import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sft.rev140701.*;
-import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfc.rev140701.service.function.chain.grouping.*;
-import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfc.rev140701.
- service.function.chain.grouping.service.function.chain.*;
-/*
-import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sl.rev140701.
- data.plane.locator.DataPlaneLocatorBuilder;
-import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sl.rev140701.
- data.plane.locator.data.plane.locator.locator.type.IpBuilder;
-*/
-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.PortNumber;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfc.rev140701.PutServiceFunctionChainsInputBuilder;
+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.ServiceFunctionChainBuilder;
+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.sfc.rev140701.service.function.chain.grouping.service.function.chain.SfcServiceFunctionBuilder;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
+/*
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sl.rev140701.
+ data.plane.locator.DataPlaneLocatorBuilder;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sl.rev140701.
+ data.plane.locator.data.plane.locator.locator.type.IpBuilder;
+*/
+
/**
* This class is a harness for live unit Testing. It has static
* methods that can are used to test various SFC datastore operations.
*/
public class SfcProviderUnitTest {
private static final Logger LOG = LoggerFactory.getLogger(SfcProviderUnitTest.class);
+
+ private SfcProviderUnitTest() {};
+
// Delete all Service Functions
public static void sfcProviderUnitTest(SfcProviderRpc sfcRpcObj) {
sfcRpcObj.deleteAllServiceFunction();
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.sfc.provider.OpendaylightSfc;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public abstract class SfcProviderAbstractAPI implements Callable<Object> {
protected static final OpendaylightSfc odlSfc = OpendaylightSfc.getOpendaylightSfcObj();
- protected String methodName = null;
- protected Object[] parameters;
- protected Class[] parameterTypes;
+ private static final Logger LOG = LoggerFactory.getLogger
+ (SfcProviderAbstractAPI.class);
+ private String methodName = null;
+ private Object[] parameters;
+ private Class[] parameterTypes;
protected DataBroker dataBroker;
+ public String getMethodName()
+ {
+ return methodName;
+ }
+
+ public void setMethodName(String methodName)
+ {
+ this.methodName = methodName;
+ }
+
+ public Object[] getParameters()
+ {
+ return parameters;
+ }
+
+ public void setParameters(Object[] parameters)
+ {
+ this.parameters = Arrays.copyOf(parameters, parameters.length);
+ }
+
+ public Class[] getParameterTypes()
+ {
+ return parameterTypes;
+ }
+
+ public void setParameterTypes(Class[] parameterTypes)
+ {
+ this.parameterTypes = Arrays.copyOf(parameterTypes,
+ parameterTypes.length);
+ }
+
+ public DataBroker getDataBroker()
+ {
+ return dataBroker;
+ }
+
+ public void setDataBroker(DataBroker dataBroker)
+ {
+ this.dataBroker = dataBroker;
+ }
+
SfcProviderAbstractAPI(Object[] params, String m) {
- this.methodName = m;
+ setMethodName(m);
this.parameters = new Object[params.length];
this.parameterTypes = new Class[params.length];
- this.parameters = Arrays.copyOf(params, params.length);
- this.dataBroker = odlSfc.getDataProvider();
+ setParameters(params);
+ setDataBroker(odlSfc.getDataProvider());
for (int i = 0; i < params.length; i++) {
this.parameterTypes[i] = params[i].getClass();
}
protected SfcProviderAbstractAPI(Object[] params, Class[] paramsTypes, String m) {
- this.methodName = m;
+ setMethodName(m);
this.parameters = new Object[params.length];
this.parameterTypes = new Class[params.length];
- this.parameters = Arrays.copyOf(params, params.length);
- this.parameterTypes = Arrays.copyOf(paramsTypes, paramsTypes.length);
- this.dataBroker = odlSfc.getDataProvider();
+ setParameters(params);
+ setParameterTypes(paramsTypes);
+ setDataBroker(odlSfc.getDataProvider());
}
@Override
method = c.getDeclaredMethod(methodName, parameterTypes);
result = method.invoke(this, parameters);
} catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
- e.printStackTrace();
+ LOG.error("Could not find method in class");
}
}
return result;
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-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.ServiceFunctionChains;
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfc.rev140701.ServiceFunctionChainsState;
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.ServiceFunctionChainKey;
-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.sfc.rev140701.service.function.chain.grouping.service.function.chain.SfcServiceFunctionKey;
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfc.rev140701.service.function.chains.state.ServiceFunctionChainState;
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfc.rev140701.service.function.chains.state.ServiceFunctionChainStateBuilder;
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfc.rev140701.service.function.chains.state.ServiceFunctionChainStateKey;
import java.util.ArrayList;
import java.util.concurrent.ExecutionException;
+import static org.opendaylight.sfc.provider.SfcProviderDebug.printTraceStart;
+import static org.opendaylight.sfc.provider.SfcProviderDebug.printTraceStop;
+
+
/**
* This class has the APIs to operate on the ServiceFunctionChain
* datastore.
return new SfcProviderServiceChainAPI(params, paramsTypes, "addChainToChainState");
}
- protected boolean putServiceFunctionChain(ServiceFunctionChain sfc) {
+ protected boolean putServiceFunctionChain(ServiceFunctionChain serviceFunctionChain) {
boolean ret = false;
- LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStart(LOG);
if (dataBroker != null) {
- InstanceIdentifier<ServiceFunctionChain> sfcEntryIID = InstanceIdentifier.builder(ServiceFunctionChains.class).
- child(ServiceFunctionChain.class, sfc.getKey()).toInstance();
+ InstanceIdentifier<ServiceFunctionChain> sfcEntryIID =
+ InstanceIdentifier.builder(ServiceFunctionChains.class)
+ .child(ServiceFunctionChain.class,
+ serviceFunctionChain.getKey())
+ .toInstance();
WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction();
writeTx.merge(LogicalDatastoreType.CONFIGURATION,
- sfcEntryIID, sfc, true);
+ sfcEntryIID, serviceFunctionChain, true);
writeTx.commit();
-
ret = true;
}
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
return ret;
}
protected ServiceFunctionChain readServiceFunctionChain(String serviceFunctionChainName) {
- LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStart(LOG);
ServiceFunctionChain sfc = null;
InstanceIdentifier<ServiceFunctionChain> sfcIID;
- ServiceFunctionChainKey serviceFunctionChainKey = new ServiceFunctionChainKey(serviceFunctionChainName);
+ ServiceFunctionChainKey serviceFunctionChainKey =
+ new ServiceFunctionChainKey(serviceFunctionChainName);
sfcIID = InstanceIdentifier.builder(ServiceFunctionChains.class)
.child(ServiceFunctionChain.class, serviceFunctionChainKey).build();
if (dataBroker != null) {
ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction();
- Optional<ServiceFunctionChain> serviceFunctionChainDataObject = null;
+ Optional<ServiceFunctionChain> serviceFunctionChainDataObject;
try {
serviceFunctionChainDataObject = readTx.read(LogicalDatastoreType.CONFIGURATION, sfcIID).get();
+ if (serviceFunctionChainDataObject != null
+ && serviceFunctionChainDataObject.isPresent()) {
+ sfc = serviceFunctionChainDataObject.get();
+ }
} catch (InterruptedException | ExecutionException e) {
- e.printStackTrace();
- }
- if (serviceFunctionChainDataObject != null
- && serviceFunctionChainDataObject.isPresent()) {
- sfc = serviceFunctionChainDataObject.get();
+ LOG.error("Could not read Service Function Chain " +
+ "configuration {}", serviceFunctionChainName);
}
}
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
return sfc;
}
protected boolean deleteServiceFunctionChain(String serviceFunctionChainName) {
boolean ret = false;
- LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
- ServiceFunctionChainKey serviceFunctionChainKey = new ServiceFunctionChainKey(serviceFunctionChainName);
- InstanceIdentifier<ServiceFunctionChain> sfcEntryIID = InstanceIdentifier.builder(ServiceFunctionChains.class)
+ printTraceStart(LOG);
+ ServiceFunctionChainKey serviceFunctionChainKey =
+ new ServiceFunctionChainKey(serviceFunctionChainName);
+ InstanceIdentifier<ServiceFunctionChain> sfcEntryIID =
+ InstanceIdentifier.builder(ServiceFunctionChains.class)
.child(ServiceFunctionChain.class, serviceFunctionChainKey).toInstance();
if (dataBroker != null) {
ret = true;
}
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
return ret;
}
protected boolean putAllServiceFunctionChains(ServiceFunctionChains sfcs) {
boolean ret = false;
- LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStart(LOG);
if (dataBroker != null) {
- InstanceIdentifier<ServiceFunctionChains> sfcsIID = InstanceIdentifier.builder(ServiceFunctionChains.class).toInstance();
+ InstanceIdentifier<ServiceFunctionChains> sfcsIID =
+ InstanceIdentifier.builder(ServiceFunctionChains.class).toInstance();
WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction();
writeTx.merge(LogicalDatastoreType.CONFIGURATION, sfcsIID, sfcs);
ret = true;
}
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
return ret;
}
protected ServiceFunctionChains readAllServiceFunctionChains() {
ServiceFunctionChains sfcs = null;
- LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
- InstanceIdentifier<ServiceFunctionChains> sfcsIID = InstanceIdentifier.builder(ServiceFunctionChains.class).toInstance();
+ printTraceStart(LOG);
+ InstanceIdentifier<ServiceFunctionChains> sfcsIID = InstanceIdentifier
+ .builder(ServiceFunctionChains.class).toInstance();
- if (odlSfc.getDataProvider() != null) {
+ if (dataBroker != null) {
ReadOnlyTransaction readTx = odlSfc.getDataProvider().newReadOnlyTransaction();
Optional<ServiceFunctionChains> serviceFunctionChainsDataObject = null;
try {
- serviceFunctionChainsDataObject = readTx.read(LogicalDatastoreType.CONFIGURATION, sfcsIID).get();
+ serviceFunctionChainsDataObject = readTx
+ .read(LogicalDatastoreType.CONFIGURATION, sfcsIID).get();
+ if (serviceFunctionChainsDataObject != null
+ && serviceFunctionChainsDataObject.isPresent()) {
+ sfcs = serviceFunctionChainsDataObject.get();
+ }
} catch (InterruptedException | ExecutionException e) {
- e.printStackTrace();
- }
- if (serviceFunctionChainsDataObject != null
- && serviceFunctionChainsDataObject.isPresent()) {
- sfcs = serviceFunctionChainsDataObject.get();
+ LOG.error("Could not read Service Function Chains " +
+ "configuration");
}
+
}
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
return sfcs;
}
protected boolean deleteAllServiceFunctionChains() {
boolean ret = false;
- LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
- if (odlSfc.getDataProvider() != null) {
+ printTraceStart(LOG);
+ if (dataBroker != null) {
- InstanceIdentifier<ServiceFunctionChains> sfcsIID = InstanceIdentifier.builder(ServiceFunctionChains.class).toInstance();
+ InstanceIdentifier<ServiceFunctionChains> sfcsIID =
+ InstanceIdentifier.builder(ServiceFunctionChains.class).toInstance();
- WriteTransaction writeTx = odlSfc.getDataProvider().newWriteOnlyTransaction();
+ WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction();
writeTx.delete(LogicalDatastoreType.CONFIGURATION, sfcsIID);
writeTx.commit();
ret = true;
}
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
return ret;
}
protected void addChainToChainState (ServiceFunctionChain serviceFunctionChain) {
- LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
- ServiceFunctionChainStateKey serviceFunctionChainStateKey = new ServiceFunctionChainStateKey(serviceFunctionChain.getName());
- InstanceIdentifier<ServiceFunctionChainState> sfcoIID = InstanceIdentifier.builder(ServiceFunctionChainsState.class)
+ printTraceStart(LOG);
+ ServiceFunctionChainStateKey serviceFunctionChainStateKey = new
+ ServiceFunctionChainStateKey(serviceFunctionChain.getName());
+ InstanceIdentifier<ServiceFunctionChainState> sfcoIID =
+ InstanceIdentifier.builder(ServiceFunctionChainsState.class)
.child(ServiceFunctionChainState.class, serviceFunctionChainStateKey).build();
ServiceFunctionChainStateBuilder serviceFunctionChainStateBuilder = new ServiceFunctionChainStateBuilder();
serviceFunctionChainStateBuilder.setName(serviceFunctionChain.getName());
- WriteTransaction writeTx = odlSfc.getDataProvider().newWriteOnlyTransaction();
+ WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction();
writeTx.merge(LogicalDatastoreType.OPERATIONAL,
sfcoIID, serviceFunctionChainStateBuilder.build(), true);
writeTx.commit();
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
}
public static void addPathToServiceFunctionChainState (ServiceFunctionChain serviceFunctionChain,
ServiceFunctionPath serviceFunctionPath) {
- LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
- ServiceFunctionChainStateKey serviceFunctionChainStateKey = new ServiceFunctionChainStateKey(serviceFunctionChain.getName());
- InstanceIdentifier<ServiceFunctionChainState> sfcoIID = InstanceIdentifier.builder(ServiceFunctionChainsState.class)
+ printTraceStart(LOG);
+ ServiceFunctionChainStateKey serviceFunctionChainStateKey = new
+ ServiceFunctionChainStateKey(serviceFunctionChain.getName());
+ InstanceIdentifier<ServiceFunctionChainState> sfcoIID = InstanceIdentifier
+ .builder(ServiceFunctionChainsState.class)
.child(ServiceFunctionChainState.class, serviceFunctionChainStateKey).build();
- ServiceFunctionChainStateBuilder serviceFunctionChainStateBuilder = new ServiceFunctionChainStateBuilder();
+ ServiceFunctionChainStateBuilder serviceFunctionChainStateBuilder = new
+ ServiceFunctionChainStateBuilder();
ArrayList<String> sfcServiceFunctionPathArrayList = new ArrayList<>();
sfcServiceFunctionPathArrayList.add(serviceFunctionPath.getName());
serviceFunctionChainStateBuilder.setSfcServiceFunctionPath(sfcServiceFunctionPathArrayList);
writeTx.merge(LogicalDatastoreType.OPERATIONAL,
sfcoIID, serviceFunctionChainStateBuilder.build(), true);
writeTx.commit();
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
}
-
+/*
private InstanceIdentifier<SfcServiceFunction> getServiceFunctionIIDFromChain (ServiceFunctionChain sfc, ServiceFunction sf) {
SfcServiceFunctionKey serviceFunctionKey = new SfcServiceFunctionKey(sf.getName());
- InstanceIdentifier<SfcServiceFunction> sfIID = InstanceIdentifier.builder(ServiceFunctionChains.class)
+ InstanceIdentifier<SfcServiceFunction> sfIID = InstanceIdentifier
+ .builder(ServiceFunctionChains.class)
.child(ServiceFunctionChain.class, sfc.getKey())
.child(SfcServiceFunction.class, serviceFunctionKey).build();
- ReadOnlyTransaction readTx = odlSfc.getDataProvider().newReadOnlyTransaction();
+ ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction();
Optional<SfcServiceFunction> serviceFunctionObject = null;
try {
serviceFunctionObject = readTx.read(LogicalDatastoreType.CONFIGURATION, sfIID).get();
+ if (serviceFunctionObject != null) {
+ serviceFunctionObject.get();
+ printTraceStop(LOG);
+ return sfIID;
+
+ } else {
+ printTraceStop(LOG);
+ return null;
+ }
} catch (InterruptedException | ExecutionException e) {
- e.printStackTrace();
- }
- if (serviceFunctionObject.get() instanceof SfcServiceFunction) {
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
- return sfIID;
- } else {
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ LOG.error("\n########## Failed to get Service Function IID " +
+ "from Chain: {}",
+ e.getMessage());
+ printTraceStop(LOG);
return null;
}
}
-
+*/
public static ServiceFunctionChains getServiceFunctionChainsRef () {
- LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStart(LOG);
InstanceIdentifier<ServiceFunctionChains> sfcsIID;
sfcsIID = InstanceIdentifier.builder(ServiceFunctionChains.class).build();
Optional<ServiceFunctionChains> serviceFunctionChainsObject = null;
try {
serviceFunctionChainsObject = readTx.read(LogicalDatastoreType.CONFIGURATION, sfcsIID).get();
+ if (serviceFunctionChainsObject != null) {
+ printTraceStop(LOG);
+ return serviceFunctionChainsObject.get();
+ } else {
+ LOG.error("\n########## Failed to get Service Function Chains reference: {}",
+ Thread.currentThread().getStackTrace()[1]);
+ return null;
+ }
} catch (InterruptedException | ExecutionException e) {
- e.printStackTrace();
- }
- if (serviceFunctionChainsObject.get() instanceof ServiceFunctionChains) {
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
- return serviceFunctionChainsObject.get();
- } else {
LOG.error("\n########## Failed to get Service Function Chains reference: {}",
- Thread.currentThread().getStackTrace()[1]);
+ e.getMessage());
return null;
}
}
public static ServiceFunctionChainsState getServiceFunctionChainsStateRef () {
- LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStart(LOG);
InstanceIdentifier<ServiceFunctionChainsState> sfcsIID;
sfcsIID = InstanceIdentifier.builder(ServiceFunctionChainsState.class).build();
Optional<ServiceFunctionChainsState> serviceFunctionChainStateObject = null;
try {
serviceFunctionChainStateObject = readTx.read(LogicalDatastoreType.OPERATIONAL, sfcsIID).get();
+ if (serviceFunctionChainStateObject != null) {
+ printTraceStop(LOG);
+ return serviceFunctionChainStateObject.get();
+ } else {
+ LOG.error("\n########## Failed to get Service Function Chains reference: {}",
+ Thread.currentThread().getStackTrace()[1]);
+ return null;
+ }
} catch (InterruptedException | ExecutionException e) {
- e.printStackTrace();
- }
- if (serviceFunctionChainStateObject.get() instanceof ServiceFunctionChainsState) {
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
- return serviceFunctionChainStateObject.get();
- } else {
LOG.error("\n########## Failed to get Service Function Chains reference: {}",
- Thread.currentThread().getStackTrace()[1]);
+ e.getMessage());
return null;
}
}
import java.util.List;
import java.util.concurrent.ExecutionException;
+import static org.opendaylight.sfc.provider.SfcProviderDebug.printTraceStart;
+import static org.opendaylight.sfc.provider.SfcProviderDebug.printTraceStop;
+
/**
* This class has the APIs to operate on the ServiceFunction
* datastore.
/*
public static ServiceFunctionForwarder readServiceFunctionForwarder(String name) {
- LOG.debug("\n########## Start: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStart(LOG)
ServiceFunctionForwarderKey serviceFunctionForwarderKey =
new ServiceFunctionForwarderKey(name);
InstanceIdentifier<ServiceFunctionForwarder> sffIID;
if (serviceFunctionForwarderObject != null &&
(serviceFunctionForwarderObject.get() instanceof ServiceFunctionForwarder)) {
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
return serviceFunctionForwarderObject.get();
} else {
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
return null;
}
}
*/
public static void addPathIdtoServiceFunctionForwarder(ServiceFunctionPath serviceFunctionPath) throws ExecutionException, InterruptedException {
- LOG.debug("\n########## Start: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStart(LOG);
InstanceIdentifier<ServiceFunctionForwarders> sffsIID;
ServiceFunctionForwardersBuilder serviceFunctionForwardersBuilder = new ServiceFunctionForwardersBuilder();
sffsIID, serviceFunctionForwardersBuilder.build(), true);
writeTx.commit();
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
//serviceFunctionForwardersBuilder.setServiceFunctionForwarder(serviceFunctionForwarderList);
* This method checks if a SFF is complete and can be sent to southbound devices
*/
public static boolean checkServiceFunctionForwarder(ServiceFunctionForwarder serviceFunctionForwarder) {
- if ((serviceFunctionForwarder.getName() != null) &&
- (serviceFunctionForwarder.getServiceFunctionDictionary() != null)) {
- return true;
- } else {
- return false;
- }
-
+ return ((serviceFunctionForwarder.getName() != null) &&
+ (serviceFunctionForwarder.getServiceFunctionDictionary() !=
+ null));
}
protected boolean putServiceFunctionForwarder(ServiceFunctionForwarder sff) {
boolean ret = false;
- LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStart(LOG);
if (dataBroker != null) {
InstanceIdentifier<ServiceFunctionForwarder> sffEntryIID = InstanceIdentifier.builder(ServiceFunctionForwarders.class).
ret = true;
}
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
return ret;
}
protected ServiceFunctionForwarder readServiceFunctionForwarder(String serviceFunctionForwarderName) {
- LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStart(LOG);
ServiceFunctionForwarder sff = null;
InstanceIdentifier<ServiceFunctionForwarder> sffIID;
ServiceFunctionForwarderKey serviceFunctionForwarderKey = new ServiceFunctionForwarderKey(serviceFunctionForwarderName);
ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction();
Optional<ServiceFunctionForwarder> serviceFunctionForwarderDataObject = null;
try {
- serviceFunctionForwarderDataObject = readTx.read(LogicalDatastoreType.CONFIGURATION, sffIID).get();
+ serviceFunctionForwarderDataObject = readTx.
+ read(LogicalDatastoreType.CONFIGURATION, sffIID).get();
} catch (InterruptedException | ExecutionException e) {
- e.printStackTrace();
+ LOG.error("Could not read Service Function Forwarder {} " +
+ "configuration", serviceFunctionForwarderName);
+ return null;
}
if (serviceFunctionForwarderDataObject != null
&& serviceFunctionForwarderDataObject.isPresent()) {
sff = serviceFunctionForwarderDataObject.get();
}
}
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
return sff;
}
protected boolean deleteServiceFunctionForwarder(String serviceFunctionForwarderName) {
boolean ret = false;
- LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStart(LOG);
ServiceFunctionForwarderKey serviceFunctionForwarderKey = new ServiceFunctionForwarderKey(serviceFunctionForwarderName);
InstanceIdentifier<ServiceFunctionForwarder> sffEntryIID = InstanceIdentifier.builder(ServiceFunctionForwarders.class).
child(ServiceFunctionForwarder.class, serviceFunctionForwarderKey).toInstance();
ret = true;
}
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
return ret;
}
protected boolean putAllServiceFunctionForwarders(ServiceFunctionForwarders sffs) {
boolean ret = false;
- LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStart(LOG);
if (dataBroker != null) {
InstanceIdentifier<ServiceFunctionForwarders> sffsIID =
ret = true;
}
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
return ret;
}
protected ServiceFunctionForwarders readAllServiceFunctionForwarders() {
ServiceFunctionForwarders sffs = null;
- LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStart(LOG);
InstanceIdentifier<ServiceFunctionForwarders> sffsIID =
InstanceIdentifier.builder(ServiceFunctionForwarders.class).toInstance();
ReadOnlyTransaction readTx = odlSfc.getDataProvider().newReadOnlyTransaction();
Optional<ServiceFunctionForwarders> serviceFunctionForwardersDataObject = null;
try {
- serviceFunctionForwardersDataObject = readTx.read(LogicalDatastoreType.CONFIGURATION, sffsIID).get();
+ serviceFunctionForwardersDataObject = readTx.
+ read(LogicalDatastoreType.CONFIGURATION, sffsIID).get();
+ if (serviceFunctionForwardersDataObject != null
+ && serviceFunctionForwardersDataObject.isPresent()) {
+ sffs = serviceFunctionForwardersDataObject.get();
+ }
} catch (InterruptedException | ExecutionException e) {
- e.printStackTrace();
- }
- if (serviceFunctionForwardersDataObject != null
- && serviceFunctionForwardersDataObject.isPresent()) {
- sffs = serviceFunctionForwardersDataObject.get();
+ LOG.error("Could not read Service Function Forwarder " +
+ "configuration data");
}
+
}
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
return sffs;
}
protected boolean deleteAllServiceFunctionForwarders() {
boolean ret = false;
- LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStart(LOG);
if (odlSfc.getDataProvider() != null) {
InstanceIdentifier<ServiceFunctionForwarders> sffsIID =
InstanceIdentifier.builder(ServiceFunctionForwarders.class).toInstance();
- WriteTransaction writeTx = odlSfc.getDataProvider().newWriteOnlyTransaction();
+ WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction();
writeTx.delete(LogicalDatastoreType.CONFIGURATION, sffsIID);
writeTx.commit();
ret = true;
}
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
return ret;
}
*/
public void createServiceFunctionForwarder(ServiceFunction serviceFunction) {
- LOG.debug("\n########## Start: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStart(LOG);
InstanceIdentifier<ServiceFunctionForwarder> sffIID;
String serviceFunctionForwarderName = serviceFunction.getSfDataPlaneLocator()
.get(0).getServiceFunctionForwarder();
LOG.debug("\n########## Creating Forwarder: {} Service Function: {} "
, serviceFunctionForwarderName, serviceFunction.getName());
- WriteTransaction writeTx = odlSfc.getDataProvider().newWriteOnlyTransaction();
+ WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction();
writeTx.merge(LogicalDatastoreType.CONFIGURATION,
sffIID, serviceFunctionForwarderBuilder.build(), true);
writeTx.commit();
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
}
public void deleteServiceFunctionFromForwarder(ServiceFunction serviceFunction) {
- LOG.debug("\n########## Start: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStart(LOG);
String serviceFunctionForwarderName = serviceFunction.getSfDataPlaneLocator()
.get(0).getServiceFunctionForwarder();
InstanceIdentifier<ServiceFunctionDictionary> sffIID;
.child(ServiceFunctionDictionary.class, serviceFunctionDictionaryKey)
.build();
- WriteTransaction writeTx = odlSfc.getDataProvider().newWriteOnlyTransaction();
+ WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction();
writeTx.delete(LogicalDatastoreType.CONFIGURATION,
sffIID);
writeTx.commit();
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
}
@SuppressWarnings("unused")
public void updateServiceFunctionForwarder(ServiceFunction serviceFunction) {
- LOG.debug("\n########## Start: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStart(LOG);
deleteServiceFunctionFromForwarder(serviceFunction);
createServiceFunctionForwarder(serviceFunction);
@SuppressWarnings("unused")
public void createServiceFunctionForwarders(ServiceFunctionChains serviceFunctionchains) {
- LOG.debug("\n########## Start: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStart(LOG);
InstanceIdentifier<ServiceFunctionForwarders> sffIID;
// Prepare top container and list
serviceFunctionForwarderList.add(serviceFunctionForwarderBuilder.build());
- LOG.debug("\n########## Creating Forwarder: {} Service Function: {} "
+ LOG.debug("\n########## Creating Forwarder: {} Service " +
+ "Function: {} "
, serviceFunctionForwarderName, serviceFunction.getName());
}
serviceFunctionForwardersBuilder.setServiceFunctionForwarder(serviceFunctionForwarderList);
- WriteTransaction writeTx = odlSfc.getDataProvider().newWriteOnlyTransaction();
+ WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction();
writeTx.merge(LogicalDatastoreType.CONFIGURATION,
sffIID, serviceFunctionForwardersBuilder.build(), true);
writeTx.commit();
}
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
}
*/
- LOG.debug("\n########## Start: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStart(LOG);
String serviceFunctionForwarderName = serviceFunction.getSfDataPlaneLocator()
.get(0).getServiceFunctionForwarder();
LOG.debug("\n########## Deleting Forwarder: {} Service Function: {} "
, serviceFunctionForwarderName, serviceFunction.getName());
- WriteTransaction writeTx = odlSfc.getDataProvider().newWriteOnlyTransaction();
+ WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction();
writeTx.delete(LogicalDatastoreType.CONFIGURATION,
sffIID);
writeTx.commit();
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
}
}
import java.util.List;
import java.util.concurrent.ExecutionException;
+import static org.opendaylight.sfc.provider.SfcProviderDebug.printTraceStart;
+import static org.opendaylight.sfc.provider.SfcProviderDebug.printTraceStop;
+
/**
* This class has the APIs to operate on the ServiceFunction
* datastore.
}
public static ServiceFunctionState readServiceFunctionState(String serviceFunctionName) {
- LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStart(LOG);
ServiceFunctionState serviceFunctionState;
ServiceFunctionStateKey serviceFunctionStateKey =
Optional<ServiceFunctionState> dataSfcStateObject = null;
try {
dataSfcStateObject = readTx.read(LogicalDatastoreType.OPERATIONAL, sfStateIID).get();
+ if (dataSfcStateObject != null) {
+ serviceFunctionState = dataSfcStateObject.get();
+ printTraceStop(LOG);
+ return serviceFunctionState;
+ } else {
+ LOG.error("\n########## Could not find Service Function State for service function {}",
+ serviceFunctionName);
+ return null;
+ }
} catch (InterruptedException | ExecutionException e) {
- e.printStackTrace();
- }
- if (dataSfcStateObject != null &&
- (dataSfcStateObject.get() instanceof ServiceFunctionState)) {
- serviceFunctionState = dataSfcStateObject.get();
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
- return serviceFunctionState;
- } else {
- LOG.error("\n########## Could not find Service Function State for service function {}",
+ LOG.error("\n########## Could not read Service Function State for" +
+ " service function {} from DataStore",
serviceFunctionName);
return null;
}
+
}
public static void deleteServiceFunctionState(String serviceFunctionName) {
- LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStart(LOG);
ServiceFunctionStateKey serviceFunctionStateKey =
*/
public static void addPathToServiceFunctionState(ServiceFunctionPath serviceFunctionPath) {
- LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStart(LOG);
ServiceFunctionStateBuilder serviceFunctionStateBuilder = new ServiceFunctionStateBuilder();
ArrayList<String> sfcServiceFunctionPathArrayList = new ArrayList<>();
sfStateIID, serviceFunctionStateBuilder.build(), true);
writeTx.commit();
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
}
}
protected static boolean putServiceFunction(ServiceFunction sf) {
boolean ret = false;
- LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStart(LOG);
if (odlSfc.getDataProvider() != null) {
InstanceIdentifier<ServiceFunction> sfEntryIID = InstanceIdentifier.builder(ServiceFunctions.class).
ret = true;
}
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
return ret;
}
protected static boolean mergeServiceFunction(ServiceFunction sf) {
boolean ret = false;
- LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStart(LOG);
if (odlSfc.getDataProvider() != null) {
InstanceIdentifier<ServiceFunction> sfEntryIID = InstanceIdentifier.builder(ServiceFunctions.class).
ret = true;
}
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
return ret;
}
protected ServiceFunction readServiceFunction(String serviceFunctionName) {
- LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStart(LOG);
ServiceFunction sf = null;
InstanceIdentifier<ServiceFunction> sfIID;
ServiceFunctionKey serviceFunctionKey = new ServiceFunctionKey(serviceFunctionName);
Optional<ServiceFunction> serviceFunctionDataObject = null;
try {
serviceFunctionDataObject = readTx.read(LogicalDatastoreType.CONFIGURATION, sfIID).get();
+ if (serviceFunctionDataObject != null
+ && serviceFunctionDataObject.isPresent()) {
+ sf = serviceFunctionDataObject.get();
+ printTraceStop(LOG);
+ return sf;
+ } else {
+ LOG.error("\n########## Could not find Service Function " +
+ "{}", serviceFunctionName);
+ return null;
+ }
} catch (InterruptedException | ExecutionException e) {
- e.printStackTrace();
- }
- if (serviceFunctionDataObject != null
- && serviceFunctionDataObject.isPresent()) {
- sf = serviceFunctionDataObject.get();
+ LOG.error("\n########## Could not read Service Function {} " +
+ "from DataStore",
+ serviceFunctionName);
+ return null;
}
+
}
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
return sf;
}
protected boolean deleteServiceFunction(String serviceFunctionName) {
boolean ret = false;
- LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStart(LOG);
ServiceFunctionKey serviceFunctionKey = new ServiceFunctionKey(serviceFunctionName);
InstanceIdentifier<ServiceFunction> sfEntryIID = InstanceIdentifier.builder(ServiceFunctions.class)
.child(ServiceFunction.class, serviceFunctionKey).toInstance();
ret = true;
}
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
return ret;
}
protected boolean putAllServiceFunctions(ServiceFunctions sfs) {
boolean ret = false;
- LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStart(LOG);
if (odlSfc.getDataProvider() != null) {
InstanceIdentifier<ServiceFunctions> sfsIID = InstanceIdentifier.builder(ServiceFunctions.class).toInstance();
ret = true;
}
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
return ret;
}
protected ServiceFunctions readAllServiceFunctions() {
ServiceFunctions sfs = null;
- LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
- InstanceIdentifier<ServiceFunctions> sfsIID = InstanceIdentifier.builder(ServiceFunctions.class).toInstance();
+ printTraceStart(LOG);
+ InstanceIdentifier<ServiceFunctions> sfsIID =
+ InstanceIdentifier.builder(ServiceFunctions.class).toInstance();
if (odlSfc.getDataProvider() != null) {
ReadOnlyTransaction readTx = odlSfc.getDataProvider().newReadOnlyTransaction();
Optional<ServiceFunctions> serviceFunctionsDataObject = null;
try {
serviceFunctionsDataObject = readTx.read(LogicalDatastoreType.CONFIGURATION, sfsIID).get();
+ if (serviceFunctionsDataObject != null
+ && serviceFunctionsDataObject.isPresent()) {
+ sfs = serviceFunctionsDataObject.get();
+ printTraceStop(LOG);
+ return sfs;
+ } else {
+ LOG.error("\n########## Could not find Service Functions");
+ return null;
+ }
} catch (InterruptedException | ExecutionException e) {
- e.printStackTrace();
- }
- if (serviceFunctionsDataObject != null
- && serviceFunctionsDataObject.isPresent()) {
- sfs = serviceFunctionsDataObject.get();
+ LOG.error("\n########## Could not read Service Functions from" +
+ " DataStore");
+ printTraceStop(LOG);
+ return null;
}
}
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
return sfs;
}
protected boolean deleteAllServiceFunctions() {
boolean ret = false;
- LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStart(LOG);
if (odlSfc.getDataProvider() != null) {
InstanceIdentifier<ServiceFunctions> sfsIID = InstanceIdentifier.builder(ServiceFunctions.class).toInstance();
ret = true;
}
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
return ret;
}
import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicInteger;
+import static org.opendaylight.sfc.provider.SfcProviderDebug.printTraceStart;
+import static org.opendaylight.sfc.provider.SfcProviderDebug.printTraceStop;
+
/**
* This class has the APIs to operate on the ServiceFunctionPath
* datastore.
@SuppressWarnings("unused")
protected boolean putServiceFunctionPath(ServiceFunctionPath sfp) {
boolean ret = false;
- LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStart(LOG);
if (dataBroker != null) {
InstanceIdentifier<ServiceFunctionPath> sfpEntryIID = InstanceIdentifier.builder(ServiceFunctionPaths.class).
ret = true;
}
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
return ret;
}
protected ServiceFunctionPath readServiceFunctionPath(String serviceFunctionPathName) {
- LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStart(LOG);
ServiceFunctionPath sfp = null;
InstanceIdentifier<ServiceFunctionPath> sfpIID;
ServiceFunctionPathKey serviceFunctionPathKey = new ServiceFunctionPathKey(serviceFunctionPathName);
ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction();
Optional<ServiceFunctionPath> serviceFunctionPathDataObject = null;
try {
- serviceFunctionPathDataObject = readTx.read(LogicalDatastoreType.CONFIGURATION, sfpIID).get();
+ serviceFunctionPathDataObject = readTx.read(LogicalDatastoreType
+ .CONFIGURATION, sfpIID).get();
+ if (serviceFunctionPathDataObject != null
+ && serviceFunctionPathDataObject.isPresent()) {
+ sfp = serviceFunctionPathDataObject.get();
+ }
} catch (InterruptedException | ExecutionException e) {
- e.printStackTrace();
- }
- if (serviceFunctionPathDataObject != null
- && serviceFunctionPathDataObject.isPresent()) {
- sfp = serviceFunctionPathDataObject.get();
+ LOG.error("Could not read Service Function Path configuration data \n");
}
}
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
return sfp;
}
protected boolean deleteServiceFunctionPath(String serviceFunctionPathName) {
boolean ret = false;
- LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStart(LOG);
ServiceFunctionPathKey serviceFunctionPathKey = new ServiceFunctionPathKey(serviceFunctionPathName);
InstanceIdentifier<ServiceFunctionPath> sfpEntryIID = InstanceIdentifier.builder(ServiceFunctionPaths.class)
.child(ServiceFunctionPath.class, serviceFunctionPathKey).toInstance();
ret = true;
}
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
return ret;
}
protected boolean putAllServiceFunctionPaths(ServiceFunctionPaths sfps) {
boolean ret = false;
- LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStart(LOG);
if (dataBroker != null) {
- InstanceIdentifier<ServiceFunctionPaths> sfpsIID = InstanceIdentifier.builder(ServiceFunctionPaths.class).toInstance();
+ InstanceIdentifier<ServiceFunctionPaths> sfpsIID = InstanceIdentifier.
+ builder(ServiceFunctionPaths.class).toInstance();
WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction();
writeTx.merge(LogicalDatastoreType.CONFIGURATION, sfpsIID, sfps);
ret = true;
}
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
return ret;
}
protected ServiceFunctionPaths readAllServiceFunctionPaths() {
ServiceFunctionPaths sfps = null;
- LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStart(LOG);
InstanceIdentifier<ServiceFunctionPaths> sfpsIID = InstanceIdentifier.builder(ServiceFunctionPaths.class).toInstance();
- if (odlSfc.getDataProvider() != null) {
- ReadOnlyTransaction readTx = odlSfc.getDataProvider().newReadOnlyTransaction();
+ if (dataBroker != null) {
+ ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction();
Optional<ServiceFunctionPaths> serviceFunctionPathsDataObject = null;
try {
serviceFunctionPathsDataObject = readTx.read(LogicalDatastoreType.CONFIGURATION, sfpsIID).get();
} catch (InterruptedException | ExecutionException e) {
- e.printStackTrace();
+ LOG.error("Could not read top-level Service Function Path " +
+ "container \n");
}
if (serviceFunctionPathsDataObject != null
&& serviceFunctionPathsDataObject.isPresent()) {
sfps = serviceFunctionPathsDataObject.get();
}
}
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
return sfps;
}
protected boolean deleteAllServiceFunctionPaths() {
boolean ret = false;
- LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStart(LOG);
if (odlSfc.getDataProvider() != null) {
- InstanceIdentifier<ServiceFunctionPaths> sfpsIID = InstanceIdentifier.builder(ServiceFunctionPaths.class).toInstance();
+ InstanceIdentifier<ServiceFunctionPaths> sfpsIID =
+ InstanceIdentifier.builder(ServiceFunctionPaths.class).toInstance();
WriteTransaction writeTx = odlSfc.getDataProvider().newWriteOnlyTransaction();
writeTx.delete(LogicalDatastoreType.CONFIGURATION, sfpsIID);
writeTx.commit();
-
ret = true;
}
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
return ret;
}
// TODO:Needs change
private void deleteServicePathInstantiatedFromChain (ServiceFunctionPath serviceFunctionPath) {
- LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStart(LOG);
ServiceFunctionChain serviceFunctionChain = null;
String serviceChainName = serviceFunctionPath.getServiceChainName();
try {
new Class[]{String.class})).get()
: null;
} catch (InterruptedException | ExecutionException e) {
- e.printStackTrace();
+ LOG.error("\n Could not read Service Function Chain configuration");
}
if (serviceFunctionChain == null) {
LOG.error("\n########## ServiceFunctionChain name for Path {} not provided",
try {
serviceFunctionChainStateObject = readTx.read(LogicalDatastoreType.OPERATIONAL, sfcStateIID).get();
} catch (InterruptedException | ExecutionException e) {
- e.printStackTrace();
+ LOG.error("\n Could not read Service Function Chain operational data \n");
}
// TODO: Remove path name from Service Function path list
if (serviceFunctionChainStateObject instanceof ServiceFunctionChainState) {
} else {
LOG.error("Failed to get reference to Service Function Chain State {} ", serviceFunctionChain.getName());
}
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
}
@SuppressWarnings("unused")
*/
protected void createServiceFunctionPathEntry (ServiceFunctionPath serviceFunctionPath) {
- LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStart(LOG);
long pathId;
- short pos_index = 0;
- int service_index;
- ServiceFunctionChain serviceFunctionChain;
- serviceFunctionChain = null;
+ short posIndex = 0;
+ int serviceIndex;
+ ServiceFunctionChain serviceFunctionChain = null;
String serviceFunctionChainName = serviceFunctionPath.getServiceChainName();
try {
serviceFunctionChain = serviceFunctionChainName != null ?
new Class[]{String.class})).get()
: null;
} catch (InterruptedException | ExecutionException e) {
- e.printStackTrace();
+ LOG.error(" \n Could not read Service Function Chain configuration for Service Path {}",
+ serviceFunctionPath.getName());
}
if (serviceFunctionChain == null) {
- LOG.error("\n########## ServiceFunctionChain name for Path {} not provided",
+ LOG.error("\n ServiceFunctionChain name for Path {} not provided",
serviceFunctionPath.getName());
return;
}
* For each ServiceFunction type in the list of ServiceFunctions we select a specific
* service function from the list of service functions by type.
*/
- List<SfcServiceFunction> SfcServiceFunctionList = serviceFunctionChain.getSfcServiceFunction();
- service_index = SfcServiceFunctionList.size();
- for (SfcServiceFunction sfcServiceFunction : SfcServiceFunctionList) {
+ List<SfcServiceFunction> sfcServiceFunctionList = serviceFunctionChain.getSfcServiceFunction();
+ serviceIndex = sfcServiceFunctionList.size();
+ for (SfcServiceFunction sfcServiceFunction : sfcServiceFunctionList) {
LOG.debug("\n########## ServiceFunction name: {}", sfcServiceFunction.getName());
/*
* we do not hit NULL Pointer exceptions
*/
- ServiceFunctionType serviceFunctionType = null;
+ ServiceFunctionType serviceFunctionType;
try {
serviceFunctionType = (ServiceFunctionType) odlSfc.executor.submit(SfcProviderServiceTypeAPI.getRead(
new Object[]{sfcServiceFunction.getType()}, new Class[]{String.class})).get();
} catch (InterruptedException | ExecutionException e) {
- e.printStackTrace();
+ LOG.error(" Could not get list of Service Functions of type {} \n", sfcServiceFunction.getType());
+ return;
}
if (serviceFunctionType != null) {
List<SftServiceFunctionName> sftServiceFunctionNameList = serviceFunctionType.getSftServiceFunctionName();
(ServiceFunction) odlSfc.executor.submit(SfcProviderServiceFunctionAPI
.getRead(new Object[]{serviceFunctionName}, new Class[]{String.class})).get();
} catch (InterruptedException | ExecutionException e) {
- e.printStackTrace();
+ LOG.error(" Could not read Service Function {} " +
+ "\n", serviceFunctionName);
}
if (serviceFunction != null) {
- servicePathHopBuilder.setHopNumber(pos_index)
+ servicePathHopBuilder.setHopNumber(posIndex)
.setServiceFunctionName(serviceFunctionName)
- .setServiceIndex((short) service_index)
+ .setServiceIndex((short) serviceIndex)
.setServiceFunctionForwarder(serviceFunction.getSfDataPlaneLocator()
- .get(0).getServiceFunctionForwarder());
- servicePathHopArrayList.add(pos_index, servicePathHopBuilder.build());
- service_index--;
- pos_index++;
+ .get(0)
+ .getServiceFunctionForwarder());
+ servicePathHopArrayList.add(posIndex, servicePathHopBuilder.build());
+ serviceIndex--;
+ posIndex++;
break;
} else {
LOG.error("\n####### Could not find suitable SF of type in data store: {}",
//SfcProviderServiceForwarderAPI.addPathIdtoServiceFunctionForwarder(newServiceFunctionPath);
SfcProviderServiceFunctionAPI.addPathToServiceFunctionState(newServiceFunctionPath);
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
}
@SuppressWarnings("unused")
private void deleteServicePathContainingFunction (ServiceFunction serviceFunction) {
- LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStart(LOG);
InstanceIdentifier<ServiceFunctionPath> sfpIID;
ServiceFunctionState serviceFunctionState;
try {
serviceFunctionStateObject = readTx.read(LogicalDatastoreType.OPERATIONAL, sfStateIID).get();
} catch (InterruptedException | ExecutionException e) {
- e.printStackTrace();
+ LOG.error("Could not read Service Function State operational data \n");
+ return;
}
if ((serviceFunctionStateObject != null) &&
} else {
LOG.warn("Failed to get reference to Service Function State {} ", serviceFunction.getName());
}
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
}
*/
private void updateServicePathContainingFunction (ServiceFunction serviceFunction) {
- LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStart(LOG);
InstanceIdentifier<ServiceFunctionPath> sfpIID;
Optional<ServiceFunctionPath> serviceFunctionPathObject = null;
try {
serviceFunctionPathObject = readTx.read(LogicalDatastoreType.CONFIGURATION, sfpIID).get();
+ if (serviceFunctionPathObject != null &&
+ (serviceFunctionPathObject.get() instanceof ServiceFunctionPath)) {
+ ServiceFunctionPath servicefunctionPath = serviceFunctionPathObject.get();
+ createServiceFunctionPathEntry(servicefunctionPath);
+ }
} catch (InterruptedException | ExecutionException e) {
- e.printStackTrace();
- }
-
- if (serviceFunctionPathObject != null &&
- (serviceFunctionPathObject.get() instanceof ServiceFunctionPath)) {
- ServiceFunctionPath servicefunctionPath = serviceFunctionPathObject.get();
- createServiceFunctionPathEntry(servicefunctionPath);
+ LOG.error("Could not read Service Function Path configuration data \n");
}
}
} else {
LOG.error("Failed to get reference to Service Function State {} ", serviceFunction.getName());
}
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
+ return;
}
}
import java.util.concurrent.ExecutionException;
+import static org.opendaylight.sfc.provider.SfcProviderDebug.printTraceStart;
+import static org.opendaylight.sfc.provider.SfcProviderDebug.printTraceStop;
+
/**
* This class has the APIs to operate on the ServiceFunctionType
* datastore.
protected boolean putServiceFunctionType(ServiceFunctionType sft) {
boolean ret = false;
- LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStart(LOG);
if (dataBroker != null) {
InstanceIdentifier<ServiceFunctionType> sftEntryIID = InstanceIdentifier.builder(ServiceFunctionTypes.class)
ret = true;
}
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
return ret;
}
protected ServiceFunctionType readServiceFunctionType(String serviceFunctionTypeName) {
- LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStart(LOG);
ServiceFunctionType sft = null;
InstanceIdentifier<ServiceFunctionType> sftIID;
- ServiceFunctionTypeKey serviceFunctionTypeKey = new ServiceFunctionTypeKey(serviceFunctionTypeName);
+ ServiceFunctionTypeKey serviceFunctionTypeKey = new
+ ServiceFunctionTypeKey(serviceFunctionTypeName);
sftIID = InstanceIdentifier.builder(ServiceFunctionTypes.class)
.child(ServiceFunctionType.class, serviceFunctionTypeKey).build();
ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction();
Optional<ServiceFunctionType> serviceFunctionChainDataObject = null;
try {
- serviceFunctionChainDataObject = readTx.read(LogicalDatastoreType.CONFIGURATION, sftIID).get();
+ serviceFunctionChainDataObject = readTx
+ .read(LogicalDatastoreType.CONFIGURATION, sftIID).get();
} catch (InterruptedException | ExecutionException e) {
- e.printStackTrace();
+ LOG.error("Could not read Service Function list for Type {} " +
+ "", serviceFunctionTypeName);
}
if (serviceFunctionChainDataObject != null
&& serviceFunctionChainDataObject.isPresent()) {
sft = serviceFunctionChainDataObject.get();
}
}
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
return sft;
}
protected boolean deleteServiceFunctionType(String serviceFunctionTypeName) {
boolean ret = false;
- LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
- ServiceFunctionTypeKey serviceFunctionTypeKey = new ServiceFunctionTypeKey(serviceFunctionTypeName);
- InstanceIdentifier<ServiceFunctionType> sftEntryIID = InstanceIdentifier.builder(ServiceFunctionTypes.class)
+ printTraceStart(LOG);
+ ServiceFunctionTypeKey serviceFunctionTypeKey = new
+ ServiceFunctionTypeKey(serviceFunctionTypeName);
+ InstanceIdentifier<ServiceFunctionType> sftEntryIID =
+ InstanceIdentifier.builder(ServiceFunctionTypes.class)
.child(ServiceFunctionType.class, serviceFunctionTypeKey).toInstance();
if (dataBroker != null) {
WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction();
writeTx.delete(LogicalDatastoreType.CONFIGURATION, sftEntryIID);
writeTx.commit();
-
ret = true;
}
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
return ret;
}
protected boolean putAllServiceFunctionTypes(ServiceFunctionTypes sfts) {
boolean ret = false;
- LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStart(LOG);
if (dataBroker != null) {
- InstanceIdentifier<ServiceFunctionTypes> sftsIID = InstanceIdentifier.builder(ServiceFunctionTypes.class).toInstance();
-
+ InstanceIdentifier<ServiceFunctionTypes> sftsIID =
+ InstanceIdentifier.builder(ServiceFunctionTypes.class).toInstance();
WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction();
writeTx.merge(LogicalDatastoreType.CONFIGURATION, sftsIID, sfts);
writeTx.commit();
-
ret = true;
}
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
return ret;
}
protected ServiceFunctionTypes readAllServiceFunctionTypes() {
ServiceFunctionTypes sfts = null;
- LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
- InstanceIdentifier<ServiceFunctionTypes> sftsIID = InstanceIdentifier.builder(ServiceFunctionTypes.class).toInstance();
+ printTraceStart(LOG);
+ InstanceIdentifier<ServiceFunctionTypes> sftsIID =
+ InstanceIdentifier.builder(ServiceFunctionTypes.class).toInstance();
if (odlSfc.getDataProvider() != null) {
- ReadOnlyTransaction readTx = odlSfc.getDataProvider().newReadOnlyTransaction();
- Optional<ServiceFunctionTypes> serviceFunctionTypesDataObject = null;
+ ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction();
+ Optional<ServiceFunctionTypes> serviceFunctionTypesDataObject;
try {
- serviceFunctionTypesDataObject = readTx.read(LogicalDatastoreType.CONFIGURATION, sftsIID).get();
+ serviceFunctionTypesDataObject = readTx
+ .read(LogicalDatastoreType.CONFIGURATION, sftsIID).get();
+ if (serviceFunctionTypesDataObject != null
+ && serviceFunctionTypesDataObject.isPresent()) {
+ sfts = serviceFunctionTypesDataObject.get();
+ }
} catch (InterruptedException | ExecutionException e) {
- e.printStackTrace();
- }
- if (serviceFunctionTypesDataObject != null
- && serviceFunctionTypesDataObject.isPresent()) {
- sfts = serviceFunctionTypesDataObject.get();
+ LOG.error("Could not read Service Function Types");
}
}
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
return sfts;
}
protected boolean deleteAllServiceFunctionTypes() {
boolean ret = false;
- LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStart(LOG);
if (odlSfc.getDataProvider() != null) {
- InstanceIdentifier<ServiceFunctionTypes> sftsIID = InstanceIdentifier.builder(ServiceFunctionTypes.class).toInstance();
-
- WriteTransaction writeTx = odlSfc.getDataProvider().newWriteOnlyTransaction();
+ InstanceIdentifier<ServiceFunctionTypes> sftsIID =
+ InstanceIdentifier.builder(ServiceFunctionTypes.class).toInstance();
+ WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction();
writeTx.delete(LogicalDatastoreType.CONFIGURATION, sftsIID);
writeTx.commit();
-
ret = true;
}
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
return ret;
}
if (serviceFunctionTypeObject != null &&
(serviceFunctionTypeObject.get() instanceof ServiceFunctionType)) {
ServiceFunctionType serviceFunctionType = serviceFunctionTypeObject.get();
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
return serviceFunctionType;
} else {
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
return null;
}
}
public void createServiceFunctionTypeEntry(ServiceFunction serviceFunction) {
- LOG.debug("\n########## Start: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStart(LOG);
String sfkey = serviceFunction.getType();
ServiceFunctionTypeKey serviceFunctionTypeKey = new ServiceFunctionTypeKey(sfkey);
//Build the instance identifier all the way down to the bottom child
- SftServiceFunctionNameKey sftServiceFunctionNameKey = new SftServiceFunctionNameKey(serviceFunction.getName());
+ SftServiceFunctionNameKey sftServiceFunctionNameKey =
+ new SftServiceFunctionNameKey(serviceFunction.getName());
InstanceIdentifier<SftServiceFunctionName> sftentryIID;
sftentryIID = InstanceIdentifier.builder(ServiceFunctionTypes.class)
// Create a item in the list keyed by service function name
- SftServiceFunctionNameBuilder sftServiceFunctionNameBuilder = new SftServiceFunctionNameBuilder();
- sftServiceFunctionNameBuilder = sftServiceFunctionNameBuilder.setName(serviceFunction.getName());
- SftServiceFunctionName sftServiceFunctionName = sftServiceFunctionNameBuilder.build();
-
- WriteTransaction writeTx = odlSfc.getDataProvider().newWriteOnlyTransaction();
+ SftServiceFunctionNameBuilder sftServiceFunctionNameBuilder =
+ new SftServiceFunctionNameBuilder();
+ sftServiceFunctionNameBuilder = sftServiceFunctionNameBuilder
+ .setName(serviceFunction.getName());
+ SftServiceFunctionName sftServiceFunctionName =
+ sftServiceFunctionNameBuilder.build();
+
+ WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction();
writeTx.merge(LogicalDatastoreType.CONFIGURATION,
sftentryIID, sftServiceFunctionName, true);
writeTx.commit();
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
}
//Build the instance identifier all the way down to the bottom child
InstanceIdentifier<SftServiceFunctionName> sftentryIID;
- SftServiceFunctionNameKey sftServiceFunctionNameKey = new SftServiceFunctionNameKey(serviceFunction.getName());
+ SftServiceFunctionNameKey sftServiceFunctionNameKey =
+ new SftServiceFunctionNameKey(serviceFunction.getName());
sftentryIID = InstanceIdentifier.builder(ServiceFunctionTypes.class)
.child(ServiceFunctionType.class, serviceFunctionTypeKey)
.child(SftServiceFunctionName.class, sftServiceFunctionNameKey).build();
- WriteTransaction writeTx = odlSfc.getDataProvider().newWriteOnlyTransaction();
+ WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction();
writeTx.delete(LogicalDatastoreType.CONFIGURATION,
sftentryIID);
writeTx.commit();
- LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+ printTraceStop(LOG);
}
}
LOG.error("\n***** Configuration file {} not found, passing *****\n", filename);
continue;
} catch (IOException e) {
- e.printStackTrace();
+ LOG.error("\n***** Configuration file {} could not be" +
+ " read: {}", filename, e.getMessage());
break;
}
try {
package org.opendaylight.sfc.sfc_test_consumer;
+import org.opendaylight.controller.config.yang.config.sfc_test_consumer.impl.SfcTestConsumerRuntimeMXBean;
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sf.rev140701.*;
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sf.rev140701.service.function.entry.SfDataPlaneLocator;
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sf.rev140701.service.function.entry.SfDataPlaneLocatorBuilder;
-import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfc.rev140701.*;
-import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfc.rev140701.service.function.chain.grouping.*;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfc.rev140701.PutServiceFunctionChainsInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfc.rev140701.ServiceFunctionChainService;
+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.ServiceFunctionChainBuilder;
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.sfc.rev140701.service.function.chain.grouping.service.function.chain.SfcServiceFunctionBuilder;
-
-import org.opendaylight.controller.config.yang.config.sfc_test_consumer.impl.SfcTestConsumerRuntimeMXBean;
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sl.rev140701.data.plane.locator.locator.type.IpBuilder;
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sn.rev140701.PutServiceNodeInputBuilder;
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sn.rev140701.ServiceNodeService;
*/
private Boolean putSf(String name, String type,
String ipMgmt, String ipLocator, int portLocator) {
- LOG.info("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+ //printTraceStart(LOG);
// Build Locator Type (ip and port)
IpAddress ipAddress = new IpAddress(ipLocator.toCharArray());
} catch (Exception e) {
LOG.warn("\n####### {} Error occurred: {}", Thread.currentThread().getStackTrace()[1], e);
- e.printStackTrace();
return Boolean.FALSE;
}
}
String ip,
List<String> sfList) {
- LOG.info("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+ //printTraceStart(LOG);
PutServiceNodeInputBuilder input = new PutServiceNodeInputBuilder();
input.setName(name)
} catch (Exception e) {
LOG.warn("\n####### {} Error occurred: {}", Thread.currentThread().getStackTrace()[1], e);
- e.printStackTrace();
return Boolean.FALSE;
}
}
* @return Boolean
*/
private Boolean putChain(String name, List<SfcServiceFunction> sfList) {
- LOG.info("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+ //printTraceStart(LOG);
PutServiceFunctionChainsInputBuilder input = new PutServiceFunctionChainsInputBuilder();
ServiceFunctionChainBuilder sfcBuilder = new ServiceFunctionChainBuilder();
}
return result.isSuccessful();
} else {
- LOG.warn("\n####### {} result is NULL", Thread.currentThread().getStackTrace()[1]);
+ LOG.error("\n####### {} result is NULL", Thread.currentThread()
+ .getStackTrace()[1]);
return Boolean.FALSE;
}
} catch (Exception e) {
LOG.warn("\n####### {} Error occurred: {}", Thread.currentThread().getStackTrace()[1], e);
- e.printStackTrace();
return Boolean.FALSE;
}
}
*/
@Override
public Boolean testAPutSf() {
- LOG.info("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+ //printTraceStart(LOG);
return putSf("firewall-test", "firewall", "10.0.0.2", "192.168.0.2", 5050);
}
*/
@Override
public Boolean testAReadSf() {
- LOG.info("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+ //printTraceStart(LOG);
ReadServiceFunctionInputBuilder input = new ReadServiceFunctionInputBuilder();
input.setName("firewall-test");
*/
@Override
public Boolean testADeleteSf() {
- LOG.info("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+ //printTraceStart(LOG);
DeleteServiceFunctionInputBuilder input = new DeleteServiceFunctionInputBuilder();
input.setName("firewall-test");
LOG.warn("*****\ntestDeleteSf result is NULL");
}
} catch (Exception e) {
- LOG.warn("Error occurred during testDeleteSf: " + e);
- e.printStackTrace();
+ LOG.warn("Error occurred during testDeleteSf: " + e.getMessage());
}
return Boolean.FALSE;
}
*/
@Override
public Boolean testBPutSfs() {
- LOG.info("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+ //printTraceStart(LOG);
Boolean res = putSf("firewall-testB", "firewall", "10.0.0.101", "192.168.0.101", 5050);
res = putSf("dpi-testB", "dpi", "10.0.0.102", "192.168.0.102", 5050) && res;
*/
@Override
public Boolean testBPutSfc() {
- LOG.info("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+ //printTraceStart(LOG);
//Put a service chain. We need to build a list of lists.
PutServiceFunctionChainsInputBuilder putServiceFunctionChainsInputBuilder = new PutServiceFunctionChainsInputBuilder();
}
} catch (Exception e) {
- LOG.warn("\n####### {} Error occurred: {}", Thread.currentThread().getStackTrace()[1], e);
- e.printStackTrace();
+ LOG.warn("\n####### {} Error occurred: {}",
+ Thread.currentThread().getStackTrace()[1], e.getMessage());
return Boolean.FALSE;
}
@Override
public Boolean testBReadSfc() {
- LOG.info("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+ //printTraceStart(LOG);
return null;
}
@Override
public Boolean testBDeleteSfc() {
- LOG.info("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+ //printTraceStart(LOG);
return null;
}
@Override
public Boolean testCPutData() {
- LOG.info("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+ //printTraceStart(LOG);
// Service Functions (real, not abstract)
Boolean res = putSf("firewall-101-1", "firewall", "10.3.1.101", "10.3.1.101", 10001);
__author__ = "Reinaldo Penno"
__copyright__ = "Copyright(c) 2014, Cisco Systems, Inc."
__license__ = "New-style BSD"
-__version__ = "0.1"
+__version__ = "0.2"
-__status__ = "Tested with SFC-Karaf distribution as of 09/10/2014"
+__status__ = "Tested with SFC-Karaf distribution as of 10/05/2014"
import requests
import json
import time
+from sfc_basic_rest_regression_messages import *
putheaders = {'content-type': 'application/json'}
getheaders = {'Accept': 'application/json'}
# ODL IP:port
-ODLIP = "127.0.0.1:8181"
+ODLIP = "127.0.0.1:8181"
# Static URLs for testing
-GET_ALL_SF_URL = "http://" + ODLIP + "/restconf/config/service-function:service-functions/"
+GET_ALL_SF_URL = "http://" + ODLIP + "/restconf/config/service-function:service-functions/"
GET_ALL_SFC_URL = "http://" + ODLIP + "/restconf/config/service-function-chain:service-function-chains/"
GET_ALL_SFF_URL = "http://" + ODLIP + "/restconf/config/service-function-forwarder:service-function-forwarders/"
GET_ALL_SFT_URL = "http://" + ODLIP + "/restconf/config/service-function-type:service-function-types/"
GET_ALL_SFP_URL = "http://" + ODLIP + "/restconf/config/service-function-path:service-function-paths/"
PUT_ONE_SFP_URL = "http://" + ODLIP + "/restconf/config/service-function-path:service-function-paths/"
+PUT_SFC3_URL = "http://" + ODLIP + "/restconf/config/service-function-chain:service-function-chains/" \
+ "service-function-chain/SFC3/"
-GETURL = "http://" + ODLIP + "/restconf/config/service-function:service-functions/service-function/%d/"
+GETURL = "http://" + ODLIP + "/restconf/config/service-function:service-functions/service-function/%d/"
# Incremental PUT. This URL is for a list element
-PUTURL = "http://" + ODLIP + "/restconf/config/service-function:service-functions/service-function/%d/"
+PUTURL = "http://" + ODLIP + "/restconf/config/service-function:service-functions/service-function/%d/"
+
+USERNAME = "admin"
+PASSWORD = "admin"
def get_initial_sf():
s = requests.Session()
print ("GETTing initially configured Service Functions \n")
- r = s.get(GET_ALL_SF_URL, stream=False )
+ r = s.get(GET_ALL_SF_URL, stream=False, auth=(USERNAME, PASSWORD))
if (r.status_code == 200) and (json.loads(r.text) == json.loads(GET_ALL_SF_RESP_JSON)):
- print ("Success \n")
+ print ("=>Success \n")
else:
- print ("Failure to get SFs \n")
-
+ print ("=>Failure to get SFs \n")
def get_initial_sfc():
s = requests.Session()
print ("GETTing initially configured Service Functions Chains \n")
- r = s.get(GET_ALL_SFC_URL, stream=False)
+ r = s.get(GET_ALL_SFC_URL, stream=False, auth=(USERNAME, PASSWORD))
if (r.status_code == 200) and (json.loads(r.text) == json.loads(GET_ALL_SFC_RESP_JSON)):
- print ("Success \n")
+ print ("=>Success \n")
else:
- print ("Failure to get SFCs \n")
+ print ("=>Failure to get SFCs \n")
+
def get_initial_sff():
s = requests.Session()
print ("GETTing initially configured Service Functions Forwarders \n")
- r = s.get(GET_ALL_SFF_URL, stream=False)
+ r = s.get(GET_ALL_SFF_URL, stream=False, auth=(USERNAME, PASSWORD))
if (r.status_code == 200) and (json.loads(r.text) == json.loads(GET_ALL_SFF_RESP_JSON)):
- print ("Success \n")
+ print ("=>Success \n")
else:
- print ("Failure to get SFFs \n")
+ print ("=>Failure to get SFFs \n")
def get_initial_sft():
s = requests.Session()
print ("GETTing initially configured Service Functions Types \n")
- r = s.get(GET_ALL_SFT_URL, stream=False)
+ r = s.get(GET_ALL_SFT_URL, stream=False, auth=(USERNAME, PASSWORD))
if (r.status_code == 200) and (json.loads(r.text) == json.loads(GET_ALL_SFT_RESP_JSON)):
- print ("Success \n")
+ print ("=>Success \n")
else:
- print ("Failure to get SFTs \n")
+ print ("=>Failure to get SFTs \n")
+
def put_one_sfp():
s = requests.Session()
print ("PUTing a single SFP \n")
- r = s.put(PUT_ONE_SFP_URL, data=PUT_ONE_SFP_JSON, headers=putheaders, stream=False)
+ r = s.put(PUT_ONE_SFP_URL, data=PUT_ONE_SFP_JSON, headers=putheaders, stream=False, auth=(USERNAME, PASSWORD))
if r.status_code == 200:
print ("Checking created SFP \n")
# Creation of SFPs is slow, need to pause here.
time.sleep(2)
- r = s.get(GET_ALL_SFP_URL, stream=False)
+ r = s.get(GET_ALL_SFP_URL, stream=False, auth=(USERNAME, PASSWORD))
if (r.status_code == 200) and (json.loads(r.text) == json.loads(GET_ALL_SFP_RESP_JSON)):
- print ("SFP created successfully \n")
+ print ("=>SFP created successfully \n")
else:
- print ("Created SFP did not pass check - Failure \n")
+ print ("=>Created SFP did not pass check - Failure \n")
else:
- print ("Failed to create SFP \n")
-
-
-PUT_ONE_SFP_JSON = """
-{
- "service-function-paths": {
- "service-function-path": [
- {
- "name": "Path-1-SFC1",
- "service-chain-name": "SFC1"
- }
- ]
- }
-}"""
-
-GET_ALL_SFP_RESP_JSON = """
-{
- "service-function-paths": {
- "service-function-path": [
- {
- "name": "Path-1-SFC1",
- "path-id": 1,
- "starting-index": 3,
- "service-chain-name": "SFC1",
- "service-path-hop": [
- {
- "hop-number": 0,
- "service-function-name": "dpi-102-1",
- "service_index": 3,
- "service-function-forwarder": "SFF-bootstrap"
- },
- {
- "hop-number": 1,
- "service-function-name": "napt44-104",
- "service_index": 2,
- "service-function-forwarder": "SFF-bootstrap"
- },
- {
- "hop-number": 2,
- "service-function-name": "firewall-104",
- "service_index": 1,
- "service-function-forwarder": "SFF-bootstrap"
- }
- ]
- }
- ]
- }
-}"""
-
-GET_ALL_SF_RESP_JSON = """
-{
- "service-functions": {
- "service-function": [
- {
- "name": "firewall-104",
- "sf-data-plane-locator": [
- {
- "name": "my-locator",
- "service-function-forwarder": "SFF-bootstrap",
- "ip": "10.3.1.104",
- "port": 10001
- }
- ],
- "nsh-aware": true,
- "ip-mgmt-address": "10.3.1.104",
- "type": "firewall"
- },
- {
- "name": "napt44-104",
- "sf-data-plane-locator": [
- {
- "name": "3",
- "service-function-forwarder": "SFF-bootstrap",
- "ip": "10.3.1.104",
- "port": 10020
- }
- ],
- "nsh-aware": true,
- "ip-mgmt-address": "10.3.1.104",
- "type": "napt44"
- },
- {
- "name": "napt44-103-2",
- "sf-data-plane-locator": [
- {
- "name": "preferred",
- "service-function-forwarder": "SFF-bootstrap",
- "ip": "10.3.1.103",
- "port": 10002
- }
- ],
- "nsh-aware": true,
- "ip-mgmt-address": "10.3.1.103",
- "type": "napt44"
- },
- {
- "name": "napt44-103-1",
- "sf-data-plane-locator": [
- {
- "name": "master",
- "service-function-forwarder": "SFF-bootstrap",
- "ip": "10.3.1.103",
- "port": 10001
- }
- ],
- "nsh-aware": true,
- "ip-mgmt-address": "10.3.1.103",
- "type": "napt44"
- },
- {
- "name": "firewall-101-1",
- "sf-data-plane-locator": [
- {
- "name": "007",
- "service-function-forwarder": "SFF-bootstrap",
- "ip": "10.3.1.101",
- "port": 10001
- }
- ],
- "nsh-aware": true,
- "ip-mgmt-address": "10.3.1.101",
- "type": "firewall"
- },
- {
- "name": "dpi-102-3",
- "sf-data-plane-locator": [
- {
- "name": "101",
- "service-function-forwarder": "SFF-bootstrap",
- "ip": "10.3.1.102",
- "port": 10003
- }
- ],
- "nsh-aware": true,
- "ip-mgmt-address": "10.3.1.102",
- "type": "dpi"
- },
- {
- "name": "firewall-101-2",
- "sf-data-plane-locator": [
- {
- "name": "2",
- "service-function-forwarder": "SFF-bootstrap",
- "ip": "10.3.1.101",
- "port": 10002
- }
- ],
- "nsh-aware": true,
- "ip-mgmt-address": "10.3.1.101",
- "type": "firewall"
- },
- {
- "name": "dpi-102-2",
- "sf-data-plane-locator": [
- {
- "name": "1",
- "service-function-forwarder": "SFF-bootstrap",
- "ip": "10.3.1.102",
- "port": 10002
- }
- ],
- "nsh-aware": true,
- "ip-mgmt-address": "10.3.1.102",
- "type": "dpi"
- },
- {
- "name": "dpi-102-1",
- "sf-data-plane-locator": [
- {
- "name": "4",
- "service-function-forwarder": "SFF-bootstrap",
- "ip": "10.3.1.102",
- "port": 10001
- }
- ],
- "nsh-aware": true,
- "ip-mgmt-address": "10.3.1.102",
- "type": "dpi"
- }
- ]
- }
-}"""
+ print ("=>Failed to create SFP \n")
-GET_ALL_SFC_RESP_JSON = """
-{
- "service-function-chains": {
- "service-function-chain": [
- {
- "name": "SFC1",
- "sfc-service-function": [
- {
- "name": "dpi-abstract1",
- "type": "dpi"
- },
- {
- "name": "napt44-abstract1",
- "type": "napt44"
- },
- {
- "name": "firewall-abstract1",
- "type": "firewall"
- }
- ]
- },
- {
- "name": "SFC2",
- "sfc-service-function": [
- {
- "name": "firewall-abstract2",
- "type": "firewall"
- },
- {
- "name": "napt44-abstract2",
- "type": "napt44"
- }
- ]
- }
- ]
- }
-}"""
-
-GET_ALL_SFF_RESP_JSON = """
-{
- "service-function-forwarders": {
- "service-function-forwarder": [
- {
- "name": "SFF-bootstrap",
- "ovs": {
- "bridge-name": "br-int",
- "rest-uri": "http://www.example.com/sffs/sff-bootstrap",
- "uuid": "4c3778e4-840d-47f4-b45e-0988e514d26c"
- },
- "service-node": "OVSDB1",
- "sff-data-plane-locator": [
- {
- "name": "eth0",
- "data-plane-locator": {
- "port": 5000,
- "ip": "192.168.1.1",
- "transport": "service-locator:vxlan-gpe"
- }
- }
- ],
- "service-function-dictionary": [
- {
- "name": "SF1",
- "type": "dp1",
- "sff-sf-data-plane-locator": {
- "port": 5000,
- "ip": "10.1.1.1"
- }
- },
- {
- "name": "SF2",
- "type": "firewall",
- "sff-sf-data-plane-locator": {
- "port": 5000,
- "ip": "10.1.1.2"
- }
- }
- ],
- "classifier": "acl-sfp-1"
- },
- {
- "name": "br-int-ovs-2",
- "ovs": {
- "bridge-name": "br-int",
- "rest-uri": "http://www.example.com/sffs/br-int-ovs-2",
- "uuid": "fd4d849f-5140-48cd-bc60-6ad1f5fc0a0"
- },
- "service-node": "OVSDB2",
- "sff-data-plane-locator": [
- {
- "name": "eth0",
- "data-plane-locator": {
- "port": 5000,
- "ip": "192.168.1.2",
- "transport": "service-locator:vxlan-gpe"
- }
- }
- ],
- "service-function-dictionary": [
- {
- "name": "SF5",
- "type": "qos",
- "sff-sf-data-plane-locator": {
- "port": 5000,
- "ip": "10.1.1.5"
- }
- },
- {
- "name": "SF6",
- "type": "napt44",
- "sff-sf-data-plane-locator": {
- "port": 5000,
- "ip": "10.1.1.6"
- }
- }
- ]
- }
- ]
- }
-}"""
-
-GET_ALL_SFT_RESP_JSON = """
-{
- "service-function-types": {
- "service-function-type": [
- {
- "type": "dpi",
- "sft-service-function-name": [
- {
- "name": "dpi-102-1"
- },
- {
- "name": "dpi-102-2"
- },
- {
- "name": "dpi-102-3"
- }
- ]
- },
- {
- "type": "napt44",
- "sft-service-function-name": [
- {
- "name": "napt44-104"
- },
- {
- "name": "napt44-103-1"
- },
- {
- "name": "napt44-103-2"
- }
- ]
- },
- {
- "type": "firewall",
- "sft-service-function-name": [
- {
- "name": "firewall-104"
- },
- {
- "name": "firewall-101-2"
- },
- {
- "name": "firewall-101-1"
- }
- ]
- }
- ]
- }
-}"""
+def put_sfc3():
+ s = requests.Session()
+ print ("PUTing a single SFC \n")
+ r = s.put(PUT_SFC3_URL, data=PUT_SFC3_JSON, headers=putheaders, stream=False, auth=(USERNAME, PASSWORD))
+ if r.status_code == 200:
+ print ("Checking created SFC \n")
+ # Creation of SFPs is slow, need to pause here.
+ time.sleep(2)
+ r = s.get(GET_ALL_SFC_URL, stream=False, auth=(USERNAME, PASSWORD))
+ if (r.status_code == 200) and (json.loads(r.text) == json.loads(GET_ALL_SFC3_RESP_JSON)):
+ print ("=>SFC created successfully \n")
+ else:
+ print ("=>Created SFC did not pass check - Failure \n")
+ else:
+ print ("=>Failed to create SFC \n")
if __name__ == "__main__":
get_initial_sfc()
get_initial_sff()
get_initial_sft()
- put_one_sfp()
\ No newline at end of file
+ put_one_sfp()
+ put_sfc3()
--- /dev/null
+__author__ = "Reinaldo Penno"
+__copyright__ = "Copyright(c) 2014, Cisco Systems, Inc."
+__license__ = "New-style BSD"
+__version__ = "0.2"
+__status__ = "Tested with SFC-Karaf distribution as of 10/05/2014"
+
+PUT_ONE_SFP_JSON = """
+{
+ "service-function-paths": {
+ "service-function-path": [
+ {
+ "name": "Path-1-SFC1",
+ "service-chain-name": "SFC1"
+ }
+ ]
+ }
+}"""
+
+GET_ALL_SFP_RESP_JSON = """
+{
+ "service-function-paths": {
+ "service-function-path": [
+ {
+ "name": "Path-1-SFC1",
+ "path-id": 1,
+ "starting-index": 3,
+ "service-chain-name": "SFC1",
+ "service-path-hop": [
+ {
+ "hop-number": 0,
+ "service-function-name": "dpi-102-1",
+ "service_index": 3,
+ "service-function-forwarder": "SFF-bootstrap"
+ },
+ {
+ "hop-number": 1,
+ "service-function-name": "napt44-104",
+ "service_index": 2,
+ "service-function-forwarder": "SFF-bootstrap"
+ },
+ {
+ "hop-number": 2,
+ "service-function-name": "firewall-104",
+ "service_index": 1,
+ "service-function-forwarder": "SFF-bootstrap"
+ }
+ ]
+ }
+ ]
+ }
+}"""
+
+GET_ALL_SF_RESP_JSON = """
+{
+ "service-functions": {
+ "service-function": [
+ {
+ "name": "firewall-104",
+ "sf-data-plane-locator": [
+ {
+ "name": "my-locator",
+ "service-function-forwarder": "SFF-bootstrap",
+ "ip": "10.3.1.104",
+ "port": 10001
+ }
+ ],
+ "nsh-aware": true,
+ "ip-mgmt-address": "10.3.1.104",
+ "type": "firewall"
+ },
+ {
+ "name": "napt44-104",
+ "sf-data-plane-locator": [
+ {
+ "name": "3",
+ "service-function-forwarder": "SFF-bootstrap",
+ "ip": "10.3.1.104",
+ "port": 10020
+ }
+ ],
+ "nsh-aware": true,
+ "ip-mgmt-address": "10.3.1.104",
+ "type": "napt44"
+ },
+ {
+ "name": "napt44-103-2",
+ "sf-data-plane-locator": [
+ {
+ "name": "preferred",
+ "service-function-forwarder": "SFF-bootstrap",
+ "ip": "10.3.1.103",
+ "port": 10002
+ }
+ ],
+ "nsh-aware": true,
+ "ip-mgmt-address": "10.3.1.103",
+ "type": "napt44"
+ },
+ {
+ "name": "napt44-103-1",
+ "sf-data-plane-locator": [
+ {
+ "name": "master",
+ "service-function-forwarder": "SFF-bootstrap",
+ "ip": "10.3.1.103",
+ "port": 10001
+ }
+ ],
+ "nsh-aware": true,
+ "ip-mgmt-address": "10.3.1.103",
+ "type": "napt44"
+ },
+ {
+ "name": "firewall-101-1",
+ "sf-data-plane-locator": [
+ {
+ "name": "007",
+ "service-function-forwarder": "SFF-bootstrap",
+ "ip": "10.3.1.101",
+ "port": 10001
+ }
+ ],
+ "nsh-aware": true,
+ "ip-mgmt-address": "10.3.1.101",
+ "type": "firewall"
+ },
+ {
+ "name": "dpi-102-3",
+ "sf-data-plane-locator": [
+ {
+ "name": "101",
+ "service-function-forwarder": "SFF-bootstrap",
+ "ip": "10.3.1.102",
+ "port": 10003
+ }
+ ],
+ "nsh-aware": true,
+ "ip-mgmt-address": "10.3.1.102",
+ "type": "dpi"
+ },
+ {
+ "name": "firewall-101-2",
+ "sf-data-plane-locator": [
+ {
+ "name": "2",
+ "service-function-forwarder": "SFF-bootstrap",
+ "ip": "10.3.1.101",
+ "port": 10002
+ }
+ ],
+ "nsh-aware": true,
+ "ip-mgmt-address": "10.3.1.101",
+ "type": "firewall"
+ },
+ {
+ "name": "dpi-102-2",
+ "sf-data-plane-locator": [
+ {
+ "name": "1",
+ "service-function-forwarder": "SFF-bootstrap",
+ "ip": "10.3.1.102",
+ "port": 10002
+ }
+ ],
+ "nsh-aware": true,
+ "ip-mgmt-address": "10.3.1.102",
+ "type": "dpi"
+ },
+ {
+ "name": "dpi-102-1",
+ "sf-data-plane-locator": [
+ {
+ "name": "4",
+ "service-function-forwarder": "SFF-bootstrap",
+ "ip": "10.3.1.102",
+ "port": 10001
+ }
+ ],
+ "nsh-aware": true,
+ "ip-mgmt-address": "10.3.1.102",
+ "type": "dpi"
+ }
+ ]
+ }
+}"""
+
+GET_ALL_SFC_RESP_JSON = """
+{
+ "service-function-chains": {
+ "service-function-chain": [
+ {
+ "name": "SFC1",
+ "sfc-service-function": [
+ {
+ "name": "dpi-abstract1",
+ "type": "dpi"
+ },
+ {
+ "name": "napt44-abstract1",
+ "type": "napt44"
+ },
+ {
+ "name": "firewall-abstract1",
+ "type": "firewall"
+ }
+ ]
+ },
+ {
+ "name": "SFC2",
+ "sfc-service-function": [
+ {
+ "name": "firewall-abstract2",
+ "type": "firewall"
+ },
+ {
+ "name": "napt44-abstract2",
+ "type": "napt44"
+ }
+ ]
+ }
+ ]
+ }
+}"""
+
+
+GET_ALL_SFF_RESP_JSON = """
+{
+ "service-function-forwarders": {
+ "service-function-forwarder": [
+ {
+ "name": "SFF-bootstrap",
+ "service-function-forwarder-ovs:ovs": {
+ "bridge-name": "br-int",
+ "rest-uri": "http://www.example.com/sffs/sff-bootstrap",
+ "uuid": "4c3778e4-840d-47f4-b45e-0988e514d26c"
+ },
+ "service-node": "OVSDB1",
+ "sff-data-plane-locator": [
+ {
+ "name": "eth0",
+ "data-plane-locator": {
+ "port": 5000,
+ "ip": "192.168.1.1",
+ "transport": "service-locator:vxlan-gpe"
+ }
+ }
+ ],
+ "service-function-dictionary": [
+ {
+ "name": "SF1",
+ "type": "dp1",
+ "sff-sf-data-plane-locator": {
+ "port": 5000,
+ "ip": "10.1.1.1"
+ }
+ },
+ {
+ "name": "SF2",
+ "type": "firewall",
+ "sff-sf-data-plane-locator": {
+ "port": 5000,
+ "ip": "10.1.1.2"
+ }
+ }
+ ],
+ "classifier": "acl-sfp-1"
+ },
+ {
+ "name": "br-int-ovs-2",
+ "service-function-forwarder-ovs:ovs": {
+ "bridge-name": "br-int",
+ "rest-uri": "http://www.example.com/sffs/br-int-ovs-2",
+ "uuid": "fd4d849f-5140-48cd-bc60-6ad1f5fc0a0"
+ },
+ "service-node": "OVSDB2",
+ "sff-data-plane-locator": [
+ {
+ "name": "eth0",
+ "data-plane-locator": {
+ "port": 5000,
+ "ip": "192.168.1.2",
+ "transport": "service-locator:vxlan-gpe"
+ }
+ }
+ ],
+ "service-function-dictionary": [
+ {
+ "name": "SF5",
+ "type": "qos",
+ "sff-sf-data-plane-locator": {
+ "port": 5000,
+ "ip": "10.1.1.5"
+ }
+ },
+ {
+ "name": "SF6",
+ "type": "napt44",
+ "sff-sf-data-plane-locator": {
+ "port": 5000,
+ "ip": "10.1.1.6"
+ }
+ }
+ ]
+ }
+ ]
+ }
+}"""
+
+GET_ALL_SFT_RESP_JSON = """
+{
+ "service-function-types": {
+ "service-function-type": [
+ {
+ "type": "dpi",
+ "sft-service-function-name": [
+ {
+ "name": "dpi-102-1"
+ },
+ {
+ "name": "dpi-102-2"
+ },
+ {
+ "name": "dpi-102-3"
+ }
+ ]
+ },
+ {
+ "type": "napt44",
+ "sft-service-function-name": [
+ {
+ "name": "napt44-104"
+ },
+ {
+ "name": "napt44-103-1"
+ },
+ {
+ "name": "napt44-103-2"
+ }
+ ]
+ },
+ {
+ "type": "firewall",
+ "sft-service-function-name": [
+ {
+ "name": "firewall-104"
+ },
+ {
+ "name": "firewall-101-2"
+ },
+ {
+ "name": "firewall-101-1"
+ }
+ ]
+ }
+ ]
+ }
+}"""
+
+PUT_SFC3_JSON = """
+{
+ "service-function-chain": [
+ {
+ "name": "SFC3",
+ "sfc-service-function" : [
+ {
+ "name" : "Chain-3-service-1",
+ "type" : "dpi"
+ },
+ {
+ "name" : "Chain-3-service-2",
+ "type" : "qos"
+ },
+ {
+ "name" : "Chain-3-service-3",
+ "type" : "firewall"
+ }
+ ]
+ }
+ ]
+}"""
+
+GET_ALL_SFC3_RESP_JSON = """
+{
+ "service-function-chains": {
+ "service-function-chain": [
+ {
+ "name": "SFC1",
+ "sfc-service-function": [
+ {
+ "name": "dpi-abstract1",
+ "type": "dpi"
+ },
+ {
+ "name": "napt44-abstract1",
+ "type": "napt44"
+ },
+ {
+ "name": "firewall-abstract1",
+ "type": "firewall"
+ }
+ ]
+ },
+ {
+ "name": "SFC2",
+ "sfc-service-function": [
+ {
+ "name": "firewall-abstract2",
+ "type": "firewall"
+ },
+ {
+ "name": "napt44-abstract2",
+ "type": "napt44"
+ }
+ ]
+ },
+ {
+ "name": "SFC3",
+ "sfc-service-function": [
+ {
+ "name": "Chain-3-service-3",
+ "type": "firewall"
+ },
+ {
+ "name": "Chain-3-service-2",
+ "type": "qos"
+ },
+ {
+ "name": "Chain-3-service-1",
+ "type": "dpi"
+ }
+ ]
+ }
+ ]
+ }
+}"""
+
+