Skip to content

Commit 3f5c166

Browse files
committed
1.3.0-RC1 -- Switch mode is here!
Provide packet inspection byte-code to get payload addressing, and MiniPlex can route packets to branches based on src/dst. Included DNP3 example src/SwitchDNP3.s -> switch.bpf Supported bytecode is a subset of eBPF. May change to RISC-V in future for better assembler support (and/or 3rd party interpreter).
1 parent 027764a commit 3f5c166

File tree

9 files changed

+707
-31
lines changed

9 files changed

+707
-31
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ if(NOT WIN32)
1010
endif()
1111

1212
project(MiniPlex LANGUAGES CXX)
13-
add_definitions(-DMP_VERSION="1.2.0")
13+
add_definitions(-DMP_VERSION="1.3.0")
1414

1515
file(GLOB ${PROJECT_NAME}_SRC src/*.cpp src/*.h)
1616

README.md

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,19 @@ ProtoConv: Protocol adapter to convert between a stream and datagrams.
1111
1212
USAGE:
1313
14-
./MiniPlex {-H|-T|-P} -p <port> [-l <localaddr>] [-Z <rcv buf size>]
15-
[-o <timeout>] [-r <trunkhost>] [-t <trunkport>] [-B
16-
<branchhost>] ... [-b <branchport>] ... [-c <console log
17-
level>] [-f <file log level>] [-F <log filename>] [-S <size
18-
in kB>] [-N <number of files>] [-x <numthreads>] [-M] [-m
19-
<milliseconds>] [--] [--version] [-h]
14+
./MiniPlex {-H|-T|-P|-X} -p <port> [-l <localaddr>] [-Z <rcv buf size>]
15+
[-o <timeout>] [-r <trunk host>] [-t <trunk port>] [-B
16+
<branch host>] ... [-b <branch port>] ... [-C <switchmode
17+
bytecode file>] [-c <console log level>] [-f <file log
18+
level>] [-F <log filename>] [-S <size in kB>] [-N <number of
19+
files>] [-x <num threads>] [-M] [-m <milliseconds>] [--]
20+
[--version] [-h]
2021
2122
2223
Where:
2324
2425
-H, --hub
25-
(OR required) Hub/Star mode: Forward datagrams from/to all endpoints.
26+
(OR required) Hub mode: Forward datagrams from/to all endpoints.
2627
-- OR --
2728
-T, --trunk
2829
(OR required) Trunk mode: Forward frames from a 'trunk' to other
@@ -31,6 +32,10 @@ Where:
3132
-P, --prune
3233
(OR required) Like Trunk mode, but limits flow to one (first in best
3334
dressed) branch
35+
-- OR --
36+
-X, --switch
37+
(OR required) Switch mode: forward datagrams based on application
38+
addresses.
3439
3540
3641
-p <port>, --port <port>
@@ -45,20 +50,28 @@ Where:
4550
-o <timeout>, --timeout <timeout>
4651
Milliseconds to keep an idle endpoint cached
4752
48-
-r <trunkhost>, --trunk_ip <trunkhost>
53+
-r <trunk host>, --trunk_ip <trunk host>
4954
Remote trunk ip address.
5055
51-
-t <trunkport>, --trunk_port <trunkport>
56+
-t <trunk port>, --trunk_port <trunk port>
5257
Remote trunk port.
5358
54-
-B <branchhost>, --branch_ip <branchhost> (accepted multiple times)
59+
-B <branch host>, --branch_ip <branch host> (accepted multiple times)
5560
Remote endpoint addresses to permanently cache. Use -b to provide
5661
respective ports in the same order.
5762
58-
-b <branchport>, --branch_port <branchport> (accepted multiple times)
63+
-b <branch port>, --branch_port <branch port> (accepted multiple
64+
times)
5965
Remote endpoint port to permanently cache. Use -B to provide
6066
respective addresses in the same order.
6167
68+
-C <switchmode bytecode file>, --byte_code <switchmode bytecode file>
69+
eBPF (subset) byte code file. Switch mode code for extracting src and
70+
dst addrs from packet data.
71+
72+
Pre-conditions: r0 = &buf, r1 = buf_size. Post-execution: result = r0
73+
(success==0), src = r2, dst = r3.
74+
6275
-c <console log level>, --console_logging <console log level>
6376
Console log level: off, critical, error, warn, info, debug, or trace.
6477
Default critical.
@@ -76,7 +89,7 @@ Where:
7689
-N <number of files>, --log_num <number of files>
7790
Keep this many log files when rolling the log. Defaults to 3
7891
79-
-x <numthreads>, --concurrency <numthreads>
92+
-x <num threads>, --concurrency <num threads>
8093
A hint for the number of threads in thread pool. Defaults to detected
8194
hardware concurrency.
8295

RELEASE_NOTES

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
# MiniPlex version 1.2.0
1+
# MiniPlex version 1.3.0-RC1
2+
3+
## 1.3.0-RC1
4+
* MiniPlex 'Switch' mode
5+
* Provide packet inspection byte-code to get payload addressing,
6+
* and MiniPlex can route packets to branches based on src/dst.
7+
* Included DNP3 example src/SwitchDNP3.s -> switch.bpf
28

39
## 1.2.0
410
* ProtoConv options for max out-of-order frames and timeout

src/CmdArgs.h

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,26 @@ struct CmdArgs
2727
{
2828
CmdArgs(int argc, char* argv[]):
2929
cmd("A minimal UDP multiplexer/hub/broker. A simple way to bolt-on rudimentary multi-cast/multi-path or combine connections.",' ',MP_VERSION),
30-
Hub("H", "hub", "Hub/Star mode: Forward datagrams from/to all endpoints."),
30+
Hub("H", "hub", "Hub mode: Forward datagrams from/to all endpoints."),
3131
Trunk("T", "trunk", "Trunk mode: Forward frames from a 'trunk' to other endpoints. Forward datagrams from other endpoints to the trunk."),
3232
Prune("P", "prune", "Like Trunk mode, but limits flow to one (first in best dressed) branch"),
33+
Switch("X", "switch", "Switch mode: forward datagrams based on application addresses."),
3334
LocalAddr("l", "local", "Local ip address. Defaults to 0.0.0.0 for all ipv4 interfaces.", false, "0.0.0.0", "localaddr"),
3435
LocalPort("p", "port", "Local port to listen/receive on.", true, 0, "port"),
3536
SoRcvBuf("Z", "so_rcvbuf", "Datagram socket receive buffer size.", false, 512L*1024, "rcv buf size"),
3637
CacheTimeout("o", "timeout", "Milliseconds to keep an idle endpoint cached",false,10000,"timeout"),
37-
TrunkAddr("r", "trunk_ip", "Remote trunk ip address.", false, "", "trunkhost"),
38-
TrunkPort("t", "trunk_port", "Remote trunk port.", false, 0, "trunkport"),
39-
BranchAddrs("B", "branch_ip", "Remote endpoint addresses to permanently cache. Use -b to provide respective ports in the same order.", false, "branchhost"),
40-
BranchPorts("b", "branch_port", "Remote endpoint port to permanently cache. Use -B to provide respective addresses in the same order.", false, "branchport"),
38+
TrunkAddr("r", "trunk_ip", "Remote trunk ip address.", false, "", "trunk host"),
39+
TrunkPort("t", "trunk_port", "Remote trunk port.", false, 0, "trunk port"),
40+
BranchAddrs("B", "branch_ip", "Remote endpoint addresses to permanently cache. Use -b to provide respective ports in the same order.", false, "branch host"),
41+
BranchPorts("b", "branch_port", "Remote endpoint port to permanently cache. Use -B to provide respective addresses in the same order.", false, "branch port"),
42+
ByteCodeFile("C", "byte_code", "eBPF (subset) byte code file. Switch mode code for extracting src and dst addrs from packet data.\n"
43+
"Pre-conditions: r0 = &buf, r1 = buf_size. Post-execution: result = r0 (success==0), src = r2, dst = r3.", false, "switch.bpf", "switchmode bytecode file"),
4144
ConsoleLevel("c", "console_logging", "Console log level: off, critical, error, warn, info, debug, or trace. Default critical.", false, "critical", "console log level"),
4245
FileLevel("f", "file_logging", "File log level: off, critical, error, warn, info, debug, or trace. Default error.", false, "error", "file log level"),
4346
LogFile("F", "log_file", "Log filename. Defaults to ./MiniPlex.log", false, "MiniPlex.log", "log filename"),
4447
LogSize("S", "log_size", "Roll the log file at this many kB. Defaults to 5000", false, 5000, "size in kB"),
4548
LogNum("N", "log_num", "Keep this many log files when rolling the log. Defaults to 3", false, 3, "number of files"),
46-
ConcurrencyHint("x", "concurrency", "A hint for the number of threads in thread pool. Defaults to detected hardware concurrency.",false,std::thread::hardware_concurrency(),"numthreads"),
49+
ConcurrencyHint("x", "concurrency", "A hint for the number of threads in thread pool. Defaults to detected hardware concurrency.",false,std::thread::hardware_concurrency(),"num threads"),
4750
Benchmark("M", "benchmark", "Run a loopback test for fixed duration (see -m) and exit."),
4851
BenchDuration("m", "benchmark_duration", "Number of milliseconds to run the loopback benchmark test. Defaults to 10000.",false,10000,"milliseconds")
4952
{
@@ -55,6 +58,7 @@ struct CmdArgs
5558
cmd.add(LogFile);
5659
cmd.add(FileLevel);
5760
cmd.add(ConsoleLevel);
61+
cmd.add(ByteCodeFile);
5862
cmd.add(BranchPorts);
5963
cmd.add(BranchAddrs);
6064
cmd.add(TrunkPort);
@@ -63,22 +67,24 @@ struct CmdArgs
6367
cmd.add(SoRcvBuf);
6468
cmd.add(LocalAddr);
6569
cmd.add(LocalPort);
66-
cmd.xorAdd({&Hub,&Trunk,&Prune});
70+
cmd.xorAdd({&Hub,&Trunk,&Prune,&Switch});
6771
cmd.parse(argc, argv);
6872

69-
if(!Hub && (TrunkAddr.getValue() == "" || TrunkPort.getValue() == 0))
70-
throw std::invalid_argument("Trunk ip and port required when not in Hub mode.");
73+
if((Prune || Trunk) && (TrunkAddr.getValue() == "" || TrunkPort.getValue() == 0))
74+
throw std::invalid_argument("Trunk ip and port required in Trunk or Prune mode.");
7175

7276
asio::error_code err;
7377
asio::ip::address::from_string(LocalAddr.getValue(),err);
7478
if(err)
7579
throw std::invalid_argument("Invalid Local IP address: "+LocalAddr.getValue());
76-
if(!Hub)
80+
81+
if(Prune || Trunk)
7782
{
7883
asio::ip::address::from_string(TrunkAddr.getValue(),err);
7984
if(err)
8085
throw std::invalid_argument("Invalid Trunk IP address: "+TrunkAddr.getValue());
8186
}
87+
8288
for(const auto& B : BranchAddrs.getValue())
8389
{
8490
asio::ip::address::from_string(B,err);
@@ -92,6 +98,7 @@ struct CmdArgs
9298
TCLAP::SwitchArg Hub;
9399
TCLAP::SwitchArg Trunk;
94100
TCLAP::SwitchArg Prune;
101+
TCLAP::SwitchArg Switch;
95102
TCLAP::ValueArg<std::string> LocalAddr;
96103
TCLAP::ValueArg<uint16_t> LocalPort;
97104
TCLAP::ValueArg<size_t> SoRcvBuf;
@@ -100,6 +107,7 @@ struct CmdArgs
100107
TCLAP::ValueArg<uint16_t> TrunkPort;
101108
TCLAP::MultiArg<std::string> BranchAddrs;
102109
TCLAP::MultiArg<uint16_t> BranchPorts;
110+
TCLAP::ValueArg<std::string> ByteCodeFile;
103111
TCLAP::ValueArg<std::string> ConsoleLevel;
104112
TCLAP::ValueArg<std::string> FileLevel;
105113
TCLAP::ValueArg<std::string> LogFile;

0 commit comments

Comments
 (0)