use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage in project openflowplugin by opendaylight.
the class OF10PacketInMessageFactoryTest method testWithNoAdditionalData.
/**
* Testing {@link OF10PacketInMessageFactory} for correct translation into POJO.
*/
@Test
public void testWithNoAdditionalData() {
ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 01 02 01 02 00 00");
PacketInMessage builtByFactory = BufferHelper.deserialize(packetInFactory, bb);
Assert.assertNull("Wrong data", builtByFactory.getData());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage in project openflowplugin by opendaylight.
the class OF10PacketInMessageFactoryTest method test.
/**
* Testing {@link OF10PacketInMessageFactory} for correct translation into POJO.
*/
@Test
public void test() {
ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 01 02 01 02 00 00 01 02 03 04");
PacketInMessage builtByFactory = BufferHelper.deserialize(packetInFactory, bb);
BufferHelper.checkHeaderV10(builtByFactory);
Assert.assertEquals("Wrong bufferID", 0x00010203L, builtByFactory.getBufferId().longValue());
Assert.assertEquals("Wrong totalLength", 0x0102, builtByFactory.getTotalLen().intValue());
Assert.assertEquals("Wrong inPort", 0x0102, builtByFactory.getInPort().intValue());
Assert.assertEquals("Wrong reason", PacketInReason.OFPRNOMATCH, builtByFactory.getReason());
Assert.assertArrayEquals("Wrong data", ByteBufUtils.hexStringToBytes("01 02 03 04"), builtByFactory.getData());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage in project openflowplugin by opendaylight.
the class ConnectionAdapterImplTest method testConsume.
/**
* Tests {@link ConnectionAdapterImpl#consume(DataObject)} with notifications.
*/
@Test
public void testConsume() {
DataObject message = new EchoRequestMessageBuilder().build();
adapter.consume(message);
verify(messageListener, times(1)).onEchoRequestMessage((EchoRequestMessage) message);
message = new ErrorMessageBuilder().build();
adapter.consume(message);
verify(messageListener, times(1)).onErrorMessage((ErrorMessage) message);
message = new ExperimenterMessageBuilder().build();
adapter.consume(message);
verify(messageListener, times(1)).onExperimenterMessage((ExperimenterMessage) message);
message = new FlowRemovedMessageBuilder().build();
adapter.consume(message);
verify(messageListener, times(1)).onFlowRemovedMessage((FlowRemovedMessage) message);
message = new HelloMessageBuilder().build();
adapter.consume(message);
verify(messageListener, times(1)).onHelloMessage((HelloMessage) message);
message = new MultipartReplyMessageBuilder().build();
adapter.consume(message);
verify(messageListener, times(1)).onMultipartReplyMessage((MultipartReplyMessage) message);
message = new PacketInMessageBuilder().build();
adapter.consume(message);
verify(messageListener, times(1)).onPacketInMessage((PacketInMessage) message);
message = new PortStatusMessageBuilder().build();
adapter.consume(message);
verify(messageListener, times(1)).onPortStatusMessage((PortStatusMessage) message);
message = new SwitchIdleEventBuilder().build();
adapter.consume(message);
verify(systemListener, times(1)).onSwitchIdleEvent((SwitchIdleEvent) message);
message = new DisconnectEventBuilder().build();
adapter.consume(message);
verify(systemListener, times(1)).onDisconnectEvent((DisconnectEvent) message);
message = new EchoRequestMessageBuilder().build();
adapter.consume(message);
verify(messageListener, times(1)).onEchoRequestMessage((EchoRequestMessage) message);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage in project openflowplugin by opendaylight.
the class PacketInMessageFactory method deserialize.
@Override
// FB doesn't recognize Objects.requireNonNull
@SuppressFBWarnings("UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR")
public PacketInMessage deserialize(final ByteBuf rawMessage) {
Objects.requireNonNull(registry);
PacketInMessageBuilder builder = new PacketInMessageBuilder();
builder.setVersion((short) EncodeConstants.OF13_VERSION_ID);
builder.setXid(rawMessage.readUnsignedInt());
builder.setBufferId(rawMessage.readUnsignedInt());
builder.setTotalLen(rawMessage.readUnsignedShort());
builder.setReason(PacketInReason.forValue(rawMessage.readUnsignedByte()));
builder.setTableId(new TableId((long) rawMessage.readUnsignedByte()));
byte[] cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
rawMessage.readBytes(cookie);
builder.setCookie(new BigInteger(1, cookie));
OFDeserializer<Match> matchDeserializer = registry.getDeserializer(MATCH_KEY);
builder.setMatch(matchDeserializer.deserialize(rawMessage));
rawMessage.skipBytes(PADDING_IN_PACKET_IN_HEADER);
byte[] data = new byte[rawMessage.readableBytes()];
rawMessage.readBytes(data);
builder.setData(data);
return builder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage in project openflowplugin by opendaylight.
the class OF10PacketInMessageFactoryTest method testSerialize.
@Test
public void testSerialize() throws Exception {
PacketInMessageBuilder builder = new PacketInMessageBuilder();
BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID);
builder.setBufferId(1L);
builder.setTotalLen(1);
builder.setInPort(1);
builder.setReason(PacketInReason.forValue(0));
byte[] data = ByteBufUtils.hexStringToBytes("00 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14");
builder.setData(data);
PacketInMessage message = builder.build();
ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
factory.serialize(message, serializedBuffer);
BufferHelper.checkHeaderV10(serializedBuffer, MESSAGE_TYPE, 34);
Assert.assertEquals("Wrong buffer id", message.getBufferId().longValue(), serializedBuffer.readUnsignedInt());
Assert.assertEquals("Wrong total len", message.getTotalLen().intValue(), serializedBuffer.readUnsignedShort());
Assert.assertEquals("Wrong port in", message.getInPort().intValue(), serializedBuffer.readUnsignedShort());
Assert.assertEquals("Wrong reason", message.getReason().getIntValue(), serializedBuffer.readUnsignedByte());
serializedBuffer.skipBytes(1);
byte[] readData = new byte[serializedBuffer.readableBytes()];
serializedBuffer.readBytes(readData);
Assert.assertArrayEquals("Wrong data", message.getData(), readData);
}
Aggregations