Merge "Initial support for RFC2385"
authorDana Kutenicsova <dkutenic@cisco.com>
Wed, 19 Mar 2014 08:22:39 +0000 (08:22 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Wed, 19 Mar 2014 08:22:39 +0000 (08:22 +0000)
109 files changed:
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/BGPActivator.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/BGPActivator.java
bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/AbstractBGPExtensionProviderActivator.java [moved from bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/pojo/AbstractBGPExtensionProviderActivator.java with 87% similarity]
bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/AbstractMessageRegistry.java [moved from bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/pojo/AbstractMessageRegistry.java with 93% similarity]
bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/pojo/SimpleMessageRegistry.java
bgp/rib-impl-config/src/main/java/org/opendaylight/controller/config/reconnectstrategy/util/ReconnectStrategyCloseable.java [deleted file]
bgp/rib-impl-config/src/main/java/org/opendaylight/controller/config/yang/bgp/rib/impl/RIBImplModule.java
bgp/rib-impl-config/src/main/java/org/opendaylight/controller/config/yang/reconnectstrategy/NeverReconnectStrategyModule.java
bgp/rib-impl-config/src/main/java/org/opendaylight/controller/config/yang/reconnectstrategy/ReconnectImmediatelyStrategyModule.java
bgp/rib-impl-config/src/main/java/org/opendaylight/controller/config/yang/reconnectstrategy/TimedReconnectStrategyModule.java
bgp/rib-impl-config/src/main/yang/reconnect-strategy.yang
bgp/rib-impl-config/src/test/java/org/opendaylight/controller/config/yang/bgp/reconnectstrategy/GlobalEventExecutorUtil.java
bgp/rib-impl-config/src/test/java/org/opendaylight/controller/config/yang/bgp/reconnectstrategy/NeverReconnectStrategyModuleTest.java
bgp/rib-impl-config/src/test/java/org/opendaylight/controller/config/yang/bgp/reconnectstrategy/ReconnectImmediatelyStrategyModuleTest.java
bgp/rib-impl-config/src/test/java/org/opendaylight/controller/config/yang/bgp/reconnectstrategy/TimedReconnectStrategyModuleTest.java
bgp/rib-impl-config/src/test/java/org/opendaylight/controller/config/yang/bgp/rib/impl/BGPDispatcherImplModuleTest.java
bgp/rib-impl-config/src/test/java/org/opendaylight/controller/config/yang/bgp/rib/impl/BGPPeerModuleTest.java
bgp/rib-impl-config/src/test/java/org/opendaylight/controller/config/yang/bgp/rib/impl/BGPTableTypeImplModuleTest.java [new file with mode: 0644]
bgp/rib-impl-config/src/test/java/org/opendaylight/controller/config/yang/bgp/rib/impl/RIBImplModuleTest.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPDispatcherImpl.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPPeer.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/RIBImpl.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/spi/BGPDispatcher.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/spi/RIB.java
commons/distributions/bgpcep-controller/src/assemble/bin.xml
commons/distributions/bgpcep-controller/src/main/resources/configuration/config.ini
integration-tests/src/test/java/org/opendaylight/protocol/integration/AbstractBundleTest.java
integration-tests/src/test/java/org/opendaylight/protocol/integration/bgp/ParserToSalTest.java
pcep/api/src/main/java/org/opendaylight/protocol/pcep/TerminationReason.java
pcep/ietf-stateful02/src/main/java/org/opendaylight/protocol/pcep/crabbe/initiated00/LSPCleanupTlvParser.java
pcep/ietf-stateful02/src/main/java/org/opendaylight/protocol/pcep/crabbe/initiated00/PCEPOpenObjectParser.java
pcep/ietf-stateful02/src/main/java/org/opendaylight/protocol/pcep/crabbe/initiated00/PCEStatefulCapabilityTlvParser.java
pcep/ietf-stateful02/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful02/Stateful02LspDbVersionTlvParser.java
pcep/ietf-stateful02/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful02/Stateful02LspObjectParser.java
pcep/ietf-stateful02/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful02/Stateful02LspSymbolicNameTlvParser.java
pcep/ietf-stateful02/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful02/Stateful02LspaObjectParser.java
pcep/ietf-stateful02/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful02/Stateful02NodeIdentifierTlvParser.java
pcep/ietf-stateful02/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful02/Stateful02OpenObjectParser.java
pcep/ietf-stateful02/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful02/Stateful02RSVPErrorSpecTlvParser.java
pcep/ietf-stateful02/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful02/Stateful02StatefulCapabilityTlvParser.java
pcep/ietf-stateful02/src/test/java/org/opendaylight/protocol/pcep/ietf/PCEPObjectParserTest.java
pcep/ietf-stateful02/src/test/java/org/opendaylight/protocol/pcep/ietf/PCEPTlvParserTest.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/initiated00/CInitiated00LspObjectParser.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/initiated00/CInitiated00SrpObjectParser.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/initiated00/CInitiated00StatefulCapabilityTlvParser.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/initiated00/CrabbeInitiatedActivator.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07LSPIdentifierIpv4TlvParser.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07LSPIdentifierIpv6TlvParser.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07LspObjectParser.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07LspSymbolicNameTlvParser.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07LspUpdateErrorTlvParser.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07LspaObjectParser.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07OpenObjectParser.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07RSVPErrorSpecTlvParser.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07SrpObjectParser.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07StatefulCapabilityTlvParser.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/StatefulActivator.java
pcep/ietf-stateful07/src/test/java/org/opendaylight/protocol/pcep/ietf/PCEPObjectParserTest.java
pcep/ietf-stateful07/src/test/java/org/opendaylight/protocol/pcep/ietf/PCEPTlvParserTest.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/Activator.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/AbstractBandwidthParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/AbstractEROWithSubobjectsParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/AbstractRROWithSubobjectsParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/AbstractXROWithSubobjectsParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPBandwidthObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPClassTypeObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPCloseObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPEndPointsIpv4ObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPEndPointsIpv6ObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPErrorObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPExcludeRouteObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPExistingBandwidthObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPExplicitRouteObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPGlobalConstraintsObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPIncludeRouteObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPLoadBalancingObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPLspaObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPMetricObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPNoPathObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPNotificationObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPObjectiveFunctionObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPOpenObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPPathKeyObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPReportedRouteObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPRequestParameterObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPSvecObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROExplicitExclusionRouteSubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/NoPathVectorTlvParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/OFListTlvParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/OrderTlvParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/OverloadedDurationTlvParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/ReqMissingTlvParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/TlvUtil.java [new file with mode: 0644]
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPObjectParserTest.java
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPTlvParserTest.java
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/AbstractObjectWithTlvsParser.java
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/EROSubobjectHandlerRegistry.java [deleted file]
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/EROSubobjectRegistry.java [new file with mode: 0644]
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PCEPExtensionConsumerContext.java
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/RROSubobjectHandlerRegistry.java [deleted file]
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/RROSubobjectRegistry.java [new file with mode: 0644]
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/TlvRegistry.java [moved from pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/TlvHandlerRegistry.java with 74% similarity]
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/XROSubobjectHandlerRegistry.java [deleted file]
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/XROSubobjectRegistry.java [new file with mode: 0644]
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleEROSubobjectRegistry.java [moved from pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleEROSubobjectHandlerRegistry.java with 60% similarity]
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimplePCEPExtensionProviderContext.java
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleRROSubobjectRegistry.java [moved from pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleRROSubobjectHandlerRegistry.java with 60% similarity]
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleTlvRegistry.java [moved from pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleTlvHandlerRegistry.java with 64% similarity]
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleXROSubobjectRegistry.java [moved from pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleXROSubobjectHandlerRegistry.java with 60% similarity]

index 53ae77bf3f727cbbbd8232933aa06a87c48f79ed..a2bb50dcc401ea7e56a63617e1d07f511d7594bd 100644 (file)
@@ -10,8 +10,8 @@ package org.opendaylight.protocol.bgp.linkstate;
 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;
index 890ca5e1958bfef0fab826b8a3f5aa4acd71ed95..54b4088e7cdf274ae0eaab60d3fbe5db4b525c4d 100644 (file)
@@ -35,6 +35,7 @@ import org.opendaylight.protocol.bgp.parser.impl.message.update.MultiExitDiscrim
 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;
@@ -42,7 +43,6 @@ import org.opendaylight.protocol.bgp.parser.spi.CapabilityRegistry;
 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;
@@ -5,14 +5,12 @@
  * 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;
 
similarity index 93%
rename from bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/pojo/AbstractMessageRegistry.java
rename to bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/AbstractMessageRegistry.java
index 066caff44be814cee13ed0fc5a6d898a20169091..00fac29ca0467803ad5dc15d632f0d3391b1f561 100644 (file)
@@ -5,15 +5,13 @@
  * 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;
@@ -21,7 +19,7 @@ import org.slf4j.LoggerFactory;
 
 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;
index a56b207bfa019a1fa1ed95cd3ff1ee033fdb1c22..9c6b6cfcf798e480f63ca7f1305a96991bc91750 100644 (file)
@@ -8,6 +8,7 @@
 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;
diff --git a/bgp/rib-impl-config/src/main/java/org/opendaylight/controller/config/reconnectstrategy/util/ReconnectStrategyCloseable.java b/bgp/rib-impl-config/src/main/java/org/opendaylight/controller/config/reconnectstrategy/util/ReconnectStrategyCloseable.java
deleted file mode 100644 (file)
index cb660cd..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.controller.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();
-       }
-}
index 865505d959b66883a2730a8f0dc36fed28bfefd3..1deb030f4e13f981dc216e84b11e7add81706f8b 100644 (file)
@@ -18,8 +18,6 @@ package org.opendaylight.controller.config.yang.bgp.rib.impl;
 
 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;
 
 /**
@@ -43,20 +41,16 @@ public final class RIBImplModule extends org.opendaylight.controller.config.yang
                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());
        }
 }
index 254e78222abfeb4abff4312c5afbd0eb8152ff73..8e478a57d531cc8e19b3ba0d6d393e01602fa3ed 100644 (file)
@@ -6,48 +6,72 @@
  * 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);
+        }
+
+    }
 }
index e1b6ebd89e94812e4c56aea473ac00fa4599b294..85f6be5df0976b342efb3e60035c6844b61ee9e6 100644 (file)
@@ -6,48 +6,72 @@
  * 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);
+        }
+
+    }
 }
index d40d35c00b2e25696b3014704eb208bed6bc0ef7..ae18a60b80aa951d1d91552094cde194575feba5 100644 (file)
@@ -6,65 +6,98 @@
  * 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);
+        }
+
+    }
 }
index a65bbe7e739229b9bb834186c67329901458631e..d1050e55905a6507819f0d3211cb4ad0a0980720 100644 (file)
@@ -32,7 +32,7 @@ module reconnect-strategy {
             "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 {
index 58df8bf9d67d800cf57b8f8f59b20db6f41e7a10..d5cb95656f2d2d0fb589d8eff417a97438db4df0 100644 (file)
@@ -7,25 +7,27 @@
  */
 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;
-       }
+    }
 
 }
index ce7abea9c6de88414863a5bfc02d80408386f91d..586a931b0b5b872b021d8f0b34b925073ffe7111 100644 (file)
@@ -7,6 +7,12 @@
  */
 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;
@@ -16,116 +22,89 @@ 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.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;
+    }
 
 }
index e392e4b2c4129e6daae96e5ef26c77009f8cfad1..2084fe6096edf5b9cd50176a8a17fc20bec85289 100644 (file)
  */
 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;
+    }
 
 }
index 0377155fe428425a2a6ef6168592f7674cfae53b..8ca8338e64bf28551e710542f3dfb066ca473fc7 100644 (file)
@@ -7,6 +7,15 @@
  */
 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;
@@ -16,196 +25,143 @@ 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.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;
+    }
 
 }
index dd820ea967f526d6ee9fabd1b660d0c1386d19b2..e0ca9128e749c4eb3e6377ef8faa84e7065eb9ad 100644 (file)
@@ -12,8 +12,6 @@ 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;
@@ -28,97 +26,79 @@ import org.opendaylight.controller.config.yang.netty.timer.HashedWheelTimerModul
 
 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;
+    }
 }
index 6570b0c9bf83e6b31ba49921a59651a8ea4b31b4..b8c350dd0656c9be3edae927899d34de2814b957 100644 (file)
@@ -12,9 +12,9 @@ import static org.junit.Assert.fail;
 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;
@@ -23,12 +23,6 @@ import org.opendaylight.controller.config.api.ValidationException;
 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;
@@ -40,119 +34,107 @@ import com.google.common.collect.Lists;
 
 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();
+    }
 }
diff --git a/bgp/rib-impl-config/src/test/java/org/opendaylight/controller/config/yang/bgp/rib/impl/BGPTableTypeImplModuleTest.java b/bgp/rib-impl-config/src/test/java/org/opendaylight/controller/config/yang/bgp/rib/impl/BGPTableTypeImplModuleTest.java
new file mode 100644 (file)
index 0000000..4bebb4e
--- /dev/null
@@ -0,0 +1,126 @@
+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;
+    }
+
+}
index d6896e9d1b893d3ad18768a5140eb57177f1c2db..2de77398154b758cff0767fbe42be38be62f94b5 100644 (file)
@@ -7,10 +7,11 @@
  */
 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;
@@ -27,6 +28,7 @@ import org.mockito.Matchers;
 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;
@@ -69,239 +71,283 @@ import org.osgi.framework.ServiceReference;
 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));
+    }
 }
index 984c7a859b7596d102553f7cd1cb318cfca8b6a1..e4bb409c3c02d7e7c7c37a8d440f51f406d4cd46 100644 (file)
@@ -53,9 +53,9 @@ public final class BGPDispatcherImpl extends AbstractDispatcher<BGPSessionImpl,
                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());
                        }
                });
        }
@@ -64,7 +64,7 @@ public final class BGPDispatcherImpl extends AbstractDispatcher<BGPSessionImpl,
        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
@@ -73,12 +73,12 @@ public final class BGPDispatcherImpl extends AbstractDispatcher<BGPSessionImpl,
                        }
                };
 
-               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());
                        }
                });
        }
