-
Notifications
You must be signed in to change notification settings - Fork 11
/
init.sh
104 lines (87 loc) · 2.58 KB
/
init.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/sh
switch_ip=10.0.0.10
switch_netmask=255.0.0.0
gateway_ip=10.0.0.1
controller_ip=10.0.0.1
controller_port=6633
local_ip=127.0.0.1
local_port=6632
ofs_dir="/root/ofs-hw"
interfaces="eth1,eth2,eth3,eth4"
ofdatapath_options="--no-slicing"
ofprotocol_options="--inactivity-probe=90"
#--datapath-id must be exactly 12 hex digits
id_num=`echo $switch_ip | awk -F '.' '{print $4}'`
if [ $id_num -lt 10 ]; then
datapath_id=00000000000$id_num
mac_d1=00
mac_d2=0$id_num
elif [ $id_num -lt 100 ]; then
datapath_id=0000000000$id_num
mac_d1=00
mac_d2=$id_num
elif [ $id_num -lt 200 ]; then
datapath_id=0000000000$id_num
mac_d1=01
mac_d2=`echo $id_num | cut -c 2-3`
else
datapath_id=000000000$id_num
mac_d1=02
mac_d2=`echo $id_num | cut -c 2-3`
fi
echo "Networking Initial, Please wait..."
# Due to driver issue, networking interfaces should be set up, then down at first.
ifconfig eth1 up
ifconfig eth2 up
ifconfig eth3 up
ifconfig eth4 up
sleep 1
ifconfig eth4 down
ifconfig eth3 down
ifconfig eth2 down
ifconfig eth1 down
ifconfig eth0 down
ifconfig eth0 hw ether 00:0a:35:$mac_d1:$mac_d2:00
ifconfig eth1 hw ether 00:0a:35:$mac_d1:$mac_d2:01
ifconfig eth2 hw ether 00:0a:35:$mac_d1:$mac_d2:02
ifconfig eth3 hw ether 00:0a:35:$mac_d1:$mac_d2:03
ifconfig eth4 hw ether 00:0a:35:$mac_d1:$mac_d2:04
sleep 1
ifconfig eth0 $switch_ip netmask $switch_netmask up
ifconfig eth1 up
ifconfig eth2 up
ifconfig eth3 up
ifconfig eth4 up
ifconfig lo up
sleep 1
ret=`route | grep "default" | awk '{print $1}'`
if [ ! $ret ]; then
route add default gw $gateway_ip
fi
echo "Network Interfaces Initial Done"
if [ ! -d $ofs_dir ]; then
echo "ERROR: Please copy ofs binaries to the directory \"$ofs_dir\""
exit
fi
echo "Entering ofs directory \"$ofs_dir\"..."
cd $ofs_dir
echo "Starting configuring udatapath..."
./udatapath/ofdatapath --datapath-id=$datapath_id --interfaces=$interfaces ptcp:$local_port $ofdatapath_options &
sleep 3
ret=`ps | grep "ofdatapath" | awk '{print $6}'`
if [ ! $ret ]; then
echo "ERROR: Excuting ofdatapath failed, please check..."
exit
fi
sleep 3
echo "Write packet-in entry to first software table #3"
./utilities/dpctl tcp:$local_ip:$local_port flow-mod cmd=add,table=3,prio=0 apply:output=ctrl:65527
echo "Starting configuring secure channel..."
./secchan/ofprotocol tcp:$local_ip:$local_port tcp:$controller_ip:$controller_port $ofprotocol_options &
sleep 3
ret=`ps | grep "ofprotocol" | awk '{print $6}'`
if [ ! $ret ]; then
echo "ERROR: Excuting ofprotocol failed, please check..."
exit
fi
echo "Openflow Switch Configured Succeessfully"