Merge branch 'master' of ssh://git.onelab.eu/git/sliver-openvswitch
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Fri, 5 Oct 2012 12:43:16 +0000 (14:43 +0200)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Fri, 5 Oct 2012 12:43:16 +0000 (14:43 +0200)
1  2 
planetlab/exp-tool/Makefile
planetlab/scripts/sliver-ovs.in

@@@ -155,18 -155,20 +155,20 @@@ cache/db.%
        @echo "Starting db server on $(call display,$*) - logs in $(call log,$@)"
        @$(SSH) $(HOST_$*) $(SUDO) sliver-ovs start-db &> $(call log,$@) && touch $@
  
- cache/switch.%: cache/db.%
+ cache/switch.%: cache/db.%
        @echo "Starting vswitchd on $(call display,$*) - logs in $(call log,$@)"
        @$(SSH) $(HOST_$*) $(SUDO) sliver-ovs start-switch &> $(call log,$@) && touch $@
  
- cache/bridge.%: cache/switch.%
+ cache/bridge.%: | cache/db.%
        @echo "Creating bridge on $(call display,$*) - logs in $(call log,$@)"
-       @$(SSH) $(HOST_$*) $(SUDO) sliver-ovs create-bridge $(BRIDGE) $(IP_$*) > $@ 2> $(call log,$@) || { rm $@; exit 1; }
-       @echo Created bridge with tap $$(cat $@) on $(call display,$*)
+       @$(SSH) $(HOST_$*) $(SUDO) \
+               sliver-ovs create-bridge $(BRIDGE) $(IP_$*) $(call default,BROPTIONS,$*) &> $(call log,$@) \
+        && touch $@
  
  cache/controller.%: cache/bridge.%
        @echo "Setting controller $(call default,CONTROLLER,$*) on $(call display,$*) - logs in $(call log,$@)"
-       @$(SSH) $(HOST_$*) $(SUDO) ovs-vsctl set-controller $(BRIDGE) $(call default,CONTROLLER,$*) &> $(call log,$@) || { rm $@; exit 1; }
+       @$(SSH) $(HOST_$*) $(SUDO) ovs-vsctl set-controller $(BRIDGE) $(call default,CONTROLLER,$*) &> $(call log,$@) \
+        && touch $@
  
  # xxx this probably needs a more thorough cleanup in cache/
  cache/stop.%: del-bridge.%
  
  ### link-oriented targets
  # L/<nodeid>-<node_id>
- L/%: cache/link.%@1 cache/link.%@2
+ L/%: cache/endpoint.%@1 cache/endpoint.%@2
        @touch $@
-       @echo "Created link $*"
+       @echo "Link $* is up"
  
  U/%: del-iface.%@1 del-iface.%@2
        @rm -f L/$*
        @echo "Deleted link $*"
  
- del-bridge.%: cache/db.%
+ del-bridge.%: cache/db.%
        @echo "Deleting bridge on $(call display,$*)"
        @$(SSH) $(HOST_$*) $(SUDO) sliver-ovs del-bridge $(BRIDGE);
        @rm -f cache/bridge.$* \
              cache/iface.$*$(SEP)*@1 cache/iface.*$(SEP)$*@2 \
