Add new revision for pcep types model
[bgpcep.git] / pcep / ietf-stateful07 / src / main / java / org / opendaylight / protocol / pcep / sync / optimizations / SyncOptimizationsLspObjectParser.java
1 /*
2  * Copyright (c) 2015 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.sync.optimizations;
9
10 import io.netty.buffer.ByteBuf;
11 import org.opendaylight.protocol.pcep.ietf.initiated00.CInitiated00LspObjectParser;
12 import org.opendaylight.protocol.pcep.spi.TlvRegistry;
13 import org.opendaylight.protocol.pcep.spi.VendorInformationTlvRegistry;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev181109.Tlvs1;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev181109.Tlvs1Builder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev181109.lsp.db.version.tlv.LspDbVersion;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.lsp.object.lsp.Tlvs;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.lsp.object.lsp.TlvsBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Tlv;
20
21 public class SyncOptimizationsLspObjectParser extends CInitiated00LspObjectParser {
22
23     public SyncOptimizationsLspObjectParser(final TlvRegistry tlvReg, final VendorInformationTlvRegistry viTlvReg) {
24         super(tlvReg, viTlvReg);
25     }
26
27     @Override
28     public void serializeTlvs(final Tlvs tlvs, final ByteBuf body) {
29         if (tlvs != null) {
30             super.serializeTlvs(tlvs, body);
31             serializeAugmentation(tlvs.augmentation(Tlvs1.class), body);
32         }
33     }
34
35     private void serializeAugmentation(final Tlvs1 tlv, final ByteBuf body) {
36         if (tlv != null) {
37             serializeTlv(tlv.getLspDbVersion(), body);
38         }
39     }
40
41     @Override
42     public void addTlv(final TlvsBuilder tbuilder, final Tlv tlv) {
43         super.addTlv(tbuilder, tlv);
44         final Tlvs1Builder syncOptTlvsBuilder = new Tlvs1Builder();
45         if (tbuilder.augmentation(Tlvs1.class) != null) {
46             final Tlvs1 t = tbuilder.augmentation(Tlvs1.class);
47             if (t.getLspDbVersion() != null) {
48                 syncOptTlvsBuilder.setLspDbVersion(t.getLspDbVersion());
49             }
50         }
51         if (tlv instanceof LspDbVersion) {
52             syncOptTlvsBuilder.setLspDbVersion((LspDbVersion) tlv);
53         }
54         tbuilder.addAugmentation(Tlvs1.class, syncOptTlvsBuilder.build());
55     }
56 }