VOL-34 Add group printing at CLI
Change-Id: I4e8e55ffd397c3d1486dc2807e92dd87eea9856e
diff --git a/cli/logical_device.py b/cli/logical_device.py
index c1a9479..0545c69 100644
--- a/cli/logical_device.py
+++ b/cli/logical_device.py
@@ -23,7 +23,7 @@
from cli.table import print_pb_as_table, print_pb_list_as_table
from cli.utils import pb2dict
-from cli.utils import print_flows
+from cli.utils import print_flows, print_groups
from voltha.protos import third_party
from google.protobuf.empty_pb2 import Empty
@@ -88,6 +88,16 @@
groups=logical_device['flow_groups']['items']
)
+ def do_groups(self, _):
+ """Show flow group table for logical device"""
+ logical_device = pb2dict(self.get_logical_device(-1))
+ print_groups(
+ 'Logical Device',
+ self.logical_device_id,
+ type='n/a',
+ groups=logical_device['flow_groups']['items']
+ )
+
def do_devices(self, line):
"""List devices that belong to this logical device"""
logical_device = self.get_logical_device()
diff --git a/cli/utils.py b/cli/utils.py
index 105931b..729c3a2 100644
--- a/cli/utils.py
+++ b/cli/utils.py
@@ -32,9 +32,9 @@
def p_cookie(cookie):
- cookie = str(cookie)
+ cookie = '%x' % int(cookie)
if len(cookie) > 8:
- return cookie[:6] + '...'
+ return '~' + cookie[len(cookie)-8:]
else:
return cookie
@@ -152,9 +152,27 @@
table.print_table(header, printfn)
- # see CORD-817 (https://jira.opencord.org/browse/CORD-817)
- # assert len(groups) == 0
+def print_groups(what, id, type, groups, printfn=_printfn):
+ header = ''.join([
+ '{} '.format(what),
+ colored(id, color='green', attrs=['bold']),
+ ' (type: ',
+ colored(type, color='blue'),
+ ')'
+ ]) + '\nGroups ({}):'.format(len(groups))
+
+ table = TablePrinter()
+ for i, group in enumerate(groups):
+ output_ports = []
+ for bucket in group['desc']['buckets']:
+ for action in bucket['actions']:
+ if action['type'] == 'OFPAT_OUTPUT':
+ output_ports.append(action['output']['port'])
+ table.add_cell(i, 0, 'group_id', value=str(group['desc']['group_id']))
+ table.add_cell(i, 1, 'buckets', value=str(dict(output=output_ports)))
+
+ table.print_table(header, printfn)
def dict2line(d):
assert isinstance(d, dict)