Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2896 lines
106 KiB

  1. #include <windows.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <conio.h>
  5. #include <string.h>
  6. #include <winsock.h>
  7. #include <tchar.h>
  8. #include <iphlpapi.h>
  9. #include "wlbsctrl.h"
  10. #include "wlbsparm.h"
  11. #include "wlbsiocl.h"
  12. #define BUF_SIZE 256
  13. typedef enum
  14. {
  15. init,
  16. query,
  17. suspend,
  18. resume,
  19. wlbsstart,
  20. stop,
  21. drainstop,
  22. enable,
  23. disable,
  24. drain,
  25. resolve,
  26. addresstostring,
  27. addresstoname,
  28. readreg,
  29. writereg,
  30. commit,
  31. getnumportrules,
  32. enumportrules,
  33. getportrule,
  34. addportrule,
  35. deleteportrule,
  36. setpassword,
  37. portset,
  38. destinationset,
  39. timeoutset,
  40. codeset
  41. }
  42. TEST_COMMAND;
  43. PTCHAR ErrStrings [] = {_TEXT("Init"),
  44. _TEXT("Query"),
  45. _TEXT("Suspend"),
  46. _TEXT("Resume"),
  47. _TEXT("Start"),
  48. _TEXT("Stop"),
  49. _TEXT("DrainStop"),
  50. _TEXT("Enable"),
  51. _TEXT("Disable"),
  52. _TEXT("Drain"),
  53. _TEXT("Resolve"),
  54. _TEXT("AddressToString"),
  55. _TEXT("AddressToName"),
  56. _TEXT("ReadReg"),
  57. _TEXT("WriteReg"),
  58. _TEXT("Commit"),
  59. _TEXT("GetNumPortRules"),
  60. _TEXT("EnumPortRules"),
  61. _TEXT("GetPortRule"),
  62. _TEXT("AddPortRule"),
  63. _TEXT("SetPassword"),
  64. _TEXT("PortSet"),
  65. _TEXT("DestinationSet"),
  66. _TEXT("TimeoutSet"),
  67. _TEXT("CodeSet"),
  68. };
  69. typedef struct Err_Struct
  70. {
  71. struct Err_Struct * next;
  72. TCHAR comment [BUF_SIZE];
  73. }
  74. Err_Struct, * PErr_Struct;
  75. static global_init = WLBS_INIT_ERROR;
  76. static PErr_Struct headq = NULL, tailq = NULL;
  77. static total_tests = 0;
  78. static failed_tests = 0;
  79. static TCHAR remote_password [BUF_SIZE];
  80. static TCHAR tbuf [BUF_SIZE];
  81. static TCHAR status_buf [BUF_SIZE];
  82. static BOOL verbose = FALSE;
  83. static remote_cl_ip = 0;
  84. static remote_host_ip = 0;
  85. static BOOL remote_test = FALSE;
  86. static BOOL local_test = FALSE;
  87. static BOOL init_test = FALSE;
  88. static BOOL version_nt4 = FALSE;
  89. static timeout = 1000; /* 1 second by default */
  90. void print_error_messages ();
  91. /* This function adds a error message to the list of error messages.
  92. * This list will be displayed at the end.
  93. */
  94. void add_error (PTCHAR errmsg)
  95. {
  96. PErr_Struct err = (PErr_Struct) malloc (sizeof (Err_Struct));
  97. total_tests ++;
  98. failed_tests++;
  99. _tcscpy (err -> comment, errmsg);
  100. err -> next = NULL;
  101. if (tailq == NULL)
  102. headq = tailq = err;
  103. else
  104. {
  105. tailq -> next = err;
  106. tailq = err;
  107. }
  108. if (verbose)
  109. _tprintf (_TEXT("%s\n"), err -> comment);
  110. return;
  111. }
  112. /* Compares the expected value with the actual returned value and generates an error message
  113. * which gets appended to the list of error messages
  114. */
  115. void verify_return_value (PTCHAR string, DWORD expected, DWORD actual)
  116. {
  117. TCHAR tbuf [BUF_SIZE];
  118. if (verbose)
  119. _tprintf( _TEXT("%s %s\n"), status_buf, string);
  120. else
  121. {
  122. putchar (8);
  123. putchar (8);
  124. putchar (8);
  125. putchar (8);
  126. printf("%4d", total_tests);
  127. }
  128. if (expected == actual)
  129. {
  130. total_tests ++;
  131. return;
  132. }
  133. _stprintf ( tbuf, _TEXT("Test Number %d %s Testing %s Expected %d Returned %d"),
  134. total_tests, status_buf, string, expected, actual);
  135. add_error (tbuf);
  136. return;
  137. }
  138. /* When two return values are possible, such as WLBS_CONVERGED or WLBS_DEFAULT */
  139. void verify_return_value2 (PTCHAR string, DWORD expected1, DWORD expected2, DWORD actual)
  140. {
  141. if (verbose)
  142. _tprintf( _TEXT("%s %s\n"), status_buf, string);
  143. if (expected1 == actual || expected2 == actual)
  144. {
  145. total_tests ++;
  146. return;
  147. }
  148. _stprintf ( tbuf, _TEXT("Test Number %d %s Testing %s Expected %d or %d Returned %d"),
  149. total_tests, status_buf, string, expected1, expected2, actual);
  150. add_error (tbuf);
  151. return;
  152. }
  153. void verify_return_value3 (PTCHAR string, DWORD expected1, DWORD expected2, DWORD expected3, DWORD actual)
  154. {
  155. if (verbose)
  156. _tprintf( _TEXT("%s %s\n"), status_buf, string);
  157. if (expected1 == actual || expected2 == actual || expected3 == actual)
  158. {
  159. total_tests ++;
  160. return;
  161. }
  162. _stprintf ( tbuf, _TEXT("Test Number %d %s Testing %s Expected %d or %d or %d Returned %d"),
  163. total_tests, status_buf, string, expected1, expected2, expected3, actual);
  164. add_error (tbuf);
  165. return;
  166. }
  167. /* This function calls all the apis without calling init
  168. * Each of the apis should return WLBS_INIT_ERROR */
  169. void check_init()
  170. {
  171. TEST_COMMAND cmd;
  172. WLBS_REG_PARAMS reg_data;
  173. WLBS_PORT_RULE port_rule;
  174. WLBS_PORT_RULE port_rules [WLBS_MAX_RULES];
  175. DWORD num = WLBS_MAX_RULES;
  176. DWORD status, status1;
  177. _tcscpy (status_buf, _TEXT("Calling the apis without Initializing"));
  178. status = WlbsQuery(WLBS_LOCAL_CLUSTER,WLBS_LOCAL_HOST,NULL,NULL,NULL,NULL);
  179. verify_return_value (_TEXT("Query"), WLBS_INIT_ERROR, status);
  180. status = WlbsSuspend(WLBS_LOCAL_CLUSTER,WLBS_LOCAL_HOST,NULL,NULL);
  181. verify_return_value (_TEXT("Suspend"), WLBS_INIT_ERROR, status);
  182. status = WlbsResume(WLBS_LOCAL_CLUSTER,WLBS_LOCAL_HOST,NULL,NULL);
  183. verify_return_value (_TEXT("Resume"), WLBS_INIT_ERROR, status);
  184. status = WlbsStart(WLBS_LOCAL_CLUSTER,WLBS_LOCAL_HOST,NULL,NULL);
  185. verify_return_value (_TEXT("Start"), WLBS_INIT_ERROR, status);
  186. status = WlbsStop(WLBS_LOCAL_CLUSTER,WLBS_LOCAL_HOST,NULL,NULL);
  187. verify_return_value (_TEXT("Stop"), WLBS_INIT_ERROR, status);
  188. status = WlbsDrainStop(WLBS_LOCAL_CLUSTER,WLBS_LOCAL_HOST,NULL,NULL);
  189. verify_return_value (_TEXT("DrainStop"), WLBS_INIT_ERROR, status);
  190. status = WlbsEnable(WLBS_LOCAL_CLUSTER,WLBS_LOCAL_HOST,NULL,NULL,80);
  191. verify_return_value (_TEXT("Enable"), WLBS_INIT_ERROR, status);
  192. status = WlbsDisable(WLBS_LOCAL_CLUSTER,WLBS_LOCAL_HOST,NULL,NULL,80);
  193. verify_return_value (_TEXT("Disable"), WLBS_INIT_ERROR, status);
  194. status = WlbsDrain(WLBS_LOCAL_CLUSTER,WLBS_LOCAL_HOST,NULL,NULL,80);
  195. verify_return_value (_TEXT("Drain"), WLBS_INIT_ERROR, status);
  196. status = WlbsReadReg(WLBS_LOCAL_CLUSTER,WLBS_LOCAL_HOST, &reg_data);
  197. verify_return_value (_TEXT("ReadReg"), WLBS_INIT_ERROR, status);
  198. status = WlbsWriteReg(WLBS_LOCAL_CLUSTER,WLBS_LOCAL_HOST, &reg_data);
  199. verify_return_value (_TEXT("WriteReg"), WLBS_INIT_ERROR, status);
  200. status = WlbsCommitChanges(WLBS_LOCAL_CLUSTER,WLBS_LOCAL_HOST);
  201. verify_return_value (_TEXT("CommitChanges"), WLBS_INIT_ERROR, status);
  202. status = WlbsGetNumPortRules(&reg_data);
  203. verify_return_value (_TEXT("GetNumPortRules"), WLBS_INIT_ERROR, status);
  204. status = WlbsEnumPortRules(&reg_data, port_rules, &num);
  205. verify_return_value (_TEXT("EnumPortRules"), WLBS_INIT_ERROR, status);
  206. status = WlbsGetPortRule(&reg_data, 80, &port_rule);
  207. verify_return_value (_TEXT("GetPortRule"), WLBS_INIT_ERROR, status);
  208. status = WlbsAddPortRule(&reg_data, &port_rule);
  209. verify_return_value (_TEXT("AddPortRule"), WLBS_INIT_ERROR, status);
  210. status = WlbsDeletePortRule (&reg_data, 80);
  211. verify_return_value (_TEXT("DeletePortRule"), WLBS_INIT_ERROR, status);
  212. /* With an invalid product name, init returns REMOTE_ONLY
  213. * On subsequent calls, it will return the same value.
  214. * Hence this test has to be performed in isolation
  215. */
  216. if (init_test)
  217. {
  218. status = WlbsInit (_TEXT("JunkName"), WLBS_API_VER, NULL);
  219. verify_return_value2 (_TEXT("Init with junk product name"), WLBS_INIT_ERROR, WLBS_REMOTE_ONLY, status);
  220. return;
  221. }
  222. status = WlbsInit (_TEXT(WLBS_PRODUCT_NAME), WLBS_API_VER, NULL);
  223. verify_return_value3 (_TEXT("Init"), WLBS_PRESENT, WLBS_REMOTE_ONLY, WLBS_LOCAL_ONLY, status);
  224. status1 = WlbsInit (_TEXT(WLBS_PRODUCT_NAME), WLBS_API_VER, NULL);
  225. verify_return_value (_TEXT("Init Again"), status, status1);
  226. global_init = status;
  227. return;
  228. }
  229. /* This function brings a particular host to the converged state.
  230. * This is done by first suspending the host and then resuming
  231. * and starting it. Wait till the cluster converges and then return
  232. */
  233. BOOL GetHostToConvergedState (DWORD cluster, DWORD host)
  234. {
  235. DWORD status;
  236. /* suspend the host and then do a resume and start to get it to converged state */
  237. status = WlbsSuspend (cluster, host, NULL, NULL);
  238. if (!(status == WLBS_OK || status == WLBS_ALREADY || status == WLBS_STOPPED))
  239. return FALSE;
  240. status = WlbsResume (cluster, host, NULL, NULL);
  241. if (status != WLBS_OK)
  242. return FALSE;
  243. status = WlbsStart (cluster, host, NULL, NULL);
  244. if (status != WLBS_OK)
  245. return FALSE;
  246. Sleep(10000); /* Wait for 10 seconds till it converges */
  247. status = WlbsQuery (cluster, host, NULL, NULL, NULL, NULL);
  248. if (status == WLBS_CONVERGED || status == WLBS_DEFAULT)
  249. return TRUE;
  250. else
  251. return FALSE;
  252. }
  253. /* This function gets all the hosts on a given cluster to the converged state */
  254. BOOL GetClusterToConvergedState (DWORD cluster)
  255. {
  256. /* suspend the entire cluster
  257. * resume the entire cluster
  258. * start the entire cluster
  259. * wait for convergence
  260. * Query should return the number of active hosts
  261. */
  262. DWORD status;
  263. /* Set the timeout so that this process gets speeded up */
  264. if (cluster == WLBS_LOCAL_CLUSTER)
  265. WlbsTimeoutSet (WlbsGetLocalClusterAddress (), 2000);
  266. else
  267. WlbsTimeoutSet (cluster, 2000);
  268. status = WlbsSuspend (cluster, WLBS_ALL_HOSTS, NULL, NULL);
  269. status = WlbsResume (cluster, WLBS_ALL_HOSTS, NULL, NULL);
  270. status = WlbsStart (cluster, WLBS_ALL_HOSTS, NULL, NULL);
  271. Sleep (10000);
  272. status = WlbsQuery (cluster, WLBS_ALL_HOSTS, NULL, NULL, NULL, NULL);
  273. if (status == WLBS_BAD_PASSW)
  274. printf("Please ensure that the password on all the machines is the same\n");
  275. /* Restore it to the default value */
  276. if (cluster == WLBS_LOCAL_CLUSTER)
  277. WlbsTimeoutSet (WlbsGetLocalClusterAddress (), 0);
  278. else
  279. WlbsTimeoutSet (cluster, 0);
  280. if ( 1 <= status && status <= WLBS_MAX_HOSTS)
  281. return TRUE;
  282. else
  283. return FALSE;
  284. }
  285. /* This function goes through the response array and verifies that for each host that is converged,
  286. * the corresponding bit in the hostmap is set.
  287. * This function is useful only when the response array is from a converged cluster
  288. */
  289. BOOL verify_hostmap_response (PWLBS_RESPONSE response, DWORD num_response, DWORD host_map)
  290. {
  291. DWORD i,j;
  292. /* For each response, if the host is converged or is the default host, then it should
  293. * figure in the hostmap. Verify this.
  294. */
  295. /* This function should be invoked only when the response array is from a converged cluster.
  296. * or from a single host, when it is converged
  297. */
  298. for (i = 0; i < num_response; i++)
  299. {
  300. if (response [i] . status == WLBS_CONVERGED || response [i] . status == WLBS_DEFAULT)
  301. {
  302. if ( ! ( host_map & (1 << (response [i] . id - 1))) )
  303. return FALSE;
  304. }
  305. else /* That particular bit should not be set */
  306. {
  307. if ( host_map & (1 << (response [i] . id - 1)) )
  308. return FALSE;
  309. }
  310. }
  311. return TRUE;
  312. }
  313. /* Verify that all the responses show the same state. This is used in cluster-wide control tests.
  314. * If the cluster is reported to be suspended, then all the hosts should show their status
  315. * to be WLBS_SUSPENDED
  316. */
  317. void verify_response_status (PWLBS_RESPONSE response, DWORD num_host, DWORD expected_status)
  318. {
  319. DWORD i;
  320. TCHAR temp [40];
  321. for (i = 0 ; i < num_host; i++)
  322. {
  323. _stprintf (temp, _TEXT("Verifying response for host %d"), response [i] . id);
  324. verify_return_value2 ( temp, expected_status, WLBS_ALREADY, response [i] . status);
  325. }
  326. }
  327. /* This function opens a TCP connection to the cluster ip on the specified port.
  328. * This function is used to test Drainstop
  329. */
  330. SOCKET OpenConnection (DWORD cluster, DWORD port)
  331. {
  332. SOCKET sock = INVALID_SOCKET;
  333. SOCKADDR_IN caddr, saddr;
  334. INT ret;
  335. sock = socket (AF_INET, SOCK_STREAM, 0);
  336. if (sock == INVALID_SOCKET)
  337. return sock;
  338. caddr . sin_family = AF_INET;
  339. caddr . sin_port = htons (0);
  340. caddr . sin_addr . s_addr = htonl (INADDR_ANY);
  341. ret = bind (sock, (LPSOCKADDR) & caddr, sizeof (caddr));
  342. if (ret == SOCKET_ERROR)
  343. {
  344. closesocket (sock);
  345. return INVALID_SOCKET;
  346. }
  347. /* setup server's address */
  348. saddr . sin_family = AF_INET;
  349. saddr . sin_port = htons ((USHORT)port);
  350. saddr . sin_addr . s_addr = cluster;
  351. ret = connect (sock, (LPSOCKADDR) & saddr, sizeof (saddr));
  352. if (ret == SOCKET_ERROR)
  353. {
  354. closesocket (sock);
  355. return INVALID_SOCKET;
  356. }
  357. return sock;
  358. }
  359. /* This function performs the password testing. The same function can be used for single host
  360. * or cluster-wide testing.
  361. */
  362. void password_test (DWORD cluster, DWORD host, PTCHAR password)
  363. {
  364. DWORD status1;
  365. /* The input password is the correct password */
  366. _stprintf (status_buf, _TEXT("Password test for cluster %d host %d"), cluster, host);
  367. /* If the password is null, then return,since password testing cannot be performed. */
  368. if (password == NULL)
  369. return;
  370. /* If it is an empty string, then again the testing cannot be performed */
  371. if (_tcslen (password) == 0)
  372. return;
  373. WlbsPasswordSet(cluster, _TEXT("JunkPassword"));
  374. /* All commands should return bad passw */
  375. status1 = WlbsQuery (cluster, host, NULL, NULL, NULL, NULL);
  376. verify_return_value (_TEXT("Query"), WLBS_BAD_PASSW, status1);
  377. status1 = WlbsDrain (cluster, host, NULL, NULL, 80);
  378. verify_return_value (_TEXT("Drain"), WLBS_BAD_PASSW, status1);
  379. status1 = WlbsDisable (cluster, host, NULL, NULL, 80);
  380. verify_return_value (_TEXT("Disable"), WLBS_BAD_PASSW, status1);
  381. status1 = WlbsEnable (cluster, host, NULL, NULL, 80);
  382. verify_return_value (_TEXT("Enable"), WLBS_BAD_PASSW, status1);
  383. status1 = WlbsSuspend (cluster, host, NULL, NULL);
  384. verify_return_value (_TEXT("Suspend"), WLBS_BAD_PASSW, status1);
  385. status1 = WlbsResume (cluster, host, NULL, NULL);
  386. verify_return_value (_TEXT("Resume"), WLBS_BAD_PASSW, status1);
  387. status1 = WlbsStop (cluster, host, NULL, NULL);
  388. verify_return_value (_TEXT("Stop"), WLBS_BAD_PASSW, status1);
  389. status1 = WlbsDrainStop (cluster, host, NULL, NULL);
  390. verify_return_value (_TEXT("Drainstop"), WLBS_BAD_PASSW, status1);
  391. status1 = WlbsStart (cluster, host, NULL, NULL);
  392. verify_return_value (_TEXT("Start"), WLBS_BAD_PASSW, status1);
  393. WlbsPasswordSet (cluster, password); /* Reset the password for future tests */
  394. Sleep (10000); /* Wait till the cluster converges */
  395. return;
  396. }
  397. /* This function verifies the portset api.
  398. * It sets the port for a given cluster and makes a query on the host
  399. * The return value should match the expected value, which can be either
  400. * WLBS_TIMEOUT or some WINSOCK error in case of an invalid port
  401. * or the status of the host if the port is a valid one
  402. */
  403. void verify_port (DWORD cluster, DWORD host, DWORD port, DWORD expected)
  404. {
  405. DWORD status;
  406. TCHAR temp [BUF_SIZE];
  407. WlbsPortSet (cluster, (WORD)port);
  408. status = WlbsQuery (cluster, host, NULL, NULL, NULL, NULL);
  409. _stprintf (temp, _TEXT("Verifying port set for port %d"), port);
  410. verify_return_value (temp, expected, status);
  411. return;
  412. }
  413. /* Get the cluster/host to drainstopped state by establishing a connection and then drainstopping it */
  414. BOOL GetDrainstopState (DWORD cluster, DWORD host, SOCKET * sock, DWORD port)
  415. {
  416. DWORD status;
  417. BOOL connected = FALSE;
  418. /* First, get the cluster or host to the converged state */
  419. if (host == WLBS_ALL_HOSTS)
  420. {
  421. if (!GetClusterToConvergedState (cluster))
  422. return FALSE;
  423. }
  424. else if (!GetHostToConvergedState (cluster, host))
  425. return FALSE;
  426. /* Open a TCP connection on the specified port */
  427. *sock = OpenConnection (cluster, port);
  428. if (*sock == INVALID_SOCKET)
  429. {
  430. add_error(_TEXT("Unable to open a connection to the cluster"));
  431. return FALSE;
  432. }
  433. /* DrainStop the host and then query it. If the status is not draining, something is wrong */
  434. status = WlbsDrainStop (cluster, host, NULL, NULL);
  435. verify_return_value (_TEXT("Drainstop with active connection"), WLBS_OK, status);
  436. Sleep (10000); /* Wait for the cluster to converge */
  437. status = WlbsQuery (cluster, host, NULL, NULL, NULL, NULL);
  438. verify_return_value (_TEXT("Query after Drainstop with active connection"), WLBS_DRAINING, status);
  439. if (status != WLBS_DRAINING)
  440. return FALSE;
  441. return TRUE;
  442. }
  443. /* This function deals with the parameter testing of the apis on a single host */
  444. void single_host_parameter_test (DWORD cluster, DWORD host)
  445. {
  446. DWORD status1, status2;
  447. DWORD host_map1, host_map2;
  448. DWORD num_host1, num_host2;
  449. WLBS_RESPONSE response1, response2, *response;
  450. DWORD cl_ip, host_ip, host_id;
  451. TCHAR temp1[40], temp2[40];
  452. DWORD temp;
  453. temp = 40;
  454. if (cluster == WLBS_LOCAL_CLUSTER)
  455. _stprintf (temp1, _TEXT("local cluster"));
  456. else
  457. WlbsAddressToString (cluster, temp1, &temp);
  458. temp = 40;
  459. if (cluster == WLBS_LOCAL_HOST)
  460. _stprintf (temp2, _TEXT("local host"));
  461. else
  462. WlbsAddressToString (host, temp2, &temp);
  463. _stprintf (status_buf, _TEXT("Single Host Parameter Test for cluster:%s host:%s"), temp1, temp2);
  464. /* First verify that the response structure and the returned value match */
  465. num_host1 = 1;
  466. host_map1 = 0;
  467. status1 = WlbsQuery (cluster, host, &response1, &num_host1, &host_map1, NULL);
  468. if ( ! verify_hostmap_response (&response1, num_host1, host_map1) )
  469. {
  470. _stprintf (tbuf, _TEXT("Querying cluster %d, host %d, returned mismatched hostmap and response"),
  471. cluster, host);
  472. add_error (tbuf);
  473. }
  474. if (cluster == WLBS_LOCAL_CLUSTER && host == WLBS_LOCAL_HOST)
  475. {
  476. /* On a local host, there can be additional tests. Query the host remotely and verify that
  477. * both the local and remote queries return the same status, the same id and the same hostmap
  478. */
  479. cl_ip = WlbsGetLocalClusterAddress ();
  480. host_ip = WlbsGetDedicatedAddress ();
  481. host_id = response1 . id;
  482. /* Query remotely first using the host ip */
  483. num_host2 = 1;
  484. host_map2 = 0;
  485. status2 = WlbsQuery (cl_ip, host_ip, &response2, &num_host2, &host_map2, NULL);
  486. verify_return_value (_TEXT("Comparing Local and Remote Query"), status1, status2);
  487. if (host_map1 != host_map2)
  488. {
  489. _stprintf (tbuf, _TEXT("Local host query and remote host query returned different hostmaps %d %d\n"),
  490. host_map1, host_map2);
  491. add_error (tbuf);
  492. }
  493. if (response1 . status != response2 . status)
  494. {
  495. _stprintf (tbuf, _TEXT("Local host query and remote query returned different statuses in response"));
  496. add_error (tbuf);
  497. }
  498. if (response1 . id != response2 . id)
  499. {
  500. _stprintf (tbuf, _TEXT("Local host query and remote query returned different ids in response"));
  501. add_error (tbuf);
  502. }
  503. if (response2 . address != host_ip )
  504. {
  505. _stprintf (tbuf, _TEXT("Local host query and remote query returned different IP Addresses"));
  506. add_error (tbuf);
  507. }
  508. /* Now query the host remotely using the host_id as a parameter and verify the returns */
  509. num_host2 = 1;
  510. status2 = WlbsQuery (WLBS_LOCAL_CLUSTER, host_id, &response2, &num_host2, &host_map2, NULL);
  511. verify_return_value (_TEXT("Querying remotely with host id"), status1, status2);
  512. if (host_map1 != host_map2)
  513. {
  514. _stprintf (tbuf, _TEXT("Local host query and remote host query with id returned different hostmaps %d %d\n"),
  515. host_map1, host_map2);
  516. add_error (tbuf);
  517. }
  518. if (response1 . status != response2 . status)
  519. {
  520. _stprintf (tbuf, _TEXT("Local host query and remote query with id returned different statuses in response"));
  521. add_error (tbuf);
  522. }
  523. if (response1 . id != response2 . id)
  524. {
  525. _stprintf (tbuf, _TEXT("Local host query and remote query with id returned different ids in response"));
  526. add_error (tbuf);
  527. }
  528. if (response2 . address != host_ip )
  529. {
  530. _stprintf (tbuf, _TEXT("Local host query and remote query returned different IP Addresses"));
  531. add_error (tbuf);
  532. }
  533. }
  534. status2 = WlbsQuery (cluster, host, NULL, NULL, NULL, NULL);
  535. verify_return_value (_TEXT("Querying with all parameters NULL"), status1, status2);
  536. num_host2 = 0;
  537. status2 = WlbsQuery (cluster, host, NULL, &num_host2, NULL, NULL);
  538. verify_return_value (_TEXT("Querying with num_host parameter = 0 and host_map = NULL"), status1, status2);
  539. status2 = WlbsQuery (1234, 0, NULL, NULL, NULL, NULL);
  540. verify_return_value (_TEXT("Querying non-existent cluster 1234"), WLBS_TIMEOUT, status2);
  541. status2 = WlbsQuery (cluster, 33, NULL, NULL, NULL, NULL);
  542. verify_return_value (_TEXT("Querying non-existent host 33"), WLBS_TIMEOUT, status2);
  543. /* Verify the portset command, only for remote queries
  544. * since the remote port is not used for local queries
  545. */
  546. if (! ( cluster == WLBS_LOCAL_CLUSTER && host == WLBS_LOCAL_HOST ) )
  547. {
  548. verify_port (cluster, host, 3000, WLBS_TIMEOUT);
  549. verify_port (cluster, host, 0, status1);
  550. verify_port (cluster, host, CVY_DEF_RCT_PORT, status1);
  551. }
  552. return;
  553. }
  554. /* This function goes through the state changes of for single host operations */
  555. void single_host_state_changes (DWORD cluster, DWORD host)
  556. {
  557. DWORD status1, status2;
  558. WLBS_RESPONSE response [WLBS_MAX_HOSTS];
  559. DWORD num_host1, num_host2;
  560. DWORD host_map1, host_map2;
  561. SOCKET sock = INVALID_SOCKET;
  562. DWORD temp_address;
  563. TCHAR temp1[40], temp2[40];
  564. DWORD temp;
  565. /* Assume that the host is in the converged state now */
  566. temp = 40;
  567. if (cluster == WLBS_LOCAL_CLUSTER)
  568. _stprintf (temp1, _TEXT("local cluster"));
  569. else
  570. WlbsAddressToString (cluster, temp1, &temp);
  571. temp = 40;
  572. if (cluster == WLBS_LOCAL_HOST)
  573. _stprintf (temp2, _TEXT("local host"));
  574. else
  575. WlbsAddressToString (host, temp2, &temp);
  576. _stprintf (status_buf, _TEXT("Single Host State Changes cluster %s host %s"), temp1, temp2);
  577. /* Call each of the apis and verify that the return values are consistent with the current
  578. * state of the host. For example, Disable would return different values depending on whether
  579. * the host was suspended or converged ....
  580. */
  581. num_host1 = 1;
  582. status1 = WlbsQuery (cluster, host, response, &num_host1, &host_map1, NULL);
  583. verify_return_value2 (_TEXT("Query"), WLBS_CONVERGED, WLBS_DEFAULT, status1);
  584. /* The following tests assume that there is a port rule for port number 80.
  585. * Otherwise the return code will be WLBS_NOT_FOUND.
  586. */
  587. num_host1 = 1;
  588. status2 = WlbsDisable (cluster, host, response, &num_host1, 80);
  589. verify_return_value (_TEXT("Disable 80"), WLBS_OK, status2);
  590. if (status2 == WLBS_NOT_FOUND)
  591. printf("Please ensure that a port rule exists for port number 80.\n");
  592. num_host1 = 1;
  593. status2 = WlbsDisable (cluster, host, response, &num_host1, 80);
  594. verify_return_value (_TEXT("Disable Again 80"), WLBS_ALREADY, status2);
  595. /* If a port rule is disabled, drain returns already */
  596. num_host1 = 1;
  597. status2 = WlbsDrain (cluster, host, response, &num_host1, 80);
  598. verify_return_value (_TEXT("Drain 80"), WLBS_ALREADY, status2);
  599. num_host1 = 1;
  600. status2 = WlbsEnable (cluster, host, response, &num_host1, 80);
  601. verify_return_value (_TEXT("Enable 80"), WLBS_OK, status2);
  602. num_host1 = 1;
  603. status2 = WlbsEnable (cluster, host, response, &num_host1, 80);
  604. verify_return_value (_TEXT("Enable Again 80"), WLBS_ALREADY, status2);
  605. num_host1 = 1;
  606. status2 = WlbsDisable (cluster, host, response, &num_host1, WLBS_ALL_PORTS);
  607. verify_return_value (_TEXT("Disable ALL"), WLBS_OK, status2);
  608. num_host1 = 1;
  609. status2 = WlbsDisable (cluster, host, response, &num_host1, WLBS_ALL_PORTS);
  610. verify_return_value (_TEXT("Disable Again ALL"), WLBS_ALREADY, status2);
  611. num_host1 = 1;
  612. status2 = WlbsDrain (cluster, host, response, &num_host1, WLBS_ALL_PORTS);
  613. verify_return_value (_TEXT("Drain ALL"), WLBS_ALREADY, status2);
  614. num_host1 = 1;
  615. status2 = WlbsEnable (cluster, host, response, &num_host1, WLBS_ALL_PORTS);
  616. verify_return_value (_TEXT("Enable ALL"), WLBS_OK, status2);
  617. num_host1 = 1;
  618. status2 = WlbsEnable (cluster, host, response, &num_host1, WLBS_ALL_PORTS);
  619. verify_return_value (_TEXT("Enable Again ALL"), WLBS_ALREADY, status2);
  620. num_host1 = 1;
  621. status2 = WlbsSuspend (cluster, host, response, &num_host1);
  622. verify_return_value (_TEXT("Suspend"), WLBS_STOPPED, status2);
  623. num_host1 = 1;
  624. status2 = WlbsQuery (cluster, host, response, &num_host1, &host_map1, NULL);
  625. verify_return_value (_TEXT("Query after Suspend"), WLBS_SUSPENDED, status2);
  626. num_host1 = 1;
  627. status2 = WlbsDrain (cluster, host, response, &num_host1, 80);
  628. verify_return_value (_TEXT("Drain after Suspend"), WLBS_SUSPENDED, status2);
  629. num_host1 = 1;
  630. status2 = WlbsDisable (cluster, host, response, &num_host1, 80);
  631. verify_return_value (_TEXT("Disable after Suspend"), WLBS_SUSPENDED, status2);
  632. num_host1 = 1;
  633. status2 = WlbsEnable (cluster, host, response, &num_host1, 80);
  634. verify_return_value (_TEXT("Enable after Suspend"), WLBS_SUSPENDED, status2);
  635. num_host1 = 1;
  636. status2 = WlbsSuspend (cluster, host, response, &num_host1);
  637. verify_return_value (_TEXT("Suspend Again"), WLBS_ALREADY, status2);
  638. num_host1 = 1;
  639. status2 = WlbsStop (cluster, host, response, &num_host1);
  640. verify_return_value (_TEXT("Stop after Suspend"), WLBS_SUSPENDED, status2);
  641. num_host1 = 1;
  642. status2 = WlbsStart (cluster, host, response, &num_host1);
  643. verify_return_value (_TEXT("Start after Suspend"), WLBS_SUSPENDED, status2);
  644. num_host1 = 1;
  645. status2 = WlbsDrainStop (cluster, host, response, &num_host1);
  646. verify_return_value (_TEXT("DrainStop after Suspend"), WLBS_SUSPENDED, status2);
  647. num_host1 = 1;
  648. status2 = WlbsResume (cluster, host, response, &num_host1);
  649. verify_return_value (_TEXT("Resume after Suspend"), WLBS_OK, status2);
  650. num_host1 = 1;
  651. status2 = WlbsQuery (cluster, host, response, &num_host1, &host_map1, NULL);
  652. verify_return_value (_TEXT("Query after Resume"), WLBS_STOPPED, status2);
  653. num_host1 = 1;
  654. status2 = WlbsDrain (cluster, host, response, &num_host1, 80);
  655. verify_return_value (_TEXT("Drain when Stopped"), WLBS_STOPPED, status2);
  656. num_host1 = 1;
  657. status2 = WlbsDisable (cluster, host, response, &num_host1, 80);
  658. verify_return_value (_TEXT("Disable when Stopped"), WLBS_STOPPED, status2);
  659. num_host1 = 1;
  660. status2 = WlbsEnable (cluster, host, response, &num_host1, 80);
  661. verify_return_value (_TEXT("Enable when Stopped"), WLBS_STOPPED, status2);
  662. num_host1 = 1;
  663. status2 = WlbsResume (cluster, host, response, &num_host1);
  664. verify_return_value (_TEXT("Resume when Stopped"), WLBS_ALREADY, status2);
  665. num_host1 = 1;
  666. status2 = WlbsStop (cluster, host, response, &num_host1);
  667. verify_return_value (_TEXT("Stop when Stopped"), WLBS_ALREADY, status2);
  668. num_host1 = 1;
  669. status2 = WlbsDrainStop (cluster, host, response, &num_host1);
  670. verify_return_value (_TEXT("DrainStop when Stopped"), WLBS_STOPPED, status2);
  671. num_host1 = 1;
  672. status2 = WlbsSuspend (cluster, host, response, &num_host1);
  673. verify_return_value (_TEXT("Suspend when Stopped"), WLBS_OK, status2);
  674. num_host1 = 1;
  675. status2 = WlbsQuery (cluster, host, response, &num_host1, &host_map1, NULL);
  676. verify_return_value (_TEXT("Query when Suspended"), WLBS_SUSPENDED, status2);
  677. num_host1 = 1;
  678. status2 = WlbsResume (cluster, host, response, &num_host1);
  679. verify_return_value (_TEXT("Resume when Suspended"), WLBS_OK, status2);
  680. num_host1 = 1;
  681. status2 = WlbsQuery (cluster, host, response, &num_host1, &host_map1, NULL);
  682. verify_return_value (_TEXT("Query when Stopped"), WLBS_STOPPED, status2);
  683. num_host1 = 1;
  684. status2 = WlbsStart (cluster, host, response, &num_host1);
  685. verify_return_value (_TEXT("Start when Stopped"), WLBS_OK, status2);
  686. num_host1 = 1;
  687. status2 = WlbsQuery (cluster, host, response, &num_host1, &host_map1, NULL);
  688. verify_return_value3 (_TEXT("Query after Starting"), WLBS_CONVERGING, WLBS_CONVERGED, WLBS_DEFAULT, status2);
  689. Sleep (10000); /* Wait for the cluster to converge */
  690. /* Modify the code to keep polling the host till it is converged ###### */
  691. num_host1 = 1;
  692. status2 = WlbsQuery (cluster, host, response, &num_host1, &host_map1, NULL);
  693. verify_return_value2 (_TEXT("Query after Waiting for Convergence"), WLBS_CONVERGED, WLBS_DEFAULT, status2);
  694. num_host1 = 1;
  695. status2 = WlbsStart (cluster, host, response, &num_host1);
  696. verify_return_value (_TEXT("Start when Converged"), WLBS_ALREADY, status2);
  697. num_host1 = 1;
  698. status2 = WlbsResume (cluster, host, response, &num_host1);
  699. verify_return_value (_TEXT("Resume when Converged"), WLBS_ALREADY, status2);
  700. num_host1 = 1;
  701. status2 = WlbsStop (cluster, host, response, &num_host1);
  702. verify_return_value (_TEXT("Stop when Converged"), WLBS_OK, status2);
  703. num_host1 = 1;
  704. status2 = WlbsQuery (cluster, host, response, &num_host1, &host_map1, NULL);
  705. verify_return_value (_TEXT("Query when Stopped"), WLBS_STOPPED, status2);
  706. num_host1 = 1;
  707. status2 = WlbsStart (cluster, host, response, &num_host1);
  708. verify_return_value (_TEXT("Start when Stopped"), WLBS_OK, status2);
  709. num_host1 = 1;
  710. status2 = WlbsQuery (cluster, host, response, &num_host1, &host_map1, NULL);
  711. verify_return_value3 (_TEXT("Query after Starting"), WLBS_CONVERGING, WLBS_CONVERGED, WLBS_DEFAULT, status2);
  712. Sleep (10000); /* Wait for the cluster to converge */
  713. num_host1 = 1;
  714. status2 = WlbsQuery (cluster, host, response, &num_host1, &host_map1, NULL);
  715. verify_return_value2 (_TEXT("Query after Waiting for Convergence"), WLBS_CONVERGED, WLBS_DEFAULT, status2);
  716. /* DrainStop is to be tested only on a remote host */
  717. if ((cluster == WLBS_LOCAL_CLUSTER || cluster == WlbsGetLocalClusterAddress()) &&
  718. (host == WLBS_LOCAL_HOST || host == WlbsGetDedicatedAddress()) )
  719. return;
  720. /* To test drainstop on a particular host, stop the entire cluster. Then start only this particular host.
  721. * Open a connection to it. Then do a drainstop. Query should return draining. Then close the connection.
  722. * Query again. The return value should be stopped. This should be done only on a remote host. This test
  723. * would fail on a local host, since the connection setup does not go through the wlbs driver, but gets
  724. * routed up the stack.
  725. */
  726. num_host1 = WLBS_MAX_HOSTS;
  727. status2 = WlbsStop (cluster, WLBS_ALL_HOSTS, response, &num_host1);
  728. verify_return_value (_TEXT("Cluster-wide stop to test drainstop"), WLBS_OK, status2);
  729. num_host1 = 1;
  730. status2 = WlbsStart (cluster, host, response, &num_host1);
  731. verify_return_value (_TEXT("Start on host after Cluster-wide stop"), WLBS_OK, status2);
  732. Sleep (10000); /* Wait till the host converges */
  733. num_host1 = 1;
  734. status2 = WlbsQuery (cluster, host, response, &num_host1, &host_map1, NULL);
  735. verify_return_value2 (_TEXT("Query after Waiting for Convergence"), WLBS_CONVERGED, WLBS_DEFAULT, status2);
  736. if (!GetDrainstopState (cluster, host, &sock, 80))
  737. return;
  738. num_host1 = 1;
  739. status2 = WlbsDisable (cluster, host, response, &num_host1, 80);
  740. verify_return_value (_TEXT("Disable after DrainStop with active connection"), WLBS_ALREADY, status2);
  741. num_host1 = 1;
  742. status2 = WlbsDrain (cluster, host, response, &num_host1, 80);
  743. verify_return_value (_TEXT("Drain after DrainStop with active connection"), WLBS_ALREADY, status2);
  744. num_host1 = 1;
  745. status2 = WlbsEnable (cluster, host, response, &num_host1, 80);
  746. verify_return_value (_TEXT("Enable after DrainStop with active connection"), WLBS_OK, status2);
  747. num_host1 = 1;
  748. status2 = WlbsEnable (cluster, host, response, &num_host1, 80);
  749. verify_return_value (_TEXT("Enable again after DrainStop with active connection"), WLBS_ALREADY, status2);
  750. num_host1 = 1;
  751. status2 = WlbsResume (cluster, host, response, &num_host1);
  752. verify_return_value (_TEXT("Resume after DrainStop with active connection"), WLBS_ALREADY, status2);
  753. num_host1 = 1;
  754. status2 = WlbsStop (cluster, host, response, &num_host1);
  755. verify_return_value (_TEXT("Stop after DrainStop with active connection"), WLBS_DRAIN_STOP, status2);
  756. closesocket (sock);
  757. /* Start the host and open a connection again */
  758. if (!GetDrainstopState (cluster, host, &sock, 80))
  759. return;
  760. num_host1 = 1;
  761. status2 = WlbsStart (cluster, host, response, &num_host1);
  762. verify_return_value (_TEXT("Start after DrainStop with active connection"), WLBS_DRAIN_STOP, status2);
  763. closesocket (sock);
  764. if (!GetDrainstopState (cluster, host, &sock, 80))
  765. return;
  766. num_host1 = 1;
  767. status2 = WlbsSuspend (cluster, host, response, &num_host1);
  768. verify_return_value (_TEXT("Suspend after DrainStop with active connection"), WLBS_DRAIN_STOP, status2);
  769. closesocket (sock); /* close the connection */
  770. if (!GetDrainstopState (cluster, host, &sock, 80))
  771. return;
  772. num_host1 = 1;
  773. status2 = WlbsQuery (cluster, host, response, &num_host1, &host_map1, NULL);
  774. verify_return_value (_TEXT("Query after DrainStop with active connection"), WLBS_DRAINING, status2);
  775. closesocket (sock);
  776. Sleep (10000); /* Wait for it to figure out that all the connections have been terminated */
  777. num_host1 = 1;
  778. status2 = WlbsQuery (cluster, host, response, &num_host1, &host_map1, NULL);
  779. verify_return_value (_TEXT("Query after DrainStop with closed connection"), WLBS_STOPPED, status2);
  780. /* issue a cluster-wide start to bring back all the hosts to the converged state.*/
  781. num_host1 = WLBS_MAX_HOSTS;
  782. status2 = WlbsStart (cluster, WLBS_ALL_HOSTS, response, &num_host1);
  783. verify_return_value (_TEXT("Cluster-wide start to restore original state"), WLBS_OK, status2);
  784. Sleep (10000); /* Wait for convergence */
  785. return;
  786. }
  787. /* This function tests the single host control operations.
  788. * It performs both the parameter tests as well as the
  789. * state change tests.
  790. */
  791. void check_single_host_operations ( )
  792. {
  793. DWORD local_cluster_ip = 0;
  794. DWORD local_dedicated_ip = 0;
  795. DWORD remote_cluster_ip = 0;
  796. DWORD remote_host = 0;
  797. if (global_init == WLBS_INIT_ERROR)
  798. {
  799. add_error(_TEXT("Cannot perform Control test due to Init Error"));
  800. return;
  801. }
  802. if (local_test)
  803. {
  804. do {
  805. if (global_init == WLBS_PRESENT)
  806. {
  807. WLBS_REG_PARAMS reg_data;
  808. DWORD status;
  809. local_cluster_ip = WlbsGetLocalClusterAddress();
  810. local_dedicated_ip = WlbsGetDedicatedAddress();
  811. status = WlbsReadReg (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST, & reg_data);
  812. WlbsCodeSet (local_cluster_ip, reg_data . i_rct_password);
  813. /* test the local call path */
  814. if ( ! GetHostToConvergedState(WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST))
  815. {
  816. printf("Unable to get the local host to converged state\n");
  817. break;
  818. }
  819. single_host_parameter_test (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST);
  820. single_host_state_changes (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST);
  821. /* test the remote call path */
  822. WlbsCodeSet (local_cluster_ip, reg_data . i_rct_password);
  823. single_host_parameter_test (local_cluster_ip, local_dedicated_ip);
  824. single_host_state_changes (local_cluster_ip, local_dedicated_ip);
  825. }
  826. } while (FALSE);
  827. }
  828. if ( ! remote_test)
  829. return;
  830. if (global_init == WLBS_PRESENT || global_init == WLBS_REMOTE_ONLY)
  831. {
  832. /* test a remote host on a remote cluster */
  833. if (remote_cl_ip == 0)
  834. {
  835. printf("Remote cluster address is invalid, so Control operations on a remote host are not tested\n");
  836. return;
  837. }
  838. if (remote_host_ip == 0)
  839. {
  840. printf("Remote host address is invalid, so Control operations on a remote host are not tested\n");
  841. return;
  842. }
  843. /* Set the password for the remote host and set it so that the operations can be performed */
  844. WlbsPasswordSet (remote_cl_ip, remote_password);
  845. WlbsTimeoutSet (remote_cl_ip, timeout);
  846. if ( ! GetHostToConvergedState(remote_cl_ip, remote_host_ip) )
  847. {
  848. printf("Unable to get the remote host to converged state. Not performing state change tests");
  849. return;
  850. }
  851. single_host_state_changes (remote_cl_ip, remote_host_ip);
  852. }
  853. else
  854. printf("Unable to perform the remote tests\n");
  855. return;
  856. }
  857. /* This function verifies the parameter testing for cluster-wide queries. It checks the response array
  858. * verifies it with the hostmap
  859. */
  860. void cluster_parameter_test (DWORD cluster)
  861. {
  862. DWORD status1, status2;
  863. DWORD host_map1, host_map2, temp_host_map;
  864. DWORD num_host1, num_host2;
  865. WLBS_RESPONSE response1, response2 [WLBS_MAX_HOSTS];
  866. PWLBS_RESPONSE response = NULL;
  867. DWORD stopped_host_id = 0;
  868. DWORD i;
  869. _stprintf (status_buf, _TEXT("Cluster-wide parameter testing for cluster %d"), cluster);
  870. /* Query with all parameters set to null should return the number of active hosts */
  871. status1 = WlbsQuery (cluster, WLBS_ALL_HOSTS, NULL, NULL, NULL, NULL);
  872. /* Query with num_hosts set to 0. On return num_hosts should be >= status1 */
  873. num_host1 = 0;
  874. status2 = WlbsQuery (cluster, WLBS_ALL_HOSTS, NULL, &num_host1, &host_map1, NULL);
  875. if (num_host1 < status1)
  876. {
  877. _stprintf (tbuf, _TEXT("Cluster-wide query returned %d active and %d total hosts"), status1, num_host1);
  878. add_error (tbuf);
  879. return;
  880. }
  881. /* Response array = #hosts + 1. Check that the boundaries are not overwritten. */
  882. response = (PWLBS_RESPONSE) malloc (sizeof (WLBS_RESPONSE) * (num_host1 + 1));
  883. memset (response, 0, (sizeof (WLBS_RESPONSE) * (num_host1 + 1)));
  884. memset (&response1, 0, sizeof (WLBS_RESPONSE));
  885. num_host2 = num_host1 - 1;
  886. status2 = WlbsQuery (cluster, WLBS_ALL_HOSTS, &response [1], &num_host2, &host_map2, NULL);
  887. if (memcmp (&response1, &response[0], sizeof (WLBS_RESPONSE)) ||
  888. memcmp (&response1, &response[num_host1], sizeof (WLBS_RESPONSE)) )
  889. {
  890. add_error(_TEXT("Response Array boundaries are over-written"));
  891. }
  892. free (response);
  893. response = NULL;
  894. /* Query again with the full response buffer */
  895. /* Verify that the hostmap and response array are in sync */
  896. num_host1 = WLBS_MAX_HOSTS;
  897. status2 = WlbsQuery (cluster, WLBS_ALL_HOSTS, response2, &num_host1, &host_map1, NULL);
  898. if (! verify_hostmap_response (response2, num_host1, host_map1) )
  899. add_error (_TEXT("Hostmap and Response do not match for the cluster wide query"));
  900. /* The following test is to verify the correctness of the hostmap parameter
  901. * Save the host_map returned in the previous query.
  902. * Stop a converged host.
  903. * Query again and get the new host_map.
  904. * */
  905. for (i = 0 ; i < num_host1; i++)
  906. {
  907. if (response2 [i] . status == WLBS_CONVERGED || response2 [i] . status == WLBS_DEFAULT)
  908. {
  909. stopped_host_id = response2 [i] . id;
  910. break;
  911. }
  912. }
  913. status1 = WlbsStop (cluster, stopped_host_id, NULL, NULL);
  914. Sleep (10000); /* Wait for the cluster to converge */
  915. /* Query the cluster again */
  916. num_host1 = WLBS_MAX_HOSTS;
  917. status1 = WlbsQuery (cluster, WLBS_ALL_HOSTS, response2, &num_host1, &host_map1, NULL);
  918. if (status2 == 1) /* This is to take care of single host clusters */
  919. verify_return_value (_TEXT("Querying cluster after stopping 1 host"), WLBS_STOPPED, status1);
  920. else
  921. verify_return_value (_TEXT("Querying cluster after stopping 1 host"), status2 - 1, status1);
  922. if (status2 > 1) /* The following verification can be done only if there are 2 or more hosts in the cluster */
  923. {
  924. /* Verify that the corresponding bit in the host_map is not set */
  925. if (! verify_hostmap_response (response2, num_host1, host_map1) )
  926. add_error (_TEXT("Hostmap and Response do not match for the cluster wide query"));
  927. if (host_map1 & (1 << (stopped_host_id - 1)) )
  928. {
  929. _stprintf (tbuf, _TEXT("Stopping host %d did not change the host_map"), stopped_host_id);
  930. add_error (tbuf);
  931. }
  932. }
  933. /* start the host again */
  934. status1 = WlbsStart (cluster, stopped_host_id, NULL, NULL);
  935. /* wait for it to converge */
  936. Sleep (10000);
  937. status1 = WlbsQuery (cluster, WLBS_ALL_HOSTS, NULL, NULL, NULL, NULL);
  938. if (! (status1 >= 1 && status1 <= WLBS_MAX_HOSTS) )
  939. printf("Unable to get the cluster to the converged state after Cluster parameter testing\n");
  940. /* Test portset */
  941. verify_port (cluster, WLBS_ALL_HOSTS, 3000, WLBS_TIMEOUT);
  942. verify_port (cluster, WLBS_ALL_HOSTS, 0, status1);
  943. verify_port (cluster, WLBS_ALL_HOSTS, CVY_DEF_RCT_PORT, status1);
  944. return;
  945. }
  946. void verify_timeout (DWORD cluster, DWORD timeout)
  947. {
  948. DWORD time1, time2, time_diff;
  949. DWORD status;
  950. WlbsTimeoutSet (cluster, timeout);
  951. if (timeout == 0) /* set it to the default value */
  952. timeout = IOCTL_REMOTE_RECV_DELAY * IOCTL_REMOTE_SEND_RETRIES * IOCTL_REMOTE_RECV_RETRIES;
  953. time1 = GetTickCount ();
  954. status = WlbsQuery (cluster, WLBS_ALL_HOSTS, NULL, NULL, NULL, NULL);
  955. time2 = GetTickCount ();
  956. time_diff = time2 - time1;
  957. if (abs (time_diff - timeout) > 1000) /* Keep a margin of 1 sec */
  958. {
  959. _stprintf ( tbuf, _TEXT("Expected timeout %d, Actual timeout %d"), timeout, time_diff);
  960. add_error (tbuf);
  961. }
  962. return;
  963. }
  964. /* This function takes the entire cluster through the different state changes.
  965. * Some special cases are when one particular host is suspended
  966. * or when one particular host is in the drainstop state.
  967. * In such cases, WLBS_SUSPENDED or WLBS_DRAINING or WLBS_DRAIN_STOP are returned.
  968. * These return values are also verified.
  969. * After these special cases, the entire cluster is taken through the state changes.
  970. * In these tests, the response array is checked to verify that the statuses of each
  971. * host is in synch with the value returned by the control operation.
  972. */
  973. void cluster_state_changes (DWORD cluster)
  974. {
  975. DWORD status1, status2;
  976. WLBS_REG_PARAMS reg_data;
  977. BOOL password_flag = TRUE;
  978. WLBS_RESPONSE response [WLBS_MAX_HOSTS];
  979. DWORD num_host, host_map;
  980. DWORD suspended_host_id;
  981. DWORD temp_address;
  982. SOCKET sock = INVALID_SOCKET;
  983. _stprintf (status_buf, _TEXT("Checking cluster state changes for cluster %d"), cluster);
  984. /* Password check on the local cluster only */
  985. if (cluster == WLBS_LOCAL_CLUSTER)
  986. {
  987. DWORD password;
  988. DWORD cluster = WlbsGetLocalClusterAddress ();
  989. status1 = WlbsReadReg(WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST, & reg_data);
  990. password = reg_data . i_rct_password;
  991. status1 = WlbsSetRemotePassword (&reg_data, _TEXT("NewPassword"));
  992. status1 = WlbsWriteReg (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST, & reg_data);
  993. status1 = WlbsCommitChanges (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST);
  994. Sleep (10000);
  995. if (status1 != WLBS_OK)
  996. {
  997. password_flag = FALSE;
  998. add_error (_TEXT("Unable to change the password on the local machine."));
  999. }
  1000. if (password_flag)
  1001. password_test (WLBS_LOCAL_CLUSTER, WLBS_ALL_HOSTS, _TEXT("NewPassword"));
  1002. status1 = WlbsReadReg(WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST, & reg_data);
  1003. reg_data . i_rct_password = password;
  1004. status1 = WlbsWriteReg (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST, & reg_data);
  1005. status1 = WlbsCommitChanges (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST);
  1006. WlbsCodeSet (cluster, password);
  1007. Sleep (10000); /* Wait till the cluster converges */
  1008. }
  1009. /* Password check on the remote cluster by getting the password beforehand */
  1010. else
  1011. {
  1012. password_test (cluster, WLBS_ALL_HOSTS, remote_password);
  1013. /* Reset the password to the original state */
  1014. WlbsPasswordSet (cluster, remote_password);
  1015. }
  1016. /* Bring any one host to the suspended state. On every command, the response should be WLBS_SUSPENDED */
  1017. _stprintf (status_buf, _TEXT("Cluster-wide commands with one suspended host"));
  1018. num_host = WLBS_MAX_HOSTS;
  1019. status1 = WlbsQuery (cluster, WLBS_ALL_HOSTS, response, &num_host, &host_map, NULL);
  1020. suspended_host_id = response [0] . id;
  1021. status1 = WlbsSuspend (cluster, suspended_host_id, NULL, NULL);
  1022. Sleep (10000); /* Wait for the cluster to converge. */
  1023. num_host = WLBS_MAX_HOSTS;
  1024. status1 = WlbsStop (cluster, WLBS_ALL_HOSTS, response, &num_host);
  1025. verify_return_value (_TEXT("Stop after suspending 1 host"), WLBS_SUSPENDED, status1);
  1026. num_host = WLBS_MAX_HOSTS;
  1027. status1 = WlbsDrainStop (cluster, WLBS_ALL_HOSTS, response, &num_host);
  1028. verify_return_value (_TEXT("Stop after suspending 1 host"), WLBS_SUSPENDED, status1);
  1029. num_host = WLBS_MAX_HOSTS;
  1030. status1 = WlbsStart (cluster, WLBS_ALL_HOSTS, response, &num_host);
  1031. verify_return_value (_TEXT("Start after suspending 1 host"), WLBS_SUSPENDED, status1);
  1032. num_host = WLBS_MAX_HOSTS;
  1033. status1 = WlbsDrain (cluster, WLBS_ALL_HOSTS, response, &num_host, 80);
  1034. verify_return_value (_TEXT("Drain after suspending 1 host"), WLBS_SUSPENDED, status1);
  1035. num_host = WLBS_MAX_HOSTS;
  1036. status1 = WlbsDisable (cluster, WLBS_ALL_HOSTS, response, &num_host, 80);
  1037. verify_return_value (_TEXT("Disable after suspending 1 host"), WLBS_SUSPENDED, status1);
  1038. num_host = WLBS_MAX_HOSTS;
  1039. status1 = WlbsEnable (cluster, WLBS_ALL_HOSTS, response, &num_host, 80);
  1040. verify_return_value (_TEXT("Enable after suspending 1 host"), WLBS_SUSPENDED, status1);
  1041. /* Now get the cluster to the converged state and test the state changes */
  1042. if ( !GetClusterToConvergedState (cluster))
  1043. {
  1044. add_error (_TEXT("Unable to get the cluster to the converged state"));
  1045. return;
  1046. }
  1047. _stprintf ( status_buf, _TEXT("Cluster-wide commands"));
  1048. num_host = WLBS_MAX_HOSTS;
  1049. status1 = WlbsSuspend (cluster, WLBS_ALL_HOSTS, response, &num_host);
  1050. verify_return_value (_TEXT("Cluster-wide Suspend"), WLBS_OK, status1);
  1051. num_host = WLBS_MAX_HOSTS;
  1052. status1 = WlbsQuery (cluster, WLBS_ALL_HOSTS, response, &num_host, &host_map, NULL);
  1053. verify_return_value (_TEXT("Query after Cluster-wide Suspend"), WLBS_SUSPENDED, status1);
  1054. verify_response_status (response, num_host, WLBS_SUSPENDED);
  1055. num_host = WLBS_MAX_HOSTS;
  1056. status1 = WlbsResume (cluster, WLBS_ALL_HOSTS, response, &num_host);
  1057. verify_return_value (_TEXT("Cluster-wide Resume after Suspend"), WLBS_OK, status1);
  1058. num_host = WLBS_MAX_HOSTS;
  1059. status1 = WlbsQuery (cluster, WLBS_ALL_HOSTS, response, &num_host, &host_map, NULL);
  1060. verify_return_value (_TEXT("Cluster-wide Query after Resume"), WLBS_STOPPED, status1);
  1061. verify_response_status (response, num_host, WLBS_STOPPED);
  1062. num_host = WLBS_MAX_HOSTS;
  1063. status1 = WlbsStart (cluster, WLBS_ALL_HOSTS, response, &num_host);
  1064. verify_return_value (_TEXT("Cluster-wide Start after Resume"), WLBS_OK, status1);
  1065. num_host = WLBS_MAX_HOSTS;
  1066. status1 = WlbsQuery (cluster, WLBS_ALL_HOSTS, response, &num_host, &host_map, NULL);
  1067. if (! (status1 == WLBS_CONVERGING || ( 1 <= status1 && status1 <= WLBS_MAX_HOSTS)) )
  1068. {
  1069. add_error (_TEXT("Error in query after cluster-wide start"));
  1070. }
  1071. Sleep (10000); /* Wait for the cluster to converge */
  1072. num_host = WLBS_MAX_HOSTS;
  1073. status1 = WlbsQuery (cluster, WLBS_ALL_HOSTS, response, &num_host, &host_map, NULL);
  1074. if ( ! ( 1 <= status1 && status1 <= WLBS_MAX_HOSTS) )
  1075. printf("Unable to get the cluster to converged state after Starting\n");
  1076. /* Test for invalid port numbers */
  1077. num_host = WLBS_MAX_HOSTS;
  1078. status1 = WlbsDrain (cluster, WLBS_ALL_HOSTS, response, &num_host, CVY_MAX_PORT + 1);
  1079. verify_return_value (_TEXT("Drain on invalid port"), WLBS_NOT_FOUND, status1);
  1080. num_host = WLBS_MAX_HOSTS;
  1081. status1 = WlbsDisable (cluster, WLBS_ALL_HOSTS, response, &num_host, CVY_MAX_PORT + 1);
  1082. verify_return_value (_TEXT("Disable on invalid port"), WLBS_NOT_FOUND, status1);
  1083. num_host = WLBS_MAX_HOSTS;
  1084. status1 = WlbsEnable (cluster, WLBS_ALL_HOSTS, response, &num_host, CVY_MAX_PORT + 1);
  1085. verify_return_value (_TEXT("Enable on invalid port"), WLBS_NOT_FOUND, status1);
  1086. Sleep (10000); /* Wait for the cluster to converge */
  1087. /* Test for invalid port numbers */
  1088. num_host = WLBS_MAX_HOSTS;
  1089. status1 = WlbsDrain (cluster, WLBS_ALL_HOSTS, response, &num_host, WLBS_ALL_PORTS);
  1090. verify_return_value (_TEXT("Drain on all port"), WLBS_OK, status1);
  1091. num_host = WLBS_MAX_HOSTS;
  1092. status1 = WlbsDisable (cluster, WLBS_ALL_HOSTS, response, &num_host, WLBS_ALL_PORTS);
  1093. verify_return_value (_TEXT("Disable on all port"), WLBS_OK, status1);
  1094. num_host = WLBS_MAX_HOSTS;
  1095. status1 = WlbsEnable (cluster, WLBS_ALL_HOSTS, response, &num_host, WLBS_ALL_PORTS);
  1096. verify_return_value (_TEXT("Enable on all port"), WLBS_OK, status1);
  1097. Sleep (10000);
  1098. /* Test timeout */
  1099. if (cluster == WLBS_LOCAL_CLUSTER)
  1100. temp_address = WlbsGetLocalClusterAddress ();
  1101. else
  1102. temp_address = cluster;
  1103. verify_timeout (temp_address, 5000);
  1104. verify_timeout (temp_address, 1000);
  1105. verify_timeout (temp_address, 0);
  1106. WlbsTimeoutSet (temp_address, timeout); /* Set the value specified by the user */
  1107. if (cluster == WLBS_LOCAL_CLUSTER)
  1108. return; /* DrainStop is not checked, since the connection will not be visible to the wlbs driver */
  1109. if (!GetDrainstopState (cluster, WLBS_ALL_HOSTS, &sock, 80))
  1110. return;
  1111. num_host = WLBS_MAX_HOSTS;
  1112. status1 = WlbsQuery (cluster, WLBS_ALL_HOSTS, response, &num_host, &host_map, NULL);
  1113. verify_return_value (_TEXT("Query after DrainStop with active connection"), WLBS_DRAINING, status1);
  1114. num_host = WLBS_MAX_HOSTS;
  1115. status1 = WlbsDisable (cluster, WLBS_ALL_HOSTS, response, &num_host, 80);
  1116. verify_return_value (_TEXT("Disable after DrainStop with active connection"), WLBS_OK, status1);
  1117. num_host = WLBS_MAX_HOSTS;
  1118. status1 = WlbsDrain (cluster, WLBS_ALL_HOSTS, response, &num_host, 80);
  1119. verify_return_value (_TEXT("Drain after DrainStop with active connection"), WLBS_OK, status1);
  1120. num_host = WLBS_MAX_HOSTS;
  1121. status1 = WlbsEnable (cluster, WLBS_ALL_HOSTS, response, &num_host, 80);
  1122. verify_return_value (_TEXT("Enable after DrainStop with active connection"), WLBS_OK, status1);
  1123. num_host = WLBS_MAX_HOSTS;
  1124. status1 = WlbsEnable (cluster, WLBS_ALL_HOSTS, response, &num_host, 80);
  1125. verify_return_value (_TEXT("Enable again after DrainStop with active connection"), WLBS_OK, status1);
  1126. num_host = WLBS_MAX_HOSTS;
  1127. status1 = WlbsStop (cluster, WLBS_ALL_HOSTS, response, &num_host);
  1128. verify_return_value (_TEXT("Stop after DrainStop with active connection"), WLBS_OK, status1);
  1129. num_host = WLBS_MAX_HOSTS;
  1130. status1 = WlbsQuery (cluster, WLBS_ALL_HOSTS, response, &num_host, &host_map, NULL);
  1131. verify_return_value (_TEXT("Query after Stop on DrainStop with active connection"), WLBS_STOPPED, status1);
  1132. closesocket (sock);
  1133. if (!GetDrainstopState (cluster, WLBS_ALL_HOSTS, &sock, 80))
  1134. return;
  1135. num_host = WLBS_MAX_HOSTS;
  1136. status1 = WlbsStart (cluster, WLBS_ALL_HOSTS, response, &num_host);
  1137. verify_return_value (_TEXT("Start after DrainStop with active connection"), WLBS_OK, status1);
  1138. Sleep (10000);
  1139. num_host = WLBS_MAX_HOSTS;
  1140. status1 = WlbsQuery (cluster, WLBS_ALL_HOSTS, response, &num_host, &host_map, NULL);
  1141. if (!(1 <= status1 && status1 <= WLBS_MAX_HOSTS))
  1142. return;
  1143. closesocket (sock);
  1144. if (!GetDrainstopState (cluster, WLBS_ALL_HOSTS, &sock, 80))
  1145. return;
  1146. num_host = WLBS_MAX_HOSTS;
  1147. status1 = WlbsSuspend (cluster, WLBS_ALL_HOSTS, response, &num_host);
  1148. verify_return_value (_TEXT("Suspend after DrainStop with active connection"), WLBS_OK, status1);
  1149. num_host = WLBS_MAX_HOSTS;
  1150. status1 = WlbsQuery (cluster, WLBS_ALL_HOSTS, response, &num_host, &host_map, NULL);
  1151. verify_return_value (_TEXT("Suspend after DrainStop with active connection"), WLBS_SUSPENDED, status1);
  1152. closesocket (sock);
  1153. if (!GetDrainstopState (cluster, WLBS_ALL_HOSTS, &sock, 80))
  1154. return;
  1155. num_host = WLBS_MAX_HOSTS;
  1156. status1 = WlbsResume (cluster, WLBS_ALL_HOSTS, response, &num_host);
  1157. verify_return_value (_TEXT("Resume on DrainStop with active connection"), WLBS_OK, status1);
  1158. closesocket (sock); /* close the connection */
  1159. Sleep (10000); /* Wait for the host to figure out that all the connections have terminated */
  1160. num_host = WLBS_MAX_HOSTS;
  1161. status1 = WlbsQuery (cluster, WLBS_ALL_HOSTS, response, &num_host, &host_map, NULL);
  1162. verify_return_value (_TEXT("Query after DrainStop with closed connection"), WLBS_STOPPED, status1);
  1163. /* issue a cluster-wide start to bring back all the hosts to the converged state.*/
  1164. num_host = WLBS_MAX_HOSTS;
  1165. status1 = WlbsStart (cluster, WLBS_ALL_HOSTS, response, &num_host);
  1166. verify_return_value (_TEXT("Cluster-wide start to restore original state"), WLBS_OK, status1);
  1167. Sleep (10000); /* Wait for the cluster to converge */
  1168. return;
  1169. }
  1170. void check_cluster_operations ( )
  1171. {
  1172. DWORD cluster = 0;
  1173. if (local_test)
  1174. {
  1175. if (global_init = WLBS_PRESENT)
  1176. {
  1177. WLBS_REG_PARAMS reg_data;
  1178. DWORD status;
  1179. status = WlbsReadReg (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST, &reg_data);
  1180. if (status != WLBS_OK)
  1181. {
  1182. printf("Unable to read from the registry to set the password\nAborting cluster checks\n");
  1183. return;
  1184. }
  1185. WlbsCodeSet (WlbsGetLocalClusterAddress (), reg_data . i_rct_password );
  1186. WlbsTimeoutSet (WlbsGetLocalClusterAddress (), timeout);
  1187. if (GetClusterToConvergedState (WLBS_LOCAL_CLUSTER))
  1188. {
  1189. cluster_parameter_test (WLBS_LOCAL_CLUSTER);
  1190. cluster_state_changes (WLBS_LOCAL_CLUSTER);
  1191. }
  1192. else
  1193. {
  1194. add_error (_TEXT("Unable to get the local cluster to the converged state"));
  1195. }
  1196. }
  1197. }
  1198. if (!remote_test)
  1199. return;
  1200. WlbsPasswordSet (remote_cl_ip, remote_password);
  1201. WlbsTimeoutSet (remote_cl_ip, timeout);
  1202. if ( GetClusterToConvergedState (remote_cl_ip))
  1203. {
  1204. cluster_parameter_test (remote_cl_ip);
  1205. cluster_state_changes (remote_cl_ip);
  1206. }
  1207. else
  1208. add_error (_TEXT("Unable to get the remote cluster to the converged state"));
  1209. return;
  1210. }
  1211. /* This function is used to find the first place where the 2 structures differ */
  1212. DWORD find_mem_change (PWLBS_REG_PARAMS data1, PWLBS_REG_PARAMS data2, DWORD size)
  1213. {
  1214. DWORD i;
  1215. printf("size of dword %d\n", sizeof (DWORD));
  1216. for (i = 4; i < size ; i += 4)
  1217. {
  1218. if (memcmp (data1, data2, i))
  1219. return i;
  1220. }
  1221. return 0;
  1222. }
  1223. void check_rules_in_structure (PWLBS_REG_PARAMS reg_data)
  1224. {
  1225. DWORD i;
  1226. printf("the number of rules is %d\n", reg_data -> i_num_rules);
  1227. for (i = 0 ; i < WLBS_MAX_RULES; i++)
  1228. {
  1229. if (reg_data -> i_port_rules [i] . i_valid)
  1230. {
  1231. printf("\tFound valid port rule %d with start port %d ep %d\n", i,
  1232. reg_data -> i_port_rules [i] . start_port,
  1233. reg_data -> i_port_rules [i] . end_port);
  1234. }
  1235. }
  1236. return;
  1237. }
  1238. /* This function tests the reads and writes to the registry */
  1239. void check_registry_rw ()
  1240. {
  1241. WLBS_REG_PARAMS saved;
  1242. WLBS_REG_PARAMS newdata;
  1243. WLBS_REG_PARAMS temp;
  1244. DWORD status;
  1245. if (global_init == WLBS_REMOTE_ONLY || global_init == WLBS_INIT_ERROR)
  1246. {
  1247. add_error (_TEXT("Cannot check registry rw since wlbs is not installed"));
  1248. return;
  1249. }
  1250. /* parameter testing */
  1251. _stprintf (status_buf, _TEXT("Parameter Test for ReadReg and WriteReg"));
  1252. status = WlbsReadReg (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST, NULL);
  1253. verify_return_value (_TEXT("ReadReg with null regdata"), WLBS_BAD_PARAMS, status);
  1254. status = WlbsWriteReg (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST, NULL);
  1255. verify_return_value (_TEXT("WriteReg with null regdata"), WLBS_BAD_PARAMS, status);
  1256. status = WlbsReadReg (12, WLBS_LOCAL_HOST, & saved);
  1257. verify_return_value (_TEXT("ReadReg on remote cluster"), WLBS_LOCAL_ONLY, status);
  1258. status = WlbsWriteReg (12, WLBS_LOCAL_HOST, & saved);
  1259. verify_return_value (_TEXT("WriteReg on remote cluster"), WLBS_LOCAL_ONLY, status);
  1260. status = WlbsReadReg (WLBS_LOCAL_CLUSTER, 10, & saved);
  1261. verify_return_value (_TEXT("ReadReg on remote host"), WLBS_LOCAL_ONLY, status);
  1262. status = WlbsWriteReg (WLBS_LOCAL_CLUSTER, 10, & saved);
  1263. verify_return_value (_TEXT("WriteReg on remote host"), WLBS_LOCAL_ONLY, status);
  1264. /* now test the actual working of read and write reg */
  1265. _stprintf (status_buf, _TEXT("Testing ReadReg and WriteReg for correctness"));
  1266. status = WlbsReadReg (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST, & saved);
  1267. verify_return_value (_TEXT("ReadReg"), WLBS_OK, status);
  1268. /* The following memset is to avoid any spurious differences */
  1269. memset (&newdata, 0, sizeof (WLBS_REG_PARAMS));
  1270. /* Fill in the structure with valid values */
  1271. newdata . alive_period = saved . alive_period + 1;
  1272. newdata . alive_tolerance = saved . alive_tolerance + 1;
  1273. _tcscpy (newdata . cl_ip_addr, _TEXT("111.222.111.222"));
  1274. _tcscpy (newdata . cl_mac_addr, _TEXT("11-22-33-44-55-66"));
  1275. _tcscpy (newdata . cl_net_mask, _TEXT("255.255.255.0"));
  1276. newdata . cluster_mode = FALSE;
  1277. _tcscpy (newdata . ded_ip_addr, _TEXT("111.222.111.233"));
  1278. _tcscpy (newdata . ded_net_mask, _TEXT("255.255.255.0"));
  1279. _tcscpy (newdata . domain_name, _TEXT("TESTDOMAINNAME"));
  1280. newdata . dscr_per_alloc = 1024;
  1281. newdata . host_priority = saved . host_priority + 1;
  1282. newdata . i_cleanup_delay = 3600;
  1283. _tcscpy (newdata . i_cluster_nic_name, saved . i_cluster_nic_name); /* This is for read-only */
  1284. newdata . i_convert_mac = FALSE;
  1285. newdata . i_expiration = 0;
  1286. newdata . i_ft_rules_enabled = TRUE;
  1287. newdata . i_ip_chg_delay = saved . i_ip_chg_delay + 1;
  1288. _tcscpy (newdata . i_license_key, _TEXT("JUNKLICENSEKEY"));
  1289. newdata . i_max_hosts = LICENSE_MAX_HOSTS;
  1290. newdata . i_max_rules = LICENSE_RULES;
  1291. newdata . i_mcast_spoof = FALSE;
  1292. newdata . i_num_rules = 0;
  1293. newdata . i_parms_ver = saved . i_parms_ver;
  1294. memset ( newdata . i_port_rules, 0, sizeof (WLBS_PORT_RULE) * WLBS_MAX_RULES);
  1295. newdata . i_rct_password = 23445;
  1296. newdata . i_rmt_password = 98765;
  1297. newdata . i_scale_client = 10;
  1298. newdata . i_verify_date = 0;
  1299. newdata . i_version = 0;
  1300. _tcscpy (newdata . i_virtual_nic_name, _TEXT("TEMP_VIRTUAL_NIC_NAME"));
  1301. newdata . install_date = 50000;
  1302. newdata . mask_src_mac = FALSE;
  1303. newdata . max_dscr_allocs = 1024;
  1304. newdata . mcast_support = FALSE;
  1305. newdata . i_nbt_support = FALSE;
  1306. newdata . num_actions = saved . num_actions + 1;
  1307. newdata . num_packets = saved . num_packets + 1;
  1308. newdata . num_send_msgs = saved . num_send_msgs + 1;
  1309. newdata . rct_enabled = FALSE;
  1310. newdata . rct_port = 2000;
  1311. status = WlbsWriteReg (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST, & newdata);
  1312. verify_return_value (_TEXT("WriteReg"), WLBS_OK, status);
  1313. memset (&temp, 0, sizeof (WLBS_REG_PARAMS));
  1314. status = WlbsReadReg (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST, & temp);
  1315. verify_return_value (_TEXT("ReadReg after a write"), WLBS_OK, status);
  1316. memset ( temp . i_port_rules, 0, sizeof (WLBS_PORT_RULE) * WLBS_MAX_RULES);
  1317. if (memcmp(&temp, &newdata, sizeof (WLBS_REG_PARAMS)))
  1318. {
  1319. _stprintf (tbuf, _TEXT("1:The data written and the data read back differ in the location %d\n"),
  1320. find_mem_change (&newdata, &temp, sizeof (WLBS_REG_PARAMS)) );
  1321. add_error (tbuf);
  1322. }
  1323. /* restore the original status of the registry */
  1324. status = WlbsWriteReg (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST, & saved);
  1325. verify_return_value (_TEXT("WriteReg to restore original state"), WLBS_OK, status);
  1326. status = WlbsReadReg (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST, & newdata);
  1327. verify_return_value (_TEXT("ReadReg"), WLBS_OK, status);
  1328. newdata . i_convert_mac = FALSE;
  1329. newdata . mcast_support = FALSE;
  1330. _tcscpy (newdata . cl_mac_addr, _TEXT("11-22-33-44-55-66"));
  1331. status = WlbsWriteReg (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST, & newdata);
  1332. verify_return_value (_TEXT("WriteReg with convertmac = false; mcast = false"), WLBS_OK, status);
  1333. status = WlbsReadReg (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST, & temp);
  1334. verify_return_value (_TEXT("ReadReg with convertmac = false; mcast = false"), WLBS_OK, status);
  1335. if (memcmp (&temp, &newdata, sizeof (WLBS_REG_PARAMS)) )
  1336. {
  1337. _stprintf (tbuf, _TEXT("2:The data written and the data read back differ in the location %d\n"),
  1338. find_mem_change (&newdata, &temp, sizeof (WLBS_REG_PARAMS)) );
  1339. add_error (tbuf);
  1340. }
  1341. newdata . i_convert_mac = TRUE;
  1342. newdata . mcast_support = FALSE;
  1343. status = WlbsWriteReg (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST, & newdata);
  1344. verify_return_value (_TEXT("WriteReg with convertmac = true; mcast = false"), WLBS_OK, status);
  1345. status = WlbsReadReg (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST, & temp);
  1346. if ( _tcsnicmp(_TEXT("02-bf"), temp . cl_mac_addr, _tcslen(_TEXT("02-bf")) ) )
  1347. {
  1348. _stprintf (tbuf, _TEXT("Error in converting mac address in the unicast mode"));
  1349. add_error (tbuf);
  1350. }
  1351. newdata . mcast_support = TRUE;
  1352. status = WlbsWriteReg (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST, & newdata);
  1353. verify_return_value (_TEXT("WriteReg with convertmac = true; mcast = true"), WLBS_OK, status);
  1354. status = WlbsReadReg (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST, & temp);
  1355. if ( _tcsnicmp (_TEXT("03-bf"), temp . cl_mac_addr, _tcslen(_TEXT("03-bf")) ))
  1356. {
  1357. _stprintf (tbuf, _TEXT("Error in converting mac address in the multicast mode"));
  1358. add_error (tbuf);
  1359. }
  1360. /* These tests are to verify that parameter checking in WlbsWriteReg is o.k. */
  1361. newdata . host_priority = CVY_MIN_PRIORITY - 1;
  1362. status = WlbsWriteReg (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST, &newdata);
  1363. verify_return_value (_TEXT("WriteReg with host priority = 0"), WLBS_BAD_PARAMS, status);
  1364. newdata . host_priority = CVY_MAX_PRIORITY + 1;
  1365. status = WlbsWriteReg (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST, &newdata);
  1366. verify_return_value (_TEXT("WriteReg with host priority = 33"), WLBS_BAD_PARAMS, status);
  1367. newdata . host_priority = saved . host_priority;
  1368. newdata . rct_port = CVY_MIN_RCT_PORT - 1;
  1369. status = WlbsWriteReg (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST, &newdata);
  1370. verify_return_value (_TEXT("WriteReg with RCT port = 0"), WLBS_BAD_PARAMS, status);
  1371. newdata . rct_port = CVY_MAX_RCT_PORT + 1;
  1372. status = WlbsWriteReg (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST, &newdata);
  1373. verify_return_value (_TEXT("WriteReg with RCT port = 65536"), WLBS_BAD_PARAMS, status);
  1374. newdata . rct_port = saved . rct_port;
  1375. newdata . i_num_rules = CVY_MAX_NUM_RULES + 1;
  1376. status = WlbsWriteReg (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST, &newdata);
  1377. verify_return_value (_TEXT("WriteReg with num_rules = 33"), WLBS_BAD_PARAMS, status);
  1378. newdata . i_num_rules = saved . i_num_rules;
  1379. newdata . i_convert_mac = FALSE;
  1380. _tcscpy (newdata . ded_ip_addr, _TEXT("0.0.0.0"));
  1381. _tcscpy (newdata . cl_ip_addr, _TEXT("0.0.0.0"));
  1382. _tcscpy (newdata . ded_net_mask, _TEXT("0.0.0.0"));
  1383. _tcscpy (newdata . cl_net_mask, _TEXT("0.0.0.0"));
  1384. _tcscpy (newdata . cl_mac_addr, _TEXT("00-11-22-33-44-AA"));
  1385. status = WlbsWriteReg (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST, &newdata);
  1386. verify_return_value (_TEXT("WriteReg with all ip addresses = 0"), WLBS_OK, status);
  1387. _tcscpy (newdata . cl_mac_addr, _TEXT("0g-11-hh-jj-kk-ll"));
  1388. status = WlbsWriteReg (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST, &newdata);
  1389. verify_return_value (_TEXT("WriteReg with cl mac addr = 0g-11-hh-jj-kk-ll"), WLBS_BAD_PARAMS, status);
  1390. _tcscpy (newdata . cl_mac_addr, _TEXT("00-11-22-33-44-AA"));
  1391. _tcscpy (newdata . cl_mac_addr, _TEXT("00-11-22-33-44-5G"));
  1392. status = WlbsWriteReg (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST, &newdata);
  1393. verify_return_value (_TEXT("WriteReg with cl mac addr = 00-11-22-33-44-5G"), WLBS_BAD_PARAMS, status);
  1394. _tcscpy (newdata . cl_mac_addr, _TEXT("00-11-22-33-44-AA"));
  1395. _tcscpy (newdata . ded_net_mask, _TEXT("333.222.222.222"));
  1396. status = WlbsWriteReg (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST, &newdata);
  1397. verify_return_value (_TEXT("WriteReg with ded ip mask = 333.222.222.222"), WLBS_BAD_PARAMS, status);
  1398. _tcscpy (newdata . ded_net_mask, _TEXT("0.0.0.0"));
  1399. _tcscpy (newdata . ded_ip_addr, _TEXT("333.222.222.222"));
  1400. status = WlbsWriteReg (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST, &newdata);
  1401. verify_return_value (_TEXT("WriteReg with ded ip addr = 333.222.222.222"), WLBS_BAD_PARAMS, status);
  1402. _tcscpy (newdata . ded_ip_addr, _TEXT("0.0.0.0"));
  1403. _tcscpy (newdata . cl_net_mask, _TEXT("333.222.222.222"));
  1404. status = WlbsWriteReg (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST, &newdata);
  1405. verify_return_value (_TEXT("WriteReg with cl ip mask = 333.222.222.222"), WLBS_BAD_PARAMS, status);
  1406. _tcscpy (newdata . cl_net_mask, _TEXT("0.0.0.0"));
  1407. _tcscpy (newdata . cl_ip_addr, _TEXT("333.222.222.222"));
  1408. status = WlbsWriteReg (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST, &newdata);
  1409. verify_return_value (_TEXT("WriteReg with cl ip addr = 333.222.222.222"), WLBS_BAD_PARAMS, status);
  1410. _tcscpy (newdata . cl_ip_addr, _TEXT("0.0.0.0"));
  1411. /* Restore the initial state */
  1412. status = WlbsWriteReg (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST, & saved);
  1413. status = WlbsCommitChanges (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST);
  1414. return;
  1415. }
  1416. /* This function verifies the commit functionality.
  1417. * It writes a new priority to the registry and commits it.
  1418. * A local query is made. The host id is checked to see that the commit has
  1419. * indeed forced the driver to load the new host id.
  1420. * This may cause the cluster (in case of multiple hosts) to go into convergence
  1421. * if the id is duplicated .....
  1422. */
  1423. void verify_host_id_changes (PWLBS_REG_PARAMS reg_data, DWORD old_priority, DWORD new_priority)
  1424. {
  1425. DWORD status;
  1426. DWORD num_host, host_map;
  1427. WLBS_RESPONSE response;
  1428. reg_data -> host_priority = new_priority;
  1429. status = WlbsWriteReg (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST, reg_data);
  1430. status = WlbsCommitChanges (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST);
  1431. verify_return_value (_TEXT("Commit after changing host priority"), WLBS_OK, status);
  1432. num_host = 1;
  1433. status = WlbsQuery (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST, &response, &num_host, &host_map, NULL);
  1434. /* Hope that Query does not return any winsock error ... */
  1435. verify_return_value (_TEXT("Verifying the host priority after commit"),
  1436. new_priority,
  1437. response . id);
  1438. return;
  1439. }
  1440. /* This function changes only the cluster and dedicated ip addresses and verifies them */
  1441. void verify_ip_address_changes (PWLBS_REG_PARAMS reg_data, PTCHAR cl_ip_addr, PTCHAR ded_ip_addr)
  1442. {
  1443. DWORD status;
  1444. _tcscpy ( reg_data -> cl_ip_addr, cl_ip_addr);
  1445. _tcscpy ( reg_data -> ded_ip_addr, ded_ip_addr);
  1446. reg_data -> i_convert_mac = FALSE; /* So that the mac address does not change */
  1447. status = WlbsWriteReg (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST, reg_data);
  1448. status = WlbsCommitChanges (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST);
  1449. /* Both nt4 and nt5 should return WLBS_OK.
  1450. * Reboot should not be returned since the mac address is not changed.
  1451. */
  1452. verify_return_value (_TEXT("Commit after changing ip addresses"), WLBS_OK, status);
  1453. verify_return_value (_TEXT("Verify Changed Cluster IP Address"),
  1454. WlbsResolve (cl_ip_addr),
  1455. WlbsGetLocalClusterAddress());
  1456. verify_return_value (_TEXT("Verify Changed Cluster IP Address"),
  1457. WlbsResolve (ded_ip_addr),
  1458. WlbsGetDedicatedAddress());
  1459. return;
  1460. }
  1461. /* This function verifies that the mac address is as specified in the registry structure.
  1462. * It uses IP helper functions to get the mac address from the adapters.
  1463. * It firsts lists all the adapters and verifies that the address on one of those
  1464. * matches that in the registry.
  1465. * This function will not work on NT4 machines since NT4 does not support some
  1466. * IP helper functions.
  1467. */
  1468. void verify_mac_address (PWLBS_REG_PARAMS reg_data)
  1469. {
  1470. IP_ADAPTER_INFO *padapter_info = NULL, *temp_adapter_info = NULL;
  1471. ULONG size;
  1472. DWORD status;
  1473. BOOL found = FALSE;
  1474. CHAR AddressFromReg [CVY_MAX_NETWORK_ADDR + 1];
  1475. CHAR AddressFromIPHelper [CVY_MAX_NETWORK_ADDR + 1];
  1476. DWORD i;
  1477. DWORD num_interfaces = 0;
  1478. Sleep (30000); /* Wait for the driver to finish reloading and then check */
  1479. #ifdef UNICODE
  1480. sprintf (AddressFromReg, "%ls", reg_data -> cl_mac_addr);
  1481. #else
  1482. sprintf (AddressFromReg, "%s", reg_data -> cl_mac_addr);
  1483. #endif
  1484. status = GetNumberOfInterfaces (&num_interfaces);
  1485. if (status != NO_ERROR)
  1486. {
  1487. printf("Unable to find any network interfaces on the local computer\nAborting the test\n");
  1488. return;
  1489. }
  1490. size = sizeof (IP_ADAPTER_INFO) * num_interfaces;
  1491. padapter_info = (IP_ADAPTER_INFO *) malloc (size);
  1492. if (padapter_info == NULL)
  1493. return;
  1494. for (i = 0 ; i < num_interfaces; i++)
  1495. padapter_info [i] . Next = NULL;
  1496. status = GetAdaptersInfo (padapter_info, & size);
  1497. if (status != ERROR_SUCCESS)
  1498. {
  1499. printf("Unable to Get Adapter Info. Cannot verify mac address.\n");
  1500. switch (status)
  1501. {
  1502. case ERROR_BUFFER_OVERFLOW : printf ("Required buffer size is %d\n", size);
  1503. break;
  1504. case ERROR_INVALID_PARAMETER : printf ("Invalid parameter\n");
  1505. break;
  1506. case ERROR_NO_DATA : printf ("No Adapter Information\n");
  1507. break;
  1508. case ERROR_NOT_SUPPORTED : printf ("Error not supported");
  1509. break;
  1510. default:
  1511. break;
  1512. }
  1513. return;
  1514. }
  1515. temp_adapter_info = padapter_info;
  1516. while (padapter_info)
  1517. {
  1518. sprintf (AddressFromIPHelper, "%02x-%02x-%02x-%02x-%02x-%02x",
  1519. padapter_info -> Address [0],
  1520. padapter_info -> Address [1],
  1521. padapter_info -> Address [2],
  1522. padapter_info -> Address [3],
  1523. padapter_info -> Address [4],
  1524. padapter_info -> Address [5]);
  1525. if (_stricmp (AddressFromIPHelper, AddressFromReg) == 0)
  1526. {
  1527. found = TRUE;
  1528. break;
  1529. }
  1530. padapter_info = padapter_info -> Next;
  1531. }
  1532. /* Free the allocated memory */
  1533. while (temp_adapter_info)
  1534. {
  1535. padapter_info = temp_adapter_info;
  1536. temp_adapter_info = temp_adapter_info -> Next;
  1537. free (padapter_info);
  1538. }
  1539. if (!found && !reg_data -> mcast_support)
  1540. {
  1541. add_error (_TEXT("In unicast mode, the registry mac address does not match the adapter mac address\n"));
  1542. return;
  1543. }
  1544. if (found && reg_data -> mcast_support)
  1545. {
  1546. add_error (_TEXT("In multicast mode, the registry mac address was written to the NIC"));
  1547. return;
  1548. }
  1549. /* If mac address is generated by converting the ip address,
  1550. * then verify that the conversion takes place
  1551. */
  1552. if (reg_data -> i_convert_mac)
  1553. {
  1554. if (!reg_data -> mcast_support)
  1555. if (_strnicmp (AddressFromIPHelper, "02-bf", strlen ("02-bf")) )
  1556. add_error (_TEXT("Generation of MAC address in unicast mode failed"));
  1557. }
  1558. return;
  1559. }
  1560. /* This function checks the working of commit api. */
  1561. void check_commit (DWORD entry_point)
  1562. {
  1563. WLBS_REG_PARAMS saved, newdata, temp_data;
  1564. DWORD status;
  1565. WLBS_RESPONSE response;
  1566. DWORD num_host, host_map;
  1567. DWORD old_priority, new_priority;
  1568. _stprintf (status_buf, _TEXT("Checking Commit"));
  1569. if (global_init == WLBS_REMOTE_ONLY || global_init == WLBS_INIT_ERROR)
  1570. {
  1571. _stprintf (tbuf, _TEXT("%s Unable to Perform Commit checks"), status_buf);
  1572. add_error(tbuf);
  1573. return;
  1574. }
  1575. /* Save the original configuration */
  1576. status = WlbsReadReg (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST, &saved);
  1577. if (status != WLBS_OK)
  1578. {
  1579. _stprintf(tbuf, _TEXT("%s Unable to save the original configuration. Aborting the tests\n"), status_buf);
  1580. add_error (tbuf);
  1581. return;
  1582. }
  1583. status = WlbsReadReg (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST, &newdata);
  1584. /* This is because commit returns reboot in nt4 on a commit when the mac address changes. */
  1585. if (version_nt4)
  1586. {
  1587. if (entry_point == 1)
  1588. {
  1589. _tprintf(_TEXT("Use ipconfig to ensure that the mac address is %s\n"), newdata . cl_mac_addr);
  1590. goto mac_addr_change1;
  1591. }
  1592. else if (entry_point == 2)
  1593. {
  1594. _tprintf(_TEXT("Use ipconfig to ensure that the mac address is %s\n"), newdata . cl_mac_addr);
  1595. goto mac_addr_change2;
  1596. }
  1597. else if (entry_point == 3)
  1598. {
  1599. _tprintf(_TEXT("Use ipconfig to ensure that the mac address is the manufacturer specified one.\n"));
  1600. goto mac_addr_change3;
  1601. }
  1602. else if (entry_point == 4)
  1603. {
  1604. _tprintf(_TEXT("Use ipconfig to ensure that the mac address is the manufacturer specified one.\n"));
  1605. _tprintf(_TEXT("Please note that the cluster IP address has been changed by this test.\nPlease reset the cluster settings\n"));
  1606. return;
  1607. }
  1608. }
  1609. /* Write without any changes */
  1610. status = WlbsWriteReg (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST, &newdata);
  1611. status = WlbsCommitChanges (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST);
  1612. verify_return_value (_TEXT("Commit without any changes"), WLBS_OK, status);
  1613. /* Change only the host priority and verify that query returns the correct priority */
  1614. old_priority = newdata . host_priority;
  1615. new_priority = newdata . host_priority + 1; /* Could cause the cluster to stop operations */
  1616. if (new_priority > CVY_MAX_HOST_PRIORITY)
  1617. new_priority = 1;
  1618. verify_host_id_changes ( &newdata, old_priority, new_priority);
  1619. /* Change back to the original value and verify */
  1620. verify_host_id_changes ( &newdata, new_priority, old_priority);
  1621. /* Verify changes in the ip addresses */
  1622. verify_ip_address_changes ( &newdata, _TEXT("111.111.111.111"), _TEXT("222.222.222.222"));
  1623. /* Restore the original addresses and verify */
  1624. verify_ip_address_changes ( &newdata, saved . cl_ip_addr, saved . ded_ip_addr);
  1625. /* Now verify mac address changes */
  1626. newdata . i_convert_mac = FALSE;
  1627. newdata . mcast_support = FALSE;
  1628. _stprintf (newdata . cl_mac_addr, _TEXT("00-12-34-56-78-9a"));
  1629. status = WlbsWriteReg (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST, &newdata);
  1630. status = WlbsCommitChanges (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST);
  1631. if (!version_nt4)
  1632. {
  1633. verify_return_value (_TEXT("Changing mac address 1"), WLBS_OK, status);
  1634. status = WlbsReadReg (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST, &temp_data);
  1635. verify_mac_address (&temp_data);
  1636. }
  1637. else
  1638. {
  1639. verify_return_value (_TEXT("Changing mac address 1"), WLBS_REBOOT, status);
  1640. printf("\n");
  1641. print_error_messages ();
  1642. printf("Total number of tests: %d Failed Tests: %d\n", total_tests, failed_tests);
  1643. printf("Please reboot the machine and start the test as \n wlbsapitest reboot 1");
  1644. exit (1);
  1645. }
  1646. mac_addr_change1:
  1647. /* When convert mac is true and mcast support is false */
  1648. newdata . i_convert_mac = TRUE;
  1649. newdata . mcast_support = FALSE;
  1650. _stprintf (newdata . cl_mac_addr, _TEXT("00-12-34-56-78-9a"));
  1651. status = WlbsWriteReg (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST, &newdata);
  1652. status = WlbsCommitChanges (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST);
  1653. if (!version_nt4)
  1654. {
  1655. verify_return_value (_TEXT("Changing mac address 2"), WLBS_OK, status);
  1656. status = WlbsReadReg (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST, &temp_data);
  1657. verify_mac_address (&temp_data);
  1658. }
  1659. else
  1660. {
  1661. verify_return_value (_TEXT("Changing mac address 2"), WLBS_REBOOT, status);
  1662. printf("\n");
  1663. print_error_messages ();
  1664. printf("Total number of tests: %d Failed Tests: %d\n", total_tests, failed_tests);
  1665. printf("Please reboot the machine and start the test as \n wlbsapitest reboot 2");
  1666. exit (1);
  1667. }
  1668. mac_addr_change2:
  1669. /* When convertmac is true and mcast_support is also true */
  1670. newdata . i_convert_mac = TRUE;
  1671. newdata . mcast_support = TRUE;
  1672. status = WlbsWriteReg (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST, &newdata);
  1673. status = WlbsCommitChanges (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST);
  1674. if (!version_nt4)
  1675. {
  1676. verify_return_value (_TEXT("Changing mac address 3"), WLBS_OK, status);
  1677. status = WlbsReadReg (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST, &temp_data);
  1678. verify_mac_address (&temp_data);
  1679. }
  1680. else
  1681. {
  1682. verify_return_value (_TEXT("Changing mac address 3"), WLBS_REBOOT, status);
  1683. printf("\n");
  1684. print_error_messages ();
  1685. printf("Total number of tests: %d Failed Tests: %d\n", total_tests, failed_tests);
  1686. printf("Please reboot the machine and start the test as \n wlbsapitest reboot 3");
  1687. exit (1);
  1688. }
  1689. mac_addr_change3:
  1690. /* Add a test to change the cluster ip address in multicast mode with convertmac set to true
  1691. * and verify that ipconfig does not display this multicast mac address.
  1692. */
  1693. _tcscpy (newdata . cl_ip_addr, _TEXT("111.222.111.222"));
  1694. status = WlbsWriteReg (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST, &newdata);
  1695. status = WlbsCommitChanges (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST);
  1696. if (!version_nt4)
  1697. {
  1698. verify_return_value (_TEXT("Changing mac address 4"), WLBS_OK, status);
  1699. status = WlbsReadReg (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST, &temp_data);
  1700. verify_mac_address (&temp_data);
  1701. }
  1702. else
  1703. {
  1704. verify_return_value (_TEXT("Changing mac address 4"), WLBS_REBOOT, status);
  1705. printf("\n");
  1706. print_error_messages ();
  1707. printf("Total number of tests: %d Failed Tests: %d\n", total_tests, failed_tests);
  1708. printf("Please reboot the machine and start the test as \n wlbsapitest reboot 4");
  1709. exit (1);
  1710. }
  1711. /* restore the original state */
  1712. if (entry_point == 0)
  1713. {
  1714. status = WlbsWriteReg (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST, &saved);
  1715. status = WlbsCommitChanges (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST);
  1716. }
  1717. return;
  1718. }
  1719. /* This function performs the parameter tests for the port rule APIs.
  1720. * This includes passing NULL parameters, invalid parameters ...
  1721. */
  1722. void port_rule_parameter_test (PWLBS_REG_PARAMS reg_data)
  1723. {
  1724. DWORD status;
  1725. PWLBS_PORT_RULE rules;
  1726. WLBS_PORT_RULE rule1, rule2;
  1727. DWORD num_rules1, num_rules2;
  1728. _stprintf (status_buf, _TEXT("Port Rule APIs Parameter Test"));
  1729. status = WlbsGetNumPortRules (NULL);
  1730. verify_return_value (_TEXT("GetNumPortRules"), WLBS_BAD_PARAMS, status);
  1731. status = WlbsEnumPortRules (NULL, NULL, NULL);
  1732. verify_return_value (_TEXT("EnumPortRules"), WLBS_BAD_PARAMS, status);
  1733. status = WlbsEnumPortRules (reg_data, NULL, NULL);
  1734. verify_return_value (_TEXT("EnumPortRules"), WLBS_BAD_PARAMS, status);
  1735. /* find the number of rules through both EnumPortRules as well as through GetNumPortRules
  1736. * Verify that both return the same number of rules
  1737. */
  1738. num_rules1 = 0;
  1739. status = WlbsEnumPortRules (reg_data, NULL, &num_rules1);
  1740. verify_return_value (_TEXT("EnumPortRules"), WLBS_TRUNCATED, status);
  1741. num_rules2 = WlbsGetNumPortRules (reg_data);
  1742. verify_return_value (_TEXT("EnumPortRules and GetNumPortRules"), num_rules2, num_rules1);
  1743. status = WlbsGetPortRule (NULL, 80, NULL);
  1744. verify_return_value (_TEXT("GetPortRule with regdata null"), WLBS_BAD_PARAMS, status);
  1745. status = WlbsGetPortRule (reg_data, 80, NULL);
  1746. verify_return_value (_TEXT("GetPortRule with port_rule null"), WLBS_BAD_PARAMS, status);
  1747. status = WlbsGetPortRule (reg_data, CVY_MAX_PORT + 1, &rule1);
  1748. verify_return_value (_TEXT("GetPortRule with invalid port"), WLBS_BAD_PARAMS, status);
  1749. status = WlbsAddPortRule (NULL, NULL);
  1750. verify_return_value (_TEXT("AddPortRule with regdata null"), WLBS_BAD_PARAMS, status);
  1751. status = WlbsAddPortRule (reg_data, NULL);
  1752. verify_return_value (_TEXT("AddPortRule with port_rule null"), WLBS_BAD_PARAMS, status);
  1753. status = WlbsDeletePortRule (NULL, 80);
  1754. verify_return_value (_TEXT("DeletePortRule with regdata null"), WLBS_BAD_PARAMS, status);
  1755. status = WlbsDeletePortRule (reg_data, CVY_MAX_PORT + 1);
  1756. verify_return_value (_TEXT("DeletePortRule with invalid port number"), WLBS_BAD_PARAMS, status);
  1757. return;
  1758. }
  1759. /* This function deletes all the existing port rules in the reg_params structure.
  1760. * This helps in starting off from a known state.
  1761. */
  1762. void delete_all_rules ( PWLBS_REG_PARAMS reg_data )
  1763. {
  1764. WLBS_PORT_RULE rules [WLBS_MAX_RULES];
  1765. DWORD num_rules;
  1766. DWORD i;
  1767. num_rules = WLBS_MAX_RULES;
  1768. WlbsEnumPortRules ( reg_data, rules, & num_rules );
  1769. for (i = 0 ; i < num_rules ; i++)
  1770. WlbsDeletePortRule ( reg_data, rules [i] . start_port );
  1771. return;
  1772. }
  1773. /* This function generates num_rules number of valid and non-ovelapping port rules
  1774. * and returns it in the rules array
  1775. */
  1776. void generate_valid_rules ( PWLBS_PORT_RULE rules, DWORD num_rules, DWORD range )
  1777. {
  1778. DWORD i;
  1779. static DWORD pri = 0;
  1780. for (i = 0 ; i < num_rules ; i++)
  1781. {
  1782. rules [i] . start_port = i * range;
  1783. rules [i] . end_port = rules [i] . start_port + range - 1;
  1784. rules [i] . mode = (pri++) % CVY_MAX_MODE + 1;
  1785. rules [i] . protocol = (pri++) % CVY_MAX_PROTOCOL + 1;
  1786. if (rules [i] . mode == WLBS_SINGLE)
  1787. rules [i] . mode_data . single . priority = (pri++) % (WLBS_MAX_HOSTS) + 1;
  1788. if (rules [i] . mode == WLBS_MULTI)
  1789. {
  1790. rules [i] . mode_data . multi . affinity = (WORD) ((pri++) % (CVY_MAX_AFFINITY + 1));
  1791. rules [i] . mode_data . multi . equal_load = (WORD) ((pri++) % 2);
  1792. rules [i] . mode_data . multi . load = (WORD) ((pri++) % (CVY_MAX_LOAD + 1));
  1793. }
  1794. }
  1795. return;
  1796. }
  1797. /* Verify that the rules returned by Enum are in sorted order */
  1798. BOOL verify_enum_port_rules (PWLBS_PORT_RULE rules, DWORD num_rules)
  1799. {
  1800. DWORD i;
  1801. if (num_rules == 0)
  1802. return TRUE;
  1803. for (i = 0 ; i < num_rules - 1; i++)
  1804. {
  1805. if (rules [i] . start_port >= rules [i + 1] . start_port)
  1806. return FALSE;
  1807. }
  1808. return TRUE;
  1809. }
  1810. /* Check that add and delete apis work fine. Verify this through calls to GetNum, Enum, GetPort */
  1811. void check_add_delete_port_rules (PWLBS_REG_PARAMS reg_data,
  1812. PWLBS_PORT_RULE rule_list,
  1813. DWORD num_rules,
  1814. DWORD range)
  1815. {
  1816. DWORD status;
  1817. DWORD num_rules1, num_rules2;
  1818. WLBS_PORT_RULE rule, rules [WLBS_MAX_RULES];
  1819. DWORD i, j, port;
  1820. /* First check the addportrule functionality.
  1821. * After adding each rule, check that GetNumPortRules returns the correct value.
  1822. * Verify that EnumPortRules also returns the correct number of rules
  1823. */
  1824. for (i = 0 ; i < WLBS_MAX_RULES ; i++)
  1825. {
  1826. j = (i * range) % num_rules;
  1827. status = WlbsAddPortRule (reg_data, &rule_list [j] );
  1828. verify_return_value (_TEXT("AddPortRule"), WLBS_OK, status);
  1829. num_rules1 = WlbsGetNumPortRules (reg_data);
  1830. verify_return_value (_TEXT("GetNumPortRules"), i+1, num_rules1);
  1831. num_rules2 = WLBS_MAX_RULES;
  1832. status = WlbsEnumPortRules (reg_data, rules, &num_rules2);
  1833. verify_return_value (_TEXT("EnumPortRules"), WLBS_OK, status);
  1834. verify_return_value (_TEXT("EnumPortRules and GetNum"), num_rules1, num_rules2);
  1835. if (!verify_enum_port_rules (rules, num_rules2))
  1836. {
  1837. add_error (_TEXT("Error in Verifying EnumPortRules. Aborting tests"));
  1838. return;
  1839. }
  1840. /* Verify that GetPortRule returns the correct port rule that was added
  1841. * Do a GetPortRule on the start port, the end port as well as on any port
  1842. * number in between.
  1843. */
  1844. if (j%3 == 0)
  1845. port = rule_list [j] . start_port;
  1846. else if (j%3 == 1)
  1847. port = rule_list [j] . end_port;
  1848. else
  1849. port = (rule_list [j] . start_port + rule_list [j] . end_port)/2;
  1850. status = WlbsGetPortRule (reg_data, port, & rule);
  1851. verify_return_value (_TEXT("GetPortRule"), WLBS_OK, status);
  1852. /* These two fields are set when the rule is added */
  1853. rule_list [j] . i_valid = rule . i_valid;
  1854. rule_list [j] . i_code = rule . i_code;
  1855. if (memcmp (&rule, &rule_list [j], sizeof (WLBS_PORT_RULE)) )
  1856. add_error (_TEXT("Port rule that was added is changed when retrieved"));
  1857. }
  1858. /* Now there is no space for any further rules.
  1859. * Try to add the remaining rules.
  1860. * WlbsAddPortRule should return WLBS_MAX_PORT_RULES each time.
  1861. * Also, get port rule should return WLBS_NOT_FOUND
  1862. */
  1863. for (i = WLBS_MAX_RULES; i < num_rules; i++)
  1864. {
  1865. j = (i * range) % num_rules;
  1866. status = WlbsAddPortRule (reg_data, & rule_list [j]);
  1867. verify_return_value (_TEXT("AddPortRule more than 32 rules"), WLBS_MAX_PORT_RULES, status);
  1868. port = rule_list [j] . start_port;
  1869. status = WlbsGetPortRule (reg_data, port, &rule);
  1870. verify_return_value (_TEXT("GetPortRule non-existent rule"), WLBS_NOT_FOUND, status);
  1871. verify_return_value (_TEXT("GetNumPortRules when max rules"), WLBS_MAX_RULES,
  1872. WlbsGetNumPortRules(reg_data));
  1873. }
  1874. /* Test delete functionality.
  1875. * Pass the start port, end port or any intermediate port number as input.
  1876. * Verify that the port rule has indeed been deleted by checking GetNumPortRules,
  1877. * EnumPortRules as well GetPortRule
  1878. */
  1879. for (i = 0 ; i < WLBS_MAX_RULES; i ++)
  1880. {
  1881. j = (i * range) % num_rules;
  1882. if (j%3 == 0)
  1883. port = rule_list [j] . start_port;
  1884. else if (j%3 == 1)
  1885. port = rule_list [j] . end_port;
  1886. else
  1887. port = (rule_list [j] . start_port + rule_list [j] . end_port) / 2;
  1888. status = WlbsDeletePortRule (reg_data, port);
  1889. verify_return_value (_TEXT("DeletePortRule"), WLBS_OK, status);
  1890. num_rules1 = WlbsGetNumPortRules (reg_data);
  1891. verify_return_value (_TEXT("GetNumPortRules after deleting"), WLBS_MAX_RULES - i - 1, num_rules1);
  1892. num_rules2 = WLBS_MAX_RULES;
  1893. status = WlbsEnumPortRules (reg_data, rules, &num_rules2);
  1894. verify_return_value (_TEXT("EnumPortRules after deleting"), WLBS_OK, status);
  1895. verify_return_value (_TEXT("EnumPortRules and GetNum after deleting"), num_rules1, num_rules2);
  1896. if (!verify_enum_port_rules (rules, num_rules2))
  1897. {
  1898. add_error (_TEXT("Error in Verifying EnumPortRules. Aborting tests"));
  1899. return;
  1900. }
  1901. status = WlbsGetPortRule (reg_data, port, & rule);
  1902. verify_return_value (_TEXT("GetPortRule after deleting"), WLBS_NOT_FOUND, status);
  1903. }
  1904. /* Try to delete the remaining rules. WLBS_NOT_FOUND should be returned in all cases.
  1905. * Also, GetNumPortRules should return 0 always */
  1906. for (i = WLBS_MAX_RULES; i < num_rules; i++)
  1907. {
  1908. j = (i * range) % num_rules;
  1909. status = WlbsDeletePortRule (reg_data, rule_list [j] . start_port);
  1910. verify_return_value (_TEXT("DeletePortRule on empty rule list"), WLBS_NOT_FOUND, status);
  1911. verify_return_value (_TEXT("GetNumPortRules on empty rule list"), 0,
  1912. WlbsGetNumPortRules(reg_data));
  1913. }
  1914. return;
  1915. }
  1916. void port_rule_functional_test (PWLBS_REG_PARAMS reg_data)
  1917. {
  1918. #define MAX_RULES 50
  1919. WLBS_PORT_RULE rule1, rule2, rule_list1 [MAX_RULES], rule_list2 [WLBS_MAX_RULES];
  1920. DWORD status1, status2;
  1921. DWORD num_rules1, num_rules2;
  1922. /* Delete all the existing rules. Add invalid rules and check that the error is detected.
  1923. * Add new rules in both sorted and unsorted order and then do an enum to verify that
  1924. * the rules get sorted. Verify that GetNumPortRules returns the correct value each time.
  1925. * Delete the rules in random order and also in sorted order. Verify that the rule is
  1926. * indeed deleted. Also, verify that enum returns all the rules in sorted order.
  1927. */
  1928. delete_all_rules (reg_data);
  1929. generate_valid_rules (rule_list1, MAX_RULES, 500);
  1930. rule1 = rule_list1 [0];
  1931. /* First, try adding invalid rules. The return value should be WLBS_BAD_PORT_PARAMS */
  1932. /* The invalid cases are listed in the apitest.c file */
  1933. /* start port > end port */
  1934. rule1 . start_port = rule1 . end_port + 1;
  1935. status1 = WlbsAddPortRule (reg_data, &rule1);
  1936. verify_return_value (_TEXT("AddPortRule sp > ep"), WLBS_BAD_PORT_PARAMS, status1);
  1937. /* invalid start port */
  1938. rule1 . start_port = CVY_MAX_PORT + 1;
  1939. rule1 . end_port = rule1 . start_port;
  1940. status1 = WlbsAddPortRule (reg_data, &rule1);
  1941. verify_return_value (_TEXT("AddPortRule sp > MAX_PORT"), WLBS_BAD_PORT_PARAMS, status1);
  1942. /* invalid end port */
  1943. rule1 . start_port = 80;
  1944. rule1 . end_port = CVY_MAX_PORT + 1;
  1945. status1 = WlbsAddPortRule (reg_data, &rule1);
  1946. verify_return_value (_TEXT("AddPortRule sp = 80 ep > MAX_PORT"), WLBS_BAD_PORT_PARAMS, status1);
  1947. /* invalid protocol */
  1948. rule1 = rule_list1 [0];
  1949. rule1 . protocol = CVY_MIN_PROTOCOL - 1;
  1950. status1 = WlbsAddPortRule (reg_data, &rule1);
  1951. verify_return_value (_TEXT("AddPortRule InvalidProtocol"), WLBS_BAD_PORT_PARAMS, status1);
  1952. rule1 . protocol = CVY_MAX_PROTOCOL + 1;
  1953. status1 = WlbsAddPortRule (reg_data, &rule1);
  1954. verify_return_value (_TEXT("AddPortRule InvalidProtocol"), WLBS_BAD_PORT_PARAMS, status1);
  1955. rule1 . protocol = CVY_MAX_PROTOCOL;
  1956. /* invalid mode */
  1957. rule1 . mode = CVY_MIN_MODE - 1;
  1958. status1 = WlbsAddPortRule (reg_data, &rule1);
  1959. verify_return_value (_TEXT("AddPortRule InvalidMode"), WLBS_BAD_PORT_PARAMS, status1);
  1960. rule1 . mode = CVY_MAX_MODE + 1;
  1961. status1 = WlbsAddPortRule (reg_data, &rule1);
  1962. verify_return_value (_TEXT("AddPortRule InvalidMode"), WLBS_BAD_PORT_PARAMS, status1);
  1963. /* invalid priority */
  1964. rule1 . mode = CVY_SINGLE;
  1965. rule1 . mode_data . single . priority = CVY_MIN_PRIORITY - 1;
  1966. status1 = WlbsAddPortRule (reg_data, &rule1);
  1967. verify_return_value (_TEXT("AddPortRule InvalidPriority"), WLBS_BAD_PORT_PARAMS, status1);
  1968. rule1 . mode_data . single . priority = CVY_MAX_PRIORITY + 1;
  1969. status1 = WlbsAddPortRule (reg_data, &rule1);
  1970. verify_return_value (_TEXT("AddPortRule InvalidPriority"), WLBS_BAD_PORT_PARAMS, status1);
  1971. /* invalid affinity */
  1972. rule1 . mode = CVY_MULTI;
  1973. rule1 . mode_data . multi . affinity = CVY_MAX_AFFINITY + 1;
  1974. status1 = WlbsAddPortRule (reg_data, &rule1);
  1975. verify_return_value (_TEXT("AddPortRule InvalidAffinity"), WLBS_BAD_PORT_PARAMS, status1);
  1976. /* invalid equal load */
  1977. rule1 . mode_data . multi . affinity = CVY_MAX_AFFINITY;
  1978. rule1 . mode_data . multi . equal_load = CVY_MAX_EQUAL_LOAD + 1;
  1979. status1 = WlbsAddPortRule (reg_data, &rule1);
  1980. verify_return_value (_TEXT("AddPortRule InvalidEqualLoad"), WLBS_BAD_PORT_PARAMS, status1);
  1981. /* invalid load */
  1982. rule1 . mode_data . multi . equal_load = CVY_MIN_EQUAL_LOAD;
  1983. rule1 . mode_data . multi . load = CVY_MAX_LOAD + 1;
  1984. status1 = WlbsAddPortRule (reg_data, &rule1);
  1985. verify_return_value (_TEXT("AddPortRule InvalidLoad"), WLBS_BAD_PORT_PARAMS, status1);
  1986. /* add a valid rule and then test for overlapping rules
  1987. * Test the different cases where overlapping can occur
  1988. */
  1989. rule1 = rule_list1 [1];
  1990. status1 = WlbsAddPortRule (reg_data, &rule1);
  1991. verify_return_value (_TEXT("AddPortRule ValidRule"), WLBS_OK, status1);
  1992. rule2 = rule1;
  1993. status1 = WlbsAddPortRule (reg_data, &rule2);
  1994. verify_return_value (_TEXT("AddPortRule Overlap. same start and end ports"), WLBS_PORT_OVERLAP, status1);
  1995. rule2 . start_port = rule1 . start_port + 1;
  1996. rule2 . end_port = rule2 . end_port - 1;
  1997. status1 = WlbsAddPortRule (reg_data, &rule2);
  1998. verify_return_value (_TEXT("AddPortRule Overlap 2 "), WLBS_PORT_OVERLAP, status1);
  1999. rule2 . start_port = rule1 . start_port - 1;
  2000. rule2 . end_port = rule2 . end_port + 1;
  2001. status1 = WlbsAddPortRule (reg_data, &rule2);
  2002. verify_return_value (_TEXT("AddPortRule Overlap 3 "), WLBS_PORT_OVERLAP, status1);
  2003. /* The following two tests would fail if the start port and the end port both are the same */
  2004. rule2 . start_port = rule1 . start_port - 1;
  2005. rule2 . end_port = rule2 . end_port - 1;
  2006. status1 = WlbsAddPortRule (reg_data, &rule2);
  2007. verify_return_value (_TEXT("AddPortRule Overlap 4 "), WLBS_PORT_OVERLAP, status1);
  2008. rule2 . start_port = rule1 . start_port + 1;
  2009. rule2 . end_port = rule2 . end_port + 1;
  2010. status1 = WlbsAddPortRule (reg_data, &rule2);
  2011. verify_return_value (_TEXT("AddPortRule Overlap 5 "), WLBS_PORT_OVERLAP, status1);
  2012. status1 = WlbsDeletePortRule (reg_data, rule1 . start_port);
  2013. verify_return_value (_TEXT("DeletePortRule"), WLBS_OK, status1);
  2014. /* First test the APIs by inserting and deleting the rules in sorted order */
  2015. check_add_delete_port_rules (reg_data, rule_list1, MAX_RULES, 1);
  2016. /* Then test the APIs by inserting and deleting the rules in pseudo - unsorted order */
  2017. check_add_delete_port_rules (reg_data, rule_list1, MAX_RULES, 7);
  2018. return;
  2019. #undef MAX_RULES
  2020. }
  2021. void check_port_rule_apis ()
  2022. {
  2023. WLBS_REG_PARAMS saved, reg_data;
  2024. DWORD status;
  2025. if (global_init == WLBS_REMOTE_ONLY || global_init == WLBS_INIT_ERROR)
  2026. {
  2027. add_error (_TEXT("WLBS is not installed on this host. Port rule apis cannot be tested"));
  2028. return;
  2029. }
  2030. /* Save the existing configuration */
  2031. status = WlbsReadReg (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST, &saved);
  2032. status = WlbsReadReg (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST, &reg_data);
  2033. port_rule_parameter_test (&reg_data);
  2034. port_rule_functional_test (&reg_data);
  2035. status = WlbsWriteReg (WLBS_LOCAL_CLUSTER, WLBS_LOCAL_HOST, &saved);
  2036. return;
  2037. }
  2038. void print_error_messages ()
  2039. {
  2040. PErr_Struct temp;
  2041. DWORD i = 0;
  2042. while (headq)
  2043. {
  2044. temp = headq;
  2045. i++;
  2046. _tprintf (_TEXT("Error %d %s\n"), i, temp -> comment);
  2047. headq = headq -> next;
  2048. free(temp);
  2049. }
  2050. return;
  2051. }
  2052. #define INTERNET_ADDRESS "111.111.11.11"
  2053. /* This function tests WlbsResolve, WlbsAddressToString and WlbsAddressToName */
  2054. void check_winsock_wrappers ()
  2055. {
  2056. DWORD lenp;
  2057. DWORD address;
  2058. TCHAR buf1[5], buf2[20], buf3[100], buf4[100];
  2059. CHAR cbuf[100], cbuf2[20];
  2060. int len = 1000;
  2061. struct hostent * host;
  2062. _stprintf (status_buf, _TEXT("Verifying Winsock Wrappers"));
  2063. verify_return_value (_TEXT("WlbsResolve on invalid name"), WlbsResolve(_TEXT("junkname")), 0);
  2064. gethostname (cbuf, len); /* Assume that this function does not fail */
  2065. #ifdef UNICODE
  2066. swprintf (buf4, _TEXT("%S"), cbuf);
  2067. #else
  2068. sprintf (buf4, "%s", cbuf);
  2069. #endif
  2070. host = gethostbyname (cbuf);
  2071. if (host == NULL)
  2072. {
  2073. add_error(_TEXT("gethostbyname failed, aborting winsock wrapper test\n"));
  2074. return;
  2075. }
  2076. verify_return_value (_TEXT("WlbsResolve on null name"), WlbsResolve(NULL),0);
  2077. address = ((struct in_addr *) (host -> h_addr)) -> s_addr;
  2078. verify_return_value (_TEXT("WlbsResolve on local machine name"), WlbsResolve(buf4),
  2079. address);
  2080. verify_return_value (_TEXT("WlbsResolve on valid dotted notation"),
  2081. WlbsResolve(_TEXT("111.111.111.111")),
  2082. inet_addr ("111.111.111.111"));
  2083. verify_return_value (_TEXT("WlbsResolve on invalid dotted notation"),
  2084. WlbsResolve(_TEXT("333.111.111.111")), 0);
  2085. lenp = 0;
  2086. verify_return_value (_TEXT("WlbsAddressToString on null buffer"),
  2087. WlbsAddressToString (address , NULL, &lenp),
  2088. FALSE );
  2089. verify_return_value (_TEXT("WlbsAddressToString required buffer length"),
  2090. strlen (inet_ntoa (* ((struct in_addr *) &address)) ) + 1, lenp);
  2091. lenp = 5;
  2092. verify_return_value (_TEXT("WlbsAddressToString on insufficient buffer"),
  2093. WlbsAddressToString (address , buf1, &lenp),
  2094. FALSE );
  2095. verify_return_value (_TEXT("WlbsAddressToString required buffer length"),
  2096. strlen (inet_ntoa (* ((struct in_addr *) &address)) ) + 1, lenp);
  2097. lenp = 20;
  2098. verify_return_value (_TEXT("WlbsAddressToString on sufficient buffer"),
  2099. WlbsAddressToString (address , buf2, &lenp),
  2100. TRUE );
  2101. verify_return_value (_TEXT("WlbsAddressToString required buffer length"),
  2102. strlen (inet_ntoa (* ((struct in_addr *) &address)) ) + 1, lenp);
  2103. #ifdef UNICODE
  2104. sprintf (cbuf2, "%ls", buf2);
  2105. #else
  2106. sprintf (cbuf2, "%s", buf2);
  2107. #endif
  2108. if (_stricmp (cbuf2, inet_ntoa (* ((struct in_addr *) &address))) )
  2109. {
  2110. _stprintf (tbuf,
  2111. _TEXT("WlbsAddressToString return was different from the value supplied. Expected %S Got %S"),
  2112. cbuf2, inet_ntoa (* ((struct in_addr *) &address)) );
  2113. add_error (tbuf);
  2114. }
  2115. /* WlbsAddressToName */
  2116. lenp = 0;
  2117. verify_return_value (_TEXT("WlbsAddressToName on null buffer"),
  2118. FALSE,
  2119. WlbsAddressToName (address, NULL, &lenp));
  2120. verify_return_value (_TEXT("WlbsAddressToName required buffer length"),
  2121. strlen ((gethostbyaddr ((char *) & address, sizeof (DWORD), AF_INET)) -> h_name) + 1,
  2122. lenp);
  2123. lenp = 5;
  2124. verify_return_value (_TEXT("WlbsAddressToName on insufficient buffer"),
  2125. FALSE,
  2126. WlbsAddressToName (address , buf1, &lenp));
  2127. verify_return_value (_TEXT("WlbsAddressToName required buffer length"),
  2128. strlen ((gethostbyaddr ((char *) & address, sizeof (DWORD), AF_INET)) -> h_name) + 1,
  2129. lenp);
  2130. lenp = 100;
  2131. verify_return_value (_TEXT("WlbsAddressToName on sufficient buffer"),
  2132. TRUE,
  2133. WlbsAddressToName (address , buf3, &lenp));
  2134. verify_return_value (_TEXT("WlbsAddressToName required buffer length"),
  2135. strlen ((gethostbyaddr ((char *) & address, sizeof (DWORD), AF_INET)) -> h_name) + 1,
  2136. lenp);
  2137. sprintf (cbuf, "%s", (gethostbyaddr ((char *) & address, sizeof (DWORD), AF_INET)) -> h_name);
  2138. #ifdef UNICODE
  2139. swprintf (buf4, L"%S", cbuf);
  2140. #else
  2141. sprintf (buf4, "%s", cbuf);
  2142. #endif
  2143. if (_tcsicmp (buf3, buf4) )
  2144. {
  2145. _stprintf (tbuf,
  2146. _TEXT("WlbsAddressToName return was different from the value supplied. Expected %s Got %s"),
  2147. buf4, buf3);
  2148. add_error (tbuf);
  2149. }
  2150. return;
  2151. }
  2152. void print_usage ()
  2153. {
  2154. printf("Usage : wlbsapitest [local] [remote cl_ip host_ip] [init] [verbose] [reboot 1|2|3] [timeout t]\n");
  2155. printf("local : for local cluster/host tests\n");
  2156. printf("remote : for remote cluster/host tests\n");
  2157. printf("init : for testing a WlbsInit special case\n");
  2158. printf("verbose: for printing the tests as they are carried out\n");
  2159. printf("reboot : for testing commit on nt4 machines. Contact kumar for further info.\n");
  2160. printf("timeout: for specifying the timeout value for cluster-wide queries. Specify it in milliseconds\n");
  2161. return;
  2162. }
  2163. INT __cdecl _tmain
  2164. (
  2165. INT argc,
  2166. PTCHAR __targv []
  2167. )
  2168. {
  2169. DWORD i;
  2170. INT arg_count;
  2171. OSVERSIONINFO osiv;
  2172. DWORD entry_point = 0;
  2173. if (argc == 1)
  2174. {
  2175. print_usage();
  2176. return 1;
  2177. }
  2178. /* Now parse the command line */
  2179. arg_count = 1;
  2180. while (arg_count < argc)
  2181. {
  2182. do {
  2183. if ( ! _tcsicmp (__targv [arg_count], _TEXT("local")) )
  2184. {
  2185. local_test = TRUE;
  2186. arg_count++;
  2187. break;
  2188. }
  2189. if ( ! _tcsicmp (__targv [arg_count], _TEXT("remote")) )
  2190. {
  2191. if ( (argc - arg_count) <= 2)
  2192. {
  2193. print_usage ();
  2194. return 1;
  2195. }
  2196. remote_cl_ip = WlbsResolve (__targv [arg_count + 1]);
  2197. remote_host_ip = WlbsResolve (__targv [arg_count + 2]);
  2198. remote_test = TRUE;
  2199. arg_count += 3;
  2200. break;
  2201. }
  2202. if ( ! _tcsicmp (__targv [arg_count], _TEXT("verbose")) )
  2203. {
  2204. verbose = TRUE;
  2205. arg_count ++;
  2206. break;
  2207. }
  2208. if ( ! _tcsicmp (__targv [arg_count], _TEXT("init")) )
  2209. {
  2210. init_test = TRUE;
  2211. arg_count ++;
  2212. break;
  2213. }
  2214. if ( ! _tcsicmp (__targv [arg_count], _TEXT("timeout")) )
  2215. {
  2216. if (argc - arg_count <= 1)
  2217. {
  2218. print_usage ();
  2219. return 1;
  2220. }
  2221. timeout = _ttoi ( __targv [arg_count + 1] );
  2222. arg_count += 2;
  2223. break;
  2224. }
  2225. if ( ! _tcsicmp (__targv [arg_count], _TEXT("reboot")) )
  2226. {
  2227. if (argc - arg_count <= 1)
  2228. {
  2229. print_usage ();
  2230. return 1;
  2231. }
  2232. entry_point = _ttoi ( __targv [arg_count + 1] );
  2233. arg_count += 2;
  2234. if (entry_point > 3)
  2235. {
  2236. print_usage ();
  2237. return 1;
  2238. }
  2239. break;
  2240. }
  2241. print_usage ();
  2242. return 1;
  2243. } while ( 0 );
  2244. }
  2245. if (remote_test)
  2246. {
  2247. printf("Please enter the password for the remote host/cluster : ");
  2248. _tscanf (_TEXT("%s"), remote_password);
  2249. }
  2250. if (!verbose)
  2251. printf("Test Number: 0000");
  2252. /* Get the version info on the OS (nt4 or higher) and store the info. */
  2253. memset (&osiv, 0, sizeof (OSVERSIONINFO));
  2254. osiv . dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
  2255. if (GetVersionEx(&osiv) == 0)
  2256. printf("error in getting the os version\n");
  2257. version_nt4 = (osiv . dwPlatformId == VER_PLATFORM_WIN32_NT) &&
  2258. (osiv . dwMajorVersion == 4);
  2259. check_init();
  2260. if (init_test)
  2261. {
  2262. printf("\n");
  2263. print_error_messages();
  2264. printf("Total number of tests: %d Failed Tests: %d\n", total_tests, failed_tests);
  2265. return 1;
  2266. }
  2267. if (version_nt4)
  2268. if (entry_point != 0)
  2269. {
  2270. check_commit (entry_point);
  2271. return 1;
  2272. }
  2273. check_single_host_operations();
  2274. check_cluster_operations();
  2275. if (!local_test)
  2276. {
  2277. printf("\n");
  2278. print_error_messages();
  2279. printf("Total number of tests: %d Failed Tests: %d\n", total_tests, failed_tests);
  2280. return 1;
  2281. }
  2282. check_port_rule_apis();
  2283. check_registry_rw();
  2284. check_commit(0);
  2285. check_winsock_wrappers();
  2286. printf("\n");
  2287. print_error_messages();
  2288. printf("Total number of tests: %d Failed Tests: %d\n", total_tests, failed_tests);
  2289. return 1;
  2290. }