def send_one_byte_at_a_time(middlebox_module, testing_part_1):
    middlebox1 = middlebox_module.WanOptimizer()
    middlebox2 = middlebox_module.WanOptimizer()
    wide_area_network = wan.Wan(middlebox1, middlebox2)

    # Iniitialize client connected to middlebox 1.
    client1_address = "1.2.3.4"
    client1_output_filename = "{}_output".format(client1_address)
    client1 = simple_client.SimpleClient(client1_address, middlebox1,
                                         client1_output_filename)

    # Initialize client connected to middlebox 2.
    client2_address = "5.6.7.8"
    client2_output_filename = "{}_output".format(client2_address)
    client2 = simple_client.SimpleClient(client2_address, middlebox2,
                                         client2_output_filename)

    sent_data = ""
    for _ in range(
            80000
    ):  # 8KB * 10 bytes so that we get a block end somewhere for part 2
        random_byte = os.urandom(1)
        client1.send_data(random_byte, client2_address)
        sent_data += random_byte
    client1.send_fin(client2_address)
    # Verify that the correct data was received.
    if not client2.received_fin:
        raise Exception("Client 2 never received a fin")
    test_utils.verify_data_sent_equals_data_received(sent_data,
                                                     client2_output_filename)
    os.remove(client1_output_filename)  # I have no idea why we need this.
    os.remove(client2_output_filename)
def verify_middlebox_handles_interleaved_data(middlebox_module,
                                              is_testing_part1):
    middlebox1 = middlebox_module.WanOptimizer()
    middlebox2 = middlebox_module.WanOptimizer()
    wide_area_network = wan.Wan(middlebox1, middlebox2)

    # Iniitialize client connected to middlebox 1.
    client1_address = "1.2.3.4"
    client1_output_filename = "{}_output".format(client1_address)
    client1 = simple_client.SimpleClient(client1_address, middlebox1,
                                         client1_output_filename)

    # Initialize 2 clients connected to middlebox 2.
    client2_address = "5.6.7.8"
    client2_output_filename = "{}_output".format(client2_address)
    client2 = simple_client.SimpleClient(client2_address, middlebox2,
                                         client2_output_filename)

    client3_address = "5.6.7.9"
    client3_output_filename = "{}_output".format(client3_address)
    client3 = simple_client.SimpleClient(client3_address, middlebox2,
                                         client3_output_filename)

    # Send part of a block from client 1 to client 2.
    first_client2_block = "a" * 3000
    client1.send_data(first_client2_block, client2_address)

    # Now send part of a block from client 1 to client 3.
    first_client3_block = "b" * 7000
    client1.send_data(first_client3_block, client3_address)

    # Now send some more data to client 2.
    second_client2_block = "a" * 14000
    client1.send_data(second_client2_block, client2_address)

    # Send more data to client 3 and close that stream.
    second_client3_block = "b" * 9000
    client1.send_data(second_client3_block, client3_address)
    client1.send_fin(client3_address)

    if not client3.received_fin:
        raise Exception("Client 3 didn't receive the fin")

    # Close the client 2 stream.
    client1.send_fin(client2_address)
    if not client2.received_fin:
        raise Exception("Client 2 didnt't receive the fin")

    # Make sure the data is correct.
    test_utils.verify_data_sent_equals_data_received(
        first_client2_block + second_client2_block, client2_output_filename)
    test_utils.verify_data_sent_equals_data_received(
        first_client3_block + second_client3_block, client3_output_filename)
Пример #3
0
def one_client_with_multiple_receivers(middlebox_module, testing_part_1):
    """ Tests a scenario where one client is sending data to 3 other clients.

    Verifies that the data received equals the data sent, and throw an Exception
    if this is not the case.
    """
    middlebox1 = middlebox_module.WanOptimizer()
    middlebox2 = middlebox_module.WanOptimizer()
    wide_area_network = wan.Wan(middlebox1, middlebox2)

    # Iniitialize client connected to middlebox 1.
    client1_address = "1.2.3.4"
    client1_output_filename = "{}_output".format(client1_address)
    client1 = simple_client.SimpleClient(client1_address, middlebox1, client1_output_filename)

    # Initialize 3 clients connected to middlebox 2.
    client2_address = "5.6.7.8"
    client2_output_filename = "{}_output".format(client2_address)
    client2 = simple_client.SimpleClient(
        client2_address, middlebox2, client2_output_filename)

    client3_address = "5.6.7.9"
    client3_output_filename = "{}_output".format(client3_address)
    client3 = simple_client.SimpleClient(
        client3_address, middlebox2, client3_output_filename)

    client4_address = "5.6.7.10"
    client4_output_filename = "{}_output".format(client4_address)
    client4 = simple_client.SimpleClient(
        client4_address, middlebox2, client4_output_filename)

    # Send data from client 1 to client 2.
    data_to_client2 = "2" * 8000
    client1.send_data(data_to_client2, client2_address)
    client1.send_fin(client2_address)
    test_utils.verify_data_sent_equals_data_received(
        data_to_client2,
        client2_output_filename)

    # Send different data from client 1 to client 3.
    data_to_client3 = "3" * 8000
    client1.send_data(data_to_client3, client3_address)
    client1.send_fin(client3_address)
    test_utils.verify_data_sent_equals_data_received(
        data_to_client3, client3_output_filename)

    # And finally, send data from client 1 to client 4.
    data_to_client4 = "4" * 8000
    client1.send_data(data_to_client4, client4_address)
    client1.send_fin(client4_address)
    test_utils.verify_data_sent_equals_data_received(
        data_to_client4, client4_output_filename)
Пример #4
0
def verify_data_is_sent_incrementally(middlebox_module, is_testing_part1):
    """ Verifies that data is sent incrementally over the WAN.

    This test makes sure that the WAN optimizer doesn't wait for a FIN
    packet to send data over the WAN.
    """

    middlebox1 = middlebox_module.WanOptimizer()
    middlebox2 = middlebox_module.WanOptimizer()
    wide_area_network = wan.Wan(middlebox1, middlebox2)

    # Iniitialize client connected to middlebox 1.
    client1_address = "1.2.3.4"
    client1_output_filename = "{}_output".format(client1_address)
    client1 = simple_client.SimpleClient(client1_address, middlebox1,
                                         client1_output_filename)

    # Initialize client connected to middlebox 2.
    client2_address = "5.6.7.8"
    client2_output_filename = "{}_output".format(client2_address)
    client2 = simple_client.SimpleClient(client2_address, middlebox2,
                                         client2_output_filename)

    # Send exactly one block from client 1 to client 2.
    if is_testing_part1:
        single_block = "a" * 8000
    else:
        single_block = (
            "From the lower part of the face he appeared" +
            " to be a man of strong character, with a thick, hanging lip," +
            " and a long, straight chin suggestive of resolution pushed t")
    client1.send_data(single_block, client2_address)

    wan_bytes_sent = wide_area_network.get_total_bytes_sent()
    if wan_bytes_sent != len(single_block):
        raise Exception(
            "Since a complete block was sent to the WAN " +
            "optimizer, a complete block should have been sent over the " +
            "WAN, but only {} bytes were sent.".format(wan_bytes_sent))

    # Send a second block, and then close the stream.
    second_block = "b" * 8000
    client1.send_data(second_block, client2_address)
    client1.send_fin(client2_address)

    test_utils.verify_data_sent_equals_data_received(
        single_block + second_block, client2_output_filename)
Пример #5
0
def test_delimiter_at_end_without_fin(middlebox_module, is_testing_part1):
    if is_testing_part1:
        print("test_delimiter_at_end_without_fin does not test simple_test")
        return
    middlebox1 = middlebox_module.WanOptimizer()
    middlebox2 = middlebox_module.WanOptimizer()
    wide_area_network = wan.Wan(middlebox1, middlebox2)

    # Iniitialize client connected to middlebox 1.
    client1_address = "1.2.3.4"
    client1_output_filename = "{}_output".format(client1_address)
    client1 = simple_client.SimpleClient(client1_address, middlebox1,
                                         client1_output_filename)

    # Initialize 2 clients connected to middlebox 2.
    client2_address = "5.6.7.8"
    client2_output_filename = "{}_output".format(client2_address)
    client2 = simple_client.SimpleClient(client2_address, middlebox2,
                                         client2_output_filename)

    client3_address = "5.6.7.9"
    client3_output_filename = "{}_output".format(client3_address)
    client3 = simple_client.SimpleClient(client3_address, middlebox2,
                                         client3_output_filename)

    # Send part of a block from client 1 to client 2.
    first_client2_block = "a" * 2000
    client1.send_data(first_client2_block, client2_address)
    #tests whether we have not recieved anything
    test_utils.verify_data_sent_equals_data_received("",
                                                     client2_output_filename)

    # Now send some more data to client 2.
    second_client2_block = " straight chin suggestive of resolution pushed t"
    client1.send_data(second_client2_block, client2_address)
    if client2.received_fin:
        raise Exception("Client 2 received the fin too early")
    #make sure data is correct, we do not have buffer, we just send everything
    test_utils.verify_data_sent_equals_data_received(
        first_client2_block + second_client2_block, client2_output_filename)

    # Close the client 2 stream.
    client1.send_fin(client2_address)
    if not client2.received_fin:
        raise Exception("Client 2 didnt't receive the fin")
    test_utils.verify_data_sent_equals_data_received(
        first_client2_block + second_client2_block, client2_output_filename)
