iperf-watcher/src/iperf3.zig
2023-10-14 21:19:20 -05:00

125 lines
3.4 KiB
Zig

const std = @import("std");
pub const IPerfReturn = struct {
start: struct {
connected: []struct {
socket: u64,
local_host: []const u8,
local_port: u16,
remote_host: []const u8,
remote_port: u16,
},
version: []const u8,
system_info: []const u8,
sock_bufsize: ?u64 = null,
sndbuf_actual: ?u64 = null,
rcvbuf_actual: ?u64 = null,
timestamp: ?struct {
time: []const u8,
timesecs: u64,
} = null,
accepted_connection: ?struct {
host: []const u8,
port: u16,
} = null,
cookie: ?[]const u8 = null,
tcp_mss_default: ?u64 = null,
target_bitrate: ?u64 = null,
fq_rate: ?u64 = null,
test_start: ?struct {
protocol: []const u8,
num_streams: u64,
blksize: u64,
omit: u64,
duration: u64,
bytes: u64,
blocks: u64,
reverse: u64,
tos: u64,
target_bitrate: u64,
bidir: u64,
fqrate: u64,
},
},
intervals: []struct {
streams: []struct {
socket: u64,
start: f128,
end: f128,
seconds: f128,
bytes: u64,
bits_per_second: f128,
omitted: bool,
sender: bool,
},
sum: struct {
start: f128,
end: f128,
seconds: f128,
bytes: u64,
bits_per_second: f128,
omitted: bool,
sender: bool,
},
},
end: struct {
streams: ?[]struct {
sender: struct {
socket: u64,
start: f128,
end: f128,
seconds: f128,
bytes: u64,
bits_per_second: f128,
sender: bool,
},
receiver: struct {
socket: u64,
start: f128,
end: f128,
seconds: f128,
bytes: u64,
bits_per_second: f128,
sender: bool,
},
} = null,
sum_sent: ?struct {
start: f128,
end: f128,
seconds: f128,
bytes: u64,
bits_per_second: f128,
sender: bool,
} = null,
sum_received: ?struct {
start: f128,
end: f128,
seconds: f128,
bytes: u64,
bits_per_second: f128,
sender: bool,
} = null,
cpu_utilization_percent: ?struct {
host_total: f128,
host_user: f128,
host_system: f128,
remote_total: f128,
remote_user: f128,
remote_system: f128,
} = null,
receiver_tcp_congestion: ?[]const u8 = null,
},
@"error": ?[]const u8 = null,
};
test "test-normal" {
const input = @embedFile("test/test-normal.json");
const result = try std.json.parseFromSlice(IPerfReturn, std.testing.allocator, input, .{});
defer result.deinit();
// std.debug.print("{}\n", .{result.value});
// const test_output = try std.fs.cwd().createFile("test.json", .{});
// try std.json.stringify(result.value, .{}, test_output.writer());
// test_output.close();
try std.testing.expect(result.value.@"error" == null);
}