int wi_set_unique_id(){ int rc=LR_PASS; char* my_controller_name; char* my_host; // host_name of load generator (injector): int iScenarioID; char* vuser_group; int iVuserID; // -1 if run in VuGen. char* sVuserID[32]; // from lr_get_vuser_ip() // char my_unique_id[64]=""; // defined as global variable. int vuser_pid=0; // Windows Process ID my_controller_name = lr_get_master_host_name(); my_host = lr_get_host_name(); vuser_pid = wi_get_vuser_pid(); lr_whoami(&iVuserID, &vuser_group, &iScenarioID); // lr_whoami returns void by design (no rc). // NOTE: When run in VuGen: Controller=None, host=%MACHINENAME%, ScenarioID=0, vuser_group=None, iVuserID=-1. wi_startPrintingInfo(); lr_output_message(">> Controller=%s, Host=%s, ScenarioID=%d, Group=%s, Vuser=%d, PID=%d." ,my_controller_name ,my_host ,iScenarioID, vuser_group ,iVuserID, vuser_pid ); wi_stopPrinting(); sprintf( global_unique_id,"C%s.H%d.S%s.G%s.U%d.P%d" ,my_controller_name ,my_host ,iScenarioID ,vuser_group ,iVuserID ,vuser_pid ); return rc; } // wi_set_unique_id
vuser_init() { lrs_startup(257); lrs_create_socket("socket0","UDP","RemoteHost=ad3.norouter.cn:1500",LrsLastArg); lr_whoami(&id, &vuser_group, &scid); srand(id+time(NULL)); rand_mac(randmac); rand_ip(randip); lr_output_message("randip=%s",randip); lr_output_message("rand_mac=%s",randmac); lr_save_string(randmac,"mac"); lr_save_string(randip,"ip"); lrs_send("socket0", "buf0", LrsLastArg); lrs_receive("socket0", "buf1", LrsLastArg); ids = lrs_get_received_buffer("socket0",18,18,NULL); buffer_convert_to_hex_string(ids,18,buf); lr_output_message("ids=%s",buf); lrs_get_buffer_by_name("buf2",&data,&size); memcpy(dev_id,ids,8); memcpy(id_rand,ids+8,10); memcpy(data+18,dev_id,8); buffer_convert_to_hex_string(data,36,buf); //lr_output_message("buf=%s",buf); lrs_set_receive_option(Mismatch,MISMATCH_CONTENT); lrs_set_send_buffer("socket0",buf,strlen(buf)); lrs_send("socket0", "buf2", LrsLastArg); lrs_receive("socket0","buf3",LrsLastArg); lrs_set_receive_option(Mismatch,MISMATCH_SIZE); lrs_get_buffer_by_name("buf4",&data,&size); memcpy(data+18,dev_id,8); buffer_convert_to_hex_string(data,44,buf); lrs_set_send_buffer("socket0",buf,strlen(buf)); lrs_send("socket0", "buf4", LrsLastArg); lrs_receive("socket0","buf5",LrsLastArg); p = lrs_get_received_buffer("socket0",18,16,NULL); memcpy(ran,p,16); oemMD5Init(&context); oemMD5Update(&context,(unsigned char*)id_rand,10); oemMD5Update(&context,(unsigned char*)ran,16); oemMD5Final((unsigned char*)digest,&context); lrs_get_buffer_by_name("buf6",&data,&size); memcpy(data+18,dev_id,8); memcpy(data+30,digest,16); buffer_convert_to_hex_string(data,131,buf); lrs_set_receive_option(Mismatch,MISMATCH_CONTENT); lrs_set_send_buffer("socket0",buf,strlen(buf)); lrs_send("socket0", "buf6", LrsLastArg); lrs_receive("socket0","buf7",LrsLastArg); lrs_set_receive_option(Mismatch,MISMATCH_SIZE); return 0; }
/*! \brief Ylib setup - determines and stores the identity of the virtual user. This runs lr_whoami and sets y_virtual_user_id and y_virtual_user_group as global variables. Called y_rand() (for it's seed), y_is_vugen_run() and others dynamically. \return void \warning Only call this if you need the y_virtual_user_id and y_virtual_group variables to be set. Ylib functions that need this will call it when required. \sa y_rand() \author Floris Kraak */ void y_setup() { // if this is filled y_setup() has already been called. if( y_virtual_user_group != NULL ) { return; } // Loadrunner sets the locale to "", causing scripts running in locales other than en_US to misbehave. // Let's set it to something sensible, that actually works for people who don't want to mess with this stuff. setlocale(LC_ALL, "C"); // Global variables, handle with care lr_whoami(&y_virtual_user_id, &y_virtual_user_group, &y_scid); y_is_vugen_run_bool = y_virtual_user_id == -1; // srand() no longer required on Windows but rand() may still be used in user code so we leave it in. srand(time(NULL) + y_virtual_user_id + ((int)y_virtual_user_group) & 1023); }
vuser_init() { char * sBuf; int iid; int isid; char *sGroupname; lr_whoami(&iid, &sGroupname, &isid); if((sBuf = (char *)malloc((strlen(sGroupname) + 7)* sizeof(char))) == NULL){ lr_error_message("Out of memory error"); }else{ sprintf(sBuf,"%s:%d",sGroupname, iid); lr_save_string(sBuf,"pVUID"); } lr_output_message("TIVMsg: Group name: %s", sBuf); free(sBuf); return 0; }
MySQLTemplate() { int rc = 0; MYSQL *db_connection; MYSQL_RES *query_result; MYSQL_ROW result_row; char *server = "localhost"; char *user = "******"; char *password = "******"; char *database = "LRDB"; int port = 3306; // default MySQL port //static char *server_options[] = { "mysql_test", "--defaults-file=my.cnf" }; //int num_elements = sizeof(server_options)/ sizeof(char *); lr_whoami(&vuser_id, &vuser_group, &scid); lr_message( "Group: %s, vuser id: %d, scenario id %d", vuser_group, vuser_id, scid); if (vuser_id == -1) { vuser_id = 1; } rc = lr_load_dll("C:\\Program Files\\MySQL\\MySQL Server 5.0\\lib\\opt\\libmysql.dll"); // You should be able to find the MySQL DLL somewhere in your MySQL install directory. if (rc != 0) { lr_error_message("Could not load libmysql.dll"); lr_abort(); } // Allocate and initialise a new MySQL object db_connection = mysql_init(NULL); if (db_connection == NULL) { lr_error_message("Insufficient memory"); return -1; } // Connect to the database if (mysql_real_connect(db_connection, server, user, password, database, port, NULL, 0) == NULL) { lr_error_message("error on connect: %s\n", mysql_error(db_connection)); return -1; } if (mysql_query(db_connection, "SELECT * FROM LATLogin;")!= 0) { lr_error_message("error on query: %s\n", mysql_error(db_connection)); return -1; } if ((query_result = mysql_store_result(db_connection)) == NULL) { lr_error_message("error on store: %s\n", mysql_error(db_connection)); return -1; } while (result_row = mysql_fetch_row(query_result)) { lr_output_message("%s - %s", result_row[0]); } mysql_free_result(query_result); // Free the MySQL object created by mysql_init mysql_close(db_connection); mysql_server_end(); return 0; }
Action() { char* data; char* ids; int size; char buf[1024]; char dev_id[9]; char id_rand[10]; char ran[16]; char digest[16]; char* p; int i = 0; char randmac[25]; char randip[17]; oemMD5_CTX context; int id, scid; char *vuser_group; lr_whoami(&id, &vuser_group, &scid); srand(id+time(NULL)); rand_mac(randmac); rand_ip(randip); lr_output_message("randip=%s",randip); lr_output_message("rand_mac=%s",randmac); lr_save_string(randmac,"mac"); lr_save_string(randip,"ip"); lrs_send("socket0", "buf0", LrsLastArg); lrs_receive("socket0", "buf1", LrsLastArg); ids = lrs_get_received_buffer("socket0",18,18,NULL); buffer_convert_to_hex_string(ids,18,buf); lr_output_message("ids=%s",buf); lrs_get_buffer_by_name("buf2",&data,&size); memcpy(dev_id,ids,8); memcpy(id_rand,ids+8,10); memcpy(data+18,dev_id,8); buffer_convert_to_hex_string(data,36,buf); //lr_output_message("buf=%s",buf); lrs_set_receive_option(Mismatch,MISMATCH_CONTENT); lrs_set_send_buffer("socket0",buf,strlen(buf)); lrs_send("socket0", "buf2", LrsLastArg); lrs_receive("socket0","buf3",LrsLastArg); lrs_set_receive_option(Mismatch,MISMATCH_SIZE); lrs_get_buffer_by_name("buf4",&data,&size); memcpy(data+18,dev_id,8); buffer_convert_to_hex_string(data,44,buf); lrs_set_send_buffer("socket0",buf,strlen(buf)); lrs_send("socket0", "buf4", LrsLastArg); lrs_receive("socket0","buf5",LrsLastArg); p = lrs_get_received_buffer("socket0",18,16,NULL); memcpy(ran,p,16); oemMD5Init(&context); oemMD5Update(&context,(unsigned char*)id_rand,10); oemMD5Update(&context,(unsigned char*)ran,16); oemMD5Final((unsigned char*)digest,&context); lrs_get_buffer_by_name("buf6",&data,&size); memcpy(data+18,dev_id,8); memcpy(data+30,digest,16); buffer_convert_to_hex_string(data,131,buf); lrs_set_receive_option(Mismatch,MISMATCH_CONTENT); lrs_set_send_buffer("socket0",buf,strlen(buf)); lrs_send("socket0", "buf6", LrsLastArg); lrs_receive("socket0","buf7",LrsLastArg); lrs_set_receive_option(Mismatch,MISMATCH_SIZE); return 0; }
void y_setup() { // Global variables, handle with care lr_whoami(&_vUserID, &_vUserGroup, NULL); }