diff options
author | imarom <imarom@cisco.com> | 2016-03-03 18:10:29 +0200 |
---|---|---|
committer | imarom <imarom@cisco.com> | 2016-03-03 18:11:08 +0200 |
commit | f749b4358cfedd1ef7e0b58f69f63ee4d00554ea (patch) | |
tree | d9d87a4480eacfb290cef25ede72a37880198cb5 /scripts/automation/trex_control_plane | |
parent | 13cfb2c4ea55b7e0dab40155d8d51e7955ae4681 (diff) |
RX stats example "stl_rx_stream.py"
Diffstat (limited to 'scripts/automation/trex_control_plane')
4 files changed, 75 insertions, 15 deletions
diff --git a/scripts/automation/trex_control_plane/stl/examples/stl_rx_stream.py b/scripts/automation/trex_control_plane/stl/examples/stl_rx_stream.py index daff6105..023b9a75 100644 --- a/scripts/automation/trex_control_plane/stl/examples/stl_rx_stream.py +++ b/scripts/automation/trex_control_plane/stl/examples/stl_rx_stream.py @@ -4,7 +4,9 @@ from trex_stl_lib.api import * import time import pprint -def rx_example (tx_port, rx_port): +def rx_example (tx_port, rx_port, burst_size): + + print "\nGoing to inject {0} packets on port {1} - checking RX stats on port {2}\n".format(burst_size, tx_port, rx_port) # create client c = STLClient() @@ -12,7 +14,8 @@ def rx_example (tx_port, rx_port): try: pkt = STLPktBuilder(pkt = Ether()/IP(src="16.0.0.1",dst="48.0.0.1")/UDP(dport=12,sport=1025)/IP()/'a_payload_example') - total_pkts = 500000 + + total_pkts = burst_size s1 = STLStream(name = 'rx', packet = pkt, rx_stats = STLRxStats(user_id = 5), @@ -27,16 +30,38 @@ def rx_example (tx_port, rx_port): # add both streams to ports c.add_streams([s1], ports = [tx_port]) - print "injecting {0} packets on port {1}".format(total_pkts, tx_port) + print "injecting {0} packets on port {1}\n".format(total_pkts, tx_port) c.clear_stats() c.start(ports = [tx_port]) c.wait_on_traffic(ports = [tx_port]) - time.sleep(1) - stats = c.get_stats() - pprint.pprint(stats['rx_stats']) - print "port 3: ipackets {0}, ibytes {1}".format(stats[3]['ipackets'], stats[3]['ibytes']) - #rx_stas = stats['rx_stats'] + # no error check - just an example... should be 5 + rx_stats = c.get_stats()['rx_stats'][5] + + tx_pkts = rx_stats['tx-pkts'][tx_port] + tx_bytes = rx_stats['tx-bytes'][tx_port] + rx_pkts = rx_stats['rx-pkts'][rx_port] + + if tx_pkts != total_pkts: + print "TX pkts mismatch - got: {0}, expected: {1}".format(tx_pkts, total_pkts) + passed = False + return + else: + print "TX pkts match - {0}".format(tx_pkts) + + if tx_bytes != (total_pkts * pkt.get_pkt_len()): + print "TX bytes mismatch - got: {0}, expected: {1}".format(tx_bytes, (total_pkts * len(pkt))) + passed = False + return + else: + print "TX bytes match - {0}".format(tx_bytes) + + if rx_pkts != total_pkts: + print "RX pkts mismatch - got: {0}, expected: {1}".format(rx_pkts, total_pkts) + passed = False + return + else: + print "RX pkts match - {0}".format(rx_pkts) except STLError as e: @@ -53,5 +78,5 @@ def rx_example (tx_port, rx_port): # run the tests -rx_example(tx_port = 0, rx_port = 3) +rx_example(tx_port = 0, rx_port = 3, burst_size = 500000) diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py index 8da7c411..39d69178 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py @@ -156,7 +156,7 @@ class AsyncEventHandler(object): def handle_async_rx_stats_event (self, data): - self.client.rx_stats = data + self.client.rx_stats.update(data) # handles an async stats update from the subscriber @@ -433,13 +433,14 @@ class STLClient(object): self.global_stats = trex_stl_stats.CGlobalStats(self.connection_info, - self.server_version, - self.ports) + self.server_version, + self.ports) self.stats_generator = trex_stl_stats.CTRexInfoGenerator(self.global_stats, - self.ports) + self.ports) + + self.rx_stats = trex_stl_stats.CRxStats() - self.rx_stats = {} ############# private functions - used by the class itself ########### @@ -745,7 +746,7 @@ class STLClient(object): stats['total'] = total - stats['rx_stats'] = copy.deepcopy(self.rx_stats) + stats['rx_stats'] = self.rx_stats.get_stats() return stats diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_packet_builder_scapy.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_packet_builder_scapy.py index b2843ac3..dc787263 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_packet_builder_scapy.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_packet_builder_scapy.py @@ -870,6 +870,13 @@ class CScapyTRexPktBuilder(CTrexPktBuilderInterface): if isinstance(sc, CTRexScRaw): self._compile_raw(sc) + def get_pkt_len (self): + if self.pkt: + return len(self.pkt) + elif self.pkt_raw: + return len(self.pkt_raw) + else: + raise CTRexPacketBuildException(-14, "Packet is empty") #################################################### # private diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py index 620ccacd..eca7fd7a 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py @@ -643,6 +643,33 @@ class CPortStats(CTRexStats): } +class CRxStats(object): + def __init__(self): + self.rx_stats = {} + + + def update (self, snapshot): + self.rx_stats = snapshot + + + def get_stats (self): + stats = {} + for user_id, user_id_data in self.rx_stats.iteritems(): + # ignore non user ID keys + try: + user_id = int(user_id) + except ValueError: + continue + + # handle user id + stats[user_id] = {} + for field, per_port_data in user_id_data.iteritems(): + stats[user_id][field] = {} + for port, value in per_port_data.iteritems(): + stats[user_id][field][int(port)] = value + + return stats + if __name__ == "__main__": pass |