BUG-47 : unfinished PCEP migration to generated DTOs.
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / protocol / pcep / impl / tlv / NoPathVectorTlvParser.java
index 1f651defc9f4fca9da7f4450eb4e716ddcb9dfba..510d678043c70593d7d2253af57b69aec91d5b3a 100644 (file)
@@ -10,13 +10,20 @@ package org.opendaylight.protocol.pcep.impl.tlv;
 import java.util.BitSet;
 
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.tlv.NoPathVectorTlv;
+import org.opendaylight.protocol.pcep.spi.TlvParser;
+import org.opendaylight.protocol.pcep.spi.TlvSerializer;
 import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.NoPathVectorTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.NoPathVectorTlv.Flags;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
+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;
 
 /**
- * Parser for {@link org.opendaylight.protocol.pcep.tlv.NoPathVectorTlv NoPathVectorTlv}
+ * Parser for {@link NoPathVectorTlv}
  */
-public class NoPathVectorTlvParser {
+public class NoPathVectorTlvParser implements TlvParser, TlvSerializer {
+
+       public static final int TYPE = 1;
 
        public static final int FLAGS_F_LENGTH = 4;
 
@@ -38,31 +45,41 @@ public class NoPathVectorTlvParser {
         */
        public static final int REACHABLITY_PROBLEM = 24;
 
-       public static NoPathVectorTlv parse(byte[] valueBytes) throws PCEPDeserializerException {
+       @Override
+       public NoPathVectorTlv parseTlv(final byte[] valueBytes) throws PCEPDeserializerException {
                if (valueBytes == null || valueBytes.length == 0)
                        throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
 
                if (valueBytes.length != FLAGS_F_LENGTH)
-                       throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + valueBytes.length + "; Expected: >=" + FLAGS_F_LENGTH + ".");
+                       throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + valueBytes.length + "; Expected: >="
+                                       + FLAGS_F_LENGTH + ".");
 
                final BitSet flags = ByteArray.bytesToBitSet(valueBytes);
-               return new NoPathVectorTlv(flags.get(PCE_UNAVAILABLE), flags.get(UNKNOWN_DEST), flags.get(UNKNOWN_SRC), flags.get(NO_GCO_SOLUTION),
-                               flags.get(NO_GCO_MIGRATION_PATH), flags.get(REACHABLITY_PROBLEM));
+
+               return new NoPathVectorBuilder().setFlags(
+                               new Flags(false, flags.get(NO_GCO_MIGRATION_PATH), flags.get(NO_GCO_SOLUTION), flags.get(REACHABLITY_PROBLEM), false, flags.get(PCE_UNAVAILABLE), flags.get(UNKNOWN_DEST), flags.get(UNKNOWN_SRC))).build();
        }
 
-       public static byte[] put(NoPathVectorTlv obj) {
-               if (obj == null)
+       @Override
+       public byte[] serializeTlv(final Tlv tlvs) {
+               if (tlvs == null)
                        throw new IllegalArgumentException("NoPathVectorTlv is mandatory.");
+               final NoPathVectorTlv tlv = (NoPathVectorTlv) tlvs;
 
                final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
 
-               flags.set(PCE_UNAVAILABLE, obj.isPceUnavailable());
-               flags.set(UNKNOWN_DEST, obj.isUnknownDest());
-               flags.set(UNKNOWN_SRC, obj.isUnknownSrc());
-               flags.set(NO_GCO_SOLUTION, obj.isNoGCOSolution());
-               flags.set(NO_GCO_MIGRATION_PATH, obj.isNoGCOMigrationPath());
-               flags.set(REACHABLITY_PROBLEM, obj.isReachablityProblem());
+               flags.set(PCE_UNAVAILABLE, tlv.getFlags().isPceUnavailable());
+               flags.set(UNKNOWN_DEST, tlv.getFlags().isUnknownDestination());
+               flags.set(UNKNOWN_SRC, tlv.getFlags().isUnknownSource());
+               flags.set(NO_GCO_SOLUTION, tlv.getFlags().isNoGcoSolution());
+               flags.set(NO_GCO_MIGRATION_PATH, tlv.getFlags().isNoGcoMigration());
+               flags.set(REACHABLITY_PROBLEM, tlv.getFlags().isP2mpUnreachable());
 
                return ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH);
        }
+
+       @Override
+       public int getType() {
+               return TYPE;
+       }
 }