Overall hardening of the code 69/11869/1
authorReinaldo Penno <[email protected]>
Mon, 6 Oct 2014 18:32:21 +0000 (11:32 -0700)
committerReinaldo Penno <[email protected]>
Fri, 10 Oct 2014 06:37:13 +0000 (06:37 +0000)
- Overall hardening of the code
- Expansion of regression testing

Change-Id: Ib62aae644d85e47ee8c14fc8566556db413082aa
Signed-off-by: Reinaldo Penno <[email protected]>
(cherry picked from commit 0ed2f0614b0076e3fbe22b2beedae52df0b9c28e)

21 files changed:
sfc-provider/src/main/java/org/opendaylight/controller/config/yang/config/sfc_provider/impl/SfcProviderModule.java
sfc-provider/src/main/java/org/opendaylight/sfc/provider/OpendaylightSfc.java
sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcProviderAbstractRestAPI.java
sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcProviderDebug.java
sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcProviderRestAPI.java
sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcProviderRpc.java
sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcProviderSfEntryDataListener.java
sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcProviderSfcDataListener.java
sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcProviderSfcEntryDataListener.java
sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcProviderSfsDataListener.java
sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcProviderUnitTest.java
sfc-provider/src/main/java/org/opendaylight/sfc/provider/api/SfcProviderAbstractAPI.java
sfc-provider/src/main/java/org/opendaylight/sfc/provider/api/SfcProviderServiceChainAPI.java
sfc-provider/src/main/java/org/opendaylight/sfc/provider/api/SfcProviderServiceForwarderAPI.java
sfc-provider/src/main/java/org/opendaylight/sfc/provider/api/SfcProviderServiceFunctionAPI.java
sfc-provider/src/main/java/org/opendaylight/sfc/provider/api/SfcProviderServicePathAPI.java
sfc-provider/src/main/java/org/opendaylight/sfc/provider/api/SfcProviderServiceTypeAPI.java
sfc-provider/src/main/java/org/opendaylight/sfc/provider/bootstrap/SfcProviderBootstrapRestAPI.java
sfc-test-consumer/src/main/java/org/opendaylight/sfc/sfc_test_consumer/SfcTestConsumerImpl.java
sfc-test/sfc_basic_rest_regression.py
sfc-test/sfc_basic_rest_regression_messages.py [new file with mode: 0644]

index 13c20fcff325f414abed8a5013f786685034b676..2f212fb40ab9eaf98e8872fcedf4da3c2834788d 100755 (executable)
@@ -22,6 +22,7 @@ import org.opendaylight.yangtools.concepts.ListenerRegistration;
 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;
@@ -72,19 +73,12 @@ public class SfcProviderModule extends org.opendaylight.controller.config.yang.c
 
         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 =
@@ -114,16 +108,6 @@ public class SfcProviderModule extends org.opendaylight.controller.config.yang.c
                 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()
@@ -144,22 +128,27 @@ public class SfcProviderModule extends org.opendaylight.controller.config.yang.c
         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);
             }
         }
 
index 0a208a6113594561ca805d7630dce451e85edf40..8f7482da39ca24a5d4b449d4018f63c69e19358e 100755 (executable)
@@ -7,11 +7,9 @@
  */
 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;
@@ -22,18 +20,12 @@ import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfp.rev1407
 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
@@ -81,19 +73,12 @@ public class OpendaylightSfc implements AutoCloseable {
     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;
     }
index 864591ac042090265e301f5d7be0b5a07799eb4c..9ccdce57013616a6ad7ea328f9793cd9f6bc9cd4 100755 (executable)
@@ -8,6 +8,9 @@
 
 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;
@@ -23,28 +26,62 @@ 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());
             }
         }
     }
index c27171b8366f7f9c8b057e908e9ddc2bc515a175..71211479c00896d56617a85bd90e222461b77caa 100644 (file)
@@ -8,8 +8,10 @@
 
 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:
  *
