correct fe306 configuration scipt
[debian6500.git] / master / opt / script / configure_fe306
CommitLineData
b3f3562f
OL
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
16DRY=
17ID=
18IP=192.168.0.1
b3f3562f
OL
19TRC6500_SCRIPT_DIR=$(dirname $0)
20
21# help function
22
23function 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
42f41509
LM
34function title () { echo -e "$conf_header\033[0;1m$*\033[0;0m"; }
35function pass () { echo -e "$conf_header\033[1;32m$*\033[0;0m"; }
36function warn () { echo -e "$conf_header\033[1;33m$*\033[0;0m"; }
37function fail () { echo -e "$conf_header\033[1;31m$*\033[0;0m"; }
38function write () { echo -n "$conf_header$*"; }
39function writeln () { echo "$conf_header$*"; }
40
b3f3562f
OL
41
42# configuration values
43
44# argument processing
45
46while [ $# -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
55done
56
57# switch port configure function ()
58
59function 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
42f41509 72 writeln connect_switch -h swm $CMD
b3f3562f
OL
73 else
74 LOG=/tmp/$PROGNAME-$$.log
42f41509 75 write "sw_configure $1: "
757c2d98 76 eval $TRC6500_SCRIPT_DIR/connect_switch $CMD swm >&$LOG && pass OK || { fail KO; cat $LOG; exit 1; }
b3f3562f
OL
77 rm -f $LOG
78 fi
79}
80
81case "$ID" in
821) CH1=0; CH2=1; CLOCKREF=external;;
832) CH1=2; CH2=3; CLOCKREF=internal;;
843) CH1=4; CH2=5; CLOCKREF=internal;;
854) CH1=6; CH2=7; CLOCKREF=internal;;
865) CH1=8; CH2=9; CLOCKREF=internal;;
876) CH1=10; CH2=11; CLOCKREF=internal;;
88all)
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"
42f41509 95 export conf_header=" "
b3f3562f 96 if [ "$DRY" = "yes" ]; then
42f41509 97 writeln $(basename $0) -i $id
b3f3562f 98 else
42f41509 99 $0 -i $id && pass OK || { fail KO; exit 1; }
b3f3562f 100 fi
42f41509 101 export conf_header=""
b3f3562f
OL
102 done
103 title "switch on all fe306 ports"
104 sw_configure on
105 exit 0
106 ;;
42f41509 107*) writeln "unknown fe306 id ($ID)"; exit 1;;
b3f3562f
OL
108esac
109
110# configure function
111
112function configure () {
42f41509 113 write "$1 [$2 <= $3]: "
b3f3562f 114 if [ "$DRY" = "yes" ]; then
42f41509 115 writeln wget -q -O - http://$IP/$1?$2=$3
b3f3562f
OL
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
123title "setup local address"
124cmd="ifconfig eth1:1 192.168.0.2 netmask 255.255.255.0"
42f41509 125[ "$DRY" = "yes" ] && writeln $cmd || { write $cmd" "; eval $cmd && pass OK || { fail KO; exit 1; }; }
b3f3562f
OL
126
127# check if fe306 is connected
128
129#title "check presence of $IP"
130#cmd="ping -c 1 -w 10 -W 10 $IP"
42f41509 131#[ "$DRY" = "yes" ] && writeln $cmd || { write $cmd" "; eval $cmd >&/dev/null && pass OK || { warn KO; ifconfig eth1:1 down; exit 0; }; }
b3f3562f
OL
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
42f41509 138[[ "$SN" =~ ^[0-9A-F][0-9A-F]$ ]] || { writeln "unknown serial number ($SN)"; exit 1; }
b3f3562f
OL
139
140# configure ip
141
142title "configure ip"
143
144configure ModeServ.cmd serv_mode MANUAL
145configure MacServ.cmd serv_mac 00.80.EE.00.$SN.01
42f41509 146configure IpServ.cmd serv_ip $(getent hosts | awk '/fe306-'$ID'/ {writeln $1}')
b3f3562f
OL
147configure MaskServ.cmd serv_mask 255.255.255.0
148
149for 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
152done
153
154configure IpMulticast.cmd multicast_ip 238.0.0.0
155configure RxMulticast.cmd multicast_rx 62002
156configure TxMulticast.cmd multicast_tx 62004
157configure TTL.cmd ttl 10
158
159# configure gps
160
161title "configure gps"
162
163configure GpsRate.cmd gps_rate 19200
164configure GpsChar.cmd gps_char 8
165configure GpsStop.cmd gps_stop 1
166configure GpsParity.cmd gps_parity no
167
168# configure miscellaneous
169
170title "configure miscellaneous"
171configure BoardNum.cmd board_num $ID
172configure RackNum.cmd rack_num 1
173configure Chan1Num.cmd channel1_num $CH1
174configure Chan2Num.cmd channel2_num $CH2
175
176configure FpgaLoc.cmd fpga_loc FLASH
177configure Clk10Mhz.cmd clk_10 $CLOCKREF
178configure PllConfig.cmd pll_cfg pll_cfg_02
179
180# unset local address
181
182title "unset local address"
183cmd="ifconfig eth1:1 down"
42f41509 184[ "$DRY" = "yes" ] && writeln $cmd || { write $cmd" "; eval $cmd && pass OK || { fail KO; exit 1; }; }
b3f3562f
OL
185
186# vim:set tabstop=4 shiftwidth=4 softtabstop=4: