|
1 | | -import ./make-test-python.nix ( |
2 | | - { pkgs, lib, ... }: |
3 | | - let |
4 | | - |
5 | | - baud = 57600; |
6 | | - tty = "/dev/ttyACM0"; |
7 | | - port = "tnc0"; |
8 | | - socatPort = 1234; |
9 | | - |
10 | | - createAX25Node = nodeId: { |
11 | | - |
12 | | - boot.kernelPackages = pkgs.linuxPackages_ham; |
13 | | - boot.kernelModules = [ "ax25" ]; |
| 1 | +{ pkgs, lib, ... }: |
| 2 | + |
| 3 | +let |
| 4 | + baud = 57600; |
| 5 | + tty = "/dev/ttyACM0"; |
| 6 | + port = "tnc0"; |
| 7 | + socatPort = 1234; |
| 8 | + |
| 9 | + createAX25Node = nodeId: { |
| 10 | + boot.kernelPackages = pkgs.linuxPackages_ham; |
| 11 | + boot.kernelModules = [ "ax25" ]; |
| 12 | + |
| 13 | + networking.firewall.allowedTCPPorts = [ socatPort ]; |
| 14 | + |
| 15 | + environment.systemPackages = with pkgs; [ |
| 16 | + libax25 |
| 17 | + ax25-tools |
| 18 | + ax25-apps |
| 19 | + socat |
| 20 | + ]; |
| 21 | + |
| 22 | + services.ax25.axports."${port}" = { |
| 23 | + inherit baud tty; |
| 24 | + enable = true; |
| 25 | + callsign = "NOCALL-${toString nodeId}"; |
| 26 | + description = "mocked tnc"; |
| 27 | + }; |
14 | 28 |
|
15 | | - networking.firewall.allowedTCPPorts = [ socatPort ]; |
| 29 | + services.ax25.axlisten = { |
| 30 | + enable = true; |
| 31 | + }; |
16 | 32 |
|
17 | | - environment.systemPackages = with pkgs; [ |
18 | | - libax25 |
19 | | - ax25-tools |
20 | | - ax25-apps |
21 | | - socat |
| 33 | + # All mocks radios will connect back to socat-broker on node 1 in order to get |
| 34 | + # all messages that are "broadcasted over the ether" |
| 35 | + systemd.services.ax25-mock-hardware = { |
| 36 | + description = "mock AX.25 TNC and Radio"; |
| 37 | + wantedBy = [ "default.target" ]; |
| 38 | + before = [ |
| 39 | + "ax25-kissattach-${port}.service" |
| 40 | + "axlisten.service" |
22 | 41 | ]; |
23 | | - |
24 | | - services.ax25.axports."${port}" = { |
25 | | - inherit baud tty; |
26 | | - enable = true; |
27 | | - callsign = "NOCALL-${toString nodeId}"; |
28 | | - description = "mocked tnc"; |
29 | | - }; |
30 | | - |
31 | | - services.ax25.axlisten = { |
32 | | - enable = true; |
33 | | - }; |
34 | | - |
35 | | - # All mocks radios will connect back to socat-broker on node 1 in order to get |
36 | | - # all messages that are "broadcasted over the ether" |
37 | | - systemd.services.ax25-mock-hardware = { |
38 | | - description = "mock AX.25 TNC and Radio"; |
39 | | - wantedBy = [ "default.target" ]; |
40 | | - before = [ |
41 | | - "ax25-kissattach-${port}.service" |
42 | | - "axlisten.service" |
43 | | - ]; |
44 | | - after = [ "network.target" ]; |
45 | | - serviceConfig = { |
46 | | - Type = "exec"; |
47 | | - ExecStart = "${pkgs.socat}/bin/socat -d -d tcp:192.168.1.1:${toString socatPort} pty,link=${tty},b${toString baud},raw"; |
48 | | - }; |
| 42 | + after = [ "network.target" ]; |
| 43 | + serviceConfig = { |
| 44 | + Type = "exec"; |
| 45 | + ExecStart = "${pkgs.socat}/bin/socat -d -d tcp:192.168.1.1:${toString socatPort} pty,link=${tty},b${toString baud},raw"; |
49 | 46 | }; |
50 | 47 | }; |
51 | | - in |
52 | | - { |
53 | | - name = "ax25Simple"; |
54 | | - nodes = { |
55 | | - node1 = lib.mkMerge [ |
56 | | - (createAX25Node 1) |
57 | | - # mimicking radios on the same frequency |
58 | | - { |
59 | | - systemd.services.ax25-mock-ether = { |
60 | | - description = "mock radio ether"; |
61 | | - wantedBy = [ "default.target" ]; |
62 | | - requires = [ "network.target" ]; |
63 | | - before = [ "ax25-mock-hardware.service" ]; |
64 | | - # broken needs access to "ss" or "netstat" |
65 | | - path = [ pkgs.iproute2 ]; |
66 | | - serviceConfig = { |
67 | | - Type = "exec"; |
68 | | - ExecStart = "${pkgs.socat}/bin/socat-broker.sh tcp4-listen:${toString socatPort}"; |
69 | | - }; |
70 | | - postStart = "${pkgs.coreutils}/bin/sleep 2"; |
| 48 | + }; |
| 49 | +in |
| 50 | +{ |
| 51 | + name = "ax25Simple"; |
| 52 | + nodes = { |
| 53 | + node1 = lib.mkMerge [ |
| 54 | + (createAX25Node 1) |
| 55 | + # mimicking radios on the same frequency |
| 56 | + { |
| 57 | + systemd.services.ax25-mock-ether = { |
| 58 | + description = "mock radio ether"; |
| 59 | + wantedBy = [ "default.target" ]; |
| 60 | + requires = [ "network.target" ]; |
| 61 | + before = [ "ax25-mock-hardware.service" ]; |
| 62 | + # broken needs access to "ss" or "netstat" |
| 63 | + path = [ pkgs.iproute2 ]; |
| 64 | + serviceConfig = { |
| 65 | + Type = "exec"; |
| 66 | + ExecStart = "${pkgs.socat}/bin/socat-broker.sh tcp4-listen:${toString socatPort}"; |
71 | 67 | }; |
72 | | - } |
73 | | - ]; |
74 | | - node2 = createAX25Node 2; |
75 | | - node3 = createAX25Node 3; |
76 | | - }; |
77 | | - testScript = |
78 | | - { ... }: |
79 | | - '' |
80 | | - def wait_for_machine(m): |
81 | | - m.succeed("lsmod | grep ax25") |
82 | | - m.wait_for_unit("ax25-axports.target") |
83 | | - m.wait_for_unit("axlisten.service") |
84 | | - m.fail("journalctl -o cat -u axlisten.service | grep -i \"no AX.25 port data configured\"") |
85 | | -
|
86 | | - # start the first node since the socat-broker needs to be running |
87 | | - node1.start() |
88 | | - node1.wait_for_unit("ax25-mock-ether.service") |
89 | | - wait_for_machine(node1) |
90 | | -
|
91 | | - node2.start() |
92 | | - node3.start() |
93 | | - wait_for_machine(node2) |
94 | | - wait_for_machine(node3) |
95 | | -
|
96 | | - # Node 1 -> Node 2 |
97 | | - node1.succeed("echo hello | ax25_call ${port} NOCALL-1 NOCALL-2") |
98 | | - node2.sleep(1) |
99 | | - node2.succeed("journalctl -o cat -u axlisten.service | grep -A1 \"NOCALL-1 to NOCALL-2 ctl I00\" | grep hello") |
100 | | -
|
101 | | - # Node 1 -> Node 3 |
102 | | - node1.succeed("echo hello | ax25_call ${port} NOCALL-1 NOCALL-3") |
103 | | - node3.sleep(1) |
104 | | - node3.succeed("journalctl -o cat -u axlisten.service | grep -A1 \"NOCALL-1 to NOCALL-3 ctl I00\" | grep hello") |
105 | | -
|
106 | | - # Node 2 -> Node 1 |
107 | | - # must sleep due to previous ax25_call lingering |
108 | | - node2.sleep(5) |
109 | | - node2.succeed("echo hello | ax25_call ${port} NOCALL-2 NOCALL-1") |
110 | | - node1.sleep(1) |
111 | | - node1.succeed("journalctl -o cat -u axlisten.service | grep -A1 \"NOCALL-2 to NOCALL-1 ctl I00\" | grep hello") |
112 | | -
|
113 | | - # Node 2 -> Node 3 |
114 | | - node2.succeed("echo hello | ax25_call ${port} NOCALL-2 NOCALL-3") |
115 | | - node3.sleep(1) |
116 | | - node3.succeed("journalctl -o cat -u axlisten.service | grep -A1 \"NOCALL-2 to NOCALL-3 ctl I00\" | grep hello") |
117 | | -
|
118 | | - # Node 3 -> Node 1 |
119 | | - # must sleep due to previous ax25_call lingering |
120 | | - node3.sleep(5) |
121 | | - node3.succeed("echo hello | ax25_call ${port} NOCALL-3 NOCALL-1") |
122 | | - node1.sleep(1) |
123 | | - node1.succeed("journalctl -o cat -u axlisten.service | grep -A1 \"NOCALL-3 to NOCALL-1 ctl I00\" | grep hello") |
124 | | -
|
125 | | - # Node 3 -> Node 2 |
126 | | - node3.succeed("echo hello | ax25_call ${port} NOCALL-3 NOCALL-2") |
127 | | - node2.sleep(1) |
128 | | - node2.succeed("journalctl -o cat -u axlisten.service | grep -A1 \"NOCALL-3 to NOCALL-2 ctl I00\" | grep hello") |
129 | | - ''; |
130 | | - } |
131 | | -) |
| 68 | + postStart = "${pkgs.coreutils}/bin/sleep 2"; |
| 69 | + }; |
| 70 | + } |
| 71 | + ]; |
| 72 | + node2 = createAX25Node 2; |
| 73 | + node3 = createAX25Node 3; |
| 74 | + }; |
| 75 | + testScript = |
| 76 | + { ... }: |
| 77 | + '' |
| 78 | + def wait_for_machine(m): |
| 79 | + m.succeed("lsmod | grep ax25") |
| 80 | + m.wait_for_unit("ax25-axports.target") |
| 81 | + m.wait_for_unit("axlisten.service") |
| 82 | + m.fail("journalctl -o cat -u axlisten.service | grep -i \"no AX.25 port data configured\"") |
| 83 | +
|
| 84 | + # start the first node since the socat-broker needs to be running |
| 85 | + node1.start() |
| 86 | + node1.wait_for_unit("ax25-mock-ether.service") |
| 87 | + wait_for_machine(node1) |
| 88 | +
|
| 89 | + node2.start() |
| 90 | + node3.start() |
| 91 | + wait_for_machine(node2) |
| 92 | + wait_for_machine(node3) |
| 93 | +
|
| 94 | + # Node 1 -> Node 2 |
| 95 | + node1.succeed("echo hello | ax25_call ${port} NOCALL-1 NOCALL-2") |
| 96 | + node2.sleep(1) |
| 97 | + node2.succeed("journalctl -o cat -u axlisten.service | grep -A1 \"NOCALL-1 to NOCALL-2 ctl I00\" | grep hello") |
| 98 | +
|
| 99 | + # Node 1 -> Node 3 |
| 100 | + node1.succeed("echo hello | ax25_call ${port} NOCALL-1 NOCALL-3") |
| 101 | + node3.sleep(1) |
| 102 | + node3.succeed("journalctl -o cat -u axlisten.service | grep -A1 \"NOCALL-1 to NOCALL-3 ctl I00\" | grep hello") |
| 103 | +
|
| 104 | + # Node 2 -> Node 1 |
| 105 | + # must sleep due to previous ax25_call lingering |
| 106 | + node2.sleep(5) |
| 107 | + node2.succeed("echo hello | ax25_call ${port} NOCALL-2 NOCALL-1") |
| 108 | + node1.sleep(1) |
| 109 | + node1.succeed("journalctl -o cat -u axlisten.service | grep -A1 \"NOCALL-2 to NOCALL-1 ctl I00\" | grep hello") |
| 110 | +
|
| 111 | + # Node 2 -> Node 3 |
| 112 | + node2.succeed("echo hello | ax25_call ${port} NOCALL-2 NOCALL-3") |
| 113 | + node3.sleep(1) |
| 114 | + node3.succeed("journalctl -o cat -u axlisten.service | grep -A1 \"NOCALL-2 to NOCALL-3 ctl I00\" | grep hello") |
| 115 | +
|
| 116 | + # Node 3 -> Node 1 |
| 117 | + # must sleep due to previous ax25_call lingering |
| 118 | + node3.sleep(5) |
| 119 | + node3.succeed("echo hello | ax25_call ${port} NOCALL-3 NOCALL-1") |
| 120 | + node1.sleep(1) |
| 121 | + node1.succeed("journalctl -o cat -u axlisten.service | grep -A1 \"NOCALL-3 to NOCALL-1 ctl I00\" | grep hello") |
| 122 | +
|
| 123 | + # Node 3 -> Node 2 |
| 124 | + node3.succeed("echo hello | ax25_call ${port} NOCALL-3 NOCALL-2") |
| 125 | + node2.sleep(1) |
| 126 | + node2.succeed("journalctl -o cat -u axlisten.service | grep -A1 \"NOCALL-3 to NOCALL-2 ctl I00\" | grep hello") |
| 127 | + ''; |
| 128 | +} |
0 commit comments