#!/bin/bash

# cleanup
nmcli c del br1 br1-port br1-iface br2 br2-port br2-iface &>/dev/null || :
ip link del dummy0 &>/dev/null || :

# passing -c is just for cleanup
[[ $1 == -c ]] && exit

# create 2 OVS bridges with one port and iface each
nmcli connection add type ovs-bridge con-name br1 ifname br1
nmcli connection add type ovs-port con-name br1-port ifname br1-port master br1 port-type ovs-bridge
nmcli connection add type ovs-interface con-name br1-iface ifname br1-iface master br1-port

nmcli connection add type ovs-bridge con-name br2 ifname br2
nmcli connection add type ovs-port con-name br2-port ifname br2-port master br2 port-type ovs-bridge
nmcli connection add type ovs-interface con-name br2-iface ifname br2-iface master br2-port

# add an external port and interface to br1
ip link add dummy0 type dummy
ovs-vsctl add-port br1 dummy0

# print
echo
echo BEFORE:
ovs-vsctl show

# deactivate br2
echo
nmcli connection down br2

# print, dummy0 must still exist
echo
echo AFTER:
ovs-vsctl show

# print test result
echo
ovs-vsctl show | grep dummy0 >/dev/null
if [[ $? == 0 ]]; then
        echo RESULT: OK
else
        echo RESULT: FAIL
fi
