@mark1russell7/harness 0.16.8 → 0.16.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/build/index.d.ts +12 -1
- package/build/index.js +39 -2
- package/build/index.js.map +1 -1
- package/image/native/src/bin/ports.rs +33 -1
- package/image/native/src/lib.rs +111 -2
- package/package.json +1 -1
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
//!
|
|
9
9
|
//! The target listens on PORT and on PORT + 2, the two destinations of a cell. It serves one command
|
|
10
10
|
//! on PORT + 1, its control port: `close COUNT` waits until it holds COUNT connections, and closes them.
|
|
11
|
+
//! `stack` gives the counters of the network stack of the target (`stack_counters`).
|
|
11
12
|
//!
|
|
12
13
|
//! The client does these steps in each round:
|
|
13
14
|
//!
|
|
@@ -22,6 +23,10 @@
|
|
|
22
23
|
//! closes it, and waits `--settle-ms`. With `--reclaim`, the client reads each FIN first. It then
|
|
23
24
|
//! writes `closing` and closes each connection. It connects again as after `--close client`.
|
|
24
25
|
//!
|
|
26
|
+
//! Before its first round and after its last round, the client writes two `stack` lines: the counters
|
|
27
|
+
//! of its own network stack, then those of the target. The change of a counter between the two lines
|
|
28
|
+
//! tells where a segment went, for example a drop at a full backlog or an ACK that the target skipped.
|
|
29
|
+
//!
|
|
25
30
|
//! With `--mode inflight`, the client writes `ready` and waits for the file `/tmp/go` before its first
|
|
26
31
|
//! round. The harness makes this file after it applies the fault, thus the fault acts on each round.
|
|
27
32
|
//!
|
|
@@ -30,7 +35,7 @@
|
|
|
30
35
|
//! reset and holds no port. A FIN at the exit of the client holds that port in TIME_WAIT for 60 s. A
|
|
31
36
|
//! range of 3 has only 2 ports for a search. Thus the third run of an environment had no control port.
|
|
32
37
|
|
|
33
|
-
use harness_native::emit;
|
|
38
|
+
use harness_native::{emit, stack_counters};
|
|
34
39
|
use prober::{errno_name, monotonic_ns};
|
|
35
40
|
use serde_json::{json, Value};
|
|
36
41
|
use std::error::Error;
|
|
@@ -83,6 +88,7 @@ fn serve(stream: TcpStream, held: &Mutex<Vec<TcpStream>>) -> Result<(), Box<dyn
|
|
|
83
88
|
let mut words = line.split_whitespace();
|
|
84
89
|
let reply = match (words.next(), words.next().and_then(|word| word.parse::<usize>().ok())) {
|
|
85
90
|
(Some("close"), Some(count)) => json!({ "closed": close_held(held, count) }),
|
|
91
|
+
(Some("stack"), None) if line.trim() == "stack" => json!({ "stack": stack_counters() }),
|
|
86
92
|
_ => json!({ "refused": line }),
|
|
87
93
|
};
|
|
88
94
|
writeln!(writer, "{reply}")?;
|
|
@@ -195,6 +201,14 @@ impl Control {
|
|
|
195
201
|
}
|
|
196
202
|
}
|
|
197
203
|
|
|
204
|
+
/// Writes the two `stack` lines: the counters of the client, then those of the target, at the point `at`.
|
|
205
|
+
fn stack_lines(at: &str, control: &mut Control) -> Result<(), Box<dyn Error>> {
|
|
206
|
+
emit("stack", json!({ "side": "client", "at": at, "counters": stack_counters() }));
|
|
207
|
+
let reply = control.ask("stack")?;
|
|
208
|
+
emit("stack", json!({ "side": "target", "at": at, "counters": reply["stack"] }));
|
|
209
|
+
Ok(())
|
|
210
|
+
}
|
|
211
|
+
|
|
198
212
|
/// Closes a connection with a reset: SO_LINGER with a time of 0, then close(2).
|
|
199
213
|
fn reset(stream: TcpStream) -> std::io::Result<()> {
|
|
200
214
|
abortive(&stream)
|
|
@@ -340,6 +354,7 @@ fn client(args: &[String]) -> Result<(), Box<dyn Error>> {
|
|
|
340
354
|
std::thread::sleep(Duration::from_millis(1));
|
|
341
355
|
}
|
|
342
356
|
}
|
|
357
|
+
stack_lines("start", &mut control)?;
|
|
343
358
|
for index in 0..plan.rounds {
|
|
344
359
|
let mut held = Vec::new();
|
|
345
360
|
for destination in &destinations {
|
|
@@ -347,6 +362,7 @@ fn client(args: &[String]) -> Result<(), Box<dyn Error>> {
|
|
|
347
362
|
}
|
|
348
363
|
close_round(&plan, destinations[0], &mut control, held)?;
|
|
349
364
|
}
|
|
365
|
+
stack_lines("end", &mut control)?;
|
|
350
366
|
emit("done", json!({}));
|
|
351
367
|
Ok(())
|
|
352
368
|
}
|
|
@@ -389,6 +405,22 @@ mod tests {
|
|
|
389
405
|
assert!(plan_of(&["--close".to_string(), "soon".to_string(), "h".to_string(), "1".to_string()]).is_err());
|
|
390
406
|
}
|
|
391
407
|
|
|
408
|
+
#[test]
|
|
409
|
+
fn the_control_port_gives_the_counters_of_the_stack_and_refuses_another_word() {
|
|
410
|
+
let listener = TcpListener::bind((Ipv4Addr::LOCALHOST, 0)).expect("a listener");
|
|
411
|
+
let address = listener.local_addr().expect("an address");
|
|
412
|
+
let held = Arc::new(Mutex::new(Vec::new()));
|
|
413
|
+
std::thread::spawn(move || {
|
|
414
|
+
let (stream, _) = listener.accept().expect("an accept");
|
|
415
|
+
serve(stream, &held).expect("the control lines");
|
|
416
|
+
});
|
|
417
|
+
let stream = TcpStream::connect(address).expect("a connect");
|
|
418
|
+
let mut control = Control { reader: BufReader::new(stream.try_clone().expect("a clone")), writer: stream };
|
|
419
|
+
let reply = control.ask("stack").expect("a reply");
|
|
420
|
+
assert!(reply["stack"]["Tcp.ActiveOpens"].as_u64().is_some(), "{reply}");
|
|
421
|
+
assert_eq!(control.ask("stack now").expect("a reply")["refused"], "stack now");
|
|
422
|
+
}
|
|
423
|
+
|
|
392
424
|
#[test]
|
|
393
425
|
fn a_range_with_no_free_port_is_refused_with_its_name() {
|
|
394
426
|
assert_eq!(errno_of(&std::io::Error::from_raw_os_error(libc::EADDRNOTAVAIL)), "EADDRNOTAVAIL");
|
package/image/native/src/lib.rs
CHANGED
|
@@ -1,10 +1,84 @@
|
|
|
1
|
-
//! What the programs of the harness's native side share: their event lines
|
|
2
|
-
//! schedule.
|
|
1
|
+
//! What the programs of the harness's native side share: their event lines, the arrivals of a
|
|
2
|
+
//! schedule and the counters of the network stack.
|
|
3
3
|
|
|
4
4
|
use prober::monotonic_ns;
|
|
5
5
|
use serde_json::{json, Value};
|
|
6
|
+
use std::collections::BTreeMap;
|
|
6
7
|
use std::error::Error;
|
|
7
8
|
|
|
9
|
+
/// The counters of the network stack, each by its name, for example `Tcp.RetransSegs`,
|
|
10
|
+
/// `TcpExt.TCPACKSkippedTimeWait`, `Dev.eth0.rx_drop` or `Softnet.dropped`. The files of snmp,
|
|
11
|
+
/// netstat and dev are of the namespace of the caller. The file softnet_stat is of the host.
|
|
12
|
+
pub fn stack_counters() -> BTreeMap<String, u64> {
|
|
13
|
+
let read = |path: &str| std::fs::read_to_string(path).unwrap_or_default();
|
|
14
|
+
let mut counters = pairs_of(&read("/proc/net/snmp"));
|
|
15
|
+
counters.extend(pairs_of(&read("/proc/net/netstat")));
|
|
16
|
+
counters.extend(devices_of(&read("/proc/net/dev")));
|
|
17
|
+
counters.extend(softnet_of(&read("/proc/net/softnet_stat")));
|
|
18
|
+
counters
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/// Reads the format of /proc/net/snmp and /proc/net/netstat: a line of names, then a line of values
|
|
22
|
+
/// with the same prefix. A value that is not a count, as the -1 of `Tcp.MaxConn`, is skipped.
|
|
23
|
+
pub fn pairs_of(text: &str) -> BTreeMap<String, u64> {
|
|
24
|
+
let lines: Vec<&str> = text.lines().collect();
|
|
25
|
+
let mut counters = BTreeMap::new();
|
|
26
|
+
let mut at = 0;
|
|
27
|
+
while at + 1 < lines.len() {
|
|
28
|
+
let (Some((prefix, names)), Some((other, values))) = (lines[at].split_once(':'), lines[at + 1].split_once(':')) else {
|
|
29
|
+
at += 1;
|
|
30
|
+
continue;
|
|
31
|
+
};
|
|
32
|
+
if prefix != other || values.split_whitespace().next().is_some_and(|first| first.parse::<i64>().is_err()) {
|
|
33
|
+
at += 1;
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
for (name, value) in names.split_whitespace().zip(values.split_whitespace()) {
|
|
37
|
+
if let Ok(value) = value.parse::<u64>() {
|
|
38
|
+
counters.insert(format!("{prefix}.{name}"), value);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
at += 2;
|
|
42
|
+
}
|
|
43
|
+
counters
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/// The columns of /proc/net/dev that the counters keep, by their place after the name of the device.
|
|
47
|
+
const DEVICE_COLUMNS: [(usize, &str); 6] =
|
|
48
|
+
[(1, "rx_packets"), (2, "rx_errs"), (3, "rx_drop"), (9, "tx_packets"), (10, "tx_errs"), (11, "tx_drop")];
|
|
49
|
+
|
|
50
|
+
/// Reads /proc/net/dev: one line for each device, after two lines of headings.
|
|
51
|
+
pub fn devices_of(text: &str) -> BTreeMap<String, u64> {
|
|
52
|
+
let mut counters = BTreeMap::new();
|
|
53
|
+
for line in text.lines() {
|
|
54
|
+
let Some((device, values)) = line.split_once(':') else { continue };
|
|
55
|
+
let values: Vec<u64> = values.split_whitespace().filter_map(|value| value.parse().ok()).collect();
|
|
56
|
+
if values.len() < 16 {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
for (column, name) in DEVICE_COLUMNS {
|
|
60
|
+
counters.insert(format!("Dev.{}.{name}", device.trim()), values[column]);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
counters
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/// Reads /proc/net/softnet_stat: one line of hexadecimal columns for each processor. The sums of the
|
|
67
|
+
/// first three columns are the packets processed, the packets dropped at a full backlog, and the
|
|
68
|
+
/// rounds that ended with work left.
|
|
69
|
+
pub fn softnet_of(text: &str) -> BTreeMap<String, u64> {
|
|
70
|
+
let mut sums = [0u64; 3];
|
|
71
|
+
for line in text.lines() {
|
|
72
|
+
for (sum, value) in sums.iter_mut().zip(line.split_whitespace()) {
|
|
73
|
+
*sum += u64::from_str_radix(value, 16).unwrap_or(0);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if text.trim().is_empty() {
|
|
77
|
+
return BTreeMap::new();
|
|
78
|
+
}
|
|
79
|
+
["processed", "dropped", "squeezed"].iter().zip(sums).map(|(name, sum)| (format!("Softnet.{name}"), sum)).collect()
|
|
80
|
+
}
|
|
81
|
+
|
|
8
82
|
/// Prints one event line, with the time of the call on CLOCK_MONOTONIC.
|
|
9
83
|
pub fn emit(event: &str, fields: Value) {
|
|
10
84
|
emit_at(event, monotonic_ns(), fields);
|
|
@@ -48,4 +122,39 @@ mod tests {
|
|
|
48
122
|
assert!(arrivals_of(r#"{"format":"rigor-schedule/1"}"#).is_err());
|
|
49
123
|
assert!(arrivals_of(r#"{"format":"rigor-schedule/1","times":["a"]}"#).is_err());
|
|
50
124
|
}
|
|
125
|
+
|
|
126
|
+
#[test]
|
|
127
|
+
fn the_counters_of_snmp_and_netstat_come_by_prefix_and_name() {
|
|
128
|
+
let snmp = "Ip: Forwarding DefaultTTL InDiscards\nIp: 1 64 3\n\
|
|
129
|
+
IcmpMsg: InType3\nIcmpMsg: 2\n\
|
|
130
|
+
Tcp: RtoAlgorithm MaxConn RetransSegs\nTcp: 1 -1 7\n";
|
|
131
|
+
let counters = pairs_of(snmp);
|
|
132
|
+
assert_eq!(counters["Ip.InDiscards"], 3);
|
|
133
|
+
assert_eq!(counters["IcmpMsg.InType3"], 2);
|
|
134
|
+
assert_eq!(counters["Tcp.RetransSegs"], 7);
|
|
135
|
+
assert!(!counters.contains_key("Tcp.MaxConn"));
|
|
136
|
+
let netstat = "TcpExt: TCPACKSkippedTimeWait TCPChallengeACK\nTcpExt: 4 0\nIpExt: InNoRoutes\nIpExt: 0\n";
|
|
137
|
+
let counters = pairs_of(netstat);
|
|
138
|
+
assert_eq!(counters["TcpExt.TCPACKSkippedTimeWait"], 4);
|
|
139
|
+
assert_eq!(counters["IpExt.InNoRoutes"], 0);
|
|
140
|
+
assert!(pairs_of("Tcp: RetransSegs\nUdp: InDatagrams\nUdp: 5\n").get("Tcp.RetransSegs").is_none());
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
#[test]
|
|
144
|
+
fn the_counters_of_a_device_and_of_the_backlog_come_from_their_columns() {
|
|
145
|
+
let dev = "Inter-| Receive | Transmit\n face |bytes packets errs drop|bytes\n\
|
|
146
|
+
eth0: 1000 10 1 2 0 0 0 0 2000 20 3 4 0 0 0 0\n";
|
|
147
|
+
let counters = devices_of(dev);
|
|
148
|
+
assert_eq!(counters["Dev.eth0.rx_packets"], 10);
|
|
149
|
+
assert_eq!(counters["Dev.eth0.rx_errs"], 1);
|
|
150
|
+
assert_eq!(counters["Dev.eth0.rx_drop"], 2);
|
|
151
|
+
assert_eq!(counters["Dev.eth0.tx_packets"], 20);
|
|
152
|
+
assert_eq!(counters["Dev.eth0.tx_errs"], 3);
|
|
153
|
+
assert_eq!(counters["Dev.eth0.tx_drop"], 4);
|
|
154
|
+
assert_eq!(counters.len(), 6);
|
|
155
|
+
let softnet = "0000000a 00000001 00000002 00000000\n00000010 00000000 00000001 00000000\n";
|
|
156
|
+
let counters = softnet_of(softnet);
|
|
157
|
+
assert_eq!((counters["Softnet.processed"], counters["Softnet.dropped"], counters["Softnet.squeezed"]), (26, 1, 3));
|
|
158
|
+
assert!(softnet_of("").is_empty());
|
|
159
|
+
}
|
|
51
160
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@mark1russell7/harness",
|
|
4
|
-
"version": "0.16.
|
|
4
|
+
"version": "0.16.9",
|
|
5
5
|
"description": "Network labs in Docker, declared as data. A cell builds a topology of networks, routers and proxies around a stock target. It injects a fault at layer 3 or 4 from a NET_ADMIN sidecar, measures the records of the kernel and judges a prediction. The faults are black holes, resets, ICMP unreachable, one-way and MTU drops, tc netem, the toxics of Toxiproxy and frozen processes. Its disk tier cuts the power of a program on LazyFS: the disk loses each write after the last fsync. Its memory tier sets the limits of the cgroup of a client, and judges its throttle above memory.high and the choice of the OOM killer. Its egress tier puts a netem or tbf qdisc on the interface of a client, and judges the departure of each datagram from the stamps of the kernel. Its replicated groups are Redis with Sentinels, MongoDB replica sets, PostgreSQL standbys, Kafka, RabbitMQ and BGP fabrics with BFD. A lab can also operate in a QEMU guest. Its first use is connection timers: keep-alive, TCP retransmission, heartbeats and reconnects.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"fault-injection",
|