Skip to content

Commit a89f7c9

Browse files
authored
Stabilized diode release candidate (#28)
* feat: creating sample Go module * feat: example error handling * refactor: random example communication message * feat: example map data type (slice) & test cases * Template for suggested experimental expectations (#24) * feat: draft variable packet size experiment * docs: new section for project replicability * docs: markdown diagram (system control flow) + blockquote highlight * refactor: utility to insights + diode collection script * fix: text cache source location * Delete `message` directory * Delete `example` directory * bump: latest Go milestone (minor release) * Topic levels for MQTT (#27) * feat: diode telemetry channel + updated configuration settings * refactor: diode config settings & remove republish code * feat: read file contents from text file * feat: MQTT index, topic, payload, & checksum (example) * feat: create new message counter via mutex * feat: send file contents via MQTT telemetry topic * nit: remove unused broker message contents * refactor: message content of diode diagnostics * docs: finalize project directory structure * refactor: variables for testing content publisher * feat: placeholder client + server (I/O) * refactor: data diode settings & connection constants * refactor: application constants with minimal error handling * deps: remove outdated string metrics library * docs: create B4-0144-355112.json (via Fend_B4_4.0.2.fw) Source: #30 * refactor: diode test variables
1 parent cb880db commit a89f7c9

18 files changed

Lines changed: 452 additions & 713 deletions

.github/workflows/go.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# This workflow will build a golang project
1+
# This workflow will build a Go project
22
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
33

44
name: ARCTIC CAMIO Lab

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@
2020
# Go workspace file
2121
go.work
2222

23-
# xperimental results
23+
# Input source → experimental results
2424
*.txt

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
all: build
2+
13
build:
2-
go build -o diode -ldflags="-X main.SemVer=0.0.7" diode.go
4+
go build -o diode -ldflags="-X main.SemVer=0.0.8" diode.go
35

46
test:
57
go test -v

Pipfile

Lines changed: 0 additions & 14 deletions
This file was deleted.

Pipfile.lock

Lines changed: 0 additions & 445 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ Scripts for verifying TCP passthrough functionality.
2323
```zsh
2424
.
2525
├── config
26-
├── config.yaml
2726
├── diode.go
2827
├── diode_test.go
2928
├── docker-compose.yaml
@@ -33,13 +32,11 @@ Scripts for verifying TCP passthrough functionality.
3332
├── go.sum
3433
├── insights
3534
├── Makefile
36-
├── mqtt
37-
├── Pipfile
38-
├── Pipfile.lock
3935
├── README.md
4036
├── sample
4137
└── utility
4238

39+
5 directories, 8 files
4340
```
4441

4542
#### Architecture Diagram (WIP)

config.yaml

Lines changed: 0 additions & 11 deletions
This file was deleted.

config/B4-0144-355112.json

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
{
2+
"/config/input/interface": 1,
3+
"/config/input/ethernet/macAddress": "f4:90:cb:a0:01:2a",
4+
"/config/input/ethernet/ip": "10.6.28.31",
5+
"/config/input/ethernet/gateway": "10.6.28.1",
6+
"/config/input/ethernet/subnetMask": "255.255.255.0",
7+
"/config/input/ethernet/dhcpMode": 0,
8+
"/config/input/rs485/baud": 4,
9+
"/config/input/rs485/dataBits": 1,
10+
"/config/input/rs485/parity": 0,
11+
"/config/input/rs485/stopBits": 0,
12+
"/config/input/rs485/protocol": 0,
13+
"/config/input/ethernet/protocol": 4,
14+
"/config/input/rs485/modbus/mode": 0,
15+
"/config/input/rs485/modbus/rxTimeout": 2,
16+
"/config/input/rs485/modbus/txTimeout": 200,
17+
"/config/input/rs485/modbus/pollingInterval": 300,
18+
"/config/input/rs485/modbus/numberOfDevices": 0,
19+
"/config/input/ethernet/modbus/mode": 1,
20+
"/config/input/ethernet/modbus/txTimeout": 2000,
21+
"/config/input/ethernet/modbus/pollingInterval": 300,
22+
"/config/input/ethernet/modbus/numberOfDevices": 1,
23+
"/config/input/ethernet/modbus/device": {
24+
"1": {
25+
"unitId": 1,
26+
"ip": "192.168.1.100",
27+
"hiByteFirst": true,
28+
"hiWordFirst": true,
29+
"numberOfGroups": 0
30+
}
31+
},
32+
"/config/input/ethernet/ftp/clientServer": 0,
33+
"/config/input/ethernet/ftp/transferMode": 0,
34+
"/config/input/ethernet/ftp/transferType": 0,
35+
"/config/input/ethernet/ftp/ip": "10.6.28.31",
36+
"/config/input/ethernet/ftp/username": "",
37+
"/config/input/ethernet/ftp/password": "",
38+
"/config/input/ethernet/ftp/portMin": 49152,
39+
"/config/input/ethernet/ftp/portMax": 65535,
40+
"/config/input/ethernet/ftp/certificate": "",
41+
"/config/input/ethernet/ftp/privateKey": "",
42+
"/config/input/ethernet/tcpServer/port": 49152,
43+
"/config/input/ethernet/tcpServer/socketTimeout": 60,
44+
"/config/input/ethernet/udpServer/port": 49152,
45+
"/config/input/ethernet/udpServer/ackEnabled": true,
46+
"/config/system/model": "FD-5M-SE1-XE2-B4-BLK",
47+
"/config/system/serialNumber": "B4-0144-355112",
48+
"/config/system/fwRevision": "4.0.2",
49+
"/config/system/configRevision": 1,
50+
"/config/system/powerFailure/enabled": true,
51+
"/config/system/powerFailure/clearTimer": 12,
52+
"/config/system/diagnostics/enabled": true,
53+
"/config/system/diagnostics/level": 1,
54+
"/config/system/diagnostics/targetIp": "10.3.14.142",
55+
"/config/system/diagnostics/targetPort": 13337,
56+
"/config/system/diagnostics/retryWaitTime": 30,
57+
"/config/system/port/alwaysOpen": true,
58+
"/config/system/port/timeout": 30,
59+
"/config/system/session/timeout": 30,
60+
"/config/output/interface": 1,
61+
"/config/output/ethernet/macAddress": "f4:90:cb:a0:01:2b",
62+
"/config/output/ethernet/ip": "10.3.14.159",
63+
"/config/output/ethernet/gateway": "10.3.14.1",
64+
"/config/output/ethernet/subnetMask": "255.255.255.0",
65+
"/config/output/ethernet/dhcpMode": 0,
66+
"/config/output/ethernet/ntpServer": "pool.ntp.org",
67+
"/config/output/ethernet/dnsServer": "8.8.8.8",
68+
"/config/output/rs485/baud": 4,
69+
"/config/output/rs485/dataBits": 1,
70+
"/config/output/rs485/parity": 0,
71+
"/config/output/rs485/stopBits": 0,
72+
"/config/output/rs485/protocol": 0,
73+
"/config/output/ethernet/protocol": 5,
74+
"/config/output/cellular/protocol": 0,
75+
"/config/output/cellular/mqtt/deviceId": "B4-0144-355112",
76+
"/config/output/cellular/mqtt/topic": "acep",
77+
"/config/output/cellular/mqtt/hostUrl": "10.3.14.142",
78+
"/config/output/cellular/mqtt/publishCycle": 1,
79+
"/config/output/cellular/mqtt/port": 1,
80+
"/config/output/ethernet/modbus/socketTimeout": 60,
81+
"/config/output/ethernet/ftp/clientServer": 1,
82+
"/config/output/ethernet/ftp/transferMode": 1,
83+
"/config/output/ethernet/ftp/transferType": 0,
84+
"/config/output/ethernet/ftp/targetIp": "192.168.1.1",
85+
"/config/output/ethernet/ftp/user": "",
86+
"/config/output/ethernet/ftp/password": "",
87+
"/config/output/ethernet/ftp/serverVerificationEnabled": true,
88+
"/config/output/ethernet/ftp/retryTimer": 10,
89+
"/config/output/ethernet/ftp/streamingEnabled": false,
90+
"/config/output/ethernet/ftp/logs/directory": "",
91+
"/config/output/ethernet/ftp/logs/enabled": true,
92+
"/config/output/ethernet/ftp/certificate": "",
93+
"/config/output/ethernet/mqtt/deviceId": "B4-0144-355112",
94+
"/config/output/ethernet/mqtt/topic": "acep",
95+
"/config/output/ethernet/mqtt/hostUrl": "10.3.14.142",
96+
"/config/output/ethernet/mqtt/publishCycle": 1,
97+
"/config/output/ethernet/mqtt/port": 1,
98+
"/config/output/ethernet/tcpJson/targetIp": "10.3.14.142",
99+
"/config/output/ethernet/tcpJson/targetPort": 49152,
100+
"/config/output/ethernet/tcpClient/targetIp": "10.3.14.142",
101+
"/config/output/ethernet/tcpClient/targetPort": 13337,
102+
"/config/output/ethernet/tcpClient/tls/enabled": false,
103+
"/config/output/ethernet/tcpClient/tls/certificate": "",
104+
"/config/output/ethernet/udpClient/targetIp": "192.168.1.20",
105+
"/config/output/ethernet/udpClient/targetPort": 49152
106+
}

config/settings.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Data Diode Settings
2+
input:
3+
ip: "localhost"
4+
port: 49152
5+
timeout: 60 # seconds
6+
output:
7+
ip: "localhost"
8+
port: 13337
9+
tls: false
10+
broker:
11+
server: "test.mosquitto.org"
12+
port: 1883
13+
topic: "diode/telemetry"

diode.go

Lines changed: 56 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,41 +13,69 @@ import (
1313
"os"
1414
"time"
1515

16-
"github.com/acep-uaf/data-diode/insights"
17-
"github.com/acep-uaf/data-diode/utility"
16+
utility "github.com/acep-uaf/data-diode/utility"
1817
"github.com/urfave/cli/v2"
1918
"gopkg.in/yaml.v2"
2019
)
2120

2221
var (
23-
SemVer string
22+
SemVer string
23+
ConfigSettings = "config/settings.yaml"
24+
InputTextFile = "docs/example.txt"
2425
)
2526

2627
type Configuration struct {
2728
Input struct {
28-
IP string
29-
Port int
29+
IP string
30+
Port int
31+
Timeout int
3032
}
3133
Output struct {
3234
IP string
3335
Port int
36+
TLS bool
3437
}
3538
Broker struct {
36-
Server string
37-
Port int
38-
Topic string
39-
Message string
39+
Server string
40+
Port int
41+
Topic string
4042
}
4143
}
4244

43-
func sampleMetrics(server string, port int) {
44-
fmt.Println(">> Local time: ", time.Now())
45-
fmt.Println(">> UTC time: ", time.Now().UTC())
46-
fmt.Println(">> Value: ", analysis.Value())
45+
func exampleContents(location string) {
46+
sample := utility.ReadLineContent(location)
47+
utility.PrintFileContent(sample)
48+
utility.OutputStatistics(sample)
49+
}
50+
51+
func republishContents(location string, mqttBrokerIP string, mqttBrokerTopic string, mqttBrokerPort int) {
52+
fileContent := utility.ReadLineContent(location)
53+
54+
fmt.Println(">> Server: ", mqttBrokerIP)
55+
fmt.Println(">> Topic: ", mqttBrokerTopic)
56+
fmt.Println(">> Port: ", mqttBrokerPort)
57+
58+
start := time.Now()
59+
60+
for i := 1; i <= len(fileContent.Lines); i++ {
61+
utility.Observability(mqttBrokerIP, mqttBrokerPort, mqttBrokerTopic, fileContent.Lines[i])
62+
}
63+
64+
t := time.Now()
65+
66+
elapsed := t.Sub(start)
67+
68+
if len(fileContent.Lines) == 0 {
69+
fmt.Println(">> No message content sent.")
70+
} else if len(fileContent.Lines) == 1 {
71+
fmt.Println(">> Sent message from ", location, " to topic: ", mqttBrokerTopic, " in ", elapsed)
72+
} else {
73+
fmt.Println(">> Sent ", len(fileContent.Lines), " messages from ", location, " to topic: ", mqttBrokerTopic, " in ", elapsed)
74+
}
4775
}
4876

4977
func main() {
50-
data, err := os.ReadFile("config.yaml")
78+
data, err := os.ReadFile(ConfigSettings)
5179

5280
if err != nil {
5381
panic(err)
@@ -62,13 +90,12 @@ func main() {
6290
// Configuration Settings
6391

6492
diodeInputSideIP := config.Input.IP
65-
diodeTCPPassthroughPort := config.Input.Port
66-
targetTCPServerIP := config.Output.IP
67-
targetTCPServerPort := config.Output.Port
93+
diodePassthroughPort := config.Input.Port
94+
targetServerIP := config.Output.IP
95+
targetServerPort := config.Output.Port
6896

6997
mqttBrokerIP := config.Broker.Server
7098
mqttBrokerPort := config.Broker.Port
71-
mqttBrokerMessage := config.Broker.Message
7299
mqttBrokerTopic := config.Broker.Topic
73100

74101
app := &cli.App{
@@ -85,7 +112,9 @@ func main() {
85112
Usage: "Input side of the data diode",
86113
Action: func(cCtx *cli.Context) error {
87114
fmt.Println("----- INPUT -----")
88-
utility.Client(diodeInputSideIP, diodeTCPPassthroughPort)
115+
fmt.Println(">> Client IP: ", diodeInputSideIP)
116+
fmt.Println(">> Client Port: ", diodePassthroughPort)
117+
utility.StartPlaceholderClient(diodeInputSideIP, diodePassthroughPort)
89118
return nil
90119
},
91120
},
@@ -95,7 +124,9 @@ func main() {
95124
Usage: "Output side of the data diode",
96125
Action: func(sCtx *cli.Context) error {
97126
fmt.Println("----- OUTPUT -----")
98-
utility.Server(targetTCPServerIP, targetTCPServerPort)
127+
fmt.Println(">> Server IP: ", targetServerIP)
128+
fmt.Println(">> Server Port: ", targetServerPort)
129+
utility.StartPlaceholderServer(targetServerIP, targetServerPort)
99130
return nil
100131
},
101132
},
@@ -105,7 +136,7 @@ func main() {
105136
Usage: "Testing state synchronization via diode I/O",
106137
Action: func(tCtx *cli.Context) error {
107138
fmt.Println("----- TEST -----")
108-
analysis.Validation()
139+
exampleContents(InputTextFile)
109140
return nil
110141
},
111142
},
@@ -125,17 +156,18 @@ func main() {
125156
Usage: "System benchmark analysis + report performance metrics",
126157
Action: func(bCtx *cli.Context) error {
127158
fmt.Println("----- BENCHMARKS -----")
128-
sampleMetrics(utility.CONN_HOST, 3333)
159+
// TODO: Perform specific benchmarks here...
160+
// e.g. ping test, network throughput, system performance, disk I/O, memory usage
129161
return nil
130162
},
131163
},
132164
{
133165
Name: "mqtt",
134166
Aliases: []string{"m"},
135-
Usage: "MQTT (TCP stream) demo",
167+
Usage: "MQTT TCP stream demo",
136168
Action: func(mCtx *cli.Context) error {
137169
fmt.Println("----- MQTT -----")
138-
utility.Republisher(mqttBrokerIP, mqttBrokerPort, mqttBrokerTopic, mqttBrokerMessage)
170+
republishContents(InputTextFile, mqttBrokerIP, mqttBrokerTopic, mqttBrokerPort)
139171
return nil
140172
},
141173
},

0 commit comments

Comments
 (0)