1 | #!/usr/bin |
---|
2 | # ===================================================================== |
---|
3 | # |
---|
4 | # This script is to generate ospf configuration for the VMs |
---|
5 | # that has XORP installed, and start xorp process. |
---|
6 | # |
---|
7 | # The script first to get the network configuration information, |
---|
8 | # such as virtual interfaces (neither eth0 nor lo), hostname, etc. |
---|
9 | # |
---|
10 | # Secondly, the script will start xorp process in the VM |
---|
11 | # |
---|
12 | # |
---|
13 | # Code by Xuan Liu |
---|
14 | # xliu@bbn.com |
---|
15 | # |
---|
16 | # June 9, 2014 |
---|
17 | # ===================================================================== |
---|
18 | |
---|
19 | |
---|
20 | cd /local/xorp_autostart/ |
---|
21 | |
---|
22 | ABS_PATH=/local/xorp_autostart |
---|
23 | |
---|
24 | vm_info_file=$ABS_PATH/vm_info.txt |
---|
25 | host=echo `hostname` |
---|
26 | echo $host |
---|
27 | |
---|
28 | # get hostname |
---|
29 | hostname | sudo tee $vm_info_file > /dev/null |
---|
30 | # get interface information |
---|
31 | /sbin/ifconfig | egrep 'eth|inet addr' | sudo tee -a $vm_info_file > /dev/null |
---|
32 | # get timestamp |
---|
33 | timestamp=$(date +"%Y-%m-%d %r") |
---|
34 | echo $timestamp |
---|
35 | |
---|
36 | |
---|
37 | xorp_conf_dir=/etc/xorp |
---|
38 | |
---|
39 | if [ -d $xorp_conf_dir ] |
---|
40 | then |
---|
41 | echo "XORP dir exist" |
---|
42 | else |
---|
43 | echo "creating xorp dir" |
---|
44 | sudo mkdir $xorp_conf_dir |
---|
45 | fi |
---|
46 | |
---|
47 | sudo /usr/bin/awk -f $ABS_PATH/ospfd-conf-gen.awk $vm_info_file "$timestamp" 24 | sudo tee $ABS_PATH/ospfd.conf > /dev/null |
---|
48 | |
---|
49 | sudo cp $ABS_PATH/ospfd.conf $xorp_conf_dir/. |
---|
50 | |
---|
51 | # check if xorp has been added to the group |
---|
52 | xorp_group=`sudo cat /etc/group | grep "xorp"` |
---|
53 | if [ "$xorp_group" = "" ] |
---|
54 | then |
---|
55 | echo "Add xorp to group" |
---|
56 | sudo groupadd xorp |
---|
57 | else |
---|
58 | echo "xorp is already added to the group" |
---|
59 | fi |
---|
60 | |
---|
61 | |
---|
62 | |
---|
63 | # first stop current xorp process if it's running |
---|
64 | |
---|
65 | xorp_pids=`ps -ef | grep xorp_ | /usr/bin/awk '{ if ( $1 == "root" ) {print $2}}'` |
---|
66 | if [ "$xorp_pids" = "" ] |
---|
67 | then |
---|
68 | echo "xorp is not running at this time" |
---|
69 | else |
---|
70 | echo "xorp is running, stop it first" |
---|
71 | ps -ef | grep xorp_ | /usr/bin/awk '{ if ( $1 == "root" ) {print "sudo kill -9 " $2}}' | sh |
---|
72 | fi |
---|
73 | |
---|
74 | |
---|
75 | # start xorp |
---|
76 | cd /usr/local/xorp/sbin/ |
---|
77 | echo "XORP is starting ......" |
---|
78 | sudo ./xorp_rtrmgr -b $xorp_conf_dir/ospfd.conf -l /tmp/xorp_rtrmgr_log -d |
---|
79 | |
---|
80 | |
---|
81 | /sbin/ifconfig -a | grep eth | awk '{ if (substr($1, 4,4) != 0) { print "sudo /sbin/ifconfig " $1 " down"}}' |sh |
---|
82 | /sbin/ifconfig -a | grep eth | awk '{ if (substr($1, 4,4) != 0) { print "sudo /sbin/ifconfig " $1 " up"}}' |sh |
---|
83 | |
---|
84 | # Turn off the reverse path filter on ubuntu |
---|
85 | sudo sysctl -w net.ipv4.conf.all.rp_filter=0 |
---|
86 | sudo sysctl -w net.ipv4.conf.default.rp_filter=0 |
---|
87 | /sbin/ifconfig -a | grep eth | awk '{ if (substr($1, 4,4) != 0) { print "sudo sysctl -w net.ipv4.conf." $1 ".rp_filter=0"}}' | sh |
---|
88 | |
---|
89 | |
---|