@@ -24,5 +26,52 @@ package org.opendaylight.sfc.provider;
  */
 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
index deb01cfb8adf94d3e9f238fe37d54a8e867f1328..561e0fa6c6b4308c1c890df469f508f796ba7e38 100755 (executable)
@@ -10,6 +10,7 @@ package org.opendaylight.sfc.provider;
 
 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;
@@ -30,6 +31,8 @@ import org.slf4j.LoggerFactory;
 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);
@@ -42,23 +45,42 @@ public class SfcProviderRestAPI extends SfcProviderAbstractRestAPI {
 
         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();
 
     }
@@ -70,14 +92,18 @@ public class SfcProviderRestAPI extends SfcProviderAbstractRestAPI {
 
         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);
index 85a7ee14bab3426354b6de2bf557bbfc06fa56e8..55ad3795c79c43eb59ab4f370b38dd7b9e211678 100755 (executable)
@@ -10,6 +10,7 @@ package org.opendaylight.sfc.provider;
 
 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;
@@ -49,6 +50,9 @@ import java.util.Random;
 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.
@@ -66,32 +70,20 @@ public class SfcProviderRpc implements ServiceFunctionService,
     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();
@@ -102,10 +94,11 @@ public class SfcProviderRpc implements ServiceFunctionService,
                     .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();
@@ -113,32 +106,33 @@ public class SfcProviderRpc implements ServiceFunctionService,
         } 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();
@@ -146,49 +140,49 @@ public class SfcProviderRpc implements ServiceFunctionService,
                         .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) {
 
@@ -197,38 +191,33 @@ public class SfcProviderRpc implements ServiceFunctionService,
                 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()));
@@ -236,10 +225,10 @@ public class SfcProviderRpc implements ServiceFunctionService,
 
     @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)
@@ -251,26 +240,26 @@ public class SfcProviderRpc implements ServiceFunctionService,
             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();
@@ -279,7 +268,8 @@ public class SfcProviderRpc implements ServiceFunctionService,
                     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
@@ -298,7 +288,7 @@ public class SfcProviderRpc implements ServiceFunctionService,
 
                     ServiceFunctionPaths paths = buildServiceFunctionPaths(list);
 
-                    WriteTransaction writeTx = odlSfc.dataProvider.newWriteOnlyTransaction();
+                    WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction();
                     writeTx.merge(LogicalDatastoreType.CONFIGURATION,
                             OpendaylightSfc.sfpIID, paths, true);
                     writeTx.commit();
@@ -316,7 +306,7 @@ public class SfcProviderRpc implements ServiceFunctionService,
             }
 
         } 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()));
@@ -329,42 +319,19 @@ public class SfcProviderRpc implements ServiceFunctionService,
                         .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;
         }
     }
 
@@ -373,15 +340,15 @@ public class SfcProviderRpc implements ServiceFunctionService,
 
         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;
     }
index f1eda59f4ee66483dd9d727a90c604546124683a..660368dd5399ea0bfdb6d85a57fb2b1fdb0b8a62 100755 (executable)
@@ -22,6 +22,9 @@ import org.slf4j.LoggerFactory;
 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
@@ -41,8 +44,10 @@ public class SfcProviderSfEntryDataListener implements DataChangeListener  {
     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()) {
@@ -65,11 +70,6 @@ public class SfcProviderSfEntryDataListener implements DataChangeListener  {
                 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};
 
@@ -92,10 +92,6 @@ public class SfcProviderSfEntryDataListener implements DataChangeListener  {
                 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());
             }
@@ -115,20 +111,12 @@ public class SfcProviderSfEntryDataListener implements DataChangeListener  {
 
                 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);
     }
 
 }
index 0bf349d8576c2e9ffea227874688b9b90cebe64f..1f9359e87b715d89573f20e6f4923aefbe4b25f3 100644 (file)
@@ -21,6 +21,9 @@ import org.slf4j.LoggerFactory;
 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
@@ -40,62 +43,70 @@ public class SfcProviderSfcDataListener implements DataChangeListener {
     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);
     }
 }
index 9a8681cde1e8096491f83c80a69e0ba2c8fa5f70..e2b6736b49196ffb46777d5604de0e8ddb58c5b3 100755 (executable)
@@ -22,6 +22,9 @@ import java.util.List;
 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.,
@@ -41,7 +44,7 @@ public class SfcProviderSfcEntryDataListener implements DataChangeListener {
     public void onDataChanged(
             final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change ) {
 
-        LOG.debug("\n########## Start: {}", Thread.currentThread().getStackTrace()[1]);
+        printTraceStart(LOG);
 
         Map<InstanceIdentifier<?>, DataObject> dataOriginalConfigurationObject = change.getOriginalData();
 
@@ -50,8 +53,9 @@ public class SfcProviderSfcEntryDataListener implements DataChangeListener {
             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());
 
                 }
@@ -70,8 +74,8 @@ public class SfcProviderSfcEntryDataListener implements DataChangeListener {
                 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());
 
                 }
@@ -109,8 +113,7 @@ public class SfcProviderSfcEntryDataListener implements DataChangeListener {
             }
         }
 
-
-        LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+        printTraceStop(LOG);
     }
 
 
index d3041115afd4911ff2219cd9393db70328808db4..839746bca80f5f63b6091568e6c7afa476bc1ef4 100644 (file)
@@ -30,7 +30,6 @@ import org.slf4j.LoggerFactory;
 public class SfcProviderSfsDataListener implements DataChangeListener {
 
     private static final Logger LOG = LoggerFactory.getLogger(SfcProviderSfsDataListener.class);
-    private OpendaylightSfc odlSfc = OpendaylightSfc.getOpendaylightSfcObj();
 
     @Override
     public void onDataChanged(
index f3a5cc75909c850db8f595cf391ed2202aae5e48..5395c260aa2b50297f756086ff7f490592798543 100755 (executable)
@@ -9,20 +9,11 @@
 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;
@@ -30,6 +21,13 @@ 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.
@@ -41,6 +39,9 @@ import java.util.List;
  */
 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();
index 1c94442e892d5201ea2b992f18164850314a17f8..bf292d9b41a9e0c8e99f58174c59b9bac2d9ac4a 100755 (executable)
@@ -10,6 +10,8 @@ package org.opendaylight.sfc.provider.api;
 
 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;
@@ -26,17 +28,60 @@ import java.util.concurrent.Callable;
 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();
@@ -44,12 +89,12 @@ public abstract class SfcProviderAbstractAPI implements Callable<Object> {
     }
 
     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
@@ -62,7 +107,7 @@ public abstract class SfcProviderAbstractAPI implements Callable<Object> {
                 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;
index 8a9f722007806490228ce53759c5c2db24af94a6..22b80a066d10f52b4844bd5c873a094bc1a51c59 100755 (executable)
@@ -12,13 +12,10 @@ import com.google.common.base.Optional;
 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;
@@ -30,6 +27,10 @@ import org.slf4j.LoggerFactory;
 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.
@@ -86,55 +87,61 @@ public class SfcProviderServiceChainAPI extends SfcProviderAbstractAPI {
         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) {
@@ -144,16 +151,17 @@ public class SfcProviderServiceChainAPI extends SfcProviderAbstractAPI {
 
             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);
@@ -161,75 +169,85 @@ public class SfcProviderServiceChainAPI extends SfcProviderAbstractAPI {
 
             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);
@@ -239,36 +257,43 @@ public class SfcProviderServiceChainAPI extends SfcProviderAbstractAPI {
         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();
 
@@ -276,21 +301,23 @@ public class SfcProviderServiceChainAPI extends SfcProviderAbstractAPI {
         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();
 
@@ -298,15 +325,17 @@ public class SfcProviderServiceChainAPI extends SfcProviderAbstractAPI {
         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;
         }
     }
index 68b2739b949af1c0db51e21d19be1470da7932ac..210d4557b9fceb492bff434744b760c72aa1f402 100755 (executable)
@@ -36,6 +36,9 @@ import java.util.ArrayList;
 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.
@@ -103,7 +106,7 @@ public class SfcProviderServiceForwarderAPI extends SfcProviderAbstractAPI {
 
     /*
     public static ServiceFunctionForwarder readServiceFunctionForwarder(String name) {
-        LOG.debug("\n########## Start: {}", Thread.currentThread().getStackTrace()[1]);
+        printTraceStart(LOG)
         ServiceFunctionForwarderKey serviceFunctionForwarderKey =
                 new ServiceFunctionForwarderKey(name);
         InstanceIdentifier<ServiceFunctionForwarder> sffIID;
@@ -121,17 +124,17 @@ public class SfcProviderServiceForwarderAPI extends SfcProviderAbstractAPI {
 
         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();
@@ -169,7 +172,7 @@ public class SfcProviderServiceForwarderAPI extends SfcProviderAbstractAPI {
                 sffsIID, serviceFunctionForwardersBuilder.build(), true);
         writeTx.commit();
 
-        LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+        printTraceStop(LOG);
 
         //serviceFunctionForwardersBuilder.setServiceFunctionForwarder(serviceFunctionForwarderList);
 
@@ -180,18 +183,14 @@ public class SfcProviderServiceForwarderAPI extends SfcProviderAbstractAPI {
      * 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).
@@ -204,12 +203,12 @@ public class SfcProviderServiceForwarderAPI extends SfcProviderAbstractAPI {
 
             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);
@@ -220,22 +219,25 @@ public class SfcProviderServiceForwarderAPI extends SfcProviderAbstractAPI {
             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();
@@ -247,13 +249,13 @@ public class SfcProviderServiceForwarderAPI extends SfcProviderAbstractAPI {
 
             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 =
@@ -265,13 +267,13 @@ public class SfcProviderServiceForwarderAPI extends SfcProviderAbstractAPI {
 
             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();
 
@@ -279,34 +281,37 @@ public class SfcProviderServiceForwarderAPI extends SfcProviderAbstractAPI {
             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;
     }
 
@@ -315,7 +320,7 @@ public class SfcProviderServiceForwarderAPI extends SfcProviderAbstractAPI {
      */
     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();
@@ -342,15 +347,15 @@ public class SfcProviderServiceForwarderAPI extends SfcProviderAbstractAPI {
         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;
@@ -363,17 +368,17 @@ public class SfcProviderServiceForwarderAPI extends SfcProviderAbstractAPI {
                 .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);
 
@@ -382,7 +387,7 @@ public class SfcProviderServiceForwarderAPI extends SfcProviderAbstractAPI {
     @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
@@ -427,18 +432,19 @@ public class SfcProviderServiceForwarderAPI extends SfcProviderAbstractAPI {
 
                 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);
 
     }
 
@@ -453,7 +459,7 @@ public class SfcProviderServiceForwarderAPI extends SfcProviderAbstractAPI {
          */
 
 
-        LOG.debug("\n########## Start: {}", Thread.currentThread().getStackTrace()[1]);
+        printTraceStart(LOG);
 
         String serviceFunctionForwarderName = serviceFunction.getSfDataPlaneLocator()
                 .get(0).getServiceFunctionForwarder();
@@ -469,10 +475,10 @@ public class SfcProviderServiceForwarderAPI extends SfcProviderAbstractAPI {
         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);
     }
 }
index 7c1bc9ba1e22d222476710a651b9e34b0c1102a9..62db4bf71add2ec27db77deddc40c16c9ac0ec1d 100755 (executable)
@@ -30,6 +30,9 @@ import java.util.ArrayList;
 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.
@@ -85,7 +88,7 @@ public class SfcProviderServiceFunctionAPI extends SfcProviderAbstractAPI {
     }
 
     public static ServiceFunctionState readServiceFunctionState(String serviceFunctionName) {
-        LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+        printTraceStart(LOG);
 
         ServiceFunctionState serviceFunctionState;
         ServiceFunctionStateKey serviceFunctionStateKey =
@@ -99,23 +102,26 @@ public class SfcProviderServiceFunctionAPI extends SfcProviderAbstractAPI {
         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 =
@@ -135,7 +141,7 @@ public class SfcProviderServiceFunctionAPI extends SfcProviderAbstractAPI {
      */
     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<>();
@@ -155,13 +161,13 @@ public class SfcProviderServiceFunctionAPI extends SfcProviderAbstractAPI {
                     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).
@@ -174,13 +180,13 @@ public class SfcProviderServiceFunctionAPI extends SfcProviderAbstractAPI {
 
             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).
@@ -193,12 +199,12 @@ public class SfcProviderServiceFunctionAPI extends SfcProviderAbstractAPI {
 
             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);
@@ -210,21 +216,31 @@ public class SfcProviderServiceFunctionAPI extends SfcProviderAbstractAPI {
             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();
@@ -236,13 +252,13 @@ public class SfcProviderServiceFunctionAPI extends SfcProviderAbstractAPI {
 
             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();
@@ -253,35 +269,44 @@ public class SfcProviderServiceFunctionAPI extends SfcProviderAbstractAPI {
 
             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();
@@ -292,7 +317,7 @@ public class SfcProviderServiceFunctionAPI extends SfcProviderAbstractAPI {
 
             ret = true;
         }
-        LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+        printTraceStop(LOG);
         return ret;
     }
 
index 117f104ca1183b059eb32ada5b7c8c6b5b58ada8..5ed6a3fa73b5b6fbb7ad150a39835bf5139fe8e2 100755 (executable)
@@ -39,6 +39,9 @@ import java.util.List;
 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.
@@ -129,7 +132,7 @@ public class SfcProviderServicePathAPI extends SfcProviderAbstractAPI {
     @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).
@@ -142,12 +145,12 @@ public class SfcProviderServicePathAPI extends SfcProviderAbstractAPI {
 
             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);
@@ -158,22 +161,23 @@ public class SfcProviderServicePathAPI extends SfcProviderAbstractAPI {
             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();
@@ -185,16 +189,17 @@ public class SfcProviderServicePathAPI extends SfcProviderAbstractAPI {
 
             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);
@@ -202,46 +207,47 @@ public class SfcProviderServicePathAPI extends SfcProviderAbstractAPI {
 
             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;
     }
 
@@ -258,7 +264,7 @@ public class SfcProviderServicePathAPI extends SfcProviderAbstractAPI {
     // 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 {
@@ -269,7 +275,7 @@ public class SfcProviderServicePathAPI extends SfcProviderAbstractAPI {
                                     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",
@@ -292,7 +298,7 @@ public class SfcProviderServicePathAPI extends SfcProviderAbstractAPI {
         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) {
@@ -330,7 +336,7 @@ public class SfcProviderServicePathAPI extends SfcProviderAbstractAPI {
         } 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")
@@ -345,13 +351,12 @@ public class SfcProviderServicePathAPI extends SfcProviderAbstractAPI {
      */
     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 ?
@@ -361,10 +366,11 @@ public class SfcProviderServicePathAPI extends SfcProviderAbstractAPI {
                                     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;
         }
@@ -378,9 +384,9 @@ public class SfcProviderServicePathAPI extends SfcProviderAbstractAPI {
          * 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());
 
             /*
@@ -389,12 +395,13 @@ public class SfcProviderServicePathAPI extends SfcProviderAbstractAPI {
              * 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();
@@ -408,17 +415,19 @@ public class SfcProviderServicePathAPI extends SfcProviderAbstractAPI {
                                     (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: {}",
@@ -470,7 +479,7 @@ public class SfcProviderServicePathAPI extends SfcProviderAbstractAPI {
         //SfcProviderServiceForwarderAPI.addPathIdtoServiceFunctionForwarder(newServiceFunctionPath);
         SfcProviderServiceFunctionAPI.addPathToServiceFunctionState(newServiceFunctionPath);
 
-        LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+        printTraceStop(LOG);
 
     }
 
@@ -503,7 +512,7 @@ public class SfcProviderServicePathAPI extends SfcProviderAbstractAPI {
     @SuppressWarnings("unused")
     private void deleteServicePathContainingFunction (ServiceFunction serviceFunction) {
 
-        LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+        printTraceStart(LOG);
 
         InstanceIdentifier<ServiceFunctionPath> sfpIID;
         ServiceFunctionState serviceFunctionState;
@@ -519,7 +528,8 @@ public class SfcProviderServicePathAPI extends SfcProviderAbstractAPI {
         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) &&
@@ -552,7 +562,7 @@ public class SfcProviderServicePathAPI extends SfcProviderAbstractAPI {
         } else {
             LOG.warn("Failed to get reference to Service Function State {} ", serviceFunction.getName());
         }
-        LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+        printTraceStop(LOG);
     }
 
 
@@ -566,7 +576,7 @@ public class SfcProviderServicePathAPI extends SfcProviderAbstractAPI {
      */
     private void updateServicePathContainingFunction (ServiceFunction serviceFunction) {
 
-        LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+        printTraceStart(LOG);
 
         InstanceIdentifier<ServiceFunctionPath> sfpIID;
 
@@ -585,19 +595,19 @@ public class SfcProviderServicePathAPI extends SfcProviderAbstractAPI {
                 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;
     }
 }
index e1cc1f8d76380632519a2b51af5f34c7996e3ce9..8108e77e5f40e84ff09af9956273fdc4ccf1fa55 100755 (executable)
@@ -25,6 +25,9 @@ import org.slf4j.LoggerFactory;
 
 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.
@@ -88,7 +91,7 @@ public class SfcProviderServiceTypeAPI extends SfcProviderAbstractAPI {
 
     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)
@@ -101,15 +104,16 @@ public class SfcProviderServiceTypeAPI extends SfcProviderAbstractAPI {
 
             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();
 
@@ -117,90 +121,93 @@ public class SfcProviderServiceTypeAPI extends SfcProviderAbstractAPI {
             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;
     }
 
@@ -226,10 +233,10 @@ public class SfcProviderServiceTypeAPI extends SfcProviderAbstractAPI {
         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;
         }
     }
@@ -237,14 +244,15 @@ public class SfcProviderServiceTypeAPI extends SfcProviderAbstractAPI {
 
     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)
@@ -253,16 +261,19 @@ public class SfcProviderServiceTypeAPI extends SfcProviderAbstractAPI {
 
 
         // 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);
 
     }
 
@@ -274,16 +285,17 @@ public class SfcProviderServiceTypeAPI extends SfcProviderAbstractAPI {
 
         //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);
     }
 }
index 532ff69d405a38452a0a08ece87fd3ac7f00002c..01a0f0e31568953465be06532c1544b5500b1fa0 100755 (executable)
@@ -86,7 +86,8 @@ public class SfcProviderBootstrapRestAPI extends SfcProviderAbstractRestAPI {
                         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 {
index f39829c190b00a51b4e2338087d42b40230e6b94..c03ef3de5ad44f214c36895d23be20dc833103a9 100755 (executable)
@@ -8,15 +8,16 @@
 
 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;
@@ -87,7 +88,7 @@ public class SfcTestConsumerImpl implements SfcTestConsumer, SfcTestConsumerRunt
      */
     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());
@@ -128,7 +129,6 @@ public class SfcTestConsumerImpl implements SfcTestConsumer, SfcTestConsumerRunt
 
         } catch (Exception e) {
             LOG.warn("\n####### {} Error occurred: {}", Thread.currentThread().getStackTrace()[1], e);
-            e.printStackTrace();
             return Boolean.FALSE;
         }
     }
@@ -137,7 +137,7 @@ public class SfcTestConsumerImpl implements SfcTestConsumer, SfcTestConsumerRunt
                             String ip,
                             List<String> sfList) {
 
-        LOG.info("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+        //printTraceStart(LOG);
         PutServiceNodeInputBuilder input = new PutServiceNodeInputBuilder();
 
         input.setName(name)
@@ -161,7 +161,6 @@ public class SfcTestConsumerImpl implements SfcTestConsumer, SfcTestConsumerRunt
 
         } catch (Exception e) {
             LOG.warn("\n####### {} Error occurred: {}", Thread.currentThread().getStackTrace()[1], e);
-            e.printStackTrace();
             return Boolean.FALSE;
         }
     }
@@ -173,7 +172,7 @@ public class SfcTestConsumerImpl implements SfcTestConsumer, SfcTestConsumerRunt
      * @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();
 
@@ -195,13 +194,13 @@ public class SfcTestConsumerImpl implements SfcTestConsumer, SfcTestConsumerRunt
                 }
                 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;
         }
     }
@@ -214,7 +213,7 @@ public class SfcTestConsumerImpl implements SfcTestConsumer, SfcTestConsumerRunt
      */
     @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);
     }
 
@@ -226,7 +225,7 @@ public class SfcTestConsumerImpl implements SfcTestConsumer, SfcTestConsumerRunt
      */
     @Override
     public Boolean testAReadSf() {
-        LOG.info("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+        //printTraceStart(LOG);
         ReadServiceFunctionInputBuilder input = new ReadServiceFunctionInputBuilder();
         input.setName("firewall-test");
 
@@ -252,7 +251,7 @@ public class SfcTestConsumerImpl implements SfcTestConsumer, SfcTestConsumerRunt
      */
     @Override
     public Boolean testADeleteSf() {
-        LOG.info("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+        //printTraceStart(LOG);
         DeleteServiceFunctionInputBuilder input = new DeleteServiceFunctionInputBuilder();
         input.setName("firewall-test");
 
@@ -270,8 +269,7 @@ public class SfcTestConsumerImpl implements SfcTestConsumer, SfcTestConsumerRunt
                 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;
     }
@@ -284,7 +282,7 @@ public class SfcTestConsumerImpl implements SfcTestConsumer, SfcTestConsumerRunt
      */
     @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;
@@ -302,7 +300,7 @@ public class SfcTestConsumerImpl implements SfcTestConsumer, SfcTestConsumerRunt
      */
     @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();
@@ -339,8 +337,8 @@ public class SfcTestConsumerImpl implements SfcTestConsumer, SfcTestConsumerRunt
             }
 
         } 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;
         }
 
@@ -348,19 +346,19 @@ public class SfcTestConsumerImpl implements SfcTestConsumer, SfcTestConsumerRunt
 
     @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);
index 9955f882d9f9e053b484b40544a84634f5440c53..f979b8e4c5f8caa8e44570ad629af139727e9d2d 100644 (file)
 __author__ = "Reinaldo Penno"
 __copyright__ = "Copyright(c) 2014, Cisco Systems, Inc."
 __license__ = "New-style BSD"
-__version__ = "0.1"
+__version__ = "0.2"
 __email__ = "[email protected]"
-__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__":
@@ -441,4 +112,5 @@ 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()
diff --git a/sfc-test/sfc_basic_rest_regression_messages.py b/sfc-test/sfc_basic_rest_regression_messages.py
new file mode 100644 (file)
index 0000000..bb0f6bf
--- /dev/null
@@ -0,0 +1,438 @@
+__author__ = "Reinaldo Penno"
+__copyright__ = "Copyright(c) 2014, Cisco Systems, Inc."
+__license__ = "New-style BSD"
+__version__ = "0.2"
+__email__ = "[email protected]"
+__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"
+          }
+        ]
+      }
+    ]
+  }
+}"""
+
+