Tim Lindberg | c50276e | 2013-04-10 11:32:03 -0700 | [diff] [blame] | 1 | #! /bin/bash |
| 2 | |
Naoki Shiota | d5d0e94 | 2014-03-27 18:57:32 -0700 | [diff] [blame] | 3 | SCRIPT_DIR=$(cd `dirname $0`; pwd) |
| 4 | |
Tim Lindberg | c50276e | 2013-04-10 11:32:03 -0700 | [diff] [blame] | 5 | #controller=`hostname` |
| 6 | switches=`ifconfig -a | grep sw |grep -v eth | awk '{print $1}'` |
| 7 | |
| 8 | function host2ip (){ |
| 9 | ip=`grep $1 /etc/hosts |grep -v "ip6"| awk '{print $1}'` |
| 10 | echo $ip |
| 11 | } |
| 12 | |
| 13 | # link.sh 00:00:00:00:ba:5e:ba:11 1 up |
| 14 | |
| 15 | if [ $# != 3 ];then |
| 16 | echo "usage: $0 <dpid> <port> <up|down>" |
| 17 | fi |
| 18 | |
| 19 | src_dpid="dpid:"`echo $1 | sed s'/://g'` |
| 20 | src_port=$2 |
| 21 | cmd=$3 |
| 22 | |
| 23 | if [ "x00:00:00:00:ba:5e:ba:11" == "x$1" ]; then |
| 24 | if [ x$cmd == "xup" ]; then |
Naoki Shiota | d5d0e94 | 2014-03-27 18:57:32 -0700 | [diff] [blame] | 25 | ${SCRIPT_DIR}/prontolink.exp 10.128.0.61 $src_port 1 |
Tim Lindberg | c50276e | 2013-04-10 11:32:03 -0700 | [diff] [blame] | 26 | elif [ x$cmd == "xdown" ]; then |
Naoki Shiota | d5d0e94 | 2014-03-27 18:57:32 -0700 | [diff] [blame] | 27 | ${SCRIPT_DIR}/prontolink.exp 10.128.0.61 $src_port 0 |
Tim Lindberg | c50276e | 2013-04-10 11:32:03 -0700 | [diff] [blame] | 28 | else |
| 29 | echo "no cmd" |
| 30 | fi |
| 31 | elif [ "x00:00:00:00:00:00:ba:12" == "x$1" ]; then |
| 32 | if [ x$cmd == "xup" ]; then |
Naoki Shiota | d5d0e94 | 2014-03-27 18:57:32 -0700 | [diff] [blame] | 33 | ${SCRIPT_DIR}/prontolink.exp 10.128.0.62 $src_port 1 |
Tim Lindberg | c50276e | 2013-04-10 11:32:03 -0700 | [diff] [blame] | 34 | elif [ x$cmd == "xdown" ]; then |
Naoki Shiota | d5d0e94 | 2014-03-27 18:57:32 -0700 | [diff] [blame] | 35 | ${SCRIPT_DIR}/prontolink.exp 10.128.0.62 $src_port 0 |
Tim Lindberg | c50276e | 2013-04-10 11:32:03 -0700 | [diff] [blame] | 36 | else |
| 37 | echo "no cmd" |
| 38 | fi |
| 39 | elif [ "x00:00:00:00:ba:5e:ba:13" == "x$1" ]; then |
| 40 | if [ x$cmd == "xup" ]; then |
Naoki Shiota | d5d0e94 | 2014-03-27 18:57:32 -0700 | [diff] [blame] | 41 | ${SCRIPT_DIR}/prontolink.exp 10.128.0.63 $src_port 1 |
Tim Lindberg | c50276e | 2013-04-10 11:32:03 -0700 | [diff] [blame] | 42 | elif [ x$cmd == "xdown" ]; then |
Naoki Shiota | d5d0e94 | 2014-03-27 18:57:32 -0700 | [diff] [blame] | 43 | ${SCRIPT_DIR}/prontolink.exp 10.128.0.63 $src_port 0 |
Tim Lindberg | c50276e | 2013-04-10 11:32:03 -0700 | [diff] [blame] | 44 | else |
| 45 | echo "no cmd" |
| 46 | fi |
| 47 | elif [ "x00:00:20:4e:7f:51:8a:35" == "x$1" ]; then |
| 48 | if [ x$cmd == "xup" ]; then |
Naoki Shiota | d5d0e94 | 2014-03-27 18:57:32 -0700 | [diff] [blame] | 49 | ${SCRIPT_DIR}/prontolink.exp 10.128.0.50 $src_port 1 |
Tim Lindberg | c50276e | 2013-04-10 11:32:03 -0700 | [diff] [blame] | 50 | elif [ x$cmd == "xdown" ]; then |
Naoki Shiota | d5d0e94 | 2014-03-27 18:57:32 -0700 | [diff] [blame] | 51 | ${SCRIPT_DIR}/prontolink.exp 10.128.0.50 $src_port 0 |
Tim Lindberg | c50276e | 2013-04-10 11:32:03 -0700 | [diff] [blame] | 52 | else |
| 53 | echo "no cmd" |
| 54 | fi |
| 55 | |
| 56 | elif [ "x00:01:00:16:97:08:9a:46" == "x$1" ]; then |
| 57 | if [ x$cmd == "xup" ]; then |
Naoki Shiota | d5d0e94 | 2014-03-27 18:57:32 -0700 | [diff] [blame] | 58 | ${SCRIPT_DIR}/neclink.exp $src_port no |
Tim Lindberg | c50276e | 2013-04-10 11:32:03 -0700 | [diff] [blame] | 59 | elif [ x$cmd == "xdown" ]; then |
Naoki Shiota | d5d0e94 | 2014-03-27 18:57:32 -0700 | [diff] [blame] | 60 | ${SCRIPT_DIR}/neclink.exp $src_port |
Tim Lindberg | c50276e | 2013-04-10 11:32:03 -0700 | [diff] [blame] | 61 | else |
| 62 | echo "no cmd" |
| 63 | fi |
| 64 | |
| 65 | |
| 66 | fi |
| 67 | |
| 68 | |
| 69 | |
| 70 | #for s in $switches; do |
| 71 | # dpid=`sudo ovs-ofctl show $s |grep dpid | awk '{print $4}'` |
| 72 | # if [ "x$dpid" == "x$src_dpid" ]; then |
| 73 | # |
| 74 | ## intf=`sudo ovs-ofctl show $s |grep addr | awk -v p=$src_port 'BEGIN {pat="^ "p"\("} |
| 75 | ## $0 ~ pat {w=match ($0, /\(.*\)/); if (w) print substr($0, RSTART+1, RLENGTH-2)}'` |
| 76 | # |
| 77 | # sudo ovs-ofctl show $s |grep addr | sed 's/[\(\)]/,/g'>/tmp/baz.out |
| 78 | # intf=`cat /tmp/baz.out | awk -v p=$src_port 'BEGIN {pat="^ "p","} |
| 79 | # $0 ~ pat {w=match($0, /,.*,/); if (w) print substr($0, RSTART+1, RLENGTH-2)}'` |
| 80 | # |
| 81 | # if [ x$intf != "x" ]; then |
| 82 | # if [ x$cmd == "xup" ]; then |
| 83 | # echo "sudo ifconfig ${intf} up" |
| 84 | # sudo ifconfig ${intf} up |
| 85 | # elif [ x$cmd == "xdown" ]; then |
| 86 | # echo "sudo ifconfig ${intf} down" |
| 87 | # sudo ifconfig ${intf} down |
| 88 | # else |
| 89 | # echo "sudo ifconfig ${intf}" |
| 90 | # sudo ifconfig ${intf} |
| 91 | # fi |
| 92 | # break |
| 93 | # fi |
| 94 | # fi |
| 95 | #done |