def conduct_path_hopping_trial(results_repository, the_trial):
    hosts = {}
    flow_allocation_seed_number = the_trial.get_parameter("seed-number")
    flows = the_trial.get_parameter("flow-set")
    flow_tokens = set()
    tag_values = defaultdict(int)

    try:
        id_to_dpid = topo_mapper.get_and_validate_onos_topo_x(TARGET_GRAPH)
        hosts = create_virtual_hosts(id_to_dpid)
        for host in hosts.values():
            host.start_traffic_generation_server()

        for flow in flows:
            source_node, destination_node, flow_tx_rate = (
                flow.source_node, flow.destination_node, flow.flow_tx_rate)

            flow_json, tag_values_for_flow = simple_paths_to_flow_json(
                flow.paths, tag_values, id_to_dpid)
            flow_token = onos_route_adder.install_flow(flow_json)
            flow_tokens.add(flow_token)
            scaled_flow_tx_rate = scale_flow_tx_rate(flow_tx_rate)
            hosts[source_node + 1].configure_flow(
                scaled_flow_tx_rate, 0.0, "uniform",
                hosts[destination_node + 1].virtual_host_ip, 50000,
                flow.splitting_ratio, 10, tag_values_for_flow)

        traffic_monitor = stat_monitor.OnMonitor(cfg.of_controller_ip,
                                                 cfg.of_controller_port)
        traffic_monitor.start_monitor()
        for host in hosts.values():
            host.start_traffic_generation_client()
        # input("Hosts have been created and flows have been added. Press enter to continue...")
        time.sleep(the_trial.get_parameter("duration"))
        traffic_monitor.stop_monitor()
        utilization_results = traffic_monitor.get_monitor_statistics()
        the_trial.add_parameter("byte-counts-over-time", utilization_results)
        the_trial.add_parameter(
            "link-utilization-over-time",
            compute_link_utilization_over_time(utilization_results))
        the_trial.add_parameter(
            "measured-link-utilization",
            compute_mean_link_utilization(utilization_results))
    except Exception as ex:
        traceback.print_exc()
        print(ex)
        input(
            "Failed to carry out path hopping test. Press enter to continue..."
        )
    finally:
        destroy_all_hosts(hosts)
        remove_all_flows(flow_tokens)
def build_tuiti_trial_provider():
    id_to_dpid = topo_mapper.get_and_validate_onos_topo_x(EXPECTED_TOPO)
    source_node, destination_node = (0, 1)
    disjoint_paths = list(node_disjoint_paths(EXPECTED_TOPO, source_node, destination_node))
    the_trial_provider = trial_provider.TrialProvider("tuiti-trial-provider")
    trial_file_directory = path.Path("/home/alexj/repos/inter-dc/trial-parameters/")
    trials = TuitiTrial.batch_from_directory(trial_file_directory, id_to_dpid, EXPECTED_TOPO)
    for the_trial in [t for t in trials 
            # if t.get_parameter("maximum-bandwidth-variation") == 50
            # and t.name == "eb-99"
            ]:
        the_trial_provider.add_trial(the_trial)
    return the_trial_provider
def serialization_testing():
    dir_path = path.Path("/home/alexj/repos/inter-dc/trial-parameters")
    id_to_dpid = topo_mapper.get_and_validate_onos_topo_x(EXPECTED_TOPO)
    trials = TuitiTrial.batch_from_directory(dir_path, id_to_dpid, EXPECTED_TOPO)
    for trial in trials:
        # if trial.name == "eb":
        #     confidence_interval = trial.get_parameter("confidence-interval")
        #     print(f"confidence interval is {confidence_interval}")
        print("Mean demand: %s" % trial.get_parameter("mean-flow-demand"))
        if trial.name == "ts":
            sample_flow = next(iter(trial.get_parameter("flow-set")))
            print(sample_flow.flow_tx_rate)

    pp.pprint([trial.name for trial in trials])
Esempio n. 4
0
def test_virtual_host_installation():
    id_to_dpid = topo_mapper.get_and_validate_onos_topo_x(SUBSTRATE_TOPOLOGY)
    sender, receiver = None, None
    # add_path_hopping_delays("ens192", 9, lambda: int(np.random.uniform(0, 1000)))
    while True:
        try:
            sender, receiver = create_sender_receiver_pair(id_to_dpid)
        except Exception as ex:
            print(ex)
            print("Failed to create sender or receiver")
        input("Okay do stuff now...") 
        try:
            destroy_sender_receiver_pair(sender, receiver)
            # remove_path_hopping_delays("ens192")
        except Exception:
            pass
        break
