f6393ba9d05b357ccebdb93b056b1f835bf227c5
[bgpcep.git] / pcep / segment-routing / src / main / java / org / opendaylight / protocol / pcep / lsp / setup / type01 / PcepRpObjectWithPstTlvParser.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.lsp.setup.type01;
9
10 import io.netty.buffer.ByteBuf;
11 import org.opendaylight.protocol.pcep.impl.object.PCEPRequestParameterObjectParser;
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.pcep.lsp.setup.type._01.rev140507.PathSetupTypeTlv;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.Tlvs1;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.Tlvs1Builder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.Tlvs2;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.Tlvs3;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.Tlvs4;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.path.setup.type.tlv.PathSetupType;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.rp.Tlvs;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.rp.TlvsBuilder;
24
25 public class PcepRpObjectWithPstTlvParser extends PCEPRequestParameterObjectParser {
26
27     public PcepRpObjectWithPstTlvParser(TlvRegistry tlvReg, VendorInformationTlvRegistry viTlvReg) {
28         super(tlvReg, viTlvReg);
29     }
30
31     @Override
32     public void addTlv(final TlvsBuilder builder, Tlv tlv) {
33         super.addTlv(builder, tlv);
34         final Tlvs1Builder tlvBuilder = new Tlvs1Builder();
35         if (builder != null) {
36             final Tlvs1 tlvs = builder.getAugmentation(Tlvs1.class);
37             if (tlvs != null && tlvs.getPathSetupType() != null) {
38                 tlvBuilder.setPathSetupType(tlvs.getPathSetupType());
39             }
40         }
41         if (tlv instanceof PathSetupType) {
42             tlvBuilder.setPathSetupType((PathSetupType) tlv);
43         }
44         builder.addAugmentation(Tlvs1.class, tlvBuilder.build()).build();
45     }
46
47     @Override
48     public void serializeTlvs(final Tlvs tlvs, final ByteBuf body) {
49         if (tlvs == null) {
50             return;
51         }
52         super.serializeTlvs(tlvs, body);
53         if (tlvs.getAugmentation(Tlvs1.class) != null) {
54             serializePathSetupType(tlvs.getAugmentation(Tlvs1.class), body);
55         } else if (tlvs.getAugmentation(Tlvs2.class) != null) {
56             serializePathSetupType(tlvs.getAugmentation(Tlvs2.class), body);
57         } else if (tlvs.getAugmentation(Tlvs3.class) != null) {
58             serializePathSetupType(tlvs.getAugmentation(Tlvs3.class), body);
59         } else if (tlvs.getAugmentation(Tlvs4.class) != null) {
60             serializePathSetupType(tlvs.getAugmentation(Tlvs4.class), body);
61         }
62     }
63
64     private void serializePathSetupType(final PathSetupTypeTlv pstTlv, final ByteBuf body) {
65         if (pstTlv.getPathSetupType() != null) {
66             serializeTlv(pstTlv.getPathSetupType(), body);
67         }
68     }
69 }