### Access Test Settings and Server Info with Swift Source: https://context7.com/m-lab/ndt7-client-ios/llms.txt Access test settings and current server information after starting a test. This example initializes NDT7Settings and NDT7Test, starts a download test, and then prints the machine and location of the current server and lists all discovered servers. ```swift import NDT7 let settings = NDT7Settings() let test = NDT7Test(settings: settings) // After test starts, access current server information test.startTest(download: true, upload: false) { error in if let server = test.settings.currentServer { print("Testing with: (server.machine)") if let location = server.location { print("Location: (location.city ?? "Unknown"), (location.country ?? "Unknown")") } // Access all discovered servers for (index, server) in test.settings.allServers.enumerated() { print("Server (index): (server.machine)") } } } ``` -------------------------------- ### Start and Manage NDT7 Speed Tests in Swift Source: https://context7.com/m-lab/ndt7-client-ios/llms.txt This Swift code illustrates how to initiate and manage NDT7 download and upload speed tests within an iOS application. It shows the setup of the NDT7Test object, assigning a delegate to receive test updates, starting both download and upload tests, handling completion or errors, and cancelling an ongoing test. The `NDT7TestInteraction` protocol is used to receive real-time measurements and status changes. ```swift import UIKit import NDT7 class ViewController: UIViewController { var ndt7Test: NDT7Test? // Variable to hold the NDT7 test instance // Function to start the NDT7 speed test func startTest() { // Initialize test with default settings let settings = NDT7Settings() ndt7Test = NDT7Test(settings: settings) ndt7Test?.delegate = self // Assign the view controller as the delegate // Start both download and upload tests with a completion handler ndt7Test?.startTest(download: true, upload: true) { [weak self] (error) in if let error = error { print("Test error: (error.localizedDescription)") // Print error if one occurred } else { print("Test completed successfully") // Indicate successful completion } } } // Function to cancel an ongoing NDT7 test func cancelTest() { ndt7Test?.cancel() // Call the cancel method on the test instance } } // Extension to conform to the NDT7TestInteraction delegate protocol extension ViewController: NDT7TestInteraction { // Delegate method called when the test status changes (started or finished) func test(kind: NDT7TestConstants.Kind, running: Bool) { switch kind { case .download: print("Download test (running ? "started" : "finished")") // Log download test status case .upload: print("Upload test (running ? "started" : "finished")") // Log upload test status } } // Delegate method called with measurement data during the test func measurement(origin: NDT7TestConstants.Origin, kind: NDT7TestConstants.Kind, measurement: NDT7Measurement) { // Origin can be .client (local) or .server (remote) // Kind can be .download or .upload // Process client-side measurements if origin == .client, let elapsedTime = measurement.appInfo?.elapsedTime, let numBytes = measurement.appInfo?.numBytes, elapsedTime >= 1000000 { // Ensure enough time has passed for meaningful calculation let seconds = elapsedTime / 1000000 // Convert microseconds to seconds let mbit = numBytes / 125000 // Convert bytes to megabits let speed = Double(Float64(mbit) / Float64(seconds)) // Calculate speed in Mbit/s print("\(kind) speed: \(speed) Mbit/s") // Print the calculated speed } // Process server-side measurements with TCP info if origin == .server, let elapsedTime = measurement.tcpInfo?.elapsedTime, let bytesAcked = measurement.tcpInfo?.bytesAcked { let seconds = elapsedTime / 1000000 // Convert microseconds to seconds let mbit = bytesAcked / 125000 // Convert bytes to megabits let speed = Double(Float64(mbit) / Float64(seconds)) // Calculate speed in Mbit/s print("Server-measured \(kind) speed: \(speed) Mbit/s") // Print server-measured speed } // Access and print detailed TCP information if available if let tcpInfo = measurement.tcpInfo { print("MinRTT: \(tcpInfo.minRTT ?? 0) μs") // Print minimum Round Trip Time print("RTT: \(tcpInfo.rtt ?? 0) μs") // Print current Round Trip Time print("Bytes retransmitted: \(tcpInfo.bytesRetrans ?? 0)") // Print retransmitted bytes count } } // Delegate method called when an error occurs during the test func error(kind: NDT7TestConstants.Kind, error: NSError) { print("\(kind) test error: \(error.localizedDescription)") // Log the error description cancelTest() // Cancel the test upon encountering an error } } ``` -------------------------------- ### NDT7 Swift Example with UI Updates Source: https://context7.com/m-lab/ndt7-client-ios/llms.txt This Swift example demonstrates a complete NDT7 speed test implementation within a UIViewController. It integrates NDT7 framework to perform download and upload tests, updates UI labels with test progress and results, and handles user interactions like starting and canceling tests. The code utilizes the NDT7TestInteraction protocol for receiving real-time measurements and error callbacks, ensuring thread-safe UI updates on the main thread. ```swift import UIKit import NDT7 class SpeedTestViewController: UIViewController { @IBOutlet weak var downloadLabel: UILabel! @IBOutlet weak var uploadLabel: UILabel! @IBOutlet weak var serverLabel: UILabel! @IBOutlet weak var startButton: UIButton! var ndt7Test: NDT7Test? = nil var downloadRunning = false var uploadRunning = false override func viewDidLoad() { super.viewDidLoad() NDT7.loggingEnabled = true } @IBAction func startButtonTapped(_ sender: UIButton) { startButton.isEnabled = false downloadLabel.text = "Testing..." uploadLabel.text = "Testing..." let settings = NDT7Settings() ndt7Test = NDT7Test(settings: settings) ndt7Test?.delegate = self ndt7Test?.startTest(download: true, upload: true) { [weak self] error in DispatchQueue.main.async { self?.startButton.isEnabled = true if let error = error { self?.showError(error.localizedDescription) } } } } @IBAction func cancelButtonTapped(_ sender: UIButton) { ndt7Test?.cancel() startButton.isEnabled = true } func showError(_ message: String) { let alert = UIAlertController(title: "Error", message: message, preferredStyle: .alert) alert.addAction(UIAlertAction(title: "OK", style: .default)) present(alert, animated: true) } } extension SpeedTestViewController: NDT7TestInteraction { func test(kind: NDT7TestConstants.Kind, running: Bool) { switch kind { case .download: downloadRunning = running case .upload: uploadRunning = running } } func measurement(origin: NDT7TestConstants.Origin, kind: NDT7TestConstants.Kind, measurement: NDT7Measurement) { // Update server information if let server = ndt7Test?.settings.currentServer { DispatchQueue.main.async { [weak self] in self?.serverLabel.text = server.machine } } // Calculate and display speed from client measurements if origin == .client, let elapsedTime = measurement.appInfo?.elapsedTime, let numBytes = measurement.appInfo?.numBytes, elapsedTime >= 1000000 { let seconds = elapsedTime / 1000000 let mbit = numBytes / 125000 let speed = Double(Float64(mbit) / Float64(seconds)) let rounded = (speed * 10).rounded() / 10 DispatchQueue.main.async { [weak self] in switch kind { case .download: self?.downloadLabel.text = "(rounded) Mbit/s" case .upload: self?.uploadLabel.text = "(rounded) Mbit/s" } } } } func error(kind: NDT7TestConstants.Kind, error: NSError) { DispatchQueue.main.async { [weak self] in self?.showError("Test failed: (error.localizedDescription)") self?.ndt7Test?.cancel() } } } ``` -------------------------------- ### Start NDT7 Download/Upload Test in Swift Source: https://github.com/m-lab/ndt7-client-ios/blob/main/docs/Classes/NDT7Test.html Starts the NDT7 download and/or upload test. This method requires boolean flags to indicate whether to run the download or upload test, and a completion handler to report any errors that occur during the test. ```swift public func startTest(download: Bool, upload: Bool, _ completion: @escaping (_ error: NSError?) -> Void) ``` -------------------------------- ### Start NDT7 Test with Default Settings - Swift Source: https://github.com/m-lab/ndt7-client-ios/blob/main/docs/Classes/NDT7.html This Swift code snippet demonstrates how to initialize and start an NDT7 speed test using default settings. It configures the NDT7 framework for logging, creates an instance of `NDT7Test`, sets itself as the delegate, and initiates both download and upload tests. Error handling is included to report any issues during the test execution. ```swift import UIKit import NDT7 class ViewController: UIViewController { var ndt7Test: NDT7Test? override func viewDidLoad() { super.viewDidLoad() // For debugging purpose you can enable logs for NDT7 framework. NDT7.loggingEnabled = true startTest() } func startTest() { ndt7Test = NDT7Test(settings: NDT7Settings()) ndt7Test?.delegate = self ndt7Test?.startTest(download: true, upload: true) { [weak self] (error) in guard self != nil else { return } if let error = error { print("NDT7 iOS Example app - error during test: (error.localizedDescription)") } } } func cancelTest() { ndt7Test?.cancel() } } extension ViewController: NDT7TestInteraction { func test(kind: NDT7TestConstants.Kind, running: Bool) { } func measurement(origin: NDT7TestConstants.Origin, kind: NDT7TestConstants.Kind, measurement: NDT7Measurement) { } func error(kind: NDT7TestConstants.Kind, error: NSError) { } } ``` -------------------------------- ### Start NDT7 Speed Test in Swift Source: https://github.com/m-lab/ndt7-client-ios/blob/main/README.md This Swift code demonstrates the complete process of setting up and initiating an NDT7 speed test for both download and upload. It covers creating settings, initializing the NDT7Test object, setting the delegate, and starting the test with a completion handler to process results or errors. ```swift import UIKit import NDT7 class ViewController: UIViewController { var ndt7Test: NDT7Test? override func viewDidLoad() { super.viewDidLoad() // For debugging purpose you can enable logs for NDT7 framework. NDT7.loggingEnabled = true startTest() } func startTest() { // 2. Create the settings for testing. NDT7Settings. let settings = NDT7Settings() // 3. Create a NDT7Test object with NDT7Settings already created. ndt7Test = NDT7Test(settings: settings) // 4. Setup a delegation for NDT7Test to get the test information. ndt7Test?.delegate = self // 5. Start speed test for download and/or upload. ndt7Test?.startTest(download: true, upload: true) { [weak self] (error) in guard self != nil else { return } if let error = error { print("NDT7 iOS Example app - Error during test: (error.localizedDescription)") } else { print("NDT7 iOS Example app - Test finished.") } } } func cancelTest() { ndt7Test?.cancel() } } // 1. Setup all the functions needed for NDT7Test delegate. extension ViewController: NDT7TestInteraction { func test(kind: NDT7TestConstants.Kind, running: Bool) { } func measurement(origin: NDT7TestConstants.Origin, kind: NDT7TestConstants.Kind, measurement: NDT7Measurement) { } func error(kind: NDT7TestConstants.Kind, error: NSError) { } } ``` -------------------------------- ### Install NDT7 iOS Client with CocoaPods Source: https://github.com/m-lab/ndt7-client-ios/blob/main/README.md This code snippet demonstrates how to add the NDT7 iOS client as a dependency to your project using CocoaPods. Ensure you have CocoaPods installed and configured for your project. After adding the pod, run 'pod install' to integrate the library. ```ruby platform :ios, '10.0' use_frameworks! target 'NDT7 example' do pod 'NDT7', '0.0.4' end ``` -------------------------------- ### Add NDT7 Client as Git Submodule Source: https://github.com/m-lab/ndt7-client-ios/blob/main/README.md This section details the manual installation process for the NDT7 client by adding it as a git submodule. It provides the command to initialize the submodule in your local repository. ```bash $ git submodule add git@github.com:m-lab/ndt7-client-ios ``` -------------------------------- ### Install NDT7 using Carthage Source: https://github.com/m-lab/ndt7-client-ios/blob/main/docs/docsets/ndt7.docset/Contents/Resources/Documents/index.html This snippet shows how to declare the NDT7 library as a dependency in a Cartfile for use with Carthage. It specifies the GitHub repository and the version constraint '~> 0.0.2'. After adding this line to the Cartfile, 'carthage update' should be executed to build the framework. ```text github "m-lab/ndt7-client-ios" ~> 0.0.2 ``` -------------------------------- ### Add NDT7 as a Git Submodule Source: https://github.com/m-lab/ndt7-client-ios/blob/main/docs/docsets/ndt7.docset/Contents/Resources/Documents/index.html This command demonstrates how to add the NDT7 client iOS repository as a submodule to an existing Git repository. This is the first step in the manual installation process, allowing the project to track the NDT7 library's source code. ```bash $ git submodule add git@github.com:m-lab/ndt7-client-ios ``` -------------------------------- ### Install NDT7 with CocoaPods Source: https://github.com/m-lab/ndt7-client-ios/blob/main/docs/index.html This code snippet demonstrates how to add the NDT7 library to an iOS project using CocoaPods. It specifies the platform version and the NDT7 pod version. ```ruby platform :ios, '10.0' use_frameworks! target 'NDT7 example' do pod 'NDT7', '0.0.2' end ``` -------------------------------- ### NDT7Measurement Example JSON Source: https://github.com/m-lab/ndt7-client-ios/blob/main/docs/Structs/NDT7Measurement.html An example of the JSON structure that NDT7Measurement objects are intended to match, as per version 0.8.3 of the NDT7 specification. This JSON illustrates the expected format and content for appInfo, connectionInfo, origin, test direction, and TCPInfo fields. ```json { "AppInfo": { "ElapsedTime": 1234, "NumBytes": 1234 }, "ConnectionInfo": { "Client": "1.2.3.4:5678", "Server": "[::1]:2345", "UUID": "" }, "Origin": "server", "Test": "download", "TCPInfo": { "BusyTime": 1234, "BytesAcked": 1234, "BytesReceived": 1234, "BytesSent": 1234, "BytesRetrans": 1234, "ElapsedTime": 1234, "MinRTT": 1234, "RTT": 1234, "RTTVar": 1234, "RWndLimited": 1234, "SndBufLimited": 1234 } } ``` -------------------------------- ### NDT7Measurement Structure Example Source: https://github.com/m-lab/ndt7-client-ios/blob/main/docs/Structs.html Represents the JSON measurements exchanged between client and server via WebSocket. This structure conforms to Codable in Swift and includes optional TCP_INFO fields. ```swift public struct NDT7Measurement : Codable ``` -------------------------------- ### NDT7Measurement Structure Definition and Example (Swift) Source: https://github.com/m-lab/ndt7-client-ios/blob/main/docs/docsets/ndt7.docset/Contents/Resources/Documents/Structs/NDT7Measurement.html Defines the NDT7Measurement structure used for exchanging JSON measurements in the NDT7 protocol. Includes an example of the expected JSON format for version 0.8.3, which contains fields for application info, connection details, origin, test direction, and TCP information. ```swift public struct NDT7Measurement : Codable { public var appInfo: NDT7APPInfo? public var bbrInfo: NDT7BBRInfo? public var connectionInfo: NDT7ConnectionInfo? public var origin: NDT7TestConstants.Origin? public var direction: NDT7TestConstants.Kind? public let tcpInfo: NDT7TCPInfo? public var rawData: String? } ``` ```json { "AppInfo": { "ElapsedTime": 1234, "NumBytes": 1234, }, "ConnectionInfo": { "Client": "1.2.3.4:5678", "Server": "[::1]:2345", "UUID": "" }, "Origin": "server", "Test": "download", "TCPInfo": { "BusyTime": 1234, "BytesAcked": 1234, "BytesReceived": 1234, "BytesSent": 1234, "BytesRetrans": 1234, "ElapsedTime": 1234, "MinRTT": 1234, "RTT": 1234, "RTTVar": 1234, "RWndLimited": 1234, "SndBufLimited": 1234 } } ``` -------------------------------- ### Initialize NDT7 Test Settings in Swift Source: https://context7.com/m-lab/ndt7-client-ios/llms.txt This code demonstrates how to initialize NDT7 test settings in Swift. You can create default settings that automatically discover the nearest M-Lab server or customize settings with specific timeouts for measurement intervals, I/O operations, and download/upload test durations. This allows for fine-grained control over the testing parameters. ```swift import NDT7 // Create default settings (auto-discovers nearest M-Lab server) let settings = NDT7Settings() // Or customize settings with custom timeouts let customTimeouts = NDT7Timeouts( measurement: 0.25, // Measurement interval (min 250ms) ioTimeout: 7.0, // I/O operation timeout downloadTimeout: 15.0, // Max download test duration uploadTimeout: 15.0 // Max upload test duration ) let customSettings = NDT7Settings(timeout: customTimeouts) ``` -------------------------------- ### NDT7Settings Initialization - Swift Source: https://github.com/m-lab/ndt7-client-ios/blob/main/docs/Structs/NDT7Settings.html Initializes the NDT7Settings structure with configurable parameters for URL, timeouts, TLS verification, geo options, and headers. It supports default values for all parameters, allowing for easy instantiation. ```swift public init(url: NDT7URL = NDT7URL(hostname: ""), timeout: NDT7Timeouts = NDT7Timeouts(), skipTLSCertificateVerification: Bool = true, useGeoOptions: Bool = false, headers: [String: String] = [NDT7WebSocketConstants.Request.headerProtocolKey: NDT7WebSocketConstants.Request.headerProtocolValue]) ``` -------------------------------- ### Discover Mlab NDT7 Server Source: https://github.com/m-lab/ndt7-client-ios/blob/main/docs/Structs/NDT7Server.html This static method facilitates the discovery of Mlab NDT7 servers. It supports discovering servers based on geo-location preferences or by identifying the closest available server. The method includes parameters for retrying requests, managing geo-option changes during retries, and utilizing a server cache for efficiency. A completion handler is provided to return the discovered server or any associated error. ```swift public static func discover(session: T = URLSession.shared as! T, withGeoOptions geoOptions: Bool, retray: UInt = 0, geoOptionsChangeInRetray: Bool = false, useNDT7ServerCache: Bool = false, _ completion: @escaping (_ server: NDT7Server?, _ error: NSError?) -> Void) -> URLSessionTaskNDT7 ``` -------------------------------- ### NDT7Test Initialization in Swift Source: https://github.com/m-lab/ndt7-client-ios/blob/main/docs/Classes/NDT7Test.html Initializes the NDT7Test class with provided settings. The settings parameter is of type NDT7Settings and contains all configurations required for an ndt7 test. ```swift public init(settings: NDT7Settings) ``` -------------------------------- ### Discover M-Lab Servers with Swift Source: https://context7.com/m-lab/ndt7-client-ios/llms.txt Manually discover available M-Lab servers using the NDT7 library. This function takes a completion handler that receives an array of servers or an error. It prints server details like machine name, location, and download/upload URLs. ```swift import NDT7 // Manually discover available M-Lab servers let task = NDT7Server.discover { (servers, error) in if let error = error { print("Server discovery failed: (error.localizedDescription)") return } guard let servers = servers, !servers.isEmpty else { print("No servers found") return } for server in servers { print("Server: (server.machine)") if let location = server.location { print("Location: (location.city ?? ""), (location.country ?? "")") } print("Download URL: (server.urls.downloadPath)") print("Upload URL: (server.urls.uploadPath)") } } ``` -------------------------------- ### NDT7Server - Mlab NDT7 Server Configuration Source: https://github.com/m-lab/ndt7-client-ios/blob/main/docs/Structs.html Represents an M-Lab NDT7 server, including its details for connection. ```APIDOC ## NDT7Server ### Description Represents an M-Lab NDT7 server that the client can connect to for performing speed tests. ### Declaration ```swift public struct NDT7Server : Codable ``` ### Fields - **`serverIP`** (String): The IP address of the NDT7 server. - **`serverName`** (String): The name or identifier of the NDT7 server. - **`country`** (String): The country where the server is located. - **`city`** (String): The city where the server is located. ### Example ```json { "serverIP": "192.0.2.1", "serverName": "ndt-test-server-01", "country": "US", "city": "New York" } ``` ``` -------------------------------- ### NDT7Settings Structure Source: https://github.com/m-lab/ndt7-client-ios/blob/main/docs/Structs.html Details the NDT7Settings structure for configuring NDT7 client behavior. ```APIDOC ## NDT7Settings Structure ### Description NDT7Settings allows for the configuration of various parameters for the NDT7 client. ### Method N/A (Structure Definition) ### Endpoint N/A (Structure Definition) ### Parameters #### Request Body - **ServerSelectionBehavior** (Enum) - Strategy for selecting the NDT7 server. - **URLBag** (NDT7URL) - Configuration for URLs used by the client. - **Timeouts** (NDT7Timeouts) - Configuration for various timeouts. ### Request Example ```json { "ServerSelectionBehavior": "random", "URLBag": { "MlabNS": "https://mlab-ns.appspot.com/redirect/ndt7" }, "Timeouts": { "ConnectTimeout": 5.0, "ControlPathTimeout": 10.0, "KeepAliveInterval": 30.0 } } ``` ### Response #### Success Response (200) - **ServerSelectionBehavior** (Enum) - Strategy for selecting the NDT7 server. - **URLBag** (NDT7URL) - Configuration for URLs used by the client. - **Timeouts** (NDT7Timeouts) - Configuration for various timeouts. #### Response Example ```json { "ServerSelectionBehavior": "random", "URLBag": { "MlabNS": "https://mlab-ns.appspot.com/redirect/ndt7" }, "Timeouts": { "ConnectTimeout": 5.0, "ControlPathTimeout": 10.0, "KeepAliveInterval": 30.0 } } ``` ``` -------------------------------- ### Add NDT7 Client Dependency using Carthage Source: https://github.com/m-lab/ndt7-client-ios/blob/main/README.md This snippet shows how to add the NDT7 client library as a dependency in your iOS project using Carthage. It involves creating a Cartfile with the specified dependency and running the 'carthage update' command to fetch and build the framework. ```bash github "m-lab/ndt7-client-ios" ~> 0.0.4 ``` ```bash $ carthage update ``` -------------------------------- ### NDT7Settings Source: https://github.com/m-lab/ndt7-client-ios/blob/main/docs/Structs.html Configuration settings for the NDT7 client, allowing customization of various parameters. ```APIDOC ## NDT7Settings ### Description Struct for configuring NDT7 client behavior. Can be initialized with default values. ### Declaration ```swift public struct NDT7Settings ``` ### Usage ```swift let settings = NDT7Settings() ``` ``` -------------------------------- ### Enable Logging in NDT7 iOS Client Source: https://context7.com/m-lab/ndt7-client-ios/llms.txt This snippet demonstrates how to enable debug logging for the NDT7 framework in an iOS application. Enabling logging provides visibility into the framework's internal activities, which can be useful for debugging and understanding test execution flow. No specific inputs or outputs are required, and it has no external dependencies beyond the NDT7 framework itself. ```swift import NDT7 // Enable debug logging to see framework activity NDT7.loggingEnabled = true ``` -------------------------------- ### Add NDT7 to Cartfile for Carthage Source: https://github.com/m-lab/ndt7-client-ios/blob/main/docs/index.html This snippet shows how to declare the NDT7 dependency in a Cartfile for use with Carthage. It specifies the GitHub repository and the versioning strategy. ```text github "m-lab/ndt7-client-ios" ~> 0.0.2 ``` -------------------------------- ### NDT7URL - URL Settings Source: https://github.com/m-lab/ndt7-client-ios/blob/main/docs/Structs.html Defines the URL configuration for the NDT7 client, specifying endpoints for measurements. ```APIDOC ## NDT7URL ### Description Struct for managing URL settings related to NDT7 measurements. ### Declaration ```swift public struct NDT7URL ``` ``` -------------------------------- ### NDT7ConnectionInfo Structure Source: https://github.com/m-lab/ndt7-client-ios/blob/main/docs/docsets/ndt7.docset/Contents/Resources/Documents/Structs/NDT7ConnectionInfo.html Provides details about the NDT7ConnectionInfo structure, including its properties and their descriptions. This is an optional object for connection information. ```APIDOC ## NDT7ConnectionInfo Structure ### Description NDT7ConnectionInfo is an optional object used to provide information about the connection four tuple. Servers MUST send this message exactly once. Clients SHOULD cache the first received instance of this message and discard any subsequently received instance. ### Method Not Applicable (Structure Definition) ### Endpoint Not Applicable (Structure Definition) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **client** (String?) - The serialization of the client endpoint according to the server. - **server** (String?) - The serialization of the server endpoint according to the server. - **uuid** (String?) - An internal unique identifier for this test within the Measurement Lab (M-Lab) platform. #### Response Example ```json { "client": "192.168.1.100:54321", "server": "10.0.0.1:3000", "uuid": "abc123xyz789" } ``` ``` -------------------------------- ### NDT7Timeouts - Timeout Settings Source: https://github.com/m-lab/ndt7-client-ios/blob/main/docs/Structs.html Manages timeout configurations for the NDT7 client operations. ```APIDOC ## NDT7Timeouts ### Description Struct for configuring timeout parameters for NDT7 tests. ### Declaration ```swift public struct NDT7Timeouts ``` ``` -------------------------------- ### NDT7TCPInfo Structure Source: https://github.com/m-lab/ndt7-client-ios/blob/main/docs/Structs/NDT7TCPInfo.html Provides details about TCP connection statistics including round-trip time, buffer limits, and data transfer metrics. ```APIDOC ## NDT7TCPInfo Structure Reference ### Description NDT7TCPInfo is an optional object that provides TCP connection statistics when available. It helps in analyzing network performance by offering insights into round-trip time, buffer behavior, and data transfer efficiency. ### Method N/A (Structure Definition) ### Endpoint N/A (Structure Definition) ### Parameters #### Structure Fields - **busyTime** (Int64?) - Optional - The number of microseconds spent actively sending data because the write queue of the TCP socket is non-empty. - **bytesAcked** (Int64?) - Optional - The number of bytes acknowledged by the receiver. This count includes WebSocket and TLS overhead. - **bytesReceived** (Int64?) - Optional - The number of bytes received by the receiver. This count includes WebSocket and TLS overhead. ### Request Example N/A (Structure Definition) ### Response #### Structure Definition ```swift public struct NDT7TCPInfo : Codable ``` #### Response Example N/A (Structure Definition) ### Error Handling N/A (Structure Definition) ``` -------------------------------- ### NDT7ConnectionInfo Structure Source: https://github.com/m-lab/ndt7-client-ios/blob/main/docs/docsets/ndt7.docset/Contents/Resources/Documents/Structs.html Provides information about the connection's four-tuple (client IP:port, server IP:port, and a unique identifier). Servers must send this once; clients should cache the first instance. ```APIDOC ## NDT7ConnectionInfo Structure ### Description Used to convey information about the connection's source and destination IP addresses and ports, along with a unique identifier for the test session. Servers are required to send this message exactly once, and clients should cache the first received message. ### Method N/A (Data Structure) ### Endpoint N/A (Data Structure) ### Parameters #### Request Body - **Client** (string) - Required - The client's IP address and port (e.g., "1.2.3.4:5678"). - **Server** (string) - Required - The server's IP address and port (e.g., "[::1]:2345"). - **UUID** (string) - Required - A platform-specific unique identifier for the test session. ### Request Example ```json { "Client": "1.2.3.4:5678", "Server": "[::1]:2345", "UUID": "a1b2c3d4-e5f6-7890-1234-567890abcdef" } ``` ### Response #### Success Response (200) - **NDT7ConnectionInfo** (object) - The connection information object. #### Response Example ```json { "Client": "1.2.3.4:5678", "Server": "[::1]:2345", "UUID": "a1b2c3d4-e5f6-7890-1234-567890abcdef" } ``` ``` -------------------------------- ### NDT7URL Structure Definition and Properties Source: https://github.com/m-lab/ndt7-client-ios/blob/main/docs/Structs/NDT7URL.html Defines the NDT7URL structure for configuring test URLs. It includes properties for server details, hostnames, download and upload paths, WebSocket usage, and computed download/upload URLs. The structure also provides an initializer to set these properties. ```Swift public struct NDT7URL { public var server: NDT7Server? public var hostname: String public let downloadPath: String public let uploadPath: String public let wss: Bool public var download: String { get } public var upload: String { get } public init(hostname: String, downloadPath: String = NDT7WebSocketConstants.Request.downloadPath, uploadPath: String = NDT7WebSocketConstants.Request.uploadPath, wss: Bool = true) } ``` -------------------------------- ### NDT7Settings Structure Source: https://github.com/m-lab/ndt7-client-ios/blob/main/docs/Structs/NDT7Settings.html The NDT7Settings structure defines the configuration parameters required for establishing and conducting an NDT7 test. It allows for customization of the WebSocket URL, connection timeouts, TLS certificate verification, geographical server selection, and HTTP headers. ```APIDOC ## NDT7Settings Structure ### Description The `NDT7Settings` structure encapsulates all the necessary settings for configuring an NDT7 test. This includes the WebSocket endpoint URL, various timeout values, options for TLS certificate verification, and the ability to specify custom headers for the request. ### Method N/A (This is a structure definition, not an API endpoint) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body This structure is typically used to initialize settings, not directly as a request body in a standard HTTP sense. However, it can be serialized or used to configure client-side test parameters. - **url** (NDT7URL) - Required - The URL for the WebSocket connection. - **timeout** (NDT7Timeouts) - Required - Configuration for various test timeouts. - **skipTLSCertificateVerification** (Bool) - Optional - If true, TLS certificate verification is skipped. Defaults to true. - **useGeoOptions** (Bool) - Optional - If true, uses geo options to fetch a list of Mlab servers; otherwise, connects to the closest one. Defaults to false. - **headers** ([String: String]) - Optional - A dictionary of custom headers to be included in the NDT7 request. Defaults to a basic protocol header. ### Request Example ```swift // Example of initializing NDT7Settings with default values let defaultSettings = NDT7Settings() // Example of initializing NDT7Settings with custom values let customURL = NDT7URL(hostname: "mlab.example.com") let customTimeouts = NDT7Timeouts(handshake: 10, upload: 20, download: 30) let customSettings = NDT7Settings( url: customURL, timeout: customTimeouts, skipTLSCertificateVerification: false, useGeoOptions: true, headers: ["X-Custom-Header": "MyValue"] ) ``` ### Response N/A (This is a client-side configuration structure) #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### NDT7BBRInfo Structure Source: https://github.com/m-lab/ndt7-client-ios/blob/main/docs/docsets/ndt7.docset/Contents/Resources/Documents/Structs.html Contains optional BBR (Bottleneck Bandwidth and Round-trip propagation time) congestion control information. ```APIDOC ## NDT7BBRInfo Structure ### Description An optional object that provides access to TCP_CC_INFO statistics specifically for the BBR congestion control algorithm. This is included when available and relevant. ### Method N/A (Data Structure) ### Endpoint N/A (Data Structure) ### Parameters N/A (Specific fields depend on the underlying OS and BBR implementation, typically includes metrics like pacing gain, bandwidth gain, etc.) ### Request Example N/A ### Response #### Success Response (200) - **NDT7BBRInfo** (object) - The BBR information object, containing relevant BBR statistics if available. #### Response Example ```json { "BBRInfo": { "PacingGain": 1.2, "BandwidthGain": 1.5 } } ``` ``` -------------------------------- ### NDT7ConnectionInfo Structure Source: https://github.com/m-lab/ndt7-client-ios/blob/main/docs/Structs.html Provides information about the connection's four-tuple. Servers must send this once. Clients should cache the first instance. Conforms to Codable in Swift. ```swift public struct NDT7ConnectionInfo : Codable ``` -------------------------------- ### NDT7URL Structure Source: https://github.com/m-lab/ndt7-client-ios/blob/main/docs/Structs.html Defines the NDT7URL structure for managing client URLs. ```APIDOC ## NDT7URL Structure ### Description NDT7URL structure holds the URLs used by the NDT7 client, including the M-Lab NS redirector. ### Method N/A (Structure Definition) ### Endpoint N/A (Structure Definition) ### Parameters #### Request Body - **MlabNS** (string) - The URL for the M-Lab Name Server redirector. ### Request Example ```json { "MlabNS": "https://mlab-ns.appspot.com/redirect/ndt7" } ``` ### Response #### Success Response (200) - **MlabNS** (string) - The URL for the M-Lab Name Server redirector. #### Response Example ```json { "MlabNS": "https://mlab-ns.appspot.com/redirect/ndt7" } ``` ``` -------------------------------- ### NDT7TCPInfo - TCP Performance Metrics Source: https://github.com/m-lab/ndt7-client-ios/blob/main/docs/Structs.html Provides detailed information about TCP connection performance, including round-trip time statistics, buffer limitations, and data transfer rates. ```APIDOC ## NDT7TCPInfo ### Description Represents detailed TCP performance metrics gathered during an NDT7 test. This includes statistics on Round-Trip Time (RTT), buffer utilization, and data transfer volume, which are crucial for diagnosing network performance bottlenecks. ### Fields #### MinRTT (Double) - **Description**: The minimum observed Round-Trip Time during the test. Useful for verifying server proximity and detecting potential performance-enhancing proxies. #### RTT (Double) - **Description**: The average Round-Trip Time observed during the test. #### RTTVar (Double) - **Description**: The variation in Round-Trip Time during the test. #### BusyTime (Double) - **Description**: The amount of time the sender was actively transmitting data. #### RWndLimited (Double) - **Description**: The amount of time the transfer was limited by the receiver's buffer space. A high value indicates insufficient receiver buffering. #### SndBufLimited (Double) - **Description**: The amount of time the transfer was limited by the sender's buffer space. A high value indicates insufficient sender buffering. #### BytesAcked (Int64) - **Description**: The total number of bytes acknowledged by the receiver. Primarily relevant for the sender (e.g., server during download). #### BytesReceived (Int64) - **Description**: The total number of bytes received by the receiver. Primarily relevant for the receiver (e.g., server during upload). #### BytesSent (Int64) - **Description**: The total number of bytes sent by the sender. #### BytesRetrans (Int64) - **Description**: The total number of bytes that were retransmitted due to packet loss. #### ElapsedTime (Double) - **Description**: The total duration of the NDT7 test in seconds. ### Calculations - **Average Speed (Bytes per second)**: `(BytesAcked / ElapsedTime) * 10^6` - **Average Speed (Bits per second)**: `(BytesAcked / ElapsedTime) * 10^6 * 8` - **Retransmission Percentage**: `(BytesRetrans / BytesSent) * 100` (approximates packet loss rate) ### Example ```json { "MinRTT": 0.015, "RTT": 0.025, "RTTVar": 0.002, "BusyTime": 9.5, "RWndLimited": 0.1, "SndBufLimited": 0.2, "BytesAcked": 100000000, "BytesReceived": 100000000, "BytesSent": 100005000, "BytesRetrans": 5000, "ElapsedTime": 10.0 } ``` ``` -------------------------------- ### NDT7Server Properties Source: https://github.com/m-lab/ndt7-client-ios/blob/main/docs/Structs/NDT7Server.html Defines the properties of an Mlab NDT7 server, including its IP address, geographical location, and Fully Qualified Domain Name (FQDN). These properties are crucial for establishing a connection to the appropriate testing server. ```swift public var ip: [String]? public var country: String? public var city: String? public var fqdn: String? public var site: String? ``` -------------------------------- ### NDT7APPInfo Structure Definition Source: https://github.com/m-lab/ndt7-client-ios/blob/main/docs/Structs/NDT7APPInfo.html Defines the NDT7APPInfo structure, which is Codable and holds optional Int64 values for elapsed time and the number of bytes sent/received at the application layer. This structure is only included in measurements when application-level data is available. ```swift public struct NDT7APPInfo : Codable { public let elapsedTime: Int64? public var numBytes: Int64? } ``` -------------------------------- ### NDT7APPInfo Structure Source: https://github.com/m-lab/ndt7-client-ios/blob/main/docs/Structs/NDT7APPInfo.html This section details the NDT7APPInfo structure, an optional object used in NDT7 measurements when application-level data is available. ```APIDOC ## NDT7APPInfo Structure ### Description NDT7APPInfo is an optional object only included in the measurement when an application-level measurement is available. ### Type `Codable struct` ### Properties #### `elapsedTime` - **Type**: `Int64?` - **Description**: The time elapsed since the beginning of this test, measured in microseconds. #### `numBytes` - **Type**: `Int64?` - **Description**: The number of bytes sent (or received) since the beginning of the specific test. This counter tracks application-level data and does not include protocol overhead. ``` -------------------------------- ### NDT7Settings Properties - Swift Source: https://github.com/m-lab/ndt7-client-ios/blob/main/docs/Structs/NDT7Settings.html Defines the properties of the NDT7Settings structure, which are used to configure the NDT7 client. These include the WebSocket URL, connection timeouts, options for TLS certificate verification, geo-based server selection, and custom request headers. ```swift public var url: NDT7URL ``` ```swift public let timeout: NDT7Timeouts ``` ```swift public let skipTLSCertificateVerification: Bool ``` ```swift public let useGeoOptions: Bool ``` ```swift public let headers: [String : String] ``` -------------------------------- ### NDT7APPInfo Structure Source: https://github.com/m-lab/ndt7-client-ios/blob/main/docs/Structs.html An optional structure included in measurements when application-level data is available. It conforms to Codable in Swift. ```swift public struct NDT7APPInfo : Codable ``` -------------------------------- ### NDT7Server Structure Declaration (Swift) Source: https://github.com/m-lab/ndt7-client-ios/blob/main/docs/Structs.html Declares the NDT7Server structure, representing an Mlab NDT7 server. This structure is Codable, facilitating its use in data exchange and configuration. ```swift public struct NDT7Server : Codable ``` -------------------------------- ### NDT7BBRInfo Structure Definition Source: https://github.com/m-lab/ndt7-client-ios/blob/main/docs/docsets/ndt7.docset/Contents/Resources/Documents/Structs/NDT7BBRInfo.html Defines the NDT7BBRInfo structure, which conforms to the Codable protocol. This structure is intended to hold optional BBR (Bottleneck Bandwidth and Round-trip propagation time) congestion control statistics, providing insights into network performance during NDT7 tests. ```swift public struct NDT7BBRInfo : Codable public let elapsedTime: Int64? public let bandwith: Int64? public let minRtt: Int64? public let pacingGain: Int64? public let cwndGain: Int64? ``` -------------------------------- ### Configure App Transport Security Exception in Info.plist Source: https://github.com/m-lab/ndt7-client-ios/blob/main/README.md This Swift code snippet demonstrates how to configure the Info.plist file to bypass App Transport Security restrictions for the 'locate.measurementlab.net' domain. This is necessary for M-Lab server discovery if data transmission requires secure channels and your app needs to make exceptions. ```swift NSAppTransportSecurity NSExceptionDomains locate.measurementlab.net NSIncludesSubdomains NSThirdPartyExceptionAllowsInsecureHTTPLoads ``` -------------------------------- ### Define NDT7BBRInfo Structure in Swift Source: https://github.com/m-lab/ndt7-client-ios/blob/main/docs/Structs/NDT7BBRInfo.html Defines the NDT7BBRInfo structure, which holds optional BBR performance metrics like elapsed time, bandwidth, minimum RTT, pacing gain, and congestion window gain. This structure is decodable and encodable, making it suitable for data serialization. ```swift public struct NDT7BBRInfo : Codable { public let elapsedTime: Int64? public let bandwith: Int64? public let minRtt: Int64? public let pacingGain: Int64? public let cwndGain: Int64? } ``` -------------------------------- ### NDT7ConnectionInfo Structure Source: https://github.com/m-lab/ndt7-client-ios/blob/main/docs/Structs.html Defines the NDT7ConnectionInfo structure, used for providing connection four-tuple information. ```APIDOC ## NDT7ConnectionInfo Structure ### Description NDT7ConnectionInfo provides information about the connection's four-tuple (source IP, source port, destination IP, destination port). Servers MUST send this exactly once, and clients SHOULD cache the first received instance. ### Method N/A (Structure Definition) ### Endpoint N/A (Structure Definition) ### Parameters #### Request Body - **Client** (string) - The client's source IP address and port (e.g., "1.2.3.4:5678"). - **Server** (string) - The server's source IP address and port (e.g., "::1:2345"). - **UUID** (string) - A platform-specific unique identifier for the connection. ### Request Example ```json { "Client": "1.2.3.4:5678", "Server": "::1:2345", "UUID": "some-uuid-string" } ``` ### Response #### Success Response (200) - **Client** (string) - The client's source IP address and port. - **Server** (string) - The server's source IP address and port. - **UUID** (string) - A platform-specific unique identifier for the connection. #### Response Example ```json { "Client": "1.2.3.4:5678", "Server": "::1:2345", "UUID": "some-uuid-string" } ``` ``` -------------------------------- ### NDT7BBRInfo Structure Source: https://github.com/m-lab/ndt7-client-ios/blob/main/docs/Structs.html An optional structure for accessing TCP_CC_INFO statistics for BBR. It conforms to Codable in Swift. ```swift public struct NDT7BBRInfo : Codable ```