ovs-test.in 4.63 KB
Newer Older
1
#! @PYTHON@
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
ovs test utility that allows to do tests between remote hosts
"""

19
import fcntl
20
import math
21 22 23 24 25 26 27 28 29 30 31 32 33 34
import os
import select
import signal
import socket
import subprocess
import sys
import time
import xmlrpclib

import argparse
import twisted

import ovstest.args as args
import ovstest.rpcserver as rpcserver
35 36
import ovstest.tests as tests
import ovstest.util as util
37 38 39 40 41 42

DEFAULT_TEST_BRIDGE = "ovstestbr0"
DEFAULT_TEST_PORT = "ovstestport0"
DEFAULT_TEST_TUN = "ovstestport1"


43 44 45
def collect_information(node):
    """Print information about hosts that will do testing"""
    print "Node %s:%u " % (node[0], node[1])
46
    server = util.rpc_client(node[0], node[1])
47 48 49
    interface_name = server.get_interface(node[0])
    phys_iface = None
    uname = server.uname()
50 51
    mtu = 1500

52
    if not interface_name:
53
        print ("Could not find interface that has %s IP address."
54
               "Make sure that you specified correct Outer IP." % (node[0]))
55
    else:
56 57 58 59 60 61 62 63 64 65
        if server.is_ovs_bridge(interface_name):
            phys_iface = server.get_iface_from_bridge(interface_name)
        else:
            phys_iface = interface_name

    if phys_iface:
        driver = server.get_driver(phys_iface)
        mtu = server.get_interface_mtu(phys_iface)

        print "Will be using %s (%s) with MTU %u" % (phys_iface, node[0],
66
                                                    mtu)
67 68
        if not driver:
            print "Unable to get driver information from ethtool."
69
        else:
70
            print "On this host %s has %s." % (phys_iface, driver)
71

72
    if not uname:
73 74 75 76
        print "Unable to retrieve kernel information. Is this Linux?"
    else:
        print "Running kernel %s." % uname
    print "\n"
77

78 79 80 81
    return mtu


if __name__ == '__main__':
82
    local_server = None
83 84 85
    try:
        ovs_args = args.ovs_initialize_args()

86 87
        if ovs_args.port is not None:  # Start in pure server mode
            rpcserver.start_rpc_server(ovs_args.port)
88

89
        elif ovs_args.servers is not None:  # Run in client mode
90 91 92
            node1 = ovs_args.servers[0]
            node2 = ovs_args.servers[1]

93 94 95 96
            # Verify whether client will need to spawn a local instance of
            # ovs-test server by looking at the first OuterIP. if it is a
            # 127.0.0.1 then spawn local ovs-test server.
            if node1[0] == "127.0.0.1":
97
                local_server = util.start_local_server(node1[1])
98 99
                # We must determine the IP address that local ovs-test server
                # will use:
100
                me = util.rpc_client(node1[0], node1[1])
101 102 103
                my_ip = me.get_my_address_from(node2[0], node2[1])
                node1 = (my_ip, node1[1], node1[2], node1[3])

104
            mtu_node2 = collect_information(node2)
105 106 107 108
            mtu_node1 = collect_information(node1)

            bandwidth = ovs_args.targetBandwidth
            interval = ovs_args.testInterval
109
            ps = util.get_datagram_sizes(mtu_node1, mtu_node2)
110 111 112 113 114 115 116

            direct = ovs_args.direct
            vlan_tag = ovs_args.vlanTag
            tunnel_modes = ovs_args.tunnelModes

            if direct is not None:
                print "Performing direct tests"
117
                tests.do_direct_tests(node2, node1, bandwidth, interval, ps)
118 119 120

            if vlan_tag is not None:
                print "Performing VLAN tests"
121 122
                tests.do_vlan_tests(node2, node1, bandwidth, interval, ps,
                                    vlan_tag)
123 124 125

            for tmode in tunnel_modes:
                print "Performing", tmode, "tests"
126 127
                tests.do_l3_tests(node2, node1, bandwidth, interval, ps,
                                  tmode)
128 129 130

    except KeyboardInterrupt:
        pass
131 132
    except xmlrpclib.Fault:
        print "Couldn't establish XMLRPC control channel"
133 134
    except socket.error:
        print "Couldn't establish XMLRPC control channel"
135 136 137 138 139 140 141
    except xmlrpclib.ProtocolError:
        print "XMLRPC control channel was abruptly terminated"
    except twisted.internet.error.CannotListenError:
        print "Couldn't start XMLRPC server on port %u" % ovs_args.port
    finally:
        if local_server is not None:
            local_server.terminate()