Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement vsock link support #811

Merged
merged 1 commit into from
Mar 19, 2024
Merged
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
44 changes: 44 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ members = [
"io/zenoh-links/zenoh-link-unixsock_stream/",
"io/zenoh-links/zenoh-link-ws/",
"io/zenoh-links/zenoh-link-unixpipe/",
"io/zenoh-links/zenoh-link-vsock/",
"io/zenoh-transport",
"plugins/zenoh-backend-example",
"plugins/zenoh-plugin-example",
Expand Down Expand Up @@ -151,6 +152,7 @@ tokio = { version = "1.35.1", default-features = false } # Default features are
tokio-util = "0.7.10"
tokio-tungstenite = "0.21"
tokio-rustls = "0.25.0"
# tokio-vsock = see: io/zenoh-links/zenoh-link-vsock/Cargo.toml (workspaces does not support platform dependent dependencies)
console-subscriber = "0.2"
typenum = "1.16.0"
uhlc = { version = "0.6.0", default-features = false } # Default features are disabled due to usage in no_std crates
Expand Down Expand Up @@ -190,6 +192,7 @@ zenoh-link-udp = { version = "0.11.0-dev", path = "io/zenoh-links/zenoh-link-udp
zenoh-link-ws = { version = "0.11.0-dev", path = "io/zenoh-links/zenoh-link-ws" }
zenoh-link-unixpipe = { version = "0.11.0-dev", path = "io/zenoh-links/zenoh-link-unixpipe" }
zenoh-link-serial = { version = "0.11.0-dev", path = "io/zenoh-links/zenoh-link-serial" }
zenoh-link-vsock = { version = "0.11.0-dev", path = "io/zenoh-links/zenoh-link-vsock" }
zenoh-link = { version = "0.11.0-dev", path = "io/zenoh-link" }
zenoh-link-commons = { version = "0.11.0-dev", path = "io/zenoh-link-commons" }
zenoh = { version = "0.11.0-dev", path = "zenoh", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion DEFAULT_CONFIG.json5
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@
link: {
/// An optional whitelist of protocols to be used for accepting and opening sessions.
/// If not configured, all the supported protocols are automatically whitelisted.
/// The supported protocols are: ["tcp" , "udp", "tls", "quic", "ws", "unixsock-stream"]
/// The supported protocols are: ["tcp" , "udp", "tls", "quic", "ws", "unixsock-stream", "vsock"]
/// For example, to only enable "tls" and "quic":
// protocols: ["tls", "quic"],
/// Configure the zenoh TX parameters of a link
Expand Down
2 changes: 2 additions & 0 deletions io/zenoh-link/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ transport_unixsock-stream = ["zenoh-link-unixsock_stream"]
transport_ws = ["zenoh-link-ws"]
transport_serial = ["zenoh-link-serial"]
transport_unixpipe = ["zenoh-link-unixpipe", "zenoh-link-unixpipe/transport_unixpipe"]
transport_vsock = ["zenoh-link-vsock"]

[dependencies]
async-trait = { workspace = true }
Expand All @@ -47,5 +48,6 @@ zenoh-link-udp = { workspace = true, optional = true }
zenoh-link-unixsock_stream = { workspace = true, optional = true }
zenoh-link-ws = { workspace = true, optional = true }
zenoh-link-unixpipe = { workspace = true, optional = true }
zenoh-link-vsock = { workspace = true, optional = true }
zenoh-protocol = { workspace = true }
zenoh-result = { workspace = true }
13 changes: 13 additions & 0 deletions io/zenoh-link/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ use zenoh_link_unixpipe::{
LinkManagerUnicastPipe, UnixPipeConfigurator, UnixPipeLocatorInspector, UNIXPIPE_LOCATOR_PREFIX,
};

#[cfg(all(feature = "transport_vsock", target_os = "linux"))]
pub use zenoh_link_vsock as vsock;
#[cfg(all(feature = "transport_vsock", target_os = "linux"))]
use zenoh_link_vsock::{LinkManagerUnicastVsock, VsockLocatorInspector, VSOCK_LOCATOR_PREFIX};

pub use zenoh_link_commons::*;
pub use zenoh_protocol::core::{EndPoint, Locator};

Expand All @@ -92,6 +97,8 @@ pub const PROTOCOLS: &[&str] = &[
serial::SERIAL_LOCATOR_PREFIX,
#[cfg(feature = "transport_unixpipe")]
unixpipe::UNIXPIPE_LOCATOR_PREFIX,
#[cfg(all(feature = "transport_vsock", target_os = "linux"))]
vsock::VSOCK_LOCATOR_PREFIX,
];

#[derive(Default, Clone)]
Expand All @@ -112,6 +119,8 @@ pub struct LocatorInspector {
serial_inspector: SerialLocatorInspector,
#[cfg(feature = "transport_unixpipe")]
unixpipe_inspector: UnixPipeLocatorInspector,
#[cfg(all(feature = "transport_vsock", target_os = "linux"))]
vsock_inspector: VsockLocatorInspector,
}
impl LocatorInspector {
pub async fn is_multicast(&self, locator: &Locator) -> ZResult<bool> {
Expand All @@ -137,6 +146,8 @@ impl LocatorInspector {
SERIAL_LOCATOR_PREFIX => self.serial_inspector.is_multicast(locator).await,
#[cfg(feature = "transport_unixpipe")]
UNIXPIPE_LOCATOR_PREFIX => self.unixpipe_inspector.is_multicast(locator).await,
#[cfg(all(feature = "transport_vsock", target_os = "linux"))]
VSOCK_LOCATOR_PREFIX => self.vsock_inspector.is_multicast(locator).await,
_ => bail!("Unsupported protocol: {}.", protocol),
}
}
Expand Down Expand Up @@ -226,6 +237,8 @@ impl LinkManagerBuilderUnicast {
UNIXPIPE_LOCATOR_PREFIX => {
Ok(std::sync::Arc::new(LinkManagerUnicastPipe::new(_manager)))
}
#[cfg(all(feature = "transport_vsock", target_os = "linux"))]
VSOCK_LOCATOR_PREFIX => Ok(std::sync::Arc::new(LinkManagerUnicastVsock::new(_manager))),
_ => bail!("Unicast not supported for {} protocol", protocol),
}
}
Expand Down
44 changes: 44 additions & 0 deletions io/zenoh-links/zenoh-link-vsock/Cargo.toml
sashacmc marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#
# Copyright (c) 2024 ZettaScale Technology
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
# which is available at https://www.apache.org/licenses/LICENSE-2.0.
#
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
#
# Contributors:
# ZettaScale Zenoh Team, <[email protected]>
#
[package]
rust-version = { workspace = true }
name = "zenoh-link-vsock"
version = { workspace = true }
repository = { workspace = true }
homepage = { workspace = true }
authors = { workspace = true }
edition = { workspace = true }
license = { workspace = true }
categories = { workspace = true }
description = "Internal crate for zenoh."
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
async-trait = { workspace = true }
tokio = { workspace = true, features = ["net", "io-util", "rt", "time"] }
tokio-util = { workspace = true, features = ["rt"] }
log = { workspace = true }
libc = { workspace = true }
zenoh-core = { workspace = true }
zenoh-link-commons = { workspace = true }
zenoh-protocol = { workspace = true }
zenoh-result = { workspace = true }
zenoh-sync = { workspace = true }
zenoh-util = { workspace = true }
zenoh-runtime = { workspace = true }

# Workspaces does not support platform dependent dependencies, and
# tokio-vsock not compiled on other platforms, so we put it there
[target.'cfg(target_os = "linux")'.dependencies]
tokio-vsock = "0.5.0"
sashacmc marked this conversation as resolved.
Show resolved Hide resolved
54 changes: 54 additions & 0 deletions io/zenoh-links/zenoh-link-vsock/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
// Copyright (c) 2024 ZettaScale Technology
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
//
// Contributors:
// ZettaScale Zenoh Team, <[email protected]>
//

//! ⚠️ WARNING ⚠️
//!
//! This crate is intended for Zenoh's internal use.
//!
//! [Click here for Zenoh's documentation](../zenoh/index.html)
//!
//! Implements [vsock](https://man7.org/linux/man-pages/man7/vsock.7.html) link support.
use async_trait::async_trait;
use zenoh_core::zconfigurable;
use zenoh_link_commons::LocatorInspector;
use zenoh_protocol::core::Locator;
use zenoh_result::ZResult;

#[cfg(target_os = "linux")]
mod unicast;
#[cfg(target_os = "linux")]
pub use unicast::*;

pub const VSOCK_LOCATOR_PREFIX: &str = "vsock";

#[derive(Default, Clone, Copy)]
pub struct VsockLocatorInspector;
#[async_trait]
impl LocatorInspector for VsockLocatorInspector {
fn protocol(&self) -> &str {
VSOCK_LOCATOR_PREFIX
}

async fn is_multicast(&self, _locator: &Locator) -> ZResult<bool> {
Ok(false)
}
}

zconfigurable! {
// Default MTU in bytes.
static ref VSOCK_DEFAULT_MTU: u16 = u16::MAX;
// Amount of time in microseconds to throttle the accept loop upon an error.
// Default set to 100 ms.
static ref VSOCK_ACCEPT_THROTTLE_TIME: u64 = 100_000;
}
Loading