Merge "BUG-730 : added test for pcep-spi registry."
authorRobert Varga <rovarga@cisco.com>
Sun, 13 Jul 2014 15:06:40 +0000 (15:06 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Sun, 13 Jul 2014 15:06:40 +0000 (15:06 +0000)
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/LinkstateAttributeParser.java
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/LinkstateNlriParser.java
bgp/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/LinkstateAttributeParserTest.java
bgp/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/LinkstateNlriParserTest.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07RSVPErrorSpecTlvParser.java
pcep/ietf-stateful07/src/test/java/org/opendaylight/protocol/pcep/ietf/PCEPTlvParserTest.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPErrorMessageParser.java
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPParserTest.java
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/AbstractObjectWithTlvsParser.java
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/TlvUtil.java

index a54cea5f0c5084e686709fc817913944b23abf60..60b9e9aa52e22e2f948b5b5407a25d7332b9bdc9 100644 (file)
@@ -376,17 +376,7 @@ public class LinkstateAttributeParser implements AttributeParser, AttributeSeria
                 LOG.debug("Parsed Metric: {}", metric);
                 break;
             case TlvCode.FORWARDING_ADDRESS:
-                IpAddress fwdAddress = null;
-                switch (value.readableBytes()) {
-                case Ipv4Util.IP4_LENGTH:
-                    fwdAddress = new IpAddress(Ipv4Util.addressForByteBuf(value));
-                    break;
-                case Ipv6Util.IPV6_LENGTH:
-                    fwdAddress = new IpAddress(Ipv6Util.addressForByteBuf(value));
-                    break;
-                default:
-                    LOG.debug("Ignoring unsupported forwarding address length {}", value.readableBytes());
-                }
+                IpAddress fwdAddress = parseForwardingAddress(value);
                 builder.setOspfForwardingAddress(fwdAddress);
                 LOG.debug("Parsed FWD Address: {}", fwdAddress);
                 break;
@@ -403,6 +393,21 @@ public class LinkstateAttributeParser implements AttributeParser, AttributeSeria
         return new PrefixAttributesCaseBuilder().setPrefixAttributes(builder.build()).build();
     }
 
