1#!/bin/sh
2
3################################################################################
4##                                                                            ##
5## Copyright (c) International Business Machines  Corp., 2005                 ##
6##                                                                            ##
7## This program is free software;  you can redistribute it and#or modify      ##
8## it under the terms of the GNU General Public License as published by       ##
9## the Free Software Foundation; either version 2 of the License, or          ##
10## (at your option) any later version.                                        ##
11##                                                                            ##
12## This program is distributed in the hope that it will be useful, but        ##
13## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
14## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   ##
15## for more details.                                                          ##
16##                                                                            ##
17## You should have received a copy of the GNU General Public License          ##
18## along with this program;  if not, write to the Free Software               ##
19## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    ##
20##                                                                            ##
21##                                                                            ##
22################################################################################
23#
24# File:
25#   ns-echoclient
26#
27# Description:
28#   Send various kind of echo request
29#
30# Author:
31#   Mitsuru Chinen <mitch@jp.ibm.com>
32#
33# Options:
34#   -S name or IP address of the server
35#   -f protocol family
36#	4: IPv4
37#	6: IPv6
38#   -s array of packet size
39#   -t timeout [sec]
40#   -h display this usage
41#
42# Outputs:
43#   Process ID of the TCP traffic server
44#
45# Exit Value:
46#    0: Exit normally
47#   >0: Exit abnormally
48#
49# History:
50#   Oct 19 2005 - Created (Mitsuru Chinen)
51#
52#-----------------------------------------------------------------------
53#Uncomment line below for debug output.
54#trace_logic=${trace_logic:-"set -x"}
55$trace_logic
56
57#-----------------------------------------------------------------------
58#
59# Function: usage
60#
61# Description:
62#   Print the usage of this script, then exit
63#
64# Argument
65#   value: exit value
66#
67#-----------------------------------------------------------------------
68usage(){
69    value=$1
70    cat << EOD >&2
71ns-echoclient [OPTION]
72	-S name or IP address of the server
73	-f protocol family
74		4: IPv4
75		6: IPv6
76	-s array of packet size
77	-h display this usage
78EOD
79
80    exit $value
81}
82
83
84#
85# Main
86#
87
88family=0
89
90while getopts 'S:f:s:h' opt ; do
91    case $opt in
92	'S')
93	server_name=$OPTARG
94	;;
95	'f')
96	family=$OPTARG
97	;;
98	's')
99	size_array="$OPTARG"
100	;;
101	'h')
102	usage 0
103	;;
104	*)
105	echo "Unknown option" >&2
106	usage 1
107	;;
108    esac
109done
110
111# Check the server name
112if [ x$server_name = x ]; then
113    echo "server name isn't specified."
114    usage 1
115fi
116
117# Define the protocol family
118case $family in
119    4)
120    ping_command="ping"
121    ;;
122    6)
123    ping_command="ping6"
124    ;;
125    *)
126    echo "protocol family should be 4 or 6."
127    usage 1
128    ;;
129esac
130
131# Send the echo request
132if [ x"$size_array" = x ]; then
133    $ping_command $server_name >/dev/null 2>&1 &
134else
135    for size in $size_array ; do
136	$ping_command -s $size $server_name >/dev/null 2>&1 &
137    done
138fi
139
140exit 0
141