📄 testrad.c
字号:
/************************************************************************* Free request and response attribute lists************************************************************************/ void radiustest_free_attrib_lists ( RADIUS_ATTRIBUTE_LIST_HANDLE request_attrib_handle, RADIUS_ATTRIBUTE_LIST_HANDLE response_attrib_handle){ if (request_attrib_handle != NULL) { if (radius_delete_attribute_list(request_attrib_handle) == false) printf ("Error: Call to delete request attribute list failed\n");/* else printf("request attribute list handle %x freed\n", request_attrib_handle);*/ } if (response_attrib_handle != NULL) { if (radius_delete_attribute_list(response_attrib_handle) == false) printf ("Error: Call to delete response attribute list failed\n");/* else printf("response attribute list handle %x freed\n", response_attrib_handle);*/ }}/************************************************************************* Test routine* This task is spawned by runmtasks and will send out either RADIUS * authentication request or accounting requests to start and stop the accounting* accounting session.************************************************************************/void radius_send_task (bool any_server, RADIUS_SERVER_HANDLE sh, Test_type request){ UINT user; for (user = 1; user <= RADIUS_TEST_REQUEST_NUMBER; user ++) { if (request == AUTHENTICATION) { radius_printf(RADIUS_DATA_PRINTF, "Sending authentication ...\n"); radius_send_test_authentication_request (user, any_server, sh); } else { radius_printf(RADIUS_DATA_PRINTF, "Sending accounting start ...\n"); radius_send_test_accounting_request (RADIUS_ACCOUNTING_START, user, any_server, sh); radius_printf(RADIUS_DATA_PRINTF, "Sending accounting stop ...\n"); radius_send_test_accounting_request (RADIUS_ACCOUNTING_STOP, user, any_server, sh); } } exit (0);} /************************************************************************* Test routine* This routine will spawn out multiple acc_test_task tasks with each task * sending out multiple requests for each user. Tester can control the number* of tasks to be spawned by inputting the test_request_number. You can run* this test to get the Client to send numerous requests to the Server perhaps* to exhaust the pool of available identifiers. ************************************************************************/void runmtasks (int test_request_number, Test_type test){ char radius_task_name [20]; int test_task_id, i; UINT p1, p2, p3; test_count = 0; radiustest_initialize(); if (test_request_number <= 0) { printf("First input parameter must be greater than 0\n"); goto BackToUser; } for (i=0; i<RADIUS_MAX_SERVERS; i++) { server_handles[i] = INVALID_HANDLE; } for (i = 1; i <= test_request_number; i++) { sprintf (radius_task_name, "tRadiusReq_(%d)\n", i); if (i >= RADIUS_MAX_SERVERS) { printf("Error: Maximum server handles exceeded\n"); break; } if (test == AUTHENTICATION) { server_handles[i - 1] = radius_get_first_server (RADIUS_AUTHENTICATION_SERVER_TYPE); } else { server_handles[i - 1] = radius_get_first_server (RADIUS_ACCOUNTING_SERVER_TYPE); } p1 = false; p2 = server_handles[i - 1]; p3 = test; test_task_id = taskSpawn (radius_task_name, RWOS_TASK_BASE_PRIORITY, VX_FP_TASK/*RWOS_TASK_DEBUG_OPTIONS*/, 10000/* RWOS_TASK_STACK_SIZE*/, (FUNCPTR) radius_send_task, p1,p2,p3,0,0,0,0,0,0,0); if ( test_task_id == ERROR ) { printf (" RADIUS test: Task for request %d Failed", i); } /* insert 5 sec delay after 100 requests so we don't run out of mbufs */ if ((i * RADIUS_TEST_REQUEST_NUMBER) % 100 == 0) taskDelay(sysClkRateGet() * BREAK_TIME); } if (test == AUTHENTICATION) { while (test_count < (i-1) * RADIUS_TEST_REQUEST_NUMBER) taskDelay (sysClkRateGet () * 1); } else { while (test_count < 2 * (i-1) * RADIUS_TEST_REQUEST_NUMBER) /* accounting start and stop for each request */ taskDelay (sysClkRateGet () * 1); } for (i=0; i<RADIUS_MAX_SERVERS; i++) { if (server_handles[i] != INVALID_HANDLE) { radius_free_server_handle (server_handles[i]); radius_printf(RADIUS_DATA_PRINTF, "Free server handle %x\n", server_handles[i]); } }BackToUser: printf("runmtasks completed\n");}/************************************************************************* Test routine* This task is spawned by runrad function (see below) to enable you to select * whether to send RADIUS authentication request or accounting request depending * on the Test_type you specify.* You can also control the number of requests you want to send by specifying* num_of_requests.************************************************************************//* Test packet retransmission *//* #define TEST_RESEND*/void radius_test_task (Test_type test, UINT num_of_requests, bool any_server){ RADIUS_SERVER_HANDLE server_handle; int i, user_id; test_count = 0; radiustest_initialize(); if (test == AUTHENTICATION) {#ifndef SERVER_DESTROY_TEST server_handle = radius_get_first_server (RADIUS_AUTHENTICATION_SERVER_TYPE);#else server_handle = radius_server_create(0,0xc0a8fe41, 1812, 3, 5, "challenge");#endif if (server_handle == INVALID_HANDLE) { printf("Can't get server handle\n"); exit (1); } radius_printf(RADIUS_DATA_PRINTF, "Auth. server handle = %x\n", server_handle); /*The long delay is added to first request to exhaust the number of retransmission * of a packet. You can disconnect the ethernet cable to the Server temporarily to * let the retransmission counter expires */ user_id = 1;#ifdef TEST_RESEND radius_send_test_authentication_request (user_id, any_server); taskDelay(sysClkRateGet() * LONG_DELAY); user_id++;#endif for (i=user_id; i <= num_of_requests; i++) { user_id = i % RADIUS_TEST_REQUEST_NUMBER; if (user_id == 0) user_id = RADIUS_TEST_REQUEST_NUMBER; radius_send_test_authentication_request (user_id, any_server, server_handle); /* insert a delay after 100 requests so we don't run out of mbufs */ if (i % 100 == 0) taskDelay(sysClkRateGet() * BREAK_TIME); }#ifdef SERVER_DESTROY_TEST if (radius_server_destroy(server_handle) == true) { printf("Destroy server\n"); }#endif while (test_count < num_of_requests) taskDelay (sysClkRateGet() * SHORT_DELAY); } else /* accounting request */ {#ifndef SERVER_DESTROY_TEST server_handle = radius_get_first_server (RADIUS_ACCOUNTING_SERVER_TYPE);#else server_handle = radius_server_create(1, 0xc0a8fe41, 1813, 3, 5, "challenge");#endif if (server_handle == INVALID_HANDLE) { exit(1); } radius_printf(RADIUS_DATA_PRINTF, "Acct. server handle = %x\n", server_handle); user_id = 1; /*The long delay is added to first request to exhaust the number of retransmission * of a packet. You can disconnect the ethernet cable to the Server temporarily to * let the retransmission counter expires */#ifdef TEST_RESEND radius_send_test_accounting_request (RADIUS_ACCOUNTING_START, user_id, any_server, server_handle); taskDelay (sysClkRateGet() * LONG_DELAY); user_id++;#endif for (i = user_id; i <= num_of_requests; i++) { user_id = i % RADIUS_TEST_REQUEST_NUMBER; if (user_id == 0) user_id = RADIUS_TEST_REQUEST_NUMBER; radius_printf(RADIUS_DATA_PRINTF, "Sending accounting start ...\n"); radius_send_test_accounting_request (RADIUS_ACCOUNTING_START, user_id, any_server, server_handle); radius_printf(RADIUS_DATA_PRINTF, "Sending accounting stop ...\n"); radius_send_test_accounting_request (RADIUS_ACCOUNTING_STOP, user_id, any_server, server_handle); /* insert a delay after 100 requests so we don't run out of mbufs */ if ((i * 2) % 100 == 0) taskDelay(sysClkRateGet() * BREAK_TIME); }#ifdef SERVER_DESTROY_TEST if (radius_server_destroy(server_handle) == true) { printf("Destroy server\n"); }#endif while (test_count < 2 * num_of_requests) taskDelay (sysClkRateGet() * SHORT_DELAY); } radius_free_server_handle (server_handle); printf("Radius server %x freed\n", server_handle); printf("Test completed\n"); exit (0);}/************************************************************************************ Routine rad* Input test, 0 = authentication, 1 = accounting* iteration, number of requests* Description This function spawns a task to invoke the radius client to send a* request to radius server. If the server is down or busy, request* will time out after the specified number of retries is exhausted.***********************************************************************************/void rad(Test_type test, UINT iteration){ UINT task_param1, task_param2, task_param3; char radius_task_name [20]; int test_task_id; sprintf (radius_task_name, "tRadiusReq_(%d)", test); task_param1 = (UINT)test; task_param2 = iteration; task_param3 = false; test_task_id = taskSpawn (radius_task_name, RWOS_TASK_BASE_PRIORITY, VX_FP_TASK, /*RWOS_TASK_DEBUG_OPTIONS*/ 10000, /* RWOS_TASK_STACK_SIZE*/ (FUNCPTR) radius_test_task, task_param1, task_param2,task_param3,0,0,0,0,0,0,0); if ( test_task_id == ERROR ) { printf (" RADIUS test: Task for request %d Failed", test); }}/************************************************************************************ Routine anyrad* Input test, 0 = authentication, 1 = accounting* iteration, number of requests* Description This function spawns a task to invoke the radius client to send a* request to radius server. If the server is down or busy, request* is sent to another available server until either the request has* been acknowledged or there is no more available server.***********************************************************************************/void radany(Test_type test, UINT iteration){ UINT task_param1, task_param2, task_param3; char radius_task_name [20]; int test_task_id; sprintf (radius_task_name, "tRadiusReq_(%d)", test); task_param1 = (UINT)test; task_param2 = iteration; task_param3 = true; test_task_id = taskSpawn (radius_task_name, RWOS_TASK_BASE_PRIORITY, VX_FP_TASK, /*RWOS_TASK_DEBUG_OPTIONS*/ 20000, /* RWOS_TASK_STACK_SIZE*/ (FUNCPTR) radius_test_task, task_param1, task_param2,task_param3,0,0,0,0,0,0,0); if ( test_task_id == ERROR ) { printf (" RADIUS test: Task for request %d Failed", test); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -