Merge "Few Validations for Match/Actios in FRMUtil"
authorEd Warnicke <eaw@cisco.com>
Wed, 4 Dec 2013 00:59:00 +0000 (00:59 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Wed, 4 Dec 2013 00:59:00 +0000 (00:59 +0000)
65 files changed:
opendaylight/config/pom.xml
opendaylight/config/yang-test-plugin/pom.xml [new file with mode: 0644]
opendaylight/config/yang-test-plugin/src/main/java/org/opendaylight/controller/config/yang/test/plugin/DeleteSources.java [new file with mode: 0644]
opendaylight/config/yang-test-plugin/src/main/java/org/opendaylight/controller/config/yang/test/plugin/ProcessSources.java [new file with mode: 0644]
opendaylight/config/yang-test-plugin/src/main/java/org/opendaylight/controller/config/yang/test/plugin/Util.java [new file with mode: 0644]
opendaylight/config/yang-test-plugin/src/main/resources/Header.txt [new file with mode: 0644]
opendaylight/config/yang-test/pom.xml
opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/DepTestImplModule.java
opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/DepTestImplModuleFactory.java
opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModule.java
opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModuleFactory.java
opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModuleUtil.java
opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/TestImplModule.java
opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/TestImplModuleFactory.java
opendaylight/config/yang-test/src/main/yang/config-test-impl.yang
opendaylight/forwardingrulesmanager/implementation/src/main/java/org/opendaylight/controller/forwardingrulesmanager/internal/ForwardingRulesManager.java
opendaylight/md-sal/clustered-data-store/implementation/pom.xml
opendaylight/md-sal/forwardingrules-manager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/consumer/impl/FRMConsumerImpl.java
opendaylight/md-sal/forwardingrules-manager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/consumer/impl/GroupConsumerImpl.java
opendaylight/md-sal/forwardingrules-manager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/consumer/impl/MeterConsumerImpl.java
opendaylight/md-sal/model/pom.xml
opendaylight/md-sal/sal-binding-broker/pom.xml
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/BindingAwareBrokerImpl.xtend
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/OsgiProviderContext.xtend
opendaylight/md-sal/sal-binding-broker/src/main/yang/opendaylight-binding-broker-impl.yang
opendaylight/md-sal/sal-binding-config/pom.xml
opendaylight/md-sal/sal-dom-api/pom.xml
opendaylight/md-sal/sal-dom-broker/pom.xml
opendaylight/md-sal/sal-netconf-connector/pom.xml
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/config/yang/md/sal/connector/netconf/NetconfConnectorModule.java
opendaylight/md-sal/sal-rest-connector/pom.xml
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/JsonMapper.java
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.xtend
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/TestUtils.java
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/ToJsonIdentityrefTest.java [new file with mode: 0644]
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/ToJsonLeafrefType.java [new file with mode: 0644]
opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/identityref/identity-module.yang [new file with mode: 0644]
opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/identityref/identityref-module.yang [new file with mode: 0644]
opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/leafref/cont-augment-module.yang [new file with mode: 0644]
opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/leafref/main-module.yang [new file with mode: 0644]
opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/leafref/xml/data_absolut_ref_to_existing_leaf.xml [new file with mode: 0644]
opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/leafref/xml/data_from_leafref_to_leafref.xml [new file with mode: 0644]
opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/leafref/xml/data_ref_to_non_existing_leaf.xml [new file with mode: 0644]
opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/leafref/xml/data_ref_to_not_leaf.xml [new file with mode: 0644]
opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/leafref/xml/data_relativ_ref_from_leaflist_to_existing_leaf.xml [new file with mode: 0644]
opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/leafref/xml/data_relativ_ref_to_existing_leaf.xml [new file with mode: 0644]
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/attributes/resolving/SimpleAttributeResolvingStrategy.java
opendaylight/netconf/config-netconf-connector/src/test/java/org/opendaylight/controller/netconf/confignetconfconnector/NetconfMappingTest.java
opendaylight/netconf/config-persister-impl/src/main/java/org/opendaylight/controller/netconf/persist/impl/ConfigPersisterNotificationHandler.java
opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClientDispatcher.java
opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfSshClientDispatcher.java
opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/NetconfServerDispatcher.java
opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfImplActivator.java
opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/ConcurrentClientsTest.java
opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/NetconfDispatcherImplTest.java
opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITSecureTest.java
opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITTest.java
opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/osgi/NetconfSSHActivator.java
opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/AbstractChannelInitializer.java
opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/AbstractSslChannelInitializer.java [deleted file]
opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/handler/NetconfHandlerFactory.java [new file with mode: 0644]
opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/osgi/NetconfConfigUtil.java
opendaylight/netconf/netconf-util/src/test/resources/netconfMessages/editConfig.xml
opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/SwitchHandler.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/match/Match.java

index c9ed19dacb2c0256f811025e2be01409b09e5bbc..99437979de214aa4177d13f739f00f7e171f6210 100644 (file)
@@ -39,6 +39,7 @@
         <module>netty-event-executor-config</module>
         <module>netty-timer-config</module>
         <module>config-persister-directory-adapter</module>
+        <module>yang-test-plugin</module>
     </modules>
 
     <profiles>
                                     </generator>
                                     <generator>
                                         <codeGeneratorClass>org.opendaylight.yangtools.yang.unified.doc.generator.maven.DocumentationGeneratorImpl</codeGeneratorClass>
-                                        <outputBaseDir>target/site</outputBaseDir>
+                                        <outputBaseDir>target/site/models</outputBaseDir>
                                     </generator>
                                 </codeGenerators>
                                 <inspectDependencies>true</inspectDependencies>
diff --git a/opendaylight/config/yang-test-plugin/pom.xml b/opendaylight/config/yang-test-plugin/pom.xml
new file mode 100644 (file)
index 0000000..30ac855
--- /dev/null
@@ -0,0 +1,28 @@
+<?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">
+    <parent>
+        <groupId>org.opendaylight.controller</groupId>
+        <artifactId>config-plugin-parent</artifactId>
+        <version>0.2.3-SNAPSHOT</version>
+        <relativePath>../config-plugin-parent</relativePath>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+    <packaging>maven-plugin</packaging>
+    <artifactId>yang-test-plugin</artifactId>
+
+    <description>Remove generated source files, after new files generation, implementation is inserted.</description>
+    <name>${project.artifactId}</name>
+    <prerequisites>
+        <maven>3.0.4</maven>
+    </prerequisites>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.maven</groupId>
+            <artifactId>maven-plugin-api</artifactId>
+            <version>3.0.5</version>
+        </dependency>
+    </dependencies>
+</project>
\ No newline at end of file
diff --git a/opendaylight/config/yang-test-plugin/src/main/java/org/opendaylight/controller/config/yang/test/plugin/DeleteSources.java b/opendaylight/config/yang-test-plugin/src/main/java/org/opendaylight/controller/config/yang/test/plugin/DeleteSources.java
new file mode 100644 (file)
index 0000000..4610662
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2013 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.test.plugin;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+import java.io.File;
+
+/**
+ * Delete all Module/ModuleFactory sources
+ *
+ * @goal delete-sources
+ *
+ * @phase initialize
+ */
+public class DeleteSources extends AbstractMojo{
+    /**
+     * @parameter expression="${project.build.sourceDirectory}"
+     * @readOnly
+     * @required
+     */
+    private File directory;
+
+    @Override
+    public void execute() throws MojoExecutionException, MojoFailureException {
+        if (directory == null || !directory.exists()) {
+            super.getLog().error("Directory does not exists.");
+        }
+        File sourceDirectory = new File(directory.getPath() + Util.replaceDots(".org.opendaylight.controller.config.yang.test.impl"));
+        if (sourceDirectory == null || !sourceDirectory.exists()) {
+            super.getLog().error("Source directory does not exists " + sourceDirectory.getPath());
+        }
+        File[] sourceFiles = sourceDirectory.listFiles();
+        for (File sourceFile: sourceFiles) {
+            if(sourceFile.getName().endsWith("Module.java") || sourceFile.getName().endsWith("ModuleFactory.java")) {
+                super.getLog().debug("Source file deleted: " + sourceFile.getName());
+                sourceFile.delete();
+            }
+        }
+    }
+}
diff --git a/opendaylight/config/yang-test-plugin/src/main/java/org/opendaylight/controller/config/yang/test/plugin/ProcessSources.java b/opendaylight/config/yang-test-plugin/src/main/java/org/opendaylight/controller/config/yang/test/plugin/ProcessSources.java
new file mode 100644 (file)
index 0000000..dbb9ddb
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 2013 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.test.plugin;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+
+/**
+ * Add implementation code from stub.txt
+ *
+ * @goal process-sources
+ *
+ * @phase process-sources
+ *
+ */
+public class ProcessSources extends AbstractMojo{
+    /**
+     * @parameter expression="${project.build.sourceDirectory}"
+     * @readOnly
+     * @required
+     */
+    private File directory;
+
+    @Override
+    public void execute() throws MojoExecutionException, MojoFailureException {
+        if (directory == null || !directory.exists()) {
+            super.getLog().error("Directory does not exists.");
+        }
+        File sourceDirectory = new File(directory.getPath() + Util.replaceDots(".org.opendaylight.controller.config.yang.test.impl"));
+        if (!sourceDirectory.exists()) {
+            super.getLog().error("Source directory does not exists " + sourceDirectory.getPath());
+        }
+        String header = "";
+        try {
+            header = Util.loadHeader();
+        } catch (IOException e) {
+           super.getLog().error("Header.txt not found.");
+        }
+        File[] sourceFiles = sourceDirectory.listFiles();
+        for (File sourceFile: sourceFiles) {
+            if(sourceFile.getName().endsWith("Module.java") || sourceFile.getName().endsWith("ModuleFactory.java")) {
+                File stubFile = new File(sourceFile.getPath().replace(".java", "Stub.txt"));
+                String stubLines = null;
+                try {
+                    if (stubFile.exists()) {
+                        stubLines = Util.loadStubFile(stubFile.getPath());
+                    }
+
+                    InputStream javaIn = new FileInputStream(sourceFile.getPath());
+                    BufferedReader javaBuf = new BufferedReader(new InputStreamReader(javaIn));
+                    StringBuffer output = new StringBuffer();
+                    String line = javaBuf.readLine();
+                    boolean writeLine = false;
+                    while ((line = javaBuf.readLine()) != null) {
+                        if(!writeLine && line.contains("*/")) {
+                            line = header;
+                            writeLine = true;
+                        } else {
+                            if (line.contains("TODO")) {
+                                writeLine = false;
+                            } else {
+                                if (stubLines != null && line.contains("throw new")) {
+                                    line = stubLines.toString();
+                                    writeLine = true;
+                                }
+                            }
+                        }
+                        if(writeLine) {
+                            output.append(line).append(System.lineSeparator());
+                        }
+                    }
+                    javaBuf.close();
+
+                    OutputStream javaOut = new FileOutputStream(sourceFile.getPath());
+                    javaOut.write(output.toString().getBytes());
+                    javaOut.close();
+                } catch (IOException e) {
+                    getLog().error("Error while reading/writing to files.", e);
+                }
+
+            }
+        }
+    }
+}
diff --git a/opendaylight/config/yang-test-plugin/src/main/java/org/opendaylight/controller/config/yang/test/plugin/Util.java b/opendaylight/config/yang-test-plugin/src/main/java/org/opendaylight/controller/config/yang/test/plugin/Util.java
new file mode 100644 (file)
index 0000000..16a41d9
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2013 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.test.plugin;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.regex.Matcher;
+
+public class Util {
+
+    public static String replaceDots(String path) {
+        path = path.replace(".", Matcher.quoteReplacement(File.separator));
+        return path;
+    }
+
+    public static String loadHeader() throws IOException {
+        StringBuffer header = new StringBuffer();
+        InputStream headIn = Util.class.getClassLoader().getResourceAsStream("Header.txt");
+        BufferedReader headBuf = new BufferedReader(new InputStreamReader(headIn));
+        String line = null;
+        while ((line = headBuf.readLine()) != null) {
+            header.append(line).append(System.lineSeparator());
+        }
+        headBuf.close();
+        return header.toString();
+    }
+
+    public static String loadStubFile(String fileName) throws IOException {
+        InputStream stubIn = new FileInputStream(fileName);
+        BufferedReader stubBuf = new BufferedReader(new InputStreamReader(stubIn));
+
+        StringBuffer stubLines = new StringBuffer();
+        String stubLine = null;
+        while ((stubLine = stubBuf.readLine()) != null) {
+            stubLines.append(stubLine).append(System.lineSeparator());
+        }
+        stubBuf.close();
+        return stubLines.toString();
+    }
+}
diff --git a/opendaylight/config/yang-test-plugin/src/main/resources/Header.txt b/opendaylight/config/yang-test-plugin/src/main/resources/Header.txt
new file mode 100644 (file)
index 0000000..068fd26
--- /dev/null
@@ -0,0 +1,7 @@
+/*
+ * Copyright (c) 2013 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
+ */
\ No newline at end of file
index e3737c78f34d584e4771dc8df99b466d1897a828..149348df4b2234e7c54c49f59fd7f7118e9d0c91 100644 (file)
                     </dependency>
                 </dependencies>
             </plugin>
+            <plugin>
+                <groupId>org.opendaylight.controller</groupId>
+                <artifactId>yang-test-plugin</artifactId>
+                <version>${config.version}</version>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>delete-sources</goal>
+                            <goal>process-sources</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
         </plugins>
     </build>
 </project>
index 1122c1ffa46a16078623850314bb4cee3fd4aef0..c64f824b150f07c6f2179a6b8ab65909d9774454 100644 (file)
@@ -1,3 +1,11 @@
+/*
+ * Copyright (c) 2013 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.test.impl;
 
 /**
@@ -28,5 +36,6 @@ public final class DepTestImplModule extends org.opendaylight.controller.config.
             public void close() throws Exception {
             }
         };
+
     }
 }
index 4152736768ca9ce12d089cb1fb039a536b712c47..c26c29ed60636f94b8dc73405cbaf7ecc948aa6b 100644 (file)
@@ -1,3 +1,11 @@
+/*
+ * Copyright (c) 2013 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.test.impl;
 
 /**
index 7e1848dd6a7f20f6692d5dc5f5cfefd49b587190..3594ee03538f4f2bb097f319cba13a679bc39960 100644 (file)
@@ -1,3 +1,11 @@
+/*
+ * Copyright (c) 2013 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.test.impl;
 
 /**
@@ -23,6 +31,7 @@ public final class NetconfTestImplModule extends org.opendaylight.controller.con
 
     @Override
     public java.lang.AutoCloseable createInstance() {
-        return NetconfTestImplModuleUtil.registerRuntimeBeans(this);
+return NetconfTestImplModuleUtil.registerRuntimeBeans(this);
+
     }
 }
index 7cab5288680b9f2cfe454d3630c1e92f3b29d3bc..accc1db76e72cf5292a8ece54cc31fb71644ead4 100644 (file)
@@ -1,3 +1,11 @@
+/*
+ * Copyright (c) 2013 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.test.impl;
 
 /**
index 58943c9df2d8db2f2bc336a9ca2e335027894efa..4de980433753e4165f66dec8fe2eb7081073ddd5 100644 (file)
@@ -1,10 +1,9 @@
-/**
- * @author Tomas Olvecky
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
  *
- * 11 2013
- *
- * Copyright (c) 2013 by Cisco Systems, Inc.
- * 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.test.impl;
 
index 52a71620bf0062f929e2496dac32d094f66d7157..9ba1db4eedc7b690499704ff6da29cb7275438d5 100644 (file)
@@ -1,3 +1,11 @@
+/*
+ * Copyright (c) 2013 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.test.impl;
 
 /**
@@ -28,5 +36,6 @@ public final class TestImplModule extends org.opendaylight.controller.config.yan
             public void close() throws Exception {
             }
         };
+
     }
 }
index ce9aa92b64ea0f4c61911b0f969c71ed048bac21..a6ce734f96ac83fe14c31d24b4b7e1e1b2094c5c 100644 (file)
@@ -1,3 +1,11 @@
+/*
+ * Copyright (c) 2013 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.test.impl;
 
 /**
index df636fd0ef3297eb3f87870afa38d8cd18098cf5..ba5021ea099361fd5d548e318a6448811020177f 100644 (file)
@@ -119,6 +119,12 @@ module config-test-impl {
                 type tt:extend-enum;
             }
 
+            leaf sleep-factor {
+                type decimal64 {
+                    fraction-digits 2;
+                }
+            }
+
            container dto-c {
                 leaf simple-arg {
                     type uint32;
index e639d41e8e1ea819fa4c56fb4fbbfbc3c481af28..45fb11a83eda110b96b1588dd43b0c8fd6c7b164 100644 (file)
@@ -847,6 +847,17 @@ public class ForwardingRulesManager implements
         }
 
         if (add) {
+            // there may be an already existing entry.
+            // remove it before adding the new one.
+            // This is necessary since we have observed that in some cases
+            // Infinispan does aggregation for operations (eg:- remove and then put a different value)
+            // related to the same key within the same transaction.
+            // Need this defensive code as the new FlowEntryInstall may be different
+            // than the old one even though the equals method returns true. This is because
+            // the equals method does not take into account the action list.
+            if(nodeIndeces.contains(flowEntries)) {
+                nodeIndeces.remove(flowEntries);
+            }
             nodeIndeces.add(flowEntries);
         } else {
             nodeIndeces.remove(flowEntries);
@@ -881,6 +892,11 @@ public class ForwardingRulesManager implements
         }
 
         if (add) {
+            // same comments in the similar code section in
+            // updateNodeFlowsDB method apply here too
+            if(indices.contains(flowEntries)) {
+                indices.remove(flowEntries);
+            }
             indices.add(flowEntries);
         } else {
             indices.remove(flowEntries);
@@ -1215,7 +1231,7 @@ public class ForwardingRulesManager implements
         if (policyName != null && !policyName.trim().isEmpty()) {
             for (Map.Entry<FlowEntry, FlowEntry> entry : this.originalSwView.entrySet()) {
                 if (policyName.equals(entry.getKey().getGroupName())) {
-                    list.add(entry.getKey().clone());
+                    list.add(entry.getValue().clone());
                 }
             }
         }
@@ -1228,7 +1244,7 @@ public class ForwardingRulesManager implements
         if (policyName != null && !policyName.trim().isEmpty()) {
             for (Map.Entry<FlowEntryInstall, FlowEntryInstall> entry : this.installedSwView.entrySet()) {
                 if (policyName.equals(entry.getKey().getGroupName())) {
-                    list.add(entry.getKey().getInstall().clone());
+                    list.add(entry.getValue().getInstall().clone());
                 }
             }
         }
@@ -2610,7 +2626,7 @@ public class ForwardingRulesManager implements
 
         // replay the installedSwView data structure to populate
         // node flows and group flows
-        for (FlowEntryInstall fei : installedSwView.keySet()) {
+        for (FlowEntryInstall fei : installedSwView.values()) {
             pendingEvents.offer(new UpdateIndexDBs(fei, true));
         }
 
@@ -3031,7 +3047,7 @@ public class ForwardingRulesManager implements
          * Streamline the updates for the per node and per group index databases
          */
         if (cacheName.equals(INSTALLED_SW_VIEW_CACHE)) {
-            pendingEvents.offer(new UpdateIndexDBs((FlowEntryInstall)key, true));
+            pendingEvents.offer(new UpdateIndexDBs((FlowEntryInstall)new_value, true));
         }
 
         if (originLocal) {
@@ -3101,7 +3117,7 @@ public class ForwardingRulesManager implements
         if (node != null) {
             for (Map.Entry<FlowEntry, FlowEntry> entry : this.originalSwView.entrySet()) {
                 if (node.equals(entry.getKey().getNode())) {
-                    list.add(entry.getKey().clone());
+                    list.add(entry.getValue().clone());
                 }
             }
         }
index 07ff98b9c521324536efdb292d425d933de8332e..9cbf35576f49ace3b4f6c26b8e7404f951f45c0a 100644 (file)
                                         </namespaceToPackage1>
                                     </additionalConfiguration>
                                 </generator>
+                                <generator>
+                                    <codeGeneratorClass>org.opendaylight.yangtools.yang.unified.doc.generator.maven.DocumentationGeneratorImpl</codeGeneratorClass>
+                                    <outputBaseDir>target/site/models</outputBaseDir>
+                                </generator>
                             </codeGenerators>
                             <inspectDependencies>true</inspectDependencies>
                         </configuration>
                         <artifactId>yang-jmx-generator-plugin</artifactId>
                         <version>0.2.3-SNAPSHOT</version>
                     </dependency>
+                    <dependency>
+                        <groupId>org.opendaylight.yangtools</groupId>
+                        <artifactId>maven-sal-api-gen-plugin</artifactId>
+                        <version>0.6.0-SNAPSHOT</version>
+                        <type>jar</type>
+                    </dependency>
                 </dependencies>
             </plugin>
         </plugins>
index d42e067334491421b3810a5272360875631c263d..bbe771fd9cc5164c155e71a43196bd36fe50a780 100644 (file)
@@ -29,14 +29,13 @@ public class FRMConsumerImpl extends AbstractBindingAwareProvider implements Com
     private static NotificationService notificationService;
     private FlowConsumerImpl flowImplRef;
     private GroupConsumerImpl groupImplRef;
+    private MeterConsumerImpl meterImplRef;
     private static DataProviderService dataProviderService;
-
-       private static IClusterContainerServices clusterContainerService = null;
-       private static IContainer container;
-       
-       @Override
+    private static IClusterContainerServices clusterContainerService = null;
+    private static IContainer container;
+    
+    @Override
     public void onSessionInitiated(ProviderContext session) {
-
         FRMConsumerImpl.p_session = session;
 
         if (!getDependentModule()) {
@@ -56,7 +55,8 @@ public class FRMConsumerImpl extends AbstractBindingAwareProvider implements Com
 
                     if (null != dataProviderService) {
                         flowImplRef = new FlowConsumerImpl();
-                        // groupImplRef = new GroupConsumerImpl();
+                        groupImplRef = new GroupConsumerImpl();
+                        meterImplRef = new MeterConsumerImpl();
                         registerWithOSGIConsole();
                     } else {
                         logger.error("Data Provider Service is down or NULL. "
@@ -99,35 +99,32 @@ public class FRMConsumerImpl extends AbstractBindingAwareProvider implements Com
         BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
         bundleContext.registerService(CommandProvider.class.getName(), this, null);
     }
-       
-       private boolean getDependentModule() {
-           do {
-        clusterContainerService = (IClusterContainerServices) ServiceHelper.getGlobalInstance(IClusterContainerServices.class, this);
-        try {
-            Thread.sleep(4);
-        } catch (InterruptedException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        }
-           } while(clusterContainerService == null);
-           
-           do {
-               
-           
-        container = (IContainer) ServiceHelper.getGlobalInstance(IContainer.class, this);
-        try {
-            Thread.sleep(5);
-        } catch (InterruptedException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        }
-           } while (container == null);
-           
-          
-        return true;
-       }
 
-       
+    private boolean getDependentModule() {
+        do {
+            clusterContainerService = (IClusterContainerServices) ServiceHelper.getGlobalInstance(
+                    IClusterContainerServices.class, this);
+            try {
+                Thread.sleep(4);
+            } catch (InterruptedException e) {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            }
+        } while (clusterContainerService == null);
+
+        do {
+
+            container = (IContainer) ServiceHelper.getGlobalInstance(IContainer.class, this);
+            try {
+                Thread.sleep(5);
+            } catch (InterruptedException e) {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            }
+        } while (container == null);
+
+        return true;
+    }
 
     public static DataProviderService getDataProviderService() {
         return dataProviderService;
@@ -138,9 +135,8 @@ public class FRMConsumerImpl extends AbstractBindingAwareProvider implements Com
     }
 
     public GroupConsumerImpl getGroupImplRef() {
-       return groupImplRef;
+        return groupImplRef;
     }
-               
 
     public static ProviderContext getProviderSession() {
         return p_session;
index 381faa41b082ea069df75ca8b5a82736d94fd642..7d16cb5b428452dfa25e110ebbc7ad795c298a18 100644 (file)
@@ -58,7 +58,7 @@ public class GroupConsumerImpl implements IForwardingRulesManager {
     private final GroupEventListener groupEventListener = new GroupEventListener();
     private Registration<NotificationListener> groupListener;
     private SalGroupService groupService;
-    private GroupDataCommitHandler commitHandler;
+    private GroupDataCommitHandler groupCommitHandler;
 
     private ConcurrentMap<GroupKey, Group> originalSwGroupView;
     private ConcurrentMap<GroupKey, Group> installedSwGroupView;
@@ -74,9 +74,6 @@ public class GroupConsumerImpl implements IForwardingRulesManager {
         InstanceIdentifier<? extends DataObject> path = InstanceIdentifier.builder(Groups.class).toInstance();
         groupService = FRMConsumerImpl.getProviderSession().getRpcService(SalGroupService.class);
 
-        clusterGroupContainerService = FRMConsumerImpl.getClusterContainerService();
-        container = FRMConsumerImpl.getContainer();
-
         if (!(cacheStartup())) {
             logger.error("Unanle to allocate/retrieve group cache");
             System.out.println("Unable to allocate/retrieve group cache");
@@ -97,8 +94,10 @@ public class GroupConsumerImpl implements IForwardingRulesManager {
             return;
         }
 
-        commitHandler = new GroupDataCommitHandler();
-        FRMConsumerImpl.getDataProviderService().registerCommitHandler(path, commitHandler);
+        groupCommitHandler = new GroupDataCommitHandler();
+        FRMConsumerImpl.getDataProviderService().registerCommitHandler(path, groupCommitHandler);
+        clusterGroupContainerService = FRMConsumerImpl.getClusterContainerService();
+        container = FRMConsumerImpl.getContainer();
     }
 
     private boolean allocateGroupCaches() {
@@ -220,23 +219,13 @@ public class GroupConsumerImpl implements IForwardingRulesManager {
                 logger.error("Container Name is invalid %s" + containerName);
                 return new Status(StatusCode.BADREQUEST, "Container Name is invalid");
             }
-
+            
             groupName = group.getGroupName();
             if (!FRMUtil.isNameValid(groupName)) {
                 logger.error("Group Name is invalid %s" + groupName);
                 return new Status(StatusCode.BADREQUEST, "Group Name is invalid");
             }
-
-           /* returnResult = doesGroupEntryExists(group.getKey(), groupName, containerName);
-
-            if (FRMUtil.operation.ADD == operation && returnResult) {
-                logger.error("Record with same Group Name exists");
-                return new Status(StatusCode.BADREQUEST, "Group record exists");
-            } else if (!returnResult) {
-                logger.error("Group record does not exist");
-                return new Status(StatusCode.BADREQUEST, "Group record does not exist");
-            }*/
-
+            
             if (!(group.getGroupType().getIntValue() >= GroupTypes.GroupAll.getIntValue() && group.getGroupType()
                     .getIntValue() <= GroupTypes.GroupFf.getIntValue())) {
                 logger.error("Invalid Group type %d" + group.getGroupType().getIntValue());
@@ -258,24 +247,8 @@ public class GroupConsumerImpl implements IForwardingRulesManager {
         }
 
         return new Status(StatusCode.SUCCESS);
-
     }
 
-   /* private boolean doesGroupEntryExists(GroupKey key, String groupName, String containerName) {
-        if (!originalSwGroupView.containsKey(key)) {
-            return false;
-        }
-
-        for (ConcurrentMap.Entry<GroupKey, Group> entry : originalSwGroupView.entrySet()) {
-            if (entry.getValue().getGroupName().equals(groupName)) {
-                if (entry.getValue().getContainerName().equals(containerName)) {
-                    return true;
-                }
-            }
-        }
-        return true;
-    }*/
-
     /**
      * Update Group entries to the southbound plugin/inventory and our internal
      * database
@@ -293,27 +266,12 @@ public class GroupConsumerImpl implements IForwardingRulesManager {
             logger.error("Group data object validation failed %s" + groupUpdateDataObject.getGroupName());
             return groupOperationStatus;
         }
-
-        /*if (originalSwGroupView.containsKey(groupKey)) {
-            originalSwGroupView.remove(groupKey);
-            originalSwGroupView.put(groupKey, groupUpdateDataObject);
-        }
-*/
-        if (groupUpdateDataObject.isInstall()) {
-            UpdateGroupInputBuilder groupData = new UpdateGroupInputBuilder();
-            updateGroupBuilder = new UpdatedGroupBuilder();
-            updateGroupBuilder.fieldsFrom(groupUpdateDataObject);
-            groupData.setUpdatedGroup(updateGroupBuilder.build());
-            // TODO how to get original group and modified group.
-
-          /*  if (installedSwGroupView.containsKey(groupKey)) {
-                installedSwGroupView.remove(groupKey);
-                installedSwGroupView.put(groupKey, groupUpdateDataObject);
-            }*/
-
-            groupService.updateGroup(groupData.build());
-        }
-
+        
+        UpdateGroupInputBuilder groupData = new UpdateGroupInputBuilder();
+        updateGroupBuilder = new UpdatedGroupBuilder();
+        updateGroupBuilder.fieldsFrom(groupUpdateDataObject);
+        groupData.setUpdatedGroup(updateGroupBuilder.build());        
+        groupService.updateGroup(groupData.build());
         return groupOperationStatus;
     }
 
@@ -331,20 +289,14 @@ public class GroupConsumerImpl implements IForwardingRulesManager {
             logger.error("Group data object validation failed %s" + groupAddDataObject.getGroupName());
             return groupOperationStatus;
         }
-
-        //originalSwGroupView.put(groupKey, groupAddDataObject);
-
-        if (groupAddDataObject.isInstall()) {
-            AddGroupInputBuilder groupData = new AddGroupInputBuilder();
-            groupData.setBuckets(groupAddDataObject.getBuckets());
-            groupData.setContainerName(groupAddDataObject.getContainerName());
-            groupData.setGroupId(groupAddDataObject.getGroupId());
-            groupData.setGroupType(groupAddDataObject.getGroupType());
-            groupData.setNode(groupAddDataObject.getNode());
-        //   installedSwGroupView.put(groupKey, groupAddDataObject);
-            groupService.addGroup(groupData.build());
-        }
-
+        
+        AddGroupInputBuilder groupData = new AddGroupInputBuilder();
+        groupData.setBuckets(groupAddDataObject.getBuckets());
+        groupData.setContainerName(groupAddDataObject.getContainerName());
+        groupData.setGroupId(groupAddDataObject.getGroupId());
+        groupData.setGroupType(groupAddDataObject.getGroupType());
+        groupData.setNode(groupAddDataObject.getNode());    
+        groupService.addGroup(groupData.build());
         return groupOperationStatus;
     }
 
@@ -362,19 +314,14 @@ public class GroupConsumerImpl implements IForwardingRulesManager {
             logger.error("Group data object validation failed %s" + groupRemoveDataObject.getGroupName());
             return groupOperationStatus;
         }
-        //originalSwGroupView.put(groupKey, groupAddDataObject);
-
-        if (groupRemoveDataObject.isInstall()) {
-            RemoveGroupInputBuilder groupData = new RemoveGroupInputBuilder();
-            groupData.setBuckets(groupRemoveDataObject.getBuckets());
-            groupData.setContainerName(groupRemoveDataObject.getContainerName());
-            groupData.setGroupId(groupRemoveDataObject.getGroupId());
-            groupData.setGroupType(groupRemoveDataObject.getGroupType());
-            groupData.setNode(groupRemoveDataObject.getNode());
-        //   installedSwGroupView.put(groupKey, groupAddDataObject);
-            groupService.removeGroup(groupData.build());
-        }
-
+       
+        RemoveGroupInputBuilder groupData = new RemoveGroupInputBuilder();
+        groupData.setBuckets(groupRemoveDataObject.getBuckets());
+        groupData.setContainerName(groupRemoveDataObject.getContainerName());
+        groupData.setGroupId(groupRemoveDataObject.getGroupId());
+        groupData.setGroupType(groupRemoveDataObject.getGroupType());
+        groupData.setNode(groupRemoveDataObject.getNode());    
+        groupService.removeGroup(groupData.build());  
         return groupOperationStatus;
     }
     
@@ -405,7 +352,7 @@ public class GroupConsumerImpl implements IForwardingRulesManager {
                        }
         }
 
-        return Rpcs.getRpcResult(true, null, null);
+        return Rpcs.getRpcResult(true, null, Collections.<RpcError>emptySet());
     }
 
     private final class GroupDataCommitHandler implements DataCommitHandler<InstanceIdentifier<?>, DataObject> {
@@ -506,7 +453,6 @@ public class GroupConsumerImpl implements IForwardingRulesManager {
 
         @Override
         public void onGroupAdded(GroupAdded notification) {
-            System.out.println("added Group..........................");
             addedGroups.add(notification);
         }
 
index cef259b395629a8681bf748d4f54fdf8761d84c7..aa9d572d79724b27031b3aaa31193ec6d9d2577c 100644 (file)
@@ -39,6 +39,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.Sal
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.SalMeterService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.meter.update.UpdatedMeterBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.BandType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.Drop;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.DscpRemark;
@@ -68,15 +69,12 @@ public class MeterConsumerImpl implements IForwardingRulesManager {
     private ConcurrentMap<MeterKey, Meter> inactiveMeters;
     @SuppressWarnings("unused")
     private IContainer container;
-
-    private IClusterContainerServices clusterMeterContainerService = null;
-    
+    private IClusterContainerServices clusterMeterContainerService = null;    
 
     public MeterConsumerImpl() {
         InstanceIdentifier<? extends DataObject> path = InstanceIdentifier.builder(Meters.class).toInstance();
         meterService = FRMConsumerImpl.getProviderSession().getRpcService(SalMeterService.class);
         clusterMeterContainerService = FRMConsumerImpl.getClusterContainerService();
-
         container = FRMConsumerImpl.getContainer();
 
         if (!(cacheStartup())) {
@@ -214,22 +212,16 @@ public class MeterConsumerImpl implements IForwardingRulesManager {
      */
     private Status addMeter(InstanceIdentifier<?> path, Meter meterAddDataObject) {
         MeterKey meterKey = meterAddDataObject.getKey();
-
-        if (null != meterKey && validateMeter(meterAddDataObject, FRMUtil.operation.ADD).isSuccess()) {
-            if (meterAddDataObject.isInstall()) {
-                AddMeterInputBuilder meterBuilder = new AddMeterInputBuilder();
-
-                meterBuilder.setContainerName(meterAddDataObject.getContainerName());
-                meterBuilder.setFlags(meterAddDataObject.getFlags());
-                meterBuilder.setMeterBandHeaders(meterAddDataObject.getMeterBandHeaders());
-                meterBuilder.setMeterId(meterAddDataObject.getMeterId());
-                meterBuilder.setNode(meterAddDataObject.getNode());
-               // originalSwMeterView.put(meterKey, meterAddDataObject);
-                meterService.addMeter(meterBuilder.build());
-            }
-
-           // originalSwMeterView.put(meterKey, meterAddDataObject);
-        } else {
+        
+        if (null != meterKey && validateMeter(meterAddDataObject, FRMUtil.operation.ADD).isSuccess()) {                 
+            AddMeterInputBuilder meterBuilder = new AddMeterInputBuilder();
+            meterBuilder.setContainerName(meterAddDataObject.getContainerName());
+            meterBuilder.setFlags(meterAddDataObject.getFlags());
+            meterBuilder.setMeterBandHeaders(meterAddDataObject.getMeterBandHeaders());
+            meterBuilder.setMeterId(new MeterId(meterAddDataObject.getId()));
+            meterBuilder.setNode(meterAddDataObject.getNode());           
+            meterService.addMeter(meterBuilder.build());
+        } else {       
             return new Status(StatusCode.BADREQUEST, "Meter Key or attribute validation failed");
         }
 
@@ -246,28 +238,12 @@ public class MeterConsumerImpl implements IForwardingRulesManager {
     private Status updateMeter(InstanceIdentifier<?> path, Meter meterUpdateDataObject) {
         MeterKey meterKey = meterUpdateDataObject.getKey();
         UpdatedMeterBuilder updateMeterBuilder = null;
-
-        if (null != meterKey && validateMeter(meterUpdateDataObject, FRMUtil.operation.UPDATE).isSuccess()) {
-
-           /* if (originalSwMeterView.containsKey(meterKey)) {
-                originalSwMeterView.remove(meterKey);
-                originalSwMeterView.put(meterKey, meterUpdateDataObject);
-            }*/
-
-            if (meterUpdateDataObject.isInstall()) {
-                UpdateMeterInputBuilder updateMeterInputBuilder = new UpdateMeterInputBuilder();
-                updateMeterBuilder = new UpdatedMeterBuilder();
-                updateMeterBuilder.fieldsFrom(meterUpdateDataObject);
-                updateMeterInputBuilder.setUpdatedMeter(updateMeterBuilder.build());
-
-              /*  if (installedSwMeterView.containsKey(meterKey)) {
-                    installedSwMeterView.remove(meterKey);
-                    installedSwMeterView.put(meterKey, meterUpdateDataObject);
-                }*/
-
-                meterService.updateMeter(updateMeterInputBuilder.build());
-            }
-
+        
+        if (null != meterKey && validateMeter(meterUpdateDataObject, FRMUtil.operation.UPDATE).isSuccess()) {                UpdateMeterInputBuilder updateMeterInputBuilder = new UpdateMeterInputBuilder();
+            updateMeterBuilder = new UpdatedMeterBuilder();
+            updateMeterBuilder.fieldsFrom(meterUpdateDataObject);
+            updateMeterInputBuilder.setUpdatedMeter(updateMeterBuilder.build());
+            meterService.updateMeter(updateMeterInputBuilder.build());
         } else {
             return new Status(StatusCode.BADREQUEST, "Meter Key or attribute validation failed");
         }
@@ -285,20 +261,15 @@ public class MeterConsumerImpl implements IForwardingRulesManager {
     private Status removeMeter(InstanceIdentifier<?> path, Meter meterRemoveDataObject) {
         MeterKey meterKey = meterRemoveDataObject.getKey();
 
-        if (null != meterKey && validateMeter(meterRemoveDataObject, FRMUtil.operation.DELETE).isSuccess()) {
-            if (meterRemoveDataObject.isInstall()) {
-                RemoveMeterInputBuilder meterBuilder = new RemoveMeterInputBuilder();
-                meterBuilder.setContainerName(meterRemoveDataObject.getContainerName());
-                meterBuilder.setNode(meterRemoveDataObject.getNode());
-                meterBuilder.setFlags(meterRemoveDataObject.getFlags());
-                meterBuilder.setMeterBandHeaders(meterRemoveDataObject.getMeterBandHeaders());
-                meterBuilder.setMeterId(meterRemoveDataObject.getMeterId());
-                meterBuilder.setNode(meterRemoveDataObject.getNode());
-               // originalSwMeterView.put(meterKey, meterAddDataObject);
-                meterService.removeMeter(meterBuilder.build());
-            }
-
-           // originalSwMeterView.put(meterKey, meterAddDataObject);
+        if (null != meterKey && validateMeter(meterRemoveDataObject, FRMUtil.operation.DELETE).isSuccess()) {            
+            RemoveMeterInputBuilder meterBuilder = new RemoveMeterInputBuilder();
+            meterBuilder.setContainerName(meterRemoveDataObject.getContainerName());
+            meterBuilder.setNode(meterRemoveDataObject.getNode());
+            meterBuilder.setFlags(meterRemoveDataObject.getFlags());
+            meterBuilder.setMeterBandHeaders(meterRemoveDataObject.getMeterBandHeaders());
+            meterBuilder.setMeterId(meterRemoveDataObject.getMeterId());
+            meterBuilder.setNode(meterRemoveDataObject.getNode());        
+            meterService.removeMeter(meterBuilder.build());
         } else {
             return new Status(StatusCode.BADREQUEST, "Meter Key or attribute validation failed");
         }
@@ -329,18 +300,6 @@ public class MeterConsumerImpl implements IForwardingRulesManager {
                 return returnStatus;
             }
 
-         /*   returnResult = doesMeterEntryExists(meter.getKey(), meterName, containerName);
-
-            if (FRMUtil.operation.ADD == operation && returnResult) {
-                logger.error("Record with same Meter Name exists");
-                returnStatus = new Status(StatusCode.BADREQUEST, "Meter record exists");
-                return returnStatus;
-            } else if (!returnResult) {
-                logger.error("Group record does not exist");
-                returnStatus = new Status(StatusCode.BADREQUEST, "Meter record does not exist");
-                return returnStatus;
-            }*/
-
             for (int i = 0; i < meter.getMeterBandHeaders().getMeterBandHeader().size(); i++) {
                 if (!meter.getFlags().isMeterBurst()) {
                     if (0 < meter.getMeterBandHeaders().getMeterBandHeader().get(i).getBurstSize()) {
@@ -377,22 +336,7 @@ public class MeterConsumerImpl implements IForwardingRulesManager {
         return new Status(StatusCode.SUCCESS);
     }
 
-    /*private boolean doesMeterEntryExists(MeterKey key, String meterName, String containerName) {
-        if (!originalSwMeterView.containsKey(key)) {
-            return false;
-        }
-
-        for (Entry<MeterKey, Meter> entry : originalSwMeterView.entrySet()) {
-            if (entry.getValue().getMeterName().equals(meterName)) {
-                if (entry.getValue().getContainerName().equals(containerName)) {
-                    return true;
-                }
-            }
-        }
-        return false;
-    }*/
-
-    private final class InternalTransaction implements DataCommitTransaction<InstanceIdentifier<?>, DataObject> {
+    final class InternalTransaction implements DataCommitTransaction<InstanceIdentifier<?>, DataObject> {
 
         private final DataModification<InstanceIdentifier<?>, DataObject> modification;
 
@@ -500,7 +444,6 @@ public class MeterConsumerImpl implements IForwardingRulesManager {
         public org.opendaylight.controller.md.sal.common.api.data.DataCommitHandler.DataCommitTransaction<InstanceIdentifier<?>, DataObject> requestCommit(
                 DataModification<InstanceIdentifier<?>, DataObject> modification) {
             // We should verify transaction
-            System.out.println("Coming in MeterDataCommitHandler");
             InternalTransaction transaction = new InternalTransaction(modification);
             transaction.prepareUpdate();
             return transaction;
@@ -555,6 +498,7 @@ public class MeterConsumerImpl implements IForwardingRulesManager {
                 }
             }
         }
+        
         return null;
     }
 }
index 2f3b7a036c6113b23d8020dd207c30ce490e6ab6..c5f1dddc344b0e239595d7ae55ac6aa3dbd1bf99 100644 (file)
@@ -66,7 +66,7 @@
                                 </generator>
                                 <generator>
                                     <codeGeneratorClass>org.opendaylight.yangtools.yang.unified.doc.generator.maven.DocumentationGeneratorImpl</codeGeneratorClass>
-                                    <outputBaseDir>target/site/restconf</outputBaseDir>
+                                    <outputBaseDir>target/site/models</outputBaseDir>
                                 </generator>
                             </codeGenerators>
                             <inspectDependencies>true</inspectDependencies>
index 51b00845aef17d832e8ec737b965b5f168f06c11..89bb1e8502570ee901d5e0f5f6052ce450140120 100644 (file)
                                         </namespaceToPackage1>
                                     </additionalConfiguration>
                                 </generator>
+                                <generator>
+                                    <codeGeneratorClass>org.opendaylight.yangtools.yang.unified.doc.generator.maven.DocumentationGeneratorImpl</codeGeneratorClass>
+                                    <outputBaseDir>target/site/models</outputBaseDir>
+                                </generator>
                             </codeGenerators>
                             <inspectDependencies>true</inspectDependencies>
                         </configuration>
                         <artifactId>yang-jmx-generator-plugin</artifactId>
                         <version>0.2.3-SNAPSHOT</version>
                     </dependency>
+                    <dependency>
+                        <groupId>org.opendaylight.yangtools</groupId>
+                        <artifactId>maven-sal-api-gen-plugin</artifactId>
+                        <version>0.6.0-SNAPSHOT</version>
+                        <type>jar</type>
+                    </dependency>
                 </dependencies>
             </plugin>
 
index 1762aac090a0eac4a29cdac122d986298d773ec1..9381a5a070e67e7c82226c5b920b06f9a952cc67 100644 (file)
@@ -48,8 +48,9 @@ import java.util.concurrent.locks.ReentrantLock
 import java.util.concurrent.Callable
 import java.util.WeakHashMap
 import javax.annotation.concurrent.GuardedBy
+import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry
 
-class BindingAwareBrokerImpl implements BindingAwareBroker, AutoCloseable {
+class BindingAwareBrokerImpl implements BindingAwareBroker, RpcProviderRegistry, AutoCloseable {
     private static val log = LoggerFactory.getLogger(BindingAwareBrokerImpl)
 
     private InstanceIdentifier<? extends DataObject> root = InstanceIdentifier.builder().toInstance();
@@ -188,22 +189,30 @@ class BindingAwareBrokerImpl implements BindingAwareBroker, AutoCloseable {
      * Registers RPC Implementation
      * 
      */
-    def <T extends RpcService> registerRpcImplementation(Class<T> type, T service, OsgiProviderContext context,
-        Hashtable<String, String> properties) {
+    override <T extends RpcService> addRpcImplementation(Class<T> type, T service) {
+        checkNotNull(type, "Service type should not be null")
+        checkNotNull(service, "Service type should not be null")
+        
         val proxy = getManagedDirectProxy(type)
         checkState(proxy.delegate === null, "The Service for type %s is already registered", type)
 
-        val osgiReg = context.bundleContext.registerService(type, service, properties);
         proxy.delegate = service;
-        return new RpcServiceRegistrationImpl<T>(type, service, osgiReg, this);
+        return new RpcServiceRegistrationImpl<T>(type, service, this);
     }
 
-    def <T extends RpcService> RoutedRpcRegistration<T> registerRoutedRpcImplementation(Class<T> type, T service,
-        OsgiProviderContext context) {
+    override <T extends RpcService> RoutedRpcRegistration<T> addRoutedRpcImplementation(Class<T> type, T service) {
+        checkNotNull(type, "Service type should not be null")
+        checkNotNull(service, "Service type should not be null")
+        
         val router = resolveRpcRouter(type);
         checkState(router !== null)
         return new RoutedRpcRegistrationImpl<T>(service, router, this)
     }
+    
+    override <T extends RpcService> getRpcService(Class<T> service) {
+        checkNotNull(service, "Service should not be null");
+        return getManagedDirectProxy(service) as T;
+    }
 
     private def <T extends RpcService> RpcRouter<T> resolveRpcRouter(Class<T> type) {
 
@@ -357,16 +366,14 @@ class RoutedRpcRegistrationImpl<T extends RpcService> extends AbstractObjectRegi
 
 class RpcServiceRegistrationImpl<T extends RpcService> extends AbstractObjectRegistration<T> implements RpcRegistration<T> {
 
-    val ServiceRegistration<T> osgiRegistration;
     private var BindingAwareBrokerImpl broker;
 
     @Property
     val Class<T> serviceType;
 
-    public new(Class<T> type, T service, ServiceRegistration<T> osgiReg, BindingAwareBrokerImpl broker) {
+    public new(Class<T> type, T service, BindingAwareBrokerImpl broker) {
         super(service);
         this._serviceType = type;
-        this.osgiRegistration = osgiReg;
         this.broker = broker;
     }
 
index 7fd3fd24d86e5d48b802c96ea5c570c675528c87..d1ec35157f5770080b75fbe794637c220c0a2d43 100644 (file)
@@ -33,22 +33,13 @@ class OsgiProviderContext extends OsgiConsumerContext implements ProviderContext
     }
 
     override <T extends RpcService> addRpcImplementation(Class<T> type, T implementation) {
-
-        // TODO Auto-generated method stub
-        val properties = new Hashtable<String, String>();
-        properties.salServiceType = SAL_SERVICE_TYPE_PROVIDER
-
-        // Fill requirements
-        val salReg = broker.registerRpcImplementation(type, implementation, this, properties)
+        val salReg = broker.addRpcImplementation(type, implementation)
         registeredServices.put(type, salReg)
         return salReg;
     }
 
     override <T extends RpcService> addRoutedRpcImplementation(Class<T> type, T implementation) throws IllegalStateException {
-        checkNotNull(type, "Service type should not be null")
-        checkNotNull(implementation, "Service type should not be null")
-        
-        val salReg = broker.registerRoutedRpcImplementation(type, implementation, this)
+        val salReg = broker.addRoutedRpcImplementation(type, implementation)
         registeredServices.put(type, salReg)
         return salReg;
     }
index 38770c193c94096323280024856ef2f1bf14dfbd..9da073f71b44545694350d17c15f588ea2c36af3 100644 (file)
@@ -25,6 +25,7 @@ module opendaylight-sal-binding-broker-impl {
     identity binding-broker-impl {
         base config:module-type;
         config:provided-service sal:binding-broker-osgi-registry;
+        config:provided-service sal:binding-rpc-registry;
         config:java-name-prefix BindingBrokerImpl;
     }
     
index 3bc50cdd2ed1aecbf55d791f0c3fe02d9ed1bd04..a913faa15bd9396e04cdbd97eb22d3864d4272b2 100644 (file)
                                         </namespaceToPackage1>
                                     </additionalConfiguration>
                                 </generator>
+                                <generator>
+                                    <codeGeneratorClass>org.opendaylight.yangtools.yang.unified.doc.generator.maven.DocumentationGeneratorImpl</codeGeneratorClass>
+                                    <outputBaseDir>target/site/models</outputBaseDir>
+                                </generator>
                             </codeGenerators>
                             <inspectDependencies>true</inspectDependencies>
                         </configuration>
                         <artifactId>yang-jmx-generator-plugin</artifactId>
                         <version>0.2.3-SNAPSHOT</version>
                     </dependency>
+                    <dependency>
+                        <groupId>org.opendaylight.yangtools</groupId>
+                        <artifactId>maven-sal-api-gen-plugin</artifactId>
+                        <version>0.6.0-SNAPSHOT</version>
+                        <type>jar</type>
+                    </dependency>
                 </dependencies>
             </plugin>
             <plugin>
index e52a7c302dc0aa378310a68874c37904e3698fdd..4ed629b77ddf8519032d106c39e8cbc40d057aba 100644 (file)
                                         </namespaceToPackage1>
                                     </additionalConfiguration>
                                 </generator>
+                                <generator>
+                                    <codeGeneratorClass>org.opendaylight.yangtools.yang.unified.doc.generator.maven.DocumentationGeneratorImpl</codeGeneratorClass>
+                                    <outputBaseDir>target/site/models</outputBaseDir>
+                                </generator>
                             </codeGenerators>
                             <inspectDependencies>true</inspectDependencies>
                         </configuration>
                         <artifactId>yang-jmx-generator-plugin</artifactId>
                         <version>0.2.3-SNAPSHOT</version>
                     </dependency>
+                    <dependency>
+                        <groupId>org.opendaylight.yangtools</groupId>
+                        <artifactId>maven-sal-api-gen-plugin</artifactId>
+                        <version>0.6.0-SNAPSHOT</version>
+                        <type>jar</type>
+                    </dependency>
                 </dependencies>
             </plugin>
             <plugin>
index a6601cef21f98e50c378cc573b2ea14f207655c7..4740b0d5697c916c747079819700d2f732550b1f 100644 (file)
                                         </namespaceToPackage1>
                                     </additionalConfiguration>
                                 </generator>
+                                <generator>
+                                    <codeGeneratorClass>org.opendaylight.yangtools.yang.unified.doc.generator.maven.DocumentationGeneratorImpl</codeGeneratorClass>
+                                    <outputBaseDir>target/site/models</outputBaseDir>
+                                </generator>
                             </codeGenerators>
                             <inspectDependencies>true</inspectDependencies>
                         </configuration>
                         <artifactId>yang-jmx-generator-plugin</artifactId>
                         <version>0.2.3-SNAPSHOT</version>
                     </dependency>
+                    <dependency>
+                        <groupId>org.opendaylight.yangtools</groupId>
+                        <artifactId>maven-sal-api-gen-plugin</artifactId>
+                        <version>0.6.0-SNAPSHOT</version>
+                        <type>jar</type>
+                    </dependency>
                 </dependencies>
             </plugin>
             
index e790a9dbb1bbd396570445e0e58da1eee105e443..fe613565a6232b608ab91ed33e014b327c4a4e2a 100644 (file)
                                         </namespaceToPackage1>
                                     </additionalConfiguration>
                                 </generator>
+                                <generator>
+                                    <codeGeneratorClass>org.opendaylight.yangtools.yang.unified.doc.generator.maven.DocumentationGeneratorImpl</codeGeneratorClass>
+                                    <outputBaseDir>target/site/models</outputBaseDir>
+                                </generator>
                             </codeGenerators>
                             <inspectDependencies>true</inspectDependencies>
                         </configuration>
                         <artifactId>yang-jmx-generator-plugin</artifactId>
                         <version>0.2.3-SNAPSHOT</version>
                     </dependency>
+                    <dependency>
+                        <groupId>org.opendaylight.yangtools</groupId>
+                        <artifactId>maven-sal-api-gen-plugin</artifactId>
+                        <version>0.6.0-SNAPSHOT</version>
+                        <type>jar</type>
+                    </dependency>
                 </dependencies>
             </plugin>
             <plugin>
index 12759246140a9d7da0947ff8f73e8d461e6614d6..4d0a1ac6b663e3ecf7aee035ab5b47157de1aed8 100644 (file)
@@ -77,10 +77,9 @@ public final class NetconfConnectorModule extends org.opendaylight.controller.co
         
         EventLoopGroup bossGroup = getBossThreadGroupDependency();
         EventLoopGroup workerGroup = getWorkerThreadGroupDependency();
-        Optional<SSLContext> maybeContext = Optional.absent();
         NetconfClientDispatcher dispatcher = null;
         if(getTcpOnly()) {
-            dispatcher = new NetconfClientDispatcher(maybeContext , bossGroup, workerGroup);
+            dispatcher = new NetconfClientDispatcher( bossGroup, workerGroup);
         } else {
             AuthenticationHandler authHandler = new LoginPassword(getUsername(),getPassword());
             dispatcher = new NetconfSshClientDispatcher(authHandler , bossGroup, workerGroup);
index bdcb0bdd2bce239d65eac72f83432c1cff036a0e..3e13a584d4b602a8f1a725ad06f491fb08c5897e 100644 (file)
       <version>2.4</version>
       <scope>test</scope>
     </dependency>
+    <dependency>
+       <groupId>org.opendaylight.yangtools</groupId>
+       <artifactId>yang-model-util</artifactId>
+       <version>0.5.9-SNAPSHOT</version>
+    </dependency>
   </dependencies>
 
   <build>
index 9608d65e41ca82a13e2dada78b5ce5dfeb0728e7..a42c468c2af27ea5f2cb84887757ed8057a4466f 100644 (file)
@@ -8,6 +8,7 @@ import java.util.*;
 import javax.activation.UnsupportedDataTypeException;
 
 import org.opendaylight.controller.sal.restconf.impl.ControllerContext;
+import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.*;
 import org.opendaylight.yangtools.yang.model.api.*;
 import org.opendaylight.yangtools.yang.model.api.type.*;
@@ -144,25 +145,43 @@ class JsonMapper {
 
         List<SimpleNode<?>> nodeLeafLists = nodeParent.getSimpleNodesByName(node.getNodeType());
         for (SimpleNode<?> nodeLeafList : nodeLeafLists) {
-            writeValueOfNodeByType(writer, nodeLeafList, schema.getType());
+            writeValueOfNodeByType(writer, nodeLeafList, schema.getType(), schema);
         }
-
         writer.endArray();
     }
 
     private void writeLeaf(JsonWriter writer, SimpleNode<?> node, LeafSchemaNode schema) throws IOException {
         writeName(node, schema, writer);
-        writeValueOfNodeByType(writer, node, schema.getType());
+        writeValueOfNodeByType(writer, node, schema.getType(), schema);
     }
 
-    private void writeValueOfNodeByType(JsonWriter writer, SimpleNode<?> node, TypeDefinition<?> type)
-            throws IOException {
+    private void writeValueOfNodeByType(JsonWriter writer, SimpleNode<?> node, TypeDefinition<?> type,
+            DataSchemaNode schema) throws IOException {
 
         String value = String.valueOf(node.getValue());
-        // TODO check Leafref, InstanceIdentifierTypeDefinition,
-        // IdentityrefTypeDefinition, UnionTypeDefinition
         TypeDefinition<?> baseType = resolveBaseTypeFrom(type);
-        if (baseType instanceof InstanceIdentifierTypeDefinition) {
+
+        // TODO check InstanceIdentifierTypeDefinition,
+        // IdentityrefTypeDefinition
+        if (baseType instanceof IdentityrefTypeDefinition) {
+            if (node.getValue() instanceof QName) {
+                QName qName = (QName) node.getValue();
+
+                ControllerContext contContext = ControllerContext.getInstance();
+                String moduleName = contContext.findModuleByNamespace(qName.getNamespace());
+
+                writer.value(moduleName + ":" + qName.getLocalName());
+            }
+
+        } else if (baseType instanceof LeafrefTypeDefinition) {
+            ControllerContext contContext = ControllerContext.getInstance();
+            LeafSchemaNode lfSchemaNode = contContext.resolveTypeFromLeafref((LeafrefTypeDefinition) baseType, schema);
+            if (lfSchemaNode != null) {
+                writeValueOfNodeByType(writer, node, lfSchemaNode.getType(), lfSchemaNode);
+            } else {
+                writer.value(value);
+            }
+        } else if (baseType instanceof InstanceIdentifierTypeDefinition) {
             writer.value(((InstanceIdentifierTypeDefinition) baseType).getPathStatement().toString());
         } else if (baseType instanceof UnionTypeDefinition) {
             processTypeIsUnionType(writer, (UnionTypeDefinition) baseType, value);
index eca4bd257298b78706cbd10321e8484ea06cab87..470b4735a441ad7b5f3e8f421c53fea904d033d3 100644 (file)
@@ -27,6 +27,9 @@ import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode
 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode
 import org.opendaylight.yangtools.yang.model.api.RpcDefinition
 import org.opendaylight.yangtools.yang.model.api.SchemaContext
+import org.opendaylight.yangtools.yang.model.api.SchemaNode
+import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition
+import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil
 
 import static com.google.common.base.Preconditions.*
 
@@ -40,8 +43,7 @@ class ControllerContext implements SchemaServiceListener {
 
     private val BiMap<URI, String> uriToModuleName = HashBiMap.create();
     private val Map<String, URI> moduleNameToUri = uriToModuleName.inverse();
-    private val Map<QName,RpcDefinition> qnameToRpc = new ConcurrentHashMap();
-    
+    private val Map<QName, RpcDefinition> qnameToRpc = new ConcurrentHashMap();
 
     private new() {
         if (INSTANCE !== null) {
@@ -52,7 +54,7 @@ class ControllerContext implements SchemaServiceListener {
     static def getInstance() {
         return INSTANCE
     }
-    
+
     private def void checkPreconditions() {
         if (schemas === null) {
             throw new ResponseException(Response.Status.SERVICE_UNAVAILABLE, RestconfProvider::NOT_INITALIZED_MSG)
@@ -131,7 +133,7 @@ class ControllerContext implements SchemaServiceListener {
     private def dispatch CharSequence toRestconfIdentifier(PathArgument argument, DataSchemaNode node) {
         throw new IllegalArgumentException("Conversion of generic path argument is not supported");
     }
-    
+
     def findModuleByNamespace(URI namespace) {
         checkPreconditions
         var module = uriToModuleName.get(namespace)
@@ -311,24 +313,55 @@ class ControllerContext implements SchemaServiceListener {
             return str;
         }
     }
-    
+
     private def QName toQName(String name) {
         val module = name.toModuleName;
         val node = name.toNodeName;
         val namespace = moduleNameToUri.get(module);
-        return new QName(namespace,null,node);
+        return new QName(namespace, null, node);
     }
-    
+
     def getRpcDefinition(String name) {
         return qnameToRpc.get(name.toQName)
     }
 
     override onGlobalContextUpdated(SchemaContext context) {
         this.schemas = context;
-        for(operation : context.operations) {
-            val qname = new QName(operation.QName.namespace,null,operation.QName.localName);
-            qnameToRpc.put(qname,operation);
+        for (operation : context.operations) {
+            val qname = new QName(operation.QName.namespace, null, operation.QName.localName);
+            qnameToRpc.put(qname, operation);
+        }
+    }
+
+    /**
+     * Resolve target type from leafref type.
+     * 
+     * According to RFC 6020 referenced element has to be leaf (chapter 9.9).
+     * Therefore if other element is referenced then null value is returned.
+     * 
+     * Currently only cases without path-predicate are supported.
+     * 
+     * @param leafRef
+     * @param schemaNode
+     *            data schema node which contains reference
+     * @return type if leaf is referenced and it is possible to find referenced
+     *         node in schema context. In other cases null value is returned
+     */
+    def LeafSchemaNode resolveTypeFromLeafref(LeafrefTypeDefinition leafRef, DataSchemaNode schemaNode) {
+        val xPath = leafRef.getPathStatement();
+        val module = SchemaContextUtil.findParentModule(schemas, schemaNode);
+
+        var SchemaNode foundSchemaNode
+        if (xPath.isAbsolute()) {
+            foundSchemaNode = SchemaContextUtil.findDataSchemaNode(schemas, module, xPath);
+        } else {
+            foundSchemaNode = SchemaContextUtil.findDataSchemaNodeForRelativeXPath(schemas, module, schemaNode, xPath);
+        }
+
+        if (foundSchemaNode instanceof LeafSchemaNode) {
+            return foundSchemaNode as LeafSchemaNode;
         }
+
+        return null;
     }
-    
 }
index 89d24ad0579b9b78a77a68f121d8f13ca75ef399..61942e81a6e5918689cb4e77d1c9758b94b85911 100644 (file)
@@ -211,10 +211,12 @@ final class TestUtils {
                 null, byteArrayOS);
 
         jsonResult = byteArrayOS.toString();
-        try {
-            outputToFile(byteArrayOS, outputPath);
-        } catch (IOException e) {
-            System.out.println("Output file wasn't cloased sucessfuly.");
+        if (outputPath != null) {
+            try {            
+                outputToFile(byteArrayOS, outputPath);
+            } catch (IOException e) {
+                System.out.println("Output file wasn't cloased sucessfuly.");
+            }
         }
 
         return jsonResult;
diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/ToJsonIdentityrefTest.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/ToJsonIdentityrefTest.java
new file mode 100644 (file)
index 0000000..c9ac042
--- /dev/null
@@ -0,0 +1,61 @@
+package org.opendaylight.controller.sal.restconf.impl.test;
+
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+import java.util.Set;
+import java.util.regex.*;
+
+import javax.ws.rs.WebApplicationException;
+
+import org.junit.*;
+import org.opendaylight.yangtools.yang.data.api.*;
+import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
+import org.opendaylight.yangtools.yang.model.api.*;
+
+public class ToJsonIdentityrefTest {
+
+    private static Set<Module> modules;
+    private static DataSchemaNode dataSchemaNode;
+
+    @BeforeClass
+    public static void initialization() {
+        modules = TestUtils.resolveModules("/yang-to-json-conversion/identityref");
+        assertEquals(2, modules.size());
+        Module module = TestUtils.resolveModule("identityref-module", modules);
+        assertNotNull(module);
+        dataSchemaNode = TestUtils.resolveDataSchemaNode(module, "cont");
+        assertNotNull(dataSchemaNode);
+
+    }
+
+    @Test
+    public void identityrefToJsonTest() {
+        String json = null;
+        try {
+            json = TestUtils
+                    .writeCompNodeWithSchemaContextToJson(prepareCompositeNode(), null, modules, dataSchemaNode);
+        } catch (WebApplicationException | IOException e) {
+            // shouldn't end here
+            assertTrue(false);
+        }
+        assertNotNull(json);
+        Pattern ptrn = Pattern.compile(".*\"lf1\"\\p{Space}*:\\p{Space}*\"identityref-module:name_test\".*",
+                Pattern.DOTALL);
+        Matcher mtch = ptrn.matcher(json);
+
+        assertTrue(mtch.matches());
+    }
+
+    private CompositeNode prepareCompositeNode() {
+        MutableCompositeNode cont = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("cont"), null, null,
+                ModifyAction.CREATE, null);
+        MutableSimpleNode<?> lf1 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf1"), cont,
+                TestUtils.buildQName("name_test", "identityref:module", "2013-12-2"), ModifyAction.CREATE, null);
+        cont.getChildren().add(lf1);
+        cont.init();
+
+        return cont;
+    }
+
+}
diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/ToJsonLeafrefType.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/ToJsonLeafrefType.java
new file mode 100644 (file)
index 0000000..a5cc02e
--- /dev/null
@@ -0,0 +1,158 @@
+package org.opendaylight.controller.sal.restconf.impl.test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.Set;
+import java.util.regex.Matcher;
+
+import javax.ws.rs.WebApplicationException;
+
+import org.junit.*;
+import org.opendaylight.yangtools.yang.model.api.*;
+
+public class ToJsonLeafrefType {
+    private static Set<Module> modules;
+    private static DataSchemaNode dataSchemaNode;
+
+    @BeforeClass
+    public static void initialization() {
+        modules = TestUtils.resolveModules("/yang-to-json-conversion/leafref");
+        assertEquals(2, modules.size());
+        Module module = TestUtils.resolveModule("main-module", modules);
+        assertNotNull(module);
+        dataSchemaNode = TestUtils.resolveDataSchemaNode(module, "cont");
+        assertNotNull(dataSchemaNode);
+
+    }
+
+    @Test
+    public void leafrefAbsolutePathToExistingLeafTest() {
+        String json = null;
+        try {
+            json = TestUtils.writeCompNodeWithSchemaContextToJson(TestUtils
+                    .loadCompositeNode("/yang-to-json-conversion/leafref/xml/data_absolut_ref_to_existing_leaf.xml"),
+                    "/yang-to-json-conversion/leafref/xml", modules, dataSchemaNode);
+        } catch (WebApplicationException | IOException e) {
+            // shouldn't end here
+            assertTrue(false);
+        }
+        assertNotNull(json);
+        java.util.regex.Pattern ptrn = java.util.regex.Pattern.compile(".*\"lf3\":\\p{Blank}*true.*",
+                java.util.regex.Pattern.DOTALL);
+        Matcher mtch = ptrn.matcher(json);
+        assertTrue(mtch.matches());
+    }
+
+    @Test
+    public void leafrefRelativePathToExistingLeafTest() {
+        String json = null;
+        try {
+            json = TestUtils.writeCompNodeWithSchemaContextToJson(TestUtils
+                    .loadCompositeNode("/yang-to-json-conversion/leafref/xml/data_relativ_ref_to_existing_leaf.xml"),
+                    "/yang-to-json-conversion/leafref/xml", modules, dataSchemaNode);
+        } catch (WebApplicationException | IOException e) {
+            // shouldn't end here
+            assertTrue(false);
+        }
+        assertNotNull(json);
+        java.util.regex.Pattern ptrn = java.util.regex.Pattern.compile(".*\"lf2\":\\p{Blank}*121.*",
+                java.util.regex.Pattern.DOTALL);
+        Matcher mtch = ptrn.matcher(json);
+        assertTrue(mtch.matches());
+    }
+
+    /**
+     * Tests case when reference to not existing element is present. In this
+     * case value from single node is printed as string.
+     */
+    @Test
+    public void leafrefToNonExistingLeafTest() {
+        String json = null;
+        try {
+            json = TestUtils.writeCompNodeWithSchemaContextToJson(TestUtils
+                    .loadCompositeNode("/yang-to-json-conversion/leafref/xml/data_ref_to_non_existing_leaf.xml"),
+                    "/yang-to-json-conversion/leafref/xml", modules, dataSchemaNode);
+        } catch (WebApplicationException | IOException e) {
+            // shouldn't end here
+            assertTrue(false);
+        }
+        assertNotNull(json);
+        java.util.regex.Pattern ptrn = java.util.regex.Pattern.compile(".*\"lf5\":\\p{Blank}*\"137\".*",
+                java.util.regex.Pattern.DOTALL);
+        Matcher mtch = ptrn.matcher(json);
+        assertTrue(mtch.matches());
+    }
+
+    /**
+     * Tests case when non leaf element is referenced. In this case value from
+     * single node is printed as string.
+     */
+    @Test
+    public void leafrefToNotLeafTest() {
+        String json = null;
+        try {
+            json = TestUtils.writeCompNodeWithSchemaContextToJson(
+                    TestUtils.loadCompositeNode("/yang-to-json-conversion/leafref/xml/data_ref_to_not_leaf.xml"),
+                    "/yang-to-json-conversion/leafref/xml", modules, dataSchemaNode);
+        } catch (WebApplicationException | IOException e) {
+            // shouldn't end here
+            assertTrue(false);
+        }
+        assertNotNull(json);
+        java.util.regex.Pattern ptrn = java.util.regex.Pattern.compile(
+                ".*\"cont-augment-module\\p{Blank}*:\\p{Blank}*lf6\":\\p{Blank}*\"44.33\".*",
+                java.util.regex.Pattern.DOTALL);
+        Matcher mtch = ptrn.matcher(json);
+        assertTrue(mtch.matches());
+    }
+
+    /**
+     * Tests case when leaflist element is refers to leaf.
+     */
+    @Test
+    public void leafrefFromLeafListToLeafTest() {
+        String json = null;
+        try {
+            json = TestUtils
+                    .writeCompNodeWithSchemaContextToJson(
+                            TestUtils
+                                    .loadCompositeNode("/yang-to-json-conversion/leafref/xml/data_relativ_ref_from_leaflist_to_existing_leaf.xml"),
+                            "/yang-to-json-conversion/leafref/xml", modules, dataSchemaNode);
+        } catch (WebApplicationException | IOException e) {
+            // shouldn't end here
+            assertTrue(false);
+        }
+        assertNotNull(json);
+        java.util.regex.Pattern ptrn = java.util.regex.Pattern
+                .compile(
+                        ".*\"cont-augment-module\\p{Blank}*:\\p{Blank}*lflst1\":\\p{Blank}*.*345,\\p{Space}*346,\\p{Space}*347.*",
+                        java.util.regex.Pattern.DOTALL);
+        Matcher mtch = ptrn.matcher(json);
+        assertTrue(mtch.matches());
+    }
+
+    /**
+     * Tests case when leaflist element is refers to leaf.
+     */
+    @Test
+    public void leafrefFromLeafrefToLeafrefTest() {
+        String json = null;
+        try {
+            json = TestUtils.writeCompNodeWithSchemaContextToJson(TestUtils
+                    .loadCompositeNode("/yang-to-json-conversion/leafref/xml/data_from_leafref_to_leafref.xml"),
+                    "/yang-to-json-conversion/leafref/xml", modules, dataSchemaNode);
+        } catch (WebApplicationException | IOException e) {
+            // shouldn't end here
+            assertTrue(false);
+        }
+        assertNotNull(json);
+        java.util.regex.Pattern ptrn = java.util.regex.Pattern.compile(
+                ".*\"cont-augment-module\\p{Blank}*:\\p{Blank}*lf7\":\\p{Blank}*200.*", java.util.regex.Pattern.DOTALL);
+        Matcher mtch = ptrn.matcher(json);
+        assertTrue(mtch.matches());
+    }
+
+}
diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/identityref/identity-module.yang b/opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/identityref/identity-module.yang
new file mode 100644 (file)
index 0000000..30890bf
--- /dev/null
@@ -0,0 +1,10 @@
+module identity-module {
+  namespace "identity:module";  
+
+  prefix "idemod";
+  revision 2013-12-2 {    
+  }
+  
+       identity iden {         
+       }
+}
\ No newline at end of file
diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/identityref/identityref-module.yang b/opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/identityref/identityref-module.yang
new file mode 100644 (file)
index 0000000..273f5d7
--- /dev/null
@@ -0,0 +1,19 @@
+module identityref-module {
+  namespace "identityref:module";  
+
+  prefix "iderefmod";
+  
+  import identity-module {prefix idemo; revision-date 2013-12-2;}
+   
+  revision 2013-12-2 {    
+  }
+  
+       container cont {
+               leaf lf1 {
+                       type identityref {
+                               base "idemo:iden";
+                       }
+               }
+       }
+         
+}
\ No newline at end of file
diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/leafref/cont-augment-module.yang b/opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/leafref/cont-augment-module.yang
new file mode 100644 (file)
index 0000000..afc23b7
--- /dev/null
@@ -0,0 +1,42 @@
+module cont-augment-module {
+  namespace "cont:augment:module";  
+
+  prefix "cntaugmod";
+  
+  import main-module {prefix mamo; revision-date 2013-12-2;}
+         
+  revision 2013-12-2 {
+  
+  }
+  
+  augment "/mamo:cont" {
+       leaf-list lflst1 {
+               type leafref {
+                       path "../lf1";
+               }
+       }       
+       
+       leaf lf4 {
+               type leafref {
+                       path "../lf1";
+               }
+       }
+       
+       /* reference to not leaf element */
+       leaf lf6 {
+               type leafref {
+                       path "../lflst1";
+               }
+       }
+       
+       leaf lf7 {
+               type leafref {
+                       path "../lf4";
+               }
+       }
+  }
+       
+
+         
+}
\ No newline at end of file
diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/leafref/main-module.yang b/opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/leafref/main-module.yang
new file mode 100644 (file)
index 0000000..8c80392
--- /dev/null
@@ -0,0 +1,43 @@
+module main-module {
+  namespace "main:module";  
+
+  prefix "mainmod";
+  revision 2013-12-2 {    
+  }
+  
+       container cont {
+               leaf lf1 {
+                       type uint32;
+               }
+               
+               container cont1 {
+                       leaf lf11 {
+                               type boolean;
+                       }
+               }
+               
+               leaf lf2 {
+                       type leafref {
+                               path "../lf1";
+                       }
+               }
+               
+               leaf lf3 {
+                       type leafref {
+                               path "/cont/cont1/lf11";
+                       }
+               }
+               
+               /* reference to nonexisting leaf */
+               leaf lf5 {
+                       type leafref {
+                               path "/cont/lf";
+                       }
+               }
+               
+               
+       }
+       
+
+         
+}
\ No newline at end of file
diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/leafref/xml/data_absolut_ref_to_existing_leaf.xml b/opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/leafref/xml/data_absolut_ref_to_existing_leaf.xml
new file mode 100644 (file)
index 0000000..bbebabe
--- /dev/null
@@ -0,0 +1,6 @@
+<cont>
+       <cont1>
+               <lf11>true</lf11>
+       </cont1>
+       <lf3>true</lf3>
+</cont>
\ No newline at end of file
diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/leafref/xml/data_from_leafref_to_leafref.xml b/opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/leafref/xml/data_from_leafref_to_leafref.xml
new file mode 100644 (file)
index 0000000..1bb9013
--- /dev/null
@@ -0,0 +1,3 @@
+<cont>
+       <lf7>200</lf7>
+</cont>
\ No newline at end of file
diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/leafref/xml/data_ref_to_non_existing_leaf.xml b/opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/leafref/xml/data_ref_to_non_existing_leaf.xml
new file mode 100644 (file)
index 0000000..dfea9c8
--- /dev/null
@@ -0,0 +1,3 @@
+<cont>
+       <lf5>137</lf5>
+</cont>
\ No newline at end of file
diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/leafref/xml/data_ref_to_not_leaf.xml b/opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/leafref/xml/data_ref_to_not_leaf.xml
new file mode 100644 (file)
index 0000000..7b05b0c
--- /dev/null
@@ -0,0 +1,3 @@
+<cont>
+       <lf6>44.33</lf6>
+</cont>
\ No newline at end of file
diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/leafref/xml/data_relativ_ref_from_leaflist_to_existing_leaf.xml b/opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/leafref/xml/data_relativ_ref_from_leaflist_to_existing_leaf.xml
new file mode 100644 (file)
index 0000000..0d8cf66
--- /dev/null
@@ -0,0 +1,5 @@
+<cont>
+       <lflst1>345</lflst1>
+       <lflst1>346</lflst1>
+       <lflst1>347</lflst1>
+</cont>
\ No newline at end of file
diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/leafref/xml/data_relativ_ref_to_existing_leaf.xml b/opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/leafref/xml/data_relativ_ref_to_existing_leaf.xml
new file mode 100644 (file)
index 0000000..4a73a8b
--- /dev/null
@@ -0,0 +1,4 @@
+<cont>
+       <lf1>121</lf1>
+       <lf2>121</lf2>
+</cont>
\ No newline at end of file
index 3b881579f1b4547ecdebbd287387a9b2b3f68aee..e1b8ecf17ee50c1a4895d73301025faabd5f88e6 100644 (file)
@@ -16,6 +16,7 @@ import org.slf4j.LoggerFactory;
 
 import javax.management.openmbean.SimpleType;
 import java.lang.reflect.Method;
+import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.util.Date;
 import java.util.Map;
@@ -65,6 +66,7 @@ final class SimpleAttributeResolvingStrategy extends AbstractAttributeResolvingS
         resolverPlugins.put(Date.class.getCanonicalName(), new DateResolver());
         resolverPlugins.put(Character.class.getCanonicalName(), new CharResolver());
         resolverPlugins.put(BigInteger.class.getCanonicalName(), new BigIntegerResolver());
+        resolverPlugins.put(BigDecimal.class.getCanonicalName(), new BigDecimalResolver());
     }
 
     static interface Resolver {
@@ -106,6 +108,14 @@ final class SimpleAttributeResolvingStrategy extends AbstractAttributeResolvingS
         }
     }
 
+    static class BigDecimalResolver extends DefaultResolver {
+
+        @Override
+        protected Object parseObject(Class<?> type, String value) throws Exception {
+            return new BigDecimal(value);
+        }
+    }
+
     static class CharResolver extends DefaultResolver {
 
         @Override
index 73d39c616221403737d5cfe7f52315b043fc19d5..d91e38db33bf9206c96c18ba178dbfaa2ef115d7 100644 (file)
@@ -137,6 +137,7 @@ public class NetconfMappingTest extends AbstractConfigTest {
         checkTypeConfigAttribute(response);
         checkTypedefs(response);
         checkEnum(response);
+        checkBigDecimal(response);
 
         edit("netconfMessages/editConfig_remove.xml");
 
@@ -162,6 +163,11 @@ public class NetconfMappingTest extends AbstractConfigTest {
         verifyNoMoreInteractions(netconfOperationRouter);
     }
 
+    private void checkBigDecimal(Element response) {
+        int size = response.getElementsByTagName("sleep-factor").getLength();
+        assertEquals(1, size);
+    }
+
     private void closeSession() throws NetconfDocumentedException, ParserConfigurationException, SAXException,
             IOException {
         DefaultCloseSession closeOp = new DefaultCloseSession(NETCONF_SESSION_ID);
index b20577afd23fcdde6bb8f3ab50b3f7f73c0c0a6f..99b7ee60a2c51c8033c44e1195f78a93328b63c9 100644 (file)
@@ -13,6 +13,22 @@ import com.google.common.base.Preconditions;
 import com.google.common.collect.Sets;
 import io.netty.channel.EventLoopGroup;
 import io.netty.channel.nio.NioEventLoopGroup;
+import java.io.Closeable;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.InetSocketAddress;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.regex.Pattern;
+import javax.annotation.concurrent.ThreadSafe;
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanServerConnection;
+import javax.management.Notification;
+import javax.management.NotificationListener;
+import javax.management.ObjectName;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpression;
 import org.opendaylight.controller.config.api.ConflictingVersionException;
 import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder;
 import org.opendaylight.controller.config.persist.api.Persister;
@@ -32,24 +48,6 @@ import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.xml.sax.SAXException;
 
-import javax.annotation.concurrent.ThreadSafe;
-import javax.management.InstanceNotFoundException;
-import javax.management.MBeanServerConnection;
-import javax.management.Notification;
-import javax.management.NotificationListener;
-import javax.management.ObjectName;
-import javax.net.ssl.SSLContext;
-import javax.xml.xpath.XPathConstants;
-import javax.xml.xpath.XPathExpression;
-import java.io.Closeable;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.InetSocketAddress;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.regex.Pattern;
-
 /**
  * Responsible for listening for notifications from netconf containing latest
  * committed configuration that should be persisted, and also for loading last
@@ -151,7 +149,7 @@ public class ConfigPersisterNotificationHandler implements NotificationListener,
         long deadline = pollingStart + timeout;
         while (System.currentTimeMillis() < deadline) {
             attempt++;
-            netconfClientDispatcher = new NetconfClientDispatcher(Optional.<SSLContext>absent(), nettyThreadgroup, nettyThreadgroup);
+            netconfClientDispatcher = new NetconfClientDispatcher(nettyThreadgroup, nettyThreadgroup);
             try {
                 netconfClient = new NetconfClient(this.toString(), address, delay, netconfClientDispatcher);
             } catch (IllegalStateException e) {
index 62c2113056afa1611300fce0c363ce293314fb49..6ac57a88c9f4750513d8be139354f78abd5575a6 100644 (file)
@@ -8,17 +8,17 @@
 
 package org.opendaylight.controller.netconf.client;
 
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
 import io.netty.channel.EventLoopGroup;
 import io.netty.channel.socket.SocketChannel;
 import io.netty.util.HashedWheelTimer;
 import io.netty.util.concurrent.Future;
 import io.netty.util.concurrent.Promise;
+import java.io.Closeable;
+import java.net.InetSocketAddress;
 import org.opendaylight.controller.netconf.api.NetconfMessage;
 import org.opendaylight.controller.netconf.api.NetconfSession;
 import org.opendaylight.controller.netconf.api.NetconfTerminationReason;
-import org.opendaylight.controller.netconf.util.AbstractSslChannelInitializer;
+import org.opendaylight.controller.netconf.util.AbstractChannelInitializer;
 import org.opendaylight.protocol.framework.AbstractDispatcher;
 import org.opendaylight.protocol.framework.ReconnectStrategy;
 import org.opendaylight.protocol.framework.SessionListener;
@@ -26,22 +26,15 @@ import org.opendaylight.protocol.framework.SessionListenerFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLEngine;
-import java.io.Closeable;
-import java.net.InetSocketAddress;
-
 public class NetconfClientDispatcher extends AbstractDispatcher<NetconfClientSession, NetconfClientSessionListener> implements Closeable {
 
     private static final Logger logger = LoggerFactory.getLogger(NetconfClient.class);
 
-    private final Optional<SSLContext> maybeContext;
     private final NetconfClientSessionNegotiatorFactory negotatorFactory;
     private final HashedWheelTimer timer;
 
-    public NetconfClientDispatcher(final Optional<SSLContext> maybeContext, EventLoopGroup bossGroup, EventLoopGroup workerGroup) {
+    public NetconfClientDispatcher(EventLoopGroup bossGroup, EventLoopGroup workerGroup) {
         super(bossGroup, workerGroup);
-        this.maybeContext = Preconditions.checkNotNull(maybeContext);
         timer = new HashedWheelTimer();
         this.negotatorFactory = new NetconfClientSessionNegotiatorFactory(timer);
     }
@@ -57,23 +50,27 @@ public class NetconfClientDispatcher extends AbstractDispatcher<NetconfClientSes
             }
 
             private void initialize(SocketChannel ch, Promise<NetconfClientSession> promise) {
-                new ClientSslChannelInitializer(maybeContext, negotatorFactory, sessionListener).initialize(ch, promise);
+                new ClientChannelInitializer( negotatorFactory, sessionListener).initialize(ch, promise);
             }
         });
     }
 
-    private static class ClientSslChannelInitializer extends AbstractSslChannelInitializer {
+    private static class ClientChannelInitializer extends AbstractChannelInitializer {
 
         private final NetconfClientSessionNegotiatorFactory negotiatorFactory;
         private final NetconfClientSessionListener sessionListener;
 
-        private ClientSslChannelInitializer(Optional<SSLContext> maybeContext,
-                                            NetconfClientSessionNegotiatorFactory negotiatorFactory, NetconfClientSessionListener sessionListener) {
-            super(maybeContext);
+        private ClientChannelInitializer(NetconfClientSessionNegotiatorFactory negotiatorFactory,
+                                            NetconfClientSessionListener sessionListener) {
             this.negotiatorFactory = negotiatorFactory;
             this.sessionListener = sessionListener;
         }
 
+        @Override
+        public void initialize(SocketChannel ch, Promise<? extends NetconfSession> promise) {
+                super.initialize(ch,promise);
+        }
+
         @Override
         protected void initializeAfterDecoder(SocketChannel ch, Promise<? extends NetconfSession> promise) {
             ch.pipeline().addLast("negotiator", negotiatorFactory.getSessionNegotiator(new SessionListenerFactory() {
@@ -84,12 +81,7 @@ public class NetconfClientDispatcher extends AbstractDispatcher<NetconfClientSes
             }, ch, promise));
         }
 
-        @Override
-        protected void initSslEngine(SSLEngine sslEngine) {
-            sslEngine.setUseClientMode(true);
-        }
     }
-
     @Override
     public void close() {
         try {
index b19c09263b9fa481c76307da0bb2dbebc310bb85..4de6cc35c0dad3f00afe949821a1dab59f4bc3da 100644 (file)
@@ -8,21 +8,21 @@
 
 package org.opendaylight.controller.netconf.client;
 
+import io.netty.channel.ChannelHandler;
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.socket.SocketChannel;
+import io.netty.util.HashedWheelTimer;
+import io.netty.util.concurrent.Future;
+import io.netty.util.concurrent.Promise;
 import java.io.IOException;
 import java.net.InetSocketAddress;
-
-import javax.net.ssl.SSLContext;
-
 import org.opendaylight.controller.netconf.api.NetconfMessage;
 import org.opendaylight.controller.netconf.api.NetconfSession;
 import org.opendaylight.controller.netconf.api.NetconfTerminationReason;
 import org.opendaylight.controller.netconf.util.AbstractChannelInitializer;
-import org.opendaylight.controller.netconf.util.handler.FramingMechanismHandlerFactory;
-import org.opendaylight.controller.netconf.util.handler.NetconfMessageAggregator;
 import org.opendaylight.controller.netconf.util.handler.ssh.SshHandler;
 import org.opendaylight.controller.netconf.util.handler.ssh.authentication.AuthenticationHandler;
 import org.opendaylight.controller.netconf.util.handler.ssh.client.Invoker;
-import org.opendaylight.controller.netconf.util.messages.FramingMechanism;
 import org.opendaylight.controller.netconf.util.messages.NetconfMessageFactory;
 import org.opendaylight.protocol.framework.ProtocolHandlerFactory;
 import org.opendaylight.protocol.framework.ProtocolMessageDecoder;
@@ -31,15 +31,6 @@ import org.opendaylight.protocol.framework.ReconnectStrategy;
 import org.opendaylight.protocol.framework.SessionListener;
 import org.opendaylight.protocol.framework.SessionListenerFactory;
 
-import com.google.common.base.Optional;
-
-import io.netty.channel.ChannelHandler;
-import io.netty.channel.EventLoopGroup;
-import io.netty.channel.socket.SocketChannel;
-import io.netty.util.HashedWheelTimer;
-import io.netty.util.concurrent.Future;
-import io.netty.util.concurrent.Promise;
-
 public class NetconfSshClientDispatcher extends NetconfClientDispatcher {
 
     private AuthenticationHandler authHandler;
@@ -48,13 +39,12 @@ public class NetconfSshClientDispatcher extends NetconfClientDispatcher {
 
     public NetconfSshClientDispatcher(AuthenticationHandler authHandler, EventLoopGroup bossGroup,
             EventLoopGroup workerGroup) {
-        super(Optional.<SSLContext> absent(), bossGroup, workerGroup);
+        super(bossGroup, workerGroup);
         this.authHandler = authHandler;
         this.timer = new HashedWheelTimer();
         this.negotatorFactory = new NetconfClientSessionNegotiatorFactory(timer);
     }
 
-    @Override
     public Future<NetconfClientSession> createClient(InetSocketAddress address,
             final NetconfClientSessionListener sessionListener, ReconnectStrategy strat) {
         return super.createClient(address, strat, new PipelineInitializer<NetconfClientSession>() {
@@ -88,12 +78,7 @@ public class NetconfSshClientDispatcher extends NetconfClientDispatcher {
             try {
                 Invoker invoker = Invoker.subsystem("netconf");
                 ch.pipeline().addFirst(new SshHandler(authenticationHandler, invoker));
-                ch.pipeline().addLast("aggregator", new NetconfMessageAggregator(FramingMechanism.EOM));
-                ch.pipeline().addLast(handlerFactory.getDecoders());
-                initializeAfterDecoder(ch, promise);
-                ch.pipeline().addLast("frameEncoder",
-                        FramingMechanismHandlerFactory.createHandler(FramingMechanism.EOM));
-                ch.pipeline().addLast(handlerFactory.getEncoders());
+                super.initialize(ch,promise);
             } catch (IOException e) {
                 throw new RuntimeException(e);
             }
index 882d368a1af3648b06579903769d48026ecdf38c..4f60788975fb910f5ae29a4fbac35b8f28d4fe08 100644 (file)
@@ -8,25 +8,21 @@
 
 package org.opendaylight.controller.netconf.impl;
 
-import com.google.common.base.Optional;
 import io.netty.channel.ChannelFuture;
 import io.netty.channel.EventLoopGroup;
 import io.netty.channel.socket.SocketChannel;
 import io.netty.util.concurrent.Promise;
+import java.net.InetSocketAddress;
 import org.opendaylight.controller.netconf.api.NetconfSession;
 import org.opendaylight.controller.netconf.impl.util.DeserializerExceptionHandler;
-import org.opendaylight.controller.netconf.util.AbstractSslChannelInitializer;
+import org.opendaylight.controller.netconf.util.AbstractChannelInitializer;
 import org.opendaylight.protocol.framework.AbstractDispatcher;
 
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLEngine;
-import java.net.InetSocketAddress;
-
 public class NetconfServerDispatcher extends AbstractDispatcher<NetconfSession, NetconfServerSessionListener> {
 
-    private final ServerSslChannelInitializer initializer;
+    private final ServerChannelInitializer initializer;
 
-    public NetconfServerDispatcher(ServerSslChannelInitializer serverChannelInitializer, EventLoopGroup bossGroup,
+    public NetconfServerDispatcher(ServerChannelInitializer serverChannelInitializer, EventLoopGroup bossGroup,
             EventLoopGroup workerGroup) {
         super(bossGroup, workerGroup);
         this.initializer = serverChannelInitializer;
@@ -43,15 +39,13 @@ public class NetconfServerDispatcher extends AbstractDispatcher<NetconfSession,
         });
     }
 
-    public static class ServerSslChannelInitializer extends AbstractSslChannelInitializer {
+    public static class ServerChannelInitializer extends AbstractChannelInitializer {
 
         private final NetconfServerSessionNegotiatorFactory negotiatorFactory;
         private final NetconfServerSessionListenerFactory listenerFactory;
 
-        public ServerSslChannelInitializer(Optional<SSLContext> maybeContext,
-                                            NetconfServerSessionNegotiatorFactory negotiatorFactory,
+        public ServerChannelInitializer(NetconfServerSessionNegotiatorFactory negotiatorFactory,
                                             NetconfServerSessionListenerFactory listenerFactory) {
-            super(maybeContext);
             this.negotiatorFactory = negotiatorFactory;
             this.listenerFactory = listenerFactory;
         }
@@ -62,10 +56,6 @@ public class NetconfServerDispatcher extends AbstractDispatcher<NetconfSession,
             ch.pipeline().addLast("negotiator", negotiatorFactory.getSessionNegotiator(listenerFactory, ch, promise));
         }
 
-        @Override
-        protected void initSslEngine(SSLEngine sslEngine) {
-            sslEngine.setUseClientMode(false);
-        }
     }
 
 }
index b334c354fbd8749026e7a01447a775aee2d74c05..1d18f063bcc062ed64fb077d7cc34d07369a8d2e 100644 (file)
@@ -7,9 +7,10 @@
  */
 package org.opendaylight.controller.netconf.impl.osgi;
 
-import com.google.common.base.Optional;
 import io.netty.channel.nio.NioEventLoopGroup;
 import io.netty.util.HashedWheelTimer;
+import java.lang.management.ManagementFactory;
+import java.net.InetSocketAddress;
 import org.opendaylight.controller.netconf.impl.DefaultCommitNotificationProducer;
 import org.opendaylight.controller.netconf.impl.NetconfServerDispatcher;
 import org.opendaylight.controller.netconf.impl.NetconfServerSessionListenerFactory;
@@ -21,10 +22,6 @@ import org.osgi.framework.BundleContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.net.ssl.SSLContext;
-import java.lang.management.ManagementFactory;
-import java.net.InetSocketAddress;
-
 public class NetconfImplActivator implements BundleActivator {
 
     private static final Logger logger = LoggerFactory.getLogger(NetconfImplActivator.class);
@@ -55,8 +52,8 @@ public class NetconfImplActivator implements BundleActivator {
 
         eventLoopGroup = new NioEventLoopGroup();
 
-        NetconfServerDispatcher.ServerSslChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerSslChannelInitializer(
-                Optional.<SSLContext>absent(), serverNegotiatorFactory, listenerFactory);
+        NetconfServerDispatcher.ServerChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerChannelInitializer(
+                serverNegotiatorFactory, listenerFactory);
         dispatch = new NetconfServerDispatcher(serverChannelInitializer, eventLoopGroup, eventLoopGroup);
 
         logger.info("Starting TCP netconf server at {}", address);
index b363976aaed6b6afd8f3aa4c9844ffb5357a661c..c0d2687a8a092b376f498e5cccadcaadfb816ab4 100644 (file)
@@ -14,6 +14,18 @@ import io.netty.channel.ChannelFuture;
 import io.netty.channel.EventLoopGroup;
 import io.netty.channel.nio.NioEventLoopGroup;
 import io.netty.util.HashedWheelTimer;
+import java.io.DataOutputStream;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.lang.management.ManagementFactory;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import javax.management.ObjectName;
 import org.apache.commons.io.IOUtils;
 import org.junit.After;
 import org.junit.AfterClass;
@@ -42,21 +54,6 @@ import org.opendaylight.controller.netconf.util.xml.XmlUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
-
-import javax.management.ObjectName;
-import javax.net.ssl.SSLContext;
-import java.io.DataOutputStream;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.lang.management.ManagementFactory;
-import java.net.InetSocketAddress;
-import java.net.Socket;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.TimeUnit;
-
 import static com.google.common.base.Preconditions.checkNotNull;
 import static org.junit.Assert.fail;
 import static org.mockito.Matchers.any;
@@ -67,8 +64,7 @@ public class ConcurrentClientsTest {
 
     private static final int CONCURRENCY = 16;
     private static EventLoopGroup nettyGroup = new NioEventLoopGroup();
-    public static final NetconfClientDispatcher NETCONF_CLIENT_DISPATCHER = new NetconfClientDispatcher(
-            Optional.<SSLContext> absent(), nettyGroup, nettyGroup);
+    public static final NetconfClientDispatcher NETCONF_CLIENT_DISPATCHER = new NetconfClientDispatcher( nettyGroup, nettyGroup);
 
     @Mock
     private YangStoreService yangStoreService;
@@ -109,8 +105,7 @@ public class ConcurrentClientsTest {
 
         NetconfServerSessionListenerFactory listenerFactory = new NetconfServerSessionListenerFactory(
                 factoriesListener, commitNot, idProvider);
-        NetconfServerDispatcher.ServerSslChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerSslChannelInitializer(
-                Optional.<SSLContext> absent(), serverNegotiatorFactory, listenerFactory);
+        NetconfServerDispatcher.ServerChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerChannelInitializer(serverNegotiatorFactory, listenerFactory);
         dispatch = new NetconfServerDispatcher(serverChannelInitializer, nettyGroup, nettyGroup);
 
         ChannelFuture s = dispatch.createServer(netconfAddress);
index e43febec793f6ad43029169ed083c7ede7f22a4d..eec96592d8e4e6e72e701a5596de52e17a1d7738 100644 (file)
@@ -8,21 +8,18 @@
 
 package org.opendaylight.controller.netconf.impl;
 
-import com.google.common.base.Optional;
 import io.netty.channel.ChannelFuture;
 import io.netty.channel.EventLoopGroup;
 import io.netty.channel.nio.NioEventLoopGroup;
 import io.netty.util.HashedWheelTimer;
+import java.lang.management.ManagementFactory;
+import java.net.InetSocketAddress;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceFactoryListener;
 import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceFactoryListenerImpl;
 
-import javax.net.ssl.SSLContext;
-import java.lang.management.ManagementFactory;
-import java.net.InetSocketAddress;
-
 public class NetconfDispatcherImplTest {
 
     private EventLoopGroup nettyGroup;
@@ -50,7 +47,7 @@ public class NetconfDispatcherImplTest {
 
         NetconfServerSessionListenerFactory listenerFactory = new NetconfServerSessionListenerFactory(
                 factoriesListener, commitNot, idProvider);
-        NetconfServerDispatcher.ServerSslChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerSslChannelInitializer(Optional.<SSLContext>absent(), serverNegotiatorFactory, listenerFactory);
+        NetconfServerDispatcher.ServerChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerChannelInitializer(serverNegotiatorFactory, listenerFactory);
 
 
         NetconfServerDispatcher dispatch = new NetconfServerDispatcher(
index 0c22a71c6b38e20b96da5163a26bed1a1b94e30b..a2b87c113c2a2f9e3b5028edefadafb69863e880 100644 (file)
@@ -8,11 +8,24 @@
 
 package org.opendaylight.controller.netconf.it;
 
-import com.google.common.base.Optional;
 import io.netty.channel.ChannelFuture;
 import io.netty.channel.EventLoopGroup;
 import io.netty.channel.nio.NioEventLoopGroup;
 import io.netty.util.HashedWheelTimer;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.management.ManagementFactory;
+import java.net.InetSocketAddress;
+import java.security.KeyManagementException;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.UnrecoverableKeyException;
+import java.security.cert.CertificateException;
+import java.util.Collection;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import javax.net.ssl.KeyManagerFactory;
+import javax.net.ssl.SSLContext;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -32,21 +45,6 @@ import org.opendaylight.controller.netconf.impl.SessionIdProvider;
 import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceFactoryListenerImpl;
 import org.opendaylight.protocol.util.SSLUtil;
 
-import javax.net.ssl.KeyManagerFactory;
-import javax.net.ssl.SSLContext;
-import java.io.IOException;
-import java.io.InputStream;
-import java.lang.management.ManagementFactory;
-import java.net.InetSocketAddress;
-import java.security.KeyManagementException;
-import java.security.KeyStoreException;
-import java.security.NoSuchAlgorithmException;
-import java.security.UnrecoverableKeyException;
-import java.security.cert.CertificateException;
-import java.util.Collection;
-import java.util.List;
-import java.util.concurrent.TimeUnit;
-
 public class NetconfITSecureTest extends AbstractConfigTest {
 
     private static final InetSocketAddress tlsAddress = new InetSocketAddress("127.0.0.1", 12024);
@@ -68,13 +66,12 @@ public class NetconfITSecureTest extends AbstractConfigTest {
 
         nettyThreadgroup = new NioEventLoopGroup();
 
-        dispatchS = createDispatcher(Optional.of(getSslContext()), factoriesListener);
+        dispatchS = createDispatcher(factoriesListener);
         ChannelFuture s = dispatchS.createServer(tlsAddress);
         s.await();
     }
 
-    private NetconfServerDispatcher createDispatcher(Optional<SSLContext> sslC,
-            NetconfOperationServiceFactoryListenerImpl factoriesListener) {
+    private NetconfServerDispatcher createDispatcher(NetconfOperationServiceFactoryListenerImpl factoriesListener) {
         SessionIdProvider idProvider = new SessionIdProvider();
         NetconfServerSessionNegotiatorFactory serverNegotiatorFactory = new NetconfServerSessionNegotiatorFactory(
                 new HashedWheelTimer(5000, TimeUnit.MILLISECONDS), factoriesListener, idProvider);
@@ -82,8 +79,8 @@ public class NetconfITSecureTest extends AbstractConfigTest {
         NetconfServerSessionListenerFactory listenerFactory = new NetconfServerSessionListenerFactory(
                 factoriesListener, commitNot, idProvider);
 
-        NetconfServerDispatcher.ServerSslChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerSslChannelInitializer(
-                sslC, serverNegotiatorFactory, listenerFactory);
+        NetconfServerDispatcher.ServerChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerChannelInitializer(
+                serverNegotiatorFactory, listenerFactory);
         return new NetconfServerDispatcher(serverChannelInitializer, nettyThreadgroup, nettyThreadgroup);
     }
 
@@ -114,7 +111,7 @@ public class NetconfITSecureTest extends AbstractConfigTest {
 
     @Test
     public void testSecure() throws Exception {
-        NetconfClientDispatcher dispatch = new NetconfClientDispatcher(Optional.of(getSslContext()), nettyThreadgroup, nettyThreadgroup);
+        NetconfClientDispatcher dispatch = new NetconfClientDispatcher(nettyThreadgroup, nettyThreadgroup);
         try (NetconfClient netconfClient = new NetconfClient("tls-client", tlsAddress, 4000, dispatch))  {
 
         }
index 65cc2b4e373a3f551633d1cb564461ab39e0b174..9483785031b9c6fee67dbb8f5d4904767b5cd49a 100644 (file)
@@ -29,7 +29,6 @@ import java.util.Set;
 import java.util.concurrent.TimeUnit;
 import java.util.regex.Pattern;
 import javax.management.ObjectName;
-import javax.net.ssl.SSLContext;
 import javax.xml.parsers.ParserConfigurationException;
 import junit.framework.Assert;
 import org.junit.After;
@@ -113,15 +112,14 @@ public class NetconfITTest extends AbstractConfigTest {
 
         commitNot = new DefaultCommitNotificationProducer(ManagementFactory.getPlatformMBeanServer());
 
-        dispatch = createDispatcher(Optional.<SSLContext> absent(), factoriesListener);
+        dispatch = createDispatcher(factoriesListener);
         ChannelFuture s = dispatch.createServer(tcpAddress);
         s.await();
 
-        clientDispatcher = new NetconfClientDispatcher(Optional.<SSLContext>absent(), nettyThreadgroup, nettyThreadgroup);
+        clientDispatcher = new NetconfClientDispatcher( nettyThreadgroup, nettyThreadgroup);
     }
 
-    private NetconfServerDispatcher createDispatcher(Optional<SSLContext> sslC,
-            NetconfOperationServiceFactoryListenerImpl factoriesListener) {
+    private NetconfServerDispatcher createDispatcher(NetconfOperationServiceFactoryListenerImpl factoriesListener) {
         SessionIdProvider idProvider = new SessionIdProvider();
         NetconfServerSessionNegotiatorFactory serverNegotiatorFactory = new NetconfServerSessionNegotiatorFactory(
                 new HashedWheelTimer(5000, TimeUnit.MILLISECONDS), factoriesListener, idProvider);
@@ -129,8 +127,8 @@ public class NetconfITTest extends AbstractConfigTest {
         NetconfServerSessionListenerFactory listenerFactory = new NetconfServerSessionListenerFactory(
                 factoriesListener, commitNot, idProvider);
 
-        NetconfServerDispatcher.ServerSslChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerSslChannelInitializer(
-                sslC, serverNegotiatorFactory, listenerFactory);
+        NetconfServerDispatcher.ServerChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerChannelInitializer(
+                serverNegotiatorFactory, listenerFactory);
         return new NetconfServerDispatcher(serverChannelInitializer, nettyThreadgroup, nettyThreadgroup);
     }
 
index d2f6c8c81ce749a234d7ae2d433dad953e2e20c6..6f164f93d9c9482613a286352a6868e41cf649c3 100644 (file)
@@ -30,15 +30,15 @@ public class NetconfSSHActivator implements BundleActivator{
 
     private NetconfSSHServer server;
     private static final Logger logger =  LoggerFactory.getLogger(NetconfSSHActivator.class);
+    private static final String EXCEPTION_MESSAGE = "Netconf ssh bridge is not available.";
 
     @Override
     public void start(BundleContext context) throws Exception {
 
         logger.trace("Starting netconf SSH  bridge.");
 
-        Optional<InetSocketAddress> sshSocketAddressOptional = NetconfConfigUtil.extractSSHNetconfAddress(context);
-        InetSocketAddress tcpSocketAddress = NetconfConfigUtil.extractTCPNetconfAddress(context,
-                "TCP is not configured, netconf ssh bridge is not available.");
+        Optional<InetSocketAddress> sshSocketAddressOptional = NetconfConfigUtil.extractSSHNetconfAddress(context,EXCEPTION_MESSAGE);
+        InetSocketAddress tcpSocketAddress = NetconfConfigUtil.extractTCPNetconfAddress(context,EXCEPTION_MESSAGE);
 
         if (sshSocketAddressOptional.isPresent()){
             server = NetconfSSHServer.start(sshSocketAddressOptional.get().getPort(),tcpSocketAddress);
index caee5421525515a2b9cef2b136cf00d2f5944fd5..aeee2fb04baea1c4bd1535d7b677fb1f50957d8e 100644 (file)
@@ -11,10 +11,22 @@ package org.opendaylight.controller.netconf.util;
 import io.netty.channel.socket.SocketChannel;
 import io.netty.util.concurrent.Promise;
 import org.opendaylight.controller.netconf.api.NetconfSession;
+import org.opendaylight.controller.netconf.util.handler.FramingMechanismHandlerFactory;
+import org.opendaylight.controller.netconf.util.handler.NetconfHandlerFactory;
+import org.opendaylight.controller.netconf.util.handler.NetconfMessageAggregator;
+import org.opendaylight.controller.netconf.util.messages.FramingMechanism;
+import org.opendaylight.controller.netconf.util.messages.NetconfMessageFactory;
 
 public abstract class AbstractChannelInitializer {
 
-    public abstract void initialize(SocketChannel ch, Promise<? extends NetconfSession> promise);
+    public void initialize(SocketChannel ch, Promise<? extends NetconfSession> promise){
+        NetconfHandlerFactory handlerFactory = new NetconfHandlerFactory(new NetconfMessageFactory());
+        ch.pipeline().addLast("aggregator", new NetconfMessageAggregator(FramingMechanism.EOM));
+        ch.pipeline().addLast(handlerFactory.getDecoders());
+        initializeAfterDecoder(ch, promise);
+        ch.pipeline().addLast("frameEncoder", FramingMechanismHandlerFactory.createHandler(FramingMechanism.EOM));
+        ch.pipeline().addLast(handlerFactory.getEncoders());
+    }
 
     protected abstract void initializeAfterDecoder(SocketChannel ch, Promise<? extends NetconfSession> promise);
 
diff --git a/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/AbstractSslChannelInitializer.java b/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/AbstractSslChannelInitializer.java
deleted file mode 100644 (file)
index d490eb2..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright (c) 2013 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.netconf.util;
-
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLEngine;
-
-import org.opendaylight.controller.netconf.api.NetconfMessage;
-import org.opendaylight.controller.netconf.api.NetconfSession;
-import org.opendaylight.controller.netconf.util.handler.FramingMechanismHandlerFactory;
-import org.opendaylight.controller.netconf.util.handler.NetconfMessageAggregator;
-import org.opendaylight.controller.netconf.util.messages.FramingMechanism;
-import org.opendaylight.controller.netconf.util.messages.NetconfMessageFactory;
-import org.opendaylight.protocol.framework.ProtocolHandlerFactory;
-import org.opendaylight.protocol.framework.ProtocolMessageDecoder;
-import org.opendaylight.protocol.framework.ProtocolMessageEncoder;
-
-import com.google.common.base.Optional;
-
-import io.netty.channel.ChannelHandler;
-import io.netty.channel.socket.SocketChannel;
-import io.netty.handler.ssl.SslHandler;
-import io.netty.util.concurrent.Promise;
-
-public abstract class AbstractSslChannelInitializer extends AbstractChannelInitializer {
-
-    private final Optional<SSLContext> maybeContext;
-    private final NetconfHandlerFactory handlerFactory;
-
-    public AbstractSslChannelInitializer(Optional<SSLContext> maybeContext) {
-        this.maybeContext = maybeContext;
-        this.handlerFactory = new NetconfHandlerFactory(new NetconfMessageFactory());
-    }
-
-    @Override
-    public void initialize(SocketChannel ch, Promise<? extends NetconfSession> promise) {
-        if (maybeContext.isPresent()) {
-            initSsl(ch);
-        }
-
-        ch.pipeline().addLast("aggregator", new NetconfMessageAggregator(FramingMechanism.EOM));
-        ch.pipeline().addLast(handlerFactory.getDecoders());
-        initializeAfterDecoder(ch, promise);
-        ch.pipeline().addLast("frameEncoder", FramingMechanismHandlerFactory.createHandler(FramingMechanism.EOM));
-        ch.pipeline().addLast(handlerFactory.getEncoders());
-    }
-
-    private void initSsl(SocketChannel ch) {
-        SSLEngine sslEngine = maybeContext.get().createSSLEngine();
-        initSslEngine(sslEngine);
-        final SslHandler handler = new SslHandler(sslEngine);
-        ch.pipeline().addLast("ssl", handler);
-    }
-
-    protected abstract void initSslEngine(SSLEngine sslEngine);
-
-    private static final class NetconfHandlerFactory extends ProtocolHandlerFactory<NetconfMessage> {
-
-        public NetconfHandlerFactory(final NetconfMessageFactory msgFactory) {
-            super(msgFactory);
-        }
-
-        @Override
-        public ChannelHandler[] getEncoders() {
-            return new ChannelHandler[] { new ProtocolMessageEncoder(this.msgFactory) };
-        }
-
-        @Override
-        public ChannelHandler[] getDecoders() {
-            return new ChannelHandler[] { new ProtocolMessageDecoder(this.msgFactory) };
-        }
-    }
-}
diff --git a/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/handler/NetconfHandlerFactory.java b/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/handler/NetconfHandlerFactory.java
new file mode 100644 (file)
index 0000000..d878c5e
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2013 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.netconf.util.handler;
+
+import io.netty.channel.ChannelHandler;
+import org.opendaylight.controller.netconf.api.NetconfMessage;
+import org.opendaylight.controller.netconf.util.messages.NetconfMessageFactory;
+import org.opendaylight.protocol.framework.ProtocolHandlerFactory;
+import org.opendaylight.protocol.framework.ProtocolMessageDecoder;
+import org.opendaylight.protocol.framework.ProtocolMessageEncoder;
+
+public class NetconfHandlerFactory extends ProtocolHandlerFactory<NetconfMessage> {
+
+    public NetconfHandlerFactory(final NetconfMessageFactory msgFactory) {
+        super(msgFactory);
+    }
+
+    @Override
+    public ChannelHandler[] getEncoders() {
+        return new ChannelHandler[] { new ProtocolMessageEncoder(this.msgFactory) };
+    }
+
+    @Override
+    public ChannelHandler[] getDecoders() {
+        return new ChannelHandler[] { new ProtocolMessageDecoder(this.msgFactory) };
+    }
+
+}
index 35e17a2a3e4564ffceac32158d00e5f7e6faba39..b1d902d6341f83415b8be25509bc6e1dc27000c2 100644 (file)
 package org.opendaylight.controller.netconf.util.osgi;
 
 import com.google.common.base.Optional;
-import org.opendaylight.protocol.util.SSLUtil;
-import org.osgi.framework.BundleContext;
-
-import javax.net.ssl.KeyManagerFactory;
-import javax.net.ssl.SSLContext;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
 import java.net.InetSocketAddress;
-
+import org.osgi.framework.BundleContext;
 import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.base.Preconditions.checkState;
 
-public class NetconfConfigUtil {
+    public class NetconfConfigUtil {
     private static final String PREFIX_PROP = "netconf.";
 
     private enum InfixProp {
-        tcp, tls, ssh
+        tcp, ssh
     }
 
     private static final String PORT_SUFFIX_PROP = ".port";
     private static final String ADDRESS_SUFFIX_PROP = ".address";
 
-    private static final String NETCONF_TLS_KEYSTORE_PROP = PREFIX_PROP + InfixProp.tls + ".keystore";
-    private static final String NETCONF_TLS_KEYSTORE_PASSWORD_PROP = NETCONF_TLS_KEYSTORE_PROP + ".password";
-
     public static InetSocketAddress extractTCPNetconfAddress(BundleContext context, String exceptionMessageIfNotFound) {
 
-        Optional<InetSocketAddress> inetSocketAddressOptional = extractSomeNetconfAddress(context, InfixProp.tcp);
+        Optional<InetSocketAddress> inetSocketAddressOptional = extractSomeNetconfAddress(context, InfixProp.tcp, exceptionMessageIfNotFound);
+
         if (inetSocketAddressOptional.isPresent() == false) {
             throw new IllegalStateException("Netconf tcp address not found." + exceptionMessageIfNotFound);
         }
         return inetSocketAddressOptional.get();
     }
 
-    public static Optional<InetSocketAddress> extractSSHNetconfAddress(BundleContext context) {
-        return extractSomeNetconfAddress(context, InfixProp.ssh);
-    }
-
-
-    public static Optional<TLSConfiguration> extractTLSConfiguration(BundleContext context) {
-        Optional<InetSocketAddress> address = extractSomeNetconfAddress(context, InfixProp.tls);
-        if (address.isPresent()) {
-            String keystoreFileName = context.getProperty(NETCONF_TLS_KEYSTORE_PROP);
-            File keystoreFile = new File(keystoreFileName);
-            checkState(keystoreFile.exists() && keystoreFile.isFile() && keystoreFile.canRead(),
-                    "Keystore file %s does not exist or is not readable file", keystoreFileName);
-            keystoreFile = keystoreFile.getAbsoluteFile();
-            String keystorePassword = context.getProperty(NETCONF_TLS_KEYSTORE_PASSWORD_PROP);
-            checkNotNull(keystoreFileName, "Property %s must be defined for tls netconf server",
-                    NETCONF_TLS_KEYSTORE_PROP);
-            keystorePassword = keystorePassword != null ? keystorePassword : "";
-            return Optional.of(new TLSConfiguration(address.get(), keystoreFile, keystorePassword));
-        } else {
-            return Optional.absent();
-        }
-    }
-
-    public static class TLSConfiguration {
-        private final InetSocketAddress address;
-        private final File keystoreFile;
-        private final String keystorePassword;
-        private final SSLContext sslContext;
-
-        TLSConfiguration(InetSocketAddress address, File keystoreFile, String keystorePassword) {
-            this.address = address;
-            this.keystoreFile = keystoreFile;
-            this.keystorePassword = keystorePassword;
-            try {
-                try (InputStream keyStoreIS = new FileInputStream(keystoreFile)) {
-                    try (InputStream trustStoreIS = new FileInputStream(keystoreFile)) {
-                        sslContext = SSLUtil.initializeSecureContext("password", keyStoreIS, trustStoreIS, KeyManagerFactory.getDefaultAlgorithm());
-                    }
-                }
-            } catch (Exception e) {
-                throw new RuntimeException("Cannot initialize ssl context for netconf file " + keystoreFile, e);
-            }
-        }
-
-        public SSLContext getSslContext() {
-            return sslContext;
-        }
-
-        public InetSocketAddress getAddress() {
-            return address;
-        }
-
-        public File getKeystoreFile() {
-            return keystoreFile;
-        }
-
-        public String getKeystorePassword() {
-            return keystorePassword;
-        }
+    public static Optional<InetSocketAddress> extractSSHNetconfAddress(BundleContext context, String exceptionMessage) {
+        return extractSomeNetconfAddress(context, InfixProp.ssh, exceptionMessage);
     }
 
     /**
      * @param context
      *            from which properties are being read.
      * @param infixProp
-     *            either tcp or tls
-     * @return absent if address is missing, value if address and port are
-     *         valid.
+     *            either tcp or ssh
+     * @return value if address and port are valid.
      * @throws IllegalStateException
-     *             if address or port are invalid
+     *             if address or port are invalid, or configuration is missing
      */
     private static Optional<InetSocketAddress> extractSomeNetconfAddress(BundleContext context,
-            InfixProp infixProp) {
+            InfixProp infixProp, String exceptionMessage) {
         String address = context.getProperty(PREFIX_PROP + infixProp + ADDRESS_SUFFIX_PROP);
         if (address == null) {
-            return Optional.absent();
+            throw new IllegalStateException("Cannot find initial netconf configuration for parameter    "
+                    +PREFIX_PROP + infixProp + ADDRESS_SUFFIX_PROP
+                    +" in config.ini. "+exceptionMessage);
         }
         String portKey = PREFIX_PROP + infixProp + PORT_SUFFIX_PROP;
         String portString = context.getProperty(portKey);
index 2233b41a850d34e0bcd15937d5e56ae1d158280e..caa0094c4b2b31a1259df17b536ebdb84d89a8b6 100644 (file)
 
                     <name>test1</name>
 
+                    <sleep-factor>
+                        2.00
+                    </sleep-factor>
+
                     <extended>
                             1
                     </extended>
index 6fddef06a8388a80a5278ce2f9a3234ae4461982..7a177fa078c8607e41bb2fa62f9ea6c2c8b7d032 100644 (file)
@@ -38,6 +38,7 @@ import org.opendaylight.controller.protocol_plugin.openflow.core.ISwitch;
 import org.openflow.protocol.OFBarrierReply;
 import org.openflow.protocol.OFBarrierRequest;
 import org.openflow.protocol.OFEchoReply;
+import org.openflow.protocol.OFEchoRequest;
 import org.openflow.protocol.OFError;
 import org.openflow.protocol.OFFeaturesReply;
 import org.openflow.protocol.OFFlowMod;
@@ -60,6 +61,7 @@ import org.openflow.util.HexString;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+
 public class SwitchHandler implements ISwitch {
     private static final Logger logger = LoggerFactory.getLogger(SwitchHandler.class);
     private static final int SWITCH_LIVENESS_TIMER = 5000;
@@ -371,6 +373,14 @@ public class SwitchHandler implements ISwitch {
                 break;
             case ECHO_REQUEST:
                 OFEchoReply echoReply = (OFEchoReply) factory.getMessage(OFType.ECHO_REPLY);
+
+                byte []payload = ((OFEchoRequest)msg).getPayload();
+                if (payload != null && payload.length != 0 ) {
+                    // the response must have the same payload as the request
+                    echoReply.setPayload(payload);
+                    echoReply.setLength( (short)(echoReply.getLength() + payload.length) );
+                }
+
                 // respond immediately
                 asyncSendNow(echoReply, msg.getXid());
 
index b8f776fc176d49085487d556dcd4e11a353751cd..2c3cfb8303736229e6c86b618642f6bd72b12aaa 100644 (file)
@@ -483,6 +483,13 @@ public class Match implements Cloneable, Serializable {
 
     @Override
     public String toString() {
-        return "Match[" + fields.values() + "]";
+        StringBuilder builder = new StringBuilder();
+        builder.append("Match [fields=");
+        builder.append(fields);
+        builder.append(", matches=");
+        builder.append(matches);
+        builder.append("]");
+        return builder.toString();
     }
+
 }