Skip to content

Commit a107a03

Browse files
committed
ProtoConv tests
1 parent f7d9f0e commit a107a03

File tree

5 files changed

+198
-96
lines changed

5 files changed

+198
-96
lines changed

.github/workflows/MiniPlex.yml

Lines changed: 66 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -58,26 +58,35 @@ jobs:
5858
README.md
5959
RELEASE_NOTES
6060
3rdPartyLicenses/LICENSE_1_0.txt
61-
62-
- if: ${{ always() && !contains(matrix.os,'windows') }}
63-
name: Start MiniPlex
64-
shell: bash
65-
run: |
66-
${{github.workspace}}/build/MiniPlex -H -p 20000 &
67-
${{github.workspace}}/build/MiniPlex -T -p 20001 -r 127.0.0.1 -t 50000 &
68-
${{github.workspace}}/build/MiniPlex -P -p 20002 -r 127.0.0.1 -t 50000 &
69-
${{github.workspace}}/build/MiniPlex -P -p 20003 -r 127.0.0.1 -t 50000 -B 127.0.0.1 -b 50001 &
70-
sleep 1
71-
61+
7262
- if: always() && contains(matrix.os,'macos')
73-
name: Mac ncat
63+
name: Mac Cats
7464
run: |
75-
brew install nmap
65+
brew install nmap socat
7666
7767
- if: always() && contains(matrix.os,'ubuntu')
78-
name: Linux ncat
68+
name: Linux Cats
69+
run: |
70+
sudo apt-get install -y ncat socat
71+
72+
- if: ${{ always() && !contains(matrix.os,'windows') }}
73+
name: Start Test Processes
74+
shell: bash
7975
run: |
80-
sudo apt-get install -y ncat
76+
build/MiniPlex -H -p 20000 &
77+
build/MiniPlex -T -p 20001 -r 127.0.0.1 -t 50000 &
78+
build/MiniPlex -P -p 20002 -r 127.0.0.1 -t 50000 &
79+
build/MiniPlex -P -p 20003 -r 127.0.0.1 -t 50000 -B 127.0.0.1 -b 50001 &
80+
socat pty,raw,echo=0,link=SerialEndpoint1 pty,raw,echo=0,link=SerialEndpoint2 &
81+
socat pty,raw,echo=0,link=SerialEndpoint3 pty,raw,echo=0,link=SerialEndpoint4 &
82+
socat pty,raw,echo=0,link=SerialEndpoint5 pty,raw,echo=0,link=SerialEndpoint6 &
83+
socat pty,raw,echo=0,link=SerialEndpoint7 pty,raw,echo=0,link=SerialEndpoint8 &
84+
sleep 0.5
85+
build/ProtoConv -l 21000 -A 127.0.0.1 -r 21001 -D 12345 -s SerialEndpoint1 -s SerialEndpoint3 -s SerialEndpoint5 -s SerialEndpoint7 &
86+
build/ProtoConv -l 22000 -A 127.0.0.1 -r 22001 -D 12345 -s SerialEndpoint8 -s SerialEndpoint6 -s SerialEndpoint4 -s SerialEndpoint2 &
87+
build/ProtoConv -l 23000 -A 127.0.0.1 -r 23001 -p DNP3 -C 0 -T 127.0.0.1 -t 20000 &
88+
sleep 0.5
89+
build/ProtoConv -l 24000 -A 127.0.0.1 -r 24001 -p DNP3 -C 1 -T 127.0.0.1 -t 20000 &
8190
8291
- if: ${{ always() && !contains(matrix.os,'windows') }}
8392
name: Test Hub Mode
@@ -98,10 +107,22 @@ jobs:
98107
name: Test Permanent Branches
99108
run: |
100109
Test/PermanentBranches.sh 50000 50001 127.0.0.1 20003
110+
111+
- if: ${{ always() && !contains(matrix.os,'windows') }}
112+
name: Test ProtoConv Delim
113+
run: |
114+
Test/ProtoConvInOut.pl Test/DNP3Hex.txt 21001 127.0.0.1 21000 22001 127.0.0.1 22000 /tmp/out.txt Test/DNP3Hex.txt
115+
116+
- if: ${{ always() && !contains(matrix.os,'windows') }}
117+
name: Test ProtoConv DNP3
118+
run: |
119+
Test/ProtoConvInOut.pl Test/DNP3HexOutOfOrder.txt 23001 127.0.0.1 23000 24001 127.0.0.1 24000 /tmp/out.txt Test/DNP3Hex.txt
101120
102121
- if: ${{ always() && !contains(matrix.os,'windows') }}
103-
name: Stop MiniPlex
122+
name: Stop Test Processes
104123
run: |
124+
killall ProtoConv || true
125+
killall socat || true
105126
killall MiniPlex || true
106127
107128
musl-build-job:
@@ -161,19 +182,28 @@ jobs:
161182
3rdPartyLicenses/LICENSE_1_0.txt
162183
163184
- if: always()
164-
name: Start MiniPlex
185+
name: Linux Cats
186+
run: |
187+
sudo apt-get install -y ncat socat
188+
189+
- if: always()
190+
name: Start Test Processes
165191
shell: bash
166192
run: |
167193
build/MiniPlex -H -p 20000 &
168194
build/MiniPlex -T -p 20001 -r 127.0.0.1 -t 50000 &
169195
build/MiniPlex -P -p 20002 -r 127.0.0.1 -t 50000 &
170196
build/MiniPlex -P -p 20003 -r 127.0.0.1 -t 50000 -B 127.0.0.1 -b 50001 &
171-
sleep 1
172-
173-
- if: always()
174-
name: Linux ncat
175-
run: |
176-
sudo apt-get install -y ncat
197+
socat pty,raw,echo=0,link=SerialEndpoint1 pty,raw,echo=0,link=SerialEndpoint2 &
198+
socat pty,raw,echo=0,link=SerialEndpoint3 pty,raw,echo=0,link=SerialEndpoint4 &
199+
socat pty,raw,echo=0,link=SerialEndpoint5 pty,raw,echo=0,link=SerialEndpoint6 &
200+
socat pty,raw,echo=0,link=SerialEndpoint7 pty,raw,echo=0,link=SerialEndpoint8 &
201+
sleep 0.5
202+
build/ProtoConv -l 21000 -A 127.0.0.1 -r 21001 -D 12345 -s SerialEndpoint1 -s SerialEndpoint3 -s SerialEndpoint5 -s SerialEndpoint7 &
203+
build/ProtoConv -l 22000 -A 127.0.0.1 -r 22001 -D 12345 -s SerialEndpoint8 -s SerialEndpoint6 -s SerialEndpoint4 -s SerialEndpoint2 &
204+
build/ProtoConv -l 23000 -A 127.0.0.1 -r 23001 -p DNP3 -C 0 -T 127.0.0.1 -t 20000 &
205+
sleep 0.5
206+
build/ProtoConv -l 24000 -A 127.0.0.1 -r 24001 -p DNP3 -C 1 -T 127.0.0.1 -t 20000 &
177207
178208
- if: always()
179209
name: Test Hub Mode
@@ -194,10 +224,22 @@ jobs:
194224
name: Test Permanent Branches
195225
run: |
196226
Test/PermanentBranches.sh 50000 50001 127.0.0.1 20003
227+
228+
- if: always()
229+
name: Test ProtoConv Delim
230+
run: |
231+
Test/ProtoConvInOut.pl Test/DNP3Hex.txt 21001 127.0.0.1 21000 22001 127.0.0.1 22000 /tmp/out.txt Test/DNP3Hex.txt
232+
233+
- if: always()
234+
name: Test ProtoConv DNP3
235+
run: |
236+
Test/ProtoConvInOut.pl Test/DNP3HexOutOfOrder.txt 23001 127.0.0.1 23000 24001 127.0.0.1 24000 /tmp/out.txt Test/DNP3Hex.txt
197237
198238
- if: always()
199-
name: Stop MiniPlex
239+
name: Stop Test Processes
200240
run: |
241+
killall ProtoConv || true
242+
killall socat || true
201243
killall MiniPlex || true
202244
203245
deploy-job:

