Masayoshi Kobayashi | 809880d | 2013-03-27 04:16:01 +0000 | [diff] [blame] | 1 | #! /bin/bash |
| 2 | controller=`hostname` |
| 3 | switches=`ifconfig -a | grep sw |grep -v eth | awk '{print $1}'` |
| 4 | |
| 5 | function host2ip (){ |
| 6 | ip=`grep $1 /etc/hosts |grep -v "ip6"| awk '{print $1}'` |
| 7 | echo $ip |
| 8 | } |
| 9 | |
| 10 | # link.sh 00:00:00:00:ba:5e:ba:11 1 up |
| 11 | |
| 12 | if [ $# != 3 ];then |
| 13 | echo "usage: $0 <dpid> <port> <up|down>" |
| 14 | fi |
| 15 | |
| 16 | src_dpid="dpid:"`echo $1 | sed s'/://g'` |
| 17 | src_port=$2 |
| 18 | cmd=$3 |
| 19 | |
| 20 | for s in $switches; do |
| 21 | dpid=`sudo ovs-ofctl show $s |grep dpid | awk '{print $4}'` |
| 22 | if [ "x$dpid" == "x$src_dpid" ]; then |
| 23 | intfs=`sudo ovs-ofctl show $s |grep addr | awk '{print $1}' | sed 's/.*(//g' | sed 's/):$//g'` |
| 24 | intf_list=() |
| 25 | for i in $intfs; do |
| 26 | intf_list+=($i) |
| 27 | done |
| 28 | intf=${intf_list[$src_port]} |
| 29 | if [ x$cmd == "xup" ]; then |
| 30 | echo "sudo ifconfig ${intf} up" |
| 31 | sudo ifconfig ${intf} up |
| 32 | elif [ x$cmd == "xdown" ]; then |
| 33 | echo "sudo ifconfig ${intf} down" |
| 34 | sudo ifconfig ${intf} down |
| 35 | else |
| 36 | echo "sudo ifconfig ${intf}" |
| 37 | sudo ifconfig ${intf} |
| 38 | fi |
| 39 | fi |
| 40 | done |