Search in sources :

Example 16 with PacketInMessage

use of org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketInMessage in project openflowplugin by opendaylight.

the class OF10PacketInMessageFactory method deserialize.

@Override
public PacketInMessage deserialize(final ByteBuf rawMessage) {
    PacketInMessageBuilder builder = new PacketInMessageBuilder();
    builder.setVersion((short) EncodeConstants.OF10_VERSION_ID);
    builder.setXid(rawMessage.readUnsignedInt());
    builder.setBufferId(rawMessage.readUnsignedInt());
    builder.setTotalLen(rawMessage.readUnsignedShort());
    builder.setInPort(rawMessage.readUnsignedShort());
    builder.setReason(PacketInReason.forValue(rawMessage.readUnsignedByte()));
    rawMessage.skipBytes(PADDING_IN_PACKET_IN_HEADER);
    int remainingBytes = rawMessage.readableBytes();
    if (remainingBytes > 0) {
        final byte[] buf = new byte[remainingBytes];
        rawMessage.readBytes(buf);
        builder.setData(buf);
    }
    return builder.build();
}
Also used : PacketInMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessageBuilder)

Example 17 with PacketInMessage

use of org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketInMessage in project openflowplugin by opendaylight.

the class PacketInMessageFactoryTest method test.

/**
 * Testing {@link PacketInMessageFactory} for correct translation into POJO.
 */
@Test
public void test() {
    ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 01 02 01 04 00 01 02 03 04 05 06 07 00 01 00 0C" + " 80 00 02 04 00 00 00 01 00 00 00 00 00 00 01 02 03 04");
    PacketInMessage builtByFactory = BufferHelper.deserialize(packetInFactory, bb);
    BufferHelper.checkHeaderV13(builtByFactory);
    Assert.assertEquals("Wrong bufferID", 0x00010203L, builtByFactory.getBufferId().longValue());
    Assert.assertEquals("Wrong totalLength", 0x0102, builtByFactory.getTotalLen().intValue());
    Assert.assertEquals("Wrong reason", PacketInReason.OFPRACTION, builtByFactory.getReason());
    Assert.assertEquals("Wrong tableID", new TableId(4L), builtByFactory.getTableId());
    Assert.assertEquals("Wrong cookie", 0x0001020304050607L, builtByFactory.getCookie().longValue());
    Assert.assertArrayEquals("Wrong data", ByteBufUtils.hexStringToBytes("01 02 03 04"), builtByFactory.getData());
}
Also used : TableId(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId) PacketInMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 18 with PacketInMessage

use of org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketInMessage in project openflowplugin by opendaylight.

the class DeviceContextImplTest method testProcessPacketInMessageFutureSuccess.

@Test
public void testProcessPacketInMessageFutureSuccess() {
    final PacketInMessage mockedPacketInMessage = mock(PacketInMessage.class);
    final NotificationPublishService mockedNotificationPublishService = mock(NotificationPublishService.class);
    final ListenableFuture stringListenableFuture = Futures.immediateFuture("dummy value");
    when(mockedNotificationPublishService.offerNotification(any(PacketReceived.class))).thenReturn(stringListenableFuture);
    deviceContext.setNotificationPublishService(mockedNotificationPublishService);
    deviceContext.processPacketInMessage(mockedPacketInMessage);
    verify(messageSpy).spyMessage(any(Class.class), eq(MessageSpy.StatisticsGroup.FROM_SWITCH));
    verify(messageSpy).spyMessage(any(Class.class), eq(MessageSpy.StatisticsGroup.FROM_SWITCH_PUBLISHED_SUCCESS));
}
Also used : ListenableFuture(com.google.common.util.concurrent.ListenableFuture) PacketReceived(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived) PacketInMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage) NotificationPublishService(org.opendaylight.controller.md.sal.binding.api.NotificationPublishService) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)11 PacketInMessage (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage)10 PacketInMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessageBuilder)7 ByteBuf (io.netty.buffer.ByteBuf)5 BigInteger (java.math.BigInteger)5 PacketReceived (org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived)5 TableId (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId)4 FlowCookie (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie)3 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 NotificationPublishService (org.opendaylight.controller.md.sal.binding.api.NotificationPublishService)2 NodeConnectorRef (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef)2 MatchEntryBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder)2 MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.MatchBuilder)2 TableId (org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableId)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 ArrayList (java.util.ArrayList)1 Optional (java.util.Optional)1 DeviceInfo (org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo)1 MessageTranslator (org.opendaylight.openflowplugin.api.openflow.device.MessageTranslator)1