Bump versions to 0.21.7-SNAPSHOT
[bgpcep.git] / bgp / extensions / evpn / src / main / java / org / opendaylight / protocol / bgp / evpn / impl / extended / communities / MACMobExtCom.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.bgp.evpn.impl.extended.communities;
9
10 import com.google.common.base.Preconditions;
11 import io.netty.buffer.ByteBuf;
12 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
13 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.MacMobilityExtendedCommunityCase;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.MacMobilityExtendedCommunityCaseBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.mac.mobility.extended.community.MacMobilityExtendedCommunity;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.mac.mobility.extended.community.MacMobilityExtendedCommunityBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.extended.community.ExtendedCommunity;
19 import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
20
21 public final class MACMobExtCom extends AbstractExtendedCommunities {
22     private static final int SUBTYPE = 0;
23     private static final int RESERVED = 1;
24
25     @Override
26     public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer)
27             throws BGPDocumentedException, BGPParsingException {
28         final boolean isStatic = buffer.readBoolean();
29         buffer.skipBytes(RESERVED);
30         return new MacMobilityExtendedCommunityCaseBuilder()
31                 .setMacMobilityExtendedCommunity(new MacMobilityExtendedCommunityBuilder()
32                     .setStatic(isStatic)
33                     .setSeqNumber(ByteBufUtils.readUint32(buffer))
34                     .build())
35                 .build();
36     }
37
38     @Override
39     public void serializeExtendedCommunity(final ExtendedCommunity extendedCommunity, final ByteBuf byteAggregator) {
40         Preconditions.checkArgument(extendedCommunity instanceof MacMobilityExtendedCommunityCase,
41             "The extended community %s is not MacMobilityExtendedCommunityCase type.", extendedCommunity);
42         final MacMobilityExtendedCommunity extCom = ((MacMobilityExtendedCommunityCase) extendedCommunity)
43                 .getMacMobilityExtendedCommunity();
44         byteAggregator.writeBoolean(extCom.getStatic());
45         byteAggregator.writeZero(RESERVED);
46         byteAggregator.writeInt(extCom.getSeqNumber().intValue());
47     }
48
49     @Override
50     public int getSubType() {
51         return SUBTYPE;
52     }
53 }