X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=planetlab%2Fscripts%2Fcreate_bridge;fp=planetlab%2Fscripts%2Fcreate_bridge;h=ad88305065dbaa234e85d9e1c42dd6f5c86be481;hb=1e3f34c7693bcabae8e443ac1b246680ef9b60e2;hp=0000000000000000000000000000000000000000;hpb=079b5942276a04b2b18f1ec5bd2e07170e3ab9bd;p=sliver-openvswitch.git diff --git a/planetlab/scripts/create_bridge b/planetlab/scripts/create_bridge new file mode 100755 index 000000000..ad8830506 --- /dev/null +++ b/planetlab/scripts/create_bridge @@ -0,0 +1,55 @@ +#!/bin/bash + +function error +{ + echo $1 >&2 + killall pltap-ovs 2>/dev/null || true + exit 1 +} + +function is_switch_running +{ + ovs-appctl version >/dev/null 2>&1 +} + +if [ -z "$1" ]; then + error "Usage: ${0##*/} " +fi + +# TODO: check paramether validity + +IP=${1%/*} +PREFIX=${1#*/} + +set -e + +# ensure ovs-vswitchd is running +if ! is_switch_running; then + echo "ovs-vswitchd not running" >&2 + exit 1 +fi + + +# check whether the address is already assigned +set -e +TAPNAME=$(ip addr show to "$IP/32" | perl -ne '/^\s*\d+:\s*([\w-]+):/ && print $1') +if [ ! -z "$TAPNAME" ]; then + if ovs-vsctl br-exists "$TAPNAME"; then + echo $TAPNAME + exit 0 + fi + error "$IP already assigned to $TAPNAME" +fi + +TAPNAME=$(pltap-ovs) +vsysc vif_up << EOF + $TAPNAME + $IP + $PREFIX +EOF +while ! ip link show up | egrep -q "^[0-9]+: +$TAPNAME:"; do + echo "Waiting for $TAPNAME to come UP..." >&2 + sleep 1 +done +ovs-vsctl add-br $TAPNAME -- set bridge $TAPNAME datapath_type=planetlab +echo $TAPNAME