Skip to content

Commit 091cae6

Browse files
committed
Merge bitcoin/bitcoin#33939: contrib: Count entry differences in asmap-tool diff summary
fd4ce55 contrib: Count entry differences in asmap-tool diff summary (Fabian Jahr) Pull request description: Currently the output of `asmap-tool.py diff` returns the total number of addresses that has changed at the end of the list. Example output currently: ``` 2602:feda:c0::/48 AS1029 # was AS43126 2604:7c00:100::/40 AS29802 # was AS40244 # 0 IPv4 addresses changed; 79552154633921058212365205504 (2^96.01) IPv6 addresses changed ``` This is good indicator but in case of a longer list I would like the number of changed entries as well, since that is an easier number to parse and for debugging of certain issues also the more relevant value. This PR adds the count of changed entries to this summary output at the end. There as also a bit more structure so it's easier to parse as well. Example new output: ``` 2602:feda:c0::/48 AS1029 # was AS43126 2604:7c00:100::/40 AS29802 # was AS40244 # Summary IPv4: 0 entries with 0 addresses changed IPv6: 12 entries with 79552154633921058212365205504 (2^96.01) addresses changed ``` ACKs for top commit: jurraca: utACK [`fd4ce55121`](bitcoin/bitcoin@fd4ce55) janb84: utACK fd4ce55 hodlinator: ACK fd4ce55 Tree-SHA512: 97cc543eaba80a33f0291b20630411bda869d3b8d1b35ed7f36792064cb1edccc8fe4740b7229b5451a88b7bd8d68c42f96829ce4255ecac3e29d70b68061608
2 parents b8e66b9 + fd4ce55 commit 091cae6

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

contrib/asmap/asmap-tool.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,19 @@ def main():
140140
state1 = load_file(args.infile1)
141141
state2 = load_file(args.infile2)
142142
ipv4_changed = 0
143+
ipv4_entries_changed = 0
143144
ipv6_changed = 0
145+
ipv6_entries_changed = 0
144146
for prefix, old_asn, new_asn in state1.diff(state2):
145147
if args.ignore_unassigned and old_asn == 0:
146148
continue
147149
net = asmap.prefix_to_net(prefix)
148150
if isinstance(net, ipaddress.IPv4Network):
149-
ipv4_changed += 1 << (32 - net.prefixlen)
151+
ipv4_changed += net.num_addresses
152+
ipv4_entries_changed += 1
150153
elif isinstance(net, ipaddress.IPv6Network):
151-
ipv6_changed += 1 << (128 - net.prefixlen)
154+
ipv6_changed += net.num_addresses
155+
ipv6_entries_changed += 1
152156
if new_asn == 0:
153157
print(f"# {net} was AS{old_asn}")
154158
elif old_asn == 0:
@@ -159,8 +163,9 @@ def main():
159163
ipv6_change_str = "" if ipv6_changed == 0 else f" (2^{math.log2(ipv6_changed):.2f})"
160164

161165
print(
162-
f"# {ipv4_changed}{ipv4_change_str} IPv4 addresses changed; "
163-
f"{ipv6_changed}{ipv6_change_str} IPv6 addresses changed"
166+
f"""# Summary
167+
IPv4: {ipv4_entries_changed} entries with {ipv4_changed}{ipv4_change_str} addresses changed
168+
IPv6: {ipv6_entries_changed} entries with {ipv6_changed}{ipv6_change_str} addresses changed"""
164169
)
165170
elif args.subcommand == "diff_addrs":
166171
state1 = load_file(args.infile1)

0 commit comments

Comments
 (0)