2 * Copyright (c) 2016 Cisco Systems, Inc. and others. 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;
11 import static org.opendaylight.protocol.bgp.parser.impl.message.BGPOpenMessageParser.AS_TRANS;
13 import com.google.common.base.Preconditions;
14 import io.netty.buffer.ByteBuf;
15 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
16 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
17 import org.opendaylight.protocol.bgp.parser.spi.extended.community.ExtendedCommunityParser;
18 import org.opendaylight.protocol.bgp.parser.spi.extended.community.ExtendedCommunitySerializer;
19 import org.opendaylight.protocol.util.ByteArray;
20 import org.opendaylight.protocol.util.ByteBufWriteUtil;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.extended.community.ExtendedCommunity;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.extended.community.extended.community.LinkBandwidthCase;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.extended.community.extended.community.LinkBandwidthCaseBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.extended.community.extended.community.link.bandwidth._case.LinkBandwidthExtendedCommunity;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.extended.community.extended.community.link.bandwidth._case.LinkBandwidthExtendedCommunityBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
28 public class LinkBandwidthEC implements ExtendedCommunityParser, ExtendedCommunitySerializer {
29 private static final int TYPE = 64;
30 private static final int SUBTYPE = 4;
31 private static final int BANDWIDTH_SIZE = 4;
32 private static final int AS_TRANS_LENGTH = 2;
35 public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer)
36 throws BGPDocumentedException, BGPParsingException {
37 buffer.skipBytes(AS_TRANS_LENGTH);
38 final LinkBandwidthExtendedCommunity lb = new LinkBandwidthExtendedCommunityBuilder()
39 .setBandwidth(new Bandwidth(ByteArray.readBytes(buffer, BANDWIDTH_SIZE)))
41 return new LinkBandwidthCaseBuilder().setLinkBandwidthExtendedCommunity(lb).build();
45 public void serializeExtendedCommunity(final ExtendedCommunity extendedCommunity, final ByteBuf body) {
46 Preconditions.checkArgument(extendedCommunity instanceof LinkBandwidthCase,
47 "The extended community %s is not LinkBandwidthCase type.", extendedCommunity);
48 final LinkBandwidthExtendedCommunity lb
49 = ((LinkBandwidthCase) extendedCommunity).getLinkBandwidthExtendedCommunity();
50 body.writeShort(AS_TRANS);
51 ByteBufWriteUtil.writeFloat32(lb.getBandwidth(), body);
55 public int getType(final boolean isTransitive) {
60 public int getSubType() {