class PacketDispatcher {

    public void dispatchPacket(byte[] payload, NodeConnectorRef ingress, MacAddress srcMac, MacAddress destMac) {
        inventoryReader.readInventory();

        String nodeId = ingress.getValue().firstIdentifierOf(Node.class).firstKeyOf(Node.class, NodeKey.class).getId()
                .getValue();
        NodeConnectorRef srcConnectorRef = inventoryReader.getControllerSwitchConnectors().get(nodeId);

        if (srcConnectorRef == null) {
            refreshInventoryReader();
            srcConnectorRef = inventoryReader.getControllerSwitchConnectors().get(nodeId);
        }
        NodeConnectorRef destNodeConnector = inventoryReader
                .getNodeConnector(ingress.getValue().firstIdentifierOf(Node.class), destMac);
        if (srcConnectorRef != null) {
            if (destNodeConnector != null) {
                sendPacketOut(payload, srcConnectorRef, destNodeConnector);
            } else {
                floodPacket(nodeId, payload, ingress, srcConnectorRef);
            }
        } else {
            LOG.info("Cannot send packet out or flood as controller node connector is not available for node {}.",
                    nodeId);
        }
    }

}