+    private static IpAddress parseForwardingAddress(final ByteBuf value) {
+        IpAddress fwdAddress = null;
+        switch (value.readableBytes()) {
+        case Ipv4Util.IP4_LENGTH:
+            fwdAddress = new IpAddress(Ipv4Util.addressForByteBuf(value));
+            break;
+        case Ipv6Util.IPV6_LENGTH:
+            fwdAddress = new IpAddress(Ipv6Util.addressForByteBuf(value));
+            break;
+        default:
+            LOG.debug("Ignoring unsupported forwarding address length {}", value.readableBytes());
+        }
+        return fwdAddress;
+    }
+
     /**
      * Serialize linkstate attributes.
      *
@@ -466,19 +471,7 @@ public class LinkstateAttributeParser implements AttributeParser, AttributeSeria
         if (linkAttributes.getLinkProtection() != null) {
             writeTLV(TlvCode.LINK_PROTECTION_TYPE, Unpooled.copyShort(linkAttributes.getLinkProtection().getIntValue()), byteAggregator);
         }
-        MplsProtocolMask mplsProtocolMask = linkAttributes.getMplsProtocol();
-        if (mplsProtocolMask != null) {
-            final ByteBuf mplsProtocolMaskBuf = Unpooled.buffer();
-            final BitSet mask = new BitSet();
-            if (mplsProtocolMask.isLdp() != null) {
-                mask.set(LDP_BIT, mplsProtocolMask.isLdp());
-            }
-            if (mplsProtocolMask.isRsvpte() != null) {
-                mask.set(RSVP_BIT, mplsProtocolMask.isRsvpte());
-            }
-            mplsProtocolMaskBuf.writeBytes(mask.toByteArray());
-            writeTLV(TlvCode.MPLS_PROTOCOL, mplsProtocolMaskBuf, byteAggregator);
-        }
+        serializeMplsProtocolMask(linkAttributes.getMplsProtocol(), byteAggregator);
         if (linkAttributes.getMetric() != null) {
             // size of metric can be 1,2 or 3 depending on the protocol
             writeTLV(TlvCode.METRIC, Unpooled.copyMedium(linkAttributes.getMetric().getValue().intValue()), byteAggregator);
@@ -496,6 +489,21 @@ public class LinkstateAttributeParser implements AttributeParser, AttributeSeria
         LOG.trace("Finished serializing Link Attributes");
     }
 
+    private static void serializeMplsProtocolMask(final MplsProtocolMask mplsProtocolMask, final ByteBuf byteAggregator ) {
+        if (mplsProtocolMask != null) {
+            final ByteBuf mplsProtocolMaskBuf = Unpooled.buffer();
+            final BitSet mask = new BitSet();
+            if (mplsProtocolMask.isLdp() != null) {
+                mask.set(LDP_BIT, mplsProtocolMask.isLdp());
+            }
+            if (mplsProtocolMask.isRsvpte() != null) {
+                mask.set(RSVP_BIT, mplsProtocolMask.isRsvpte());
+            }
+            mplsProtocolMaskBuf.writeBytes(mask.toByteArray());
+            writeTLV(TlvCode.MPLS_PROTOCOL, mplsProtocolMaskBuf, byteAggregator);
+        }
+    }
+
     private void serializeNodeAttributes(final NodeAttributesCase nodeAttributesCase, final ByteBuf byteAggregator) {
         LOG.trace("Started serializing Node Attributes");
         final NodeAttributes nodeAttributes = nodeAttributesCase.getNodeAttributes();
@@ -506,7 +514,25 @@ public class LinkstateAttributeParser implements AttributeParser, AttributeSeria
             }
             writeTLV(TlvCode.MULTI_TOPOLOGY_ID, mpIdBuf, byteAggregator);
         }
-        final NodeFlagBits nodeFlagBits = nodeAttributes.getNodeFlags();
+        serializeNodeFlagBits(nodeAttributes.getNodeFlags(), byteAggregator);
+        if (nodeAttributes.getDynamicHostname() != null) {
+            writeTLV(TlvCode.DYNAMIC_HOSTNAME, Unpooled.wrappedBuffer(nodeAttributes.getDynamicHostname().getBytes()), byteAggregator);
+        }
+        if (nodeAttributes.getIsisAreaId() != null) {
+            for (final IsisAreaIdentifier isisAreaIdentifier : nodeAttributes.getIsisAreaId()) {
+                writeTLV(TlvCode.ISIS_AREA_IDENTIFIER, Unpooled.wrappedBuffer(isisAreaIdentifier.getValue()), byteAggregator);
+            }
+        }
+        if (nodeAttributes.getIpv4RouterId() != null) {
+            writeTLV(TlvCode.LOCAL_IPV4_ROUTER_ID, Unpooled.wrappedBuffer(InetAddresses.forString(nodeAttributes.getIpv4RouterId().getValue()).getAddress()), byteAggregator);
+        }
+        if (nodeAttributes.getIpv6RouterId() != null) {
+            writeTLV(TlvCode.LOCAL_IPV6_ROUTER_ID, Unpooled.wrappedBuffer(InetAddresses.forString(nodeAttributes.getIpv6RouterId().getValue()).getAddress()), byteAggregator);
+        }
+        LOG.trace("Finished serializing Node Attributes");
+    }
+
+    private static void serializeNodeFlagBits(final NodeFlagBits nodeFlagBits, final ByteBuf byteAggregator) {
         if (nodeFlagBits != null) {
             final ByteBuf nodeFlagBuf = Unpooled.buffer();
             final BitSet flags = new BitSet();
@@ -525,28 +551,13 @@ public class LinkstateAttributeParser implements AttributeParser, AttributeSeria
             nodeFlagBuf.writeBytes(flags.toByteArray());
             writeTLV(TlvCode.NODE_FLAG_BITS, nodeFlagBuf, byteAggregator);
         }
-        if (nodeAttributes.getDynamicHostname() != null) {
-            writeTLV(TlvCode.DYNAMIC_HOSTNAME, Unpooled.wrappedBuffer(nodeAttributes.getDynamicHostname().getBytes()), byteAggregator);
-        }
-        if (nodeAttributes.getIsisAreaId() != null) {
-            for (final IsisAreaIdentifier isisAreaIdentifier : nodeAttributes.getIsisAreaId()) {
-                writeTLV(TlvCode.ISIS_AREA_IDENTIFIER, Unpooled.wrappedBuffer(isisAreaIdentifier.getValue()), byteAggregator);
-            }
-        }
-        if (nodeAttributes.getIpv4RouterId() != null) {
-            writeTLV(TlvCode.LOCAL_IPV4_ROUTER_ID, Unpooled.wrappedBuffer(InetAddresses.forString(nodeAttributes.getIpv4RouterId().getValue()).getAddress()), byteAggregator);
-        }
-        if (nodeAttributes.getIpv6RouterId() != null) {
-            writeTLV(TlvCode.LOCAL_IPV6_ROUTER_ID, Unpooled.wrappedBuffer(InetAddresses.forString(nodeAttributes.getIpv6RouterId().getValue()).getAddress()), byteAggregator);
-        }
-        LOG.trace("Finished serializing Node Attributes");
     }
 
     private void serializePrefixAttributes(final PrefixAttributesCase prefixAttributesCase, final ByteBuf byteAggregator) {
         final PrefixAttributes prefixAtrributes = prefixAttributesCase.getPrefixAttributes();
         if (prefixAtrributes.getIgpBits() != null) {
-            BitSet igpBit = new BitSet();
-            Boolean bit = prefixAtrributes.getIgpBits().getUpDown().isUpDown();
+            final BitSet igpBit = new BitSet();
+            final Boolean bit = prefixAtrributes.getIgpBits().getUpDown().isUpDown();
             if (bit != null) {
                 igpBit.set(UP_DOWN_BIT, bit);
             }
@@ -569,7 +580,10 @@ public class LinkstateAttributeParser implements AttributeParser, AttributeSeria
         if (prefixAtrributes.getPrefixMetric() != null) {
             writeTLV(TlvCode.PREFIX_METRIC, Unpooled.copyInt(prefixAtrributes.getPrefixMetric().getValue().intValue()), byteAggregator);
         }
-        IpAddress forwardingAddress = prefixAtrributes.getOspfForwardingAddress();
+        serializeForwardingAddress(prefixAtrributes.getOspfForwardingAddress(), byteAggregator);
+    }
+
+    private static void serializeForwardingAddress(final IpAddress forwardingAddress, final ByteBuf byteAggregator) {
         if (forwardingAddress != null) {
             final ByteBuf ospfBuf = Unpooled.buffer();
             if (forwardingAddress.getIpv4Address() != null) {
index dcaf6e6624a50bf2ce31b7e911e0e577b319d73e..474d5bdcade8eebda2aa4b53be1989a66c3d5bb7 100644 (file)
@@ -10,14 +10,11 @@ package org.opendaylight.protocol.bgp.linkstate;
 import com.google.common.collect.Lists;
 import com.google.common.primitives.UnsignedBytes;
 import com.google.common.primitives.UnsignedInteger;
-
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.ByteBufUtil;
 import io.netty.buffer.Unpooled;
-
 import java.math.BigInteger;
 import java.util.List;
-
 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
 import org.opendaylight.protocol.bgp.parser.spi.NlriParser;
 import org.opendaylight.protocol.bgp.parser.spi.NlriSerializer;
@@ -91,6 +88,7 @@ public final class LinkstateNlriParser implements NlriParser, NlriSerializer {
     private static final int ROUTE_DISTINGUISHER_LENGTH = 8;
     private static final int PROTOCOL_ID_LENGTH = 1;
     private static final int IDENTIFIER_LENGTH = 8;
+    private static final int OSPF_PSEUDONODE_ROUTER_ID_LENGTH = 8;
     private static final int OSPF_ROUTER_ID_LENGTH = 4;
     private static final int ISO_SYSTEM_ID_LENGTH = 6;
     private static final int PSN_LENGTH = 1;
@@ -130,7 +128,7 @@ public final class LinkstateNlriParser implements NlriParser, NlriSerializer {
                 builder.setLinkLocalIdentifier(value.readUnsignedInt());
                 builder.setLinkRemoteIdentifier(value.readUnsignedInt());
                 LOG.debug("Parsed link local {} remote {} Identifiers.", builder.getLinkLocalIdentifier(),
-                        builder.getLinkRemoteIdentifier());
+                    builder.getLinkRemoteIdentifier());
                 break;
             case TlvCode.IPV4_IFACE_ADDRESS:
                 final Ipv4InterfaceIdentifier lipv4 = new Ipv4InterfaceIdentifier(Ipv4Util.addressForByteBuf(value));
@@ -200,27 +198,27 @@ public final class LinkstateNlriParser implements NlriParser, NlriSerializer {
         }
         LOG.trace("Finished parsing Node descriptors.");
         return (local) ? new LocalNodeDescriptorsBuilder().setAsNumber(asnumber).setDomainId(bgpId).setAreaId(ai).setCRouterIdentifier(
-                routerId).build()
-                : new RemoteNodeDescriptorsBuilder().setAsNumber(asnumber).setDomainId(bgpId).setAreaId(ai).setCRouterIdentifier(routerId).build();
+            routerId).build()
+            : new RemoteNodeDescriptorsBuilder().setAsNumber(asnumber).setDomainId(bgpId).setAreaId(ai).setCRouterIdentifier(routerId).build();
     }
 
     private static CRouterIdentifier parseRouterId(final ByteBuf value) throws BGPParsingException {
         if (value.readableBytes() == ISO_SYSTEM_ID_LENGTH || (value.readableBytes() == ISO_SYSTEM_ID_LENGTH + PSN_LENGTH && value.getByte(ISO_SYSTEM_ID_LENGTH) == 0)) {
             return new IsisNodeCaseBuilder().setIsisNode(
-                    new IsisNodeBuilder().setIsoSystemId(new IsoSystemIdentifier(ByteArray.readBytes(value, ISO_SYSTEM_ID_LENGTH))).build()).build();
+                new IsisNodeBuilder().setIsoSystemId(new IsoSystemIdentifier(ByteArray.readBytes(value, ISO_SYSTEM_ID_LENGTH))).build()).build();
         }
         if (value.readableBytes() == ISO_SYSTEM_ID_LENGTH + PSN_LENGTH) {
             final IsIsRouterIdentifier iri = new IsIsRouterIdentifierBuilder().setIsoSystemId(
-                    new IsoSystemIdentifier(ByteArray.readBytes(value, ISO_SYSTEM_ID_LENGTH))).build();
+                new IsoSystemIdentifier(ByteArray.readBytes(value, ISO_SYSTEM_ID_LENGTH))).build();
             return new IsisPseudonodeCaseBuilder().setIsisPseudonode(new IsisPseudonodeBuilder().setIsIsRouterIdentifier(iri).setPsn((short) value.readByte()).build()).build();
         }
         if (value.readableBytes() == OSPF_ROUTER_ID_LENGTH) {
             return new OspfNodeCaseBuilder().setOspfNode(
-                    new OspfNodeBuilder().setOspfRouterId(value.readUnsignedInt()).build()).build();
+                new OspfNodeBuilder().setOspfRouterId(value.readUnsignedInt()).build()).build();
         }
-        if (value.readableBytes() == 8) {
+        if (value.readableBytes() == OSPF_PSEUDONODE_ROUTER_ID_LENGTH) {
             return new OspfPseudonodeCaseBuilder().setOspfPseudonode(
-                    new OspfPseudonodeBuilder().setOspfRouterId(value.readUnsignedInt()).setLanInterface(new OspfInterfaceIdentifier(value.readUnsignedInt())).build()).build();
+                new OspfPseudonodeBuilder().setOspfRouterId(value.readUnsignedInt()).setLanInterface(new OspfInterfaceIdentifier(value.readUnsignedInt())).build()).build();
         }
         throw new BGPParsingException("Router Id of invalid length " + value.readableBytes());
     }
@@ -319,7 +317,7 @@ public final class LinkstateNlriParser implements NlriParser, NlriSerializer {
             nlri.skipBytes(locallength);
             builder.setLocalNodeDescriptors((LocalNodeDescriptors) localDescriptor);
             final int restLength = length - (this.isVpn ? ROUTE_DISTINGUISHER_LENGTH : 0) - PROTOCOL_ID_LENGTH - IDENTIFIER_LENGTH
-                    - TYPE_LENGTH - LENGTH_SIZE - locallength;
+                - TYPE_LENGTH - LENGTH_SIZE - locallength;
             LOG.trace("Restlength {}", restLength);
             ByteBuf rest = nlri.slice(nlri.readerIndex(), restLength);
             switch (type) {
@@ -350,9 +348,9 @@ public final class LinkstateNlriParser implements NlriParser, NlriSerializer {
         final List<CLinkstateDestination> dst = parseNlri(nlri);
 
         builder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
-                new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCaseBuilder().setDestinationLinkstate(
-                        new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.linkstate._case.DestinationLinkstateBuilder().setCLinkstateDestination(
-                                dst).build()).build()).build());
+            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCaseBuilder().setDestinationLinkstate(
+                new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.linkstate._case.DestinationLinkstateBuilder().setCLinkstateDestination(
+                    dst).build()).build()).build());
     }
 
     @Override
@@ -363,8 +361,8 @@ public final class LinkstateNlriParser implements NlriParser, NlriSerializer {
         final List<CLinkstateDestination> dst = parseNlri(nlri);
 
         builder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
-                new DestinationLinkstateCaseBuilder().setDestinationLinkstate(
-                        new DestinationLinkstateBuilder().setCLinkstateDestination(dst).build()).build()).build());
+            new DestinationLinkstateCaseBuilder().setDestinationLinkstate(
+                new DestinationLinkstateBuilder().setCLinkstateDestination(dst).build()).build()).build());
     }
 
     /**
@@ -445,7 +443,10 @@ public final class LinkstateNlriParser implements NlriParser, NlriSerializer {
 
     private static void serializeLinkDescriptors(final LinkDescriptors descriptors, final ByteBuf buffer) {
         if (descriptors.getLinkLocalIdentifier() != null && descriptors.getLinkRemoteIdentifier() != null) {
-            LinkstateAttributeParser.writeTLV(TlvCode.LINK_LR_IDENTIFIERS, Unpooled.copyInt(descriptors.getLinkLocalIdentifier().intValue()), buffer);
+            final ByteBuf identifierBuf = Unpooled.buffer();
+            identifierBuf.writeInt(descriptors.getLinkLocalIdentifier().intValue());
+            identifierBuf.writeInt(descriptors.getLinkRemoteIdentifier().intValue());
+            LinkstateAttributeParser.writeTLV(TlvCode.LINK_LR_IDENTIFIERS, identifierBuf, buffer);
         }
         if (descriptors.getIpv4InterfaceAddress() != null) {
             LinkstateAttributeParser.writeTLV(TlvCode.IPV4_IFACE_ADDRESS, Unpooled.wrappedBuffer(Ipv4Util.bytesForAddress(descriptors.getIpv4InterfaceAddress())), buffer);
@@ -470,7 +471,7 @@ public final class LinkstateNlriParser implements NlriParser, NlriSerializer {
         }
         if (descriptors.getOspfRouteType() != null) {
             LinkstateAttributeParser.writeTLV(TlvCode.OSPF_ROUTE_TYPE,
-                    Unpooled.wrappedBuffer(new byte[] {UnsignedBytes.checkedCast(descriptors.getOspfRouteType().getIntValue()) }), buffer);
+                Unpooled.wrappedBuffer(new byte[] {UnsignedBytes.checkedCast(descriptors.getOspfRouteType().getIntValue()) }), buffer);
         }
         if (descriptors.getIpReachabilityInformation() != null) {
             final IpPrefix prefix = descriptors.getIpReachabilityInformation();
@@ -489,15 +490,12 @@ public final class LinkstateNlriParser implements NlriParser, NlriSerializer {
         final PathAttributes pathAttributes = (PathAttributes) attribute;
         final PathAttributes1 pathAttributes1 = pathAttributes.getAugmentation(PathAttributes1.class);
         final PathAttributes2 pathAttributes2 = pathAttributes.getAugmentation(PathAttributes2.class);
-        if (pathAttributes1 == null && pathAttributes2 == null) {
-            return;
-        }
         if (pathAttributes1 != null) {
             final AdvertizedRoutes routes = (pathAttributes1.getMpReachNlri()).getAdvertizedRoutes();
             if (routes != null &&
-                    routes.getDestinationType()
-                    instanceof
-                    org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCase) {
+                routes.getDestinationType()
+                instanceof
+                org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCase) {
                 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCase
                 linkstateCase = (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCase) routes.getDestinationType();
 
index 413ec49d73fa6434c8af76c8c3bd8e465e8c6f2f..914c683ac4cd2b45b357b5edc4601003ff1cd166 100644 (file)
@@ -14,12 +14,9 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
 import com.google.common.collect.Lists;
-
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-
 import java.util.Arrays;
-
 import org.junit.Test;
 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
 import org.opendaylight.protocol.util.ByteArray;
@@ -39,8 +36,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.link
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.linkstate._case.DestinationLinkstateBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.PathAttributesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes1Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes2Builder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.MpReachNlriBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.MpUnreachNlriBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder;
 
 public class LinkstateAttributeParserTest {
 
@@ -67,13 +67,24 @@ public class LinkstateAttributeParserTest {
 
     private static PathAttributesBuilder createBuilder(final NlriType type) {
         return new PathAttributesBuilder().addAugmentation(
-                org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes1.class,
-                new PathAttributes1Builder().setMpReachNlri(
-                        new MpReachNlriBuilder().setAfi(LinkstateAddressFamily.class).setSafi(LinkstateSubsequentAddressFamily.class).setAdvertizedRoutes(
-                                new AdvertizedRoutesBuilder().setDestinationType(
-                                        new DestinationLinkstateCaseBuilder().setDestinationLinkstate(
-                                                new DestinationLinkstateBuilder().setCLinkstateDestination(
-                                                        Lists.newArrayList(new CLinkstateDestinationBuilder().setNlriType(type).build())).build()).build()).build()).build()).build());
+            org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes1.class,
+            new PathAttributes1Builder().setMpReachNlri(
+                new MpReachNlriBuilder().setAfi(LinkstateAddressFamily.class).setSafi(LinkstateSubsequentAddressFamily.class).setAdvertizedRoutes(
+                    new AdvertizedRoutesBuilder().setDestinationType(
+                        new DestinationLinkstateCaseBuilder().setDestinationLinkstate(
+                            new DestinationLinkstateBuilder().setCLinkstateDestination(
+                                Lists.newArrayList(new CLinkstateDestinationBuilder().setNlriType(type).build())).build()).build()).build()).build()).build());
+    }
+
+    private static PathAttributesBuilder createUnreachBuilder(final NlriType type) {
+        return new PathAttributesBuilder().addAugmentation(
+            org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes2.class,
+            new PathAttributes2Builder().setMpUnreachNlri(
+                new MpUnreachNlriBuilder().setAfi(LinkstateAddressFamily.class).setSafi(LinkstateSubsequentAddressFamily.class).setWithdrawnRoutes(
+                    new WithdrawnRoutesBuilder().setDestinationType(
+                        new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCaseBuilder().setDestinationLinkstate(
+                            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.linkstate._case.DestinationLinkstateBuilder().setCLinkstateDestination(
+                                Lists.newArrayList(new CLinkstateDestinationBuilder().setNlriType(type).build())).build()).build()).build()).build()).build());
     }
 
     @Test
@@ -102,7 +113,7 @@ public class LinkstateAttributeParserTest {
         //serialization
         final ByteBuf buff = Unpooled.buffer();
         this.parser.serializeAttribute(builder.build(), buff);
-        buff.readerIndex(buff.readerIndex() + 3);
+        buff.skipBytes(3);
         // there is unresolved TLV at the end, that needs to be cut off
         assertArrayEquals(ByteArray.subByte(LINK_ATTR, 0, LINK_ATTR.length -5), ByteArray.getAllBytes(buff));
     }
@@ -130,14 +141,14 @@ public class LinkstateAttributeParserTest {
         //serialization
         final ByteBuf buff = Unpooled.buffer();
         this.parser.serializeAttribute(builder.build(), buff);
-        buff.readerIndex(buff.readerIndex() + 3);
+        buff.skipBytes(3);
         // there is unresolved TLV at the end, that needs to be cut off
         assertTrue(Arrays.equals(ByteArray.subByte(NODE_ATTR, 0, NODE_ATTR.length -5), ByteArray.getAllBytes(buff)) || Arrays.equals(NODE_ATTR_S, ByteArray.getAllBytes(buff)));
     }
 
     @Test
     public void testPositiveV4Prefixes() throws BGPParsingException {
-        final PathAttributesBuilder builder = createBuilder(NlriType.Ipv4Prefix);
+        final PathAttributesBuilder builder = createUnreachBuilder(NlriType.Ipv4Prefix);
         this.parser.parseAttribute(Unpooled.copiedBuffer(P4_ATTR), builder);
 
         final PathAttributes1 attrs = builder.getAugmentation(PathAttributes1.class);
@@ -156,7 +167,7 @@ public class LinkstateAttributeParserTest {
         //serialization
         final ByteBuf buff = Unpooled.buffer();
         this.parser.serializeAttribute(builder.build(), buff);
-        buff.readerIndex(buff.readerIndex() + 3);
+        buff.skipBytes(3);
         // there is unresolved TLV at the end, that needs to be cut off
         assertArrayEquals(ByteArray.subByte(P4_ATTR, 0, P4_ATTR.length -5), ByteArray.getAllBytes(buff));
     }
index 2918cbff7a5b11c835f0c4b94ed32e1e273ae9a7..d6526d550b35a34b0f68cd945c6fb3c2aae224f2 100644 (file)
@@ -12,13 +12,10 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
 
 import com.google.common.collect.Lists;
-
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-
 import java.math.BigInteger;
 import java.util.List;
-
 import org.junit.Test;
 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
 import org.opendaylight.protocol.util.ByteArray;
@@ -68,15 +65,17 @@ public class LinkstateNlriParserTest {
         (byte) 0x00, (byte) 0x29, (byte) 0x29, (byte) 0x29, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x07, (byte) 0x00, (byte) 0x00,
         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x39, (byte) 0x05 };
 
-    private final byte[] linkNlri = new byte[] { (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x53, (byte) 0x02, (byte) 0x00, (byte) 0x00,
+    private final byte[] linkNlri = new byte[] { (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x65, (byte) 0x02, (byte) 0x00, (byte) 0x00,
         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x1a,
         (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x48, (byte) 0x02, (byte) 0x01,
         (byte) 0x00, (byte) 0x04, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x06,
         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x42, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x18,
         (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x48, (byte) 0x02, (byte) 0x01,
         (byte) 0x00, (byte) 0x04, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x04,
-        (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x40, (byte) 0x01, (byte) 0x03, (byte) 0x00, (byte) 0x04, (byte) 0xc5, (byte) 0x14,
-        (byte) 0xa0, (byte) 0x2a, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x04, (byte) 0xc5, (byte) 0x14, (byte) 0xa0, (byte) 0x28 };
+        (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x40, 1, 2, 0, 8, 1, 2, 3, 4, 0x0a, 0x0b, 0x0c, 0x0d,
+        (byte) 0x01, (byte) 0x03, (byte) 0x00, (byte) 0x04, (byte) 0xc5, (byte) 0x14,
+        (byte) 0xa0, (byte) 0x2a, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x04, (byte) 0xc5, (byte) 0x14, (byte) 0xa0, (byte) 0x28,
+        1, 7, 0, 2, 0, 3};
 
     private final byte[] prefixNlri = new byte[] { (byte) 0x00, (byte) 0x03, (byte) 0x00, (byte) 0x39, (byte) 0x02, (byte) 0x00,
         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x00,
index 2232a3430d8702bf6d496e02b2e46cf54f62b5eb..f60af72215dc59e03db174e262e70b9d145f420a 100644 (file)
@@ -15,7 +15,6 @@ import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
 import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedShort;
 
 import com.google.common.base.Preconditions;
-import com.google.common.primitives.UnsignedBytes;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import java.util.BitSet;
@@ -50,6 +49,7 @@ public final class Stateful07RSVPErrorSpecTlvParser implements TlvParser, TlvSer
     public static final int TYPE = 21;
 
     private static final int FLAGS_F_LENGTH = 1;
+    private static final int HEADER_LENGTH = 4;
 
     private static final int RSVP_ERROR_CLASS_NUM = 6;
     private static final int RSVP_IPV4_ERROR_CLASS_TYPE = 1;
@@ -66,8 +66,10 @@ public final class Stateful07RSVPErrorSpecTlvParser implements TlvParser, TlvSer
         if (buffer == null) {
             return null;
         }
-        final int classNum = UnsignedBytes.toInt(buffer.readByte());
-        final int classType = UnsignedBytes.toInt(buffer.readByte());
+        // throw away contents of length field
+        buffer.readUnsignedShort();
+        final int classNum = buffer.readUnsignedByte();
+        final int classType = buffer.readUnsignedByte();
         ErrorType errorType = null;
         if (classNum == RSVP_ERROR_CLASS_NUM) {
             errorType = parseRsvp(classType, buffer.slice());
@@ -96,8 +98,8 @@ public final class Stateful07RSVPErrorSpecTlvParser implements TlvParser, TlvSer
     private UserCase parseUserError(final ByteBuf buffer) {
         final UserErrorBuilder error = new UserErrorBuilder();
         error.setEnterprise(new EnterpriseNumber(buffer.readUnsignedInt()));
-        error.setSubOrg((short) UnsignedBytes.toInt(buffer.readByte()));
-        final int errDescrLength = UnsignedBytes.toInt(buffer.readByte());
+        error.setSubOrg(buffer.readUnsignedByte());
+        final int errDescrLength = buffer.readUnsignedByte();
         error.setValue(buffer.readUnsignedShort());
         error.setDescription(ByteArray.bytesToHRString(ByteArray.readBytes(buffer, errDescrLength)));
         // if we have any subobjects, place the implementation here
@@ -106,23 +108,24 @@ public final class Stateful07RSVPErrorSpecTlvParser implements TlvParser, TlvSer
 
     private void serializerUserError(final UserError ue, final ByteBuf body) {
         byte[] desc = (ue.getDescription() == null) ? new byte[0] : ue.getDescription().getBytes();
-        body.writeByte(USER_ERROR_CLASS_NUM);
-        body.writeByte(USER_ERROR_CLASS_TYPE);
+        final ByteBuf userErrorBuf = Unpooled.buffer();
         Preconditions.checkArgument(ue.getEnterprise() != null, "EnterpriseNumber is mandatory");
-        writeUnsignedInt(ue.getEnterprise().getValue(), body);
-        writeUnsignedByte(ue.getSubOrg(), body);
-        body.writeByte(desc.length);
+        writeUnsignedInt(ue.getEnterprise().getValue(), userErrorBuf);
+        writeUnsignedByte(ue.getSubOrg(), userErrorBuf);
+        userErrorBuf.writeByte(desc.length);
         Preconditions.checkArgument(ue.getValue() != null, "Value is mandatory.");
-        writeUnsignedShort(ue.getValue(), body);
-        body.writeBytes(desc);
+        writeUnsignedShort(ue.getValue(), userErrorBuf);
+        userErrorBuf.writeBytes(desc);
+        userErrorBuf.writeZero(TlvUtil.getPadding(desc.length, TlvUtil.PADDED_TO));
+        formatRSVPObject(USER_ERROR_CLASS_NUM, USER_ERROR_CLASS_TYPE, userErrorBuf, body);
     }
 
     private RsvpCase parseRsvp(final int classType, final ByteBuf buffer) {
         final RsvpErrorBuilder builder = new RsvpErrorBuilder();
         if (classType == RSVP_IPV4_ERROR_CLASS_TYPE) {
-            builder.setNode(new IpAddress(Ipv4Util.addressForBytes(ByteArray.readBytes(buffer, Ipv4Util.IP4_LENGTH))));
+            builder.setNode(new IpAddress(Ipv4Util.addressForByteBuf(buffer)));
         } else if (classType == RSVP_IPV6_ERROR_CLASS_TYPE) {
-            builder.setNode(new IpAddress(Ipv6Util.addressForBytes(ByteArray.readBytes(buffer, Ipv6Util.IPV6_LENGTH))));
+            builder.setNode(new IpAddress(Ipv6Util.addressForByteBuf(buffer)));
         }
         final BitSet flags = ByteArray.bytesToBitSet(ByteArray.readBytes(buffer, FLAGS_F_LENGTH));
         builder.setFlags(new Flags(flags.get(IN_PLACE_FLAG_OFFSET), flags.get(NOT_GUILTY_FLAGS_OFFSET)));
@@ -139,19 +142,27 @@ public final class Stateful07RSVPErrorSpecTlvParser implements TlvParser, TlvSer
         flags.set(NOT_GUILTY_FLAGS_OFFSET, rsvp.getFlags().isNotGuilty());
         final IpAddress node = rsvp.getNode();
         Preconditions.checkArgument(node != null, "Node is mandatory.");
+        final ByteBuf rsvpObjBuf = Unpooled.buffer();
+        int type = 0;
         if (node.getIpv4Address() != null) {
-            body.writeByte(RSVP_ERROR_CLASS_NUM);
-            body.writeByte(RSVP_IPV4_ERROR_CLASS_TYPE);
-            writeIpv4Address(node.getIpv4Address(), body);
+            type = RSVP_IPV4_ERROR_CLASS_TYPE;
+            writeIpv4Address(node.getIpv4Address(), rsvpObjBuf);
         } else {
-            body.writeByte(RSVP_ERROR_CLASS_NUM);
-            body.writeByte(RSVP_IPV6_ERROR_CLASS_TYPE);
-            writeIpv6Address(node.getIpv6Address(), body);
+            type = RSVP_IPV6_ERROR_CLASS_TYPE;
+            writeIpv6Address(node.getIpv6Address(), rsvpObjBuf);
         }
-        writeBitSet(flags, FLAGS_F_LENGTH, body);
+        writeBitSet(flags, FLAGS_F_LENGTH, rsvpObjBuf);
         Preconditions.checkArgument(rsvp.getCode() != null, "Code is mandatory.");
-        writeUnsignedByte(rsvp.getCode(), body);
+        writeUnsignedByte(rsvp.getCode(), rsvpObjBuf);
         Preconditions.checkArgument(rsvp.getValue() != null, "Value is mandatory.");
-        writeUnsignedShort(rsvp.getValue(), body);
+        writeUnsignedShort(rsvp.getValue(), rsvpObjBuf);
+        formatRSVPObject(RSVP_ERROR_CLASS_NUM, type, rsvpObjBuf, body);
+    }
+
+    private static void formatRSVPObject(final int objClass, final int type, final ByteBuf body, final ByteBuf out) {
+        out.writeShort(body.writerIndex() + HEADER_LENGTH);
+        out.writeByte(objClass);
+        out.writeByte(type);
+        out.writeBytes(body);
     }
 }
index 34193df05cf4265a0c65ec71fb094e1f77eaf04e..7550e1e391bc4dd36373b8dbd07f09390d9bded8 100644 (file)
@@ -61,13 +61,13 @@ public class PCEPTlvParserTest {
         (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,
+    private static final byte[] rsvpErrorBytes = { 0x00, 0x15, 0x00, 0x0c, 0, 0x0c, 0x06, 0x01, 0x12, 0x34, 0x56, 0x78, 0x02, (byte) 0x92, 0x16,
+        0x02 };
+    private static final byte[] rsvpError6Bytes = { 0x00, 0x15, 0x00, 0x18, 0, 0x18, 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 };
+        (byte) 0xc5, (byte) 0xd9};
+    private static final byte[] userErrorBytes = { 0x00, 0x15, 0x00, 0x18, 0, 0x18, (byte) 0xc2, 0x01, 0x00, 0x00, 0x30, 0x39, 0x05, 0x09, 0x00,
+        0x26, 0x75, 0x73, 0x65, 0x72, 0x20, 0x64, 0x65, 0x73, 0x63, 0, 0, 0 };
 
     @Test
     public void testStatefulTlv() throws PCEPDeserializerException {
@@ -83,7 +83,7 @@ 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 nameeee".getBytes())).build();
+            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(Unpooled.wrappedBuffer(ByteArray.cutBytes(symbolicNameBytes, 4))));
         final ByteBuf buff = Unpooled.buffer();
         parser.serializeTlv(tlv, buff);
@@ -109,7 +109,7 @@ public class PCEPTlvParserTest {
             (byte) 0x78 })));
         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();
+            new LspId(65535L)).setTunnelId(new TunnelId(4660)).build();
         assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(lspIdentifiers4Bytes, 4))));
         final ByteBuf buff = Unpooled.buffer();
         parser.serializeTlv(tlv, buff);
@@ -130,7 +130,7 @@ public class PCEPTlvParserTest {
             (byte) 0x9A, (byte) 0xBC, (byte) 0xDE, (byte) 0xF0, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9A,
             (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();
+            new LspId(4660L)).setTunnelId(new TunnelId(65535)).build();
         assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(lspIdentifiers6Bytes, 4))));
         final ByteBuf buff = Unpooled.buffer();
         parser.serializeTlv(tlv, buff);
index c82dc64c0801f9608a80e6995775cf0f28677451..f62f82bf975227cfad13cb3732f91baf8a0a6a92 100644 (file)
@@ -8,13 +8,10 @@
 package org.opendaylight.protocol.pcep.impl.message;
 
 import com.google.common.base.Preconditions;
-
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-
 import java.util.ArrayList;
 import java.util.List;
-
 import org.opendaylight.protocol.pcep.spi.AbstractMessageParser;
 import org.opendaylight.protocol.pcep.spi.MessageUtil;
 import org.opendaylight.protocol.pcep.spi.ObjectRegistry;
@@ -159,7 +156,7 @@ public class PCEPErrorMessageParser extends AbstractMessageParser {
             }
         }
 
-        if (errorObjects.isEmpty() && errorObjects.isEmpty()) {
+        if (errorObjects.isEmpty()) {
             throw new PCEPDeserializerException("At least one PCEPErrorObject is mandatory.");
         }
 
index 5e9ee2b21c01f702a3a3d888cf83c4606e88c1d7..b6d6a58467da3c65c78733b9a91c7fa8653806ed 100644 (file)
@@ -10,12 +10,11 @@ package org.opendaylight.protocol.pcep.impl;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
+
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-
 import java.util.ArrayList;
 import java.util.List;
-
 import org.junit.Test;
 import org.opendaylight.protocol.pcep.spi.MessageRegistry;
 import org.opendaylight.protocol.pcep.spi.pojo.ServiceLoaderPCEPExtensionProviderContext;
@@ -23,6 +22,7 @@ import org.opendaylight.protocol.util.ByteArray;
 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;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.KeepaliveBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Pcerr;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.keepalive.message.KeepaliveMessageBuilder;
 
 public class PCEPParserTest {
@@ -45,6 +45,8 @@ public class PCEPParserTest {
         assertTrue(out.get(0) instanceof Keepalive);
         decoder.decode(null, Unpooled.wrappedBuffer(new byte[] { 0x20, 0x07, 0, 0x0C, 0x0F, 0x10, 0, 8, 0, 0, 0, 5 }), out);
         assertTrue(out.get(1) instanceof Close);
+        decoder.decode(null, Unpooled.wrappedBuffer(new byte[] { 0x20, 06, 00, 0x18, 0x21,0x10, 00,0x0c, 00,00,00,00,00,00,00,01,0x0d,0x10,00,0x08,00,00,0x18,02 }), out);
+        assertTrue(out.get(2) instanceof Pcerr);
     }
 
     @Test
index 5d2548ef042b87d39df455c26db6b0b92cf6fc68..3a79af9decaf121811f45a45cab82dc141599374 100644 (file)
@@ -18,6 +18,12 @@ public abstract class AbstractObjectWithTlvsParser<T> implements ObjectParser, O
 
     private static final Logger LOG = LoggerFactory.getLogger(AbstractObjectWithTlvsParser.class);
 
+    private static final int TLV_TYPE_F_LENGTH = 2;
+    private static final int TLV_LENGTH_F_LENGTH = 2;
+    private static final int TLV_HEADER_LENGTH = TLV_LENGTH_F_LENGTH + TLV_TYPE_F_LENGTH;
+
+    public static final int PADDED_TO = 4;
+
     private final TlvRegistry tlvReg;
 
     protected AbstractObjectWithTlvsParser(final TlvRegistry tlvReg) {
index c6ac9f94656a6601eed86c6ccbf6d99b77aeeaaf..1ce8d40d7b5647eedf364843cfb57f71f4698183 100644 (file)
@@ -13,7 +13,7 @@ public final class TlvUtil {
 
     protected static final int HEADER_SIZE = 4;
 
-    protected static final int PADDED_TO = 4;
+    public static final int PADDED_TO = 4;
 
     private TlvUtil() {
     }