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