#!/bin/sh
count=0;
cntr=0;
while true; do
    count=$((++count));
    echo "removing controller";
    sudo ovs-vsctl del-controller br-int;
    echo "setting controller";
    sudo ovs-vsctl set-controller br-int tcp:10.8.125.230:6653;
    echo "removing controller";
    sudo ovs-vsctl del-controller br-int;
    echo "setting controller";
    sudo ovs-vsctl set-controller br-int tcp:10.8.125.230:6653;
    echo "count is $count"
    while true; do 
        sudo ovs-vsctl show |grep -A3 "Bridge br-int" | grep is_connected;
        if [ $? -eq 1 ]
        then
            echo ".";
            cntr=$((++cntr));
            if [ $cntr -eq 10 ]
            then
                echo "Controller is NOT connected!";
                break;
            fi
            sleep 1;
        else
            echo "Controller is connected!";
            cntr=0;
            break;
        fi
    done;
done;

