BUG-4826: Evpn Extended communities handlers 91/37591/4
authorClaudio D. Gasparini <cgaspari@cisco.com>
Tue, 5 Apr 2016 09:22:59 +0000 (11:22 +0200)
committerClaudio D. Gasparini <cgaspari@cisco.com>
Mon, 18 Apr 2016 10:45:57 +0000 (10:45 +0000)
Evpn Extended communities handlers
https://tools.ietf.org/html/rfc7432#section-7.5

Change-Id: I20328e15b60a885b64a9ffbf4ac34eb6fe7a23f8
Signed-off-by: Claudio D. Gasparini <cgaspari@cisco.com>
bgp/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/BGPActivator.java
bgp/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/extended/communities/AbstractExtendedCommunities.java [new file with mode: 0644]
bgp/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/extended/communities/DefaultGatewayExtCom.java [new file with mode: 0644]
bgp/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/extended/communities/ESILabelExtCom.java [new file with mode: 0644]
bgp/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/extended/communities/ESImpRouteTargetExtCom.java [new file with mode: 0644]
bgp/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/extended/communities/MACMobExtCom.java [new file with mode: 0644]

index 3346f472b5a6235f49df3686462931ddf714b77f..6ec8eaefc5f7ae1eed5a7e4e81f8eec01373ce31 100644 (file)
@@ -10,15 +10,43 @@ package org.opendaylight.protocol.bgp.evpn;
 import java.util.ArrayList;
 import java.util.List;
 import org.opendaylight.protocol.bgp.evpn.impl.esi.types.ESIActivator;
+import org.opendaylight.protocol.bgp.evpn.impl.extended.communities.DefaultGatewayExtCom;
+import org.opendaylight.protocol.bgp.evpn.impl.extended.communities.ESILabelExtCom;
+import org.opendaylight.protocol.bgp.evpn.impl.extended.communities.ESImpRouteTargetExtCom;
+import org.opendaylight.protocol.bgp.evpn.impl.extended.communities.MACMobExtCom;
 import org.opendaylight.protocol.bgp.parser.spi.AbstractBGPExtensionProviderActivator;
 import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.DefaultGatewayExtendedCommunityCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.update.attributes.extended.communities.extended.community.EsImportRouteExtendedCommunityCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.update.attributes.extended.communities.extended.community.EsiLabelExtendedCommunityCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.update.attributes.extended.communities.extended.community.MacMobilityExtendedCommunityCase;
 
