Created
May 9, 2023 15:50
-
-
Save digizeph/8dcae023eb6ce253ba18c744fbdd2836 to your computer and use it in GitHub Desktop.
Parse a RIB dump file into prefix-to-AS mapping HashMap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn pfx2as(url: &str) -> Result<HashMap<IpNet, HashSet<u32>>> { | |
let mut data: HashMap<IpNet, HashSet<u32>> = HashMap::new(); | |
for elem in bgpkit_parser::BgpkitParser::new(url)? { | |
let prefix = elem.prefix.prefix; | |
let origins = elem | |
.origin_asns | |
.unwrap() | |
.into_iter() | |
.map(|v| v.asn) | |
.collect::<Vec<u32>>(); | |
data.entry(prefix) | |
.or_insert_with(|| HashSet::new()) | |
.extend(origins); | |
} | |
Ok(data) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/bgpkit/bgpkit-parser