netdev-dpdk: fix mbuf leaks
[cascardo/ovs.git] / utilities / ovs-l3ping.in
1 #! @PYTHON@
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at:
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 """
16 ovs L3 ping utility allows to do tests between two remote hosts without
17 opening holes in the firewall for the XML RPC control connection.  This is
18 achieved by tunneling the control connection inside the tunnel itself.
19 """
20
21 import socket
22 import xmlrpclib
23
24 import ovstest.args as args
25 import ovstest.tests as tests
26 import ovstest.util as util
27
28
29 def get_packet_sizes(me, he, remote_ip):
30     """
31     This function retrieves MTUs from both hosts and returns a list of
32     packet sizes, that are more likely to uncover possible configuration
33     issues.
34     """
35     mtu_node1 = 1500
36     mtu_node2 = 1500
37     server1 = util.rpc_client(me[0], me[1])
38     server2 = util.rpc_client(he[0], he[1])
39     iface1 = server2.get_interface(remote_ip)
40     iface2 = server1.get_interface_from_routing_decision(remote_ip)
41     if iface1:
42         mtu_node1 = server2.get_interface_mtu(iface1)
43     if iface2:
44         mtu_node2 = server1.get_interface_mtu(iface2)
45     return util.get_datagram_sizes(mtu_node1, mtu_node2)
46
47
48 if __name__ == '__main__':
49     local_server = None
50     try:
51         args = args.l3_initialize_args()
52         tunnel_mode = args.tunnelMode
53         if args.server is not None:  # Start in server mode
54             local_server = tests.configure_l3(args.server, tunnel_mode)
55             local_server.wait()
56         elif args.client is not None:  # Run in client mode
57             bandwidth = args.targetBandwidth
58             interval = args.testInterval
59             me = (util.ip_from_cidr(args.client[1][0]), args.client[1][1],
60                   args.client[1][0], args.client[1][2])
61             he = (args.client[2][0], args.client[2][1],
62                   args.client[2][0], args.client[2][2])
63             local_server = tests. configure_l3(args.client, tunnel_mode)
64             ps = get_packet_sizes(me, he, args.client[0])
65             tests.do_direct_tests(me, he, bandwidth, interval, ps)
66     except KeyboardInterrupt:
67         print "Terminating"
68     except xmlrpclib.Fault:
69         print "Couldn't contact peer"
70     except socket.error:
71         print "Couldn't contact peer"
72     except xmlrpclib.ProtocolError:
73         print "XMLRPC control channel was abruptly terminated"
74     finally:
75         if local_server is not None:
76             local_server.terminate()