2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.protocol.bgp.evpn.impl.extended.communities;
10 import static org.opendaylight.protocol.util.MplsLabelUtil.byteBufForMplsLabel;
11 import static org.opendaylight.protocol.util.MplsLabelUtil.mplsLabelForByteBuf;
13 import com.google.common.base.Preconditions;
14 import io.netty.buffer.ByteBuf;
15 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
16 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.esi.label.extended.community.EsiLabelExtendedCommunity;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.esi.label.extended.community.EsiLabelExtendedCommunityBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.EsiLabelExtendedCommunityCase;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.EsiLabelExtendedCommunityCaseBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.ExtendedCommunity;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.MplsLabel;
24 public final class ESILabelExtCom extends AbstractExtendedCommunities {
25 private static final int SUBTYPE = 1;
26 private static final int RESERVED = 2;
29 public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer)
30 throws BGPDocumentedException, BGPParsingException {
31 final boolean singleActive = buffer.readBoolean();
32 buffer.skipBytes(RESERVED);
33 final MplsLabel label = mplsLabelForByteBuf(buffer);
34 return new EsiLabelExtendedCommunityCaseBuilder().setEsiLabelExtendedCommunity(
35 new EsiLabelExtendedCommunityBuilder().setEsiLabel(label)
36 .setSingleActiveMode(singleActive).build()).build();
40 public void serializeExtendedCommunity(final ExtendedCommunity extendedCommunity, final ByteBuf byteAggregator) {
41 Preconditions.checkArgument(extendedCommunity instanceof EsiLabelExtendedCommunityCase,
42 "The extended community %s is not EsiLabelExtendedCommunityCaseCase type.", extendedCommunity);
43 final EsiLabelExtendedCommunity extCom = ((EsiLabelExtendedCommunityCase) extendedCommunity)
44 .getEsiLabelExtendedCommunity();
45 byteAggregator.writeBoolean(extCom.isSingleActiveMode());
46 byteAggregator.writeZero(RESERVED);
47 byteAggregator.writeBytes(byteBufForMplsLabel(extCom.getEsiLabel()));
51 public int getSubType() {