MVPN RFC6514 Extendend communities 52/71152/3
authorClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Fri, 20 Apr 2018 05:42:46 +0000 (07:42 +0200)
committerClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Sun, 22 Apr 2018 20:02:37 +0000 (22:02 +0200)
Implement parser/serializer for new
extended communities

JIRA: BGPCEP-396
Change-Id: I3e5dd62e906d40ef4cd8239256539010acfb83d0
Signed-off-by: Claudio D. Gasparini <claudio.gasparini@pantheon.tech>
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/Ipv4SpecificEcHandler.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/SourceASHandler.java [new file with mode: 0644]
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/VrfRouteImportHandler.java [new file with mode: 0644]
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/four/octect/as/specific/SourceAS4OctectHandler.java [new file with mode: 0644]
bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/Ipv4SpecificEcHandlerTest.java
bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/SourceAS4OctectASHandlerTest.java [new file with mode: 0644]
bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/SourceASHandlerTest.java [new file with mode: 0644]
bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/VrfRouteImportHandlerTest.java [new file with mode: 0644]
bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/extended/community/Inet4SpecificExtendedCommunityCommonUtil.java [new file with mode: 0644]
bgp/parser-spi/src/test/java/org/opendaylight/protocol/bgp/parser/spi/extended/community/Inet4SpecificExtendedCommunityCommonUtilTest.java [new file with mode: 0644]

index 68ce4550b62f74768bde17afa00e09055edc2413..63665f08915668b78ae6494927898ad49ffcae4b 100755 (executable)
@@ -48,9 +48,12 @@ import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communi
 import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.RouteOriginIpv4EcHandler;
 import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.RouteTargetAsTwoOctetEcHandler;
 import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.RouteTargetIpv4EcHandler;
+import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.SourceASHandler;
+import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.VrfRouteImportHandler;
 import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.four.octect.as.specific.Generic4OctASEcHandler;
 import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.four.octect.as.specific.RouteOrigin4OctectASEcHandler;
 import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.four.octect.as.specific.RouteTarget4OctectASEcHandler;
+import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.four.octect.as.specific.SourceAS4OctectHandler;
 import org.opendaylight.protocol.bgp.parser.spi.AbstractBGPExtensionProviderActivator;
 import org.opendaylight.protocol.bgp.parser.spi.AddressFamilyRegistry;
 import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
@@ -326,5 +329,22 @@ public final class BGPActivator extends AbstractBGPExtensionProviderActivator {
         regs.add(context.registerExtendedCommunityParser(encapsulationECHandler.getType(true), encapsulationECHandler.getSubType(),
                 encapsulationECHandler));
         regs.add(context.registerExtendedCommunitySerializer(EncapsulationCase.class, encapsulationECHandler));
+
+
+        final SourceAS4OctectHandler source4ASHandler = new SourceAS4OctectHandler();
+        regs.add(context.registerExtendedCommunityParser(source4ASHandler.getType(true),
+                source4ASHandler.getSubType(), source4ASHandler));
+        regs.add(context.registerExtendedCommunitySerializer(SourceAs4ExtendedCommunityCase.class, source4ASHandler));
+
+        final SourceASHandler sourceASHandler = new SourceASHandler();
+        regs.add(context.registerExtendedCommunityParser(sourceASHandler.getType(true),
+                sourceASHandler.getSubType(), sourceASHandler));
+        regs.add(context.registerExtendedCommunitySerializer(SourceAsExtendedCommunityCase.class, sourceASHandler));
+
+        final VrfRouteImportHandler vrfRouteImportHandler = new VrfRouteImportHandler();
+        regs.add(context.registerExtendedCommunityParser(vrfRouteImportHandler.getType(true),
+                vrfRouteImportHandler.getSubType(), vrfRouteImportHandler));
+        regs.add(context.registerExtendedCommunitySerializer(SourceAsExtendedCommunityCase.class,
+                vrfRouteImportHandler));
     }
 }
