def test_allbad_network(self): """reliability over network with all of the above problems""" # setup environment run_command(netem_change.format("corrupt 1% duplicate 10% loss 10% 25% delay 20ms reorder 25% 50%")) # launch localhost client connecting to server client_socket.connect() # client sends content to server client_socket.send(input_file) # because it takes a bit of time for the data to be send over, there needs to be a bit of a delay here time.sleep(0.3) # server receives content from client server_socket.recv(output_path.format("all_bad")) # content received by server matches the content sent by client # calculate checksum of both input and output file and compare them f_in = open(input_file, 'rb') inp_bytes = f_in.read() f_in.close() f_out = open(output_file.format("all_bad"), 'rb') outp_bytes = f_out.read() f_out.close() self.assertEqual(inp_bytes, outp_bytes, "The input and output file are NOT equal.") self.assertEqual(calculate_checksum(inp_bytes), calculate_checksum(outp_bytes), "The checksum of the input and output file are NOT equal.")
def test_ideal_network(self): """reliability over an ideal framework""" # setup environment (nothing to set) # launch localhost client connecting to server client_socket.connect() # client sends content to server client_socket.send(input_file) # because it takes a bit of time for the data to be send over, there needs to be a bit of a delay here time.sleep(0.3) # server receives content from client server_socket.recv(output_path.format("ideal")) # content received by server matches the content sent by client # calculate checksum of both input and output file and compare them f_in = open(input_file, 'rb') inp_bytes = f_in.read() f_in.close() f_out = open(output_file.format("ideal"), 'rb') outp_bytes = f_out.read() f_out.close() self.assertEqual(inp_bytes, outp_bytes, "The input and output file are NOT equal.") self.assertEqual(calculate_checksum(inp_bytes), calculate_checksum(outp_bytes), "The checksum of the input and output file are NOT equal.")
def test_flipping_network(self): """reliability over network with bit flips (which sometimes results in lower layer packet loss)""" # setup environment run_command(netem_change.format("corrupt 1%")) # launch localhost client connecting to server client_socket.connect() # client sends content to server client_socket.send(input_file) # because it takes a bit of time for the data to be send over, there needs to be a bit of a delay here time.sleep(0.3) # server receives content from client server_socket.recv(output_path.format("flip")) # content received by server matches the content sent by client # calculate checksum of both input and output file and compare them f_in = open(input_file, 'rb') inp_bytes = f_in.read() f_in.close() f_out = open(output_file.format("flip"), 'rb') outp_bytes = f_out.read() f_out.close() self.assertEqual(inp_bytes, outp_bytes, "The input and output file are NOT equal.") self.assertEqual(calculate_checksum(inp_bytes), calculate_checksum(outp_bytes), "The checksum of the input and output file are NOT equal.")