}
}
+ 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.";
}
}
+ 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;
uses as-4-spec-common;
}
}
+ case encapsulation-case {
+ container encapsulation-extended-community {
+ uses encapsulation-extended-community;
+ }
+ }
}
}
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;
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;
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));
}
}
--- /dev/null
+/*
+ * 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;
+ }
+}
--- /dev/null
+/*
+ * 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