01c7d41936c4809830766fc57c8366240e952159
[bgpcep.git] / pcep / segment-routing / src / main / java / org / opendaylight / protocol / pcep / lsp / setup / type01 / CInitiated00SrpObjectWithPstTlvParser.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.ietf.initiated00.CInitiated00SrpObjectParser;
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.ietf.stateful.rev131222.srp.object.srp.Tlvs;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.srp.TlvsBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.PathSetupTypeTlv;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.Tlvs5;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.Tlvs6;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.Tlvs7;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.Tlvs7Builder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.Tlvs8;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.path.setup.type.tlv.PathSetupType;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
24
25 public class CInitiated00SrpObjectWithPstTlvParser extends CInitiated00SrpObjectParser {
26
27     public CInitiated00SrpObjectWithPstTlvParser(final TlvRegistry tlvReg, final VendorInformationTlvRegistry viTlvReg) {
28         super(tlvReg, viTlvReg);
29     }
30
31     @Override
32     public void addTlv(final TlvsBuilder builder, final Tlv tlv) {
33         super.addTlv(builder, tlv);
34         final Tlvs7Builder tlvBuilder = new Tlvs7Builder();
35         if (builder != null) {
36             final Tlvs7 tlvs = builder.getAugmentation(Tlvs7.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(Tlvs7.class, tlvBuilder.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(Tlvs5.class) != null) {
54             serializePathSetupType(tlvs.getAugmentation(Tlvs5.class), body);
55         } else if (tlvs.getAugmentation(Tlvs6.class) != null) {
56             serializePathSetupType(tlvs.getAugmentation(Tlvs6.class), body);
57         } else if (tlvs.getAugmentation(Tlvs7.class) != null) {
58             serializePathSetupType(tlvs.getAugmentation(Tlvs7.class), body);
59         } else if (tlvs.getAugmentation(Tlvs8.class) != null) {
60             serializePathSetupType(tlvs.getAugmentation(Tlvs8.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 }