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 com.google.common.base.Preconditions;
11 import io.netty.buffer.ByteBuf;
12 import io.netty.buffer.Unpooled;
13 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
14 import org.opendaylight.protocol.pcep.spi.TlvParser;
15 import org.opendaylight.protocol.pcep.spi.TlvSerializer;
16 import org.opendaylight.protocol.pcep.spi.TlvUtil;
17 import org.opendaylight.protocol.util.BitArray;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.NoPathVectorTlv.Flags;
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.pcrep.message.pcrep.message.replies.result.failure._case.no.path.tlvs.NoPathVector;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.failure._case.no.path.tlvs.NoPathVectorBuilder;
24 * Parser for {@link NoPathVector}
26 public class NoPathVectorTlvParser implements TlvParser, TlvSerializer {
28 public static final int TYPE = 1;
30 private static final int FLAGS_SIZE = 32;
32 private static final int REACHABLITY_PROBLEM = 24;
33 private static final int NO_GCO_SOLUTION = 25;
34 private static final int NO_GCO_MIGRATION_PATH = 26;
35 private static final int PATH_KEY = 27;
36 private static final int CHAIN_UNAVAILABLE = 28;
37 private static final int UNKNOWN_SRC = 29;
38 private static final int UNKNOWN_DEST = 30;
39 private static final int PCE_UNAVAILABLE = 31;
42 public NoPathVector parseTlv(final ByteBuf buffer) throws PCEPDeserializerException {
46 if (buffer.readableBytes() != FLAGS_SIZE / Byte.SIZE) {
47 throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: >="
48 + FLAGS_SIZE / Byte.SIZE + ".");
50 final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE);
51 return new NoPathVectorBuilder().setFlags(
52 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();
56 public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
57 Preconditions.checkArgument(tlv instanceof NoPathVector, "NoPathVectorTlv is mandatory.");
58 final NoPathVector noPath = (NoPathVector) tlv;
59 final ByteBuf body = Unpooled.buffer();
60 final BitArray flags = new BitArray(FLAGS_SIZE);
61 final Flags f = noPath.getFlags();
62 flags.set(REACHABLITY_PROBLEM, f.isP2mpUnreachable());
63 flags.set(NO_GCO_SOLUTION, f.isNoGcoSolution());
64 flags.set(NO_GCO_MIGRATION_PATH, f.isNoGcoMigration());
65 flags.set(PATH_KEY, f.isPathKey());
66 flags.set(CHAIN_UNAVAILABLE, f.isChainUnavailable());
67 flags.set(UNKNOWN_SRC, f.isUnknownSource());
68 flags.set(UNKNOWN_DEST, f.isUnknownDestination());
69 flags.set(PCE_UNAVAILABLE, f.isPceUnavailable());
70 flags.toByteBuf(body);
71 TlvUtil.formatTlv(TYPE, body, buffer);