We use the builtin functionality of ovs-vsctl to check
for already existing bridges and ports on creation,
or already non existing ones on deletion. In this way
we get a more significant return value from ovs-vsctl
in case of error.
wait_device $TAPNAME 60 && \
ovs-vsctl --db=unix:$DB_SOCKET add-br $TAPNAME -- set bridge $TAPNAME datapath_type=planetlab
echo $TAPNAME
wait_device $TAPNAME 60 && \
ovs-vsctl --db=unix:$DB_SOCKET add-br $TAPNAME -- set bridge $TAPNAME datapath_type=planetlab
echo $TAPNAME
}
function create_port () {
}
function create_port () {
is_switch_running || { echo "ovs-vswitchd not running" >&2 ; exit 1 ; }
set -e
is_switch_running || { echo "ovs-vswitchd not running" >&2 ; exit 1 ; }
set -e
- if ! ovs-vsctl --db=unix:$DB_SOCKET list-ports "$bridge" | grep -q "^$port\$"; then
- ovs-vsctl --db=unix:$DB_SOCKET add-port "$bridge" "$port" -- set interface "$port" type=tunnel
- fi
+ ovs-vsctl --db=unix:$DB_SOCKET -- --may-exist add-port "$bridge" "$port" -- set interface "$port" type=tunnel
ovs-appctl --target=ovs-vswitchd netdev-tunnel/get-port "$port"
ovs-appctl --target=ovs-vswitchd netdev-tunnel/get-port "$port"
}
function set_remote_endpoint () {
}
function set_remote_endpoint () {
ovs-vsctl --db=unix:$DB_SOCKET set interface $local_port \
options:remote_ip=$remote_ip \
options:remote_port=$remote_UDP_port
ovs-vsctl --db=unix:$DB_SOCKET set interface $local_port \
options:remote_ip=$remote_ip \
options:remote_port=$remote_UDP_port
}
#################### del functions
}
#################### del functions
- if ovs-vsctl --db=unix:$DB_SOCKET br-exists "$bridge_name"; then
- ovs-vsctl --db=unix:$DB_SOCKET $W del-br $bridge_name
- fi
- return 0
+ ovs-vsctl --db=unix:$DB_SOCKET $W -- --if-exists del-br $bridge_name
- set -e
- if ovs-vsctl --db=unix:$DB_SOCKET port-to-br "$port" >/dev/null 2>&1; then
- ovs-vsctl --db=unix:$DB_SOCKET $W del-port "$port"
- fi
- return 0
+ ovs-vsctl --db=unix:$DB_SOCKET $W -- --if-exists del-port "$port"