index a61c3efac8a2748365db5a564827291eaee44bc4..dc318c46a42e2f2c896bb29db6d50d9a08e6ff68 100644 (file)
@@ -8,39 +8,48 @@
 
 package org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities;
 
+import static org.opendaylight.protocol.bgp.parser.spi.extended.community.Inet4SpecificExtendedCommunityCommonUtil.parseCommon;
+import static org.opendaylight.protocol.bgp.parser.spi.extended.community.Inet4SpecificExtendedCommunityCommonUtil.serializeCommon;
+
 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.AbstractIpv4ExtendedCommunity;
-import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.protocol.util.ByteBufWriteUtil;
-import org.opendaylight.protocol.util.Ipv4Util;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.ExtendedCommunity;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.Inet4SpecificExtendedCommunityCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.Inet4SpecificExtendedCommunityCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.inet4.specific.extended.community._case.Inet4SpecificExtendedCommunity;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.inet4.specific.extended.community._case.Inet4SpecificExtendedCommunityBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.inet4.specific.extended.community.common.Inet4SpecificExtendedCommunityCommon;
 
 public final class Ipv4SpecificEcHandler extends AbstractIpv4ExtendedCommunity {
 
     private static final int SUBTYPE = 0;
 
     @Override
-    public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer) throws BGPDocumentedException, BGPParsingException {
+    public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer) {
         return new Inet4SpecificExtendedCommunityCaseBuilder().setInet4SpecificExtendedCommunity(
-                new Inet4SpecificExtendedCommunityBuilder().setGlobalAdministrator(
-                        Ipv4Util.addressForByteBuf(buffer)).setLocalAdministrator(
-                        ByteArray.readBytes(buffer, INET_LOCAL_ADMIN_LENGTH)).build()).build();
+                new Inet4SpecificExtendedCommunityBuilder()
+                        .setInet4SpecificExtendedCommunityCommon(parseCommon(buffer))
+                        .build()).build();
     }
 
     @Override
     public void serializeExtendedCommunity(final ExtendedCommunity extendedCommunity, final ByteBuf byteAggregator) {
         Preconditions.checkArgument(extendedCommunity instanceof Inet4SpecificExtendedCommunityCase,
-                "The extended community %s is not Inet4SpecificExtendedCommunityCase type.", extendedCommunity);
-        final Inet4SpecificExtendedCommunity inet4SpecificExtendedCommunity = ((Inet4SpecificExtendedCommunityCase) extendedCommunity).getInet4SpecificExtendedCommunity();
-        ByteBufWriteUtil.writeIpv4Address(inet4SpecificExtendedCommunity.getGlobalAdministrator(), byteAggregator);
-        byteAggregator.writeBytes(inet4SpecificExtendedCommunity.getLocalAdministrator());
+                "The extended community %s is not Inet4SpecificExtendedCommunityCase type.",
+                extendedCommunity);
+        final Inet4SpecificExtendedCommunity inet4SpecificExtendedCommunity
+                = ((Inet4SpecificExtendedCommunityCase) extendedCommunity).getInet4SpecificExtendedCommunity();
+
+        final Inet4SpecificExtendedCommunityCommon common
+                = inet4SpecificExtendedCommunity.getInet4SpecificExtendedCommunityCommon();
+        if (common != null) {
+            serializeCommon(inet4SpecificExtendedCommunity.getInet4SpecificExtendedCommunityCommon(), byteAggregator);
+        } else {
+            ByteBufWriteUtil.writeIpv4Address(inet4SpecificExtendedCommunity.getGlobalAdministrator(), byteAggregator);
+            byteAggregator.writeBytes(inet4SpecificExtendedCommunity.getLocalAdministrator());
+        }
     }
 
     @Override
diff --git a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/SourceASHandler.java b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/SourceASHandler.java
new file mode 100644 (file)
index 0000000..d38289b
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ *  Copyright (c) 2018 AT&T Intellectual Property. 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.base.Preconditions;
+import com.google.common.primitives.Ints;
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.protocol.bgp.parser.spi.extended.community.AbstractTwoOctetAsExtendedCommunity;
+import org.opendaylight.protocol.util.ByteBufWriteUtil;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.ShortAsNumber;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.ExtendedCommunity;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.SourceAsExtendedCommunityCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.SourceAsExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.source.as.extended.community._case.SourceAsExtendedCommunity;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.source.as.extended.community._case.SourceAsExtendedCommunityBuilder;
+
+public final class SourceASHandler extends AbstractTwoOctetAsExtendedCommunity {
+    private static final short SUBTYPE = 9;
+    private static final int LOCAL_ADMIN = 0;
+
+    @Override
+    public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer) {
+        final SourceAsExtendedCommunityBuilder builder = new SourceAsExtendedCommunityBuilder();
+        builder.setGlobalAdministrator(new ShortAsNumber((long) buffer.readUnsignedShort()));
+        buffer.skipBytes(AS_LOCAL_ADMIN_LENGTH);
+        return new SourceAsExtendedCommunityCaseBuilder().setSourceAsExtendedCommunity(builder.build()).build();
+    }
+
+    @Override
+    public void serializeExtendedCommunity(final ExtendedCommunity extendedCommunity, final ByteBuf body) {
+        Preconditions.checkArgument(extendedCommunity instanceof SourceAsExtendedCommunityCase,
+                "The extended community %s is not SourceAsExtendedCommunityCase type.",
+                extendedCommunity);
+        final SourceAsExtendedCommunity excomm = ((SourceAsExtendedCommunityCase) extendedCommunity)
+                .getSourceAsExtendedCommunity();
+        ByteBufWriteUtil.writeUnsignedShort(Ints.checkedCast(excomm.getGlobalAdministrator().getValue()), body);
+        ByteBufWriteUtil.writeInt(LOCAL_ADMIN, body);
+    }
+
+    @Override
+    public int getSubType() {
+        return SUBTYPE;
+    }
+}
diff --git a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/VrfRouteImportHandler.java b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/VrfRouteImportHandler.java
new file mode 100644 (file)
index 0000000..94f6bf6
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ *  Copyright (c) 2018 AT&T Intellectual Property. 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.opendaylight.protocol.bgp.parser.spi.extended.community.Inet4SpecificExtendedCommunityCommonUtil.parseCommon;
+import static org.opendaylight.protocol.bgp.parser.spi.extended.community.Inet4SpecificExtendedCommunityCommonUtil.serializeCommon;
+
+import com.google.common.base.Preconditions;
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.protocol.bgp.parser.spi.extended.community.AbstractIpv4ExtendedCommunity;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.ExtendedCommunity;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.VrfRouteImportExtendedCommunityCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.VrfRouteImportExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.vrf.route._import.extended.community._case.VrfRouteImportExtendedCommunity;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.vrf.route._import.extended.community._case.VrfRouteImportExtendedCommunityBuilder;
+
+public final class VrfRouteImportHandler extends AbstractIpv4ExtendedCommunity {
+    private static final short SUBTYPE = 11;
+
+    @Override
+    public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer) {
+        return new VrfRouteImportExtendedCommunityCaseBuilder().setVrfRouteImportExtendedCommunity(
+                new VrfRouteImportExtendedCommunityBuilder()
+                        .setInet4SpecificExtendedCommunityCommon(parseCommon(buffer))
+                        .build()).build();
+    }
+
+    @Override
+    public void serializeExtendedCommunity(final ExtendedCommunity extendedCommunity, final ByteBuf byteAggregator) {
+        Preconditions.checkArgument(extendedCommunity instanceof VrfRouteImportExtendedCommunityCase,
+                "The extended community %s is not VrfRouteImportExtendedCommunityCase type.",
+                extendedCommunity);
+        final VrfRouteImportExtendedCommunity inet4SpecificExtendedCommunity
+                = ((VrfRouteImportExtendedCommunityCase) extendedCommunity).getVrfRouteImportExtendedCommunity();
+        serializeCommon(inet4SpecificExtendedCommunity.getInet4SpecificExtendedCommunityCommon(), byteAggregator);
+    }
+
+    @Override
+    public int getSubType() {
+        return SUBTYPE;
+    }
+}
diff --git a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/four/octect/as/specific/SourceAS4OctectHandler.java b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/four/octect/as/specific/SourceAS4OctectHandler.java
new file mode 100644 (file)
index 0000000..452fcda
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ *  Copyright (c) 2018 AT&T Intellectual Property. 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.four.octect.as.specific;
+
+import com.google.common.base.Preconditions;
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.protocol.bgp.parser.spi.extended.community.Abstract4OctetAsExtendedCommunity;
+import org.opendaylight.protocol.util.ByteBufWriteUtil;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.ExtendedCommunity;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.SourceAs4ExtendedCommunityCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.SourceAs4ExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.source.as._4.extended.community._case.SourceAs4ExtendedCommunityBuilder;
+
+public final class SourceAS4OctectHandler extends Abstract4OctetAsExtendedCommunity {
+    private static final short SUBTYPE = 209;
+    private static final int LOCAL_ADMIN = 0;
+    private static final short LOCAL_LENGTH = 2;
+
+    @Override
+    public ExtendedCommunity parseExtendedCommunity(final ByteBuf body) {
+        final SourceAs4ExtendedCommunityBuilder builder = new SourceAs4ExtendedCommunityBuilder();
+        builder.setAsNumber(new AsNumber(body.readUnsignedInt()));
+        body.skipBytes(LOCAL_LENGTH);
+        return new SourceAs4ExtendedCommunityCaseBuilder().setSourceAs4ExtendedCommunity(
+                builder.build()).build();
+    }
+
+    @Override
+    public void serializeExtendedCommunity(final ExtendedCommunity extendedCommunity, final ByteBuf body) {
+        Preconditions.checkArgument(extendedCommunity instanceof SourceAs4ExtendedCommunityCase,
+                "The extended community %s is not SourceAs4ExtendedCommunityCase type.",
+                extendedCommunity);
+
+        body.writeInt(((SourceAs4ExtendedCommunityCase) extendedCommunity).getSourceAs4ExtendedCommunity()
+                .getAsNumber().getValue().intValue());
+        ByteBufWriteUtil.writeUnsignedShort(LOCAL_ADMIN, body);
+    }
+
+    @Override
+    public int getSubType() {
+        return SUBTYPE;
+    }
+}
index 1b55983dd07ba2e53e1220723a3ad5a7e38e726d..14e3f68e5b4e01d4b96fe987df378f3fe9cec8a9 100644 (file)
@@ -8,37 +8,67 @@
 
 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.Assert;
 import org.junit.Test;
