forked from dlinknctu/OpenNet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·255 lines (207 loc) · 6.96 KB
/
install.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#!/bin/bash
#==============================================================================
#title : install.sh
#description : This script will install OpenNet
# Support Ubuntu 14.04.1, CentOS 7, Fedora 21
#==============================================================================
set -o nounset
set -e
ROOT_PATH=`pwd`
OVS_VERSION='2.3.1'
MININET_VERSION='2.2.0'
NS3_VERSION='3.21'
PYGCCXML_VERSION='1.0.0'
DIST=Unknown
RELEASE=Unknown
CODENAME=Unknown
function detect_os {
test -e /etc/fedora-release && DIST="Fedora"
test -e /etc/centos-release && DIST="CentOS"
if [ "$DIST" = "Fedora" ] || [ "$DIST" = "CentOS" ]; then
install='yum -y install'
remove='yum -y erase'
pkginst='rpm -ivh'
# Prereqs for this script
if ! which lsb_release &> /dev/null; then
$install redhat-lsb-core
fi
fi
if which lsb_release &> /dev/null; then
DIST=`lsb_release -is`
RELEASE=`lsb_release -rs`
CODENAME=`lsb_release -cs`
fi
grep Ubuntu /etc/lsb-release &> /dev/null && DIST="Ubuntu"
if [ "$DIST" = "Ubuntu" ] ; then
install='apt-get -y install'
remove='apt-get -y remove'
pkginst='dpkg -i'
# Prereqs for this script
if ! which lsb_release &> /dev/null; then
$install lsb-release
fi
fi
echo "Detected Linux distribution: $DIST $RELEASE $CODENAME"
}
function mininet {
echo "Fetch Mininet"
cd $ROOT_PATH
if [ ! -d mininet ]; then
git clone https://github.com/mininet/mininet.git
fi
cd $ROOT_PATH/mininet && git checkout tags/$MININET_VERSION
cp $ROOT_PATH/mininet-patch/util/install.sh $ROOT_PATH/mininet/util/
./util/install.sh -fn
}
function openvswitch {
cd $ROOT_PATH
if [ "$DIST" = "Ubuntu" ]; then
wget http://openvswitch.org/releases/openvswitch-$OVS_VERSION.tar.gz
tar zxvf openvswitch-$OVS_VERSION.tar.gz && cd openvswitch-$OVS_VERSION
#TODO Need to integrate *deb
dpkg-checkbuilddeps
fakeroot debian/rules binary
dpkg -i $ROOT_PATH/openvswitch-switch_$OVS_VERSION-1_amd64.deb $ROOT_PATH/openvswitch-common_$OVS_VERSION-1_amd64.deb
fi
if [ "$DIST" = "CentOS" ] || [ "$DIST" = "Fedora" ]; then
mkdir -p $ROOT_PATH/rpmbuild/SOURCES/ && cd $ROOT_PATH/rpmbuild/SOURCES/
wget http://openvswitch.org/releases/openvswitch-$OVS_VERSION.tar.gz
tar zxvf openvswitch-$OVS_VERSION.tar.gz && cd openvswitch-$OVS_VERSION
rpmbuild -bb --define "_topdir $ROOT_PATH/rpmbuild" --without check rhel/openvswitch.spec
rpm -ivh --replacepkgs --replacefiles --nodeps $ROOT_PATH/rpmbuild/RPMS/x86_64/openvswitch*.rpm
/etc/init.d/openvswitch start
fi
}
function ns3 {
echo "Fetch ns-$NS3_VERSION"
cd $ROOT_PATH
if [ ! -f ns-allinone-$NS3_VERSION.tar.bz2 ]; then
curl -O -k https://www.nsnam.org/release/ns-allinone-$NS3_VERSION.tar.bz2
fi
tar xf ns-allinone-$NS3_VERSION.tar.bz2
}
function pygccxml {
echo "Fetch and install pygccxml"
cd $ROOT_PATH
if [ ! -f pygccxml-$PYGCCXML_VERSION.zip ]; then
wget http://nchc.dl.sourceforge.net/project/pygccxml/pygccxml/pygccxml-1.0/pygccxml-$PYGCCXML_VERSION.zip
fi
unzip -o pygccxml-$PYGCCXML_VERSION.zip && cd $ROOT_PATH/pygccxml-$PYGCCXML_VERSION
python setup.py install
if [ "$DIST" = "Fedora" ] || [ "$DIST" = "CentOS" ]; then
sed -e "s/gccxml\_path=''/gccxml\_path='\/usr\/local\/bin'/" -i /usr/lib/python2.7/site-packages/pygccxml/parser/config.py
fi
if [ "$DIST" = "Ubuntu" ]; then
sed -e "s/gccxml_path=''/gccxml_path='\/usr\/local\/bin'/" -i /usr/local/lib/python2.7/dist-packages/pygccxml/parser/config.py
fi
}
function gccxml {
echo "Install gccxml"
cd $ROOT_PATH
if [ ! -d gccxml ]; then
git clone https://github.com/gccxml/gccxml.git
fi
cd gccxml
mkdir -p gccxml-build && cd gccxml-build
cmake ../
make
make install
if [ ! -L /bin/gccxml ]; then
ln -s /usr/local/bin/gccxml /bin/gccxml
fi
}
function enviroment {
echo "Prepare Enviroment"
if [ "$DIST" = "Fedora" ] || [ "$DIST" = "CentOS" ]; then
$install make git vim openssh openssh-server unzip curl gcc wget \
gcc-c++ python python-devel cmake glibc-devel.i686 glibc-devel.x86_64 net-tools \
make python-devel openssl-devel kernel-devel graphviz kernel-debug-devel \
autoconf automake rpm-build redhat-rpm-config libtool
SELINUX_STATUS="$(grep SELINUX=disabled /etc/selinux/config)"
if [ $? -eq 1 ]; then
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
fi
systemctl stop firewalld.service
systemctl disable firewalld.service
fi
if [ "$DIST" = "Ubuntu" ] ; then
$install gcc g++ python python-dev make cmake gcc-4.8-multilib g++-4.8-multilib \
python-setuptools unzip curl build-essential debhelper make autoconf automake \
patch dpkg-dev libssl-dev libncurses5-dev libpcre3-dev graphviz python-all \
python-qt4 python-zopeinterface python-twisted-conch
fi
wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py -O - | python
}
function opennet {
echo "Install OpenNet"
cd $ROOT_PATH
cp mininet-patch/mininet/ns3.py mininet/mininet/
cp mininet-patch/mininet/node.py mininet/mininet/
cp mininet-patch/examples/wifiroaming.py mininet/examples/
#rebuild mininet
$ROOT_PATH/mininet/util/install.sh -n
#patch
cp $ROOT_PATH/ns3-patch/*.patch $ROOT_PATH/ns-allinone-3.21/ns-3.21
cd $ROOT_PATH/ns-allinone-3.21/ns-3.21
patch -p1 < animation-interface.patch
patch -p1 < netanim-python.patch
patch -p1 < sta-wifi-scan.patch
if [ "$DIST" = "Ubuntu" ]; then
sed -e "s/\['network'\]/\['internet', 'network', 'core'\]/" -i src/tap-bridge/wscript
fi
./waf configure
./waf --apiscan=netanim
./waf --apiscan=wifi
./waf build
}
function finish {
echo " OpenNet installation complete."
echo " Please try following commands to run the simulation/"
echo " \$ cd $ROOT_PATH/ns-allinone-3.21/ns-3.21/"
echo " \$ ./waf shell"
echo " \$ cd $ROOT_PATH/mininet/examples"
echo " \$ python wifiroaming.py"
}
function all {
detect_os
enviroment
pygccxml
gccxml
ns3
mininet
openvswitch
opennet
finish
}
function usage {
echo
echo Usage: $(basename $0) -[$PARA] >&2
echo "-a: Install OpenNet World"
echo "-f: Finish message"
echo
exit 2
}
PARA='amdhenpgosf'
if [ $# -eq 0 ]
then
usage
else
while getopts $PARA OPTION
do
case $OPTION in
a) all;;
m) mininet;;
d) detect_os;;
h) usage;;
e) enviroment;;
n) ns3;;
p) pygccxml;;
g) gccxml;;
o) opennet;;
s) openvswitch;;
f) finish;;
esac
done
shift $(($OPTIND - 1))
fi