## -*- mode: python; coding: utf-8 -*-

## rrul test specification

AGGREGATOR='timeseries'
TOTAL_LENGTH=LENGTH
DESCRIPTION="Latency measurements under intermittent UDP bursts"
DEFAULTS={'PLOT': "ping"}

DATA_SETS = o([
    ('Ping (ms) UDP EF',
     {'command': find_netperf("UDP_RR", LENGTH, HOST, marking="EF,EF"),
      'data_transform': 'rr_to_ms',
      'units': 'ms',
      'runner': 'netperf_demo',}),
    ('Ping (ms) UDP BK',
     {'command': find_netperf("UDP_RR", LENGTH, HOST, marking="CS1,CS1"),
      'data_transform': 'rr_to_ms',
      'units': 'ms',
      'runner': 'netperf_demo',}),
    ('Ping (ms) UDP BE',
     {'command': find_netperf("UDP_RR", LENGTH, HOST),
      'data_transform': 'rr_to_ms',
      'units': 'ms',
      'runner': 'netperf_demo',}),
    ('Ping (ms) ICMP',
     {'command': find_ping(IP_VERSION, STEP_SIZE, LENGTH, HOST),
      'units': 'ms',
      'runner': 'ping',}),
    ('Ping (ms) avg',
     {'apply_to': [glob("Ping (ms)*")],
       'units': 'ms',
       'runner': 'average',}),
    ])

TEST_PARAMETERS['burst_ports'] = parse_int(try_test_parameters(('burst_ports', 'burst-ports'), 1000))
TEST_PARAMETERS['burst_length'] = parse_int(try_test_parameters(('burst_length', 'burst-length'), 5))
TEST_PARAMETERS['burst_psize'] = parse_int(try_test_parameters(('burst_psize', 'burst-psize'), 500))
TEST_PARAMETERS['burst_tos'] = parse_int(try_test_parameters(('burst_tos', 'burst-tos'), 0))

TOS = ("-t %s" % TEST_PARAMETERS['burst_tos']) if TEST_PARAMETERS['burst_tos'] else ""

BURST_LENGTH=TEST_PARAMETERS['burst_length']

for i in range(LENGTH//(DELAY+BURST_LENGTH)):
    DATA_SETS['Burst %d' % i] = {
        'command': "traffic-gen -f %s -p 0 -l %d -s %s -dD %s %s" % (
            TEST_PARAMETERS['burst_ports'],
            TEST_PARAMETERS['burst_length'],
            TEST_PARAMETERS['burst_psize'],
            TOS,
            HOST),
        'delay': DELAY*(i+1)+BURST_LENGTH*i,
        'units': 'N/A',
        'runner': 'silent_process',}

PLOTS = o([
    ('ping',
     {'description': 'Ping plot',
      'type': 'timeseries',
      'legend_title': 'Ping (ms)',
      'axis_labels': ['Latency (ms)'],
      'series': [
                 {'data': 'Ping (ms) UDP BE',
                  'label': 'UDP BE'},
                 {'data': 'Ping (ms) UDP BK',
                  'label': 'UDP BK'},
                 {'data': 'Ping (ms) ICMP',
                  'label': 'ICMP'},
		 {'data': 'Ping (ms) UDP EF',
                  'label': 'UDP EF'},
                 {'data': 'Ping (ms) avg',
                  'label': 'Avg',
                  'smoothing': 10,
                  'color': 'black',
                  'linewidth': 2}]}),

    ('ping_cdf',
     {'description': 'Ping CDF plot',
      'type': 'cdf',
      'axis_labels': ['Latency (ms)'],
      'parent': 'ping',
      'cutoff': (DELAY,DELAY)}),

    ('icmp_cdf',
     {'description': 'ICMP CDF plot',
      'type': 'cdf',
      'axis_labels': ['Latency (ms)'],
      'series': [{'data': 'Ping (ms) ICMP',
                  'label': 'Ping (ms)'},
                 ],
      'cutoff': (DELAY,DELAY)}),

    ('box_ping',
     {'description': 'Ping box plot',
      'parent': 'ping',
      'type': 'box'}),

    ('qq_icmp',
     {'description': 'Q-Q plot of ICMP pings',
      'type': 'qq',
      'series': [{'data': 'Ping (ms) ICMP',
                  'label': 'Latency (ms)'},
                 ]}),

    ])
