import java.util.ArrayList;
import java.util.List;
+import org.opendaylight.protocol.bgp.parser.spi.AbstractBGPExtensionProviderActivator;
import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
-import org.opendaylight.protocol.bgp.parser.spi.pojo.AbstractBGPExtensionProviderActivator;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.LinkstateAddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.LinkstateSubsequentAddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.MplsLabeledVpnSubsequentAddressFamily;
import org.opendaylight.protocol.bgp.parser.impl.message.update.NextHopAttributeParser;
import org.opendaylight.protocol.bgp.parser.impl.message.update.OriginAttributeParser;
import org.opendaylight.protocol.bgp.parser.impl.message.update.OriginatorIdAttributeParser;
+import org.opendaylight.protocol.bgp.parser.spi.AbstractBGPExtensionProviderActivator;
import org.opendaylight.protocol.bgp.parser.spi.AddressFamilyRegistry;
import org.opendaylight.protocol.bgp.parser.spi.AttributeRegistry;
import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
import org.opendaylight.protocol.bgp.parser.spi.NlriRegistry;
import org.opendaylight.protocol.bgp.parser.spi.ParameterRegistry;
import org.opendaylight.protocol.bgp.parser.spi.SubsequentAddressFamilyRegistry;
-import org.opendaylight.protocol.bgp.parser.spi.pojo.AbstractBGPExtensionProviderActivator;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Keepalive;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Notify;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Open;
* 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.protocol.bgp.parser.spi.pojo;
+package org.opendaylight.protocol.bgp.parser.spi;
import java.util.List;
import javax.annotation.concurrent.GuardedBy;
-import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderActivator;
-import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* 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.protocol.bgp.parser.spi.pojo;
+package org.opendaylight.protocol.bgp.parser.spi;
import java.util.Arrays;
import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
import org.opendaylight.protocol.bgp.parser.BGPError;
import org.opendaylight.protocol.bgp.parser.BGPParsingException;
-import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
-import org.opendaylight.protocol.bgp.parser.spi.MessageUtil;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yangtools.yang.binding.Notification;
import org.slf4j.Logger;
import com.google.common.primitives.UnsignedBytes;
-abstract class AbstractMessageRegistry implements MessageRegistry {
+public abstract class AbstractMessageRegistry implements MessageRegistry {
private static final Logger LOG = LoggerFactory.getLogger(AbstractMessageRegistry.class);
private static final byte[] MARKER;
package org.opendaylight.protocol.bgp.parser.spi.pojo;
import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
+import org.opendaylight.protocol.bgp.parser.spi.AbstractMessageRegistry;
import org.opendaylight.protocol.bgp.parser.spi.MessageParser;
import org.opendaylight.protocol.bgp.parser.spi.MessageSerializer;
import org.opendaylight.protocol.concepts.HandlerRegistry;
+++ /dev/null
-/*
- * 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.reconnectstrategy.util;
-
-import io.netty.util.concurrent.Future;
-
-import org.opendaylight.protocol.framework.ReconnectStrategy;
-
-public final class ReconnectStrategyCloseable implements ReconnectStrategy,
-AutoCloseable {
-
- private final ReconnectStrategy inner;
-
- public ReconnectStrategyCloseable(final ReconnectStrategy inner) {
- this.inner = inner;
- }
-
- @Override
- public void close() {
-
- }
-
- @Override
- public int getConnectTimeout() throws Exception {
- return this.inner.getConnectTimeout();
- }
-
- @Override
- public Future<Void> scheduleReconnect(final Throwable cause) {
- return this.inner.scheduleReconnect(cause);
- }
-
- @Override
- public void reconnectSuccessful() {
- this.inner.reconnectSuccessful();
- }
-}
import org.opendaylight.controller.config.api.JmxAttributeValidationException;
import org.opendaylight.protocol.bgp.rib.impl.RIBImpl;
-import org.opendaylight.protocol.framework.ReconnectStrategy;
-import org.opendaylight.protocol.framework.ReconnectStrategyFactory;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
/**
JmxAttributeValidationException.checkNotNull(getExtensions(), "is not set.", this.extensionsJmxAttribute);
JmxAttributeValidationException.checkNotNull(getRibId(), "is not set.", this.ribIdJmxAttribute);
JmxAttributeValidationException.checkNotNull(getLocalAs(), "is not set.", this.localAsJmxAttribute);
- JmxAttributeValidationException.checkNotNull(getBgpId(), "is not set.", this.localAsJmxAttribute);
+ JmxAttributeValidationException.checkNotNull(getBgpId(), "is not set.", this.bgpIdJmxAttribute);
JmxAttributeValidationException.checkNotNull(getTcpReconnectStrategy(), "is not set.", this.tcpReconnectStrategyJmxAttribute);
JmxAttributeValidationException.checkNotNull(getSessionReconnectStrategy(), "is not set.", this.sessionReconnectStrategyJmxAttribute);
- JmxAttributeValidationException.checkNotNull(getLocalTable(), "is not set.", this.sessionReconnectStrategyJmxAttribute);
+ JmxAttributeValidationException.checkNotNull(getLocalTable(), "is not set.", this.localTableJmxAttribute);
}
@Override
public java.lang.AutoCloseable createInstance() {
return new RIBImpl(getRibId(), new AsNumber(getLocalAs()), getBgpId(), getExtensionsDependency(),
- getBgpDispatcherDependency(), new ReconnectStrategyFactory() {
- @Override
- public ReconnectStrategy createReconnectStrategy() {
- return getTcpReconnectStrategyDependency();
- }
- }, getSessionReconnectStrategyDependency(), getDataProviderDependency(), getLocalTableDependency());
+ getBgpDispatcherDependency(), getTcpReconnectStrategyDependency()
+ , getSessionReconnectStrategyDependency(), getDataProviderDependency(), getLocalTableDependency());
}
}
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
/**
-* Generated file
+ * Generated file
-* Generated from: yang module name: reconnect-strategy yang module local name: never-reconnect-strategy
-* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
-* Generated at: Tue Nov 12 13:27:18 CET 2013
-*
-* Do not modify this file unless it is present under src/main directory
-*/
+ * Generated from: yang module name: reconnect-strategy yang module local name: never-reconnect-strategy
+ * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
+ * Generated at: Tue Nov 12 13:27:18 CET 2013
+ *
+ * Do not modify this file unless it is present under src/main directory
+ */
package org.opendaylight.controller.config.yang.reconnectstrategy;
+import io.netty.util.concurrent.EventExecutor;
+
import org.opendaylight.controller.config.api.JmxAttributeValidationException;
-import org.opendaylight.controller.config.reconnectstrategy.util.ReconnectStrategyCloseable;
import org.opendaylight.protocol.framework.NeverReconnectStrategy;
import org.opendaylight.protocol.framework.ReconnectStrategy;
+import org.opendaylight.protocol.framework.ReconnectStrategyFactory;
/**
*
*/
-public final class NeverReconnectStrategyModule extends org.opendaylight.controller.config.yang.reconnectstrategy.AbstractNeverReconnectStrategyModule
-{
+public final class NeverReconnectStrategyModule extends
+ org.opendaylight.controller.config.yang.reconnectstrategy.AbstractNeverReconnectStrategyModule {
- public NeverReconnectStrategyModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
+ public NeverReconnectStrategyModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
+ org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
super(identifier, dependencyResolver);
}
- public NeverReconnectStrategyModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, NeverReconnectStrategyModule oldModule, java.lang.AutoCloseable oldInstance) {
+ public NeverReconnectStrategyModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
+ org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
+ NeverReconnectStrategyModule oldModule, java.lang.AutoCloseable oldInstance) {
super(identifier, dependencyResolver, oldModule, oldInstance);
}
@Override
- public void validate(){
- super.validate();
- JmxAttributeValidationException.checkNotNull(getTimeout(),
- "value is not set.", timeoutJmxAttribute);
- JmxAttributeValidationException.checkCondition(getTimeout() >= 0,
- "value " + getTimeout() + " is less than 0",
- timeoutJmxAttribute);
+ public void validate() {
+ super.validate();
+ 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() {
- ReconnectStrategy reconnectStrategy = new NeverReconnectStrategy(getExecutorDependency(), getTimeout());
- return new ReconnectStrategyCloseable(reconnectStrategy);
- }
+ return new NeverReconnectStrategyFactory(getExecutorDependency(), getTimeout());
+ }
+
+ private static final class NeverReconnectStrategyFactory implements ReconnectStrategyFactory, AutoCloseable {
+
+ private final EventExecutor executor;
+ private final int timeout;
+
+ public NeverReconnectStrategyFactory(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);
+ }
+
+ }
}
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
/**
-* Generated file
+ * Generated file
-* Generated from: yang module name: reconnect-strategy yang module local name: reconnect-immediately-strategy
-* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
-* Generated at: Tue Nov 12 13:27:18 CET 2013
-*
-* Do not modify this file unless it is present under src/main directory
-*/
+ * Generated from: yang module name: reconnect-strategy yang module local name: reconnect-immediately-strategy
+ * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
+ * Generated at: Tue Nov 12 13:27:18 CET 2013
+ *
+ * Do not modify this file unless it is present under src/main directory
+ */
package org.opendaylight.controller.config.yang.reconnectstrategy;
+import io.netty.util.concurrent.EventExecutor;
+
import org.opendaylight.controller.config.api.JmxAttributeValidationException;
-import org.opendaylight.controller.config.reconnectstrategy.util.ReconnectStrategyCloseable;
import org.opendaylight.protocol.framework.ReconnectImmediatelyStrategy;
import org.opendaylight.protocol.framework.ReconnectStrategy;
+import org.opendaylight.protocol.framework.ReconnectStrategyFactory;
/**
*
*/
-public final class ReconnectImmediatelyStrategyModule extends org.opendaylight.controller.config.yang.reconnectstrategy.AbstractReconnectImmediatelyStrategyModule
-{
+public final class ReconnectImmediatelyStrategyModule extends
+ org.opendaylight.controller.config.yang.reconnectstrategy.AbstractReconnectImmediatelyStrategyModule {
- public ReconnectImmediatelyStrategyModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
+ public ReconnectImmediatelyStrategyModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
+ org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
super(identifier, dependencyResolver);
}
- public ReconnectImmediatelyStrategyModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, ReconnectImmediatelyStrategyModule oldModule, java.lang.AutoCloseable oldInstance) {
+ public ReconnectImmediatelyStrategyModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
+ org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
+ ReconnectImmediatelyStrategyModule oldModule, java.lang.AutoCloseable oldInstance) {
super(identifier, dependencyResolver, oldModule, oldInstance);
}
@Override
- public void validate(){
- super.validate();
- JmxAttributeValidationException.checkNotNull(getTimeout(),
- "value is not set.", timeoutJmxAttribute);
- JmxAttributeValidationException.checkCondition(getTimeout() >= 0,
- "value " + getTimeout() + " is less than 0",
- timeoutJmxAttribute);
+ public void validate() {
+ super.validate();
+ 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() {
- final ReconnectStrategy reconnectStrategy = new ReconnectImmediatelyStrategy(getExecutorDependency(), getTimeout());
- return new ReconnectStrategyCloseable(reconnectStrategy);
- }
+ return new ReconnectImmediatelyStrategyFactory(getExecutorDependency(), getTimeout());
+ }
+
+ private static final class ReconnectImmediatelyStrategyFactory implements ReconnectStrategyFactory, AutoCloseable {
+
+ private final EventExecutor executor;
+ private final int timeout;
+
+ public ReconnectImmediatelyStrategyFactory(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);
+ }
+
+ }
}
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
/**
-* Generated file
+ * Generated file
-* Generated from: yang module name: reconnect-strategy yang module local name: timed-reconnect-strategy
-* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
-* Generated at: Tue Nov 12 13:27:18 CET 2013
-*
-* Do not modify this file unless it is present under src/main directory
-*/
+ * Generated from: yang module name: reconnect-strategy yang module local name: timed-reconnect-strategy
+ * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
+ * Generated at: Tue Nov 12 13:27:18 CET 2013
+ *
+ * Do not modify this file unless it is present under src/main directory
+ */
package org.opendaylight.controller.config.yang.reconnectstrategy;
+import io.netty.util.concurrent.EventExecutor;
+
import org.opendaylight.controller.config.api.JmxAttributeValidationException;
-import org.opendaylight.controller.config.reconnectstrategy.util.ReconnectStrategyCloseable;
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 TimedReconnectStrategyModule extends org.opendaylight.controller.config.yang.reconnectstrategy.AbstractTimedReconnectStrategyModule
-{
+public final class TimedReconnectStrategyModule extends
+ org.opendaylight.controller.config.yang.reconnectstrategy.AbstractTimedReconnectStrategyModule {
- public TimedReconnectStrategyModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
+ public TimedReconnectStrategyModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
+ org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
super(identifier, dependencyResolver);
}
- public TimedReconnectStrategyModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, TimedReconnectStrategyModule oldModule, java.lang.AutoCloseable oldInstance) {
+ public TimedReconnectStrategyModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
+ org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
+ TimedReconnectStrategyModule oldModule, java.lang.AutoCloseable oldInstance) {
super(identifier, dependencyResolver, oldModule, oldInstance);
}
@Override
- public void validate(){
- super.validate();
- 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);
+ public void validate() {
+ super.validate();
+ 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() {
- ReconnectStrategy reconnectStrategy = new TimedReconnectStrategy(
- getExecutorDependency(), getConnectTime(), getMinSleep(),
- getSleepFactor().doubleValue(), getMaxSleep(),
- getMaxAttempts(), getDeadline());
- return new ReconnectStrategyCloseable(reconnectStrategy);
- }
+ return new TimedReconnectStrategyFactory(getExecutorDependency(),
+ getConnectTime(), getMinSleep(), getSleepFactor().doubleValue(), getMaxSleep(), getMaxAttempts(),
+ getDeadline());
+ }
+
+ private static final class TimedReconnectStrategyFactory 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 TimedReconnectStrategyFactory(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);
+ }
+
+ }
}
"Service representing a reconnect strategy.";
base "config:service-type";
- config:java-class "org.opendaylight.protocol.framework.ReconnectStrategy";
+ config:java-class "org.opendaylight.protocol.framework.ReconnectStrategyFactory";
}
identity never-reconnect-strategy {
*/
package org.opendaylight.controller.config.yang.bgp.reconnectstrategy;
-import org.opendaylight.controller.config.util.ConfigTransactionJMXClient;
-import org.opendaylight.controller.config.yang.netty.eventexecutor.GlobalEventExecutorModuleFactory;
-
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;
+
public class GlobalEventExecutorUtil {
- public static ObjectName createOrGetInstance(
- final ConfigTransactionJMXClient transaction)
- throws InstanceAlreadyExistsException {
- ObjectName on;
+ public static ObjectName create(final ConfigTransactionJMXClient transaction) throws InstanceAlreadyExistsException {
try {
- on = transaction.lookupConfigBean(GlobalEventExecutorModuleFactory.NAME, GlobalEventExecutorModuleFactory.SINGLETON_NAME);
+ return transaction.lookupConfigBean(GlobalEventExecutorModuleFactory.NAME,
+ GlobalEventExecutorModuleFactory.SINGLETON_NAME);
} catch (InstanceNotFoundException e) {
- on = transaction.createModule(GlobalEventExecutorModuleFactory.NAME, GlobalEventExecutorModuleFactory.SINGLETON_NAME);
+ try {
+ return transaction.createModule(GlobalEventExecutorModuleFactory.NAME,
+ GlobalEventExecutorModuleFactory.SINGLETON_NAME);
+ } catch (InstanceAlreadyExistsException e1) {
+ throw new IllegalStateException(e1);
+ }
}
- return on;
- }
+ }
}
*/
package org.opendaylight.controller.config.yang.bgp.reconnectstrategy;
+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.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver;
import org.opendaylight.controller.config.util.ConfigTransactionJMXClient;
import org.opendaylight.controller.config.yang.netty.eventexecutor.GlobalEventExecutorModuleFactory;
-import org.opendaylight.controller.config.yang.reconnectstrategy.AbstractNeverReconnectStrategyModuleFactory;
import org.opendaylight.controller.config.yang.reconnectstrategy.NeverReconnectStrategyModuleFactory;
import org.opendaylight.controller.config.yang.reconnectstrategy.NeverReconnectStrategyModuleMXBean;
-import javax.management.InstanceAlreadyExistsException;
-import javax.management.InstanceNotFoundException;
-import javax.management.ObjectName;
-
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
public class NeverReconnectStrategyModuleTest extends AbstractConfigTest {
- private final String instanceName = GlobalEventExecutorModuleFactory.SINGLETON_NAME;
+ private static final String INSTANCE_NAME = "never-recconect-strategy-impl";
+ private static final String FACTORY_NAME = NeverReconnectStrategyModuleFactory.NAME;
+
+ @Before
+ public void setUp() throws Exception {
+ super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(
+ new NeverReconnectStrategyModuleFactory(), new GlobalEventExecutorModuleFactory()));
+ }
- private NeverReconnectStrategyModuleFactory factory;
-
- private GlobalEventExecutorModuleFactory executorFactory;
+ @Test
+ public void testValidationExceptionTimeoutNotSet() throws Exception {
+ try {
+ createInstance(null);
+ fail();
+ } catch (ValidationException e) {
+ assertTrue(e.getMessage().contains("Timeout value is not set."));
+ }
+ }
- @Before
- public void setUp() throws Exception {
- this.factory = new NeverReconnectStrategyModuleFactory();
- this.executorFactory = new GlobalEventExecutorModuleFactory();
- super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(
- factory, executorFactory));
- }
+ @Test
+ public void testValidationExceptionTimeoutMinValue() throws Exception {
+ try {
+ createInstance(-1);
+ fail();
+ } catch (ValidationException e) {
+ assertTrue(e.getMessage().contains("is less than 0"));
+ }
+ }
- @Test
- public void testValidationExceptionTimeoutNotSet()
- throws InstanceAlreadyExistsException {
- try {
- ConfigTransactionJMXClient transaction = configRegistryClient
- .createTransaction();
- createInstance(transaction, this.factory.getImplementationName(), instanceName, null);
- transaction.validateConfig();
- fail();
- } catch (ValidationException e) {
- assertTrue(e.getMessage().contains("Timeout value is not set."));
- }
- }
+ @Test
+ public void testCreateBean() throws Exception {
+ final CommitStatus status = createInstance();
+ assertBeanCount(1, FACTORY_NAME);
+ assertStatus(status, 2, 0, 0);
+ }
- @Test
- public void testValidationExceptionTimeoutMinValue()
- throws InstanceAlreadyExistsException {
- try {
- ConfigTransactionJMXClient transaction = configRegistryClient
- .createTransaction();
- createInstance(transaction, this.factory.getImplementationName(), instanceName, -1);
- transaction.validateConfig();
- fail();
- } catch (ValidationException e) {
- assertTrue(e.getMessage().contains("is less than 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 testCreateBean() throws Exception {
- ConfigTransactionJMXClient transaction = configRegistryClient
- .createTransaction();
- createInstance(transaction, this.factory.getImplementationName(), instanceName, 500);
- transaction.validateConfig();
- CommitStatus status = transaction.commit();
- assertBeanCount(1, factory.getImplementationName());
- assertStatus(status, 2, 0, 0);
- }
+ @Test
+ public void testReconfigure() throws Exception {
+ createInstance();
+ final ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
+ assertBeanCount(1, FACTORY_NAME);
+ final NeverReconnectStrategyModuleMXBean mxBean = transaction.newMBeanProxy(
+ transaction.lookupConfigBean(FACTORY_NAME, INSTANCE_NAME), NeverReconnectStrategyModuleMXBean.class);
+ mxBean.setTimeout(200);
+ final CommitStatus status = transaction.commit();
+ assertBeanCount(1, FACTORY_NAME);
+ assertStatus(status, 0, 1, 1);
+ }
- @Test
- public void testReusingOldInstance() throws InstanceAlreadyExistsException,
- ConflictingVersionException, ValidationException {
- ConfigTransactionJMXClient transaction = configRegistryClient
- .createTransaction();
- createInstance(transaction, this.factory.getImplementationName(), instanceName, 500);
- transaction.commit();
- transaction = configRegistryClient.createTransaction();
- assertBeanCount(1, factory.getImplementationName());
- CommitStatus status = transaction.commit();
- assertBeanCount(1, factory.getImplementationName());
- assertStatus(status, 0, 0, 2);
- }
+ private CommitStatus createInstance() throws Exception {
+ return createInstance(500);
+ }
- @Test
- public void testReconfigure() throws InstanceAlreadyExistsException,
- ConflictingVersionException, ValidationException,
- InstanceNotFoundException {
- ConfigTransactionJMXClient transaction = configRegistryClient
- .createTransaction();
- createInstance(transaction, this.factory.getImplementationName(), instanceName, 500);
- transaction.commit();
- transaction = configRegistryClient.createTransaction();
- assertBeanCount(1, factory.getImplementationName());
- NeverReconnectStrategyModuleMXBean mxBean = transaction
- .newMBeanProxy(transaction.lookupConfigBean(
- AbstractNeverReconnectStrategyModuleFactory.NAME,
- instanceName), NeverReconnectStrategyModuleMXBean.class);
- mxBean.setTimeout(200);
- CommitStatus status = transaction.commit();
- assertBeanCount(1, factory.getImplementationName());
- assertStatus(status, 0, 1, 1);
- }
+ private CommitStatus createInstance(final Integer timeout) throws InstanceAlreadyExistsException,
+ ConflictingVersionException, ValidationException {
+ final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
+ createInstance(transaction, timeout);
+ return transaction.commit();
+ }
- public static ObjectName createInstance(
- final ConfigTransactionJMXClient transaction, final String moduleName,
- final String instanceName, final Integer timeout) throws InstanceAlreadyExistsException {
- ObjectName nameCreated = transaction.createModule(
- moduleName, instanceName);
- NeverReconnectStrategyModuleMXBean mxBean = transaction.newMBeanProxy(
- nameCreated, NeverReconnectStrategyModuleMXBean.class);
- mxBean.setTimeout(timeout);
- mxBean.setExecutor(GlobalEventExecutorUtil.createOrGetInstance(transaction));
- return nameCreated;
- }
+ private static ObjectName createInstance(final ConfigTransactionJMXClient transaction, final Integer timeout)
+ throws InstanceAlreadyExistsException {
+ final ObjectName nameCreated = transaction.createModule(FACTORY_NAME, INSTANCE_NAME);
+ final NeverReconnectStrategyModuleMXBean mxBean = transaction.newMBeanProxy(nameCreated,
+ NeverReconnectStrategyModuleMXBean.class);
+ mxBean.setTimeout(timeout);
+ mxBean.setExecutor(GlobalEventExecutorUtil.create(transaction));
+ return nameCreated;
+ }
}
*/
package org.opendaylight.controller.config.yang.bgp.reconnectstrategy;
+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;
-import org.opendaylight.controller.config.yang.reconnectstrategy.AbstractReconnectImmediatelyStrategyModuleFactory;
import org.opendaylight.controller.config.yang.reconnectstrategy.ReconnectImmediatelyStrategyModuleFactory;
import org.opendaylight.controller.config.yang.reconnectstrategy.ReconnectImmediatelyStrategyModuleMXBean;
-import javax.management.InstanceAlreadyExistsException;
-import javax.management.InstanceNotFoundException;
-import javax.management.ObjectName;
-
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
public class ReconnectImmediatelyStrategyModuleTest extends AbstractConfigTest {
- private final String instanceName = GlobalEventExecutorModuleFactory.SINGLETON_NAME;
+ private static final String INSTANCE_NAME = "reconnect-immediately-strategy-impl";
+ private static final String FACTORY_NAME = ReconnectImmediatelyStrategyModuleFactory.NAME;
- private ReconnectImmediatelyStrategyModuleFactory factory;
+ @Before
+ public void setUp() throws Exception {
+ super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(
+ new ReconnectImmediatelyStrategyModuleFactory(), new GlobalEventExecutorModuleFactory()));
+ }
- private GlobalEventExecutorModuleFactory executorFactory;
+ @Test
+ public void testValidationExceptionTimeoutNotSet() throws Exception {
+ try {
+ createInstance(null);
+ fail();
+ } catch (ValidationException e) {
+ assertTrue(e.getMessage().contains("Timeout value is not set."));
+ }
+ }
- @Before
- public void setUp() throws Exception {
- this.factory = new ReconnectImmediatelyStrategyModuleFactory();
- this.executorFactory = new GlobalEventExecutorModuleFactory();
- super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(
- factory, executorFactory));
- }
+ @Test
+ public void testValidationExceptionTimeoutMinValue() throws Exception {
+ try {
+ createInstance(-1);
+ fail();
+ } catch (ValidationException e) {
+ assertTrue(e.getMessage().contains("is less than 0"));
+ }
+ }
- @Test
- public void testValidationExceptionTimeoutNotSet()
- throws InstanceAlreadyExistsException {
- try {
- ConfigTransactionJMXClient transaction = configRegistryClient
- .createTransaction();
- createInstance(transaction, this.factory.getImplementationName(), instanceName, null);
- transaction.validateConfig();
- fail();
- } catch (ValidationException e) {
- assertTrue(e.getMessage().contains("Timeout value is not set."));
- }
- }
+ @Test
+ public void testCreateBean() throws Exception {
+ final CommitStatus status = createInstance();
+ assertBeanCount(1, FACTORY_NAME);
+ assertStatus(status, 2, 0, 0);
+ }
- @Test
- public void testValidationExceptionTimeoutMinValue()
- throws InstanceAlreadyExistsException {
- try {
- ConfigTransactionJMXClient transaction = configRegistryClient
- .createTransaction();
- createInstance(transaction, this.factory.getImplementationName(), instanceName, -1);
- transaction.validateConfig();
- fail();
- } catch (ValidationException e) {
- assertTrue(e.getMessage().contains("is less than 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 testCreateBean() throws Exception {
- ConfigTransactionJMXClient transaction = configRegistryClient
- .createTransaction();
- createInstance(transaction, this.factory.getImplementationName(), instanceName, 500);
- transaction.validateConfig();
- CommitStatus status = transaction.commit();
- assertBeanCount(1, factory.getImplementationName());
- assertStatus(status, 2, 0, 0);
- }
+ @Test
+ public void testReconfigure() throws Exception {
+ createInstance();
+ final ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
+ assertBeanCount(1, FACTORY_NAME);
+ final ReconnectImmediatelyStrategyModuleMXBean mxBean = transaction.newMBeanProxy(
+ transaction.lookupConfigBean(FACTORY_NAME, INSTANCE_NAME),
+ ReconnectImmediatelyStrategyModuleMXBean.class);
+ mxBean.setTimeout(200);
+ final CommitStatus status = transaction.commit();
+ assertBeanCount(1, FACTORY_NAME);
+ assertStatus(status, 0, 1, 1);
+ }
- @Test
- public void testReusingOldInstance() throws InstanceAlreadyExistsException,
- ConflictingVersionException, ValidationException {
- ConfigTransactionJMXClient transaction = configRegistryClient
- .createTransaction();
- createInstance(transaction, this.factory.getImplementationName(), instanceName, 100);
- transaction.commit();
- transaction = configRegistryClient.createTransaction();
- assertBeanCount(1, factory.getImplementationName());
- CommitStatus status = transaction.commit();
- assertBeanCount(1, factory.getImplementationName());
- assertStatus(status, 0, 0, 2);
- }
+ private CommitStatus createInstance() throws Exception {
+ return createInstance(500);
+ }
- @Test
- public void testReconfigure() throws InstanceAlreadyExistsException,
- ConflictingVersionException, ValidationException,
- InstanceNotFoundException {
- ConfigTransactionJMXClient transaction = configRegistryClient
- .createTransaction();
- createInstance(transaction, this.factory.getImplementationName(), instanceName, 500);
- transaction.commit();
- transaction = configRegistryClient.createTransaction();
- assertBeanCount(1, factory.getImplementationName());
- ReconnectImmediatelyStrategyModuleMXBean mxBean = transaction
- .newMBeanProxy(transaction.lookupConfigBean(
- AbstractReconnectImmediatelyStrategyModuleFactory.NAME,
- instanceName),
- ReconnectImmediatelyStrategyModuleMXBean.class);
- mxBean.setTimeout(200);
- CommitStatus status = transaction.commit();
- assertBeanCount(1, factory.getImplementationName());
- assertStatus(status, 0, 1, 1);
- }
+ private CommitStatus createInstance(final Integer timeout) throws Exception {
+ final ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
+ createInstance(transaction, timeout);
+ return transaction.commit();
+ }
- public static ObjectName createInstance(
- final ConfigTransactionJMXClient transaction,
- final String moduleName,
- final String instanceName, final Integer timeout) throws InstanceAlreadyExistsException {
- ObjectName nameCreated = transaction.createModule(
- moduleName, instanceName);
- ReconnectImmediatelyStrategyModuleMXBean mxBean = transaction
- .newMBeanProxy(nameCreated,
- ReconnectImmediatelyStrategyModuleMXBean.class);
- mxBean.setTimeout(timeout);
- mxBean.setExecutor(GlobalEventExecutorUtil.createOrGetInstance(transaction));
- return nameCreated;
- }
+ private static ObjectName createInstance(final ConfigTransactionJMXClient transaction, final Integer timeout)
+ throws InstanceAlreadyExistsException {
+ final ObjectName nameCreated = transaction.createModule(FACTORY_NAME, INSTANCE_NAME);
+ final ReconnectImmediatelyStrategyModuleMXBean mxBean = transaction.newMBeanProxy(nameCreated,
+ ReconnectImmediatelyStrategyModuleMXBean.class);
+ mxBean.setTimeout(timeout);
+ mxBean.setExecutor(GlobalEventExecutorUtil.create(transaction));
+ return nameCreated;
+ }
}
*/
package org.opendaylight.controller.config.yang.bgp.reconnectstrategy;
+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.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver;
import org.opendaylight.controller.config.util.ConfigTransactionJMXClient;
import org.opendaylight.controller.config.yang.netty.eventexecutor.GlobalEventExecutorModuleFactory;
-import org.opendaylight.controller.config.yang.reconnectstrategy.AbstractTimedReconnectStrategyModuleFactory;
import org.opendaylight.controller.config.yang.reconnectstrategy.TimedReconnectStrategyModuleFactory;
import org.opendaylight.controller.config.yang.reconnectstrategy.TimedReconnectStrategyModuleMXBean;
-import javax.management.InstanceAlreadyExistsException;
-import javax.management.InstanceNotFoundException;
-import javax.management.ObjectName;
-import java.math.BigDecimal;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
public class TimedReconnectStrategyModuleTest extends AbstractConfigTest {
- private final String instanceName = "timed";
-
- private TimedReconnectStrategyModuleFactory factory;
-
- private GlobalEventExecutorModuleFactory executorFactory;
-
- @Before
- public void setUp() throws Exception {
- this.factory = new TimedReconnectStrategyModuleFactory();
- this.executorFactory = new GlobalEventExecutorModuleFactory();
- super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(
- factory, executorFactory));
- }
-
- @Test
- public void testValidationExceptionSleepFactorNotSet()
- throws InstanceAlreadyExistsException {
- try {
- ConfigTransactionJMXClient transaction = configRegistryClient
- .createTransaction();
- createInstance(transaction, this.factory.getImplementationName(), instanceName, 500, 100L, null, 500L,
- 10L, 10000L);
- transaction.validateConfig();
- fail();
- } catch (ValidationException e) {
- assertTrue(e.getMessage().contains("SleepFactor value is not set."));
- }
- }
-
- @Test
- public void testValidationExceptionSleepFactorMinValue()
- throws InstanceAlreadyExistsException {
- try {
- ConfigTransactionJMXClient transaction = configRegistryClient
- .createTransaction();
- createInstance(transaction, this.factory.getImplementationName(), instanceName, 500, 100L,
- new BigDecimal(0.5), 500L, 10L, 10000L);
- transaction.validateConfig();
- fail();
- } catch (ValidationException e) {
- assertTrue(e.getMessage().contains("is less than 1"));
- }
- }
-
- @Test
- public void testValidationExceptionConnectTimeNotSet()
- throws InstanceAlreadyExistsException {
- try {
- ConfigTransactionJMXClient transaction = configRegistryClient
- .createTransaction();
- createInstance(transaction, this.factory.getImplementationName(), instanceName, null, 100L,
- new BigDecimal(1.0), 500L, 10L, 10000L);
- transaction.validateConfig();
- fail();
- } catch (ValidationException e) {
- assertTrue(e.getMessage().contains("ConnectTime value is not set."));
- }
- }
-
- @Test
- public void testValidationExceptionConnectTimeMinValue()
- throws InstanceAlreadyExistsException {
- try {
- ConfigTransactionJMXClient transaction = configRegistryClient
- .createTransaction();
- createInstance(transaction, this.factory.getImplementationName(), instanceName, -1, 100L, new BigDecimal(
- 1.0), 500L, 10L, 10000L);
- transaction.validateConfig();
- fail();
- } catch (ValidationException e) {
- assertTrue(e.getMessage().contains("is less than 0"));
- }
- }
-
- @Test
- public void testValidationExceptionMinSleepNotSet()
- throws InstanceAlreadyExistsException {
- try {
- ConfigTransactionJMXClient transaction = configRegistryClient
- .createTransaction();
- createInstance(transaction, this.factory.getImplementationName(), instanceName, 100, null,
- new BigDecimal(1.0), 100L, 10L, 10000L);
- transaction.validateConfig();
- fail();
- } catch (ValidationException e) {
- assertTrue(e.getMessage().contains("MinSleep value is not set."));
- }
- }
-
- @Test
- public void testValidationExceptionMaxSleep()
- throws InstanceAlreadyExistsException {
- try {
- ConfigTransactionJMXClient transaction = configRegistryClient
- .createTransaction();
- createInstance(transaction, this.factory.getImplementationName(), instanceName, 100, 300L,
- new BigDecimal(1.0), 100L, 10L, 10000L);
- transaction.validateConfig();
- fail();
- } catch (ValidationException e) {
- assertTrue(e.getMessage().contains(
- "is greter than MaxSleep"));
- }
- }
-
- @Test
- public void testCreateBean() throws Exception {
- ConfigTransactionJMXClient transaction = configRegistryClient
- .createTransaction();
- createInstance(transaction, this.factory.getImplementationName(), instanceName, 500, 100L,
- new BigDecimal(1.0), 500L, 10L, 10000L);
- transaction.validateConfig();
- CommitStatus status = transaction.commit();
- assertBeanCount(1, factory.getImplementationName());
- assertStatus(status, 2, 0, 0);
- }
-
- @Test
- public void testReusingOldInstance() throws InstanceAlreadyExistsException,
- ConflictingVersionException, ValidationException {
- ConfigTransactionJMXClient transaction = configRegistryClient
- .createTransaction();
- createInstance(transaction, this.factory.getImplementationName(), instanceName, 500, 100L,
- new BigDecimal(1.0), 500L, 10L, 10000L);
- transaction.commit();
- transaction = configRegistryClient.createTransaction();
- assertBeanCount(1, factory.getImplementationName());
- CommitStatus status = transaction.commit();
- assertBeanCount(1, factory.getImplementationName());
- assertStatus(status, 0, 0, 2);
- }
-
- @Test
- public void testReconfigure() throws InstanceAlreadyExistsException,
- ConflictingVersionException, ValidationException,
- InstanceNotFoundException {
- ConfigTransactionJMXClient transaction = configRegistryClient
- .createTransaction();
- createInstance(transaction, this.factory.getImplementationName(), instanceName, 500, 100L,
- new BigDecimal(1.0), new Long(500), new Long(10), new Long(
- 10000));
- transaction.commit();
- transaction = configRegistryClient.createTransaction();
- assertBeanCount(1, factory.getImplementationName());
- TimedReconnectStrategyModuleMXBean mxBean = transaction
- .newMBeanProxy(transaction.lookupConfigBean(
- AbstractTimedReconnectStrategyModuleFactory.NAME,
- instanceName), TimedReconnectStrategyModuleMXBean.class);
- assertEquals(mxBean.getMinSleep(), new Long(100));
- mxBean.setMinSleep(200L);
- assertEquals(mxBean.getMinSleep(), new Long(200));
- CommitStatus status = transaction.commit();
- assertBeanCount(1, factory.getImplementationName());
- assertStatus(status, 0, 1, 1);
-
- }
-
- public static ObjectName createInstance(
- final ConfigTransactionJMXClient transaction,
- final String moduleName,
- final String instanceName, final Integer connectTime,
- final Long minSleep, final BigDecimal sleepFactor,
- final Long maxSleep, final Long maxAttempts, final Long deadline) throws InstanceAlreadyExistsException {
- ObjectName nameCreated = transaction.createModule(
- moduleName, instanceName);
- TimedReconnectStrategyModuleMXBean mxBean = transaction.newMBeanProxy(
- nameCreated, TimedReconnectStrategyModuleMXBean.class);
- mxBean.setConnectTime(connectTime);
- mxBean.setDeadline(deadline);
- mxBean.setMaxAttempts(maxAttempts);
- mxBean.setMaxSleep(maxSleep);
- mxBean.setMinSleep(minSleep);
- mxBean.setSleepFactor(sleepFactor);
- mxBean.setExecutor(GlobalEventExecutorUtil.createOrGetInstance(transaction));
- return nameCreated;
- }
+ private static final String INSTANCE_NAME = "timed-recconect-stategy-impl";
+ private static final String FACTORY_NAME = TimedReconnectStrategyModuleFactory.NAME;
+
+ @Before
+ public void setUp() throws Exception {
+ super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(
+ new TimedReconnectStrategyModuleFactory(), 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 TimedReconnectStrategyModuleMXBean mxBean = transaction.newMBeanProxy(
+ transaction.lookupConfigBean(FACTORY_NAME, INSTANCE_NAME), TimedReconnectStrategyModuleMXBean.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 TimedReconnectStrategyModuleMXBean mxBean = transaction.newMBeanProxy(nameCreated,
+ TimedReconnectStrategyModuleMXBean.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;
+ }
}
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;
public class BGPDispatcherImplModuleTest extends AbstractConfigTest {
- private final String instanceName = "bgp-message-fct";
-
- private BGPDispatcherImplModuleFactory factory;
-
- private NettyThreadgroupModuleFactory threadgroupFactory;
-
- private RIBExtensionsImplModuleFactory messageFactory;
-
- private SimpleBGPExtensionProviderContextModuleFactory extensionFactory;
-
- private HashedWheelTimerModuleFactory hwtFactory;
-
- @Before
- public void setUp() throws Exception {
- this.factory = new BGPDispatcherImplModuleFactory();
- this.threadgroupFactory = new NettyThreadgroupModuleFactory();
- this.messageFactory = new RIBExtensionsImplModuleFactory();
- this.extensionFactory = new SimpleBGPExtensionProviderContextModuleFactory();
- this.hwtFactory = new HashedWheelTimerModuleFactory();
- super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(
- this.factory, threadgroupFactory, messageFactory, extensionFactory, hwtFactory));
- }
-
- @Test
- public void testCreateBean() throws Exception {
- ConfigTransactionJMXClient transaction = configRegistryClient
- .createTransaction();
- createInstance(transaction, this.factory.getImplementationName(), instanceName);
- transaction.validateConfig();
- CommitStatus status = transaction.commit();
- assertBeanCount(1, factory.getImplementationName());
- assertStatus(status, 5, 0, 0);
- }
-
- @Test
- public void testReusingOldInstance() throws InstanceAlreadyExistsException,
- ConflictingVersionException, ValidationException {
- ConfigTransactionJMXClient transaction = configRegistryClient
- .createTransaction();
- createInstance(transaction, this.factory.getImplementationName(), instanceName);
- transaction.commit();
- transaction = configRegistryClient.createTransaction();
- assertBeanCount(1, factory.getImplementationName());
- CommitStatus status = transaction.commit();
- assertBeanCount(1, factory.getImplementationName());
- assertStatus(status, 0, 0, 5);
- }
-
- public static ObjectName createInstance(final ConfigTransactionJMXClient transaction, final String moduleName,
- final String instanceName) throws InstanceAlreadyExistsException {
- ObjectName nameCreated = transaction.createModule(
- moduleName, instanceName);
- BGPDispatcherImplModuleMXBean mxBean = transaction.newMBeanProxy(
- nameCreated, BGPDispatcherImplModuleMXBean.class);
- mxBean.setBossGroup(createThreadgroupInstance(transaction, "boss-threadgroup", 10));
- mxBean.setWorkerGroup(createThreadgroupInstance(transaction, "worker-threadgroup", 10));
- mxBean.setBgpExtensions(createBgpExtensionsInstance(transaction, "bgp-extensions"));
- mxBean.setTimer(createTimerInstance(transaction, ""));
- return nameCreated;
- }
-
- public static ObjectName createThreadgroupInstance(
- final ConfigTransactionJMXClient transaction,
- final String instanceName,
- final Integer threadCount) throws InstanceAlreadyExistsException {
- ObjectName nameCreated = transaction.createModule(NettyThreadgroupModuleFactory.NAME,
- instanceName);
- NettyThreadgroupModuleMXBean mxBean = transaction.newMBeanProxy(
- nameCreated, NettyThreadgroupModuleMXBean.class);
- mxBean.setThreadCount(threadCount);
- return nameCreated;
- }
-
- public static ObjectName createTimerInstance(final ConfigTransactionJMXClient transaction, final String instanceName)
- throws InstanceAlreadyExistsException {
- ObjectName nameCreated = transaction.createModule(HashedWheelTimerModuleFactory.NAME,
- instanceName);
- HashedWheelTimerModuleMXBean mxBean = transaction.newMBeanProxy(
- nameCreated, HashedWheelTimerModuleMXBean.class);
- return nameCreated;
-
- }
-
- public static ObjectName createBgpExtensionsInstance(
- final ConfigTransactionJMXClient transaction,
- final String instanceName)
- throws InstanceAlreadyExistsException {
- ObjectName nameCreated = transaction.createModule(SimpleBGPExtensionProviderContextModuleFactory.NAME,
- instanceName);
- transaction.newMBeanProxy(nameCreated,
- SimpleBGPExtensionProviderContextModuleMXBean.class);
- return nameCreated;
- }
+ private static final String INSTANCE_NAME = "bgp-message-fct";
+ private static final String FACTORY_NAME = BGPDispatcherImplModuleFactory.NAME;
+
+ private static final String TIMER_INSTANCE_NAME = "timer-impl";
+ private static final String BGP_EXTENSION_INSTANCE_NAME = "bgp-extension-impl";
+ private static final String BOSS_TG_INSTANCE_NAME = "boss-threadgroup-impl";
+ private static final String WORKER_TG_INSTANCE_NAME = "worker-threadgroup-impl";
+
+ @Before
+ public void setUp() throws Exception {
+ super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(
+ new BGPDispatcherImplModuleFactory(), new NettyThreadgroupModuleFactory(),
+ new RIBExtensionsImplModuleFactory(), new SimpleBGPExtensionProviderContextModuleFactory(),
+ new HashedWheelTimerModuleFactory()));
+ }
+
+ @Test
+ public void testCreateBean() throws Exception {
+ CommitStatus status = createInstance();
+ assertBeanCount(1, FACTORY_NAME);
+ assertStatus(status, 5, 0, 0);
+ }
+
+ @Test
+ public void testReusingOldInstance() throws Exception {
+ createInstance();
+ ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
+ assertBeanCount(1, FACTORY_NAME);
+ CommitStatus status = transaction.commit();
+ assertBeanCount(1, FACTORY_NAME);
+ assertStatus(status, 0, 0, 5);
+ }
+
+ private CommitStatus createInstance() throws Exception {
+ ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
+ createInstance(transaction);
+ return transaction.commit();
+ }
+
+ public static ObjectName createInstance(final ConfigTransactionJMXClient transaction)
+ throws InstanceAlreadyExistsException {
+ ObjectName nameCreated = transaction.createModule(FACTORY_NAME, INSTANCE_NAME);
+ BGPDispatcherImplModuleMXBean mxBean = transaction.newMBeanProxy(nameCreated,
+ BGPDispatcherImplModuleMXBean.class);
+ mxBean.setBossGroup(createThreadgroupInstance(transaction, BOSS_TG_INSTANCE_NAME, 10));
+ mxBean.setWorkerGroup(createThreadgroupInstance(transaction, WORKER_TG_INSTANCE_NAME, 10));
+ mxBean.setBgpExtensions(createBgpExtensionsInstance(transaction));
+ mxBean.setTimer(createTimerInstance(transaction));
+ return nameCreated;
+ }
+
+ private static ObjectName createThreadgroupInstance(final ConfigTransactionJMXClient transaction,
+ final String instanceName, final Integer threadCount) throws InstanceAlreadyExistsException {
+ ObjectName nameCreated = transaction.createModule(NettyThreadgroupModuleFactory.NAME, instanceName);
+ NettyThreadgroupModuleMXBean mxBean = transaction
+ .newMBeanProxy(nameCreated, NettyThreadgroupModuleMXBean.class);
+ mxBean.setThreadCount(threadCount);
+ return nameCreated;
+ }
+
+ private static ObjectName createTimerInstance(final ConfigTransactionJMXClient transaction)
+ throws InstanceAlreadyExistsException {
+ ObjectName nameCreated = transaction.createModule(HashedWheelTimerModuleFactory.NAME, TIMER_INSTANCE_NAME);
+ transaction.newMBeanProxy(nameCreated, HashedWheelTimerModuleMXBean.class);
+ return nameCreated;
+
+ }
+
+ private static ObjectName createBgpExtensionsInstance(final ConfigTransactionJMXClient transaction)
+ throws InstanceAlreadyExistsException {
+ ObjectName nameCreated = transaction.createModule(SimpleBGPExtensionProviderContextModuleFactory.NAME,
+ BGP_EXTENSION_INSTANCE_NAME);
+ transaction.newMBeanProxy(nameCreated, SimpleBGPExtensionProviderContextModuleMXBean.class);
+ return nameCreated;
+ }
}
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
+import java.util.Collections;
import java.util.List;
-import javax.management.InstanceAlreadyExistsException;
import javax.management.ObjectName;
import org.junit.Test;
import org.opendaylight.controller.config.api.jmx.CommitStatus;
import org.opendaylight.controller.config.spi.ModuleFactory;
import org.opendaylight.controller.config.util.ConfigTransactionJMXClient;
-import org.opendaylight.controller.config.yang.bgp.rib.spi.RIBExtensionsImplModuleFactory;
-import org.opendaylight.controller.config.yang.md.sal.binding.impl.DataBrokerImplModuleFactory;
-import org.opendaylight.controller.config.yang.md.sal.dom.impl.DomBrokerImplModuleFactory;
-import org.opendaylight.controller.config.yang.md.sal.dom.impl.HashMapDataStoreModuleFactory;
-import org.opendaylight.controller.config.yang.netty.eventexecutor.GlobalEventExecutorModuleFactory;
-import org.opendaylight.controller.config.yang.reconnectstrategy.TimedReconnectStrategyModuleFactory;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
public class BGPPeerModuleTest extends RIBImplModuleTest {
- private final String instanceName = "bgp-impl1";
-
- public static ObjectName createBgpPeerInstance(final ConfigTransactionJMXClient transaction,
- final String instanceName, final String host, final Integer port) throws Exception {
- final ObjectName nameCreated = transaction.createModule(BGPPeerModuleFactory.NAME, instanceName);
- final BGPPeerModuleMXBean mxBean = transaction.newMXBeanProxy(nameCreated, BGPPeerModuleMXBean.class);
-
- // FIXME JMX crashes if union was not created via artificial constructor
- // annotated for JMX as value
- // IpAddress host1 = new IpAddress(new Ipv4Address(host));
- mxBean.setHost(host == null ? null : new IpAddress(host.toCharArray()));
- mxBean.setPort(port==null ? null : new PortNumber(port));
- mxBean.setAdvertizedTable(Lists.newArrayList(createAdvertisedTable(transaction, BGPTableTypeImplModuleFactory.NAME)));
- mxBean.setRib(createInstance(transaction, RIBImplModuleFactory.NAME, "ribImpl",
- DataBrokerImplModuleFactory.NAME, TimedReconnectStrategyModuleFactory.NAME,
- GlobalEventExecutorModuleFactory.NAME, BGPDispatcherImplModuleFactory.NAME,
- RIBExtensionsImplModuleFactory.NAME, DomBrokerImplModuleFactory.NAME,
- HashMapDataStoreModuleFactory.NAME));
- return nameCreated;
- }
-
- private static ObjectName createAdvertisedTable(final ConfigTransactionJMXClient transaction, final String tableTypeModuleName) throws InstanceAlreadyExistsException {
- String instanceName = "table-type";
- final ObjectName nameCreated = transaction.createModule(tableTypeModuleName, instanceName);
- BGPTableTypeImplModuleMXBean mxBean = transaction.newMXBeanProxy(nameCreated, BGPTableTypeImplModuleMXBean.class);
-
- mxBean.setAfi(new IdentityAttributeRef(Ipv4AddressFamily.QNAME.toString()));
- mxBean.setSafi(new IdentityAttributeRef(MplsLabeledVpnSubsequentAddressFamily.QNAME.toString()));
- return nameCreated;
- }
-
- @Override
- protected List<ModuleFactory> getModuleFactories() {
- List<ModuleFactory> moduleFactories = super.getModuleFactories();
- moduleFactories.add(new BGPPeerModuleFactory());
- moduleFactories.add(new BGPTableTypeImplModuleFactory());
- return moduleFactories;
- }
-
- @Test
- public void testValidationExceptionPortNotSet() throws Exception {
- final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
- try {
- createBgpPeerInstance(transaction, this.instanceName, "127.0.0.1", null);
- transaction.validateConfig();
- fail();
- } catch (final ValidationException e) {
- transaction.abortConfig();
- assertTrue(e.getMessage().contains("Port value is not set."));
- }
- }
-
- @Test
- public void testValidationExceptionHostNotSet() throws Exception {
- final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
- try {
- createBgpPeerInstance(transaction, this.instanceName, null, null);
- transaction.validateConfig();
- fail();
- } catch (final ValidationException e) {
- transaction.abortConfig();
- assertTrue(e.getMessage().contains("Host value is not set."));
- }
- }
-
- @Override
- @Test
- public void testCreateBean() throws Exception {
- final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
- createBgpPeerInstance(transaction, this.instanceName, "127.0.0.1", 1);
- transaction.validateConfig();
- final CommitStatus status = transaction.commit();
- assertBeanCount(1, BGPPeerModuleFactory.NAME);
- assertStatus(status, 16, 0, 0);
- }
-
- @Override
- protected CodecRegistry getCodecRegistry() {
- IdentityCodec<?> idCodec = mock(IdentityCodec.class);
- doReturn(Ipv4AddressFamily.class).when(idCodec).deserialize(Ipv4AddressFamily.QNAME);
- doReturn(MplsLabeledVpnSubsequentAddressFamily.class).when(idCodec).deserialize(MplsLabeledVpnSubsequentAddressFamily.QNAME);
-
- CodecRegistry codecReg = super.getCodecRegistry();
- doReturn(idCodec).when(codecReg).getIdentityCodec();
- return codecReg;
- }
-
- @Test
- public void testReusingOldInstance() throws Exception {
- ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
- createBgpPeerInstance(transaction, this.instanceName, "127.0.0.1", 1);
- transaction.validateConfig();
- CommitStatus status = transaction.commit();
- transaction = this.configRegistryClient.createTransaction();
- assertBeanCount(1, BGPPeerModuleFactory.NAME);
- status = transaction.commit();
- assertBeanCount(1, BGPPeerModuleFactory.NAME);
- assertStatus(status, 0, 0, 16);
- }
-
- @Test
- public void testReconfigure() throws Exception {
- ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
- createBgpPeerInstance(transaction, this.instanceName, "127.0.0.1", 1);
- transaction.validateConfig();
- CommitStatus status = transaction.commit();
- transaction = this.configRegistryClient.createTransaction();
- assertBeanCount(1, BGPPeerModuleFactory.NAME);
- final BGPPeerModuleMXBean mxBean = transaction.newMXBeanProxy(
- transaction.lookupConfigBean(BGPPeerModuleFactory.NAME, this.instanceName), BGPPeerModuleMXBean.class);
- mxBean.setPort(new PortNumber(10));
- status = transaction.commit();
- assertBeanCount(1, BGPPeerModuleFactory.NAME);
- assertStatus(status, 0, 1, 15);
- }
+ private static final String INSTANCE_NAME = "bgp-peer-module-impl";
+ private static final String FACTORY_NAME = BGPPeerModuleFactory.NAME;
+
+ private static final String HOST = "127.0.0.1";
+
+ @Override
+ protected CodecRegistry getCodecRegistry() {
+ IdentityCodec<?> idCodec = mock(IdentityCodec.class);
+ doReturn(Ipv4AddressFamily.class).when(idCodec).deserialize(Ipv4AddressFamily.QNAME);
+ doReturn(MplsLabeledVpnSubsequentAddressFamily.class).when(idCodec).deserialize(
+ MplsLabeledVpnSubsequentAddressFamily.QNAME);
+
+ CodecRegistry codecReg = super.getCodecRegistry();
+ doReturn(idCodec).when(codecReg).getIdentityCodec();
+ return codecReg;
+ }
+
+ @Override
+ protected List<ModuleFactory> getModuleFactories() {
+ List<ModuleFactory> moduleFactories = super.getModuleFactories();
+ moduleFactories.add(new BGPPeerModuleFactory());
+ moduleFactories.add(new BGPTableTypeImplModuleFactory());
+ return moduleFactories;
+ }
+
+ @Test
+ public void testValidationExceptionPortNotSet() throws Exception {
+ try {
+ createBgpPeerInstance(HOST, null);
+ fail();
+ } catch (final ValidationException e) {
+ assertTrue(e.getMessage().contains("Port value is not set."));
+ }
+ }
+
+ @Test
+ public void testValidationExceptionHostNotSet() throws Exception {
+ try {
+ createBgpPeerInstance(null, 1);
+ fail();
+ } catch (final ValidationException e) {
+ assertTrue(e.getMessage().contains("Host value is not set."));
+ }
+ }
+
+ @Override
+ @Test
+ public void testCreateBean() throws Exception {
+ final CommitStatus status = createBgpPeerInstance();
+ assertBeanCount(1, FACTORY_NAME);
+ assertStatus(status, 16, 0, 0);
+ }
+
+ @Test
+ public void testReusingOldInstance() throws Exception {
+ CommitStatus status = createBgpPeerInstance();
+ ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
+ assertBeanCount(1, FACTORY_NAME);
+ status = transaction.commit();
+ assertBeanCount(1, FACTORY_NAME);
+ assertStatus(status, 0, 0, 16);
+ }
+
+ @Test
+ public void testReconfigure() throws Exception {
+ CommitStatus status = createBgpPeerInstance();
+ ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
+ assertBeanCount(1, FACTORY_NAME);
+ final BGPPeerModuleMXBean mxBean = transaction.newMXBeanProxy(
+ transaction.lookupConfigBean(FACTORY_NAME, INSTANCE_NAME), BGPPeerModuleMXBean.class);
+ mxBean.setPort(new PortNumber(10));
+ status = transaction.commit();
+ assertBeanCount(1, FACTORY_NAME);
+ assertStatus(status, 0, 1, 15);
+ }
+
+ private static ObjectName createBgpPeerInstance(final ConfigTransactionJMXClient transaction, final String host,
+ final Integer port) throws Exception {
+ final ObjectName nameCreated = transaction.createModule(FACTORY_NAME, INSTANCE_NAME);
+ final BGPPeerModuleMXBean mxBean = transaction.newMXBeanProxy(nameCreated, BGPPeerModuleMXBean.class);
+
+ // FIXME JMX crashes if union was not created via artificial constructor
+ // annotated for JMX as value
+ // IpAddress host1 = new IpAddress(new Ipv4Address(host));
+ mxBean.setHost(host == null ? null : new IpAddress(host.toCharArray()));
+ mxBean.setPort(port == null ? null : new PortNumber(port));
+ mxBean.setAdvertizedTable(Collections.<ObjectName> emptyList());
+ mxBean.setRib(createInstance(transaction));
+ mxBean.setAdvertizedTable(Lists.newArrayList(BGPTableTypeImplModuleTest.createTableInstance(transaction,
+ new IdentityAttributeRef(Ipv4AddressFamily.QNAME.toString()), new IdentityAttributeRef(
+ MplsLabeledVpnSubsequentAddressFamily.QNAME.toString()))));
+ return nameCreated;
+ }
+
+ private CommitStatus createBgpPeerInstance() throws Exception {
+ return createBgpPeerInstance(HOST, 1);
+ }
+
+ private CommitStatus createBgpPeerInstance(final String host, final Integer port) throws Exception {
+ final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
+ createBgpPeerInstance(transaction, host, port);
+ return transaction.commit();
+ }
}
--- /dev/null
+package org.opendaylight.controller.config.yang.bgp.rib.impl;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+
+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.IdentityAttributeRef;
+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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.MplsLabeledVpnSubsequentAddressFamily;
+import org.opendaylight.yangtools.yang.data.impl.codec.CodecRegistry;
+import org.opendaylight.yangtools.yang.data.impl.codec.IdentityCodec;
+
+public class BGPTableTypeImplModuleTest extends AbstractConfigTest {
+
+ private static final String INSTANCE_NAME = "bgp-table-type-impl";
+ private static final String FACTORY_NAME = BGPTableTypeImplModuleFactory.NAME;
+
+ private IdentityAttributeRef afiRef = new IdentityAttributeRef(Ipv4AddressFamily.QNAME.toString());
+ private IdentityAttributeRef safiRef = new IdentityAttributeRef(
+ MplsLabeledVpnSubsequentAddressFamily.QNAME.toString());
+
+ @Before
+ public void setUp() throws Exception {
+ super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(new BGPTableTypeImplModuleFactory()));
+ }
+
+ @Override
+ protected CodecRegistry getCodecRegistry() {
+ IdentityCodec<?> idCodec = mock(IdentityCodec.class);
+ doReturn(Ipv4AddressFamily.class).when(idCodec).deserialize(Ipv4AddressFamily.QNAME);
+ doReturn(MplsLabeledVpnSubsequentAddressFamily.class).when(idCodec).deserialize(
+ MplsLabeledVpnSubsequentAddressFamily.QNAME);
+ doReturn(Ipv6AddressFamily.class).when(idCodec).deserialize(Ipv6AddressFamily.QNAME);
+
+ CodecRegistry codecReg = super.getCodecRegistry();
+ doReturn(idCodec).when(codecReg).getIdentityCodec();
+ return codecReg;
+ }
+
+ @Test
+ public void testValidationExceptionAfiNotSet() throws InstanceAlreadyExistsException, ConflictingVersionException {
+ try {
+ createInstance(null, safiRef);
+ fail();
+ } catch (ValidationException e) {
+ assertTrue(e.getMessage().contains("Afi value is not set."));
+ }
+ }
+
+ @Test
+ public void testValidationExceptionSafiNotSet() throws InstanceAlreadyExistsException, ConflictingVersionException {
+ try {
+ createInstance(afiRef, null);
+ fail();
+ } catch (ValidationException e) {
+ assertTrue(e.getMessage().contains("Safi value is not set."));
+ }
+ }
+
+ @Test
+ public void testCreateBean() throws Exception {
+ final CommitStatus status = createInstance();
+ assertBeanCount(1, FACTORY_NAME);
+ assertStatus(status, 1, 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, 1);
+ }
+
+ @Test
+ public void testReconfigure() throws Exception {
+ createInstance();
+ final ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
+ assertBeanCount(1, FACTORY_NAME);
+ final BGPTableTypeImplModuleMXBean mxBean = transaction.newMXBeanProxy(
+ transaction.lookupConfigBean(FACTORY_NAME, INSTANCE_NAME), BGPTableTypeImplModuleMXBean.class);
+ mxBean.setAfi(new IdentityAttributeRef(Ipv6AddressFamily.QNAME.toString()));
+ final CommitStatus status = transaction.commit();
+ assertBeanCount(1, FACTORY_NAME);
+ assertStatus(status, 0, 1, 0);
+ }
+
+ private CommitStatus createInstance() throws Exception {
+ return createInstance(afiRef, safiRef);
+ }
+
+ private CommitStatus createInstance(final IdentityAttributeRef afiRef, final IdentityAttributeRef safiRef)
+ throws ConflictingVersionException, ValidationException, InstanceAlreadyExistsException {
+ ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
+ createTableInstance(transaction, afiRef, safiRef);
+ return transaction.commit();
+ }
+
+ public static ObjectName createTableInstance(final ConfigTransactionJMXClient transaction,
+ final IdentityAttributeRef afiRef, final IdentityAttributeRef safiRef)
+ throws InstanceAlreadyExistsException {
+ final ObjectName nameCreated = transaction.createModule(FACTORY_NAME, INSTANCE_NAME);
+ BGPTableTypeImplModuleMXBean mxBean = transaction.newMXBeanProxy(nameCreated,
+ BGPTableTypeImplModuleMXBean.class);
+
+ mxBean.setAfi(afiRef);
+ mxBean.setSafi(safiRef);
+ return nameCreated;
+ }
+
+}
*/
package org.opendaylight.controller.config.yang.bgp.rib.impl;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
-import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
+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 com.google.common.collect.Lists;
public class RIBImplModuleTest extends AbstractConfigTest {
- private static final String INSTANCE_NAME = GlobalEventExecutorModuleFactory.SINGLETON_NAME;
- private static final String TRANSACTION_NAME = "testTransaction";
+ private static final String INSTANCE_NAME = "rib-impl";
+ private static final String FACTORY_NAME = RIBImplModuleFactory.NAME;
+ private static final String TRANSACTION_NAME = "testTransaction";
- private RIBImplModuleFactory factory;
- private DataBrokerImplModuleFactory dataBrokerFactory;
- private TimedReconnectStrategyModuleFactory reconnectFactory;
- private BGPDispatcherImplModuleFactory dispactherFactory;
- private NettyThreadgroupModuleFactory threadgroupFactory;
- private GlobalEventExecutorModuleFactory executorFactory;
- private SimpleBGPExtensionProviderContextModuleFactory extensionFactory;
- private RIBExtensionsImplModuleFactory ribExtensionsFactory;
- private DomBrokerImplModuleFactory domBrokerFactory;
- private RuntimeMappingModuleFactory runtimeMappingFactory;
- private HashMapDataStoreModuleFactory dataStroreFactory;
- private HashedWheelTimerModuleFactory hwtFactory;
+ private static final String RIB_ID = "test";
+ private static final String BGP_ID = "192.168.1.1";
- @Mock
- private DataModificationTransaction mockedTransaction;
+ private static final String SESSION_RS_INSTANCE_NAME = "session-reconnect-strategy-impl";
+ private static final String TCP_RS_INSTANCE_NAME = "tcp-reconnect-strategy";
+ private static final String DATA_BROKER_INSTANCE_NAME = "data-broker-impl";
+ private static final String DOM_BROKER_INSTANCE_NAME = "data-broker-impl";
+ private static final String DATA_STORE_INSTANCE_NAME = "data-store-impl";
+ private static final String RIB_EXTENSIONS_INSTANCE_NAME = "rib-extensions-impl";
- @Mock
- private DataProviderService mockedDataProvider;
+ @Mock
+ private DataModificationTransaction mockedTransaction;
- @Mock
- private Future<RpcResult<TransactionStatus>> mockedFuture;
+ @Mock
+ private DataProviderService mockedDataProvider;
- @Mock
- private RpcResult<TransactionStatus> mockedResult;
+ @Mock
+ private Future<RpcResult<TransactionStatus>> mockedFuture;
- @SuppressWarnings("unchecked")
- @Before
- public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
+ @Mock
+ private RpcResult<TransactionStatus> mockedResult;
- this.factory = new RIBImplModuleFactory();
- this.dataBrokerFactory = new DataBrokerImplModuleFactory();
- this.executorFactory = new GlobalEventExecutorModuleFactory();
- this.dispactherFactory = new BGPDispatcherImplModuleFactory();
- this.threadgroupFactory = new NettyThreadgroupModuleFactory();
- this.reconnectFactory = new TimedReconnectStrategyModuleFactory();
- this.extensionFactory = new SimpleBGPExtensionProviderContextModuleFactory();
- this.ribExtensionsFactory = new RIBExtensionsImplModuleFactory();
- this.domBrokerFactory = new DomBrokerImplModuleFactory();
- this.runtimeMappingFactory = new RuntimeMappingModuleFactory();
- this.dataStroreFactory = new HashMapDataStoreModuleFactory();
- this.hwtFactory = new HashedWheelTimerModuleFactory();
+ @SuppressWarnings("unchecked")
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
- List<ModuleFactory> moduleFactories = getModuleFactories();
- super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(mockedContext, moduleFactories
- .toArray(new ModuleFactory[moduleFactories.size()])));
+ List<ModuleFactory> moduleFactories = getModuleFactories();
+ super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(mockedContext, moduleFactories
+ .toArray(new ModuleFactory[moduleFactories.size()])));
- Filter mockedFilter = mock(Filter.class);
- Mockito.doReturn(mockedFilter).when(mockedContext).createFilter(Mockito.anyString());
-
- Mockito.doNothing().when(mockedContext).addServiceListener(any(ServiceListener.class), Mockito.anyString());
+ Filter mockedFilter = mock(Filter.class);
+ Mockito.doReturn(mockedFilter).when(mockedContext).createFilter(Mockito.anyString());
- Mockito.doNothing().when(mockedContext).addBundleListener(any(BundleListener.class));
-
- Mockito.doReturn(new Bundle[]{}).when(mockedContext).getBundles();
-
- Mockito.doReturn(new ServiceReference[]{}).when(mockedContext).getServiceReferences(Matchers.anyString(), Matchers.anyString());
-
- ServiceReference<?> emptyServiceReference = mock(ServiceReference.class, "Empty");
-
- ServiceReference<?> dataProviderServiceReference = mock(ServiceReference.class, "Data Provider");
-
-
- Mockito.doReturn(mockedFilter).when(mockedContext).createFilter(Mockito.anyString());
-
- Mockito.doNothing().when(mockedContext).addServiceListener(any(ServiceListener.class), Mockito.anyString());
-
- Mockito.doNothing().when(mockedContext).addBundleListener(any(BundleListener.class));
-
- Mockito.doReturn(new Bundle[]{}).when(mockedContext).getBundles();
-
- Mockito.doReturn(new ServiceReference[]{}).when(mockedContext).getServiceReferences(Matchers.anyString(), Matchers.anyString());
-
- //mockedDataProvider = mock(DataProviderService.class);
-
-
- Mockito.doReturn("Empty reference").when(emptyServiceReference).toString();
- Mockito.doReturn("Data Provider Service Reference").when(dataProviderServiceReference).toString();
- //
- Mockito.doReturn(emptyServiceReference).when(mockedContext).getServiceReference(any(Class.class));
- Mockito.doReturn(dataProviderServiceReference).when(mockedContext).getServiceReference(DataProviderService.class);
-
- Mockito.doReturn(mockedDataProvider).when(mockedContext).getService(dataProviderServiceReference);
-
- //Mockito.doReturn(null).when(mockedContext).getService(dataProviderServiceReference);
- Mockito.doReturn(null).when(mockedContext).getService(emptyServiceReference);
-
-
- Registration<DataCommitHandler<InstanceIdentifier, CompositeNode>> registration = mock(Registration.class);
- Mockito.doReturn(registration).when(mockedDataProvider).registerCommitHandler(any(InstanceIdentifier.class),
- any(DataCommitHandler.class));
- Mockito.doReturn(registration).when(mockedDataProvider).registerCommitHandler(any(InstanceIdentifier.class),
- any(DataCommitHandler.class));
-
- Mockito.doReturn(null).when(mockedDataProvider).readOperationalData(any(InstanceIdentifier.class));
- Mockito.doReturn(mockedTransaction).when(mockedDataProvider).beginTransaction();
-
- Mockito.doNothing().when(mockedTransaction).putOperationalData(any(InstanceIdentifier.class), any(CompositeNode.class));
- Mockito.doNothing().when(mockedTransaction).removeOperationalData(any(InstanceIdentifier.class));
-
- Mockito.doReturn(mockedFuture).when(mockedTransaction).commit();
- Mockito.doReturn(TRANSACTION_NAME).when(mockedTransaction).getIdentifier();
-
- Mockito.doReturn(mockedResult).when(mockedFuture).get();
- Mockito.doReturn(true).when(mockedResult).isSuccessful();
- Mockito.doReturn(Collections.emptySet()).when(mockedResult).getErrors();
- }
-
- protected List<ModuleFactory> getModuleFactories() {
- return Lists.newArrayList(this.factory,
- this.dispactherFactory, this.threadgroupFactory,
- this.reconnectFactory, this.dataBrokerFactory, this.executorFactory, this.extensionFactory,
- this.ribExtensionsFactory, this.domBrokerFactory, this.runtimeMappingFactory,
- this.dataStroreFactory, this.hwtFactory);
- }
-
- @Override
- protected BundleContextServiceRegistrationHandler getBundleContextServiceRegistrationHandler(final Class<?> serviceType) {
- if (serviceType.equals(SchemaServiceListener.class)) {
- return new BundleContextServiceRegistrationHandler() {
- @Override
- public void handleServiceRegistration(final Object o) {
- SchemaServiceListener listener = (SchemaServiceListener) o;
- listener.onGlobalContextUpdated(getMockedSchemaContext());
- }
- };
- }
-
- return super.getBundleContextServiceRegistrationHandler(serviceType);
- }
-
- @Test
- public void testCreateBean() throws Exception {
- ConfigTransactionJMXClient transaction = configRegistryClient
- .createTransaction();
- createInstance(transaction, this.factory.getImplementationName(), INSTANCE_NAME,
- this.dataBrokerFactory.getImplementationName(), this.reconnectFactory.getImplementationName(),
- this.executorFactory.getImplementationName(), this.dispactherFactory.getImplementationName(),
- this.ribExtensionsFactory.getImplementationName(), this.domBrokerFactory.getImplementationName(),
- this.dataStroreFactory.getImplementationName());
- transaction.validateConfig();
- CommitStatus status = transaction.commit();
- Thread.sleep(2000);
- assertBeanCount(1, factory.getImplementationName());
- assertStatus(status, 14, 0, 0);
- }
-
- @After
- public void closeAllModules() throws Exception {
- super.destroyAllConfigBeans();
- }
-
- public static ObjectName createInstance(final ConfigTransactionJMXClient transaction, final String moduleName,
- final String instanceName, final String bindingDataModuleName, final String reconnectModueName,
- final String executorModuleName, final String dispatcherModuleName, final String ribExtensionsModuleName,
- final String domBrokerModuleName, final String dataStroreModuleName)
- throws Exception {
- ObjectName nameCreated = transaction.createModule(
- moduleName, instanceName);
- RIBImplModuleMXBean mxBean = transaction.newMXBeanProxy(
- nameCreated, RIBImplModuleMXBean.class);
- ObjectName reconnectObjectName = TimedReconnectStrategyModuleTest.createInstance(transaction, reconnectModueName, "session-reconnect-strategy", 100, 1000L, new BigDecimal(1.0), 5000L, 2000L, null);
- mxBean.setSessionReconnectStrategy(reconnectObjectName);
- mxBean.setDataProvider(createDataBrokerInstance(transaction, bindingDataModuleName, "data-broker-impl", domBrokerModuleName, dataStroreModuleName));
- ObjectName reconnectStrategyON = TimedReconnectStrategyModuleTest.createInstance(transaction, reconnectModueName, "tcp-reconnect-strategy", 100, 1000L, new BigDecimal(1.0), 5000L, 2000L, null);
- mxBean.setTcpReconnectStrategy(reconnectStrategyON);
- mxBean.setBgpDispatcher(BGPDispatcherImplModuleTest.createInstance(transaction, dispatcherModuleName, "bgp-dispatcher"));
- mxBean.setExtensions(createRibExtensionsInstance(transaction, ribExtensionsModuleName, "rib-extensions-privider1"));
- mxBean.setRibId(new RibId("test"));
- mxBean.setLocalAs(5000L);
- mxBean.setBgpId(new Ipv4Address("192.168.1.1"));
- return nameCreated;
- }
-
- public static ObjectName createDataBrokerInstance(final ConfigTransactionJMXClient transaction, final String moduleName,
- final String instanceName, final String domBrokerModuleName, final String dataStroreModuleName) throws
- InstanceAlreadyExistsException, InstanceNotFoundException {
- ObjectName nameCreated = transaction.createModule(
- moduleName, instanceName);
- DataBrokerImplModuleMXBean mxBean = transaction.newMBeanProxy(
- nameCreated, DataBrokerImplModuleMXBean.class);
- mxBean.setDomBroker(createDomBrokerInstance(transaction, domBrokerModuleName, "dom-broker1", dataStroreModuleName));
- mxBean.setMappingService(lookupMappingServiceInstance(transaction));
- return nameCreated;
- }
-
- public static ObjectName createDomBrokerInstance(final ConfigTransactionJMXClient transaction, final String moduleName,
- final String instanceName, final String dataStroreModuleName) throws InstanceAlreadyExistsException {
- ObjectName nameCreated = transaction.createModule(
- moduleName, instanceName);
- DomBrokerImplModuleMXBean mxBean = transaction.newMBeanProxy(
- nameCreated, DomBrokerImplModuleMXBean.class);
- mxBean.setDataStore(createDataStoreInstance(transaction, dataStroreModuleName, "has-map-data-strore-instance"));
- return nameCreated;
- }
-
- public static ObjectName createDataStoreInstance(final ConfigTransactionJMXClient transaction, final String moduleName,
- final String instanceName) throws InstanceAlreadyExistsException {
- ObjectName nameCreated = transaction.createModule(
- moduleName, instanceName);
- transaction.newMBeanProxy(
- nameCreated, HashMapDataStoreModuleMXBean.class);
- return nameCreated;
- }
-
- public static ObjectName lookupMappingServiceInstance(final ConfigTransactionJMXClient transaction) {
-
- try {
- return transaction.lookupConfigBean(RuntimeMappingModuleFactory.NAME, RuntimeMappingModuleFactory.SINGLETON_NAME);
- } catch (InstanceNotFoundException e) {
- try {
- return transaction.createModule(RuntimeMappingModuleFactory.NAME, RuntimeMappingModuleFactory.SINGLETON_NAME);
- } catch (InstanceAlreadyExistsException e1) {
- throw new IllegalStateException(e1);
- }
- }
- }
-
- public static ObjectName createRibExtensionsInstance(final ConfigTransactionJMXClient transaction, final String moduleName,
- final String instanceName) throws InstanceAlreadyExistsException {
- ObjectName nameCreated = transaction.createModule(
- moduleName, instanceName);
- transaction.newMBeanProxy(
- nameCreated, RIBExtensionsImplModuleMXBean.class);
- return nameCreated;
- }
-
- public SchemaContext getMockedSchemaContext() {
- List<String> paths = Arrays.asList("/META-INF/yang/bgp-rib.yang", "/META-INF/yang/ietf-inet-types.yang",
- "/META-INF/yang/bgp-message.yang", "/META-INF/yang/bgp-multiprotocol.yang", "/META-INF/yang/bgp-types.yang");
- return YangParserWrapper.parseYangFiles(getFilesAsInputStreams(paths));
- }
+ Mockito.doNothing().when(mockedContext).addServiceListener(any(ServiceListener.class), Mockito.anyString());
+
+ Mockito.doNothing().when(mockedContext).addBundleListener(any(BundleListener.class));
+
+ Mockito.doReturn(new Bundle[] {}).when(mockedContext).getBundles();
+
+ Mockito.doReturn(new ServiceReference[] {}).when(mockedContext)
+ .getServiceReferences(Matchers.anyString(), Matchers.anyString());
+
+ ServiceReference<?> emptyServiceReference = mock(ServiceReference.class, "Empty");
+
+ ServiceReference<?> dataProviderServiceReference = mock(ServiceReference.class, "Data Provider");
+
+ Mockito.doReturn(mockedFilter).when(mockedContext).createFilter(Mockito.anyString());
+
+ Mockito.doNothing().when(mockedContext).addServiceListener(any(ServiceListener.class), Mockito.anyString());
+
+ Mockito.doNothing().when(mockedContext).addBundleListener(any(BundleListener.class));
+
+ Mockito.doReturn(new Bundle[] {}).when(mockedContext).getBundles();
+
+ Mockito.doReturn(new ServiceReference[] {}).when(mockedContext)
+ .getServiceReferences(Matchers.anyString(), Matchers.anyString());
+
+ // mockedDataProvider = mock(DataProviderService.class);
+
+ Mockito.doReturn("Empty reference").when(emptyServiceReference).toString();
+ Mockito.doReturn("Data Provider Service Reference").when(dataProviderServiceReference).toString();
+ //
+ Mockito.doReturn(emptyServiceReference).when(mockedContext).getServiceReference(any(Class.class));
+ Mockito.doReturn(dataProviderServiceReference).when(mockedContext)
+ .getServiceReference(DataProviderService.class);
+
+ Mockito.doReturn(mockedDataProvider).when(mockedContext).getService(dataProviderServiceReference);
+
+ // Mockito.doReturn(null).when(mockedContext).getService(dataProviderServiceReference);
+ Mockito.doReturn(null).when(mockedContext).getService(emptyServiceReference);
+
+ Registration<DataCommitHandler<InstanceIdentifier, CompositeNode>> registration = mock(Registration.class);
+ Mockito.doReturn(registration).when(mockedDataProvider)
+ .registerCommitHandler(any(InstanceIdentifier.class), any(DataCommitHandler.class));
+ Mockito.doReturn(registration).when(mockedDataProvider)
+ .registerCommitHandler(any(InstanceIdentifier.class), any(DataCommitHandler.class));
+
+ Mockito.doReturn(null).when(mockedDataProvider).readOperationalData(any(InstanceIdentifier.class));
+ Mockito.doReturn(mockedTransaction).when(mockedDataProvider).beginTransaction();
+
+ Mockito.doNothing().when(mockedTransaction)
+ .putOperationalData(any(InstanceIdentifier.class), any(CompositeNode.class));
+ Mockito.doNothing().when(mockedTransaction).removeOperationalData(any(InstanceIdentifier.class));
+
+ Mockito.doReturn(mockedFuture).when(mockedTransaction).commit();
+ Mockito.doReturn(TRANSACTION_NAME).when(mockedTransaction).getIdentifier();
+
+ Mockito.doReturn(mockedResult).when(mockedFuture).get();
+ Mockito.doReturn(true).when(mockedResult).isSuccessful();
+ Mockito.doReturn(Collections.emptySet()).when(mockedResult).getErrors();
+ }
+
+ protected List<ModuleFactory> getModuleFactories() {
+ return Lists.newArrayList(new RIBImplModuleFactory(), new DataBrokerImplModuleFactory(),
+ new GlobalEventExecutorModuleFactory(), new BGPDispatcherImplModuleFactory(),
+ new NettyThreadgroupModuleFactory(), new TimedReconnectStrategyModuleFactory(),
+ new SimpleBGPExtensionProviderContextModuleFactory(), new RIBExtensionsImplModuleFactory(),
+ new DomBrokerImplModuleFactory(), new RuntimeMappingModuleFactory(),
+ new HashMapDataStoreModuleFactory(), new HashedWheelTimerModuleFactory());
+ }
+
+ @Override
+ protected BundleContextServiceRegistrationHandler getBundleContextServiceRegistrationHandler(
+ final Class<?> serviceType) {
+ if (serviceType.equals(SchemaServiceListener.class)) {
+ return new BundleContextServiceRegistrationHandler() {
+ @Override
+ public void handleServiceRegistration(final Object o) {
+ SchemaServiceListener listener = (SchemaServiceListener) o;
+ listener.onGlobalContextUpdated(getMockedSchemaContext());
+ }
+ };
+ }
+
+ return super.getBundleContextServiceRegistrationHandler(serviceType);
+ }
+
+ @Test
+ public void testValidationExceptionRibIdNotSet() throws Exception {
+ try {
+ createInstance(null, 500L, new Ipv4Address(BGP_ID));
+ fail();
+ } catch (ValidationException e) {
+ assertTrue(e.getMessage().contains("RibId is not set."));
+ }
+ }
+
+ @Test
+ public void testValidationExceptionLocalAsNotSet() throws Exception {
+ try {
+ createInstance(new RibId(RIB_ID), null, new Ipv4Address(BGP_ID));
+ fail();
+ } catch (ValidationException e) {
+ assertTrue(e.getMessage().contains("LocalAs is not set."));
+ }
+ }
+
+ @Test
+ public void testValidationExceptionBgpIdNotSet() throws Exception {
+ try {
+ createInstance(new RibId(RIB_ID), 500L, null);
+ fail();
+ } catch (ValidationException e) {
+ assertTrue(e.getMessage().contains("BgpId is not set."));
+ }
+ }
+
+ @Test
+ public void testCreateBean() throws Exception {
+ CommitStatus status = createInstance();
+ Thread.sleep(2000);
+ assertBeanCount(1, FACTORY_NAME);
+ assertStatus(status, 14, 0, 0);
+ }
+
+ @Test
+ public void testReusingOldInstance() throws Exception {
+ createInstance();
+ Thread.sleep(2000);
+ ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
+ assertBeanCount(1, FACTORY_NAME);
+ CommitStatus status = transaction.commit();
+ assertBeanCount(1, FACTORY_NAME);
+ assertStatus(status, 0, 0, 14);
+ }
+
+ @Test
+ public void testReconfigure() throws Exception {
+ createInstance();
+ Thread.sleep(2000);
+ final ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
+ assertBeanCount(1, FACTORY_NAME);
+ final RIBImplModuleMXBean mxBean = transaction.newMBeanProxy(
+ transaction.lookupConfigBean(FACTORY_NAME, INSTANCE_NAME), RIBImplModuleMXBean.class);
+ mxBean.setLocalAs(100L);
+ final CommitStatus status = transaction.commit();
+ assertBeanCount(1, FACTORY_NAME);
+ assertStatus(status, 0, 1, 13);
+ }
+
+ @After
+ public void closeAllModules() throws Exception {
+ super.destroyAllConfigBeans();
+ }
+
+ private CommitStatus createInstance() throws Exception {
+ ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
+ createInstance(transaction);
+ return transaction.commit();
+ }
+
+ private CommitStatus createInstance(final RibId ribId, final Long localAs, final Ipv4Address bgpId)
+ throws Exception {
+ ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
+ createInstance(transaction, ribId, localAs, bgpId);
+ return transaction.commit();
+ }
+
+ private static ObjectName createInstance(final ConfigTransactionJMXClient transaction, final RibId ribId,
+ final Long localAs, final Ipv4Address bgpId) throws Exception {
+ ObjectName nameCreated = transaction.createModule(RIBImplModuleFactory.NAME, INSTANCE_NAME);
+ RIBImplModuleMXBean mxBean = transaction.newMXBeanProxy(nameCreated, RIBImplModuleMXBean.class);
+ ObjectName reconnectObjectName = TimedReconnectStrategyModuleTest.createInstance(transaction,
+ SESSION_RS_INSTANCE_NAME);
+ mxBean.setSessionReconnectStrategy(reconnectObjectName);
+ mxBean.setDataProvider(createDataBrokerInstance(transaction));
+ ObjectName reconnectStrategyON = TimedReconnectStrategyModuleTest.createInstance(transaction,
+ TCP_RS_INSTANCE_NAME);
+ mxBean.setTcpReconnectStrategy(reconnectStrategyON);
+ mxBean.setBgpDispatcher(BGPDispatcherImplModuleTest.createInstance(transaction));
+ mxBean.setExtensions(createRibExtensionsInstance(transaction));
+ mxBean.setRibId(ribId);
+ mxBean.setLocalAs(localAs);
+ mxBean.setBgpId(bgpId);
+ return nameCreated;
+ }
+
+ public static ObjectName createInstance(final ConfigTransactionJMXClient transaction) throws Exception {
+ return createInstance(transaction, new RibId(RIB_ID), 5000L, new Ipv4Address(BGP_ID));
+ }
+
+ private static ObjectName createDataBrokerInstance(final ConfigTransactionJMXClient transaction)
+ throws InstanceAlreadyExistsException, InstanceNotFoundException {
+ ObjectName nameCreated = transaction.createModule(DataBrokerImplModuleFactory.NAME, DATA_BROKER_INSTANCE_NAME);
+ DataBrokerImplModuleMXBean mxBean = transaction.newMBeanProxy(nameCreated, DataBrokerImplModuleMXBean.class);
+ mxBean.setDomBroker(createDomBrokerInstance(transaction));
+ mxBean.setMappingService(lookupMappingServiceInstance(transaction));
+ return nameCreated;
+ }
+
+ private static ObjectName createDomBrokerInstance(final ConfigTransactionJMXClient transaction)
+ throws InstanceAlreadyExistsException {
+ ObjectName nameCreated = transaction.createModule(DomBrokerImplModuleFactory.NAME, DOM_BROKER_INSTANCE_NAME);
+ DomBrokerImplModuleMXBean mxBean = transaction.newMBeanProxy(nameCreated, DomBrokerImplModuleMXBean.class);
+ mxBean.setDataStore(createDataStoreInstance(transaction));
+ return nameCreated;
+ }
+
+ private static ObjectName createDataStoreInstance(final ConfigTransactionJMXClient transaction)
+ throws InstanceAlreadyExistsException {
+ ObjectName nameCreated = transaction.createModule(HashMapDataStoreModuleFactory.NAME, DATA_STORE_INSTANCE_NAME);
+ transaction.newMBeanProxy(nameCreated, HashMapDataStoreModuleMXBean.class);
+ return nameCreated;
+ }
+
+ private static ObjectName lookupMappingServiceInstance(final ConfigTransactionJMXClient transaction) {
+
+ try {
+ return transaction.lookupConfigBean(RuntimeMappingModuleFactory.NAME,
+ RuntimeMappingModuleFactory.SINGLETON_NAME);
+ } catch (InstanceNotFoundException e) {
+ try {
+ return transaction.createModule(RuntimeMappingModuleFactory.NAME,
+ RuntimeMappingModuleFactory.SINGLETON_NAME);
+ } catch (InstanceAlreadyExistsException e1) {
+ throw new IllegalStateException(e1);
+ }
+ }
+ }
+
+ private static ObjectName createRibExtensionsInstance(final ConfigTransactionJMXClient transaction)
+ throws InstanceAlreadyExistsException {
+ ObjectName nameCreated = transaction.createModule(RIBExtensionsImplModuleFactory.NAME,
+ RIB_EXTENSIONS_INSTANCE_NAME);
+ transaction.newMBeanProxy(nameCreated, RIBExtensionsImplModuleMXBean.class);
+ return nameCreated;
+ }
+
+ public SchemaContext getMockedSchemaContext() {
+ List<String> paths = Arrays.asList("/META-INF/yang/bgp-rib.yang", "/META-INF/yang/ietf-inet-types.yang",
+ "/META-INF/yang/bgp-message.yang", "/META-INF/yang/bgp-multiprotocol.yang",
+ "/META-INF/yang/bgp-types.yang");
+ return YangParserWrapper.parseYangFiles(getFilesAsInputStreams(paths));
+ }
}
return super.createClient(address, strategy, new PipelineInitializer<BGPSessionImpl>() {
@Override
public void initializeChannel(final SocketChannel ch, final Promise<BGPSessionImpl> promise) {
- ch.pipeline().addLast(hf.getDecoders());
+ ch.pipeline().addLast(BGPDispatcherImpl.this.hf.getDecoders());
ch.pipeline().addLast("negotiator", snf.getSessionNegotiator(slf, ch, promise));
- ch.pipeline().addLast(hf.getEncoders());
+ ch.pipeline().addLast(BGPDispatcherImpl.this.hf.getEncoders());
}
});
}
public Future<Void> createReconnectingClient(final InetSocketAddress address,
final BGPSessionPreferences preferences, final AsNumber remoteAs,
final BGPSessionListener listener, final ReconnectStrategyFactory connectStrategyFactory,
- final ReconnectStrategy reestablishStrategy) {
+ final ReconnectStrategyFactory reestablishStrategyFactory) {
final BGPSessionNegotiatorFactory snf = new BGPSessionNegotiatorFactory(this.timer, preferences, remoteAs);
final SessionListenerFactory<BGPSessionListener> slf = new SessionListenerFactory<BGPSessionListener>() {
@Override
}
};
- return super.createReconnectingClient(address, connectStrategyFactory, reestablishStrategy, new PipelineInitializer<BGPSessionImpl>() {
+ return super.createReconnectingClient(address, connectStrategyFactory, reestablishStrategyFactory.createReconnectStrategy(), new PipelineInitializer<BGPSessionImpl>() {
@Override
public void initializeChannel(final SocketChannel ch, final Promise<BGPSessionImpl> promise) {
- ch.pipeline().addLast(hf.getDecoders());
+ ch.pipeline().addLast(BGPDispatcherImpl.this.hf.getDecoders());
ch.pipeline().addLast("negotiator", snf.getSessionNegotiator(slf, ch, promise));
- ch.pipeline().addLast(hf.getEncoders());
+ ch.pipeline().addLast(BGPDispatcherImpl.this.hf.getEncoders());
}
});
}
final AsNumber remoteAs, final RIB rib) {
this.rib = Preconditions.checkNotNull(rib);
this.name = Preconditions.checkNotNull(name);
- cf = rib.getDispatcher().createReconnectingClient(address, prefs, remoteAs, this, rib.getTcpStrategyFactory(), rib.getSessionStrategy());
+ this.cf = rib.getDispatcher().createReconnectingClient(address, prefs, remoteAs, this, rib.getTcpStrategyFactory(), rib.getSessionStrategyFactory());
}
@Override
public synchronized void close() {
- if (cf != null) {
- cf.cancel(true);
- if (session != null) {
- session.close();
- session = null;
+ if (this.cf != null) {
+ this.cf.cancel(true);
+ if (this.session != null) {
+ this.session.close();
+ this.session = null;
}
- cf = null;
+ this.cf = null;
}
}
LOG.info("Session with peer {} went up with tables: {}", this.name, session.getAdvertisedTableTypes());
this.session = session;
- this.comparator = new BGPObjectComparator(rib.getLocalAs(), rib.getBgpIdentifier(), session.getBgpId());
+ this.comparator = new BGPObjectComparator(this.rib.getLocalAs(), this.rib.getBgpIdentifier(), session.getBgpId());
for (final BgpTableType t : session.getAdvertisedTableTypes()) {
final TablesKey key = new TablesKey(t.getAfi(), t.getSafi());
@Override
public String getName() {
- return name;
+ return this.name;
}
@Override
import org.opendaylight.protocol.bgp.rib.spi.AdjRIBsIn;
import org.opendaylight.protocol.bgp.rib.spi.Peer;
import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionConsumerContext;
-import org.opendaylight.protocol.framework.ReconnectStrategy;
import org.opendaylight.protocol.framework.ReconnectStrategyFactory;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
private static final Update EOR = new UpdateBuilder().build();
private static final TablesKey IPV4_UNICAST_TABLE = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
private final ReconnectStrategyFactory tcpStrategyFactory;
- private final ReconnectStrategy sessionStrategy;
+ private final ReconnectStrategyFactory sessionStrategyFactory;
private final BGPDispatcher dispatcher;
private final DataProviderService dps;
private final AsNumber localAs;
private final RIBTables tables;
public RIBImpl(final RibId ribId, final AsNumber localAs, final Ipv4Address localBgpId, final RIBExtensionConsumerContext extensions,
- final BGPDispatcher dispatcher, final ReconnectStrategyFactory tcpStrategyFactory, final ReconnectStrategy sessionStrategy,
+ final BGPDispatcher dispatcher, final ReconnectStrategyFactory tcpStrategyFactory, final ReconnectStrategyFactory sessionStrategyFactory,
final DataProviderService dps, final List<BgpTableType> localTables) {
super(InstanceIdentifier.builder(BgpRib.class).child(Rib.class, new RibKey(Preconditions.checkNotNull(ribId))).toInstance());
this.dps = Preconditions.checkNotNull(dps);
this.localAs = Preconditions.checkNotNull(localAs);
this.bgpIdentifier = Preconditions.checkNotNull(localBgpId);
this.dispatcher = Preconditions.checkNotNull(dispatcher);
- this.sessionStrategy = Preconditions.checkNotNull(sessionStrategy);
+ this.sessionStrategyFactory = Preconditions.checkNotNull(sessionStrategyFactory);
this.tcpStrategyFactory = Preconditions.checkNotNull(tcpStrategyFactory);
this.localTables = ImmutableList.copyOf(localTables);
this.tables = new RIBTables(extensions);
for (BgpTableType t : localTables) {
final TablesKey key = new TablesKey(t.getAfi(), t.getSafi());
- if (tables.create(trans, this, key) == null) {
+ if (this.tables.create(trans, this, key) == null) {
LOG.debug("Did not create local table for unhandled table type {}", t);
}
}
@Override
public AsNumber getLocalAs() {
- return localAs;
+ return this.localAs;
}
@Override
public Ipv4Address getBgpIdentifier() {
- return bgpIdentifier;
+ return this.bgpIdentifier;
}
@Override
public List<? extends BgpTableType> getLocalTables() {
- return localTables;
+ return this.localTables;
}
@Override
public ReconnectStrategyFactory getTcpStrategyFactory() {
- return tcpStrategyFactory;
+ return this.tcpStrategyFactory;
}
@Override
- public ReconnectStrategy getSessionStrategy() {
- return sessionStrategy;
+ public ReconnectStrategyFactory getSessionStrategyFactory() {
+ return this.sessionStrategyFactory;
}
@Override
public BGPDispatcher getDispatcher() {
- return dispatcher;
+ return this.dispatcher;
}
@Override
BGPSessionListener listener, ReconnectStrategy strategy);
Future<Void> createReconnectingClient(InetSocketAddress address, BGPSessionPreferences preferences, AsNumber remoteAs,
- BGPSessionListener listener, ReconnectStrategyFactory connectStrategyFactory, ReconnectStrategy reestablishStrategy);
+ BGPSessionListener listener, ReconnectStrategyFactory connectStrategyFactory, ReconnectStrategyFactory reestablishStrategyFactory);
}
import java.util.List;
import org.opendaylight.protocol.bgp.rib.spi.Peer;
-import org.opendaylight.protocol.framework.ReconnectStrategy;
import org.opendaylight.protocol.framework.ReconnectStrategyFactory;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
BGPDispatcher getDispatcher();
ReconnectStrategyFactory getTcpStrategyFactory();
- ReconnectStrategy getSessionStrategy();
+ ReconnectStrategyFactory getSessionStrategyFactory();
}
</directory>
<excludes>
<exclude>version.properties</exclude>
+ <exclude>configuration/config.ini</exclude>
</excludes>
<outputDirectory>
opendaylight/
<outputDirectory>opendaylight</outputDirectory>
<filtered>true</filtered>
</file>
+ <file>
+ <source>src/main/resources/configuration/config.ini</source>
+ <outputDirectory>opendaylight/configuration</outputDirectory>
+ <filtered>true</filtered>
+ </file>
</files>
</assembly>
reference\:file\:../lib/slf4j-api-1.7.2.jar@1:start,\
reference\:file\:../lib/logback-classic-1.0.9.jar@1:start,\
reference\:file\:../lib/logback-core-1.0.9.jar@1:start,\
- reference\:file\:../lib/logging.bridge-0.4.2@1:start,\
+ reference\:file\:../lib/logging.bridge-${controller.version}@1:start,\
reference\:file\:../lib/jersey-core-1.17.jar@2:start,\
reference\:file\:../lib/jersey-server-1.17.jar@2:start
ret.add(mavenBundle("com.google.guava", "guava").versionAsInProject());
ret.add(mavenBundle("commons-codec", "commons-codec").versionAsInProject());
ret.add(mavenBundle("org.apache.commons", "commons-lang3").versionAsInProject());
+ ret.add(mavenBundle("commons-io", "commons-io").versionAsInProject());
ret.add(TestHelper.getNettyBundles());
ret.add(TestHelper.getLoggingBundles());
import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionProviderContext;
import org.opendaylight.protocol.bgp.rib.spi.SimpleRIBExtensionProviderContext;
import org.opendaylight.protocol.bgp.util.HexDumpBGPFileParser;
-import org.opendaylight.protocol.framework.ReconnectStrategy;
import org.opendaylight.protocol.framework.ReconnectStrategyFactory;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
ReconnectStrategyFactory tcpStrategyFactory;
@Mock
- ReconnectStrategy sessionStrategy;
+ ReconnectStrategyFactory sessionStrategy;
@Before
public void setUp() throws Exception {
}).when(this.mockedTransaction).readOperationalData(Matchers.any(InstanceIdentifier.class));
- Mockito.doReturn(GlobalEventExecutor.INSTANCE.newSucceededFuture(null)).when(dispatcher).
+ Mockito.doReturn(GlobalEventExecutor.INSTANCE.newSucceededFuture(null)).when(this.dispatcher).
createReconnectingClient(Mockito.any(InetSocketAddress.class), Mockito.any(BGPSessionPreferences.class), Mockito.any(AsNumber.class),
- Mockito.any(BGPSessionListener.class), Mockito.eq(tcpStrategyFactory), Mockito.eq(sessionStrategy));
+ Mockito.any(BGPSessionListener.class), Mockito.eq(this.tcpStrategyFactory), Mockito.eq(this.sessionStrategy));
- ext = new SimpleRIBExtensionProviderContext();
- baseact = new RIBActivator();
- lsact = new org.opendaylight.protocol.bgp.linkstate.RIBActivator();
+ this.ext = new SimpleRIBExtensionProviderContext();
+ this.baseact = new RIBActivator();
+ this.lsact = new org.opendaylight.protocol.bgp.linkstate.RIBActivator();
- baseact.startRIBExtensionProvider(ext);
- lsact.startRIBExtensionProvider(ext);
+ this.baseact.startRIBExtensionProvider(this.ext);
+ this.lsact.startRIBExtensionProvider(this.ext);
}
@After
public void tearDown() {
- lsact.close();
- baseact.close();
+ this.lsact.close();
+ this.baseact.close();
}
private void runTestWithTables(final List<BgpTableType> tables) {
- final RIBImpl rib = new RIBImpl(new RibId("testRib"), new AsNumber(72L), new Ipv4Address("127.0.0.1"), ext,
+ final RIBImpl rib = new RIBImpl(new RibId("testRib"), new AsNumber(72L), new Ipv4Address("127.0.0.1"), this.ext,
this.dispatcher, this.tcpStrategyFactory, this.sessionStrategy, this.providerService, tables);
final BGPPeer peer = new BGPPeer("peer-" + this.mock.toString(), null, null, rib.getLocalAs(), rib);
public enum TerminationReason {
Unknown((short) 1), ExpDeadtimer((short) 2), MalformedMsg((short) 3), TooManyUnknownReqRep((short) 4), TooManyUnknownMsg((short) 5);
- short value;
- static Map<Short, TerminationReason> valueMap;
+ private short value;
+ private static final Map<Short, TerminationReason> valueMap;
static {
valueMap = Maps.newHashMap();
*/
package org.opendaylight.protocol.pcep.crabbe.initiated00;
+import org.opendaylight.protocol.pcep.impl.tlv.TlvUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.TlvParser;
import org.opendaylight.protocol.pcep.spi.TlvSerializer;
@Override
public byte[] serializeTlv(final Tlv tlv) {
- return ByteArray.intToBytes(((LspCleanup) tlv).getTimeout().intValue());
+ return TlvUtil.formatTlv(TYPE, ByteArray.intToBytes(((LspCleanup) tlv).getTimeout().intValue()));
}
@Override
package org.opendaylight.protocol.pcep.crabbe.initiated00;
import org.opendaylight.protocol.pcep.ietf.stateful02.Stateful02OpenObjectParser;
-import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated._00.rev140113.Tlvs1;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated._00.rev140113.Tlvs1Builder;
*/
public final class PCEPOpenObjectParser extends Stateful02OpenObjectParser {
- public PCEPOpenObjectParser(final TlvHandlerRegistry tlvReg) {
+ public PCEPOpenObjectParser(final TlvRegistry tlvReg) {
super(tlvReg);
}
import java.util.BitSet;
import org.opendaylight.protocol.pcep.ietf.stateful02.Stateful02StatefulCapabilityTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.TlvUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated._00.rev140113.Stateful1;
if (sct.isIncludeDbVersion() != null && sct.isIncludeDbVersion()) {
flags.set(S_FLAG_OFFSET, sct.isIncludeDbVersion());
}
- return ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH);
+ return TlvUtil.formatTlv(TYPE, ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH));
}
}
\ No newline at end of file
import java.math.BigInteger;
+import org.opendaylight.protocol.pcep.impl.tlv.TlvUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.TlvParser;
import org.opendaylight.protocol.pcep.spi.TlvSerializer;
public byte[] serializeTlv(final Tlv tlv) {
Preconditions.checkNotNull(tlv, "LspDbVersionTlv is mandatory.");
final LspDbVersion lsp = (LspDbVersion) tlv;
- return ByteArray.longToBytes(lsp.getVersion().longValue(), DBV_F_LENGTH);
+ return TlvUtil.formatTlv(TYPE, ByteArray.longToBytes(lsp.getVersion().longValue(), DBV_F_LENGTH));
}
@Override
import org.opendaylight.protocol.pcep.spi.AbstractObjectWithTlvsParser;
import org.opendaylight.protocol.pcep.spi.ObjectUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.PlspId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.lsp.db.version.tlv.LspDbVersion;
private static final int REMOVE_FLAG_OFFSET = 12;
private static final int OPERATIONAL_FLAG_OFFSET = 13;
- public Stateful02LspObjectParser(final TlvHandlerRegistry tlvReg) {
+ public Stateful02LspObjectParser(final TlvRegistry tlvReg) {
super(tlvReg);
}
*/
package org.opendaylight.protocol.pcep.ietf.stateful02;
+import org.opendaylight.protocol.pcep.impl.tlv.TlvUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.TlvParser;
import org.opendaylight.protocol.pcep.spi.TlvSerializer;
throw new IllegalArgumentException("SymbolicPathNameTlv is mandatory.");
}
final SymbolicPathName spn = (SymbolicPathName) tlv;
- return spn.getPathName().getValue();
+ return TlvUtil.formatTlv(TYPE, spn.getPathName().getValue());
}
@Override
package org.opendaylight.protocol.pcep.ietf.stateful02;
import org.opendaylight.protocol.pcep.impl.object.PCEPLspaObjectParser;
-import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated._00.rev140113.Tlvs2;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated._00.rev140113.Tlvs2Builder;
*/
public class Stateful02LspaObjectParser extends PCEPLspaObjectParser {
- public Stateful02LspaObjectParser(final TlvHandlerRegistry tlvReg) {
+ public Stateful02LspaObjectParser(final TlvRegistry tlvReg) {
super(tlvReg);
}
*/
package org.opendaylight.protocol.pcep.ietf.stateful02;
+import org.opendaylight.protocol.pcep.impl.tlv.TlvUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.TlvParser;
import org.opendaylight.protocol.pcep.spi.TlvSerializer;
@Override
public byte[] serializeTlv(final Tlv tlv) {
- return ((NodeIdentifier) tlv).getValue();
+ return TlvUtil.formatTlv(TYPE, ((NodeIdentifier) tlv).getValue());
}
@Override
package org.opendaylight.protocol.pcep.ietf.stateful02;
import org.opendaylight.protocol.pcep.impl.object.PCEPOpenObjectParser;
-import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.Tlvs2;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.Tlvs2Builder;
*/
public class Stateful02OpenObjectParser extends PCEPOpenObjectParser {
- public Stateful02OpenObjectParser(final TlvHandlerRegistry tlvReg) {
+ public Stateful02OpenObjectParser(final TlvRegistry tlvReg) {
super(tlvReg);
}
import org.opendaylight.protocol.concepts.Ipv4Util;
import org.opendaylight.protocol.concepts.Ipv6Util;
+import org.opendaylight.protocol.pcep.impl.tlv.TlvUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.TlvParser;
import org.opendaylight.protocol.pcep.spi.TlvSerializer;
if (rsvp.getErrorType().getImplementedInterface().equals(RsvpCase.class)) {
final RsvpCase r = (RsvpCase) rsvp.getErrorType();
- return serializeRsvp(r.getRsvpError());
+ return TlvUtil.formatTlv(TYPE, serializeRsvp(r.getRsvpError()));
} else {
final UserCase u = (UserCase) rsvp.getErrorType();
- return serializerUserError(u.getUserError());
+ return TlvUtil.formatTlv(TYPE, serializerUserError(u.getUserError()));
}
}
final byte descLen = UnsignedBytes.checkedCast(desc.length);
// if we have any subobjects, place the implementation here
final byte[] bytes = new byte[2 + ENTERPRISE_F_LENGTH + SUB_ORG_F_LENGTH + USER_VALUE_F_LENGTH + ERR_DESCR_LENGTH_F_LENGTH
- + desc.length];
+ + desc.length];
bytes[0] = UnsignedBytes.checkedCast(USER_ERROR_CLASS_NUM);
bytes[1] = UnsignedBytes.checkedCast(USER_ERROR_CLASS_TYPE);
int offset = 2;
import java.util.BitSet;
+import org.opendaylight.protocol.pcep.impl.tlv.TlvUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.TlvParser;
import org.opendaylight.protocol.pcep.spi.TlvSerializer;
final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
flags.set(U_FLAG_OFFSET, sct.isLspUpdateCapability());
flags.set(S_FLAG_OFFSET, sct.isIncludeDbVersion());
- return ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH);
+ return TlvUtil.formatTlv(TYPE, ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH));
}
@Override
import org.opendaylight.protocol.pcep.ietf.stateful02.Stateful02LspaObjectParser;
import org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.protocol.pcep.spi.pojo.ServiceLoaderPCEPExtensionProviderContext;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated._00.rev140113.Stateful1;
public class PCEPObjectParserTest {
- private TlvHandlerRegistry tlvRegistry;
+ private TlvRegistry tlvRegistry;
@Before
public void setUp() throws Exception {
import org.opendaylight.protocol.pcep.ietf.stateful02.Stateful02RSVPErrorSpecTlvParser;
import org.opendaylight.protocol.pcep.ietf.stateful02.Stateful02StatefulCapabilityTlvParser;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
+import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.lsp.db.version.tlv.LspDbVersion;
public class PCEPTlvParserTest {
- private static final byte[] statefulBytes = { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01 };
- private static final byte[] symbolicNameBytes = { (byte) 0x4d, (byte) 0x65, (byte) 0x64, (byte) 0x20, (byte) 0x74, (byte) 0x65,
- (byte) 0x73, (byte) 0x74, (byte) 0x20, (byte) 0x6f, (byte) 0x66, (byte) 0x20, (byte) 0x73, (byte) 0x79, (byte) 0x6d,
- (byte) 0x62, (byte) 0x6f, (byte) 0x6c, (byte) 0x69, (byte) 0x63, (byte) 0x20, (byte) 0x6e, (byte) 0x61, (byte) 0x6d,
- (byte) 0x65 };
- private static final byte[] rsvpErrorBytes = { (byte) 0x06, (byte) 0x01, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
- (byte) 0x02, (byte) 0x92, (byte) 0x16, (byte) 0x02 };
- private static final byte[] rsvpError6Bytes = { (byte) 0x06, (byte) 0x02, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
- (byte) 0x9a, (byte) 0xbc, (byte) 0xde, (byte) 0xf0, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9a,
- (byte) 0xbc, (byte) 0xde, (byte) 0xf0, (byte) 0x02, (byte) 0xd5, (byte) 0xc5, (byte) 0xd9 };
- private static final byte[] userErrorBytes = { (byte) 0xc2, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x30, (byte) 0x39,
- (byte) 0x05, (byte) 0x09, (byte) 0x00, (byte) 0x26, (byte) 0x75, (byte) 0x73, (byte) 0x65, (byte) 0x72, (byte) 0x20,
- (byte) 0x64, (byte) 0x65, (byte) 0x73, (byte) 0x63 };
- private static final byte[] lspDbBytes = { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
- (byte) 0xb4 };
+ private static final byte[] statefulBytes = { 0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01 };
+ private static final byte[] symbolicNameBytes = { 0x00, 0x11, 0x00, 0x19, 0x4d, 0x65, 0x64, 0x20, 0x74, 0x65,
+ 0x73, 0x74, 0x20, 0x6f, 0x66, 0x20, 0x73, 0x79, 0x6d, 0x62, 0x6f, 0x6c, 0x69, 0x63, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x00, 0x00, 0x00 };
+ private static final byte[] rsvpErrorBytes = { 0x00, 0x15, 0x00, 0x0a, 0x06, 0x01, 0x12, 0x34, 0x56, 0x78, 0x02, (byte) 0x92, 0x16, 0x02, 0x00, 0x00 };
+ private static final byte[] rsvpError6Bytes = { 0x00, 0x15, 0x00, 0x16, 0x06, 0x02, 0x12, 0x34, 0x56, 0x78,
+ (byte) 0x9a, (byte) 0xbc, (byte) 0xde, (byte) 0xf0, 0x12, 0x34, 0x56, 0x78, (byte) 0x9a,
+ (byte) 0xbc, (byte) 0xde, (byte) 0xf0, 0x02, (byte) 0xd5, (byte) 0xc5, (byte) 0xd9, 0x00, 0x00 };
+ private static final byte[] userErrorBytes = { 0x00, 0x15, 0x00, 0x13, (byte) 0xc2, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x30, (byte) 0x39,
+ (byte) 0x05, (byte) 0x09, (byte) 0x00, (byte) 0x26, (byte) 0x75, (byte) 0x73, (byte) 0x65, (byte) 0x72, (byte) 0x20,
+ (byte) 0x64, (byte) 0x65, (byte) 0x73, (byte) 0x63, 0x00 };
+ private static final byte[] lspDbBytes = { 0x00, 0x17, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0xb4 };
@Test
public void testStatefulTlv() throws PCEPDeserializerException {
final Stateful02StatefulCapabilityTlvParser parser = new Stateful02StatefulCapabilityTlvParser();
final Stateful tlv = new StatefulBuilder().setLspUpdateCapability(Boolean.TRUE).setIncludeDbVersion(false).build();
- assertEquals(tlv, parser.parseTlv(statefulBytes));
+ assertEquals(tlv, parser.parseTlv(ByteArray.cutBytes(statefulBytes, 4)));
assertArrayEquals(statefulBytes, parser.serializeTlv(tlv));
}
final Stateful02LspSymbolicNameTlvParser parser = new Stateful02LspSymbolicNameTlvParser();
final SymbolicPathName tlv = new SymbolicPathNameBuilder().setPathName(
new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.SymbolicPathName("Med test of symbolic name".getBytes())).build();
- assertEquals(tlv, parser.parseTlv(symbolicNameBytes));
+ assertEquals(tlv, parser.parseTlv(ByteArray.subByte(symbolicNameBytes, 4, 25)));
assertArrayEquals(symbolicNameBytes, parser.serializeTlv(tlv));
}
builder.setCode((short) 146);
builder.setValue(5634);
final RsvpErrorSpec tlv = new RsvpErrorSpecBuilder().setErrorType(new RsvpCaseBuilder().setRsvpError(builder.build()).build()).build();
- assertEquals(tlv, parser.parseTlv(rsvpErrorBytes));
+ assertEquals(tlv, parser.parseTlv(ByteArray.subByte(rsvpErrorBytes, 4, 10)));
assertArrayEquals(rsvpErrorBytes, parser.serializeTlv(tlv));
}
builder.setCode((short) 213);
builder.setValue(50649);
final RsvpErrorSpec tlv = new RsvpErrorSpecBuilder().setErrorType(new RsvpCaseBuilder().setRsvpError(builder.build()).build()).build();
- assertEquals(tlv, parser.parseTlv(rsvpError6Bytes));
+ assertEquals(tlv, parser.parseTlv(ByteArray.subByte(rsvpError6Bytes, 4, 22)));
assertArrayEquals(rsvpError6Bytes, parser.serializeTlv(tlv));
}
builder.setValue(38);
builder.setDescription("user desc");
final RsvpErrorSpec tlv = new RsvpErrorSpecBuilder().setErrorType(new UserCaseBuilder().setUserError(builder.build()).build()).build();
- assertEquals(tlv, parser.parseTlv(userErrorBytes));
+ assertEquals(tlv, parser.parseTlv(ByteArray.subByte(userErrorBytes, 4, 19)));
assertArrayEquals(userErrorBytes, parser.serializeTlv(tlv));
}
public void testLspDbVersionTlv() throws PCEPDeserializerException {
final Stateful02LspDbVersionTlvParser parser = new Stateful02LspDbVersionTlvParser();
final LspDbVersion tlv = new LspDbVersionBuilder().setVersion(BigInteger.valueOf(180L)).build();
- assertEquals(tlv, parser.parseTlv(lspDbBytes));
+ assertEquals(tlv, parser.parseTlv(ByteArray.cutBytes(lspDbBytes, 4)));
assertArrayEquals(lspDbBytes, parser.serializeTlv(tlv));
}
import org.opendaylight.protocol.pcep.ietf.stateful07.Stateful07LspObjectParser;
import org.opendaylight.protocol.pcep.spi.ObjectUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.Lsp1;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.Lsp1Builder;
private static final int CREATE_FLAG_OFFSET = 8;
- public CInitiated00LspObjectParser(final TlvHandlerRegistry tlvReg) {
+ public CInitiated00LspObjectParser(final TlvRegistry tlvReg) {
super(tlvReg);
}
import org.opendaylight.protocol.pcep.ietf.stateful07.Stateful07SrpObjectParser;
import org.opendaylight.protocol.pcep.spi.ObjectUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.Srp1;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.Srp1Builder;
private static final int REMOVE_FLAG = 31;
- public CInitiated00SrpObjectParser(final TlvHandlerRegistry tlvReg) {
+ public CInitiated00SrpObjectParser(final TlvRegistry tlvReg) {
super(tlvReg);
}
import java.util.BitSet;
import org.opendaylight.protocol.pcep.ietf.stateful07.Stateful07StatefulCapabilityTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.TlvUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.Stateful1;
flags.set(I_FLAG_OFFSET, sfi.isInitiation());
}
flags.set(U_FLAG_OFFSET, sct.isLspUpdateCapability());
- return ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH);
+ return TlvUtil.formatTlv(TYPE, ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH));
}
}
import java.util.List;
import org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderContext;
-import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.protocol.pcep.spi.pojo.AbstractPCEPExtensionProviderActivator;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.Pcinitiate;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.Lsp;
new CInitiated00PCInitiateMessageParser(context.getObjectHandlerRegistry())));
regs.add(context.registerMessageSerializer(Pcinitiate.class, new CInitiated00PCInitiateMessageParser(context.getObjectHandlerRegistry())));
- final TlvHandlerRegistry tlvReg = context.getTlvHandlerRegistry();
+ final TlvRegistry tlvReg = context.getTlvHandlerRegistry();
regs.add(context.registerObjectParser(CInitiated00LspObjectParser.CLASS, CInitiated00LspObjectParser.TYPE, new CInitiated00LspObjectParser(tlvReg)));
regs.add(context.registerObjectSerializer(Lsp.class, new CInitiated00LspObjectParser(tlvReg)));
regs.add(context.registerObjectParser(CInitiated00SrpObjectParser.CLASS, CInitiated00SrpObjectParser.TYPE, new CInitiated00SrpObjectParser(tlvReg)));
package org.opendaylight.protocol.pcep.ietf.stateful07;
import org.opendaylight.protocol.concepts.Ipv4Util;
+import org.opendaylight.protocol.pcep.impl.tlv.TlvUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.TlvParser;
import org.opendaylight.protocol.pcep.spi.TlvSerializer;
ByteArray.copyWhole(Ipv4Util.bytesForAddress(ipv4.getIpv4ExtendedTunnelId()), bytes, offset);
offset += EX_TUNNEL_ID4_F_LENGTH;
ByteArray.copyWhole(Ipv4Util.bytesForAddress(ipv4.getIpv4TunnelEndpointAddress()), bytes, offset);
- return bytes;
+ return TlvUtil.formatTlv(TYPE, bytes);
}
@Override
package org.opendaylight.protocol.pcep.ietf.stateful07;
import org.opendaylight.protocol.concepts.Ipv6Util;
+import org.opendaylight.protocol.pcep.impl.tlv.TlvUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.TlvParser;
import org.opendaylight.protocol.pcep.spi.TlvSerializer;
ByteArray.copyWhole(Ipv6Util.bytesForAddress(ipv6.getIpv6ExtendedTunnelId()), bytes, offset);
offset += EX_TUNNEL_ID6_F_LENGTH;
ByteArray.copyWhole(Ipv6Util.bytesForAddress(ipv6.getIpv6TunnelEndpointAddress()), bytes, offset);
- return bytes;
+ return TlvUtil.formatTlv(TYPE, bytes);
}
@Override
import org.opendaylight.protocol.pcep.spi.AbstractObjectWithTlvsParser;
import org.opendaylight.protocol.pcep.spi.ObjectUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.OperationalStatus;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.PlspId;
protected static final int ADMINISTRATIVE_FLAG_OFFSET = 12;
protected static final int OPERATIONAL_OFFSET = 9;
- public Stateful07LspObjectParser(final TlvHandlerRegistry tlvReg) {
+ public Stateful07LspObjectParser(final TlvRegistry tlvReg) {
super(tlvReg);
}
*/
package org.opendaylight.protocol.pcep.ietf.stateful07;
+import org.opendaylight.protocol.pcep.impl.tlv.TlvUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.TlvParser;
import org.opendaylight.protocol.pcep.spi.TlvSerializer;
throw new IllegalArgumentException("SymbolicPathNameTlv is mandatory.");
}
final SymbolicPathName spn = (SymbolicPathName) tlv;
- return spn.getPathName().getValue();
+ return TlvUtil.formatTlv(TYPE, spn.getPathName().getValue());
}
@Override
*/
package org.opendaylight.protocol.pcep.ietf.stateful07;
+import org.opendaylight.protocol.pcep.impl.tlv.TlvUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.TlvParser;
import org.opendaylight.protocol.pcep.spi.TlvSerializer;
throw new IllegalArgumentException("LspErrorCodeTlv is mandatory.");
}
final LspErrorCode lsp = (LspErrorCode) tlv;
- return ByteArray.longToBytes(lsp.getErrorCode(), UPDATE_ERR_CODE_LENGTH);
+ return TlvUtil.formatTlv(TYPE, ByteArray.longToBytes(lsp.getErrorCode(), UPDATE_ERR_CODE_LENGTH));
}
@Override
package org.opendaylight.protocol.pcep.ietf.stateful07;
import org.opendaylight.protocol.pcep.impl.object.PCEPLspaObjectParser;
-import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Tlvs2;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Tlvs2Builder;
*/
public final class Stateful07LspaObjectParser extends PCEPLspaObjectParser {
- public Stateful07LspaObjectParser(final TlvHandlerRegistry tlvReg) {
+ public Stateful07LspaObjectParser(final TlvRegistry tlvReg) {
super(tlvReg);
}
package org.opendaylight.protocol.pcep.ietf.stateful07;
import org.opendaylight.protocol.pcep.impl.object.PCEPOpenObjectParser;
-import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Tlvs1;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Tlvs1Builder;
*/
public class Stateful07OpenObjectParser extends PCEPOpenObjectParser {
- public Stateful07OpenObjectParser(final TlvHandlerRegistry tlvReg) {
+ public Stateful07OpenObjectParser(final TlvRegistry tlvReg) {
super(tlvReg);
}
import org.opendaylight.protocol.concepts.Ipv4Util;
import org.opendaylight.protocol.concepts.Ipv6Util;
+import org.opendaylight.protocol.pcep.impl.tlv.TlvUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.TlvParser;
import org.opendaylight.protocol.pcep.spi.TlvSerializer;
if (rsvp.getErrorType().getImplementedInterface().equals(RsvpCase.class)) {
final RsvpCase r = (RsvpCase) rsvp.getErrorType();
- return serializeRsvp(r.getRsvpError());
+ return TlvUtil.formatTlv(TYPE, serializeRsvp(r.getRsvpError()));
} else {
final UserCase u = (UserCase) rsvp.getErrorType();
- return serializerUserError(u.getUserError());
+ return TlvUtil.formatTlv(TYPE, serializerUserError(u.getUserError()));
}
}
import org.opendaylight.protocol.pcep.spi.AbstractObjectWithTlvsParser;
import org.opendaylight.protocol.pcep.spi.ObjectUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.SrpIdNumber;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.Srp;
protected static final int MIN_SIZE = FLAGS_SIZE + SRP_ID_SIZE;
- public Stateful07SrpObjectParser(final TlvHandlerRegistry tlvReg) {
+ public Stateful07SrpObjectParser(final TlvRegistry tlvReg) {
super(tlvReg);
}
import java.util.BitSet;
+import org.opendaylight.protocol.pcep.impl.tlv.TlvUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.TlvParser;
import org.opendaylight.protocol.pcep.spi.TlvSerializer;
final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
flags.set(U_FLAG_OFFSET, sct.isLspUpdateCapability());
- return ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH);
+ return TlvUtil.formatTlv(TYPE, ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH));
}
@Override
import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
import org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderContext;
-import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.protocol.pcep.spi.pojo.AbstractPCEPExtensionProviderActivator;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Pcrpt;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Pcupd;
regs.add(context.registerMessageParser(Stateful07PCReportMessageParser.TYPE, new Stateful07PCReportMessageParser(objReg)));
regs.add(context.registerMessageSerializer(Pcrpt.class, new Stateful07PCReportMessageParser(objReg)));
- final TlvHandlerRegistry tlvReg = context.getTlvHandlerRegistry();
+ final TlvRegistry tlvReg = context.getTlvHandlerRegistry();
regs.add(context.registerObjectParser(Stateful07LspObjectParser.CLASS, Stateful07LspObjectParser.TYPE, new Stateful07LspObjectParser(tlvReg)));
regs.add(context.registerObjectSerializer(Lsp.class, new Stateful07LspObjectParser(tlvReg)));
regs.add(context.registerObjectParser(Stateful07SrpObjectParser.CLASS, Stateful07SrpObjectParser.TYPE, new Stateful07SrpObjectParser(tlvReg)));
import org.opendaylight.protocol.pcep.ietf.stateful07.Stateful07OpenObjectParser;
import org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.protocol.pcep.spi.pojo.ServiceLoaderPCEPExtensionProviderContext;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.Lsp1;
public class PCEPObjectParserTest {
- private TlvHandlerRegistry tlvRegistry;
+ private TlvRegistry tlvRegistry;
@Before
public void setUp() throws Exception {
import org.opendaylight.protocol.pcep.ietf.stateful07.Stateful07LSPIdentifierIpv6TlvParser;
import org.opendaylight.protocol.pcep.ietf.stateful07.Stateful07LspSymbolicNameTlvParser;
import org.opendaylight.protocol.pcep.ietf.stateful07.Stateful07LspUpdateErrorTlvParser;
-import org.opendaylight.protocol.pcep.ietf.stateful07.Stateful07StatefulCapabilityTlvParser;
import org.opendaylight.protocol.pcep.ietf.stateful07.Stateful07RSVPErrorSpecTlvParser;
+import org.opendaylight.protocol.pcep.ietf.stateful07.Stateful07StatefulCapabilityTlvParser;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
+import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.error.code.tlv.LspErrorCode;
public class PCEPTlvParserTest {
- private static final byte[] statefulBytes = { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01 };
- private static final byte[] symbolicNameBytes = { (byte) 0x4d, (byte) 0x65, (byte) 0x64, (byte) 0x20, (byte) 0x74, (byte) 0x65,
- (byte) 0x73, (byte) 0x74, (byte) 0x20, (byte) 0x6f, (byte) 0x66, (byte) 0x20, (byte) 0x73, (byte) 0x79, (byte) 0x6d,
- (byte) 0x62, (byte) 0x6f, (byte) 0x6c, (byte) 0x69, (byte) 0x63, (byte) 0x20, (byte) 0x6e, (byte) 0x61, (byte) 0x6d,
- (byte) 0x65 };
- private static final byte[] lspUpdateErrorBytes = { (byte) 0x25, (byte) 0x68, (byte) 0x95, (byte) 0x03 };
- private static final byte[] lspIdentifiers4Bytes = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0xFF, (byte) 0xFF,
- (byte) 0x12, (byte) 0x34, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x12, (byte) 0x34, (byte) 0x56,
- (byte) 0x78 };
- private static final byte[] lspIdentifiers6Bytes = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9A, (byte) 0xBC,
- (byte) 0xDE, (byte) 0xF0, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9A, (byte) 0xBC, (byte) 0xDE,
- (byte) 0xF0, (byte) 0x12, (byte) 0x34, (byte) 0xFF, (byte) 0xFF, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
- (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x01, (byte) 0x23, (byte) 0x45, (byte) 0x67, (byte) 0x01,
- (byte) 0x23, (byte) 0x45, (byte) 0x67, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9A, (byte) 0xBC,
- (byte) 0xDE, (byte) 0xF0, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9A, (byte) 0xBC, (byte) 0xDE,
- (byte) 0xF0 };
- private static final byte[] rsvpErrorBytes = { (byte) 0x06, (byte) 0x01, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
- (byte) 0x02, (byte) 0x92, (byte) 0x16, (byte) 0x02 };
- private static final byte[] rsvpError6Bytes = { (byte) 0x06, (byte) 0x02, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
- (byte) 0x9a, (byte) 0xbc, (byte) 0xde, (byte) 0xf0, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9a,
- (byte) 0xbc, (byte) 0xde, (byte) 0xf0, (byte) 0x02, (byte) 0xd5, (byte) 0xc5, (byte) 0xd9 };
- private static final byte[] userErrorBytes = { (byte) 0xc2, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x30, (byte) 0x39,
- (byte) 0x05, (byte) 0x09, (byte) 0x00, (byte) 0x26, (byte) 0x75, (byte) 0x73, (byte) 0x65, (byte) 0x72, (byte) 0x20,
- (byte) 0x64, (byte) 0x65, (byte) 0x73, (byte) 0x63 };
+ private static final byte[] statefulBytes = { 0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01 };
+ private static final byte[] symbolicNameBytes = { 0x00, 0x11, 0x00, 0x1C, 0x4d, 0x65, 0x64, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x6f,
+ 0x66, 0x20, 0x73, 0x79, 0x6d, 0x62, 0x6f, 0x6c, 0x69, 0x63, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x65, 0x65, 0x65 };
+ private static final byte[] lspUpdateErrorBytes = { 0x00, 0x14, 0x00, 0x04, 0x25, 0x68, (byte) 0x95, 0x03 };
+ private static final byte[] lspIdentifiers4Bytes = { 0x00, 0x12, 0x00, 0x10, 0x12, 0x34, 0x56, 0x78, (byte) 0xFF, (byte) 0xFF, 0x12, 0x34, 0x12, 0x34,
+ 0x56, 0x78, 0x12, 0x34, 0x56, 0x78 };
+ private static final byte[] lspIdentifiers6Bytes = { 0x00, 0x13, 0x00, 0x34, 0x12, 0x34, 0x56, 0x78, (byte) 0x9A, (byte) 0xBC,
+ (byte) 0xDE, (byte) 0xF0, 0x12, 0x34, 0x56, 0x78, (byte) 0x9A, (byte) 0xBC, (byte) 0xDE,
+ (byte) 0xF0, 0x12, 0x34, (byte) 0xFF, (byte) 0xFF, 0x12, 0x34, 0x56, 0x78,
+ 0x12, 0x34, 0x56, 0x78, 0x01, 0x23, 0x45, 0x67, 0x01,
+ 0x23, 0x45, 0x67, 0x12, 0x34, 0x56, 0x78, (byte) 0x9A, (byte) 0xBC,
+ (byte) 0xDE, (byte) 0xF0, 0x12, 0x34, 0x56, 0x78, (byte) 0x9A, (byte) 0xBC, (byte) 0xDE,
+ (byte) 0xF0 };
+ private static final byte[] rsvpErrorBytes = { 0x00, 0x15, 0x00, 0x0a, 0x06, 0x01, 0x12, 0x34, 0x56, 0x78, 0x02, (byte) 0x92, 0x16, 0x02, 0x00, 0x00 };
+ private static final byte[] rsvpError6Bytes = { 0x00, 0x15, 0x00, 0x16, 0x06, 0x02, 0x12, 0x34, 0x56, 0x78, (byte) 0x9a, (byte) 0xbc, (byte) 0xde, (byte) 0xf0,
+ 0x12, 0x34, 0x56, 0x78, (byte) 0x9a, (byte) 0xbc, (byte) 0xde, (byte) 0xf0, 0x02, (byte) 0xd5, (byte) 0xc5, (byte) 0xd9, 0x00, 0x00 };
+ private static final byte[] userErrorBytes = { 0x00, 0x15, 0x00, 0x13, (byte) 0xc2, 0x01, 0x00, 0x00, 0x30, 0x39, 0x05, 0x09, 0x00, 0x26,
+ 0x75, 0x73, 0x65, 0x72, 0x20, 0x64, 0x65, 0x73, 0x63, 0x00 };
@Test
public void testStatefulTlv() throws PCEPDeserializerException {
final Stateful07StatefulCapabilityTlvParser parser = new Stateful07StatefulCapabilityTlvParser();
final Stateful tlv = new StatefulBuilder().setLspUpdateCapability(Boolean.TRUE).build();
- assertEquals(tlv, parser.parseTlv(statefulBytes));
+ assertEquals(tlv, parser.parseTlv(ByteArray.cutBytes(statefulBytes, 4)));
assertArrayEquals(statefulBytes, parser.serializeTlv(tlv));
}
public void testSymbolicNameTlv() throws PCEPDeserializerException {
final Stateful07LspSymbolicNameTlvParser parser = new Stateful07LspSymbolicNameTlvParser();
final SymbolicPathName tlv = new SymbolicPathNameBuilder().setPathName(
- new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.SymbolicPathName("Med test of symbolic name".getBytes())).build();
- assertEquals(tlv, parser.parseTlv(symbolicNameBytes));
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.SymbolicPathName("Med test of symbolic nameeee".getBytes())).build();
+ assertEquals(tlv, parser.parseTlv(ByteArray.cutBytes(symbolicNameBytes, 4)));
assertArrayEquals(symbolicNameBytes, parser.serializeTlv(tlv));
}
public void testLspErrorCodeTlv() throws PCEPDeserializerException {
final Stateful07LspUpdateErrorTlvParser parser = new Stateful07LspUpdateErrorTlvParser();
final LspErrorCode tlv = new LspErrorCodeBuilder().setErrorCode(627610883L).build();
- assertEquals(tlv, parser.parseTlv(lspUpdateErrorBytes));
+ assertEquals(tlv, parser.parseTlv(ByteArray.cutBytes(lspUpdateErrorBytes, 4)));
assertArrayEquals(lspUpdateErrorBytes, parser.serializeTlv(tlv));
}
afi.setIpv4TunnelEndpointAddress(Ipv4Util.addressForBytes(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 }));
final LspIdentifiers tlv = new LspIdentifiersBuilder().setAddressFamily(new Ipv4CaseBuilder().setIpv4(afi.build()).build()).setLspId(
new LspId(65535L)).setTunnelId(new TunnelId(4660)).build();
- assertEquals(tlv, parser.parseTlv(lspIdentifiers4Bytes));
+ assertEquals(tlv, parser.parseTlv(ByteArray.cutBytes(lspIdentifiers4Bytes, 4)));
assertArrayEquals(lspIdentifiers4Bytes, parser.serializeTlv(tlv));
}
(byte) 0xBC, (byte) 0xDE, (byte) 0xF0 }));
final LspIdentifiers tlv = new LspIdentifiersBuilder().setAddressFamily(new Ipv6CaseBuilder().setIpv6(afi.build()).build()).setLspId(
new LspId(4660L)).setTunnelId(new TunnelId(65535)).build();
- assertEquals(tlv, parser.parseTlv(lspIdentifiers6Bytes));
+ assertEquals(tlv, parser.parseTlv(ByteArray.cutBytes(lspIdentifiers6Bytes, 4)));
assertArrayEquals(lspIdentifiers6Bytes, parser.serializeTlv(tlv));
}
builder.setCode((short) 146);
builder.setValue(5634);
final RsvpErrorSpec tlv = new RsvpErrorSpecBuilder().setErrorType(new RsvpCaseBuilder().setRsvpError(builder.build()).build()).build();
- assertEquals(tlv, parser.parseTlv(rsvpErrorBytes));
+ assertEquals(tlv, parser.parseTlv(ByteArray.cutBytes(rsvpErrorBytes, 4)));
assertArrayEquals(rsvpErrorBytes, parser.serializeTlv(tlv));
}
builder.setCode((short) 213);
builder.setValue(50649);
final RsvpErrorSpec tlv = new RsvpErrorSpecBuilder().setErrorType(new RsvpCaseBuilder().setRsvpError(builder.build()).build()).build();
- assertEquals(tlv, parser.parseTlv(rsvpError6Bytes));
+ assertEquals(tlv, parser.parseTlv(ByteArray.cutBytes(rsvpError6Bytes, 4)));
assertArrayEquals(rsvpError6Bytes, parser.serializeTlv(tlv));
}
builder.setValue(38);
builder.setDescription("user desc");
final RsvpErrorSpec tlv = new RsvpErrorSpecBuilder().setErrorType(new UserCaseBuilder().setUserError(builder.build()).build()).build();
- assertEquals(tlv, parser.parseTlv(userErrorBytes));
+ assertEquals(tlv, parser.parseTlv(ByteArray.cutBytes(userErrorBytes, 4)));
assertArrayEquals(userErrorBytes, parser.serializeTlv(tlv));
}
}
import org.opendaylight.protocol.pcep.impl.tlv.OrderTlvParser;
import org.opendaylight.protocol.pcep.impl.tlv.OverloadedDurationTlvParser;
import org.opendaylight.protocol.pcep.impl.tlv.ReqMissingTlvParser;
-import org.opendaylight.protocol.pcep.spi.EROSubobjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.EROSubobjectRegistry;
import org.opendaylight.protocol.pcep.spi.LabelHandlerRegistry;
import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
import org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderContext;
-import org.opendaylight.protocol.pcep.spi.RROSubobjectHandlerRegistry;
-import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
-import org.opendaylight.protocol.pcep.spi.XROSubobjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.RROSubobjectRegistry;
+import org.opendaylight.protocol.pcep.spi.TlvRegistry;
+import org.opendaylight.protocol.pcep.spi.XROSubobjectRegistry;
import org.opendaylight.protocol.pcep.spi.pojo.AbstractPCEPExtensionProviderActivator;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Close;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Keepalive;
context.registerLabelSerializer(GeneralizedLabelCase.class, new GeneralizedLabelParser());
context.registerLabelSerializer(WavebandSwitchingLabelCase.class, new WavebandSwitchingLabelParser());
- final EROSubobjectHandlerRegistry eroSubReg = context.getEROSubobjectHandlerRegistry();
+ final EROSubobjectRegistry eroSubReg = context.getEROSubobjectHandlerRegistry();
context.registerEROSubobjectParser(EROIpv4PrefixSubobjectParser.TYPE, new EROIpv4PrefixSubobjectParser());
context.registerEROSubobjectParser(EROIpv6PrefixSubobjectParser.TYPE, new EROIpv6PrefixSubobjectParser());
context.registerEROSubobjectParser(EROAsNumberSubobjectParser.TYPE, new EROAsNumberSubobjectParser());
context.registerEROSubobjectSerializer(UnnumberedCase.class, new EROUnnumberedInterfaceSubobjectParser());
context.registerEROSubobjectSerializer(PathKeyCase.class, new EROPathKey32SubobjectParser());
- final RROSubobjectHandlerRegistry rroSubReg = context.getRROSubobjectHandlerRegistry();
+ final RROSubobjectRegistry rroSubReg = context.getRROSubobjectHandlerRegistry();
context.registerRROSubobjectParser(RROIpv4PrefixSubobjectParser.TYPE, new RROIpv4PrefixSubobjectParser());
context.registerRROSubobjectParser(RROIpv6PrefixSubobjectParser.TYPE, new RROIpv6PrefixSubobjectParser());
context.registerRROSubobjectParser(RROLabelSubobjectParser.TYPE, new RROLabelSubobjectParser(labelReg));
org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.subobject.subobject.type.PathKeyCase.class,
new RROPathKey32SubobjectParser());
- final XROSubobjectHandlerRegistry xroSubReg = context.getXROSubobjectHandlerRegistry();
+ final XROSubobjectRegistry xroSubReg = context.getXROSubobjectHandlerRegistry();
context.registerXROSubobjectParser(XROIpv4PrefixSubobjectParser.TYPE, new XROIpv4PrefixSubobjectParser());
context.registerXROSubobjectParser(XROIpv6PrefixSubobjectParser.TYPE, new XROIpv6PrefixSubobjectParser());
context.registerXROSubobjectParser(XROAsNumberSubobjectParser.TYPE, new XROAsNumberSubobjectParser());
context.registerXROSubobjectSerializer(UnnumberedCase.class, new XROUnnumberedInterfaceSubobjectParser());
context.registerXROSubobjectSerializer(PathKeyCase.class, new XROPathKey32SubobjectParser());
- final TlvHandlerRegistry tlvReg = context.getTlvHandlerRegistry();
+ final TlvRegistry tlvReg = context.getTlvHandlerRegistry();
context.registerTlvParser(NoPathVectorTlvParser.TYPE, new NoPathVectorTlvParser());
context.registerTlvParser(OverloadedDurationTlvParser.TYPE, new OverloadedDurationTlvParser());
context.registerTlvParser(ReqMissingTlvParser.TYPE, new ReqMissingTlvParser());
import org.opendaylight.protocol.pcep.spi.AbstractObjectWithTlvsParser;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.bandwidth.object.Bandwidth;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.bandwidth.object.BandwidthBuilder;
private static final int BANDWIDTH_F_LENGTH = 4;
- AbstractBandwidthParser(final TlvHandlerRegistry tlvReg) {
+ AbstractBandwidthParser(final TlvRegistry tlvReg) {
super(tlvReg);
}
import java.util.List;
-import org.opendaylight.protocol.pcep.spi.EROSubobjectHandlerRegistry;
-import org.opendaylight.protocol.pcep.spi.EROSubobjectSerializer;
+import org.opendaylight.protocol.pcep.spi.EROSubobjectRegistry;
import org.opendaylight.protocol.pcep.spi.ObjectParser;
import org.opendaylight.protocol.pcep.spi.ObjectSerializer;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
private static final int LENGTH_F_OFFSET = TYPE_FLAG_F_OFFSET + SUB_TYPE_FLAG_F_LENGTH;
private static final int SO_CONTENTS_OFFSET = LENGTH_F_OFFSET + SUB_LENGTH_F_LENGTH;
- private final EROSubobjectHandlerRegistry subobjReg;
+ private final EROSubobjectRegistry subobjReg;
- protected AbstractEROWithSubobjectsParser(final EROSubobjectHandlerRegistry subobjReg) {
+ protected AbstractEROWithSubobjectsParser(final EROSubobjectRegistry subobjReg) {
this.subobjReg = Preconditions.checkNotNull(subobjReg);
}
System.arraycopy(bytes, offset + SO_CONTENTS_OFFSET, soContentsBytes, 0, length - SO_CONTENTS_OFFSET);
LOG.debug("Attempt to parse subobject from bytes: {}", ByteArray.bytesToHexString(soContentsBytes));
- final Subobject sub = this.subobjReg.getSubobjectParser(type).parseSubobject(soContentsBytes, loose);
- LOG.debug("Subobject was parsed. {}", sub);
-
- subs.add(sub);
-
+ final Subobject sub = this.subobjReg.parseSubobject(type, soContentsBytes, loose);
+ if (sub == null) {
+ LOG.warn("Unknown subobject type: {}. Ignoring subobject.", type);
+ } else {
+ LOG.debug("Subobject was parsed. {}", sub);
+ subs.add(sub);
+ }
offset += length;
}
return subs;
}
protected final byte[] serializeSubobject(final List<Subobject> subobjects) {
-
final List<byte[]> result = Lists.newArrayList();
-
int finalLength = 0;
-
for (final Subobject subobject : subobjects) {
-
- final EROSubobjectSerializer serializer = this.subobjReg.getSubobjectSerializer(subobject.getSubobjectType());
-
- final byte[] bytes = serializer.serializeSubobject(subobject);
-
- finalLength += bytes.length;
- result.add(bytes);
+ final byte[] bytes = this.subobjReg.serializeSubobject(subobject);
+ if (bytes == null) {
+ LOG.warn("Could not find serializer for subobject type: {}. Skipping subobject.", subobject.getSubobjectType());
+ } else {
+ finalLength += bytes.length;
+ result.add(bytes);
+ }
}
-
final byte[] resultBytes = new byte[finalLength];
int byteOffset = 0;
for (final byte[] b : result) {
import org.opendaylight.protocol.pcep.spi.ObjectParser;
import org.opendaylight.protocol.pcep.spi.ObjectSerializer;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.spi.RROSubobjectHandlerRegistry;
-import org.opendaylight.protocol.pcep.spi.RROSubobjectSerializer;
+import org.opendaylight.protocol.pcep.spi.RROSubobjectRegistry;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.Subobject;
import org.slf4j.Logger;
private static final int LENGTH_F_OFFSET = TYPE_FLAG_F_OFFSET + SUB_TYPE_FLAG_F_LENGTH;
private static final int SO_CONTENTS_OFFSET = LENGTH_F_OFFSET + SUB_LENGTH_F_LENGTH;
- private final RROSubobjectHandlerRegistry subobjReg;
+ private final RROSubobjectRegistry subobjReg;
- protected AbstractRROWithSubobjectsParser(final RROSubobjectHandlerRegistry subobjReg) {
+ protected AbstractRROWithSubobjectsParser(final RROSubobjectRegistry subobjReg) {
this.subobjReg = Preconditions.checkNotNull(subobjReg);
}
System.arraycopy(bytes, offset + SO_CONTENTS_OFFSET, soContentsBytes, 0, length - SO_CONTENTS_OFFSET);
LOG.debug("Attempt to parse subobject from bytes: {}", ByteArray.bytesToHexString(soContentsBytes));
- final Subobject sub = this.subobjReg.getSubobjectParser(type).parseSubobject(soContentsBytes);
- LOG.debug("Subobject was parsed. {}", sub);
-
- subs.add(sub);
-
+ final Subobject sub = this.subobjReg.parseSubobject(type, soContentsBytes);
+ if (sub == null) {
+ LOG.warn("Unknown subobject type: {}. Ignoring subobject.", type);
+ } else {
+ LOG.debug("Subobject was parsed. {}", sub);
+ subs.add(sub);
+ }
offset += length;
}
return subs;
}
protected final byte[] serializeSubobject(final List<Subobject> subobjects) {
-
final List<byte[]> result = Lists.newArrayList();
-
int finalLength = 0;
-
for (final Subobject subobject : subobjects) {
-
- final RROSubobjectSerializer serializer = this.subobjReg.getSubobjectSerializer(subobject.getSubobjectType());
-
- final byte[] bytes = serializer.serializeSubobject(subobject);
- finalLength += bytes.length;
- result.add(bytes);
+ final byte[] bytes = this.subobjReg.serializeSubobject(subobject);
+ if (bytes == null) {
+ LOG.warn("Could not find serializer for subobject type: {}. Skipping subobject.", subobject.getSubobjectType());
+ } else {
+ finalLength += bytes.length;
+ result.add(bytes);
+ }
}
-
final byte[] resultBytes = new byte[finalLength];
int byteOffset = 0;
for (final byte[] b : result) {
import org.opendaylight.protocol.pcep.spi.ObjectParser;
import org.opendaylight.protocol.pcep.spi.ObjectSerializer;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.spi.XROSubobjectHandlerRegistry;
-import org.opendaylight.protocol.pcep.spi.XROSubobjectSerializer;
+import org.opendaylight.protocol.pcep.spi.XROSubobjectRegistry;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.xro.Subobject;
import org.slf4j.Logger;
private static final int LENGTH_F_OFFSET = TYPE_FLAG_F_OFFSET + SUB_TYPE_FLAG_F_LENGTH;
private static final int SO_CONTENTS_OFFSET = LENGTH_F_OFFSET + SUB_LENGTH_F_LENGTH;
- private final XROSubobjectHandlerRegistry subobjReg;
+ private final XROSubobjectRegistry subobjReg;
- protected AbstractXROWithSubobjectsParser(final XROSubobjectHandlerRegistry subobjReg) {
+ protected AbstractXROWithSubobjectsParser(final XROSubobjectRegistry subobjReg) {
this.subobjReg = Preconditions.checkNotNull(subobjReg);
}
soContentsBytes = ByteArray.subByte(bytes, offset, length - SO_CONTENTS_OFFSET);
LOG.debug("Attempt to parse subobject from bytes: {}", ByteArray.bytesToHexString(soContentsBytes));
- final Subobject sub = this.subobjReg.getSubobjectParser(type).parseSubobject(soContentsBytes, mandatory);
- LOG.debug("Subobject was parsed. {}", sub);
-
- subs.add(sub);
-
+ final Subobject sub = this.subobjReg.parseSubobject(type, soContentsBytes, mandatory);
+ if (sub == null) {
+ LOG.warn("Unknown subobject type: {}. Ignoring subobject.", type);
+ } else {
+ LOG.debug("Subobject was parsed. {}", sub);
+ subs.add(sub);
+ }
offset += soContentsBytes.length;
}
return subs;
}
protected final byte[] serializeSubobject(final List<Subobject> subobjects) {
-
final List<byte[]> result = Lists.newArrayList();
-
int finalLength = 0;
-
for (final Subobject subobject : subobjects) {
-
- final XROSubobjectSerializer serializer = this.subobjReg.getSubobjectSerializer(subobject.getSubobjectType());
-
- final byte[] bytes = serializer.serializeSubobject(subobject);
- finalLength += bytes.length;
- result.add(bytes);
+ final byte[] bytes = this.subobjReg.serializeSubobject(subobject);
+ if (bytes == null) {
+ LOG.warn("Could not find serializer for subobject type: {}. Skipping subobject.", subobject.getSubobjectType());
+ } else {
+ finalLength += bytes.length;
+ result.add(bytes);
+ }
}
-
final byte[] resultBytes = new byte[finalLength];
int byteOffset = 0;
for (final byte[] b : result) {
import java.util.Arrays;
import org.opendaylight.protocol.pcep.spi.ObjectUtil;
-import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.bandwidth.object.Bandwidth;
private static final int BANDWIDTH_LENGTH = 4;
- public PCEPBandwidthObjectParser(final TlvHandlerRegistry tlvReg) {
+ public PCEPBandwidthObjectParser(final TlvRegistry tlvReg) {
super(tlvReg);
}
import org.opendaylight.protocol.pcep.spi.ObjectUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.PCEPErrors;
-import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.protocol.pcep.spi.UnknownObject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
*/
private static final int SIZE = (RESERVED + CT_F_LENGTH) / 8;
- public PCEPClassTypeObjectParser(final TlvHandlerRegistry tlvReg) {
+ public PCEPClassTypeObjectParser(final TlvRegistry tlvReg) {
super(tlvReg);
}
import org.opendaylight.protocol.pcep.spi.AbstractObjectWithTlvsParser;
import org.opendaylight.protocol.pcep.spi.ObjectUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
*/
private static final int TLVS_OFFSET = REASON_F_OFFSET + REASON_F_LENGTH;
- public PCEPCloseObjectParser(final TlvHandlerRegistry tlvReg) {
+ public PCEPCloseObjectParser(final TlvRegistry tlvReg) {
super(tlvReg);
}
import org.opendaylight.protocol.pcep.spi.ObjectUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.PCEPErrors;
-import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.protocol.pcep.spi.UnknownObject;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
private static final int SRC4_F_OFFSET = 0;
private static final int DEST4_F_OFFSET = SRC4_F_OFFSET + SRC4_F_LENGTH;
- public PCEPEndPointsIpv4ObjectParser(final TlvHandlerRegistry tlvReg) {
+ public PCEPEndPointsIpv4ObjectParser(final TlvRegistry tlvReg) {
super(tlvReg);
}
import org.opendaylight.protocol.pcep.spi.ObjectUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.PCEPErrors;
-import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.protocol.pcep.spi.UnknownObject;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
private static final int SRC6_F_OFFSET = 0;
private static final int DEST6_F_OFFSET = SRC6_F_OFFSET + SRC6_F_LENGTH;
- public PCEPEndPointsIpv6ObjectParser(final TlvHandlerRegistry tlvReg) {
+ public PCEPEndPointsIpv6ObjectParser(final TlvRegistry tlvReg) {
super(tlvReg);
}
import org.opendaylight.protocol.pcep.spi.AbstractObjectWithTlvsParser;
import org.opendaylight.protocol.pcep.spi.ObjectUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
private static final int EV_F_OFFSET = ET_F_OFFSET + ET_F_LENGTH;
private static final int TLVS_OFFSET = EV_F_OFFSET + EV_F_LENGTH;
- public PCEPErrorObjectParser(final TlvHandlerRegistry tlvReg) {
+ public PCEPErrorObjectParser(final TlvRegistry tlvReg) {
super(tlvReg);
}
import org.opendaylight.protocol.pcep.spi.ObjectUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.spi.XROSubobjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.XROSubobjectRegistry;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
private static final int FLAGS_OFFSET = 3;
- public PCEPExcludeRouteObjectParser(final XROSubobjectHandlerRegistry registry) {
+ public PCEPExcludeRouteObjectParser(final XROSubobjectRegistry registry) {
super(registry);
}
import java.util.Arrays;
import org.opendaylight.protocol.pcep.spi.ObjectUtil;
-import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.bandwidth.object.Bandwidth;
private static final int BANDWIDTH_LENGTH = 4;
- public PCEPExistingBandwidthObjectParser(final TlvHandlerRegistry tlvReg) {
+ public PCEPExistingBandwidthObjectParser(final TlvRegistry tlvReg) {
super(tlvReg);
}
*/
package org.opendaylight.protocol.pcep.impl.object;
-import org.opendaylight.protocol.pcep.spi.EROSubobjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.EROSubobjectRegistry;
import org.opendaylight.protocol.pcep.spi.ObjectUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
public static final int TYPE = 1;
- public PCEPExplicitRouteObjectParser(final EROSubobjectHandlerRegistry subobjReg) {
+ public PCEPExplicitRouteObjectParser(final EROSubobjectRegistry subobjReg) {
super(subobjReg);
}
import org.opendaylight.protocol.pcep.spi.AbstractObjectWithTlvsParser;
import org.opendaylight.protocol.pcep.spi.ObjectUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.gc.object.Gc;
private static final int TLVS_OFFSET = OVER_BOOKING_FACTOR_F_OFFSET + OVER_BOOKING_FACTOR_F_LENGTH;
- public PCEPGlobalConstraintsObjectParser(final TlvHandlerRegistry tlvReg) {
+ public PCEPGlobalConstraintsObjectParser(final TlvRegistry tlvReg) {
super(tlvReg);
}
import java.util.List;
-import org.opendaylight.protocol.pcep.spi.EROSubobjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.EROSubobjectRegistry;
import org.opendaylight.protocol.pcep.spi.ObjectUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
public static final int TYPE = 1;
- public PCEPIncludeRouteObjectParser(final EROSubobjectHandlerRegistry subobjReg) {
+ public PCEPIncludeRouteObjectParser(final EROSubobjectRegistry subobjReg) {
super(subobjReg);
}
import org.opendaylight.protocol.pcep.spi.AbstractObjectWithTlvsParser;
import org.opendaylight.protocol.pcep.spi.ObjectUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
private static final int SIZE = MIN_BAND_F_OFFSET + MIN_BAND_F_LENGTH;
- public PCEPLoadBalancingObjectParser(final TlvHandlerRegistry tlvReg) {
+ public PCEPLoadBalancingObjectParser(final TlvRegistry tlvReg) {
super(tlvReg);
}
import org.opendaylight.protocol.pcep.spi.AbstractObjectWithTlvsParser;
import org.opendaylight.protocol.pcep.spi.ObjectUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
private static final int FLAGS_F_OFFSET = HOLD_PRIO_F_OFFSET + HOLD_PRIO_F_LENGTH;
private static final int TLVS_F_OFFSET = FLAGS_F_OFFSET + FLAGS_F_LENGTH + 1;
- public PCEPLspaObjectParser(final TlvHandlerRegistry tlvReg) {
+ public PCEPLspaObjectParser(final TlvRegistry tlvReg) {
super(tlvReg);
}
import org.opendaylight.protocol.pcep.spi.AbstractObjectWithTlvsParser;
import org.opendaylight.protocol.pcep.spi.ObjectUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
private static final int SIZE = METRIC_VALUE_F_OFFSET + METRIC_VALUE_F_LENGTH;
- public PCEPMetricObjectParser(final TlvHandlerRegistry tlvReg) {
+ public PCEPMetricObjectParser(final TlvRegistry tlvReg) {
super(tlvReg);
}
import org.opendaylight.protocol.pcep.spi.AbstractObjectWithTlvsParser;
import org.opendaylight.protocol.pcep.spi.ObjectUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
*/
private static final int C_FLAG_OFFSET = 0;
- public PCEPNoPathObjectParser(final TlvHandlerRegistry tlvReg) {
+ public PCEPNoPathObjectParser(final TlvRegistry tlvReg) {
super(tlvReg);
}
import org.opendaylight.protocol.pcep.spi.AbstractObjectWithTlvsParser;
import org.opendaylight.protocol.pcep.spi.ObjectUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
private static final int NV_F_OFFSET = NT_F_OFFSET + NT_F_LENGTH;
private static final int TLVS_OFFSET = NV_F_OFFSET + NV_F_LENGTH;
- public PCEPNotificationObjectParser(final TlvHandlerRegistry tlvReg) {
+ public PCEPNotificationObjectParser(final TlvRegistry tlvReg) {
super(tlvReg);
}
import org.opendaylight.protocol.pcep.spi.AbstractObjectWithTlvsParser;
import org.opendaylight.protocol.pcep.spi.ObjectUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
private static final int OF_CODE_F_OFFSET = 0;
private static final int TLVS_OFFSET = OF_CODE_F_OFFSET + OF_CODE_F_LENGTH + 2;
- public PCEPObjectiveFunctionObjectParser(final TlvHandlerRegistry tlvReg) {
+ public PCEPObjectiveFunctionObjectParser(final TlvRegistry tlvReg) {
super(tlvReg);
}
import org.opendaylight.protocol.pcep.spi.ObjectUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.PCEPErrors;
-import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.protocol.pcep.spi.UnknownObject;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
private static final int PCEP_VERSION = 1;
- public PCEPOpenObjectParser(final TlvHandlerRegistry tlvReg) {
+ public PCEPOpenObjectParser(final TlvRegistry tlvReg) {
super(tlvReg);
}
import java.util.List;
-import org.opendaylight.protocol.pcep.spi.EROSubobjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.EROSubobjectRegistry;
import org.opendaylight.protocol.pcep.spi.ObjectUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
public static final int TYPE = 1;
- public PCEPPathKeyObjectParser(final EROSubobjectHandlerRegistry subReg) {
+ public PCEPPathKeyObjectParser(final EROSubobjectRegistry subReg) {
super(subReg);
}
import org.opendaylight.protocol.pcep.spi.ObjectUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.spi.RROSubobjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.RROSubobjectRegistry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.Rro;
public static final int TYPE = 1;
- public PCEPReportedRouteObjectParser(final RROSubobjectHandlerRegistry subobjReg) {
+ public PCEPReportedRouteObjectParser(final RROSubobjectRegistry subobjReg) {
super(subobjReg);
}
import org.opendaylight.protocol.pcep.spi.AbstractObjectWithTlvsParser;
import org.opendaylight.protocol.pcep.spi.ObjectUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
private static final int E_FLAG_OFFSET = 20;
- public PCEPRequestParameterObjectParser(final TlvHandlerRegistry tlvReg) {
+ public PCEPRequestParameterObjectParser(final TlvRegistry tlvReg) {
super(tlvReg);
}
import org.opendaylight.protocol.pcep.spi.AbstractObjectWithTlvsParser;
import org.opendaylight.protocol.pcep.spi.ObjectUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
*/
private static final int MIN_SIZE = FLAGS_F_LENGTH + FLAGS_F_OFFSET;
- public PCEPSvecObjectParser(final TlvHandlerRegistry tlvReg) {
+ public PCEPSvecObjectParser(final TlvRegistry tlvReg) {
super(tlvReg);
}
import org.opendaylight.protocol.pcep.spi.EROSubobjectParser;
import org.opendaylight.protocol.pcep.spi.EROSubobjectSerializer;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.spi.XROSubobjectHandlerRegistry;
-import org.opendaylight.protocol.pcep.spi.XROSubobjectParser;
-import org.opendaylight.protocol.pcep.spi.XROSubobjectSerializer;
+import org.opendaylight.protocol.pcep.spi.XROSubobjectRegistry;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.SubobjectBuilder;
private static final int LENGTH_F_OFFSET = TYPE_FLAG_F_OFFSET + SUB_TYPE_FLAG_F_LENGTH;
private static final int SO_CONTENTS_OFFSET = LENGTH_F_OFFSET + SUB_LENGTH_F_LENGTH;
- private final XROSubobjectHandlerRegistry registry;
+ private final XROSubobjectRegistry registry;
- public EROExplicitExclusionRouteSubobjectParser(final XROSubobjectHandlerRegistry registry) {
+ public EROExplicitExclusionRouteSubobjectParser(final XROSubobjectRegistry registry) {
this.registry = registry;
}
soContentsBytes = new byte[length - SO_CONTENTS_OFFSET];
System.arraycopy(bytes, offset + SO_CONTENTS_OFFSET, soContentsBytes, 0, length - SO_CONTENTS_OFFSET);
- final XROSubobjectParser parser = this.registry.getSubobjectParser(type);
-
- subs.add(parser.parseSubobject(soContentsBytes, mandatory));
+ subs.add(this.registry.parseSubobject(type, soContentsBytes, mandatory));
offset += length;
}
for (final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.xro.Subobject subobject : subobjects) {
- final XROSubobjectSerializer serializer = this.registry.getSubobjectSerializer(subobject.getSubobjectType());
-
- final byte[] bytes = serializer.serializeSubobject(subobject);
+ final byte[] bytes = this.registry.serializeSubobject(subobject);
finalLength += bytes.length;
result.add(bytes);
}
flags.set(UNKNOWN_SRC, tlv.getFlags().isUnknownSource());
flags.set(UNKNOWN_DEST, tlv.getFlags().isUnknownDestination());
flags.set(PCE_UNAVAILABLE, tlv.getFlags().isPceUnavailable());
- return ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH);
+ return TlvUtil.formatTlv(TYPE, ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH));
}
@Override
for (int i = 0; i < size; i++) {
ByteArray.copyWhole(ByteArray.shortToBytes(ofCodes.get(i).getValue().shortValue()), retBytes, i * OF_CODE_ELEMENT_LENGTH);
}
- return retBytes;
+ return TlvUtil.formatTlv(TYPE, retBytes);
}
@Override
ByteArray.copyWhole(ByteArray.longToBytes(otlv.getDelete(), ORDR_DEL_LENGTH), bytes, offset);
offset += ORDR_DEL_LENGTH;
ByteArray.copyWhole(ByteArray.longToBytes(otlv.getSetup(), ORDR_SETUP_LENGTH), bytes, offset);
- return bytes;
+ return TlvUtil.formatTlv(TYPE, bytes);
}
@Override
throw new IllegalArgumentException("OverloadedTlv is mandatory.");
}
final OverloadDuration odt = (OverloadDuration) tlv;
- return ByteArray.longToBytes(odt.getDuration(), OVERLOADED_DURATION_LENGTH);
+ return TlvUtil.formatTlv(TYPE, ByteArray.longToBytes(odt.getDuration(), OVERLOADED_DURATION_LENGTH));
}
@Override
throw new IllegalArgumentException("ReqMissingTlv is mandatory.");
}
final ReqMissing req = (ReqMissing) tlv;
- return ByteArray.longToBytes(req.getRequestId().getValue(), REQ_ID_LENGTH);
+ return TlvUtil.formatTlv(TYPE, ByteArray.longToBytes(req.getRequestId().getValue(), REQ_ID_LENGTH));
}
@Override
--- /dev/null
+/*
+ * 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.protocol.pcep.impl.tlv;
+
+import org.opendaylight.protocol.pcep.spi.AbstractObjectWithTlvsParser;
+import org.opendaylight.protocol.util.ByteArray;
+
+public class TlvUtil {
+
+ private static final int TLV_TYPE_F_LENGTH = 2;
+ private static final int TLV_LENGTH_F_LENGTH = 2;
+ private static final int HEADER_SIZE = TLV_LENGTH_F_LENGTH + TLV_TYPE_F_LENGTH;
+
+ protected static final int PADDED_TO = 4;
+
+ private TlvUtil() {
+ }
+
+ public static byte[] formatTlv(final int type, final byte[] valueBytes) {
+ final byte[] typeBytes = ByteArray.intToBytes(type, TLV_TYPE_F_LENGTH);
+
+ final byte[] lengthBytes = ByteArray.intToBytes(valueBytes.length, TLV_LENGTH_F_LENGTH);
+
+ final byte[] bytes = new byte[HEADER_SIZE + valueBytes.length + AbstractObjectWithTlvsParser.getPadding(HEADER_SIZE + valueBytes.length, PADDED_TO)];
+
+ int byteOffset = 0;
+ System.arraycopy(typeBytes, 0, bytes, byteOffset, TLV_TYPE_F_LENGTH);
+ byteOffset += TLV_TYPE_F_LENGTH;
+ System.arraycopy(lengthBytes, 0, bytes, byteOffset, TLV_LENGTH_F_LENGTH);
+ byteOffset += TLV_LENGTH_F_LENGTH;
+ System.arraycopy(valueBytes, 0, bytes, byteOffset, valueBytes.length);
+ return bytes;
+ }
+}
import org.opendaylight.protocol.pcep.impl.object.PCEPSvecObjectParser;
import org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.protocol.pcep.spi.pojo.SimplePCEPExtensionProviderContext;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
public class PCEPObjectParserTest {
- private TlvHandlerRegistry tlvRegistry;
+ private TlvRegistry tlvRegistry;
private SimplePCEPExtensionProviderContext ctx;
private Activator act;
import org.opendaylight.protocol.pcep.impl.tlv.OverloadedDurationTlvParser;
import org.opendaylight.protocol.pcep.impl.tlv.ReqMissingTlvParser;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
+import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.NoPathVectorTlv;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OfId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.RequestId;
public class PCEPTlvParserTest {
- private static final byte[] noPathVectorBytes = { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xa7 };
- private static final byte[] overloadedBytes = { (byte) 0x7f, (byte) 0xff, (byte) 0xff, (byte) 0xff };
- private static final byte[] reqMissingBytes = { (byte) 0xF7, (byte) 0x82, (byte) 0x35, (byte) 0x17 };
- private static final byte[] orderBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x00, (byte) 0x00, (byte) 0x00,
- (byte) 0x01 };
- private static final byte[] ofListBytes = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 };
+ private static final byte[] noPathVectorBytes = { 0x00, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00, (byte) 0xa7 };
+ private static final byte[] overloadedBytes = { 0x00, 0x02, 0x00, 0x04, 0x7f, (byte) 0xff, (byte) 0xff, (byte) 0xff };
+ private static final byte[] reqMissingBytes = { 0x00, 0x03, 0x00, 0x04, (byte) 0xF7, (byte) 0x82, 0x35, 0x17 };
+ private static final byte[] orderBytes = { 0x00, 0x05, 0x00, 0x08, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, 0x00, 0x00, 0x00, 0x01 };
+ private static final byte[] ofListBytes = { 0x00, 0x04, 0x00, 0x04, 0x12, 0x34, 0x56, 0x78 };
@Test
public void testNoPathVectorTlv() throws PCEPDeserializerException {
final NoPathVectorTlvParser parser = new NoPathVectorTlvParser();
final NoPathVectorTlv tlv = new NoPathVectorBuilder().setFlags(
new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.NoPathVectorTlv.Flags(false, true, false, true, false, true, true, true)).build();
- assertEquals(tlv, parser.parseTlv(noPathVectorBytes));
+ assertEquals(tlv, parser.parseTlv(ByteArray.cutBytes(noPathVectorBytes, 4)));
assertArrayEquals(noPathVectorBytes, parser.serializeTlv(tlv));
}
public void testOverloadedDurationTlv() throws PCEPDeserializerException {
final OverloadedDurationTlvParser parser = new OverloadedDurationTlvParser();
final OverloadDuration tlv = new OverloadDurationBuilder().setDuration(0x7FFFFFFFL).build();
- assertEquals(tlv, parser.parseTlv(overloadedBytes));
+ assertEquals(tlv, parser.parseTlv(ByteArray.cutBytes(overloadedBytes, 4)));
assertArrayEquals(overloadedBytes, parser.serializeTlv(tlv));
}
public void testReqMissingTlv() throws PCEPDeserializerException {
final ReqMissingTlvParser parser = new ReqMissingTlvParser();
final ReqMissing tlv = new ReqMissingBuilder().setRequestId(new RequestId(0xF7823517L)).build();
- assertEquals(tlv, parser.parseTlv(reqMissingBytes));
+ assertEquals(tlv, parser.parseTlv(ByteArray.cutBytes(reqMissingBytes, 4)));
assertArrayEquals(reqMissingBytes, parser.serializeTlv(tlv));
}
public void testOrderTlv() throws PCEPDeserializerException {
final OrderTlvParser parser = new OrderTlvParser();
final Order tlv = new OrderBuilder().setDelete(0xFFFFFFFFL).setSetup(0x00000001L).build();
- assertEquals(tlv, parser.parseTlv(orderBytes));
+ assertEquals(tlv, parser.parseTlv(ByteArray.cutBytes(orderBytes, 4)));
assertArrayEquals(orderBytes, parser.serializeTlv(tlv));
}
ids.add(new OfId(0x1234));
ids.add(new OfId(0x5678));
final OfList tlv = new OfListBuilder().setCodes(ids).build();
- assertEquals(tlv, parser.parseTlv(ofListBytes));
+ assertEquals(tlv, parser.parseTlv(ByteArray.cutBytes(ofListBytes, 4)));
assertArrayEquals(ofListBytes, parser.serializeTlv(tlv));
}
}
*/
package org.opendaylight.protocol.pcep.spi;
+import java.util.Arrays;
+
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
import org.slf4j.Logger;
protected static final int PADDED_TO = 4;
- private final TlvHandlerRegistry tlvReg;
+ private final TlvRegistry tlvReg;
- protected AbstractObjectWithTlvsParser(final TlvHandlerRegistry tlvReg) {
+ protected AbstractObjectWithTlvsParser(final TlvRegistry tlvReg) {
this.tlvReg = Preconditions.checkNotNull(tlvReg);
}
final byte[] tlvBytes = ByteArray.subByte(bytes, byteOffset, length);
LOG.trace("Attempt to parse tlv from bytes: {}", ByteArray.bytesToHexString(tlvBytes));
- final TlvParser parser = this.tlvReg.getTlvParser(type);
- if (parser != null) {
- final Tlv tlv = parser.parseTlv(tlvBytes);
- LOG.trace("Tlv was parsed. {}", tlv);
- addTlv(builder, tlv);
- } else {
- LOG.warn("Unknown TLV received. Type {}. Ignoring it.", type);
- }
+ final Tlv tlv = this.tlvReg.parseTlv(type, tlvBytes);
+ LOG.trace("Tlv was parsed. {}", tlv);
+ addTlv(builder, tlv);
byteOffset += length + getPadding(TLV_HEADER_LENGTH + length, PADDED_TO);
}
}
protected final byte[] serializeTlv(final Tlv tlv) {
-
- final TlvSerializer serializer = this.tlvReg.getTlvSerializer(tlv);
- LOG.trace("Choosen serializer {}", serializer);
-
- final byte[] typeBytes = ByteArray.intToBytes(serializer.getType(), TLV_TYPE_F_LENGTH);
-
- final byte[] valueBytes = serializer.serializeTlv(tlv);
-
- final byte[] lengthBytes = ByteArray.intToBytes(valueBytes.length, TLV_LENGTH_F_LENGTH);
-
- final byte[] bytes = new byte[TLV_HEADER_LENGTH + valueBytes.length + getPadding(TLV_HEADER_LENGTH + valueBytes.length, PADDED_TO)];
-
- int byteOffset = 0;
- System.arraycopy(typeBytes, 0, bytes, byteOffset, TLV_TYPE_F_LENGTH);
- byteOffset += TLV_TYPE_F_LENGTH;
- System.arraycopy(lengthBytes, 0, bytes, byteOffset, TLV_LENGTH_F_LENGTH);
- byteOffset += TLV_LENGTH_F_LENGTH;
- System.arraycopy(valueBytes, 0, bytes, byteOffset, valueBytes.length);
- return bytes;
+ Preconditions.checkNotNull(tlv, "PCEP TLV is mandatory.");
+ LOG.trace("Serializing PCEP TLV {}", tlv);
+ final byte[] ret = this.tlvReg.serializeTlv(tlv);
+ if (ret == null) {
+ LOG.warn("TLV serializer for type {} could not be found.", tlv);
+ }
+ LOG.trace("Serialized PCEP TLV {}.", Arrays.toString(ret));
+ return ret;
}
protected void addTlv(final T builder, final Tlv tlv) {
// FIXME: No TLVs by default, fallback to augments
}
- protected static int getPadding(final int length, final int padding) {
+ public static int getPadding(final int length, final int padding) {
return (padding - (length % padding)) % padding;
}
}
+++ /dev/null
-/*
- * 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.protocol.pcep.spi;
-
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.SubobjectType;
-
-public interface EROSubobjectHandlerRegistry {
- EROSubobjectParser getSubobjectParser(int subobjectType);
- EROSubobjectSerializer getSubobjectSerializer(SubobjectType subobject);
-}
--- /dev/null
+/*
+ * 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.protocol.pcep.spi;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject;
+
+public interface EROSubobjectRegistry {
+ /**
+ * Finds parser for given subobject type in the registry. Delegates parsing to found parser.
+ * @param type subobject type, key in parser registry
+ * @param buffer subobject raw binary value to be parsed
+ * @param loose ERO specific common field
+ * @return null if the parser for this subobject could not be found
+ * @throws PCEPDeserializerException if the parsing did not succeed
+ */
+ Subobject parseSubobject(final int subobjectType, final byte[] buffer, final boolean loose) throws PCEPDeserializerException;
+
+ /**
+ * Find serializer for given subobject. Delegates parsing to found serializer.
+ * @param subobject to be parsed
+ * @return null if the serializer for this subobject could not be found
+ */
+ byte[] serializeSubobject(final Subobject subobject);
+}
ObjectHandlerRegistry getObjectHandlerRegistry();
- EROSubobjectHandlerRegistry getEROSubobjectHandlerRegistry();
+ EROSubobjectRegistry getEROSubobjectHandlerRegistry();
- RROSubobjectHandlerRegistry getRROSubobjectHandlerRegistry();
+ RROSubobjectRegistry getRROSubobjectHandlerRegistry();
- XROSubobjectHandlerRegistry getXROSubobjectHandlerRegistry();
+ XROSubobjectRegistry getXROSubobjectHandlerRegistry();
- TlvHandlerRegistry getTlvHandlerRegistry();
+ TlvRegistry getTlvHandlerRegistry();
}
+++ /dev/null
-/*
- * 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.protocol.pcep.spi;
-
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.record.route.subobjects.SubobjectType;
-
-public interface RROSubobjectHandlerRegistry {
- RROSubobjectParser getSubobjectParser(int subobjectType);
- RROSubobjectSerializer getSubobjectSerializer(SubobjectType subobject);
-}
--- /dev/null
+/*
+ * 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.protocol.pcep.spi;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.Subobject;
+
+public interface RROSubobjectRegistry {
+ /**
+ * Finds parser for given subobject type in the registry. Delegates parsing to found parser.
+ * @param type subobject type, key in parser registry
+ * @param buffer subobject raw binary value to be parsed
+ * @return null if the parser for this subobject could not be found
+ * @throws PCEPDeserializerException if the parsing did not succeed
+ */
+ Subobject parseSubobject(final int type, final byte[] buffer) throws PCEPDeserializerException;
+
+ /**
+ * Find serializer for given subobject. Delegates parsing to found serializer.
+ * @param subobject to be parsed
+ * @return null if the serializer for this subobject could not be found
+ */
+ byte[] serializeSubobject(final Subobject subobject);
+}
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
-public interface TlvHandlerRegistry {
- TlvParser getTlvParser(int tlvType);
- TlvSerializer getTlvSerializer(Tlv tlv);
+public interface TlvRegistry {
+ Tlv parseTlv(final int type, final byte[] buffer) throws PCEPDeserializerException;
+ byte[] serializeTlv(final Tlv tlv);
}
+++ /dev/null
-/*
- * 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.protocol.pcep.spi;
-
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.SubobjectType;
-
-public interface XROSubobjectHandlerRegistry {
- XROSubobjectParser getSubobjectParser(int subobjectType);
- XROSubobjectSerializer getSubobjectSerializer(SubobjectType subobject);
-}
--- /dev/null
+/*
+ * 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.protocol.pcep.spi;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.xro.Subobject;
+
+public interface XROSubobjectRegistry {
+ /**
+ * Finds parser for given subobject type in the registry. Delegates parsing to found parser.
+ * @param type subobject type, key in parser registry
+ * @param buffer subobject raw binary value to be parsed
+ * @param mandatory XRO specific common field
+ * @return null if the parser for this subobject could not be found
+ * @throws PCEPDeserializerException if the parsing did not succeed
+ */
+ Subobject parseSubobject(final int type, final byte[] buffer, final boolean mandatory) throws PCEPDeserializerException;
+
+ /**
+ * Find serializer for given subobject. Delegates parsing to found serializer.
+ * @param subobject to be parsed
+ * @return null if the serializer for this subobject could not be found
+ */
+ byte[] serializeSubobject(final Subobject subobject);
+}
package org.opendaylight.protocol.pcep.spi.pojo;
import org.opendaylight.protocol.concepts.HandlerRegistry;
-import org.opendaylight.protocol.pcep.spi.EROSubobjectHandlerRegistry;
import org.opendaylight.protocol.pcep.spi.EROSubobjectParser;
+import org.opendaylight.protocol.pcep.spi.EROSubobjectRegistry;
import org.opendaylight.protocol.pcep.spi.EROSubobjectSerializer;
+import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.util.Values;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.SubobjectType;
import org.opendaylight.yangtools.yang.binding.DataContainer;
import com.google.common.base.Preconditions;
-public final class SimpleEROSubobjectHandlerRegistry implements EROSubobjectHandlerRegistry {
+public final class SimpleEROSubobjectRegistry implements EROSubobjectRegistry {
private final HandlerRegistry<DataContainer, EROSubobjectParser, EROSubobjectSerializer> handlers = new HandlerRegistry<>();
public AutoCloseable registerSubobjectParser(final int subobjectType, final EROSubobjectParser parser) {
}
@Override
- public EROSubobjectParser getSubobjectParser(final int subobjectType) {
- Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= Values.UNSIGNED_SHORT_MAX_VALUE);
- return this.handlers.getParser(subobjectType);
+ public Subobject parseSubobject(int type, byte[] buffer, boolean loose) throws PCEPDeserializerException {
+ Preconditions.checkArgument(type >= 0 && type <= Values.UNSIGNED_SHORT_MAX_VALUE);
+ final EROSubobjectParser parser = this.handlers.getParser(type);
+ if (parser == null) {
+ return null;
+ }
+ return parser.parseSubobject(buffer, loose);
}
@Override
- public EROSubobjectSerializer getSubobjectSerializer(final SubobjectType subobject) {
- return this.handlers.getSerializer(subobject.getImplementedInterface());
+ public byte[] serializeSubobject(Subobject subobject) {
+ final EROSubobjectSerializer serializer = this.handlers.getSerializer(subobject.getSubobjectType().getImplementedInterface());
+ if (serializer == null) {
+ return null;
+ }
+ return serializer.serializeSubobject(subobject);
}
}
import javax.annotation.concurrent.ThreadSafe;
-import org.opendaylight.protocol.pcep.spi.EROSubobjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.EROSubobjectRegistry;
import org.opendaylight.protocol.pcep.spi.EROSubobjectParser;
import org.opendaylight.protocol.pcep.spi.EROSubobjectSerializer;
import org.opendaylight.protocol.pcep.spi.LabelHandlerRegistry;
import org.opendaylight.protocol.pcep.spi.ObjectParser;
import org.opendaylight.protocol.pcep.spi.ObjectSerializer;
import org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderContext;
-import org.opendaylight.protocol.pcep.spi.RROSubobjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.RROSubobjectRegistry;
import org.opendaylight.protocol.pcep.spi.RROSubobjectParser;
import org.opendaylight.protocol.pcep.spi.RROSubobjectSerializer;
-import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.protocol.pcep.spi.TlvParser;
import org.opendaylight.protocol.pcep.spi.TlvSerializer;
-import org.opendaylight.protocol.pcep.spi.XROSubobjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.XROSubobjectRegistry;
import org.opendaylight.protocol.pcep.spi.XROSubobjectParser;
import org.opendaylight.protocol.pcep.spi.XROSubobjectSerializer;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
private final SimpleLabelHandlerRegistry labelReg = new SimpleLabelHandlerRegistry();
private final SimpleMessageHandlerRegistry msgReg = new SimpleMessageHandlerRegistry();
private final SimpleObjectHandlerRegistry objReg = new SimpleObjectHandlerRegistry();
- private final SimpleEROSubobjectHandlerRegistry eroSubReg = new SimpleEROSubobjectHandlerRegistry();
- private final SimpleRROSubobjectHandlerRegistry rroSubReg = new SimpleRROSubobjectHandlerRegistry();
- private final SimpleXROSubobjectHandlerRegistry xroSubReg = new SimpleXROSubobjectHandlerRegistry();
- private final SimpleTlvHandlerRegistry tlvReg = new SimpleTlvHandlerRegistry();
+ private final SimpleEROSubobjectRegistry eroSubReg = new SimpleEROSubobjectRegistry();
+ private final SimpleRROSubobjectRegistry rroSubReg = new SimpleRROSubobjectRegistry();
+ private final SimpleXROSubobjectRegistry xroSubReg = new SimpleXROSubobjectRegistry();
+ private final SimpleTlvRegistry tlvReg = new SimpleTlvRegistry();
@Override
public final LabelHandlerRegistry getLabelHandlerRegistry() {
}
@Override
- public final EROSubobjectHandlerRegistry getEROSubobjectHandlerRegistry() {
+ public final EROSubobjectRegistry getEROSubobjectHandlerRegistry() {
return this.eroSubReg;
}
@Override
- public final RROSubobjectHandlerRegistry getRROSubobjectHandlerRegistry() {
+ public final RROSubobjectRegistry getRROSubobjectHandlerRegistry() {
return this.rroSubReg;
}
@Override
- public final XROSubobjectHandlerRegistry getXROSubobjectHandlerRegistry() {
+ public final XROSubobjectRegistry getXROSubobjectHandlerRegistry() {
return this.xroSubReg;
}
@Override
- public final TlvHandlerRegistry getTlvHandlerRegistry() {
+ public final TlvRegistry getTlvHandlerRegistry() {
return this.tlvReg;
}
package org.opendaylight.protocol.pcep.spi.pojo;
import org.opendaylight.protocol.concepts.HandlerRegistry;
-import org.opendaylight.protocol.pcep.spi.RROSubobjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.RROSubobjectParser;
+import org.opendaylight.protocol.pcep.spi.RROSubobjectRegistry;
import org.opendaylight.protocol.pcep.spi.RROSubobjectSerializer;
import org.opendaylight.protocol.util.Values;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.Subobject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.record.route.subobjects.SubobjectType;
import org.opendaylight.yangtools.yang.binding.DataContainer;
import com.google.common.base.Preconditions;
-public final class SimpleRROSubobjectHandlerRegistry implements RROSubobjectHandlerRegistry {
+public final class SimpleRROSubobjectRegistry implements RROSubobjectRegistry {
private final HandlerRegistry<DataContainer, RROSubobjectParser, RROSubobjectSerializer> handlers = new HandlerRegistry<>();
public AutoCloseable registerSubobjectParser(final int subobjectType, final RROSubobjectParser parser) {
return this.handlers.registerParser(subobjectType, parser);
}
- @Override
- public RROSubobjectParser getSubobjectParser(final int subobjectType) {
- Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= Values.UNSIGNED_SHORT_MAX_VALUE);
- return this.handlers.getParser(subobjectType);
- }
-
public AutoCloseable registerSubobjectSerializer(final Class<? extends SubobjectType> subobjectClass,
final RROSubobjectSerializer serializer) {
return this.handlers.registerSerializer(subobjectClass, serializer);
}
@Override
- public RROSubobjectSerializer getSubobjectSerializer(final SubobjectType subobject) {
- return this.handlers.getSerializer(subobject.getImplementedInterface());
+ public Subobject parseSubobject(int type, byte[] buffer) throws PCEPDeserializerException {
+ Preconditions.checkArgument(type >= 0 && type <= Values.UNSIGNED_SHORT_MAX_VALUE);
+ final RROSubobjectParser parser = this.handlers.getParser(type);
+ if (parser == null) {
+ return null;
+ }
+ return parser.parseSubobject(buffer);
+ }
+
+ @Override
+ public byte[] serializeSubobject(Subobject subobject) {
+ final RROSubobjectSerializer serializer = this.handlers.getSerializer(subobject.getSubobjectType().getImplementedInterface());
+ if (serializer == null) {
+ return null;
+ }
+ return serializer.serializeSubobject(subobject);
}
}
package org.opendaylight.protocol.pcep.spi.pojo;
import org.opendaylight.protocol.concepts.HandlerRegistry;
-import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.TlvParser;
+import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.protocol.pcep.spi.TlvSerializer;
import org.opendaylight.protocol.util.Values;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
/**
*
*/
-public final class SimpleTlvHandlerRegistry implements TlvHandlerRegistry {
+public final class SimpleTlvRegistry implements TlvRegistry {
+
private final HandlerRegistry<DataContainer, TlvParser, TlvSerializer> handlers = new HandlerRegistry<>();
public AutoCloseable registerTlvParser(final int tlvType, final TlvParser parser) {
}
@Override
- public TlvParser getTlvParser(final int tlvType) {
- return this.handlers.getParser(tlvType);
+ public Tlv parseTlv(final int type, final byte[] buffer) throws PCEPDeserializerException {
+ Preconditions.checkArgument(type >= 0 && type <= Values.UNSIGNED_SHORT_MAX_VALUE);
+ final TlvParser parser = this.handlers.getParser(type);
+ if (parser == null) {
+ return null;
+ }
+ return parser.parseTlv(buffer);
}
@Override
- public TlvSerializer getTlvSerializer(final Tlv tlv) {
- return this.handlers.getSerializer(tlv.getImplementedInterface());
+ public byte[] serializeTlv(final Tlv tlv) {
+ final TlvSerializer serializer = this.handlers.getSerializer(tlv.getImplementedInterface());
+ if (serializer == null) {
+ return null;
+ }
+ return serializer.serializeTlv(tlv);
}
}
package org.opendaylight.protocol.pcep.spi.pojo;
import org.opendaylight.protocol.concepts.HandlerRegistry;
-import org.opendaylight.protocol.pcep.spi.XROSubobjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.XROSubobjectParser;
+import org.opendaylight.protocol.pcep.spi.XROSubobjectRegistry;
import org.opendaylight.protocol.pcep.spi.XROSubobjectSerializer;
import org.opendaylight.protocol.util.Values;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.xro.Subobject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.SubobjectType;
import org.opendaylight.yangtools.yang.binding.DataContainer;
import com.google.common.base.Preconditions;
-public final class SimpleXROSubobjectHandlerRegistry implements XROSubobjectHandlerRegistry {
+public final class SimpleXROSubobjectRegistry implements XROSubobjectRegistry {
private final HandlerRegistry<DataContainer, XROSubobjectParser, XROSubobjectSerializer> handlers = new HandlerRegistry<>();
public AutoCloseable registerSubobjectParser(final int subobjectType, final XROSubobjectParser parser) {
}
@Override
- public XROSubobjectParser getSubobjectParser(final int subobjectType) {
- Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= Values.UNSIGNED_SHORT_MAX_VALUE);
- return this.handlers.getParser(subobjectType);
+ public Subobject parseSubobject(int type, byte[] buffer, boolean mandatory) throws PCEPDeserializerException {
+ Preconditions.checkArgument(type >= 0 && type <= Values.UNSIGNED_SHORT_MAX_VALUE);
+ final XROSubobjectParser parser = this.handlers.getParser(type);
+ if (parser == null) {
+ return null;
+ }
+ return parser.parseSubobject(buffer, mandatory);
}
@Override
- public XROSubobjectSerializer getSubobjectSerializer(final SubobjectType subobject) {
- return this.handlers.getSerializer(subobject.getImplementedInterface());
+ public byte[] serializeSubobject(Subobject subobject) {
+ final XROSubobjectSerializer serializer = this.handlers.getSerializer(subobject.getSubobjectType().getImplementedInterface());
+ if (serializer == null) {
+ return null;
+ }
+ return serializer.serializeSubobject(subobject);
}
}