index 8b4e49527704e8a6bf6bb191ab588407d82b7363..86d90248801914177d66fb743dc1721993c5ba54 100644 (file)
@@ -55,18 +55,18 @@ public final class BGPPeer implements BGPSessionListener, Peer, AutoCloseable {
                        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;
                }
        }
 
@@ -84,7 +84,7 @@ public final class BGPPeer implements BGPSessionListener, Peer, AutoCloseable {
                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());
@@ -130,7 +130,7 @@ public final class BGPPeer implements BGPSessionListener, Peer, AutoCloseable {
 
        @Override
        public String getName() {
-               return name;
+               return this.name;
        }
 
        @Override
index c99241b67818ac40b022dec70d2e40134bc4f00d..812415a0a569c811853ffd877e080dd646178206 100644 (file)
@@ -22,7 +22,6 @@ import org.opendaylight.protocol.bgp.rib.impl.spi.RIB;
 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;
@@ -71,7 +70,7 @@ public final class RIBImpl extends DefaultRibReference implements AutoCloseable,
        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;
@@ -80,14 +79,14 @@ public final class RIBImpl extends DefaultRibReference implements AutoCloseable,
        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);
@@ -105,7 +104,7 @@ public final class RIBImpl extends DefaultRibReference implements AutoCloseable,
 
                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);
                        }
                }
@@ -258,32 +257,32 @@ public final class RIBImpl extends DefaultRibReference implements AutoCloseable,
 
        @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
index f474def0cfa06766eada14660c6711fed2032faa..67d21d2bc09d7c46f7b3f9d0f01379151d0a34ea 100644 (file)
@@ -34,5 +34,5 @@ public interface BGPDispatcher {
                        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);
 }
index 1042a28ced7fbfaee84cdf68ebc4660cbab49c86..96ac30dfcb8fece25c2d96e6505cf41a1bc111af 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.protocol.bgp.rib.impl.spi;
 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;
@@ -32,5 +31,5 @@ public interface RIB {
 
        BGPDispatcher getDispatcher();
        ReconnectStrategyFactory getTcpStrategyFactory();
-       ReconnectStrategy getSessionStrategy();
+       ReconnectStrategyFactory getSessionStrategyFactory();
 }
index b23d91abf83ae40a3c8f66ab73c08eb692eaa205..7acca5e9dcb5b6e7b6d89822a0932dbf8b3bb911 100644 (file)
@@ -70,6 +70,7 @@
             </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>
index 442aef6306a4619e2f4f17f92d236627808498d9..50445d7b1049710126348d728fb26f6d65156b27 100644 (file)
@@ -8,7 +8,7 @@ osgi.bundles=\
     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
 
index 8349e54ee6d9c1eaaea88beb6bfed5cc959d41e8..f4f24a69bcd66c49d6c3b7495475c2363e2bb7fd 100644 (file)
@@ -48,6 +48,7 @@ public abstract class AbstractBundleTest {
                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());
index 5fb31c3a499d3a2503c79bbccb06d1115c6f1053..189424545f3f7bf5570652946f4087d7ad751f72 100644 (file)
@@ -45,7 +45,6 @@ import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBExtensionProviderActivat
 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;
@@ -91,7 +90,7 @@ public class ParserToSalTest {
        ReconnectStrategyFactory tcpStrategyFactory;
 
        @Mock
-       ReconnectStrategy sessionStrategy;
+       ReconnectStrategyFactory sessionStrategy;
 
        @Before
        public void setUp() throws Exception {
@@ -158,26 +157,26 @@ public class ParserToSalTest {
 
                }).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);
 
index 7a4f39a51b58f9e2ac1fb7d547b28e31448ac603..9f1438d375196a3502caa1a2123d9dda8670a5ff 100644 (file)
@@ -14,8 +14,8 @@ import com.google.common.collect.Maps;
 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();
index 067a9b7c1d4b5425e42f91f8346608b25f9a0833..ac502a44ce5ad28bfba56ccd5f141575ede5ea5e 100644 (file)
@@ -7,6 +7,7 @@
  */
 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;
@@ -21,7 +22,7 @@ public final class LSPCleanupTlvParser implements TlvParser, 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
index a1df09163be8176d1ba5567357be8788e9c1b49e..041b97e40584e32e2cf14b3e5b80bded685be62c 100644 (file)
@@ -8,7 +8,7 @@
 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;
@@ -26,7 +26,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
  */
 public final class PCEPOpenObjectParser extends Stateful02OpenObjectParser {
 
-       public PCEPOpenObjectParser(final TlvHandlerRegistry tlvReg) {
+       public PCEPOpenObjectParser(final TlvRegistry tlvReg) {
                super(tlvReg);
        }
 
index d5a9c1c22473754b353735ef5af88165b2ddb4ea..1585ecd5901eaab12e3f834917cf5776834fac94 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.protocol.pcep.crabbe.initiated00;
 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;
@@ -67,6 +68,6 @@ public final class PCEStatefulCapabilityTlvParser extends Stateful02StatefulCapa
                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
index 0e898ab3425f804ebdb233edd1d9df846d83c5c5..468af9ff5060981fc7b3f0417a3cc7f3d36e0389 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.protocol.pcep.ietf.stateful02;
 
 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;
@@ -37,7 +38,7 @@ public final class Stateful02LspDbVersionTlvParser implements TlvParser, TlvSeri
        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
index 8f57cc02103b60c8a36856dfb323597d1fed9f58..180d4f957fe09bc27dbe659c41ab93bbfa489a4e 100644 (file)
@@ -12,7 +12,7 @@ import java.util.BitSet;
 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;
@@ -49,7 +49,7 @@ public final class Stateful02LspObjectParser extends AbstractObjectWithTlvsParse
        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);
        }
 
index 958a6088862580d0bcebba76232163c95679132f..bb64746c1659654c78b41eda1d3151adadf5a02f 100644 (file)
@@ -7,6 +7,7 @@
  */
 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;
@@ -33,7 +34,7 @@ public final class Stateful02LspSymbolicNameTlvParser implements TlvParser, TlvS
                        throw new IllegalArgumentException("SymbolicPathNameTlv is mandatory.");
                }
                final SymbolicPathName spn = (SymbolicPathName) tlv;
-               return spn.getPathName().getValue();
+               return TlvUtil.formatTlv(TYPE, spn.getPathName().getValue());
        }
 
        @Override
index d206c10c69669d277bcfca517f2320a80770dc5f..fd2ae865bf9026e12b337c6cfb2ba2728cd9e690 100644 (file)
@@ -8,7 +8,7 @@
 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;
