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 io.netty.buffer.ByteBuf;
12 import org.opendaylight.protocol.pcep.spi.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.Tlv;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.order.tlv.Order;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.order.tlv.OrderBuilder;
21 * Parser for {@link Order}
23 public class OrderTlvParser implements TlvParser, TlvSerializer {
25 public static final int TYPE = 5;
27 private static final int ORDR_DEL_LENGTH = 4;
29 private static final int ORDR_SETUP_LENGTH = 4;
32 public Order parseTlv(final ByteBuf buffer) throws PCEPDeserializerException {
36 return new OrderBuilder().setDelete(buffer.readUnsignedInt()).setSetup(buffer.readUnsignedInt()).build();
40 public byte[] serializeTlv(final Tlv tlv) {
42 throw new IllegalArgumentException("OrderTlv is mandatory.");
44 final Order otlv = (Order) tlv;
45 final byte[] bytes = new byte[ORDR_DEL_LENGTH + ORDR_SETUP_LENGTH];
47 ByteArray.copyWhole(ByteArray.longToBytes(otlv.getDelete(), ORDR_DEL_LENGTH), bytes, offset);
48 offset += ORDR_DEL_LENGTH;
49 ByteArray.copyWhole(ByteArray.longToBytes(otlv.getSetup(), ORDR_SETUP_LENGTH), bytes, offset);
50 return TlvUtil.formatTlv(TYPE, bytes);