2
* This program is free software; you can redistribute it and/or modify
3
* it under the terms of the GNU General Public License as published by
4
* the Free Software Foundation; either version 2 of the License, or
5
* (at your option) any later version.
7
* This program is distributed in the hope that it will be useful,
8
* but WITHOUT ANY WARRANTY; without even the implied warranty of
9
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
* GNU General Public License for more details.
12
* You should have received a copy of the GNU General Public License
13
* along with this program; if not, write to the Free Software
14
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
* Author : Richard GAYRAUD - 04 Nov 2003
21
* Francois-Xavier Kowalski
23
* From Hewlett Packard Company.
28
* Guillaume Teissier from FTR&D
31
* Charles P Wright from IBM Research
35
class opentask *opentask::instance = NULL;
36
unsigned long opentask::calls_since_last_rate_change = 0;
37
unsigned long opentask::last_rate_change_time = 0;
39
void opentask::initialize() {
40
assert(instance == NULL);
41
instance = new opentask();
44
opentask::opentask() {
48
opentask::~opentask() {
52
void opentask::dump() {
53
WARNING("Uniform rate call generation task: %d", rate);
56
unsigned int opentask::wake() {
59
} else if (users >= 0) {
60
/* We need to wait until another call is terminated. */
63
/* We need to compute when the next call is going to be opened. */
64
return (unsigned long) (last_rate_change_time + ((calls_since_last_rate_change + 1) / (rate/rate_period_ms)));
68
bool opentask::run() {
69
int calls_to_open = 0;
82
unsigned long long current_calls = main_scenario->stats->GetStat(CStat::CPT_C_CurrentCall);
83
unsigned long long total_calls = main_scenario->stats->GetStat(CStat::CPT_C_IncomingCallCreated) + main_scenario->stats->GetStat(CStat::CPT_C_OutgoingCallCreated);
86
calls_to_open = ((l = (users - current_calls)) > 0) ? l : 0;
88
calls_to_open = (unsigned int)
89
((l=(long)floor(((clock_tick - last_rate_change_time) * rate/rate_period_ms)
90
- calls_since_last_rate_change))>0?l:0);
93
if (total_calls + calls_to_open > stop_after) {
94
calls_to_open = stop_after - total_calls;
97
if (open_calls_allowed && (current_calls + calls_to_open > open_calls_allowed)) {
98
calls_to_open = open_calls_allowed - current_calls;
101
if (calls_to_open < 0) {
105
unsigned int start_clock = getmilliseconds();
108
while(calls_to_open--)
110
/* Associate a user with this call, if we are in users mode. */
113
userid = freeUsers.back();
114
freeUsers.pop_back();
117
// adding a new OUTGOING CALL
118
main_scenario->stats->computeStat(CStat::E_CREATE_OUTGOING_CALL);
119
call * call_ptr = call::add_call(userid, is_ipv6, use_remote_sending_addr ? &remote_sending_sockaddr : &remote_sockaddr);
121
ERROR("Out of memory allocating call!");
124
calls_since_last_rate_change++;
126
outbound_congestion = false;
131
call_ptr->associate_socket(main_socket);
132
main_socket->ss_count++;
136
call_ptr->associate_socket(tcp_multiplex);
137
tcp_multiplex->ss_count++;
141
if (getmilliseconds() > start_clock) {
147
if (calls_to_open <= 0) {
153
// Quit after asked number of calls is reached
154
if(total_calls >= stop_after) {
162
void opentask::set_paused(bool new_paused)
165
/* Doesn't do anything, we must be in server mode. */
169
instance->setPaused();
171
instance->setRunning();
181
void opentask::set_rate(double new_rate)
184
/* Doesn't do anything, we must be in server mode. */
192
last_rate_change_time = getmilliseconds();
193
calls_since_last_rate_change = 0;
195
if(!open_calls_user_setting) {
197
int call_duration_min = main_scenario->duration;
199
if(duration > call_duration_min) call_duration_min = duration;
201
if(call_duration_min < 1000) call_duration_min = 1000;
203
open_calls_allowed = (int)((3.0 * rate * call_duration_min) / (double)rate_period_ms);
204
if(!open_calls_allowed) {
205
open_calls_allowed = 1;
210
void opentask::set_users(int new_users)
213
/* Doesn't do anything, we must be in server mode. */
222
if (users < new_users ) {
223
while (users < new_users) {
225
if (!retiredUsers.empty()) {
226
userid = retiredUsers.back();
227
retiredUsers.pop_back();
230
userVarMap[userid] = new VariableTable(userVariables);
232
freeUsers.push_front(userid);
237
users = open_calls_allowed = new_users;
239
last_rate_change_time = clock_tick;
240
calls_since_last_rate_change = 0;
242
assert(open_calls_user_setting);
244
instance->setRunning();
247
void opentask::freeUser(int userId) {
248
if (main_scenario->stats->GetStat(CStat::CPT_C_CurrentCall) > open_calls_allowed) {
249
retiredUsers.push_front(userId);
251
freeUsers.push_front(userId);
252
/* Wake up the call creation thread. */
254
instance->setRunning();