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