2 * Copyright (c) 2013 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
8 package org.opendaylight.protocol.pcep.impl.tlv;
10 import java.math.BigInteger;
12 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
13 import org.opendaylight.protocol.pcep.spi.TlvParser;
14 import org.opendaylight.protocol.pcep.spi.TlvSerializer;
15 import org.opendaylight.protocol.util.ByteArray;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspDbVersionTlv;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.tlvs.LspDbVersionBuilder;
21 * Parser for {@link LspDbVersionTlv}
23 public class LspDbVersionTlvParser implements TlvParser, TlvSerializer {
25 public static final int TYPE = 23;
27 private static final int DBV_F_LENGTH = 8;
30 public LspDbVersionTlv parseTlv(final byte[] buffer) throws PCEPDeserializerException {
31 return new LspDbVersionBuilder().setVersion(BigInteger.valueOf(ByteArray.bytesToLong(ByteArray.subByte(buffer, 0, DBV_F_LENGTH)))).build();
35 public byte[] serializeTlv(final Tlv tlv) {
37 throw new IllegalArgumentException("LspDbVersionTlv is mandatory.");
38 final LspDbVersionTlv lsp = (LspDbVersionTlv) tlv;
39 return ByteArray.subByte(lsp.getVersion().toByteArray(), 0, DBV_F_LENGTH);
43 public int getType() {