Search in sources :

Example 1 with PacketIn

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

the class DeviceContextImpl method handlePacketInMessage.

private void handlePacketInMessage(final PacketIn packetIn, final Class<?> implementedInterface, final Match match) {
    messageSpy.spyMessage(implementedInterface, MessageSpy.StatisticsGroup.FROM_SWITCH);
    final ConnectionAdapter connectionAdapter = getPrimaryConnectionContext().getConnectionAdapter();
    if (packetIn == null) {
        LOG.debug("Received a null packet from switch {}", connectionAdapter.getRemoteAddress());
        messageSpy.spyMessage(implementedInterface, MessageSpy.StatisticsGroup.FROM_SWITCH_TRANSLATE_SRC_FAILURE);
        return;
    }
    final OpenflowVersion openflowVersion = OpenflowVersion.get(deviceInfo.getVersion());
    // Try to get ingress from match
    final NodeConnectorRef nodeConnectorRef = Objects.nonNull(packetIn.getIngress()) ? packetIn.getIngress() : Optional.ofNullable(match).map(Match::getInPort).map(nodeConnectorId -> InventoryDataServiceUtil.portNumberfromNodeConnectorId(openflowVersion, nodeConnectorId)).map(portNumber -> InventoryDataServiceUtil.nodeConnectorRefFromDatapathIdPortno(deviceInfo.getDatapathId(), portNumber, openflowVersion)).orElse(null);
    messageSpy.spyMessage(implementedInterface, MessageSpy.StatisticsGroup.FROM_SWITCH_TRANSLATE_OUT_SUCCESS);
    if (!packetInLimiter.acquirePermit()) {
        LOG.debug("Packet limited");
        // TODO: save packet into emergency slot if possible
        messageSpy.spyMessage(implementedInterface, MessageSpy.StatisticsGroup.FROM_SWITCH_PACKET_IN_LIMIT_REACHED_AND_DROPPED);
        return;
    }
    final ListenableFuture<?> offerNotification = notificationPublishService.offerNotification(new PacketReceivedBuilder(packetIn).setIngress(nodeConnectorRef).setMatch(MatchUtil.transformMatch(match, org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.packet.received.Match.class)).build());
    if (NotificationPublishService.REJECTED.equals(offerNotification)) {
        LOG.debug("notification offer rejected");
        messageSpy.spyMessage(implementedInterface, MessageSpy.StatisticsGroup.FROM_SWITCH_NOTIFICATION_REJECTED);
        packetInLimiter.drainLowWaterMark();
        packetInLimiter.releasePermit();
        return;
    }
    Futures.addCallback(offerNotification, new FutureCallback<Object>() {

        @Override
        public void onSuccess(final Object result) {
            messageSpy.spyMessage(implementedInterface, MessageSpy.StatisticsGroup.FROM_SWITCH_PUBLISHED_SUCCESS);
            packetInLimiter.releasePermit();
        }

        @Override
        public void onFailure(final Throwable throwable) {
            messageSpy.spyMessage(implementedInterface, MessageSpy.StatisticsGroup.FROM_SWITCH_NOTIFICATION_REJECTED);
            LOG.debug("notification offer failed: {}", throwable.getMessage());
            LOG.trace("notification offer failed..", throwable);
            packetInLimiter.releasePermit();
        }
    }, MoreExecutors.directExecutor());
}
Also used : MultipartWriterProvider(org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProvider) FlowCapableNodeConnectorStatisticsData(org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.FlowCapableNodeConnectorStatisticsData) DeviceMeterRegistry(org.opendaylight.openflowplugin.api.openflow.registry.meter.DeviceMeterRegistry) ServiceGroupIdentifier(org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier) Future(java.util.concurrent.Future) Error(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.Error) PacketInMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage) NodeConnectorKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey) ExtensionConverterProvider(org.opendaylight.openflowplugin.extension.api.core.extension.ExtensionConverterProvider) NodeRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef) ContextChainState(org.opendaylight.openflowplugin.api.openflow.lifecycle.ContextChainState) PortStatusMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage) PortGrouping(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortGrouping) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) FlowCapableNodeConnectorStatisticsDataBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.FlowCapableNodeConnectorStatisticsDataBuilder) ConnectionAdapter(org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter) PacketReceivedBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceivedBuilder) AbstractDeviceInitializer(org.opendaylight.openflowplugin.impl.device.initialization.AbstractDeviceInitializer) PacketReceived(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived) DataContainer(org.opendaylight.yangtools.yang.binding.DataContainer) MultiMsgCollectorImpl(org.opendaylight.openflowplugin.impl.device.listener.MultiMsgCollectorImpl) ConversionException(org.opendaylight.openflowplugin.extension.api.exception.ConversionException) TransactionChainManager(org.opendaylight.openflowplugin.common.txchain.TransactionChainManager) DeviceInitializerProvider(org.opendaylight.openflowplugin.impl.device.initialization.DeviceInitializerProvider) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) OpenflowVersion(org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion) PacketIn(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketIn) Xid(org.opendaylight.openflowplugin.api.openflow.device.Xid) OfHeader(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader) Nullable(javax.annotation.Nullable) ContextChainMastershipState(org.opendaylight.openflowplugin.api.openflow.lifecycle.ContextChainMastershipState) AbstractRequestContext(org.opendaylight.openflowplugin.impl.rpc.AbstractRequestContext) NodeConnectorRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef) Match(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match) FutureCallback(com.google.common.util.concurrent.FutureCallback) ExecutionException(java.util.concurrent.ExecutionException) Futures(com.google.common.util.concurrent.Futures) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) ExtensionConverterProviderKeeper(org.opendaylight.openflowplugin.extension.api.ExtensionConverterProviderKeeper) KeyedInstanceIdentifier(org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier) TranslatorKey(org.opendaylight.openflowplugin.api.openflow.md.core.TranslatorKey) ConvertorMessageFromOFJava(org.opendaylight.openflowplugin.extension.api.ConvertorMessageFromOFJava) ContextChainHolder(org.opendaylight.openflowplugin.api.openflow.lifecycle.ContextChainHolder) DeviceFlowRegistryImpl(org.opendaylight.openflowplugin.impl.registry.flow.DeviceFlowRegistryImpl) NodeConnectorBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorBuilder) DeviceFlowRegistry(org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry) NodeConnector(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) NotificationPublishService(org.opendaylight.controller.md.sal.binding.api.NotificationPublishService) ContextChainMastershipWatcher(org.opendaylight.openflowplugin.api.openflow.lifecycle.ContextChainMastershipWatcher) ExperimenterMessageFromDevBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.message.service.rev151020.ExperimenterMessageFromDevBuilder) MessagePath(org.opendaylight.openflowplugin.extension.api.path.MessagePath) MessageTranslator(org.opendaylight.openflowplugin.api.openflow.device.MessageTranslator) DeviceContext(org.opendaylight.openflowplugin.api.openflow.device.DeviceContext) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) Collection(java.util.Collection) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) ExperimenterDataOfChoice(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.experimenter.core.ExperimenterDataOfChoice) Objects(java.util.Objects) DeviceInfo(org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo) List(java.util.List) ContextChain(org.opendaylight.openflowplugin.api.openflow.lifecycle.ContextChain) ExperimenterMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage) MessageSpy(org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy) HashedWheelTimer(io.netty.util.HashedWheelTimer) MultiMsgCollector(org.opendaylight.openflowplugin.api.openflow.device.handlers.MultiMsgCollector) Optional(java.util.Optional) DeviceMeterRegistryImpl(org.opendaylight.openflowplugin.impl.registry.meter.DeviceMeterRegistryImpl) InventoryDataServiceUtil(org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil) FlowRemoved(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemoved) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) FlowCapableNodeConnector(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ConvertorExecutor(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MultipartWriterProviderFactory(org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProviderFactory) DeviceState(org.opendaylight.openflowplugin.api.openflow.device.DeviceState) HashSet(java.util.HashSet) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) RequestContextUtil(org.opendaylight.openflowplugin.impl.services.util.RequestContextUtil) PortReason(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortReason) Nonnull(javax.annotation.Nonnull) PortStatus(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatus) MessageTypeKey(org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey) ConnectionContext(org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext) DeviceGroupRegistryImpl(org.opendaylight.openflowplugin.impl.registry.group.DeviceGroupRegistryImpl) Logger(org.slf4j.Logger) OFConstants(org.opendaylight.openflowplugin.api.OFConstants) TimeUnit(java.util.concurrent.TimeUnit) DeviceGroupRegistry(org.opendaylight.openflowplugin.api.openflow.registry.group.DeviceGroupRegistry) ExperimenterMessageOfChoice(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.experimenter.types.rev151020.experimenter.core.message.ExperimenterMessageOfChoice) RequestContext(org.opendaylight.openflowplugin.api.openflow.device.RequestContext) TranslatorLibrary(org.opendaylight.openflowplugin.api.openflow.device.TranslatorLibrary) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Collections(java.util.Collections) MatchUtil(org.opendaylight.openflowplugin.impl.util.MatchUtil) NodeConnectorRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef) OpenflowVersion(org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion) Match(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match) PacketReceivedBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceivedBuilder) ConnectionAdapter(org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter) DataObject(org.opendaylight.yangtools.yang.binding.DataObject)

Example 2 with PacketIn

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

the class NodeConnectorRefToPortTranslator method toNodeConnectorRef.

/**
 * Converts {@link PacketIn} to {@link NodeConnectorRef}.
 * @param packetIn Packet input
 * @param dataPathId Data path id
 * @return packet input converted to node connector reference
 */
@Nullable
public static NodeConnectorRef toNodeConnectorRef(@Nonnull PacketIn packetIn, BigInteger dataPathId) {
    Preconditions.checkNotNull(packetIn);
    NodeConnectorRef ref = null;
    Long port = getPortNoFromPacketIn(packetIn);
    if (port != null) {
        OpenflowVersion version = OpenflowVersion.get(packetIn.getVersion());
        ref = InventoryDataServiceUtil.nodeConnectorRefFromDatapathIdPortno(dataPathId, port, version);
    }
    return ref;
}
Also used : NodeConnectorRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef) OpenflowVersion(org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion) Nullable(javax.annotation.Nullable)

Example 3 with PacketIn

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

the class NodeConnectorRefToPortTranslatorTest method testGetPortNoFromPacketIn.

@Test
public void testGetPortNoFromPacketIn() throws Exception {
    PacketIn packetIn = createPacketIn(PORT_NO);
    Long portNo = NodeConnectorRefToPortTranslator.getPortNoFromPacketIn(packetIn);
    assertEquals(portNo, PORT_NO);
}
Also used : PacketIn(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketIn) Test(org.junit.Test)

Example 4 with PacketIn

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

the class NodeConnectorRefToPortTranslatorTest method testNodeConnectorConversion.

@Test
public void testNodeConnectorConversion() throws Exception {
    // Mock the packet in message
    PacketIn packetIn = createPacketIn(PORT_NO);
    // Convert PacketIn to NodeConnectorRef
    NodeConnectorRef ref = NodeConnectorRefToPortTranslator.toNodeConnectorRef(packetIn, DATA_PATH_ID);
    // Get port number from created NodeConnectorRef
    Long refPort = NodeConnectorRefToPortTranslator.fromNodeConnectorRef(ref, OF_VERSION);
    // Check if we got the correct port number
    assertEquals(PORT_NO, refPort);
    // Check if 2 NodeConnectorRef created from same PacketIn have same value
    assertEquals(ref, NodeConnectorRefToPortTranslator.toNodeConnectorRef(packetIn, DATA_PATH_ID));
    // Check if 2 NodeConnectorRef created from same PacketIn but different datapaths do not have same value
    assertNotSame(ref, NodeConnectorRefToPortTranslator.toNodeConnectorRef(packetIn, BigInteger.ONE));
}
Also used : PacketIn(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketIn) NodeConnectorRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef) Test(org.junit.Test)

Example 5 with PacketIn

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

the class NodeConnectorRefToPortTranslatorTest method createPacketIn.

private static PacketIn createPacketIn(long portNo) {
    InPortBuilder inPortBuilder = new InPortBuilder().setPortNumber(new PortNumber(portNo));
    InPortCaseBuilder caseBuilder = new InPortCaseBuilder().setInPort(inPortBuilder.build());
    MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder().setOxmClass(OpenflowBasicClass.class).setOxmMatchField(InPort.class).setHasMask(false).setMatchEntryValue(caseBuilder.build());
    MatchBuilder matchBuilder = new MatchBuilder().setMatchEntry(Lists.newArrayList(matchEntryBuilder.build()));
    return new PacketInMessageBuilder().setVersion(OFConstants.OFP_VERSION_1_0).setData(PACKET_DATA.getBytes()).setReason(PacketInReason.OFPRACTION).setMatch(matchBuilder.build()).setVersion(OFConstants.OFP_VERSION_1_3).setCookie(BigInteger.ZERO).setTableId(new TableId(TABLE_ID)).build();
}
Also used : TableId(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId) PacketInMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessageBuilder) MatchEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder) InPortBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.in.port._case.InPortBuilder) InPortCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.InPortCaseBuilder) OpenflowBasicClass(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OpenflowBasicClass) PortNumber(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.MatchBuilder)

Aggregations

NodeConnectorRef (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef)4 Nullable (javax.annotation.Nullable)2 Test (org.junit.Test)2 OpenflowVersion (org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion)2 PacketIn (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketIn)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 FutureCallback (com.google.common.util.concurrent.FutureCallback)1 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 HashedWheelTimer (io.netty.util.HashedWheelTimer)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 ExecutionException (java.util.concurrent.ExecutionException)1 Future (java.util.concurrent.Future)1