use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessage in project openflowplugin by opendaylight.
the class FlowRemovedMessageFactory method deserialize.
@Override
// FB doesn't recognize Objects.requireNonNull
@SuppressFBWarnings("UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR")
public FlowRemovedMessage deserialize(ByteBuf rawMessage) {
Objects.requireNonNull(registry);
FlowRemovedMessageBuilder builder = new FlowRemovedMessageBuilder();
builder.setVersion((short) EncodeConstants.OF13_VERSION_ID);
builder.setXid(rawMessage.readUnsignedInt());
byte[] cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
rawMessage.readBytes(cookie);
builder.setCookie(new BigInteger(1, cookie));
builder.setPriority(rawMessage.readUnsignedShort());
builder.setReason(FlowRemovedReason.forValue(rawMessage.readUnsignedByte()));
builder.setTableId(new TableId((long) rawMessage.readUnsignedByte()));
builder.setDurationSec(rawMessage.readUnsignedInt());
builder.setDurationNsec(rawMessage.readUnsignedInt());
builder.setIdleTimeout(rawMessage.readUnsignedShort());
builder.setHardTimeout(rawMessage.readUnsignedShort());
byte[] packetCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
rawMessage.readBytes(packetCount);
builder.setPacketCount(new BigInteger(1, packetCount));
byte[] byteCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
rawMessage.readBytes(byteCount);
builder.setByteCount(new BigInteger(1, byteCount));
OFDeserializer<Match> matchDeserializer = registry.getDeserializer(new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, EncodeConstants.EMPTY_VALUE, Match.class));
builder.setMatch(matchDeserializer.deserialize(rawMessage));
return builder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessage in project openflowplugin by opendaylight.
the class OF10FlowRemovedMessageFactoryTest method test.
/**
* Testing {@link OF10FlowRemovedMessageFactory} for correct translation into POJO.
*/
@Test
public void test() {
ByteBuf bb = BufferHelper.buildBuffer("00 24 08 D1 00 20 AA BB CC DD EE FF " + // 36
"AA BB CC DD EE FF 00 05 10 00 00 08 07 06 00 00 10 11 12 13 01 02 03 04 " + // match
"50 50 20 20 " + "00 01 02 03 04 05 06 07 00 03 01 00 00 00 00 02 " + // 41
"00 00 00 05 00 08 00 00 00 01 02 03 04 05 06 07 00 01 02 03 04 05 06 07");
FlowRemovedMessage builtByFactory = BufferHelper.deserialize(flowFactory, bb);
BufferHelper.checkHeaderV10(builtByFactory);
Assert.assertEquals("Wrong cookie", 0x0001020304050607L, builtByFactory.getCookie().longValue());
Assert.assertEquals("Wrong priority", 0x03, builtByFactory.getPriority().intValue());
Assert.assertEquals("Wrong reason", 0x01, builtByFactory.getReason().getIntValue());
Assert.assertEquals("Wrong durationSec", 0x00000002L, builtByFactory.getDurationSec().longValue());
Assert.assertEquals("Wrong durationNsec", 0x00000005L, builtByFactory.getDurationNsec().longValue());
Assert.assertEquals("Wrong idleTimeout", 0x08, builtByFactory.getIdleTimeout().intValue());
Assert.assertEquals("Wrong packetCount", 0x0001020304050607L, builtByFactory.getPacketCount().longValue());
Assert.assertEquals("Wrong byteCount", 0x0001020304050607L, builtByFactory.getByteCount().longValue());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessage in project openflowplugin by opendaylight.
the class FlowRemovedMessageFactoryTest method testSerialize.
@Test
public void testSerialize() throws Exception {
FlowRemovedMessageBuilder builder = new FlowRemovedMessageBuilder();
BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
builder.setCookie(BigInteger.valueOf(1234L));
builder.setPriority(1234);
builder.setReason(FlowRemovedReason.forValue(2));
builder.setTableId(new TableId(65L));
builder.setDurationSec(1234L);
builder.setDurationNsec(1234L);
builder.setIdleTimeout(1234);
builder.setHardTimeout(1234);
builder.setPacketCount(BigInteger.valueOf(1234L));
builder.setByteCount(BigInteger.valueOf(1234L));
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 FlowRemovedMessage message = builder.build();
ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
// simulate parent message
serializedBuffer.writeInt(1);
serializedBuffer.writeZero(2);
serializedBuffer.writeShort(3);
factory.serialize(message, serializedBuffer);
// read parent message
serializedBuffer.readInt();
serializedBuffer.skipBytes(2);
serializedBuffer.readShort();
BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 72);
Assert.assertEquals("Wrong cookie", message.getCookie().longValue(), serializedBuffer.readLong());
Assert.assertEquals("Wrong priority", message.getPriority().intValue(), serializedBuffer.readShort());
Assert.assertEquals("Wrong reason", message.getReason().getIntValue(), serializedBuffer.readByte());
Assert.assertEquals("Wrong Table ID", message.getTableId().getValue().intValue(), serializedBuffer.readUnsignedByte());
Assert.assertEquals("Wrong duration sec", message.getDurationSec().intValue(), serializedBuffer.readInt());
Assert.assertEquals("Wrong duration nsec", message.getDurationNsec().intValue(), serializedBuffer.readInt());
Assert.assertEquals("Wrong Idle timeout", message.getIdleTimeout().intValue(), serializedBuffer.readShort());
Assert.assertEquals("Wrong Hard timeout", message.getIdleTimeout().intValue(), serializedBuffer.readShort());
Assert.assertEquals("Wrong Packet count", message.getPacketCount().longValue(), serializedBuffer.readLong());
Assert.assertEquals("Wrong Byte count", message.getByteCount().longValue(), serializedBuffer.readLong());
Assert.assertEquals("Wrong match type", 1, serializedBuffer.readUnsignedShort());
serializedBuffer.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
Assert.assertEquals("Wrong oxm class", 0x8000, serializedBuffer.readUnsignedShort());
short fieldAndMask = serializedBuffer.readUnsignedByte();
Assert.assertEquals("Wrong oxm hasMask", 0, fieldAndMask & 1);
Assert.assertEquals("Wrong oxm field", 1, fieldAndMask >> 1);
serializedBuffer.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
Assert.assertEquals("Wrong oxm value", 42, serializedBuffer.readUnsignedInt());
Assert.assertEquals("Wrong oxm class", 0x8000, serializedBuffer.readUnsignedShort());
fieldAndMask = serializedBuffer.readUnsignedByte();
Assert.assertEquals("Wrong oxm hasMask", 0, fieldAndMask & 1);
Assert.assertEquals("Wrong oxm field", 9, fieldAndMask >> 1);
serializedBuffer.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
Assert.assertEquals("Wrong oxm value", 4, serializedBuffer.readUnsignedByte());
serializedBuffer.skipBytes(7);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessage in project openflowplugin by opendaylight.
the class FlowRemovedMessageFactoryTest method test.
/**
* Testing {@link FlowRemovedMessageFactory} for correct translation into POJO.
*/
@Test
public void test() {
ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 04 05 06 07 00 03 02 04 00 00 00 02" + " 00 00 00 05 00 01 00 03 00 01 02 03 04 05 06 07 00 01 02 03 04 05 06 07");
FlowRemovedMessage builtByFactory = BufferHelper.deserialize(flowFactory, bb);
BufferHelper.checkHeaderV13(builtByFactory);
Assert.assertTrue(builtByFactory.getCookie().longValue() == 0x0001020304050607L);
Assert.assertTrue(builtByFactory.getPriority() == 0x03);
Assert.assertEquals("Wrong reason", 0x02, builtByFactory.getReason().getIntValue());
Assert.assertEquals("Wrong tableId", new TableId(4L), builtByFactory.getTableId());
Assert.assertEquals("Wrong durationSec", 0x02L, builtByFactory.getDurationSec().longValue());
Assert.assertEquals("Wrong durationNsec", 0x05L, builtByFactory.getDurationNsec().longValue());
Assert.assertEquals("Wrong idleTimeout", 0x01, builtByFactory.getIdleTimeout().intValue());
Assert.assertEquals("Wrong hardTimeout", 0x03, builtByFactory.getHardTimeout().intValue());
Assert.assertEquals("Wrong packetCount", 0x0001020304050607L, builtByFactory.getPacketCount().longValue());
Assert.assertEquals("Wrong byteCount", 0x0001020304050607L, builtByFactory.getByteCount().longValue());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessage in project openflowplugin by opendaylight.
the class FlowRemovedTranslatorTest method testTranslateV10.
@Test
public void testTranslateV10() throws Exception {
org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemoved flowRemovedMessage = buildMessage(true);
final FlowRemoved flowRemoved = translatorV10.translate(flowRemovedMessage, deviceInfo, null);
assertEquals(flowRemovedMessage.getCookie(), flowRemoved.getCookie().getValue());
assertEquals(flowRemovedMessage.getPriority(), flowRemoved.getPriority());
assertEquals((short) 0, flowRemoved.getTableId().shortValue());
}
Aggregations