Bug-5933: Support for draft-ietf-bess-evpn-overlay-02 54/39454/6
authorAjay <ajayl.bro@gmail.com>
Wed, 25 May 2016 23:43:04 +0000 (23:43 +0000)
committerMilos Fabian <milfabia@cisco.com>
Tue, 31 May 2016 17:12:02 +0000 (17:12 +0000)
- defined new encapsulation extended community in bgp-types.yang
- implemented parser/serializer for it and registered the same
- added unit-tests to cover the new code

Change-Id: I63cc95d2b61b7a983981df07b68daf0f63425aba
Signed-off-by: Ajay <ajayl.bro@gmail.com>
bgp/concepts/src/main/yang/bgp-types.yang
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/BGPActivator.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/EncapsulationEC.java [new file with mode: 0755]
bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/EncapsulationECTest.java [new file with mode: 0755]

index 6c51c4be395250169ccfaf5d88aa4152e283ad7b..b8091613a9f12be5d7e5c44b7093deb07438ebf5 100644 (file)
@@ -138,6 +138,54 @@ module bgp-types {
         }
     }
 
+    typedef encapsulation-tunnel-type {
+        reference "http://www.iana.org/assignments/bgp-parameters/bgp-parameters.xhtml#tunnel-types";
+        type enumeration {
+            enum l2tpv3-over-ip {
+                value 1;
+            }
+            enum gre {
+                value 2;
+            }
+            enum transmit-tunnel-endpoint {
+                value 3;
+            }
+            enum ipsec-tunnel-mode {
+                value 4;
+            }
+            enum ip-in-ip-ipsec-transport-mode {
+                value 5;
+            }
+            enum mpls-in-ip-tunnel-ipsec-transport-mode {
+                value 6;
+            }
+            enum ip-in-ip {
+                value 7;
+            }
+            enum vxlan {
+                value 8;
+            }
+            enum nvgre {
+                value 9;
+            }
+            enum mpls {
+                value 10;
+            }
+            enum mpls-in-gre {
+                value 11;
+            }
+            enum vxlan-gpe {
+                value 12;
+            }
+            enum mpls-in-udp {
+                value 13;
+            }
+            enum ipv6-tunnel {
+                value 14;
+            }
+        }
+    }
+
     grouping bgp-aggregator {
         reference "http://tools.ietf.org/html/rfc4271#section-5.1.7";
         description "BGP Path Attribute AGGREGATOR.";
@@ -201,6 +249,17 @@ module bgp-types {
         }
     }
 
+    grouping encapsulation-extended-community {
+        reference "https://tools.ietf.org/html/rfc5512#section-4.5";
+        description "BGP Encapsulation extended community";
+
+        leaf tunnel-type {
+            description "Tunnel type specifying the encapsulation protocol";
+            mandatory true;
+            type encapsulation-tunnel-type;
+        }
+    }
+
     grouping extended-community {
         leaf transitive {
             type boolean;
@@ -298,6 +357,11 @@ module bgp-types {
                     uses as-4-spec-common;
                 }
             }
+            case encapsulation-case {
+                container encapsulation-extended-community {
+                    uses encapsulation-extended-community;
+                }
+            }
         }
     }
 
index 8339f9ba0d718039c84de6d10fc00d226eeb568b..5b30152669bbc388577bf8ad961557d42cff89a1 100755 (executable)
@@ -44,6 +44,7 @@ import org.opendaylight.protocol.bgp.parser.impl.message.update.OriginatorIdAttr
 import org.opendaylight.protocol.bgp.parser.impl.message.update.UnrecognizedAttributesSerializer;
 import org.opendaylight.protocol.bgp.parser.impl.message.update.WithdrawnRoutesSerializer;
 import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.AsTwoOctetSpecificEcHandler;
+import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.EncapsulationEC;
 import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.Ipv4SpecificEcHandler;
 import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.LinkBandwidthEC;
 import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.OpaqueEcHandler;
@@ -99,6 +100,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.type
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.As4RouteOriginExtendedCommunityCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.As4RouteTargetExtendedCommunityCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.AsSpecificExtendedCommunityCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.EncapsulationCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.Inet4SpecificExtendedCommunityCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.LinkBandwidthCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.OpaqueExtendedCommunityCase;
@@ -338,5 +340,10 @@ public final class BGPActivator extends AbstractBGPExtensionProviderActivator {
         final RouteOrigin4OctectASEcHandler rOrig4Oct = new RouteOrigin4OctectASEcHandler();
         regs.add(context.registerExtendedCommunityParser(rOrig4Oct.getType(true), rOrig4Oct.getSubType(), rOrig4Oct));
         regs.add(context.registerExtendedCommunitySerializer(As4RouteOriginExtendedCommunityCase.class, rOrig4Oct));
+
+        final EncapsulationEC encapsulationECHandler = new EncapsulationEC();
+        regs.add(context.registerExtendedCommunityParser(encapsulationECHandler.getType(true), encapsulationECHandler.getSubType(),
+                encapsulationECHandler));
+        regs.add(context.registerExtendedCommunitySerializer(EncapsulationCase.class, encapsulationECHandler));
     }
 }
diff --git a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/EncapsulationEC.java b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/EncapsulationEC.java
new file mode 100755 (executable)
index 0000000..efd86bf
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2016 Brocade Communications 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.bgp.parser.impl.message.update.extended.communities;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Preconditions;
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
+import org.opendaylight.protocol.bgp.parser.BGPParsingException;
+import org.opendaylight.protocol.bgp.parser.spi.extended.community.AbstractOpaqueExtendedCommunity;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.EncapsulationTunnelType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.ExtendedCommunity;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.EncapsulationCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.EncapsulationCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.encapsulation._case.EncapsulationExtendedCommunity;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.encapsulation._case.EncapsulationExtendedCommunityBuilder;
+
+/**
+ * Parser for BGP Encapsulation extended community attribute.
+ *
+ * @see <a href="https://tools.ietf.org/html/rfc5512#section-4.5">BGP Encapsulation Extended Community</a>
+ */
+
+public class EncapsulationEC extends AbstractOpaqueExtendedCommunity {
+    @VisibleForTesting
+    public static final int SUBTYPE = 12;
+    private static final int RESERVED_SIZE = 4;
+    private static final int CONTENT_SIZE = 6;
+
+    @Override
+    public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer) throws BGPDocumentedException, BGPParsingException {
+        Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
+        Preconditions.checkArgument(buffer.readableBytes() == CONTENT_SIZE, "Wrong length of array of bytes. Passed: " + buffer.readableBytes() + ".");
+        buffer.skipBytes(RESERVED_SIZE);
+        final EncapsulationExtendedCommunity encap = new EncapsulationExtendedCommunityBuilder()
+            .setTunnelType(EncapsulationTunnelType.forValue(buffer.readUnsignedShort()))
+            .build();
+        return new EncapsulationCaseBuilder().setEncapsulationExtendedCommunity(encap).build();
+    }
+
+    @Override
+    public void serializeExtendedCommunity(final ExtendedCommunity extendedCommunity, final ByteBuf body) {
+        Preconditions.checkArgument(extendedCommunity instanceof EncapsulationCase,
+            "The extended community %s is not EncapsulationCase type.", extendedCommunity);
+        final EncapsulationExtendedCommunity encap = ((EncapsulationCase) extendedCommunity).getEncapsulationExtendedCommunity();
+        body.writeZero(RESERVED_SIZE);
+        body.writeShort(encap.getTunnelType().getIntValue());
+    }
+
+    @Override
+    public int getSubType() {
+        return SUBTYPE;
+    }
+}
diff --git a/bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/EncapsulationECTest.java b/bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/EncapsulationECTest.java
new file mode 100755 (executable)
index 0000000..3641f1a
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2016 Brocade Communications 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.bgp.parser.impl.message.update.extended.communities;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
+import org.opendaylight.protocol.bgp.parser.BGPParsingException;
+import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.EncapsulationTunnelType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.ExtendedCommunity;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.EncapsulationCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.EncapsulationCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.LinkBandwidthCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.encapsulation._case.EncapsulationExtendedCommunityBuilder;
+
+public class EncapsulationECTest {
+    private static final byte[] RESULT = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a };
+    private static final int COMMUNITY_VALUE_SIZE = 6;
+    private static final EncapsulationTunnelType TUNNEL_TYPE = EncapsulationTunnelType.Mpls;
+    private EncapsulationEC parser;
+
+    @Before
+    public void setUp() {
+        this.parser = new EncapsulationEC();
+    }
+
+    @Test
+    public void testParser() throws BGPParsingException, BGPDocumentedException {
+        final ByteBuf buffer = Unpooled.buffer(COMMUNITY_VALUE_SIZE);
+
+        final EncapsulationCase expected = new EncapsulationCaseBuilder().setEncapsulationExtendedCommunity(new EncapsulationExtendedCommunityBuilder()
+            .setTunnelType(TUNNEL_TYPE)
+            .build()).build();
+        this.parser.serializeExtendedCommunity(expected, buffer);
+        assertArrayEquals(RESULT, ByteArray.getAllBytes(buffer));
+
+        final ExtendedCommunity result = this.parser.parseExtendedCommunity(Unpooled.wrappedBuffer(RESULT));
+        assertEquals(expected, result);
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testWrongCase() {
+        this.parser.serializeExtendedCommunity(new LinkBandwidthCaseBuilder().build(), null);
+    }
+
+    @Test
+    public void testSubtype() {
+        assertEquals(EncapsulationEC.SUBTYPE, this.parser.getSubType());
+    }
+}
\ No newline at end of file