#!/bin/bash

# Set up defaults, then dot in base configuration.
# - base - base directory number
# - count - number of directory numbers per instance (must be even)
# - node_idx - index of this node (--index parameter to chef)
# - sipp_count - number of sipp instances per node
# - password - SIP password to use for all DNs (insecure but OK for stress)
base=2010000000
count=30000
node_idx=1
sipp_count=1
password=7kkzTyGW
. /etc/clearwater/config

# Clear out old configuration files.
rm -f /usr/share/clearwater/sip-stress/users.csv.*

# Figure out how many targets we have.  Due to TCP port limitations, we can't
# run more than one sipp instance per target.
if [ -f /etc/clearwater/cluster_settings ] ; then
  . /etc/clearwater/cluster_settings
  num_targets=$(echo $bono_servers | sed -e 's/,/\n/g' | wc -l)
  if [ $num_targets -lt $sipp_count ] ; then
    sipp_count=$num_targets
  fi
else
  sipp_count=1
fi

# Create configuration files for each sipp instance.
for index in $(seq $(((node_idx - 1) * sipp_count + 1)) $((node_idx * sipp_count))) ; do
  { echo USER
    for dn in $(eval echo {$((base + (count * (index - 1))))..$((base + (count * index)- 1))..2})
    do
      echo "$dn;[authentication username=$dn@$home_domain password=$password];$((dn + 1));[authentication username=$((dn + 1))@$home_domain password=$password]"
    done
  } > /usr/share/clearwater/sip-stress/users.csv.$index
done
