BUG-139: PCEP TLVs extensions implementation
[bgpcep.git] / pcep / ietf-stateful07 / src / main / java / org / opendaylight / protocol / pcep / sync / optimizations / SyncOptimizationsOpenObjectParser.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.stateful07.Stateful07OpenObjectParser;
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.rev150714.Tlvs3;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Tlvs3Builder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.lsp.db.version.tlv.LspDbVersion;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.speaker.entity.id.tlv.SpeakerEntityId;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.Tlvs;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder;
21
22 public class SyncOptimizationsOpenObjectParser extends Stateful07OpenObjectParser {
23
24     public SyncOptimizationsOpenObjectParser(final TlvRegistry tlvReg, final VendorInformationTlvRegistry viTlvReg) {
25         super(tlvReg, viTlvReg);
26     }
27
28
29     @Override
30     public void addTlv(final TlvsBuilder tbuilder, final Tlv tlv) {
31         super.addTlv(tbuilder, tlv);
32         final Tlvs3Builder syncOptTlvsBuilder = new Tlvs3Builder();
33         if (tbuilder.getAugmentation(Tlvs3.class) != null) {
34             final Tlvs3 t = tbuilder.getAugmentation(Tlvs3.class);
35             if (t.getLspDbVersion() != null) {
36                 syncOptTlvsBuilder.setLspDbVersion(t.getLspDbVersion());
37             }
38             if (t.getSpeakerEntityId() != null) {
39                 syncOptTlvsBuilder.setSpeakerEntityId(t.getSpeakerEntityId());
40             }
41         }
42         if (tlv instanceof LspDbVersion) {
43             syncOptTlvsBuilder.setLspDbVersion((LspDbVersion) tlv);
44         }
45         if (tlv instanceof SpeakerEntityId) {
46             syncOptTlvsBuilder.setSpeakerEntityId((SpeakerEntityId) tlv);
47         }
48         tbuilder.addAugmentation(Tlvs3.class, syncOptTlvsBuilder.build());
49     }
50
51     @Override
52     public void serializeTlvs(final Tlvs tlvs, final ByteBuf body) {
53         if (tlvs == null) {
54             return;
55         }
56         super.serializeTlvs(tlvs, body);
57         if (tlvs.getAugmentation(Tlvs3.class) != null) {
58             final Tlvs3 syncOptTlvs = tlvs.getAugmentation(Tlvs3.class);
59             if (syncOptTlvs.getLspDbVersion() != null) {
60                 serializeTlv(syncOptTlvs.getLspDbVersion(), body);
61             }
62             if (syncOptTlvs.getSpeakerEntityId() != null) {
63                 serializeTlv(syncOptTlvs.getSpeakerEntityId(), body);
64             }
65         }
66     }
67 }