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.initiated00;
10 import io.netty.buffer.ByteBuf;
12 import java.util.BitSet;
14 import org.opendaylight.protocol.pcep.ietf.stateful07.Stateful07StatefulCapabilityTlvParser;
15 import org.opendaylight.protocol.pcep.impl.tlv.TlvUtil;
16 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
17 import org.opendaylight.protocol.util.ByteArray;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.Stateful1;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.Stateful1Builder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.stateful.capability.tlv.Stateful;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.stateful.capability.tlv.StatefulBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
25 * Parser for {@link Stateful}
27 public final class CInitiated00StatefulCapabilityTlvParser extends Stateful07StatefulCapabilityTlvParser {
29 private static final int I_FLAG_OFFSET = 29;
32 public Stateful parseTlv(final ByteBuf buffer) throws PCEPDeserializerException {
36 if (buffer.readableBytes() < FLAGS_F_LENGTH) {
37 throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: >= "
38 + FLAGS_F_LENGTH + ".");
40 final BitSet flags = ByteArray.bytesToBitSet(ByteArray.readBytes(buffer, FLAGS_F_LENGTH));
42 final StatefulBuilder sb = new StatefulBuilder();
43 sb.setLspUpdateCapability(flags.get(U_FLAG_OFFSET));
45 if (flags.get(I_FLAG_OFFSET)) {
46 sb.addAugmentation(Stateful1.class, new Stateful1Builder().setInitiation(Boolean.TRUE).build());
52 public byte[] serializeTlv(final Tlv tlv) {
54 throw new IllegalArgumentException("StatefulCapabilityTlv is mandatory.");
56 final Stateful sct = (Stateful) tlv;
58 final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
60 final Stateful1 sfi = sct.getAugmentation(Stateful1.class);
62 flags.set(I_FLAG_OFFSET, sfi.isInitiation());
64 flags.set(U_FLAG_OFFSET, sct.isLspUpdateCapability());
65 return TlvUtil.formatTlv(TYPE, ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH));