6a199967e10db6dbd3bd600a7c9c095d59102481
[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.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.es._import.route.extended.community.EsImportRouteExtendedCommunity;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.es._import.route.extended.community.EsImportRouteExtendedCommunityBuilder;
17 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.EsImportRouteExtendedCommunityCase;
18 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.EsImportRouteExtendedCommunityCaseBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.ExtendedCommunity;
20
21 public final class ESImpRouteTargetExtCom extends AbstractExtendedCommunities {
22     private static final int SUBTYPE = 2;
23     private static final int MAC_ADDRESS_LENGTH = 6;
24
25     @Override
26     public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer) {
27         final MacAddress mac = IetfYangUtil.INSTANCE.macAddressFor(ByteArray.readBytes(buffer, MAC_ADDRESS_LENGTH));
28
29         return new EsImportRouteExtendedCommunityCaseBuilder().setEsImportRouteExtendedCommunity(
30                 new EsImportRouteExtendedCommunityBuilder().setEsImport(mac).build()).build();
31     }
32
33     @Override
34     public void serializeExtendedCommunity(final ExtendedCommunity extendedCommunity, final ByteBuf byteAggregator) {
35         Preconditions.checkArgument(extendedCommunity instanceof EsImportRouteExtendedCommunityCase,
36                 "The extended community %s is not EsImportRouteExtendedCommunityCaseCase type.",
37                 extendedCommunity);
38         final EsImportRouteExtendedCommunity extCom = ((EsImportRouteExtendedCommunityCase) extendedCommunity)
39                 .getEsImportRouteExtendedCommunity();
40         byteAggregator.writeBytes(IetfYangUtil.INSTANCE.macAddressBytes(extCom.getEsImport()));
41     }
42
43     @Override
44     public int getSubType() {
45         return SUBTYPE;
46     }
47 }