Bump versions to 0.21.6-SNAPSHOT
[bgpcep.git] / bgp / extensions / evpn / src / main / java / org / opendaylight / protocol / bgp / evpn / impl / extended / communities / ESImpRouteTargetExtCom.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.util.ByteArray;
13 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.IetfYangUtil;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.es._import.route.extended.community.EsImportRouteExtendedCommunityBuilder;
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.EsImportRouteExtendedCommunityCase;
16 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.EsImportRouteExtendedCommunityCaseBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.extended.community.ExtendedCommunity;
18
19 public final class ESImpRouteTargetExtCom extends AbstractExtendedCommunities {
20     private static final int SUBTYPE = 2;
21     private static final int MAC_ADDRESS_LENGTH = 6;
22
23     @Override
24     public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer) {
25         return new EsImportRouteExtendedCommunityCaseBuilder()
26             .setEsImportRouteExtendedCommunity(new EsImportRouteExtendedCommunityBuilder()
27                 .setEsImport(IetfYangUtil.macAddressFor(ByteArray.readBytes(buffer, MAC_ADDRESS_LENGTH)))
28                 .build())
29             .build();
30     }
31
32     @Override
33     public void serializeExtendedCommunity(final ExtendedCommunity extendedCommunity, final ByteBuf byteAggregator) {
34         Preconditions.checkArgument(extendedCommunity instanceof EsImportRouteExtendedCommunityCase,
35                 "The extended community %s is not EsImportRouteExtendedCommunityCaseCase type.",
36                 extendedCommunity);
37         final var extCom = ((EsImportRouteExtendedCommunityCase) extendedCommunity).getEsImportRouteExtendedCommunity();
38         byteAggregator.writeBytes(IetfYangUtil.macAddressBytes(extCom.getEsImport()));
39     }
40
41     @Override
42     public int getSubType() {
43         return SUBTYPE;
44     }
45 }