-import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
-import org.opendaylight.protocol.bgp.parser.BGPParsingException;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.ExtendedCommunity;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.Inet4SpecificExtendedCommunityCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.Inet4SpecificExtendedCommunityCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.inet4.specific.extended.community._case.Inet4SpecificExtendedCommunityBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.inet4.specific.extended.community.common.Inet4SpecificExtendedCommunityCommonBuilder;
 
 public class Ipv4SpecificEcHandlerTest {
 
     private static final byte[] INPUT = {
-        12, 51, 2, 5, 21, 45
+            12, 51, 2, 5, 21, 45
     };
 
     @Test
-    public void testHandler() throws BGPDocumentedException, BGPParsingException {
+    public void testHandlerDeprecated() {
+        final Ipv4SpecificEcHandler handler = new Ipv4SpecificEcHandler();
+        final Inet4SpecificExtendedCommunityCase input
+                = new Inet4SpecificExtendedCommunityCaseBuilder().setInet4SpecificExtendedCommunity(
+                new Inet4SpecificExtendedCommunityBuilder()
+                        .setGlobalAdministrator(new Ipv4Address("12.51.2.5"))
+                        .setLocalAdministrator(new byte[]{21, 45}).build()).build();
+
+        final Inet4SpecificExtendedCommunityCase expected
+                = new Inet4SpecificExtendedCommunityCaseBuilder().setInet4SpecificExtendedCommunity(
+                new Inet4SpecificExtendedCommunityBuilder()
+                        .setInet4SpecificExtendedCommunityCommon(new Inet4SpecificExtendedCommunityCommonBuilder()
+                                .setGlobalAdministrator(new Ipv4Address("12.51.2.5"))
+                                .setLocalAdministrator(new byte[]{21, 45}).build()).build())
+                .build();
+        final ExtendedCommunity exComm = handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT));
+        assertEquals(expected, exComm);
+
+        final ByteBuf output = Unpooled.buffer(INPUT.length);
+        handler.serializeExtendedCommunity(input, output);
+        assertArrayEquals(INPUT, output.array());
+    }
+
+    @Test
+    public void testHandle() {
         final Ipv4SpecificEcHandler handler = new Ipv4SpecificEcHandler();
-        final Inet4SpecificExtendedCommunityCase expected = new Inet4SpecificExtendedCommunityCaseBuilder().setInet4SpecificExtendedCommunity(
-                new Inet4SpecificExtendedCommunityBuilder().setGlobalAdministrator(new Ipv4Address("12.51.2.5")).setLocalAdministrator(
-                        new byte[] { 21, 45 }).build()).build();
+        final Inet4SpecificExtendedCommunityCase expected
+                = new Inet4SpecificExtendedCommunityCaseBuilder().setInet4SpecificExtendedCommunity(
+                new Inet4SpecificExtendedCommunityBuilder()
+                        .setInet4SpecificExtendedCommunityCommon(new Inet4SpecificExtendedCommunityCommonBuilder()
+                                .setGlobalAdministrator(new Ipv4Address("12.51.2.5"))
+                                .setLocalAdministrator(new byte[]{21, 45}).build()).build())
+                .build();
 
         final ExtendedCommunity exComm = handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT));