-public final class BGPActivator extends AbstractBGPExtensionProviderActivator {
+
+public class BGPActivator extends AbstractBGPExtensionProviderActivator {
     @Override
     protected List<AutoCloseable> startImpl(final BGPExtensionProviderContext context) {
         final List<AutoCloseable> regs = new ArrayList<>();
 
+        registerExtendedCommunities(context, regs);
         ESIActivator.registerEsiTypeParsers(regs);
         return regs;
     }
-}
+
+    private void registerExtendedCommunities(final BGPExtensionProviderContext context, final List<AutoCloseable> regs) {
+        final DefaultGatewayExtCom defGEC = new DefaultGatewayExtCom();
+        regs.add(context.registerExtendedCommunityParser(defGEC.getType(true), defGEC.getSubType(), defGEC));
+        regs.add(context.registerExtendedCommunitySerializer(DefaultGatewayExtendedCommunityCase.class, defGEC));
+
+        final ESILabelExtCom esiLEC = new ESILabelExtCom();
+        regs.add(context.registerExtendedCommunityParser(esiLEC.getType(true), esiLEC.getSubType(), esiLEC));
+        regs.add(context.registerExtendedCommunitySerializer(EsiLabelExtendedCommunityCase.class, esiLEC));
+
+        final ESImpRouteTargetExtCom esImpEC = new ESImpRouteTargetExtCom();
+        regs.add(context.registerExtendedCommunityParser(esImpEC.getType(true), esImpEC.getSubType(), esImpEC));
+        regs.add(context.registerExtendedCommunitySerializer(EsImportRouteExtendedCommunityCase.class, esImpEC));
+
+        final MACMobExtCom macEC = new MACMobExtCom();
+        regs.add(context.registerExtendedCommunityParser(macEC.getType(true), macEC.getSubType(), macEC));
+        regs.add(context.registerExtendedCommunitySerializer(MacMobilityExtendedCommunityCase.class, macEC));
+    }
+}
\ No newline at end of file
diff --git a/bgp/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/extended/communities/AbstractExtendedCommunities.java b/bgp/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/extended/communities/AbstractExtendedCommunities.java
new file mode 100644 (file)
index 0000000..33308c5
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * 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.evpn.impl.extended.communities;
+
+import org.opendaylight.protocol.bgp.parser.spi.extended.community.ExtendedCommunityParser;
+import org.opendaylight.protocol.bgp.parser.spi.extended.community.ExtendedCommunitySerializer;
+import org.opendaylight.protocol.bgp.parser.spi.extended.community.ExtendedCommunityUtil;
+
+abstract class AbstractExtendedCommunities implements ExtendedCommunityParser, ExtendedCommunitySerializer {
+    private static final int TYPE = 6;
+
+    @Override
+    public final int getType(final boolean isTransitive) {
+        return ExtendedCommunityUtil.setTransitivity(TYPE, isTransitive);
+    }
+}
diff --git a/bgp/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/extended/communities/DefaultGatewayExtCom.java b/bgp/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/extended/communities/DefaultGatewayExtCom.java
new file mode 100644 (file)
index 0000000..354c826
--- /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.evpn.impl.extended.communities;
+
+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.evpn.rev160321._default.gateway.extended.community.DefaultGatewayExtendedCommunityBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.DefaultGatewayExtendedCommunityCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.DefaultGatewayExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.ExtendedCommunity;
+
+public final class DefaultGatewayExtCom extends AbstractOpaqueExtendedCommunity {
+    private static final int SUBTYPE = 13;
+    private static final int RESERVED = 6;
+
+    @Override
+    public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer) throws BGPDocumentedException, BGPParsingException {
+        Preconditions.checkArgument(buffer.readableBytes() == RESERVED, "Wrong length of array of bytes. Passed: %s .", buffer.readableBytes());
+        buffer.skipBytes(RESERVED);
+        return new DefaultGatewayExtendedCommunityCaseBuilder().setDefaultGatewayExtendedCommunity(
+            new DefaultGatewayExtendedCommunityBuilder().build()).build();
+    }
+
+    @Override
+    public void serializeExtendedCommunity(final ExtendedCommunity extendedCommunity, final ByteBuf byteAggregator) {
+        Preconditions.checkArgument(extendedCommunity instanceof DefaultGatewayExtendedCommunityCase,
+            "The extended community %s is not DefaultGatewayExtendedCommunityCase type.", extendedCommunity);
+        byteAggregator.writeZero(RESERVED);
+    }
+
+    @Override
+    public int getSubType() {
+        return SUBTYPE;
+    }
+}
diff --git a/bgp/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/extended/communities/ESILabelExtCom.java b/bgp/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/extended/communities/ESILabelExtCom.java
new file mode 100644 (file)
index 0000000..1559d82
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * 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.evpn.impl.extended.communities;
+
+import static org.opendaylight.protocol.util.MplsLabelUtil.byteBufForMplsLabel;
+import static org.opendaylight.protocol.util.MplsLabelUtil.mplsLabelForByteBuf;
+
+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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.esi.label.extended.community.EsiLabelExtendedCommunity;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.esi.label.extended.community.EsiLabelExtendedCommunityBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.EsiLabelExtendedCommunityCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.EsiLabelExtendedCommunityCaseBuilder;
+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.network.concepts.rev131125.MplsLabel;
+
+public final class ESILabelExtCom extends AbstractExtendedCommunities {
+    private static final int SUBTYPE = 1;
+    private static final int RESERVED = 2;
+
+    @Override
+    public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer) throws BGPDocumentedException, BGPParsingException {
+        final boolean singleActive = buffer.readBoolean();
+        buffer.skipBytes(RESERVED);
+        final MplsLabel label = mplsLabelForByteBuf(buffer);
+        return new EsiLabelExtendedCommunityCaseBuilder().setEsiLabelExtendedCommunity(
+            new EsiLabelExtendedCommunityBuilder().setEsiLabel(label).setSingleActiveMode(singleActive).build()).build();
+    }
+
+    @Override
+    public void serializeExtendedCommunity(final ExtendedCommunity extendedCommunity, final ByteBuf byteAggregator) {
+        Preconditions.checkArgument(extendedCommunity instanceof EsiLabelExtendedCommunityCase,
+            "The extended community %s is not EsiLabelExtendedCommunityCaseCase type.", extendedCommunity);
+        final EsiLabelExtendedCommunity extCom = ((EsiLabelExtendedCommunityCase) extendedCommunity).getEsiLabelExtendedCommunity();
+        byteAggregator.writeBoolean(extCom.isSingleActiveMode());
+        byteAggregator.writeZero(RESERVED);
+        byteAggregator.writeBytes(byteBufForMplsLabel(extCom.getEsiLabel()));
+    }
+
+    @Override
+    public int getSubType() {
+        return SUBTYPE;
+    }
+}
diff --git a/bgp/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/extended/communities/ESImpRouteTargetExtCom.java b/bgp/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/extended/communities/ESImpRouteTargetExtCom.java
new file mode 100644 (file)
index 0000000..1faaaec
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * 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.evpn.impl.extended.communities;
+
+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.util.ByteArray;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.IetfYangUtil;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.es._import.route.extended.community.EsImportRouteExtendedCommunity;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.es._import.route.extended.community.EsImportRouteExtendedCommunityBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.EsImportRouteExtendedCommunityCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.EsImportRouteExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.ExtendedCommunity;
+
+public final class ESImpRouteTargetExtCom extends AbstractExtendedCommunities {
+    private static final int SUBTYPE = 2;
+    private static final int MAC_ADDRESS_LENGTH = 6;
+
+    @Override
+    public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer) throws BGPDocumentedException, BGPParsingException {
+        final MacAddress mac = IetfYangUtil.INSTANCE.macAddressFor(ByteArray.readBytes(buffer, MAC_ADDRESS_LENGTH));
+
+        return new EsImportRouteExtendedCommunityCaseBuilder().setEsImportRouteExtendedCommunity(
+            new EsImportRouteExtendedCommunityBuilder().setEsImport(mac).build()).build();
+    }
+
+    @Override
+    public void serializeExtendedCommunity(final ExtendedCommunity extendedCommunity, final ByteBuf byteAggregator) {
+        Preconditions.checkArgument(extendedCommunity instanceof EsImportRouteExtendedCommunityCase,
+            "The extended community %s is not EsImportRouteExtendedCommunityCaseCase type.", extendedCommunity);
+        final EsImportRouteExtendedCommunity extCom = ((EsImportRouteExtendedCommunityCase) extendedCommunity).getEsImportRouteExtendedCommunity();
+        byteAggregator.writeBytes(IetfYangUtil.INSTANCE.bytesFor(extCom.getEsImport()));
+    }
+
+    @Override
+    public int getSubType() {
+        return SUBTYPE;
+    }
+}
diff --git a/bgp/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/extended/communities/MACMobExtCom.java b/bgp/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/extended/communities/MACMobExtCom.java
new file mode 100644 (file)
index 0000000..12aed9d
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * 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.evpn.impl.extended.communities;
+
+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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.MacMobilityExtendedCommunityCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.MacMobilityExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.mac.mobility.extended.community.MacMobilityExtendedCommunity;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.mac.mobility.extended.community.MacMobilityExtendedCommunityBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.ExtendedCommunity;
+
+public final class MACMobExtCom extends AbstractExtendedCommunities {
+    private static final int SUBTYPE = 0;
+    private static final int RESERVED = 1;
+
+    @Override
+    public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer) throws BGPDocumentedException, BGPParsingException {
+        final boolean isStatic = buffer.readBoolean();
+        buffer.skipBytes(RESERVED);
+        final long seqNumber = buffer.readUnsignedInt();
+        return new MacMobilityExtendedCommunityCaseBuilder().setMacMobilityExtendedCommunity(new MacMobilityExtendedCommunityBuilder()
+            .setStatic(isStatic).setSeqNumber(seqNumber).build()).build();
+    }
+
+    @Override
+    public void serializeExtendedCommunity(final ExtendedCommunity extendedCommunity, final ByteBuf byteAggregator) {
+        Preconditions.checkArgument(extendedCommunity instanceof MacMobilityExtendedCommunityCase,
+            "The extended community %s is not MacMobilityExtendedCommunityCase type.", extendedCommunity);
+        final MacMobilityExtendedCommunity extCom = ((MacMobilityExtendedCommunityCase) extendedCommunity).getMacMobilityExtendedCommunity();
+        byteAggregator.writeBoolean(extCom.isStatic());
+        byteAggregator.writeZero(RESERVED);
+        byteAggregator.writeInt(extCom.getSeqNumber().intValue());
+    }
+
+    @Override
+    public int getSubType() {
+        return SUBTYPE;
+    }
+}