blob: 57323efa2f26bd61dfc3f7233a396da3a6b8abf8 [file] [log] [blame]
Masayoshi Kobayashi809880d2013-03-27 04:16:01 +00001#! /bin/bash
Umesh Krishnaswamyf8a2f4d2013-03-27 21:58:20 -07002
Masayoshi Kobayashi809880d2013-03-27 04:16:01 +00003controller=`hostname`
Masayoshi Kobayashi640ad692014-01-22 23:37:59 -08004switches=`sudo ovs-vsctl list-br`
Masayoshi Kobayashi809880d2013-03-27 04:16:01 +00005
6function 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
13if [ $# != 3 ];then
14 echo "usage: $0 <dpid> <port> <up|down>"
Masayoshi Kobayashi640ad692014-01-22 23:37:59 -080015 echo " example: $0 00:00:00:00:ba:5e:ba:11 1 up"
16 exit
Masayoshi Kobayashi809880d2013-03-27 04:16:01 +000017fi
18
Masayoshi Kobayashi640ad692014-01-22 23:37:59 -080019src_dpid=`echo $1 | sed s'/://g'`
Masayoshi Kobayashi809880d2013-03-27 04:16:01 +000020src_port=$2
21cmd=$3
22
23for s in $switches; do
Masayoshi Kobayashi640ad692014-01-22 23:37:59 -080024 dpid=`sudo ovs-ofctl show $s |grep dpid | awk '{if(match($0,/dpid:[0-9|a-d]*/)){ print substr($0,RSTART+5,RLENGTH)}}'`
Masayoshi Kobayashi809880d2013-03-27 04:16:01 +000025 if [ "x$dpid" == "x$src_dpid" ]; then
Masayoshi Kobayashiabe9cfe2013-03-28 08:17:59 +000026
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 Krishnaswamyf8a2f4d2013-03-27 21:58:20 -070034 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 Kobayashi809880d2013-03-27 04:16:01 +000046 fi
47 fi
48done