Advertisement
Guest User

Untitled

a guest
Nov 18th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.39 KB | None | 0 0
  1. import os
  2. import sys
  3. import client
  4. import wan
  5. import simple_client
  6.  
  7. def comprehensive_test(middlebox_module, testing_part_1):
  8. """ tests a bunch of stuff """
  9. delimiter = " straight chin suggestive of resolution pushed t"
  10. names = {}
  11.  
  12. # Initialize middle boxes
  13. middle_box_A = middlebox_module.WanOptimizer()
  14. middle_box_B = middlebox_module.WanOptimizer()
  15. WAN = wan.Wan(middle_box_A, middle_box_B)
  16.  
  17. # Initialize clients connected to middle_box_A
  18. client_A1_addr = "11.11.11.11"
  19. client_A2_addr = "12.12.12.12"
  20. client_A3_addr = "13.13.13.13"
  21. CA1_output_f = "{}_output".format(client_A1_addr)
  22. client_A1 = simple_client.SimpleClient(client_A1_addr, middle_box_A, CA1_output_f)
  23. CA2_output_f = "{}_output".format(client_A2_addr)
  24. client_A2 = simple_client.SimpleClient(client_A2_addr, middle_box_A, CA2_output_f)
  25. CA3_output_f = "{}_output".format(client_A3_addr)
  26. client_A3 = simple_client.SimpleClient(client_A3_addr, middle_box_A, CA3_output_f)
  27. # client_A1 = client.EndHost("client_A1", client_A1_addr, middle_box_A)
  28. # names["A1"] = "client_A1"
  29. # client_A2 = client.EndHost("client_A2", client_A2_addr, middle_box_A)
  30. # names["A2"] = "client_A2"
  31. # client_A3 = client.EndHost("client_A3", client_A3_addr, middle_box_A)
  32. # names["A3"] = "client_A3"
  33.  
  34. # Initialize clients connected to middle_box_B
  35. client_B1_addr = "21.21.21.21"
  36. client_B2_addr = "22.22.22.22"
  37. client_B3_addr = "23.23.23.23"
  38. CB1_output_f = "{}_output".format(client_B1_addr)
  39. client_B1 = simple_client.SimpleClient(client_B1_addr, middle_box_B, CB1_output_f)
  40. CB2_output_f = "{}_output".format(client_B2_addr)
  41. client_B2 = simple_client.SimpleClient(client_B2_addr, middle_box_B, CB2_output_f)
  42. CB3_output_f = "{}_output".format(client_B3_addr)
  43. client_B3 = simple_client.SimpleClient(client_B3_addr, middle_box_B, CB3_output_f)
  44. # client_B1 = client.EndHost("client_B1", client_B1_addr, middle_box_B)
  45. # names["B1"] = "client_B1"
  46. # client_B2 = client.EndHost("client_B2", client_B2_addr, middle_box_B)
  47. # names["B2"] = "client_B2"
  48. # client_B3 = client.EndHost("client_B3", client_B3_addr, middle_box_B)
  49. # names["B3"] = "client_B3"
  50.  
  51.  
  52. # f = "comprehensive_test.txt"
  53. # extra = len(f) + len(client.FILENAME_DELIMITER)
  54. # comprehensive_file = open(f, "w+")
  55. # comprehensive_file.write(delimiter[:47])
  56. # comprehensive_file.close()
  57. # client_A1.send_file(f, client_B2_addr)
  58. # comprehensive_file = open(f, "w+")
  59. # comprehensive_file.write(delimiter[47])
  60. # comprehensive_file.close()
  61. # client_A1.send_file(f, client_B2_addr)
  62. # client_B2.send_file(f, client_A1_addr)
  63. # client_B2.send_file(f, client_A2_addr)
  64. # client_B2.send_file(f, client_A3_addr)
  65. # os.remove("{}-{}".format(names["A1"], f))
  66. # os.remove("{}-{}".format(names["A2"], f))
  67. # os.remove("{}-{}".format(names["A3"], f))
  68. # os.remove("{}-{}".format(names["B2"], f))
  69. # os.remove(f)
  70. # PART 1: Send a file from client
  71. client_A1.send_data("i"*52 + delimiter[:47], client_B1_addr)
  72. client_A1.send_data(delimiter[47] + "i"*52 + delimiter, client_B1_addr)
  73. #client_A1.send_fin(client_B1_addr)
  74. client_B1.send_data("i"*52 + delimiter, client_A1_addr)
  75. #client_B1.send_fin(client_A1_addr)
  76. if not testing_part_1 and WAN.get_total_bytes_sent() != 140:
  77. raise Exception("\nYour program doesn't scan through the buffer properly.\n"
  78. "When you receive a packet and there is a nonempty buffer\n"
  79. "associated with the current flow, the first window should\n"
  80. "contain 47 bytes from the preexisting buffer and 1 byte \n"
  81. "from the new packet payload.\n"
  82. "You should have sent 140 bytes, you sent {} bytes.".format(WAN.get_total_bytes_sent()))
  83. payload = ""
  84. for i in range(1, 31):
  85. payload += (delimiter + str(i))
  86. client_A1.send_data(payload, client_B1_addr)
  87. client_A1.send_fin(client_B1_addr)
  88. client_B3.send_data(payload, client_A2_addr)
  89. client_B3.send_fin(client_A2_addr)
  90. client_A3.send_data(payload, client_B2_addr)
  91. client_A3.send_fin(client_B2_addr)
  92. client_B2.send_data(payload, client_A3_addr)
  93. client_B2.send_fin(client_A3_addr)
  94. client_A2.send_data(payload, client_B3_addr)
  95. client_A2.send_fin(client_B3_addr)
  96. client_B1.send_data(payload, client_A1_addr)
  97. client_B1.send_fin(client_A1_addr)
  98.  
  99. os.remove(CA1_output_f)
  100. os.remove(CB1_output_f)
  101. os.remove(CA2_output_f)
  102. os.remove(CA3_output_f)
  103. os.remove(CB2_output_f)
  104. os.remove(CB3_output_f)
  105.  
  106. if not testing_part_1 and WAN.get_total_bytes_sent() - 140 != 4591:
  107. raise Exception("\nThe packet sent (6 times in total) contained 31 blocks within it.\n"
  108. "The first packet should account for 1491 bytes, the 5 packets\n"
  109. "sent following it would then account for 31*20*5 (3100) bytes bringing\n"
  110. "the grand total of bytes which should have been sent over the WAN to\n"
  111. "4591. You sent {} bytes".format(WAN.get_total_bytes_sent()-140))
  112.  
  113. client_B4_addr = "24.24.24.24"
  114. CB4_output_f = "{}_output".format(client_B4_addr)
  115. client_B4 = simple_client.SimpleClient(client_B4_addr, middle_box_B, CB4_output_f)
  116. client_A4_addr = "14.14.14.14"
  117. CA4_output_f = "{}_output".format(client_A4_addr)
  118. client_A4 = simple_client.SimpleClient(client_A4_addr, middle_box_A, CA4_output_f)
  119.  
  120. for i in range(0, 10):
  121. client_A4.send_data(str(i)*1460 + delimiter[0:40], client_B4_addr)
  122. client_A4.send_data(delimiter[40:], client_B4_addr)
  123.  
  124. client_A4.send_fin(client_B4_addr)
  125.  
  126. for i in range(0, 10):
  127. client_B4.send_data(str(i)*1460 + delimiter[0:40], client_A4_addr)
  128. client_B4.send_data(delimiter[40:], client_A4_addr)
  129.  
  130. client_B4.send_fin(client_A4_addr)
  131.  
  132. os.remove(CA4_output_f)
  133. os.remove(CB4_output_f)
  134.  
  135. if not testing_part_1 and WAN.get_total_bytes_sent() - (4591 + 140) != 15280:
  136. raise Exception("You are not properly adjusting the window when you scan for a delimiter.\n"
  137. "You should have sent 15280 bytes, but you sent {} bytes."
  138. .format(WAN.get_total_bytes_sent() - (4591 + 140)))
  139.  
  140. client_B5_addr = "25.25.25.25"
  141. CB5_output_f = "{}_output".format(client_B5_addr)
  142. client_B5 = simple_client.SimpleClient(client_B5_addr, middle_box_B, CB5_output_f)
  143. client_A5_addr = "15.15.15.15"
  144. CA5_output_f = "{}_output".format(client_A5_addr)
  145. client_A5 = simple_client.SimpleClient(client_A5_addr, middle_box_A, CA5_output_f)
  146.  
  147. for i in range(0, 10):
  148. client_A5.send_data(str(i) + "hello!" + delimiter[0:20], client_B5_addr)
  149. client_A5.send_data(delimiter[20:], client_B5_addr)
  150. client_B5.send_data(str(i) + "hello!" + delimiter, client_A5_addr)
  151.  
  152. client_A5.send_fin(client_B5_addr)
  153. client_B5.send_fin(client_A5_addr)
  154.  
  155. os.remove(CA5_output_f)
  156. os.remove(CB5_output_f)
  157.  
  158. if not testing_part_1 and WAN.get_total_bytes_sent() - (4591 + 140 + 15280) != 750:
  159. raise Exception("Window is not being indexed properly, you should have sent 750 bytes.\n"
  160. "You sent {} bytes.".format(WAN.get_total_bytes_sent() - (4591 + 140 + 15280)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement