2007-10-11 19:06:29 +08:00
|
|
|
/* $OpenLDAP$ */
|
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
*
|
2009-01-22 08:40:04 +08:00
|
|
|
* Copyright 2006-2009 The OpenLDAP Foundation.
|
2007-10-11 19:06:29 +08:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted only as authorized by the OpenLDAP
|
|
|
|
* Public License.
|
|
|
|
*
|
|
|
|
* A copy of this license is available in file LICENSE in the
|
|
|
|
* top-level directory of the distribution or, alternatively, at
|
|
|
|
* <http://www.OpenLDAP.org/license.html>.
|
|
|
|
*/
|
|
|
|
/* ACKNOWLEDGEMENTS:
|
|
|
|
* This work was initially developed by Howard Chu for inclusion
|
|
|
|
* in OpenLDAP Software.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <ac/stdlib.h>
|
|
|
|
|
|
|
|
#include <ac/ctype.h>
|
|
|
|
#include <ac/param.h>
|
|
|
|
#include <ac/socket.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/unistd.h>
|
|
|
|
#include <ac/wait.h>
|
|
|
|
#include <ac/time.h>
|
|
|
|
#include <ac/signal.h>
|
|
|
|
|
|
|
|
#include <ldap.h>
|
|
|
|
#include <ldap_pvt_thread.h>
|
|
|
|
#include <lutil.h>
|
|
|
|
|
|
|
|
static int
|
|
|
|
do_time( );
|
|
|
|
|
|
|
|
/* This program is a simplified version of SLAMD's WeightedAuthRate jobclass.
|
|
|
|
* It doesn't offer as much configurability, but it's a good starting point.
|
|
|
|
* When run without the -R option it will behave as a Standard AuthRate job.
|
|
|
|
* Eventually this will grow into a set of C-based load generators for the SLAMD
|
|
|
|
* framework. This code is anywhere from 2 to 10 times more efficient than the
|
|
|
|
* original Java code, allowing servers to be fully loaded without requiring
|
|
|
|
* anywhere near as much load-generation hardware.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
usage( char *name )
|
|
|
|
{
|
2007-12-22 12:41:28 +08:00
|
|
|
fprintf( stderr, "usage: %s -H <uri> -b <baseDN> -w <passwd> -t <seconds> -r lo:hi\n\t"
|
|
|
|
"[-R %:lo:hi] [-f <filter-template>] [-n <threads>] [-D <bindDN>] [-i <seconds>]\n",
|
2007-10-11 19:06:29 +08:00
|
|
|
name );
|
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *filter = "(uid=user.%d)";
|
|
|
|
|
|
|
|
static char hname[1024];
|
|
|
|
static char *uri = "ldap:///";
|
|
|
|
static char *base;
|
|
|
|
static char *pass;
|
2007-12-22 12:41:28 +08:00
|
|
|
static char *binder;
|
2007-10-11 19:06:29 +08:00
|
|
|
|
|
|
|
static int tdur, r1per, r1lo, r1hi, r2per, r2lo, r2hi;
|
|
|
|
static int threads = 1;
|
|
|
|
|
2007-12-22 12:41:28 +08:00
|
|
|
static int interval = 30;
|
|
|
|
|
2007-10-11 19:06:29 +08:00
|
|
|
static volatile int *r1binds, *r2binds;
|
|
|
|
static int *r1old, *r2old;
|
|
|
|
static volatile int finish;
|
|
|
|
|
|
|
|
int
|
|
|
|
main( int argc, char **argv )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2007-12-22 12:41:28 +08:00
|
|
|
while ( (i = getopt( argc, argv, "b:D:H:w:f:n:i:t:r:R:" )) != EOF ) {
|
2007-10-11 19:06:29 +08:00
|
|
|
switch( i ) {
|
|
|
|
case 'b': /* base DN of a tree of user DNs */
|
|
|
|
base = strdup( optarg );
|
|
|
|
break;
|
|
|
|
|
2007-12-22 12:41:28 +08:00
|
|
|
case 'D':
|
|
|
|
binder = strdup( optarg );
|
|
|
|
break;
|
|
|
|
|
2007-10-11 19:06:29 +08:00
|
|
|
case 'H': /* the server uri */
|
|
|
|
uri = strdup( optarg );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'w':
|
|
|
|
pass = strdup( optarg );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 't': /* the duration to run */
|
|
|
|
if ( lutil_atoi( &tdur, optarg ) != 0 ) {
|
|
|
|
usage( argv[0] );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-12-22 12:41:28 +08:00
|
|
|
case 'i': /* the time interval */
|
|
|
|
if ( lutil_atoi( &interval, optarg ) != 0 ) {
|
|
|
|
usage( argv[0] );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-10-11 19:06:29 +08:00
|
|
|
case 'r': /* the uid range */
|
|
|
|
if ( sscanf(optarg, "%d:%d", &r1lo, &r1hi) != 2 ) {
|
|
|
|
usage( argv[0] );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'R': /* percentage:2nd uid range */
|
|
|
|
if ( sscanf(optarg, "%d:%d:%d", &r2per, &r2lo, &r2hi) != 3 ) {
|
|
|
|
usage( argv[0] );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'f':
|
|
|
|
filter = optarg;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'n':
|
|
|
|
if ( lutil_atoi( &threads, optarg ) != 0 || threads < 1 ) {
|
|
|
|
usage( argv[0] );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
usage( argv[0] );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( tdur == 0 || r1hi <= r1lo )
|
|
|
|
usage( argv[0] );
|
|
|
|
|
|
|
|
r1per = 100 - r2per;
|
|
|
|
if ( r1per < 1 )
|
|
|
|
usage( argv[0] );
|
|
|
|
|
|
|
|
r1binds = calloc( threads*4, sizeof( int ));
|
|
|
|
r2binds = r1binds + threads;
|
|
|
|
r1old = (int *)r2binds + threads;
|
|
|
|
r2old = r1old + threads;
|
|
|
|
|
|
|
|
do_time( );
|
|
|
|
|
|
|
|
exit( EXIT_SUCCESS );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *
|
|
|
|
my_task( void *my_num )
|
|
|
|
{
|
2007-12-22 12:41:28 +08:00
|
|
|
LDAP *ld = NULL, *sld = NULL;
|
2007-10-11 19:06:29 +08:00
|
|
|
ber_int_t msgid;
|
|
|
|
LDAPMessage *res, *msg;
|
|
|
|
char *attrs[] = { "1.1", NULL };
|
|
|
|
int rc = LDAP_SUCCESS;
|
|
|
|
int tid = *(int *)my_num;
|
|
|
|
|
|
|
|
ldap_initialize( &ld, uri );
|
|
|
|
if ( ld == NULL ) {
|
|
|
|
perror( "ldap_initialize" );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
int version = LDAP_VERSION3;
|
|
|
|
(void) ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION,
|
|
|
|
&version );
|
|
|
|
}
|
|
|
|
(void) ldap_set_option( ld, LDAP_OPT_REFERRALS, LDAP_OPT_OFF );
|
|
|
|
|
2007-12-22 12:41:28 +08:00
|
|
|
ldap_initialize( &sld, uri );
|
|
|
|
if ( sld == NULL ) {
|
|
|
|
perror( "ldap_initialize" );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
int version = LDAP_VERSION3;
|
|
|
|
(void) ldap_set_option( sld, LDAP_OPT_PROTOCOL_VERSION,
|
|
|
|
&version );
|
|
|
|
}
|
|
|
|
(void) ldap_set_option( sld, LDAP_OPT_REFERRALS, LDAP_OPT_OFF );
|
|
|
|
if ( binder ) {
|
|
|
|
rc = ldap_bind_s( sld, binder, pass, LDAP_AUTH_SIMPLE );
|
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
|
|
|
ldap_perror( sld, "ldap_bind" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-11 19:06:29 +08:00
|
|
|
r1binds[tid] = 0;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
char dn[BUFSIZ], *ptr, fstr[256];
|
|
|
|
int j, isr1;
|
|
|
|
|
|
|
|
if ( finish )
|
|
|
|
break;
|
|
|
|
|
|
|
|
j = rand() % 100;
|
|
|
|
if ( j < r1per ) {
|
|
|
|
j = rand() % r1hi;
|
|
|
|
isr1 = 1;
|
|
|
|
} else {
|
|
|
|
j = rand() % (r2hi - r2lo + 1 );
|
|
|
|
j += r2lo;
|
|
|
|
isr1 = 0;
|
|
|
|
}
|
|
|
|
sprintf(fstr, filter, j);
|
|
|
|
|
2007-12-22 12:41:28 +08:00
|
|
|
rc = ldap_search_ext( sld, base, LDAP_SCOPE_SUB,
|
2007-10-11 19:06:29 +08:00
|
|
|
fstr, attrs, 0, NULL, NULL, 0, 0, &msgid );
|
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
2007-12-22 12:41:28 +08:00
|
|
|
ldap_perror( sld, "ldap_search_ex" );
|
2007-10-11 19:06:29 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-12-22 12:41:28 +08:00
|
|
|
while (( rc=ldap_result( sld, LDAP_RES_ANY, LDAP_MSG_ONE, NULL, &res )) >0){
|
2007-10-11 19:06:29 +08:00
|
|
|
BerElement *ber;
|
|
|
|
struct berval bv;
|
|
|
|
char *ptr;
|
|
|
|
int done = 0;
|
|
|
|
|
2007-12-22 12:41:28 +08:00
|
|
|
for (msg = ldap_first_message( sld, res ); msg;
|
|
|
|
msg = ldap_next_message( sld, msg )) {
|
2007-10-11 19:06:29 +08:00
|
|
|
switch ( ldap_msgtype( msg )) {
|
|
|
|
case LDAP_RES_SEARCH_ENTRY:
|
2007-12-22 12:41:28 +08:00
|
|
|
rc = ldap_get_dn_ber( sld, msg, &ber, &bv );
|
2007-10-11 19:06:29 +08:00
|
|
|
strcpy(dn, bv.bv_val );
|
|
|
|
ber_free( ber, 0 );
|
|
|
|
break;
|
|
|
|
case LDAP_RES_SEARCH_RESULT:
|
|
|
|
done = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ( done )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ldap_msgfree( res );
|
|
|
|
if ( done ) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = ldap_bind_s( ld, dn, pass, LDAP_AUTH_SIMPLE );
|
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
|
|
|
ldap_perror( ld, "ldap_bind" );
|
|
|
|
}
|
|
|
|
if ( isr1 )
|
|
|
|
r1binds[tid]++;
|
|
|
|
else
|
|
|
|
r2binds[tid]++;
|
|
|
|
}
|
|
|
|
|
2007-12-22 12:41:28 +08:00
|
|
|
ldap_unbind( sld );
|
2007-10-11 19:06:29 +08:00
|
|
|
ldap_unbind( ld );
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
do_time( )
|
|
|
|
{
|
|
|
|
struct timeval tv;
|
|
|
|
time_t now, prevt, start;
|
|
|
|
|
|
|
|
int r1new, r2new;
|
|
|
|
int dt, dr1, dr2, rr1, rr2;
|
|
|
|
int dr10, dr20;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
gethostname(hname, sizeof(hname));
|
|
|
|
printf("%s(tid)\tdeltaT\tauth1\tauth2\trate1\trate2\tRate1+2\n", hname);
|
|
|
|
srand(getpid());
|
|
|
|
|
|
|
|
prevt = start = time(0L);
|
|
|
|
|
|
|
|
for ( i = 0; i<threads; i++ ) {
|
|
|
|
ldap_pvt_thread_t thr;
|
|
|
|
r1binds[i] = i;
|
|
|
|
ldap_pvt_thread_create( &thr, 1, my_task, (void *)&r1binds[i] );
|
|
|
|
}
|
|
|
|
|
|
|
|
for (;;) {
|
2007-12-22 12:41:28 +08:00
|
|
|
tv.tv_sec = interval;
|
2007-10-11 19:06:29 +08:00
|
|
|
tv.tv_usec = 0;
|
|
|
|
|
|
|
|
select(0, NULL, NULL, NULL, &tv);
|
|
|
|
|
|
|
|
now = time(0L);
|
|
|
|
|
|
|
|
dt = now - prevt;
|
|
|
|
prevt = now;
|
|
|
|
|
|
|
|
dr10 = 0;
|
|
|
|
dr20 = 0;
|
|
|
|
|
|
|
|
for ( i = 0; i < threads; i++ ) {
|
|
|
|
r1new = r1binds[i];
|
|
|
|
r2new = r2binds[i];
|
|
|
|
|
|
|
|
dr1 = r1new - r1old[i];
|
|
|
|
dr2 = r2new - r2old[i];
|
|
|
|
rr1 = dr1 / dt;
|
|
|
|
rr2 = dr2 / dt;
|
|
|
|
|
|
|
|
printf("%s(%d)\t%d\t%d\t%d\t%d\t%d\t%d\n",
|
|
|
|
hname, i, dt, dr1, dr2, rr1, rr2, rr1 + rr2);
|
|
|
|
|
|
|
|
dr10 += dr1;
|
|
|
|
dr20 += dr2;
|
|
|
|
|
|
|
|
r1old[i] = r1new;
|
|
|
|
r2old[i] = r2new;
|
|
|
|
}
|
|
|
|
if ( i > 1 ) {
|
|
|
|
rr1 = dr10 / dt;
|
|
|
|
rr2 = dr20 / dt;
|
|
|
|
|
|
|
|
printf("%s(sum)\t%d\t%d\t%d\t%d\t%d\t%d\n",
|
|
|
|
hname, 0, dr10, dr20, rr1, rr2, rr1 + rr2);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( now - start >= tdur ) {
|
|
|
|
finish = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|