From 0488165ba6f6bb0df3437b88e9e38386983f11cd Mon Sep 17 00:00:00 2001 From: Milos Fabian Date: Wed, 16 Jul 2014 15:50:53 +0200 Subject: [PATCH] Revert "Bug 1205 - AS path segment value encoded by 2 bytes" This reverts commit d4f23f2d138b7bf0f1e1d2b61b5720749daf207f. Change-Id: Iaa6e1d467630ba4bc32d9b67db6f09150d46d914 Signed-off-by: Milos Fabian --- .../message/update/AsPathSegmentParser.java | 22 ++++++------- .../bgp/parser/impl/BGPParserTest.java | 29 ++++++++---------- .../protocol/bgp/parser/impl/ParserTest.java | 13 -------- bgp/parser-impl/src/test/resources/up1.bin | Bin 82 -> 84 bytes bgp/parser-impl/src/test/resources/up2.bin | Bin 126 -> 128 bytes bgp/parser-impl/src/test/resources/up3.bin | Bin 69 -> 75 bytes 6 files changed, 22 insertions(+), 42 deletions(-) diff --git a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/AsPathSegmentParser.java b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/AsPathSegmentParser.java index 457114d729..fb174412ae 100644 --- a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/AsPathSegmentParser.java +++ b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/AsPathSegmentParser.java @@ -10,14 +10,12 @@ package org.opendaylight.protocol.bgp.parser.impl.message.update; import static org.opendaylight.protocol.bgp.parser.impl.message.update.AsPathSegmentParser.SegmentType.AS_SEQUENCE; import static org.opendaylight.protocol.bgp.parser.impl.message.update.AsPathSegmentParser.SegmentType.AS_SET; -import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBuf; import java.util.ArrayList; import java.util.List; - import org.opendaylight.protocol.util.ReferenceCache; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ShortAsNumber; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.AListCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.ASetCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.a.list._case.AList; @@ -32,7 +30,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.type */ public final class AsPathSegmentParser { - public static final int AS_NUMBER_LENGTH = 2; + public static final int AS_NUMBER_LENGTH = 4; /** * Possible types of AS Path segments. @@ -70,9 +68,8 @@ public final class AsPathSegmentParser { static List parseAsSequence(final ReferenceCache refCache, final int count, final ByteBuf buffer) { final List coll = new ArrayList<>(); for (int i = 0; i < count; i++) { - long asValue = buffer.readUnsignedShort(); coll.add( - refCache.getSharedReference(new AsSequenceBuilder().setAs(refCache.getSharedReference(new AsNumber(asValue))).build())); + refCache.getSharedReference(new AsSequenceBuilder().setAs(refCache.getSharedReference(new AsNumber(buffer.readUnsignedInt()))).build())); } return coll; } @@ -80,14 +77,13 @@ public final class AsPathSegmentParser { static List parseAsSet(final ReferenceCache refCache, final int count, final ByteBuf buffer) { final List coll = new ArrayList<>(); for (int i = 0; i < count; i++) { - long asValue = buffer.readUnsignedShort(); coll.add(refCache.getSharedReference( - new AsNumber(asValue))); + new AsNumber(buffer.readUnsignedInt()))); } return coll; } - static void serializeAsSet(final ASetCase aSetCase, final ByteBuf byteAggregator) { + static void serializeAsSet(ASetCase aSetCase, ByteBuf byteAggregator) { ASet aset = aSetCase.getASet(); if (aset == null || aset.getAsSet() == null) { return; @@ -95,19 +91,19 @@ public final class AsPathSegmentParser { byteAggregator.writeByte(serializeType(AS_SET)); byteAggregator.writeByte(aset.getAsSet().size()); for (AsNumber asNumber : aset.getAsSet()) { - byteAggregator.writeShort(new ShortAsNumber(asNumber).getValue().shortValue()); + byteAggregator.writeInt(asNumber.getValue().intValue()); } } - static void serializeAsSequence(final AListCase aListCase, final ByteBuf byteAggregator) { - final AList alist = aListCase.getAList(); + static void serializeAsSequence(AListCase aListCase, ByteBuf byteAggregator) { + AList alist = aListCase.getAList(); if (alist == null || alist.getAsSequence() == null) { return; } byteAggregator.writeByte(serializeType(AS_SEQUENCE)); byteAggregator.writeByte(alist.getAsSequence().size()); for (AsSequence value : alist.getAsSequence()) { - byteAggregator.writeShort(new ShortAsNumber(value.getAs()).getValue().shortValue()); + byteAggregator.writeInt(value.getAs().getValue().intValue()); } } } diff --git a/bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/BGPParserTest.java b/bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/BGPParserTest.java index c5ec4ba1e5..0c5ceae8fa 100644 --- a/bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/BGPParserTest.java +++ b/bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/BGPParserTest.java @@ -14,10 +14,8 @@ import static org.junit.Assert.assertNull; import com.google.common.collect.Lists; import com.google.common.collect.Sets; - import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; - import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; @@ -25,7 +23,6 @@ import java.math.BigInteger; import java.util.ArrayList; import java.util.List; import java.util.Set; - import org.junit.BeforeClass; import org.junit.Test; import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl; @@ -170,10 +167,10 @@ public class BGPParserTest { * Tests IPv4 NEXT_HOP, ATOMIC_AGGREGATE, COMMUNITY, NLRI * * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker - * 00 52 <- length (82) - including header + * 00 54 <- length (84) - including header * 02 <- message type * 00 00 <- withdrawn routes length - * 00 2f <- total path attribute length (47) + * 00 31 <- total path attribute length (49) * 40 <- attribute flags * 01 <- attribute type code (origin) * 01 <- attribute length @@ -183,7 +180,7 @@ public class BGPParserTest { * 06 <- attribute length * 02 <- AS_SEQUENCE * 01 <- path segment count - * fd ea <- path segment value (65002) + * 00 00 fd ea <- path segment value (65002) * 40 <- attribute flags * 03 <- attribute type code (Next Hop) * 04 <- attribute length @@ -195,7 +192,7 @@ public class BGPParserTest { * 60 <- attribute flags * 06 <- attribute type code (atomic aggregate) * 00 <- attribute length - * 64 <- attribute flags + * 40 <- attribute flags * 08 <- attribute type code (community) * 10 <- attribute length FF FF FF * 01 <- value (NO_EXPORT) @@ -287,20 +284,20 @@ public class BGPParserTest { * Tests IPv6 NEXT_HOP, NLRI, ORIGIN.IGP, MULTI_EXIT_DISC, ORIGINATOR-ID, CLUSTER_LIST. * * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker - * 00 7e <- length (126) - including header + * 00 80 <- length (128) - including header * 02 <- message type * 00 00 <- withdrawn routes length - * 00 67 <- total path attribute length (103) + * 00 69 <- total path attribute length (105) * 40 <- attribute flags * 01 <- attribute type code (origin) * 01 <- attribute length * 00 <- Origin value (IGP) * 40 <- attribute flags * 02 <- attribute type code (as path) - * 04 <- attribute length + * 06 <- attribute length * 02 <- AS_SEQUENCE * 01 <- path segment count - * fd e9 <- path segment value (65001) + * 00 00 fd e9 <- path segment value (65001) * 40 <- attribute flags * 03 <- attribute type code (next hop) * 04 <- attribute length @@ -413,10 +410,10 @@ public class BGPParserTest { * Tests more AS Numbers in AS_PATH, AGGREGATOR, ORIGIN.INCOMPLETE * * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker - * 00 45 <- length (69) - including header + * 00 4b <- length (75) - including header * 02 <- message type * 00 00 <- withdrawn routes length - * 00 30 <- total path attribute length (42) + * 00 30 <- total path attribute length (48) * 40 <- attribute flags * 01 <- attribute type code (origin) * 01 <- attribute length @@ -426,11 +423,11 @@ public class BGPParserTest { * 10 <- attribute length * 02 <- AS_SEQUENCE * 01 <- path segment count - * 00 1e <- path segment value (30) + * 00 00 00 1e <- path segment value (30) * 01 <- AS_SET * 02 <- path segment count - * 00 0a <- path segment value (10) - * 00 14 <- path segment value (20) + * 00 00 00 0a <- path segment value (10) + * 00 00 00 14 <- path segment value (20) * 40 <- attribute flags * 03 <- attribute type (Next hop) * 04 <- attribute length diff --git a/bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/ParserTest.java b/bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/ParserTest.java index 146ac29f06..8280ca6f49 100644 --- a/bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/ParserTest.java +++ b/bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/ParserTest.java @@ -310,17 +310,4 @@ public class ParserTest { // the capabilities can be swapped. assertTrue(Arrays.equals(openWithCpblt1, ByteArray.getAllBytes(result)) || Arrays.equals(openWithCpblt2, ByteArray.getAllBytes(result))); } - - // https://bugs.opendaylight.org/show_bug.cgi?id=1370 - // tests if all bytes are read after deserialization error occurs - @Test - public void testUpdateMsgParser() throws BGPParsingException { - final ByteBuf buffer = Unpooled.copiedBuffer(updateMsg); - try { - ParserTest.reg.parseMessage(buffer); - fail(); - } catch(BGPDocumentedException e) { - assertEquals(0, buffer.readableBytes()); - } - } } diff --git a/bgp/parser-impl/src/test/resources/up1.bin b/bgp/parser-impl/src/test/resources/up1.bin index 9cb7a1cce7beab62c516b57021a7affb11dc4c5e..cddc48604816d9d88490a337daee5ea67d0e2d27 100644 GIT binary patch delta 40 icmWFvQTmSt7($pB7#Iv47#SHHnAn&Y85kxi7y$qWKN7G2 delta 38 gcmWFuQuvPs7=oA>7#Q>&7#SHHm{^z?Cn^~M0OJZ0ssI20 diff --git a/bgp/parser-impl/src/test/resources/up2.bin b/bgp/parser-impl/src/test/resources/up2.bin index f93d9e87c90ada21c15e83492ef99f5d5d7d0abb..c3aba85ff8e99d2a77cdeb44e698234c50f1225c 100644 GIT binary patch delta 41 jcmb