Merge branch 'master' of ssh://git.onelab.eu/git/sliver-openvswitch
authorGiuseppe Lettieri <g.lettieri@iet.unipi.it>
Tue, 11 Sep 2012 07:49:04 +0000 (09:49 +0200)
committerGiuseppe Lettieri <g.lettieri@iet.unipi.it>
Tue, 11 Sep 2012 07:49:04 +0000 (09:49 +0200)
Conflicts:
planetlab/scripts/sliver-ovs

1  2 
planetlab/scripts/sliver-ovs

@@@ -11,7 -11,6 +11,7 @@@ DB_CONF_FILE=/etc/openvswitch/conf.d
  DB_SCHEMA=/usr/share/openvswitch/vswitch.ovsschema
  DB_PID_FILE=/var/run/openvswitch/db.pid
  DB_LOG=/var/log/ovs-db.log
 +DB_CTRL_SOCKET=/var/run/openvswitch/db-ctrl.sock
  ##
  DB_SOCKET=/var/run/openvswitch/db.sock
  ##
@@@ -34,10 -33,6 +34,10 @@@ function is_switch_running 
      ovs-appctl --target=$SWITCH_SOCKET version >& /dev/null
  }
  
 +function is_db_running {
 +    ovs-appctl --target=$DB_CTRL_SOCKET version >& /dev/null
 +}
 +
  function tapname () {
      IP=$1; shift
      echo $(ip addr show to "$IP/32" | perl -ne '/^\s*\d+:\s*([\w-]+):/ && print $1')
@@@ -99,7 -94,6 +99,7 @@@ function start_db () 
            --bootstrap-ca-cert=db:SSL,ca_cert \
            --pidfile=$DB_PID_FILE \
            --log-file=$DB_LOG \
 +          --unixctl=$DB_CTRL_SOCKET \
            --detach >& /dev/null
      else
        echo 'ovsdb-server appears to be running already, *not* starting'
@@@ -114,9 -108,6 +114,9 @@@ function start_switch () 
  
      [[ -n "$@" ]] && error "Usage: $COMMAND start-switch"
  
 +    # ensure ovsdb-server is running
 +    is_db_running || { echo "ovsdb-server not running" >&2 ; exit 1 ; }
 +
      if [ ! -f "$SWITCH_PID_FILE" ] ; then
        ovs-vswitchd \
            --pidfile=$SWITCH_PID_FILE \
@@@ -181,7 -172,7 +181,7 @@@ function create_bridge () 
        $PREFIX
  EOF
      wait_device $TAPNAME 60 && \
-       ovs-vsctl --db=$DB_SOCKET add-br $TAPNAME -- set bridge $TAPNAME datapath_type=planetlab
+       ovs-vsctl --db=unix:$DB_SOCKET add-br $TAPNAME -- set bridge $TAPNAME datapath_type=planetlab
      echo $TAPNAME
      return 0
  }
@@@ -193,12 -184,9 +193,12 @@@ function create_port () 
      port=$1; shift
      [[ -n "$@" ]] || error "$COMMAND create-port <bridge> <port>"
  
 +    # ensure ovs-vswitchd is running
 +    is_switch_running || { echo "ovs-vswitchd not running" >&2 ; exit 1 ; }
 +
      set -e
-     if ! ovs-vsctl --db=$DB_SOCKET list-ports "$bridge" | grep -q "^$port\$"; then
-       ovs-vsctl --db=$DB_SOCKET add-port "$bridge" "$port" -- set interface "$port" type=tunnel
+     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-appctl --target=$SWITCH_SOCKET netdev-tunnel/get-port "$port"
      return 0
@@@ -212,16 -200,10 +212,15 @@@ function del_bridge () 
      [[ -n "$@" ]] && error "Usage: ${COMMAND} del-bridge <bridge name>"
  
      W=
 -    is_switch_running || W="--no-wait"
 +    if ! is_switch_running; then
 +      # we can delete the bridge even if ovs-vswitchd is not running,
 +      # but we need a running ovsdb-server
 +      is_db_running || { echo "ovsdb-server not running" >&2; exit 1; }
 +      W="--no-wait"
 +    fi
  
-     set -e
-     if ovs-vsctl --db=$DB_SOCKET $W br-exists "$bridge_name"; then
-       ovs-vsctl --db=$DB_SOCKET $W del-br $bridge_name
+     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
  }
@@@ -231,17 -213,9 +230,17 @@@ function del_port () 
      bridge_name=$1; shift
      [[ -n "$@" ]] && error "Usage: ${COMMAND} del-port <port>"
  
 +    W=
 +    if ! is_switch_running; then
 +      # we can delete the port even if ovs-vswitchd is not running,
 +      # but we need a running ovsdb-server
 +      is_db_running || { echo "ovsdb-server not running" >&2; exit 1; }
 +      W="--no-wait"
 +    fi
 +
      set -e
-     if ovs-vsctl --db=$DB_SOCKET $W port-to-br "$1" >/dev/null 2>&1; then
-       ovs-vsctl --db=$DB_SOCKET $W del-port "$1"
+     if ovs-vsctl --db=unix:$DB_SOCKET port-to-br "$1" >/dev/null 2>&1; then
 -      ovs-vsctl --db=unix:$DB_SOCKET del-port "$1"
++      ovs-vsctl --db=unix:$DB_SOCKET $W del-port "$1"
      fi
      return 0
  }