Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,80 @@ jobs:
path: target/${{ matrix.target }}/release/${{ steps.binary_filename.outputs.name }}
retention-days: 30

# Build yang-consumer binary
#
# Windows and x86_64-apple-darwin are intentionally omitted: yang5/rdkafka
# don't build on Windows yet, and yang5 links system libpcre2 which can't be
# cross-compiled from arm64 macos-latest.
build-yang-consumer-bin:
runs-on: ${{ matrix.os }}
container: ${{ matrix.container }}
needs: version
name: Build yang-consumer binary (${{ matrix.dist_and_arch }})
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
binary_name: netcalyx-yang-consumer
strip_command: true
smoke_test: true
install_deps: |
sudo apt-get update
sudo apt-get install -y cmake perl gcc g++ libpcre2-dev libcurl4-openssl-dev
dist_and_arch: x86_64-ubuntu_latest # used just for naming the binary
- os: ubuntu-latest
container: rockylinux/rockylinux:8.10
target: x86_64-unknown-linux-gnu
binary_name: netcalyx-yang-consumer
strip_command: true
smoke_test: true
install_deps: |
dnf install -y gcc gcc-c++ pcre2-devel perl-core cmake git curl libcurl-devel
dist_and_arch: x86_64-el8_10 # used just for naming the binary
- os: macos-latest
target: aarch64-apple-darwin
binary_name: netcalyx-yang-consumer
strip_command: true
smoke_test: true
dist_and_arch: aarch64-apple-latest # used just for naming the binary
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0 # needs full git history so shadow-rs embeds tag/commit info
- name: Install build dependencies
if: matrix.install_deps
run: ${{ matrix.install_deps }}
- name: Install stable Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
- name: Build yang-consumer
run: |
if [ "$RUNNER_OS" = "macOS" ]; then
export C_INCLUDE_PATH="$C_INCLUDE_PATH:$HOMEBREW_PREFIX/include"
fi
cargo build --locked --release --target ${{ matrix.target }} -p netcalyx-yang-consumer
- name: Smoke test (run --help)
if: matrix.smoke_test == 'true'
run: ./target/${{ matrix.target }}/release/${{ matrix.binary_name }} --help
- name: Strip binary
if: matrix.strip_command == 'true'
run: strip target/${{ matrix.target }}/release/${{ matrix.binary_name }}
- name: Create complete binary file name
id: binary_filename
run: echo "name=netcalyx-yang-consumer-${{ needs.version.outputs.version }}-${{ needs.version.outputs.release }}-${{ matrix.dist_and_arch }}" >> "$GITHUB_OUTPUT"
- name: Rename binary
run: mv "target/${{ matrix.target }}/release/${{ matrix.binary_name }}" "target/${{ matrix.target }}/release/${{ steps.binary_filename.outputs.name }}"
- name: Upload yang-consumer artifact
uses: actions/upload-artifact@v7
with:
name: ${{ steps.binary_filename.outputs.name }}
path: target/${{ matrix.target }}/release/${{ steps.binary_filename.outputs.name }}
retention-days: 30

commitlint:
runs-on: ubuntu-latest
steps:
Expand Down
21 changes: 20 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ members = [
"crates/udp-notif-service",
"crates/collector",
"crates/yang-push",
"crates/yang-consumer",
"crates/pcap-decoder",
"crates/netconf-proto",
"fuzz",
Expand All @@ -40,6 +41,7 @@ netcalyx-udp-notif-pkt = { version = "0.2.0", path = "crates/udp-notif-pkt" }
netcalyx-udp-notif-service = { version = "0.2.0", path = "crates/udp-notif-service" }
netcalyx-analytics = { version = "0.2.0", path = "crates/analytics" }
netcalyx-yang-push = { version = "0.2.0", path = "crates/yang-push" }
netcalyx-yang-consumer = { version = "0.2.0", path = "crates/yang-consumer" }
netcalyx-pcap-decoder = { version = "0.2.0", path = "crates/pcap-decoder" }
netcalyx-netconf-proto = { version = "0.2.0", path = "crates/netconf-proto" }
thiserror = "2.0"
Expand Down
1 change: 0 additions & 1 deletion crates/collector/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ chrono = { workspace = true, default-features = false, features = [
"clock",
] }
tempfile = { workspace = true }
yang5 = { workspace = true }
tracing-test = { workspace = true }

[features]
Expand Down
59 changes: 33 additions & 26 deletions crates/collector/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright (C) 2026-present The NetCalyx Authors.
// Copyright (C) 2024-present The NetGauze Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -204,6 +205,30 @@ fn init_open_telemetry(
Ok(())
}

/// Builds the multi-line version/build info string
fn version_info() -> &'static str {
Box::leak(
format!(
"{}\n \
Commit: {} ({})\n \
Branch/Tag: {} / {}\n \
Build Time: {}\n \
Rust: {} ({})\n \
OS: {}",
build::PKG_VERSION,
build::COMMIT_HASH,
build::COMMIT_DATE,
build::BRANCH,
build::TAG,
build::BUILD_TIME,
build::RUST_VERSION,
build::BUILD_RUST_CHANNEL,
build::BUILD_OS,
)
.into_boxed_str(),
)
}

/// NetCalyx network metrics collector CLI arguments
#[derive(clap::Parser, Debug)]
#[command(
Expand All @@ -212,41 +237,23 @@ fn init_open_telemetry(
NetCalyx network telemetry collector.

Log level can also be overridden via the RUST_LOG environment variable:
RUST_LOG=netcalyx_collector=trace netcalyx-collector config.yaml"

RUST_LOG=netcalyx_collector=trace netcalyx-collector config.yaml",
disable_version_flag = true,
version = version_info()
)]
struct Args {
/// Path to the YAML config file
#[arg(required_unless_present = "version")]
config_file: Option<PathBuf>,
config_file: PathBuf,

/// Print version and build information, then exit
#[arg(long, short = 'v', action = clap::ArgAction::SetTrue)]
version: bool,
#[arg(long, short = 'V', action = clap::ArgAction::Version)]
version: Option<bool>,
}

fn main() -> anyhow::Result<()> {
let args = Args::parse();
if args.version {
println!("NetCalyx Collector");
println!(" Version: {}", build::PKG_VERSION);
println!(
" Commit: {} ({})",
build::COMMIT_HASH,
build::COMMIT_DATE
);
println!(" Branch/Tag: {} / {}", build::BRANCH, build::TAG);
println!(" Build Time: {}", build::BUILD_TIME);
println!(
" Rust: {} ({})",
build::RUST_VERSION,
build::BUILD_RUST_CHANNEL
);
println!(" OS: {}", build::BUILD_OS);
std::process::exit(0);
}

// Safe to unwrap: clap guarantees config_file is Some when --version is absent
let config_file = args.config_file.unwrap();
let config_file = args.config_file;
let file = File::open(&config_file)?;
let reader = BufReader::new(file);
let config: CollectorConfig = match from_reader(reader) {
Expand Down
5 changes: 5 additions & 0 deletions crates/pcap-decoder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ CLI Utility to convert NetFlow, IPFIX, BGP, BMP or UDP-Nofif data from a PCAP fi
"""
keywords = ["pcap", "parser", "decoder", "protocol"]
categories = ["network-programming", "parsing"]
build = "build.rs"

[dependencies]
netcalyx-flow-pkt = { workspace = true, features = ["codec"] }
Expand All @@ -28,6 +29,10 @@ pcap-parser = { workspace = true, features = ["data"] }
bytes = { workspace = true }
tokio-util = { workspace = true, default-features = false, features = ["codec"] }
clap = { workspace = true, features = ["default", "derive"] }
shadow-rs = { workspace = true, features = ["default", "metadata", "build"] }

[build-dependencies]
shadow-rs = { workspace = true, default-features = true }

[dev-dependencies]
chrono = { workspace = true, default-features = false, features = [
Expand Down
23 changes: 23 additions & 0 deletions crates/pcap-decoder/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (C) 2026-present The NetCalyx Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
// implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use shadow_rs::ShadowBuilder;

fn main() {
ShadowBuilder::builder()
.deny_const(Default::default())
.build()
.unwrap();
}
39 changes: 38 additions & 1 deletion crates/pcap-decoder/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright (C) 2026-present The NetCalyx Authors.
// Copyright (C) 2025-present The NetGauze Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -18,8 +19,35 @@ use netcalyx_pcap_decoder::{
BgpProtocolHandler, BmpProtocolHandler, Config, FlowProtocolHandler, UdpNotifProtocolHandler,
load_pcap_and_process,
};
use shadow_rs::shadow;
use std::path::PathBuf;

shadow!(build);

/// Builds the multi-line version/build info string shown
fn version_info() -> &'static str {
Box::leak(
format!(
"{}\n \
Commit: {} ({})\n \
Branch/Tag: {} / {}\n \
Build Time: {}\n \
Rust: {} ({})\n \
OS: {}",
build::PKG_VERSION,
build::COMMIT_HASH,
build::COMMIT_DATE,
build::BRANCH,
build::TAG,
build::BUILD_TIME,
build::RUST_VERSION,
build::BUILD_RUST_CHANNEL,
build::BUILD_OS,
)
.into_boxed_str(),
)
}

#[derive(Debug, Clone, ValueEnum)]
pub enum ProtocolToDecode {
BGP,
Expand All @@ -29,7 +57,12 @@ pub enum ProtocolToDecode {
}

#[derive(Debug, Parser)]
#[command(long_about = None)]
#[command(
about,
long_about = None,
disable_version_flag = true,
version = version_info()
)]
struct Cli {
/// Input PCAP file path
#[clap(short, long)]
Expand Down Expand Up @@ -57,6 +90,10 @@ struct Cli {
/// Include the PCAP frame number alongside each JSON output entry
#[clap(long, default_value_t = false)]
show_frame_number: bool,

/// Print version and build information, then exit
#[arg(long, short = 'V', action = clap::ArgAction::Version)]
version: Option<bool>,
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
Expand Down
39 changes: 39 additions & 0 deletions crates/yang-consumer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
lints.workspace = true

[package]
name = "netcalyx-yang-consumer"
version = "0.2.0"
edition = "2024"
authors = ["NetCalyx Authors"]
license = "Apache-2.0"
readme = "README.md"
repository = "https://github.com/network-analytics/NetCalyx"
homepage = "https://github.com/network-analytics/NetCalyx"
description = """
CLI utility to consume YANG-encoded telemetry messages from Kafka and validate them against YANG schemas from a Schema Registry.
"""
keywords = ["yang", "kafka", "telemetry", "schema-registry", "validation"]
categories = ["network-programming", "command-line-utilities"]
build = "build.rs"

[dependencies]
netcalyx-netconf-proto = { workspace = true }
netcalyx-yang-push = { workspace = true }
anyhow = { workspace = true }
clap = { workspace = true, features = ["derive"] }
futures-util = { workspace = true }
serde_json = { workspace = true }
tokio = { workspace = true, default-features = false, features = ["net", "io-util", "sync", "time", "rt-multi-thread", "macros", "signal"] }
tracing = { workspace = true }
tracing-subscriber = { workspace = true, features = ["env-filter"] }
shadow-rs = { workspace = true, features = ["default", "metadata", "build"] }
yang5 = { workspace = true }
schema-registry-client = { workspace = true }
rdkafka = { workspace = true, features = [
"tokio",
"cmake-build",
"ssl-vendored",
] }

[build-dependencies]
shadow-rs = { workspace = true, default-features = true }
File renamed without changes.
Loading
Loading