def build_mininet_test_trial_provider():

    id_to_dpid = topo_mapper.get_and_validate_onos_topo_x(EXPECTED_TOPO)
    source_node, destination_node = (0, 1) 
    print(source_node, destination_node)
    disjoint_paths = list(node_disjoint_paths(EXPECTED_TOPO, source_node, destination_node))
    the_trial_provider = trial_provider.TrialProvider("mininet-trial")
    flow_set = trial_provider.FlowSet()
    the_trial = trial_provider.Trial("mininet-test")
    the_trial.add_parameter("duration", 120)

    flow_tx_rate = 131072 * 100
    the_flow = trial_provider.Flow( source_node        = source_node
                                  , destination_node   = destination_node
                                  , flow_tx_rate       = flow_tx_rate
                                  , paths              = disjoint_paths
                                  , splitting_ratio    = [1.0] + [0]*(len(disjoint_paths)-1)
                                  )
    flow_set.add_flows([the_flow])
    the_trial.add_parameter("seed-number", 0)
    the_trial.add_parameter("flow-set", flow_set)
    the_trial.add_parameter("traffic-sampling-distribution", "uniform")
    the_trial_provider.add_trial(the_trial)
    return the_trial_provider
Esempio n. 6
0
def conduct_path_hopping_trial(results_repository, the_trial):
    def stringify(value):
        return value if type(value) == str else str(value)

    def get_sender_kwargs(the_trial):
        sender_kwargs = { "port"            : the_trial.get_parameter("port")
                        , "K"               : the_trial.get_parameter("K")
                        , "N"               : the_trial.get_parameter("N")
                        , "data_file"       : the_trial.get_parameter("input-file")
                        , "message_size"    : the_trial.get_parameter("message-size")
                        , "timestep"        : the_trial.get_parameter("timestep")
                        , "hop_probability" : the_trial.get_parameter("lambda")
                        , "reliable"        : the_trial.get_parameter("reliable")
                        , "hop_method"      : the_trial.get_parameter("hop")
                        }
        sender_kwargs = {kw: stringify(arg) for kw, arg in sender_kwargs.items()}
        return sender_kwargs

    def get_receiver_kwargs(the_trial, sender_ip):
        receiver_kwargs = { "sender_ip"             : sender_ip
                          , "port"                  : the_trial.get_parameter("port")
                          , "data_file"             : the_trial.get_parameter("output-file")
                          , "timestep"              : the_trial.get_parameter("timestep")
                          , "hopping_probability"   : the_trial.get_parameter("lambda")
                          }
        receiver_kwargs = {kw: stringify(arg) for kw, arg in receiver_kwargs.items()}
        return receiver_kwargs

    def collect_mpc_sender_hopping_times():
        hopping_times_record_path = path.Path("./hopping-time-record.txt")
        hopping_times_text = hopping_times_record_path.read_text()
        hopping_times = [int(s_i) for s_i in hopping_times_text.splitlines()]
        hopping_times_record_path.unlink()
        return hopping_times

    sender, receiver, packet_capture = None, None, None
    try:
        id_to_dpid = topo_mapper.get_and_validate_onos_topo_x(SUBSTRATE_TOPOLOGY)

        sender, receiver = create_sender_receiver_pair(id_to_dpid)
        time.sleep(10)

        packet_capture = pcap.InterfaceCapture("ens192")
        traffic_monitor = stat_monitor.OnMonitor(cfg.of_controller_ip, cfg.of_controller_port)

        packet_capture.start_capture()
        traffic_monitor.start_monitor()

        sender.start_path_hopping_sender(**get_sender_kwargs(the_trial))

        start_time = time.time()
        receiver.start_path_hopping_receiver(
                **get_receiver_kwargs(the_trial, sender.virtual_host_ip))
    
        print("Waiting on the receiver to terminate...")
        receiver.wait_until_done()
        end_time = time.time()
        print("Receiver has terminated.")
        elapsed_tx_time = end_time - start_time
        traffic_monitor.stop_monitor()
        utilization_results = traffic_monitor.get_monitor_statistics()

        packet_capture.stop_capture()
        packets = packet_capture.process_capture_data()
        
        hopping_times = collect_mpc_sender_hopping_times()
        print("Captured %d packets" % len(packets))

        the_trial.add_parameter("packet-dump", packets)
        the_trial.add_parameter("measured-link-utilization", utilization_results)
        the_trial.add_parameter("link-utilization-over-time",
                compute_link_utilization_over_time(utilization_results))
        the_trial.add_parameter("elapsed-tx-time", elapsed_tx_time)
        the_trial.add_parameter("hopping-times", hopping_times)
    except Exception as ex:
        traceback.print_exc()
        print(ex)
        input("Failed to carry out path hopping attacker test. Press enter to continue...")
    finally:
        destroy_sender_receiver_pair(sender, receiver)
        if packet_capture != None and packet_capture.is_capture_running():
            packet_capture.stop_capture()
def conduct_test_mininet_trial(results_reposity, the_trial):
    hosts                           = {}
    flow_allocation_seed_number     = the_trial.get_parameter("seed-number")
    flows                           = the_trial.get_parameter("flow-set")
    flow_tokens                     = set()
    tag_values                      = defaultdict(int)

    try:
        id_to_dpid  = topo_mapper.get_and_validate_onos_topo_x(EXPECTED_TOPO)
        pp.pprint(id_to_dpid)
        hosts       = create_mininet_hosts(id_to_dpid, [0, 1])

        for host in hosts.values():
            host.start_traffic_generation_server()
            # print(f"PID of server on host with IP {host.host_ip} is {host.server_proc.pid}")
        
        source_node, destination_node = (0, 1)
        flow_rate_list = [1310720]*300
        hosts[source_node].configure_flow_with_precomputed_transmit_rates(flow_rate_list,
                hosts[destination_node].host_ip, 50000, [1.0, 0.0, 0.0, 0.0, 0.0], hosts[source_node].host_id,
                10, [0, 0, 0, 0, 0])
        # for flow_id, flow in enumerate(flows):
        #     source_node, destination_node, flow_tx_rate = (flow.source_node, flow.destination_node,
        #             flow.flow_tx_rate)
        #     flow_json, tag_values_for_flow = simple_paths_to_flow_json(flow.paths, tag_values, id_to_dpid)
        #     flow_token = onos_route_adder.install_flow(flow_json)
        #     flow_tokens.add(flow_token)

        #     # ======================================= For Testing ======================================= 
        #     hosts[flow.source_node].configure_flow(flow.flow_tx_rate, 0.0, 
        #         the_trial.get_parameter("traffic-sampling-distribution"), hosts[flow.destination_node].host_ip,
        #         50000, [1.0] + [0.0]*(len(flow.paths)-1), 100, [0]*len(flow.paths))
        #     # ======================================= End Testing ======================================= 


        # print(f"Tag values:\n{tag_values_for_flow}")
        time.sleep(10)
        traffic_monitor = stat_monitor.OnMonitor(cfg.of_controller_ip, cfg.of_controller_port)
        traffic_monitor.start_monitor()

        for host in hosts.values():
            host.start_traffic_generation_client()
        
        traffic_generation_client_pid = hosts[0].client_proc.pid
        print(f"PID of traffic generation client: {traffic_generation_client_pid}")

        # print(f"Trial duration is {the_trial.get_parameter('duration')}")
        # time.sleep(the_trial.get_parameter("duration"))
        # time.sleep(300)
        input("Press enter to continue...")

        for host in hosts.values():
            host.stop_traffic_generation_client()

        for host in hosts.values():
            host.stop_traffic_generation_server()

        traffic_monitor.stop_monitor()
        
        utilization_results = traffic_monitor.get_monitor_statistics()
        link_utilization_over_time = stat_monitor.compute_link_utilization_over_time(utilization_results)
        mean_link_utilization = stat_monitor.compute_mean_link_utilization(utilization_results)
        end_host_results = collect_end_host_results(hosts)
        path.Path("./mean-link-utilization.txt").write_text(pp.pformat(mean_link_utilization))
        path.Path("./raw-utilization-results.txt").write_text(pp.pformat(utilization_results))
        path.Path("./host-utilization-results.txt").write_text(pp.pformat(end_host_results))
        pp.pprint(end_host_results)

        the_trial.add_parameter("byte-counts-over-time", utilization_results)
        # pp.pprint(utilization_results)
    except Exception as ex:
        print(ex)
        exc_type, exc_value, exc_traceback = sys.exc_info()
        traceback.print_tb(exc_traceback, limit=10, file=sys.stdout)
    finally:
        destroy_all_mininet_hosts(hosts)
        remove_all_flows(flow_tokens)