@@ -23,7 +23,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
  */
 public class Stateful02LspaObjectParser extends PCEPLspaObjectParser {
 
-       public Stateful02LspaObjectParser(final TlvHandlerRegistry tlvReg) {
+       public Stateful02LspaObjectParser(final TlvRegistry tlvReg) {
                super(tlvReg);
        }
 
index 1e106c390777f586d84c952343dbd26b62baeadf..31a8483a6da3c7395b5d55357a861685cc5c792a 100644 (file)
@@ -7,6 +7,7 @@
  */
 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;
@@ -25,7 +26,7 @@ public final class Stateful02NodeIdentifierTlvParser implements TlvParser, TlvSe
 
        @Override
        public byte[] serializeTlv(final Tlv tlv) {
-               return ((NodeIdentifier) tlv).getValue();
+               return TlvUtil.formatTlv(TYPE, ((NodeIdentifier) tlv).getValue());
        }
 
        @Override
index aa56c5837be98cbb4c47489c3dc3785812bc5028..25342434865d1e194122b6c8e0150754ab1c4c6d 100644 (file)
@@ -8,7 +8,7 @@
 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;
@@ -24,7 +24,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
  */
 public class Stateful02OpenObjectParser extends PCEPOpenObjectParser {
 
-       public Stateful02OpenObjectParser(final TlvHandlerRegistry tlvReg) {
+       public Stateful02OpenObjectParser(final TlvRegistry tlvReg) {
                super(tlvReg);
        }
 
index 8b4da97f0693fc165ed1657f6958b531ff3ffaa2..1d85ad33070e65a194e7658620a74d7008d5ce6e 100644 (file)
@@ -11,6 +11,7 @@ import java.util.BitSet;
 
 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;
@@ -94,10 +95,10 @@ public final class Stateful02RSVPErrorSpecTlvParser implements TlvParser, TlvSer
 
                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()));
                }
        }
 
@@ -126,7 +127,7 @@ public final class Stateful02RSVPErrorSpecTlvParser implements TlvParser, TlvSer
                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;
index 988a31127815e46f770f3bb698f53a4016594fe6..57a6349e0885464c5acfb3c702724d17e9cb3fde 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.protocol.pcep.ietf.stateful02;
 
 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;
@@ -53,7 +54,7 @@ public class Stateful02StatefulCapabilityTlvParser implements TlvParser, TlvSeri
                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
index 21dd7c5fb4872807f2ecf72400a0ff684f409d8d..c7523647d4e97d4e91a5851f237674d7ad25f3f5 100644 (file)
@@ -18,7 +18,7 @@ import org.opendaylight.protocol.pcep.crabbe.initiated00.PCEPOpenObjectParser;
 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;
@@ -40,7 +40,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev
 
 public class PCEPObjectParserTest {
 
-       private TlvHandlerRegistry tlvRegistry;
+       private TlvRegistry tlvRegistry;
 
        @Before
        public void setUp() throws Exception {
index 060e40bebfb790476424ac6fbbcbd9d5c8dd95cf..c2ade720b1daba5fd59d563cf0fa984e5766f386 100644 (file)
@@ -20,6 +20,7 @@ import org.opendaylight.protocol.pcep.ietf.stateful02.Stateful02LspSymbolicNameT
 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;
@@ -37,27 +38,23 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.cra
 
 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));
        }
 
@@ -66,7 +63,7 @@ public class PCEPTlvParserTest {
                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));
        }
 
@@ -79,7 +76,7 @@ public class PCEPTlvParserTest {
                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));
        }
 
@@ -94,7 +91,7 @@ public class PCEPTlvParserTest {
                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));
        }
 
@@ -107,7 +104,7 @@ public class PCEPTlvParserTest {
                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));
        }
 
@@ -115,7 +112,7 @@ public class PCEPTlvParserTest {
        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));
 
        }
index b39f21abe829586c6afd8fab5ceee93a495d76e3..6569fdb05cc0347eba8ebe1f8ed2c59401335e17 100644 (file)
@@ -12,7 +12,7 @@ import java.util.BitSet;
 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;
@@ -31,7 +31,7 @@ public final class CInitiated00LspObjectParser extends Stateful07LspObjectParser
 
        private static final int CREATE_FLAG_OFFSET = 8;
 
-       public CInitiated00LspObjectParser(final TlvHandlerRegistry tlvReg) {
+       public CInitiated00LspObjectParser(final TlvRegistry tlvReg) {
                super(tlvReg);
        }
 
index c800742a37210392f46418c66f0f3da982684b68..737be9b721b0a9a5622134b6f6b33cfc07abff98 100644 (file)
@@ -13,7 +13,7 @@ import java.util.BitSet;
 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;
@@ -30,7 +30,7 @@ public final class CInitiated00SrpObjectParser extends Stateful07SrpObjectParser
 
        private static final int REMOVE_FLAG = 31;
 
-       public CInitiated00SrpObjectParser(final TlvHandlerRegistry tlvReg) {
+       public CInitiated00SrpObjectParser(final TlvRegistry tlvReg) {
                super(tlvReg);
        }
 
index 171b5a9fb69a70d8fb54e34e0da718b3053edb38..a9ccb0d2060f2d4153b2688324b7e0b2f3694ede 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.protocol.pcep.ietf.initiated00;
 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;
@@ -59,6 +60,6 @@ public final class CInitiated00StatefulCapabilityTlvParser extends Stateful07Sta
                        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));
        }
 }
index ef59729b67eb8d514a6dd4db3253f0859bf92d47..5a1de2053f0604f6dfcd669f6b79904b2bc33a56 100644 (file)
@@ -11,7 +11,7 @@ import java.util.ArrayList;
 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;
@@ -27,7 +27,7 @@ public final class CrabbeInitiatedActivator extends AbstractPCEPExtensionProvide
                                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)));
index 4b1622a62256589ce881e290a517e94d2050687d..6bc0d770ae19057cae9c18f7689a240ad7c377d7 100644 (file)
@@ -8,6 +8,7 @@
 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;
@@ -88,7 +89,7 @@ public final class Stateful07LSPIdentifierIpv4TlvParser implements TlvParser, Tl
                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
index 433521b4420c7b6a09c805b31a6758360304ee0f..17daf51256d641db8188a6d377b30de31bdb9ce5 100644 (file)
@@ -8,6 +8,7 @@
 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;
@@ -81,7 +82,7 @@ public final class Stateful07LSPIdentifierIpv6TlvParser implements TlvParser, Tl
                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
index aa4a2ebcf2eb9ea3f6ebcf4d46040ad78a59db78..74dc7ba7860b93eda90e47d0f6aed3c80c712e4f 100644 (file)
@@ -12,7 +12,7 @@ import java.util.BitSet;
 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;
@@ -54,7 +54,7 @@ public class Stateful07LspObjectParser extends AbstractObjectWithTlvsParser<Tlvs
        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);
        }
 
index 3f0937e9f76a5d158627211d5fefa438a3c903c5..4dac10ada6966d171653c651abc41b4372d43122 100644 (file)
@@ -7,6 +7,7 @@
  */
 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;
@@ -33,7 +34,7 @@ public final class Stateful07LspSymbolicNameTlvParser implements TlvParser, TlvS
                        throw new IllegalArgumentException("SymbolicPathNameTlv is mandatory.");
                }
                final SymbolicPathName spn = (SymbolicPathName) tlv;
-               return spn.getPathName().getValue();
+               return TlvUtil.formatTlv(TYPE, spn.getPathName().getValue());
        }
 
        @Override
index fc752cc27465611bafb2f3459f110d148d3a90ea..cc7d53b1531bc6795117edf0f70e3db92bf17634 100644 (file)
@@ -7,6 +7,7 @@
  */
 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;
@@ -35,7 +36,7 @@ public final class Stateful07LspUpdateErrorTlvParser implements TlvParser, TlvSe
                        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
