Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import sys
- import client
- import wan
- import simple_client
- def comprehensive_test(middlebox_module, testing_part_1):
- """ tests a bunch of stuff """
- delimiter = " straight chin suggestive of resolution pushed t"
- names = {}
- # Initialize middle boxes
- middle_box_A = middlebox_module.WanOptimizer()
- middle_box_B = middlebox_module.WanOptimizer()
- WAN = wan.Wan(middle_box_A, middle_box_B)
- # Initialize clients connected to middle_box_A
- client_A1_addr = "11.11.11.11"
- client_A2_addr = "12.12.12.12"
- client_A3_addr = "13.13.13.13"
- CA1_output_f = "{}_output".format(client_A1_addr)
- client_A1 = simple_client.SimpleClient(client_A1_addr, middle_box_A, CA1_output_f)
- CA2_output_f = "{}_output".format(client_A2_addr)
- client_A2 = simple_client.SimpleClient(client_A2_addr, middle_box_A, CA2_output_f)
- CA3_output_f = "{}_output".format(client_A3_addr)
- client_A3 = simple_client.SimpleClient(client_A3_addr, middle_box_A, CA3_output_f)
- # client_A1 = client.EndHost("client_A1", client_A1_addr, middle_box_A)
- # names["A1"] = "client_A1"
- # client_A2 = client.EndHost("client_A2", client_A2_addr, middle_box_A)
- # names["A2"] = "client_A2"
- # client_A3 = client.EndHost("client_A3", client_A3_addr, middle_box_A)
- # names["A3"] = "client_A3"
- # Initialize clients connected to middle_box_B
- client_B1_addr = "21.21.21.21"
- client_B2_addr = "22.22.22.22"
- client_B3_addr = "23.23.23.23"
- CB1_output_f = "{}_output".format(client_B1_addr)
- client_B1 = simple_client.SimpleClient(client_B1_addr, middle_box_B, CB1_output_f)
- CB2_output_f = "{}_output".format(client_B2_addr)
- client_B2 = simple_client.SimpleClient(client_B2_addr, middle_box_B, CB2_output_f)
- CB3_output_f = "{}_output".format(client_B3_addr)
- client_B3 = simple_client.SimpleClient(client_B3_addr, middle_box_B, CB3_output_f)
- # client_B1 = client.EndHost("client_B1", client_B1_addr, middle_box_B)
- # names["B1"] = "client_B1"
- # client_B2 = client.EndHost("client_B2", client_B2_addr, middle_box_B)
- # names["B2"] = "client_B2"
- # client_B3 = client.EndHost("client_B3", client_B3_addr, middle_box_B)
- # names["B3"] = "client_B3"
- # f = "comprehensive_test.txt"
- # extra = len(f) + len(client.FILENAME_DELIMITER)
- # comprehensive_file = open(f, "w+")
- # comprehensive_file.write(delimiter[:47])
- # comprehensive_file.close()
- # client_A1.send_file(f, client_B2_addr)
- # comprehensive_file = open(f, "w+")
- # comprehensive_file.write(delimiter[47])
- # comprehensive_file.close()
- # client_A1.send_file(f, client_B2_addr)
- # client_B2.send_file(f, client_A1_addr)
- # client_B2.send_file(f, client_A2_addr)
- # client_B2.send_file(f, client_A3_addr)
- # os.remove("{}-{}".format(names["A1"], f))
- # os.remove("{}-{}".format(names["A2"], f))
- # os.remove("{}-{}".format(names["A3"], f))
- # os.remove("{}-{}".format(names["B2"], f))
- # os.remove(f)
- # PART 1: Send a file from client
- client_A1.send_data("i"*52 + delimiter[:47], client_B1_addr)
- client_A1.send_data(delimiter[47] + "i"*52 + delimiter, client_B1_addr)
- #client_A1.send_fin(client_B1_addr)
- client_B1.send_data("i"*52 + delimiter, client_A1_addr)
- #client_B1.send_fin(client_A1_addr)
- if not testing_part_1 and WAN.get_total_bytes_sent() != 140:
- raise Exception("\nYour program doesn't scan through the buffer properly.\n"
- "When you receive a packet and there is a nonempty buffer\n"
- "associated with the current flow, the first window should\n"
- "contain 47 bytes from the preexisting buffer and 1 byte \n"
- "from the new packet payload.\n"
- "You should have sent 140 bytes, you sent {} bytes.".format(WAN.get_total_bytes_sent()))
- payload = ""
- for i in range(1, 31):
- payload += (delimiter + str(i))
- client_A1.send_data(payload, client_B1_addr)
- client_A1.send_fin(client_B1_addr)
- client_B3.send_data(payload, client_A2_addr)
- client_B3.send_fin(client_A2_addr)
- client_A3.send_data(payload, client_B2_addr)
- client_A3.send_fin(client_B2_addr)
- client_B2.send_data(payload, client_A3_addr)
- client_B2.send_fin(client_A3_addr)
- client_A2.send_data(payload, client_B3_addr)
- client_A2.send_fin(client_B3_addr)
- client_B1.send_data(payload, client_A1_addr)
- client_B1.send_fin(client_A1_addr)
- os.remove(CA1_output_f)
- os.remove(CB1_output_f)
- os.remove(CA2_output_f)
- os.remove(CA3_output_f)
- os.remove(CB2_output_f)
- os.remove(CB3_output_f)
- if not testing_part_1 and WAN.get_total_bytes_sent() - 140 != 4591:
- raise Exception("\nThe packet sent (6 times in total) contained 31 blocks within it.\n"
- "The first packet should account for 1491 bytes, the 5 packets\n"
- "sent following it would then account for 31*20*5 (3100) bytes bringing\n"
- "the grand total of bytes which should have been sent over the WAN to\n"
- "4591. You sent {} bytes".format(WAN.get_total_bytes_sent()-140))
- client_B4_addr = "24.24.24.24"
- CB4_output_f = "{}_output".format(client_B4_addr)
- client_B4 = simple_client.SimpleClient(client_B4_addr, middle_box_B, CB4_output_f)
- client_A4_addr = "14.14.14.14"
- CA4_output_f = "{}_output".format(client_A4_addr)
- client_A4 = simple_client.SimpleClient(client_A4_addr, middle_box_A, CA4_output_f)
- for i in range(0, 10):
- client_A4.send_data(str(i)*1460 + delimiter[0:40], client_B4_addr)
- client_A4.send_data(delimiter[40:], client_B4_addr)
- client_A4.send_fin(client_B4_addr)
- for i in range(0, 10):
- client_B4.send_data(str(i)*1460 + delimiter[0:40], client_A4_addr)
- client_B4.send_data(delimiter[40:], client_A4_addr)
- client_B4.send_fin(client_A4_addr)
- os.remove(CA4_output_f)
- os.remove(CB4_output_f)
- if not testing_part_1 and WAN.get_total_bytes_sent() - (4591 + 140) != 15280:
- raise Exception("You are not properly adjusting the window when you scan for a delimiter.\n"
- "You should have sent 15280 bytes, but you sent {} bytes."
- .format(WAN.get_total_bytes_sent() - (4591 + 140)))
- client_B5_addr = "25.25.25.25"
- CB5_output_f = "{}_output".format(client_B5_addr)
- client_B5 = simple_client.SimpleClient(client_B5_addr, middle_box_B, CB5_output_f)
- client_A5_addr = "15.15.15.15"
- CA5_output_f = "{}_output".format(client_A5_addr)
- client_A5 = simple_client.SimpleClient(client_A5_addr, middle_box_A, CA5_output_f)
- for i in range(0, 10):
- client_A5.send_data(str(i) + "hello!" + delimiter[0:20], client_B5_addr)
- client_A5.send_data(delimiter[20:], client_B5_addr)
- client_B5.send_data(str(i) + "hello!" + delimiter, client_A5_addr)
- client_A5.send_fin(client_B5_addr)
- client_B5.send_fin(client_A5_addr)
- os.remove(CA5_output_f)
- os.remove(CB5_output_f)
- if not testing_part_1 and WAN.get_total_bytes_sent() - (4591 + 140 + 15280) != 750:
- raise Exception("Window is not being indexed properly, you should have sent 750 bytes.\n"
- "You sent {} bytes.".format(WAN.get_total_bytes_sent() - (4591 + 140 + 15280)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement