blob: dc202e7872c3ba9b6f9a0d0962914634ad7d6fdb [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`
4switches=`ifconfig -a | grep sw |grep -v eth | awk '{print $1}'`
5
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>"
15fi
16
17src_dpid="dpid:"`echo $1 | sed s'/://g'`
18src_port=$2
19cmd=$3
20
21for 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 Kobayashiabe9cfe2013-03-28 08:17:59 +000024
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 Krishnaswamyf8a2f4d2013-03-27 21:58:20 -070032 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 Kobayashi809880d2013-03-27 04:16:01 +000044 fi
45 fi
46done