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
--- /dev/null
+/*
+ * 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);
+ }
+}
--- /dev/null
+/*
+ * 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;
+ }
+}
--- /dev/null
+/*
+ * 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;
+ }
+}
--- /dev/null
+/*
+ * 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;
+ }
+}
--- /dev/null
+/*
+ * 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;
+ }
+}