sign: Add totals to dict returned from getStreamStatsDict()
This commit is contained in:
parent
5f82912f91
commit
954a931717
100
binding/core.py
100
binding/core.py
@ -70,37 +70,111 @@ class DroneProxy(object):
|
||||
def getStreamStatsDict(self, stream_guid_list): # FIXME: rename?
|
||||
"""
|
||||
Convenience method for fetching stream stats which returns an object
|
||||
containing port/sguid dictionaries for easier access e.g. assuming
|
||||
the return value of this function is assigned to stream_stats,
|
||||
containing port/sguid dictionaries for easier access e.g.
|
||||
|
||||
stream_stats.port[1].sguid[101].tx_pkts
|
||||
stream_stats = drone.getStreamStatsDict(guid_list)
|
||||
|
||||
This method is a wrapper around the actual getStreamStats() RPC
|
||||
stream_stats.sguid[101].port[1].tx_pkts
|
||||
stream_stats.port[1].sguid[101].rx_bytes
|
||||
|
||||
In addition, you can also retrieve totals across ports, e.g.
|
||||
|
||||
stream_stats.port[1].total.rx_pkts
|
||||
stream_stats.port[1].total.rx_bytes
|
||||
stream_stats.port[1].total.tx_pkts
|
||||
stream_stats.port[1].total.tx_bytes
|
||||
|
||||
and totals across sguids -
|
||||
|
||||
stream_stats.sguid[101].total.tx_pkts
|
||||
stream_stats.sguid[101].total.rx_pkts
|
||||
stream_stats.sguid[101].total.pkt_loss
|
||||
|
||||
This method is a wrapper around the getStreamStats() RPC
|
||||
"""
|
||||
class StreamStatsDict:
|
||||
class StreamStatsPortTotal:
|
||||
def __init__(self):
|
||||
self.tx_pkts = 0
|
||||
self.rx_pkts = 0
|
||||
self.tx_bytes = 0
|
||||
self.rx_bytes = 0
|
||||
def __repr__(self):
|
||||
s = 'port: {\n'
|
||||
for k, v in self.port.items():
|
||||
s += str(k) + ': {\n' + str(v) + '}\n'
|
||||
s += '}\n'
|
||||
s = ' total: { \n'
|
||||
s += ' rx_pkts: ' + str(self.rx_pkts) + ' \n'
|
||||
s += ' rx_bytes: ' + str(self.rx_bytes) + ' \n'
|
||||
s += ' tx_pkts: ' + str(self.tx_pkts) + ' \n'
|
||||
s += ' tx_bytes: ' + str(self.tx_bytes) + ' \n'
|
||||
s += ' }\n'
|
||||
return s
|
||||
class StreamStatsDictPort:
|
||||
def __init__(self):
|
||||
self.sguid = dict()
|
||||
self.total = StreamStatsPortTotal()
|
||||
def __repr__(self):
|
||||
s = ' sguid: { \n'
|
||||
for k, v in self.sguid.items():
|
||||
s += ' ' + str(k) + ': {\n ' \
|
||||
+ str(v).replace('\n', '\n ') + '}\n'
|
||||
s += ' }\n'
|
||||
s += str(self.total)
|
||||
return s
|
||||
class StreamStatsGuidTotal:
|
||||
def __init__(self):
|
||||
self.tx_pkts = 0
|
||||
self.rx_pkts = 0
|
||||
self.pkt_loss = 0
|
||||
def __repr__(self):
|
||||
s = ' total: { \n'
|
||||
s += ' tx_pkts: ' + str(self.tx_pkts) + ' \n'
|
||||
s += ' rx_pkts: ' + str(self.rx_pkts) + ' \n'
|
||||
s += ' pkt_loss: ' + str(self.pkt_loss) + ' \n'
|
||||
s += ' }\n'
|
||||
return s
|
||||
class StreamStatsDictGuid:
|
||||
def __init__(self):
|
||||
self.port = dict()
|
||||
self.total = StreamStatsGuidTotal()
|
||||
def __repr__(self):
|
||||
s = ' port: { \n'
|
||||
for k, v in self.port.items():
|
||||
s += ' ' + str(k) + ': {\n ' \
|
||||
+ str(v).replace('\n', '\n ') + '}\n'
|
||||
s += ' }\n'
|
||||
s += str(self.total)
|
||||
return s
|
||||
class StreamStatsDict:
|
||||
def __init__(self):
|
||||
self.port = dict()
|
||||
self.sguid = dict()
|
||||
def __repr__(self):
|
||||
s = 'port: {\n'
|
||||
for k, v in self.port.items():
|
||||
s += str(k) + ': {\n' + str(v) + '}\n'
|
||||
s += '}\n'
|
||||
s += 'sguid: {\n'
|
||||
for k, v in self.sguid.items():
|
||||
s += str(k) + ': {\n' + str(v) + '}\n'
|
||||
s += '}\n'
|
||||
return s
|
||||
ssl = self.getStreamStats(stream_guid_list)
|
||||
ssd = StreamStatsDict()
|
||||
# TODO: ssd.aggr = dict()
|
||||
ssd.port = dict()
|
||||
for ss in ssl.stream_stats:
|
||||
if ss.port_id.id not in ssd.port:
|
||||
ssd.port[ss.port_id.id] = StreamStatsDictPort()
|
||||
# TODO: ssd.port[ss.port_id.id].aggr = dict()
|
||||
ssd.port[ss.port_id.id].sguid = dict()
|
||||
assert ss.stream_guid.id not in ssd.port[ss.port_id.id].sguid
|
||||
ssd.port[ss.port_id.id].sguid[ss.stream_guid.id] = ss
|
||||
|
||||
ssd.port[ss.port_id.id].total.tx_pkts += ss.tx_pkts
|
||||
ssd.port[ss.port_id.id].total.rx_pkts += ss.rx_pkts
|
||||
ssd.port[ss.port_id.id].total.tx_bytes += ss.tx_bytes
|
||||
ssd.port[ss.port_id.id].total.rx_bytes += ss.rx_bytes
|
||||
|
||||
if ss.stream_guid.id not in ssd.sguid:
|
||||
ssd.sguid[ss.stream_guid.id] = StreamStatsDictGuid()
|
||||
assert ss.port_id.id not in ssd.sguid[ss.stream_guid.id].port
|
||||
ssd.sguid[ss.stream_guid.id].port[ss.port_id.id] = ss
|
||||
ssd.sguid[ss.stream_guid.id].total.tx_pkts += ss.tx_pkts
|
||||
ssd.sguid[ss.stream_guid.id].total.rx_pkts += ss.rx_pkts
|
||||
ssd.sguid[ss.stream_guid.id].total.pkt_loss += \
|
||||
ss.tx_pkts - ss.rx_pkts
|
||||
return ssd
|
||||
|
@ -494,6 +494,7 @@ def test_unidir(drone, ports, dut, dut_ports, dut_ip, emul_ports, dgid_list,
|
||||
assert len(ssd.port) == 2
|
||||
assert len(ssd.port[ports.x_num].sguid) == num_sign_streams
|
||||
assert len(ssd.port[ports.y_num].sguid) == num_sign_streams
|
||||
assert len(ssd.sguid) == num_sign_streams
|
||||
|
||||
# dump X capture buffer
|
||||
log.info('getting X capture buffer')
|
||||
@ -589,9 +590,11 @@ def test_unidir(drone, ports, dut, dut_ports, dut_ip, emul_ports, dgid_list,
|
||||
assert ssd.port[ports.x_num].sguid[guid].tx_bytes \
|
||||
== ssd.port[ports.y_num].sguid[guid].rx_bytes
|
||||
|
||||
assert ssd.sguid[guid].total.tx_pkts \
|
||||
== ssd.sguid[guid].total.rx_pkts
|
||||
assert ssd.sguid[guid].total.pkt_loss == 0
|
||||
|
||||
# for unidir verify rx on tx port is 0 and vice versa
|
||||
# FIXME: failing currently because tx pkts on tx port seem to be
|
||||
# captured by rxStatsPoller_ on tx port
|
||||
assert ssd.port[ports.x_num].sguid[guid].rx_pkts == 0
|
||||
assert ssd.port[ports.x_num].sguid[guid].rx_bytes == 0
|
||||
assert ssd.port[ports.y_num].sguid[guid].tx_pkts == 0
|
||||
|
Loading…
Reference in New Issue
Block a user