Search in sources :

Example 1 with PacketInMessage

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage in project openflowplugin by opendaylight.

the class PacketReceivedTranslator method getPacketInMatch.

@VisibleForTesting
org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.packet.received.Match getPacketInMatch(final PacketInMessage input, final BigInteger datapathId) {
    final VersionDatapathIdConvertorData datapathIdConvertorData = new VersionDatapathIdConvertorData(input.getVersion());
    datapathIdConvertorData.setDatapathId(datapathId);
    final Optional<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder> matchOptional = convertorExecutor.convert(input.getMatch(), datapathIdConvertorData);
    final MatchBuilder matchBuilder = matchOptional.map(matchBuilder1 -> new MatchBuilder(matchBuilder1.build())).orElseGet(MatchBuilder::new);
    final AugmentTuple<org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.packet.received.Match> matchExtensionWrap = MatchExtensionHelper.processAllExtensions(input.getMatch().getMatchEntry(), OpenflowVersion.get(input.getVersion()), MatchPath.PACKET_RECEIVED_MATCH);
    if (matchExtensionWrap != null) {
        matchBuilder.addAugmentation(matchExtensionWrap.getAugmentationClass(), matchExtensionWrap.getAugmentationObject());
    }
    return matchBuilder.build();
}
Also used : PacketInUtil(org.opendaylight.openflowplugin.impl.util.PacketInUtil) ConvertorExecutor(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor) MatchPath(org.opendaylight.openflowplugin.extension.api.path.MatchPath) FlowCookie(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie) NodeConnectorRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef) MatchExtensionHelper(org.opendaylight.openflowplugin.openflow.md.core.extension.MatchExtensionHelper) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.packet.received.MatchBuilder) OpenflowVersion(org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion) DeviceInfo(org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo) VersionDatapathIdConvertorData(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData) PacketReceivedBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceivedBuilder) MessageTranslator(org.opendaylight.openflowplugin.api.openflow.device.MessageTranslator) PacketInMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage) AugmentTuple(org.opendaylight.openflowplugin.extension.api.AugmentTuple) Optional(java.util.Optional) BigInteger(java.math.BigInteger) VisibleForTesting(com.google.common.annotations.VisibleForTesting) TableId(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableId) PacketReceived(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived) NodeConnectorRefToPortTranslator(org.opendaylight.openflowplugin.impl.util.NodeConnectorRefToPortTranslator) VersionDatapathIdConvertorData(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.packet.received.MatchBuilder) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with PacketInMessage

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage in project openflowplugin by opendaylight.

the class PacketReceivedTranslatorTest method testTranslate.

@Test
public void testTranslate() throws Exception {
    final KeyedInstanceIdentifier<Node, NodeKey> nodePath = KeyedInstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(new NodeId("openflow:10")));
    final PacketReceivedTranslator packetReceivedTranslator = new PacketReceivedTranslator(convertorManager);
    final PacketInMessage packetInMessage = createPacketInMessage(DATA.getBytes(), PORT_NO);
    Mockito.when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(nodePath);
    final PacketReceived packetReceived = packetReceivedTranslator.translate(packetInMessage, deviceInfo, null);
    Assert.assertArrayEquals(packetInMessage.getData(), packetReceived.getPayload());
    Assert.assertEquals("org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.SendToController", packetReceived.getPacketInReason().getName());
    Assert.assertEquals("openflow:10:" + PORT_NO, packetReceived.getIngress().getValue().firstKeyOf(NodeConnector.class, NodeConnectorKey.class).getId().getValue());
    Assert.assertEquals(0L, packetReceived.getFlowCookie().getValue().longValue());
    Assert.assertEquals(42L, packetReceived.getTableId().getValue().longValue());
}
Also used : NodeConnector(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) NodeId(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId) PacketReceived(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived) PacketInMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage) NodeKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey) Nodes(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes) NodeConnectorKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey) Test(org.junit.Test)

Example 3 with PacketInMessage

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage in project openflowplugin by opendaylight.

the class DeviceContextImpl method processPacketInMessage.

@Override
public void processPacketInMessage(final PacketInMessage packetInMessage) {
    if (isMasterOfDevice()) {
        final PacketReceived packetReceived = packetInTranslator.translate(packetInMessage, getDeviceInfo(), null);
        handlePacketInMessage(packetReceived, packetInMessage.getImplementedInterface(), packetReceived.getMatch());
    } else {
        LOG.debug("Controller is not owner of the device {}, skipping packet_in message", deviceInfo.getLOGValue());
    }
}
Also used : PacketReceived(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived)

Example 4 with PacketInMessage

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage in project openflowplugin by opendaylight.

the class DeviceContextImplTest method testProcessPacketInMessageFutureFailure.

@Test
public void testProcessPacketInMessageFutureFailure() {
    final PacketInMessage mockedPacketInMessage = mock(PacketInMessage.class);
    final NotificationPublishService mockedNotificationPublishService = mock(NotificationPublishService.class);
    final ListenableFuture dummyFuture = Futures.immediateFailedFuture(new IllegalStateException());
    when(mockedNotificationPublishService.offerNotification(any(PacketReceived.class))).thenReturn(dummyFuture);
    deviceContext.setNotificationPublishService(mockedNotificationPublishService);
    deviceContext.processPacketInMessage(mockedPacketInMessage);
    verify(messageSpy).spyMessage(any(Class.class), eq(MessageSpy.StatisticsGroup.FROM_SWITCH_NOTIFICATION_REJECTED));
}
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)

Example 5 with PacketInMessage

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage in project openflowplugin by opendaylight.

the class OpenflowProtocolListenerFullImplTest method testOnPacketInMessage.

/**
 * Test method for
 * {@link OpenflowProtocolListenerFullImpl#onPacketInMessage(
 * org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage)}.
 */
@Test
public void testOnPacketInMessage() {
    PacketInMessage packetInMessage = new PacketInMessageBuilder().setVersion(OFConstants.OFP_VERSION_1_3).setXid(xid).build();
    ofProtocolListener.onPacketInMessage(packetInMessage);
    Mockito.verify(deviceReplyProcessor).processPacketInMessage(Matchers.any(PacketInMessage.class));
}
Also used : PacketInMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessageBuilder) PacketInMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage) 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