def verify_data_is_sent_incrementally(middlebox_module, is_testing_part1):
    """ Verifies that data is sent incrementally over the WAN.

    This test makes sure that the WAN optimizer doesn't wait for a FIN
    packet to send data over the WAN.
    """
    if not is_testing_part1:
        # This test is only valid for part 1 (because part 2
        # splits blocks differently).
        return
    middlebox1 = middlebox_module.WanOptimizer()
    middlebox2 = middlebox_module.WanOptimizer()
    wide_area_network = wan.Wan(middlebox1, middlebox2)

    # Iniitialize client connected to middlebox 1.
    client1_address = "1.2.3.4"
    client1_output_filename = "{}_output".format(client1_address)
    client1 = simple_client.SimpleClient(client1_address, middlebox1,
                                         client1_output_filename)

    # Initialize client connected to middlebox 2.
    client2_address = "5.6.7.8"
    client2_output_filename = "{}_output".format(client2_address)
    client2 = simple_client.SimpleClient(client2_address, middlebox2,
                                         client2_output_filename)

    # Send exactly one block from client 1 to client 2.
    single_block = "a" * 8000
    client1.send_data(single_block, client2_address)

    wan_bytes_sent = wide_area_network.get_total_bytes_sent()
    if wan_bytes_sent != 8000:
        raise Exception(
            "Since a complete block was sent to the WAN " +
            "optimizer, a complete block should have been sent over the " +
            "WAN, but only {} bytes were sent.".format(wan_bytes_sent))

    # Send a second block, and then close the stream.
    second_block = "b" * 8000
    client1.send_data(second_block, client2_address)
    client1.send_fin(client2_address)

    test_utils.verify_data_sent_equals_data_received(
        single_block + second_block, client2_output_filename)
def send_48_bytes(middlebox_module, testing_part_1):
    SPECIAL_BYTES = "flamed face and disreputable clothes, walked int"

    middlebox1 = middlebox_module.WanOptimizer()
    middlebox2 = middlebox_module.WanOptimizer()
    wide_area_network = wan.Wan(middlebox1, middlebox2)

    # Iniitialize client connected to middlebox 1.
    client1_address = "1.2.3.4"
    client1_output_filename = "{}_output".format(client1_address)
    client1 = simple_client.SimpleClient(client1_address, middlebox1,
                                         client1_output_filename)

    # Initialize client connected to middlebox 2.
    client2_address = "5.6.7.8"
    client2_output_filename = "{}_output".format(client2_address)
    client2 = simple_client.SimpleClient(client2_address, middlebox2,
                                         client2_output_filename)

    client1.send_data(SPECIAL_BYTES, client2_address)
    client1.send_fin(client2_address)
    # Verify that the correct data was received.
    if not client2.received_fin:
        raise Exception("Client 2 never received a fin")
    test_utils.verify_data_sent_equals_data_received(SPECIAL_BYTES,
                                                     client2_output_filename)
    os.remove(client2_output_filename)

    client2.send_data(SPECIAL_BYTES, client1_address)
    client2.send_fin(client1_address)
    if not client1.received_fin:
        raise Exception("Client 1 never received a fin")
    test_utils.verify_data_sent_equals_data_received(SPECIAL_BYTES,
                                                     client1_output_filename)
    os.remove(client1_output_filename)

    achieved_reduction = compute_reduction(len(SPECIAL_BYTES),
                                           wide_area_network)
    expected_reduction = 0.29
    if achieved_reduction < expected_reduction:
        raise Exception(
            "Too many bytes were sent over the network. Expected reduction rate was {} but achieved only {}."
            .format(expected_reduction, achieved_reduction))
Пример #8
0
def simple_send_test(middlebox_module, data_to_send, data_to_send_in_reverse):
    """ Sends data between two clients.

    Verifies that the data received equals the data sent, and throw an Exception
    if this is not the case.
    """
    middlebox1 = middlebox_module.WanOptimizer()
    middlebox2 = middlebox_module.WanOptimizer()
    wide_area_network = wan.Wan(middlebox1, middlebox2)

    # Iniitialize client connected to middlebox 1.
    client1_address = "1.2.3.4"
    client1_output_filename = "{}_output".format(client1_address)
    client1 = simple_client.SimpleClient(client1_address, middlebox1, client1_output_filename)

    # Initialize client connected to middlebox 2.
    client2_address = "5.6.7.8"
    client2_output_filename = "{}_output".format(client2_address)
    client2 = simple_client.SimpleClient(client2_address, middlebox2, client2_output_filename)

    if data_to_send:
        client1.send_data(data_to_send, client2_address)
        client1.send_fin(client2_address)
        # Verify that the correct data was received.
        if not client2.received_fin:
            raise Exception("Client 2 never received a fin")
        test_utils.verify_data_sent_equals_data_received(
            data_to_send,
            client2_output_filename)

    if data_to_send_in_reverse:
        client2.send_data(data_to_send_in_reverse, client1_address)
        client2.send_fin(client1_address)
        if not client1.received_fin:
            raise Exception("Client 1 never received a fin")
        test_utils.verify_data_sent_equals_data_received(
            data_to_send_in_reverse,
            client1_output_filename)
Пример #9
0
def test_right_partitions(middlebox_module, is_testing_part1):
    """
    This function is a test of Aisha's example

    So in example you've given, the window will progress like this...
    [0:4] ---> found a block
    [5:9] ----> found a block
    and I would have the following two blocks. 'aaaaa' and 'aaaaa'

    let's say if the string was 'bbbaaaaaaaaaaaaaaa'
    the window will progress as follows:
    [0:4]
    [1:5]
    [2:6]
    [3:7] ---> found a block = 'bbbaaaaa'
    [8:12] ---> found a block = 'aaaaa'
    [13:17] ---->found a block. = 'aaaaa'

    except that I will use the delimiter " straight chin suggestive of resolution pushed t"
    instead.
    """
    if is_testing_part1:
        delimit = "b" * 8000
        first_expected_bytes = 16020  #one 8000 byte block for
        second_expected_bytes = 16080
        third_expected_bytes = 16100
        first_client2_block = "a" * 2000 + delimit[:6000] + delimit + delimit
        second_client2_block = delimit
    else:
        delimit = " straight chin suggestive of resolution pushed t"
        first_expected_bytes = 2116
        second_expected_bytes = 2176
        third_expected_bytes = 2196
        first_client2_block = "a" * 2000 + delimit + delimit + delimit
        second_client2_block = delimit

    middlebox1 = middlebox_module.WanOptimizer()
    middlebox2 = middlebox_module.WanOptimizer()
    wide_area_network = wan.Wan(middlebox1, middlebox2)

    # Iniitialize client connected to middlebox 1.
    client1_address = "1.2.3.4"
    client1_output_filename = "{}_output".format(client1_address)
    client1 = simple_client.SimpleClient(client1_address, middlebox1,
                                         client1_output_filename)

    # Initialize 2 clients connected to middlebox 2.
    client2_address = "5.6.7.8"
    client2_output_filename = "{}_output".format(client2_address)
    client2 = simple_client.SimpleClient(client2_address, middlebox2,
                                         client2_output_filename)

    # Send part of a block from client 1 to client 2.
    client1.send_data(first_client2_block, client2_address)
    #tests whether we recieved right thing
    test_utils.verify_data_sent_equals_data_received(first_client2_block,
                                                     client2_output_filename)
    bytes_sent = wide_area_network.get_total_bytes_sent()
    print('bytes sent 1')
    print(bytes_sent)
    if bytes_sent != first_expected_bytes:
        raise Exception("not correct number of bytes")

    #send again
    client1.send_data(first_client2_block, client2_address)
    #tests whether we recieved right thing
    test_utils.verify_data_sent_equals_data_received(
        first_client2_block + first_client2_block, client2_output_filename)

    bytes_sent = wide_area_network.get_total_bytes_sent()
    print('bytes sent 2')
    print(bytes_sent)
    if bytes_sent != second_expected_bytes:
        raise Exception("not correct number of bytes")

    # Now send some more data to client 2.
    client1.send_data_with_fin(second_client2_block, client2_address)
    # Close the client 2 stream.
    if not client2.received_fin:
        raise Exception("Client 2 didnt't receive the fin")

    #make sure data is correct, we do not have buffer, we just send everything
    test_utils.verify_data_sent_equals_data_received(
        first_client2_block + first_client2_block + second_client2_block,
        client2_output_filename)

    bytes_sent = wide_area_network.get_total_bytes_sent()
    print('bytes sent 3')
    print(bytes_sent)
    if bytes_sent != third_expected_bytes:
        raise Exception("not correct number of bytes")