index 4193ac057b432d5e2dcc6c55c2368d4de523874f..700ad8f585151fc3076134ebf0e14194978ec159 100644 (file)
@@ -8,7 +8,7 @@
 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;
@@ -23,7 +23,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
  */
 public final class Stateful07LspaObjectParser extends PCEPLspaObjectParser {
 
-       public Stateful07LspaObjectParser(final TlvHandlerRegistry tlvReg) {
+       public Stateful07LspaObjectParser(final TlvRegistry tlvReg) {
                super(tlvReg);
        }
 
index d4e93fd26c73a6a7a6172c9174c7e502d3ee7f73..dd64d7eae517eb645cb5fb876e1944fdc01743d1 100644 (file)
@@ -8,7 +8,7 @@
 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;
@@ -23,7 +23,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
  */
 public class Stateful07OpenObjectParser extends PCEPOpenObjectParser {
 
-       public Stateful07OpenObjectParser(final TlvHandlerRegistry tlvReg) {
+       public Stateful07OpenObjectParser(final TlvRegistry tlvReg) {
                super(tlvReg);
        }
 
index 643c543027fd4d2ccd5f55781c31737e7aabe60d..8f8edc496afe2e922e8e656124e2e502981d4c42 100644 (file)
@@ -11,6 +11,7 @@ import java.util.BitSet;
 
 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;
@@ -94,10 +95,10 @@ public final class Stateful07RSVPErrorSpecTlvParser implements TlvParser, TlvSer
 
                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()));
                }
        }
 
index 1e7bb69631cf609822615715cd9ff6b181505bc4..cfbc85bf6971fef0d8b1faab830514ac7f274ab9 100644 (file)
@@ -12,7 +12,7 @@ import java.util.Arrays;
 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;
@@ -41,7 +41,7 @@ public class Stateful07SrpObjectParser extends AbstractObjectWithTlvsParser<SrpB
 
        protected static final int MIN_SIZE = FLAGS_SIZE + SRP_ID_SIZE;
 
-       public Stateful07SrpObjectParser(final TlvHandlerRegistry tlvReg) {
+       public Stateful07SrpObjectParser(final TlvRegistry tlvReg) {
                super(tlvReg);
        }
 
index e188013fcd63cbac045f2ddbba9df87176a6aeae..319c30bb17593b626c5c3a46ff52ef1722270f49 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.protocol.pcep.ietf.stateful07;
 
 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;
@@ -54,7 +55,7 @@ public class Stateful07StatefulCapabilityTlvParser implements TlvParser, TlvSeri
                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
index ce274ba45b2c6a4b4a47b73c8d0f6dec8ab317d6..0125e462f9db915e916b8753997bbbae882cbf46 100644 (file)
@@ -12,7 +12,7 @@ import java.util.List;
 
 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;
@@ -36,7 +36,7 @@ public final class StatefulActivator extends AbstractPCEPExtensionProviderActiva
                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)));
index 45c79f821f14fe51c9a6e58b8f5d5c6636b12adc..adca0b3fcdecd2a4f0e6d4dca7f9e19755f2590a 100644 (file)
@@ -20,7 +20,7 @@ import org.opendaylight.protocol.pcep.ietf.stateful07.Stateful07LspaObjectParser
 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;
@@ -50,7 +50,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev
 
 public class PCEPObjectParserTest {
 
-       private TlvHandlerRegistry tlvRegistry;
+       private TlvRegistry tlvRegistry;
 
        @Before
        public void setUp() throws Exception {
index 0516f279c86c839d538168c561fbf2b3c8eab223..b55d93c28139d95f32dcc83c6076564c918660d6 100644 (file)
@@ -17,9 +17,10 @@ import org.opendaylight.protocol.pcep.ietf.stateful07.Stateful07LSPIdentifierIpv
 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;
@@ -47,36 +48,30 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev
 
 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));
        }
 
@@ -84,8 +79,8 @@ public class PCEPTlvParserTest {
        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));
        }
 
@@ -93,7 +88,7 @@ public class PCEPTlvParserTest {
        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));
        }
 
@@ -107,7 +102,7 @@ public class PCEPTlvParserTest {
                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));
        }
 
@@ -126,7 +121,7 @@ public class PCEPTlvParserTest {
                                (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));
        }
 
@@ -139,7 +134,7 @@ public class PCEPTlvParserTest {
                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));
        }
 
@@ -154,7 +149,7 @@ public class PCEPTlvParserTest {
                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));
        }
 
@@ -167,7 +162,7 @@ public class PCEPTlvParserTest {
                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));
        }
 }
index 5360f6327f8361d8b01f152ba25c604b8c07b820..fb1ba57facd2afa70f89b0c5809518f9542b8c67 100644 (file)
@@ -64,13 +64,13 @@ import org.opendaylight.protocol.pcep.impl.tlv.OFListTlvParser;
 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;
@@ -123,7 +123,7 @@ public final class Activator extends AbstractPCEPExtensionProviderActivator {
                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());
@@ -138,7 +138,7 @@ public final class Activator extends AbstractPCEPExtensionProviderActivator {
                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));
@@ -159,7 +159,7 @@ public final class Activator extends AbstractPCEPExtensionProviderActivator {
                                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());
@@ -174,7 +174,7 @@ public final class Activator extends AbstractPCEPExtensionProviderActivator {
                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());
index ea7bb0bf0807b51767717a6e76d5db2ff98fdb95..512dbd78730347460ae4336563d08f33d6f68003 100644 (file)
@@ -9,7 +9,7 @@ package org.opendaylight.protocol.pcep.impl.object;
 
 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;
@@ -18,7 +18,7 @@ abstract class AbstractBandwidthParser extends AbstractObjectWithTlvsParser<Band
 
        private static final int BANDWIDTH_F_LENGTH = 4;
 
-       AbstractBandwidthParser(final TlvHandlerRegistry tlvReg) {
+       AbstractBandwidthParser(final TlvRegistry tlvReg) {
                super(tlvReg);
        }
 
index 324e9f40e3934c0695ee7fe9af6cbe9a20df40d0..5fd58c8f826b41a431bb2e235af2e34a83fc2023 100644 (file)
@@ -9,8 +9,7 @@ package org.opendaylight.protocol.pcep.impl.object;
 
 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;
@@ -33,9 +32,9 @@ public abstract class AbstractEROWithSubobjectsParser implements ObjectParser, O
        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);
        }
 
@@ -68,32 +67,30 @@ public abstract class AbstractEROWithSubobjectsParser implements ObjectParser, O
                        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) {
index 412c61b4e8d5a49ceb53112de9cb76b17d614ad8..a6de248353a7d7506b1d75159fda82eb1a399078 100644 (file)
@@ -12,8 +12,7 @@ import java.util.List;
 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;
@@ -33,9 +32,9 @@ public abstract class AbstractRROWithSubobjectsParser implements ObjectParser, O
        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);
        }
 
@@ -67,31 +66,30 @@ public abstract class AbstractRROWithSubobjectsParser implements ObjectParser, O
                        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) {
index cd2d0628ba26e3e6b00f7f72035978c466cd0a74..a7bee2d2c37e256cc6aed24b9c5358040de37f1f 100644 (file)
@@ -12,8 +12,7 @@ import java.util.List;
 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;
@@ -35,9 +34,9 @@ public abstract class AbstractXROWithSubobjectsParser implements ObjectParser, O
        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);
        }
 
@@ -70,31 +69,30 @@ public abstract class AbstractXROWithSubobjectsParser implements ObjectParser, O
                        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) {
index 64ca01e1705815226b371ebef900ab480cc294ad..0910199d789e94db2401805871980134bddaf745 100644 (file)
@@ -10,7 +10,7 @@ package org.opendaylight.protocol.pcep.impl.object;
 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;
 
@@ -25,7 +25,7 @@ public class PCEPBandwidthObjectParser extends AbstractBandwidthParser {
 
        private static final int BANDWIDTH_LENGTH = 4;
 
-       public PCEPBandwidthObjectParser(final TlvHandlerRegistry tlvReg) {
+       public PCEPBandwidthObjectParser(final TlvRegistry tlvReg) {
                super(tlvReg);
        }
 
index dd020084549391e24e0679b0abe188a0b3f0dd98..67087ad716db387416b4faf30ca6a7e6c6349b57 100644 (file)
@@ -11,7 +11,7 @@ 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.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;
@@ -47,7 +47,7 @@ public class PCEPClassTypeObjectParser extends AbstractObjectWithTlvsParser<Clas
         */
        private static final int SIZE = (RESERVED + CT_F_LENGTH) / 8;
 
-       public PCEPClassTypeObjectParser(final TlvHandlerRegistry tlvReg) {
+       public PCEPClassTypeObjectParser(final TlvRegistry tlvReg) {
                super(tlvReg);
        }
 
index 8710a77d13ce05d641a1f9a2c92aa5fab44400a1..14375e75daff5ffe558e6a9894d7b79a2d9c38b7 100644 (file)
@@ -10,7 +10,7 @@ package org.opendaylight.protocol.pcep.impl.object;
 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;
@@ -46,7 +46,7 @@ public class PCEPCloseObjectParser extends AbstractObjectWithTlvsParser<CCloseBu
         */
        private static final int TLVS_OFFSET = REASON_F_OFFSET + REASON_F_LENGTH;
 
-       public PCEPCloseObjectParser(final TlvHandlerRegistry tlvReg) {
+       public PCEPCloseObjectParser(final TlvRegistry tlvReg) {
                super(tlvReg);
        }
 
index 681e3faf2deabcfb4468a678c4f9e7cb4cf1233c..ef905e4874ce511b089fd3ade6c1b6dfca9cb563 100644 (file)
@@ -12,7 +12,7 @@ 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.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;
@@ -45,7 +45,7 @@ public class PCEPEndPointsIpv4ObjectParser extends AbstractObjectWithTlvsParser<
        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);
        }
 
index 2cc12f9565b373afd25b9f896de628253da64807..25c1efcf92c300f69beb4253dc97b22ce7e3f2e5 100644 (file)
@@ -12,7 +12,7 @@ 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.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;
@@ -45,7 +45,7 @@ public class PCEPEndPointsIpv6ObjectParser extends AbstractObjectWithTlvsParser<
        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);
        }
 
index 84c4479f29b0e02e7eca81db7da6b6060e2ddf24..44c7b0bfe0b6d045790364b09055a6690562242f 100644 (file)
@@ -10,7 +10,7 @@ package org.opendaylight.protocol.pcep.impl.object;
 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;
@@ -41,7 +41,7 @@ public class PCEPErrorObjectParser extends AbstractObjectWithTlvsParser<ErrorObj
        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);
        }
 
index 1ca2adf11b1bae8e8f3f4dacc4687ade5d8e1674..ce612b8e8ee996cfa36f88156dc7c126445925e0 100644 (file)
@@ -9,7 +9,7 @@ package org.opendaylight.protocol.pcep.impl.object;
 
 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;
@@ -30,7 +30,7 @@ public final class PCEPExcludeRouteObjectParser extends AbstractXROWithSubobject
 
        private static final int FLAGS_OFFSET = 3;
 
-       public PCEPExcludeRouteObjectParser(final XROSubobjectHandlerRegistry registry) {
+       public PCEPExcludeRouteObjectParser(final XROSubobjectRegistry registry) {
                super(registry);
        }
 
index af263908922f1b4c9af503afba4292e5c0807c4e..e86abaf5518011a9d8098971196fec20ef09f5de 100644 (file)
@@ -10,7 +10,7 @@ package org.opendaylight.protocol.pcep.impl.object;
 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;
 
@@ -25,7 +25,7 @@ public class PCEPExistingBandwidthObjectParser extends AbstractBandwidthParser {
 
        private static final int BANDWIDTH_LENGTH = 4;
 
-       public PCEPExistingBandwidthObjectParser(final TlvHandlerRegistry tlvReg) {
+       public PCEPExistingBandwidthObjectParser(final TlvRegistry tlvReg) {
                super(tlvReg);
        }
 
index bec1f4c5f59d642c6a21765ebba5772d8c41f2dd..550b2730367e0761bb2b73bcffff44821f2a2373 100644 (file)
@@ -7,7 +7,7 @@
  */
 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;
@@ -24,7 +24,7 @@ public class PCEPExplicitRouteObjectParser extends AbstractEROWithSubobjectsPars
 
        public static final int TYPE = 1;
 
-       public PCEPExplicitRouteObjectParser(final EROSubobjectHandlerRegistry subobjReg) {
+       public PCEPExplicitRouteObjectParser(final EROSubobjectRegistry subobjReg) {
                super(subobjReg);
        }
 
index 995a0df2d04601f4a166f35310cdf3bdb86d3290..f046722db314af9c2a2d46418ce23bdb6bfead4b 100644 (file)
@@ -10,7 +10,7 @@ package org.opendaylight.protocol.pcep.impl.object;
 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;
@@ -39,7 +39,7 @@ public class PCEPGlobalConstraintsObjectParser extends AbstractObjectWithTlvsPar
 
        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);
        }
 
index 47950d0e6307e0169e2d83a35fcc0f3150dea601..da537b6717c473f3d24ca6f41d4b8f6d838d85fc 100644 (file)
@@ -9,7 +9,7 @@ package org.opendaylight.protocol.pcep.impl.object;
 
 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;
@@ -30,7 +30,7 @@ public class PCEPIncludeRouteObjectParser extends AbstractEROWithSubobjectsParse
 
        public static final int TYPE = 1;
 
-       public PCEPIncludeRouteObjectParser(final EROSubobjectHandlerRegistry subobjReg) {
+       public PCEPIncludeRouteObjectParser(final EROSubobjectRegistry subobjReg) {
                super(subobjReg);
        }
 
index 229504490aa73297fe3f5d40ae3ea0344af9b3a9..01af33f8cfb612e9405679918540636ff25452ea 100644 (file)
@@ -10,7 +10,7 @@ package org.opendaylight.protocol.pcep.impl.object;
 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;
@@ -39,7 +39,7 @@ public class PCEPLoadBalancingObjectParser extends AbstractObjectWithTlvsParser<
 
        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);
        }
 
index 6865faadee132179aa3800ece113c25a42ab4f75..56f451a0554ac010118ed8e6cb89ca0d635022b6 100644 (file)
@@ -12,7 +12,7 @@ import java.util.BitSet;
 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;
@@ -59,7 +59,7 @@ public class PCEPLspaObjectParser extends AbstractObjectWithTlvsParser<TlvsBuild
        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);
        }
 
index 92f985823c8bd634147a77acb09db98092cd12bd..83a759bbc057da9558b02c9e28eaaa663d164688 100644 (file)
@@ -12,7 +12,7 @@ import java.util.BitSet;
 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;
@@ -53,7 +53,7 @@ public class PCEPMetricObjectParser extends AbstractObjectWithTlvsParser<MetricB
 
        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);
        }
 
index 482905c580bb6a483f20564c54ff7ebb730e04d4..a96451513aac7d696baf1200361f0b5fb54201b4 100644 (file)
@@ -12,7 +12,7 @@ import java.util.BitSet;
 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;
@@ -54,7 +54,7 @@ public class PCEPNoPathObjectParser extends AbstractObjectWithTlvsParser<NoPathB
         */
        private static final int C_FLAG_OFFSET = 0;
 
-       public PCEPNoPathObjectParser(final TlvHandlerRegistry tlvReg) {
+       public PCEPNoPathObjectParser(final TlvRegistry tlvReg) {
                super(tlvReg);
        }
 
index 161963c6485f573d015f2d13151e73a566d4300c..27921669032f5e6ecbce9d160181048702675c6d 100644 (file)
@@ -10,7 +10,7 @@ package org.opendaylight.protocol.pcep.impl.object;
 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;
@@ -47,7 +47,7 @@ public class PCEPNotificationObjectParser extends AbstractObjectWithTlvsParser<C
        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);
        }
 
index 8947567de37e349ddf5d2f0d4a0d293935ca53e6..0a14d607204a5529a53e84f769863e48e6925eda 100644 (file)
@@ -10,7 +10,7 @@ package org.opendaylight.protocol.pcep.impl.object;
 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;
@@ -37,7 +37,7 @@ public class PCEPObjectiveFunctionObjectParser extends AbstractObjectWithTlvsPar
        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);
        }
 
index f2e4801652a3684eb47c319087b850127629cb31..d27b341391d3effd88517bb69df5e3a63e83fc08 100644 (file)
@@ -12,7 +12,7 @@ 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.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;
@@ -68,7 +68,7 @@ public class PCEPOpenObjectParser extends AbstractObjectWithTlvsParser<TlvsBuild
 
        private static final int PCEP_VERSION = 1;
 
-       public PCEPOpenObjectParser(final TlvHandlerRegistry tlvReg) {
+       public PCEPOpenObjectParser(final TlvRegistry tlvReg) {
                super(tlvReg);
        }
 
index 59a5327604d31a7290b555c21e06255db8f8d5f1..10a9c54235f097d9382a4a72ab2e30c2581986a3 100644 (file)
@@ -9,7 +9,7 @@ package org.opendaylight.protocol.pcep.impl.object;
 
 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;
@@ -32,7 +32,7 @@ public class PCEPPathKeyObjectParser extends AbstractEROWithSubobjectsParser {
 
        public static final int TYPE = 1;
 
-       public PCEPPathKeyObjectParser(final EROSubobjectHandlerRegistry subReg) {
+       public PCEPPathKeyObjectParser(final EROSubobjectRegistry subReg) {
                super(subReg);
        }
 
index e1db1036323ec3c712c56035a762b95119368d43..2c54f57a8bf2307284fdedfd32df344916ea3125 100644 (file)
@@ -9,7 +9,7 @@ package org.opendaylight.protocol.pcep.impl.object;
 
 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;
@@ -24,7 +24,7 @@ public class PCEPReportedRouteObjectParser extends AbstractRROWithSubobjectsPars
 
        public static final int TYPE = 1;
 
-       public PCEPReportedRouteObjectParser(final RROSubobjectHandlerRegistry subobjReg) {
+       public PCEPReportedRouteObjectParser(final RROSubobjectRegistry subobjReg) {
                super(subobjReg);
        }
 
index 680a4ab8e4222d029a0ad94131a661ea90a81bb9..fd05116cff83264faa12f6390b957bb0b4e6bc5c 100644 (file)
@@ -14,7 +14,7 @@ import java.util.BitSet;
 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;
@@ -92,7 +92,7 @@ public class PCEPRequestParameterObjectParser extends AbstractObjectWithTlvsPars
 
        private static final int E_FLAG_OFFSET = 20;
 
-       public PCEPRequestParameterObjectParser(final TlvHandlerRegistry tlvReg) {
+       public PCEPRequestParameterObjectParser(final TlvRegistry tlvReg) {
                super(tlvReg);
        }
 
index f0c32f0e5440c3fee5e9759be4c20272fa857cba..210021372da0f62c450e272284a80be5f0705ff7 100644 (file)
@@ -13,7 +13,7 @@ import java.util.List;
 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;
@@ -56,7 +56,7 @@ public class PCEPSvecObjectParser extends AbstractObjectWithTlvsParser<SvecBuild
         */
        private static final int MIN_SIZE = FLAGS_F_LENGTH + FLAGS_F_OFFSET;
 
-       public PCEPSvecObjectParser(final TlvHandlerRegistry tlvReg) {
+       public PCEPSvecObjectParser(final TlvRegistry tlvReg) {
                super(tlvReg);
        }
 
index 8ddc26655d3f7d6b8bbf510a9cdcda0116ed6933..69d3ab57372755e97d6bf47b9c006a79539039bf 100644 (file)
@@ -13,9 +13,7 @@ import org.opendaylight.protocol.pcep.impl.object.EROSubobjectUtil;
 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;
@@ -37,9 +35,9 @@ public class EROExplicitExclusionRouteSubobjectParser implements EROSubobjectPar
        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;
        }
 
@@ -109,9 +107,7 @@ public class EROExplicitExclusionRouteSubobjectParser implements EROSubobjectPar
                        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;
                }
@@ -127,9 +123,7 @@ public class EROExplicitExclusionRouteSubobjectParser implements EROSubobjectPar
 
                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);
                }
index bcf96c79dbc7a071ef240c59e0b013568d66d273..755f4fb95035994f92e261bbbd7e8b1773225b15 100644 (file)
@@ -66,7 +66,7 @@ public class NoPathVectorTlvParser implements TlvParser, TlvSerializer {
                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
index 3d2cd77bf8b670a29a06e3200f2ebaf268a850b1..2698542fe265601ccd4da61421425653bc34ab7d 100644 (file)
@@ -68,7 +68,7 @@ public class OFListTlvParser implements TlvParser, TlvSerializer {
                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
index aeca92b5e4aa586cfd114768f121840d18da4e24..f8c55d75b100f421a139bc3c5cdf6dc40c7c4dd3 100644 (file)
@@ -43,7 +43,7 @@ public class OrderTlvParser implements TlvParser, TlvSerializer {
                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
index 49b536871fdf67efc21521ac93409245266e519d..b8e3f1404e271f5a2eea2abe6c4bdd95c692e0b6 100644 (file)
@@ -35,7 +35,7 @@ public class OverloadedDurationTlvParser implements TlvParser, TlvSerializer {
                        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
index 69604c7b6313d95b0eb9dd85b8945ce3da38a912..aee2be28657328e30779c0b8a982c635134a6d01 100644 (file)
@@ -36,7 +36,7 @@ public class ReqMissingTlvParser implements TlvParser, TlvSerializer {
                        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
diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/TlvUtil.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/TlvUtil.java
new file mode 100644 (file)
index 0000000..0c680cc
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * 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;
+       }
+}
index 11895ec24ccc8ede3c72d4b767c211ba7ac2cf5b..945b68cc5fb3422bceba084c3e18df536ed8a458 100644 (file)
@@ -41,7 +41,7 @@ import org.opendaylight.protocol.pcep.impl.object.PCEPRequestParameterObjectPars
 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;
@@ -102,7 +102,7 @@ import com.google.common.primitives.UnsignedBytes;
 
 public class PCEPObjectParserTest {
 
-       private TlvHandlerRegistry tlvRegistry;
+       private TlvRegistry tlvRegistry;
 
        private SimplePCEPExtensionProviderContext ctx;
        private Activator act;
index ef5df09163ddda57a809c38ca1c3218c558aaceb..39bb404364d483e086be337773ed11c6b3c867b8 100644 (file)
@@ -19,6 +19,7 @@ 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.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;
@@ -36,19 +37,18 @@ import com.google.common.collect.Lists;
 
 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));
        }
 
@@ -56,14 +56,14 @@ public class PCEPTlvParserTest {
        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));
        }
 
@@ -71,7 +71,7 @@ public class PCEPTlvParserTest {
        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));
        }
 
