Add Instruction serializers 73/48773/13
authorTomas Slusny <tomas.slusny@pantheon.tech>
Tue, 29 Nov 2016 09:49:45 +0000 (10:49 +0100)
committerTomas Slusny <tomas.slusny@pantheon.tech>
Wed, 14 Dec 2016 17:11:58 +0000 (17:11 +0000)
Inject instruction serializers into InstructionSerializerInjector.
These serializers will serialize these intrusctions to raw bytes:

  - ApplyActions
  - ClearActions
  - GoToTable
  - Meter
  - WriteActions
  - WriteMetadata

Change-Id: I72a254b897234b3e7f29c0ea2d1496f0bc517e43
Signed-off-by: Tomas Slusny <tomas.slusny@pantheon.tech>
13 files changed:
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/InstructionSerializerInjector.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/instructions/ApplyActionsInstructionSerializer.java [new file with mode: 0644]
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/instructions/ClearActionsInstructionSerializer.java [new file with mode: 0644]
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/instructions/GoToTableInstructionSerializer.java [new file with mode: 0644]
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/instructions/MeterInstructionSerializer.java [new file with mode: 0644]
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/instructions/WriteActionsInstructionSerializer.java [new file with mode: 0644]
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/instructions/WriteMetadataInstructionSerializer.java [new file with mode: 0644]
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/instructions/ApplyActionsInstructionSerializerTest.java [new file with mode: 0644]
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/instructions/ClearActionsInstructionSerializerTest.java [new file with mode: 0644]
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/instructions/GoToTableInstructionSerializerTest.java [new file with mode: 0644]
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/instructions/MeterInstructionSerializerTest.java [new file with mode: 0644]
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/instructions/WriteActionsInstructionSerializerTest.java [new file with mode: 0644]
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/instructions/WriteMetadataInstructionSerializerTest.java [new file with mode: 0644]

index a75d200da5c17c6d501df0e3c3b174eb201d8b26..e39a103ff6a4b05ee28c3cbb82fe8e5fbd034fea 100644 (file)
@@ -15,7 +15,19 @@ import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerExtensionProvider;
 import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey;
 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.openflowplugin.impl.protocol.serialization.instructions.ApplyActionsInstructionSerializer;
