4 # This script configures lnet with the routes in the passed in file.
5 # The routes should be in the following format:
6 # <network>: { gateway: <gateway>@<exit network> [hop: <hop>] [priority: <prioirty>] }
9 # tcp1: { gateway: 10.1.1.2@tcp0, priority: 3 }
10 # tcp4: { gateway: 10.3.3.4@tcp }
11 # tcp6: { gateway: 10.3.3.6@tcp, hop: 2, priority: 5 }
12 # tcp7: { gateway: 10.3.3.[6-12]@tcp, priority: 20, hop: 8 }
14 # The purpose of this script is to circumvent the limitation on the number of
15 # routes which could be configured through the lustre.conf module parameters.
17 ###########################################################################
20 progname=$(basename $0)
25 Setup or cleanup LNET routes from specified config file"
26 usage: $progname [--setup|--cleanup|--dry-run|--verbose]
28 --setup: configure routes listed in config_file
29 --cleanup: unconfigure routes listed in config_file
30 --dry-run: echo commands to be run, but do not execute them
31 --verbose: echo commands before they are executed
35 # Set default paramters
41 [ -z "$1" ] && usage && exit 1
44 while [ ! -f "$1" ]; do
46 -c|--cleanup) CMD=del_route; shift ;;
47 -h|--help) usage; exit 0 ;;
48 -n|--dry-run) EXEC=false; VERBOSE=true; shift ;;
49 -s|--setup) CMD=add_route; shift ;;
50 -v|--verbose) VERBOSE=true; shift ;;
55 # Usage: do_lctl <params>
56 # execut the command and/or print if verbose is set
60 $VERBOSE && echo "lctl $@"
69 # Usage: find_arg_value <array> <arg>
75 declare -a array=("${!1}")
76 for ((i = 0; i < ${#array[@]}; i++)); do
77 if [ "${array[$i]}" == "$arg" ]; then
78 value="${array[$((i + 1))]}"
86 # Parse line using ':' and ',' as delimiters and ignoring all
87 # white space, tabs and linefeed
91 # get the mandatory parameters: network and gateway
92 # If either is not present skip that line
98 if [ -z $network ] || [ -z $gateway ] ||
99 [ $GATE != "gateway" ]; then
105 baselctl="--net $network add_route $gateway"
107 # walk through the optional params until you hit
108 # the closing brace. Build an associative db:
111 while [ $i -lt ${#params[@]} ]; do
113 if [ "$option" == "}" ]; then
116 outoptions[$i]=$option
119 outoptions[$i]=$value
123 # find the hop and priority
124 # This can be expanded later on if we add extra
126 # NOTE: the order between hop and priority is not
127 # enforced. It's also possible to add hop without
128 # prio or prio without hop
129 priority=$(find_arg_value outoptions[@] "priority")
130 hop=$(find_arg_value outoptions[@] "hop")
131 if [ -n "$priority" ] && [ -z "$hop" ]; then
132 baselctl+=" 1 $priority"
134 baselctl+=" $hop $priority"
138 baselctl="del_route $gateway"