Created
January 19, 2021 15:16
-
-
Save djoreilly/8523f96cf53e535459ad75642544dba4 to your computer and use it in GitHub Desktop.
Sort and tabulate the output of ovs-ofctl dump-flows
This file contains 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
''' | |
Make the output of ovs-ofctl dump-flows more readable | |
''' | |
import re | |
import sys | |
from tabulate import tabulate | |
PAT = re.compile("^ cookie.*table=(\d+), n_packets=(\d+).+ priority=(\d+),*(.*) actions=(.+)") | |
if len(sys.argv) == 2: | |
flows_file = sys.argv[1] | |
else: | |
print("Usage: python ovs-sort-flows.py /tmp/dump-flows.txt") | |
sys.exit() | |
rows = [] | |
with open(flows_file) as f: | |
for line in f.readlines(): | |
m = re.match(PAT, line) | |
if not m: | |
continue | |
priority = m.group(3) | |
table = m.group(1) | |
n_packets = m.group(2) | |
match = m.group(4) | |
actions = m.group(5) | |
rows.append((int(table), int(priority), n_packets, match, actions)) | |
# sort by table asending and then priority descending | |
rows.sort(key=lambda k: (k[0],-k[1])) | |
headers = ['T', 'P', 'Packets', 'Match', 'Actions'] | |
print(tabulate(rows, headers)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment