Masayoshi Kobayashi | 809880d | 2013-03-27 04:16:01 +0000 | [diff] [blame] | 1 | #! /bin/bash |
Umesh Krishnaswamy | f8a2f4d | 2013-03-27 21:58:20 -0700 | [diff] [blame] | 2 | |
Masayoshi Kobayashi | 809880d | 2013-03-27 04:16:01 +0000 | [diff] [blame] | 3 | controller=`hostname` |
| 4 | switches=`ifconfig -a | grep sw |grep -v eth | awk '{print $1}'` |
| 5 | |
| 6 | function host2ip (){ |
| 7 | ip=`grep $1 /etc/hosts |grep -v "ip6"| awk '{print $1}'` |
| 8 | echo $ip |
| 9 | } |
| 10 | |
| 11 | # link.sh 00:00:00:00:ba:5e:ba:11 1 up |
| 12 | |
| 13 | if [ $# != 3 ];then |
| 14 | echo "usage: $0 <dpid> <port> <up|down>" |
| 15 | fi |
| 16 | |
| 17 | src_dpid="dpid:"`echo $1 | sed s'/://g'` |
| 18 | src_port=$2 |
| 19 | cmd=$3 |
| 20 | |
| 21 | for s in $switches; do |
| 22 | dpid=`sudo ovs-ofctl show $s |grep dpid | awk '{print $4}'` |
| 23 | if [ "x$dpid" == "x$src_dpid" ]; then |
Masayoshi Kobayashi | abe9cfe | 2013-03-28 08:17:59 +0000 | [diff] [blame] | 24 | |
| 25 | # intf=`sudo ovs-ofctl show $s |grep addr | awk -v p=$src_port 'BEGIN {pat="^ "p"\("} |
| 26 | # $0 ~ pat {w=match ($0, /\(.*\)/); if (w) print substr($0, RSTART+1, RLENGTH-2)}'` |
| 27 | |
| 28 | sudo ovs-ofctl show $s |grep addr | sed 's/[\(\)]/,/g'>/tmp/baz.out |
| 29 | intf=`cat /tmp/baz.out | awk -v p=$src_port 'BEGIN {pat="^ "p","} |
| 30 | $0 ~ pat {w=match($0, /,.*,/); if (w) print substr($0, RSTART+1, RLENGTH-2)}'` |
| 31 | |
Umesh Krishnaswamy | f8a2f4d | 2013-03-27 21:58:20 -0700 | [diff] [blame] | 32 | if [ x$intf != "x" ]; then |
| 33 | if [ x$cmd == "xup" ]; then |
| 34 | echo "sudo ifconfig ${intf} up" |
| 35 | sudo ifconfig ${intf} up |
| 36 | elif [ x$cmd == "xdown" ]; then |
| 37 | echo "sudo ifconfig ${intf} down" |
| 38 | sudo ifconfig ${intf} down |
| 39 | else |
| 40 | echo "sudo ifconfig ${intf}" |
| 41 | sudo ifconfig ${intf} |
| 42 | fi |
| 43 | break |
Masayoshi Kobayashi | 809880d | 2013-03-27 04:16:01 +0000 | [diff] [blame] | 44 | fi |
| 45 | fi |
| 46 | done |