Skip to content

Commit b65653c

Browse files
authored
Merge pull request #91 from bgpkit/feature/as2rel-extension
Enhanced AS2Rel Command and New Pfx2as Command
2 parents d460eaf + a7b257f commit b65653c

File tree

16 files changed

+2258
-59
lines changed

16 files changed

+2258
-59
lines changed

CHANGELOG.md

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,55 @@ All notable changes to this project will be documented in this file.
44

55
## Unreleased
66

7+
### New Features
8+
9+
* Added new `monocle pfx2as` command for prefix-to-ASN mapping lookups
10+
* **Search by prefix**: Query prefixes to find their origin ASNs
11+
* Example: `monocle pfx2as 1.1.1.0/24`
12+
* **Search by ASN**: Query an ASN to find all its announced prefixes
13+
* Example: `monocle pfx2as 13335` or `monocle pfx2as AS13335`
14+
* **RPKI validation**: Shows RPKI validation status (valid/invalid/not_found) for each prefix-ASN pair
15+
* **`--show-name`**: Display AS organization name for each origin ASN
16+
* **`--include-sub`**: Include sub-prefixes (more specific) in results
17+
* Example: `monocle pfx2as 8.0.0.0/8 --include-sub --limit 20`
18+
* **`--include-super`**: Include super-prefixes (less specific) in results
19+
* Example: `monocle pfx2as 1.1.1.0/24 --include-super`
20+
* **`--limit`**: Limit the number of results
21+
* Supports all standard output formats (`--format table/json/psv/etc.`)
22+
23+
* Enhanced `monocle as2rel` command with advanced filtering and multi-ASN support
24+
* **`--min-visibility <PERCENT>`**: Filter results by minimum visibility percentage (0-100)
25+
* Available for all as2rel queries
26+
* Filters out relationships seen by fewer than the specified percentage of peers
27+
* **`--single-homed`**: Find ASNs that are single-homed to the queried ASN
28+
* Shows only ASNs where the queried ASN is their ONLY upstream provider
29+
* Useful for identifying customers with no redundancy
30+
* Example: `monocle as2rel 2914 --single-homed`
31+
* **`--is-upstream`**: Filter to show only downstream customers of the queried ASN
32+
* Shows relationships where the queried ASN is the upstream (provider)
33+
* **`--is-downstream`**: Filter to show only upstream providers of the queried ASN
34+
* Shows relationships where the queried ASN is a downstream (customer)
35+
* **`--is-peer`**: Filter to show only peer relationships (settlement-free interconnection)
36+
* **Multi-ASN support**: Query relationships among multiple ASNs at once
37+
* When more than two ASNs are provided, shows all pair combinations
38+
* Results sorted by asn1, with asn1 < asn2 for each pair
39+
* Example: `monocle as2rel 174 2914 3356` shows all three pair relationships
40+
741
### Bug Fixes
842

943
* Fixed "database is locked" error in `monocle config db-refresh` command (Issue #90)
1044
* The `do_refresh` function was opening redundant database connections for ASInfo and AS2Rel data sources
1145
* Now correctly uses the already-passed database connection parameter
1246

47+
### Improvements
48+
49+
* Added visual `...` row indicator in tables when results are truncated
50+
* Search results table now shows a `...` row when more matches exist
51+
* RPKI ROA tables show truncation indicator
52+
* Announced prefixes table shows truncation indicator
53+
* Connectivity section (upstreams/peers/downstreams) tables show truncation indicator
54+
* Makes it much more visible that additional results are available
55+
1356
### New Features
1457

1558
* Added global `--no-refresh` flag to disable automatic data refresh
@@ -25,8 +68,6 @@ All notable changes to this project will be documented in this file.
2568
* Automatically loads ASInfo data before showing ASPA output
2669
* AS names and countries are displayed in ASPA results
2770

28-
### Improvements
29-
3071
* Added comprehensive tests for database initialization with mock data
3172
* Tests for all repositories being accessible after initialization
3273
* Tests for schema version verification

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ name = "as2rel_queries"
5454
path = "examples/database/as2rel_queries.rs"
5555
required-features = ["database"]
5656

57+
[[example]]
58+
name = "pfx2as_search"
59+
path = "examples/database/pfx2as_search.rs"
60+
required-features = ["lens-bgpkit"]
61+
5762
# BGPKIT examples - requires bgpkit-* crates
5863
[[example]]
5964
name = "country_lookup"

README.md

Lines changed: 137 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ See through all Border Gateway Protocol (BGP) data with a monocle.
2424
- [`monocle inspect`](#monocle-inspect)
2525
- [`monocle country`](#monocle-country)
2626
- [`monocle as2rel`](#monocle-as2rel)
27+
- [`monocle pfx2as`](#monocle-pfx2as)
2728
- [`monocle rpki`](#monocle-rpki)
2829
- [`monocle rpki validate`](#monocle-rpki-validate)
2930
- [`monocle rpki roas`](#monocle-rpki-roas)
@@ -186,12 +187,13 @@ Subcommands:
186187
- `parse`: parse individual MRT files
187188
- `search`: search for matching messages from all available public MRT files
188189
- `server`: start a WebSocket server for programmatic access
189-
- `inspect`: unified AS and prefix information lookup (replaces `whois` and `pfx2as`)
190+
- `inspect`: unified AS and prefix information lookup
190191
- `country`: utility to look up country name and code
191192
- `time`: utility to convert time between unix timestamp and RFC3339 string
193+
- `as2rel`: AS-level relationship lookup between ASNs
194+
- `pfx2as`: prefix-to-ASN mapping lookup with RPKI validation
192195
- `rpki`: RPKI validation and ROA/ASPA listing
193196
- `ip`: IP information lookup
194-
- `as2rel`: AS-level relationship lookup between ASNs
195197
- `config`: configuration display and database management (refresh, backup, sources)
196198

197199
### Global Options
@@ -583,22 +585,29 @@ Look up AS-level relationships between ASNs using BGPKIT's AS relationship data.
583585
➜ monocle as2rel --help
584586
AS-level relationship lookup between ASNs
585587
586-
Usage: monocle as2rel [OPTIONS] <ASN1> [ASN2]
588+
Usage: monocle as2rel [OPTIONS] <ASNS>...
587589
588590
Arguments:
589-
<ASN1> First ASN to look up
590-
[ASN2] Second ASN (optional, shows all relationships for ASN1 if omitted)
591+
<ASNS>... One or more ASNs to query relationships for
592+
- Single ASN: shows all relationships for that ASN
593+
- Two ASNs: shows the relationship between them
594+
- Multiple ASNs: shows relationships for all pairs (asn1 < asn2)
591595
592596
Options:
593-
--debug Print debug information
594-
--format <FORMAT> Output format: table (default), markdown, json, json-pretty, json-line, psv
595-
--json Output as JSON objects (shortcut for --format json-pretty)
596-
--update Force update the local database
597-
--no-explain Hide the explanation text in table output
598-
--sort-by-asn Sort results by ASN2 ascending (default: sort by connected % descending)
599-
--show-name Show organization name for ASN2 (truncated to 20 chars)
600-
--show-full-name Show full organization name without truncation
601-
-h, --help Print help
597+
--debug Print debug information
598+
--format <FORMAT> Output format: table (default), markdown, json, json-pretty, json-line, psv
599+
--json Output as JSON objects (shortcut for --format json-pretty)
600+
--update Force update the local database
601+
--no-explain Hide the explanation text in table output
602+
--sort-by-asn Sort results by ASN2 ascending (default: sort by connected % descending)
603+
--show-name Show organization name for ASN2 (truncated to 20 chars)
604+
--show-full-name Show full organization name without truncation
605+
--min-visibility <PCT> Minimum visibility percentage (0-100) to include in results
606+
--single-homed Only show ASNs that are single-homed to the queried ASN
607+
--is-upstream Only show relationships where the queried ASN is an upstream (provider)
608+
--is-downstream Only show relationships where the queried ASN is a downstream (customer)
609+
--is-peer Only show peer relationships
610+
-h, --help Print help
602611
```
603612

604613
Output columns:
@@ -611,14 +620,128 @@ Output columns:
611620
Examples:
612621

613622
```text
623+
# Look up relationship between two ASNs
614624
➜ monocle as2rel 13335 174
615625
┌───────┬──────┬───────────┬───────┬─────────────┬─────────────┐
616626
│ asn1 │ asn2 │ connected │ peer │ as1_upstream│ as2_upstream│
617627
├───────┼──────┼───────────┼───────┼─────────────┼─────────────┤
618628
│ 13335 │ 174 │ 95.2% │ 85.1% │ 2.3% │ 7.8% │
619629
└───────┴──────┴───────────┴───────┴─────────────┴─────────────┘
620630
631+
# Show all relationships for an ASN with names
621632
➜ monocle as2rel 13335 --show-name | head -10
633+
634+
# Find ASNs that are single-homed to AS2914 (NTT)
635+
➜ monocle as2rel 2914 --single-homed --show-name
636+
637+
# Find single-homed ASNs with at least 10% visibility
638+
➜ monocle as2rel 2914 --single-homed --min-visibility 10
639+
640+
# Show only downstream customers of an ASN
641+
➜ monocle as2rel 2914 --is-upstream --show-name
642+
643+
# Show only upstream providers of an ASN
644+
➜ monocle as2rel 13335 --is-downstream --show-name
645+
646+
# Show relationships among multiple ASNs (all pairs)
647+
➜ monocle as2rel 174 2914 3356 --show-name
648+
```
649+
650+
### `monocle pfx2as`
651+
652+
Look up prefix-to-ASN mappings. Query by prefix to find origin ASNs, or by ASN to find announced prefixes.
653+
Results include RPKI validation status for each prefix-ASN pair.
654+
655+
```text
656+
➜ monocle pfx2as --help
657+
Prefix-to-ASN mapping lookup
658+
659+
Query by prefix to find origin ASNs, or by ASN to find announced prefixes.
660+
Includes RPKI validation status for each prefix-ASN pair.
661+
662+
Usage: monocle pfx2as [OPTIONS] <QUERY>
663+
664+
Arguments:
665+
<QUERY> Query: an IP prefix (e.g., 1.1.1.0/24) or ASN (e.g., 13335, AS13335)
666+
667+
Options:
668+
-u, --update Force update the local pfx2as database
669+
--include-sub Include sub-prefixes (more specific) in results when querying by prefix
670+
--include-super Include super-prefixes (less specific) in results when querying by prefix
671+
--show-name Show AS name for each origin ASN
672+
--show-full-name Show full AS name without truncation (default truncates to 20 chars)
673+
-l, --limit <N> Limit the number of results (default: no limit)
674+
--debug Print debug information
675+
--format <FORMAT> Output format: table (default), markdown, json, json-pretty, json-line, psv
676+
--json Output as JSON objects (shortcut for --format json-pretty)
677+
-h, --help Print help
678+
```
679+
680+
Examples:
681+
682+
```text
683+
# Look up a prefix - shows origin ASN and RPKI validation status
684+
➜ monocle pfx2as 1.1.1.0/24
685+
╭────────────┬────────────┬───────╮
686+
│ prefix │ origin_asn │ rpki │
687+
├────────────┼────────────┼───────┤
688+
│ 1.1.1.0/24 │ 13335 │ valid │
689+
╰────────────┴────────────┴───────╯
690+
691+
# Look up with AS name
692+
➜ monocle pfx2as 1.1.1.0/24 --show-name
693+
╭────────────┬────────────┬───────────────┬───────╮
694+
│ prefix │ origin_asn │ as_name │ rpki │
695+
├────────────┼────────────┼───────────────┼───────┤
696+
│ 1.1.1.0/24 │ 13335 │ CLOUDFLARENET │ valid │
697+
╰────────────┴────────────┴───────────────┴───────╯
698+
699+
# Look up by ASN - shows all prefixes announced by the ASN
700+
➜ monocle pfx2as 13335 --limit 5 --show-name
701+
╭─────────────────────┬────────────┬───────────────┬───────────╮
702+
│ prefix │ origin_asn │ as_name │ rpki │
703+
├─────────────────────┼────────────┼───────────────┼───────────┤
704+
│ 172.69.7.0/24 │ 13335 │ CLOUDFLARENET │ valid │
705+
│ 2606:4700:839a::/48 │ 13335 │ CLOUDFLARENET │ valid │
706+
│ 8.36.218.0/24 │ 13335 │ CLOUDFLARENET │ not_found │
707+
│ 2400:cb00:b8e6::/48 │ 13335 │ CLOUDFLARENET │ valid │
708+
│ 172.68.134.0/24 │ 13335 │ CLOUDFLARENET │ valid │
709+
╰─────────────────────┴────────────┴───────────────┴───────────╯
710+
711+
# Include sub-prefixes (more specific prefixes)
712+
➜ monocle pfx2as 8.8.0.0/16 --include-sub --limit 5 --show-name
713+
╭──────────────┬────────────┬────────────┬───────────╮
714+
│ prefix │ origin_asn │ as_name │ rpki │
715+
├──────────────┼────────────┼────────────┼───────────┤
716+
│ 8.0.0.0/12 │ 3356 │ LEVEL3 │ not_found │
717+
│ 8.8.8.0/24 │ 15169 │ GOOGLE │ valid │
718+
│ 8.8.249.0/24 │ 989 │ ANAXA3-ASN │ valid │
719+
│ 8.8.216.0/24 │ 13781 │ ENERGYNET │ valid │
720+
│ 8.8.64.0/24 │ 3356 │ LEVEL3 │ not_found │
721+
╰──────────────┴────────────┴────────────┴───────────╯
722+
723+
# Include super-prefixes (less specific prefixes)
724+
➜ monocle pfx2as 1.1.1.0/24 --include-super
725+
726+
# JSON output
727+
➜ monocle pfx2as 13335 --limit 3 --json
728+
[
729+
{
730+
"prefix": "172.69.7.0/24",
731+
"origin_asn": 13335,
732+
"rpki": "valid"
733+
},
734+
{
735+
"prefix": "2606:4700:839a::/48",
736+
"origin_asn": 13335,
737+
"rpki": "valid"
738+
},
739+
{
740+
"prefix": "8.36.218.0/24",
741+
"origin_asn": 13335,
742+
"rpki": "not_found"
743+
}
744+
]
622745
```
623746

624747
### `monocle rpki`

examples/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ cargo run --release --example output_formats --features lens-core
1616
# Database operations
1717
cargo run --release --example database_basics --features database
1818
cargo run --release --example as2rel_queries --features database
19+
cargo run --release --example pfx2as_search --features lens-bgpkit
1920

2021
# BGP operations
2122
cargo run --release --example country_lookup --features lens-bgpkit
@@ -61,6 +62,7 @@ SQLite operations without lens overhead.
6162
**Files:**
6263
- `database/database_basics.rs` - MonocleDatabase, schema management
6364
- `database/as2rel_queries.rs` - Query AS-level relationships
65+
- `database/pfx2as_search.rs` - Prefix-to-ASN mapping and search (requires `lens-bgpkit`)
6466

6567
### BGPKIT Examples (`lens-bgpkit`)
6668

0 commit comments

Comments
 (0)