Test/DNP3Hex.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
0564ff730000010050ad48a8810600200317a900010d0000009562193a31cb92010e015c210000953a31cb92503b0111015c210000953a31cb920113012fa2b42e0000953a31cb92011401642e0000959af03a31cb920116012f2e0000953a31cb92078c011701642e0000953a31cb92011a01095e65000000953a31cb92010e01b02500007d965c3e31cb92011101b02500007d3e31cb92a6690113014d3200007d3e31cb92011401e749a73100007d3e31cb920116014d3200007d41ae3e31cb92011701e73100007d3e31cb92d063011a010a0000007d3e31cb92010d01810c03170000654231cb92010e013a280000659fdd4231cb92010f019d160000654231cb9261b901100181170000654231cb920111013a891f280000654231cb9201126660
2+
0564ff53000001000db509019d160000654231cb92011301f43421460000654231cb92011401f73400006542fa0231cb92011501ed270000654231cb920156061601f4340000654231cb92011701f73427b90000654231cb92011801ed270000654210e131cb920113018c3500004e4631cb92012ecf16018c3500004e4631cb92011a010900e2ee00004e4631cb920100010e0000004248ad0f31cb920101010c000000424831cb9201930c02010e000000424831cb92010d019318aa4f0000424831cb92010e017826000042480ff831cb92010f0199170000424831cb92015cf1100193180000424831cb9201110178264adc0000424831cb92011201991700004248dc5631cb92011301d5340000424831cb920174b8140153340000424831cbdb82
3+
0564ff730000010050ad0a92011501d8290000424831cb9201164d6c01d5340000424831cb9201170153340058c300424831cb92011801d8290000424831a23acb92011a010a000000424831cb92010d835e013c1900002a4c31cb92010e01e621001723002a4c31cb92010f013e1800002a4c316a0ecb920110013c1900002a4c31cb920111b6b501e62100002a4c31cb920112013e1800cae1002a4c31cb920113015f3100002a4c31fd0dcb92011401d23000002a4c31cb920115822a01f82a00002a4c31cb920116015f3100195b002a4c31cb92011701d23000002a4c31abe6cb92011801f82a00002a4c31cb92010e263001301e00001f4e31cb92011101301e00a9a8001f4e31cb920113013c2e00001f4e310d72cb920114018f2d00001f1ddb
4+
0564ff53000001000db50b4e31cb920116013c2e00001f4e31cb146f920117018f2d00001f4e31cb92010d016205d2190000075231cb92010e019e1b0000dea5075231cb92010f01a7180000075231cb771792011001d2190000075231cb92011101ad3e9e1b0000075231cb92011201a7180000dff9075231cb92011301d12c0000075231cbab03920114018c2b0000075231cb92011501a4f7e32b0000075231cb92011601d12c0000a120075231cb920117018c2b0000075231cb086b92011801e32b0000075231cb92011901866e01010000075231cb9201040102010000e44d075231cb92010e01151a0000fb5331cbb18392011101151a0000fb5331cb92011301b1c9d12b0000fb5331cb92011401012b0000d4e9fb5331cb92011601d12b70c3
5+
0564ff730000010050ad0c0000fb5331cb92011701012b0000fb47bd5331cb92010e01a11a0000d85931cb92f91a011101a11a0000d85931cb9201130167f9802c0000d85931cb920114017b2b0000d85acf5931cb92011601672c0000d85931cb9258120117017b2b0000d85931cb92010e010037f71d0000cc5b31cb92011101001d0000cc1a4a5b31cb92011301282e0000cc5b31cb921b320114012d2d0000cc5b31cb9201160128a9572e0000cc5b31cb920117012d2d0000cc3ff95b31cb92010e0125200000b45f31cb92864601110125200000b45f31cb92011301a7eedc300000b45f31cb920114011f2f0000b41d6b5f31cb92011601a7300000b45f31cb928d7b0117011f2f0000b45f31cb92010e0154d2ab2500009c6331cb9201119e8d
6+
0564ff53000001000db50d01542500009c6331cb920113017234269600009c6331cb92011401ed3200009c63197331cb92011501742b00009c6331cb920125d01601723400009c6331cb92011701ed32393d00009c6331cb92011801742b00009c63650131cb92010d012c190000856731cb920173b50e0111290000856731cb920110012c19fd180000856731cb92011101112900008567000931cb92011301f1370000856731cb9201fcbb14018f360000856731cb92011501db2a7ee90000856731cb92011601f13700008567cd1031cb920117018f360000856731cb9201f5001801db2a0000856731cb920100010d00549100006d6b31cb920101010b0000006d6bf47731cb920102010d0000006d6b31cb9201967f0d012e1800006d6b31cbd74d
7+
0564ff730000010050ad0e92010e018d2a00006d6b31cb92010f89c7014b1700006d6b31cb920110012e18000b8d006d6b31cb920111018d2a00006d6b31dbe0cb920112014b1700006d6b31cb92011432b301f83600006d6b31cb9201150158290050ac006d6b31cb92011701f83600006d6b31e1adcb92011801582900006d6b31cb920119fb0501e30000006d6b31cb92010401e40000f303006d6b31cb92010d01ad170000566f31aab7cb92010e0158290000566f31cb920110844101ad170000566f31cb92011101582900b6c300566f31cb92011301cd360000566f31ea6bcb92011401ad350000566f31cb92011599fc0172280000566f31cb92011601cd36009a5900566f31cb92011701ad350000566f315f46cb9201180172280000561217
8+
0564ff53000001000db50f6f31cb92010d01271700004a7131cbe6aa92010e01072500004a7131cb92010f01fbbf321600004a7131cb9201100127170000634a4a7131cb92011101072500004a7131cb907992011201321600004a7131cb92011301e0b65e3200004a7131cb92011401b0310000dea64a7131cb92011501672700004a7131cb81f4920116015e3200004a7131cb92011701f593b03100004a7131cb9201180167270000580c4a7131cb920100010c000000327531cb001b920101010a000000327531cb92010201764c0c000000327531cb92010d01a716000017cf327531cb92010e0140200000327531cb1fd592010f01c4150000327531cb920110019b4da7160000327531cb920111014020000066ec327531cb92011201c415b917
9+
0564327300000100fb70900000327531cb92011301b52d000032bec57531cb920114013c2d0000327531cb920068011501c9260000327531cb9201434a

Test/DNP3HexOutOfOrder.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
0564ff53000001000db509019d160000654231cb92011301f43421460000654231cb92011401f73400006542fa0231cb92011501ed270000654231cb920156061601f4340000654231cb92011701f73427b90000654231cb92011801ed270000654210e131cb920113018c3500004e4631cb92012ecf16018c3500004e4631cb92011a010900e2ee00004e4631cb920100010e0000004248ad0f31cb920101010c000000424831cb9201930c02010e000000424831cb92010d019318aa4f0000424831cb92010e017826000042480ff831cb92010f0199170000424831cb92015cf1100193180000424831cb9201110178264adc0000424831cb92011201991700004248dc5631cb92011301d5340000424831cb920174b8140153340000424831cbdb82
2+
0564ff730000010050ad48a8810600200317a900010d0000009562193a31cb92010e015c210000953a31cb92503b0111015c210000953a31cb920113012fa2b42e0000953a31cb92011401642e0000959af03a31cb920116012f2e0000953a31cb92078c011701642e0000953a31cb92011a01095e65000000953a31cb92010e01b02500007d965c3e31cb92011101b02500007d3e31cb92a6690113014d3200007d3e31cb92011401e749a73100007d3e31cb920116014d3200007d41ae3e31cb92011701e73100007d3e31cb92d063011a010a0000007d3e31cb92010d01810c03170000654231cb92010e013a280000659fdd4231cb92010f019d160000654231cb9261b901100181170000654231cb920111013a891f280000654231cb9201126660
3+
0564ff730000010050ad0a92011501d8290000424831cb9201164d6c01d5340000424831cb9201170153340058c300424831cb92011801d8290000424831a23acb92011a010a000000424831cb92010d835e013c1900002a4c31cb92010e01e621001723002a4c31cb92010f013e1800002a4c316a0ecb920110013c1900002a4c31cb920111b6b501e62100002a4c31cb920112013e1800cae1002a4c31cb920113015f3100002a4c31fd0dcb92011401d23000002a4c31cb920115822a01f82a00002a4c31cb920116015f3100195b002a4c31cb92011701d23000002a4c31abe6cb92011801f82a00002a4c31cb92010e263001301e00001f4e31cb92011101301e00a9a8001f4e31cb920113013c2e00001f4e310d72cb920114018f2d00001f1ddb
4+
0564ff53000001000db50d01542500009c6331cb920113017234269600009c6331cb92011401ed3200009c63197331cb92011501742b00009c6331cb920125d01601723400009c6331cb92011701ed32393d00009c6331cb92011801742b00009c63650131cb92010d012c190000856731cb920173b50e0111290000856731cb920110012c19fd180000856731cb92011101112900008567000931cb92011301f1370000856731cb9201fcbb14018f360000856731cb92011501db2a7ee90000856731cb92011601f13700008567cd1031cb920117018f360000856731cb9201f5001801db2a0000856731cb920100010d00549100006d6b31cb920101010b0000006d6bf47731cb920102010d0000006d6b31cb9201967f0d012e1800006d6b31cbd74d
5+
0564ff730000010050ad0e92010e018d2a00006d6b31cb92010f89c7014b1700006d6b31cb920110012e18000b8d006d6b31cb920111018d2a00006d6b31dbe0cb920112014b1700006d6b31cb92011432b301f83600006d6b31cb9201150158290050ac006d6b31cb92011701f83600006d6b31e1adcb92011801582900006d6b31cb920119fb0501e30000006d6b31cb92010401e40000f303006d6b31cb92010d01ad170000566f31aab7cb92010e0158290000566f31cb920110844101ad170000566f31cb92011101582900b6c300566f31cb92011301cd360000566f31ea6bcb92011401ad350000566f31cb92011599fc0172280000566f31cb92011601cd36009a5900566f31cb92011701ad350000566f315f46cb9201180172280000561217
6+
0564ff53000001000db50f6f31cb92010d01271700004a7131cbe6aa92010e01072500004a7131cb92010f01fbbf321600004a7131cb9201100127170000634a4a7131cb92011101072500004a7131cb907992011201321600004a7131cb92011301e0b65e3200004a7131cb92011401b0310000dea64a7131cb92011501672700004a7131cb81f4920116015e3200004a7131cb92011701f593b03100004a7131cb9201180167270000580c4a7131cb920100010c000000327531cb001b920101010a000000327531cb92010201764c0c000000327531cb92010d01a716000017cf327531cb92010e0140200000327531cb1fd592010f01c4150000327531cb920110019b4da7160000327531cb920111014020000066ec327531cb92011201c415b917
7+
0564ff53000001000db50b4e31cb920116013c2e00001f4e31cb146f920117018f2d00001f4e31cb92010d016205d2190000075231cb92010e019e1b0000dea5075231cb92010f01a7180000075231cb771792011001d2190000075231cb92011101ad3e9e1b0000075231cb92011201a7180000dff9075231cb92011301d12c0000075231cbab03920114018c2b0000075231cb92011501a4f7e32b0000075231cb92011601d12c0000a120075231cb920117018c2b0000075231cb086b92011801e32b0000075231cb92011901866e01010000075231cb9201040102010000e44d075231cb92010e01151a0000fb5331cbb18392011101151a0000fb5331cb92011301b1c9d12b0000fb5331cb92011401012b0000d4e9fb5331cb92011601d12b70c3
8+
0564ff730000010050ad0c0000fb5331cb92011701012b0000fb47bd5331cb92010e01a11a0000d85931cb92f91a011101a11a0000d85931cb9201130167f9802c0000d85931cb920114017b2b0000d85acf5931cb92011601672c0000d85931cb9258120117017b2b0000d85931cb92010e010037f71d0000cc5b31cb92011101001d0000cc1a4a5b31cb92011301282e0000cc5b31cb921b320114012d2d0000cc5b31cb9201160128a9572e0000cc5b31cb920117012d2d0000cc3ff95b31cb92010e0125200000b45f31cb92864601110125200000b45f31cb92011301a7eedc300000b45f31cb920114011f2f0000b41d6b5f31cb92011601a7300000b45f31cb928d7b0117011f2f0000b45f31cb92010e0154d2ab2500009c6331cb9201119e8d
9+
0564327300000100fb70900000327531cb92011301b52d000032bec57531cb920114013c2d0000327531cb920068011501c9260000327531cb9201434a

