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.

543 lines
16 KiB

  1. // Copyright (c) Microsoft. All rights reserved.
  2. //
  3. // This is unpublished source code of Microsoft.
  4. // The copyright notice above does not evidence any
  5. // actual or intended publication of such source code.
  6. // OneLiner : Implementation of MNLBNetCfg
  7. // DevUnit : wlbstest
  8. // Author : Murtaza Hakim
  9. // include files
  10. #include "MNLBNetCfg.h"
  11. #include "MTrace.h"
  12. #include "WTokens.h"
  13. // History:
  14. // --------
  15. //
  16. //
  17. // Revised by : mhakim
  18. // Date : 02-12-01
  19. // Reason : Added password support.
  20. // constructor
  21. //
  22. MNLBNetCfg::MNLBNetCfg( const _bstr_t& ip,
  23. const _bstr_t& fullNicName )
  24. :
  25. m_ip( ip ),
  26. m_fullNicName( fullNicName )
  27. {
  28. }
  29. // constructor
  30. //
  31. MNLBNetCfg::MNLBNetCfg( const _bstr_t& fullNicName )
  32. :
  33. m_ip( L"self"),
  34. m_fullNicName( fullNicName )
  35. {
  36. }
  37. // unbind
  38. //
  39. MNLBNetCfg::MNLBNetCfg_Error
  40. MNLBNetCfg::unbind()
  41. {
  42. MWmiObject machine( m_ip,
  43. L"root\\microsoftnlb",
  44. L"administrator",
  45. L"" );
  46. vector<MWmiInstance> instanceStore;
  47. _bstr_t relPath = L"NlbsNic.FullName=\"" + m_fullNicName + "\"";
  48. machine.getSpecificInstance( L"NlbsNic",
  49. relPath,
  50. &instanceStore );
  51. // input parameters are none.
  52. //
  53. vector<MWmiParameter *> inputParameters;
  54. // output parameters which are of interest.
  55. //
  56. vector<MWmiParameter *> outputParameters;
  57. MWmiParameter ReturnValue(L"ReturnValue");
  58. outputParameters.push_back( &ReturnValue );
  59. instanceStore[0].runMethod( L"Unbind",
  60. inputParameters,
  61. outputParameters );
  62. if( long( ReturnValue.getValue() ) != 0 )
  63. {
  64. TRACE( MTrace::SEVERE_ERROR,
  65. L"Not able to unbind nlb" );
  66. throw _com_error( WBEM_E_NOT_FOUND );
  67. }
  68. return MNLBNetCfg_SUCCESS;
  69. }
  70. // isBound
  71. //
  72. MNLBNetCfg::MNLBNetCfg_Error
  73. MNLBNetCfg::isBound()
  74. {
  75. MWmiObject machine( m_ip,
  76. L"root\\microsoftnlb",
  77. L"administrator",
  78. L"" );
  79. vector<MWmiInstance> instanceStore;
  80. _bstr_t relPath = L"NlbsNic.FullName=\"" + m_fullNicName + "\"";
  81. machine.getSpecificInstance( L"NlbsNic",
  82. relPath,
  83. &instanceStore );
  84. // input parameters are none.
  85. //
  86. vector<MWmiParameter *> inputParameters;
  87. // output parameters which are of interest.
  88. //
  89. vector<MWmiParameter *> outputParameters;
  90. MWmiParameter ReturnValue(L"ReturnValue");
  91. outputParameters.push_back( &ReturnValue );
  92. instanceStore[0].runMethod( L"IsBound",
  93. inputParameters,
  94. outputParameters );
  95. if( long( ReturnValue.getValue() ) == 1 )
  96. {
  97. return BOUND;
  98. }
  99. else if( long( ReturnValue.getValue() ) == 0 )
  100. {
  101. return UNBOUND;
  102. }
  103. else
  104. {
  105. TRACE( MTrace::SEVERE_ERROR,
  106. L"Not able to check if nlb is bound or not" );
  107. throw _com_error( WBEM_E_NOT_FOUND );
  108. }
  109. return MNLBNetCfg_SUCCESS;
  110. }
  111. // addClusterIP
  112. //
  113. MNLBNetCfg::MNLBNetCfg_Error
  114. MNLBNetCfg::addClusterIP( const _bstr_t& clusterIP,
  115. const _bstr_t& subnet )
  116. {
  117. if( m_ip == _bstr_t( L"self" ) )
  118. {
  119. MIPAddressAdmin ipAdmin( m_fullNicName );
  120. ipAdmin.addIPAddress( clusterIP,
  121. subnet );
  122. }
  123. else
  124. {
  125. MIPAddressAdmin ipAdmin( m_ip,
  126. m_fullNicName );
  127. ipAdmin.addIPAddress( clusterIP,
  128. subnet );
  129. }
  130. return MNLBNetCfg_SUCCESS;
  131. }
  132. // removeClusterIP
  133. //
  134. MNLBNetCfg::MNLBNetCfg_Error
  135. MNLBNetCfg::removeClusterIP( const _bstr_t& clusterIP )
  136. {
  137. if( m_ip == _bstr_t( L"self" ) )
  138. {
  139. MIPAddressAdmin ipAdmin( m_fullNicName );
  140. ipAdmin.deleteIPAddress( clusterIP );
  141. }
  142. else
  143. {
  144. MIPAddressAdmin ipAdmin( m_ip,
  145. m_fullNicName);
  146. ipAdmin.deleteIPAddress( clusterIP );
  147. }
  148. return MNLBNetCfg_SUCCESS;
  149. }
  150. MNLBNetCfg::MNLBNetCfg_Error
  151. MNLBNetCfg::bind()
  152. {
  153. MWmiObject machine( m_ip,
  154. L"root\\microsoftnlb",
  155. L"administrator",
  156. L"" );
  157. vector<MWmiInstance> instanceStore;
  158. _bstr_t relPath = L"NlbsNic.FullName=\"" + m_fullNicName + "\"";
  159. machine.getSpecificInstance( L"NlbsNic",
  160. relPath,
  161. &instanceStore );
  162. // input parameters are none.
  163. //
  164. vector<MWmiParameter *> inputParameters;
  165. // output parameters which are of interest.
  166. //
  167. vector<MWmiParameter *> outputParameters;
  168. MWmiParameter ReturnValue(L"ReturnValue");
  169. outputParameters.push_back( &ReturnValue );
  170. instanceStore[0].runMethod( L"Bind",
  171. inputParameters,
  172. outputParameters );
  173. if( long( ReturnValue.getValue() ) != 0 )
  174. {
  175. TRACE( MTrace::SEVERE_ERROR,
  176. L"Not able to bind nlb" );
  177. throw _com_error( WBEM_E_NOT_FOUND );
  178. }
  179. return MNLBNetCfg_SUCCESS;
  180. }
  181. MNLBNetCfg::MNLBNetCfg_Error
  182. MNLBNetCfg::bindAndConfigure(
  183. const ClusterData* p_clusterData,
  184. const _bstr_t& machineName
  185. )
  186. {
  187. ClusterData* p_clusterDataCopy =
  188. const_cast <ClusterData *>( p_clusterData );
  189. MWmiObject machine( m_ip,
  190. L"root\\microsoftnlb",
  191. L"administrator",
  192. L"" );
  193. vector<MWmiInstance> instanceStore;
  194. _bstr_t relPath = L"NlbsNic.FullName=\"" + m_fullNicName + "\"";
  195. machine.getSpecificInstance( L"NlbsNic",
  196. relPath,
  197. &instanceStore );
  198. // input parameters
  199. //
  200. vector<MWmiParameter *> inputParameters;
  201. // cluster properties
  202. MWmiParameter ClusterIPAddress(L"ClusterIPAddress");
  203. inputParameters.push_back( &ClusterIPAddress );
  204. ClusterIPAddress.setValue( p_clusterDataCopy->cp.cIP );
  205. MWmiParameter ClusterNetworkMask(L"ClusterNetworkMask");
  206. inputParameters.push_back( &ClusterNetworkMask );
  207. ClusterNetworkMask.setValue( p_clusterDataCopy->cp.cSubnetMask );
  208. MWmiParameter ClusterName(L"ClusterName");
  209. inputParameters.push_back( &ClusterName );
  210. ClusterName.setValue( p_clusterDataCopy->cp.cFullInternetName );
  211. MWmiParameter MulticastSupportEnabled(L"MulticastSupportEnabled");
  212. inputParameters.push_back( &MulticastSupportEnabled );
  213. MulticastSupportEnabled.setValue( p_clusterDataCopy->cp.multicastSupportEnabled );
  214. MWmiParameter IGMPSupport(L"IGMPSupport");
  215. inputParameters.push_back( &IGMPSupport );
  216. IGMPSupport.setValue( p_clusterDataCopy->cp.igmpSupportEnabled );
  217. MWmiParameter RemoteControlEnabled(L"RemoteControlEnabled");
  218. inputParameters.push_back( &RemoteControlEnabled );
  219. RemoteControlEnabled.setValue( p_clusterDataCopy->cp.remoteControlEnabled );
  220. MWmiParameter Password(L"Password");
  221. inputParameters.push_back( &Password );
  222. Password.setValue( p_clusterDataCopy->cp.password );
  223. // host properties
  224. MWmiParameter HostPriority(L"HostPriority");
  225. inputParameters.push_back( &HostPriority );
  226. HostPriority.setValue( p_clusterDataCopy->hosts[machineName].hp.hID );
  227. MWmiParameter DedicatedIPAddress(L"DedicatedIPAddress");
  228. inputParameters.push_back( &DedicatedIPAddress );
  229. DedicatedIPAddress.setValue( p_clusterDataCopy->hosts[machineName].hp.hIP );
  230. MWmiParameter DedicatedNetworkMask(L"DedicatedNetworkMask");
  231. inputParameters.push_back( &DedicatedNetworkMask );
  232. DedicatedNetworkMask.setValue( p_clusterDataCopy->hosts[machineName].hp.hSubnetMask );
  233. MWmiParameter ClusterModeOnStart(L"ClusterModeOnStart");
  234. inputParameters.push_back( &ClusterModeOnStart );
  235. ClusterModeOnStart.setValue( p_clusterDataCopy->hosts[machineName].hp.initialClusterStateActive );
  236. // port rules
  237. vector<_bstr_t> portRulesVector;
  238. getPortRules( p_clusterData,
  239. machineName,
  240. portRulesVector );
  241. SAFEARRAY* portRulesArray;
  242. SAFEARRAYBOUND rgsabound[1];
  243. rgsabound[0].lLbound = 0;
  244. rgsabound[0].cElements = portRulesVector.size();
  245. portRulesArray = SafeArrayCreate( VT_BSTR, 1, rgsabound );
  246. LONG scount = 0;
  247. HRESULT hr;
  248. for( int i = 0; i < portRulesVector.size(); ++i )
  249. {
  250. scount = i;
  251. hr = SafeArrayPutElement( portRulesArray,
  252. &scount,
  253. (wchar_t * ) portRulesVector[i] );
  254. }
  255. VARIANT portRulesVariant;
  256. portRulesVariant.vt = VT_ARRAY | VT_BSTR;
  257. portRulesVariant.parray = portRulesArray;
  258. MWmiParameter PortRules(L"PortRules");
  259. inputParameters.push_back( &PortRules );
  260. PortRules.setValue( portRulesVariant );
  261. // output parameters which are of interest.
  262. //
  263. vector<MWmiParameter *> outputParameters;
  264. MWmiParameter ReturnValue(L"ReturnValue");
  265. outputParameters.push_back( &ReturnValue );
  266. instanceStore[0].runMethod( L"BindAndConfigure",
  267. inputParameters,
  268. outputParameters );
  269. return MNLBNetCfg_SUCCESS;
  270. }
  271. void
  272. MNLBNetCfg::getPortRules( const ClusterData* p_clusterData,
  273. const _bstr_t& myMachine,
  274. vector<_bstr_t>& myPortRules )
  275. {
  276. wchar_t portBuf[1000];
  277. wstring temp;
  278. WTokens tok;
  279. vector<wstring> tokens;
  280. map< long, PortDataELB>::iterator topELB;
  281. map< long, PortDataULB>::iterator topULB;
  282. map< long, PortDataD>::iterator topD;
  283. map< long, PortDataF>::iterator topF;
  284. wstring trafficToHandle;
  285. wstring affinity;
  286. for( topELB = p_clusterData->portELB.begin(); topELB != p_clusterData->portELB.end(); ++topELB )
  287. {
  288. if( (*topELB).second._trafficToHandle == MNLBPortRule::both )
  289. {
  290. trafficToHandle = L"Both";
  291. }
  292. else if( (*topELB).second._trafficToHandle == MNLBPortRule::tcp )
  293. {
  294. trafficToHandle = L"TCP";
  295. }
  296. else
  297. {
  298. trafficToHandle = L"UDP";
  299. }
  300. if( (*topELB).second._affinity == MNLBPortRule::single )
  301. {
  302. affinity = L"Single";
  303. }
  304. else if( (*topELB).second._affinity == MNLBPortRule::none )
  305. {
  306. affinity = L"None";
  307. }
  308. else
  309. {
  310. affinity = L"Class C";
  311. }
  312. wsprintf( portBuf, L"%d\t%d\t%s\tMultiple\t \tEqual\t%s\t",
  313. (*topELB).second._startPort,
  314. (*topELB).second._endPort,
  315. trafficToHandle.c_str(),
  316. affinity.c_str() );
  317. myPortRules.push_back( portBuf );
  318. }
  319. for( topULB = p_clusterData->portULB.begin(); topULB != p_clusterData->portULB.end(); ++topULB )
  320. {
  321. if( (*topULB).second._trafficToHandle == MNLBPortRule::both )
  322. {
  323. trafficToHandle = L"Both";
  324. }
  325. else if( (*topULB).second._trafficToHandle == MNLBPortRule::tcp )
  326. {
  327. trafficToHandle = L"TCP";
  328. }
  329. else
  330. {
  331. trafficToHandle = L"UDP";
  332. }
  333. if( (*topULB).second._affinity == MNLBPortRule::single )
  334. {
  335. affinity = L"Single";
  336. }
  337. else if( (*topULB).second._affinity == MNLBPortRule::none )
  338. {
  339. affinity = L"None";
  340. }
  341. else
  342. {
  343. affinity = L"Class C";
  344. }
  345. int loadWeight = (*topULB).second.machineMapToLoadWeight[myMachine];
  346. wsprintf( portBuf, L"%d\t%d\t%s\tMultiple\t \t%d\t%s",
  347. (*topULB).second._startPort,
  348. (*topULB).second._endPort,
  349. trafficToHandle.c_str(),
  350. loadWeight,
  351. affinity.c_str() );
  352. myPortRules.push_back( portBuf );
  353. }
  354. for( topD = p_clusterData->portD.begin(); topD != p_clusterData->portD.end(); ++topD )
  355. {
  356. if( (*topD).second._trafficToHandle == MNLBPortRule::both )
  357. {
  358. trafficToHandle = L"Both";
  359. }
  360. else if( (*topD).second._trafficToHandle == MNLBPortRule::tcp )
  361. {
  362. trafficToHandle = L"TCP";
  363. }
  364. else
  365. {
  366. trafficToHandle = L"UDP";
  367. }
  368. wsprintf( portBuf, L"%d\t%d\t%s\tDisabled\t \t \t \t",
  369. (*topD).second._startPort,
  370. (*topD).second._endPort,
  371. trafficToHandle.c_str() );
  372. myPortRules.push_back( portBuf );
  373. }
  374. for( topF = p_clusterData->portF.begin(); topF != p_clusterData->portF.end(); ++topF )
  375. {
  376. if( (*topF).second._trafficToHandle == MNLBPortRule::both )
  377. {
  378. trafficToHandle = L"Both";
  379. }
  380. else if( (*topF).second._trafficToHandle == MNLBPortRule::tcp )
  381. {
  382. trafficToHandle = L"TCP";
  383. }
  384. else
  385. {
  386. trafficToHandle = L"UDP";
  387. }
  388. wsprintf( portBuf, L"%d\t%d\t%s\tSingle\t%d\t \t \t",
  389. (*topF).second._startPort,
  390. (*topF).second._endPort,
  391. trafficToHandle.c_str(),
  392. (*topF).second.machineMapToPriority[ myMachine ] );
  393. myPortRules.push_back( portBuf );
  394. }
  395. }
  396. MNLBNetCfg::MNLBNetCfg_Error
  397. MNLBNetCfg::modifyClusterProperties(const ClusterProperties* p_clusterProperties)
  398. {
  399. MWmiObject machine( m_ip,
  400. L"root\\microsoftnlb",
  401. L"administrator",
  402. L"" );
  403. vector<MWmiInstance> instanceStore;
  404. _bstr_t relPath = L"NlbsNic.FullName=\"" + m_fullNicName + "\"";
  405. machine.getSpecificInstance( L"NlbsNic",
  406. relPath,
  407. &instanceStore );
  408. // input parameters
  409. //
  410. vector<MWmiParameter *> inputParameters;
  411. // cluster properties
  412. MWmiParameter ClusterIPAddress(L"ClusterIPAddress");
  413. inputParameters.push_back( &ClusterIPAddress );
  414. ClusterIPAddress.setValue(p_clusterProperties->cIP);
  415. MWmiParameter ClusterNetworkMask(L"ClusterNetworkMask");
  416. inputParameters.push_back( &ClusterNetworkMask );
  417. ClusterNetworkMask.setValue( p_clusterProperties->cSubnetMask );
  418. MWmiParameter ClusterName(L"ClusterName");
  419. inputParameters.push_back( &ClusterName );
  420. ClusterName.setValue( p_clusterProperties->cFullInternetName );
  421. MWmiParameter MulticastSupportEnabled(L"MulticastSupportEnabled");
  422. inputParameters.push_back( &MulticastSupportEnabled );
  423. MulticastSupportEnabled.setValue( p_clusterProperties->multicastSupportEnabled );
  424. MWmiParameter IGMPSupport(L"IGMPSupport");
  425. inputParameters.push_back( &IGMPSupport );
  426. IGMPSupport.setValue( p_clusterProperties->igmpSupportEnabled );
  427. MWmiParameter RemoteControlEnabled(L"RemoteControlEnabled");
  428. inputParameters.push_back( &RemoteControlEnabled );
  429. RemoteControlEnabled.setValue( p_clusterProperties->remoteControlEnabled );
  430. MWmiParameter Password(L"Password");
  431. inputParameters.push_back( &Password );
  432. Password.setValue( p_clusterProperties->password );
  433. // output parameters which are of interest.
  434. //
  435. vector<MWmiParameter *> outputParameters;
  436. MWmiParameter ReturnValue(L"ReturnValue");
  437. outputParameters.push_back( &ReturnValue );
  438. instanceStore[0].runMethod( L"ModifyClusterProperties",
  439. inputParameters,
  440. outputParameters );
  441. return MNLBNetCfg_SUCCESS;
  442. }