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