Stage 2 of SFC Provider Application 86/8586/1
authorReinaldo Penno <[email protected]>
Wed, 2 Jul 2014 23:13:34 +0000 (16:13 -0700)
committerReinaldo Penno <[email protected]>
Wed, 2 Jul 2014 23:13:34 +0000 (16:13 -0700)
- Provider plug-in
- Changes to parent pom to compile provider plug-in

Change-Id: I2bf3624a05e233e292bd60d9cc102addf291ac3a
Signed-off-by: Reinaldo Penno <[email protected]>
15 files changed:
pom.xml
sfc-provider/.gitignore [new file with mode: 0644]
sfc-provider/pom.xml [new file with mode: 0644]
sfc-provider/src/main/java/org/opendaylight/controller/config/yang/config/sfc_provider/impl/SfcProviderModule.java [new file with mode: 0644]
sfc-provider/src/main/java/org/opendaylight/controller/config/yang/config/sfc_provider/impl/SfcProviderModuleFactory.java [new file with mode: 0644]
sfc-provider/src/main/java/org/opendaylight/sfc/provider/OpendaylightSfc.java [new file with mode: 0644]
sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcProviderDebug.java [new file with mode: 0644]
sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcProviderRpc.java [new file with mode: 0644]
sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcProviderSfDataListener.java [new file with mode: 0644]
sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcProviderSfcDataListener.java [new file with mode: 0644]
sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcProviderSffDataListener.java [new file with mode: 0644]
sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcProviderSfpDataListener.java [new file with mode: 0644]
sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcProviderSnDataListener.java [new file with mode: 0644]
sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcProviderUnitTest.java [new file with mode: 0644]
sfc-provider/src/main/yang/sfc-provider-impl.yang [new file with mode: 0644]

diff --git a/pom.xml b/pom.xml
index 5c74d5ad45edd227f013d620f92f488123824491..89387fd03602cfb288641e6b28fdaec8937ca2f3 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -33,5 +33,6 @@
     <modules>
         <module>model</module>
         <module>sfc-model</module>
+        <module>sfc-provider</module>
     </modules>
 </project>
diff --git a/sfc-provider/.gitignore b/sfc-provider/.gitignore
new file mode 100644 (file)
index 0000000..5647ebf
--- /dev/null
@@ -0,0 +1,29 @@
+*.class
+**/target
+bin/
+dist
+**/logs
+products
+repository
+workspace
+*~
+1target
+target-ide
+.classpath
+.project
+.settings
+MANIFEST.MF
+opendaylight/northbound/integrationtest/logs/*
+*.ipr
+*.iml
+*.iws
+.idea
+xtend-gen
+yang-gen-config
+yang-gen-sal
+classes
+out/
+.externalToolBuilders
+maven-eclipse.xml
+.DS_STORE
+.metadata
\ No newline at end of file
diff --git a/sfc-provider/pom.xml b/sfc-provider/pom.xml
new file mode 100644 (file)
index 0000000..bb16fd3
--- /dev/null
@@ -0,0 +1,312 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.opendaylight.sfc</groupId>
+        <artifactId>parent</artifactId>
+        <version>0.0.1-SNAPSHOT</version>
+        <relativePath>../</relativePath>
+    </parent>
+    <groupId>org.opendaylight.sfc</groupId>
+    <artifactId>sfc-provider</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+    <packaging>bundle</packaging>
+
+    <properties>
+        <bundle.plugin.version>2.4.0</bundle.plugin.version>
+        <checkstyle.version>2.10</checkstyle.version>
+        <compiler.version>2.3.2</compiler.version>
+        <config.version>0.2.5-SNAPSHOT</config.version>
+        <ietf.model.version>2010.09.24.4-SNAPSHOT</ietf.model.version>
+        <jmxGeneratorPath>src/main/yang-gen-config</jmxGeneratorPath>
+        <mdsal.version>1.1-SNAPSHOT</mdsal.version>
+        <nexusproxy>http://nexus.opendaylight.org/content</nexusproxy>
+        <osgi.core.version>5.0.0</osgi.core.version>
+        <salGeneratorPath>src/main/yang-gen-sal</salGeneratorPath>
+        <yang.ext.version>2013.09.07.4-SNAPSHOT</yang.ext.version>
+        <yangtools.generator.version>0.6.2-SNAPSHOT</yangtools.generator.version>
+        <yangtools.version>0.6.2-SNAPSHOT</yangtools.version>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>sfc-model</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+            <version>1.7.2</version>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.controller</groupId>
+            <artifactId>config-api</artifactId>
+            <version>${config.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.controller</groupId>
+            <artifactId>sal-binding-api</artifactId>
+            <version>${mdsal.version}</version>
+        </dependency>
+       <dependency>
+            <groupId>org.opendaylight.controller</groupId>
+            <artifactId>sal-common-api</artifactId>
+            <version>${mdsal.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.controller</groupId>
+            <artifactId>sal-binding-config</artifactId>
+            <version>${mdsal.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.controller</groupId>
+            <artifactId>sal-binding-util</artifactId>
+            <version>${mdsal.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.controller</groupId>
+            <artifactId>sal-broker-impl</artifactId>
+            <version>${mdsal.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.controller</groupId>
+            <artifactId>sal-common</artifactId>
+            <version>${mdsal.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.controller</groupId>
+            <artifactId>sal-common-util</artifactId>
+            <version>${mdsal.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.controller</groupId>
+            <artifactId>yang-jmx-generator</artifactId>
+            <version>${config.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.controller</groupId>
+            <artifactId>yang-jmx-generator</artifactId>
+            <version>${config.version}</version>
+            <type>test-jar</type>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.controller</groupId>
+            <artifactId>yang-jmx-generator-plugin</artifactId>
+            <version>${config.version}</version>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+            <version>${osgi.core.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>yang-binding</artifactId>
+            <version>${yangtools.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>binding-generator-impl</artifactId>
+            <version>${yangtools.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>concepts</artifactId>
+            <version>${yangtools.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>binding-generator-util</artifactId>
+            <version>${yangtools.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>binding-type-provider</artifactId>
+            <version>${yangtools.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>yang-common</artifactId>
+            <version>${yangtools.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.sonatype.plugins</groupId>
+            <artifactId>munge-maven-plugin</artifactId>
+            <version>1.0</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>${compiler.version}</version>
+                <inherited>true</inherited>
+                <configuration>
+                    <source>1.7</source>
+                    <target>1.7</target>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <version>${bundle.plugin.version}</version>
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                        <Export-Package>org.opendaylight.controller.sfc.*;</Export-Package>
+                        <Bundle-Name>${project.groupId}.${project.artifactId}</Bundle-Name>
+                    </instructions>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-checkstyle-plugin</artifactId>
+                <version>${checkstyle.version}</version>
+                <configuration>
+                    <failsOnError>true</failsOnError>
+                    <configLocation>../checkstyle.xml</configLocation>
+                    <consoleOutput>true</consoleOutput>
+                    <includeTestSourceDirectory>true</includeTestSourceDirectory>
+                    <sourceDirectory>${project.basedir}</sourceDirectory>
+                    <includes>**\/*.yang</includes>
+                    <excludes>**\/target\/,**\/bin\/,**\/third-party,**\/yang-gen-sal</excludes>
+                </configuration>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>check</goal>
+                        </goals>
+                        <phase>process-sources</phase>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.opendaylight.yangtools</groupId>
+                <artifactId>yang-maven-plugin</artifactId>
+                <version>${yangtools.version}</version>
+                <executions>
+                    <execution>
+                        <id>config</id>
+                        <goals>
+                            <goal>generate-sources</goal>
+                        </goals>
+                        <configuration>
+                            <codeGenerators>
+                                <generator>
+                                    <codeGeneratorClass>org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator</codeGeneratorClass>
+                                    <outputBaseDir>${jmxGeneratorPath}</outputBaseDir>
+                                    <additionalConfiguration>
+                                        <namespaceToPackage1>urn:opendaylight:params:xml:ns:yang:controller==org.opendaylight.controller.config.yang</namespaceToPackage1>
+                                    </additionalConfiguration>
+                                </generator>
+                                <generator>
+                                    <codeGeneratorClass>org.opendaylight.yangtools.maven.sal.api.gen.plugin.CodeGeneratorImpl</codeGeneratorClass>
+                                    <outputBaseDir>${salGeneratorPath}</outputBaseDir>
+                                </generator>
+                            </codeGenerators>
+                            <inspectDependencies>true</inspectDependencies>
+                        </configuration>
+                    </execution>
+                </executions>
+                <dependencies>
+                    <dependency>
+                        <groupId>org.opendaylight.controller</groupId>
+                        <artifactId>yang-jmx-generator-plugin</artifactId>
+                        <version>${config.version}</version>
+                        <scope>compile</scope>
+                    </dependency>
+                    <dependency>
+                        <groupId>org.opendaylight.yangtools</groupId>
+                        <artifactId>maven-sal-api-gen-plugin</artifactId>
+                        <version>${yangtools.version}</version>
+                        <scope>compile</scope>
+                    </dependency>
+                    <dependency>
+                        <groupId>org.osgi</groupId>
+                        <artifactId>org.osgi.core</artifactId>
+                        <version>${osgi.core.version}</version>
+                        <scope>compile</scope>
+                    </dependency>
+                </dependencies>
+            </plugin>
+        </plugins>
+        <pluginManagement>
+            <plugins>
+                <plugin>
+                    <groupId>org.opendaylight.yangtools</groupId>
+                    <artifactId>yang-maven-plugin</artifactId>
+                    <version>${yangtools.version}</version>
+                </plugin>
+            </plugins>
+        </pluginManagement>
+    </build>
+    <scm>
+        <connection>scm:git:ssh://git.opendaylight.org:29418/controller.git</connection>
+        <developerConnection>scm:git:ssh://git.opendaylight.org:29418/controller.git</developerConnection>
+        <tag>HEAD</tag>
+        <url>https://wiki.opendaylight.org/view/OpenDaylight_Controller:MD-SAL</url>
+    </scm>
+
+    <repositories>
+        <!-- Opendaylight public group -->
+        <repository>
+            <snapshots>
+                <enabled>false</enabled>
+            </snapshots>
+            <id>odlPublic</id>
+            <name>odlPublic</name>
+            <url>${nexusproxy}/groups/public/</url>
+        </repository>
+        <!-- OpenDayLight Snapshot artifact -->
+        <repository>
+            <releases>
+                <enabled>false</enabled>
+            </releases>
+            <id>opendaylight-snapshot</id>
+            <url>${nexusproxy}/repositories/opendaylight.snapshot/</url>
+        </repository>
+    </repositories>
+
+    <pluginRepositories>
+        <!-- Opendaylight public group -->
+        <pluginRepository>
+            <snapshots>
+                <enabled>false</enabled>
+            </snapshots>
+            <id>odlPublic</id>
+            <name>odlPublic</name>
+            <url>${nexusproxy}/groups/public/</url>
+        </pluginRepository>
+        <!-- OpenDayLight Snapshot artifact -->
+        <pluginRepository>
+            <releases>
+                <enabled>false</enabled>
+            </releases>
+            <id>opendaylight-snapshot</id>
+            <url>${nexusproxy}/repositories/opendaylight.snapshot/</url>
+        </pluginRepository>
+    </pluginRepositories>
+
+    <distributionManagement>
+        <!-- OpenDayLight Released artifact -->
+        <repository>
+            <id>opendaylight-release</id>
+            <url>${nexusproxy}/repositories/opendaylight.release/</url>
+        </repository>
+        <!-- OpenDayLight Snapshot artifact -->
+        <snapshotRepository>
+            <id>opendaylight-snapshot</id>
+            <url>${nexusproxy}/repositories/opendaylight.snapshot/</url>
+        </snapshotRepository>
+        <!-- Site deployment -->
+        <!-- site>
+                <id>website</id>
+                <url>${sitedeploy}</url>
+            </site -->
+    </distributionManagement>
+</project>
diff --git a/sfc-provider/src/main/java/org/opendaylight/controller/config/yang/config/sfc_provider/impl/SfcProviderModule.java b/sfc-provider/src/main/java/org/opendaylight/controller/config/yang/config/sfc_provider/impl/SfcProviderModule.java
new file mode 100644 (file)
index 0000000..cdf22ce
--- /dev/null
@@ -0,0 +1,124 @@
+/*
+ * 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.controller.config.yang.config.sfc_provider.impl;
+
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
+import org.opendaylight.controller.sal.binding.api.data.DataChangeListener;
+import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
+import org.opendaylight.sfc.provider.OpendaylightSfc;
+import org.opendaylight.sfc.provider.SfcProviderRpc;
+import org.opendaylight.sfc.provider.SfcProviderSfDataListener;
+import org.opendaylight.sfc.provider.SfcProviderSfcDataListener;
+import org.opendaylight.sfc.provider.SfcProviderSfpDataListener;
+import org.opendaylight.sfc.provider.SfcProviderSnDataListener;
+import org.opendaylight.sfc.provider.SfcProviderSffDataListener;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfc.rev140630.ServiceFunctionChainService;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sf.rev140629.*;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This class is called from the MD-SAL infra in order to bootstrap
+ * the SFC Provider plug-in
+ *
+ * <p>
+ * @author Reinaldo Penno ([email protected])
+ * @author Konstantin Blagov ()
+ * @version 0.1
+ * @since       2014-06-30
+ * @see org.opendaylight.controller.config.yang.config.sfc_provider.impl.SfcProviderModule
+ */
+
+
+public class SfcProviderModule extends org.opendaylight.controller.config.yang.config.sfc_provider.impl.AbstractSfcProviderModule {
+
+    private static final Logger LOG = LoggerFactory.getLogger(SfcProviderModule.class);    
+    
+    public SfcProviderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
+        super(identifier, dependencyResolver);
+    }
+
+    public SfcProviderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.controller.config.yang.config.sfc_provider.impl.SfcProviderModule oldModule, java.lang.AutoCloseable oldInstance) {
+        super(identifier, dependencyResolver, oldModule, oldInstance);
+    }
+
+    @Override
+    public void customValidation() {
+        // add custom validation form module attributes here.
+    }
+
+    /*
+     *  This is the entry point for SFc Provider
+     */
+    @Override
+    public java.lang.AutoCloseable createInstance() {
+        final OpendaylightSfc opendaylightSfc = new OpendaylightSfc();
+
+
+        DataProviderService dataBrokerService = getDataBrokerDependency();
+        opendaylightSfc.setDataProvider(dataBrokerService);
+
+        final SfcProviderRpc sfcProviderRpc = new SfcProviderRpc();
+
+        SfcProviderSfDataListener sfcProviderSfDataListener = new SfcProviderSfDataListener();
+        SfcProviderSfcDataListener sfcProviderSfcDataListener = new SfcProviderSfcDataListener();
+        SfcProviderSfpDataListener sfcProviderSfpDataListener = new SfcProviderSfpDataListener();
+        SfcProviderSnDataListener sfcProviderSnDataListener = new SfcProviderSnDataListener();
+        SfcProviderSffDataListener sfcProviderSffDataListener = new SfcProviderSffDataListener();
+
+        // We listen for changes in all datastore trees with specific objects for each one
+        final ListenerRegistration<DataChangeListener> sfDataChangeListenerRegistration =
+                dataBrokerService.registerDataChangeListener( OpendaylightSfc.sfIID, sfcProviderSfDataListener);
+        final ListenerRegistration<DataChangeListener> snDataChangeListenerRegistration =
+                dataBrokerService.registerDataChangeListener( OpendaylightSfc.snIID, sfcProviderSnDataListener );
+        final ListenerRegistration<DataChangeListener> sfpDataChangeListenerRegistration =
+                dataBrokerService.registerDataChangeListener( OpendaylightSfc.sfpIID, sfcProviderSfpDataListener );
+        final ListenerRegistration<DataChangeListener> sfcDataChangeListenerRegistration =
+                dataBrokerService.registerDataChangeListener( OpendaylightSfc.sfcIID, sfcProviderSfcDataListener  );
+        final ListenerRegistration<DataChangeListener> sffDataChangeListenerRegistration =
+                dataBrokerService.registerDataChangeListener( OpendaylightSfc.sffIID, sfcProviderSffDataListener );
+
+        final BindingAwareBroker.RpcRegistration<ServiceFunctionService> sfRpcRegistration =
+                getRpcRegistryDependency()
+                        .addRpcImplementation(ServiceFunctionService.class,
+                                sfcProviderRpc);
+        final BindingAwareBroker.RpcRegistration<ServiceFunctionChainService> sfcRpcRegistration =
+                getRpcRegistryDependency()
+                        .addRpcImplementation(ServiceFunctionChainService.class,
+                                sfcProviderRpc);
+
+        // close()
+        final class AutoCloseableSfc implements AutoCloseable {
+
+            @Override
+            public void close() throws Exception {
+                sfDataChangeListenerRegistration.close();
+                snDataChangeListenerRegistration.close();
+                sfpDataChangeListenerRegistration.close();
+                sfcDataChangeListenerRegistration.close();
+                sffDataChangeListenerRegistration.close();
+                sfRpcRegistration.close();
+                sfcRpcRegistration.close();
+
+                //runtimeReg.close();
+                opendaylightSfc.close();
+                LOG.info("SFC provider (instance {}) torn down.", this);
+            }
+        }
+
+        AutoCloseable ret = new AutoCloseableSfc();
+        LOG.info("SFC provider (instance {}) initialized.", ret);
+        return ret;
+    }
+
+
+}
diff --git a/sfc-provider/src/main/java/org/opendaylight/controller/config/yang/config/sfc_provider/impl/SfcProviderModuleFactory.java b/sfc-provider/src/main/java/org/opendaylight/controller/config/yang/config/sfc_provider/impl/SfcProviderModuleFactory.java
new file mode 100644 (file)
index 0000000..e1e6929
--- /dev/null
@@ -0,0 +1,13 @@
+/*
+* Generated file
+*
+* Generated from: yang module name: sfc-provider-impl yang module local name: sfc-provider-impl
+* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
+* Generated at: Fri Jun 13 15:24:40 PDT 2014
+*
+* Do not modify this file unless it is present under src/main directory
+*/
+package org.opendaylight.controller.config.yang.config.sfc_provider.impl;
+public class SfcProviderModuleFactory extends org.opendaylight.controller.config.yang.config.sfc_provider.impl.AbstractSfcProviderModuleFactory {
+
+}
diff --git a/sfc-provider/src/main/java/org/opendaylight/sfc/provider/OpendaylightSfc.java b/sfc-provider/src/main/java/org/opendaylight/sfc/provider/OpendaylightSfc.java
new file mode 100644 (file)
index 0000000..a6356dd
--- /dev/null
@@ -0,0 +1,110 @@
+/*
+ * 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 com.google.common.util.concurrent.Futures;
+import org.opendaylight.controller.sal.binding.api.AbstractBindingAwareProvider;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
+import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
+import org.opendaylight.controller.sal.binding.api.data.DataBrokerService;
+import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
+import org.opendaylight.controller.sal.common.util.Rpcs;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sf.rev140629.ServiceFunctions;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sn.rev140630.ServiceNodes;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfp.rev140626.ServiceFunctionPaths;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfc.rev140630.ServiceFunctionChains;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sff.rev140630.ServiceFunctionForwarders;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.RpcService;
+import org.opendaylight.yangtools.yang.common.RpcError;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+
+/**
+ * This the main SFC Provider class. It is instantiated from the
+ * SFCProviderModule class.
+ *
+ * <p>
+ * @author Konstantin Blagov ()
+ * @author Reinaldo Penno ([email protected])
+ * @version 0.1
+ * @since       2014-06-30
+ * @see org.opendaylight.controller.config.yang.config.sfc_provider.impl.SfcProviderModule
+ */
+
+public class OpendaylightSfc implements AutoCloseable {
+
+
+   private static final Logger LOG = LoggerFactory.getLogger(OpendaylightSfc.class);
+   public static final InstanceIdentifier<ServiceFunctions>  sfIID =
+           InstanceIdentifier.builder(ServiceFunctions.class).build();
+   public static final InstanceIdentifier<ServiceNodes>  snIID =
+           InstanceIdentifier.builder(ServiceNodes.class).build();
+   public static final InstanceIdentifier<ServiceFunctionPaths>  sfpIID =
+           InstanceIdentifier.builder(ServiceFunctionPaths.class).build();
+   public static final InstanceIdentifier<ServiceFunctionChains>  sfcIID =
+           InstanceIdentifier.builder(ServiceFunctionChains.class).build();
+   public static final InstanceIdentifier<ServiceFunctionForwarders>  sffIID =
+           InstanceIdentifier.builder(ServiceFunctionForwarders.class).build();
+
+   private ExecutorService executor;
+   protected DataBrokerService dataProvider;
+   private static OpendaylightSfc opendaylightSfcObj;
+
+   private Future<RpcResult<Void>> currentTask;
+
+   public OpendaylightSfc() {
+
+       executor = Executors.newFixedThreadPool(1);
+       opendaylightSfcObj = this;
+   }
+
+   private Future<RpcResult<Void>> inProgressError() {
+       RpcResult<Void> result = Rpcs.<Void> getRpcResult(false, null, Collections.<RpcError> emptySet());
+       return Futures.immediateFuture(result);
+   }
+
+   public void setDataProvider(DataBrokerService salDataProvider) {
+       this.dataProvider = salDataProvider;
+   }
+
+    public DataBrokerService getDataProvider(DataBrokerService salDataProvider) {
+        return this.dataProvider;
+    }
+
+    public static OpendaylightSfc getOpendaylightSfcObj () {
+        return OpendaylightSfc.opendaylightSfcObj;
+    }
+
+   /**
+    * Implemented from the AutoCloseable interface.
+    */
+    @Override
+    public void close() throws ExecutionException, InterruptedException {
+        // When we close this service we need to shutdown our executor!
+        executor.shutdown();
+
+        if (dataProvider != null) {
+            final DataModificationTransaction t = dataProvider.beginTransaction();
+            t.removeOperationalData(sfIID);
+            t.removeOperationalData(sfcIID);
+            t.removeOperationalData(snIID);
+            t.removeOperationalData(sffIID);
+            t.removeOperationalData(sfpIID);
+            t.commit().get();
+        }
+    }
+}
diff --git a/sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcProviderDebug.java b/sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcProviderDebug.java
new file mode 100644 (file)
index 0000000..c27171b
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * 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;
+
+/**
+ * This class is used to control unit test coding and debugging
+ *
+ * Example:
+ *
+ * if (SfcProviderDebug.ON) {
+ *   ...
+ * }
+ *
+ * <p>
+ * @author Reinaldo Penno ([email protected])
+ * @version 0.1
+ * @since       2014-06-30
+ */
+public final class SfcProviderDebug {
+
+    public static boolean ON = false;
+}
\ No newline at end of file
diff --git a/sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcProviderRpc.java b/sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcProviderRpc.java
new file mode 100644 (file)
index 0000000..681c445
--- /dev/null
@@ -0,0 +1,245 @@
+/*
+ * 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 com.google.common.util.concurrent.Futures;
+import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
+import org.opendaylight.controller.sal.common.util.Rpcs;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.RpcError;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfc.rev140630.ServiceFunctionChains;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfc.rev140630.ServiceFunctionChainService;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sf.rev140629.ServiceFunctions;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sf.rev140629.service.functions.*;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sf.rev140629.*;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfc.rev140630.ServiceFunctionChainsBuilder;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfc.rev140630.PutServiceFunctionChainsInput;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+
+
+/**
+ * This class holds all RPCs methods for SFC Provider.
+ *
+ * <p>
+ * @author Reinaldo Penno ([email protected])
+ * @author Konstantin Blagov ()
+ * @version 0.1
+ * @since       2014-06-30
+ */
+
+public class SfcProviderRpc implements ServiceFunctionService, ServiceFunctionChainService {
+
+    private static final Logger LOG = LoggerFactory
+            .getLogger(SfcProviderRpc.class);
+    private OpendaylightSfc odlSfc = OpendaylightSfc.getOpendaylightSfcObj();
+    private SfcProviderRpc sfcRpcObj;
+
+    /*
+    public SfcProviderRpc () {
+        this.sfcRpcObj = this;
+    }
+    */
+
+    public static SfcProviderRpc getSfcProviderRpc() {
+        return new SfcProviderRpc();
+    }
+
+
+    private ServiceFunctions buildServiceFunctions(List<ServiceFunction> list) {
+
+        ServiceFunctionsBuilder builder = new ServiceFunctionsBuilder();
+        builder.setServiceFunction(list);
+        return builder.build();
+    }
+
+    @Override
+    public Future<RpcResult<Void>> putServiceFunction(PutServiceFunctionInput input) {
+        LOG.info("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+        LOG.info("\n####### Input: " + input);
+
+
+        if (odlSfc.dataProvider != null) {
+            ServiceFunctionBuilder sfbuilder = new ServiceFunctionBuilder();
+            ServiceFunctionKey sfkey = new ServiceFunctionKey(input.getName());
+            ServiceFunction sf = sfbuilder.setName(input.getName()).setType(input.getType())
+                    .setKey(sfkey).setIpMgmtAddress(input.getIpMgmtAddress()).build();
+
+            InstanceIdentifier<ServiceFunction>  sfIID = InstanceIdentifier.builder(ServiceFunctions.class).
+                    child(ServiceFunction.class, sf.getKey()).toInstance();
+            final DataModificationTransaction t = odlSfc.dataProvider
+                    .beginTransaction();
+
+            t.putConfigurationData(sfIID, sf);
+            try {
+                t.commit().get();
+            } catch (ExecutionException | InterruptedException e) {
+                LOG.warn("Failed to update-function, operational otherwise", e);
+            }
+
+        } else {
+            LOG.warn("\n####### Data Provider is NULL : {}", Thread.currentThread().getStackTrace()[1]);
+        }
+        LOG.info("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+        return Futures.immediateFuture(Rpcs.<Void>getRpcResult(true,
+                Collections.<RpcError>emptySet()));
+    }
+
+    @Override
+    public Future<RpcResult<ReadServiceFunctionOutput>> readServiceFunction(ReadServiceFunctionInput input) {
+        LOG.info("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+        LOG.info("Input: " + input);
+
+        if (odlSfc.dataProvider != null) {
+            String name = input.getName();
+            ServiceFunctionKey sfkey = new ServiceFunctionKey(input.getName());
+            InstanceIdentifier<ServiceFunction> sfIID;
+            sfIID = InstanceIdentifier.builder(ServiceFunctions.class).
+                    child(ServiceFunction.class, sfkey).toInstance();
+            DataObject dataObject = odlSfc.dataProvider.readConfigurationData(sfIID);
+            if (dataObject instanceof ServiceFunction) {
+                LOG.info("readServiceFunction Success: {}", ((ServiceFunction) dataObject).getName());
+                ServiceFunction sf = (ServiceFunction) dataObject;
+                ReadServiceFunctionOutput rsfoutput = null;
+                ReadServiceFunctionOutputBuilder outputBuilder = new ReadServiceFunctionOutputBuilder();
+                outputBuilder.setName(sf.getName())
+                        .setIpMgmtAddress(sf.getIpMgmtAddress())
+                        .setType(sf.getType());
+                rsfoutput = outputBuilder.build();
+                LOG.info("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+                return Futures.immediateFuture(Rpcs.<ReadServiceFunctionOutput>getRpcResult(true, rsfoutput, Collections.<RpcError>emptySet()));
+            }
+            LOG.info("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+            return Futures.immediateFuture(Rpcs.<ReadServiceFunctionOutput>getRpcResult(true, null, Collections.<RpcError>emptySet()));
+        } else {
+            LOG.warn("dataProvider is null");
+            LOG.info("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+            return Futures.immediateFuture(Rpcs.<ReadServiceFunctionOutput>getRpcResult(true, null, Collections.<RpcError>emptySet()));
+        }
+    }
+
+    @Override
+    public Future<RpcResult<Void>> deleteAllServiceFunction() {
+        LOG.info("\n########## Start: {}", Thread.currentThread().getStackTrace()[1]);
+        if (odlSfc.dataProvider != null) {
+            final DataModificationTransaction t = odlSfc.dataProvider
+                    .beginTransaction();
+            t.removeConfigurationData(odlSfc.sfIID);
+            try {
+                t.commit().get();
+            } catch (InterruptedException | ExecutionException e) {
+                LOG.warn("deleteServiceFunction failed", e);
+            }
+        } else {
+            LOG.warn("dataProvider is null");
+        }
+        LOG.info("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+        return Futures.immediateFuture(Rpcs.<Void>getRpcResult(true,
+                Collections.<RpcError>emptySet()));
+    }
+
+    @Override
+    public Future<RpcResult<Void>> deleteServiceFunction(DeleteServiceFunctionInput input) {
+        LOG.info("\n########## Start: {}", Thread.currentThread().getStackTrace()[1]);
+        LOG.info("Input: " + input);
+        if (odlSfc.dataProvider != null) {
+            DataObject dataObject = odlSfc.dataProvider.readConfigurationData(odlSfc.sfIID);
+            if (dataObject instanceof ServiceFunctions) {
+
+                ServiceFunctionKey sfkey = new ServiceFunctionKey(input.getName());
+                InstanceIdentifier<ServiceFunction> sfIID;
+                sfIID = InstanceIdentifier.builder(ServiceFunctions.class).
+                        child(ServiceFunction.class, sfkey).toInstance();
+
+                final DataModificationTransaction t = odlSfc.dataProvider
+                        .beginTransaction();
+                t.removeConfigurationData(sfIID);
+                try {
+                    t.commit().get();
+                } catch (InterruptedException | ExecutionException e) {
+                    LOG.warn("deleteServiceFunction failed", e);
+                }
+            }
+        } else {
+            LOG.warn("dataProvider is null");
+        }
+        LOG.info("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+        return Futures.immediateFuture(Rpcs.<Void>getRpcResult(true,
+                Collections.<RpcError>emptySet()));
+    }
+
+    @Override
+    public Future<RpcResult<Void>> putServiceFunctionChains(PutServiceFunctionChainsInput input) {
+        LOG.info("\n####### Start: {}", Thread.currentThread().getStackTrace()[1]);
+        ServiceFunctionChainsBuilder builder = new ServiceFunctionChainsBuilder();
+        builder = builder.setServiceFunctionChain(input.getServiceFunctionChain());
+
+        ServiceFunctionChains sfcs = builder.build();
+
+        if (odlSfc.dataProvider != null) {
+            final DataModificationTransaction t = odlSfc.dataProvider.beginTransaction();
+            t.putConfigurationData(odlSfc.sfcIID, sfcs);
+
+            try {
+                t.commit().get();
+            } catch (ExecutionException | InterruptedException e) {
+                LOG.warn("putServiceFunctionChain failed, operational otherwise", e);
+            }
+        } else {
+            LOG.warn("dataProvider is null");
+        }
+        return Futures.immediateFuture(Rpcs.<Void>getRpcResult(true,
+                Collections.<RpcError>emptySet()));
+    }
+
+    public Future<RpcResult<Void>> updateFunctionDpiWa20()  {
+        LOG.info("\n########## Start: {}", Thread.currentThread().getStackTrace()[1]);
+        IpAddress ip = new IpAddress("10.0.0.11".toCharArray());
+        ServiceFunctionBuilder sfbuilder = new ServiceFunctionBuilder();
+        ServiceFunctionKey sfkey = new ServiceFunctionKey("fw-wa");
+        sfbuilder.setKey(sfkey);
+        ServiceFunction sf = sfbuilder.setName("fw-wa")
+                .setType(Firewall.class)
+                .setIpMgmtAddress(ip).build();
+
+
+        LOG.info("updateFunctionDpiWa20: bbb\n");
+        if (odlSfc.dataProvider != null) {
+            LOG.info("updateFunctionDpiWa20: dataProvider not null\n");
+            final DataModificationTransaction t = odlSfc.dataProvider
+                    .beginTransaction();
+
+            InstanceIdentifier<ServiceFunction>  sfIID = InstanceIdentifier.builder(ServiceFunctions.class).
+                    child(ServiceFunction.class, sf.getKey()).toInstance();
+
+            t.putConfigurationData(sfIID, sf);
+            try {
+                t.commit().get();
+            } catch (ExecutionException | InterruptedException e) {
+                LOG.warn("Failed to update-function, operational otherwise", e);
+            }
+        }
+        else{
+            LOG.info("updateFunctionDpiWa20: dataProvider not null\n");
+        }
+        LOG.info("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+        return Futures.immediateFuture(Rpcs.<Void> getRpcResult(true,
+                Collections.<RpcError> emptySet()));
+    }
+}
diff --git a/sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcProviderSfDataListener.java b/sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcProviderSfDataListener.java
new file mode 100644 (file)
index 0000000..0ec4154
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * 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.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sf.rev140629.ServiceFunctions;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sf.rev140629.service.functions.*;
+
+
+import org.opendaylight.controller.md.sal.common.api.data.DataChangeEvent;
+import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
+import org.opendaylight.controller.sal.binding.api.data.DataChangeListener;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This class gets called whenever there is a change to
+ * the Service Functions data store.
+ *
+ * <p>
+ * @author Reinaldo Penno ([email protected])
+ * @version 0.1
+ * @since       2014-06-30
+ */
+
+public class SfcProviderSfDataListener implements DataChangeListener {
+
+    private static final Logger LOG = LoggerFactory.getLogger(SfcProviderSfDataListener.class);
+
+    @Override
+    public void onDataChanged(
+            DataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
+
+        LOG.info("\n########## Start: {}", Thread.currentThread().getStackTrace()[1]);
+
+        boolean b = change.getUpdatedConfigurationData().containsKey(OpendaylightSfc.sfIID);
+        DataObject dataObject = change.getUpdatedConfigurationData().get( OpendaylightSfc.sfIID );
+        if( dataObject instanceof  ServiceFunctions)
+        {
+            ServiceFunctions servicefunctions = (ServiceFunctions)dataObject;
+            for (ServiceFunction servicefunction : servicefunctions.getServiceFunction()) {
+                LOG.info("\n Service Function name: {}", servicefunction.getName());
+            }
+            LOG.info("\n########## Caught ServiceFunctions: {}", Thread.currentThread().getStackTrace()[1]);
+        }
+        // Debug and Unit Test. We trigger the unit test code by adding a service function to the datastore.
+        if (SfcProviderDebug.ON) {
+            SfcProviderDebug.ON = false;
+            SfcProviderUnitTest.sfcProviderUnitTest(SfcProviderRpc.getSfcProviderRpc());
+        }
+
+        LOG.info("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+    }
+}
diff --git a/sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcProviderSfcDataListener.java b/sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcProviderSfcDataListener.java
new file mode 100644 (file)
index 0000000..a455b0e
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * 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.common.api.data.DataChangeEvent;
+import org.opendaylight.controller.sal.binding.api.data.DataChangeListener;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sf.rev140629.ServiceFunctions;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sf.rev140629.service.functions.ServiceFunction;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * This class gets called whenever there is a change to
+ * the Service Functions data store.
+ *
+ * <p>
+ * @author Reinaldo Penno ([email protected])
+ * @version 0.1
+ * @since       2014-06-30
+ */
+public class SfcProviderSfcDataListener implements DataChangeListener {
+
+    private static final Logger LOG = LoggerFactory.getLogger(SfcProviderSfcDataListener.class);
+
+    @Override
+    public void onDataChanged(
+            DataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
+
+        LOG.info("\n########## Start: {}", Thread.currentThread().getStackTrace()[1]);
+
+
+
+        LOG.info("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+    }
+}
diff --git a/sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcProviderSffDataListener.java b/sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcProviderSffDataListener.java
new file mode 100644 (file)
index 0000000..13dd2ce
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * 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.common.api.data.DataChangeEvent;
+import org.opendaylight.controller.sal.binding.api.data.DataChangeListener;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This class holds all RPCs methods for SFC Provider.
+ *
+ * <p>
+ * @author Reinaldo Penno ([email protected])
+ * @version 0.1
+ * @since       2014-06-30
+ */
+public class SfcProviderSffDataListener implements DataChangeListener  {
+
+    private static final Logger LOG = LoggerFactory.getLogger(SfcProviderSnDataListener.class);
+
+    @Override
+    public void onDataChanged(
+            DataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
+
+        LOG.info("\n########## Start: {}", Thread.currentThread().getStackTrace()[1]);
+
+
+        LOG.info("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+    }
+
+}
diff --git a/sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcProviderSfpDataListener.java b/sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcProviderSfpDataListener.java
new file mode 100644 (file)
index 0000000..83aaeff
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * 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.common.api.data.DataChangeEvent;
+import org.opendaylight.controller.sal.binding.api.data.DataChangeListener;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This class holds all RPCs methods for SFC Provider.
+ *
+ * <p>
+ * @author Reinaldo Penno ([email protected])
+ * @version 0.1
+ * @since       2014-06-30
+ */
+
+public class SfcProviderSfpDataListener implements DataChangeListener {
+
+    private static final Logger LOG = LoggerFactory.getLogger(SfcProviderSfpDataListener.class);
+
+    @Override
+    public void onDataChanged(
+            DataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
+
+        LOG.info("\n########## Start: {}", Thread.currentThread().getStackTrace()[1]);
+
+
+        LOG.info("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+    }
+}
diff --git a/sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcProviderSnDataListener.java b/sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcProviderSnDataListener.java
new file mode 100644 (file)
index 0000000..443d999
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * 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.common.api.data.DataChangeEvent;
+import org.opendaylight.controller.sal.binding.api.data.DataChangeListener;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This class holds all RPCs methods for SFC Provider.
+ *
+ * <p>
+ * @author Reinaldo Penno ([email protected])
+ * @version 0.1
+ * @since       2014-06-30
+ */
+
+public class SfcProviderSnDataListener implements DataChangeListener {
+
+    private static final Logger LOG = LoggerFactory.getLogger(SfcProviderSnDataListener.class);
+
+    @Override
+    public void onDataChanged(
+            DataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
+
+        LOG.info("\n########## Start: {}", Thread.currentThread().getStackTrace()[1]);
+
+
+        LOG.info("\n########## Stop: {}", Thread.currentThread().getStackTrace()[1]);
+    }
+}
diff --git a/sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcProviderUnitTest.java b/sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcProviderUnitTest.java
new file mode 100644 (file)
index 0000000..db50bb8
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * 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.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sf.rev140629.*;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfc.rev140630.PutServiceFunctionChainsInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfc.rev140630.service.function.chain.grouping.ServiceFunctionChain;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfc.rev140630.service.function.chain.grouping.ServiceFunctionChainBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfc.rev140630.service.function.chain.grouping.service.function.chain.*;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * This class is a harness for live unit Testing. It has static
+ * methods that can are used to test various SFC datastore operations.
+ * <p>
+ * @author Reinaldo Penno ([email protected])
+ * @author Konstantin Blagov ()
+ * @version 0.1
+ * @since       2014-06-30
+ */
+public class SfcProviderUnitTest {
+    private static final Logger LOG = LoggerFactory.getLogger(SfcProviderUnitTest.class);
+    // Delete all Service Functions
+    public static void sfcProviderUnitTest(SfcProviderRpc sfcRpcObj) {
+        sfcRpcObj.deleteAllServiceFunction();
+        // Put one Service Function
+        PutServiceFunctionInputBuilder psfibuilder = new PutServiceFunctionInputBuilder();
+        IpAddress ip = new IpAddress("10.0.0.1".toCharArray());
+        PutServiceFunctionInput psfi = psfibuilder.setName("test-fw-ca").setType(Firewall.class).setIpMgmtAddress(ip).build();
+        sfcRpcObj.putServiceFunction(psfi);
+        // Put one Service Function
+        psfibuilder = new PutServiceFunctionInputBuilder();
+        ip = new IpAddress("10.0.0.2".toCharArray());
+        psfi = psfibuilder.setName("test-fw-ut").setType(Firewall.class).setIpMgmtAddress(ip).build();
+        sfcRpcObj.putServiceFunction(psfi);
+        // Delete one Service Function
+        DeleteServiceFunctionInputBuilder dsfibuilder = new DeleteServiceFunctionInputBuilder();
+        DeleteServiceFunctionInput dsfi = dsfibuilder.setName("test-fw-ca").build();
+        sfcRpcObj.deleteServiceFunction(dsfi);
+        // Read One Service Function
+        ReadServiceFunctionInputBuilder rsfibuilder = new ReadServiceFunctionInputBuilder();
+        ReadServiceFunctionInput rsfi = rsfibuilder.setName("test-fw-ut").build();
+        try {
+            RpcResult<ReadServiceFunctionOutput> result = sfcRpcObj.readServiceFunction(rsfi).get();
+            if (result.isSuccessful()) {
+                ReadServiceFunctionOutput rsfo = result.getResult();
+                LOG.info("\n########## Read Service Function: {}", rsfo.getType());
+            } else {
+                LOG.warn("Read Service Function RPC not successfully finished");
+            }
+        } catch (Exception e) {
+            LOG.warn("Error occurred during SF Read Test: " + e);
+        }
+        //Put a service chain. We need to build a list of lists.
+        PutServiceFunctionChainsInputBuilder psfcibuilder = new PutServiceFunctionChainsInputBuilder();
+        ServiceFunctionChainBuilder sfcbuilder = new ServiceFunctionChainBuilder();
+
+        List<ServiceFunctionChain> sfclist = new ArrayList<>();
+        List<ServiceFunctionType> sftlist = new ArrayList<>();
+
+        ServiceFunctionTypeBuilder sftBuilder = new ServiceFunctionTypeBuilder();
+        sftlist.add(sftBuilder.setName("napt44-testB").setType("napt44").build());
+        sftlist.add(sftBuilder.setName("firewall-testB").setType("firewall").build());
+        sftlist.add(sftBuilder.setName("dpi-testB").setType("dpi").build());
+
+        // Now we add list function type list to Service Chain list.
+        sfclist.add(sfcbuilder.setName("Chain-1").setServiceFunctionType(sftlist).build());
+
+        psfcibuilder = psfcibuilder.setServiceFunctionChain(sfclist);
+        sfcRpcObj.putServiceFunctionChains(psfcibuilder.build());
+
+    }
+}
diff --git a/sfc-provider/src/main/yang/sfc-provider-impl.yang b/sfc-provider/src/main/yang/sfc-provider-impl.yang
new file mode 100644 (file)
index 0000000..9ab8110
--- /dev/null
@@ -0,0 +1,56 @@
+// vi: set smarttab et sw=4 tabstop=4:
+module sfc-provider-impl {
+
+  yang-version 1;
+  namespace "urn:opendaylight:params:xml:ns:yang:controller:config:sfc-provider:impl";
+  prefix "sfc-provider-impl";
+
+  import config { prefix config; revision-date 2013-04-05; }
+  import rpc-context { prefix rpcx; revision-date 2013-06-17; }
+  import opendaylight-md-sal-binding { prefix mdsal; revision-date 2013-10-28; }
+
+
+  description
+      "This module contains the base YANG definitions for
+      sfc-provider impl implementation.";
+
+  revision "2014-05-13" {
+      description
+          "Initial revision.";
+  }
+
+  // This is the definition of the service implementation as a module identity
+  identity sfc-provider-impl {
+      base config:module-type;
+
+      // Specifies the prefix for generated java classes.
+      config:java-name-prefix SfcProvider;
+  }
+
+
+  // Augments the 'configuration' choice node under modules/module.
+  augment "/config:modules/config:module/config:configuration" {
+    case service-function-provider-impl {
+      when "/config:modules/config:module/config:type = 'sfc-provider-impl'";
+
+      //wires in the data-broker service
+      container data-broker {
+        uses config:service-ref {
+          refine type {
+              mandatory false;
+              config:required-identity mdsal:binding-data-broker;
+          }
+        }
+      }
+
+      container rpc-registry {
+        uses config:service-ref {
+          refine type {
+             mandatory true;
+             config:required-identity mdsal:binding-rpc-registry;
+          }
+        }
+      }
+    }
+  }
+}