Fix RD pattern in RouteDistinguisherBuilder 72/57272/1
authorXiao Liang <shaw.leon@gmail.com>
Wed, 3 May 2017 08:44:08 +0000 (08:44 +0000)
committerClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Wed, 17 May 2017 12:10:54 +0000 (12:10 +0000)
Type 0 RD is 2+4 bytes.

Change-Id: I7ec0099cf5c1cdf8ab7d333dc26756c17228579b
Signed-off-by: Xiao Liang <shaw.leon@gmail.com>
(cherry picked from commit a52ecc55a9dca19ce563cea27263ea0842ff9789)

bgp/concepts/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/bgp/types/rev130919/RouteDistinguisherBuilder.java
bgp/concepts/src/test/java/org/opendaylight/bgp/concepts/RouteDistinguisherUtilTest.java

index a9a1c455df05f9ef638ce70e83adc1cfb2dabc5f..c4900a22a8fda7cf8c5819dfa39ede17f60ff5a5 100644 (file)
@@ -23,6 +23,10 @@ public final class RouteDistinguisherBuilder {
 
     private static final Pattern RD_TWO_OCTET_AS =
         Pattern.compile("0:"
+            + "([0-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|"
+            + "[1-5][0-9][0-9][0-9][0-9]|6[0-4][0-9][0-9][0-9]|"
+            + "65[0-4][0-9][0-9]|655[0-2][0-9]|6553[0-5])"
+            + ":"
             + "([0-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|"
             + "[1-9][0-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9][0-9]|"
             + "[1-9][0-9][0-9][0-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]|"
@@ -30,11 +34,7 @@ public final class RouteDistinguisherBuilder {
             + "4[0-1][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]|42[0-8][0-9][0-9][0-9][0-9][0-9][0-9][0-9]|"
             + "429[0-3][0-9][0-9][0-9][0-9][0-9][0-9]|4294[0-8][0-9][0-9][0-9][0-9][0-9]|"
             + "42949[0-5][0-9][0-9][0-9][0-9]|429496[0-6][0-9][0-9][0-9]|4294967[0-1][0-9][0-9]|"
-            + "42949672[0-8][0-9]|429496729[0-5])"
-            + ":"
-            + "([0-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|"
-            + "[1-5][0-9][0-9][0-9][0-9]|6[0-4][0-9][0-9][0-9]|"
-            + "65[0-4][0-9][0-9]|655[0-2][0-9]|6553[0-5])");
+            + "42949672[0-8][0-9]|429496729[0-5])");
 
     private static final Pattern RD_IPV4 =
         Pattern.compile("((([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}"
index 378018bebaf22251dbaf3555dcbdc97a11d7de16..b5c3adc4ba84480d3d2593d252aae5f83579dfe6 100644 (file)
@@ -23,7 +23,9 @@ public class RouteDistinguisherUtilTest {
     private static final String IP_PORT = "10";
     private static final String ADMIN = "55";
     private static final String ASSIGNED_NUMBER = "65535";
+    private static final String ASSIGNED_NUMBER_BIG = "4294967295";
     private static final byte[] AS_2B_BYTES = { 0, 0, 0, 55, 0, 0, (byte)0xff, (byte)0xff};
+    private static final byte[] AS_2B_BYTES_BIG = { 0, 0, 0, 55, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff};
     private static final byte[] IP_BYTES = { 0, 1, 1, 2, 3, 4, 0, 10 };
     private static final byte[] AS_4B_BYTES = { 0, 2, 0, 0, 0, 55, (byte)0xff, (byte)0xff};
     private static final byte[] INVALID_RD_TYPE_BYTES = { 0, 3, 0, 0, 0, 55, (byte)0xff, (byte)0xff};
@@ -40,6 +42,17 @@ public class RouteDistinguisherUtilTest {
         assertEquals("0" + SEPARATOR + ADMIN + SEPARATOR + ASSIGNED_NUMBER, parsed.getRdTwoOctetAs().getValue());
     }
 
+    @Test
+    public void testAs2BLongRouteDistinguisher() {
+        final RouteDistinguisher expected = createRouteDistinguisher(0, ADMIN, ASSIGNED_NUMBER_BIG);
+        final RouteDistinguisher parsed = RouteDistinguisherUtil.parseRouteDistinguisher(Unpooled.copiedBuffer(AS_2B_BYTES_BIG));
+        assertEquals(expected.getRdTwoOctetAs(), parsed.getRdTwoOctetAs());
+        final ByteBuf byteAggregator = Unpooled.buffer(AS_2B_BYTES_BIG.length);
+        RouteDistinguisherUtil.serializeRouteDistinquisher(expected, byteAggregator);
+        assertArrayEquals(AS_2B_BYTES_BIG, byteAggregator.array());
+        assertEquals("0" + SEPARATOR + ADMIN + SEPARATOR + ASSIGNED_NUMBER_BIG, parsed.getRdTwoOctetAs().getValue());
+    }
+
     @Test
     public void testIpv4RouteDistinguisher() {
         final RouteDistinguisher expected = createRouteDistinguisher(1, IP_ADDRESS, IP_PORT);