+function get_local_ip () {
+
+ get_params "bridge" "$@"
+
+ set -e
+ ovs-vsctl --db=unix:$DB_SOCKET br-exists "$bridge" || return
+ local ip=$(ovs-vsctl get interface "$bridge" options:local_ip)
+ local netmask=$(ovs-vsctl get interface "$bridge" options:local_netmask)
+ eval echo $ip/$netmask
+}
+
+function get_local_links () {
+
+ get_params "bridge" "$@"
+
+ set -e
+ ovs-vsctl --db=unix:$DB_SOCKET br-exists "$bridge" || return
+ ovs-vsctl --db=unix:$DB_SOCKET list-ifaces "$bridge"
+}
+
+### for demos - connect to an ndnmap deployment to visualize links bandwidth
+# this expects 3 arguments
+# an interface name, L<id1>-<id2> based on your ids in conf.mk
+# the hostname for a ndnmap deployment
+# a linkid, this is the id that this link has in your ndnmap scenario (hard-coded in some json file)
+# 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_probe_once () {
+ iface=$1; shift
+ hostname=$1; shift
+ linkid=$1; shift
+ rx_bytes=$(ovs-appctl netdev-tunnel/get-rx-bytes $iface)
+ tx_bytes=$(ovs-appctl netdev-tunnel/get-tx-bytes $iface)
+ rx_bits=$(($rx_bytes*8))
+ tx_bits=$(($tx_bytes*8))
+ now=$(date +%s).$(date +%N)
+ trigger=http://${hostname}/bw/${linkid}/${now}/${rx_bits}/${tx_bits}
+# curl -s -L $trigger | grep -q "Got it" || echo Missed event with $trigger
+# echo $trigger
+ curl -s -L $trigger >& /dev/null
+}
+
+### the front end, manages pid and so on
+function gmap_probe () {
+ iface=$1; shift
+ hostname=$1; shift
+ linkid=$1; shift
+ looptime=$1; shift
+ [ -z "$looptime" ] && looptime=1
+ pid_file=/var/run/openvswitch/gmap-$iface.pid
+ if [ -f $pid_file ] ; then
+ pid=$(cat $pid_file)
+ [ -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_probe_once $iface $hostname $linkid
+ sleep $looptime
+ done &
+ # this is the pid for the background process
+ echo $! > $pid_file
+}
+
+####################
+# xxx tmp for a demo
+# there *must* be a better way to do that
+# the thing is the slice sees several tap devices at this point, which is odd...
+# for now I'm searching the tapname based on some hint - the vnet ip range
+VNET=10.0.16
+function show_mac () {
+ ifnames=$(grep : /proc/net/dev | cut -d: -f1 | awk '{print $1;}')
+ tapname=""
+ for ifname in $ifnames; do
+ ifconfig $ifname | grep -q "$VNET" && tapname=$ifname
+ done
+ if [ -z "$tapname" ] ; then
+ echo "no-tap-found-for$VNET"
+ exit 1
+ fi
+ ifconfig $tapname | grep -i hwaddr | awk '{print $5;}'
+}
+