Skip to content

feat: RIB reconstruction with two-table SQLite output#121

Merged
digizeph merged 5 commits intomainfrom
dev/update-rib-docs
Mar 26, 2026
Merged

feat: RIB reconstruction with two-table SQLite output#121
digizeph merged 5 commits intomainfrom
dev/update-rib-docs

Conversation

@digizeph
Copy link
Copy Markdown
Member

@digizeph digizeph commented Mar 24, 2026

Summary

This PR introduces the monocle rib command for reconstructing RIB (Routing Information Base) state at arbitrary timestamps, with a redesigned two-table SQLite output schema.

Commits in this PR

  1. feat: add rib reconstruction command (7b2f888)

    • Initial implementation of RIB reconstruction
    • Selects latest RIB before target timestamp and replays updates
    • Supports stdout output and SQLite export via --sqlite-path
    • Handles multiple timestamp reconstruction with merged SQLite output
  2. fix: infer rib sqlite output from sqlite path (018906c)

    • Fixed SQLite output path inference logic
  3. fix: use positional rib timestamps (b4455ec)

    • Changed RIB timestamp arguments from flag-based to positional
    • Improved CLI ergonomics for specifying target timestamps
  4. perf: keep rib replay state in memory (1903f88)

    • Keep working RIB state in memory during reconstruction
    • Remove SQLite lookups from the replay hot path
    • Narrow reconstructed entries to essential fields
  5. feat: redesign RIB SQLite output with ribs and updates tables (bc922d1)

    • Changed SQLite schema from single elems table to two tables:
      • ribs: final reconstructed RIB states at each target timestamp
      • updates: filtered BGP updates for 2nd and later RIBs only
    • Use Arc<str> for collector and prefix fields (7% speedup)
    • Remove unnecessary per-snapshot O(n log n) sorting
    • Reduce updates query window from +2h lookahead to exact target (33% fewer files)
    • Added StoredRibUpdate struct for tracking filtered updates

Breaking Changes

  • SQLite output schema changed: Previously used single elems table, now uses two tables:
    • ribs table: stores final reconstructed RIB states
    • updates table: stores filtered BGP updates used to build 2nd and later RIB snapshots

New Features

  • Reconstruct RIB state at arbitrary timestamps
  • Filter by origin ASN, country, prefix, AS path, peer ASN, collector, project
  • Full-feed only filtering based on broker peer metadata
  • SQLite export with separate tables for final states and intermediate updates

Schema Details

ribs table

CREATE TABLE ribs (
    rib_ts INTEGER NOT NULL,         -- Target RIB timestamp
    timestamp REAL NOT NULL,         -- Actual BGP message timestamp  
    collector TEXT NOT NULL,         -- Route collector name
    peer_ip TEXT NOT NULL,           -- Peer IP address
    peer_asn INTEGER NOT NULL,       -- Peer AS number
    prefix TEXT NOT NULL,            -- Network prefix
    path_id INTEGER,                 -- BGP path identifier
    as_path TEXT,                    -- AS path string
    origin_asns TEXT                 -- Origin AS numbers
);

updates table (2nd and later RIBs only)

CREATE TABLE updates (
    rib_ts INTEGER NOT NULL,         -- Target RIB timestamp
    timestamp REAL NOT NULL,         -- Update message timestamp
    collector TEXT NOT NULL,         -- Route collector name
    peer_ip TEXT NOT NULL,           -- Peer IP address
    peer_asn INTEGER NOT NULL,       -- Peer AS number
    prefix TEXT NOT NULL,            -- Network prefix
    path_id INTEGER,                 -- BGP path identifier
    as_path TEXT,                    -- AS path string
    origin_asns TEXT,               -- Origin AS numbers
    elem_type TEXT NOT NULL          -- 'ANNOUNCE' or 'WITHDRAW'
);

Testing

  • All existing tests pass
  • Added new test for two-table SQLite store functionality
  • Verified with rrc18 collector test data

Documentation

  • Updated README.md with detailed schema documentation
  • Added comprehensive inline documentation in code
  • Documented all CLI options and filters

- add rib reconstruction for arbitrary timestamps using base RIBs and replayed updates
- support stdout and SQLite output with country and full-feed filters
- document rib command behavior in the README and changelog
- remove the rib output-type parameter and use --sqlite-path to enable SQLite output
- require --sqlite-path for multi-timestamp rib runs
- update README and changelog for the revised rib CLI
- move rib timestamps from repeated --ts flags to positional operands
- keep --sqlite-path for SQLite output and multi-timestamp runs
- update README, changelog, and examples for the revised rib CLI
BREAKING CHANGE: SQLite output schema changed from single 'elems' table
to two tables:
- 'ribs': stores final reconstructed RIB states at each target timestamp
- 'updates': stores filtered BGP updates for 2nd and later RIBs only

Performance improvements:
- Use Arc<str> for collector and prefix fields to reduce allocations
- Remove unnecessary per-snapshot O(n log n) sorting
- Reduce updates query window from +2h lookahead to exact target

Changes:
- Added StoredRibUpdate struct for tracking filtered updates
- Updated RibSqliteStore with two-table schema
- Modified reconstruct_snapshots callback to include filtered updates
- Added comprehensive documentation for new schema
@digizeph digizeph merged commit 5387149 into main Mar 26, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant