From: Giovanni Meo Date: Tue, 3 Dec 2013 13:59:15 +0000 (+0000) Subject: Merge "Fix bug 171. EchoReply payload must be the same as the correspoding EchoReques... X-Git-Tag: jenkins-controller-bulk-release-prepare-only-2-1~270 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=39214b1fd8492ab553730ed9303ce7c950696631;hp=9d7777b3ffa62929c17c14f086529132a06b4eaf;p=controller.git Merge "Fix bug 171. EchoReply payload must be the same as the correspoding EchoRequest payload openVSwitch send empty request resulting in null payload in ODP redundant import removed rabased to the latest merged commit" --- diff --git a/opendaylight/config/pom.xml b/opendaylight/config/pom.xml index c9ed19dacb..675e5cf80d 100644 --- a/opendaylight/config/pom.xml +++ b/opendaylight/config/pom.xml @@ -39,6 +39,7 @@ netty-event-executor-config netty-timer-config config-persister-directory-adapter + yang-test-plugin diff --git a/opendaylight/config/yang-test-plugin/pom.xml b/opendaylight/config/yang-test-plugin/pom.xml new file mode 100644 index 0000000000..30ac8554fe --- /dev/null +++ b/opendaylight/config/yang-test-plugin/pom.xml @@ -0,0 +1,28 @@ + + + + org.opendaylight.controller + config-plugin-parent + 0.2.3-SNAPSHOT + ../config-plugin-parent + + 4.0.0 + maven-plugin + yang-test-plugin + + Remove generated source files, after new files generation, implementation is inserted. + ${project.artifactId} + + 3.0.4 + + + + + org.apache.maven + maven-plugin-api + 3.0.5 + + + \ 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 index 0000000000..461066215f --- /dev/null +++ b/opendaylight/config/yang-test-plugin/src/main/java/org/opendaylight/controller/config/yang/test/plugin/DeleteSources.java @@ -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 index 0000000000..dbb9ddb363 --- /dev/null +++ b/opendaylight/config/yang-test-plugin/src/main/java/org/opendaylight/controller/config/yang/test/plugin/ProcessSources.java @@ -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 index 0000000000..16a41d9adb --- /dev/null +++ b/opendaylight/config/yang-test-plugin/src/main/java/org/opendaylight/controller/config/yang/test/plugin/Util.java @@ -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 index 0000000000..068fd26844 --- /dev/null +++ b/opendaylight/config/yang-test-plugin/src/main/resources/Header.txt @@ -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 diff --git a/opendaylight/config/yang-test/pom.xml b/opendaylight/config/yang-test/pom.xml index e3737c78f3..149348df4b 100644 --- a/opendaylight/config/yang-test/pom.xml +++ b/opendaylight/config/yang-test/pom.xml @@ -101,6 +101,19 @@ + + org.opendaylight.controller + yang-test-plugin + ${config.version} + + + + delete-sources + process-sources + + + + diff --git a/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/DepTestImplModule.java b/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/DepTestImplModule.java index 1122c1ffa4..c64f824b15 100644 --- a/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/DepTestImplModule.java +++ b/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/DepTestImplModule.java @@ -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 { } }; + } } diff --git a/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/DepTestImplModuleFactory.java b/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/DepTestImplModuleFactory.java index 4152736768..c26c29ed60 100644 --- a/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/DepTestImplModuleFactory.java +++ b/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/DepTestImplModuleFactory.java @@ -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; /** diff --git a/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModule.java b/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModule.java index 7e1848dd6a..3594ee0353 100644 --- a/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModule.java +++ b/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModule.java @@ -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); + } } diff --git a/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModuleFactory.java b/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModuleFactory.java index 7cab528868..accc1db76e 100644 --- a/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModuleFactory.java +++ b/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModuleFactory.java @@ -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; /** diff --git a/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModuleUtil.java b/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModuleUtil.java index 58943c9df2..4de9804337 100644 --- a/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModuleUtil.java +++ b/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModuleUtil.java @@ -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; diff --git a/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/TestImplModule.java b/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/TestImplModule.java index 52a71620bf..9ba1db4eed 100644 --- a/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/TestImplModule.java +++ b/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/TestImplModule.java @@ -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 { } }; + } } diff --git a/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/TestImplModuleFactory.java b/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/TestImplModuleFactory.java index ce9aa92b64..a6ce734f96 100644 --- a/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/TestImplModuleFactory.java +++ b/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/TestImplModuleFactory.java @@ -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; /** diff --git a/opendaylight/forwardingrulesmanager/implementation/src/main/java/org/opendaylight/controller/forwardingrulesmanager/internal/ForwardingRulesManager.java b/opendaylight/forwardingrulesmanager/implementation/src/main/java/org/opendaylight/controller/forwardingrulesmanager/internal/ForwardingRulesManager.java index e639d41e8e..45fb11a83e 100644 --- a/opendaylight/forwardingrulesmanager/implementation/src/main/java/org/opendaylight/controller/forwardingrulesmanager/internal/ForwardingRulesManager.java +++ b/opendaylight/forwardingrulesmanager/implementation/src/main/java/org/opendaylight/controller/forwardingrulesmanager/internal/ForwardingRulesManager.java @@ -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 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 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 entry : this.originalSwView.entrySet()) { if (node.equals(entry.getKey().getNode())) { - list.add(entry.getKey().clone()); + list.add(entry.getValue().clone()); } } } diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/BindingAwareBrokerImpl.xtend b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/BindingAwareBrokerImpl.xtend index 1762aac090..9381a5a070 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/BindingAwareBrokerImpl.xtend +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/BindingAwareBrokerImpl.xtend @@ -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 root = InstanceIdentifier.builder().toInstance(); @@ -188,22 +189,30 @@ class BindingAwareBrokerImpl implements BindingAwareBroker, AutoCloseable { * Registers RPC Implementation * */ - def registerRpcImplementation(Class type, T service, OsgiProviderContext context, - Hashtable properties) { + override addRpcImplementation(Class 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(type, service, osgiReg, this); + return new RpcServiceRegistrationImpl(type, service, this); } - def RoutedRpcRegistration registerRoutedRpcImplementation(Class type, T service, - OsgiProviderContext context) { + override RoutedRpcRegistration addRoutedRpcImplementation(Class 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(service, router, this) } + + override getRpcService(Class service) { + checkNotNull(service, "Service should not be null"); + return getManagedDirectProxy(service) as T; + } private def RpcRouter resolveRpcRouter(Class type) { @@ -357,16 +366,14 @@ class RoutedRpcRegistrationImpl extends AbstractObjectRegi class RpcServiceRegistrationImpl extends AbstractObjectRegistration implements RpcRegistration { - val ServiceRegistration osgiRegistration; private var BindingAwareBrokerImpl broker; @Property val Class serviceType; - public new(Class type, T service, ServiceRegistration osgiReg, BindingAwareBrokerImpl broker) { + public new(Class type, T service, BindingAwareBrokerImpl broker) { super(service); this._serviceType = type; - this.osgiRegistration = osgiReg; this.broker = broker; } diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/OsgiProviderContext.xtend b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/OsgiProviderContext.xtend index 7fd3fd24d8..d1ec35157f 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/OsgiProviderContext.xtend +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/OsgiProviderContext.xtend @@ -33,22 +33,13 @@ class OsgiProviderContext extends OsgiConsumerContext implements ProviderContext } override addRpcImplementation(Class type, T implementation) { - - // TODO Auto-generated method stub - val properties = new Hashtable(); - 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 addRoutedRpcImplementation(Class 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; } diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/yang/opendaylight-binding-broker-impl.yang b/opendaylight/md-sal/sal-binding-broker/src/main/yang/opendaylight-binding-broker-impl.yang index 38770c193c..9da073f71b 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/main/yang/opendaylight-binding-broker-impl.yang +++ b/opendaylight/md-sal/sal-binding-broker/src/main/yang/opendaylight-binding-broker-impl.yang @@ -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; } diff --git a/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/config/yang/md/sal/connector/netconf/NetconfConnectorModule.java b/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/config/yang/md/sal/connector/netconf/NetconfConnectorModule.java index 1275924614..4d0a1ac6b6 100644 --- a/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/config/yang/md/sal/connector/netconf/NetconfConnectorModule.java +++ b/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/config/yang/md/sal/connector/netconf/NetconfConnectorModule.java @@ -77,10 +77,9 @@ public final class NetconfConnectorModule extends org.opendaylight.controller.co EventLoopGroup bossGroup = getBossThreadGroupDependency(); EventLoopGroup workerGroup = getWorkerThreadGroupDependency(); - Optional 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); diff --git a/opendaylight/md-sal/sal-rest-connector/pom.xml b/opendaylight/md-sal/sal-rest-connector/pom.xml index bdcb0bdd2b..3e13a584d4 100644 --- a/opendaylight/md-sal/sal-rest-connector/pom.xml +++ b/opendaylight/md-sal/sal-rest-connector/pom.xml @@ -77,6 +77,11 @@ 2.4 test + + org.opendaylight.yangtools + yang-model-util + 0.5.9-SNAPSHOT + diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/JsonMapper.java b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/JsonMapper.java index 9608d65e41..a42c468c2a 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/JsonMapper.java +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/JsonMapper.java @@ -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> 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); diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.xtend b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.xtend index eca4bd2572..470b4735a4 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.xtend +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.xtend @@ -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 uriToModuleName = HashBiMap.create(); private val Map moduleNameToUri = uriToModuleName.inverse(); - private val Map qnameToRpc = new ConcurrentHashMap(); - + private val Map 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; } - } diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/TestUtils.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/TestUtils.java index 89d24ad057..61942e81a6 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/TestUtils.java +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/TestUtils.java @@ -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 index 0000000000..c9ac042ff1 --- /dev/null +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/ToJsonIdentityrefTest.java @@ -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 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 index 0000000000..a5cc02e9f2 --- /dev/null +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/ToJsonLeafrefType.java @@ -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 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 index 0000000000..30890bf9c3 --- /dev/null +++ b/opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/identityref/identity-module.yang @@ -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 index 0000000000..273f5d77ee --- /dev/null +++ b/opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/identityref/identityref-module.yang @@ -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 index 0000000000..afc23b7946 --- /dev/null +++ b/opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/leafref/cont-augment-module.yang @@ -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 index 0000000000..8c8039290c --- /dev/null +++ b/opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/leafref/main-module.yang @@ -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 index 0000000000..bbebabec4e --- /dev/null +++ b/opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/leafref/xml/data_absolut_ref_to_existing_leaf.xml @@ -0,0 +1,6 @@ + + + true + + true + \ 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 index 0000000000..1bb9013a7f --- /dev/null +++ b/opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/leafref/xml/data_from_leafref_to_leafref.xml @@ -0,0 +1,3 @@ + + 200 + \ 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 index 0000000000..dfea9c811d --- /dev/null +++ b/opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/leafref/xml/data_ref_to_non_existing_leaf.xml @@ -0,0 +1,3 @@ + + 137 + \ 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 index 0000000000..7b05b0c89f --- /dev/null +++ b/opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/leafref/xml/data_ref_to_not_leaf.xml @@ -0,0 +1,3 @@ + + 44.33 + \ 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 index 0000000000..0d8cf660ac --- /dev/null +++ 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 @@ -0,0 +1,5 @@ + + 345 + 346 + 347 + \ 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 index 0000000000..4a73a8b0c4 --- /dev/null +++ b/opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/leafref/xml/data_relativ_ref_to_existing_leaf.xml @@ -0,0 +1,4 @@ + + 121 + 121 + \ No newline at end of file diff --git a/opendaylight/netconf/config-persister-impl/src/main/java/org/opendaylight/controller/netconf/persist/impl/ConfigPersisterNotificationHandler.java b/opendaylight/netconf/config-persister-impl/src/main/java/org/opendaylight/controller/netconf/persist/impl/ConfigPersisterNotificationHandler.java index b20577afd2..99b7ee60a2 100644 --- a/opendaylight/netconf/config-persister-impl/src/main/java/org/opendaylight/controller/netconf/persist/impl/ConfigPersisterNotificationHandler.java +++ b/opendaylight/netconf/config-persister-impl/src/main/java/org/opendaylight/controller/netconf/persist/impl/ConfigPersisterNotificationHandler.java @@ -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.absent(), nettyThreadgroup, nettyThreadgroup); + netconfClientDispatcher = new NetconfClientDispatcher(nettyThreadgroup, nettyThreadgroup); try { netconfClient = new NetconfClient(this.toString(), address, delay, netconfClientDispatcher); } catch (IllegalStateException e) { diff --git a/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClientDispatcher.java b/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClientDispatcher.java index 62c2113056..6ac57a88c9 100644 --- a/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClientDispatcher.java +++ b/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClientDispatcher.java @@ -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 implements Closeable { private static final Logger logger = LoggerFactory.getLogger(NetconfClient.class); - private final Optional maybeContext; private final NetconfClientSessionNegotiatorFactory negotatorFactory; private final HashedWheelTimer timer; - public NetconfClientDispatcher(final Optional 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 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 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 promise) { + super.initialize(ch,promise); + } + @Override protected void initializeAfterDecoder(SocketChannel ch, Promise promise) { ch.pipeline().addLast("negotiator", negotiatorFactory.getSessionNegotiator(new SessionListenerFactory() { @@ -84,12 +81,7 @@ public class NetconfClientDispatcher extends AbstractDispatcher absent(), bossGroup, workerGroup); + super(bossGroup, workerGroup); this.authHandler = authHandler; this.timer = new HashedWheelTimer(); this.negotatorFactory = new NetconfClientSessionNegotiatorFactory(timer); } - @Override public Future createClient(InetSocketAddress address, final NetconfClientSessionListener sessionListener, ReconnectStrategy strat) { return super.createClient(address, strat, new PipelineInitializer() { @@ -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); } diff --git a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/NetconfServerDispatcher.java b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/NetconfServerDispatcher.java index 882d368a1a..4f60788975 100644 --- a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/NetconfServerDispatcher.java +++ b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/NetconfServerDispatcher.java @@ -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 { - 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 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 AbstractDispatcherabsent(), serverNegotiatorFactory, listenerFactory); + NetconfServerDispatcher.ServerChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerChannelInitializer( + serverNegotiatorFactory, listenerFactory); dispatch = new NetconfServerDispatcher(serverChannelInitializer, eventLoopGroup, eventLoopGroup); logger.info("Starting TCP netconf server at {}", address); diff --git a/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/ConcurrentClientsTest.java b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/ConcurrentClientsTest.java index b363976aae..c0d2687a8a 100644 --- a/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/ConcurrentClientsTest.java +++ b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/ConcurrentClientsTest.java @@ -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. 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. absent(), serverNegotiatorFactory, listenerFactory); + NetconfServerDispatcher.ServerChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerChannelInitializer(serverNegotiatorFactory, listenerFactory); dispatch = new NetconfServerDispatcher(serverChannelInitializer, nettyGroup, nettyGroup); ChannelFuture s = dispatch.createServer(netconfAddress); diff --git a/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/NetconfDispatcherImplTest.java b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/NetconfDispatcherImplTest.java index e43febec79..eec96592d8 100644 --- a/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/NetconfDispatcherImplTest.java +++ b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/NetconfDispatcherImplTest.java @@ -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.absent(), serverNegotiatorFactory, listenerFactory); + NetconfServerDispatcher.ServerChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerChannelInitializer(serverNegotiatorFactory, listenerFactory); NetconfServerDispatcher dispatch = new NetconfServerDispatcher( diff --git a/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITSecureTest.java b/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITSecureTest.java index 0c22a71c6b..a2b87c113c 100644 --- a/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITSecureTest.java +++ b/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITSecureTest.java @@ -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 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)) { } diff --git a/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITTest.java b/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITTest.java index 65cc2b4e37..9483785031 100644 --- a/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITTest.java +++ b/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITTest.java @@ -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. absent(), factoriesListener); + dispatch = createDispatcher(factoriesListener); ChannelFuture s = dispatch.createServer(tcpAddress); s.await(); - clientDispatcher = new NetconfClientDispatcher(Optional.absent(), nettyThreadgroup, nettyThreadgroup); + clientDispatcher = new NetconfClientDispatcher( nettyThreadgroup, nettyThreadgroup); } - private NetconfServerDispatcher createDispatcher(Optional 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); } diff --git a/opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/osgi/NetconfSSHActivator.java b/opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/osgi/NetconfSSHActivator.java index d2f6c8c81c..6f164f93d9 100644 --- a/opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/osgi/NetconfSSHActivator.java +++ b/opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/osgi/NetconfSSHActivator.java @@ -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 sshSocketAddressOptional = NetconfConfigUtil.extractSSHNetconfAddress(context); - InetSocketAddress tcpSocketAddress = NetconfConfigUtil.extractTCPNetconfAddress(context, - "TCP is not configured, netconf ssh bridge is not available."); + Optional sshSocketAddressOptional = NetconfConfigUtil.extractSSHNetconfAddress(context,EXCEPTION_MESSAGE); + InetSocketAddress tcpSocketAddress = NetconfConfigUtil.extractTCPNetconfAddress(context,EXCEPTION_MESSAGE); if (sshSocketAddressOptional.isPresent()){ server = NetconfSSHServer.start(sshSocketAddressOptional.get().getPort(),tcpSocketAddress); diff --git a/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/AbstractChannelInitializer.java b/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/AbstractChannelInitializer.java index caee542152..aeee2fb04b 100644 --- a/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/AbstractChannelInitializer.java +++ b/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/AbstractChannelInitializer.java @@ -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 promise); + public void initialize(SocketChannel ch, Promise 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 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 index d490eb2be6..0000000000 --- a/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/AbstractSslChannelInitializer.java +++ /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 maybeContext; - private final NetconfHandlerFactory handlerFactory; - - public AbstractSslChannelInitializer(Optional maybeContext) { - this.maybeContext = maybeContext; - this.handlerFactory = new NetconfHandlerFactory(new NetconfMessageFactory()); - } - - @Override - public void initialize(SocketChannel ch, Promise 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 { - - 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 index 0000000000..d878c5e819 --- /dev/null +++ b/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/handler/NetconfHandlerFactory.java @@ -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 { + + 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/osgi/NetconfConfigUtil.java b/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/osgi/NetconfConfigUtil.java index 35e17a2a3e..b1d902d634 100644 --- a/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/osgi/NetconfConfigUtil.java +++ b/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/osgi/NetconfConfigUtil.java @@ -9,117 +9,50 @@ 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 inetSocketAddressOptional = extractSomeNetconfAddress(context, InfixProp.tcp); + Optional 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 extractSSHNetconfAddress(BundleContext context) { - return extractSomeNetconfAddress(context, InfixProp.ssh); - } - - - public static Optional extractTLSConfiguration(BundleContext context) { - Optional 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 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 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); diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/match/Match.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/match/Match.java index b8f776fc17..2c3cfb8303 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/match/Match.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/match/Match.java @@ -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(); } + }