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.impl.tlv;
10 import java.util.BitSet;
12 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
13 import org.opendaylight.protocol.pcep.spi.TlvParser;
14 import org.opendaylight.protocol.pcep.spi.TlvSerializer;
15 import org.opendaylight.protocol.util.ByteArray;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.NoPathVectorTlv;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.NoPathVectorTlv.Flags;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.failure.no.path.tlvs.NoPathVectorBuilder;
22 * Parser for {@link NoPathVectorTlv}
24 public class NoPathVectorTlvParser implements TlvParser, TlvSerializer {
26 public static final int TYPE = 1;
28 private static final int FLAGS_F_LENGTH = 4;
30 private static final int REACHABLITY_PROBLEM = 24;
31 private static final int NO_GCO_SOLUTION = 25;
32 private static final int NO_GCO_MIGRATION_PATH = 26;
33 private static final int PATH_KEY = 27;
34 private static final int CHAIN_UNAVAILABLE = 28;
35 private static final int UNKNOWN_SRC = 29;
36 private static final int UNKNOWN_DEST = 30;
37 private static final int PCE_UNAVAILABLE = 31;
40 public NoPathVectorTlv parseTlv(final byte[] valueBytes) throws PCEPDeserializerException {
41 if (valueBytes == null || valueBytes.length == 0) {
42 throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
44 if (valueBytes.length != FLAGS_F_LENGTH) {
45 throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + valueBytes.length + "; Expected: >="
46 + FLAGS_F_LENGTH + ".");
48 final BitSet flags = ByteArray.bytesToBitSet(valueBytes);
49 return new NoPathVectorBuilder().setFlags(
50 new Flags(flags.get(CHAIN_UNAVAILABLE), flags.get(NO_GCO_MIGRATION_PATH), flags.get(NO_GCO_SOLUTION), flags.get(REACHABLITY_PROBLEM), flags.get(PATH_KEY), flags.get(PCE_UNAVAILABLE), flags.get(UNKNOWN_DEST), flags.get(UNKNOWN_SRC))).build();
54 public byte[] serializeTlv(final Tlv tlvs) {
56 throw new IllegalArgumentException("NoPathVectorTlv is mandatory.");
58 final NoPathVectorTlv tlv = (NoPathVectorTlv) tlvs;
60 final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
61 flags.set(REACHABLITY_PROBLEM, tlv.getFlags().isP2mpUnreachable());
62 flags.set(NO_GCO_SOLUTION, tlv.getFlags().isNoGcoSolution());
63 flags.set(NO_GCO_MIGRATION_PATH, tlv.getFlags().isNoGcoMigration());
64 flags.set(PATH_KEY, tlv.getFlags().isPathKey());
65 flags.set(CHAIN_UNAVAILABLE, tlv.getFlags().isChainUnavailable());
66 flags.set(UNKNOWN_SRC, tlv.getFlags().isUnknownSource());
67 flags.set(UNKNOWN_DEST, tlv.getFlags().isUnknownDestination());
68 flags.set(PCE_UNAVAILABLE, tlv.getFlags().isPceUnavailable());
69 return ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH);
73 public int getType() {