def conduct_mininet_trial(results_repository, schema_vars, the_trial_provider, the_trial):
    hosts                           = {}
    flow_allocation_seed_number     = the_trial.get_parameter("seed-number")
    flows                           = the_trial.get_parameter("flow-set")
    flow_tokens                     = set()
    tag_values                      = defaultdict(int)

    try:
        id_to_dpid  = topo_mapper.get_and_validate_onos_topo_x(EXPECTED_TOPO)
        # pp.pprint(id_to_dpid)
        hosts       = create_mininet_hosts(id_to_dpid, [0, 1])

        for host in hosts.values():
            host.start_traffic_generation_server()
            # print(f"PID of server on host with IP {host.host_ip} is {host.server_proc.pid}")
        
        k_matrix = [0.0]*len(flows)
        for flow_id, flow in enumerate(flows):
            source, destination_node, flow_tx_rate_list = (flow.source_node, flow.destination_node, 
                    flow.flow_tx_rate)
            flow_json, tag_values_for_flow = simple_paths_to_flow_json(flow.paths, tag_values, id_to_dpid)
            flow_token = onos_route_adder.install_flow(flow_json)
            flow_tokens.add(flow_token)

            # k_matrix is the splitting ratio
            # tag_values indicate which DSCP tag to use for the path. I think we want a K-matrix that looks
            # kind of like this:
            #
            #                                           1 0 0 0 0
            #                                           0 1 0 0 0
            #                                           0 0 1 0 0
            #                                           0 0 0 1 0
            #                                           0 0 0 0 1
            k_matrix[flow_id] = 1.0
            hosts[flow.source_node].configure_flow_with_precomputed_transmit_rates(
                    flow_tx_rate_list, hosts[flow.destination_node].host_ip, 50000, 
                    pycopy.copy(k_matrix), hosts[flow.source_node].host_id, 
                    1, tag_values_for_flow, flow_id)
            k_matrix[flow_id] = 0.0

            # print(f"Flow source node: {flow.source_node}. Flow destination node: {flow.destination_node}")
            # print(f"Flow source IP: {hosts[flow.source_node].host_ip}, Flow destination IP: {hosts[flow.destination_node].host_ip}")

        for flow_id, background_flow in enumerate(the_trial.get_parameter("background-traffic-flow-set")):
            source, destination, flow_tx_rate_list = (background_flow.source_node, 
                    background_flow.destination_node, background_flow.flow_tx_rate)
            # @TODO: Another thing I need to think about is whether I should have separate flow rules
            #        (i.e. separate DSCP values) for the foreground and background traffic. I don't think
            #        that it would be necessary to have them but it might be useful as it would allow me 
            #        to use ONOS to monitor transmission rates of background and foreground traffic separately.
            #        Might be able to do that with port numbers too but that would probably be more difficult/
            #        annoying. As an alternative the traffic generation clients will record the number of packtes
            #        for foreground and background traffic but you can only calculate average transmit rate
            #        over the course of the entire flow, not on a per timeslot basis.
            # flow_json, tag_values_for_flow = simple_paths_to_flow_json(flow.paths, tag_values, id_to_dpid)
            # flow_token = onos_route_adder.install_flow(flow_json)
            # flow_tokens.add(flow_token)

            # @TODO: I think the values that I'm getting from the solver are actually link capacity,
            #        not the volume of background traffic. So rather than using those values directly 
            #        to compute a transmit rate, I need to compute (link_capacity - value_from_solver)
            #        and then use that to derive a transmission rate. 
            k_matrix[flow_id] = 1.0
            hosts[background_flow.source_node].configure_flow_with_precomputed_transmit_rates(
                    flow_tx_rate_list, hosts[background_flow.destination_node].host_ip, 50000,
                    pycopy.copy(k_matrix), hosts[background_flow.source_node].host_id,
                    1, tag_values_for_flow, flow_id)
            k_matrix[flow_id] = 0.0


        # print(f"Tag values:\n{tag_values_for_flow}")
        time.sleep(10)
        traffic_monitor = stat_monitor.OnMonitor(cfg.of_controller_ip, cfg.of_controller_port)
        traffic_monitor.start_monitor()

        for host in hosts.values():
            host.start_traffic_generation_client()

        traffic_generation_pids = [proc.pid for proc in hosts[0].client_procs]
        print(f"PIDs of traffic generation process': {traffic_generation_pids}")  
        trial_duration = the_trial.get_parameter("duration")
        # trial_duration = 10
        for idx in progressbar.progressbar(range(int(trial_duration))):
            time.sleep(1.0)
        # input("Press enter to continue...")

        for host in hosts.values():
            host.stop_traffic_generation_client()

        for host in hosts.values():
            host.stop_traffic_generation_server()

        traffic_monitor.stop_monitor()
        
        utilization_results = traffic_monitor.get_monitor_statistics()
        link_utilization_over_time = stat_monitor.compute_link_utilization_over_time(utilization_results)
        mean_link_utilization = stat_monitor.compute_mean_link_utilization(utilization_results)
        end_host_results = collect_end_host_results(hosts)
        path.Path("./mean-link-utilization.txt").write_text(pp.pformat(mean_link_utilization))
        path.Path("./raw-utilization-results.txt").write_text(pp.pformat(utilization_results))
        path.Path("./host-utilization-results.txt").write_text(pp.pformat(end_host_results))

        the_trial.add_parameter("byte-counts-over-time", utilization_results)
        the_trial.add_parameter("link-utilization-over-time", link_utilization_over_time)
        the_trial.add_parameter("measured-link-utilization", mean_link_utilization)
        the_trial.add_parameter("end-host-results", end_host_results)
    except Exception as ex:
        print(ex)
        exc_type, exc_value, exc_traceback = sys.exc_info()
        traceback.print_tb(exc_traceback, limit=10, file=sys.stdout)
    finally:
        destroy_all_mininet_hosts(hosts)
        remove_all_flows(flow_tokens)