use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput in project openflowplugin by opendaylight.
the class OF10FlowModInputMessageFactory method deserialize.
@Override
// FB doesn't recognize Objects.requireNonNull
@SuppressFBWarnings("UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR")
public FlowModInput deserialize(ByteBuf rawMessage) {
Objects.requireNonNull(registry);
FlowModInputBuilder builder = new FlowModInputBuilder();
builder.setVersion((short) EncodeConstants.OF10_VERSION_ID);
builder.setXid(rawMessage.readUnsignedInt());
OFDeserializer<MatchV10> matchDeserializer = registry.getDeserializer(new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, EncodeConstants.EMPTY_VALUE, MatchV10.class));
builder.setMatchV10(matchDeserializer.deserialize(rawMessage));
byte[] cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
rawMessage.readBytes(cookie);
builder.setCookie(new BigInteger(1, cookie));
builder.setCommand(FlowModCommand.forValue(rawMessage.readUnsignedShort()));
builder.setIdleTimeout(rawMessage.readUnsignedShort());
builder.setHardTimeout(rawMessage.readUnsignedShort());
builder.setPriority(rawMessage.readUnsignedShort());
builder.setBufferId(rawMessage.readUnsignedInt());
builder.setOutPort(new PortNumber((long) rawMessage.readUnsignedShort()));
builder.setFlagsV10(createFlowModFlagsFromBitmap(rawMessage.readUnsignedShort()));
CodeKeyMaker keyMaker = CodeKeyMakerFactory.createActionsKeyMaker(EncodeConstants.OF10_VERSION_ID);
List<Action> actions = ListDeserializer.deserializeList(EncodeConstants.OF10_VERSION_ID, rawMessage.readableBytes(), rawMessage, keyMaker, registry);
builder.setAction(actions);
return builder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput in project openflowplugin by opendaylight.
the class OF10FlowModInputMessageFactoryTest method test.
@Test
public void test() {
ByteBuf bb = BufferHelper.buildBuffer("00 38 20 ff 00 3a 01 01 01 01 01 01 ff " + "ff ff ff ff ff 00 12 05 00 00 2a 04 07 00 00 08 08 08 08 10 10 10 10 " + "19 fd 19 e9 ff 01 04 01 06 00 07 01 00 00 00 0c 00 10 00 01 00 00 00 02 " + "11 46 00 03 00 07 00 08 02 02 02 02 00 09 00 08 00 2a 00 00 ");
FlowModInput deserializedMessage = BufferHelper.deserialize(factory, bb);
BufferHelper.checkHeaderV10(deserializedMessage);
Assert.assertEquals("Wrong Match", createMatch(), deserializedMessage.getMatchV10());
byte[] cookie = new byte[] { (byte) 0xFF, 0x01, 0x04, 0x01, 0x06, 0x00, 0x07, 0x01 };
Assert.assertEquals("Wrong cookie", new BigInteger(1, cookie), deserializedMessage.getCookie());
Assert.assertEquals("Wrong command", FlowModCommand.forValue(0), deserializedMessage.getCommand());
Assert.assertEquals("Idle Timeout", 12, deserializedMessage.getIdleTimeout().intValue());
Assert.assertEquals("Wrong Hard Timeout", 16, deserializedMessage.getHardTimeout().intValue());
Assert.assertEquals("Wrong priority", 1, 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 flags", new FlowModFlagsV10(true, false, true), deserializedMessage.getFlagsV10());
Assert.assertEquals("Wrong actions", createAction(), deserializedMessage.getAction());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput in project openflowplugin by opendaylight.
the class FlowModInputMessageFactoryTest method test.
@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");
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 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 group", 98L, deserializedMessage.getOutGroup().longValue());
Assert.assertEquals("Wrong flags", new FlowModFlags(true, false, true, false, true), deserializedMessage.getFlags());
Assert.assertEquals("Wrong match", createMatch(), deserializedMessage.getMatch());
Assert.assertEquals("Wrong instructions", createInstructions(), deserializedMessage.getInstruction());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput in project openflowplugin by opendaylight.
the class FlowModInputMessageFactoryTest method testFlowModInputMessageFactory.
/**
* Testing of {@link FlowModInputMessageFactory} for correct translation from POJO.
*/
@Test
public void testFlowModInputMessageFactory() throws Exception {
FlowModInputBuilder builder = new FlowModInputBuilder();
BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
byte[] cookie = new byte[] { (byte) 0xFF, 0x01, 0x04, 0x01, 0x06, 0x00, 0x07, 0x01 };
builder.setCookie(new BigInteger(1, cookie));
byte[] cookieMask = new byte[] { (byte) 0xFF, 0x05, 0x00, 0x00, 0x09, 0x30, 0x00, 0x30 };
builder.setCookieMask(new BigInteger(1, cookieMask));
builder.setTableId(new TableId(65L));
builder.setCommand(FlowModCommand.forValue(2));
builder.setIdleTimeout(12);
builder.setHardTimeout(0);
builder.setPriority(126);
builder.setBufferId(2L);
builder.setOutPort(new PortNumber(4422L));
builder.setOutGroup(98L);
builder.setFlags(new FlowModFlags(true, false, true, false, true));
MatchBuilder matchBuilder = new MatchBuilder();
matchBuilder.setType(OxmMatchType.class);
final List<MatchEntry> entries = new ArrayList<>();
MatchEntryBuilder entriesBuilder = new MatchEntryBuilder();
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(InPhyPort.class);
entriesBuilder.setHasMask(false);
InPhyPortCaseBuilder inPhyPortCaseBuilder = new InPhyPortCaseBuilder();
InPhyPortBuilder inPhyPortBuilder = new InPhyPortBuilder();
inPhyPortBuilder.setPortNumber(new PortNumber(42L));
inPhyPortCaseBuilder.setInPhyPort(inPhyPortBuilder.build());
entriesBuilder.setMatchEntryValue(inPhyPortCaseBuilder.build());
entries.add(entriesBuilder.build());
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(IpEcn.class);
entriesBuilder.setHasMask(false);
IpEcnCaseBuilder ipEcnCaseBuilder = new IpEcnCaseBuilder();
IpEcnBuilder ipEcnBuilder = new IpEcnBuilder();
ipEcnBuilder.setEcn((short) 4);
ipEcnCaseBuilder.setIpEcn(ipEcnBuilder.build());
entriesBuilder.setMatchEntryValue(ipEcnCaseBuilder.build());
entries.add(entriesBuilder.build());
matchBuilder.setMatchEntry(entries);
builder.setMatch(matchBuilder.build());
final List<Instruction> instructions = new ArrayList<>();
InstructionBuilder insBuilder = new InstructionBuilder();
GotoTableCaseBuilder goToCaseBuilder = new GotoTableCaseBuilder();
GotoTableBuilder instructionBuilder = new GotoTableBuilder();
instructionBuilder.setTableId((short) 43);
goToCaseBuilder.setGotoTable(instructionBuilder.build());
insBuilder.setInstructionChoice(goToCaseBuilder.build());
instructions.add(insBuilder.build());
WriteMetadataCaseBuilder metadataCaseBuilder = new WriteMetadataCaseBuilder();
WriteMetadataBuilder metadataBuilder = new WriteMetadataBuilder();
metadataBuilder.setMetadata(cookie);
metadataBuilder.setMetadataMask(cookieMask);
metadataCaseBuilder.setWriteMetadata(metadataBuilder.build());
insBuilder.setInstructionChoice(metadataCaseBuilder.build());
instructions.add(insBuilder.build());
insBuilder = new InstructionBuilder();
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);
caseBuilder.setOutputAction(outputBuilder.build());
actionBuilder.setActionChoice(caseBuilder.build());
actions.add(actionBuilder.build());
actionsBuilder.setAction(actions);
applyActionsCaseBuilder.setApplyActions(actionsBuilder.build());
insBuilder.setInstructionChoice(applyActionsCaseBuilder.build());
instructions.add(insBuilder.build());
builder.setInstruction(instructions);
final FlowModInput message = builder.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
// simulate parent message
out.writeInt(1);
out.writeZero(2);
out.writeShort(3);
flowModFactory.serialize(message, out);
// read parent message
out.readInt();
out.skipBytes(2);
out.readShort();
BufferHelper.checkHeaderV13(out, (byte) 14, 128);
cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
out.readBytes(cookie);
Assert.assertEquals("Wrong cookie", message.getCookie(), new BigInteger(1, cookie));
cookieMask = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
out.readBytes(cookieMask);
Assert.assertEquals("Wrong cookieMask", message.getCookieMask(), new BigInteger(1, cookieMask));
Assert.assertEquals("Wrong tableId", message.getTableId().getValue().intValue(), out.readUnsignedByte());
Assert.assertEquals("Wrong command", message.getCommand().getIntValue(), out.readUnsignedByte());
Assert.assertEquals("Wrong idleTimeOut", message.getIdleTimeout().intValue(), out.readShort());
Assert.assertEquals("Wrong hardTimeOut", message.getHardTimeout().intValue(), out.readShort());
Assert.assertEquals("Wrong priority", message.getPriority().intValue(), out.readUnsignedShort());
Assert.assertEquals("Wrong bufferId", message.getBufferId().intValue(), out.readUnsignedInt());
Assert.assertEquals("Wrong outPort", message.getOutPort().getValue().intValue(), out.readUnsignedInt());
Assert.assertEquals("Wrong outGroup", message.getOutGroup().intValue(), out.readUnsignedInt());
Assert.assertEquals("Wrong flags", message.getFlags(), createFlowModFlagsFromBitmap(out.readUnsignedShort()));
out.skipBytes(PADDING_IN_FLOW_MOD_MESSAGE);
Assert.assertEquals("Wrong match type", 1, out.readUnsignedShort());
out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
Assert.assertEquals("Wrong oxm class", 0x8000, out.readUnsignedShort());
short fieldAndMask = out.readUnsignedByte();
Assert.assertEquals("Wrong oxm hasMask", 0, fieldAndMask & 1);
Assert.assertEquals("Wrong oxm field", 1, fieldAndMask >> 1);
out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
Assert.assertEquals("Wrong oxm value", 42, out.readUnsignedInt());
Assert.assertEquals("Wrong oxm class", 0x8000, out.readUnsignedShort());
fieldAndMask = out.readUnsignedByte();
Assert.assertEquals("Wrong oxm hasMask", 0, fieldAndMask & 1);
Assert.assertEquals("Wrong oxm field", 9, fieldAndMask >> 1);
out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
Assert.assertEquals("Wrong oxm value", 4, out.readUnsignedByte());
out.skipBytes(7);
Assert.assertEquals("Wrong instruction type", 1, out.readUnsignedShort());
out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
Assert.assertEquals("Wrong instruction value", 43, out.readUnsignedByte());
out.skipBytes(3);
Assert.assertEquals("Wrong instruction type", 2, out.readUnsignedShort());
out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
out.skipBytes(EncodeConstants.SIZE_OF_INT_IN_BYTES);
byte[] cookieRead = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
out.readBytes(cookieRead);
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.assertEquals("Wrong instruction type", 4, out.readUnsignedShort());
Assert.assertEquals("Wrong instruction length", 24, out.readUnsignedShort());
out.skipBytes(4);
Assert.assertEquals("Wrong action type", 0, out.readUnsignedShort());
Assert.assertEquals("Wrong action length", 16, out.readUnsignedShort());
Assert.assertEquals("Wrong port", 42, out.readUnsignedInt());
Assert.assertEquals("Wrong max-length", 52, out.readUnsignedShort());
out.skipBytes(6);
Assert.assertTrue("Unread data", out.readableBytes() == 0);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput in project openflowplugin by opendaylight.
the class OF10FlowModInputMessageFactoryTest method testFlowModInputMessageFactory.
/**
* Testing of {@link OF10FlowModInputMessageFactory} for correct translation from POJO.
*/
@Test
public void testFlowModInputMessageFactory() throws Exception {
FlowModInputBuilder builder = new FlowModInputBuilder();
BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID);
MatchV10Builder matchBuilder = new MatchV10Builder();
matchBuilder.setWildcards(new FlowWildcardsV10(true, true, true, true, true, true, true, true, true, true));
matchBuilder.setNwSrcMask((short) 0);
matchBuilder.setNwDstMask((short) 0);
matchBuilder.setInPort(58);
matchBuilder.setDlSrc(new MacAddress("01:01:01:01:01:01"));
matchBuilder.setDlDst(new MacAddress("ff:ff:ff:ff:ff:ff"));
matchBuilder.setDlVlan(18);
matchBuilder.setDlVlanPcp((short) 5);
matchBuilder.setDlType(42);
matchBuilder.setNwTos((short) 4);
matchBuilder.setNwProto((short) 7);
matchBuilder.setNwSrc(new Ipv4Address("8.8.8.8"));
matchBuilder.setNwDst(new Ipv4Address("16.16.16.16"));
matchBuilder.setTpSrc(6653);
matchBuilder.setTpDst(6633);
builder.setMatchV10(matchBuilder.build());
byte[] cookie = new byte[] { (byte) 0xFF, 0x01, 0x04, 0x01, 0x06, 0x00, 0x07, 0x01 };
builder.setCookie(new BigInteger(1, cookie));
builder.setCommand(FlowModCommand.forValue(0));
builder.setIdleTimeout(12);
builder.setHardTimeout(16);
builder.setPriority(1);
builder.setBufferId(2L);
builder.setOutPort(new PortNumber(4422L));
builder.setFlagsV10(new FlowModFlagsV10(true, false, true));
final List<Action> actions = new ArrayList<>();
ActionBuilder actionBuilder = new ActionBuilder();
SetNwDstCaseBuilder nwDstCaseBuilder = new SetNwDstCaseBuilder();
SetNwDstActionBuilder nwDstBuilder = new SetNwDstActionBuilder();
nwDstBuilder.setIpAddress(new Ipv4Address("2.2.2.2"));
nwDstCaseBuilder.setSetNwDstAction(nwDstBuilder.build());
actionBuilder.setActionChoice(nwDstCaseBuilder.build());
actions.add(actionBuilder.build());
actionBuilder = new ActionBuilder();
SetTpSrcCaseBuilder tpSrcCaseBuilder = new SetTpSrcCaseBuilder();
SetTpSrcActionBuilder tpSrcBuilder = new SetTpSrcActionBuilder();
tpSrcBuilder.setPort(new PortNumber(42L));
tpSrcCaseBuilder.setSetTpSrcAction(tpSrcBuilder.build());
actionBuilder.setActionChoice(tpSrcCaseBuilder.build());
actions.add(actionBuilder.build());
builder.setAction(actions);
FlowModInput message = builder.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
flowModFactory.serialize(message, out);
BufferHelper.checkHeaderV10(out, (byte) 14, 88);
Assert.assertEquals("Wrong wildcards", 3678463, out.readUnsignedInt());
Assert.assertEquals("Wrong inPort", 58, out.readUnsignedShort());
byte[] dlSrc = new byte[6];
out.readBytes(dlSrc);
Assert.assertEquals("Wrong dlSrc", "01:01:01:01:01:01", ByteBufUtils.macAddressToString(dlSrc));
byte[] dlDst = new byte[6];
out.readBytes(dlDst);
Assert.assertEquals("Wrong dlDst", "FF:FF:FF:FF:FF:FF", ByteBufUtils.macAddressToString(dlDst));
Assert.assertEquals("Wrong dlVlan", 18, out.readUnsignedShort());
Assert.assertEquals("Wrong dlVlanPcp", 5, out.readUnsignedByte());
out.skipBytes(1);
Assert.assertEquals("Wrong dlType", 42, out.readUnsignedShort());
Assert.assertEquals("Wrong nwTos", 4, out.readUnsignedByte());
Assert.assertEquals("Wrong nwProto", 7, out.readUnsignedByte());
out.skipBytes(2);
Assert.assertEquals("Wrong nwSrc", 134744072, out.readUnsignedInt());
Assert.assertEquals("Wrong nwDst", 269488144, out.readUnsignedInt());
Assert.assertEquals("Wrong tpSrc", 6653, out.readUnsignedShort());
Assert.assertEquals("Wrong tpDst", 6633, out.readUnsignedShort());
byte[] cookieRead = new byte[8];
out.readBytes(cookieRead);
Assert.assertArrayEquals("Wrong cookie", cookie, cookieRead);
Assert.assertEquals("Wrong command", 0, out.readUnsignedShort());
Assert.assertEquals("Wrong idleTimeOut", 12, out.readUnsignedShort());
Assert.assertEquals("Wrong hardTimeOut", 16, out.readUnsignedShort());
Assert.assertEquals("Wrong priority", 1, out.readUnsignedShort());
Assert.assertEquals("Wrong bufferId", 2, out.readUnsignedInt());
Assert.assertEquals("Wrong outPort", 4422, out.readUnsignedShort());
Assert.assertEquals("Wrong flags", 3, out.readUnsignedShort());
Assert.assertEquals("Wrong action - type", 7, out.readUnsignedShort());
Assert.assertEquals("Wrong action - length", 8, out.readUnsignedShort());
Assert.assertEquals("Wrong flags", 33686018, out.readUnsignedInt());
Assert.assertEquals("Wrong action - type", 9, out.readUnsignedShort());
Assert.assertEquals("Wrong action - length", 8, out.readUnsignedShort());
Assert.assertEquals("Wrong flags", 42, out.readUnsignedShort());
out.skipBytes(2);
}
Aggregations