-
Notifications
You must be signed in to change notification settings - Fork 16
use -p threads flag #97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
jurraca
wants to merge
4
commits into
asmap:master
Choose a base branch
from
jurraca:threads-flag
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,87 +20,47 @@ def parse_rpki(context): | |
|
|
||
| dups_count = 0 | ||
| out_count = 0 | ||
| invalids = 0 | ||
| incompletes = 0 | ||
| not_roas = 0 | ||
|
|
||
| with open(raw_input, "r") as dump: | ||
| data = json.loads(dump.read()) | ||
| print(f'Parsing {len(data)} ROAs') | ||
|
|
||
| for roa in data: | ||
| # Sometimes ROAs are incomplete and we have to skip them | ||
| key_list = [ | ||
| 'type', | ||
| 'validation', | ||
| 'aki', | ||
| 'ski', | ||
| 'vrps', | ||
| 'valid_until' | ||
| ] | ||
| if not all(key in roa for key in key_list): | ||
| incompletes += 1 | ||
| continue | ||
|
|
||
| # We are only interested in ROAs | ||
| if roa['type'] != "roa": | ||
| not_roas += 1 | ||
| print(f'Parsing {data["metadata"]["roas"]} ROAs') | ||
|
|
||
| for roa in data["roas"]: | ||
| asn = roa['asn'] | ||
| expiry = roa['expires'] | ||
| prefix = parse_pfx(roa['prefix']) | ||
|
|
||
| # Bogon prefixes and ASNs are excluded since they can not | ||
| # be used for routing. | ||
| if not prefix or is_bogon_pfx(prefix) or is_bogon_asn(asn): | ||
| if context.debug_log: | ||
| with open(context.debug_log, 'a') as logs: | ||
| logs.write(f"RPKI: parser encountered an invalid entry: {prefix} with ASN {asn}\n") | ||
| continue | ||
|
|
||
| # We are only interested in valid ROAs | ||
| if roa['validation'] != "OK": | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. only valid ROAs are output |
||
| invalids += 1 | ||
| if context.max_encode and is_out_of_encoding_range(asn, context.max_encode): | ||
| continue | ||
|
|
||
| valid_until = roa['valid_until'] | ||
| valid_since = roa['valid_since'] | ||
|
|
||
| for vrp in roa['vrps']: | ||
| asn = vrp['asid'] | ||
| prefix = parse_pfx(vrp['prefix']) | ||
| if not prefix: | ||
| if context.debug_log: | ||
| with open(context.debug_log, 'a') as logs: | ||
| logs.write(f"Could not parse prefix from line: {vrp['prefix']}") | ||
| continue | ||
| # Bogon prefixes and ASNs are excluded since they can not | ||
| # be used for routing. | ||
| if is_bogon_pfx(prefix) or is_bogon_asn(asn): | ||
| if context.debug_log: | ||
| with open(context.debug_log, 'a') as logs: | ||
| logs.write(f"RPKI: parser encountered an invalid IP network: {prefix}\n") | ||
| continue | ||
|
|
||
| if context.max_encode and is_out_of_encoding_range(asn, context.max_encode): | ||
| continue | ||
|
|
||
| # Multiple ROAs for the same prefix are possible and we need | ||
| # to decide if we update the entry or not | ||
| if output_cache.get(prefix): | ||
| dups_count += 1 | ||
| # If the new ASN is from a ROA that is valid for longer, | ||
| # we override the old entry with it | ||
| [old_asn, old_valid_until, old_valid_since] = output_cache[prefix] | ||
| if int(valid_until) > int(old_valid_until): | ||
| output_cache[prefix] = [asn, valid_until, valid_since] | ||
| # If the entries have the same validity period, we need to | ||
| # choose a different tie breaker | ||
| if int(valid_until) == int(old_valid_until): | ||
| # Prefer the ROA that was announced last | ||
| if int(valid_since) > int(old_valid_since): | ||
| output_cache[prefix] = [asn, valid_until, valid_since] | ||
| # If the ROAs were also announced at the same time, we | ||
| # fall back to using the lower ASN just to be | ||
| # deterministic | ||
| if int(valid_since) == int(old_valid_since): | ||
| if int(asn) < int(old_asn): | ||
| output_cache[prefix] = [asn, valid_until, valid_since] | ||
| else: | ||
| # No duplicate, add to cache | ||
| output_cache[prefix] = [asn, valid_until, valid_since] | ||
| # Multiple ROAs for the same prefix are possible and we need | ||
| # to decide if we update the entry or not | ||
| if output_cache.get(prefix): | ||
| dups_count += 1 | ||
| # If the new ASN is from a ROA that is valid for longer, | ||
| # we override the old entry with it | ||
| [old_asn, old_expiry] = output_cache[prefix] | ||
| if expiry > old_expiry: | ||
| output_cache[prefix] = [asn, expiry] | ||
| # If the entries have the same validity period, we need to | ||
| # choose a different tie breaker | ||
| if expiry == old_expiry: | ||
| if int(asn) < int(old_asn): | ||
| output_cache[prefix] = [asn, expiry] | ||
| else: | ||
| # No duplicate, add to cache | ||
| output_cache[prefix] = [asn, expiry] | ||
|
|
||
| with open(rpki_res, "w") as asmap: | ||
| for prefix, [asn, _, _] in output_cache.items(): | ||
| for prefix, [asn, _] in output_cache.items(): | ||
| line_out = f"{prefix} AS{asn}" | ||
|
|
||
| asmap.write(line_out + '\n') | ||
|
|
@@ -110,6 +70,3 @@ def parse_rpki(context): | |
|
|
||
| print(f'Result entries written: {out_count}') | ||
| print(f'Duplicates found: {dups_count}') | ||
| print(f'Invalids found: {invalids}') | ||
| print(f'Incompletes: {incompletes}') | ||
| print(f'Non-ROA files: {not_roas}') | ||
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
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
they're all ROAs, iiuc