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 static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
12 import com.google.common.base.Preconditions;
13 import io.netty.buffer.ByteBuf;
14 import io.netty.buffer.Unpooled;
15 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
16 import org.opendaylight.protocol.pcep.spi.TlvParser;
17 import org.opendaylight.protocol.pcep.spi.TlvSerializer;
18 import org.opendaylight.protocol.pcep.spi.TlvUtil;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.order.tlv.Order;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.order.tlv.OrderBuilder;
24 * Parser for {@link Order}
26 public class OrderTlvParser implements TlvParser, TlvSerializer {
28 public static final int TYPE = 5;
31 public Order parseTlv(final ByteBuf buffer) throws PCEPDeserializerException {
35 return new OrderBuilder().setDelete(buffer.readUnsignedInt()).setSetup(buffer.readUnsignedInt()).build();
39 public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
40 Preconditions.checkArgument(tlv instanceof Order, "OrderTlv is mandatory.");
41 final Order otlv = (Order) tlv;
42 final ByteBuf body = Unpooled.buffer();
43 writeUnsignedInt(otlv.getDelete(), body);
44 writeUnsignedInt(otlv.getSetup(), body);
45 TlvUtil.formatTlv(TYPE, body, buffer);