nx_fabric_cc_gate.nx source
↩ module page · 125 lines · 6637 B
1// nx_fabric_cc_gate.nx -- LIVE GATE for R2 (congestion control + telemetry over RTT).
2// Proves: a DCTCP-style ECN-telemetry controller holds the bottleneck queue near a low
3// setpoint K at FULL utilisation over an RTT link, where an open-loop window bufferbloats
4// -- with negative controls so the result cannot be rigged.
5//
6// criteria:
7// 1 R2 utilisation >= 90% (keeps the RTT link full)
8// 2 R2 q_p99 <= 3*K (queue BOUNDED near the ECN setpoint)
9// 3 baseline util >= 90% AND baseline q_p99 >= 3*R2 q_p99 (open-loop BLOATS at equal util)
10// 4 R2 telemetry error == 0 (reported queue tracks the true queue)
11// negative controls:
12// NC1 ignore ECN marks -> queue bloats (>= 3*R2) (the REACTION holds the queue)
13// NC2 never mark (K huge) -> queue bloats (>= 3*R2) (the TELEMETRY SIGNAL is essential)
14// NC3 telemetry recount matches on every run (no fabricated telemetry)
15//
16// expect_exit: 0 license_tier: ORIGINAL
17import "nx_fabric_cc.nx"
18
19func gp(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
20func gn(v: i64) -> i64 {
21 let b: *u8 = sys_mmap(28); var m: i64 = v
22 if m < 0 { m = 0 - m; sys_write(1, "-" as *u8, 1) }
23 let t: *u8 = sys_mmap(28); var k: i64 = 0
24 if m == 0 { t[0] = 48 as u8; k = 1 }
25 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
26 var i: i64 = 0
27 while i < k { b[i] = t[k - 1 - i]; i = i + 1 }
28 sys_write(1, b, k); return 0
29}
30func fdn(fd: i64, v: i64) -> i64 {
31 let b: *u8 = sys_mmap(28); var m: i64 = v; if m < 0 { m = 0 - m }
32 let t: *u8 = sys_mmap(28); var k: i64 = 0
33 if m == 0 { t[0] = 48 as u8; k = 1 }
34 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
35 var i: i64 = 0
36 while i < k { b[i] = t[k - 1 - i]; i = i + 1 }
37 sys_write(fd, b, k); return 0
38}
39func chk(name: *u8, ok: i64) -> i64 {
40 if ok == 1 { gp(" PASS " as *u8); gp(name); gp("\n" as *u8); return 1 }
41 gp(" FAIL " as *u8); gp(name); gp("\n" as *u8); return 0
42}
43func show(tag: *u8, m: *CcMetrics) -> i64 {
44 gp(tag); gp(": util(x1000)=" as *u8); gn(m.util_x1000); gp(" q_p50=" as *u8); gn(m.q_p50)
45 gp(" q_p99=" as *u8); gn(m.q_p99); gp(" drops=" as *u8); gn(m.drops)
46 gp(" tele_err=" as *u8); gn(m.tele_max_err); gp(" ticks=" as *u8); gn(m.ticks); gp("\n" as *u8); return 0
47}
48
49func main() -> i64 {
50 let N: i64 = 1200 // ~300 ticks; warmup skips ~96, ~200 steady-state samples
51 let D: i64 = 4
52 let RTT: i64 = 8 // BDP = D*RTT = 32
53 let BUF: i64 = 200
54 let K: i64 = 16 // ECN setpoint (the latency<->throughput knob; K=8 gives
55 // q_p99=6 but only 89.9% util -- K=16 balances both)
56 let OPENW: i64 = 170 // open-loop window -> standing queue ~ OPENW-BDP (~138)
57
58 gp("nx_fabric_cc R2 gate -- ECN-telemetry congestion control over RTT vs open-loop\n" as *u8)
59 gp("link: N=" as *u8); gn(N); gp(" drain=" as *u8); gn(D); gp("/tick RTT=" as *u8); gn(RTT)
60 gp(" (BDP=" as *u8); gn(D * RTT); gp(") buffer=" as *u8); gn(BUF); gp(" ECN-K=" as *u8); gn(K); gp("\n" as *u8)
61
62 let r2: *CcMetrics = sys_mmap(64) as *CcMetrics
63 let base: *CcMetrics = sys_mmap(64) as *CcMetrics
64 let nc1: *CcMetrics = sys_mmap(64) as *CcMetrics
65 let nc2: *CcMetrics = sys_mmap(64) as *CcMetrics
66
67 cc_run(CC_DCTCP, N, D, RTT, BUF, K, OPENW, r2) // R2: ECN-adaptive
68 cc_run(CC_OPEN, N, D, RTT, BUF, K, OPENW, base) // baseline: fixed window
69 cc_run(CC_NC1, N, D, RTT, BUF, K, OPENW, nc1) // NC1: marks ignored
70 cc_run(CC_DCTCP, N, D, RTT, BUF, 100000, OPENW, nc2) // NC2: K huge -> never marks
71
72 show("R2 (DCTCP/ECN telemetry)" as *u8, r2)
73 show("BASELINE (open-loop window)" as *u8, base)
74 show("NC1 (DCTCP, marks ignored)" as *u8, nc1)
75 show("NC2 (DCTCP, never marks)" as *u8, nc2)
76
77 var pass: i64 = 0
78 var tot: i64 = 0
79
80 var c1: i64 = 0; if r2.util_x1000 >= 900 { c1 = 1 }
81 pass = pass + chk("1 R2 utilisation >= 90% (RTT link kept full)" as *u8, c1); tot = tot + 1
82
83 var c2: i64 = 0; if r2.q_p99 <= 3 * K { c2 = 1 }
84 pass = pass + chk("2 R2 q_p99 <= 3*K (queue BOUNDED near ECN setpoint)" as *u8, c2); tot = tot + 1
85
86 var c3: i64 = 0
87 if base.util_x1000 >= 900 { if r2.q_p99 >= 1 { if base.q_p99 >= 3 * r2.q_p99 { c3 = 1 } } }
88 pass = pass + chk("3 baseline util>=90% AND q_p99 >= 3*R2 (open-loop BLOATS at equal util)" as *u8, c3); tot = tot + 1
89
90 var c4: i64 = 0; if r2.tele_max_err == 0 { c4 = 1 }
91 pass = pass + chk("4 R2 telemetry error == 0 (reported queue == true queue)" as *u8, c4); tot = tot + 1
92
93 var cn1: i64 = 0; if r2.q_p99 >= 1 { if nc1.q_p99 >= 3 * r2.q_p99 { cn1 = 1 } }
94 pass = pass + chk("NC1 marks ignored -> bloat >= 3*R2 (the REACTION holds the queue)" as *u8, cn1); tot = tot + 1
95
96 var cn2: i64 = 0; if r2.q_p99 >= 1 { if nc2.q_p99 >= 3 * r2.q_p99 { cn2 = 1 } }
97 pass = pass + chk("NC2 never marks -> bloat >= 3*R2 (the TELEMETRY SIGNAL is essential)" as *u8, cn2); tot = tot + 1
98
99 var cn3: i64 = 0
100 if r2.tele_max_err == 0 { if base.tele_max_err == 0 { if nc1.tele_max_err == 0 { if nc2.tele_max_err == 0 { cn3 = 1 } } } }
101 pass = pass + chk("NC3 telemetry recount matches on every run (no fabricated telemetry)" as *u8, cn3); tot = tot + 1
102
103 gp("---- nx_fabric_cc R2 gate: passed " as *u8); gn(pass); gp(" / " as *u8); gn(tot); gp("\n" as *u8)
104
105 if pass == tot {
106 let lfd: i64 = sys_openat_append("knowledge/status/fabric_nx_fabric_cc.log" as *u8, 0x1a4)
107 if lfd >= 0 {
108 sys_write(lfd, "R2-FABRIC-CC organ=nx_fabric_cc checks=" as *u8, 39)
109 fdn(lfd, pass); sys_write(lfd, "/" as *u8, 1); fdn(lfd, tot)
110 sys_write(lfd, " ecn-bounded-queue+telemetry+NC1/2/3 verdict=GREEN\n" as *u8, 51)
111 sys_close(lfd)
112 }
113 gp("R2 LIVE GREEN -- ECN-telemetry congestion control bounds the queue over RTT\n" as *u8)
114 sys_exit(0)
115 }
116 let rfd: i64 = sys_openat_append("knowledge/status/fabric_nx_fabric_cc.log" as *u8, 0x1a4)
117 if rfd >= 0 {
118 sys_write(rfd, "R2-FABRIC-CC organ=nx_fabric_cc checks=" as *u8, 39)
119 fdn(rfd, pass); sys_write(rfd, "/" as *u8, 1); fdn(rfd, tot)
120 sys_write(rfd, " verdict=RED\n" as *u8, 13)
121 sys_close(rfd)
122 }
123 sys_exit(1)
124 return 0
125}