|
1 | 1 | #!/bin/bash |
2 | 2 |
|
| 3 | +# Parameter Description: |
| 4 | +# $1: Configuration file (mandatory parameter) |
| 5 | +# $2: Optional parameter that specifies the path to the ipfixprobe library directory. |
| 6 | +# If this parameter is not provided, the default value "/usr/lib64/ipfixprobe" will be used. |
| 7 | + |
3 | 8 | CONFFILE="/etc/ipfixprobe/$1.conf" |
4 | 9 |
|
| 10 | +# Help function to display usage instructions |
| 11 | +show_help() { |
| 12 | + echo "Usage: $0 CONFIG_NAME [LIBRARY_PATH]" |
| 13 | + echo "" |
| 14 | + echo "CONFIG_NAME: Name of the configuration file (without the '.conf' extension)." |
| 15 | + echo " The full path will be '/etc/ipfixprobe/[CONFIG_NAME].conf'." |
| 16 | + echo "LIBRARY_PATH: Optional path to the ipfixprobe library directory." |
| 17 | + echo " If not provided, the default value '/usr/lib64/ipfixprobe' will be used." |
| 18 | + echo "" |
| 19 | + echo "Example 1: Use the default library path:" |
| 20 | + echo " $0 [name]" |
| 21 | + echo "" |
| 22 | + echo "Example 2: Specify a custom library path:" |
| 23 | + echo " $0 [name] /usr/local/lib64/ipfixprobe" |
| 24 | + echo "" |
| 25 | +} |
| 26 | + |
| 27 | +# Check if the user asked for help |
| 28 | +if [[ "$1" == "--help" || "$1" == "-h" ]]; then |
| 29 | + show_help |
| 30 | + exit 0 |
| 31 | +fi |
| 32 | + |
| 33 | +# Parameter Description: |
| 34 | +# $1: Configuration file name (mandatory parameter) |
| 35 | +# $2: Optional parameter that specifies the path to the ipfixprobe library directory. |
| 36 | +# If this parameter is not provided, the default value "/usr/local |
| 37 | + |
| 38 | + |
| 39 | +parse_old_format() { |
| 40 | + # Parse the old format of the configuration file |
| 41 | + source "$CONFFILE" |
| 42 | + input="" |
| 43 | + dpdkinput="" |
| 44 | + if [ "$USE_DPDK" = "1" ]; then |
| 45 | + # check |
| 46 | + if [ -z "$DPDK_QUEUES_COUNT" ]; then |
| 47 | + echo "Missing DPDK_QUEUES_COUNT in configuration of DPDK mode." |
| 48 | + exit 1 |
| 49 | + fi |
| 50 | + |
| 51 | + if [ ! -z "$DPDK_LCORES" ]; then |
| 52 | + DPDK_LCORES="--lcores $DPDK_LCORES" |
| 53 | + fi |
| 54 | + |
| 55 | + if [ -n "$DPDK_OPTS" -a "${DPDK_OPTS:0:1}" != ";" ]; then |
| 56 | + DPDK_OPTS=";$DPDK_OPTS" |
| 57 | + fi |
| 58 | + |
| 59 | + # create array with input workers affinities |
| 60 | + if [ ! -z "$DPDK_INPUT_WORKER_CPUS" ]; then |
| 61 | + if `declare -p DPDK_INPUT_WORKER_CPUS > /dev/null 2>/dev/null`; then |
| 62 | + if [ "${#DPDK_INPUT_WORKER_CPUS[@]}" -ne "$DPDK_QUEUES_COUNT" ]; then |
| 63 | + echo "DPDK_INPUT_WORKER_CPUS length must be the same as queues count." |
| 64 | + exit 1 |
| 65 | + fi |
| 66 | + fi |
| 67 | + fi |
| 68 | + for ((i = 0; i < DPDK_QUEUES_COUNT; i++)); do |
| 69 | + if [ ! -z "$DPDK_INPUT_WORKER_CPUS" ]; then |
| 70 | + affinities[i]="@${DPDK_INPUT_WORKER_CPUS[$i]}" |
| 71 | + else |
| 72 | + affinities[i]="" |
| 73 | + fi |
| 74 | + done |
| 75 | + |
| 76 | + # set up DPDK interface(s) |
| 77 | + if [ "$DPDK_RING" = "1" ]; then |
| 78 | + # checks |
| 79 | + if [ -z "$DPDK_RING_PATTERN" ]; then |
| 80 | + echo "Missing DPDK_RING_PATTERN in configuration of DPDK_RING mode." |
| 81 | + exit 1 |
| 82 | + fi |
| 83 | + if [ -z "$DPDK_RING_STARTIDX" ]; then |
| 84 | + echo "Missing DPDK_RING_STARTIDX in configuration of DPDK_RING mode, using 0." |
| 85 | + DPDK_RING_STARTIDX=0 |
| 86 | + fi |
| 87 | + |
| 88 | + # mring interfaces |
| 89 | + dpdkinput=("-i" "dpdk-ring${affinities[0]};r=$(printf "$DPDK_RING_PATTERN" "$DPDK_RING_STARTIDX")${DPDK_OPTS};e=$DPDK_LCORES $DPDK_EXTRA_EAL") |
| 90 | + plugin_idx=1 |
| 91 | + for ((ifc=($DPDK_RING_STARTIDX+1); ifc<($DPDK_RING_STARTIDX + $DPDK_QUEUES_COUNT);ifc++)); do |
| 92 | + dpdkinput+=("-i" "dpdk-ring${affinities[$plugin_idx]};r=$(printf "$DPDK_RING_PATTERN" "$ifc")") |
| 93 | + ((plugin_idx++)) |
| 94 | + done |
| 95 | + else |
| 96 | + # DPDK port interface |
| 97 | + dpdkinput=("-i" "dpdk${affinities[0]};p=${DPDK_PORT}${DPDK_OPTS};q=$DPDK_QUEUES_COUNT;e=$DPDK_LCORES $DPDK_EXTRA_EAL -a $DPDK_DEVICE") |
| 98 | + for ((ifc=1; ifc<$DPDK_QUEUES_COUNT;ifc++)); do |
| 99 | + dpdkinput+=("-i" "dpdk${affinities[$ifc]}") |
| 100 | + done |
| 101 | + fi |
| 102 | + fi |
| 103 | + if `declare -p INPUT > /dev/null 2>/dev/null`; then |
| 104 | + # list of input plugins |
| 105 | + for ifc in "${!INPUT[@]}"; do |
| 106 | + input="$input -i ${INPUT[ifc]}" |
| 107 | + done |
| 108 | + fi |
| 109 | + CACHE_SIZE_PARAM="" |
| 110 | + if [ ! -z ${CACHE_SIZE+x} ]; then |
| 111 | + CACHE_SIZE_PARAM="size=${CACHE_SIZE}" |
| 112 | + fi |
| 113 | + CACHE_ACTIVET_PARAM="" |
| 114 | + if [ ! -z ${ACTIVE_TIMEOUT+x} ]; then |
| 115 | + CACHE_ACTIVET_PARAM=";active=${ACTIVE_TIMEOUT}" |
| 116 | + fi |
| 117 | + CACHE_INACTIVE_PARAM="" |
| 118 | + if [ ! -z ${INACTIVE_TIMEOUT+x} ]; then |
| 119 | + CACHE_INACTIVE_PARAM=";inactive=${INACTIVE_TIMEOUT}" |
| 120 | + fi |
| 121 | + CACHE_FRAG_ENABLE_PARAM="" |
| 122 | + if [ ! -z ${FRAG_CACHE_ENABLE+x} ]; then |
| 123 | + CACHE_FRAG_ENABLE_PARAM=";frag-enable=${FRAG_CACHE_ENABLE}" |
| 124 | + fi |
| 125 | + CACHE_FRAG_SIZE="" |
| 126 | + if [ ! -z ${FRAG_CACHE_SIZE+x} ]; then |
| 127 | + CACHE_FRAG_SIZE=";frag-size=${FRAG_CACHE_SIZE}" |
| 128 | + fi |
| 129 | + CACHE_FRAG_TIMEOUT="" |
| 130 | + if [ ! -z ${FRAG_CACHE_TIMEOUT+x} ]; then |
| 131 | + CACHE_FRAG_TIMEOUT=";frag-timeout=${FRAG_CACHE_TIMEOUT}" |
| 132 | + fi |
| 133 | + storage="-s cache;${CACHE_SIZE_PARAM}${CACHE_ACTIVET_PARAM}${CACHE_INACTIVE_PARAM}${CACHE_FRAG_ENABLE_PARAM}${CACHE_FRAG_SIZE}${CACHE_FRAG_TIMEOUT}" |
| 134 | + process="" |
| 135 | + if `declare -p PROCESS > /dev/null 2>/dev/null`; then |
| 136 | + # list of input plugins |
| 137 | + for ifc in "${!PROCESS[@]}"; do |
| 138 | + process="$process -p ${PROCESS[ifc]}" |
| 139 | + done |
| 140 | + fi |
| 141 | + UDP_PARAM="" |
| 142 | + if [[ $UDP == "yes" ]]; then |
| 143 | + UDP_PARAM="udp"; |
| 144 | + fi |
| 145 | + |
| 146 | + NON_BLOCKING_TCP_PARAM="" |
| 147 | + if [[ $NON_BLOCKING_TCP == "yes" ]]; then |
| 148 | + NON_BLOCKING_TCP_PARAM="non-blocking-tcp"; |
| 149 | + fi |
| 150 | + |
| 151 | + output_affinity="" |
| 152 | + if [ ! -z "$OUTPUT_WORKER_CPU" ]; then |
| 153 | + output_affinity="@$OUTPUT_WORKER_CPU" |
| 154 | + fi |
| 155 | + |
| 156 | + LZ4_COMPRESSION_PARAM="" |
| 157 | + if [[ $LZ4_COMPRESSION == "yes" ]]; then |
| 158 | + LZ4_COMPRESSION_PARAM="lz4-compression"; |
| 159 | + fi |
| 160 | + |
| 161 | + output="-o ipfix$output_affinity;host=${HOST:-127.0.0.1};port=${PORT:-4739};id=${LINK:-0};dir=${DIR:-0};${UDP_PARAM};${NON_BLOCKING_TCP_PARAM};${LZ4_COMPRESSION_PARAM};template=${TEMPLATE_REFRESH_RATE:-300}" |
| 162 | + |
| 163 | + telemetry="" |
| 164 | + if [ "$USE_FUSE" = "1" ]; then |
| 165 | + telemetry="-t ${FUSE_MOUNT_POINT}" |
| 166 | + fi |
| 167 | + |
| 168 | + exec /usr/bin/ipfixprobe "${dpdkinput[@]}" $input $storage $process $output $telemetry $EXTRA_ARGS |
| 169 | +} |
| 170 | + |
5 | 171 | if [ -e "$CONFFILE" ]; then |
6 | | - source "$CONFFILE" |
7 | | - input="" |
8 | | - dpdkinput="" |
9 | | - if [ "$USE_DPDK" = "1" ]; then |
10 | | - # check |
11 | | - if [ -z "$DPDK_QUEUES_COUNT" ]; then |
12 | | - echo "Missing DPDK_QUEUES_COUNT in configuration of DPDK mode." |
13 | | - exit 1 |
14 | | - fi |
15 | | - |
16 | | - if [ ! -z "$DPDK_LCORES" ]; then |
17 | | - DPDK_LCORES="--lcores $DPDK_LCORES" |
18 | | - fi |
19 | | - |
20 | | - if [ -n "$DPDK_OPTS" -a "${DPDK_OPTS:0:1}" != ";" ]; then |
21 | | - DPDK_OPTS=";$DPDK_OPTS" |
22 | | - fi |
23 | | - |
24 | | - # create array with input workers affinities |
25 | | - if [ ! -z "$DPDK_INPUT_WORKER_CPUS" ]; then |
26 | | - if `declare -p DPDK_INPUT_WORKER_CPUS > /dev/null 2>/dev/null`; then |
27 | | - if [ "${#DPDK_INPUT_WORKER_CPUS[@]}" -ne "$DPDK_QUEUES_COUNT" ]; then |
28 | | - echo "DPDK_INPUT_WORKER_CPUS length must be the same as queues count." |
29 | | - exit 1 |
30 | | - fi |
31 | | - fi |
32 | | - fi |
33 | | - for ((i = 0; i < DPDK_QUEUES_COUNT; i++)); do |
34 | | - if [ ! -z "$DPDK_INPUT_WORKER_CPUS" ]; then |
35 | | - affinities[i]="@${DPDK_INPUT_WORKER_CPUS[$i]}" |
36 | | - else |
37 | | - affinities[i]="" |
38 | | - fi |
39 | | - done |
40 | | - |
41 | | - # set up DPDK interface(s) |
42 | | - if [ "$DPDK_RING" = "1" ]; then |
43 | | - # checks |
44 | | - if [ -z "$DPDK_RING_PATTERN" ]; then |
45 | | - echo "Missing DPDK_RING_PATTERN in configuration of DPDK_RING mode." |
46 | | - exit 1 |
47 | | - fi |
48 | | - if [ -z "$DPDK_RING_STARTIDX" ]; then |
49 | | - echo "Missing DPDK_RING_STARTIDX in configuration of DPDK_RING mode, using 0." |
50 | | - DPDK_RING_STARTIDX=0 |
51 | | - fi |
52 | | - |
53 | | - # mring interfaces |
54 | | - dpdkinput=("-i" "dpdk-ring${affinities[0]};r=$(printf "$DPDK_RING_PATTERN" "$DPDK_RING_STARTIDX")${DPDK_OPTS};e=$DPDK_LCORES $DPDK_EXTRA_EAL") |
55 | | - plugin_idx=1 |
56 | | - for ((ifc=($DPDK_RING_STARTIDX+1); ifc<($DPDK_RING_STARTIDX + $DPDK_QUEUES_COUNT);ifc++)); do |
57 | | - dpdkinput+=("-i" "dpdk-ring${affinities[$plugin_idx]};r=$(printf "$DPDK_RING_PATTERN" "$ifc")") |
58 | | - ((plugin_idx++)) |
59 | | - done |
60 | | - else |
61 | | - # DPDK port interface |
62 | | - dpdkinput=("-i" "dpdk${affinities[0]};p=${DPDK_PORT}${DPDK_OPTS};q=$DPDK_QUEUES_COUNT;e=$DPDK_LCORES $DPDK_EXTRA_EAL -a $DPDK_DEVICE") |
63 | | - for ((ifc=1; ifc<$DPDK_QUEUES_COUNT;ifc++)); do |
64 | | - dpdkinput+=("-i" "dpdk${affinities[$ifc]}") |
65 | | - done |
66 | | - fi |
67 | | - fi |
68 | | - if `declare -p INPUT > /dev/null 2>/dev/null`; then |
69 | | - # list of input plugins |
70 | | - for ifc in "${!INPUT[@]}"; do |
71 | | - input="$input -i ${INPUT[ifc]}" |
72 | | - done |
73 | | - fi |
74 | | - CACHE_SIZE_PARAM="" |
75 | | - if [ ! -z ${CACHE_SIZE+x} ]; then |
76 | | - CACHE_SIZE_PARAM="size=${CACHE_SIZE}" |
77 | | - fi |
78 | | - CACHE_ACTIVET_PARAM="" |
79 | | - if [ ! -z ${ACTIVE_TIMEOUT+x} ]; then |
80 | | - CACHE_ACTIVET_PARAM=";active=${ACTIVE_TIMEOUT}" |
81 | | - fi |
82 | | - CACHE_INACTIVE_PARAM="" |
83 | | - if [ ! -z ${INACTIVE_TIMEOUT+x} ]; then |
84 | | - CACHE_INACTIVE_PARAM=";inactive=${INACTIVE_TIMEOUT}" |
85 | | - fi |
86 | | - CACHE_FRAG_ENABLE_PARAM="" |
87 | | - if [ ! -z ${FRAG_CACHE_ENABLE+x} ]; then |
88 | | - CACHE_FRAG_ENABLE_PARAM=";frag-enable=${FRAG_CACHE_ENABLE}" |
89 | | - fi |
90 | | - CACHE_FRAG_SIZE="" |
91 | | - if [ ! -z ${FRAG_CACHE_SIZE+x} ]; then |
92 | | - CACHE_FRAG_SIZE=";frag-size=${FRAG_CACHE_SIZE}" |
93 | | - fi |
94 | | - CACHE_FRAG_TIMEOUT="" |
95 | | - if [ ! -z ${FRAG_CACHE_TIMEOUT+x} ]; then |
96 | | - CACHE_FRAG_TIMEOUT=";frag-timeout=${FRAG_CACHE_TIMEOUT}" |
97 | | - fi |
98 | | - storage="-s cache;${CACHE_SIZE_PARAM}${CACHE_ACTIVET_PARAM}${CACHE_INACTIVE_PARAM}${CACHE_FRAG_ENABLE_PARAM}${CACHE_FRAG_SIZE}${CACHE_FRAG_TIMEOUT}" |
99 | | - process="" |
100 | | - if `declare -p PROCESS > /dev/null 2>/dev/null`; then |
101 | | - # list of input plugins |
102 | | - for ifc in "${!PROCESS[@]}"; do |
103 | | - process="$process -p ${PROCESS[ifc]}" |
104 | | - done |
105 | | - fi |
106 | | - UDP_PARAM="" |
107 | | - if [[ $UDP == "yes" ]]; then |
108 | | - UDP_PARAM="udp"; |
109 | | - fi |
110 | | - |
111 | | - NON_BLOCKING_TCP_PARAM="" |
112 | | - if [[ $NON_BLOCKING_TCP == "yes" ]]; then |
113 | | - NON_BLOCKING_TCP_PARAM="non-blocking-tcp"; |
114 | | - fi |
115 | | - |
116 | | - output_affinity="" |
117 | | - if [ ! -z "$OUTPUT_WORKER_CPU" ]; then |
118 | | - output_affinity="@$OUTPUT_WORKER_CPU" |
119 | | - fi |
120 | | - |
121 | | - LZ4_COMPRESSION_PARAM="" |
122 | | - if [[ $LZ4_COMPRESSION == "yes" ]]; then |
123 | | - LZ4_COMPRESSION_PARAM="lz4-compression"; |
124 | | - fi |
125 | | - |
126 | | - output="-o ipfix$output_affinity;host=${HOST:-127.0.0.1};port=${PORT:-4739};id=${LINK:-0};dir=${DIR:-0};${UDP_PARAM};${NON_BLOCKING_TCP_PARAM};${LZ4_COMPRESSION_PARAM};template=${TEMPLATE_REFRESH_RATE:-300}" |
127 | | - |
128 | | - telemetry="" |
129 | | - if [ "$USE_FUSE" = "1" ]; then |
130 | | - telemetry="-t ${FUSE_MOUNT_POINT}" |
131 | | - fi |
132 | | - |
133 | | - exec /usr/bin/ipfixprobe "${dpdkinput[@]}" $input $storage $process $output $telemetry $EXTRA_ARGS |
| 172 | + if grep -q 'INPUT\[' $CONFFILE; then |
| 173 | + echo "WARNING: Legacy configuration format detected. This format is obsolete and will be removed in version 5.2." |
| 174 | + echo "Please transition to the new YAML configuration format. For more details, visit: https://github.com/CESNET/ipfixprobe/blob/master/init/link0.conf.example" |
| 175 | + parse_old_format |
| 176 | + else |
| 177 | + IPFIXPROBE_LIB_DIR="${2:-/usr/lib64/ipfixprobe}" |
| 178 | + command=$(python3 $IPFIXPROBE_LIB_DIR/config2args.py --config $CONFFILE) |
| 179 | + status=$? |
| 180 | + |
| 181 | + if [ $status -ne 0 ]; then |
| 182 | + echo "Cannot convert yaml config" >&2 |
| 183 | + exit $status |
| 184 | + fi |
| 185 | + eval "exec $command" |
| 186 | + fi |
134 | 187 | else |
135 | | - echo "Configuration file '$CONFFILE' does not exist, exitting." >&2 |
136 | | - exit 1 |
| 188 | + echo "Error: Configuration file '$CONFFILE' does not exist, exitting." >&2 |
| 189 | + show_help |
| 190 | + exit 1 |
137 | 191 | fi |
| 192 | + |
| 193 | +exit 0 |
0 commit comments