X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=resources%2Ftools%2Ftrex%2Ftrex_stateless_profile.py;h=15e21570574316923ea5354f70e4ca4a982115de;hb=refs%2Fchanges%2F01%2F20001%2F3;hp=aa68a014b804f9a853a2fd9c903b7c80d212966b;hpb=ac259ea21d8663dbdaea21589bace5f5f8ea94c7;p=csit.git diff --git a/resources/tools/trex/trex_stateless_profile.py b/resources/tools/trex/trex_stateless_profile.py index aa68a014b8..15e2157057 100755 --- a/resources/tools/trex/trex_stateless_profile.py +++ b/resources/tools/trex/trex_stateless_profile.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 # Copyright (c) 2019 Cisco and/or its affiliates. # Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,10 +22,9 @@ import sys import argparse import json -sys.path.insert(0, "/opt/trex-core-2.35/scripts/automation/" - "trex_control_plane/stl/") - -from trex_stl_lib.api import * +sys.path.insert(0, "/opt/trex-core-2.54/scripts/automation/" + "trex_control_plane/interactive/") +from trex.stl.api import * def fmt_latency(lat_min, lat_avg, lat_max): @@ -40,7 +39,6 @@ def fmt_latency(lat_min, lat_avg, lat_max): :return: Formatted and rounded output "min/avg/max" :rtype: string """ - try: t_min = int(round(float(lat_min))) except ValueError: @@ -97,7 +95,6 @@ def simple_burst(profile_file, duration, framesize, rate, warmup_time, port_0, :type async_start: bool :type unidirection: bool """ - client = None total_rcvd = 0 total_sent = 0 @@ -118,7 +115,7 @@ def simple_burst(profile_file, duration, framesize, rate, warmup_time, port_0, try: # Create the client: - client = STLClient(verbose_level=LoggerApi.VERBOSE_QUIET) + client = STLClient() # Connect to server: client.connect() # Prepare our ports (the machine has 0 <--> 1 with static route): @@ -126,8 +123,7 @@ def simple_burst(profile_file, duration, framesize, rate, warmup_time, port_0, client.remove_all_streams(ports=[port_0, port_1]) if "macsrc" in profile_file: - client.set_port_attr(ports=[port_0, port_1], promiscuous=True, - resolve=False) + client.set_port_attr(ports=[port_0, port_1], promiscuous=True) if isinstance(framesize, int): client.add_streams(streams[0], ports=[port_0]) if not unidirection: @@ -170,8 +166,7 @@ def simple_burst(profile_file, duration, framesize, rate, warmup_time, port_0, stats = client.get_stats() print("##### Warmup statistics #####") - print(json.dumps(stats, indent=4, separators=(',', ': '), - sort_keys=True)) + print(json.dumps(stats, indent=4, separators=(',', ': '))) lost_a = stats[port_0]["opackets"] - stats[port_1]["ipackets"] if not unidirection: @@ -203,8 +198,7 @@ def simple_burst(profile_file, duration, framesize, rate, warmup_time, port_0, stats = client.get_stats() print("##### Statistics #####") - print(json.dumps(stats, indent=4, separators=(',', ': '), - sort_keys=True)) + print(json.dumps(stats, indent=4, separators=(',', ': '))) lost_a = stats[port_0]["opackets"] - stats[port_1]["ipackets"] if not unidirection: @@ -234,8 +228,8 @@ def simple_burst(profile_file, duration, framesize, rate, warmup_time, port_0, print("packets lost from {p_1} --> {p_0}: {v} pkts".format( p_0=port_0, p_1=port_1, v=lost_b)) - except STLError as err: - sys.stderr.write("{0}\n".format(err)) + except STLError as ex_error: + print(ex_error, file=sys.stderr) sys.exit(1) finally: @@ -245,10 +239,6 @@ def simple_burst(profile_file, duration, framesize, rate, warmup_time, port_0, else: if client: client.disconnect() - if isinstance(rate, unicode): - rate = rate.encode("utf-8") - if isinstance(duration, unicode): - duration = duration.encode("utf-8") print("rate={0!r}, totalReceived={1}, totalSent={2}, " "frameLoss={3}, latencyStream0(usec)={4}, " "latencyStream1(usec)={5}, targetDuration={d!r}". @@ -262,7 +252,6 @@ def main(): It verifies the given command line arguments and runs "simple_burst" function. """ - parser = argparse.ArgumentParser() parser.add_argument("-p", "--profile", required=True,