Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
32 changes: 32 additions & 0 deletions Cargo.lock

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

7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

members = [
"acl",
"acl-filter",
"args",
"cli",
"common",
Expand Down Expand Up @@ -66,6 +67,7 @@ repository = "https://github.com/githedgehog/dataplane/"

# Internal
acl = { path = "./acl", package = "dataplane-acl", features = [] }
acl-filter = { path = "./acl-filter", package = "dataplane-acl-filter", features = [] }
args = { path = "./args", package = "dataplane-args", features = [] }
cli = { path = "./cli", package = "dataplane-cli", features = [] }
common = { path = "./common", package = "dataplane-common", features = [] }
Expand Down Expand Up @@ -273,6 +275,11 @@ package = "dataplane-acl"
miri = false # hopeless + pointless
wasm = false # hopeless + pointless

[workspace.metadata.package.acl-filter]
package = "dataplane-acl-filter"
miri = false # hopeless + pointless
wasm = false # hopeless + pointless

[workspace.metadata.package.args]
package = "dataplane-args"
miri = true
Expand Down
37 changes: 37 additions & 0 deletions acl-filter/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[package]
name = "dataplane-acl-filter"
edition.workspace = true
license.workspace = true
publish.workspace = true
version.workspace = true

[dependencies]
acl = { workspace = true }
common = { workspace = true }
concurrency = { workspace = true }
config = { workspace = true }
dpdk = { workspace = true }
indenter = { workspace = true }
linkme = { workspace = true }
lookup = { workspace = true }
lpm = { workspace = true }
match-action = { workspace = true, features = ["derive"] }
net = { workspace = true }
pipeline = { workspace = true }
tracectl = { workspace = true }
tracing = { workspace = true }

[dev-dependencies]
# The reference (linear-scan) ACL backend is the differential-test oracle and drives the fast,
# EAL-free semantic suite. It is `cfg(test)`-gated in the source, so it is never part of a
# production build; this dev-dep just makes `acl::reference` available to test builds.
acl = { workspace = true, features = ["reference"] }
config = { workspace = true, features = ["testing"] }
dpdk = { workspace = true, features = ["test"] }
flow-entry = { workspace = true }
flow-filter = { workspace = true }
lpm = { workspace = true, features = ["testing"] }
nat = { workspace = true }
net = { workspace = true, features = ["builder"] }
tokio = { workspace = true, features = ["macros", "rt", "time"] }
tracing-test = { workspace = true, features = [] }
106 changes: 106 additions & 0 deletions acl-filter/src/access.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Open Network Fabric Authors

//! Read and write handles for the ACL filter context.

use crate::context::{AclTables, PRODUCTION_BACKEND};
use concurrency::slot::Slot;
use concurrency::sync::Arc;
use config::ConfigError;
use config::external::overlay::ValidatedOverlay;

#[derive(Debug, Default)]
pub struct AclFilterContext {
pub(super) acls: AclTables,
}

impl TryFrom<&ValidatedOverlay> for AclFilterContext {
type Error = ConfigError;

fn try_from(overlay: &ValidatedOverlay) -> Result<Self, Self::Error> {
let acls = AclTables::build(overlay, PRODUCTION_BACKEND)?;
Ok(Self { acls })
}
}

#[cfg(test)]
impl AclFilterContext {
/// Build a context using the reference backend, for tests that want the fast, EAL-free oracle.
/// Production goes through [`TryFrom`], which uses the rte_acl backend.
pub(crate) fn for_test(overlay: &ValidatedOverlay) -> Self {
use crate::context::Backend;
let acls = AclTables::build(overlay, Backend::Reference)
.expect("reference backend build is infallible");
Self { acls }
}

/// Build a context using the rte_acl backend, for the differential test that exercises the
/// production classifier. Requires the EAL to be initialized (`#[dpdk::with_eal]`).
pub(crate) fn for_test_dpdk(overlay: &ValidatedOverlay) -> Result<Self, ConfigError> {
use crate::context::Backend;
let acls = AclTables::build(overlay, Backend::Dpdk)?;
Ok(Self { acls })
}
}

/// Control-plane handle used to hot-swap the context.
#[derive(Debug, Clone)]
pub struct AclFilterContextWriter(Arc<Slot<AclFilterContext>>);

impl Default for AclFilterContextWriter {
fn default() -> Self {
Self(Arc::new(Slot::from_pointee(AclFilterContext::default())))
}
}

impl AclFilterContextWriter {
/// Create a new handle with a default context.
#[must_use]
pub fn new() -> Self {
Self::default()
}

/// Atomically publish a new context on reconfiguration.
pub fn store(&self, context: AclFilterContext) {
self.0.store(Arc::new(context));
}

/// Obtain a reader for the context.
#[must_use]
pub fn get_reader(&self) -> AclFilterContextReader {
AclFilterContextReader(Arc::clone(&self.0))
}

/// Obtain a reader factory for the context.
#[must_use]
pub fn get_reader_factory(&self) -> AclFilterContextReaderFactory {
AclFilterContextReaderFactory(self.get_reader())
}
}

#[derive(Debug, Clone)]
pub struct AclFilterContextReader(Arc<Slot<AclFilterContext>>);

impl AclFilterContextReader {
/// Load the current context for read-only access.
#[must_use]
pub fn load(&self) -> Arc<AclFilterContext> {
// FIXME: We'd like to use self.0.load() instead of .load_full() (saves the cost of the
// atomic counter update, although x86_64 shouldn't be affected), but if we do, then the
// loom and shuttle back-ends expect a different return type for the method
// (arc_swap::Guard<Arc<AclFilterContext>>). We need to create a wrapper around that type in
// the concurrency crate.
self.0.load_full()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why load_full() and not load() ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I couldn't get it to compile with load() for all of the standard case, loom, and shuttle otherwise. I used load_full() like we use in masquerade for the allocator. I can look a bit more into it, do you know what the right solution would be instead?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Fredi-raspall The alternative I have consists in introducing dedicated features for the crate:

diff --git i/Cargo.lock w/Cargo.lock
index 66dc60c5e598..d49acb88cfc8 100644
--- i/Cargo.lock
+++ w/Cargo.lock
@@ -1241,6 +1241,7 @@ dependencies = [
 name = "dataplane-acl-filter"
 version = "0.22.0"
 dependencies = [
+ "arc-swap",
  "dataplane-acl",
  "dataplane-common",
  "dataplane-concurrency",
diff --git i/acl-filter/Cargo.toml w/acl-filter/Cargo.toml
index ce11065fc465..e60b6fb3c6eb 100644
--- i/acl-filter/Cargo.toml
+++ w/acl-filter/Cargo.toml
@@ -5,8 +5,14 @@ license.workspace = true
 publish.workspace = true
 version.workspace = true
 
+[features]
+loom = ["concurrency/loom"]
+shuttle = ["concurrency/shuttle"]
+shuttle_dfs = ["concurrency/shuttle_dfs", "shuttle"]
+
 [dependencies]
 acl = { workspace = true }
+arc-swap = { workspace = true }
 common = { workspace = true }
 concurrency = { workspace = true }
 config = { workspace = true }
diff --git i/acl-filter/src/access.rs w/acl-filter/src/access.rs
index 0667dda7961a..5c1eb1fd954d 100644
--- i/acl-filter/src/access.rs
+++ w/acl-filter/src/access.rs
@@ -83,9 +83,17 @@ pub struct AclFilterContextReader(Arc<Slot<AclFilterContext>>);
 
 impl AclFilterContextReader {
     /// Load the current context for read-only access.
+    #[cfg(not(any(feature = "loom", feature = "shuttle")))]
+    #[must_use]
+    pub fn load(&self) -> arc_swap::Guard<Arc<AclFilterContext>> {
+        self.0.load()
+    }
+
+    /// Load the current context for read-only access (loom/shuttle).
+    #[cfg(any(feature = "loom", feature = "shuttle"))]
     #[must_use]
     pub fn load(&self) -> Arc<AclFilterContext> {
-        self.0.load_full()
+        self.0.load()
     }
 }
 

If you think it's worth it, I can change.

@daniel-noland or do you know if we have a wrapper for this already? Introducing new crate features just to accommodate for the return type doesn't look optimal, maybe I'm missing something simpler?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed in meeting (without Fredi): Let's keep as it is for now, the perf delta isn't worth troubling ourselves with the new crate features. I added a FIXME: comment in the code to explain that, at some point, we should add a wrapper around the type in the concurrency crate, so we can use .load().

}
}

#[derive(Debug, Clone)]
pub struct AclFilterContextReaderFactory(AclFilterContextReader);

impl AclFilterContextReaderFactory {
/// Obtain a reader from the factory.
#[must_use]
pub fn handle(&self) -> AclFilterContextReader {
self.0.clone()
}
}
Loading
Loading