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` |
Masayoshi Kobayashi | 640ad69 | 2014-01-22 23:37:59 -0800 | [diff] [blame] | 4 | switches=`sudo ovs-vsctl list-br` |
Masayoshi Kobayashi | 809880d | 2013-03-27 04:16:01 +0000 | [diff] [blame] | 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>" |
Masayoshi Kobayashi | 640ad69 | 2014-01-22 23:37:59 -0800 | [diff] [blame] | 15 | echo " example: $0 00:00:00:00:ba:5e:ba:11 1 up" |
| 16 | exit |
Masayoshi Kobayashi | 809880d | 2013-03-27 04:16:01 +0000 | [diff] [blame] | 17 | fi |
| 18 | |
Masayoshi Kobayashi | 640ad69 | 2014-01-22 23:37:59 -0800 | [diff] [blame] | 19 | src_dpid=`echo $1 | sed s'/://g'` |
Masayoshi Kobayashi | 809880d | 2013-03-27 04:16:01 +0000 | [diff] [blame] | 20 | src_port=$2 |
| 21 | cmd=$3 |
| 22 | |
| 23 | for s in $switches; do |
Masayoshi Kobayashi | 640ad69 | 2014-01-22 23:37:59 -0800 | [diff] [blame] | 24 | dpid=`sudo ovs-ofctl show $s |grep dpid | awk '{if(match($0,/dpid:[0-9|a-d]*/)){ print substr($0,RSTART+5,RLENGTH)}}'` |
Masayoshi Kobayashi | 809880d | 2013-03-27 04:16:01 +0000 | [diff] [blame] | 25 | if [ "x$dpid" == "x$src_dpid" ]; then |
Masayoshi Kobayashi | abe9cfe | 2013-03-28 08:17:59 +0000 | [diff] [blame] | 26 | |
| 27 | # intf=`sudo ovs-ofctl show $s |grep addr | awk -v p=$src_port 'BEGIN {pat="^ "p"\("} |
| 28 | # $0 ~ pat {w=match ($0, /\(.*\)/); if (w) print substr($0, RSTART+1, RLENGTH-2)}'` |
| 29 | |
| 30 | sudo ovs-ofctl show $s |grep addr | sed 's/[\(\)]/,/g'>/tmp/baz.out |
| 31 | intf=`cat /tmp/baz.out | awk -v p=$src_port 'BEGIN {pat="^ "p","} |
| 32 | $0 ~ pat {w=match($0, /,.*,/); if (w) print substr($0, RSTART+1, RLENGTH-2)}'` |
| 33 | |
Umesh Krishnaswamy | f8a2f4d | 2013-03-27 21:58:20 -0700 | [diff] [blame] | 34 | if [ x$intf != "x" ]; then |
| 35 | if [ x$cmd == "xup" ]; then |
| 36 | echo "sudo ifconfig ${intf} up" |
| 37 | sudo ifconfig ${intf} up |
| 38 | elif [ x$cmd == "xdown" ]; then |
| 39 | echo "sudo ifconfig ${intf} down" |
| 40 | sudo ifconfig ${intf} down |
| 41 | else |
| 42 | echo "sudo ifconfig ${intf}" |
| 43 | sudo ifconfig ${intf} |
| 44 | fi |
| 45 | break |
Masayoshi Kobayashi | 809880d | 2013-03-27 04:16:01 +0000 | [diff] [blame] | 46 | fi |
| 47 | fi |
| 48 | done |