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.tlv.NoPathVectorTlv;
14 import org.opendaylight.protocol.util.ByteArray;
17 * Parser for {@link org.opendaylight.protocol.pcep.tlv.NoPathVectorTlv NoPathVectorTlv}
19 public class NoPathVectorTlvParser {
21 public static final int FLAGS_F_LENGTH = 4;
24 * flags offsets inside flags field in bits
26 public static final int PCE_UNAVAILABLE = 31;
27 public static final int UNKNOWN_DEST = 30;
28 public static final int UNKNOWN_SRC = 29;
31 * flags offsets of flags added by GCO extension
33 public static final int NO_GCO_SOLUTION = 25;
34 public static final int NO_GCO_MIGRATION_PATH = 26;
37 * flags offsets of flags added by RFC 6006
39 public static final int REACHABLITY_PROBLEM = 24;
41 public static NoPathVectorTlv parse(byte[] valueBytes) throws PCEPDeserializerException {
42 if (valueBytes == null || valueBytes.length == 0)
43 throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
45 if (valueBytes.length != FLAGS_F_LENGTH)
46 throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + valueBytes.length + "; Expected: >=" + FLAGS_F_LENGTH + ".");
48 final BitSet flags = ByteArray.bytesToBitSet(valueBytes);
49 return new NoPathVectorTlv(flags.get(PCE_UNAVAILABLE), flags.get(UNKNOWN_DEST), flags.get(UNKNOWN_SRC), flags.get(NO_GCO_SOLUTION),
50 flags.get(NO_GCO_MIGRATION_PATH), flags.get(REACHABLITY_PROBLEM));
53 public static byte[] put(NoPathVectorTlv obj) {
55 throw new IllegalArgumentException("NoPathVectorTlv is mandatory.");
57 final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
59 flags.set(PCE_UNAVAILABLE, obj.isPceUnavailable());
60 flags.set(UNKNOWN_DEST, obj.isUnknownDest());
61 flags.set(UNKNOWN_SRC, obj.isUnknownSrc());
62 flags.set(NO_GCO_SOLUTION, obj.isNoGCOSolution());
63 flags.set(NO_GCO_MIGRATION_PATH, obj.isNoGCOMigrationPath());
64 flags.set(REACHABLITY_PROBLEM, obj.isReachablityProblem());
66 return ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH);