diff --git a/Sources/Tools/QUICTransfer/main.swift b/Sources/Tools/QUICTransfer/main.swift index f1e32fc..cdf35dc 100644 --- a/Sources/Tools/QUICTransfer/main.swift +++ b/Sources/Tools/QUICTransfer/main.swift @@ -43,9 +43,18 @@ final class QUICTransfer { let NSEC_PER_MSEC = UInt64(Duration.milliseconds(1) / Duration.nanoseconds(1)) var serverSigningKey = P256.Signing.PrivateKey() - func run(iterations: Int, loggingHandle: LoggingHandle, group: DispatchGroup, sendSize: Int) -> Double { - let ipv4Client = Endpoint(address: IPv4Address(localIPv4Address)!, port: 0) - let ipv4Server = Endpoint(address: IPv4Address(remoteIPv4Address)!, port: 0) + func run( + iterations: Int, + loggingHandle: LoggingHandle, + group: DispatchGroup, + sendSize: Int, + linkDelay: NetworkDuration = .zero + ) -> Double { + let ipv4Client = Endpoint(address: IPv4Address(localIPv4Address)!, port: 1234) + let ipv4Server = Endpoint(address: IPv4Address(remoteIPv4Address)!, port: 2345) + var clientStream: StreamUpperHarness? = nil + var clientInput: NewStreamFlowHarness? = nil + var serverInput: NewStreamFlowHarness? = nil // Create a random payload to send back and forth var payload = [UInt8](repeating: 0, count: sendSize) payload = (0.. Void)? = nil + serverReadCompletion = { _ in + let readBytes = serverStream.readAndDrop() + if readBytes > 0 { + serverReadDataSizeForIteration += readBytes + totalReadSize += readBytes + } + if serverReadDataSizeForIteration >= payload.count { + serverReadCompletion = nil + index += 1 + group.leave() + } else { + serverStream.waitForInboundDataAvailable(completion: serverReadCompletion!) + } + } + serverStream.waitForInboundDataAvailable(completion: serverReadCompletion!) + } + group.wait() + } + + group.enter() + context.async { + clientStream.stop() clientInput.stop() clientInput.teardown() serverInput.stop() @@ -264,6 +305,7 @@ final class QUICTransfer { group.leave() } group.wait() + print("Completed \(index) / \(iterations) transfers") // Short circuit and return 0 if index does not match iterations if index != iterations { @@ -281,6 +323,7 @@ final class QUICTransfer { var iterations = 10000 // 5gb total (if 500000 sendSize) var loggingHandler: LoggingHandle = LoggingHandle(loggingType: .none) var sendSize = 500000 // 500kb +var linkDelay = NetworkDuration.zero var arguments = CommandLine.arguments.dropFirst(0) if arguments.contains("-iterations"), let index = arguments.firstIndex(of: "-iterations") @@ -310,6 +353,15 @@ if arguments.contains("-size"), } } } +if arguments.contains("-link-delay-ms"), + let index = arguments.firstIndex(of: "-link-delay-ms") +{ + if arguments.count >= (index + 2) { + if let linkDelayOption = Int(arguments[index + 1]) { + linkDelay = .milliseconds(linkDelayOption) + } + } +} // Create and run the transfers let quicTransfer = QUICTransfer() @@ -319,7 +371,8 @@ let totalTime = quicTransfer.run( iterations: iterations, loggingHandle: loggingHandler, group: group, - sendSize: sendSize + sendSize: sendSize, + linkDelay: linkDelay ) if totalTime > 0 { print("Finished all (\(iterations)) transfers in \(totalTime) seconds")