aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_srv6_ad_flow.py
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2021-05-28 18:28:05 -0700
committerFlorin Coras <fcoras@cisco.com>2021-05-28 18:48:22 -0700
commitb6fe52f3da79d4c4ea8095b9d36988b0825a9891 (patch)
treed33814a1f71a662b83b31137d34c4eefe0e44ae9 /test/test_srv6_ad_flow.py
parent5c520919e838bcb645ddd879641d54c620740989 (diff)
tls: fix handling of failed accepts
Type: fix Signed-off-by: Florin Coras <fcoras@cisco.com> Change-Id: I34b53dcaf4f049157b538ea40a39033d43e525a5
Diffstat (limited to 'test/test_srv6_ad_flow.py')
0 files changed, 0 insertions, 0 deletions
bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
import stl_path
from trex_stl_lib.api import *
import argparse
import sys


def inject_pcap (c, pcap_file, port, loop_count, ipg_usec, duration):

    pcap_file = os.path.abspath(pcap_file)

    c.reset(ports = [port])
    c.push_remote(pcap_file, ports = [port], ipg_usec = ipg_usec, speedup = 1.0, count = loop_count, duration = duration)
    # assume 100 seconds is enough - but can be more
    c.wait_on_traffic(ports = [port], timeout = 100)

    stats = c.get_stats()
    opackets = stats[port]['opackets']

    return opackets
    #print("{0} packets were Tx on port {1}\n".format(opackets, port))

    

def setParserOptions():
    parser = argparse.ArgumentParser(prog="stl_pcap.py")

    parser.add_argument("-f", "--file", help = "pcap file to inject",
                        dest = "pcap",
                        required = True,
                        type = str)

    parser.add_argument("-s", "--server", help = "TRex server address",
                        dest = "server",
                        default = 'localhost',
                        type = str)

    parser.add_argument("-p", "--port", help = "port to inject on",
                        dest = "port",
                        required = True,
                        type = int)

    parser.add_argument("-n", "--number", help = "How many times to inject pcap [default is 1, 0 means forever]",
                        dest = "loop_count",
                        default = 1,
                        type = int)

    parser.add_argument("-i", help = "IPG in usec",
                        dest = "ipg",
                        default = None,
                        type = float)

    parser.add_argument("-d", help = "duration in seconds",
                        dest = "duration",
                        default = -1,
                        type = float)

    return parser

def sizeof_fmt(num, suffix='B'):
    for unit in ['','Ki','Mi','Gi','Ti','Pi','Ei','Zi']:
        if abs(num) < 1024.0:
            return "%3.1f%s%s" % (num, unit, suffix)
        num /= 1024.0
    return "%.1f%s%s" % (num, 'Yi', suffix)


def read_txt_file (filename):

    with open(filename) as f:
        lines = f.readlines()

    caps = []
    for raw in lines:
       raw = raw.rstrip()
       if raw[0] == '#':
           continue
       ext=os.path.splitext(raw)[1]
       if ext not in ['.cap', '.pcap', '.erf']:
           # skip unknown format
           continue
    
       caps.append(raw)

    return caps


def start (args):
    
    parser = setParserOptions()
    options = parser.parse_args(args)
    
    ext = os.path.splitext(options.pcap)[1]
    if ext == '.txt':
        caps = read_txt_file(options.pcap)
    elif ext in ['.cap', '.pcap']:
        caps = [options.pcap]
    else:
        print("unknown file extension for file {0}".format(options.pcap))
        return

    c = STLClient(server = options.server)
    try:
        c.connect()
        for i, cap in enumerate(caps, start = 1):
            before = time.time()
            print ("{:} CAP {:} @ {:} - ".format(i, cap, sizeof_fmt(os.path.getsize(cap)))),
            injected = inject_pcap(c, cap, options.port, options.loop_count, options.ipg, options.duration)
            print("took {:.2f} seconds for {:} packets").format(time.time() - before, injected)

    except STLError as e:
        print(e)
        return

    finally:
        c.disconnect()

def main ():
    start(sys.argv[1:])

# inject pcap
if __name__ == '__main__':
    main()