From 68e39a353a35c30d648ecbf88393539d6fd71ba0 Mon Sep 17 00:00:00 2001 From: Fred Clausen <43556888+fredclausen@users.noreply.github.com> Date: Mon, 16 Sep 2024 06:48:50 -0600 Subject: [PATCH] Add in ability to disable service types in an easier way then before --- Cargo.lock | 6 +- Cargo.toml | 2 +- Dockerfile | 83 ++++--- Dockerfile.local | 5 +- README.md | 31 +-- rust/libraries/acars_config/src/lib.rs | 63 +++-- .../src/service_init.rs | 229 +++++++++--------- 7 files changed, 219 insertions(+), 200 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 76ddbac0..50cd598c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,7 +4,7 @@ version = 3 [[package]] name = "acars_config" -version = "1.1.0" +version = "1.2.0" dependencies = [ "clap", "log", @@ -13,7 +13,7 @@ dependencies = [ [[package]] name = "acars_connection_manager" -version = "1.1.0" +version = "1.2.0" dependencies = [ "acars_config", "acars_vdlm2_parser", @@ -30,7 +30,7 @@ dependencies = [ [[package]] name = "acars_router" -version = "1.1.0" +version = "1.2.0" dependencies = [ "acars_config", "acars_connection_manager", diff --git a/Cargo.toml b/Cargo.toml index 1efca043..c2a467c2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ resolver = "2" [workspace.package] edition = "2021" -version = "1.1.0" +version = "1.2.0" authors = ["Fred Clausen", "Mike Nye", "Alex Austin"] description = "ACARS Router: A Utility to ingest ACARS/VDLM2/HFDL from many sources, process, and feed out to many consumers." documentation = "https://github.com/sdr-enthusiasts/acars_router" diff --git a/Dockerfile b/Dockerfile index a318f395..6d7aaea2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,21 +1,24 @@ FROM ghcr.io/sdr-enthusiasts/docker-baseimage:base ENV AR_LISTEN_UDP_ACARS=5550 \ - AR_LISTEN_TCP_ACARS=5550 \ - AR_LISTEN_UDP_VDLM2=5555 \ - AR_LISTEN_TCP_VDLM2=5555 \ - AR_LISTEN_UDP_HFDL=5556 \ - AR_LISTEN_TCP_HFDL=5556 \ - AR_LISTEN_ZMQ_ACARS=35550 \ - AR_LISTEN_ZMQ_VDLM2=35555 \ - AR_LISTEN_ZMQ_HFDL=35556 \ - AR_SERVE_TCP_ACARS=15550 \ - AR_SERVE_TCP_VDLM2=15555 \ - AR_SERVE_TCP_HFDL=15556 \ - AR_SERVE_ZMQ_ACARS=45550 \ - AR_SERVE_ZMQ_VDLM2=45555 \ - AR_SERVE_ZMQ_HFDL=45556 \ - AR_ADD_PROXY_ID=true + AR_LISTEN_TCP_ACARS=5550 \ + AR_LISTEN_UDP_VDLM2=5555 \ + AR_LISTEN_TCP_VDLM2=5555 \ + AR_LISTEN_UDP_HFDL=5556 \ + AR_LISTEN_TCP_HFDL=5556 \ + AR_LISTEN_ZMQ_ACARS=35550 \ + AR_LISTEN_ZMQ_VDLM2=35555 \ + AR_LISTEN_ZMQ_HFDL=35556 \ + AR_SERVE_TCP_ACARS=15550 \ + AR_SERVE_TCP_VDLM2=15555 \ + AR_SERVE_TCP_HFDL=15556 \ + AR_SERVE_ZMQ_ACARS=45550 \ + AR_SERVE_ZMQ_VDLM2=45555 \ + AR_SERVE_ZMQ_HFDL=45556 \ + AR_ADD_PROXY_ID=true \ + AR_DISABLE_ACARS=false \ + AR_DISABLE_VDLM2=false \ + AR_DISABLE_HFDL=false SHELL ["/bin/bash", "-o", "pipefail", "-c"] COPY ./rootfs / @@ -25,28 +28,28 @@ COPY ./bin/acars_router.amd64/acars_router /opt/acars_router.amd64 # hadolint ignore=DL3008,DL3003,SC1091 RUN set -x && \ - KEPT_PACKAGES=() && \ - TEMP_PACKAGES=() && \ - KEPT_PACKAGES+=(libzmq5) && \ - apt-get update && \ - apt-get install -y --no-install-recommends \ - "${KEPT_PACKAGES[@]}" \ - "${TEMP_PACKAGES[@]}"\ - && \ - # ensure binaries are executable - chmod -v a+x \ - /opt/acars_router.armv7 \ - /opt/acars_router.arm64 \ - /opt/acars_router.amd64 \ - && \ - # remove foreign architecture binaries - /rename_current_arch_binary.sh && \ - rm -fv \ - /opt/acars_router.* \ - && \ - # clean up - apt-get remove -y "${TEMP_PACKAGES[@]}" && \ - apt-get autoremove -y && \ - rm -rf /src/* /tmp/* /var/lib/apt/lists/* && \ - # test - /opt/acars_router --version + KEPT_PACKAGES=() && \ + TEMP_PACKAGES=() && \ + KEPT_PACKAGES+=(libzmq5) && \ + apt-get update && \ + apt-get install -y --no-install-recommends \ + "${KEPT_PACKAGES[@]}" \ + "${TEMP_PACKAGES[@]}"\ + && \ + # ensure binaries are executable + chmod -v a+x \ + /opt/acars_router.armv7 \ + /opt/acars_router.arm64 \ + /opt/acars_router.amd64 \ + && \ + # remove foreign architecture binaries + /rename_current_arch_binary.sh && \ + rm -fv \ + /opt/acars_router.* \ + && \ + # clean up + apt-get remove -y "${TEMP_PACKAGES[@]}" && \ + apt-get autoremove -y && \ + rm -rf /src/* /tmp/* /var/lib/apt/lists/* && \ + # test + /opt/acars_router --version diff --git a/Dockerfile.local b/Dockerfile.local index 36fc3913..31699693 100644 --- a/Dockerfile.local +++ b/Dockerfile.local @@ -25,7 +25,10 @@ ENV AR_LISTEN_UDP_ACARS=5550 \ AR_SERVE_ZMQ_ACARS=45550 \ AR_SERVE_ZMQ_VDLM2=45555 \ AR_SERVE_ZMQ_HFDL=45556 \ - AR_ADD_PROXY_ID=true + AR_ADD_PROXY_ID=true \ + AR_DISABLE_ACARS=false \ + AR_DISABLE_VDLM2=false \ + AR_DISABLE_HFDL=false SHELL ["/bin/bash", "-o", "pipefail", "-c"] COPY rootfs / diff --git a/README.md b/README.md index d6bf6443..a61360ef 100644 --- a/README.md +++ b/README.md @@ -105,20 +105,20 @@ The nomenclature for the environment variables is as follows: ### Outbound data -| Env Variable | Command Line Switch | Default | Description | -| ------------------ | ------------------- | ------- | ---------------------------------------- | -| AR_SEND_UDP_ACARS | --send-udp-acars | `unset` | UDP host:port to send ACARS messages to | -| AR_SEND_UDP_VDLM2 | --send-udp-vdlm2 | `unset` | UDP host:port to send VDLM2 messages to | -| AR_SEND_UDP_HFDL | --send-udp-hfdl | `unset` | UDP host:port to send HFDL messages to | -| AR_SEND_TCP_ACARS | --send-tcp-acars | `unset` | TCP host:port to send ACARS messages to | -| AR_SEND_TCP_VDLM2 | --send-tcp-vdlm2 | `unset` | TCP host:port to send VDLM2 messages to | -| AR_SEND_TCP_HFDL | --send-tcp-hfdl | `unset` | TCP host:port to send HFDL messages to | -| AR_SERVE_TCP_ACARS | --serve-tcp-acars | `15550` | TCP port to serve ACARS messages to | -| AR_SERVE_TCP_VDLM2 | --serve-tcp-vdlm2 | `15555` | TCP port to serve VDLM2 messages to | -| AR_SERVE_TCP_HFDL | --serve-tcp-hfdl | `15556` | TCP port to serve HFDL messages to | -| AR_SERVE_ZMQ_ACARS | --serve-zmq-acars | `45550` | ZMQ port to serve ACARS messages to | -| AR_SERVE_ZMQ_VDLM2 | --serve-zmq-vdlm2 | `45555` | ZMQ port to serve VDLM2 messages to | -| AR_SERVE_ZMQ_HFDL | --serve-zmq-hfdl | `45556` | ZMQ port to serve HFDL messages to | +| Env Variable | Command Line Switch | Default | Description | +| ------------------ | ------------------- | ------- | --------------------------------------- | +| AR_SEND_UDP_ACARS | --send-udp-acars | `unset` | UDP host:port to send ACARS messages to | +| AR_SEND_UDP_VDLM2 | --send-udp-vdlm2 | `unset` | UDP host:port to send VDLM2 messages to | +| AR_SEND_UDP_HFDL | --send-udp-hfdl | `unset` | UDP host:port to send HFDL messages to | +| AR_SEND_TCP_ACARS | --send-tcp-acars | `unset` | TCP host:port to send ACARS messages to | +| AR_SEND_TCP_VDLM2 | --send-tcp-vdlm2 | `unset` | TCP host:port to send VDLM2 messages to | +| AR_SEND_TCP_HFDL | --send-tcp-hfdl | `unset` | TCP host:port to send HFDL messages to | +| AR_SERVE_TCP_ACARS | --serve-tcp-acars | `15550` | TCP port to serve ACARS messages to | +| AR_SERVE_TCP_VDLM2 | --serve-tcp-vdlm2 | `15555` | TCP port to serve VDLM2 messages to | +| AR_SERVE_TCP_HFDL | --serve-tcp-hfdl | `15556` | TCP port to serve HFDL messages to | +| AR_SERVE_ZMQ_ACARS | --serve-zmq-acars | `45550` | ZMQ port to serve ACARS messages to | +| AR_SERVE_ZMQ_VDLM2 | --serve-zmq-vdlm2 | `45555` | ZMQ port to serve VDLM2 messages to | +| AR_SERVE_ZMQ_HFDL | --serve-zmq-hfdl | `45556` | ZMQ port to serve HFDL messages to | ### Inbound data @@ -154,3 +154,6 @@ The nomenclature for the environment variables is as follows: | AR_STATS_EVERY | --stats-every | `5` | How often to print stats to the log in minutes | | AR_STATS_VERBOSE | --stats-verbose | `false` | Print verbose stats to the log | | AR_REASSEMBLY_WINDOW | --reassemble-window | `1.0` | If a message comes in, but part of the message is missing, this value will be used to keep the partial message fragment around while attempting to wait for the second (or subsequent) part(s) | +| AR_DISABLE_ACARS | --disable-acars | `false` | Disable ACARS processing. Valid values are `true` or `false` | +| AR_DISABLE_VDLM2 | --disable-vdlm | `false` | Disable VDLM processing. Valid values are `true` or `false` | +| AR_DISABLE_HFDL | --disable-hfdl | `false` | Disable HFDL processing. Valid values are `true` or `false` | diff --git a/rust/libraries/acars_config/src/lib.rs b/rust/libraries/acars_config/src/lib.rs index 6b1b27ca..7ed54cb3 100644 --- a/rust/libraries/acars_config/src/lib.rs +++ b/rust/libraries/acars_config/src/lib.rs @@ -61,6 +61,15 @@ pub struct Input { default_value = "1.0" )] pub reassembly_window: f64, + /// Disable ACARS input + #[clap(long, env = "AR_DISABLE_ACARS", value_parser)] + pub disable_acars: bool, + /// Disable VDLM2 input + #[clap(long, env = "AR_DISABLE_VDLM2", value_parser)] + pub disable_vdlm2: bool, + /// Disable HFDL input + #[clap(long, env = "AR_DISABLE_HFDL", value_parser)] + pub disable_hfdl: bool, // Input Options @@ -215,38 +224,44 @@ impl Input { debug!("AR_LISTEN_ZMQ_ACARS: {:?}", self.listen_zmq_acars); debug!("AR_LISTEN_ZMQ_VDLM2: {:?}", self.listen_zmq_vdlm2); debug!("AR_LISTEN_ZMQ_HFDL: {:?}", self.listen_zmq_hfdl); + debug!("AR_DISABLE_ACARS: {:?}", self.disable_acars); + debug!("AR_DISABLE_VDLM2: {:?}", self.disable_vdlm2); + debug!("AR_DISABLE_HFDL: {:?}", self.disable_hfdl); } pub fn acars_configured(&self) -> bool { - self.receive_tcp_acars.is_some() - || self.listen_udp_acars.is_some() - || self.listen_tcp_acars.is_some() - || self.receive_zmq_acars.is_some() - || self.send_udp_acars.is_some() - || self.send_tcp_acars.is_some() - || self.serve_tcp_acars.is_some() - || self.serve_zmq_acars.is_some() + !self.disable_acars + && (self.receive_tcp_acars.is_some() + || self.listen_udp_acars.is_some() + || self.listen_tcp_acars.is_some() + || self.receive_zmq_acars.is_some() + || self.send_udp_acars.is_some() + || self.send_tcp_acars.is_some() + || self.serve_tcp_acars.is_some() + || self.serve_zmq_acars.is_some()) } pub fn vdlm_configured(&self) -> bool { - self.receive_tcp_vdlm2.is_some() - || self.listen_udp_vdlm2.is_some() - || self.listen_tcp_vdlm2.is_some() - || self.receive_zmq_vdlm2.is_some() - || self.send_udp_vdlm2.is_some() - || self.send_tcp_vdlm2.is_some() - || self.serve_tcp_vdlm2.is_some() - || self.serve_zmq_vdlm2.is_some() + !self.disable_vdlm2 + && (self.receive_tcp_vdlm2.is_some() + || self.listen_udp_vdlm2.is_some() + || self.listen_tcp_vdlm2.is_some() + || self.receive_zmq_vdlm2.is_some() + || self.send_udp_vdlm2.is_some() + || self.send_tcp_vdlm2.is_some() + || self.serve_tcp_vdlm2.is_some() + || self.serve_zmq_vdlm2.is_some()) } pub fn hfdl_configured(&self) -> bool { - self.receive_tcp_hfdl.is_some() - || self.listen_udp_hfdl.is_some() - || self.listen_tcp_hfdl.is_some() - || self.receive_zmq_hfdl.is_some() - || self.send_udp_hfdl.is_some() - || self.send_tcp_hfdl.is_some() - || self.serve_tcp_hfdl.is_some() - || self.serve_zmq_hfdl.is_some() + !self.disable_hfdl + && (self.receive_tcp_hfdl.is_some() + || self.listen_udp_hfdl.is_some() + || self.listen_tcp_hfdl.is_some() + || self.receive_zmq_hfdl.is_some() + || self.send_udp_hfdl.is_some() + || self.send_tcp_hfdl.is_some() + || self.serve_tcp_hfdl.is_some() + || self.serve_zmq_hfdl.is_some()) } } diff --git a/rust/libraries/acars_connection_manager/src/service_init.rs b/rust/libraries/acars_connection_manager/src/service_init.rs index 62b6be83..7b3c1527 100644 --- a/rust/libraries/acars_connection_manager/src/service_init.rs +++ b/rust/libraries/acars_connection_manager/src/service_init.rs @@ -46,130 +46,51 @@ use tokio_util::codec::{Framed, LinesCodec}; pub async fn start_processes(args: Input) { args.print_values(); - let message_handler_config_acars: MessageHandlerConfig = - MessageHandlerConfig::new(&args, "ACARS"); - let message_handler_config_vdlm: MessageHandlerConfig = - MessageHandlerConfig::new(&args, "VDLM"); - let message_handler_config_hfdl: MessageHandlerConfig = - MessageHandlerConfig::new(&args, "HFDL"); - - // ACARS Servers // Create the input channel all receivers will send their data to. // NOTE: To keep this straight in my head, the "TX" is the RECEIVER server (and needs a channel to TRANSMIT data to) // The "RX" is the TRANSMIT server (and needs a channel to RECEIVE data from) - let (tx_receivers_acars, rx_receivers_acars) = mpsc::channel(32); - // Create the input channel processed messages will be sent to - let (tx_processed_acars, rx_processed_acars) = mpsc::channel(32); - // VDLM - // Create the input channel all receivers will send their data to. - let (tx_receivers_vdlm, rx_receivers_vdlm) = mpsc::channel(32); - // Create the input channel processed messages will be sent to - let (tx_processed_vdlm, rx_processed_vdlm) = mpsc::channel(32); - // HFDL - // Create the input channel all receivers will send their data to. - let (tx_receivers_hfdl, rx_receivers_hfdl) = mpsc::channel(32); - // Create the input channel processed messages will be sent to - let (tx_processed_hfdl, rx_processed_hfdl) = mpsc::channel(32); - - // start the input servers - debug!("Starting input servers"); - // start_listener_servers(&config, tx_receivers_acars, tx_receivers_vdlm); - info!("Starting ACARS input servers"); - let acars_input_config: OutputServerConfig = OutputServerConfig::new( - &args.listen_udp_acars, - &args.listen_tcp_acars, - &args.listen_zmq_acars, - &args.receive_tcp_acars, - &args.receive_zmq_acars, - &args.reassembly_window, - ServerType::Acars, - ); - tokio::spawn(async move { - acars_input_config.start_listeners(tx_receivers_acars); - }); - - let vdlm_input_config: OutputServerConfig = OutputServerConfig::new( - &args.listen_udp_vdlm2, - &args.listen_tcp_vdlm2, - &args.listen_zmq_vdlm2, - &args.receive_tcp_vdlm2, - &args.receive_zmq_vdlm2, - &args.reassembly_window, - ServerType::Vdlm2, - ); - tokio::spawn(async move { - vdlm_input_config.start_listeners(tx_receivers_vdlm); - }); - - let hfdl_input_config: OutputServerConfig = OutputServerConfig::new( - &args.listen_udp_hfdl, - &args.listen_tcp_hfdl, - &args.listen_zmq_hfdl, - &args.receive_tcp_hfdl, - &args.receive_zmq_hfdl, - &args.reassembly_window, - ServerType::Hfdl, - ); - - tokio::spawn(async move { - hfdl_input_config.start_listeners(tx_receivers_hfdl); - }); - - // start the output servers - debug!("Starting output servers"); - - info!("Starting ACARS Output Servers"); - let acars_output_config: SenderServerConfig = SenderServerConfig::new( - &args.send_udp_acars, - &args.send_tcp_acars, - &args.serve_tcp_acars, - &args.serve_zmq_acars, - &args.max_udp_packet_size, - ); - - tokio::spawn(async move { - acars_output_config - .start_senders(rx_processed_acars, "ACARS") - .await; - }); - - info!("Starting VDLM Output Servers"); - let vdlm_output_config: SenderServerConfig = SenderServerConfig::new( - &args.send_udp_vdlm2, - &args.send_tcp_vdlm2, - &args.serve_tcp_vdlm2, - &args.serve_zmq_vdlm2, - &args.max_udp_packet_size, - ); - - tokio::spawn(async move { - vdlm_output_config - .start_senders(rx_processed_vdlm, "VDLM") - .await; - }); - - info!("Starting HFDL Output Servers"); - let hfdl_output_config: SenderServerConfig = SenderServerConfig::new( - &args.send_udp_hfdl, - &args.send_tcp_hfdl, - &args.serve_tcp_hfdl, - &args.serve_zmq_hfdl, - &args.max_udp_packet_size, - ); - - tokio::spawn(async move { - hfdl_output_config - .start_senders(rx_processed_hfdl, "HFDL") - .await; - }); - - // Start the message handler tasks. - // Don't start the queue watcher UNLESS there is a valid input source AND output source for the message type - debug!("Starting the message handler tasks"); if args.acars_configured() { + let message_handler_config_acars: MessageHandlerConfig = + MessageHandlerConfig::new(&args, "ACARS"); + + let (tx_receivers_acars, rx_receivers_acars) = mpsc::channel(32); + // Create the input channel processed messages will be sent to + let (tx_processed_acars, rx_processed_acars) = mpsc::channel(32); + + // start the input servers + debug!("Starting input servers"); + // start_listener_servers(&config, tx_receivers_acars, tx_receivers_vdlm); + info!("Starting ACARS input servers"); + let acars_input_config: OutputServerConfig = OutputServerConfig::new( + &args.listen_udp_acars, + &args.listen_tcp_acars, + &args.listen_zmq_acars, + &args.receive_tcp_acars, + &args.receive_zmq_acars, + &args.reassembly_window, + ServerType::Acars, + ); + tokio::spawn(async move { + acars_input_config.start_listeners(tx_receivers_acars); + }); + + info!("Starting ACARS Output Servers"); + let acars_output_config: SenderServerConfig = SenderServerConfig::new( + &args.send_udp_acars, + &args.send_tcp_acars, + &args.serve_tcp_acars, + &args.serve_zmq_acars, + &args.max_udp_packet_size, + ); + + tokio::spawn(async move { + acars_output_config + .start_senders(rx_processed_acars, "ACARS") + .await; + }); tokio::spawn(async move { message_handler_config_acars .watch_message_queue(rx_receivers_acars, tx_processed_acars) @@ -180,6 +101,43 @@ pub async fn start_processes(args: Input) { } if args.vdlm_configured() { + let message_handler_config_vdlm: MessageHandlerConfig = + MessageHandlerConfig::new(&args, "VDLM"); + + // VDLM + // Create the input channel all receivers will send their data to. + let (tx_receivers_vdlm, rx_receivers_vdlm) = mpsc::channel(32); + // Create the input channel processed messages will be sent to + let (tx_processed_vdlm, rx_processed_vdlm) = mpsc::channel(32); + + let vdlm_input_config: OutputServerConfig = OutputServerConfig::new( + &args.listen_udp_vdlm2, + &args.listen_tcp_vdlm2, + &args.listen_zmq_vdlm2, + &args.receive_tcp_vdlm2, + &args.receive_zmq_vdlm2, + &args.reassembly_window, + ServerType::Vdlm2, + ); + tokio::spawn(async move { + vdlm_input_config.start_listeners(tx_receivers_vdlm); + }); + + info!("Starting VDLM Output Servers"); + let vdlm_output_config: SenderServerConfig = SenderServerConfig::new( + &args.send_udp_vdlm2, + &args.send_tcp_vdlm2, + &args.serve_tcp_vdlm2, + &args.serve_zmq_vdlm2, + &args.max_udp_packet_size, + ); + + tokio::spawn(async move { + vdlm_output_config + .start_senders(rx_processed_vdlm, "VDLM") + .await; + }); + tokio::spawn(async move { message_handler_config_vdlm .watch_message_queue(rx_receivers_vdlm, tx_processed_vdlm) @@ -192,6 +150,43 @@ pub async fn start_processes(args: Input) { } if args.hfdl_configured() { + let message_handler_config_hfdl: MessageHandlerConfig = + MessageHandlerConfig::new(&args, "HFDL"); + // HFDL + // Create the input channel all receivers will send their data to. + let (tx_receivers_hfdl, rx_receivers_hfdl) = mpsc::channel(32); + // Create the input channel processed messages will be sent to + let (tx_processed_hfdl, rx_processed_hfdl) = mpsc::channel(32); + + let hfdl_input_config: OutputServerConfig = OutputServerConfig::new( + &args.listen_udp_hfdl, + &args.listen_tcp_hfdl, + &args.listen_zmq_hfdl, + &args.receive_tcp_hfdl, + &args.receive_zmq_hfdl, + &args.reassembly_window, + ServerType::Hfdl, + ); + + tokio::spawn(async move { + hfdl_input_config.start_listeners(tx_receivers_hfdl); + }); + + info!("Starting HFDL Output Servers"); + let hfdl_output_config: SenderServerConfig = SenderServerConfig::new( + &args.send_udp_hfdl, + &args.send_tcp_hfdl, + &args.serve_tcp_hfdl, + &args.serve_zmq_hfdl, + &args.max_udp_packet_size, + ); + + tokio::spawn(async move { + hfdl_output_config + .start_senders(rx_processed_hfdl, "HFDL") + .await; + }); + tokio::spawn(async move { message_handler_config_hfdl .watch_message_queue(rx_receivers_hfdl, tx_processed_hfdl)