Crate rapimt

Crate rapimt 

Source
Expand description

§Rapimt

Rapimt implements the Flash inverse model transformation pipeline (see docs/flash-sigcomm22.pdf) entirely in Rust. The crate that you depend on (rapimt) is a lightweight facade over a set of internal crates that cover predicate engines, inverse model arithmetic, device IO, and pluggable verification logic.

§Workspace layout

  • rapimt::core — header-space encoders, predicate engines (Ruddy and Oxidd), match macros, and forwarding action traits.
  • rapimt::im — inverse model data structures plus rule monitors such as FastRuleMonitor.
  • rapimt::io — parsers and loaders (default router format and InfiniBand snapshots).
  • rapimt::ver — graph-based verification drivers and plugins.
  • rapimt::prelude — re-exports of the symbols most developers reach for (use rapimt::prelude::*;).

§Typical workflow

  1. Pick a PredicateEngine (Ruddy for fast single-threaded prototyping, Oxidd for multi-threaded production runs) and enable the feature flags for the header fields you care about (dip, sip, sport, …).
  2. Load topology information with an InstanceLoader or your own device specific loader and obtain an ActionEncoder.
  3. Parse the device FIB into Rule objects via FibLoader.
  4. Feed incremental changes into a RuleMonitor (e.g. FastRuleMonitor) to generate per-device inverse models.
  5. Resize and merge device models into a network-wide InverseModel, then dispatch verification plugins.
use rapimt::core::prelude::{SeqAction, RuddyPredicateEngine};
use rapimt::io::prelude::{InstanceLoader, DefaultInstLoader, FibLoader, PortInfoBase};
use rapimt::im::prelude::{RuleMonitorLike, FastRuleMonitor, InverseModel, MapInverseModel, TPTRuleStore};

fn demo() -> Result<(), Box<dyn std::error::Error>> {
  let engine = RuddyPredicateEngine::init(10_000, 1_000);
  let loader = DefaultInstLoader::default();

  // Load the action encoder for a device.
  let spec = std::fs::read_to_string("specs/dev0.spec")?;
  let codex: PortInfoBase = loader.load(&spec).unwrap();

  // Parse the FIB and insert rules into a monitor.
  let fib = std::fs::read_to_string("fibs/dev0.fib")?;
  let (_, rules) = codex.load(&engine, &fib).unwrap();
  let mut monitor: FastRuleMonitor<_, _, TPTRuleStore<_, _>> =
      FastRuleMonitor::new(&engine);
  let update: MapInverseModel<SeqAction<usize>, _, _> = monitor.insert(rules);
  assert!(update.property_check());

  // Resize/merge updates for a multi-device network.
  let mut net: MapInverseModel<SeqAction<usize>, _, _> = InverseModel::default();
  net <<= InverseModel::resize(update, /*num_devices*/ 1, /*offset*/ 0);
  Ok(())
}

For a longer, end-to-end walkthrough read docs/development.md.

§Feature flags

The crate documentation includes an auto-generated table of all feature flags via document_features::document_features!().

  • dip (enabled by default) — Support encoding 32-bit destination IPv4 addresses
  • sip — Support encoding 32-bit source IPv4 addresses
  • dport — Support encoding 16-bit destination port numbers
  • sport — Support encoding 16-bit source port numbers
  • tag — Support encoding 16-bit VLAN tags
  • lid — Support encoding 16-bit InfiniBand lid
  • arc — Use Arc instead of Rc for shared objects

Modules§

core
Public re-exported. Action encoding and decoding, and match encoding.
im
Public re-exported. InverseModel operations and generations.
io
Public re-exported. Parse topology and rules from diverse sources.
prelude
Public re-exported. use rapimt::prelude::*; to import common structs, traits, etc.
tpt
Public re-exported. Ternary Patricia Tree (TPT) implementation for Rule monitor to insert, remove, lookup rules. (Only helpful for prefix matching)
ver
Public re-exported. Verification traits and implementations.