Skip to content

Commit

Permalink
Stabilized diode release candidate (#28)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
TechSolomon authored Mar 14, 2024
1 parent cb880db commit a89f7c9
Show file tree
Hide file tree
Showing 18 changed files with 452 additions and 713 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This workflow will build a golang project
# This workflow will build a Go project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: ARCTIC CAMIO Lab
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
# Go workspace file
go.work

# xperimental results
# Input source → experimental results
*.txt
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
all: build

build:
go build -o diode -ldflags="-X main.SemVer=0.0.7" diode.go
go build -o diode -ldflags="-X main.SemVer=0.0.8" diode.go

test:
go test -v
Expand Down
14 changes: 0 additions & 14 deletions Pipfile

This file was deleted.

445 changes: 0 additions & 445 deletions Pipfile.lock

This file was deleted.

5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ Scripts for verifying TCP passthrough functionality.
```zsh
.
├── config
├── config.yaml
├── diode.go
├── diode_test.go
├── docker-compose.yaml
Expand All @@ -33,13 +32,11 @@ Scripts for verifying TCP passthrough functionality.
├── go.sum
├── insights
├── Makefile
├── mqtt
├── Pipfile
├── Pipfile.lock
├── README.md
├── sample
└── utility

5 directories, 8 files
```

#### Architecture Diagram (WIP)
Expand Down
11 changes: 0 additions & 11 deletions config.yaml

This file was deleted.

106 changes: 106 additions & 0 deletions config/B4-0144-355112.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
{
"/config/input/interface": 1,
"/config/input/ethernet/macAddress": "f4:90:cb:a0:01:2a",
"/config/input/ethernet/ip": "10.6.28.31",
"/config/input/ethernet/gateway": "10.6.28.1",
"/config/input/ethernet/subnetMask": "255.255.255.0",
"/config/input/ethernet/dhcpMode": 0,
"/config/input/rs485/baud": 4,
"/config/input/rs485/dataBits": 1,
"/config/input/rs485/parity": 0,
"/config/input/rs485/stopBits": 0,
"/config/input/rs485/protocol": 0,
"/config/input/ethernet/protocol": 4,
"/config/input/rs485/modbus/mode": 0,
"/config/input/rs485/modbus/rxTimeout": 2,
"/config/input/rs485/modbus/txTimeout": 200,
"/config/input/rs485/modbus/pollingInterval": 300,
"/config/input/rs485/modbus/numberOfDevices": 0,
"/config/input/ethernet/modbus/mode": 1,
"/config/input/ethernet/modbus/txTimeout": 2000,
"/config/input/ethernet/modbus/pollingInterval": 300,
"/config/input/ethernet/modbus/numberOfDevices": 1,
"/config/input/ethernet/modbus/device": {
"1": {
"unitId": 1,
"ip": "192.168.1.100",
"hiByteFirst": true,
"hiWordFirst": true,
"numberOfGroups": 0
}
},
"/config/input/ethernet/ftp/clientServer": 0,
"/config/input/ethernet/ftp/transferMode": 0,
"/config/input/ethernet/ftp/transferType": 0,
"/config/input/ethernet/ftp/ip": "10.6.28.31",
"/config/input/ethernet/ftp/username": "",
"/config/input/ethernet/ftp/password": "",
"/config/input/ethernet/ftp/portMin": 49152,
"/config/input/ethernet/ftp/portMax": 65535,
"/config/input/ethernet/ftp/certificate": "",
"/config/input/ethernet/ftp/privateKey": "",
"/config/input/ethernet/tcpServer/port": 49152,
"/config/input/ethernet/tcpServer/socketTimeout": 60,
"/config/input/ethernet/udpServer/port": 49152,
"/config/input/ethernet/udpServer/ackEnabled": true,
"/config/system/model": "FD-5M-SE1-XE2-B4-BLK",
"/config/system/serialNumber": "B4-0144-355112",
"/config/system/fwRevision": "4.0.2",
"/config/system/configRevision": 1,
"/config/system/powerFailure/enabled": true,
"/config/system/powerFailure/clearTimer": 12,
"/config/system/diagnostics/enabled": true,
"/config/system/diagnostics/level": 1,
"/config/system/diagnostics/targetIp": "10.3.14.142",
"/config/system/diagnostics/targetPort": 13337,
"/config/system/diagnostics/retryWaitTime": 30,
"/config/system/port/alwaysOpen": true,
"/config/system/port/timeout": 30,
"/config/system/session/timeout": 30,
"/config/output/interface": 1,
"/config/output/ethernet/macAddress": "f4:90:cb:a0:01:2b",
"/config/output/ethernet/ip": "10.3.14.159",
"/config/output/ethernet/gateway": "10.3.14.1",
"/config/output/ethernet/subnetMask": "255.255.255.0",
"/config/output/ethernet/dhcpMode": 0,
"/config/output/ethernet/ntpServer": "pool.ntp.org",
"/config/output/ethernet/dnsServer": "8.8.8.8",
"/config/output/rs485/baud": 4,
"/config/output/rs485/dataBits": 1,
"/config/output/rs485/parity": 0,
"/config/output/rs485/stopBits": 0,
"/config/output/rs485/protocol": 0,
"/config/output/ethernet/protocol": 5,
"/config/output/cellular/protocol": 0,
"/config/output/cellular/mqtt/deviceId": "B4-0144-355112",
"/config/output/cellular/mqtt/topic": "acep",
"/config/output/cellular/mqtt/hostUrl": "10.3.14.142",
"/config/output/cellular/mqtt/publishCycle": 1,
"/config/output/cellular/mqtt/port": 1,
"/config/output/ethernet/modbus/socketTimeout": 60,
"/config/output/ethernet/ftp/clientServer": 1,
"/config/output/ethernet/ftp/transferMode": 1,
"/config/output/ethernet/ftp/transferType": 0,
"/config/output/ethernet/ftp/targetIp": "192.168.1.1",
"/config/output/ethernet/ftp/user": "",
"/config/output/ethernet/ftp/password": "",
"/config/output/ethernet/ftp/serverVerificationEnabled": true,
"/config/output/ethernet/ftp/retryTimer": 10,
"/config/output/ethernet/ftp/streamingEnabled": false,
"/config/output/ethernet/ftp/logs/directory": "",
"/config/output/ethernet/ftp/logs/enabled": true,
"/config/output/ethernet/ftp/certificate": "",
"/config/output/ethernet/mqtt/deviceId": "B4-0144-355112",
"/config/output/ethernet/mqtt/topic": "acep",
"/config/output/ethernet/mqtt/hostUrl": "10.3.14.142",
"/config/output/ethernet/mqtt/publishCycle": 1,
"/config/output/ethernet/mqtt/port": 1,
"/config/output/ethernet/tcpJson/targetIp": "10.3.14.142",
"/config/output/ethernet/tcpJson/targetPort": 49152,
"/config/output/ethernet/tcpClient/targetIp": "10.3.14.142",
"/config/output/ethernet/tcpClient/targetPort": 13337,
"/config/output/ethernet/tcpClient/tls/enabled": false,
"/config/output/ethernet/tcpClient/tls/certificate": "",
"/config/output/ethernet/udpClient/targetIp": "192.168.1.20",
"/config/output/ethernet/udpClient/targetPort": 49152
}
13 changes: 13 additions & 0 deletions config/settings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Data Diode Settings
input:
ip: "localhost"
port: 49152
timeout: 60 # seconds
output:
ip: "localhost"
port: 13337
tls: false
broker:
server: "test.mosquitto.org"
port: 1883
topic: "diode/telemetry"
80 changes: 56 additions & 24 deletions diode.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,69 @@ import (
"os"
"time"

"github.com/acep-uaf/data-diode/insights"
"github.com/acep-uaf/data-diode/utility"
utility "github.com/acep-uaf/data-diode/utility"
"github.com/urfave/cli/v2"
"gopkg.in/yaml.v2"
)

var (
SemVer string
SemVer string
ConfigSettings = "config/settings.yaml"
InputTextFile = "docs/example.txt"
)

type Configuration struct {
Input struct {
IP string
Port int
IP string
Port int
Timeout int
}
Output struct {
IP string
Port int
TLS bool
}
Broker struct {
Server string
Port int
Topic string
Message string
Server string
Port int
Topic string
}
}

func sampleMetrics(server string, port int) {
fmt.Println(">> Local time: ", time.Now())
fmt.Println(">> UTC time: ", time.Now().UTC())
fmt.Println(">> Value: ", analysis.Value())
func exampleContents(location string) {
sample := utility.ReadLineContent(location)
utility.PrintFileContent(sample)
utility.OutputStatistics(sample)
}

func republishContents(location string, mqttBrokerIP string, mqttBrokerTopic string, mqttBrokerPort int) {
fileContent := utility.ReadLineContent(location)

fmt.Println(">> Server: ", mqttBrokerIP)
fmt.Println(">> Topic: ", mqttBrokerTopic)
fmt.Println(">> Port: ", mqttBrokerPort)

start := time.Now()

for i := 1; i <= len(fileContent.Lines); i++ {
utility.Observability(mqttBrokerIP, mqttBrokerPort, mqttBrokerTopic, fileContent.Lines[i])
}

t := time.Now()

elapsed := t.Sub(start)

if len(fileContent.Lines) == 0 {
fmt.Println(">> No message content sent.")
} else if len(fileContent.Lines) == 1 {
fmt.Println(">> Sent message from ", location, " to topic: ", mqttBrokerTopic, " in ", elapsed)
} else {
fmt.Println(">> Sent ", len(fileContent.Lines), " messages from ", location, " to topic: ", mqttBrokerTopic, " in ", elapsed)
}
}

func main() {
data, err := os.ReadFile("config.yaml")
data, err := os.ReadFile(ConfigSettings)

if err != nil {
panic(err)
Expand All @@ -62,13 +90,12 @@ func main() {
// Configuration Settings

diodeInputSideIP := config.Input.IP
diodeTCPPassthroughPort := config.Input.Port
targetTCPServerIP := config.Output.IP
targetTCPServerPort := config.Output.Port
diodePassthroughPort := config.Input.Port
targetServerIP := config.Output.IP
targetServerPort := config.Output.Port

mqttBrokerIP := config.Broker.Server
mqttBrokerPort := config.Broker.Port
mqttBrokerMessage := config.Broker.Message
mqttBrokerTopic := config.Broker.Topic

app := &cli.App{
Expand All @@ -85,7 +112,9 @@ func main() {
Usage: "Input side of the data diode",
Action: func(cCtx *cli.Context) error {
fmt.Println("----- INPUT -----")
utility.Client(diodeInputSideIP, diodeTCPPassthroughPort)
fmt.Println(">> Client IP: ", diodeInputSideIP)
fmt.Println(">> Client Port: ", diodePassthroughPort)
utility.StartPlaceholderClient(diodeInputSideIP, diodePassthroughPort)
return nil
},
},
Expand All @@ -95,7 +124,9 @@ func main() {
Usage: "Output side of the data diode",
Action: func(sCtx *cli.Context) error {
fmt.Println("----- OUTPUT -----")
utility.Server(targetTCPServerIP, targetTCPServerPort)
fmt.Println(">> Server IP: ", targetServerIP)
fmt.Println(">> Server Port: ", targetServerPort)
utility.StartPlaceholderServer(targetServerIP, targetServerPort)
return nil
},
},
Expand All @@ -105,7 +136,7 @@ func main() {
Usage: "Testing state synchronization via diode I/O",
Action: func(tCtx *cli.Context) error {
fmt.Println("----- TEST -----")
analysis.Validation()
exampleContents(InputTextFile)
return nil
},
},
Expand All @@ -125,17 +156,18 @@ func main() {
Usage: "System benchmark analysis + report performance metrics",
Action: func(bCtx *cli.Context) error {
fmt.Println("----- BENCHMARKS -----")
sampleMetrics(utility.CONN_HOST, 3333)
// TODO: Perform specific benchmarks here...
// e.g. ping test, network throughput, system performance, disk I/O, memory usage
return nil
},
},
{
Name: "mqtt",
Aliases: []string{"m"},
Usage: "MQTT (TCP stream) demo",
Usage: "MQTT TCP stream demo",
Action: func(mCtx *cli.Context) error {
fmt.Println("----- MQTT -----")
utility.Republisher(mqttBrokerIP, mqttBrokerPort, mqttBrokerTopic, mqttBrokerMessage)
republishContents(InputTextFile, mqttBrokerIP, mqttBrokerTopic, mqttBrokerPort)
return nil
},
},
Expand Down
Loading

0 comments on commit a89f7c9

Please sign in to comment.