correct issue with trc6500-webconfig package installation
[debian6500.git] / trc6500-master-file / script / configure_fe306.sh
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
34function title () { echo -e "\033[0;1m$*\033[0;0m"; }
35function pass () { echo -e "\033[1;32m$*\033[0;0m"; }
36function warn () { echo -e "\033[1;33m$*\033[0;0m"; }
37function fail () { echo -e "\033[1;31m$*\033[0;0m"; }
38
39# configuration values
40
41# argument processing
42
43while [ $# -gt 0 ]; do
44 case "$1" in
45 -a) ID=all;;
46 -d) DRY=yes;;
47 -h) usage 0;;
48 -i) shift; ID=$1;;
49 *) usage 1;;
50 esac
51 shift
52done
53
54# switch port configure function ()
55
56function sw_configure () {
57 case "$1" in
58 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";;
59 on) CMD="-c 'configure terminal' -c 'interface range g1/39-44' -c 'no shutdown' -c end -c exit";;
60 1) CMD="-c 'configure terminal' -c 'interface g1/39' -c 'no shutdown' -c end -c exit";;
61 2) CMD="-c 'configure terminal' -c 'interface g1/40' -c 'no shutdown' -c end -c exit";;
62 3) CMD="-c 'configure terminal' -c 'interface g1/41' -c 'no shutdown' -c end -c exit";;
63 4) CMD="-c 'configure terminal' -c 'interface g1/42' -c 'no shutdown' -c end -c exit";;
64 5) CMD="-c 'configure terminal' -c 'interface g1/43' -c 'no shutdown' -c end -c exit";;
65 6) CMD="-c 'configure terminal' -c 'interface g1/44' -c 'no shutdown' -c end -c exit";;
66 esac
67
68 if [ "$DRY" = "yes" ]; then
69 echo connect_switch.tcl -h swm $CMD
70 else
71 LOG=/tmp/$PROGNAME-$$.log
72 echo -n "sw_configure $1: "
73 eval $TRC6500_SCRIPT_DIR/connect_switch.tcl $CMD swm >&$LOG && pass OK || { fail KO; cat $LOG; exit 1; }
74 rm -f $LOG
75 fi
76}
77
78case "$ID" in
791) CH1=0; CH2=1; CLOCKREF=external;;
802) CH1=2; CH2=3; CLOCKREF=internal;;
813) CH1=4; CH2=5; CLOCKREF=internal;;
824) CH1=6; CH2=7; CLOCKREF=internal;;
835) CH1=8; CH2=9; CLOCKREF=internal;;
846) CH1=10; CH2=11; CLOCKREF=internal;;
85all)
86 for id in $(seq 1 5); do
87 title "switch off all fe306 ports"
88 sw_configure off
89 title "switch on port for fe306 $id"
90 sw_configure $id
91 title "configure fe306 $id"
92 if [ "$DRY" = "yes" ]; then
93 echo $(basename $0) -i $id
94 else
95 { $0 -i $id | mawk -W interactive '{print " " $0}'; } && pass OK || { fail KO; exit 1; }
96 fi
97 done
98 title "switch on all fe306 ports"
99 sw_configure on
100 exit 0
101 ;;
102*) echo "unknown fe306 id ($ID)"; exit 1;;
103esac
104
105# configure function
106
107function configure () {
108 echo -n "$1 [$2 <= $3]: "
109 if [ "$DRY" = "yes" ]; then
110 echo wget -q -O - http://$IP/$1?$2=$3
111 else
112 wget -q -O - http://$IP/$1?$2=$3 >/dev/null && pass OK || { fail KO; exit 1; }
113 fi
114}
115
116# setup local address
117
118title "setup local address"
119cmd="ifconfig eth1:1 192.168.0.2 netmask 255.255.255.0"
120[ "$DRY" = "yes" ] && echo $cmd || { echo -n $cmd" "; eval $cmd && pass OK || { fail KO; exit 1; }; }
121
122# check if fe306 is connected
123
124#title "check presence of $IP"
125#cmd="ping -c 1 -w 10 -W 10 $IP"
126#[ "$DRY" = "yes" ] && echo $cmd || { echo -n $cmd" "; eval $cmd >&/dev/null && pass OK || { warn KO; ifconfig eth1:1 down; exit 0; }; }
127
128# get serial number
129
130[ "$DRY" = "yes" ] && SN=00 || \
131 SN=$(wget -q -O - http://$IP/versions_en.html | mawk '/MODULE/ { module = 1 } /Serial Number/ { if (module) { printf "%02X", $4; exit 0 } }')
132
133[[ "$SN" =~ ^[0-9A-F][0-9A-F]$ ]] || { echo "unknown serial number ($SN)"; exit 1; }
134
135# configure ip
136
137title "configure ip"
138
139configure ModeServ.cmd serv_mode MANUAL
140configure MacServ.cmd serv_mac 00.80.EE.00.$SN.01
637fd25c 141configure IpServ.cmd serv_ip $(getent hosts | awk '/fe306-'$ID'/ {print $1}')
b3f3562f
OL
142configure MaskServ.cmd serv_mask 255.255.255.0
143
144for i in $(seq 1 8); do
145 configure MacProd$i.cmd prod_mac$i 00.80.EE.00.$SN.0$((i+1))
146 configure IpProd$i.cmd prod_ip$i 10.133.26.1$ID$i
147done
148
149configure IpMulticast.cmd multicast_ip 238.0.0.0
150configure RxMulticast.cmd multicast_rx 62002
151configure TxMulticast.cmd multicast_tx 62004
152configure TTL.cmd ttl 10
153
154# configure gps
155
156title "configure gps"
157
158configure GpsRate.cmd gps_rate 19200
159configure GpsChar.cmd gps_char 8
160configure GpsStop.cmd gps_stop 1
161configure GpsParity.cmd gps_parity no
162
163# configure miscellaneous
164
165title "configure miscellaneous"
166configure BoardNum.cmd board_num $ID
167configure RackNum.cmd rack_num 1
168configure Chan1Num.cmd channel1_num $CH1
169configure Chan2Num.cmd channel2_num $CH2
170
171configure FpgaLoc.cmd fpga_loc FLASH
172configure Clk10Mhz.cmd clk_10 $CLOCKREF
173configure PllConfig.cmd pll_cfg pll_cfg_02
174
175# unset local address
176
177title "unset local address"
178cmd="ifconfig eth1:1 down"
179[ "$DRY" = "yes" ] && echo $cmd || { echo -n $cmd" "; eval $cmd && pass OK || { fail KO; exit 1; }; }
180
181# vim:set tabstop=4 shiftwidth=4 softtabstop=4: