From 7ea0ae34f0fa6ef51fb02047823d5a063d9fa416 Mon Sep 17 00:00:00 2001 From: Jerry Date: Wed, 25 Nov 2020 18:04:35 +0800 Subject: [PATCH] roa.py: add Address Space Usage --- scripts/roa.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/scripts/roa.py b/scripts/roa.py index bcc055d..3a40f5f 100755 --- a/scripts/roa.py +++ b/scripts/roa.py @@ -339,6 +339,22 @@ def make_summary(): for prefix in prefixes: print(prefix) print("```") + IP_VRSIONS = {4, 6} + used_ip_count = {ver: sum([ip_network(str(prefix)).num_addresses for prefix in prefixes if prefix.version == ver]) for ver in IP_VRSIONS} + total_ip_count = {ver: sum([prefix.num_addresses for prefix in NEO_NETWORK_POOL if prefix.version == ver]) for ver in IP_VRSIONS} + print() + print("## Address Space Usage") + print() + address_space_usage_table = tabulate( + ( + (f"IPv{ver}", f"{(u:=used_ip_count.get(ver)):.5g}", f"{(t:=total_ip_count.get(ver)):.5g}", f"{t-u:.5g}", f"{u/t*100:.2f}%", f"{(t-u)/t*100:.2f}%") + for ver in IP_VRSIONS + ), + headers=["IP Version", "Total", "Used", "Free", "Percent Used", "Percent Free"], + tablefmt="github", + disable_numparse=True + ) + print(address_space_usage_table) return stream.getvalue()