Source code of Windows XP (NT5)
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.

178 lines
4.0 KiB

  1. /*++
  2. Copyright(c) 2001 Microsoft Corporation
  3. Module Name:
  4. NLB Manager
  5. File Name:
  6. nlbhost.cpp
  7. Abstract:
  8. Implementation of class NLBHost
  9. NLBHost is responsible for connecting to an NLB host and getting/setting
  10. its NLB-related configuration.
  11. History:
  12. 03/31/01 JosephJ Created
  13. --*/
  14. #include "tprov.h"
  15. VOID
  16. MyLogger(
  17. PVOID Context,
  18. const WCHAR * Text
  19. )
  20. {
  21. wprintf(L"LOG: %s", Text);
  22. wprintf(L"\n");
  23. }
  24. void test_tmgr(int argc, WCHAR* argv[])
  25. {
  26. WCHAR wszBuf[1024];
  27. NLBHost * pHost = NULL;
  28. WBEMSTATUS Status;
  29. NLBHost::HostInformation *pHostInfo = NULL;
  30. pHost = new NLBHost(
  31. L"JOSEPHJ4E",
  32. L"JosephJ's Dev Machine",
  33. MyLogger,
  34. NULL // Logger context
  35. );
  36. if (pHost == NULL)
  37. {
  38. MyLogger(NULL, L"Could not create an instance of NLBHost.");
  39. goto end;
  40. }
  41. UINT PingStatus = pHost->Ping();
  42. if (PingStatus!=ERROR_SUCCESS) goto end;
  43. Status = pHost->GetHostInformation(
  44. &pHostInfo
  45. );
  46. if (FAILED(Status))
  47. {
  48. pHostInfo = NULL;
  49. goto end;
  50. }
  51. int NumNics = pHostInfo->NumNics;
  52. wsprintf(
  53. wszBuf,
  54. L"Processing host with MachineName %s(NumNics=%d)",
  55. (LPCWSTR)pHostInfo->MachineName,
  56. NumNics
  57. );
  58. MyLogger(NULL, wszBuf);
  59. for( int i = 0; i < NumNics; i++)
  60. {
  61. NLBHost::NicInformation *pNicInfo;
  62. NLB_EXTENDED_CLUSTER_CONFIGURATION ClusterConfig;
  63. UINT GenerationId=0;
  64. UINT RequestId;
  65. pNicInfo = &pHostInfo->nicInformation[i];
  66. wsprintf(
  67. wszBuf,
  68. L"Processing NIC %s (%s)\n",
  69. (LPCWSTR) pNicInfo->adapterGuid,
  70. (LPCWSTR) pNicInfo->friendlyName
  71. );
  72. MyLogger(NULL, wszBuf);
  73. Status = pHost->GetClusterConfiguration(
  74. pNicInfo->adapterGuid,
  75. &ClusterConfig
  76. );
  77. if (FAILED(Status))
  78. {
  79. // Failure...
  80. continue;
  81. }
  82. Status = pHost->SetClusterConfiguration(
  83. pNicInfo->adapterGuid,
  84. &ClusterConfig,
  85. GenerationId,
  86. &RequestId
  87. );
  88. if (Status == WBEM_S_PENDING)
  89. {
  90. INT Delay = 1000; // 1 sec
  91. // Give some time for the remote host's connectivity to be lost...
  92. //
  93. MyLogger(NULL, L"Sleeping for 5 seconds.");
  94. Sleep(5000);
  95. // Now wait until we can ping the host, then query for the async
  96. // result of the SetClusterConfiguration operation.
  97. // We keep polling for the result, sleeping increasing amounts
  98. // in between.
  99. //
  100. MyLogger(NULL, L"Pinging the host ....");
  101. while (pHost->Ping() == ERROR_SUCCESS)
  102. {
  103. UINT ResultCode;
  104. _bstr_t ResultText;
  105. MyLogger(NULL, L"Checking for asynchronous completion...");
  106. Status = pHost->GetAsyncResult(
  107. RequestId,
  108. &GenerationId,
  109. &ResultCode,
  110. &ResultText
  111. );
  112. if (Status == WBEM_S_PENDING)
  113. {
  114. break;
  115. }
  116. MyLogger(NULL, L"Operation still pending...");
  117. MyLogger(NULL, L"Waiting to try again ....");
  118. Sleep(Delay);
  119. MyLogger(NULL, L"Pinging the host ....");
  120. Delay *=2;
  121. }
  122. }
  123. }
  124. end:
  125. if (pHostInfo != NULL)
  126. {
  127. delete pHostInfo;
  128. pHostInfo = NULL;
  129. }
  130. if (pHost != NULL)
  131. {
  132. delete pHost;
  133. pHost = NULL;
  134. }
  135. return;
  136. }