package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;
import io.netty.buffer.ByteBuf;
-import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import org.junit.Assert;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.Match;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.MatchBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput;
+import org.opendaylight.yangtools.yang.common.Uint16;
+import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.common.Uint64;
+import org.opendaylight.yangtools.yang.common.Uint8;
/**
- * @author giuseppex.petralia@intel.com
+ * Unit tests for FlowModInputMessageFactory.
*
+ * @author giuseppex.petralia@intel.com
*/
public class FlowModInputMessageFactoryTest {
private OFDeserializer<FlowModInput> flowFactory;
/**
- * Initializes deserializer registry and lookups correct deserializer
+ * Initializes deserializer registry and lookups correct deserializer.
*/
@Before
public void startUp() {
DeserializerRegistry registry = new DeserializerRegistryImpl();
registry.init();
flowFactory = registry
- .getDeserializer(new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 14, FlowModInput.class));
+ .getDeserializer(new MessageCodeKey(EncodeConstants.OF_VERSION_1_3, 14, FlowModInput.class));
}
@Test
- public void test() throws Exception {
- ByteBuf bb = BufferHelper
- .buildBuffer("ff 01 04 01 06 00 07 01 ff 05 00 00 09 30 00 30 41 02 00 0c 00 00 00 7e 00 "
- + "00 00 02 00 00 11 46 00 00 00 62 00 0b 00 00 00 01 00 11 80 00 02 04 00 00 00 2a 80 00 12 01 04 00 "
- + "00 00 00 00 00 00 00 01 00 08 2b 00 00 00 00 02 00 18 00 00 00 00 ff 01 04 01 06 00 07 01 ff 05 00 00 "
- + "09 30 00 30 00 04 00 18 00 00 00 00 00 00 00 10 00 00 00 2a 00 34 00 00 00 00 00 00");
+ public void test() {
+ ByteBuf bb = BufferHelper.buildBuffer(
+ "ff 01 04 01 06 00 07 01 ff 05 00 00 09 30 00 30 41 02 00 0c 00 00 00 7e 00 "
+ + "00 00 02 00 00 11 46 00 00 00 62 00 0b 00 00 00 01 00 11 80 00 02 04 00 00 00 2a 80 00 12 01 04 00 "
+ + "00 00 00 00 00 00 00 01 00 08 2b 00 00 00 00 02 00 18 00 00 00 00 ff 01 04 01 06 00 07 01 ff 05 00 00 "
+ + "09 30 00 30 00 04 00 18 00 00 00 00 00 00 00 10 00 00 00 2a 00 34 00 00 00 00 00 00");
FlowModInput deserializedMessage = BufferHelper.deserialize(flowFactory, bb);
BufferHelper.checkHeaderV13(deserializedMessage);
- byte[] cookie = new byte[] { (byte) 0xFF, 0x01, 0x04, 0x01, 0x06, 0x00, 0x07, 0x01 };
- Assert.assertEquals("Wrong cookie", new BigInteger(1, cookie), deserializedMessage.getCookie());
- byte[] cookieMask = new byte[] { (byte) 0xFF, 0x05, 0x00, 0x00, 0x09, 0x30, 0x00, 0x30 };
- Assert.assertEquals("Wrong cookie mask", new BigInteger(1, cookieMask), deserializedMessage.getCookieMask());
- Assert.assertEquals("Wrong table id", new TableId(65L), deserializedMessage.getTableId());
+ Assert.assertEquals("Wrong cookie", Uint64.valueOf("FF01040106000701", 16), deserializedMessage.getCookie());
+ Assert.assertEquals("Wrong cookie mask", Uint64.valueOf("FF05000009300030", 16),
+ deserializedMessage.getCookieMask());
+ Assert.assertEquals("Wrong table id", new TableId(Uint32.valueOf(65)), deserializedMessage.getTableId());
Assert.assertEquals("Wrong command", FlowModCommand.forValue(2), deserializedMessage.getCommand());
Assert.assertEquals("Wrong idle timeout", 12, deserializedMessage.getIdleTimeout().intValue());
Assert.assertEquals("Wrong hard timeout", 0, deserializedMessage.getHardTimeout().intValue());
Assert.assertEquals("Wrong priority", 126, deserializedMessage.getPriority().intValue());
Assert.assertEquals("Wrong buffer id ", 2L, deserializedMessage.getBufferId().longValue());
- Assert.assertEquals("Wrong out port", new PortNumber(4422L), deserializedMessage.getOutPort());
+ Assert.assertEquals("Wrong out port", new PortNumber(Uint32.valueOf(4422)), deserializedMessage.getOutPort());
Assert.assertEquals("Wrong out group", 98L, deserializedMessage.getOutGroup().longValue());
Assert.assertEquals("Wrong flags", new FlowModFlags(true, false, true, false, true),
deserializedMessage.getFlags());
}
- private List<Instruction> createInstructions() {
- List<Instruction> instructions = new ArrayList<>();
+ private static List<Instruction> createInstructions() {
+ final List<Instruction> instructions = new ArrayList<>();
InstructionBuilder insBuilder = new InstructionBuilder();
GotoTableCaseBuilder goToCaseBuilder = new GotoTableCaseBuilder();
GotoTableBuilder instructionBuilder = new GotoTableBuilder();
- instructionBuilder.setTableId((short) 43);
+ instructionBuilder.setTableId(Uint8.valueOf(43));
goToCaseBuilder.setGotoTable(instructionBuilder.build());
insBuilder.setInstructionChoice(goToCaseBuilder.build());
instructions.add(insBuilder.build());
insBuilder.setInstructionChoice(metadataCaseBuilder.build());
instructions.add(insBuilder.build());
insBuilder = new InstructionBuilder();
- ApplyActionsCaseBuilder applyActionsCaseBuilder = new ApplyActionsCaseBuilder();
- ApplyActionsBuilder actionsBuilder = new ApplyActionsBuilder();
- List<Action> actions = new ArrayList<>();
- ActionBuilder actionBuilder = new ActionBuilder();
+ final ApplyActionsCaseBuilder applyActionsCaseBuilder = new ApplyActionsCaseBuilder();
+ final ApplyActionsBuilder actionsBuilder = new ApplyActionsBuilder();
+ final List<Action> actions = new ArrayList<>();
+ final ActionBuilder actionBuilder = new ActionBuilder();
OutputActionCaseBuilder caseBuilder = new OutputActionCaseBuilder();
OutputActionBuilder outputBuilder = new OutputActionBuilder();
- outputBuilder.setPort(new PortNumber(42L));
- outputBuilder.setMaxLength(52);
+ outputBuilder.setPort(new PortNumber(Uint32.valueOf(42)));
+ outputBuilder.setMaxLength(Uint16.valueOf(52));
caseBuilder.setOutputAction(outputBuilder.build());
actionBuilder.setActionChoice(caseBuilder.build());
actions.add(actionBuilder.build());
return instructions;
}
- private Match createMatch() {
+ private static Match createMatch() {
MatchBuilder matchBuilder = new MatchBuilder();
- matchBuilder.setType(OxmMatchType.class);
- List<MatchEntry> entries = new ArrayList<>();
+ matchBuilder.setType(OxmMatchType.VALUE);
+ final List<MatchEntry> entries = new ArrayList<>();
MatchEntryBuilder entriesBuilder = new MatchEntryBuilder();
- entriesBuilder.setOxmClass(OpenflowBasicClass.class);
- entriesBuilder.setOxmMatchField(InPhyPort.class);
+ entriesBuilder.setOxmClass(OpenflowBasicClass.VALUE);
+ entriesBuilder.setOxmMatchField(InPhyPort.VALUE);
entriesBuilder.setHasMask(false);
InPhyPortCaseBuilder inPhyPortCaseBuilder = new InPhyPortCaseBuilder();
InPhyPortBuilder inPhyPortBuilder = new InPhyPortBuilder();
- inPhyPortBuilder.setPortNumber(new PortNumber(42L));
+ inPhyPortBuilder.setPortNumber(new PortNumber(Uint32.valueOf(42)));
inPhyPortCaseBuilder.setInPhyPort(inPhyPortBuilder.build());
entriesBuilder.setMatchEntryValue(inPhyPortCaseBuilder.build());
entries.add(entriesBuilder.build());
- entriesBuilder.setOxmClass(OpenflowBasicClass.class);
- entriesBuilder.setOxmMatchField(IpEcn.class);
+ entriesBuilder.setOxmClass(OpenflowBasicClass.VALUE);
+ entriesBuilder.setOxmMatchField(IpEcn.VALUE);
entriesBuilder.setHasMask(false);
IpEcnCaseBuilder ipEcnCaseBuilder = new IpEcnCaseBuilder();
IpEcnBuilder ipEcnBuilder = new IpEcnBuilder();
- ipEcnBuilder.setEcn((short) 4);
+ ipEcnBuilder.setEcn(Uint8.valueOf(4));
ipEcnCaseBuilder.setIpEcn(ipEcnBuilder.build());
entriesBuilder.setMatchEntryValue(ipEcnCaseBuilder.build());
entries.add(entriesBuilder.build());
matchBuilder.setMatchEntry(entries);
return matchBuilder.build();
}
-
}