Revert "Bug 1205 - AS path segment value encoded by 2 bytes" 82/9082/1
authorMilos Fabian <milfabia@cisco.com>
Wed, 16 Jul 2014 13:50:53 +0000 (15:50 +0200)
committerMilos Fabian <milfabia@cisco.com>
Wed, 16 Jul 2014 14:57:33 +0000 (16:57 +0200)
This reverts commit d4f23f2d138b7bf0f1e1d2b61b5720749daf207f.

Change-Id: Iaa6e1d467630ba4bc32d9b67db6f09150d46d914
Signed-off-by: Milos Fabian <milfabia@cisco.com>
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/AsPathSegmentParser.java
bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/BGPParserTest.java
bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/ParserTest.java
bgp/parser-impl/src/test/resources/up1.bin
bgp/parser-impl/src/test/resources/up2.bin
bgp/parser-impl/src/test/resources/up3.bin

index 457114d7291282d8656d633db1d6cb03ceff0641..fb174412ae18181c33e5e297be9cbc58ac9114ff 100644 (file)
@@ -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<AsSequence> parseAsSequence(final ReferenceCache refCache, final int count, final ByteBuf buffer) {
         final List<AsSequence> 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<AsNumber> parseAsSet(final ReferenceCache refCache, final int count, final ByteBuf buffer) {
         final List<AsNumber> 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());
         }
     }
 }
index c5ec4ba1e5d0f3f90c466f886f8529bf2064b701..0c5ceae8fa669b9ae5a36f46c23eb4a81243cf34 100644 (file)
@@ -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
index 146ac29f06ff557662c84b6e75d60dd80287d15a..8280ca6f4969691619f08538c169b641cb900095 100644 (file)
@@ -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());
-        }
-    }
 }
index 9cb7a1cce7beab62c516b57021a7affb11dc4c5e..cddc48604816d9d88490a337daee5ea67d0e2d27 100644 (file)
Binary files a/bgp/parser-impl/src/test/resources/up1.bin and b/bgp/parser-impl/src/test/resources/up1.bin differ
index f93d9e87c90ada21c15e83492ef99f5d5d7d0abb..c3aba85ff8e99d2a77cdeb44e698234c50f1225c 100644 (file)
Binary files a/bgp/parser-impl/src/test/resources/up2.bin and b/bgp/parser-impl/src/test/resources/up2.bin differ
index 984a0d9adaa0877fb3671a7cfba205496686092f..f8afa742b0674cb52db18be9e968ccdb15883e00 100644 (file)
Binary files a/bgp/parser-impl/src/test/resources/up3.bin and b/bgp/parser-impl/src/test/resources/up3.bin differ