-        Assert.assertEquals(expected, exComm);
+        assertEquals(expected, exComm);
 
         final ByteBuf output = Unpooled.buffer(INPUT.length);
         handler.serializeExtendedCommunity(expected, output);
-        Assert.assertArrayEquals(INPUT, output.array());
+        assertArrayEquals(INPUT, output.array());
     }
 
 }
diff --git a/bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/SourceAS4OctectASHandlerTest.java b/bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/SourceAS4OctectASHandlerTest.java
new file mode 100644 (file)
index 0000000..597a5cf
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ *  Copyright (c) 2018 AT&T Intellectual Property. 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.assertEquals;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.junit.Assert;
+import org.junit.Test;
+import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.four.octect.as.specific.SourceAS4OctectHandler;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.ExtendedCommunity;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.As4GenericSpecExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.SourceAs4ExtendedCommunityCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.SourceAs4ExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.source.as._4.extended.community._case.SourceAs4ExtendedCommunityBuilder;
+
+public class SourceAS4OctectASHandlerTest {
+    private static final byte[] INPUT = {
+            0, 0, 0, 20, 0, 0
+    };
+    private final SourceAS4OctectHandler handler = new SourceAS4OctectHandler();
+
+
+    @Test
+    public void testHandler() {
+        final SourceAs4ExtendedCommunityCase expected = new SourceAs4ExtendedCommunityCaseBuilder()
+                .setSourceAs4ExtendedCommunity(new SourceAs4ExtendedCommunityBuilder()
+                        .setAsNumber(new AsNumber(20L)).build()).build();
+
+        final ExtendedCommunity exComm = this.handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT));
+        assertEquals(expected, exComm);
+
+        final ByteBuf output = Unpooled.buffer(INPUT.length);
+        this.handler.serializeExtendedCommunity(expected, output);
+        Assert.assertArrayEquals(INPUT, output.array());
+
+        assertEquals(209, this.handler.getSubType());
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testHandlerError() {
+        this.handler.serializeExtendedCommunity(new As4GenericSpecExtendedCommunityCaseBuilder().build(), null);
+    }
+}
diff --git a/bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/SourceASHandlerTest.java b/bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/SourceASHandlerTest.java
new file mode 100644 (file)
index 0000000..50f8a7a
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ *  Copyright (c) 2018 AT&T Intellectual Property. 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.assertEquals;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.junit.Assert;
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.ShortAsNumber;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.ExtendedCommunity;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.As4GenericSpecExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.SourceAsExtendedCommunityCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.SourceAsExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.source.as.extended.community._case.SourceAsExtendedCommunityBuilder;
+
+public class SourceASHandlerTest {
+    private static final byte[] INPUT = {
+            0, 1, 0, 0, 0, 0
+    };
+
+    private final SourceASHandler handler = new SourceASHandler();
+
+    @Test
+    public void testHandler() {
+        final SourceAsExtendedCommunityCase expected = new SourceAsExtendedCommunityCaseBuilder()
+                .setSourceAsExtendedCommunity(new SourceAsExtendedCommunityBuilder()
+                        .setGlobalAdministrator(new ShortAsNumber(1L))
+                        .build()).build();
+
+        final ExtendedCommunity exComm = handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT));
+        Assert.assertEquals(expected, exComm);
+
+        final ByteBuf output = Unpooled.buffer(INPUT.length);
+        handler.serializeExtendedCommunity(expected, output);
+        Assert.assertArrayEquals(INPUT, output.array());
+
+        assertEquals(9, this.handler.getSubType());
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testHandlerError() {
+        this.handler.serializeExtendedCommunity(new As4GenericSpecExtendedCommunityCaseBuilder().build(),
+                null);
+    }
+}
diff --git a/bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/VrfRouteImportHandlerTest.java b/bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/VrfRouteImportHandlerTest.java
new file mode 100644 (file)
index 0000000..9bbd7cb
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ *  Copyright (c) 2018 AT&T Intellectual Property. 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.assertEquals;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.junit.Assert;
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.ExtendedCommunity;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.As4GenericSpecExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.VrfRouteImportExtendedCommunityCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.VrfRouteImportExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.vrf.route._import.extended.community._case.VrfRouteImportExtendedCommunityBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.inet4.specific.extended.community.common.Inet4SpecificExtendedCommunityCommonBuilder;
+
+public class VrfRouteImportHandlerTest {
+
+    private static final byte[] INPUT = {
+            12, 51, 2, 5, 21, 45
+    };
+    private final VrfRouteImportHandler handler = new VrfRouteImportHandler();
+
+    @Test
+    public void testHandler() {
+        final VrfRouteImportExtendedCommunityCase expected = new VrfRouteImportExtendedCommunityCaseBuilder()
+                .setVrfRouteImportExtendedCommunity(new VrfRouteImportExtendedCommunityBuilder()
+                        .setInet4SpecificExtendedCommunityCommon(new Inet4SpecificExtendedCommunityCommonBuilder()
+                                .setGlobalAdministrator(new Ipv4Address("12.51.2.5"))
+                                .setLocalAdministrator(new byte[]{21, 45}).build())
+                        .build())
+                .build();
+
+        final ExtendedCommunity exComm = handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT));
+        Assert.assertEquals(expected, exComm);
+
+        final ByteBuf output = Unpooled.buffer(INPUT.length);
+        handler.serializeExtendedCommunity(expected, output);
+        Assert.assertArrayEquals(INPUT, output.array());
+
+        assertEquals(11, this.handler.getSubType());
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testHandlerError() {
+        this.handler.serializeExtendedCommunity(new As4GenericSpecExtendedCommunityCaseBuilder().build(), null);
+    }
+}
diff --git a/bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/extended/community/Inet4SpecificExtendedCommunityCommonUtil.java b/bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/extended/community/Inet4SpecificExtendedCommunityCommonUtil.java
new file mode 100644 (file)
index 0000000..c4c78f6
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ *  Copyright (c) 2018 AT&T Intellectual Property. 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.spi.extended.community;
+
+import static org.opendaylight.protocol.bgp.parser.spi.extended.community.AbstractIpv4ExtendedCommunity.INET_LOCAL_ADMIN_LENGTH;
+
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.ByteBufWriteUtil;
+import org.opendaylight.protocol.util.Ipv4Util;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.inet4.specific.extended.community.common.Inet4SpecificExtendedCommunityCommon;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.inet4.specific.extended.community.common.Inet4SpecificExtendedCommunityCommonBuilder;
+
+public final class Inet4SpecificExtendedCommunityCommonUtil {
+    private Inet4SpecificExtendedCommunityCommonUtil() {
+        throw new UnsupportedOperationException();
+    }
+
+
+    public static Inet4SpecificExtendedCommunityCommon parseCommon(final ByteBuf buffer) {
+        return new Inet4SpecificExtendedCommunityCommonBuilder()
+                .setGlobalAdministrator(Ipv4Util.addressForByteBuf(buffer))
+                .setLocalAdministrator(ByteArray.readBytes(buffer, INET_LOCAL_ADMIN_LENGTH))
+                .build();
+    }
+
+    public static void serializeCommon(
+            final Inet4SpecificExtendedCommunityCommon extComm,
+            final ByteBuf byteAggregator) {
+        ByteBufWriteUtil.writeIpv4Address(extComm.getGlobalAdministrator(), byteAggregator);
+        byteAggregator.writeBytes(extComm.getLocalAdministrator());
+    }
+
+}
diff --git a/bgp/parser-spi/src/test/java/org/opendaylight/protocol/bgp/parser/spi/extended/community/Inet4SpecificExtendedCommunityCommonUtilTest.java b/bgp/parser-spi/src/test/java/org/opendaylight/protocol/bgp/parser/spi/extended/community/Inet4SpecificExtendedCommunityCommonUtilTest.java
new file mode 100644 (file)
index 0000000..eb61ed8
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ *  Copyright (c) 2018 AT&T Intellectual Property. 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.spi.extended.community;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.junit.Assert;
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.inet4.specific.extended.community.common.Inet4SpecificExtendedCommunityCommon;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.inet4.specific.extended.community.common.Inet4SpecificExtendedCommunityCommonBuilder;
+
+public class Inet4SpecificExtendedCommunityCommonUtilTest {
+    private static final byte[] INPUT = {
+            12, 51, 2, 5, 21, 45
+    };
+
+    @Test
+    public void testHandle() {
+        final Inet4SpecificExtendedCommunityCommon expected
+                = new Inet4SpecificExtendedCommunityCommonBuilder()
+                .setGlobalAdministrator(new Ipv4Address("12.51.2.5"))
+                .setLocalAdministrator(new byte[]{21, 45}).build();
+
+        final Inet4SpecificExtendedCommunityCommon exComm = Inet4SpecificExtendedCommunityCommonUtil
+                .parseCommon(Unpooled.copiedBuffer(INPUT));
+        Assert.assertEquals(expected, exComm);
+
+        final ByteBuf output = Unpooled.buffer(INPUT.length);
+        Inet4SpecificExtendedCommunityCommonUtil.serializeCommon(expected, output);
+        Assert.assertArrayEquals(INPUT, output.array());
+    }
+
+}
\ No newline at end of file