3 # 2010 Razvan Deaconescu, razvan.deaconescu@cs.pub.ro
7 # * starts/stops a client
8 # * manages when client completes
10 # use _DEBUG="off" to turn off debug printing
13 # Read the global configuration file
14 # Check if the global configuration file exists
15 if [ ! -e globalconfig ]; then
16 echo "Warning: The global config file globalconfig does not exist."
21 # Read the node-specific configuration file
22 # Check if the node-specific configuration file exists
23 if [ ! -e ../ClientWorkingFolders/TmpLogs/node_config ]; then
24 echo "Warning: The global config file ../ClientWorkingFolders/TmpLogs/node_config does not exist."
26 source ../ClientWorkingFolders/TmpLogs/node_config
29 # Read client mappings configuration file
30 # Check if the client mappings configuration file exists
31 if [ ! -e client_script_mappings ]; then
32 echo "Warning: The client mappings config file client_script_mappings does not exist."
34 source client_script_mappings
41 declare -a suspend_resume
45 local tmp_array=($(echo "$PERIODS" | sed 's/[,()]/ /g'))
46 start_time=${tmp_array[0]}
47 local len=${#tmp_array[@]}
48 DEBUG echo "PERIODS: $PERIODS"
50 stop_time=${tmp_array[$(($len-1))]}
52 for ((i = 1; i < $len-1; i++)); do
53 suspend_resume[$(($i - 1))]=${tmp_array[$i]}
60 DEBUG echo "suspending client ..."
61 kill -STOP ${client_pid}
67 DEBUG echo "resuming client ..."
68 kill -CONT ${client_pid}
71 # test whether time in period (t1, t2) is infinte ("-" sign)
72 # if that is the case, sleep indefinitely, waiting for shut down
77 if test "$time" = "-"; then
84 DEBUG echo "start_time is ${start_time}"
85 DEBUG echo "suspend_resume is ${suspend_resume[@]}"
86 DEBUG echo "stop_time is ${stop_time}"
88 # Initial sleep (before the client is started for the first time)
89 to_sleep=${start_time}
90 # Saving sleep time to log file - this script's output is redirected to the client log file
91 echo "SLEEP $to_sleep"
94 # Starting the client for the first time
95 DEBUG echo "CLIENT_TYPE is ${CLIENT_TYPE}"
96 start_client ${CLIENT_TYPE} ${DL_BW} ${UL_BW} ${NO_CONNECTIONS}
98 DEBUG echo "background_pid is ${background_pid}"
99 old_time=${start_time}
101 for ((i = 0; i < ${#suspend_resume[@]}; i += 2)); do
102 # Sleeping while the client runs. When i wake up i will suspend the client
103 test_infinite ${suspend_resume[$i]}
105 to_sleep=$((${suspend_resume[$i]} - ${old_time}))
107 client_pid=$(pgrep -P ${background_pid})
108 DEBUG echo "client_pid is ${client_pid}"
109 suspend_client ${client_pid}
110 old_time=${suspend_resume[$i]}
112 # Client is suspended. Sleeping until the client should be restarted. When i wake up i will start the client
113 test_infinite ${suspend_resume[$(($i+1))]}
115 to_sleep=$((${suspend_resume[$(($i+1))]} - ${old_time}))
116 # Saving sleep time to log file - this script's output is redirected to the client log file
117 echo "SLEEP $to_sleep"
119 resume_client ${client_pid}
120 old_time=${suspend_resume[$(($i+1))]}
123 # Sleeping while the client runs. When i wake up i will suspend the client for the last time
124 test_infinite ${stop_time}
126 to_sleep=$((${stop_time} - ${old_time}))
128 stop_client ${CLIENT_TYPE}