Skip to content

Conversation

@digizeph
Copy link
Member

Summary

This PR adds significant enhancements to the as2rel command with advanced filtering capabilities, introduces a new pfx2as command for prefix-to-ASN mapping lookups, and improves table output with visual truncation indicators.

New Features

New monocle pfx2as Command

A new command for prefix-to-ASN mapping lookups with RPKI validation:

# Search by prefix
monocle pfx2as 1.1.1.0/24

# Search by ASN
monocle pfx2as 13335 --limit 10 --show-name

# Include sub/super prefixes
monocle pfx2as 8.0.0.0/8 --include-sub --limit 20
monocle pfx2as 1.1.1.0/24 --include-super

Features:

  • Auto-detects query type (ASN or prefix)
  • Shows RPKI validation status (valid/invalid/not_found) for each prefix-ASN pair
  • --show-name flag to display AS organization names
  • --include-sub to include more specific (sub) prefixes
  • --include-super to include less specific (super) prefixes
  • --limit to control result count
  • Supports all standard output formats (table, json, psv, etc.)

Enhanced monocle as2rel Command

New filtering options for more targeted relationship queries:

Option Description
--min-visibility <PERCENT> Filter by minimum visibility percentage (0-100)
--single-homed Find ASNs single-homed to the queried ASN
--is-upstream Show only downstream customers
--is-downstream Show only upstream providers
--is-peer Show only peer relationships

Multi-ASN Support:

# Query relationships among multiple ASNs (shows all pair combinations)
monocle as2rel 174 2914 3356 --show-name

Single-homed Discovery:

# Find ASNs that have only AS2914 as their upstream
monocle as2rel 2914 --single-homed --show-name

# Filter to single-homed ASNs with at least 10% visibility
monocle as2rel 2914 --single-homed --min-visibility 10

Visual Truncation Indicators

Tables now show a ... row when results are truncated, making it immediately visible that additional data exists:

╭────────────┬────────────┬───────╮
│ prefix     │ origin_asn │ rpki  │
├────────────┼────────────┼───────┤
│ 1.1.1.0/24 │ 13335      │ valid │
│ 8.8.8.0/24 │ 15169      │ valid │
│ ...        │ ...        │ ...   │
╰────────────┴────────────┴───────╯

This applies to:

  • Search results
  • RPKI ROA listings
  • Announced prefixes
  • Connectivity sections (upstreams/peers/downstreams)

Architecture

The pfx2as implementation follows the lens/command separation pattern per DEVELOPMENT.md:

  • Pfx2asLens (src/lens/pfx2as/mod.rs): Contains all business logic

    • Query type detection (ASN vs prefix)
    • RPKI validation integration
    • AS name enrichment from ASInfo database
    • Result formatting for various output formats
  • Command (src/bin/commands/pfx2as.rs): Thin CLI wrapper (~170 lines)

    • Handles CLI argument parsing
    • Manages data refresh prompts
    • Delegates all logic to the lens

Files Changed

New Files:

  • src/bin/commands/pfx2as.rs - CLI command handler
  • examples/database/pfx2as_search.rs - Usage example

Modified Files:

  • src/lens/pfx2as/mod.rs - Enhanced with search functionality, RPKI validation, AS name enrichment
  • src/lens/as2rel/mod.rs - Added filtering and multi-ASN support
  • src/lens/as2rel/args.rs - New CLI arguments
  • src/database/monocle/as2rel.rs - New database query methods
  • src/lens/inspect/mod.rs - Added truncation indicators
  • src/bin/commands/as2rel.rs - Updated command handler
  • src/bin/monocle.rs - Added Pfx2as command
  • README.md - Documentation for pfx2as command
  • CHANGELOG.md - Feature documentation
  • Cargo.toml - Added example entry
  • examples/README.md - Added pfx2as example

Testing

  • All existing tests pass
  • New unit tests for Pfx2asSearchArgs and Pfx2asSearchResult
  • Manual testing of all new features

Breaking Changes

None. All changes are additive.

New features for the as2rel command:

- --min-visibility <PERCENT>: Filter results by minimum visibility percentage
  Available for all as2rel queries to exclude low-confidence relationships

- --single-homed: Find ASNs single-homed to the queried ASN
  Shows only ASNs where the queried ASN is their ONLY upstream provider
  Useful for identifying customers with no transit redundancy

- --is-upstream: Filter to show only downstream customers
  Shows relationships where the queried ASN is the provider

- --is-downstream: Filter to show only upstream providers
  Shows relationships where the queried ASN is the customer

- --is-peer: Filter to show only peer relationships
  Shows settlement-free interconnection relationships

- Multi-ASN support: Query relationships among multiple ASNs
  When >2 ASNs provided, shows all pair combinations (asn1 < asn2)
  Results sorted by asn1

Database changes:
- Added find_single_homed_to() method for efficient single-homed lookups
- Added search_asn_by_rel_type() for relationship-filtered queries
- Added search_multi_asn_pairs_with_names() for multi-ASN queries

WebSocket API updated with corresponding parameters.
- Search results table now shows a '...' row when more matches exist
- RPKI ROA tables (both prefix and ASN queries) show truncation indicator
- Announced prefixes table shows truncation indicator
- Connectivity section (upstreams/peers/downstreams) tables show truncation indicator

This makes it much more visible that additional results are available,
addressing the issue where users might not notice the truncation message
below the table.
Add new 'monocle pfx2as' command that provides:
- Search by prefix to find origin ASNs (e.g., monocle pfx2as 1.1.1.0/24)
- Search by ASN to find announced prefixes (e.g., monocle pfx2as 13335)
- RPKI validation status display for each prefix-ASN pair
- --show-name flag to display AS organization names
- --include-sub flag to include more specific (sub) prefixes
- --include-super flag to include less specific (super) prefixes
- --limit flag to limit results
- Support for all standard output formats

The implementation follows the lens/command separation pattern:
- Pfx2asLens (src/lens/pfx2as/mod.rs) contains all business logic
  - Query type detection (ASN vs prefix)
  - RPKI validation integration
  - AS name enrichment from ASInfo database
  - Result formatting for various output formats
- Command (src/bin/commands/pfx2as.rs) is a thin wrapper handling only
  CLI-specific concerns like argument parsing and data refresh prompts

Also adds:
- pfx2as_search.rs example in examples/database/
- Updated examples/README.md with new example
- Updated CHANGELOG.md with feature documentation
- Add pfx2as to Table of Contents
- Add pfx2as to subcommands list in Usage section
- Add detailed monocle pfx2as section with:
  - Command help output
  - Examples for prefix lookup, ASN lookup
  - Examples with --show-name, --include-sub, --include-super
  - JSON output example
@digizeph digizeph merged commit b65653c into main Dec 19, 2025
1 check passed
@digizeph digizeph deleted the feature/as2rel-extension branch December 19, 2025 00:28
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.

2 participants