4 import ovstest.util as util
6 DEFAULT_TEST_BRIDGE = "ovstestbr0"
7 DEFAULT_TEST_PORT = "ovstestport0"
8 DEFAULT_TEST_TUN = "ovstestport1"
12 def do_udp_tests(receiver, sender, tbwidth, duration, port_sizes):
13 """Schedule UDP tests between receiver and sender"""
14 server1 = util.rpc_client(receiver[0], receiver[1])
15 server2 = util.rpc_client(sender[0], sender[1])
17 udpformat = '{0:>15} {1:>15} {2:>15} {3:>15} {4:>15}'
19 print ("UDP test from %s:%u to %s:%u with target bandwidth %s" %
20 (sender[0], sender[1], receiver[0], receiver[1],
21 util.bandwidth_to_string(tbwidth)))
22 print udpformat.format("Datagram Size", "Snt Datagrams", "Rcv Datagrams",
23 "Datagram Loss", "Bandwidth")
25 for size in port_sizes:
26 listen_handle = NO_HANDLE
27 send_handle = NO_HANDLE
29 packetcnt = (tbwidth * duration) / size
31 listen_handle = server1.create_udp_listener(receiver[3])
32 if listen_handle == NO_HANDLE:
33 print ("Server could not open UDP listening socket on port"
34 " %u. Try to restart the server.\n" % receiver[3])
36 send_handle = server2.create_udp_sender(
37 (util.ip_from_cidr(receiver[2]),
38 receiver[3]), packetcnt, size,
41 # Using sleep here because there is no other synchronization
42 # source that would notify us when all sent packets were received
43 time.sleep(duration + 1)
45 rcv_packets = server1.get_udp_listener_results(listen_handle)
46 snt_packets = server2.get_udp_sender_results(send_handle)
48 loss = math.ceil(((snt_packets - rcv_packets) * 10000.0) /
50 bwidth = (rcv_packets * size) / duration
52 print udpformat.format(size, snt_packets, rcv_packets,
53 '%.2f%%' % loss, util.bandwidth_to_string(bwidth))
55 if listen_handle != NO_HANDLE:
56 server1.close_udp_listener(listen_handle)
57 if send_handle != NO_HANDLE:
58 server2.close_udp_sender(send_handle)
62 def do_tcp_tests(receiver, sender, duration):
63 """Schedule TCP tests between receiver and sender"""
64 server1 = util.rpc_client(receiver[0], receiver[1])
65 server2 = util.rpc_client(sender[0], sender[1])
67 tcpformat = '{0:>15} {1:>15} {2:>15}'
68 print "TCP test from %s:%u to %s:%u (full speed)" % (sender[0], sender[1],
69 receiver[0], receiver[1])
70 print tcpformat.format("Snt Bytes", "Rcv Bytes", "Bandwidth")
72 listen_handle = NO_HANDLE
73 send_handle = NO_HANDLE
75 listen_handle = server1.create_tcp_listener(receiver[3])
76 if listen_handle == NO_HANDLE:
77 print ("Server was unable to open TCP listening socket on port"
78 " %u. Try to restart the server.\n" % receiver[3])
80 send_handle = server2.create_tcp_sender(util.ip_from_cidr(receiver[2]),
81 receiver[3], duration)
83 time.sleep(duration + 1)
85 rcv_bytes = long(server1.get_tcp_listener_results(listen_handle))
86 snt_bytes = long(server2.get_tcp_sender_results(send_handle))
88 bwidth = rcv_bytes / duration
90 print tcpformat.format(snt_bytes, rcv_bytes,
91 util.bandwidth_to_string(bwidth))
93 if listen_handle != NO_HANDLE:
94 server1.close_tcp_listener(listen_handle)
95 if send_handle != NO_HANDLE:
96 server2.close_tcp_sender(send_handle)
100 def do_l3_tests(node1, node2, bandwidth, duration, ps, type):
102 Do L3 tunneling tests. Each node is given as 4 tuple - physical
103 interface IP, control port, test IP and test port.
105 server1 = util.rpc_client(node1[0], node1[1])
106 server2 = util.rpc_client(node2[0], node2[1])
107 servers_with_bridges = []
109 server1.create_bridge(DEFAULT_TEST_BRIDGE)
110 servers_with_bridges.append(server1)
111 server2.create_bridge(DEFAULT_TEST_BRIDGE)
112 servers_with_bridges.append(server2)
114 server1.interface_up(DEFAULT_TEST_BRIDGE)
115 server2.interface_up(DEFAULT_TEST_BRIDGE)
117 server1.interface_assign_ip(DEFAULT_TEST_BRIDGE, node1[2], None)
118 server2.interface_assign_ip(DEFAULT_TEST_BRIDGE, node2[2], None)
120 server1.add_port_to_bridge(DEFAULT_TEST_BRIDGE, DEFAULT_TEST_TUN)
121 server2.add_port_to_bridge(DEFAULT_TEST_BRIDGE, DEFAULT_TEST_TUN)
123 server1.ovs_vsctl_set("Interface", DEFAULT_TEST_TUN, "type",
125 server2.ovs_vsctl_set("Interface", DEFAULT_TEST_TUN, "type",
127 server1.ovs_vsctl_set("Interface", DEFAULT_TEST_TUN, "options",
128 "remote_ip", node2[0])
129 server2.ovs_vsctl_set("Interface", DEFAULT_TEST_TUN, "options",
130 "remote_ip", node1[0])
132 do_udp_tests(node1, node2, bandwidth, duration, ps)
133 do_udp_tests(node2, node1, bandwidth, duration, ps)
134 do_tcp_tests(node1, node2, duration)
135 do_tcp_tests(node2, node1, duration)
138 for server in servers_with_bridges:
139 server.del_bridge(DEFAULT_TEST_BRIDGE)
143 def do_vlan_tests(node1, node2, bandwidth, duration, ps, tag):
145 Do VLAN tests between node1 and node2. Each node is given
146 as 4 tuple - physical interface IP, control port, test IP and
149 server1 = util.rpc_client(node1[0], node1[1])
150 server2 = util.rpc_client(node2[0], node2[1])
155 servers_with_test_ports = []
158 interface_node1 = server1.get_interface(node1[0])
159 interface_node2 = server2.get_interface(node2[0])
161 if server1.is_ovs_bridge(interface_node1):
162 br_name1 = interface_node1
164 br_name1 = DEFAULT_TEST_BRIDGE
165 server1.create_test_bridge(br_name1, interface_node1)
167 if server2.is_ovs_bridge(interface_node2):
168 br_name2 = interface_node2
170 br_name2 = DEFAULT_TEST_BRIDGE
171 server2.create_test_bridge(br_name2, interface_node2)
173 server1.add_port_to_bridge(br_name1, DEFAULT_TEST_PORT)
174 servers_with_test_ports.append(server1)
175 server2.add_port_to_bridge(br_name2, DEFAULT_TEST_PORT)
176 servers_with_test_ports.append(server2)
178 server1.ovs_vsctl_set("Port", DEFAULT_TEST_PORT, "tag", None, tag)
179 server2.ovs_vsctl_set("Port", DEFAULT_TEST_PORT, "tag", None, tag)
181 server1.ovs_vsctl_set("Interface", DEFAULT_TEST_PORT, "type", None,
183 server2.ovs_vsctl_set("Interface", DEFAULT_TEST_PORT, "type", None,
186 server1.interface_assign_ip(DEFAULT_TEST_PORT, node1[2], None)
187 server2.interface_assign_ip(DEFAULT_TEST_PORT, node2[2], None)
189 server1.interface_up(DEFAULT_TEST_PORT)
190 server2.interface_up(DEFAULT_TEST_PORT)
192 do_udp_tests(node1, node2, bandwidth, duration, ps)
193 do_udp_tests(node2, node1, bandwidth, duration, ps)
194 do_tcp_tests(node1, node2, duration)
195 do_tcp_tests(node2, node1, duration)
198 for server in servers_with_test_ports:
199 server.del_port_from_bridge(DEFAULT_TEST_PORT)
200 if br_name1 == DEFAULT_TEST_BRIDGE:
201 server1.del_test_bridge(br_name1, interface_node1)
202 if br_name2 == DEFAULT_TEST_BRIDGE:
203 server2.del_test_bridge(br_name2, interface_node2)
206 def do_direct_tests(node1, node2, bandwidth, duration, ps):
208 Do tests between outer IPs without involving Open vSwitch. Each
209 node is given as 4 tuple - physical interface IP, control port,
210 test IP and test port. Direct tests will use physical interface
211 IP as the test IP address.
213 n1 = (node1[0], node1[1], node1[0], node1[3])
214 n2 = (node2[0], node2[1], node2[0], node2[3])
216 do_udp_tests(n1, n2, bandwidth, duration, ps)
217 do_udp_tests(n2, n1, bandwidth, duration, ps)
218 do_tcp_tests(n1, n2, duration)
219 do_tcp_tests(n2, n1, duration)
222 def configure_l3(conf, tunnel_mode):
224 This function creates a temporary test bridge and adds an L3 tunnel.
226 s = util.start_local_server(conf[1][1])
227 server = util.rpc_client("127.0.0.1", conf[1][1])
228 server.create_bridge(DEFAULT_TEST_BRIDGE)
229 server.add_port_to_bridge(DEFAULT_TEST_BRIDGE, DEFAULT_TEST_PORT)
230 server.interface_up(DEFAULT_TEST_BRIDGE)
231 server.interface_assign_ip(DEFAULT_TEST_BRIDGE, conf[1][0],
233 server.ovs_vsctl_set("Interface", DEFAULT_TEST_PORT, "type",
235 server.ovs_vsctl_set("Interface", DEFAULT_TEST_PORT, "options",
236 "remote_ip", conf[0])