Enable restart of CSS modules on blueprint container restart
[bgpcep.git] / pcep / base-parser / src / main / java / org / opendaylight / protocol / pcep / parser / tlv / OverloadedDurationTlvParser.java
1 /*
2  * Copyright (c) 2013 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.pcep.parser.tlv;
9
10 import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
11
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.overload.duration.tlv.OverloadDuration;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.overload.duration.tlv.OverloadDurationBuilder;
22
23 /**
24  * Parser for {@link OverloadDuration}
25  */
26 public class OverloadedDurationTlvParser implements TlvParser, TlvSerializer {
27
28     public static final int TYPE = 2;
29
30     @Override
31     public OverloadDuration parseTlv(final ByteBuf buffer) throws PCEPDeserializerException {
32         if (buffer == null) {
33             return null;
34         }
35         return new OverloadDurationBuilder().setDuration(buffer.readUnsignedInt()).build();
36     }
37
38     @Override
39     public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
40         Preconditions.checkArgument(tlv instanceof OverloadDuration, "OverloadedTlv is mandatory.");
41         final ByteBuf body = Unpooled.buffer();
42         writeUnsignedInt(((OverloadDuration) tlv).getDuration(), body);
43         TlvUtil.formatTlv(TYPE, body, buffer);
44     }
45 }