private static final byte EXPERIMENTER_TYPE = 7;
private static final byte GOTO_TABLE_LENGTH = 8;
private static final byte WRITE_METADATA_LENGTH = 24;
- private static final byte WRITE_ACTIONS_LENGTH = 8;
- private static final byte APPLY_ACTIONS_LENGTH = 8;
- private static final byte CLEAR_ACTIONS_LENGTH = 8;
private static final byte METER_LENGTH = 8;
private static final byte EXPERIMENTER_LENGTH = 8;
+ private static final byte ACTIONS_INSTRUCTION_LENGTH = 8;
private static final byte PADDING_IN_GOTO_TABLE = 3;
private static final byte PADDING_IN_WRITE_METADATA = 4;
private static final byte PADDING_IN_CLEAR_ACTIONS = 4;
private static final byte INSTRUCTION_IDS_LENGTH = 4;
+ private static final byte PADDING_IN_ACTIONS_INSTRUCTION = 4;
/**
* Encodes instructions
} else if (type.isAssignableFrom(ApplyActions.class)) {
writeActionsInstruction(out, instruction, APPLY_ACTIONS_TYPE);
} else if (type.isAssignableFrom(ClearActions.class)) {
- writeTypeAndLength(out, CLEAR_ACTIONS_TYPE, CLEAR_ACTIONS_LENGTH);
+ writeTypeAndLength(out, CLEAR_ACTIONS_TYPE, ACTIONS_INSTRUCTION_LENGTH);
ByteBufUtils.padBuffer(PADDING_IN_CLEAR_ACTIONS, out);
} else if (type.isAssignableFrom(Meter.class)) {
writeTypeAndLength(out, METER_TYPE, METER_LENGTH);
private static void writeActionsInstruction(ByteBuf out,
Instructions instruction, int type) {
- final byte ACTIONS_INSTRUCTION_LENGTH = 8;
- final byte PADDING_IN_ACTIONS_INSTRUCTION = 4;
out.writeShort(type);
- List<ActionsList> actions = instruction.getAugmentation(ActionsInstruction.class).getActionsList();
- out.writeShort(ACTIONS_INSTRUCTION_LENGTH + ActionsSerializer.computeLengthOfActions(actions));
- ByteBufUtils.padBuffer(PADDING_IN_ACTIONS_INSTRUCTION, out);
- ActionsSerializer.encodeActions(actions, out);
+ if (instruction.getAugmentation(ActionsInstruction.class) != null) {
+ List<ActionsList> actions = instruction.getAugmentation(ActionsInstruction.class).getActionsList();
+ out.writeShort(ACTIONS_INSTRUCTION_LENGTH + ActionsSerializer.computeLengthOfActions(actions));
+ ByteBufUtils.padBuffer(PADDING_IN_ACTIONS_INSTRUCTION, out);
+ ActionsSerializer.encodeActions(actions, out);
+ } else {
+ out.writeShort(ACTIONS_INSTRUCTION_LENGTH);
+ ByteBufUtils.padBuffer(PADDING_IN_ACTIONS_INSTRUCTION, out);
+ }
}
/**
} else if (type.isAssignableFrom(WriteMetadata.class)) {
length += WRITE_METADATA_LENGTH;
} else if (type.isAssignableFrom(WriteActions.class)) {
- length += WRITE_ACTIONS_LENGTH + ActionsSerializer.computeLengthOfActions(
+ length += ACTIONS_INSTRUCTION_LENGTH;
+ if (instruction.getAugmentation(ActionsInstruction.class) != null) {
+ length += ActionsSerializer.computeLengthOfActions(
instruction.getAugmentation(ActionsInstruction.class).getActionsList());
+ }
} else if (type.isAssignableFrom(ApplyActions.class)) {
- length += APPLY_ACTIONS_LENGTH + ActionsSerializer.computeLengthOfActions(
- instruction.getAugmentation(ActionsInstruction.class).getActionsList());
+ length += ACTIONS_INSTRUCTION_LENGTH;
+ if (instruction.getAugmentation(ActionsInstruction.class) != null) {
+ length += ActionsSerializer.computeLengthOfActions(
+ instruction.getAugmentation(ActionsInstruction.class).getActionsList());
+ }
} else if (type.isAssignableFrom(ClearActions.class)) {
- length += CLEAR_ACTIONS_LENGTH;
+ length += ACTIONS_INSTRUCTION_LENGTH;
} else if (type.isAssignableFrom(Meter.class)) {
length += METER_LENGTH;
} else if (type.isAssignableFrom(Experimenter.class)) {
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntryBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TableIdInstruction;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TableIdInstructionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.ApplyActions;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.GotoTable;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteMetadata;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.Instructions;
metaBuilder.setMetadataMask(cookieMask);
insBuilder.addAugmentation(MetadataInstruction.class, metaBuilder.build());
instructions.add(insBuilder.build());
+ insBuilder = new InstructionsBuilder();
+ insBuilder.setType(ApplyActions.class);
+ insBuilder.addAugmentation(MetadataInstruction.class, metaBuilder.build());
+ instructions.add(insBuilder.build());
builder.setInstructions(instructions);
FlowModInput message = builder.build();
byte[] cookieMaskRead = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
out.readBytes(cookieMaskRead);
Assert.assertArrayEquals("Wrong metadata", cookie, cookieRead);
- Assert.assertArrayEquals("Wrong metadata mask", cookieMask, cookieMaskRead);
+ Assert.assertArrayEquals("Wrong metadata mask", cookieMask, cookieMaskRead);
+ Assert.assertEquals("Wrong instruction type", 4, out.readUnsignedShort());
+ Assert.assertEquals("Wrong instruction length", 8, out.readUnsignedShort());
+ out.skipBytes(4);
+ Assert.assertTrue("Unread data", out.readableBytes() == 0);
}
private static FlowModFlags createFlowModFlagsFromBitmap(int input){