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.

1842 lines
50 KiB

  1. /*
  2. NETWORK LOAD BALANCING - CONTROL API - TEST UTILITY
  3. Copyright (C), 1999 by Microsoft Corporation
  4. PROPRIETARY TRADE SECRET INFORMATION OF MICROSOFT CORPORATION
  5. The information contained in this file is not to be disclosed or copied in any
  6. form or distributed to a third party without written permission from Microsoft
  7. Corporation.
  8. THE SOFTWARE IS PROVIDED TO YOU "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
  9. EXPRESSED, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF
  10. MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
  11. $Archive:: $
  12. $Revision:: $
  13. $Author:: $
  14. $Date:: $
  15. $Modtime:: $
  16. $Nokeywords:: $
  17. */
  18. #include <windows.h>
  19. #include <stdlib.h>
  20. #include <stdio.h>
  21. #include <conio.h>
  22. #include <string.h>
  23. #include <winsock.h>
  24. #include <tchar.h>
  25. #include "wlbsctrl.h"
  26. #include "wlbsconfig.h"
  27. #define stricmp strcmp
  28. /* TYPES */
  29. typedef enum
  30. {
  31. query,
  32. suspend,
  33. resume,
  34. start,
  35. stop,
  36. drainstop,
  37. enable,
  38. disable,
  39. drain
  40. }
  41. WLBS_CMD;
  42. /* GLOBALS */
  43. #define BUF_SIZE 80
  44. static CHAR buf [BUF_SIZE];
  45. static CHAR buf2 [BUF_SIZE];
  46. static TCHAR tbuf [BUF_SIZE];
  47. static TCHAR tbuf2 [BUF_SIZE];
  48. static WLBS_RESPONSE resp [WLBS_MAX_HOSTS];
  49. /* PROCEDURES */
  50. void generate_port_rules ( PWLBS_PORT_RULE rules, DWORD num_rules, DWORD range );
  51. void delete_all_rules ( PWLBS_REG_PARAMS reg_data );
  52. void test_commit ( PWLBS_REG_PARAMS reg_data, BOOL flag1, BOOL flag2 );
  53. DWORD testnewapi (void);
  54. INT __cdecl _tmain
  55. (
  56. INT argc,
  57. PTCHAR __targv []
  58. )
  59. {
  60. DWORD ret;
  61. DWORD status;
  62. INT arg_index;
  63. WLBS_CMD cmd;
  64. DWORD port;
  65. DWORD cluster;
  66. DWORD host;
  67. PCHAR hp;
  68. PTCHAR thp;
  69. DWORD i;
  70. DWORD hosts;
  71. DWORD host_map;
  72. DWORD buf_size = BUF_SIZE;
  73. printf ("WLBS Control API V1.0 (c) 1999 by Microsoft Corporation\n");
  74. /* initialize convoy control routines */
  75. ret = WlbsInit (_TEXT(WLBS_PRODUCT_NAME), WLBS_API_VER, NULL);
  76. switch (ret)
  77. {
  78. case WLBS_PRESENT:
  79. printf ("Can execute remote and local commands.\n");
  80. break;
  81. case WLBS_REMOTE_ONLY:
  82. printf ("Can execute local commands.\n");
  83. break;
  84. case WLBS_LOCAL_ONLY:
  85. printf ("Can execute remote commands.\n");
  86. break;
  87. default:
  88. printf ("Error initializing API.\n");
  89. return 2;
  90. }
  91. #if 0
  92. {
  93. WLBS_REG_PARAMS params;
  94. DWORD status;
  95. if ((status = WlbsLocalReadReg(& params)) != WLBS_OK)
  96. {
  97. printf("WlbsLocalReadReg error %d\n", status);
  98. return 1;
  99. }
  100. printf("WlbsLocalReadReg success\n");
  101. if (argc > 1)
  102. _tcsncpy(params.cl_ip_addr, _TEXT("172.31.240.176"), WLBS_MAX_CL_IP_ADDR);
  103. else
  104. _tcsncpy(params.cl_ip_addr, _TEXT("172.31.240.175"), WLBS_MAX_CL_IP_ADDR);
  105. if ((status = WlbsLocalWriteReg(& params)) != WLBS_OK)
  106. {
  107. printf("WlbsLocalWriteReg error %d\n", status);
  108. return 1;
  109. }
  110. printf("WlbsLocalWriteReg success\n");
  111. if ((status = WlbsLocalCommitChanges()) != WLBS_OK)
  112. {
  113. printf("WlbsLocalCommitChanges error %d\n", status);
  114. return 1;
  115. }
  116. printf("WlbsLocalCommitChanges success\n");
  117. return 1;
  118. }
  119. #endif
  120. arg_index = 1;
  121. if (argc < 2)
  122. goto usage;
  123. /* parse command line arguments */
  124. if (_tcsicmp (__targv[arg_index], _TEXT("testnewapi")) == 0)
  125. {
  126. testnewapi();
  127. return 1;
  128. }
  129. if (_tcsicmp (__targv [arg_index], _TEXT("suspend")) == 0)
  130. {
  131. cmd = suspend;
  132. arg_index ++;
  133. }
  134. else if (_tcsicmp (__targv [arg_index], _TEXT("resume")) == 0)
  135. {
  136. cmd = resume;
  137. arg_index ++;
  138. }
  139. else if (_tcsicmp (__targv [arg_index], _TEXT("start")) == 0)
  140. {
  141. cmd = start;
  142. arg_index ++;
  143. }
  144. else if (_tcsicmp (__targv [arg_index], _TEXT("stop")) == 0)
  145. {
  146. cmd = stop;
  147. arg_index ++;
  148. }
  149. else if (_tcsicmp (__targv [arg_index], _TEXT("drainstop")) == 0)
  150. {
  151. cmd = drainstop;
  152. arg_index ++;
  153. }
  154. else if (_tcsicmp (__targv [arg_index], _TEXT("query")) == 0)
  155. {
  156. cmd = query;
  157. arg_index ++;
  158. }
  159. else if (_tcsicmp (__targv [arg_index], _TEXT("enable")) == 0)
  160. {
  161. arg_index ++;
  162. if (argc < 3)
  163. goto usage;
  164. if (_tcsicmp (__targv [arg_index], _TEXT("all")) == 0)
  165. port = WLBS_ALL_PORTS;
  166. else
  167. port = _ttoi (__targv [arg_index]);
  168. if (port == 0 && __targv [arg_index][0] != _TEXT('0'))
  169. goto usage;
  170. cmd = enable;
  171. arg_index ++;
  172. }
  173. else if (_tcsicmp (__targv [arg_index], _TEXT("disable")) == 0)
  174. {
  175. arg_index ++;
  176. if (argc < 3)
  177. goto usage;
  178. if (_tcsicmp (__targv [arg_index], _TEXT("all")) == 0)
  179. port = WLBS_ALL_PORTS;
  180. else
  181. port = _ttoi (__targv [arg_index]);
  182. if (port == 0 && __targv [arg_index][0] != _TEXT('0'))
  183. goto usage;
  184. cmd = disable;
  185. arg_index ++;
  186. }
  187. else if (_tcsicmp (__targv [arg_index], _TEXT("drain")) == 0)
  188. {
  189. arg_index ++;
  190. if (argc < 3)
  191. goto usage;
  192. if (_tcsicmp (__targv [arg_index], _TEXT("all")) == 0)
  193. port = WLBS_ALL_PORTS;
  194. else
  195. port = _ttoi (__targv [arg_index]);
  196. if (port == 0 && __targv [arg_index][0] != _TEXT('0'))
  197. goto usage;
  198. cmd = drain;
  199. arg_index ++;
  200. }
  201. else
  202. goto usage;
  203. cluster = WLBS_LOCAL_CLUSTER;
  204. host = WLBS_LOCAL_HOST;
  205. /* parse remote command arguments */
  206. if (arg_index < argc)
  207. {
  208. thp = _tcschr (__targv [arg_index], _TEXT(':'));
  209. /* cluster-wide operation */
  210. if (thp == NULL)
  211. {
  212. cluster = WlbsResolve (__targv [arg_index]);
  213. if (cluster == 0)
  214. {
  215. _tprintf (_TEXT("Bad cluster %s\n"), __targv [arg_index]);
  216. return 1;
  217. }
  218. host = WLBS_ALL_HOSTS;
  219. }
  220. else
  221. {
  222. * thp = 0;
  223. thp ++;
  224. cluster = WlbsResolve (__targv [arg_index]);
  225. if (cluster == 0)
  226. {
  227. _tprintf (_TEXT("Bad cluster %s\n"), __targv [arg_index]);
  228. return 1;
  229. }
  230. if (_tcslen (thp) <= 2 && thp [0] >= _TEXT('0') && thp [0] <= _TEXT('9')
  231. && ((thp [1] >= _TEXT('0') && thp [1] <= _TEXT('9')) || thp [1] == 0))
  232. {
  233. host = _ttoi (thp);
  234. }
  235. else
  236. {
  237. host = WlbsResolve (thp);
  238. if (host == 0)
  239. {
  240. _tprintf (_TEXT("Bad host %s\n"), thp);
  241. return 1;
  242. }
  243. }
  244. }
  245. arg_index ++;
  246. /* parse remote control parameters */
  247. while (arg_index < argc)
  248. {
  249. if (__targv [arg_index] [0] == _TEXT('/') || __targv [arg_index] [0] == _TEXT('-'))
  250. {
  251. if (_tcsicmp (__targv [arg_index] + 1, _TEXT("PASSW")) == 0)
  252. {
  253. arg_index ++;
  254. if (arg_index >= argc || __targv [arg_index] [0] == _TEXT('/') ||
  255. __targv [arg_index] [0] == _TEXT('-'))
  256. {
  257. printf ("Password: ");
  258. for (i = 0; i < BUF_SIZE; i ++)
  259. {
  260. buf [i] = (CHAR) _getch ();
  261. if (buf [i] == 13)
  262. {
  263. buf [i] = 0;
  264. break;
  265. }
  266. }
  267. printf ("\n");
  268. if (i == 0)
  269. WlbsPasswordSet (cluster, NULL);
  270. else
  271. {
  272. #ifdef UNICODE
  273. _stprintf (tbuf, _TEXT("%S"), buf);
  274. #else
  275. _stprintf (tbuf, _TEXT("%s"), buf);
  276. #endif
  277. WlbsPasswordSet (cluster, tbuf);
  278. }
  279. }
  280. else
  281. {
  282. WlbsPasswordSet (cluster, __targv [arg_index]);
  283. arg_index ++;
  284. }
  285. }
  286. else if (_tcsicmp (__targv [arg_index] + 1, _TEXT("PORT")) == 0)
  287. {
  288. arg_index ++;
  289. if (arg_index >= argc || __targv [arg_index] [0] == _TEXT('/') ||
  290. __targv [arg_index] [0] == _TEXT('-'))
  291. goto usage;
  292. WlbsPortSet (cluster, (USHORT) _ttoi (__targv [arg_index]));
  293. if (port == 0)
  294. goto usage;
  295. arg_index ++;
  296. }
  297. else if (_tcsicmp (__targv [arg_index] + 1, _TEXT("DEST")) == 0)
  298. {
  299. arg_index ++;
  300. if (arg_index >= argc || __targv [arg_index] [0] == _TEXT('/') ||
  301. __targv [arg_index] [0] == _TEXT('-'))
  302. goto usage;
  303. WlbsDestinationSet (cluster, WlbsResolve (__targv [arg_index]));
  304. arg_index ++;
  305. }
  306. else if (_tcsicmp (__targv [arg_index] + 1, _TEXT("TIMEOUT")) == 0)
  307. {
  308. arg_index ++;
  309. if (arg_index >= argc || __targv [arg_index] [0] == _TEXT('/') ||
  310. __targv [arg_index] [0] == _TEXT('-'))
  311. goto usage;
  312. WlbsTimeoutSet (cluster, _ttoi (__targv [arg_index]));
  313. arg_index ++;
  314. }
  315. else
  316. goto usage;
  317. }
  318. else
  319. goto usage;
  320. }
  321. }
  322. /* execute command */
  323. hosts = WLBS_MAX_HOSTS;
  324. switch (cmd)
  325. {
  326. case query:
  327. status = WlbsQuery (cluster, host, resp, &hosts, &host_map, NULL);
  328. switch (status)
  329. {
  330. case WLBS_INIT_ERROR:
  331. printf ("WLBS Control API not initialized.\n");
  332. return 2;
  333. case WLBS_LOCAL_ONLY:
  334. printf ("Can only execute local commands.\n");
  335. return 2;
  336. case WLBS_REMOTE_ONLY:
  337. printf ("Can only execute remote commands.\n");
  338. return 2;
  339. case WLBS_BAD_PASSW:
  340. printf ("Bad password specified.\n");
  341. return 2;
  342. case WLBS_TIMEOUT:
  343. printf ("Timed out awaiting response.\n");
  344. return 2;
  345. case WLBS_IO_ERROR:
  346. printf ("Error connecting to WLBS device.\n");
  347. return 2;
  348. case WLBS_STOPPED:
  349. if (host == WLBS_ALL_HOSTS)
  350. printf ("All cluster hosts are stopped.\n");
  351. else
  352. printf ("Cluster host %d is stopped.\n", resp [0] . id);
  353. break;
  354. case WLBS_SUSPENDED:
  355. if (host == WLBS_ALL_HOSTS)
  356. printf ("All cluster hosts are suspended.\n");
  357. else
  358. printf ("Cluster host %d is suspended.\n", resp [0] . id);
  359. break;
  360. case WLBS_CONVERGING:
  361. if (host == WLBS_ALL_HOSTS)
  362. printf ("Cluster is converging.\n");
  363. else
  364. printf ("Cluster host %d is converging.\n", resp [0] . id);
  365. break;
  366. case WLBS_DRAINING:
  367. if (host == WLBS_ALL_HOSTS)
  368. printf ("Cluster is draining.\n");
  369. else
  370. printf ("Cluster host %d is draining.\n", resp [0] . id);
  371. break;
  372. case WLBS_CONVERGED:
  373. printf ("Cluster host %d is converged.\n", resp [0] . id);
  374. break;
  375. case WLBS_DEFAULT:
  376. printf ("Cluster host %d is converged as DEFAULT.\n", resp [0] . id);
  377. break;
  378. default:
  379. if (status >= WSABASEERR)
  380. {
  381. printf ("WinSock error %d.\n", status);
  382. return 2;
  383. }
  384. printf ("There are %d active hosts in the cluster.\n", status);
  385. }
  386. if (host == WLBS_ALL_HOSTS)
  387. {
  388. printf ("Received responses from %d hosts:\n", hosts);
  389. for (i = 0; i < hosts && i < WLBS_MAX_HOSTS; i ++)
  390. {
  391. buf_size = BUF_SIZE;
  392. WlbsAddressToString (resp [i] . address, tbuf, & buf_size);
  393. buf_size = BUF_SIZE;
  394. WlbsAddressToName (resp [i] . address, tbuf2, & buf_size);
  395. _tprintf (_TEXT("Host %d [%s - %25s]: "), resp [i] . id, tbuf, tbuf2);
  396. switch (resp [i] . status)
  397. {
  398. case WLBS_STOPPED:
  399. printf ("stopped\n");
  400. break;
  401. case WLBS_CONVERGING:
  402. printf ("converging\n");
  403. break;
  404. case WLBS_DRAINING:
  405. printf ("draining\n");
  406. break;
  407. case WLBS_CONVERGED:
  408. printf ("converged\n");
  409. break;
  410. case WLBS_SUSPENDED:
  411. printf ("suspended\n");
  412. break;
  413. case WLBS_DEFAULT:
  414. printf ("converged as DEFAULT\n");
  415. break;
  416. }
  417. }
  418. }
  419. else
  420. {
  421. BOOL first = TRUE;
  422. printf ("The following hosts are part of the cluster:\n");
  423. for (i = 0; i < 32; i ++)
  424. {
  425. if (host_map & (1 << i))
  426. {
  427. if (! first)
  428. printf (", ");
  429. else
  430. first = FALSE;
  431. printf ("%d", i + 1);
  432. }
  433. }
  434. printf ("\n");
  435. }
  436. break;
  437. case suspend:
  438. status = WlbsSuspend (cluster, host, resp, & hosts);
  439. switch (status)
  440. {
  441. case WLBS_INIT_ERROR:
  442. printf ("WLBS Control API not initialized.\n");
  443. return 2;
  444. case WLBS_LOCAL_ONLY:
  445. printf ("Can only execute local commands.\n");
  446. return 2;
  447. case WLBS_REMOTE_ONLY:
  448. printf ("Can only execute remote commands.\n");
  449. return 2;
  450. case WLBS_BAD_PASSW:
  451. printf ("Bad password specified.\n");
  452. return 2;
  453. case WLBS_TIMEOUT:
  454. printf ("Timed out awaiting response.\n");
  455. return 2;
  456. case WLBS_IO_ERROR:
  457. printf ("Error connecting to WLBS device.\n");
  458. return 2;
  459. case WLBS_OK:
  460. if (host == WLBS_ALL_HOSTS)
  461. printf ("All cluster hosts suspended.\n");
  462. else
  463. printf ("Cluster mode control suspended.\n");
  464. break;
  465. case WLBS_ALREADY:
  466. printf ("Cluster mode control already suspended.\n");
  467. break;
  468. case WLBS_DRAIN_STOP:
  469. printf ("Cluster mode control suspended; draining preempted.\n");
  470. break;
  471. case WLBS_STOPPED:
  472. printf ("Cluster mode stopped and control suspended.\n");
  473. break;
  474. default:
  475. if (status >= WSABASEERR)
  476. {
  477. printf ("WinSock error %d.\n", status);
  478. return 2;
  479. }
  480. }
  481. if (host == WLBS_ALL_HOSTS)
  482. {
  483. printf ("Received responses from %d hosts:\n", hosts);
  484. for (i = 0; i < hosts && i < WLBS_MAX_HOSTS; i ++)
  485. {
  486. buf_size = BUF_SIZE;
  487. WlbsAddressToString (resp [i] . address, tbuf, & buf_size);
  488. buf_size = BUF_SIZE;
  489. WlbsAddressToName (resp [i] . address, tbuf2, & buf_size);
  490. _tprintf (_TEXT("Host %d [%s - %25s]: "), resp [i] . id, tbuf, tbuf2);
  491. switch (resp [i] . status)
  492. {
  493. case WLBS_OK:
  494. printf ("suspended\n");
  495. break;
  496. case WLBS_ALREADY:
  497. printf ("already suspended\n");
  498. break;
  499. case WLBS_DRAIN_STOP:
  500. printf ("suspended from draining\n");
  501. break;
  502. case WLBS_STOPPED:
  503. printf ("stopped and suspended\n");
  504. break;
  505. }
  506. }
  507. }
  508. break;
  509. case resume:
  510. status = WlbsResume (cluster, host, resp, & hosts);
  511. switch (status)
  512. {
  513. case WLBS_INIT_ERROR:
  514. printf ("WLBS Control API not initialized.\n");
  515. return 2;
  516. case WLBS_LOCAL_ONLY:
  517. printf ("Can only execute local commands.\n");
  518. return 2;
  519. case WLBS_REMOTE_ONLY:
  520. printf ("Can only execute remote commands.\n");
  521. return 2;
  522. case WLBS_BAD_PASSW:
  523. printf ("Bad password specified.\n");
  524. return 2;
  525. case WLBS_TIMEOUT:
  526. printf ("Timed out awaiting response.\n");
  527. return 2;
  528. case WLBS_IO_ERROR:
  529. printf ("Error connecting to WLBS device.\n");
  530. return 2;
  531. case WLBS_OK:
  532. if (host == WLBS_ALL_HOSTS)
  533. printf ("All cluster hosts resumed.\n");
  534. else
  535. printf ("Cluster mode control resumed.\n");
  536. break;
  537. case WLBS_ALREADY:
  538. printf ("Cluster mode control already resumed.\n");
  539. break;
  540. default:
  541. if (status >= WSABASEERR)
  542. {
  543. printf ("WinSock error %d.\n", status);
  544. return 2;
  545. }
  546. }
  547. if (host == WLBS_ALL_HOSTS)
  548. {
  549. printf ("Received responses from %d hosts:\n", hosts);
  550. for (i = 0; i < hosts && i < WLBS_MAX_HOSTS; i ++)
  551. {
  552. buf_size = BUF_SIZE;
  553. WlbsAddressToString (resp [i] . address, tbuf, & buf_size);
  554. buf_size = BUF_SIZE;
  555. WlbsAddressToName (resp [i] . address, tbuf2, & buf_size);
  556. _tprintf (_TEXT("Host %d [%s - %25s]: "), resp [i] . id, tbuf, tbuf2);
  557. switch (resp [i] . status)
  558. {
  559. case WLBS_OK:
  560. printf ("resumed\n");
  561. break;
  562. case WLBS_ALREADY:
  563. printf ("already resumed\n");
  564. break;
  565. }
  566. }
  567. }
  568. break;
  569. case start:
  570. status = WlbsStart (cluster, host, resp, & hosts);
  571. switch (status)
  572. {
  573. case WLBS_INIT_ERROR:
  574. printf ("WLBS Control API not initialized.\n");
  575. return 2;
  576. case WLBS_LOCAL_ONLY:
  577. printf ("Can only execute local commands.\n");
  578. return 2;
  579. case WLBS_REMOTE_ONLY:
  580. printf ("Can only execute remote commands.\n");
  581. return 2;
  582. case WLBS_BAD_PASSW:
  583. printf ("Bad password specified.\n");
  584. return 2;
  585. case WLBS_TIMEOUT:
  586. printf ("Timed out awaiting response.\n");
  587. return 2;
  588. case WLBS_IO_ERROR:
  589. printf ("Error connecting to WLBS device.\n");
  590. return 2;
  591. case WLBS_OK:
  592. if (host == WLBS_ALL_HOSTS)
  593. printf ("All cluster hosts started.\n");
  594. else
  595. printf ("Cluster mode started.\n");
  596. break;
  597. case WLBS_BAD_PARAMS:
  598. if (host == WLBS_ALL_HOSTS)
  599. printf ("Some host(s) could not start cluster mode due to parameter errors.\n");
  600. else
  601. printf ("Could not start cluster mode due to parameter errors.\n");
  602. break;
  603. case WLBS_ALREADY:
  604. printf ("Cluster mode already started.\n");
  605. break;
  606. case WLBS_SUSPENDED:
  607. if (host == WLBS_ALL_HOSTS)
  608. printf ("All cluster hosts suspended.\n");
  609. else
  610. printf ("Cluster mode control suspended.\n");
  611. break;
  612. case WLBS_DRAIN_STOP:
  613. printf ("Cluster mode started; draining preempted.\n");
  614. break;
  615. default:
  616. if (status >= WSABASEERR)
  617. {
  618. printf ("WinSock error %d.\n", status);
  619. return 2;
  620. }
  621. }
  622. if (host == WLBS_ALL_HOSTS)
  623. {
  624. printf ("Received responses from %d hosts:\n", hosts);
  625. for (i = 0; i < hosts && i < WLBS_MAX_HOSTS; i ++)
  626. {
  627. buf_size = BUF_SIZE;
  628. WlbsAddressToString (resp [i] . address, tbuf, & buf_size);
  629. buf_size = BUF_SIZE;
  630. WlbsAddressToName (resp [i] . address, tbuf2, & buf_size);
  631. _tprintf (_TEXT("Host %d [%s - %25s]: "), resp [i] . id, tbuf, tbuf2);
  632. switch (resp [i] . status)
  633. {
  634. case WLBS_OK:
  635. printf ("started\n");
  636. break;
  637. case WLBS_ALREADY:
  638. printf ("already started\n");
  639. break;
  640. case WLBS_SUSPENDED:
  641. printf ("control suspended\n");
  642. break;
  643. case WLBS_DRAIN_STOP:
  644. printf ("started from draining\n");
  645. break;
  646. case WLBS_BAD_PARAMS:
  647. printf ("bad parameters\n");
  648. break;
  649. }
  650. }
  651. }
  652. break;
  653. case stop:
  654. status = WlbsStop (cluster, host, resp, & hosts);
  655. switch (status)
  656. {
  657. case WLBS_INIT_ERROR:
  658. printf ("WLBS Control API not initialized.\n");
  659. return 2;
  660. case WLBS_LOCAL_ONLY:
  661. printf ("Can only execute local commands.\n");
  662. return 2;
  663. case WLBS_REMOTE_ONLY:
  664. printf ("Can only execute remote commands.\n");
  665. return 2;
  666. case WLBS_BAD_PASSW:
  667. printf ("Bad password specified.\n");
  668. return 2;
  669. case WLBS_TIMEOUT:
  670. printf ("Timed out awaiting response.\n");
  671. return 2;
  672. case WLBS_IO_ERROR:
  673. printf ("Error connecting to WLBS device.\n");
  674. return 2;
  675. case WLBS_OK:
  676. if (host == WLBS_ALL_HOSTS)
  677. printf ("All cluster hosts stopped.\n");
  678. else
  679. printf ("Cluster mode stopped.\n");
  680. break;
  681. case WLBS_ALREADY:
  682. printf ("Cluster mode already stopped.\n");
  683. break;
  684. case WLBS_SUSPENDED:
  685. if (host == WLBS_ALL_HOSTS)
  686. printf ("All cluster hosts suspended.\n");
  687. else
  688. printf ("Cluster mode control suspended.\n");
  689. break;
  690. case WLBS_DRAIN_STOP:
  691. printf ("Cluster mode stopped; draining preempted.\n");
  692. break;
  693. default:
  694. if (status >= WSABASEERR)
  695. {
  696. printf ("WinSock error %d.\n", status);
  697. return 2;
  698. }
  699. }
  700. if (host == WLBS_ALL_HOSTS)
  701. {
  702. printf ("Received responses from %d hosts:\n", hosts);
  703. for (i = 0; i < hosts && i < WLBS_MAX_HOSTS; i ++)
  704. {
  705. buf_size = BUF_SIZE;
  706. WlbsAddressToString (resp [i] . address, tbuf, & buf_size);
  707. buf_size = BUF_SIZE;
  708. WlbsAddressToName (resp [i] . address, tbuf2, & buf_size);
  709. _tprintf (_TEXT("Host %d [%s - %25s]: "), resp [i] . id, tbuf, tbuf2);
  710. switch (resp [i] . status)
  711. {
  712. case WLBS_OK:
  713. printf ("stopped\n");
  714. break;
  715. case WLBS_ALREADY:
  716. printf ("already stopped\n");
  717. break;
  718. case WLBS_SUSPENDED:
  719. printf ("control suspended\n");
  720. break;
  721. case WLBS_DRAIN_STOP:
  722. printf ("stopped from draining\n");
  723. break;
  724. }
  725. }
  726. }
  727. break;
  728. case drainstop:
  729. status = WlbsDrainStop (cluster, host, resp, & hosts);
  730. switch (status)
  731. {
  732. case WLBS_INIT_ERROR:
  733. printf ("WLBS Control API not initialized.\n");
  734. return 2;
  735. case WLBS_LOCAL_ONLY:
  736. printf ("Can only execute local commands.\n");
  737. return 2;
  738. case WLBS_REMOTE_ONLY:
  739. printf ("Can only execute remote commands.\n");
  740. return 2;
  741. case WLBS_BAD_PASSW:
  742. printf ("Bad password specified.\n");
  743. return 2;
  744. case WLBS_TIMEOUT:
  745. printf ("Timed out awaiting response.\n");
  746. return 2;
  747. case WLBS_IO_ERROR:
  748. printf ("Error connecting to WLBS device.\n");
  749. return 2;
  750. case WLBS_OK:
  751. if (host == WLBS_ALL_HOSTS)
  752. printf ("All cluster hosts set to drain.\n");
  753. else
  754. printf ("Draining started.\n");
  755. break;
  756. case WLBS_STOPPED:
  757. if (host == WLBS_ALL_HOSTS)
  758. printf ("Cluster mode stopped on all hosts.\n");
  759. else
  760. printf ("Cluster mode stopped.\n");
  761. break;
  762. case WLBS_ALREADY:
  763. printf ("Already draining.\n");
  764. break;
  765. case WLBS_SUSPENDED:
  766. if (host == WLBS_ALL_HOSTS)
  767. printf ("All cluster hosts suspended.\n");
  768. else
  769. printf ("Cluster mode control suspended.\n");
  770. break;
  771. default:
  772. if (status >= WSABASEERR)
  773. {
  774. printf ("WinSock error %d.\n", status);
  775. return 2;
  776. }
  777. }
  778. if (host == WLBS_ALL_HOSTS)
  779. {
  780. printf ("Received responses from %d hosts:\n", hosts);
  781. for (i = 0; i < hosts && i < WLBS_MAX_HOSTS; i ++)
  782. {
  783. buf_size = BUF_SIZE;
  784. WlbsAddressToString (resp [i] . address, tbuf, & buf_size);
  785. buf_size = BUF_SIZE;
  786. WlbsAddressToName (resp [i] . address, tbuf2, & buf_size);
  787. _tprintf (_TEXT("Host %d [%s - %25s]: "), resp [i] . id, tbuf, tbuf2);
  788. switch (resp [i] . status)
  789. {
  790. case WLBS_OK:
  791. printf ("draining\n");
  792. break;
  793. case WLBS_ALREADY:
  794. printf ("already draining\n");
  795. break;
  796. case WLBS_SUSPENDED:
  797. printf ("control suspended\n");
  798. break;
  799. case WLBS_STOPPED:
  800. printf ("stopped\n");
  801. break;
  802. }
  803. }
  804. }
  805. break;
  806. case enable:
  807. status = WlbsEnable (cluster, host, resp, & hosts, port);
  808. switch (status)
  809. {
  810. case WLBS_INIT_ERROR:
  811. printf ("WLBS Control API not initialized.\n");
  812. return 2;
  813. case WLBS_LOCAL_ONLY:
  814. printf ("Can only execute local commands.\n");
  815. return 2;
  816. case WLBS_REMOTE_ONLY:
  817. printf ("Can only execute remote commands.\n");
  818. return 2;
  819. case WLBS_BAD_PASSW:
  820. printf ("Bad password specified.\n");
  821. return 2;
  822. case WLBS_TIMEOUT:
  823. printf ("Timed out awaiting response.\n");
  824. return 2;
  825. case WLBS_IO_ERROR:
  826. printf ("Error connecting to WLBS device.\n");
  827. return 2;
  828. case WLBS_OK:
  829. if (host == WLBS_ALL_HOSTS)
  830. printf ("Port rule(s) enabled on all started hosts.\n");
  831. else
  832. printf ("Port rule(s) enabled.\n");
  833. break;
  834. case WLBS_NOT_FOUND:
  835. if (host == WLBS_ALL_HOSTS)
  836. printf ("Port rule does not exist on some host(s).\n");
  837. else
  838. printf ("Port rule does not exist.\n");
  839. break;
  840. case WLBS_STOPPED:
  841. printf ("Cluster mode stopped.\n");
  842. break;
  843. case WLBS_ALREADY:
  844. printf ("Already enabled.\n");
  845. break;
  846. case WLBS_SUSPENDED:
  847. if (host == WLBS_ALL_HOSTS)
  848. printf ("All cluster hosts suspended.\n");
  849. else
  850. printf ("Cluster mode control suspended.\n");
  851. break;
  852. case WLBS_DRAINING:
  853. printf ("Host is draining.\n");
  854. break;
  855. default:
  856. if (status >= WSABASEERR)
  857. {
  858. printf ("WinSock error %d.\n", status);
  859. return 2;
  860. }
  861. }
  862. if (host == WLBS_ALL_HOSTS)
  863. {
  864. printf ("Received responses from %d hosts:\n", hosts);
  865. for (i = 0; i < hosts && i < WLBS_MAX_HOSTS; i ++)
  866. {
  867. buf_size = BUF_SIZE;
  868. WlbsAddressToString (resp [i] . address, tbuf, & buf_size);
  869. buf_size = BUF_SIZE;
  870. WlbsAddressToName (resp [i] . address, tbuf2, & buf_size);
  871. _tprintf (_TEXT("Host %d [%s - %25s]: "), resp [i] . id, tbuf, tbuf2);
  872. switch (resp [i] . status)
  873. {
  874. case WLBS_OK:
  875. printf ("enabled\n");
  876. break;
  877. case WLBS_ALREADY:
  878. printf ("already enabled\n");
  879. break;
  880. case WLBS_SUSPENDED:
  881. printf ("control suspended\n");
  882. break;
  883. case WLBS_STOPPED:
  884. printf ("stopped\n");
  885. break;
  886. case WLBS_DRAINING:
  887. printf ("draining\n");
  888. break;
  889. case WLBS_NOT_FOUND:
  890. printf ("not found\n");
  891. break;
  892. }
  893. }
  894. }
  895. break;
  896. case disable:
  897. status = WlbsDisable (cluster, host, resp, & hosts, port);
  898. switch (status)
  899. {
  900. case WLBS_INIT_ERROR:
  901. printf ("WLBS Control API not initialized.\n");
  902. return 2;
  903. case WLBS_LOCAL_ONLY:
  904. printf ("Can only execute local commands.\n");
  905. return 2;
  906. case WLBS_REMOTE_ONLY:
  907. printf ("Can only execute remote commands.\n");
  908. return 2;
  909. case WLBS_BAD_PASSW:
  910. printf ("Bad password specified.\n");
  911. return 2;
  912. case WLBS_TIMEOUT:
  913. printf ("Timed out awaiting response.\n");
  914. return 2;
  915. case WLBS_IO_ERROR:
  916. printf ("Error connecting to WLBS device.\n");
  917. return 2;
  918. case WLBS_OK:
  919. if (host == WLBS_ALL_HOSTS)
  920. printf ("Port rule(s) disabled on all started hosts.\n");
  921. else
  922. printf ("Port rule(s) disabled.\n");
  923. break;
  924. case WLBS_NOT_FOUND:
  925. if (host == WLBS_ALL_HOSTS)
  926. printf ("Port rule does not exist on some host(s).\n");
  927. else
  928. printf ("Port rule does not exist.\n");
  929. break;
  930. case WLBS_STOPPED:
  931. printf ("Cluster mode stopped.\n");
  932. break;
  933. case WLBS_ALREADY:
  934. printf ("Already disabled.\n");
  935. break;
  936. case WLBS_SUSPENDED:
  937. if (host == WLBS_ALL_HOSTS)
  938. printf ("All cluster hosts suspended.\n");
  939. else
  940. printf ("Cluster mode control suspended.\n");
  941. break;
  942. case WLBS_DRAINING:
  943. printf ("Host is draining.\n");
  944. break;
  945. default:
  946. if (status >= WSABASEERR)
  947. {
  948. printf ("WinSock error %d.\n", status);
  949. return 2;
  950. }
  951. }
  952. if (host == WLBS_ALL_HOSTS)
  953. {
  954. printf ("Received responses from %d hosts:\n", hosts);
  955. for (i = 0; i < hosts && i < WLBS_MAX_HOSTS; i ++)
  956. {
  957. buf_size = BUF_SIZE;
  958. WlbsAddressToString (resp [i] . address, tbuf, & buf_size);
  959. buf_size = BUF_SIZE;
  960. WlbsAddressToName (resp [i] . address, tbuf2, & buf_size);
  961. _tprintf (_TEXT("Host %d [%s - %25s]: "), resp [i] . id, tbuf, tbuf2);
  962. switch (resp [i] . status)
  963. {
  964. case WLBS_OK:
  965. printf ("disabled\n");
  966. break;
  967. case WLBS_ALREADY:
  968. printf ("already disabled\n");
  969. break;
  970. case WLBS_SUSPENDED:
  971. printf ("control suspended\n");
  972. break;
  973. case WLBS_STOPPED:
  974. printf ("stopped\n");
  975. break;
  976. case WLBS_DRAINING:
  977. printf ("draining\n");
  978. break;
  979. case WLBS_NOT_FOUND:
  980. printf ("not found\n");
  981. break;
  982. }
  983. }
  984. }
  985. break;
  986. case drain:
  987. status = WlbsDrain (cluster, host, resp, & hosts, port);
  988. switch (status)
  989. {
  990. case WLBS_INIT_ERROR:
  991. printf ("WLBS Control API not initialized.\n");
  992. return 2;
  993. case WLBS_LOCAL_ONLY:
  994. printf ("Can only execute local commands.\n");
  995. return 2;
  996. case WLBS_REMOTE_ONLY:
  997. printf ("Can only execute remote commands.\n");
  998. return 2;
  999. case WLBS_BAD_PASSW:
  1000. printf ("Bad password specified.\n");
  1001. return 2;
  1002. case WLBS_TIMEOUT:
  1003. printf ("Timed out awaiting response.\n");
  1004. return 2;
  1005. case WLBS_IO_ERROR:
  1006. printf ("Error connecting to WLBS device.\n");
  1007. return 2;
  1008. case WLBS_OK:
  1009. if (host == WLBS_ALL_HOSTS)
  1010. printf ("Port rule(s) set to drain on all started hosts.\n");
  1011. else
  1012. printf ("Port rule(s) set to drain.\n");
  1013. break;
  1014. case WLBS_NOT_FOUND:
  1015. if (host == WLBS_ALL_HOSTS)
  1016. printf ("Port rule does not exist on some host(s).\n");
  1017. else
  1018. printf ("Port rule does not exist.\n");
  1019. break;
  1020. case WLBS_STOPPED:
  1021. printf ("Cluster mode stopped.\n");
  1022. break;
  1023. case WLBS_ALREADY:
  1024. printf ("Already disabled.\n");
  1025. break;
  1026. case WLBS_SUSPENDED:
  1027. if (host == WLBS_ALL_HOSTS)
  1028. printf ("All cluster hosts suspended.\n");
  1029. else
  1030. printf ("Cluster mode control suspended.\n");
  1031. break;
  1032. case WLBS_DRAINING:
  1033. printf ("Host is draining.\n");
  1034. break;
  1035. default:
  1036. if (status >= WSABASEERR)
  1037. {
  1038. printf ("WinSock error %d.\n", status);
  1039. return 2;
  1040. }
  1041. }
  1042. if (host == WLBS_ALL_HOSTS)
  1043. {
  1044. printf ("Received responses from %d hosts:\n", hosts);
  1045. for (i = 0; i < hosts && i < WLBS_MAX_HOSTS; i ++)
  1046. {
  1047. buf_size = BUF_SIZE;
  1048. WlbsAddressToString (resp [i] . address, tbuf, & buf_size);
  1049. buf_size = BUF_SIZE;
  1050. WlbsAddressToName (resp [i] . address, tbuf2, & buf_size);
  1051. _tprintf (_TEXT("Host %d [%s - %25s]: "), resp [i] . id, tbuf, tbuf2);
  1052. switch (resp [i] . status)
  1053. {
  1054. case WLBS_OK:
  1055. printf ("set to drain\n");
  1056. break;
  1057. case WLBS_ALREADY:
  1058. printf ("already draining\n");
  1059. break;
  1060. case WLBS_SUSPENDED:
  1061. printf ("control suspended\n");
  1062. break;
  1063. case WLBS_STOPPED:
  1064. printf ("stopped\n");
  1065. break;
  1066. case WLBS_DRAINING:
  1067. printf ("draining\n");
  1068. break;
  1069. case WLBS_NOT_FOUND:
  1070. printf ("not found\n");
  1071. break;
  1072. }
  1073. }
  1074. }
  1075. break;
  1076. default:
  1077. break;
  1078. }
  1079. return 0;
  1080. usage:
  1081. printf ("Usage: %s <command> [<cluster>[:<host>] [/PASSW [<password>]] [/PORT <port>]\n [/DEST <destination>] [/TIMEOUT <msec>]]\n", __targv [0]);
  1082. printf ("<command>\n");
  1083. printf (" query - queries which hosts are currently part of the cluster\n");
  1084. printf (" suspend - suspend control over cluster operations\n");
  1085. printf (" resume - resume control over cluster operations\n");
  1086. printf (" start - starts WLBS cluster operations\n");
  1087. printf (" stop - stops WLBS cluster operations\n");
  1088. printf (" drainstop - finishes all existing connections and\n");
  1089. printf (" stops WLBS cluster operations\n");
  1090. printf (" enable <port> | ALL - enables traffic for <port> rule or ALL ports\n");
  1091. printf (" disable <port> | ALL - disables ALL traffic for <port> rule or ALL ports\n");
  1092. printf (" drain <port> | ALL - disables NEW traffic for <port> rule or ALL ports\n");
  1093. printf ("Remote options:\n");
  1094. printf (" <cluster> - cluster name | cluster primary IP address\n");
  1095. printf (" <host> - host within the cluster (default - ALL hosts):\n");
  1096. printf (" dedicated name | IP address |\n");
  1097. printf (" host priority ID (1..32) | 0 for current DEFAULT host\n");
  1098. printf (" /PASSW <password> - remote control password (default - NONE)\n");
  1099. printf (" blank <password> for console prompt\n");
  1100. printf (" /PORT <port> - cluster's remote control UDP port (default - 1717)\n");
  1101. printf (" /DEST <destination> - alternative destination to send control messages:\n");
  1102. printf (" system name | IP address (default - <cluster>)\n");
  1103. printf (" /TIMEOUT <msecs> - set timeout for awaiting replies from the cluster\n");
  1104. printf (" (default - 10,000)\n");
  1105. return 1;
  1106. }
  1107. void generate_port_rules ( PWLBS_PORT_RULE rules, DWORD num_rules, DWORD range )
  1108. {
  1109. DWORD i;
  1110. static DWORD pri = 1;
  1111. for (i = 0 ; i < num_rules ; i++)
  1112. {
  1113. rules [i] . start_port = i * range;
  1114. rules [i] . end_port = rules [i] . start_port + range - 1;
  1115. rules [i] . mode = WLBS_SINGLE;
  1116. rules [i] . mode = (pri++) % 4 + 1;
  1117. rules [i] . mode = WLBS_MULTI;
  1118. rules [i] . protocol = WLBS_TCP_UDP;
  1119. rules [i] . protocol = (pri++) %4 + 1;
  1120. rules [i] . valid = rand();
  1121. /* The following is just for testing */
  1122. /* rules [i] . end_port = rules [i] . start_port - 1; */
  1123. if (rules [i] . mode == WLBS_SINGLE)
  1124. {
  1125. rules [i] . mode_data . single . priority = (pri++) % (WLBS_MAX_HOSTS + 6) + 1;
  1126. }
  1127. if (rules [i] . mode == WLBS_MULTI)
  1128. {
  1129. rules [i] . mode_data . multi . affinity = (WORD) ((pri++) % 4);
  1130. rules [i] . mode_data . multi . equal_load = (WORD) ((pri++) % 3);
  1131. rules [i] . mode_data . multi . load = (WORD) ((pri++) % 110);
  1132. }
  1133. }
  1134. return;
  1135. }
  1136. void delete_all_rules ( PWLBS_REG_PARAMS reg_data )
  1137. {
  1138. WLBS_PORT_RULE rules [WLBS_MAX_RULES];
  1139. DWORD num_rules;
  1140. DWORD i;
  1141. num_rules = WlbsGetNumPortRules ( reg_data );
  1142. printf("num_rules is %d\n", num_rules);
  1143. WlbsEnumPortRules ( reg_data, rules, & num_rules );
  1144. printf("num_rules is %d\n", num_rules);
  1145. for (i = 0 ; i < num_rules ; i++)
  1146. {
  1147. if (TRUE)
  1148. {
  1149. printf("Deleting rule %d start %d result %d\n",i,
  1150. rules [i] . start_port,
  1151. WlbsDeletePortRule ( reg_data, rules [i] . start_port ) );
  1152. }
  1153. }
  1154. printf("Number of rules in registry is %d\n", WlbsGetNumPortRules ( reg_data ) );
  1155. return;
  1156. }
  1157. void test_commit ( PWLBS_REG_PARAMS reg_data, BOOL flag1, BOOL flag2 )
  1158. {
  1159. /* read from the registry
  1160. * change some values to cause only a reload
  1161. * write and check the return value of commit
  1162. */
  1163. DWORD retval;
  1164. if (flag1)
  1165. {
  1166. retval = WlbsReadReg (WLBS_LOCAL_CLUSTER, reg_data);
  1167. if (retval != WLBS_OK)
  1168. {
  1169. printf("1:Error in reading from the registry\n");
  1170. return;
  1171. }
  1172. /* randomly change some values */
  1173. reg_data -> host_priority = 2;
  1174. reg_data -> alive_period = 1000;
  1175. _stprintf ( reg_data -> domain_name, _TEXT("rkcluster.domain.com"));
  1176. retval = WlbsWriteReg (WLBS_LOCAL_CLUSTER, reg_data);
  1177. if (retval != WLBS_OK)
  1178. {
  1179. printf("1:Error in writing to the registry\n");
  1180. return;
  1181. }
  1182. retval = WlbsCommitChanges (WLBS_LOCAL_CLUSTER);
  1183. if (retval == WLBS_OK)
  1184. {
  1185. printf("1:Successfully reloaded\n");
  1186. }
  1187. else if (retval == WLBS_REBOOT)
  1188. {
  1189. printf("1:Reboot required\n");
  1190. }
  1191. else
  1192. {
  1193. printf("1:retval was neither ok nor reboot\n");
  1194. }
  1195. }
  1196. /* read from the registry
  1197. * change cl_ip_addr or mcast_support or set i_convert_mac to false and set some mac addr
  1198. * write and check the return value of commit
  1199. */
  1200. if (!flag2)
  1201. {
  1202. return;
  1203. }
  1204. retval = WlbsReadReg (WLBS_LOCAL_CLUSTER, reg_data);
  1205. if (retval != WLBS_OK)
  1206. {
  1207. printf("2:Error in reading from the registry\n");
  1208. return;
  1209. }
  1210. {
  1211. /* change the cl_ip_addr */
  1212. _stprintf (reg_data -> cl_ip_addr, _TEXT("10.0.0.200"));
  1213. reg_data -> mcast_support = FALSE;
  1214. reg_data -> i_convert_mac = FALSE;
  1215. _stprintf ( reg_data -> cl_mac_addr, _TEXT("00-bf-ab-cd-ef-13"));
  1216. _tprintf(_TEXT("The original cl net mask is %s\n"), reg_data -> cl_net_mask );
  1217. _tprintf(_TEXT("The original ded net mask is %s\n"), reg_data -> ded_net_mask );
  1218. _stprintf ( reg_data -> cl_net_mask, _TEXT("255.255.255.0"));
  1219. _stprintf ( reg_data -> ded_net_mask , _TEXT("255.255.255.0"));
  1220. _tprintf(_TEXT("The new ip address should be %s\n"), reg_data -> cl_ip_addr);
  1221. _tprintf(_TEXT("The length of the string %d\n"), _tcslen (reg_data -> cl_ip_addr));
  1222. }
  1223. retval = WlbsWriteReg (WLBS_LOCAL_CLUSTER, reg_data);
  1224. if (retval != WLBS_OK)
  1225. {
  1226. printf("2:Error in writing to the registry\n");
  1227. return;
  1228. }
  1229. _tprintf (_TEXT("The mac address should be %s"), reg_data -> cl_mac_addr);
  1230. retval = WlbsCommitChanges (WLBS_LOCAL_CLUSTER);
  1231. if (retval == WLBS_OK)
  1232. {
  1233. printf("2:Successfully reloaded\n");
  1234. return;
  1235. }
  1236. else if (retval == WLBS_REBOOT)
  1237. {
  1238. printf("2:Reboot required\n");
  1239. return;
  1240. }
  1241. else if (retval == WLBS_REG_ERROR)
  1242. {
  1243. printf("2:RegError\n");
  1244. return;
  1245. }
  1246. printf("2:The retval from commit was neither ok nor reboot\n");
  1247. return;
  1248. }
  1249. DWORD testnewapi (void)
  1250. {
  1251. WLBS_REG_PARAMS reg_data;
  1252. WLBS_PORT_RULE rule;
  1253. WLBS_PORT_RULE rules_list [ 100 ];
  1254. DWORD num_rules = 0;
  1255. DWORD range = 0;
  1256. DWORD status = 0;
  1257. TCHAR * newdomainname = _TEXT("rkcluster.domain.com");
  1258. DWORD i,k;
  1259. DWORD host_map = 0;
  1260. WLBS_RESPONSE response [3];
  1261. DWORD size = 3;
  1262. /*
  1263. status = WlbsQuery (WLBS_LOCAL_CLUSTER, 1, response, &size, &host_map, NULL);
  1264. printf("Query status is %d size = %d\n", status, size);
  1265. printf("response is %d %d %x\n", response [0] . id, response [0] . status, response [0] . address);
  1266. printf("response is %d %d %x\n", response [1] . id, response [1] . status, response [1] . address);
  1267. return 0;
  1268. */
  1269. status = WlbsReadReg(WLBS_LOCAL_CLUSTER, &reg_data);
  1270. if (status == WLBS_INIT_ERROR)
  1271. {
  1272. printf ("WlbsReadReg returned an init error\n");
  1273. return 0;
  1274. }
  1275. printf("Printing the TCHAR fields in the reg_data structure\n");
  1276. _tprintf (_TEXT("virtual_nic_name %s\n"), reg_data . i_virtual_nic_name );
  1277. _tprintf (_TEXT("cl_mac_addr %s\n"), reg_data . cl_mac_addr );
  1278. _tprintf (_TEXT("cl_ip_addr %s\n"), reg_data . cl_ip_addr );
  1279. _tprintf (_TEXT("cl_net_mask %s\n"), reg_data . cl_net_mask );
  1280. _tprintf (_TEXT("ded_ip_addr %s\n"), reg_data . ded_ip_addr );
  1281. _tprintf (_TEXT("ded_net_mask %s\n"), reg_data . ded_net_mask );
  1282. _tprintf (_TEXT("domain_name %s\n"), reg_data . domain_name );
  1283. _tprintf (_TEXT("i_license_key %s\n"), reg_data . i_license_key );
  1284. /* test_commit ( &reg_data, TRUE, TRUE);
  1285. return 1;
  1286. reg_data . host_priority = 31;
  1287. */
  1288. WlbsSetRemotePassword ( & reg_data, _TEXT(""));
  1289. status = WlbsWriteReg(WLBS_LOCAL_CLUSTER, &reg_data);
  1290. printf("WlbsWriteReg returned %d\n", status);
  1291. return 1;
  1292. memset ((void *) &reg_data, 0, sizeof (WLBS_REG_PARAMS));
  1293. if (WlbsReadReg (WLBS_LOCAL_CLUSTER, &reg_data) == WLBS_INIT_ERROR)
  1294. {
  1295. printf ("WlbsReadReg returned an init error\n");
  1296. return 0;
  1297. }
  1298. _tprintf(_TEXT("Read again from the registry. Domain name %s\n"), reg_data . domain_name );
  1299. printf("The new host priority is %d\n", reg_data . host_priority);
  1300. if (FALSE)
  1301. {
  1302. printf("checking the get num port rules function\n");
  1303. num_rules = WlbsGetNumPortRules ( & reg_data );
  1304. printf("num of rules is %d\n", num_rules );
  1305. printf("checking the get num port rules function\n");
  1306. printf("num of rules is %d\n", WlbsGetNumPortRules ( &reg_data) );
  1307. printf("Writing to the registry %d\n", WlbsWriteReg(WLBS_LOCAL_CLUSTER, &reg_data) );
  1308. WlbsCommitChanges (WLBS_LOCAL_CLUSTER);
  1309. memset ((void *) &reg_data, 0, sizeof (WLBS_REG_PARAMS));
  1310. if (WlbsReadReg (WLBS_LOCAL_CLUSTER, &reg_data) == WLBS_INIT_ERROR)
  1311. {
  1312. printf ("WlbsReadReg returned an init error\n");
  1313. return 0;
  1314. }
  1315. for (k=0;k<1;k++)
  1316. {
  1317. delete_all_rules ( &reg_data );
  1318. printf("Deleted all the port rules. Num of rules now is %d\n", reg_data . i_num_rules);
  1319. if (TRUE)
  1320. {
  1321. num_rules = 100;
  1322. range = 600;
  1323. generate_port_rules ( rules_list, num_rules, range );
  1324. rules_list [0] . mode = WLBS_SINGLE;
  1325. rules_list [0] . mode_data . single . priority = 5;
  1326. for (i = 0 ; i < num_rules; i++)
  1327. {
  1328. DWORD status = WlbsAddPortRule (&reg_data, &rules_list [i]);
  1329. printf("Adding port rule start %d end %d rule # %d result %d\n",
  1330. rules_list[i] . start_port,
  1331. rules_list[i] . end_port,
  1332. i,
  1333. status);
  1334. }
  1335. printf("Number of rules is %d\n", WlbsGetNumPortRules ( &reg_data ) );
  1336. }
  1337. printf("Writing the changes to the registry\n");
  1338. WlbsWriteReg (WLBS_LOCAL_CLUSTER, &reg_data);
  1339. WlbsCommitChanges (WLBS_LOCAL_CLUSTER);
  1340. }
  1341. }
  1342. for (i=0; i<1; i++)
  1343. {
  1344. memset ( &reg_data, 0, sizeof (reg_data));
  1345. WlbsReadReg (WLBS_LOCAL_CLUSTER, &reg_data);
  1346. reg_data . host_priority = i%32 + 1;
  1347. WlbsWriteReg (WLBS_LOCAL_CLUSTER, &reg_data);
  1348. WlbsCommitChanges (WLBS_LOCAL_CLUSTER);
  1349. }
  1350. test_commit (&reg_data, TRUE, TRUE);
  1351. return 1;
  1352. }