f0672de0153bd448a7bcbcbf9fac11d8437feb70
[bgpcep.git] / bgp / 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.rev180329.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.rev180329.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.rev180329.mac.mobility.extended.community.MacMobilityExtendedCommunity;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.mac.mobility.extended.community.MacMobilityExtendedCommunityBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.ExtendedCommunity;
19
20 public final class MACMobExtCom extends AbstractExtendedCommunities {
21     private static final int SUBTYPE = 0;
22     private static final int RESERVED = 1;
23
24     @Override
25     public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer)
26             throws BGPDocumentedException, BGPParsingException {
27         final boolean isStatic = buffer.readBoolean();
28         buffer.skipBytes(RESERVED);
29         final long seqNumber = buffer.readUnsignedInt();
30         return new MacMobilityExtendedCommunityCaseBuilder()
31                 .setMacMobilityExtendedCommunity(new MacMobilityExtendedCommunityBuilder()
32             .setStatic(isStatic).setSeqNumber(seqNumber).build()).build();
33     }
34
35     @Override
36     public void serializeExtendedCommunity(final ExtendedCommunity extendedCommunity, final ByteBuf byteAggregator) {
37         Preconditions.checkArgument(extendedCommunity instanceof MacMobilityExtendedCommunityCase,
38             "The extended community %s is not MacMobilityExtendedCommunityCase type.", extendedCommunity);
39         final MacMobilityExtendedCommunity extCom = ((MacMobilityExtendedCommunityCase) extendedCommunity)
40                 .getMacMobilityExtendedCommunity();
41         byteAggregator.writeBoolean(extCom.isStatic());
42         byteAggregator.writeZero(RESERVED);
43         byteAggregator.writeInt(extCom.getSeqNumber().intValue());
44     }
45
46     @Override
47     public int getSubType() {
48         return SUBTYPE;
49     }
50 }