1*9c5db199SXin Lifrom autotest_lib.server import autotest, hosts, subcommand, test 2*9c5db199SXin Lifrom autotest_lib.server import utils 3*9c5db199SXin Li 4*9c5db199SXin Liclass netpipe(test.test): 5*9c5db199SXin Li version = 2 6*9c5db199SXin Li 7*9c5db199SXin Li def run_once(self, pair, buffer, upper_bound, variance): 8*9c5db199SXin Li print("running on %s and %s\n" % (pair[0], pair[1])) 9*9c5db199SXin Li 10*9c5db199SXin Li # Designate a platform label for the server side of tests. 11*9c5db199SXin Li server_label = 'net_server' 12*9c5db199SXin Li 13*9c5db199SXin Li server = hosts.create_host(pair[0]) 14*9c5db199SXin Li client = hosts.create_host(pair[1]) 15*9c5db199SXin Li 16*9c5db199SXin Li # If client has the server_label, then swap server and client. 17*9c5db199SXin Li platform_label = client.get_platform_label() 18*9c5db199SXin Li if platform_label == server_label: 19*9c5db199SXin Li (server, client) = (client, server) 20*9c5db199SXin Li 21*9c5db199SXin Li # Disable IP Filters if they are enabled. 22*9c5db199SXin Li for m in [client, server]: 23*9c5db199SXin Li status = m.run('iptables -L') 24*9c5db199SXin Li if not status.exit_status: 25*9c5db199SXin Li m.disable_ipfilters() 26*9c5db199SXin Li 27*9c5db199SXin Li # Starting a test indents the status.log entries. This test starts 2 28*9c5db199SXin Li # additional tests causing their log entries to be indented twice. This 29*9c5db199SXin Li # double indent confuses the parser, so reset the indent level on the 30*9c5db199SXin Li # job, let the forked tests record their entries, then restore the 31*9c5db199SXin Li # previous indent level. 32*9c5db199SXin Li self.job._indenter.decrement() 33*9c5db199SXin Li 34*9c5db199SXin Li server_at = autotest.Autotest(server) 35*9c5db199SXin Li client_at = autotest.Autotest(client) 36*9c5db199SXin Li 37*9c5db199SXin Li template = ''.join(["job.run_test('netpipe', server_ip='%s', ", 38*9c5db199SXin Li "client_ip='%s', role='%s', bidirectional=True, ", 39*9c5db199SXin Li "buffer_size=%d, upper_bound=%d," 40*9c5db199SXin Li "perturbation_size=%d, tag='%s')"]) 41*9c5db199SXin Li 42*9c5db199SXin Li server_control_file = template % (server.ip, client.ip, 'server', 43*9c5db199SXin Li buffer, upper_bound, variance, 44*9c5db199SXin Li 'server') 45*9c5db199SXin Li client_control_file = template % (server.ip, client.ip, 'client', 46*9c5db199SXin Li buffer, upper_bound, variance, 47*9c5db199SXin Li 'client') 48*9c5db199SXin Li 49*9c5db199SXin Li server_command = subcommand.subcommand(server_at.run, 50*9c5db199SXin Li [server_control_file, server.hostname], 51*9c5db199SXin Li subdir='../') 52*9c5db199SXin Li client_command = subcommand.subcommand(client_at.run, 53*9c5db199SXin Li [client_control_file, client.hostname], 54*9c5db199SXin Li subdir='../') 55*9c5db199SXin Li 56*9c5db199SXin Li subcommand.parallel([server_command, client_command]) 57*9c5db199SXin Li 58*9c5db199SXin Li # The parser needs a keyval file to know what host ran the test. 59*9c5db199SXin Li utils.write_keyval('../' + server.hostname, 60*9c5db199SXin Li {"hostname": server.hostname}) 61*9c5db199SXin Li utils.write_keyval('../' + client.hostname, 62*9c5db199SXin Li {"hostname": client.hostname}) 63*9c5db199SXin Li 64*9c5db199SXin Li # Restore indent level of main job. 65*9c5db199SXin Li self.job._indenter.increment() 66*9c5db199SXin Li 67*9c5db199SXin Li for m in [client, server]: 68*9c5db199SXin Li status = m.run('iptables -L') 69*9c5db199SXin Li if not status.exit_status: 70*9c5db199SXin Li m.enable_ipfilters() 71