YANG revision dates mass-update
[bgpcep.git] / bmp / bmp-parser-impl / src / main / java / org / opendaylight / protocol / bmp / parser / tlv / StatType007TlvHandler.java
1 /*
2  * Copyright (c) 2015 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.bmp.parser.tlv;
9
10 import static com.google.common.base.Preconditions.checkArgument;
11
12 import io.netty.buffer.ByteBuf;
13 import org.opendaylight.protocol.bmp.spi.parser.BmpDeserializationException;
14 import org.opendaylight.protocol.bmp.spi.parser.BmpTlvParser;
15 import org.opendaylight.protocol.bmp.spi.parser.BmpTlvSerializer;
16 import org.opendaylight.protocol.bmp.spi.parser.TlvUtil;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Gauge64;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.Tlv;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.stat.tlvs.AdjRibsInRoutesTlv;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.stat.tlvs.AdjRibsInRoutesTlvBuilder;
21 import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
22
23 public class StatType007TlvHandler implements BmpTlvParser, BmpTlvSerializer {
24     public static final int TYPE = 7;
25
26     @Override
27     public void serializeTlv(final Tlv tlv, final ByteBuf output) {
28         checkArgument(tlv instanceof AdjRibsInRoutesTlv, "AdjRibsInRoutesTlv is mandatory.");
29         TlvUtil.formatTlvGauge64(TYPE, ((AdjRibsInRoutesTlv) tlv).getCount(), output);
30     }
31
32     @Override
33     public Tlv parseTlv(final ByteBuf buffer) throws BmpDeserializationException {
34         if (buffer == null) {
35             return null;
36         }
37         return new AdjRibsInRoutesTlvBuilder().setCount(new Gauge64(ByteBufUtils.readUint64(buffer))).build();
38     }
39 }