#!/bin/bash # # Copyright: 2013 Sipwise Development Team # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This package is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # # On Debian systems, the complete text of the GNU General # Public License version 3 can be found in "/usr/share/common-licenses/GPL-3". # function usage { echo "Usage: sipp.sh [-p PORT] [-m MPORT] [-t TIMEOUT] [-r] [-T TRANSPORT] scenario.xml" echo "Options:" echo -e "\t-p: sip port. default 50602/50603(responder)" echo -e "\t-m: media port" echo -e "\t-t: timeout. default 10/25(responder)" echo -e "\t-i: IP. default 127.0.0.1" echo -e "\t-T: transport [UDP|TCP] default UDP" echo -e "\t-r: responder" echo -e "\t-b: run sipp in background (responder)" echo "Arguments:" echo -e "\t sipp_scenario.xml file" } while getopts 'hrp:m:t:i:T:b' opt; do case $opt in h) usage; exit 0;; r) RESP=1;; p) PORT=$OPTARG;; m) MPORT=$OPTARG;; t) TIMEOUT=$OPTARG;; i) IP=$OPTARG;; T) TRANSPORT=${OPTARG,,};; b) BACK="-bg";; esac done shift $((OPTIND - 1)) if [[ $# -ne 1 ]]; then echo "Wrong number of arguments" usage exit 1 fi if ! [ -f "$1" ]; then echo "No $1 file found" usage exit 1 fi BASE_DIR="$(dirname "$1")" IP=${IP:-"127.0.0.1"} IP_SERVER=${IP_SERVER:-"127.0.0.1"} MAX="5000" if [ "${TRANSPORT}" == "tcp" ]; then TRANSPORT_ARG="-t t1" else TRANSPORT_ARG="-t u1" fi # shellcheck disable=SC2086 { if [ -z "${RESP}" ]; then if [ -n "${MPORT}" ]; then MPORT_ARG="-mp ${MPORT}" fi PORT=${PORT:-"50602"} TIMEOUT=${TIMEOUT:-"10"} sipp -max_socket $MAX ${TRANSPORT_ARG}\ -inf "${BASE_DIR}/callee.csv" -inf "${BASE_DIR}/caller.csv" \ -sf "$1" -i "$IP" -p "$PORT" \ -nr -nd -m 1 ${MPORT_ARG} \ -timeout "${TIMEOUT}" -timeout_error -trace_err \ "$IP_SERVER" &> /dev/null status=$? else if [ -n "${MPORT}" ]; then MPORT_ARG="-rtp_echo -mp ${MPORT}" fi PORT=${PORT:-"50603"} TIMEOUT=${TIMEOUT:-"25"} if [ -z "${BACK}" ]; then sipp -max_socket $MAX ${TRANSPORT_ARG}\ -inf "${BASE_DIR}/callee.csv" -inf "${BASE_DIR}/caller.csv" \ -sf "$1" -i "$IP" -p "$PORT" \ -nr -nd -m 1 ${MPORT_ARG} \ -timeout "${TIMEOUT}" -timeout_error -trace_err \ "$IP_SERVER" &> /dev/null status=$? else tmp=$(sipp $BACK -max_socket $MAX ${TRANSPORT_ARG}\ -inf "${BASE_DIR}/callee.csv" -inf "${BASE_DIR}/caller.csv" \ -sf "$1" -i "$IP" -p "$PORT" \ -nr -nd -m 1 ${MPORT_ARG} \ -timeout "${TIMEOUT}" -timeout_error -trace_err \ "$IP_SERVER") # shellcheck disable=SC2046 echo "$tmp" | cut -d= -f2 | sed -e 's_\[__' -e 's_\]__' status=0 fi fi } exit $status #EOF