2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.protocol.pcep.crabbe.initiated00;
10 import org.opendaylight.protocol.pcep.ietf.stateful02.Stateful02OpenObjectParser;
11 import org.opendaylight.protocol.pcep.spi.TlvRegistry;
12 import org.opendaylight.protocol.util.ByteArray;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated._00.rev140113.Tlvs1;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated._00.rev140113.Tlvs1Builder;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated._00.rev140113.lsp.cleanup.tlv.LspCleanup;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.Tlvs2;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.Tlvs2Builder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.stateful.capability.tlv.Stateful;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.Tlvs;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder;
24 * Parser for Open object
26 public final class PCEPOpenObjectParser extends Stateful02OpenObjectParser {
28 public PCEPOpenObjectParser(final TlvRegistry tlvReg) {
33 public void addTlv(final TlvsBuilder tbuilder, final Tlv tlv) {
34 super.addTlv(tbuilder, tlv);
35 final Tlvs2Builder statefulBuilder = new Tlvs2Builder();
36 if (tbuilder.getAugmentation(Tlvs2.class) != null) {
37 final Tlvs2 t = tbuilder.getAugmentation(Tlvs2.class);
38 if (t.getStateful() != null) {
39 statefulBuilder.setStateful(t.getStateful());
42 final Tlvs1Builder cleanupBuilder = new Tlvs1Builder();
43 if (tbuilder.getAugmentation(Tlvs1.class) != null) {
44 final Tlvs1 t = tbuilder.getAugmentation(Tlvs1.class);
45 if (t.getLspCleanup() != null) {
46 cleanupBuilder.setLspCleanup(t.getLspCleanup());
49 if (tlv instanceof Stateful) {
50 statefulBuilder.setStateful((Stateful) tlv);
51 } else if (tlv instanceof LspCleanup) {
52 cleanupBuilder.setLspCleanup((LspCleanup) tlv);
54 tbuilder.addAugmentation(Tlvs2.class, statefulBuilder.build());
55 tbuilder.addAugmentation(Tlvs1.class, cleanupBuilder.build());
59 public byte[] serializeTlvs(final Tlvs tlvs) {
63 final byte[] prev = super.serializeTlvs(tlvs);
64 int finalLength = prev.length;
65 byte[] cleanupBytes = null;
66 if (tlvs.getAugmentation(Tlvs1.class) != null) {
67 final Tlvs1 cleanupTlv = tlvs.getAugmentation(Tlvs1.class);
68 if (cleanupTlv.getLspCleanup() != null) {
69 cleanupBytes = serializeTlv(cleanupTlv.getLspCleanup());
70 finalLength += cleanupBytes.length;
73 final byte[] result = new byte[finalLength];
74 ByteArray.copyWhole(prev, result, 0);
75 int offset = prev.length;
76 if (cleanupBytes != null) {
77 ByteArray.copyWhole(cleanupBytes, result, offset);
78 offset += cleanupBytes.length;