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 # skip lines that are entirely whitespace or
87 # when the first non-whitespace character is #
88 if [[ "$line" =~ ^[[:space:]]*(#|$) ]]; then
92 # Parse line using ':' and ',' as delimiters and ignoring all
93 # white space, tabs and linefeed
97 # get the mandatory parameters: network and gateway
98 # If either is not present skip that line
104 if [ -z $network ] || [ -z $gateway ] ||
105 [ $GATE != "gateway" ]; then
111 baselctl="--net $network add_route $gateway"
113 # walk through the optional params until you hit
114 # the closing brace. Build an associative db:
117 while [ $i -lt ${#params[@]} ]; do
119 if [ "$option" == "}" ]; then
122 outoptions[$i]=$option
125 outoptions[$i]=$value
129 # find the hop and priority
130 # This can be expanded later on if we add extra
132 # NOTE: the order between hop and priority is not
133 # enforced. It's also possible to add hop without
134 # prio or prio without hop
135 priority=$(find_arg_value outoptions[@] "priority")
136 hop=$(find_arg_value outoptions[@] "hop")
137 if [ -n "$priority" ] && [ -z "$hop" ]; then
138 baselctl+=" 1 $priority"
140 baselctl+=" $hop $priority"
144 baselctl="del_route $gateway"