Skip to content
kit-tmPublic

About

Implementation of KIRA (Kademlia-directed ID-based Routing Architecture) in Rust

Resources

Stars

2 stars

Watchers

0 watching

Forks

Latest commit

 

History

1,671 Commits

Folders and files

Repository files navigation

KIRA Implementation

This repository collects the different components used for the implementation of the scalable zero-touch routing architecture KIRA in Rust started by Moritz Hepp (2022) at the Institute of Telematics at KIT. This implementation supplies a routing daemon that provides IPv6 connectivity without configuration as well as a distributed hash table that can be used to provide a simple key-value store to map names to IPv6 addresses. The IPv6 addresses are currently randomly generated from the ULA address realm and are as such not routable on the Internet. As KIRA is designed to be a routing solution for control planes it deliberately uses ULAs for now (they are not routable on the Internet).

Implementation Status

This implementation is in version 0.1.0 and therefore is still work-in-progress in many parts.

For a working example see DNS-DHT-Example.

Repo Structure

  • KIRA Routing Daemon: Contains the crate representing the routing daemon executable.
  • Sans-I/O R²/KAD: Contains the implementation of the routing protocol of KIRA, R²/KAD.
  • KIRA Library: Contains the different abstract modules, classes, traits to implement a complete routing daemon. Crucially this provides the i/o implementation of R²/KAD.
  • KIRA Forwarding: Contains the traits and implementations of the fast forwarding layer of KIRA.
  • KeLLy: Contains kellyd, the KeLLy link-layer topology discovery running next to kirad.
  • Examples: Contains minimal examples of running KIRA in an emulated network using Containernet.

More specific information can be found in the respective folders and in the following chapters.

Documentation

The KIRA routing daemon is primarily implemented in Rust, leveraging the language's documentation capabilities through rustdoc. To generate and view the documentation for the respective packages, run:

make doc

Fast Forwarding

Data packets are forwarded along paths identified by PathIDs (see section 3.10 of the KIRA draft). The encapsulation carrying the PathIDs is selected with --forwarding (or KIRA_FORWARDING). It has to be the same on all nodes of a network, as the modes also differ in how a path to a contact is split into path segments, each with its own PathID:

Mode Path segments Encapsulation PathID handling Overhead
gre (default) one GRE header nftables 44 bytes
srv6 up to two outer IPv6 header and, for two segments, a Reduced Segment Routing Header (RFC 8754) eBPF program at TC ingress 40 bytes, 64 bytes with two segments
  • One segment: the whole path has a single PathID. Paths of more than three hops require an explicit path setup in all nodes that are more than two hops away from the end of the path.
  • Two segments (as specified in the draft): paths of up to three hops consist of one segment, longer paths get a second segment of two hops (paths of four and five hops) or three hops (longer paths). Only paths of six or more hops require an explicit path setup, and only in some of the nodes on the path.

