Search in sources :

Example 6 with PacketIn

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

the class LearningSwitchHandlerSimpleImpl method onPacketReceived.

@Override
public void onPacketReceived(PacketReceived notification) {
    if (!isLearning) {
        // ignoring packets - this should not happen
        return;
    }
    LOG.debug("Received packet via match: {}", notification.getMatch());
    // detect and compare node - we support one switch
    if (!nodePath.contains(notification.getIngress().getValue())) {
        return;
    }
    // read src MAC and dst MAC
    byte[] dstMacRaw = PacketUtils.extractDstMac(notification.getPayload());
    byte[] srcMacRaw = PacketUtils.extractSrcMac(notification.getPayload());
    byte[] etherType = PacketUtils.extractEtherType(notification.getPayload());
    MacAddress dstMac = PacketUtils.rawMacToMac(dstMacRaw);
    MacAddress srcMac = PacketUtils.rawMacToMac(srcMacRaw);
    NodeConnectorKey ingressKey = InstanceIdentifierUtils.getNodeConnectorKey(notification.getIngress().getValue());
    LOG.debug("Received packet from MAC match: {}, ingress: {}", srcMac, ingressKey.getId());
    LOG.debug("Received packet to   MAC match: {}", dstMac);
    LOG.debug("Ethertype: {}", Integer.toHexString(0x0000ffff & ByteBuffer.wrap(etherType).getShort()));
    // learn by IPv4 traffic only
    if (Arrays.equals(ETH_TYPE_IPV4, etherType)) {
        NodeConnectorRef previousPort = mac2portMapping.put(srcMac, notification.getIngress());
        if (previousPort != null && !notification.getIngress().equals(previousPort)) {
            NodeConnectorKey previousPortKey = InstanceIdentifierUtils.getNodeConnectorKey(previousPort.getValue());
            LOG.debug("mac2port mapping changed by mac {}: {} -> {}", srcMac, previousPortKey, ingressKey.getId());
        }
        // if dst MAC mapped:
        NodeConnectorRef destNodeConnector = mac2portMapping.get(dstMac);
        if (destNodeConnector != null) {
            synchronized (coveredMacPaths) {
                if (!destNodeConnector.equals(notification.getIngress())) {
                    // add flow
                    addBridgeFlow(srcMac, dstMac, destNodeConnector);
                    addBridgeFlow(dstMac, srcMac, notification.getIngress());
                } else {
                    LOG.debug("useless rule ignoring - both MACs are behind the same port");
                }
            }
            LOG.debug("packetIn-directing.. to {}", InstanceIdentifierUtils.getNodeConnectorKey(destNodeConnector.getValue()).getId());
            sendPacketOut(notification.getPayload(), notification.getIngress(), destNodeConnector);
        } else {
            // flood
            LOG.debug("packetIn-still flooding.. ");
            flood(notification.getPayload(), notification.getIngress());
        }
    } else {
        // non IPv4 package
        flood(notification.getPayload(), notification.getIngress());
    }
}
Also used : NodeConnectorRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) NodeConnectorKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey)

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