467b7624a573265405323afede3f8f5645037982
[bgpcep.git] / pcep / segment-routing / src / main / java / org / opendaylight / protocol / pcep / segment / routing / PcepOpenObjectWithSpcTlvParser.java
1 /*
2  * Copyright (c) 2014 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.segment.routing;
9
10 import io.netty.buffer.ByteBuf;
11 import org.opendaylight.protocol.pcep.spi.TlvRegistry;
12 import org.opendaylight.protocol.pcep.spi.VendorInformationTlvRegistry;
13 import org.opendaylight.protocol.pcep.sync.optimizations.SyncOptimizationsOpenObjectParser;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev150112.Tlvs1;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev150112.Tlvs1Builder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev150112.sr.pce.capability.tlv.SrPceCapability;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.Tlvs;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder;
20
21 public class PcepOpenObjectWithSpcTlvParser extends SyncOptimizationsOpenObjectParser {
22
23     public PcepOpenObjectWithSpcTlvParser(final TlvRegistry tlvReg, final VendorInformationTlvRegistry viTlvReg) {
24         super(tlvReg, viTlvReg);
25     }
26
27     @Override
28     public void addTlv(final TlvsBuilder tbuilder, final Tlv tlv) {
29         super.addTlv(tbuilder, tlv);
30         final Tlvs1Builder tlvBuilder = new Tlvs1Builder();
31         if (tbuilder.getAugmentation(Tlvs1.class) != null) {
32             final Tlvs1 tlvs = tbuilder.getAugmentation(Tlvs1.class);
33             if (tlvs.getSrPceCapability() != null) {
34                 tlvBuilder.setSrPceCapability(tlvs.getSrPceCapability());
35             }
36         }
37         if (tlv instanceof SrPceCapability) {
38             tlvBuilder.setSrPceCapability((SrPceCapability) tlv);
39         }
40         tbuilder.addAugmentation(Tlvs1.class, tlvBuilder.build());
41     }
42
43     @Override
44     public void serializeTlvs(final Tlvs tlvs, final ByteBuf body) {
45         if (tlvs == null) {
46             return;
47         }
48         super.serializeTlvs(tlvs, body);
49         if (tlvs.getAugmentation(Tlvs1.class) != null) {
50             final Tlvs1 spcTlvs = tlvs.getAugmentation(Tlvs1.class);
51             if (spcTlvs.getSrPceCapability() != null) {
52                 serializeTlv(spcTlvs.getSrPceCapability(), body);
53             }
54         }
55     }
56 }