use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.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());
}
}
Aggregations