network_delay.py 6.32 KB
Newer Older
1 2 3 4 5 6 7 8 9
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

#   OpenBACH is a generic testbed able to control/configure multiple
#   network/physical entities (under test) and collect data from them. It is
#   composed of an Auditorium (HMIs), a Controller, a Collector and multiple
#   Agents (one for each network entity that wants to be tested).
#
#
Mathias Ettinger's avatar
Mathias Ettinger committed
10
#   Copyright © 2016-2020 CNES
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
#
#
#   This file is part of the OpenBACH testbed.
#
#
#   OpenBACH is a free software : you can redistribute it and/or modify it under
#   the terms of the GNU General Public License as published by the Free Software
#   Foundation, either version 3 of the License, or (at your option) any later
#   version.
#
#   This program is distributed in the hope that it will be useful, but WITHOUT
#   ANY WARRANTY, without even the implied warranty of MERCHANTABILITY or FITNESS
#   FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
#   details.
#
#   You should have received a copy of the GNU General Public License along with
#   this program. If not, see http://www.gnu.org/licenses/.

29 30
from scenario_builder import Scenario
from scenario_builder.helpers.network.fping import fping_measure_rtt
David Fernandes's avatar
David Fernandes committed
31
from scenario_builder.helpers.network.d_itg import ditg_packet_rate
32
from scenario_builder.helpers.postprocessing.time_series import time_series_on_same_graph
33
from scenario_builder.helpers.postprocessing.histogram import cdf_on_same_graph
34
from scenario_builder.helpers.admin.synchronization import synchronization
35
from scenario_builder.openbach_functions import StartJobInstance, StartScenarioInstance
36

37
SCENARIO_NAME = 'network_delay'
38 39
SCENARIO_DESCRIPTION = """This network_delay scenario allows to
compare the RTT measurement of fping (ICMP) and d-itg (UDP). It
40
can be configured to start the traffic either simultaneously or
41
sequentially.
42
It can then, optionally, plot the delay measurements using time-series and CDF.
43 44 45
"""


46 47
def delay_simultaneous(
        server_entity, client_entity, server_ip, client_ip, duration,
48
        max_synchro_off=None, synchronization_timeout=60, scenario_name=SCENARIO_NAME):
49
    scenario = Scenario(scenario_name, SCENARIO_DESCRIPTION)
50 51
    scenario.add_constant('server_ip', server_ip)
    scenario.add_constant('client_ip', client_ip)
52 53
    scenario.add_constant('duration', duration)

54 55

    wait_finished = []
56
    if max_synchro_off is not None and max_synchro_off > 0.0:
57 58 59 60 61
        synchro_ntp_client = synchronization(
                scenario, server_entity,
                max_synchro_off,
                synchronization_timeout)
        synchro_ntp_server = synchronization(
62 63
                scenario, client_entity,
                max_synchro_off, 
64
                synchronization_timeout)
65

66 67 68 69 70
        wait_finished = []
        for function in scenario.openbach_functions:
            if isinstance(function, StartJobInstance):
                wait_finished.append(function)

71 72 73 74
    srv = ditg_packet_rate(
            scenario, client_entity, server_entity,
            '$server_ip', '$client_ip', 'UDP', packet_rate=1,
            duration='$duration', meter='rttm',
75
            wait_finished=wait_finished)
76 77 78
    fping_measure_rtt(
            scenario, client_entity, '$server_ip', '$duration',
            wait_launched=srv, wait_delay=1,
79
            wait_finished=wait_finished)
80 81 82 83

    return scenario


84 85
def delay_sequential(
        server_entity, client_entity, server_ip, client_ip, duration,
86
        max_synchro_off=None, synchronization_timeout=60, scenario_name=SCENARIO_NAME):
87
    scenario = Scenario(scenario_name, SCENARIO_DESCRIPTION)
88 89
    scenario.add_constant('server_ip', server_ip)
    scenario.add_constant('client_ip', client_ip)
90 91
    scenario.add_constant('duration', duration)

92
    wait_finished = []
93
    if max_synchro_off is not None and max_synchro_off > 0.0:
94
        synchro_ntp_client = synchronization(
95 96
                scenario, client_entity,
                max_synchro_off,
97
                synchronization_timeout)
98 99 100 101 102 103 104 105 106
        synchro_ntp_server = synchronization(
                scenario, server_entity,
                max_synchro_off,
                synchronization_timeout)

        wait_finished = []
        for function in scenario.openbach_functions:
            if isinstance(function, StartJobInstance):
                wait_finished.append(function)
107 108 109 110 111

    ditg = ditg_packet_rate(
            scenario, client_entity, server_entity,
            '$server_ip', '$client_ip', 'UDP', packet_rate=1,
            duration='$duration', meter='rttm',
112
            wait_finished=wait_finished)
113 114 115
    fping_measure_rtt(
            scenario, client_entity, '$server_ip', '$duration',
            wait_finished=ditg)
116

117 118 119
    return scenario


120
def build(
121
        server_entity, client_entity, server_ip, client_ip,
122 123
        duration, simultaneous,
        max_synchro_off=None,
124
        synchronization_timeout=60,
125 126
        post_processing_entity=None, 
        scenario_name=SCENARIO_NAME):
127
    scenario = (delay_simultaneous if simultaneous else delay_sequential)(
128
            server_entity, client_entity,
129
            server_ip, client_ip, duration, 
130
            max_synchro_off, synchronization_timeout,
131
            scenario_name)
132

133
    if post_processing_entity is not None:
134 135 136 137
        waiting_jobs = []
        for function in scenario.openbach_functions:
            if isinstance(function, StartJobInstance):
                waiting_jobs.append(function)
138

139
        post_processed = list(scenario.extract_function_id('fping', 'd-itg_send'))
140
        legend = [['d-itg_send ({})'.format(client_entity)], ['fping ({})'.format(client_entity)]]
141 142 143 144 145 146 147
        time_series_on_same_graph(
                scenario,
                post_processing_entity,
                post_processed,
                [['rtt', 'rtt_sender']],
                [['RTT delay (ms)']],
                [['RTTs time series']],
148
                legend,
149 150 151
                filename='time_series_rtt_{}_{}'.format(client_entity, server_entity),
                wait_finished=waiting_jobs,
                wait_delay=2)
152 153 154 155 156 157 158 159
        cdf_on_same_graph(
                scenario,
                post_processing_entity,
                post_processed,
                100,
                [['rtt', 'rtt_sender']],
                [['RTT delay (ms)']],
                [['RTT CDF']],
160
                legend,
161 162 163
                filename='histogram_rtt_{}_{}'.format(client_entity, server_entity),
                wait_finished=waiting_jobs,
                wait_delay=2)
164

165
    return scenario