+import org.opendaylight.openflowplugin.impl.protocol.serialization.instructions.ClearActionsInstructionSerializer;
+import org.opendaylight.openflowplugin.impl.protocol.serialization.instructions.GoToTableInstructionSerializer;
+import org.opendaylight.openflowplugin.impl.protocol.serialization.instructions.MeterInstructionSerializer;
+import org.opendaylight.openflowplugin.impl.protocol.serialization.instructions.WriteActionsInstructionSerializer;
+import org.opendaylight.openflowplugin.impl.protocol.serialization.instructions.WriteMetadataInstructionSerializer;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ClearActionsCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.GoToTableCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.MeterCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteActionsCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteMetadataCase;
 
 /**
  * Util class for injecting new instruction serializers into OpenflowJava
@@ -30,6 +42,12 @@ class InstructionSerializerInjector {
         // Inject new instruction serializers here using injector created by createInjector method
         final Function<Class<? extends Instruction>, Consumer<OFSerializer<? extends Instruction>>> injector =
                 createInjector(provider, EncodeConstants.OF13_VERSION_ID);
+        injector.apply(ApplyActionsCase.class).accept(new ApplyActionsInstructionSerializer());
+        injector.apply(ClearActionsCase.class).accept(new ClearActionsInstructionSerializer());
+        injector.apply(GoToTableCase.class).accept(new GoToTableInstructionSerializer());
+        injector.apply(MeterCase.class).accept(new MeterInstructionSerializer());
+        injector.apply(WriteActionsCase.class).accept(new WriteActionsInstructionSerializer());
+        injector.apply(WriteMetadataCase.class).accept(new WriteMetadataInstructionSerializer());
     }
 
     /**
diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/instructions/ApplyActionsInstructionSerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/instructions/ApplyActionsInstructionSerializer.java
new file mode 100644 (file)
index 0000000..87235d5
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2016 Pantheon Technologies s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.openflowplugin.impl.protocol.serialization.instructions;
+
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.openflowjava.protocol.impl.util.InstructionConstants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase;
+
+public class ApplyActionsInstructionSerializer extends AbstractActionInstructionSerializer {
+
+    @Override
+    public void serialize(Instruction input, ByteBuf outBuffer) {
+        int index = outBuffer.writerIndex();
+        super.serialize(input, outBuffer);
+        writeActions(ApplyActionsCase.class.cast(input).getApplyActions(),
+                EncodeConstants.OF13_VERSION_ID, outBuffer,index);
+    }
+
+    @Override
+    protected int getType() {
+        return InstructionConstants.APPLY_ACTIONS_TYPE;
+    }
+
+    @Override
+    protected int getLength() {
+        return InstructionConstants.STANDARD_INSTRUCTION_LENGTH;
+    }
+
+}
diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/instructions/ClearActionsInstructionSerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/instructions/ClearActionsInstructionSerializer.java
new file mode 100644 (file)
index 0000000..6e85ba5
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2016 Pantheon Technologies s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.openflowplugin.impl.protocol.serialization.instructions;
+
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.openflowjava.protocol.impl.util.InstructionConstants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction;
+
+public class ClearActionsInstructionSerializer extends AbstractInstructionSerializer {
+
+    @Override
+    public void serialize(Instruction input, ByteBuf outBuffer) {
+        super.serialize(input, outBuffer);
+        outBuffer.writeZero(InstructionConstants.PADDING_IN_ACTIONS_INSTRUCTION);
+    }
+
+    @Override
+    protected int getType() {
+        return InstructionConstants.CLEAR_ACTIONS_TYPE;
+    }
+
+    @Override
+    protected int getLength() {
+        return InstructionConstants.STANDARD_INSTRUCTION_LENGTH;
+    }
+
+}
diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/instructions/GoToTableInstructionSerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/instructions/GoToTableInstructionSerializer.java
new file mode 100644 (file)
index 0000000..dc0a384
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2016 Pantheon Technologies s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.openflowplugin.impl.protocol.serialization.instructions;
+
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.openflowjava.protocol.impl.util.InstructionConstants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.GoToTableCase;
+
+public class GoToTableInstructionSerializer extends AbstractInstructionSerializer {
+
+    @Override
+    public void serialize(Instruction input, ByteBuf outBuffer) {
+        super.serialize(input, outBuffer);
+        outBuffer.writeByte(GoToTableCase.class.cast(input).getGoToTable().getTableId());
+        outBuffer.writeZero(InstructionConstants.PADDING_IN_GOTO_TABLE);
+    }
+
+    @Override
+    protected int getType() {
+        return InstructionConstants.GOTO_TABLE_TYPE;
+    }
+
+    @Override
+    protected int getLength() {
+        return InstructionConstants.STANDARD_INSTRUCTION_LENGTH;
+    }
+
+}
diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/instructions/MeterInstructionSerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/instructions/MeterInstructionSerializer.java
new file mode 100644 (file)
index 0000000..0e5e042
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2016 Pantheon Technologies s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.openflowplugin.impl.protocol.serialization.instructions;
+
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.openflowjava.protocol.impl.util.InstructionConstants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.MeterCase;
+
+public class MeterInstructionSerializer extends AbstractInstructionSerializer {
+
+    @Override
+    public void serialize(Instruction input, ByteBuf outBuffer) {
+        super.serialize(input, outBuffer);
+        outBuffer.writeInt(MeterCase.class.cast(input).getMeter().getMeterId().getValue().intValue());
+    }
+
+    @Override
+    protected int getType() {
+        return InstructionConstants.METER_TYPE;
+    }
+
+    @Override
+    protected int getLength() {
+        return InstructionConstants.STANDARD_INSTRUCTION_LENGTH;
+    }
+
+}
diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/instructions/WriteActionsInstructionSerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/instructions/WriteActionsInstructionSerializer.java
new file mode 100644 (file)
index 0000000..75561ad
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2016 Pantheon Technologies s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.openflowplugin.impl.protocol.serialization.instructions;
+
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.openflowjava.protocol.impl.util.InstructionConstants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteActionsCase;
+
+public class WriteActionsInstructionSerializer extends AbstractActionInstructionSerializer {
+
+    @Override
+    public void serialize(Instruction input, ByteBuf outBuffer) {
+        int index = outBuffer.writerIndex();
+        super.serialize(input, outBuffer);
+        writeActions(WriteActionsCase.class.cast(input).getWriteActions(),
+                EncodeConstants.OF13_VERSION_ID, outBuffer,index);
+    }
+
+    @Override
+    protected int getType() {
+        return InstructionConstants.WRITE_ACTIONS_TYPE;
+    }
+
+    @Override
+    protected int getLength() {
+        return InstructionConstants.STANDARD_INSTRUCTION_LENGTH;
+    }
+
+}
diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/instructions/WriteMetadataInstructionSerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/instructions/WriteMetadataInstructionSerializer.java
new file mode 100644 (file)
index 0000000..eb4f292
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2016 Pantheon Technologies s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.openflowplugin.impl.protocol.serialization.instructions;
+
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.openflowjava.protocol.impl.util.InstructionConstants;
+import org.opendaylight.openflowplugin.openflow.md.util.ByteUtil;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteMetadataCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.write.metadata._case.WriteMetadata;
+
+public class WriteMetadataInstructionSerializer extends AbstractInstructionSerializer {
+
+    @Override
+    public void serialize(Instruction input, ByteBuf outBuffer) {
+        super.serialize(input, outBuffer);
+        final WriteMetadata writeMetadata = WriteMetadataCase.class.cast(input).getWriteMetadata();
+        outBuffer.writeZero(InstructionConstants.PADDING_IN_WRITE_METADATA);
+        outBuffer.writeBytes(ByteUtil.convertBigIntegerToNBytes(writeMetadata.getMetadata(), EncodeConstants.SIZE_OF_LONG_IN_BYTES));
+        outBuffer.writeBytes(ByteUtil.convertBigIntegerToNBytes(writeMetadata.getMetadataMask(), EncodeConstants.SIZE_OF_LONG_IN_BYTES));
+    }
+
+    @Override
+    protected int getType() {
+        return InstructionConstants.WRITE_METADATA_TYPE;
+    }
+
+    @Override
+    protected int getLength() {
+        return InstructionConstants.WRITE_METADATA_LENGTH;
+    }
+
+}
diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/instructions/ApplyActionsInstructionSerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/instructions/ApplyActionsInstructionSerializerTest.java
new file mode 100644 (file)
index 0000000..d4e4d87
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2016 Pantheon Technologies s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.openflowplugin.impl.protocol.serialization.instructions;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+import java.util.Collections;
+import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
+import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants;
+import org.opendaylight.openflowjava.protocol.impl.util.InstructionConstants;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.src.action._case.SetNwSrcActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder;
+
+public class ApplyActionsInstructionSerializerTest extends AbstractInstructionSerializerTest {
+
+    @Test
+    public void testSerialize() throws Exception {
+        final int order = 0;
+        final Ipv4Prefix prefix = new Ipv4Prefix("192.168.76.0/32");
+
+        final Instruction instruction = new ApplyActionsCaseBuilder()
+                .setApplyActions(new ApplyActionsBuilder()
+                        .setAction(Collections.singletonList(new ActionBuilder()
+                                .setOrder(order)
+                                .setKey(new ActionKey(order))
+                                .setAction(new SetNwSrcActionCaseBuilder()
+                                        .setSetNwSrcAction(new SetNwSrcActionBuilder()
+                                                .setAddress(new Ipv4Builder()
+                                                        .setIpv4Address(prefix)
+                                                .build())
+                                        .build())
+                                        .build())
+                                .build()))
+                        .build())
+                .build();
+
+        assertInstruction(instruction, out -> {
+            out.skipBytes(InstructionConstants.PADDING_IN_ACTIONS_INSTRUCTION);
+            assertEquals(out.readUnsignedShort(), ActionConstants.SET_FIELD_CODE);
+            out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); // Skip length of set field action
+            assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS);
+            assertEquals(out.readUnsignedByte(), OxmMatchConstants.IPV4_SRC << 1);
+            out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); // Skip match entry length
+
+            byte[] addressBytes = new byte[4];
+            out.readBytes(addressBytes);
+            assertArrayEquals(addressBytes, new byte[] { (byte) 192, (byte) 168, 76, 0 });
+
+            out.skipBytes(4); // Padding at end
+        });
+    }
+
+    @Override
+    protected Class<? extends Instruction> getClazz() {
+        return ApplyActionsCase.class;
+    }
+
+    @Override
+    protected int getType() {
+        return InstructionConstants.APPLY_ACTIONS_TYPE;
+    }
+
+    @Override
+    protected int getLength() {
+        return 24;
+    }
+
+}
diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/instructions/ClearActionsInstructionSerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/instructions/ClearActionsInstructionSerializerTest.java
new file mode 100644 (file)
index 0000000..876907d
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2016 Pantheon Technologies s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.openflowplugin.impl.protocol.serialization.instructions;
+
+import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.impl.util.InstructionConstants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ClearActionsCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ClearActionsCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.clear.actions._case.ClearActionsBuilder;
+
+public class ClearActionsInstructionSerializerTest extends AbstractInstructionSerializerTest {
+
+    @Test
+    public void testSerialize() throws Exception {
+        final Instruction instruction = new ClearActionsCaseBuilder()
+                .setClearActions(new ClearActionsBuilder()
+                        .build())
+                .build();
+
+        assertInstruction(instruction, out -> out.skipBytes(InstructionConstants.PADDING_IN_ACTIONS_INSTRUCTION));
+    }
+
+    @Override
+    protected Class<? extends Instruction> getClazz() {
+        return ClearActionsCase.class;
+    }
+
+    @Override
+    protected int getType() {
+        return InstructionConstants.CLEAR_ACTIONS_TYPE;
+    }
+
+    @Override
+    protected int getLength() {
+        return InstructionConstants.STANDARD_INSTRUCTION_LENGTH;
+    }
+
+}
diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/instructions/GoToTableInstructionSerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/instructions/GoToTableInstructionSerializerTest.java
new file mode 100644 (file)
index 0000000..fc130ce
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2016 Pantheon Technologies s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.openflowplugin.impl.protocol.serialization.instructions;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.impl.util.InstructionConstants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.GoToTableCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.GoToTableCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.go.to.table._case.GoToTableBuilder;
+
+public class GoToTableInstructionSerializerTest extends AbstractInstructionSerializerTest {
+
+    @Test
+    public void testSerialize() throws Exception {
+        final short table = 2;
+
+        final Instruction instruction = new GoToTableCaseBuilder()
+                .setGoToTable(new GoToTableBuilder()
+                        .setTableId(table)
+                        .build())
+                .build();
+
+        assertInstruction(instruction, out -> {
+            assertEquals(out.readUnsignedByte(), table);
+            out.skipBytes(InstructionConstants.PADDING_IN_GOTO_TABLE);
+        });
+    }
+
+    @Override
+    protected Class<? extends Instruction> getClazz() {
+        return GoToTableCase.class;
+    }
+
+    @Override
+    protected int getType() {
+        return InstructionConstants.GOTO_TABLE_TYPE;
+    }
+
+    @Override
+    protected int getLength() {
+        return InstructionConstants.STANDARD_INSTRUCTION_LENGTH;
+    }
+
+}
\ No newline at end of file
diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/instructions/MeterInstructionSerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/instructions/MeterInstructionSerializerTest.java
new file mode 100644 (file)
index 0000000..090b58c
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2016 Pantheon Technologies s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.openflowplugin.impl.protocol.serialization.instructions;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.impl.util.InstructionConstants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.MeterCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.MeterCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.meter._case.MeterBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId;
+
+public class MeterInstructionSerializerTest extends AbstractInstructionSerializerTest {
+
+    @Test
+    public void testSerialize() throws Exception {
+        final long meter = 2;
+
+        final Instruction instruction = new MeterCaseBuilder()
+                .setMeter(new MeterBuilder()
+                        .setMeterId(new MeterId(meter))
+                        .build())
+                .build();
+
+        assertInstruction(instruction, out -> assertEquals(out.readUnsignedInt(), meter));
+    }
+
+    @Override
+    protected Class<? extends Instruction> getClazz() {
+        return MeterCase.class;
+    }
+
+    @Override
+    protected int getType() {
+        return InstructionConstants.METER_TYPE;
+    }
+
+    @Override
+    protected int getLength() {
+        return InstructionConstants.STANDARD_INSTRUCTION_LENGTH;
+    }
+
+}
diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/instructions/WriteActionsInstructionSerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/instructions/WriteActionsInstructionSerializerTest.java
new file mode 100644 (file)
index 0000000..bf2587f
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2016 Pantheon Technologies s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.openflowplugin.impl.protocol.serialization.instructions;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+import java.util.Collections;
+import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
+import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants;
+import org.opendaylight.openflowjava.protocol.impl.util.InstructionConstants;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.src.action._case.SetNwSrcActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteActionsCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteActionsCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.write.actions._case.WriteActionsBuilder;
+
+public class WriteActionsInstructionSerializerTest extends AbstractInstructionSerializerTest {
+
+    @Test
+    public void testSerialize() throws Exception {
+        final int order = 0;
+        final Ipv4Prefix prefix = new Ipv4Prefix("192.168.76.0/32");
+
+        final Instruction instruction = new WriteActionsCaseBuilder()
+                .setWriteActions(new WriteActionsBuilder()
+                        .setAction(Collections.singletonList(new ActionBuilder()
+                                .setOrder(order)
+                                .setKey(new ActionKey(order))
+                                .setAction(new SetNwSrcActionCaseBuilder()
+                                        .setSetNwSrcAction(new SetNwSrcActionBuilder()
+                                                .setAddress(new Ipv4Builder()
+                                                        .setIpv4Address(prefix)
+                                                .build())
+                                        .build())
+                                        .build())
+                                .build()))
+                        .build())
+                .build();
+
+        assertInstruction(instruction, out -> {
+            out.skipBytes(InstructionConstants.PADDING_IN_ACTIONS_INSTRUCTION);
+            assertEquals(out.readUnsignedShort(), ActionConstants.SET_FIELD_CODE);
+            out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); // Skip length of set field action
+            assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS);
+            assertEquals(out.readUnsignedByte(), OxmMatchConstants.IPV4_SRC << 1);
+            out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); // Skip match entry length
+
+            byte[] addressBytes = new byte[4];
+            out.readBytes(addressBytes);
+            assertArrayEquals(addressBytes, new byte[] { (byte) 192, (byte) 168, 76, 0 });
+
+            out.skipBytes(4); // Padding at end
+        });
+    }
+
+    @Override
+    protected Class<? extends Instruction> getClazz() {
+        return WriteActionsCase.class;
+    }
+
+    @Override
+    protected int getType() {
+        return InstructionConstants.WRITE_ACTIONS_TYPE;
+    }
+
+    @Override
+    protected int getLength() {
+        return 24;
+    }
+
+}
diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/instructions/WriteMetadataInstructionSerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/instructions/WriteMetadataInstructionSerializerTest.java
new file mode 100644 (file)
index 0000000..10b0d81
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2016 Pantheon Technologies s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.openflowplugin.impl.protocol.serialization.instructions;
+
+import static org.junit.Assert.assertEquals;
+
+import java.math.BigInteger;
+import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.impl.util.InstructionConstants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteMetadataCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteMetadataCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.write.metadata._case.WriteMetadataBuilder;
+
+public class WriteMetadataInstructionSerializerTest extends AbstractInstructionSerializerTest {
+
+    @Test
+    public void testSerialize() throws Exception {
+        final long metadata = 10L;
+        final long metadataMask = 10L;
+
+        final Instruction instruction = new WriteMetadataCaseBuilder()
+                .setWriteMetadata(new WriteMetadataBuilder()
+                        .setMetadata(BigInteger.valueOf(metadata))
+                        .setMetadataMask(BigInteger.valueOf(metadataMask))
+                        .build())
+                .build();
+
+        assertInstruction(instruction, out -> {
+            out.skipBytes(InstructionConstants.PADDING_IN_WRITE_METADATA);
+            assertEquals(out.readLong(), metadata);
+            assertEquals(out.readLong(), metadataMask);
+        });
+    }
+
+    @Override
+    protected Class<? extends Instruction> getClazz() {
+        return WriteMetadataCase.class;
+    }
+
+    @Override
+    protected int getType() {
+        return InstructionConstants.WRITE_METADATA_TYPE;
+    }
+
+    @Override
+    protected int getLength() {
+        return InstructionConstants.WRITE_METADATA_LENGTH;
+    }
+
+}