Test/ProtoConvInOut.pl

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#!/usr/bin/perl
2+
use strict;
3+
use warnings;
4+
use Socket;
5+
use IO::Select;
6+
use Time::HiRes qw(sleep);
7+
8+
# Check for correct number of arguments
9+
die "Usage: $0 <input_file> <snd_source_port> <snd_destination_ip> <snd_destination_port> <rcv_source_port> <rcv_destination_ip> <rcv_destination_port> <output_file> <diff_file>\n"
10+
unless @ARGV == 9;
11+
12+
my ($input_file, $snd_source_port, $snd_dest_ip, $snd_dest_port, $rcv_source_port, $rcv_dest_ip, $rcv_dest_port, $output_file, $diff_file) = @ARGV;
13+
14+
# Fork to run send and receive operations concurrently
15+
my $pid = fork();
16+
17+
die "Fork failed: $!" unless defined $pid;
18+
19+
if ($pid == 0) {
20+
# Child process - receive
21+
do_udp($output_file, $rcv_source_port, $rcv_dest_ip, $rcv_dest_port, "receive");
22+
exit 0;
23+
} else {
24+
# Parent process - send
25+
# Small delay to ensure receiver starts first
26+
sleep(0.5);
27+
28+
do_udp($input_file, $snd_source_port, $snd_dest_ip, $snd_dest_port, "send");
29+
30+
# Wait for child process to complete
31+
waitpid($pid, 0);
32+
33+
# Diff the input and output files
34+
if(system("diff", $diff_file, $output_file) != 0)
35+
{
36+
die "Test Failed. Diff does not pass";
37+
}
38+
print "Test Passed.\n";
39+
exit 0;
40+
}
41+
42+
sub do_udp {
43+
my ($filename, $source_port, $dest_ip, $dest_port, $direction) = @_;
44+
45+
# Create UDP socket
46+
socket(my $sock, PF_INET, SOCK_DGRAM, getprotobyname('udp'))
47+
or die "Could not create socket: $!";
48+
49+
# Bind to specific source port
50+
bind($sock, sockaddr_in($source_port, INADDR_ANY))
51+
or die "Could not bind to source port: $!";
52+
53+
# Resolve destination address
54+
my $dest_addr = inet_aton($dest_ip)
55+
or die "Could not resolve destination IP: $!";
56+
57+
# Prepare destination socket address
58+
my $dest_sock_addr = sockaddr_in($dest_port, $dest_addr);
59+
60+
if ($direction eq "send") {
61+
# Open input file
62+
open(my $fh, '<', $filename)
63+
or die "Could not open file '$filename' for reading: $!";
64+
65+
# Process each line
66+
while (my $hex_line = <$fh>)
67+
{
68+
chomp $hex_line;
69+
70+
# Convert hex string to binary
71+
my $binary_data = pack("H*", $hex_line);
72+
73+
# Send UDP packet
74+
send($sock, $binary_data, 0, $dest_sock_addr)
75+
or die "Could not send packet: $!";
76+
}
77+
close($fh);
78+
}
79+
else #receive
80+
{
81+
# Open output file
82+
open(my $output_fh, '>', $filename)
83+
or die "Could not open file '$filename' for writing: $!";
84+
85+
# Create a selector for handling timeouts
86+
my $sel = IO::Select->new($sock);
87+
88+
# Receive packets with a 2-second idle timeout
89+
while (1)
90+
{
91+
my @ready = $sel->can_read(2); # 2-second timeout
92+
93+
if (@ready) {
94+
my $packet;
95+
my $peer_addr = recv($sock, $packet, 65535, 0);
96+
97+
if (defined $peer_addr) {
98+
# Convert received binary data to hex
99+
my $hex_packet = unpack("H*", $packet);
100+
101+
# Write hex packet to file
102+
print $output_fh "$hex_packet\n";
103+
}
104+
} else {
105+
# No packets received for 2 seconds, exit loop
106+
last;
107+
}
108+
}
109+
110+
close($output_fh);
111+
}
112+
113+
close($sock);
114+
}

0 commit comments

Comments
 (0)