2 * Copyright (c) 2018 AT&T Intellectual Property. 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
9 package org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.route.target;
11 import static org.opendaylight.protocol.bgp.parser.spi.extended.community.AbstractTwoOctetAsExtendedCommunity.AS_LOCAL_ADMIN_LENGTH;
13 import com.google.common.primitives.Ints;
14 import io.netty.buffer.ByteBuf;
15 import org.opendaylight.protocol.util.ByteArray;
16 import org.opendaylight.protocol.util.ByteBufWriteUtil;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.ShortAsNumber;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.route.target.extended.community.grouping.RouteTargetExtendedCommunity;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.route.target.extended.community.grouping.RouteTargetExtendedCommunityBuilder;
22 * Route Target Extended Community Parser / Serializer.
24 * @author Claudio D. Gasparini
26 public final class RouteTargetExtendedCommunityHandler {
27 private RouteTargetExtendedCommunityHandler() {
28 throw new UnsupportedOperationException();
31 public static RouteTargetExtendedCommunity parse(final ByteBuf buffer) {
32 return new RouteTargetExtendedCommunityBuilder()
33 .setGlobalAdministrator(new ShortAsNumber((long) buffer.readUnsignedShort()))
34 .setLocalAdministrator(ByteArray.readBytes(buffer, AS_LOCAL_ADMIN_LENGTH))
38 public static void serialize(final RouteTargetExtendedCommunity routeTarget, final ByteBuf byteAggregator) {
39 ByteBufWriteUtil.writeUnsignedShort(Ints.checkedCast(routeTarget.getGlobalAdministrator().getValue()),
41 byteAggregator.writeBytes(routeTarget.getLocalAdministrator());