-             cache/link.$*$(SEP)*@?  cache/link.*$(SEP)$*@?  \
+             cache/port.$*$(SEP)*@1  cache/port.*$(SEP)$*@2  \
+             cache/endpoint.$*$(SEP)*@?  cache/endpoint.*$(SEP)$*@?  \
              L/$*$(SEP)*             L/*$(SEP)$*
  
- del-switch.%: del-bridge.%
+ del-switch.%:
        @echo "Shutting down switch on $(call display,$*)"
        @$(SSH) $(HOST_$*) $(SUDO) sliver-ovs stop-switch
-       @rm -f cache/switch.$* 
+       @rm -f cache/switch.$* \
+              cache/port.$*$(SEP)*@1  cache/port.*$(SEP)$*@2  \
+              cache/endpoint.$*$(SEP)*@2  cache/endpoint.*$(SEP)$*@1  \
+              L/$*$(SEP)*            L/*$(SEP)$*
  
  del-db.%:
        @echo "Shutting down db on $(call display,$*)"
        @$(SSH) $(HOST_$*) $(SUDO) sliver-ovs stop-db
        @rm -f cache/db.$*
  
- del-controller-%:
+ del-controller-%: | cache/db.%
        @echo "Removing controller for $(call display,$*)"
        @$(SSH) $(HOST_$*) $(SUDO) sliver-ovs del-controller $(BRIDGE)
        @rm -f cache/controller.$*
  
- del-links: $(addprefix U/,$(notdir $(filter-out %.log,$(wildcard L/*))))
+ del-links: $(addprefix U/,$(notdir $(wildcard L/*)))
  
- del-switchs: $(addprefix del-,$(notdir $(filter-out %.log,$(wildcard cache/switch.*))))
+ del-switchs: $(addprefix del-,$(notdir $(wildcard cache/switch.*)))
  
- del-dbs: $(addprefix del-,$(notdir $(filter-out %.log,$(wildcard cache/db.*))))
+ del-dbs: $(addprefix del-,$(notdir $(wildcard cache/db.*)))
  
  shutdown: del-switchs del-dbs
  
@@@ -253,11 -259,11 +259,11 @@@ cache/rsnap.links.%
  
  .SECONDEXPANSION:
  
- del-iface.%: cache/db.$$(call get,%)
+ del-iface.%: 
        @echo "Removing interface for link $(call linkpart,$*) from $(call get,$*)"
        @$(SSH) $(HOST_$(call get,$*)) \
                $(SUDO) sliver-ovs del-port L$(call linkpart,$*)
-       @rm -f cache/iface.$* cache/link.$* cache/link.$(call opp,$*)
+       @rm -f cache/iface.$* cache/port.$* cache/endpoint.$* cache/endpoint.$(call opp,$*)
  
  
  ### '%' here is leftid-rightid@{1,2}
  #linkid=$(call linkpart,%)
  #nodeid=$(call get,%)
  #bridgefile=cache/bridge.$(nodeid)
- cache/iface.%: cache/bridge.$$(call get,%)
+ cache/iface.%: cache/bridge.$$(call get,%) | cache/switch.$$(call get,%)
        @echo "Creating interface for link $(call linkpart,$(*F)) on $(call display,$(call get,$(*F))) - logs in $(call log,$@)"
        @$(SSH) $(call solve,$(call get,$(*F))) $(SUDO) sliver-ovs create-port $(BRIDGE) \
-               L$(call linkpart,$(*F)) > $@ 2> $(call log,$@) || { rm $@; exit 1; }
+               L$(call linkpart,$(*F)) &> $(call log,$@) \
+        && touch $@
+ cache/port.%: cache/iface.% cache/switch.$$(call get,%)
+       @echo "Getting port number for link $(call linkpart,$(*F)) on $(call display,$(call get,$(*F))) - logs in $(call log,$@)"
+       @$(SSH) $(call solve,$(call get,$(*F))) $(SUDO) \
+               ovs-appctl netdev-tunnel/get-port L$(call linkpart,$(*F)) > $@ 2> $(call log,$@) \
+        || { rm $@; exit 1; }
  
  
  # linkid=$(call linkpart,%)
  # nodeid=$(call get,%)
  # iface1=cache/iface.%
  # iface2=cache/iface.$(call opp,%)
- cache/link.%: cache/host.$$(call rget,%) cache/iface.% cache/iface.$$(call opp,%)
+ cache/endpoint.%: cache/host.$$(call rget,%) cache/port.$$(call opp,%) cache/iface.%
        @echo "Setting port number of link $(call linkpart,$(*F)) on $(call display,$(call get,$(*F))) - logs in $(call log,$@)"
        @$(SSH) $(call solve,$(call get,$(*F))) $(SUDO) sliver-ovs set-remote-endpoint L$(call linkpart,$(*F)) \
                        $$(cat cache/host.$(call rget,$(*F))) \
-                       $$(cat cache/iface.$(call opp,$(*F))) 2> $(call log,$@) \
+                       $$(cat cache/port.$(call opp,$(*F))) 2> $(call log,$@) \
         && touch $@
  
  ####################
- CLEANTARGETS=$(addprefix del-,$(notdir $(filter-out %.log,$(wildcard cache/bridge.*))))
+ CLEANTARGETS=$(addprefix del-,$(notdir $(wildcard cache/bridge.*)))
  clean: $(CLEANTARGETS)
  distclean:
        rm -rf L log cache
@@@ -295,23 -308,6 +308,23 @@@ graph.dot
  graph.ps: graph.dot
        dot -Tps < $^ > $@      
  
 +####################
 +# googlemap stuff
 +# Uses:
 +# GMAP_SERVER, the hostname that runs an ndnmap instance
 +# GMAP_PROBES, a list of tuples of the form
 +# <linkid>=<nodeid>=<internal_linkid>=<frequency>
 +# e.g.
 +# SENDER-MUX=SENDER=3=0.5
 +# which would mean, the link 'SENDER-MUX' should be monitored at the 'SENDER' node and is coded 
 +# in links.json with id=3, every half second
 +# sliver-ovs gmap-probe is designed to run in background,
 +# and so that a new run will kill any previously running instance
 +gprobes: $(foreach probe,$(GMAP_PROBES),gprobe-$(probe))
 +
 +gprobe-%: FORCE
 +      $(SSH) -n $(call solve,$(word 2,$(subst @, ,$(*F)))) $(SUDO) \
 +      sliver-ovs gmap-probe L$(word 1,$(subst @, ,$(*F))) $(GMAP_SERVER) $(word 3,$(subst @, ,$(*F))) $(word 4,$(subst @, ,$(*F)))
  
  ####################
  # 'virtual' targets in that there's no real file attached
@@@ -332,7 -328,7 +345,7 @@@ $(foreach id,$(ALL_NODE_IDS), $(eval $(
  
  define link_shortcuts
  iface.%: cache/iface.%
link.%: cache/link.%
endpoint.%: cache/endpoint.%
  endef
  
  $(foreach id,$(ALL_LINK_IDS), $(eval $(call link_shortcuts,$(id))))
@@@ -29,7 -29,7 +29,7 @@@ function error 
  function get_params {
      params=$1; shift
      err_msg="$COMMAND $SUBCOMMAND $(echo $params | perl -pe 's/\S+/<$&>/g')"
-     for p in $(echo $params); do
+     for p in $params; do
          [[ -z "$@" ]] && error "$err_msg"
          pname=$(echo -n $p|perl -pe 's/\W/_/g')
          eval $pname="$1"; shift
@@@ -157,19 -157,26 +157,26 @@@ function stop () 
  #################### create functions
  function create_bridge () {
      
-     get_params "bridge IP/PREFIX" "$@"
+     get_params "bridge IP/PREFIX" "$1" "$2"
+     shift; shift;
  
      IP=${IP_PREFIX%/*}
      PREFIX=${IP_PREFIX#*/}
  
-     # ensure ovs-vswitchd is running
-     is_switch_running || { echo "ovs-vswitchd not running" >&2 ; exit 1 ; }
+     W=
+     if ! is_switch_running; then
+       # we can create 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
-     ovs-vsctl --db=unix:$DB_SOCKET -- --may-exist add-br "$bridge" \
+     ovs-vsctl --db=unix:$DB_SOCKET $W -- --may-exist add-br "$bridge" \
        -- set bridge "$bridge" datapath_type=planetlab \
-       -- set interface "$bridge" options:local_ip="$IP" option:local_netmask="$PREFIX"
-     ovs-appctl netdev-pltap/get-tapname "$bridge"
+       -- set interface "$bridge" options:local_ip="$IP" option:local_netmask="$PREFIX" \
+       -- "$@"
  }
  
  function create_port () {
@@@ -267,7 -274,7 +274,7 @@@ function show () 
  # this one-shot function writes the current statistics onto the ndnmap site
  # it needs to be called regularly so that ndnmap can do the bw computations
  # would make sense for the caller to redirect stderr onto some relevant location
 -function gmap_report_once () {
 +function gmap_probe_once () {
      iface=$1; shift
      hostname=$1; shift
      linkid=$1; shift
  }
  
  ### the front end, manages pid and so on
 -function gmap_report () {
 +function gmap_probe () {
      iface=$1; shift
      hostname=$1; shift
      linkid=$1; shift
        [ -n "$pid" ] && kill $pid >& /dev/null
        rm $pid_file
      fi
 +    # close std fds so that ssh invokations can return
 +    exec <&-
 +    exec >&-
      while true; do
 -      gmap_report_once $iface $hostname $linkid
 +      gmap_probe_once $iface $hostname $linkid
        sleep $looptime
      done &
      # this is the pid for the background process
  SUPPORTED_SUBCOMMANDS="start stop status 
  start_db stop_db start_switch stop_switch
  create_bridge create_port del_bridge del_port
 -show set_remote_endpoint set_controller del_controller gmap_report"
 +show set_remote_endpoint set_controller del_controller gmap_probe"
  
  function main () {
        message="Usage: $COMMAND <subcommand> ...