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

## rrul test specification

include("netperf_definitions.inc")
DESCRIPTION="RTT Fair Realtime Response Under Load"
DEFAULTS={'PLOT': "all_scaled",
          'HOSTS': [
              'snapon.lab.bufferbloat.net',
              'demo.tohojo.dk']}

# This makes sure that four hosts are specified on the command line, and if not
# filles up the HOSTS list with input from the DEFAULTS above (repeating them if
# necessary).
min_host_count(4)

DATA_SETS = o([
    ('TCP upload BE %s' % HOSTS[0],
     {'command': "%s -Y CS0,CS0 -H %s -t TCP_STREAM -l %d -f m" % (GLOBAL_COMMAND, HOSTS[0], LENGTH),
      'delay': DELAY,
      'units': 'Mbits/s',
      'runner': 'netperf_demo',}),
    ('TCP upload BE %s' % HOSTS[1],
     {'command': "%s -Y CS0,CS0 -H %s -t TCP_STREAM -l %d -f m" % (GLOBAL_COMMAND, HOSTS[1], LENGTH),
      'delay': DELAY,
      'units': 'Mbits/s',
      'runner': 'netperf_demo',}),
    ('TCP upload BK %s' % HOSTS[2],
     {'command': "%s -Y CS1,CS1 -H %s -t TCP_STREAM -l %d -f m" % (GLOBAL_COMMAND, HOSTS[2], LENGTH),
      'delay': DELAY,
      'units': 'Mbits/s',
      'runner': 'netperf_demo',}),
    ('TCP upload BK %s' % HOSTS[3],
     {'command': "%s -Y CS1,CS1 -H %s -t TCP_STREAM -l %d -f m" % (GLOBAL_COMMAND, HOSTS[3], LENGTH),
       'delay': DELAY,
       'units': 'Mbits/s',
       'runner': 'netperf_demo',}),
    ('TCP upload avg',
     {'apply_to': [glob("TCP upload*", exclude=["TCP upload sum"])],
       'units': 'Mbits/s',
       'runner': 'average',}),
    ('TCP upload sum',
     {'apply_to': [glob("TCP upload*", exclude=["TCP upload avg"])],
       'units': 'Mbits/s',
       'runner': 'sum',}),

    ('TCP download BE %s' % HOSTS[0],
     {'command': "%s -Y CS0,CS0 -H %s -t TCP_MAERTS -l %d -f m" % (GLOBAL_COMMAND, HOSTS[0], LENGTH),
      'delay': DELAY,
      'units': 'Mbits/s',
      'runner': 'netperf_demo',}),
    ('TCP download BE %s' % HOSTS[1],
     {'command': "%s -Y CS0,CS0 -H %s -t TCP_MAERTS -l %d -f m" % (GLOBAL_COMMAND, HOSTS[1], LENGTH),
      'delay': DELAY,
      'units': 'Mbits/s',
      'runner': 'netperf_demo',}),
    ('TCP download BK %s' % HOSTS[2],
     {'command': "%s -Y CS1,CS1 -H %s -t TCP_MAERTS -l %d -f m" % (GLOBAL_COMMAND, HOSTS[2], LENGTH),
      'delay': DELAY,
      'units': 'Mbits/s',
      'runner': 'netperf_demo',}),
    ('TCP download BK %s' % HOSTS[3] ,
     {'command': "%s -Y CS1,CS1 -H %s -t TCP_MAERTS -l %d -f m" % (GLOBAL_COMMAND, HOSTS[3], LENGTH),
       'delay': DELAY,
       'units': 'Mbits/s',
       'runner': 'netperf_demo',}),
    ('TCP download avg',
     {'apply_to': [glob("TCP download*", exclude=["TCP download sum"])],
       'units': 'Mbits/s',
       'runner': 'average',}),
    ('TCP download sum',
     {'apply_to': [glob("TCP download*", exclude=["TCP download avg"])],
       'units': 'Mbits/s',
       'runner': 'sum',}),

    ('Ping (ms) ICMP %s' % HOSTS[0],
     {'command': find_ping(IP_VERSION, STEP_SIZE, TOTAL_LENGTH, HOSTS[0]),
      'units': 'ms',
      'runner': 'ping',}),
    ('Ping (ms) ICMP %s' % HOSTS[1],
     {'command': find_ping(IP_VERSION, STEP_SIZE, TOTAL_LENGTH, HOSTS[1]),
      'units': 'ms',
      'runner': 'ping',}),
    ('Ping (ms) ICMP %s' % HOSTS[2],
     {'command': find_ping(IP_VERSION, STEP_SIZE, TOTAL_LENGTH, HOSTS[2]),
      'units': 'ms',
      'runner': 'ping',}),
    ('Ping (ms) ICMP %s' % HOSTS[3],
     {'command': find_ping(IP_VERSION, STEP_SIZE, TOTAL_LENGTH, HOSTS[3]),
      'units': 'ms',
      'runner': 'ping',}),
    ('Ping (ms) avg',
     {'apply_to': [glob("Ping (ms)*")],
       'units': 'ms',
       'runner': 'average',}),
    ])

PLOTS = o([
    ('download',
     {'description': 'Download bandwidth plot',
      'type': 'timeseries',
      'legend_title': 'TCP download',
      'series': [{'data': 'TCP download BE %s' % HOSTS[0],
                  'label': 'BE %s' %HOSTS[0],
                  'linewidth': 2.0},
                 {'data': 'TCP download BE %s' % HOSTS[1],
                  'label': 'BE %s' % HOSTS[1] },
                 {'data': 'TCP download BK %s' % HOSTS[2],
                  'label': 'BK %s' % HOSTS[2] },
                 {'data': 'TCP download BK %s' % HOSTS[3],
                  'label': 'BK %s' % HOSTS[3]},
                 {'data': 'TCP download avg',
                  'label': 'Avg',
                  'smoothing': 10,
                  'color': 'black',
                  'linewidth': 2}]}),

    ('download_scaled',
     {'description': 'Download bandwidth w/axes scaled to remove outliers',
      'parent': 'download',
      'scaling': (5,95)}),

    ('upload',
     {'description': 'Upload bandwidth plot',
      'type': 'timeseries',
      'legend_title': 'TCP upload',
      'series': [{'data': 'TCP upload BE %s' % HOSTS[0],
                  'label': 'BE %s' % HOSTS[0],
                  'linewidth': 2.0},
                 {'data': 'TCP upload BE %s' % HOSTS[1],
                  'label': 'BE %s' % HOSTS[1]},
                 {'data': 'TCP upload BK %s' % HOSTS[2],
                  'label': 'BK %s' % HOSTS[2]},
                 {'data': 'TCP upload BK %s' % HOSTS[3],
                  'label': 'BK %s' % HOSTS[3]},
                 {'data': 'TCP upload avg',
                  'label': 'Avg',
                  'smoothing': 10,
                  'color': 'black',
                  'linewidth': 2}]}),

    ('upload_scaled',
     {'description': 'Upload bandwidth w/axes scaled to remove outliers',
      'parent': 'upload',
      'scaling': (5,95)}),

    ('ping',
     {'description': 'Ping plot',
      'type': 'timeseries',
      'legend_title': 'Ping (ms)',
      'series': [
                 {'data': 'Ping (ms) ICMP %s' % HOSTS[0],
                  'label': 'ICMP %s' % HOSTS[0] },
                 {'data': 'Ping (ms) ICMP %s' % HOSTS[0],
                  'label': 'ICMP %s' % HOSTS[0] },
                 {'data': 'Ping (ms) ICMP %s' % HOSTS[1],
                  'label': 'ICMP %s' % HOSTS[1] },
                 {'data': 'Ping (ms) ICMP %s' % HOSTS[2],
                  'label': 'ICMP %s' % HOSTS[2] },
                 {'data': 'Ping (ms) ICMP %s' % HOSTS[3],
                  'label': 'ICMP %s' % HOSTS[3] },
                 {'data': 'Ping (ms) avg',
                  'label': 'Avg',
                  'smoothing': 10,
                  'color': 'black',
                  'linewidth': 2}]}),

    ('ping_scaled',
     {'description': 'Ping w/axes scaled to remove outliers',
      'parent': 'ping',
      'scaling': (5,95)}),

    ('ping_cdf',
     {'description': 'Ping CDF plot',
      'type': 'cdf',
      'parent': 'ping',
      'cutoff': (DELAY,DELAY)}),

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

    ('totals',
     {'description': 'Total bandwidth and average ping plot',
      'type': 'timeseries',
      'dual_axes': True,
      'series': [{'data': 'TCP download sum',
                  'label': 'Download',
                  'smoothing': 10},
                 {'data': 'TCP upload sum',
                  'label': 'Upload',
                  'smoothing': 10},
                 {'data': 'Ping (ms) avg',
                  'label': 'Ping (ms)',
                  'smoothing': 10,
                  'color': 'red',
                  'axis': 2}]}),
    ('totals_scaled',
     {'description': 'Total bandwidth and average ping plot (scaled)',
      'parent': 'totals',
      'scaling': (5,95)}),

    ('all_scaled',
     {'description': 'Download, upload, ping (scaled versions)',
      'type': 'meta',
      'subplots': ('download_scaled', 'upload_scaled', 'ping_scaled')}),

    ('all',
     {'description': 'Download, upload, ping (unscaled versions)',
      'type': 'meta',
      'subplots': ('download', 'upload', 'ping')}),
    ])
