API classes changed to Callable 86/10286/1
authorKonstantin Blagov <[email protected]>
Tue, 26 Aug 2014 08:17:19 +0000 (10:17 +0200)
committerKonstantin Blagov <[email protected]>
Tue, 26 Aug 2014 08:17:19 +0000 (10:17 +0200)
Added put/read/delete methods
Applied new DataBroker transactions API
Added dependencies for unit testing
Outdated classes to instantiate a SFC moved to sub-package

Change-Id: I69758c6212e1c8be81cdefbac4e7ebda41ae786c
Signed-off-by: Konstantin Blagov <[email protected]>
15 files changed:
sfc-provider/pom.xml
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/SfcProviderAbstractAPI.java [new file with mode: 0755]
sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcProviderRpc.java
sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcProviderServiceChainAPI.java
sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcProviderServiceForwarderAPI.java
sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcProviderServiceFunctionAPI.java
sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcProviderServicePathAPI.java
sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcProviderServiceTypeAPI.java
sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcProviderSfEntryDataListener.java
sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcProviderSfcEntryDataListener.java
sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcProviderSfpEntryDataListener.java
sfc-provider/src/main/java/org/opendaylight/sfc/provider/util/SfcSftMapper.java [moved from sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcSftMapper.java with 83% similarity]
sfc-provider/src/main/java/org/opendaylight/sfc/provider/util/SfcSnMapper.java [moved from sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcSnMapper.java with 96% similarity]

index 0461940e05118eee49b375c0f4c0228542617334..e8997cdbb58ae12adf58f12eb3c8aa25b0012b00 100755 (executable)
             <artifactId>yang-common</artifactId>
             <version>${yangtools.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.opendaylight.controller</groupId>
+            <artifactId>sal-binding-broker-impl</artifactId>
+            <version>1.1-SNAPSHOT</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.controller</groupId>
+            <artifactId>sal-binding-broker-impl</artifactId>
+            <version>1.1-SNAPSHOT</version>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>org.sonatype.plugins</groupId>
             <artifactId>munge-maven-plugin</artifactId>
             <type>jar</type>
             <scope>compile</scope>
         </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <!-- version>4.8.1</version -->
+            <version>[4.8.1, 4.11]</version>
+            <!-- version>4.11</version -->
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>
                     </instructions>
                 </configuration>
             </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-jar-plugin</artifactId>
+                <version>2.4</version>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>test-jar</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-checkstyle-plugin</artifactId>
index 8088c3424d5e87a596cafcb721118eeddec9c446..d34bb9fd27e4ea7c8072bc7868d78b01e87c50bd 100755 (executable)
@@ -26,8 +26,17 @@ import org.opendaylight.sfc.provider.SfcProviderSnDataListener;
 import org.opendaylight.sfc.provider.bootstrap.SfcProviderBootstrapRestAPI;
 import org.opendaylight.sfc.provider.logback.SfcProviderLogbackLoader;
 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sf.rev140701.ServiceFunctionService;
+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.sf.rev140701.service.functions.ServiceFunction;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sf.rev140701.service.functions.ServiceFunctionBuilder;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sf.rev140701.service.functions.ServiceFunctionKey;
 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.sl.rev140701.data.plane.locator.locator.type.IpBuilder;
 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sn.rev140701.ServiceNodeService;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -173,6 +182,10 @@ public class SfcProviderModule extends org.opendaylight.controller.config.yang.c
         scheduledExecutorService.schedule
                 (SfcProviderBootstrapRestAPI.getPutBootstrapData(emptyObjArray, emptyClassArray), 15,
                         TimeUnit.SECONDS);
+
+        scheduledExecutorService.shutdown();
+
+
         LOG.info("SFC provider (instance {}) initialized.", ret);
         return ret;
     }
index c9e9d86871160ba92986b8c0d7e2a2e84d4e52de..98ff89428189990b0309bf4780564c7b13b5523b 100755 (executable)
@@ -78,7 +78,7 @@ public class OpendaylightSfc implements AutoCloseable {
     public static final InstanceIdentifier<ServiceFunctionTypes>  sftIID =
            InstanceIdentifier.builder(ServiceFunctionTypes.class).build();
 
-    protected ExecutorService executor;
+    public ExecutorService executor;
     protected DataBroker dataProvider;
     private static OpendaylightSfc opendaylightSfcObj;
 
@@ -99,7 +99,7 @@ public class OpendaylightSfc implements AutoCloseable {
        this.dataProvider = salDataProvider;
     }
 
-    public AsyncDataBroker getDataProvider(AsyncDataBroker salDataProvider) {
+    public DataBroker getDataProvider() {
         return this.dataProvider;
     }
 
diff --git a/sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcProviderAbstractAPI.java b/sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcProviderAbstractAPI.java
new file mode 100755 (executable)
index 0000000..0eed3bd
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.sfc.provider;
+
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.concurrent.Callable;
+
+/**
+ * <p/>
+ *
+ * @author Konstantin Blagov ([email protected])
+ * @version 0.1
+ * @since 2014-06-30
+ */
+public abstract class SfcProviderAbstractAPI implements Callable<Object> {
+
+    protected static final OpendaylightSfc odlSfc = OpendaylightSfc.getOpendaylightSfcObj();
+    protected String methodName = null;
+    protected Object[] parameters;
+    protected Class[] parameterTypes;
+    protected DataBroker dataBroker;
+
+    SfcProviderAbstractAPI(Object[] params, String m) {
+        this.methodName = m;
+        this.parameters = new Object[params.length];
+        this.parameterTypes = new Class[params.length];
+        this.parameters = Arrays.copyOf(params, params.length);
+        this.dataBroker = odlSfc.getDataProvider();
+
+        for (int i = 0; i < params.length; i++) {
+            this.parameterTypes[i] = params[i].getClass();
+        }
+    }
+
+    SfcProviderAbstractAPI(Object[] params, Class[] paramsTypes, String m) {
+        this.methodName = 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();
+    }
+
+    @Override
+    public final Object call() {
+        Object result = null;
+        if (methodName != null) {
+            Class<?> c = this.getClass();
+            Method method;
+            try {
+                method = c.getDeclaredMethod(methodName, parameterTypes);
+                result = method.invoke(this, parameters);
+            } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
+                e.printStackTrace();
+            }
+        }
+        return result;
+    }
+}
index 8eaa21ffb700a3cec8994c93ff007107349a1646..3a383e5b8191c63b59995ea6b97e2e71551e9f55 100755 (executable)
@@ -14,6 +14,7 @@ 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.controller.sal.common.util.Rpcs;
+import org.opendaylight.sfc.provider.util.SfcSftMapper;
 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;
index 890b3b95112f13c281313524bd1021f4500866ce..3cf30818318f9e76ed45ea483706914c72087167 100644 (file)
@@ -27,10 +27,7 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.concurrent.ExecutionException;
 
 /**
@@ -45,45 +42,169 @@ import java.util.concurrent.ExecutionException;
  *
  * <p>
  * @author Reinaldo Penno ([email protected])
+ * @author Konstantin Blagov ([email protected])
  * @version 0.1
  * @since       2014-06-30
  */
-public class SfcProviderServiceChainAPI implements Runnable {
+public class SfcProviderServiceChainAPI extends SfcProviderAbstractAPI {
 
-    private ServiceFunctionChain serviceFunctionChain;
     private static final Logger LOG = LoggerFactory.getLogger(SfcProviderServiceChainAPI.class);
-    private static final OpendaylightSfc odlSfc = OpendaylightSfc.getOpendaylightSfcObj();
-    private String methodName = null;
-    private Object[] parameters;
-    private Class[] parameterTypes;
-
-    SfcProviderServiceChainAPI (Object[] params, String m) {
-        int i = 0;
-        this.methodName = m;
-        this.parameters = new Object[params.length];
-        this.parameterTypes = new Class[params.length];
-        this.parameters = Arrays.copyOf(params, params.length);
-        for (Object obj : parameters) {
-            this.parameterTypes[i] = obj.getClass();
-            i++;
-        }
 
+    SfcProviderServiceChainAPI(Object[] params, String m) {
+        super(params, m);
+    }
+
+    SfcProviderServiceChainAPI(Object[] params, Class[] paramsTypes, String m) {
+        super(params, paramsTypes, m);
+    }
+
+    public static SfcProviderServiceChainAPI getPut(Object[] params, Class[] paramsTypes) {
+        return new SfcProviderServiceChainAPI(params, paramsTypes, "putServiceFunctionChain");
+    }
+
+    public static SfcProviderServiceChainAPI getRead(Object[] params, Class[] paramsTypes) {
+        return new SfcProviderServiceChainAPI(params, paramsTypes, "readServiceFunctionChain");
+    }
+
+    public static SfcProviderServiceChainAPI getDelete(Object[] params, Class[] paramsTypes) {
+        return new SfcProviderServiceChainAPI(params, paramsTypes, "deleteServiceFunctionChain");
+    }
+
+    public static SfcProviderServiceChainAPI getPutAll(Object[] params, Class[] paramsTypes) {
+        return new SfcProviderServiceChainAPI(params, paramsTypes, "putAllServiceFunctionChains");
+    }
+
+    public static SfcProviderServiceChainAPI getReadAll(Object[] params, Class[] paramsTypes) {
+        return new SfcProviderServiceChainAPI(params, paramsTypes, "readAllServiceFunctionChains");
     }
 
-    SfcProviderServiceChainAPI (Object[] params, Class[] paramsTypes, String m) {
-        this.methodName = 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);
+    public static SfcProviderServiceChainAPI getDeleteAll(Object[] params, Class[] paramsTypes) {
+        return new SfcProviderServiceChainAPI(params, paramsTypes, "deleteAllServiceFunctionChains");
     }
 
     public static  SfcProviderServiceChainAPI getAddChainToChainState (Object[] params, Class[] paramsTypes) {
         return new SfcProviderServiceChainAPI(params, paramsTypes, "addChainToChainState");
     }
 
-    @SuppressWarnings("unused")
-    private void addChainToChainState (ServiceFunctionChain serviceFunctionChain) {
+    protected boolean putServiceFunctionChain(ServiceFunctionChain sfc) {
+        boolean ret = false;
+        LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+        if (dataBroker != null) {
+
+            InstanceIdentifier<ServiceFunctionChain> sfcEntryIID = InstanceIdentifier.builder(ServiceFunctionChains.class).
+                    child(ServiceFunctionChain.class, sfc.getKey()).toInstance();
+
+            WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction();
+            writeTx.merge(LogicalDatastoreType.CONFIGURATION,
+                    sfcEntryIID, sfc, true);
+            writeTx.commit();
+
+            ret = true;
+        }
+        LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+        return ret;
+    }
+
+    protected ServiceFunctionChain readServiceFunctionChain(String serviceFunctionChainName) {
+        LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+        ServiceFunctionChain sfc = null;
+        InstanceIdentifier<ServiceFunctionChain> sfcIID;
+        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;
+            try {
+                serviceFunctionChainDataObject = readTx.read(LogicalDatastoreType.CONFIGURATION, sfcIID).get();
+            } catch (InterruptedException | ExecutionException e) {
+                e.printStackTrace();
+            }
+            if (serviceFunctionChainDataObject != null
+                    && serviceFunctionChainDataObject.isPresent()) {
+                sfc = serviceFunctionChainDataObject.get();
+            }
+        }
+        LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+        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)
+                .child(ServiceFunctionChain.class, serviceFunctionChainKey).toInstance();
+
+        if (dataBroker != null) {
+            WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction();
+            writeTx.delete(LogicalDatastoreType.CONFIGURATION, sfcEntryIID);
+            writeTx.commit();
+
+            ret = true;
+        }
+        LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+        return ret;
+    }
+
+    protected boolean putAllServiceFunctionChains(ServiceFunctionChains sfcs) {
+        boolean ret = false;
+        LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+        if (dataBroker != null) {
+
+            InstanceIdentifier<ServiceFunctionChains> sfcsIID = InstanceIdentifier.builder(ServiceFunctionChains.class).toInstance();
+
+            WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction();
+            writeTx.merge(LogicalDatastoreType.CONFIGURATION, sfcsIID, sfcs);
+            writeTx.commit();
+
+            ret = true;
+        }
+        LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+        return ret;
+    }
+
+    protected ServiceFunctionChains readAllServiceFunctionChains() {
+        ServiceFunctionChains sfcs = null;
+        LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+        InstanceIdentifier<ServiceFunctionChains> sfcsIID = InstanceIdentifier.builder(ServiceFunctionChains.class).toInstance();
+
+        if (odlSfc.getDataProvider() != null) {
+            ReadOnlyTransaction readTx = odlSfc.getDataProvider().newReadOnlyTransaction();
+            Optional<ServiceFunctionChains> serviceFunctionChainsDataObject = null;
+            try {
+                serviceFunctionChainsDataObject = readTx.read(LogicalDatastoreType.CONFIGURATION, sfcsIID).get();
+            } catch (InterruptedException | ExecutionException e) {
+                e.printStackTrace();
+            }
+            if (serviceFunctionChainsDataObject != null
+                    && serviceFunctionChainsDataObject.isPresent()) {
+                sfcs = serviceFunctionChainsDataObject.get();
+            }
+        }
+        LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+        return sfcs;
+    }
+
+    protected boolean deleteAllServiceFunctionChains() {
+        boolean ret = false;
+        LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+        if (odlSfc.getDataProvider() != null) {
+
+            InstanceIdentifier<ServiceFunctionChains> sfcsIID = InstanceIdentifier.builder(ServiceFunctionChains.class).toInstance();
+
+            WriteTransaction writeTx = odlSfc.getDataProvider().newWriteOnlyTransaction();
+            writeTx.delete(LogicalDatastoreType.CONFIGURATION, sfcsIID);
+            writeTx.commit();
+
+            ret = true;
+        }
+        LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+        return ret;
+    }
+
+    protected void addChainToChainState (ServiceFunctionChain serviceFunctionChain) {
 
         LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
         ServiceFunctionChainStateKey serviceFunctionChainStateKey = new ServiceFunctionChainStateKey(serviceFunctionChain.getName());
@@ -123,31 +244,6 @@ public class SfcProviderServiceChainAPI implements Runnable {
 
     }
 
-
-    public static ServiceFunctionChain readServiceFunctionChain(String serviceFunctionChainName) {
-        LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
-        InstanceIdentifier<ServiceFunctionChain> sfcIID;
-        ServiceFunctionChainKey serviceFunctionChainKey = new ServiceFunctionChainKey(serviceFunctionChainName);
-        sfcIID = InstanceIdentifier.builder(ServiceFunctionChains.class)
-                .child(ServiceFunctionChain.class, serviceFunctionChainKey).build();
-
-        ReadOnlyTransaction readTx = odlSfc.dataProvider.newReadOnlyTransaction();
-        Optional<ServiceFunctionChain> serviceFunctionChainObject = null;
-        try {
-            serviceFunctionChainObject = readTx.read(LogicalDatastoreType.CONFIGURATION, sfcIID).get();
-        } catch (InterruptedException | ExecutionException e) {
-            e.printStackTrace();
-        }
-
-        if (serviceFunctionChainObject.get() instanceof ServiceFunctionChain) {
-            LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
-            return serviceFunctionChainObject.get();
-        } else {
-            LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
-            return null;
-        }
-    }
-
     private InstanceIdentifier<SfcServiceFunction> getServiceFunctionIIDFromChain (ServiceFunctionChain sfc, ServiceFunction sf) {
         SfcServiceFunctionKey serviceFunctionKey = new SfcServiceFunctionKey(sf.getName());
         InstanceIdentifier<SfcServiceFunction> sfIID = InstanceIdentifier.builder(ServiceFunctionChains.class)
@@ -215,18 +311,4 @@ public class SfcProviderServiceChainAPI implements Runnable {
         }
     }
 
-    @Override
-    public void run() {
-        if (methodName != null) {
-            Class<?> c = this.getClass();
-            Method method;
-            try {
-                method = c.getDeclaredMethod(methodName, parameterTypes);
-                method.invoke(this, parameters);
-            } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
-                e.printStackTrace();
-            }
-        }
-
-    }
 }
index 55912fe3e65f9ee0859e34d5481c29ffe845b31b..454a063c2f513d34d6637aca41d238373118eeb7 100644 (file)
@@ -32,72 +32,285 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.List;
 import java.util.concurrent.ExecutionException;
 
 /**
  * This class has the APIs to operate on the ServiceFunction
  * datastore.
- *
+ * <p/>
  * It is normally called from onDataChanged() through a executor
  * service. We need to use an executor service because we can not
  * operate on a datastore while on onDataChanged() context.
- * @see org.opendaylight.sfc.provider.SfcProviderSfEntryDataListener
  *
- *
- * <p>
  * @author Reinaldo Penno ([email protected])
+ * @author Konstantin Blagov ([email protected])
  * @version 0.1
- * @since       2014-06-30
+ * @see org.opendaylight.sfc.provider.SfcProviderSfEntryDataListener
+ * <p/>
+ * <p/>
+ * <p/>
+ * @since 2014-06-30
  */
-public class SfcProviderServiceForwarderAPI implements Runnable {
+public class SfcProviderServiceForwarderAPI extends SfcProviderAbstractAPI {
     private static final Logger LOG = LoggerFactory.getLogger(SfcProviderServiceForwarderAPI.class);
-    private static final OpendaylightSfc odlSfc = OpendaylightSfc.getOpendaylightSfcObj();
-    private String methodName = null;
-    private Object[] parameters;
-    private Class[] parameterTypes;
-
-
-    SfcProviderServiceForwarderAPI (Object[] params, String m) {
-        int i = 0;
-        this.methodName = m;
-        this.parameters = new Object[params.length];
-        this.parameterTypes = new Class[params.length];
-        this.parameters = Arrays.copyOf(params, params.length);
-        for (Object obj : parameters) {
-            this.parameterTypes[i] = obj.getClass();
-            i++;
+
+    SfcProviderServiceForwarderAPI(Object[] params, String m) {
+        super(params, m);
+    }
+
+    SfcProviderServiceForwarderAPI(Object[] params, Class[] paramsTypes, String m) {
+        super(params, paramsTypes, m);
+    }
+
+
+    public static SfcProviderServiceForwarderAPI getPut(Object[] params, Class[] paramsTypes) {
+        return new SfcProviderServiceForwarderAPI(params, paramsTypes, "putServiceFunctionForwarder");
+    }
+
+    public static SfcProviderServiceForwarderAPI getRead(Object[] params, Class[] paramsTypes) {
+        return new SfcProviderServiceForwarderAPI(params, paramsTypes, "readServiceFunctionForwarder");
+    }
+
+    public static SfcProviderServiceForwarderAPI getDelete(Object[] params, Class[] paramsTypes) {
+        return new SfcProviderServiceForwarderAPI(params, paramsTypes, "deleteServiceFunctionForwarder");
+    }
+
+    public static SfcProviderServiceForwarderAPI getPutAll(Object[] params, Class[] paramsTypes) {
+        return new SfcProviderServiceForwarderAPI(params, paramsTypes, "putAllServiceFunctionForwarders");
+    }
+
+    public static SfcProviderServiceForwarderAPI getReadAll(Object[] params, Class[] paramsTypes) {
+        return new SfcProviderServiceForwarderAPI(params, paramsTypes, "readAllServiceFunctionForwarders");
+    }
+
+    public static SfcProviderServiceForwarderAPI getDeleteAll(Object[] params, Class[] paramsTypes) {
+        return new SfcProviderServiceForwarderAPI(params, paramsTypes, "deleteAllServiceFunctionForwarders");
+    }
+
+    public static SfcProviderServiceForwarderAPI getDeleteServiceFunctionFromForwarder(Object[] params, Class[] paramsTypes) {
+        return new SfcProviderServiceForwarderAPI(params, paramsTypes, "deleteServiceFunctionFromForwarder");
+    }
+
+    public static SfcProviderServiceForwarderAPI getCreateServiceForwarderAPI(Object[] params, Class[] paramsTypes) {
+        return new SfcProviderServiceForwarderAPI(params, paramsTypes, "createServiceFunctionForwarder");
+    }
+
+    public static SfcProviderServiceForwarderAPI getUpdateServiceForwarderAPI(Object[] params, Class[] paramsTypes) {
+        return new SfcProviderServiceForwarderAPI(params, paramsTypes, "updateServiceFunctionForwarder");
+    }
+
+    /*
+    public static ServiceFunctionForwarder readServiceFunctionForwarder(String name) {
+        LOG.debug("\n########## Start: {}", Thread.currentThread().getStackTrace()[1]);
+        ServiceFunctionForwarderKey serviceFunctionForwarderKey =
+                new ServiceFunctionForwarderKey(name);
+        InstanceIdentifier<ServiceFunctionForwarder> sffIID;
+        sffIID = InstanceIdentifier.builder(ServiceFunctionForwarders.class)
+                .child(ServiceFunctionForwarder.class, serviceFunctionForwarderKey)
+                .build();
+
+        ReadOnlyTransaction readTx = odlSfc.dataProvider.newReadOnlyTransaction();
+        Optional<ServiceFunctionForwarder> serviceFunctionForwarderObject = null;
+        try {
+            serviceFunctionForwarderObject = readTx.read(LogicalDatastoreType.CONFIGURATION, sffIID).get();
+        } catch (InterruptedException | ExecutionException e) {
+            e.printStackTrace();
         }
 
+        if (serviceFunctionForwarderObject != null &&
+                (serviceFunctionForwarderObject.get() instanceof ServiceFunctionForwarder)) {
+            LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+            return serviceFunctionForwarderObject.get();
+        } else {
+            LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+            return null;
+        }
     }
+    */
+
+    public static void addPathIdtoServiceFunctionForwarder(ServiceFunctionPath serviceFunctionPath) throws ExecutionException, InterruptedException {
+        LOG.debug("\n########## Start: {}", Thread.currentThread().getStackTrace()[1]);
+
+        InstanceIdentifier<ServiceFunctionForwarders> sffsIID;
+        ServiceFunctionForwardersBuilder serviceFunctionForwardersBuilder = new ServiceFunctionForwardersBuilder();
+        ArrayList<ServiceFunctionForwarder> serviceFunctionForwarderList = new ArrayList<>();
+        List<SfpServiceFunction> sfpServiceFunctionArrayList = serviceFunctionPath.getSfpServiceFunction();
+
+        for (SfpServiceFunction sfpServiceFunction : sfpServiceFunctionArrayList) {
+
+            ServiceFunctionForwarderKey serviceFunctionForwarderKey =
+                    new ServiceFunctionForwarderKey(sfpServiceFunction.getServiceFunctionForwarder());
+            ServiceFunctionForwarder serviceFunctionForwarder =
+                    (ServiceFunctionForwarder) odlSfc.executor.submit(SfcProviderServiceForwarderAPI.getRead(
+                            new Object[]{sfpServiceFunction.getServiceFunctionForwarder()},
+                            new Class[]{String.class})).get();
+            ServiceFunctionForwarderBuilder serviceFunctionForwarderBuilder = new ServiceFunctionForwarderBuilder();
+            if (serviceFunctionForwarder != null) {
+                //serviceFunctionForwarderBuilder.setPathId(serviceFunctionPath.getPathId());
+                serviceFunctionForwarderBuilder.setName(sfpServiceFunction.getServiceFunctionForwarder());
+                serviceFunctionForwarderBuilder.setSffDataPlaneLocator(serviceFunctionForwarder.getSffDataPlaneLocator());
+                serviceFunctionForwarderBuilder.setServiceFunctionDictionary(serviceFunctionForwarder.getServiceFunctionDictionary());
+                serviceFunctionForwarderBuilder.setKey(serviceFunctionForwarderKey);
+
+            } else {
+                LOG.error("Failed to read Service Function Forwarder from data store");
+                continue;
+            }
+            serviceFunctionForwarderList.add(serviceFunctionForwarderBuilder.build());
+        }
+
+        serviceFunctionForwardersBuilder.setServiceFunctionForwarder(serviceFunctionForwarderList);
+        sffsIID = InstanceIdentifier.builder(ServiceFunctionForwarders.class).build();
+
+        WriteTransaction writeTx = odlSfc.dataProvider.newWriteOnlyTransaction();
+        writeTx.merge(LogicalDatastoreType.CONFIGURATION,
+                sffsIID, serviceFunctionForwardersBuilder.build(), true);
+        writeTx.commit();
+
+        LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+
+        //serviceFunctionForwardersBuilder.setServiceFunctionForwarder(serviceFunctionForwarderList);
 
-    SfcProviderServiceForwarderAPI (Object[] params, Class[] paramsTypes, String m) {
-        this.methodName = 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);
     }
 
+    // TODO: need to check for sff-data-plane-locator
+    /*
+     * 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;
+        }
 
-    public static  SfcProviderServiceForwarderAPI getDeleteServiceFunctionFromForwarder(Object[] params, Class[] paramsTypes) {
-        return new SfcProviderServiceForwarderAPI (params, paramsTypes, "deleteServiceFunctionFromForwarder");
     }
 
-    public static  SfcProviderServiceForwarderAPI getCreateServiceForwarderAPI (Object[] params, Class[] paramsTypes) {
-        return new SfcProviderServiceForwarderAPI (params, paramsTypes, "createServiceFunctionForwarder");
+    protected boolean putServiceFunctionForwarder(ServiceFunctionForwarder sff) {
+        boolean ret = false;
+        LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+        if (dataBroker != null) {
+
+            InstanceIdentifier<ServiceFunctionForwarder> sffEntryIID = InstanceIdentifier.builder(ServiceFunctionForwarders.class).
+                    child(ServiceFunctionForwarder.class, sff.getKey()).toInstance();
+
+            WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction();
+            writeTx.merge(LogicalDatastoreType.CONFIGURATION,
+                    sffEntryIID, sff, true);
+            writeTx.commit();
+
+            ret = true;
+        }
+        LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+        return ret;
     }
 
-    public static  SfcProviderServiceForwarderAPI getUpdateServiceForwarderAPI (Object[] params, Class[] paramsTypes) {
-        return new SfcProviderServiceForwarderAPI (params, paramsTypes, "updateServiceFunctionForwarder");
+    protected ServiceFunctionForwarder readServiceFunctionForwarder(String serviceFunctionForwarderName) {
+        LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+        ServiceFunctionForwarder sff = null;
+        InstanceIdentifier<ServiceFunctionForwarder> sffIID;
+        ServiceFunctionForwarderKey serviceFunctionForwarderKey = new ServiceFunctionForwarderKey(serviceFunctionForwarderName);
+        sffIID = InstanceIdentifier.builder(ServiceFunctionForwarders.class)
+                .child(ServiceFunctionForwarder.class, serviceFunctionForwarderKey).build();
+
+        if (dataBroker != null) {
+            ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction();
+            Optional<ServiceFunctionForwarder> serviceFunctionForwarderDataObject = null;
+            try {
+                serviceFunctionForwarderDataObject = readTx.read(LogicalDatastoreType.CONFIGURATION, sffIID).get();
+            } catch (InterruptedException | ExecutionException e) {
+                e.printStackTrace();
+            }
+            if (serviceFunctionForwarderDataObject != null
+                    && serviceFunctionForwarderDataObject.isPresent()) {
+                sff = serviceFunctionForwarderDataObject.get();
+            }
+        }
+        LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+        return sff;
     }
 
+    protected boolean deleteServiceFunctionForwarder(String serviceFunctionForwarderName) {
+        boolean ret = false;
+        LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+        ServiceFunctionForwarderKey serviceFunctionForwarderKey = new ServiceFunctionForwarderKey(serviceFunctionForwarderName);
+        InstanceIdentifier<ServiceFunctionForwarder> sffEntryIID = InstanceIdentifier.builder(ServiceFunctionForwarders.class).
+                child(ServiceFunctionForwarder.class, serviceFunctionForwarderKey).toInstance();
 
-    public void createServiceFunctionForwarder (ServiceFunction serviceFunction) {
+        if (dataBroker != null) {
+            WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction();
+            writeTx.delete(LogicalDatastoreType.CONFIGURATION, sffEntryIID);
+            writeTx.commit();
+
+            ret = true;
+        }
+        LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+        return ret;
+    }
+
+    protected boolean putAllServiceFunctionForwarders(ServiceFunctionForwarders sffs) {
+        boolean ret = false;
+        LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+        if (dataBroker != null) {
+
+            InstanceIdentifier<ServiceFunctionForwarders> sffsIID =
+                    InstanceIdentifier.builder(ServiceFunctionForwarders.class).toInstance();
+
+            WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction();
+            writeTx.merge(LogicalDatastoreType.CONFIGURATION, sffsIID, sffs);
+            writeTx.commit();
+
+            ret = true;
+        }
+        LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+        return ret;
+    }
+
+    protected ServiceFunctionForwarders readAllServiceFunctionForwarders() {
+        ServiceFunctionForwarders sffs = null;
+        LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+        InstanceIdentifier<ServiceFunctionForwarders> sffsIID =
+                InstanceIdentifier.builder(ServiceFunctionForwarders.class).toInstance();
+
+        if (odlSfc.getDataProvider() != null) {
+            ReadOnlyTransaction readTx = odlSfc.getDataProvider().newReadOnlyTransaction();
+            Optional<ServiceFunctionForwarders> serviceFunctionForwardersDataObject = null;
+            try {
+                serviceFunctionForwardersDataObject = readTx.read(LogicalDatastoreType.CONFIGURATION, sffsIID).get();
+            } catch (InterruptedException | ExecutionException e) {
+                e.printStackTrace();
+            }
+            if (serviceFunctionForwardersDataObject != null
+                    && serviceFunctionForwardersDataObject.isPresent()) {
+                sffs = serviceFunctionForwardersDataObject.get();
+            }
+        }
+        LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+        return sffs;
+    }
+
+    protected boolean deleteAllServiceFunctionForwarders() {
+        boolean ret = false;
+        LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+        if (odlSfc.getDataProvider() != null) {
+
+            InstanceIdentifier<ServiceFunctionForwarders> sffsIID =
+                    InstanceIdentifier.builder(ServiceFunctionForwarders.class).toInstance();
+
+            WriteTransaction writeTx = odlSfc.getDataProvider().newWriteOnlyTransaction();
+            writeTx.delete(LogicalDatastoreType.CONFIGURATION, sffsIID);
+            writeTx.commit();
+
+            ret = true;
+        }
+        LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+        return ret;
+    }
+
+    public void createServiceFunctionForwarder(ServiceFunction serviceFunction) {
 
         LOG.debug("\n########## Start: {}", Thread.currentThread().getStackTrace()[1]);
         InstanceIdentifier<ServiceFunctionForwarder> sffIID;
@@ -124,7 +337,7 @@ public class SfcProviderServiceForwarderAPI implements Runnable {
         serviceFunctionForwarderBuilder.setServiceFunctionDictionary(serviceFunctionDictionaryList);
 
         LOG.debug("\n########## Creating Forwarder: {}  Service Function: {} "
-                ,serviceFunctionForwarderName, serviceFunction.getName());
+                , serviceFunctionForwarderName, serviceFunction.getName());
 
         WriteTransaction writeTx = odlSfc.dataProvider.newWriteOnlyTransaction();
         writeTx.merge(LogicalDatastoreType.CONFIGURATION,
@@ -133,7 +346,7 @@ public class SfcProviderServiceForwarderAPI implements Runnable {
         LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
     }
 
-    public void deleteServiceFunctionFromForwarder (ServiceFunction serviceFunction) {
+    public void deleteServiceFunctionFromForwarder(ServiceFunction serviceFunction) {
         LOG.debug("\n########## Start: {}", Thread.currentThread().getStackTrace()[1]);
         String serviceFunctionForwarderName = serviceFunction.getSfDataPlaneLocator().
                 getServiceFunctionForwarder();
@@ -153,16 +366,18 @@ public class SfcProviderServiceForwarderAPI implements Runnable {
         writeTx.commit();
         LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
     }
+
     @SuppressWarnings("unused")
-    public void updateServiceFunctionForwarder (ServiceFunction serviceFunction) {
+    public void updateServiceFunctionForwarder(ServiceFunction serviceFunction) {
 
         LOG.debug("\n########## Start: {}", Thread.currentThread().getStackTrace()[1]);
         deleteServiceFunctionFromForwarder(serviceFunction);
         createServiceFunctionForwarder(serviceFunction);
 
     }
+
     @SuppressWarnings("unused")
-    public void createServiceFunctionForwarders (ServiceFunctionChains serviceFunctionchains) {
+    public void createServiceFunctionForwarders(ServiceFunctionChains serviceFunctionchains) {
 
         LOG.debug("\n########## Start: {}", Thread.currentThread().getStackTrace()[1]);
         InstanceIdentifier<ServiceFunctionForwarders> sffIID;
@@ -179,10 +394,12 @@ public class SfcProviderServiceForwarderAPI implements Runnable {
 
             // Iterate thorough all Service Functions in a single chain
             List<SfcServiceFunction> sfcServiceFunctionList = serviceFunctionChain.getSfcServiceFunction();
-            for (SfcServiceFunction sfcServiceFunction :sfcServiceFunctionList) {
+            for (SfcServiceFunction sfcServiceFunction : sfcServiceFunctionList) {
 
-                // Read all data of a single Service Service
-                ServiceFunction serviceFunction = SfcProviderServiceFunctionAPI.readServiceFunction(sfcServiceFunction.getName());
+                // Read a single Service Function
+                ServiceFunction serviceFunction = (ServiceFunction) SfcProviderServiceFunctionAPI
+                        .getRead(
+                                new Object[]{sfcServiceFunction.getName()}, new Class[]{String.class}).call();
 
                 // Build a single service function forwarder
                 String serviceFunctionForwarderName = serviceFunction.getSfDataPlaneLocator().
@@ -220,8 +437,9 @@ public class SfcProviderServiceForwarderAPI implements Runnable {
         LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
 
     }
+
     @SuppressWarnings("unused")
-    public void deleteServiceFunctionForwarderfromSF (ServiceFunction serviceFunction) {
+    public void deleteServiceFunctionForwarderfromSF(ServiceFunction serviceFunction) {
 
         /*
          * TODO: We assume that if a ServiceFunction exists it belongs to a ServiceFunctionForwarder
@@ -242,10 +460,10 @@ public class SfcProviderServiceForwarderAPI implements Runnable {
                 new ServiceFunctionDictionaryKey(serviceFunction.getName());
         sffIID = InstanceIdentifier.builder(ServiceFunctionForwarders.class)
                 .child(ServiceFunctionForwarder.class, serviceFunctionForwarderKey)
-                .child(ServiceFunctionDictionary.class, serviceFunctionDictionaryKey )
+                .child(ServiceFunctionDictionary.class, serviceFunctionDictionaryKey)
                 .build();
         LOG.debug("\n########## Deleting Forwarder: {}  Service Function: {} "
-                ,serviceFunctionForwarderName, serviceFunction.getName());
+                , serviceFunctionForwarderName, serviceFunction.getName());
 
         WriteTransaction writeTx = odlSfc.dataProvider.newWriteOnlyTransaction();
         writeTx.delete(LogicalDatastoreType.CONFIGURATION,
@@ -254,102 +472,4 @@ public class SfcProviderServiceForwarderAPI implements Runnable {
         LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
     }
 
-    @SuppressWarnings("unused")
-    public static ServiceFunctionForwarder readServiceFunctionForwarder(String name) {
-        LOG.debug("\n########## Start: {}", Thread.currentThread().getStackTrace()[1]);
-        ServiceFunctionForwarderKey serviceFunctionForwarderKey =
-                new ServiceFunctionForwarderKey(name);
-        InstanceIdentifier<ServiceFunctionForwarder> sffIID;
-        sffIID = InstanceIdentifier.builder(ServiceFunctionForwarders.class)
-                .child(ServiceFunctionForwarder.class, serviceFunctionForwarderKey)
-                .build();
-
-        ReadOnlyTransaction readTx = odlSfc.dataProvider.newReadOnlyTransaction();
-        Optional<ServiceFunctionForwarder> serviceFunctionForwarderObject = null;
-        try {
-            serviceFunctionForwarderObject = readTx.read(LogicalDatastoreType.CONFIGURATION, sffIID).get();
-        } catch (InterruptedException | ExecutionException e) {
-            e.printStackTrace();
-        }
-
-        if (serviceFunctionForwarderObject != null &&
-                (serviceFunctionForwarderObject.get() instanceof ServiceFunctionForwarder)) {
-            LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
-            return serviceFunctionForwarderObject.get();
-        } else {
-            LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
-            return null;
-        }
-    }
-
-    public static void addPathIdtoServiceFunctionForwarder(ServiceFunctionPath serviceFunctionPath) {
-        LOG.debug("\n########## Start: {}", Thread.currentThread().getStackTrace()[1]);
-
-        InstanceIdentifier<ServiceFunctionForwarders> sffsIID;
-        ServiceFunctionForwardersBuilder serviceFunctionForwardersBuilder = new ServiceFunctionForwardersBuilder();
-        ArrayList<ServiceFunctionForwarder> serviceFunctionForwarderList =  new ArrayList<>();
-        List<SfpServiceFunction> sfpServiceFunctionArrayList = serviceFunctionPath.getSfpServiceFunction();
-
-        for (SfpServiceFunction sfpServiceFunction : sfpServiceFunctionArrayList) {
-
-            ServiceFunctionForwarderKey serviceFunctionForwarderKey =
-                    new ServiceFunctionForwarderKey(sfpServiceFunction.getServiceFunctionForwarder());
-            ServiceFunctionForwarder serviceFunctionForwarder =  readServiceFunctionForwarder (sfpServiceFunction.getServiceFunctionForwarder());
-            ServiceFunctionForwarderBuilder serviceFunctionForwarderBuilder = new ServiceFunctionForwarderBuilder();
-            if (serviceFunctionForwarder != null) {
-                //serviceFunctionForwarderBuilder.setPathId(serviceFunctionPath.getPathId());
-                serviceFunctionForwarderBuilder.setName(sfpServiceFunction.getServiceFunctionForwarder());
-                serviceFunctionForwarderBuilder.setSffDataPlaneLocator(serviceFunctionForwarder.getSffDataPlaneLocator());
-                serviceFunctionForwarderBuilder.setServiceFunctionDictionary(serviceFunctionForwarder.getServiceFunctionDictionary());
-                serviceFunctionForwarderBuilder.setKey(serviceFunctionForwarderKey);
-
-            } else {
-                LOG.error("Failed to read Service Function Forwarder from data store");
-                continue;
-            }
-            serviceFunctionForwarderList.add(serviceFunctionForwarderBuilder.build());
-        }
-
-        serviceFunctionForwardersBuilder.setServiceFunctionForwarder(serviceFunctionForwarderList);
-        sffsIID = InstanceIdentifier.builder(ServiceFunctionForwarders.class).build();
-
-        WriteTransaction writeTx = odlSfc.dataProvider.newWriteOnlyTransaction();
-        writeTx.merge(LogicalDatastoreType.CONFIGURATION,
-                sffsIID, serviceFunctionForwardersBuilder.build(), true);
-        writeTx.commit();
-
-        LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
-
-        //serviceFunctionForwardersBuilder.setServiceFunctionForwarder(serviceFunctionForwarderList);
-
-    }
-
-    // TODO: need to check for sff-data-plane-locator
-    /*
-     * 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;
-        }
-
-    }
-
-    @Override
-    public void run() {
-        if (methodName != null) {
-            Class<?> c = this.getClass();
-            Method method;
-            try {
-                method = c.getDeclaredMethod(methodName, parameterTypes);
-                method.invoke(this, parameters);
-            } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
-                e.printStackTrace();
-            }
-        }
-
-    }
 }
index 865c991c46595b28cdfcfda1526140f2440f47ba..bb6eacc2b88d51a42c450ea9c8de4b031ce2f057 100644 (file)
@@ -26,106 +26,65 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.List;
 import java.util.concurrent.ExecutionException;
 
 /**
  * This class has the APIs to operate on the ServiceFunction
  * datastore.
- *
+ * <p/>
  * It is normally called from onDataChanged() through a executor
  * service. We need to use an executor service because we can not
  * operate on a datastore while on onDataChanged() context.
- * @see org.opendaylight.sfc.provider.SfcProviderSfEntryDataListener
- *
  *
- * <p>
  * @author Reinaldo Penno ([email protected])
+ * @author Konstantin Blagov ([email protected])
  * @version 0.1
- * @since       2014-06-30
+ * @see org.opendaylight.sfc.provider.SfcProviderSfEntryDataListener
+ * @since 2014-06-30
  */
-public class SfcProviderServiceFunctionAPI implements Runnable {
+public class SfcProviderServiceFunctionAPI extends SfcProviderAbstractAPI {
 
     private static final Logger LOG = LoggerFactory.getLogger(SfcProviderServiceFunctionAPI.class);
-    private static final OpendaylightSfc odlSfc = OpendaylightSfc.getOpendaylightSfcObj();
-    private String methodName = null;
-    private Object[] parameters;
-    private Class[] parameterTypes;
 
-    SfcProviderServiceFunctionAPI (Object[] params, Class[] paramsTypes, String m) {
-        this.methodName = 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);
+    SfcProviderServiceFunctionAPI(Object[] params, String m) {
+        super(params, m);
     }
 
-    public static  SfcProviderServiceFunctionAPI getDeleteServicePathFromServiceFunctionState (Object[] params, Class[] paramsTypes) {
-        return new SfcProviderServiceFunctionAPI (params, paramsTypes, "deleteServicePathFromServiceFunctionState");
+    SfcProviderServiceFunctionAPI(Object[] params, Class[] paramsTypes, String m) {
+        super(params, paramsTypes, m);
     }
 
-    public static ServiceFunction readServiceFunction(String serviceFunctionName) {
-        LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
-        InstanceIdentifier<ServiceFunction> sfIID;
-        ServiceFunctionKey serviceFunctionKey = new ServiceFunctionKey(serviceFunctionName);
-        sfIID = InstanceIdentifier.builder(ServiceFunctions.class)
-                .child(ServiceFunction.class, serviceFunctionKey).build();
-
-        ReadOnlyTransaction readTx = odlSfc.dataProvider.newReadOnlyTransaction();
-        Optional<ServiceFunction> serviceFunctiondataObject = null;
-        try {
-            serviceFunctiondataObject = readTx.read(LogicalDatastoreType.CONFIGURATION, sfIID).get();
-        } catch (InterruptedException | ExecutionException e) {
-            e.printStackTrace();
-        }
-        if (serviceFunctiondataObject != null &&
-                (serviceFunctiondataObject.get() instanceof ServiceFunction)) {
-            LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
-            return serviceFunctiondataObject.get();
-        } else {
-            LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
-            return null;
-        }
+    public static SfcProviderServiceFunctionAPI getDeleteServicePathFromServiceFunctionState(Object[] params, Class[] paramsTypes) {
+        return new SfcProviderServiceFunctionAPI(params, paramsTypes, "deleteServicePathFromServiceFunctionState");
     }
 
-    /*
-     * When a Service Path is deleted directly (not as a consequence of deleting a SF), we need
-     * to remove its reference from all the ServiceFunction states.
-     */
-    @SuppressWarnings("unused")
-    public void deleteServicePathFromServiceFunctionState (ServiceFunctionPath serviceFunctionPath) {
+    public static SfcProviderServiceFunctionAPI getPut(Object[] params, Class[] paramsTypes) {
+        return new SfcProviderServiceFunctionAPI(params, paramsTypes, "putServiceFunction");
+    }
 
-        List<SfpServiceFunction>  sfpServiceFunctionList = serviceFunctionPath.getSfpServiceFunction();
-        for (SfpServiceFunction sfpServiceFunction : sfpServiceFunctionList) {
-            String serviceFunctionName = sfpServiceFunction.getName();
-            ServiceFunctionState serviceFunctionState = readServiceFunctionState(serviceFunctionName);
-            ServiceFunctionStateKey serviceFunctionStateKey = new ServiceFunctionStateKey(serviceFunctionName);
-            InstanceIdentifier<ServiceFunctionState> sfStateIID =
-                    InstanceIdentifier.builder(ServiceFunctionsState.class)
-                            .child(ServiceFunctionState.class, serviceFunctionStateKey)
-                            .build();
+    public static SfcProviderServiceFunctionAPI getRead(Object[] params, Class[] paramsTypes) {
+        return new SfcProviderServiceFunctionAPI(params, paramsTypes, "readServiceFunction");
+    }
 
-            List<String> sfServiceFunctionPathList = serviceFunctionState.getSfServiceFunctionPath();
-            List<String> newPathList = new ArrayList<>();
-            newPathList.addAll(sfServiceFunctionPathList);
-            newPathList.remove(serviceFunctionPath.getName());
-            ServiceFunctionStateBuilder serviceFunctionStateBuilder = new ServiceFunctionStateBuilder();
-            serviceFunctionStateBuilder.setName(serviceFunctionName);
-            serviceFunctionStateBuilder.setSfServiceFunctionPath(newPathList);
+    public static SfcProviderServiceFunctionAPI getDelete(Object[] params, Class[] paramsTypes) {
+        return new SfcProviderServiceFunctionAPI(params, paramsTypes, "deleteServiceFunction");
+    }
 
+    public static SfcProviderServiceFunctionAPI getPutAll(Object[] params, Class[] paramsTypes) {
+        return new SfcProviderServiceFunctionAPI(params, paramsTypes, "putAllServiceFunctions");
+    }
 
-            ReadWriteTransaction writeTx = odlSfc.dataProvider.newReadWriteTransaction();
-            writeTx.put(LogicalDatastoreType.CONFIGURATION, sfStateIID, serviceFunctionStateBuilder.build(), true);
-            writeTx.commit();
-        }
+    public static SfcProviderServiceFunctionAPI getReadAll(Object[] params, Class[] paramsTypes) {
+        return new SfcProviderServiceFunctionAPI(params, paramsTypes, "readAllServiceFunctions");
     }
 
+    public static SfcProviderServiceFunctionAPI getDeleteAll(Object[] params, Class[] paramsTypes) {
+        return new SfcProviderServiceFunctionAPI(params, paramsTypes, "deleteAllServiceFunctions");
+    }
 
-    public static ServiceFunctionState readServiceFunctionState (String serviceFunctionName) {
+    public static ServiceFunctionState readServiceFunctionState(String serviceFunctionName) {
         LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
 
         ServiceFunctionState serviceFunctionState;
@@ -155,7 +114,7 @@ public class SfcProviderServiceFunctionAPI implements Runnable {
         }
     }
 
-    public static void deleteServiceFunctionState (String serviceFunctionName) {
+    public static void deleteServiceFunctionState(String serviceFunctionName) {
         LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
 
 
@@ -174,7 +133,7 @@ public class SfcProviderServiceFunctionAPI implements Runnable {
     /*
      * We add the path name to the operational store of each SF in the path.
      */
-    public static void addPathToServiceFunctionState (ServiceFunctionPath serviceFunctionPath) {
+    public static void addPathToServiceFunctionState(ServiceFunctionPath serviceFunctionPath) {
 
         LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
 
@@ -200,18 +159,173 @@ public class SfcProviderServiceFunctionAPI implements Runnable {
         }
     }
 
-    @Override
-    public void run() {
-        if (methodName != null) {
-            Class<?> c = this.getClass();
-            Method method;
+    protected static boolean putServiceFunction(ServiceFunction sf) {
+        boolean ret = false;
+        LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+        if (odlSfc.getDataProvider() != null) {
+
+            InstanceIdentifier<ServiceFunction> sfEntryIID = InstanceIdentifier.builder(ServiceFunctions.class).
+                    child(ServiceFunction.class, sf.getKey()).toInstance();
+
+            WriteTransaction writeTx = odlSfc.getDataProvider().newWriteOnlyTransaction();
+            writeTx.put(LogicalDatastoreType.CONFIGURATION,
+                    sfEntryIID, sf, true);
+            writeTx.commit();
+
+            ret = true;
+        }
+        LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+        return ret;
+    }
+
+    protected static boolean mergeServiceFunction(ServiceFunction sf) {
+        boolean ret = false;
+        LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+        if (odlSfc.getDataProvider() != null) {
+
+            InstanceIdentifier<ServiceFunction> sfEntryIID = InstanceIdentifier.builder(ServiceFunctions.class).
+                    child(ServiceFunction.class, sf.getKey()).toInstance();
+
+            WriteTransaction writeTx = odlSfc.getDataProvider().newWriteOnlyTransaction();
+            writeTx.merge(LogicalDatastoreType.CONFIGURATION,
+                    sfEntryIID, sf, true);
+            writeTx.commit();
+
+            ret = true;
+        }
+        LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+        return ret;
+    }
+
+    protected ServiceFunction readServiceFunction(String serviceFunctionName) {
+        LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+        ServiceFunction sf = null;
+        InstanceIdentifier<ServiceFunction> sfIID;
+        ServiceFunctionKey serviceFunctionKey = new ServiceFunctionKey(serviceFunctionName);
+        sfIID = InstanceIdentifier.builder(ServiceFunctions.class)
+                .child(ServiceFunction.class, serviceFunctionKey).build();
+
+        if (odlSfc.getDataProvider() != null) {
+            ReadOnlyTransaction readTx = odlSfc.getDataProvider().newReadOnlyTransaction();
+            Optional<ServiceFunction> serviceFunctionDataObject = null;
+            try {
+                serviceFunctionDataObject = readTx.read(LogicalDatastoreType.CONFIGURATION, sfIID).get();
+            } catch (InterruptedException | ExecutionException e) {
+                e.printStackTrace();
+            }
+            if (serviceFunctionDataObject != null
+                    && serviceFunctionDataObject.isPresent()) {
+                sf = serviceFunctionDataObject.get();
+            }
+        }
+        LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+        return sf;
+    }
+
+    protected boolean deleteServiceFunction(String serviceFunctionName) {
+        boolean ret = false;
+        LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+        ServiceFunctionKey serviceFunctionKey = new ServiceFunctionKey(serviceFunctionName);
+        InstanceIdentifier<ServiceFunction> sfEntryIID = InstanceIdentifier.builder(ServiceFunctions.class)
+                .child(ServiceFunction.class, serviceFunctionKey).toInstance();
+
+        if (odlSfc.getDataProvider() != null) {
+            WriteTransaction writeTx = odlSfc.getDataProvider().newWriteOnlyTransaction();
+            writeTx.delete(LogicalDatastoreType.CONFIGURATION, sfEntryIID);
+            writeTx.commit();
+
+            ret = true;
+        }
+        LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+        return ret;
+    }
+
+    protected boolean putAllServiceFunctions(ServiceFunctions sfs) {
+        boolean ret = false;
+        LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+        if (odlSfc.getDataProvider() != null) {
+
+            InstanceIdentifier<ServiceFunctions> sfsIID = InstanceIdentifier.builder(ServiceFunctions.class).toInstance();
+
+            WriteTransaction writeTx = odlSfc.getDataProvider().newWriteOnlyTransaction();
+            writeTx.put(LogicalDatastoreType.CONFIGURATION, sfsIID, sfs);
+            writeTx.commit();
+
+            ret = true;
+        }
+        LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+        return ret;
+    }
+
+    protected ServiceFunctions readAllServiceFunctions() {
+        ServiceFunctions sfs = null;
+        LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+        InstanceIdentifier<ServiceFunctions> sfsIID = InstanceIdentifier.builder(ServiceFunctions.class).toInstance();
+
+        if (odlSfc.getDataProvider() != null) {
+            ReadOnlyTransaction readTx = odlSfc.getDataProvider().newReadOnlyTransaction();
+            Optional<ServiceFunctions> serviceFunctionsDataObject = null;
             try {
-                method = c.getDeclaredMethod(methodName, parameterTypes);
-                method.invoke(this, parameters);
-            } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
+                serviceFunctionsDataObject = readTx.read(LogicalDatastoreType.CONFIGURATION, sfsIID).get();
+            } catch (InterruptedException | ExecutionException e) {
                 e.printStackTrace();
             }
+            if (serviceFunctionsDataObject != null
+                    && serviceFunctionsDataObject.isPresent()) {
+                sfs = serviceFunctionsDataObject.get();
+            }
+        }
+        LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+        return sfs;
+    }
+
+    protected boolean deleteAllServiceFunctions() {
+        boolean ret = false;
+        LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+        if (odlSfc.getDataProvider() != null) {
+
+            InstanceIdentifier<ServiceFunctions> sfsIID = InstanceIdentifier.builder(ServiceFunctions.class).toInstance();
+
+            WriteTransaction writeTx = odlSfc.getDataProvider().newWriteOnlyTransaction();
+            writeTx.delete(LogicalDatastoreType.CONFIGURATION, sfsIID);
+            writeTx.commit();
+
+            ret = true;
         }
+        LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+        return ret;
+    }
+
+    /*
+     * When a Service Path is deleted directly (not as a consequence of deleting a SF), we need
+     * to remove its reference from all the ServiceFunction states.
+     */
+    @SuppressWarnings("unused")
+    public void deleteServicePathFromServiceFunctionState(ServiceFunctionPath serviceFunctionPath) {
+
+        List<SfpServiceFunction> sfpServiceFunctionList = serviceFunctionPath.getSfpServiceFunction();
+        for (SfpServiceFunction sfpServiceFunction : sfpServiceFunctionList) {
+            String serviceFunctionName = sfpServiceFunction.getName();
+            ServiceFunctionState serviceFunctionState = readServiceFunctionState(serviceFunctionName);
+            ServiceFunctionStateKey serviceFunctionStateKey = new ServiceFunctionStateKey(serviceFunctionName);
+            InstanceIdentifier<ServiceFunctionState> sfStateIID =
+                    InstanceIdentifier.builder(ServiceFunctionsState.class)
+                            .child(ServiceFunctionState.class, serviceFunctionStateKey)
+                            .build();
 
+            List<String> sfServiceFunctionPathList = serviceFunctionState.getSfServiceFunctionPath();
+            List<String> newPathList = new ArrayList<>();
+            newPathList.addAll(sfServiceFunctionPathList);
+            newPathList.remove(serviceFunctionPath.getName());
+            ServiceFunctionStateBuilder serviceFunctionStateBuilder = new ServiceFunctionStateBuilder();
+            serviceFunctionStateBuilder.setName(serviceFunctionName);
+            serviceFunctionStateBuilder.setSfServiceFunctionPath(newPathList);
+
+
+            ReadWriteTransaction writeTx = odlSfc.dataProvider.newReadWriteTransaction();
+            writeTx.put(LogicalDatastoreType.CONFIGURATION, sfStateIID, serviceFunctionStateBuilder.build(), true);
+            writeTx.commit();
+        }
     }
+
 }
index 8121fb7f824d86a358eede2ad6283561dc6c337d..be5bf36d71e39370bb80415ab76527ba6566f0e9 100644 (file)
@@ -34,10 +34,7 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.List;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.atomic.AtomicInteger;
@@ -45,47 +42,56 @@ import java.util.concurrent.atomic.AtomicInteger;
 /**
  * This class has the APIs to operate on the ServiceFunctionPath
  * datastore.
- *
+ * <p/>
  * It is normally called from onDataChanged() through a executor
  * service. We need to use an executor service because we can not
  * operate on a datastore while on onDataChanged() context.
- * @see org.opendaylight.sfc.provider.SfcProviderSfpEntryDataListener
  *
- *
- * <p>
  * @author Reinaldo Penno ([email protected])
+ * @author Konstantin Blagov ([email protected])
  * @version 0.1
+ * @see org.opendaylight.sfc.provider.SfcProviderSfpEntryDataListener
+ * <p/>
+ * <p/>
+ * <p/>
  * @since       2014-06-30
  */
-public class SfcProviderServicePathAPI implements Runnable {
+public class SfcProviderServicePathAPI extends SfcProviderAbstractAPI {
 
     private static final Logger LOG = LoggerFactory.getLogger(SfcProviderServicePathAPI.class);
-    private static final OpendaylightSfc odlSfc = OpendaylightSfc.getOpendaylightSfcObj();
-    private String methodName = null;
-    private Object[] parameters;
-    private Class[] parameterTypes;
     private static AtomicInteger numCreatedPath = new AtomicInteger(0);
 
 
     SfcProviderServicePathAPI (Object[] params, String m) {
-        int i = 0;
-        this.methodName = m;
-        this.parameters = new Object[params.length];
-        this.parameterTypes = new Class[params.length];
-        this.parameters = Arrays.copyOf(params, params.length);
-        for (Object obj : parameters) {
-            this.parameterTypes[i] = obj.getClass();
-            i++;
+        super(params, m);
         }
 
+    SfcProviderServicePathAPI(Object[] params, Class[] paramsTypes, String m) {
+        super(params, paramsTypes, m);
+    }
+
+    public static SfcProviderServicePathAPI getPut(Object[] params, Class[] paramsTypes) {
+        return new SfcProviderServicePathAPI(params, paramsTypes, "putServiceFunctionPath");
+    }
+
+    public static SfcProviderServicePathAPI getRead(Object[] params, Class[] paramsTypes) {
+        return new SfcProviderServicePathAPI(params, paramsTypes, "readServiceFunctionPath");
+    }
+
+    public static SfcProviderServicePathAPI getDelete(Object[] params, Class[] paramsTypes) {
+        return new SfcProviderServicePathAPI(params, paramsTypes, "deleteServiceFunctionPath");
+    }
+
+    public static SfcProviderServicePathAPI getPutAll(Object[] params, Class[] paramsTypes) {
+        return new SfcProviderServicePathAPI(params, paramsTypes, "putAllServiceFunctionPaths");
+    }
+
+    public static SfcProviderServicePathAPI getReadAll(Object[] params, Class[] paramsTypes) {
+        return new SfcProviderServicePathAPI(params, paramsTypes, "readAllServiceFunctionPaths");
     }
 
-    SfcProviderServicePathAPI (Object[] params, Class[] paramsTypes, String m) {
-        this.methodName = 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);
+    public static SfcProviderServicePathAPI getDeleteAll(Object[] params, Class[] paramsTypes) {
+        return new SfcProviderServicePathAPI(params, paramsTypes, "deleteAllServiceFunctionPaths");
     }
 
     public static  SfcProviderServicePathAPI getDeleteServicePathContainingFunction (Object[] params, Class[] paramsTypes) {
@@ -112,6 +118,9 @@ public class SfcProviderServicePathAPI implements Runnable {
         return new SfcProviderServicePathAPI(params, paramsTypes, "updateServicePathContainingFunction");
     }
 
+    public static int numCreatedPathGetValue() {
+        return numCreatedPath.get();
+    }
 
     public int numCreatedPathIncrementGet() {
         return numCreatedPath.incrementAndGet();
@@ -121,8 +130,122 @@ public class SfcProviderServicePathAPI implements Runnable {
         return numCreatedPath.decrementAndGet();
     }
 
-    public static int numCreatedPathGetValue() {
-        return numCreatedPath.get();
+    protected boolean putServiceFunctionPath(ServiceFunctionPath sfp) {
+        boolean ret = false;
+        LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+        if (dataBroker != null) {
+
+            InstanceIdentifier<ServiceFunctionPath> sfpEntryIID = InstanceIdentifier.builder(ServiceFunctionPaths.class).
+                    child(ServiceFunctionPath.class, sfp.getKey()).toInstance();
+
+            WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction();
+            writeTx.merge(LogicalDatastoreType.CONFIGURATION,
+                    sfpEntryIID, sfp, true);
+            writeTx.commit();
+
+            ret = true;
+    }
+        LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+        return ret;
+    }
+
+    protected ServiceFunctionPath readServiceFunctionPath(String serviceFunctionPathName) {
+        LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+        ServiceFunctionPath sfp = null;
+        InstanceIdentifier<ServiceFunctionPath> sfpIID;
+        ServiceFunctionPathKey serviceFunctionPathKey = new ServiceFunctionPathKey(serviceFunctionPathName);
+        sfpIID = InstanceIdentifier.builder(ServiceFunctionPaths.class)
+                .child(ServiceFunctionPath.class, serviceFunctionPathKey).build();
+
+        if (dataBroker != null) {
+            ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction();
+            Optional<ServiceFunctionPath> serviceFunctionPathDataObject = null;
+            try {
+                serviceFunctionPathDataObject = readTx.read(LogicalDatastoreType.CONFIGURATION, sfpIID).get();
+            } catch (InterruptedException | ExecutionException e) {
+                e.printStackTrace();
+            }
+            if (serviceFunctionPathDataObject != null
+                    && serviceFunctionPathDataObject.isPresent()) {
+                sfp = serviceFunctionPathDataObject.get();
+            }
+        }
+        LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+        return sfp;
+    }
+
+    protected boolean deleteServiceFunctionPath(String serviceFunctionPathName) {
+        boolean ret = false;
+        LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+        ServiceFunctionPathKey serviceFunctionPathKey = new ServiceFunctionPathKey(serviceFunctionPathName);
+        InstanceIdentifier<ServiceFunctionPath> sfpEntryIID = InstanceIdentifier.builder(ServiceFunctionPaths.class)
+                .child(ServiceFunctionPath.class, serviceFunctionPathKey).toInstance();
+
+        if (dataBroker != null) {
+            WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction();
+            writeTx.delete(LogicalDatastoreType.CONFIGURATION, sfpEntryIID);
+            writeTx.commit();
+
+            ret = true;
+        }
+        LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+        return ret;
+    }
+
+    protected boolean putAllServiceFunctionPaths(ServiceFunctionPaths sfps) {
+        boolean ret = false;
+        LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+        if (dataBroker != null) {
+
+            InstanceIdentifier<ServiceFunctionPaths> sfpsIID = InstanceIdentifier.builder(ServiceFunctionPaths.class).toInstance();
+
+            WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction();
+            writeTx.merge(LogicalDatastoreType.CONFIGURATION, sfpsIID, sfps);
+            writeTx.commit();
+
+            ret = true;
+        }
+        LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+        return ret;
+    }
+
+    protected ServiceFunctionPaths readAllServiceFunctionPaths() {
+        ServiceFunctionPaths sfps = null;
+        LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+        InstanceIdentifier<ServiceFunctionPaths> sfpsIID = InstanceIdentifier.builder(ServiceFunctionPaths.class).toInstance();
+
+        if (odlSfc.getDataProvider() != null) {
+            ReadOnlyTransaction readTx = odlSfc.getDataProvider().newReadOnlyTransaction();
+            Optional<ServiceFunctionPaths> serviceFunctionPathsDataObject = null;
+            try {
+                serviceFunctionPathsDataObject = readTx.read(LogicalDatastoreType.CONFIGURATION, sfpsIID).get();
+            } catch (InterruptedException | ExecutionException e) {
+                e.printStackTrace();
+            }
+            if (serviceFunctionPathsDataObject != null
+                    && serviceFunctionPathsDataObject.isPresent()) {
+                sfps = serviceFunctionPathsDataObject.get();
+            }
+        }
+        LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+        return sfps;
+    }
+
+    protected boolean deleteAllServiceFunctionPaths() {
+        boolean ret = false;
+        LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+        if (odlSfc.getDataProvider() != null) {
+
+            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]);
+        return ret;
     }
 
    /* Today A Service Function Chain modification is catastrophic. We delete all Paths
@@ -139,10 +262,19 @@ public class SfcProviderServicePathAPI implements Runnable {
     private void deleteServicePathInstantiatedFromChain (ServiceFunctionPath serviceFunctionPath) {
 
         LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
-        ServiceFunctionChain serviceFunctionChain;
+        ServiceFunctionChain serviceFunctionChain = null;
         String serviceChainName = serviceFunctionPath.getServiceChainName();
-        if ((serviceChainName == null) || ((serviceFunctionChain = SfcProviderServiceChainAPI
-                .readServiceFunctionChain(serviceChainName)) == null)) {
+        try {
+            serviceFunctionChain = serviceChainName != null ?
+                    (ServiceFunctionChain) odlSfc.executor
+                            .submit(SfcProviderServiceChainAPI.getRead(
+                                    new Object[]{serviceChainName},
+                                    new Class[]{String.class})).get()
+                    : null;
+        } catch (InterruptedException | ExecutionException e) {
+            e.printStackTrace();
+        }
+        if (serviceFunctionChain == null) {
             LOG.error("\n########## ServiceFunctionChain name for Path {} not provided",
                     serviceFunctionPath.getName());
             return;
@@ -221,10 +353,20 @@ public class SfcProviderServicePathAPI implements Runnable {
         long pathId;
         int pos_index = 0;
         int service_index;
-        ServiceFunctionChain serviceFunctionChain;
+        ServiceFunctionChain serviceFunctionChain = null;
+        serviceFunctionChain = null;
         String serviceFunctionChainName = serviceFunctionPath.getServiceChainName();
-        if ((serviceFunctionChainName == null) || ((serviceFunctionChain = SfcProviderServiceChainAPI
-                    .readServiceFunctionChain(serviceFunctionChainName)) == null)) {
+        try {
+            serviceFunctionChain = serviceFunctionChainName != null ?
+                    (ServiceFunctionChain) odlSfc.executor
+                            .submit(SfcProviderServiceChainAPI.getRead(
+                                    new Object[]{serviceFunctionChainName},
+                                    new Class[]{String.class})).get()
+                    : null;
+        } catch (InterruptedException | ExecutionException e) {
+            e.printStackTrace();
+        }
+        if (serviceFunctionChain == null) {
             LOG.error("\n########## ServiceFunctionChain name for Path {} not provided",
                     serviceFunctionPath.getName());
             return;
@@ -250,18 +392,28 @@ public class SfcProviderServicePathAPI implements Runnable {
              * we do not hit NULL Pointer exceptions
              */
 
-            ServiceFunctionType serviceFunctionType = SfcProviderServiceTypeAPI.getServiceFunctionTypeList(sfcServiceFunction.getType());
+            ServiceFunctionType serviceFunctionType = null;
+            try {
+                serviceFunctionType = (ServiceFunctionType) odlSfc.executor.submit(SfcProviderServiceTypeAPI.getRead(
+                        new Object[]{sfcServiceFunction.getType()}, new Class[]{String.class})).get();
+            } catch (InterruptedException | ExecutionException e) {
+                e.printStackTrace();
+            }
             if (serviceFunctionType != null) {
                 List<SftServiceFunctionName> sftServiceFunctionNameList = serviceFunctionType.getSftServiceFunctionName();
                 if (!sftServiceFunctionNameList.isEmpty()) {
                     for (SftServiceFunctionName sftServiceFunctionName : sftServiceFunctionNameList) {
                         // TODO: API to select suitable Service Function
                         String serviceFunctionName = sftServiceFunctionName.getName();
-                        ServiceFunction serviceFunction;
-                        if ((serviceFunctionName != null) && ((
-                             serviceFunction = SfcProviderServiceFunctionAPI
-                                    .readServiceFunction(serviceFunctionName)) != null)) {
-
+                        ServiceFunction serviceFunction = null;
+                        try {
+                            serviceFunction =
+                                    (ServiceFunction) odlSfc.executor.submit(SfcProviderServiceFunctionAPI
+                                            .getRead(new Object[]{serviceFunctionName}, new Class[]{String.class})).get();
+                        } catch (InterruptedException | ExecutionException e) {
+                            e.printStackTrace();
+                        }
+                        if (serviceFunction != null) {
                             sfpServiceFunctionBuilder.setName(serviceFunctionName)
                                     .setServiceIndex((short)service_index)
                                         .setServiceFunctionForwarder(serviceFunction.getSfDataPlaneLocator()
@@ -324,6 +476,7 @@ public class SfcProviderServicePathAPI implements Runnable {
 
     }
 
+    /*
     private void deleteServiceFunctionPathEntry (ServiceFunctionChain serviceFunctionChain) {
 
         LOG.info("\n########## Start: {}", Thread.currentThread().getStackTrace()[1]);
@@ -341,32 +494,8 @@ public class SfcProviderServicePathAPI implements Runnable {
         LOG.info("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
 
     }
+    */
 
-    public static ServiceFunctionPath readServiceFunctionPath (String path) {
-        LOG.info("\n########## Start: {}", Thread.currentThread().getStackTrace()[1]);
-        ServiceFunctionPathKey serviceFuntionPathKey = new ServiceFunctionPathKey(path);
-        InstanceIdentifier<ServiceFunctionPath> sfpIID;
-        sfpIID = InstanceIdentifier.builder(ServiceFunctionPaths.class)
-                .child(ServiceFunctionPath.class, serviceFuntionPathKey)
-                .build();
-
-        ReadOnlyTransaction readTx = odlSfc.dataProvider.newReadOnlyTransaction();
-        Optional<ServiceFunctionPath> serviceFunctionPathObject = null;
-        try {
-            serviceFunctionPathObject = readTx.read(LogicalDatastoreType.CONFIGURATION, sfpIID).get();
-        } catch (InterruptedException | ExecutionException e) {
-            e.printStackTrace();
-        }
-
-        if (serviceFunctionPathObject != null  &&
-                (serviceFunctionPathObject.get() instanceof ServiceFunctionPath)) {
-            LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
-            return serviceFunctionPathObject.get();
-        } else {
-            LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
-            return null;
-        }
-    }
 
     /*
      * We iterate through all service paths that use this service function and remove them.
@@ -474,18 +603,4 @@ public class SfcProviderServicePathAPI implements Runnable {
         LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
     }
 
-    @Override
-    public void run() {
-        if (methodName != null) {
-            Class<?> c = this.getClass();
-            Method method;
-            try {
-                method = c.getDeclaredMethod(methodName, parameterTypes);
-                method.invoke(this, parameters);
-            } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
-                e.printStackTrace();
             }
-        }
-
-    }
-}
index 19a626326f040d95ac24be90df4c03cacc4faaae..71a54f0d6b8d73f2d5de8720e8d71c9281708f6c 100644 (file)
@@ -23,128 +23,195 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.Arrays;
 import java.util.concurrent.ExecutionException;
 
 /**
  * This class has the APIs to operate on the ServiceFunctionType
  * datastore.
- *
+ * <p/>
  * It is normally called from onDataChanged() through a executor
  * service. We need to use an executor service because we can not
  * operate on a datastore while on onDataChanged() context.
- * @see org.opendaylight.sfc.provider.SfcProviderSfEntryDataListener
  *
- *
- * <p>
  * @author Reinaldo Penno ([email protected])
+ * @author Konstantin Blagov ([email protected])
  * @version 0.1
- * @since       2014-06-30
+ * @see org.opendaylight.sfc.provider.SfcProviderSfEntryDataListener
+ * <p/>
+ * <p/>
+ * <p/>
+ * @since 2014-06-30
  */
-public class SfcProviderServiceTypeAPI implements Runnable {
+public class SfcProviderServiceTypeAPI extends SfcProviderAbstractAPI {
 
     private static final Logger LOG = LoggerFactory.getLogger(SfcProviderServiceTypeAPI.class);
-    private static final OpendaylightSfc odlSfc = OpendaylightSfc.getOpendaylightSfcObj();
-    private String methodName = null;
-    private Class[] parameterTypes;
-    Object[] parameters;
-
-    SfcProviderServiceTypeAPI (Object[] params, String m) {
-        int i = 0;
-        this.methodName = m;
-        this.parameters = new Object[params.length];
-        this.parameterTypes = new Class[params.length];
-        this.parameters = Arrays.copyOf(params, params.length);
-        for (Object obj : parameters) {
-            this.parameterTypes[i] = obj.getClass();
-            i++;
-        }
 
+    SfcProviderServiceTypeAPI(Object[] params, String m) {
+        super(params, m);
+    }
+
+    SfcProviderServiceTypeAPI(Object[] params, Class[] paramsTypes, String m) {
+        super(params, paramsTypes, m);
+    }
+
+    public static SfcProviderServiceTypeAPI getPut(Object[] params, Class[] paramsTypes) {
+        return new SfcProviderServiceTypeAPI(params, paramsTypes, "putServiceFunctionType");
+    }
+
+    public static SfcProviderServiceTypeAPI getRead(Object[] params, Class[] paramsTypes) {
+        return new SfcProviderServiceTypeAPI(params, paramsTypes, "readServiceFunctionType");
+    }
+
+    public static SfcProviderServiceTypeAPI getDelete(Object[] params, Class[] paramsTypes) {
+        return new SfcProviderServiceTypeAPI(params, paramsTypes, "deleteServiceFunctionType");
+    }
+
+    public static SfcProviderServiceTypeAPI getPutAll(Object[] params, Class[] paramsTypes) {
+        return new SfcProviderServiceTypeAPI(params, paramsTypes, "putAllServiceFunctionTypes");
     }
 
-    SfcProviderServiceTypeAPI (Object[] params, Class[] paramsTypes, String m) {
-        this.methodName = 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);
+    public static SfcProviderServiceTypeAPI getReadAll(Object[] params, Class[] paramsTypes) {
+        return new SfcProviderServiceTypeAPI(params, paramsTypes, "readAllServiceFunctionTypes");
     }
 
-    public static  SfcProviderServiceTypeAPI getCreateServiceFunctionToServiceType(Object[] params, Class[] paramsTypes) {
+    public static SfcProviderServiceTypeAPI getDeleteAll(Object[] params, Class[] paramsTypes) {
+        return new SfcProviderServiceTypeAPI(params, paramsTypes, "deleteAllServiceFunctionTypes");
+    }
+
+    public static SfcProviderServiceTypeAPI getCreateServiceFunctionToServiceType(Object[] params, Class[] paramsTypes) {
         return new SfcProviderServiceTypeAPI(params, paramsTypes, "createServiceFunctionTypeEntry");
     }
 
-    public static  SfcProviderServiceTypeAPI getDeleteServiceFunctionFromServiceType (Object[] params, Class[] paramsTypes) {
+    public static SfcProviderServiceTypeAPI getDeleteServiceFunctionFromServiceType(Object[] params, Class[] paramsTypes) {
         return new SfcProviderServiceTypeAPI(params, paramsTypes, "deleteServiceFunctionTypeEntry");
     }
 
+    protected boolean putServiceFunctionType(ServiceFunctionType sft) {
+        boolean ret = false;
+        LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+        if (dataBroker != null) {
 
-    public void createServiceFunctionTypeEntry (ServiceFunction serviceFunction) {
+            InstanceIdentifier<ServiceFunctionType> sftEntryIID = InstanceIdentifier.builder(ServiceFunctionTypes.class)
+                    .child(ServiceFunctionType.class, sft.getKey()).toInstance();
 
+            WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction();
+            writeTx.merge(LogicalDatastoreType.CONFIGURATION,
+                    sftEntryIID, sft, true);
+            writeTx.commit();
 
-        LOG.debug("\n########## Start: {}", Thread.currentThread().getStackTrace()[1]);
+            ret = true;
+        }
+        LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+        return ret;
+    }
 
-        String sfkey = serviceFunction.getType();
-        ServiceFunctionTypeKey serviceFunctionTypeKey = new ServiceFunctionTypeKey(sfkey);
+    protected ServiceFunctionType readServiceFunctionType(String serviceFunctionTypeName) {
+        LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+        ServiceFunctionType sft = null;
+        InstanceIdentifier<ServiceFunctionType> sftIID;
+        ServiceFunctionTypeKey serviceFunctionTypeKey = new ServiceFunctionTypeKey(serviceFunctionTypeName);
+        sftIID = InstanceIdentifier.builder(ServiceFunctionTypes.class)
+                .child(ServiceFunctionType.class, serviceFunctionTypeKey).build();
 
-        //Build the instance identifier all the way down to the bottom child
+        if (dataBroker != null) {
+            ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction();
+            Optional<ServiceFunctionType> serviceFunctionChainDataObject = null;
+            try {
+                serviceFunctionChainDataObject = readTx.read(LogicalDatastoreType.CONFIGURATION, sftIID).get();
+            } catch (InterruptedException | ExecutionException e) {
+                e.printStackTrace();
+            }
+            if (serviceFunctionChainDataObject != null
+                    && serviceFunctionChainDataObject.isPresent()) {
+                sft = serviceFunctionChainDataObject.get();
+            }
+        }
+        LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+        return sft;
+    }
 
-        SftServiceFunctionNameKey sftServiceFunctionNameKey = new SftServiceFunctionNameKey(serviceFunction.getName());
+    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)
+                .child(ServiceFunctionType.class, serviceFunctionTypeKey).toInstance();
 
-        InstanceIdentifier<SftServiceFunctionName> sftentryIID;
-        sftentryIID = InstanceIdentifier.builder(ServiceFunctionTypes.class)
-               .child(ServiceFunctionType.class, serviceFunctionTypeKey)
-                .child(SftServiceFunctionName.class,sftServiceFunctionNameKey).build();
+        if (dataBroker != null) {
+            WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction();
+            writeTx.delete(LogicalDatastoreType.CONFIGURATION, sftEntryIID);
+            writeTx.commit();
 
+            ret = true;
+        }
+        LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+        return ret;
+    }
 
-        // Create a item in the list keyed by service function name
-        SftServiceFunctionNameBuilder sftServiceFunctionNameBuilder = new SftServiceFunctionNameBuilder();
-        sftServiceFunctionNameBuilder = sftServiceFunctionNameBuilder.setName(serviceFunction.getName());
-        SftServiceFunctionName sftServiceFunctionName = sftServiceFunctionNameBuilder.build();
+    protected boolean putAllServiceFunctionTypes(ServiceFunctionTypes sfts) {
+        boolean ret = false;
+        LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+        if (dataBroker != null) {
 
-        WriteTransaction writeTx = odlSfc.dataProvider.newWriteOnlyTransaction();
-        writeTx.merge(LogicalDatastoreType.CONFIGURATION,
-                sftentryIID, sftServiceFunctionName, true);
-        writeTx.commit();
+            InstanceIdentifier<ServiceFunctionTypes> sftsIID = InstanceIdentifier.builder(ServiceFunctionTypes.class).toInstance();
 
-        LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+            WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction();
+            writeTx.merge(LogicalDatastoreType.CONFIGURATION, sftsIID, sfts);
+            writeTx.commit();
 
+            ret = true;
+        }
+        LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+        return ret;
     }
 
-    public void deleteServiceFunctionTypeEntry (ServiceFunction serviceFunction) {
+    protected ServiceFunctionTypes readAllServiceFunctionTypes() {
+        ServiceFunctionTypes sfts = null;
+        LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+        InstanceIdentifier<ServiceFunctionTypes> sftsIID = InstanceIdentifier.builder(ServiceFunctionTypes.class).toInstance();
 
-        LOG.debug("\n########## Start: {}", Thread.currentThread().getStackTrace()[1]);
-        String sfkey = serviceFunction.getType();
-        ServiceFunctionTypeKey  serviceFunctionTypeKey = new ServiceFunctionTypeKey(sfkey);
+        if (odlSfc.getDataProvider() != null) {
+            ReadOnlyTransaction readTx = odlSfc.getDataProvider().newReadOnlyTransaction();
+            Optional<ServiceFunctionTypes> serviceFunctionTypesDataObject = null;
+            try {
+                serviceFunctionTypesDataObject = readTx.read(LogicalDatastoreType.CONFIGURATION, sftsIID).get();
+            } catch (InterruptedException | ExecutionException e) {
+                e.printStackTrace();
+            }
+            if (serviceFunctionTypesDataObject != null
+                    && serviceFunctionTypesDataObject.isPresent()) {
+                sfts = serviceFunctionTypesDataObject.get();
+            }
+        }
+        LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+        return sfts;
+    }
 
-        //Build the instance identifier all the way down to the bottom child
-        InstanceIdentifier<SftServiceFunctionName> sftentryIID;
-        SftServiceFunctionNameKey sftServiceFunctionNameKey = new SftServiceFunctionNameKey(serviceFunction.getName());
-        sftentryIID = InstanceIdentifier.builder(ServiceFunctionTypes.class).
-                child(ServiceFunctionType.class, serviceFunctionTypeKey)
-                .child(SftServiceFunctionName.class,sftServiceFunctionNameKey).build();
+    protected boolean deleteAllServiceFunctionTypes() {
+        boolean ret = false;
+        LOG.debug("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+        if (odlSfc.getDataProvider() != null) {
 
-        WriteTransaction writeTx = odlSfc.dataProvider.newWriteOnlyTransaction();
-        writeTx.delete(LogicalDatastoreType.CONFIGURATION,
-                sftentryIID);
-        writeTx.commit();
+            InstanceIdentifier<ServiceFunctionTypes> sftsIID = InstanceIdentifier.builder(ServiceFunctionTypes.class).toInstance();
+
+            WriteTransaction writeTx = odlSfc.getDataProvider().newWriteOnlyTransaction();
+            writeTx.delete(LogicalDatastoreType.CONFIGURATION, sftsIID);
+            writeTx.commit();
 
+            ret = true;
+        }
         LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+        return ret;
     }
 
-    public static ServiceFunctionType getServiceFunctionTypeList (String type) {
+    /*
+    public static ServiceFunctionType getServiceFunctionTypeList(String typeName) {
 
         LOG.debug("\n########## Start: {}", Thread.currentThread().getStackTrace()[1]);
         InstanceIdentifier<ServiceFunctionType> sftListIID;
         ServiceFunctionTypeKey serviceFunctionTypeKey;
-        serviceFunctionTypeKey = new ServiceFunctionTypeKey(type);
+        serviceFunctionTypeKey = new ServiceFunctionTypeKey(typeName);
 
-            /*
-             * We iterate thorough the list of service function types and for each one we get a suitable
-             * Service Function
-             */
         sftListIID = InstanceIdentifier.builder(ServiceFunctionTypes.class)
                 .child(ServiceFunctionType.class, serviceFunctionTypeKey).build();
 
@@ -166,19 +233,58 @@ public class SfcProviderServiceTypeAPI implements Runnable {
             return null;
         }
     }
+    */
 
-    @Override
-    public void run() {
-        if (methodName != null) {
-            Class<?> c = this.getClass();
-            Method method;
-            try {
-                method = c.getDeclaredMethod(methodName, parameterTypes);
-                method.invoke(this, parameters);
-            } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
-                e.printStackTrace();
-            }
-        }
+    public void createServiceFunctionTypeEntry(ServiceFunction serviceFunction) {
+
+        LOG.debug("\n########## Start: {}", Thread.currentThread().getStackTrace()[1]);
 
+        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());
+
+        InstanceIdentifier<SftServiceFunctionName> sftentryIID;
+        sftentryIID = InstanceIdentifier.builder(ServiceFunctionTypes.class)
+                .child(ServiceFunctionType.class, serviceFunctionTypeKey)
+                .child(SftServiceFunctionName.class, sftServiceFunctionNameKey).build();
+
+
+        // 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.dataProvider.newWriteOnlyTransaction();
+        writeTx.merge(LogicalDatastoreType.CONFIGURATION,
+                sftentryIID, sftServiceFunctionName, true);
+        writeTx.commit();
+
+        LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+
+    }
+
+    public void deleteServiceFunctionTypeEntry(ServiceFunction serviceFunction) {
+
+        LOG.debug("\n########## Start: {}", Thread.currentThread().getStackTrace()[1]);
+        String sfkey = serviceFunction.getType();
+        ServiceFunctionTypeKey serviceFunctionTypeKey = new ServiceFunctionTypeKey(sfkey);
+
+        //Build the instance identifier all the way down to the bottom child
+        InstanceIdentifier<SftServiceFunctionName> sftentryIID;
+        SftServiceFunctionNameKey sftServiceFunctionNameKey = new SftServiceFunctionNameKey(serviceFunction.getName());
+        sftentryIID = InstanceIdentifier.builder(ServiceFunctionTypes.class)
+                .child(ServiceFunctionType.class, serviceFunctionTypeKey)
+                .child(SftServiceFunctionName.class, sftServiceFunctionNameKey).build();
+
+        WriteTransaction writeTx = odlSfc.dataProvider.newWriteOnlyTransaction();
+        writeTx.delete(LogicalDatastoreType.CONFIGURATION,
+                sftentryIID);
+        writeTx.commit();
+
+        LOG.debug("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
     }
+
 }
index 486efb2f3819a9450f7c8cc02c43a6338a0b8844..d7cbcf035f275acec4cd4a1807c00196c52f3013 100644 (file)
@@ -60,7 +60,7 @@ public class SfcProviderSfEntryDataListener implements DataChangeListener  {
                 Object[] serviceTypeObj = {originalServiceFunction};
                 Class[] serviceTypeClass = {ServiceFunction.class};
 
-                odlSfc.executor.execute(SfcProviderServiceTypeAPI
+                odlSfc.executor.submit(SfcProviderServiceTypeAPI
                         .getDeleteServiceFunctionFromServiceType(serviceTypeObj, serviceTypeClass));
 
                 //Object[] sfParams = {originalServiceFunction};
@@ -71,7 +71,7 @@ public class SfcProviderSfEntryDataListener implements DataChangeListener  {
                 Object[] functionParams = {originalServiceFunction};
                 Class[] functionParamsTypes = {ServiceFunction.class};
 
-                odlSfc.executor.execute(SfcProviderServicePathAPI
+                odlSfc.executor.submit(SfcProviderServicePathAPI
                         .getDeleteServicePathContainingFunction(functionParams, functionParamsTypes));
             }
         }
@@ -87,7 +87,7 @@ public class SfcProviderSfEntryDataListener implements DataChangeListener  {
                 Object[] serviceTypeObj = {createdServiceFunction};
                 Class[] serviceTypeClass = {ServiceFunction.class};
 
-                odlSfc.executor.execute(SfcProviderServiceTypeAPI
+                odlSfc.executor.submit(SfcProviderServiceTypeAPI
                         .getCreateServiceFunctionToServiceType(serviceTypeObj, serviceTypeClass));
 
                 //Object[] sfParams = {createdServiceFunction};
@@ -108,7 +108,7 @@ public class SfcProviderSfEntryDataListener implements DataChangeListener  {
                 ServiceFunction updatedServiceFunction = (ServiceFunction) entry.getValue();
                 Object[] serviceTypeObj = {updatedServiceFunction};
                 Class[] serviceTypeClass = {ServiceFunction.class};
-                odlSfc.executor.execute(SfcProviderServiceTypeAPI
+                odlSfc.executor.submit(SfcProviderServiceTypeAPI
                         .getCreateServiceFunctionToServiceType(serviceTypeObj, serviceTypeClass));
 
                 Object[] sfParams = {updatedServiceFunction};
@@ -116,7 +116,7 @@ public class SfcProviderSfEntryDataListener implements DataChangeListener  {
                 //odlSfc.executor.execute(SfcProviderServiceForwarderAPI
                 //        .getUpdateServiceForwarderAPI(sfParams, sfParamsTypes ));
 
-                odlSfc.executor.execute(SfcProviderServicePathAPI
+                odlSfc.executor.submit(SfcProviderServicePathAPI
                         .getUpdateServicePathContainingFunction(sfParams, sfParamsTypes));
             }
         }
index abca394490f90eca0b87e0e7f711db3dbd6214e0..e4de91c089b7d0ea8e34d1809df4071a69354a05 100644 (file)
@@ -67,7 +67,7 @@ public class SfcProviderSfcEntryDataListener implements DataChangeListener {
                 LOG.debug("\n########## Created ServiceFunctionChain name: {}", createdServiceFunctionChain.getName());
                 Object[] serviceChainObj = {createdServiceFunctionChain};
                 Class[] serviceChainClass = {ServiceFunctionChain.class};
-                odlSfc.executor.execute(SfcProviderServiceChainAPI
+                odlSfc.executor.submit(SfcProviderServiceChainAPI
                         .getAddChainToChainState(serviceChainObj, serviceChainClass));
                 List<SfcServiceFunction>  SfcServiceFunctionList = createdServiceFunctionChain.getSfcServiceFunction();
                 for (SfcServiceFunction sfcServiceFunction : SfcServiceFunctionList) {
index d4f5ec400b4c3879582eefc064c7236eaa6a0415..5145bde16587fb5f21060935c92fbc3313dc1d5f 100644 (file)
@@ -61,7 +61,7 @@ public class SfcProviderSfpEntryDataListener implements DataChangeListener {
                 LOG.debug("\n########## Created ServiceFunctionChain name: {}", createdServiceFunctionPath.getName());
                 Object[] servicePathObj = {createdServiceFunctionPath};
                 Class[] servicePathClass = {ServiceFunctionPath.class};
-                odlSfc.executor.execute(SfcProviderServicePathAPI
+                odlSfc.executor.submit(SfcProviderServicePathAPI
                         .getCreateServicePathAPI(servicePathObj, servicePathClass));
             }
         }
@@ -76,7 +76,7 @@ public class SfcProviderSfpEntryDataListener implements DataChangeListener {
                         updatedServiceFunctionPath.getName());
                 Object[] servicePathObj = {updatedServiceFunctionPath};
                 Class[] servicePathClass = {ServiceFunctionPath.class};
-                odlSfc.executor.execute(SfcProviderServicePathAPI
+                odlSfc.executor.submit(SfcProviderServicePathAPI
                         .getUpdateServicePathAPI(servicePathObj, servicePathClass));
             }
         }
@@ -90,7 +90,7 @@ public class SfcProviderSfpEntryDataListener implements DataChangeListener {
                 Object[] serviceTypeObj = {originalServiceFunctionPath};
                 Class[] serviceTypeClass = {ServiceFunctionPath.class};
 
-                odlSfc.executor.execute(SfcProviderServiceFunctionAPI
+                odlSfc.executor.submit(SfcProviderServiceFunctionAPI
                         .getDeleteServicePathFromServiceFunctionState(serviceTypeObj, serviceTypeClass));
             }
         }
similarity index 83%
rename from sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcSftMapper.java
rename to sfc-provider/src/main/java/org/opendaylight/sfc/provider/util/SfcSftMapper.java
index 2608de6d320d3fa6a9dfffdd03125cf1916a2e28..3d751984c60875e400d36efe86399b205302e141 100755 (executable)
@@ -1,8 +1,10 @@
-package org.opendaylight.sfc.provider;
+package org.opendaylight.sfc.provider.util;
 
 import com.google.common.base.Optional;
 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.sfc.provider.OpendaylightSfc;
+import org.opendaylight.sfc.provider.SfcProviderServiceFunctionAPI;
 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.sn.rev140701.ServiceNodes;
 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sn.rev140701.service.nodes.ServiceNode;
@@ -16,7 +18,7 @@ import java.util.concurrent.ExecutionException;
 /**
  * This class maps service function types to service node mappers
  *
- * @see org.opendaylight.sfc.provider.SfcSnMapper
+ * @see SfcSnMapper
  * <p>
  * @author Konstantin Blagov ([email protected])
  * @version 0.1
@@ -35,7 +37,7 @@ public class SfcSftMapper {
 
     public void update() {
         if (odlSfc != null) {
-            ReadOnlyTransaction readTx = odlSfc.dataProvider.newReadOnlyTransaction();
+            ReadOnlyTransaction readTx = odlSfc.getDataProvider().newReadOnlyTransaction();
             Optional<ServiceNodes> dataObject = null;
             try {
                 dataObject = readTx.read(LogicalDatastoreType.CONFIGURATION, OpendaylightSfc.snIID).get();
@@ -49,7 +51,13 @@ public class SfcSftMapper {
                 for(ServiceNode sn : snList){
                     List<String> sfNameList = sn.getServiceFunction();
                     for(String sfName : sfNameList){
-                        ServiceFunction sf = SfcProviderServiceFunctionAPI.readServiceFunction(sfName);
+                        ServiceFunction sf = null;
+                        try {
+                            sf = (ServiceFunction) odlSfc.executor.submit(SfcProviderServiceFunctionAPI.getRead(
+                                    new Object[]{sfName}, new Class[]{String.class})).get();
+                        } catch (InterruptedException | ExecutionException e) {
+                            e.printStackTrace();
+                        }
                         if ( sf != null) {
                             this.add(sf.getType(), sn.getName(), sf);
                         } else {
similarity index 96%
rename from sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcSnMapper.java
rename to sfc-provider/src/main/java/org/opendaylight/sfc/provider/util/SfcSnMapper.java
index 7e1a0ca26fe53a4157b2748173a5c1474c789c60..155bcba668487dd6bdec552c00a86f573fc3fcdd 100755 (executable)
@@ -1,4 +1,4 @@
-package org.opendaylight.sfc.provider;
+package org.opendaylight.sfc.provider.util;
 
 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sf.rev140701.service.functions.ServiceFunction;