e6a83634daaafc062b1af4f84d637819fb359508
[debian6500.git] / master / opt / script / configure_fe306
1 #!/bin/bash
2
3 # parameters
4 #
5 # ============================================================================
6 #
7 # Copyright (C) THALES. All rights reserved
8 # Author: Laurent Mazet
9 #
10 # 2013-11-10 V1.0 : Creation
11 #
12 # 2013-11-20 V1.1 : L.Mazet ajout possibilite de configuration du switch
13 #
14 # ============================================================================
15
16 DRY=
17 ID=
18 IP=192.168.0.1
19 TRC6500_SCRIPT_DIR=$(dirname $0)
20
21 # help function
22
23 function usage () {
24 echo "usage: $PROGNAME [-a] [-d] [-h] [-i <id>]"
25 echo " -a: configure all boards"
26 echo " -d: dry mode"
27 echo " -h: help message"
28 echo " -i: board id (from 1 to 5)"
29 exit $@
30 }
31
32 # formating functions
33
34 function title () { echo -e "$conf_header\033[0;1m$*\033[0;0m"; }
35 function pass () { echo -e "$conf_header\033[1;32m$*\033[0;0m"; }
36 function warn () { echo -e "$conf_header\033[1;33m$*\033[0;0m"; }
37 function fail () { echo -e "$conf_header\033[1;31m$*\033[0;0m"; }
38 function write () { echo -n "$conf_header$*"; }
39 function writeln () { echo "$conf_header$*"; }
40
41
42 # configuration values
43
44 # argument processing
45
46 while [ $# -gt 0 ]; do
47 case "$1" in
48 -a) ID=all;;
49 -d) DRY=yes;;
50 -h) usage 0;;
51 -i) shift; ID=$1;;
52 *) usage 1;;
53 esac
54 shift
55 done
56
57 # switch port configure function ()
58
59 function sw_configure () {
60 case "$1" in
61 off) CMD="-c 'configure terminal' -c 'interface range g1/39-44' -c 'shutdown' -c end -c 'clear mac address-table dynamic' -c 'clear ip arp inspection log' -c exit";;
62 on) CMD="-c 'configure terminal' -c 'interface range g1/39-44' -c 'no shutdown' -c end -c exit";;
63 1) CMD="-c 'configure terminal' -c 'interface g1/39' -c 'no shutdown' -c end -c exit";;
64 2) CMD="-c 'configure terminal' -c 'interface g1/40' -c 'no shutdown' -c end -c exit";;
65 3) CMD="-c 'configure terminal' -c 'interface g1/41' -c 'no shutdown' -c end -c exit";;
66 4) CMD="-c 'configure terminal' -c 'interface g1/42' -c 'no shutdown' -c end -c exit";;
67 5) CMD="-c 'configure terminal' -c 'interface g1/43' -c 'no shutdown' -c end -c exit";;
68 6) CMD="-c 'configure terminal' -c 'interface g1/44' -c 'no shutdown' -c end -c exit";;
69 esac
70
71 if [ "$DRY" = "yes" ]; then
72 writeln connect_switch -h swm $CMD
73 else
74 LOG=/tmp/$PROGNAME-$$.log
75 write "sw_configure $1: "
76 eval $TRC6500_SCRIPT_DIR/connect_switch $CMD swm >&$LOG && pass OK || { fail KO; cat $LOG; exit 1; }
77 rm -f $LOG
78 fi
79 }
80
81 case "$ID" in
82 1) CH1=0; CH2=1; CLOCKREF=external;;
83 2) CH1=2; CH2=3; CLOCKREF=internal;;
84 3) CH1=4; CH2=5; CLOCKREF=internal;;
85 4) CH1=6; CH2=7; CLOCKREF=internal;;
86 5) CH1=8; CH2=9; CLOCKREF=internal;;
87 6) CH1=10; CH2=11; CLOCKREF=internal;;
88 all)
89 for id in $(seq 1 5); do
90 title "switch off all fe306 ports"
91 sw_configure off
92 title "switch on port for fe306 $id"
93 sw_configure $id
94 title "configure fe306 $id"
95 export conf_header=" "
96 if [ "$DRY" = "yes" ]; then
97 writeln $(basename $0) -i $id
98 else
99 $0 -i $id && pass OK || { fail KO; exit 1; }
100 fi
101 export conf_header=""
102 done
103 title "switch on all fe306 ports"
104 sw_configure on
105 exit 0
106 ;;
107 *) writeln "unknown fe306 id ($ID)"; exit 1;;
108 esac
109
110 # configure function
111
112 function configure () {
113 write "$1 [$2 <= $3]: "
114 if [ "$DRY" = "yes" ]; then
115 writeln wget -q -O - http://$IP/$1?$2=$3
116 else
117 wget -q -O - http://$IP/$1?$2=$3 >/dev/null && pass OK || { fail KO; exit 1; }
118 fi
119 }
120
121 # setup local address
122
123 title "setup local address"
124 cmd="ifconfig eth1:1 192.168.0.2 netmask 255.255.255.0"
125 [ "$DRY" = "yes" ] && writeln $cmd || { write $cmd" "; eval $cmd && pass OK || { fail KO; exit 1; }; }
126
127 # check if fe306 is connected
128
129 #title "check presence of $IP"
130 #cmd="ping -c 1 -w 10 -W 10 $IP"
131 #[ "$DRY" = "yes" ] && writeln $cmd || { write $cmd" "; eval $cmd >&/dev/null && pass OK || { warn KO; ifconfig eth1:1 down; exit 0; }; }
132
133 # get serial number
134
135 [ "$DRY" = "yes" ] && SN=00 || \
136 SN=$(wget -q -O - http://$IP/versions_en.html | mawk '/MODULE/ { module = 1 } /Serial Number/ { if (module) { printf "%02X", $4; exit 0 } }')
137
138 [[ "$SN" =~ ^[0-9A-F][0-9A-F]$ ]] || { writeln "unknown serial number ($SN)"; exit 1; }
139
140 # configure ip
141
142 title "configure ip"
143
144 configure ModeServ.cmd serv_mode MANUAL
145 configure MacServ.cmd serv_mac 00.80.EE.00.$SN.01
146 configure IpServ.cmd serv_ip $(getent hosts | awk '/fe306-'$ID'/ {writeln $1}')
147 configure MaskServ.cmd serv_mask 255.255.255.0
148
149 for i in $(seq 1 8); do
150 configure MacProd$i.cmd prod_mac$i 00.80.EE.00.$SN.0$((i+1))
151 configure IpProd$i.cmd prod_ip$i 10.133.26.1$ID$i
152 done
153
154 configure IpMulticast.cmd multicast_ip 238.0.0.0
155 configure RxMulticast.cmd multicast_rx 62002
156 configure TxMulticast.cmd multicast_tx 62004
157 configure TTL.cmd ttl 10
158
159 # configure gps
160
161 title "configure gps"
162
163 configure GpsRate.cmd gps_rate 19200
164 configure GpsChar.cmd gps_char 8
165 configure GpsStop.cmd gps_stop 1
166 configure GpsParity.cmd gps_parity no
167
168 # configure miscellaneous
169
170 title "configure miscellaneous"
171 configure BoardNum.cmd board_num $ID
172 configure RackNum.cmd rack_num 1
173 configure Chan1Num.cmd channel1_num $CH1
174 configure Chan2Num.cmd channel2_num $CH2
175
176 configure FpgaLoc.cmd fpga_loc FLASH
177 configure Clk10Mhz.cmd clk_10 $CLOCKREF
178 configure PllConfig.cmd pll_cfg pll_cfg_02
179
180 # unset local address
181
182 title "unset local address"
183 cmd="ifconfig eth1:1 down"
184 [ "$DRY" = "yes" ] && writeln $cmd || { write $cmd" "; eval $cmd && pass OK || { fail KO; exit 1; }; }
185
186 # vim:set tabstop=4 shiftwidth=4 softtabstop=4: