BUG-5767: 4-Octet AS Specific BGP Extended Community 38/38138/3
authorClaudio D. Gasparini <cgaspari@cisco.com>
Fri, 22 Apr 2016 13:25:55 +0000 (15:25 +0200)
committerMilos Fabian <milfabia@cisco.com>
Fri, 29 Apr 2016 16:57:22 +0000 (16:57 +0000)
new  4-Octet AS Specific BGP Extended Community
ref.:https://tools.ietf.org/html/rfc5668

Change-Id: Icd317952ba43813085d4fd1cec3fc726809bd13f
Signed-off-by: Claudio D. Gasparini <cgaspari@cisco.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/four/octect/as/specific/Generic4OctASEcHandler.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/RouteOrigin4OctectASEcHandler.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/RouteTarget4OctectASEcHandler.java [new file with mode: 0644]
bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/four/octect/as/specific/Generic4OctASEcHandlerTest.java [new file with mode: 0644]
bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/four/octect/as/specific/RouteOrigin4OctectASEcHandlerTest.java [new file with mode: 0644]
bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/four/octect/as/specific/RouteTarget4OctectASEcHandlerTest.java [new file with mode: 0644]
bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/extended/community/Abstract4OctetAsExtendedCommunity.java [new file with mode: 0644]
bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/extended/community/FourOctAsCommonECUtil.java [new file with mode: 0644]

index bda50355055e1467cd68ef121835ca0ba2c370e3..782f27db0992945d80fb064ada22e6e26ff41b27 100644 (file)
@@ -164,6 +164,22 @@ module bgp-types {
         }
     }
 
+    grouping as-4-generic-spec-common-ec {
+        container as-4-generic-spec-extended-community {
+            leaf as-number {
+                description "Carries a 4-octet Autonomous System (AS) number";
+                reference "https://tools.ietf.org/html/rfc5668#section-2";
+
+                mandatory true;
+                type inet:as-number;
+            }
+
+            leaf local-administrator {
+                type uint16;
+            }
+        }
+    }
+
     grouping extended-community {
         leaf transitive {
             type boolean;
@@ -243,6 +259,24 @@ module bgp-types {
                     uses link-bandwidth-extended-community;
                 }
             }
+            case as-4-generic-spec-extended-community-case {
+                container as-4-generic-spec-extended-community {
+                    reference "https://www.ietf.org/archive/id/draft-ietf-idr-as4octet-extcomm-generic-subtype-08.txt";
+                    uses as-4-generic-spec-common-ec;
+                }
+            }
+            case as-4-route-target-extended-community-case {
+                container as-4-route-target-extended-community {
+                    reference "https://tools.ietf.org/html/rfc5668";
+                    uses as-4-generic-spec-common-ec;
+                }
+            }
+            case as-4-route-origin-extended-community-case {
+                container as-4-route-origin-extended-community {
+                    reference "https://tools.ietf.org/html/rfc5668";
+                    uses as-4-generic-spec-common-ec;
+                }
+            }
         }
     }
 
index 2066ab07ddf37dd0f53011ec1144dbde2f5ff6fd..491cb461c72ec11f0aa3add5bee31724c5cd8f9a 100644 (file)
@@ -50,6 +50,9 @@ 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.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.next.hop.Ipv4NextHopParserSerializer;
 import org.opendaylight.protocol.bgp.parser.impl.message.update.next.hop.Ipv6NextHopParserSerializer;
 import org.opendaylight.protocol.bgp.parser.spi.AbstractBGPExtensionProviderActivator;
@@ -90,6 +93,9 @@ 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.MplsLabeledVpnSubsequentAddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.NextHop;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.As4GenericSpecExtendedCommunityCase;
+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.Inet4SpecificExtendedCommunityCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.LinkBandwidthCase;
@@ -315,5 +321,18 @@ public final class BGPActivator extends AbstractBGPExtensionProviderActivator {
         regs.add(context.registerExtendedCommunityParser(linkBandwidthECHandler.getType(false), linkBandwidthECHandler.getSubType(),
             linkBandwidthECHandler));
         regs.add(context.registerExtendedCommunitySerializer(LinkBandwidthCase.class, linkBandwidthECHandler));
+
+        final Generic4OctASEcHandler gen4OctASEcHandler = new Generic4OctASEcHandler();
+        regs.add(context.registerExtendedCommunityParser(gen4OctASEcHandler.getType(true), gen4OctASEcHandler.getSubType(), gen4OctASEcHandler));
+        regs.add(context.registerExtendedCommunityParser(gen4OctASEcHandler.getType(false), gen4OctASEcHandler.getSubType(), gen4OctASEcHandler));
+        regs.add(context.registerExtendedCommunitySerializer(As4GenericSpecExtendedCommunityCase.class, gen4OctASEcHandler));
+
+        final RouteTarget4OctectASEcHandler rt4ASHandler = new RouteTarget4OctectASEcHandler();
+        regs.add(context.registerExtendedCommunityParser(rt4ASHandler.getType(true), rt4ASHandler.getSubType(), rt4ASHandler));
+        regs.add(context.registerExtendedCommunitySerializer(As4RouteTargetExtendedCommunityCase.class, rt4ASHandler));
+
+        final RouteOrigin4OctectASEcHandler rOrig4Oct = new RouteOrigin4OctectASEcHandler();
+        regs.add(context.registerExtendedCommunityParser(rOrig4Oct.getType(true), rOrig4Oct.getSubType(), rOrig4Oct));
+        regs.add(context.registerExtendedCommunitySerializer(As4RouteOriginExtendedCommunityCase.class, rOrig4Oct));
     }
 }
diff --git a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/four/octect/as/specific/Generic4OctASEcHandler.java b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/four/octect/as/specific/Generic4OctASEcHandler.java
new file mode 100644 (file)
index 0000000..84308f1
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2016 Cisco 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.four.octect.as.specific;
+
+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.Abstract4OctetAsExtendedCommunity;
+import org.opendaylight.protocol.bgp.parser.spi.extended.community.FourOctAsCommonECUtil;
+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.As4GenericSpecExtendedCommunityCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.As4GenericSpecExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.as._4.generic.spec.extended.community._case.As4GenericSpecExtendedCommunityBuilder;
+
+public final class Generic4OctASEcHandler extends Abstract4OctetAsExtendedCommunity {
+    private static final int SUBTYPE = 4;
+
+    @Override
+    public ExtendedCommunity parseExtendedCommunity(final ByteBuf body) throws BGPDocumentedException, BGPParsingException {
+        return new As4GenericSpecExtendedCommunityCaseBuilder().setAs4GenericSpecExtendedCommunity(new As4GenericSpecExtendedCommunityBuilder()
+            .setAs4GenericSpecExtendedCommunity(FourOctAsCommonECUtil.parseCommon(body)).build()).build();
+    }
+
+    @Override
+    public void serializeExtendedCommunity(final ExtendedCommunity extendedCommunity, final ByteBuf body) {
+        Preconditions.checkArgument(extendedCommunity instanceof As4GenericSpecExtendedCommunityCase,
+            "The extended community %s is not As4GenericSpecExtendedCommunityCase type.", extendedCommunity);
+        FourOctAsCommonECUtil.serializeCommon(((As4GenericSpecExtendedCommunityCase) extendedCommunity).getAs4GenericSpecExtendedCommunity()
+            .getAs4GenericSpecExtendedCommunity(), 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/four/octect/as/specific/RouteOrigin4OctectASEcHandler.java b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/four/octect/as/specific/RouteOrigin4OctectASEcHandler.java
new file mode 100644 (file)
index 0000000..bb5419b
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2016 Cisco 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.four.octect.as.specific;
+
+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.Abstract4OctetAsExtendedCommunity;
+import org.opendaylight.protocol.bgp.parser.spi.extended.community.FourOctAsCommonECUtil;
+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.As4RouteOriginExtendedCommunityCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.As4RouteOriginExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.as._4.route.origin.extended.community._case.As4RouteOriginExtendedCommunityBuilder;
+
+public final class RouteOrigin4OctectASEcHandler extends Abstract4OctetAsExtendedCommunity {
+    private static final int SUBTYPE = 3;
+
+    @Override
+    public ExtendedCommunity parseExtendedCommunity(final ByteBuf body) throws BGPDocumentedException, BGPParsingException {
+        return new As4RouteOriginExtendedCommunityCaseBuilder().setAs4RouteOriginExtendedCommunity(new As4RouteOriginExtendedCommunityBuilder()
+            .setAs4GenericSpecExtendedCommunity(FourOctAsCommonECUtil.parseCommon(body)).build()).build();
+    }
+
+    @Override
+    public void serializeExtendedCommunity(final ExtendedCommunity extendedCommunity, final ByteBuf body) {
+        Preconditions.checkArgument(extendedCommunity instanceof As4RouteOriginExtendedCommunityCase,
+            "The extended community %s is not As4RouteOriginExtendedCommunityCase type.", extendedCommunity);
+        FourOctAsCommonECUtil.serializeCommon(((As4RouteOriginExtendedCommunityCase) extendedCommunity)
+            .getAs4RouteOriginExtendedCommunity().getAs4GenericSpecExtendedCommunity(), 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/four/octect/as/specific/RouteTarget4OctectASEcHandler.java b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/four/octect/as/specific/RouteTarget4OctectASEcHandler.java
new file mode 100644 (file)
index 0000000..b14ba04
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2016 Cisco 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.four.octect.as.specific;
+
+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.Abstract4OctetAsExtendedCommunity;
+import org.opendaylight.protocol.bgp.parser.spi.extended.community.FourOctAsCommonECUtil;
+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.As4RouteTargetExtendedCommunityCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.As4RouteTargetExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.as._4.route.target.extended.community._case.As4RouteTargetExtendedCommunityBuilder;
+
+public final class RouteTarget4OctectASEcHandler extends Abstract4OctetAsExtendedCommunity {
+    private static final int SUBTYPE = 2;
+
+    @Override
+    public ExtendedCommunity parseExtendedCommunity(final ByteBuf body) throws BGPDocumentedException, BGPParsingException {
+        return new As4RouteTargetExtendedCommunityCaseBuilder().setAs4RouteTargetExtendedCommunity(new As4RouteTargetExtendedCommunityBuilder()
+            .setAs4GenericSpecExtendedCommunity(FourOctAsCommonECUtil.parseCommon(body)).build()).build();
+    }
+
+    @Override
+    public void serializeExtendedCommunity(final ExtendedCommunity extendedCommunity, final ByteBuf body) {
+        Preconditions.checkArgument(extendedCommunity instanceof As4RouteTargetExtendedCommunityCase,
+            "The extended community %s is not As4RouteTargetExtendedCommunityCase type.", extendedCommunity);
+        FourOctAsCommonECUtil.serializeCommon(((As4RouteTargetExtendedCommunityCase) extendedCommunity).getAs4RouteTargetExtendedCommunity()
+            .getAs4GenericSpecExtendedCommunity(), body);
+    }
+
+    @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/four/octect/as/specific/Generic4OctASEcHandlerTest.java b/bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/four/octect/as/specific/Generic4OctASEcHandlerTest.java
new file mode 100644 (file)
index 0000000..0b413d5
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2016 Cisco 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.four.octect.as.specific;
+
+import static org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.four.octect.as.specific.RouteOrigin4OctectASEcHandlerTest.AS_COMMON;
+import static org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.four.octect.as.specific.RouteOrigin4OctectASEcHandlerTest.INPUT;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.junit.Assert;
+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.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.As4GenericSpecExtendedCommunityCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.As4GenericSpecExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.As4RouteOriginExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.as._4.generic.spec.extended.community._case.As4GenericSpecExtendedCommunityBuilder;
+
+public final class Generic4OctASEcHandlerTest {
+    Generic4OctASEcHandler handler;
+
+    @Before
+    public void Setup() {
+        this.handler = new Generic4OctASEcHandler();
+    }
+
+    @Test
+    public void testHandler() throws BGPDocumentedException, BGPParsingException {
+        final As4GenericSpecExtendedCommunityCase expected = new As4GenericSpecExtendedCommunityCaseBuilder()
+            .setAs4GenericSpecExtendedCommunity(new As4GenericSpecExtendedCommunityBuilder()
+                .setAs4GenericSpecExtendedCommunity(AS_COMMON).build()).build();
+
+        final ExtendedCommunity exComm = this.handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT));
+        Assert.assertEquals(expected, exComm);
+
+        final ByteBuf output = Unpooled.buffer(INPUT.length);
+        this.handler.serializeExtendedCommunity(expected, output);
+        Assert.assertArrayEquals(INPUT, output.array());
+    }
+
+    @Test(expected=IllegalArgumentException.class)
+    public void testHandlerError() throws BGPDocumentedException, BGPParsingException {
+        this.handler.serializeExtendedCommunity(new As4RouteOriginExtendedCommunityCaseBuilder().build(), null);
+    }
+}
\ No newline at end of file
diff --git a/bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/four/octect/as/specific/RouteOrigin4OctectASEcHandlerTest.java b/bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/four/octect/as/specific/RouteOrigin4OctectASEcHandlerTest.java
new file mode 100644 (file)
index 0000000..c4f4d7e
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2016 Cisco 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.four.octect.as.specific;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.junit.Assert;
+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.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.as._4.generic.spec.common.ec.As4GenericSpecExtendedCommunity;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as._4.generic.spec.common.ec.As4GenericSpecExtendedCommunityBuilder;
+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.As4GenericSpecExtendedCommunityCaseBuilder;
+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.As4RouteOriginExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.as._4.route.origin.extended.community._case.As4RouteOriginExtendedCommunityBuilder;
+
+public final class RouteOrigin4OctectASEcHandlerTest {
+
+    static final byte[] INPUT = {
+        0, 0, 0, 20, 0, 100
+    };
+    static final As4GenericSpecExtendedCommunity AS_COMMON = new As4GenericSpecExtendedCommunityBuilder().setAsNumber(new AsNumber(20L))
+        .setLocalAdministrator(100).build();
+    RouteOrigin4OctectASEcHandler handler;
+
+    @Before
+    public void Setup() {
+        this.handler = new RouteOrigin4OctectASEcHandler();
+    }
+
+    @Test
+    public void testHandler() throws BGPDocumentedException, BGPParsingException {
+
+        final As4RouteOriginExtendedCommunityCase expected = new As4RouteOriginExtendedCommunityCaseBuilder()
+            .setAs4RouteOriginExtendedCommunity(new As4RouteOriginExtendedCommunityBuilder()
+                .setAs4GenericSpecExtendedCommunity(AS_COMMON).build()).build();
+
+        final ExtendedCommunity exComm = this.handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT));
+        Assert.assertEquals(expected, exComm);
+
+        final ByteBuf output = Unpooled.buffer(INPUT.length);
+        this.handler.serializeExtendedCommunity(expected, output);
+        Assert.assertArrayEquals(INPUT, output.array());
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testHandlerError() throws BGPDocumentedException, BGPParsingException {
+        this.handler.serializeExtendedCommunity(new As4GenericSpecExtendedCommunityCaseBuilder().build(), null);
+    }
+}
\ No newline at end of file
diff --git a/bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/four/octect/as/specific/RouteTarget4OctectASEcHandlerTest.java b/bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/four/octect/as/specific/RouteTarget4OctectASEcHandlerTest.java
new file mode 100644 (file)
index 0000000..623edfb
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2016 Cisco 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.four.octect.as.specific;
+
+import static org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.four.octect.as.specific.RouteOrigin4OctectASEcHandlerTest.AS_COMMON;
+import static org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.four.octect.as.specific.RouteOrigin4OctectASEcHandlerTest.INPUT;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.junit.Assert;
+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.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.As4RouteOriginExtendedCommunityCaseBuilder;
+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.As4RouteTargetExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.as._4.route.target.extended.community._case.As4RouteTargetExtendedCommunityBuilder;
+
+public class RouteTarget4OctectASEcHandlerTest {
+    RouteTarget4OctectASEcHandler handler;
+
+    @Before
+    public void Setup() {
+        this.handler = new RouteTarget4OctectASEcHandler();
+    }
+
+    @Test
+    public void testHandler() throws BGPDocumentedException, BGPParsingException {
+        final As4RouteTargetExtendedCommunityCase expected = new As4RouteTargetExtendedCommunityCaseBuilder()
+            .setAs4RouteTargetExtendedCommunity(new As4RouteTargetExtendedCommunityBuilder()
+                .setAs4GenericSpecExtendedCommunity(AS_COMMON).build()).build();
+
+        final ExtendedCommunity exComm = this.handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT));
+        Assert.assertEquals(expected, exComm);
+
+        final ByteBuf output = Unpooled.buffer(INPUT.length);
+        this.handler.serializeExtendedCommunity(expected, output);
+        Assert.assertArrayEquals(INPUT, output.array());
+    }
+
+    @Test(expected=IllegalArgumentException.class)
+    public void testHandlerError() throws BGPDocumentedException, BGPParsingException {
+        this.handler.serializeExtendedCommunity(new As4RouteOriginExtendedCommunityCaseBuilder().build(), null);
+    }
+}
\ No newline at end of file
diff --git a/bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/extended/community/Abstract4OctetAsExtendedCommunity.java b/bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/extended/community/Abstract4OctetAsExtendedCommunity.java
new file mode 100644 (file)
index 0000000..28ee18e
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2016 Cisco 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.spi.extended.community;
+
+public abstract class Abstract4OctetAsExtendedCommunity implements ExtendedCommunityParser, ExtendedCommunitySerializer {
+
+    private static final int TRANSITIVE_TYPE = 2;
+    private static final int NON_TRANSITIVE_TYPE = 66;
+
+    @Override
+    public int getType(final boolean isTransitive) {
+        if (isTransitive) {
+            return TRANSITIVE_TYPE;
+        }
+        return NON_TRANSITIVE_TYPE;
+    }
+}
diff --git a/bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/extended/community/FourOctAsCommonECUtil.java b/bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/extended/community/FourOctAsCommonECUtil.java
new file mode 100644 (file)
index 0000000..a488dc2
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2016 Cisco 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.spi.extended.community;
+
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.protocol.util.ByteBufWriteUtil;
+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.as._4.generic.spec.common.ec.As4GenericSpecExtendedCommunity;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as._4.generic.spec.common.ec.As4GenericSpecExtendedCommunityBuilder;
+
+public final class FourOctAsCommonECUtil {
+    private FourOctAsCommonECUtil() {
+        throw new UnsupportedOperationException();
+    }
+
+    public static As4GenericSpecExtendedCommunity parseCommon(final ByteBuf body) {
+        return new As4GenericSpecExtendedCommunityBuilder().setAsNumber(new AsNumber(body.readUnsignedInt()))
+            .setLocalAdministrator(body.readUnsignedShort()).build();
+    }
+
+    public static void serializeCommon(final As4GenericSpecExtendedCommunity extComm, final ByteBuf body) {
+        body.writeInt(extComm.getAsNumber().getValue().intValue());
+        ByteBufWriteUtil.writeUnsignedShort(extComm.getLocalAdministrator(), body);
+    }
+}