#!/bin/sh

set -e

modprobe openvswitch || true

echo "kernel modules loaded: "
# Check that ovs loaded
lsmod | grep "openvswitch"
echo "OK"

echo "Checking daemons: "
pgrep ovs-vswitchd
pgrep ovsdb-server
echo "OK"

echo "stop conflicting openvswitch testcontroller"
systemctl stop openvswitch-testcontroller || true

if dpkg --compare-versions "$(dpkg-query --showformat '${Version}\n' --show mininet)" ge "2.3.0-1"; then
    PYCMD="python3"
else
    PYCMD="python2"
fi

echo -n "running openflow tests using mininet"
${PYCMD} `dirname $0`/openflow.py 2>&1
echo "OK"
