Skip to content

Commit 226b96c

Browse files
DanielTimLeedavem330
authored andcommitted
samples: pktgen: add some helper functions for port parsing
This commit adds port parsing and port validate helper function to parse single or range of port(s) from a given string. (e.g. 1234, 443-444) Helpers will be used in prior to set target port(s) in samples/pktgen. Signed-off-by: Daniel T. Lee <[email protected]> Acked-by: Jesper Dangaard Brouer <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent a346abe commit 226b96c

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

samples/pktgen/functions.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,37 @@ function get_node_cpus()
162162

163163
echo $node_cpu_list
164164
}
165+
166+
# Given a single or range of port(s), return minimum and maximum port number.
167+
function parse_ports()
168+
{
169+
local port_str=$1
170+
local port_list
171+
local min_port
172+
local max_port
173+
174+
IFS="-" read -ra port_list <<< $port_str
175+
176+
min_port=${port_list[0]}
177+
max_port=${port_list[1]:-$min_port}
178+
179+
echo $min_port $max_port
180+
}
181+
182+
# Given a minimum and maximum port, verify port number.
183+
function validate_ports()
184+
{
185+
local min_port=$1
186+
local max_port=$2
187+
188+
# 0 < port < 65536
189+
if [[ $min_port -gt 0 && $min_port -lt 65536 ]]; then
190+
if [[ $max_port -gt 0 && $max_port -lt 65536 ]]; then
191+
if [[ $min_port -le $max_port ]]; then
192+
return 0
193+
fi
194+
fi
195+
fi
196+
197+
err 5 "Invalid port(s): $min_port-$max_port"
198+
}

0 commit comments

Comments
 (0)