The forwarding state installed by a path setup is soft state that is refreshed by the periodic path probing. (GRE can't carry a second PathID with the tunnel devices of the Linux kernel, which refuse to nest the encapsulation.)

SRv6

The srv6 mode is only available if kirad is built with the srv6 feature:

cargo build --release --features srv6

Intermediate nodes replace the PathID in the destination address of the outer header, which regular SRv6 endpoints don't do. This is done by an eBPF program (kira-forwarding-ebpf) that is embedded into kirad and attached to the ingress of all interfaces managed by it.

Building it additionally requires:

  • a nightly toolchain with the rust-src component: rustup toolchain install nightly --component rust-src
  • bpf-linker

Running it requires:

  • Linux >= 6.0 with CONFIG_IPV6_SEG6_LWTUNNEL and CONFIG_BPF_SYSCALL
  • CAP_NET_ADMIN and CAP_BPF (or root)
  • interfaces with Ethernet framing

The state of the eBPF program can be inspected with bpftool net show and bpftool map dump name PATH_TABLE.

Key-Based Routing

Besides NodeIPs (--node-ip-prefix, default fc00::/16), which are routed exactly to the node with the NodeId, kirad routes KeyIPs (--key-ip-prefix, default fcbb::/16): a packet to fcbb::/16 + a 112-bit key is delivered to the node owning the key, i.e., the node whose NodeId is closest to the key by the XOR metric, as in KIRA's overlay routing and DHT. A packet to the NodeIP of a non-existing node is dropped instead.

Each node derives prefix routes for the KeyIPs from its routing table: for each depth d, the NodeIds sharing exactly the first d bits with the node form a branch (the bucket d, or a subtree of the last bucket's range). Each non-empty branch is routed to one contact in it, which is closer to all keys of the branch, and the keys left after the deepest non-empty branch get local routes, so that sockets bound to :: receive them. Compared to routes to the owners of the keys, packets take about one more overlay hop on average, but the number of routes doesn't depend on the bucket size. Keys of empty branches are routed like the keys of the other half (the routes are mirrored). Nodes need about 20–30 routes on average and up to about 150 for 99 % of the nodes; only nodes whose NodeIds share unusually long prefixes would need more than 4096 mirrored routes and drop some keys instead (see the documentation of kira_r2kad::domain::key_routing). The routes use the same encapsulation as the routes to the contacts.

Key-based routing is enabled by default. --no-key-routing (KIRA_NO_KEY_ROUTING=true) installs no key routes: the node then drops packets to KeyIPs, also those passing through, so it has to be set on all nodes or none. KeLLy (kellyd) needs it on all nodes and exits on a node without it; kiratest ignores --no-key-routing together with --kellyd.

Control Interface

kirad serves a local control interface on a Unix domain socket (--control-socket, default /run/kirad/kirad.sock; --no-control-socket to disable it). It uses one JSON object per line, e.g.:

echo '{"request":"routing_table"}' | socat - UNIX-CONNECT:/run/kirad/kirad.sock

Requests are node_info, routing_table (buckets with their ID ranges and contacts with paths), underlay_neighbors (with the node's state sequence number), key_route ("key": "<hex>") and subscribe, which streams notifications about changed contacts and underlay neighbors. See kira_r2kad::domain::control for the message definitions.

Cloning the repository

To simply clone the repository use this:

git clone git@gitlab.kit.edu:kit/tm/telematics/kira/kira-rust.git

Tasks

Task Command Description
Build make build, cargo build Compiles the daemon with creates an executable
Build (release) make build-release, cargo build --release Compiles the daemon with release profile and creates an executable1
Build (docker) make build-images Compiles and builds provided docker images (no Rust install required)
Code Documentation make doc Generates and views the documentation of all Rust packages
Install Daemon make install Compiles the daemon with release profile and installs it system-wide
Uninstall Daemon make uninstall Removes the daemon installation from the system
Debian Package make pkg-debian-<TARGET> Build a Debian package for the target architecture2 (targets: x86_64, aarch64)

Dependencies

  • Rust: Build the daemon and documentation from source (not required for building the container images), a full Rust toolchain is recommended.
  • Docker: Run examples, build container images, cross compile Debian packages.
  • m4: Install daemon, build Debian packages.
  • dpkg-shlibdeps: Build Debian packages.

Running on physical hosts

To run the task on a physical host we recommend using the provided systemd-service files.

Installation

  1. make build-release: Build the release version of kirad
  2. sudo make install: install the daemon and its files to the system

If you're on a Debian-based system (dpkg), you can also build and install the Debian package of your architecture (example on x86_64):

make pkg-debian-x86_64
sudo apt-get install target/x86_64-unknown-linux-musl/debian/kirad_0.1.0-1_amd64.deb

Manage All Interfaces

systemctl enable --now kirad.service

Manage Some Interfaces

Currently, you can only blacklist interfaces using the kirad@.service by using the numbers of the interfaces:

systemctl enable --now kirad@$(systemd-escape 4,2).service

This will exclude the interface 4 and 2 interface from being managed by the routing daemon. You can obtain a list of all your interfaces by running ip link.

Message Statistics

To measure the overhead of KIRA, kirad counts the sent and received R²/KAD messages and their bytes per message type and writes them as JSON on shutdown (SIGTERM/SIGINT):

kirad --benchmark-path stats.json --stats-interval 10   # or BENCH_PATH=… STATS_INTERVAL=…
  • stats.json: totals and per message type (per_kind) the messages, the UDP payload bytes and the bytes on the wire (incl. 48 B of IPv6/UDP headers), each also as average per second. A message sent to several interfaces is counted once per interface.
  • stats.json.jsonl (only with --stats-interval N, N > 0): a snapshot of the cumulative counters every N seconds, one JSON object per line, for rates over time. It survives a SIGKILL, which prevents writing stats.json.

In the emulation of kira-test, set KIRA_STATS_DIR to get a file per node and sum them up afterwards:

KIRA_STATS_DIR=stats STATS_INTERVAL=5 KIRA_TOPOS="tests/topos/minimal.gml" uv --project=tests/kira-test run pytest
uv --project=tests/kira-test run python -m kira_emu.stats stats [--json]

Development

You should install the following additional dependencies for development:

  • pre-commit: Catch invalid commits that would be flagged later by GitLab's CI.
  • Clippy: Catch common mistakes in Rust code.
  • Nightly rustfmt: make sure your Rust code conforms the set style guide.
  • rust-analyzer: Language server for your favorite IDE (optional).
  • Userspace utilities of nftables: [kira-test] uses the nft utility to query to current state of the forwarding tier; Generally handy for debugging the forwarding tier.
  • bpftool: the counterpart for the SRv6 forwarding, used by [kira-test] if KIRA_FORWARDING=srv6 is set.

If you want to contribute to the Python-based emulation with network namespaces at kira-test, you should additionally install the used project manager uv.

Testing

You should test your changes before submitting any changes. Write Rust unit tests and run them using:

cargo test --workspace

Additionally, you can test the kirad in network emulation scenarios interactively using the kiratest REPL or run automatic tests on the provided topology:

uv --project=./tests/kira-test run kiratest tests/topos/minimal.gml
KIRA_TOPOS="tests/topos/minimal.gml" uv --project=tests/kira-test run pytest

Since the size of the emulated topologies is rather small, you should probably build kirad with the small_buckets feature to store less contacts per bucket of the routing table. Pytest is doing this automatically but for kiratest you have to build a binary manually:

cargo build --features=small_buckets

More information on the Python-based emulation can be found at kira-test.

Footnotes

  1. The executable can be found at target/release/kirad ↩

  2. <TARGET>-unknown-linux-musl, cross compilation is done using cargo-cross and requires Docker or Podman. ↩

About

Implementation of KIRA (Kademlia-directed ID-based Routing Architecture) in Rust

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages