From: Ed Warnicke Date: Wed, 2 Apr 2014 23:28:41 +0000 (+0000) Subject: Merge changes I6bc37e88,I0514b26e X-Git-Tag: autorelease-tag-v20140601202136_82eb3f9~286 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=5aa059de760149de263e9068fd87aa38a8f82835;hp=2d980b055ac55f04e2ad370c69d0a477fb552db1 Merge changes I6bc37e88,I0514b26e * changes: Fixed missing keys in sal-compatibility flows. Bug 508: Fixed concurrent conflicting commits by InventoryManager. --- diff --git a/opendaylight/arphandler/src/main/java/org/opendaylight/controller/arphandler/internal/ArpHandler.java b/opendaylight/arphandler/src/main/java/org/opendaylight/controller/arphandler/internal/ArpHandler.java index 083e2ed0e9..e549182439 100644 --- a/opendaylight/arphandler/src/main/java/org/opendaylight/controller/arphandler/internal/ArpHandler.java +++ b/opendaylight/arphandler/src/main/java/org/opendaylight/controller/arphandler/internal/ArpHandler.java @@ -64,6 +64,31 @@ import org.opendaylight.controller.topologymanager.ITopologyManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +/** + * The ArpHandler offers services to react on ARP requests and replies + * sent by network hosts. Moreover it allows for creating ARP messages + * by the controller itself. + * + * The ARP Handler on ODL doesn't use the requester MAC address in + * order to avoid to have to build a spanning tree where to forward + * ARP Requests. The ARP requests are broadcast packets so in order to + * reach everywhere need to be flooded, when you flood in a network + * that is not a tree (all the networks has some level of redundancy) + * that would create forwarding loops without a spanning tree. Given + * the need is only to send out the ARP requests toward all the hosts + * we actually don't need to implement a flooding mechanism in software + * (which would be expensive) we just send out the ARP request toward + * all the ports that are suspected to be host ports on all the + * switches (from the controller). Now the condition for which a port + * is marked as host port could potentially be incorrect so when the + * controller sends out the ARP Request that could come back to the + * controller and could cause another request not needed. So changing + * the source MAC address of the request to be the one of the controller, + * controller can protect itself from honoring twice the same request. + * This enables an ARP handler resolution, without the need of spanning + * tree and limiting software flooding to the minimum required. + */ + public class ArpHandler implements IHostFinder, IListenDataPacket, ICacheUpdateAware { private static final Logger log = LoggerFactory.getLogger(ArpHandler.class); static final String ARP_EVENT_CACHE_NAME = "arphandler.arpRequestReplyEvent"; diff --git a/opendaylight/commons/protocol-framework/pom.xml b/opendaylight/commons/protocol-framework/pom.xml index a03518235b..650d2dd35b 100644 --- a/opendaylight/commons/protocol-framework/pom.xml +++ b/opendaylight/commons/protocol-framework/pom.xml @@ -25,6 +25,11 @@ 3.0.4 + + ${project.build.directory}/generated-sources/config + ${project.build.directory}/generated-sources/sal + + io.netty @@ -54,6 +59,14 @@ org.slf4j slf4j-api + + org.opendaylight.controller + config-api + + + org.opendaylight.controller + netty-config-api + @@ -64,6 +77,29 @@ junit junit + + org.opendaylight.controller + config-manager + test + + + org.opendaylight.controller + config-manager + ${config.version} + test + test-jar + + + org.opendaylight.controller + config-util + ${config.version} + test + + + org.opendaylight.controller + netty-event-executor-config + test + @@ -90,6 +126,72 @@ + + org.opendaylight.yangtools + yang-maven-plugin + + + + generate-sources + + + + + + org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator + + ${jmxGeneratorPath} + + + urn:opendaylight:params:xml:ns:yang:controller==org.opendaylight.controller.config.yang + + + + + + org.opendaylight.yangtools.maven.sal.api.gen.plugin.CodeGeneratorImpl + + + ${salGeneratorPath} + + + + true + + + + + + org.opendaylight.controller + yang-jmx-generator-plugin + ${config.version} + + + org.opendaylight.yangtools + maven-sal-api-gen-plugin + ${yangtools.version} + + + + + org.codehaus.mojo + build-helper-maven-plugin + + + add-source + generate-sources + + add-source + + + + ${jmxGeneratorPath} + ${salGeneratorPath} + + + + + diff --git a/opendaylight/commons/protocol-framework/src/main/java/org/opendaylight/controller/config/yang/protocol/framework/NeverReconnectStrategyFactoryModule.java b/opendaylight/commons/protocol-framework/src/main/java/org/opendaylight/controller/config/yang/protocol/framework/NeverReconnectStrategyFactoryModule.java new file mode 100644 index 0000000000..a97f65e941 --- /dev/null +++ b/opendaylight/commons/protocol-framework/src/main/java/org/opendaylight/controller/config/yang/protocol/framework/NeverReconnectStrategyFactoryModule.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.config.yang.protocol.framework; + +import io.netty.util.concurrent.EventExecutor; + +import org.opendaylight.controller.config.api.JmxAttributeValidationException; +import org.opendaylight.protocol.framework.NeverReconnectStrategy; +import org.opendaylight.protocol.framework.ReconnectStrategy; +import org.opendaylight.protocol.framework.ReconnectStrategyFactory; + +/** +* +*/ +public final class NeverReconnectStrategyFactoryModule extends org.opendaylight.controller.config.yang.protocol.framework.AbstractNeverReconnectStrategyFactoryModule + { + + public NeverReconnectStrategyFactoryModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { + super(identifier, dependencyResolver); + } + + public NeverReconnectStrategyFactoryModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, + NeverReconnectStrategyFactoryModule oldModule, java.lang.AutoCloseable oldInstance) { + + super(identifier, dependencyResolver, oldModule, oldInstance); + } + + @Override + protected void customValidation(){ + JmxAttributeValidationException.checkNotNull(getTimeout(), "value is not set.", timeoutJmxAttribute); + JmxAttributeValidationException.checkCondition(getTimeout() >= 0, "value " + getTimeout() + " is less than 0", + timeoutJmxAttribute); + } + + @Override + public java.lang.AutoCloseable createInstance() { + return new NeverReconnectStrategyFactoryCloseable(getExecutorDependency(), getTimeout()); + } + + private static final class NeverReconnectStrategyFactoryCloseable implements ReconnectStrategyFactory, AutoCloseable { + + private final EventExecutor executor; + private final int timeout; + + public NeverReconnectStrategyFactoryCloseable(final EventExecutor executor, final int timeout) { + this.executor = executor; + this.timeout = timeout; + } + + @Override + public void close() throws Exception { + // no-op + } + + @Override + public ReconnectStrategy createReconnectStrategy() { + return new NeverReconnectStrategy(this.executor, this.timeout); + } + + } +} diff --git a/opendaylight/commons/protocol-framework/src/main/java/org/opendaylight/controller/config/yang/protocol/framework/NeverReconnectStrategyFactoryModuleFactory.java b/opendaylight/commons/protocol-framework/src/main/java/org/opendaylight/controller/config/yang/protocol/framework/NeverReconnectStrategyFactoryModuleFactory.java new file mode 100644 index 0000000000..bbdc9394cf --- /dev/null +++ b/opendaylight/commons/protocol-framework/src/main/java/org/opendaylight/controller/config/yang/protocol/framework/NeverReconnectStrategyFactoryModuleFactory.java @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.config.yang.protocol.framework; + +/** +* +*/ +public class NeverReconnectStrategyFactoryModuleFactory extends org.opendaylight.controller.config.yang.protocol.framework.AbstractNeverReconnectStrategyFactoryModuleFactory +{ + + +} diff --git a/opendaylight/commons/protocol-framework/src/main/java/org/opendaylight/controller/config/yang/protocol/framework/ReconnectImmediatelyStrategyFactoryModule.java b/opendaylight/commons/protocol-framework/src/main/java/org/opendaylight/controller/config/yang/protocol/framework/ReconnectImmediatelyStrategyFactoryModule.java new file mode 100644 index 0000000000..580a53be94 --- /dev/null +++ b/opendaylight/commons/protocol-framework/src/main/java/org/opendaylight/controller/config/yang/protocol/framework/ReconnectImmediatelyStrategyFactoryModule.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.config.yang.protocol.framework; + +import io.netty.util.concurrent.EventExecutor; + +import org.opendaylight.controller.config.api.JmxAttributeValidationException; +import org.opendaylight.protocol.framework.ReconnectImmediatelyStrategy; +import org.opendaylight.protocol.framework.ReconnectStrategy; +import org.opendaylight.protocol.framework.ReconnectStrategyFactory; + +/** +* +*/ +public final class ReconnectImmediatelyStrategyFactoryModule extends org.opendaylight.controller.config.yang.protocol.framework.AbstractReconnectImmediatelyStrategyFactoryModule + { + + public ReconnectImmediatelyStrategyFactoryModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { + super(identifier, dependencyResolver); + } + + public ReconnectImmediatelyStrategyFactoryModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, + ReconnectImmediatelyStrategyFactoryModule oldModule, java.lang.AutoCloseable oldInstance) { + + super(identifier, dependencyResolver, oldModule, oldInstance); + } + + @Override + protected void customValidation(){ + JmxAttributeValidationException.checkNotNull(getTimeout(), "value is not set.", timeoutJmxAttribute); + JmxAttributeValidationException.checkCondition(getTimeout() >= 0, "value " + getTimeout() + " is less than 0", + timeoutJmxAttribute); + } + + @Override + public java.lang.AutoCloseable createInstance() { + return new ReconnectImmediatelyStrategyFactoryCloseable(getExecutorDependency(), getTimeout()); + } + + private static final class ReconnectImmediatelyStrategyFactoryCloseable implements ReconnectStrategyFactory, AutoCloseable { + + private final EventExecutor executor; + private final int timeout; + + public ReconnectImmediatelyStrategyFactoryCloseable(final EventExecutor executor, final int timeout) { + this.executor = executor; + this.timeout = timeout; + } + + @Override + public void close() throws Exception { + // no-op + } + + @Override + public ReconnectStrategy createReconnectStrategy() { + return new ReconnectImmediatelyStrategy(this.executor, this.timeout); + } + + } +} diff --git a/opendaylight/commons/protocol-framework/src/main/java/org/opendaylight/controller/config/yang/protocol/framework/ReconnectImmediatelyStrategyFactoryModuleFactory.java b/opendaylight/commons/protocol-framework/src/main/java/org/opendaylight/controller/config/yang/protocol/framework/ReconnectImmediatelyStrategyFactoryModuleFactory.java new file mode 100644 index 0000000000..6e72458be8 --- /dev/null +++ b/opendaylight/commons/protocol-framework/src/main/java/org/opendaylight/controller/config/yang/protocol/framework/ReconnectImmediatelyStrategyFactoryModuleFactory.java @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.config.yang.protocol.framework; + +/** +* +*/ +public class ReconnectImmediatelyStrategyFactoryModuleFactory extends org.opendaylight.controller.config.yang.protocol.framework.AbstractReconnectImmediatelyStrategyFactoryModuleFactory +{ + + +} diff --git a/opendaylight/commons/protocol-framework/src/main/java/org/opendaylight/controller/config/yang/protocol/framework/TimedReconnectStrategyFactoryModule.java b/opendaylight/commons/protocol-framework/src/main/java/org/opendaylight/controller/config/yang/protocol/framework/TimedReconnectStrategyFactoryModule.java new file mode 100644 index 0000000000..b8849c7a1d --- /dev/null +++ b/opendaylight/commons/protocol-framework/src/main/java/org/opendaylight/controller/config/yang/protocol/framework/TimedReconnectStrategyFactoryModule.java @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.config.yang.protocol.framework; + +import io.netty.util.concurrent.EventExecutor; + +import org.opendaylight.controller.config.api.JmxAttributeValidationException; +import org.opendaylight.protocol.framework.ReconnectStrategy; +import org.opendaylight.protocol.framework.ReconnectStrategyFactory; +import org.opendaylight.protocol.framework.TimedReconnectStrategy; + +import com.google.common.base.Preconditions; + +/** +* +*/ +public final class TimedReconnectStrategyFactoryModule extends org.opendaylight.controller.config.yang.protocol.framework.AbstractTimedReconnectStrategyFactoryModule + { + + public TimedReconnectStrategyFactoryModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { + super(identifier, dependencyResolver); + } + + public TimedReconnectStrategyFactoryModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, + TimedReconnectStrategyFactoryModule oldModule, java.lang.AutoCloseable oldInstance) { + + super(identifier, dependencyResolver, oldModule, oldInstance); + } + + @Override + protected void customValidation(){ + JmxAttributeValidationException.checkNotNull(getSleepFactor(), "value is not set.", sleepFactorJmxAttribute); + JmxAttributeValidationException.checkCondition(getSleepFactor().doubleValue() >= 1, "value " + getSleepFactor() + + " is less than 1", sleepFactorJmxAttribute); + + JmxAttributeValidationException.checkNotNull(getConnectTime(), "value is not set.", connectTimeJmxAttribute); + JmxAttributeValidationException.checkCondition(getConnectTime() >= 0, "value " + getConnectTime() + + " is less than 0", connectTimeJmxAttribute); + + JmxAttributeValidationException.checkNotNull(getMinSleep(), "value is not set.", minSleepJmxAttribute); + JmxAttributeValidationException.checkCondition(getMaxSleep() == null || getMinSleep() <= getMaxSleep(), + "value " + getMinSleep() + " is greter than MaxSleep " + getMaxSleep(), minSleepJmxAttribute); + } + + @Override + public java.lang.AutoCloseable createInstance() { + return new TimedReconnectStrategyFactoryCloseable(getExecutorDependency(), + getConnectTime(), getMinSleep(), getSleepFactor().doubleValue(), getMaxSleep(), getMaxAttempts(), + getDeadline()); + } + + private static final class TimedReconnectStrategyFactoryCloseable implements ReconnectStrategyFactory, AutoCloseable { + + private final EventExecutor executor; + private final Long deadline, maxAttempts, maxSleep; + private final double sleepFactor; + private final int connectTime; + private final long minSleep; + + public TimedReconnectStrategyFactoryCloseable(final EventExecutor executor, final int connectTime, final long minSleep, final double sleepFactor, + final Long maxSleep, final Long maxAttempts, final Long deadline) { + Preconditions.checkArgument(maxSleep == null || minSleep <= maxSleep); + Preconditions.checkArgument(sleepFactor >= 1); + Preconditions.checkArgument(connectTime >= 0); + this.executor = Preconditions.checkNotNull(executor); + this.deadline = deadline; + this.maxAttempts = maxAttempts; + this.minSleep = minSleep; + this.maxSleep = maxSleep; + this.sleepFactor = sleepFactor; + this.connectTime = connectTime; + } + + @Override + public void close() throws Exception { + // no-op + } + + @Override + public ReconnectStrategy createReconnectStrategy() { + return new TimedReconnectStrategy(this.executor, + this.connectTime, this.minSleep, this.sleepFactor, this.maxSleep, this.maxAttempts, + this.deadline); + } + + } +} diff --git a/opendaylight/commons/protocol-framework/src/main/java/org/opendaylight/controller/config/yang/protocol/framework/TimedReconnectStrategyFactoryModuleFactory.java b/opendaylight/commons/protocol-framework/src/main/java/org/opendaylight/controller/config/yang/protocol/framework/TimedReconnectStrategyFactoryModuleFactory.java new file mode 100644 index 0000000000..7f92e3a408 --- /dev/null +++ b/opendaylight/commons/protocol-framework/src/main/java/org/opendaylight/controller/config/yang/protocol/framework/TimedReconnectStrategyFactoryModuleFactory.java @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.config.yang.protocol.framework; + +/** +* +*/ +public class TimedReconnectStrategyFactoryModuleFactory extends org.opendaylight.controller.config.yang.protocol.framework.AbstractTimedReconnectStrategyFactoryModuleFactory +{ + + +} diff --git a/opendaylight/commons/protocol-framework/src/main/yang/odl-protocol-framework-cfg.yang b/opendaylight/commons/protocol-framework/src/main/yang/odl-protocol-framework-cfg.yang new file mode 100644 index 0000000000..1856369178 --- /dev/null +++ b/opendaylight/commons/protocol-framework/src/main/yang/odl-protocol-framework-cfg.yang @@ -0,0 +1,151 @@ +// vi: set smarttab et sw=4 tabstop=4: +module protocol-framework { + yang-version 1; + namespace "urn:opendaylight:params:xml:ns:yang:controller:protocol:framework"; + prefix "pf"; + + import config { prefix config; revision-date 2013-04-05; } + import netty { prefix netty; revision-date 2013-11-19; } + + organization "Cisco Systems, Inc."; + + contact "Milos Fabian "; + + description + "This module contains the base YANG definitions for + protocol framework. + + Copyright (c)2013 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"; + + revision "2014-03-13" { + description + "Changed reconnect-strategy to reconnect-strategy-factory - represents ReconnectStrategyFactory. + reconnect-strategy-factory modules provides reconnect-strategy-factory service."; + } + + revision "2013-11-09" { + description + "Initial revision"; + } + + identity reconnect-strategy-factory { + description + "Service representing a reconnect strategy factory."; + + base "config:service-type"; + config:java-class "org.opendaylight.protocol.framework.ReconnectStrategyFactory"; + } + + identity never-reconnect-strategy-factory { + base config:module-type; + config:provided-service reconnect-strategy-factory; + config:java-name-prefix NeverReconnectStrategyFactory; + } + + augment "/config:modules/config:module/config:configuration" { + case never-reconnect-strategy-factory { + when "/config:modules/config:module/config:type = 'never-reconnect-strategy-factory'"; + + leaf timeout { + mandatory true; + type int32; + } + + container executor { + uses config:service-ref { + refine type { + mandatory true; + config:required-identity netty:netty-event-executor; + } + } + } + } + } + + identity reconnect-immediately-strategy-factory { + base config:module-type; + config:provided-service reconnect-strategy-factory; + config:java-name-prefix ReconnectImmediatelyStrategyFactory; + } + + augment "/config:modules/config:module/config:configuration" { + case reconnect-immediately-strategy-factory { + when "/config:modules/config:module/config:type = 'reconnect-immediately-strategy-factory'"; + + leaf timeout { + mandatory true; + type int32; + } + + container executor { + uses config:service-ref { + refine type { + mandatory true; + config:required-identity netty:netty-event-executor; + } + } + } + } + } + + identity timed-reconnect-strategy-factory { + base config:module-type; + config:provided-service reconnect-strategy-factory; + config:java-name-prefix TimedReconnectStrategyFactory; + } + + augment "/config:modules/config:module/config:configuration" { + case timed-reconnect-strategy-factory { + when "/config:modules/config:module/config:type = 'timed-reconnect-strategy-factory'"; + + leaf deadline { + type int64; + units "epoch nanoseconds"; + } + + leaf max-attempts { + mandatory true; + type int64; + } + + leaf max-sleep { + mandatory true; + type int64; + units "milliseconds"; + } + + leaf min-sleep { + mandatory true; + type int64; + units "milliseconds"; + } + + leaf sleep-factor { + mandatory true; + type decimal64 { + fraction-digits 2; + } + } + + leaf connect-time { + mandatory true; + type int32; + units "milliseconds"; + } + + container executor { + uses config:service-ref { + refine type { + mandatory true; + config:required-identity netty:netty-event-executor; + } + } + } + } + } +} \ No newline at end of file diff --git a/opendaylight/commons/protocol-framework/src/test/java/org/opendaylight/controller/config/yang/protocol/framework/GlobalEventExecutorUtil.java b/opendaylight/commons/protocol-framework/src/test/java/org/opendaylight/controller/config/yang/protocol/framework/GlobalEventExecutorUtil.java new file mode 100644 index 0000000000..695e36cbef --- /dev/null +++ b/opendaylight/commons/protocol-framework/src/test/java/org/opendaylight/controller/config/yang/protocol/framework/GlobalEventExecutorUtil.java @@ -0,0 +1,37 @@ +/* + * 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.protocol.framework; + +import javax.management.InstanceAlreadyExistsException; +import javax.management.InstanceNotFoundException; +import javax.management.ObjectName; + +import org.opendaylight.controller.config.util.ConfigTransactionJMXClient; +import org.opendaylight.controller.config.yang.netty.eventexecutor.GlobalEventExecutorModuleFactory; + +final class GlobalEventExecutorUtil { + + private GlobalEventExecutorUtil() { + throw new UnsupportedOperationException(); + } + + public static ObjectName create(final ConfigTransactionJMXClient transaction) throws InstanceAlreadyExistsException { + try { + return transaction.lookupConfigBean(GlobalEventExecutorModuleFactory.NAME, + GlobalEventExecutorModuleFactory.SINGLETON_NAME); + } catch (InstanceNotFoundException e) { + try { + return transaction.createModule(GlobalEventExecutorModuleFactory.NAME, + GlobalEventExecutorModuleFactory.SINGLETON_NAME); + } catch (InstanceAlreadyExistsException e1) { + throw new IllegalStateException(e1); + } + } + } + +} diff --git a/opendaylight/commons/protocol-framework/src/test/java/org/opendaylight/controller/config/yang/protocol/framework/NeverReconnectStrategyModuleTest.java b/opendaylight/commons/protocol-framework/src/test/java/org/opendaylight/controller/config/yang/protocol/framework/NeverReconnectStrategyModuleTest.java new file mode 100644 index 0000000000..d77c9aa962 --- /dev/null +++ b/opendaylight/commons/protocol-framework/src/test/java/org/opendaylight/controller/config/yang/protocol/framework/NeverReconnectStrategyModuleTest.java @@ -0,0 +1,108 @@ +/* + * 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.protocol.framework; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import javax.management.InstanceAlreadyExistsException; +import javax.management.ObjectName; + +import org.junit.Before; +import org.junit.Test; +import org.opendaylight.controller.config.api.ConflictingVersionException; +import org.opendaylight.controller.config.api.ValidationException; +import org.opendaylight.controller.config.api.jmx.CommitStatus; +import org.opendaylight.controller.config.manager.impl.AbstractConfigTest; +import org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver; +import org.opendaylight.controller.config.util.ConfigTransactionJMXClient; +import org.opendaylight.controller.config.yang.netty.eventexecutor.GlobalEventExecutorModuleFactory; + +public class NeverReconnectStrategyModuleTest extends AbstractConfigTest { + + private static final String INSTANCE_NAME = "never-reconect-strategy-factory-impl"; + private static final String FACTORY_NAME = NeverReconnectStrategyFactoryModuleFactory.NAME; + + @Before + public void setUp() throws Exception { + super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver( + new NeverReconnectStrategyFactoryModuleFactory(), new GlobalEventExecutorModuleFactory())); + } + + @Test + public void testValidationExceptionTimeoutNotSet() throws Exception { + try { + createInstance(null); + fail(); + } catch (ValidationException e) { + assertTrue(e.getMessage().contains("Timeout value is not set.")); + } + } + + @Test + public void testValidationExceptionTimeoutMinValue() throws Exception { + try { + createInstance(-1); + fail(); + } catch (ValidationException e) { + assertTrue(e.getMessage().contains("is less than 0")); + } + } + + @Test + public void testCreateBean() throws Exception { + final CommitStatus status = createInstance(); + assertBeanCount(1, FACTORY_NAME); + assertStatus(status, 2, 0, 0); + } + + @Test + public void testReusingOldInstance() throws Exception { + createInstance(); + final ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction(); + assertBeanCount(1, FACTORY_NAME); + final CommitStatus status = transaction.commit(); + assertBeanCount(1, FACTORY_NAME); + assertStatus(status, 0, 0, 2); + } + + @Test + public void testReconfigure() throws Exception { + createInstance(); + final ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction(); + assertBeanCount(1, FACTORY_NAME); + final NeverReconnectStrategyFactoryModuleMXBean mxBean = transaction.newMBeanProxy( + transaction.lookupConfigBean(FACTORY_NAME, INSTANCE_NAME), NeverReconnectStrategyFactoryModuleMXBean.class); + mxBean.setTimeout(200); + final CommitStatus status = transaction.commit(); + assertBeanCount(1, FACTORY_NAME); + assertStatus(status, 0, 1, 1); + } + + private CommitStatus createInstance() throws Exception { + return createInstance(500); + } + + private CommitStatus createInstance(final Integer timeout) throws InstanceAlreadyExistsException, + ConflictingVersionException, ValidationException { + final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction(); + createInstance(transaction, timeout); + return transaction.commit(); + } + + private static ObjectName createInstance(final ConfigTransactionJMXClient transaction, final Integer timeout) + throws InstanceAlreadyExistsException { + final ObjectName nameCreated = transaction.createModule(FACTORY_NAME, INSTANCE_NAME); + final NeverReconnectStrategyFactoryModuleMXBean mxBean = transaction.newMBeanProxy(nameCreated, + NeverReconnectStrategyFactoryModuleMXBean.class); + mxBean.setTimeout(timeout); + mxBean.setExecutor(GlobalEventExecutorUtil.create(transaction)); + return nameCreated; + } + +} diff --git a/opendaylight/commons/protocol-framework/src/test/java/org/opendaylight/controller/config/yang/protocol/framework/ReconnectImmediatelyStrategyModuleTest.java b/opendaylight/commons/protocol-framework/src/test/java/org/opendaylight/controller/config/yang/protocol/framework/ReconnectImmediatelyStrategyModuleTest.java new file mode 100644 index 0000000000..24a0e912a3 --- /dev/null +++ b/opendaylight/commons/protocol-framework/src/test/java/org/opendaylight/controller/config/yang/protocol/framework/ReconnectImmediatelyStrategyModuleTest.java @@ -0,0 +1,107 @@ +/* + * 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.protocol.framework; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import javax.management.InstanceAlreadyExistsException; +import javax.management.ObjectName; + +import org.junit.Before; +import org.junit.Test; +import org.opendaylight.controller.config.api.ValidationException; +import org.opendaylight.controller.config.api.jmx.CommitStatus; +import org.opendaylight.controller.config.manager.impl.AbstractConfigTest; +import org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver; +import org.opendaylight.controller.config.util.ConfigTransactionJMXClient; +import org.opendaylight.controller.config.yang.netty.eventexecutor.GlobalEventExecutorModuleFactory; + +public class ReconnectImmediatelyStrategyModuleTest extends AbstractConfigTest { + + private static final String INSTANCE_NAME = "reconnect-immediately-strategy-factory-impl"; + private static final String FACTORY_NAME = ReconnectImmediatelyStrategyFactoryModuleFactory.NAME; + + @Before + public void setUp() throws Exception { + super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver( + new ReconnectImmediatelyStrategyFactoryModuleFactory(), new GlobalEventExecutorModuleFactory())); + } + + @Test + public void testValidationExceptionTimeoutNotSet() throws Exception { + try { + createInstance(null); + fail(); + } catch (ValidationException e) { + assertTrue(e.getMessage().contains("Timeout value is not set.")); + } + } + + @Test + public void testValidationExceptionTimeoutMinValue() throws Exception { + try { + createInstance(-1); + fail(); + } catch (ValidationException e) { + assertTrue(e.getMessage().contains("is less than 0")); + } + } + + @Test + public void testCreateBean() throws Exception { + final CommitStatus status = createInstance(); + assertBeanCount(1, FACTORY_NAME); + assertStatus(status, 2, 0, 0); + } + + @Test + public void testReusingOldInstance() throws Exception { + createInstance(); + final ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction(); + assertBeanCount(1, FACTORY_NAME); + final CommitStatus status = transaction.commit(); + assertBeanCount(1, FACTORY_NAME); + assertStatus(status, 0, 0, 2); + } + + @Test + public void testReconfigure() throws Exception { + createInstance(); + final ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction(); + assertBeanCount(1, FACTORY_NAME); + final ReconnectImmediatelyStrategyFactoryModuleMXBean mxBean = transaction.newMBeanProxy( + transaction.lookupConfigBean(FACTORY_NAME, INSTANCE_NAME), + ReconnectImmediatelyStrategyFactoryModuleMXBean.class); + mxBean.setTimeout(200); + final CommitStatus status = transaction.commit(); + assertBeanCount(1, FACTORY_NAME); + assertStatus(status, 0, 1, 1); + } + + private CommitStatus createInstance() throws Exception { + return createInstance(500); + } + + private CommitStatus createInstance(final Integer timeout) throws Exception { + final ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction(); + createInstance(transaction, timeout); + return transaction.commit(); + } + + private static ObjectName createInstance(final ConfigTransactionJMXClient transaction, final Integer timeout) + throws InstanceAlreadyExistsException { + final ObjectName nameCreated = transaction.createModule(FACTORY_NAME, INSTANCE_NAME); + final ReconnectImmediatelyStrategyFactoryModuleMXBean mxBean = transaction.newMBeanProxy(nameCreated, + ReconnectImmediatelyStrategyFactoryModuleMXBean.class); + mxBean.setTimeout(timeout); + mxBean.setExecutor(GlobalEventExecutorUtil.create(transaction)); + return nameCreated; + } + +} diff --git a/opendaylight/commons/protocol-framework/src/test/java/org/opendaylight/controller/config/yang/protocol/framework/TimedReconnectStrategyModuleTest.java b/opendaylight/commons/protocol-framework/src/test/java/org/opendaylight/controller/config/yang/protocol/framework/TimedReconnectStrategyModuleTest.java new file mode 100644 index 0000000000..d051a00a12 --- /dev/null +++ b/opendaylight/commons/protocol-framework/src/test/java/org/opendaylight/controller/config/yang/protocol/framework/TimedReconnectStrategyModuleTest.java @@ -0,0 +1,166 @@ +/* + * 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.protocol.framework; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.math.BigDecimal; + +import javax.management.InstanceAlreadyExistsException; +import javax.management.ObjectName; + +import org.junit.Before; +import org.junit.Test; +import org.opendaylight.controller.config.api.ConflictingVersionException; +import org.opendaylight.controller.config.api.ValidationException; +import org.opendaylight.controller.config.api.jmx.CommitStatus; +import org.opendaylight.controller.config.manager.impl.AbstractConfigTest; +import org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver; +import org.opendaylight.controller.config.util.ConfigTransactionJMXClient; +import org.opendaylight.controller.config.yang.netty.eventexecutor.GlobalEventExecutorModuleFactory; + +public class TimedReconnectStrategyModuleTest extends AbstractConfigTest { + + private static final String INSTANCE_NAME = "timed-reconect-stategy-facotry-impl"; + private static final String FACTORY_NAME = TimedReconnectStrategyFactoryModuleFactory.NAME; + + @Before + public void setUp() throws Exception { + super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver( + new TimedReconnectStrategyFactoryModuleFactory(), new GlobalEventExecutorModuleFactory())); + } + + @Test + public void testValidationExceptionSleepFactorNotSet() throws Exception { + try { + createInstance(500, 100L, null, 500L, 10L, 10000L); + fail(); + } catch (ValidationException e) { + assertTrue(e.getMessage().contains("SleepFactor value is not set.")); + } + } + + @Test + public void testValidationExceptionSleepFactorMinValue() throws Exception { + try { + createInstance(500, 100L, new BigDecimal(0.5), 500L, 10L, 10000L); + fail(); + } catch (ValidationException e) { + assertTrue(e.getMessage().contains("is less than 1")); + } + } + + @Test + public void testValidationExceptionConnectTimeNotSet() throws Exception { + try { + createInstance(null, 100L, new BigDecimal(1.0), 500L, 10L, 10000L); + fail(); + } catch (ValidationException e) { + assertTrue(e.getMessage().contains("ConnectTime value is not set.")); + } + } + + @Test + public void testValidationExceptionConnectTimeMinValue() throws Exception { + try { + createInstance(-1, 100L, new BigDecimal(1.0), 500L, 10L, 10000L); + fail(); + } catch (ValidationException e) { + assertTrue(e.getMessage().contains("is less than 0")); + } + } + + @Test + public void testValidationExceptionMinSleepNotSet() throws Exception { + try { + createInstance(100, null, new BigDecimal(1.0), 100L, 10L, 10000L); + fail(); + } catch (ValidationException e) { + assertTrue(e.getMessage().contains("MinSleep value is not set.")); + } + } + + @Test + public void testValidationExceptionMaxSleep() throws Exception { + try { + createInstance(100, 300L, new BigDecimal(1.0), 100L, 10L, 10000L); + fail(); + } catch (ValidationException e) { + assertTrue(e.getMessage().contains("is greter than MaxSleep")); + } + } + + @Test + public void testCreateBean() throws Exception { + final CommitStatus status = createInstance(); + assertBeanCount(1, FACTORY_NAME); + assertStatus(status, 2, 0, 0); + } + + @Test + public void testReusingOldInstance() throws Exception { + createInstance(); + final ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction(); + assertBeanCount(1, FACTORY_NAME); + final CommitStatus status = transaction.commit(); + assertBeanCount(1, FACTORY_NAME); + assertStatus(status, 0, 0, 2); + } + + @Test + public void testReconfigure() throws Exception { + createInstance(); + final ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction(); + assertBeanCount(1, FACTORY_NAME); + final TimedReconnectStrategyFactoryModuleMXBean mxBean = transaction.newMBeanProxy( + transaction.lookupConfigBean(FACTORY_NAME, INSTANCE_NAME), TimedReconnectStrategyFactoryModuleMXBean.class); + assertEquals(mxBean.getMinSleep(), new Long(100)); + mxBean.setMinSleep(200L); + assertEquals(mxBean.getMinSleep(), new Long(200)); + final CommitStatus status = transaction.commit(); + assertBeanCount(1, FACTORY_NAME); + assertStatus(status, 0, 1, 1); + + } + + private CommitStatus createInstance() throws Exception { + return createInstance(500, 100L, new BigDecimal(1.0), 500L, 10L, 10000L); + } + + private CommitStatus createInstance(final Integer connectTime, final Long minSleep, final BigDecimal sleepFactor, + final Long maxSleep, final Long maxAttempts, final Long deadline) throws ConflictingVersionException, + ValidationException, InstanceAlreadyExistsException { + ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction(); + createInstance(transaction, INSTANCE_NAME, connectTime, minSleep, sleepFactor, maxSleep, maxAttempts, deadline); + return transaction.commit(); + } + + public static ObjectName createInstance(final ConfigTransactionJMXClient transaction, final String InstanceName) + throws Exception { + return createInstance(transaction, InstanceName, 500, 100L, new BigDecimal(1.0), 500L, 10L, 10000L); + } + + private static ObjectName createInstance(final ConfigTransactionJMXClient transaction, final String instanceName, + final Integer connectTime, final Long minSleep, final BigDecimal sleepFactor, final Long maxSleep, + final Long maxAttempts, final Long deadline) throws InstanceAlreadyExistsException { + final ObjectName nameCreated = transaction.createModule(FACTORY_NAME, instanceName); + final TimedReconnectStrategyFactoryModuleMXBean mxBean = transaction.newMBeanProxy(nameCreated, + TimedReconnectStrategyFactoryModuleMXBean.class); + mxBean.setConnectTime(connectTime); + mxBean.setDeadline(deadline); + mxBean.setMaxAttempts(maxAttempts); + mxBean.setMaxSleep(maxSleep); + mxBean.setMinSleep(minSleep); + mxBean.setSleepFactor(sleepFactor); + mxBean.setExecutor(GlobalEventExecutorUtil.create(transaction)); + return nameCreated; + } + +} diff --git a/opendaylight/md-sal/sal-binding-it/src/main/java/org/opendaylight/controller/test/sal/binding/it/TestHelper.java b/opendaylight/md-sal/sal-binding-it/src/main/java/org/opendaylight/controller/test/sal/binding/it/TestHelper.java index ba639ad7c2..ccfe86e7b1 100644 --- a/opendaylight/md-sal/sal-binding-it/src/main/java/org/opendaylight/controller/test/sal/binding/it/TestHelper.java +++ b/opendaylight/md-sal/sal-binding-it/src/main/java/org/opendaylight/controller/test/sal/binding/it/TestHelper.java @@ -52,7 +52,6 @@ public class TestHelper { mavenBundle("io.netty", "netty-codec").versionAsInProject(), // mavenBundle("io.netty", "netty-transport").versionAsInProject(), // - mavenBundle(CONTROLLER, "protocol-framework").versionAsInProject(), // mavenBundle(CONTROLLER, "config-manager").versionAsInProject(), // // mavenBundle("commons-io", "commons-io").versionAsInProject(), // mavenBundle(CONTROLLER, "config-manager").versionAsInProject(), // @@ -64,6 +63,9 @@ public class TestHelper { mavenBundle(CONTROLLER, "ietf-netconf-monitoring-extension").versionAsInProject(), // mavenBundle(CONTROLLER, "netconf-monitoring").versionAsInProject(), // + mavenBundle(CONTROLLER, "netty-config-api"), // + mavenBundle(CONTROLLER, "protocol-framework").versionAsInProject(), // + mavenBundle(CONTROLLER, "netconf-client").versionAsInProject(), // mavenBundle(CONTROLLER, "netconf-util").versionAsInProject(), // mavenBundle(CONTROLLER + ".thirdparty", "ganymed").versionAsInProject(), //