From: Michal Polkorab Date: Thu, 20 Mar 2014 10:53:59 +0000 (+0100) Subject: Bug 755 - Fixed ExperimenterAction X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=43bd504b4692ef655187cd4182585e8141d8611e;p=openflowjava.git Bug 755 - Fixed ExperimenterAction Signed-off-by: Michal Polkorab Change-Id: I6cd66ac6ecd35ddd17b9a489633a2443464e8581 (cherry picked from commit 6cd66ac6ecd35ddd17b9a489633a2443464e8581) --- diff --git a/openflow-protocol-api/src/main/yang/openflow-augments.yang b/openflow-protocol-api/src/main/yang/openflow-augments.yang index fb5e755e..a3ee05a9 100644 --- a/openflow-protocol-api/src/main/yang/openflow-augments.yang +++ b/openflow-protocol-api/src/main/yang/openflow-augments.yang @@ -228,6 +228,9 @@ leaf experimenter { type uint32; } + leaf data { + type binary; + } } // OF1.0 structures augment "/ofaction:actions-container/ofaction:action" { diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsDeserializer.java index b3175232..ab5d0847 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsDeserializer.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsDeserializer.java @@ -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(); } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsSerializer.java index 6c26cc2c..10cd78d7 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsSerializer.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsSerializer.java @@ -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) { diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsDeserializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsDeserializerTest.java index d7f79c8c..a63edea9 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsDeserializerTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsDeserializerTest.java @@ -14,6 +14,7 @@ import java.util.List; import org.junit.Assert; import org.junit.Test; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterAction; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.GroupIdAction; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsTtlAction; @@ -55,7 +56,8 @@ public class ActionsDeserializerTest { + "00 18 00 08 00 00 00 00 " + "00 19 00 10 80 00 02 04 00 00 00 0B 00 00 00 00 " + "00 1A 00 08 00 0A 00 00 " - + "00 1B 00 08 00 00 00 00"); + + "00 1B 00 08 00 00 00 00 " + + "FF FF 00 10 00 00 00 08 00 01 02 03 04 05 06 07"); message.skipBytes(4); // skip XID LOGGER.info("bytes: " + message.readableBytes()); @@ -121,6 +123,12 @@ public class ActionsDeserializerTest { actions.get(14).getAugmentation(EthertypeAction.class).getEthertype().getValue().intValue()); Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight." + "openflow.common.action.rev130731.PopPbb", actions.get(15).getType().getName()); + Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight." + + "openflow.common.action.rev130731.Experimenter", actions.get(16).getType().getName()); + Assert.assertEquals("Wrong experimenter", 8, actions.get(16).getAugmentation(ExperimenterAction.class) + .getExperimenter().intValue()); + Assert.assertArrayEquals("Wrong data", new byte[]{0, 1, 2, 3, 4, 5, 6, 7}, actions.get(16) + .getAugmentation(ExperimenterAction.class).getData()); Assert.assertTrue("Unread data in message", message.readableBytes() == 0); } diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsSerializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsSerializerTest.java index 20d5e179..14f50d0b 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsSerializerTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsSerializerTest.java @@ -167,6 +167,7 @@ public class ActionsSerializerTest { actionBuilder.setType(Experimenter.class); ExperimenterActionBuilder experimenter = new ExperimenterActionBuilder(); experimenter.setExperimenter(4L); + experimenter.setData(new byte[]{0, 1, 2, 3, 4, 5, 6, 7}); actionBuilder.addAugmentation(ExperimenterAction.class, experimenter.build()); actions.add(actionBuilder.build()); @@ -234,8 +235,12 @@ public class ActionsSerializerTest { Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort()); out.skipBytes(4); Assert.assertEquals("Wrong action type", 65535, out.readUnsignedShort()); - Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort()); - Assert.assertEquals("Wrong action experimenter", 4, out.readUnsignedInt()); + Assert.assertEquals("Wrong action length", 16, out.readUnsignedShort()); + Assert.assertEquals("Wrong experimenter", 4, out.readUnsignedInt()); + byte[] data = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; + out.readBytes(data); + Assert.assertArrayEquals("Wrong data", new byte[]{0, 1, 2, 3, 4, 5, 6, 7}, data); + Assert.assertTrue("Unread data", out.readableBytes() == 0); } }