Add new revision for pcep types model
[bgpcep.git] / pcep / ietf-stateful07 / src / main / java / org / opendaylight / protocol / pcep / ietf / stateful07 / Stateful07LspUpdateErrorTlvParser.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.ietf.stateful07;
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.ietf.stateful.rev181109.lsp.error.code.tlv.LspErrorCode;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.lsp.error.code.tlv.LspErrorCodeBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Tlv;
22
23 /**
24  * Parser for {@link LspErrorCode}
25  */
26 public final class Stateful07LspUpdateErrorTlvParser implements TlvParser, TlvSerializer {
27
28     public static final int TYPE = 20;
29
30     private static final int CONTENT_LENGTH = Integer.SIZE / Byte.SIZE;
31
32     @Override
33     public LspErrorCode parseTlv(final ByteBuf buffer) throws PCEPDeserializerException {
34         if (buffer == null) {
35             return null;
36         }
37         return new LspErrorCodeBuilder().setErrorCode(buffer.readUnsignedInt()).build();
38     }
39
40     @Override
41     public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
42         Preconditions.checkArgument(tlv instanceof LspErrorCode, "LspErrorCodeTlv is mandatory.");
43         final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
44         writeUnsignedInt(((LspErrorCode) tlv).getErrorCode(), body);
45         TlvUtil.formatTlv(TYPE, body, buffer);
46     }
47 }