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>
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
// 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());
}
/**
--- /dev/null
+/*
+ * 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;
+ }
+
+}
--- /dev/null
+/*
+ * 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;
+ }
+
+}
--- /dev/null
+/*
+ * 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;
+ }
+
+}
--- /dev/null
+/*
+ * 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;
+ }
+
+}
--- /dev/null
+/*
+ * 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;
+ }
+
+}
--- /dev/null
+/*
+ * 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;
+ }
+
+}
--- /dev/null
+/*
+ * 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;
+ }
+
+}
--- /dev/null
+/*
+ * 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;
+ }
+
+}
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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;
+ }
+
+}
--- /dev/null
+/*
+ * 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;
+ }
+
+}
--- /dev/null
+/*
+ * 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;
+ }
+
+}