Fix to convert Tunnel Id and Metadata BigInteger value to 64 bits (8 element byte... 52/3552/1
authorDeepthi V V <deepthi.v.v@ericsson.com>
Sun, 8 Dec 2013 06:25:59 +0000 (11:55 +0530)
committerDeepthi V V <deepthi.v.v@ericsson.com>
Sun, 8 Dec 2013 06:42:35 +0000 (12:12 +0530)
Signed-off-by: Deepthi V V <deepthi.v.v@ericsson.com>
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/FlowConvertor.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/MatchConvertor.java

index e52b06698a86a07fe48d5bb21636d20cd5996544..68e5fe769d4217f8f1031ea82559445a84b4fda7 100644 (file)
@@ -187,8 +187,9 @@ public class FlowConvertor {
                 instructionBuilder
                         .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteMetadata.class);
                 MetadataInstructionBuilder metadataBuilder = new MetadataInstructionBuilder();
-                metadataBuilder.setMetadata(writeMetadata.getMetadata().toByteArray());
-                metadataBuilder.setMetadataMask(writeMetadata.getMetadataMask().toByteArray());
+                metadataBuilder.setMetadata(MatchConvertor.convertBigIntegerTo64Bit(writeMetadata.getMetadata()));
+                metadataBuilder
+                        .setMetadataMask(MatchConvertor.convertBigIntegerTo64Bit(writeMetadata.getMetadataMask()));
                 instructionBuilder.addAugmentation(MetadataInstruction.class, metadataBuilder.build());
                 instructionsList.add(instructionBuilder.build());
             }
index 84acac63aaaf94dd7ef588c5f65f904c19e7059e..887a6009a6b82e062753c66b625c4de6e28275f4 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor;
 
 import java.math.BigInteger;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Dscp;
@@ -714,10 +715,30 @@ public class MatchConvertor {
 
     private static void addMetadataAugmentation(MatchEntriesBuilder builder, BigInteger metadata) {
         MetadataMatchEntryBuilder metadataMatchEntry = new MetadataMatchEntryBuilder();
-        metadataMatchEntry.setMetadata(metadata.toByteArray());
+        metadataMatchEntry.setMetadata(convertBigIntegerTo64Bit(metadata));
         builder.addAugmentation(MetadataMatchEntry.class, metadataMatchEntry.build());
     }
 
+    /**
+     * Utility method to convert BigInteger to 8 element byte array
+     * @param bigInteger
+     * @return byte array containing 64 bits.
+     */
+    public static byte[] convertBigIntegerTo64Bit(BigInteger bigInteger) {
+        if (bigInteger == null) {
+            return null;
+        }
+        byte[] inputArray = bigInteger.toByteArray();
+        byte[] outputArray = new byte[8];
+        if (bigInteger.compareTo(BigInteger.ZERO) < 0) {
+            Arrays.fill(outputArray, (byte) -1);
+        } else {
+            Arrays.fill(outputArray, (byte) 0);
+        }
+        System.arraycopy(inputArray, 0, outputArray, outputArray.length - inputArray.length, inputArray.length);
+        return outputArray;
+    }
+
     /**
      * @return true if Ipv4Prefix contains prefix (and it is used in mask),
      *         false otherwise