Bug 755 - Fixed ExperimenterAction 15/6215/1
authorMichal Polkorab <michal.polkorab@pantheon.sk>
Thu, 20 Mar 2014 10:53:59 +0000 (11:53 +0100)
committerMichal Polkorab <michal.polkorab@pantheon.sk>
Tue, 15 Apr 2014 15:27:18 +0000 (15:27 +0000)
Signed-off-by: Michal Polkorab <michal.polkorab@pantheon.sk>
Change-Id: I6cd66ac6ecd35ddd17b9a489633a2443464e8581
(cherry picked from commit 6cd66ac6ecd35ddd17b9a489633a2443464e8581)

openflow-protocol-api/src/main/yang/openflow-augments.yang
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsDeserializer.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsSerializer.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsDeserializerTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsSerializerTest.java

index fb5e755e31ec72d456192f1c922529d7b72ab6ec..a3ee05a9303fa2656ce0f36cec783b36bf7089bf 100644 (file)
          leaf experimenter {\r
              type uint32;\r
          }\r
+         leaf data {\r
+             type binary;\r
+         }\r
      }\r
      // OF1.0 structures\r
      augment "/ofaction:actions-container/ofaction:action" {\r
index b3175232ddaf86f7de5cc12174cd515faf93b6c3..ab5d084783ee6951edd31efdb27281967eb12b04 100644 (file)
@@ -67,6 +67,7 @@ public abstract class ActionsDeserializer {
     private static final byte PADDING_IN_SET_MPLS_TTL_ACTIONS_HEADER = 3;
     private static final byte PADDING_IN_PUSH_VLAN_ACTIONS_HEADER = 2;
     private static final byte PADDING_IN_NW_TTL_ACTIONS_HEADER = 3;
+    private static final byte EXPERIMENTER_ACTION_HEADER_LENGTH = 8;
     
     /**
      * Creates list of actions (OpenFlow v1.3)
@@ -131,7 +132,7 @@ public abstract class ActionsDeserializer {
                 actions.add(createPopPbbAction(input, actionBuilder));
                 break;
             case 0xFFFF:
-                actions.add(createExperimenterAction(input, actionBuilder));
+                actions.add(createExperimenterAction(input, actionBuilder, currentActionLength));
                 break;
             default:
                 break;
@@ -313,10 +314,16 @@ public abstract class ActionsDeserializer {
         return actionBuilder.build();
     }
     
-    private static Action createExperimenterAction(ByteBuf in, ActionBuilder actionBuilder) {
+    private static Action createExperimenterAction(ByteBuf in, ActionBuilder actionBuilder, int actionLength) {
         actionBuilder.setType(Experimenter.class);
         ExperimenterActionBuilder experimenter = new ExperimenterActionBuilder();
         experimenter.setExperimenter(in.readUnsignedInt());
+        int dataLength = actionLength - EXPERIMENTER_ACTION_HEADER_LENGTH;
+        if (dataLength > 0) {
+            byte[] data = new byte[dataLength];
+            in.readBytes(data);
+            experimenter.setData(data);
+        }
         actionBuilder.addAugmentation(ExperimenterAction.class, experimenter.build());
         return actionBuilder.build();
     }
index 6c26cc2c65e1c9a879a2ff407cc558cea726e511..10cd78d7cd2fa31a9710bd5d79e6afccc69bfa4a 100644 (file)
@@ -70,7 +70,7 @@ public abstract class ActionsSerializer {
     private static final byte SET_QUEUE_LENGTH = 8;
     private static final byte GROUP_LENGTH = 8;
     private static final byte SET_NW_TTL_LENGTH = 8;
-    private static final byte EXPERIMENTER_LENGTH = 8;
+    private static final byte EXPERIMENTER_ACTION_HEADER_LENGTH = 8;
     private static final byte ACTION_HEADER_LENGTH = 8;
     private static final byte LENGTH_OF_ETHERTYPE_ACTION = 8;
     private static final byte LENGTH_OF_OTHER_ACTIONS = 8;
@@ -293,9 +293,15 @@ public abstract class ActionsSerializer {
 
     private static void encodeExperimenterAction(Action action, ByteBuf outBuffer) {
         outBuffer.writeShort(EXPERIMENTER_CODE);
-        outBuffer.writeShort(EXPERIMENTER_LENGTH);
         ExperimenterAction experimenter = action.getAugmentation(ExperimenterAction.class);
-        outBuffer.writeInt(experimenter.getExperimenter().intValue());
+        if (experimenter.getData() != null) {
+            outBuffer.writeShort(EXPERIMENTER_ACTION_HEADER_LENGTH + experimenter.getData().length);
+            outBuffer.writeInt(experimenter.getExperimenter().intValue());
+            outBuffer.writeBytes(experimenter.getData());
+        } else {
+            outBuffer.writeShort(EXPERIMENTER_ACTION_HEADER_LENGTH);
+            outBuffer.writeInt(experimenter.getExperimenter().intValue());
+        }
     }
     
     private static void encodeRestOfActionHeader(ByteBuf outBuffer) {
index d7f79c8cb5be72e647e32cd1da1f66f4fb3dd6ff..a63edea95735bf90c54ff2624fd5b25cf1e71df5 100644 (file)
@@ -14,6 +14,7 @@ import java.util.List;
 import org.junit.Assert;\r
 import org.junit.Test;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeAction;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterAction;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.GroupIdAction;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsTtlAction;\r
@@ -55,7 +56,8 @@ public class ActionsDeserializerTest {
                 + "00 18 00 08 00 00 00 00 "\r
                 + "00 19 00 10 80 00 02 04 00 00 00 0B 00 00 00 00 "\r
                 + "00 1A 00 08 00 0A 00 00 "\r
-                + "00 1B 00 08 00 00 00 00");\r
+                + "00 1B 00 08 00 00 00 00 "\r
+                + "FF FF 00 10 00 00 00 08 00 01 02 03 04 05 06 07");\r
         \r
         message.skipBytes(4); // skip XID\r
         LOGGER.info("bytes: " + message.readableBytes());\r
@@ -121,6 +123,12 @@ public class ActionsDeserializerTest {
                 actions.get(14).getAugmentation(EthertypeAction.class).getEthertype().getValue().intValue());\r
         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."\r
                 + "openflow.common.action.rev130731.PopPbb", actions.get(15).getType().getName());\r
+        Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."\r
+                + "openflow.common.action.rev130731.Experimenter", actions.get(16).getType().getName());\r
+        Assert.assertEquals("Wrong experimenter", 8, actions.get(16).getAugmentation(ExperimenterAction.class)\r
+                .getExperimenter().intValue());\r
+        Assert.assertArrayEquals("Wrong data", new byte[]{0, 1, 2, 3, 4, 5, 6, 7}, actions.get(16)\r
+                .getAugmentation(ExperimenterAction.class).getData());\r
         Assert.assertTrue("Unread data in message", message.readableBytes() == 0);\r
     }\r
 \r
index 20d5e17969d2bf5bad318e4f03aecc19db6feb5b..14f50d0be944fcf062df7d5baaca163855bb02d9 100644 (file)
@@ -167,6 +167,7 @@ public class ActionsSerializerTest {
         actionBuilder.setType(Experimenter.class);\r
         ExperimenterActionBuilder experimenter = new ExperimenterActionBuilder();\r
         experimenter.setExperimenter(4L);\r
+        experimenter.setData(new byte[]{0, 1, 2, 3, 4, 5, 6, 7});\r
         actionBuilder.addAugmentation(ExperimenterAction.class, experimenter.build());\r
         actions.add(actionBuilder.build());\r
         \r
@@ -234,8 +235,12 @@ public class ActionsSerializerTest {
         Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());\r
         out.skipBytes(4);\r
         Assert.assertEquals("Wrong action type", 65535, out.readUnsignedShort());\r
-        Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());\r
-        Assert.assertEquals("Wrong action experimenter", 4, out.readUnsignedInt());\r
+        Assert.assertEquals("Wrong action length", 16, out.readUnsignedShort());\r
+        Assert.assertEquals("Wrong experimenter", 4, out.readUnsignedInt());\r
+        byte[] data = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];\r
+        out.readBytes(data);\r
+        Assert.assertArrayEquals("Wrong data", new byte[]{0, 1, 2, 3, 4, 5, 6, 7}, data);\r
+        Assert.assertTrue("Unread data", out.readableBytes() == 0);\r
     }\r
 \r
 }\r