2 * Copyright (c) 2013 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.ietf.stateful07;
10 import org.opendaylight.protocol.pcep.impl.object.PCEPOpenObjectParser;
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.ietf.stateful.rev131222.Tlvs1;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Tlvs1Builder;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.stateful.capability.tlv.Stateful;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Open;
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;
22 * Parser for {@link Open}
24 public class Stateful07OpenObjectParser extends PCEPOpenObjectParser {
26 public Stateful07OpenObjectParser(final TlvRegistry tlvReg) {
31 public void addTlv(final TlvsBuilder tbuilder, final Tlv tlv) {
32 super.addTlv(tbuilder, tlv);
33 final Tlvs1Builder statefulBuilder = new Tlvs1Builder();
34 if (tbuilder.getAugmentation(Tlvs1.class) != null) {
35 final Tlvs1 t = tbuilder.getAugmentation(Tlvs1.class);
36 if (t.getStateful() != null) {
37 statefulBuilder.setStateful(t.getStateful());
40 if (tlv instanceof Stateful) {
41 statefulBuilder.setStateful((Stateful) tlv);
43 tbuilder.addAugmentation(Tlvs1.class, statefulBuilder.build());
47 public byte[] serializeTlvs(final Tlvs tlvs) {
51 final byte[] prev = super.serializeTlvs(tlvs);
52 int finalLength = prev.length;
53 byte[] ofListBytes = null;
54 byte[] statefulBytes = null;
55 if (tlvs.getOfList() != null) {
56 ofListBytes = serializeTlv(tlvs.getOfList());
57 finalLength += ofListBytes.length;
59 if (tlvs.getAugmentation(Tlvs1.class) != null) {
60 final Tlvs1 statefulTlvs = tlvs.getAugmentation(Tlvs1.class);
61 if (statefulTlvs.getStateful() != null) {
62 statefulBytes = serializeTlv(statefulTlvs.getStateful());
63 finalLength += statefulBytes.length;
66 final byte[] result = new byte[finalLength];
67 ByteArray.copyWhole(prev, result, 0);
68 int offset = prev.length;
69 if (ofListBytes != null) {
70 ByteArray.copyWhole(ofListBytes, result, offset);
71 offset += ofListBytes.length;
73 if (statefulBytes != null) {
74 ByteArray.copyWhole(statefulBytes, result, offset);
75 offset += statefulBytes.length;