@@ -82,7 +82,7 @@ public class PCEPTlvParserTest {
                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));
        }
 }
index 083949ed410fb1f2b959121e7f1b59d65f71993d..3949a1eb37b911962cef0e2743e08419240361e6 100644 (file)
@@ -7,6 +7,8 @@
  */
 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;
@@ -24,9 +26,9 @@ public abstract class AbstractObjectWithTlvsParser<T> implements ObjectParser, O
 
        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);
        }
 
@@ -56,45 +58,29 @@ public abstract class AbstractObjectWithTlvsParser<T> implements ObjectParser, O
                        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;
        }
 }
diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/EROSubobjectHandlerRegistry.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/EROSubobjectHandlerRegistry.java
deleted file mode 100644 (file)
index f70c72a..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.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);
-}
diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/EROSubobjectRegistry.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/EROSubobjectRegistry.java
new file mode 100644 (file)
index 0000000..bc97b26
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * 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);
+}
index 8a0f74d659343b9318a535b5a8dbbe72ba54991c..b59452d47238d7ec84bfc80ac731ed4159d0ba7b 100644 (file)
@@ -15,11 +15,11 @@ public interface PCEPExtensionConsumerContext {
 
        ObjectHandlerRegistry getObjectHandlerRegistry();
 
-       EROSubobjectHandlerRegistry getEROSubobjectHandlerRegistry();
+       EROSubobjectRegistry getEROSubobjectHandlerRegistry();
 
-       RROSubobjectHandlerRegistry getRROSubobjectHandlerRegistry();
+       RROSubobjectRegistry getRROSubobjectHandlerRegistry();
 
-       XROSubobjectHandlerRegistry getXROSubobjectHandlerRegistry();
+       XROSubobjectRegistry getXROSubobjectHandlerRegistry();
 
-       TlvHandlerRegistry getTlvHandlerRegistry();
+       TlvRegistry getTlvHandlerRegistry();
 }
diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/RROSubobjectHandlerRegistry.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/RROSubobjectHandlerRegistry.java
deleted file mode 100644 (file)
index 1c44267..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.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);
-}
diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/RROSubobjectRegistry.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/RROSubobjectRegistry.java
new file mode 100644 (file)
index 0000000..c2055e9
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * 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);
+}
similarity index 74%
rename from pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/TlvHandlerRegistry.java
rename to pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/TlvRegistry.java
index 24c296dec8d2a6fc50ccb2d13462595b91ddd533..6631d34bd3cac81c73cd4957e8601a815bbb4ff0 100644 (file)
@@ -9,7 +9,7 @@ package org.opendaylight.protocol.pcep.spi;
 
 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);
 }
diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/XROSubobjectHandlerRegistry.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/XROSubobjectHandlerRegistry.java
deleted file mode 100644 (file)
index b8f08c0..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.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);
-}
diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/XROSubobjectRegistry.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/XROSubobjectRegistry.java
new file mode 100644 (file)
index 0000000..69b0327
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * 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);
+}
similarity index 60%
rename from pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleEROSubobjectHandlerRegistry.java
rename to pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleEROSubobjectRegistry.java
index 29950954671791874c6e14a9740f61194113016c..cd042c5472800b871c5752eaf822d9ca7c59e13f 100644 (file)
@@ -8,16 +8,18 @@
 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) {
@@ -31,13 +33,21 @@ public final class SimpleEROSubobjectHandlerRegistry implements EROSubobjectHand
        }
 
        @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);
        }
 }
index 2dd5cd0b47438d6cbb184c43146ef039d03e275e..27fa7be5c912e542e3f862365130a8843c53d3af 100644 (file)
@@ -9,7 +9,7 @@ package org.opendaylight.protocol.pcep.spi.pojo;
 
 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;
@@ -22,13 +22,13 @@ import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
 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;
@@ -45,10 +45,10 @@ public class SimplePCEPExtensionProviderContext implements PCEPExtensionProvider
        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() {
@@ -66,22 +66,22 @@ public class SimplePCEPExtensionProviderContext implements PCEPExtensionProvider
        }
 
        @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;
        }
 
similarity index 60%
rename from pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleRROSubobjectHandlerRegistry.java
rename to pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleRROSubobjectRegistry.java
index b4aa770e0ec79ae6be11b095533564ec1d06fde3..e483113364a46e297521a85e2c8c7bd97e275b70 100644 (file)
@@ -8,16 +8,18 @@
 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) {
@@ -25,19 +27,27 @@ public final class SimpleRROSubobjectHandlerRegistry implements RROSubobjectHand
                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);
        }
 }
similarity index 64%
rename from pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleTlvHandlerRegistry.java
rename to pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleTlvRegistry.java
index 9a08f7992145e5b14f8f29e35de25964d872f7d6..7f8462ad50855d9b823ca3d7e18e340494dc0af5 100644 (file)
@@ -8,8 +8,9 @@
 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;
@@ -20,7 +21,8 @@ import com.google.common.base.Preconditions;
 /**
  *
  */
-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) {
@@ -33,12 +35,21 @@ public final class SimpleTlvHandlerRegistry implements TlvHandlerRegistry {
        }
 
        @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);
        }
 }
similarity index 60%
rename from pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleXROSubobjectHandlerRegistry.java
rename to pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleXROSubobjectRegistry.java
index a206bddc116721dd36050df23da3f324c1e0a6e0..85e4b3dc3031fb9f124df1dc9f0b730938ef4d44 100644 (file)
@@ -8,16 +8,18 @@
 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) {
@@ -31,13 +33,21 @@ public final class SimpleXROSubobjectHandlerRegistry implements XROSubobjectHand
        }
 
        @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);
        }
 }