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.

1340 lines
38 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 MNLBProviderSetting
  7. // DevUnit : wlbstest
  8. // Author : Murtaza Hakim
  9. // History:
  10. // --------
  11. //
  12. // Revised by : mhakim
  13. // Date : 02-09-01
  14. // Reason : clustersetting class no longer has igmpjoininterval
  15. // property.
  16. //
  17. // Revised by : mhakim
  18. // Date : 02-11-01
  19. // Reason : password support added.
  20. //
  21. // Revised by : mhakim
  22. // Date : 02-14-01
  23. // Reason : The order in which win2k and whistler settings
  24. // is done depends on previous state of cluster.
  25. // include files
  26. #include "MNLBProviderSetting.h"
  27. #include "MTrace.h"
  28. #include "WTokens.h"
  29. #include "NICCard.h"
  30. #include <iostream>
  31. using namespace std;
  32. // constructor for local machine
  33. //
  34. MNLBProviderSetting::MNLBProviderSetting( _bstr_t fullNICName )
  35. : mIP( L"self" ),
  36. nic( fullNICName ),
  37. p_machine( 0 )
  38. {
  39. connectToMachine();
  40. TRACE(MTrace::INFO, L"mnlbssetting constructor\n");
  41. }
  42. // default constructor
  43. //
  44. // note that default constructor is purposely left undefined.
  45. // NO one should be using it. It is declared just for vector class usage.
  46. // copy constructor
  47. //
  48. MNLBProviderSetting::MNLBProviderSetting(const MNLBProviderSetting& objToCopy )
  49. : mIP( objToCopy.mIP ),
  50. nic( objToCopy.nic ),
  51. p_machine( auto_ptr<MWmiObject>( new MWmiObject( *objToCopy.p_machine ) ) )
  52. {
  53. TRACE(MTrace::INFO, L"mnlbssetting copy constructor\n");
  54. }
  55. // assignment operator
  56. //
  57. MNLBProviderSetting&
  58. MNLBProviderSetting::operator=( const MNLBProviderSetting& rhs )
  59. {
  60. mIP = rhs.mIP;
  61. nic = rhs.nic;
  62. p_machine = auto_ptr<MWmiObject>( new MWmiObject( *rhs.p_machine ) );
  63. TRACE(MTrace::INFO, L"mnlbssetting assignment operator\n");
  64. return *this;
  65. }
  66. // destructor
  67. //
  68. MNLBProviderSetting::~MNLBProviderSetting()
  69. {
  70. TRACE(MTrace::INFO, L"mnlbssetting destructor\n");
  71. }
  72. // getClusterProperties
  73. //
  74. MNLBProviderSetting::MNLBProviderSetting_Error
  75. MNLBProviderSetting::getClusterProperties( ClusterProperties* cp )
  76. {
  77. _bstr_t clusterIP;
  78. _bstr_t hostID;
  79. getClusterIPAndHostID( clusterIP, hostID );
  80. // set parameters to get for win2k
  81. //
  82. vector<MWmiParameter* > parameterStoreWin2k;
  83. MWmiParameter ClusterIPAddress(L"ClusterIPAddress");
  84. parameterStoreWin2k.push_back( &ClusterIPAddress );
  85. MWmiParameter ClusterNetworkMask(L"ClusterNetworkMask");
  86. parameterStoreWin2k.push_back( &ClusterNetworkMask );
  87. MWmiParameter ClusterName(L"ClusterName");
  88. parameterStoreWin2k.push_back( &ClusterName );
  89. MWmiParameter ClusteMACAddress(L"ClusterMACAddress");
  90. parameterStoreWin2k.push_back( &ClusteMACAddress );
  91. MWmiParameter MulticastSupportEnabled(L"MulticastSupportEnabled");
  92. parameterStoreWin2k.push_back( &MulticastSupportEnabled );
  93. MWmiParameter RemoteControlEnabled(L"RemoteControlEnabled");
  94. parameterStoreWin2k.push_back( &RemoteControlEnabled );
  95. // set parameters to get for whistler
  96. // these properties only present in whistler.
  97. //
  98. vector<MWmiParameter* > parameterStoreWhistler;
  99. MWmiParameter IgmpSupport(L"IgmpSupport");
  100. parameterStoreWhistler.push_back( &IgmpSupport );
  101. MWmiParameter ClusterIPToMulticastIP(L"ClusterIPToMulticastIP");
  102. parameterStoreWhistler.push_back( &ClusterIPToMulticastIP );
  103. MWmiParameter MulticastIPAddress(L"MulticastIPAddress");
  104. parameterStoreWhistler.push_back( &MulticastIPAddress );
  105. // Edited( mhakim 02-09-01)
  106. // now no longer do we have any igmpjoininterval property.
  107. //
  108. // MWmiParameter IgmpJoinInterval(L"IgmpJoinInterval");
  109. // parameterStoreWhistler.push_back( &IgmpJoinInterval );
  110. // get instances of clustersetting class.
  111. //
  112. vector< MWmiInstance > instanceStore;
  113. _bstr_t relPath = L"MicrosoftNLB_ClusterSetting.Name=\"" + clusterIP + L":" + hostID + L"\"";
  114. p_machine->getSpecificInstance( L"MicrosoftNLB_ClusterSetting",
  115. relPath,
  116. &instanceStore );
  117. // get win2k parameters
  118. instanceStore[0].getParameters( parameterStoreWin2k );
  119. // get whistler parameters
  120. bool machineIsWhistler = true;
  121. try
  122. {
  123. // this will fail on win2k
  124. // as adapterguid, igmpsupport etc are not present.
  125. instanceStore[0].getParameters( parameterStoreWhistler );
  126. }
  127. catch( _com_error e )
  128. {
  129. // maybe it was a win2k machine. This exception is expected, thus catch.
  130. // for better safety, need to find exact error code returned and then only do the
  131. // folllowing otherwise need to rethrow.
  132. //
  133. TRACE( MTrace::INFO, L"tried whistler operation on win2k, this is expected\n");
  134. machineIsWhistler = false;
  135. }
  136. cp->cIP = ClusterIPAddress.getValue();
  137. cp->cSubnetMask = ClusterNetworkMask.getValue();
  138. cp->cFullInternetName = ClusterName.getValue();
  139. cp->cNetworkAddress = ClusteMACAddress.getValue();
  140. cp->multicastSupportEnabled = MulticastSupportEnabled.getValue();
  141. cp->remoteControlEnabled = RemoteControlEnabled.getValue();
  142. if( machineIsWhistler == true )
  143. {
  144. cp->igmpSupportEnabled = IgmpSupport.getValue();
  145. cp->clusterIPToMulticastIP = ClusterIPToMulticastIP.getValue();
  146. cp->multicastIPAddress = MulticastIPAddress.getValue();
  147. // Edited( mhakim 02-09-01)
  148. // now no longer do we have any igmpjoininterval property.
  149. //
  150. // cp->igmpJoinInterval = IgmpJoinInterval.getValue();
  151. }
  152. return MNLBProviderSetting_SUCCESS;
  153. }
  154. // getHostProperties
  155. //
  156. MNLBProviderSetting::MNLBProviderSetting_Error
  157. MNLBProviderSetting::getHostProperties( HostProperties* hp )
  158. {
  159. _bstr_t clusterIP;
  160. _bstr_t hostID;
  161. getClusterIPAndHostID( clusterIP, hostID );
  162. // get node properties
  163. //
  164. vector<MWmiParameter* > parameterStoreWin2k;
  165. // the status code is to be got from the Node class.
  166. //
  167. MWmiParameter StatusCode(L"StatusCode");
  168. parameterStoreWin2k.push_back( &StatusCode );
  169. vector< MWmiInstance > instanceStore;
  170. _bstr_t relPath = L"MicrosoftNLB_Node.Name=\"" + clusterIP + L":" + hostID + L"\"";
  171. p_machine->getSpecificInstance( L"MicrosoftNLB_Node",
  172. relPath,
  173. &instanceStore );
  174. instanceStore[0].getParameters( parameterStoreWin2k );
  175. hp->hostStatus = long( StatusCode.getValue() );
  176. parameterStoreWin2k.erase( parameterStoreWin2k.begin(), parameterStoreWin2k.end() );
  177. instanceStore.erase( instanceStore.begin(), instanceStore.end() );
  178. MWmiParameter DedicatedIPAddress(L"DedicatedIPAddress");
  179. parameterStoreWin2k.push_back( &DedicatedIPAddress );
  180. MWmiParameter DedicatedNetworkMask(L"DedicatedNetworkMask");
  181. parameterStoreWin2k.push_back( &DedicatedNetworkMask );
  182. MWmiParameter HostPriority(L"HostPriority");
  183. parameterStoreWin2k.push_back( &HostPriority );
  184. MWmiParameter ClusterModeOnStart(L"ClusterModeOnStart");
  185. parameterStoreWin2k.push_back( &ClusterModeOnStart );
  186. MWmiParameter Server("__Server");
  187. parameterStoreWin2k.push_back( &Server);
  188. // set parameters to get for whistler
  189. // these properties only present in whistler.
  190. //
  191. vector<MWmiParameter* > parameterStoreWhistler;
  192. MWmiParameter AdapterGuid(L"AdapterGuid");
  193. parameterStoreWhistler.push_back( &AdapterGuid );
  194. // get instances of nodesetting class.
  195. //
  196. relPath = L"MicrosoftNLB_NodeSetting.Name=\"" + clusterIP + L":" + hostID + L"\"";
  197. p_machine->getSpecificInstance( L"MicrosoftNLB_NodeSetting",
  198. relPath,
  199. &instanceStore );
  200. // get win2k parameters.
  201. instanceStore[0].getParameters( parameterStoreWin2k );
  202. // get whistler parameters
  203. bool machineIsWhistler = true;
  204. try
  205. {
  206. // this will fail on win2k
  207. // as adapterguid, igmpsupport etc are not present.
  208. instanceStore[0].getParameters( parameterStoreWhistler );
  209. }
  210. catch( _com_error e )
  211. {
  212. // maybe it was a win2k machine. This exception is expected, thus catch.
  213. // for better safety, need to find exact error code returned and then only do the
  214. // folllowing otherwise need to rethrow.
  215. //
  216. TRACE( MTrace::INFO, L"tried whistler operation on win2k, this is expected\n");
  217. machineIsWhistler = false;
  218. }
  219. hp->hIP = DedicatedIPAddress.getValue();
  220. hp->hSubnetMask = DedicatedNetworkMask.getValue();
  221. hp->hID = HostPriority.getValue();
  222. hp->initialClusterStateActive = ClusterModeOnStart.getValue();
  223. hp->machineName = Server.getValue();
  224. return MNLBProviderSetting_SUCCESS;
  225. }
  226. // setClusterProperties
  227. //
  228. MNLBProviderSetting::MNLBProviderSetting_Error
  229. MNLBProviderSetting::setClusterProperties( const ClusterProperties& cp,
  230. unsigned long* retVal
  231. )
  232. {
  233. _bstr_t clusterIP;
  234. _bstr_t hostID;
  235. getClusterIPAndHostID( clusterIP, hostID );
  236. // set parameters to set for win2k
  237. vector<MWmiParameter* > parameterStoreWin2k;
  238. MWmiParameter ClusterIPAddress(L"ClusterIPAddress");
  239. ClusterIPAddress.setValue( cp.cIP );
  240. parameterStoreWin2k.push_back( &ClusterIPAddress );
  241. MWmiParameter ClusterNetworkMask(L"ClusterNetworkMask");
  242. ClusterNetworkMask.setValue( cp.cSubnetMask );
  243. parameterStoreWin2k.push_back( &ClusterNetworkMask );
  244. MWmiParameter ClusterName(L"ClusterName");
  245. ClusterName.setValue( cp.cFullInternetName );
  246. parameterStoreWin2k.push_back( &ClusterName );
  247. // mac address cannot be set.
  248. MWmiParameter MulticastSupportEnabled(L"MulticastSupportEnabled");
  249. MulticastSupportEnabled.setValue( cp.multicastSupportEnabled );
  250. parameterStoreWin2k.push_back( &MulticastSupportEnabled );
  251. MWmiParameter RemoteControlEnabled(L"RemoteControlEnabled");
  252. RemoteControlEnabled.setValue( cp.remoteControlEnabled );
  253. parameterStoreWin2k.push_back( &RemoteControlEnabled );
  254. // set parameters for whistler.
  255. // these properties only for whistler
  256. vector<MWmiParameter* > parameterStoreWhistler;
  257. MWmiParameter IgmpSupport(L"IgmpSupport");
  258. IgmpSupport.setValue( cp.igmpSupportEnabled );
  259. parameterStoreWhistler.push_back( &IgmpSupport );
  260. MWmiParameter ClusterIPToMulticastIP(L"ClusterIPToMulticastIP");
  261. ClusterIPToMulticastIP.setValue( cp.clusterIPToMulticastIP );
  262. parameterStoreWhistler.push_back( &ClusterIPToMulticastIP );
  263. MWmiParameter MulticastIPAddress(L"MulticastIPAddress");
  264. MulticastIPAddress.setValue( cp.multicastIPAddress );
  265. parameterStoreWhistler.push_back( &MulticastIPAddress );
  266. // Edited( mhakim 02-09-01)
  267. // now no longer do we have any igmpjoininterval property.
  268. //
  269. // MWmiParameter IgmpJoinInterval(L"IgmpJoinInterval");
  270. // IgmpJoinInterval.setValue( cp.igmpJoinInterval );
  271. // parameterStoreWhistler.push_back( &IgmpJoinInterval );
  272. vector< MWmiInstance > instanceStore;
  273. _bstr_t relPath = L"MicrosoftNLB_ClusterSetting.Name=\"" + clusterIP + L":" + hostID + L"\"";
  274. p_machine->getSpecificInstance( L"MicrosoftNLB_ClusterSetting",
  275. relPath,
  276. &instanceStore );
  277. // Edited( mhakim 02-14-01)
  278. //
  279. // The order in which win2k and whistler operations
  280. // need to be done depends on previous state of cluster.
  281. // If the previous mode of cluster was unicast, then
  282. // you have to do win2k first, whistler next.
  283. // If the previous mode was mcast+igmp you have to
  284. // do whistler first, win2k next.
  285. // If the previous mode was mcast, the order does not
  286. // matter.
  287. // All this is because you cant have unicast+igmp
  288. // together.
  289. // find previous cluster mode.
  290. ClusterProperties cpPrevious;
  291. getClusterProperties( &cpPrevious );
  292. if( cpPrevious.multicastSupportEnabled == false )
  293. {
  294. // mode is unicast
  295. // set win2k parameters.
  296. instanceStore[0].setParameters( parameterStoreWin2k );
  297. // set whistler parameters.
  298. try
  299. {
  300. instanceStore[0].setParameters( parameterStoreWhistler );
  301. }
  302. catch( _com_error e )
  303. {
  304. // maybe it was a win2k machine. This exception is expected, thus catch.
  305. // For better safety, need to match error code returned with expected and then only do the
  306. // folllowing otherwise need to rethrow.
  307. //
  308. TRACE( MTrace::INFO, L"tried whistler operation on win2k, this is expected\n");
  309. }
  310. }
  311. else
  312. {
  313. // set whistler parameters.
  314. try
  315. {
  316. instanceStore[0].setParameters( parameterStoreWhistler );
  317. }
  318. catch( _com_error e )
  319. {
  320. // maybe it was a win2k machine. This exception is expected, thus catch.
  321. // For better safety, need to match error code returned with expected and then only do the
  322. // folllowing otherwise need to rethrow.
  323. //
  324. TRACE( MTrace::INFO, L"tried whistler operation on win2k, this is expected\n");
  325. }
  326. // set win2k parameters.
  327. instanceStore[0].setParameters( parameterStoreWin2k );
  328. }
  329. // sync up the driver with these changes.
  330. reload( retVal );
  331. return MNLBProviderSetting_SUCCESS;
  332. }
  333. // setHostProperties
  334. //
  335. MNLBProviderSetting::MNLBProviderSetting_Error
  336. MNLBProviderSetting::setHostProperties( const HostProperties& hp,
  337. unsigned long* retVal )
  338. {
  339. _bstr_t clusterIP;
  340. _bstr_t hostID;
  341. getClusterIPAndHostID( clusterIP, hostID );
  342. // set node properties
  343. //
  344. vector<MWmiParameter* > parameterStore;
  345. MWmiParameter DedicatedIPAddress(L"DedicatedIPAddress");
  346. DedicatedIPAddress.setValue( hp.hIP );
  347. parameterStore.push_back( &DedicatedIPAddress );
  348. MWmiParameter DedicatedNetworkMask(L"DedicatedNetworkMask");
  349. DedicatedNetworkMask.setValue( hp.hSubnetMask );
  350. parameterStore.push_back( &DedicatedNetworkMask );
  351. MWmiParameter HostPriority(L"HostPriority");
  352. HostPriority.setValue( hp.hID );
  353. parameterStore.push_back( &HostPriority );
  354. MWmiParameter ClusterModeOnStart(L"ClusterModeOnStart");
  355. ClusterModeOnStart.setValue( hp.initialClusterStateActive );
  356. parameterStore.push_back( &ClusterModeOnStart );
  357. // get instances of nodesetting class.
  358. //
  359. vector< MWmiInstance > instanceStore;
  360. _bstr_t relPath = L"MicrosoftNLB_NodeSetting.Name=\"" + clusterIP + L":" + hostID + L"\"";
  361. p_machine->getSpecificInstance( L"MicrosoftNLB_NodeSetting",
  362. relPath,
  363. &instanceStore );
  364. instanceStore[0].setParameters( parameterStore );
  365. // sync up the driver with these changes.
  366. reload( retVal );
  367. return MNLBProviderSetting_SUCCESS;
  368. }
  369. // getPortRulesLoadBalanced
  370. //
  371. MNLBProviderSetting::MNLBProviderSetting_Error
  372. MNLBProviderSetting::getPortRulesLoadBalanced( vector<MNLBPortRuleLoadBalanced>* portsLB )
  373. {
  374. vector<MWmiInstance> instanceStore;
  375. return getPortRulesLoadBalanced_private( portsLB,
  376. &instanceStore );
  377. }
  378. // getPortRulesLoadBalanced_private
  379. //
  380. MNLBProviderSetting::MNLBProviderSetting_Error
  381. MNLBProviderSetting::getPortRulesLoadBalanced_private( vector<MNLBPortRuleLoadBalanced>* portsLB,
  382. vector<MWmiInstance>* instances )
  383. {
  384. _bstr_t clusterIP;
  385. _bstr_t hostID;
  386. getClusterIPAndHostID( clusterIP, hostID );
  387. _bstr_t myName = clusterIP + L":" + hostID;
  388. // get port properties.
  389. //
  390. vector<MWmiParameter* > parameterStore;
  391. MWmiParameter Name(L"Name");
  392. parameterStore.push_back( &Name );
  393. MWmiParameter StartPort(L"StartPort");
  394. parameterStore.push_back( &StartPort );
  395. MWmiParameter EndPort(L"EndPort");
  396. parameterStore.push_back( &EndPort );
  397. MWmiParameter ProtocolProp(L"Protocol");
  398. parameterStore.push_back( &ProtocolProp );
  399. MWmiParameter EqualLoad(L"EqualLoad");
  400. parameterStore.push_back( &EqualLoad );
  401. MWmiParameter LoadWeight(L"LoadWeight");
  402. parameterStore.push_back( &LoadWeight );
  403. MWmiParameter AffinityProp(L"Affinity");
  404. parameterStore.push_back( &AffinityProp );
  405. MNLBPortRule::Affinity affinity;
  406. MNLBPortRule::Protocol trafficToHandle;
  407. p_machine->getInstances( L"MicrosoftNLB_PortRuleLoadBalanced",
  408. instances );
  409. for( int i = 0; i < instances->size(); ++i )
  410. {
  411. (*instances)[i].getParameters( parameterStore );
  412. if( _bstr_t( Name.getValue() ) != myName )
  413. {
  414. // this portrule is not for this cluster
  415. continue;
  416. }
  417. switch( long (ProtocolProp.getValue()) )
  418. {
  419. case 1:
  420. trafficToHandle = MNLBPortRule::tcp;
  421. break;
  422. case 2:
  423. trafficToHandle = MNLBPortRule::udp;
  424. break;
  425. case 3:
  426. trafficToHandle = MNLBPortRule::both;
  427. break;
  428. default:
  429. // bug.
  430. TRACE( MTrace::SEVERE_ERROR, "unidentified protocol\n" );
  431. throw _com_error( WBEM_E_UNEXPECTED );
  432. break;
  433. }
  434. switch( long(AffinityProp.getValue()) )
  435. {
  436. case 0:
  437. affinity = MNLBPortRule::none;
  438. break;
  439. case 1:
  440. affinity = MNLBPortRule::single;
  441. break;
  442. case 2:
  443. affinity = MNLBPortRule::classC;
  444. break;
  445. default:
  446. // bug.
  447. TRACE( MTrace::SEVERE_ERROR, "unidentified affinity\n" );
  448. throw _com_error( WBEM_E_UNEXPECTED );
  449. break;
  450. }
  451. portsLB->push_back( MNLBPortRuleLoadBalanced(long (StartPort.getValue()),
  452. long( EndPort.getValue()),
  453. trafficToHandle,
  454. bool( EqualLoad.getValue()),
  455. long( LoadWeight.getValue()),
  456. affinity) );
  457. }
  458. return MNLBProviderSetting_SUCCESS;
  459. }
  460. // getPortRulesFailover
  461. //
  462. MNLBProviderSetting::MNLBProviderSetting_Error
  463. MNLBProviderSetting::getPortRulesFailover( vector<MNLBPortRuleFailover>* portsF )
  464. {
  465. vector<MWmiInstance> instanceStore;
  466. return getPortRulesFailover_private( portsF,
  467. &instanceStore );
  468. }
  469. // getPortRulesFailover_private
  470. //
  471. MNLBProviderSetting::MNLBProviderSetting_Error
  472. MNLBProviderSetting::getPortRulesFailover_private( vector<MNLBPortRuleFailover>* portsF,
  473. vector<MWmiInstance>* instances )
  474. {
  475. _bstr_t clusterIP;
  476. _bstr_t hostID;
  477. getClusterIPAndHostID( clusterIP, hostID );
  478. _bstr_t myName = clusterIP + L":" + hostID;
  479. // get port properties.
  480. //
  481. vector<MWmiParameter* > parameterStore;
  482. MWmiParameter Name(L"Name");
  483. parameterStore.push_back( &Name );
  484. MWmiParameter StartPort(L"StartPort");
  485. parameterStore.push_back( &StartPort );
  486. MWmiParameter EndPort(L"EndPort");
  487. parameterStore.push_back( &EndPort );
  488. MWmiParameter ProtocolProp(L"Protocol");
  489. parameterStore.push_back( &ProtocolProp );
  490. MWmiParameter Priority(L"Priority");
  491. parameterStore.push_back( &Priority );
  492. MNLBPortRule::Protocol trafficToHandle;
  493. p_machine->getInstances( L"MicrosoftNLB_PortRuleFailover",
  494. instances );
  495. for( int i = 0; i < instances->size(); ++i )
  496. {
  497. (*instances)[i].getParameters( parameterStore );
  498. if( _bstr_t( Name.getValue() ) != myName )
  499. {
  500. // this portrule is not for this cluster
  501. continue;
  502. }
  503. switch( long (ProtocolProp.getValue()) )
  504. {
  505. case 1:
  506. trafficToHandle = MNLBPortRule::tcp;
  507. break;
  508. case 2:
  509. trafficToHandle = MNLBPortRule::udp;
  510. break;
  511. case 3:
  512. trafficToHandle = MNLBPortRule::both;
  513. break;
  514. default:
  515. // bug.
  516. TRACE( MTrace::SEVERE_ERROR, "unidentified protocol\n" );
  517. throw _com_error( WBEM_E_UNEXPECTED );
  518. break;
  519. }
  520. portsF->push_back( MNLBPortRuleFailover(long (StartPort.getValue()),
  521. long( EndPort.getValue()),
  522. trafficToHandle,
  523. long( Priority.getValue()) )
  524. );
  525. }
  526. return MNLBProviderSetting_SUCCESS;
  527. }
  528. // getPortRulesDisabled
  529. //
  530. MNLBProviderSetting::MNLBProviderSetting_Error
  531. MNLBProviderSetting::getPortRulesDisabled( vector<MNLBPortRuleDisabled>* portsD )
  532. {
  533. vector<MWmiInstance> instanceStore;
  534. return getPortRulesDisabled_private( portsD,
  535. &instanceStore );
  536. }
  537. // getPortRulesDisabled_private
  538. //
  539. MNLBProviderSetting::MNLBProviderSetting_Error
  540. MNLBProviderSetting::getPortRulesDisabled_private( vector<MNLBPortRuleDisabled>* portsD,
  541. vector<MWmiInstance>* instances )
  542. {
  543. _bstr_t clusterIP;
  544. _bstr_t hostID;
  545. getClusterIPAndHostID( clusterIP, hostID );
  546. _bstr_t myName = clusterIP + L":" + hostID;
  547. // get port properties.
  548. //
  549. vector<MWmiParameter* > parameterStore;
  550. MWmiParameter Name(L"Name");
  551. parameterStore.push_back( &Name );
  552. MWmiParameter StartPort(L"StartPort");
  553. parameterStore.push_back( &StartPort );
  554. MWmiParameter EndPort(L"EndPort");
  555. parameterStore.push_back( &EndPort );
  556. MWmiParameter ProtocolProp(L"Protocol");
  557. parameterStore.push_back( &ProtocolProp );
  558. MNLBPortRule::Protocol trafficToHandle;
  559. p_machine->getInstances( L"MicrosoftNLB_PortRuleDisabled",
  560. instances );
  561. for( int i = 0; i < instances->size(); ++i )
  562. {
  563. (*instances)[i].getParameters( parameterStore );
  564. if( _bstr_t( Name.getValue() ) != myName )
  565. {
  566. // this portrule is not for this cluster
  567. continue;
  568. }
  569. switch( long (ProtocolProp.getValue()) )
  570. {
  571. case 1:
  572. trafficToHandle = MNLBPortRule::tcp;
  573. break;
  574. case 2:
  575. trafficToHandle = MNLBPortRule::udp;
  576. break;
  577. case 3:
  578. trafficToHandle = MNLBPortRule::both;
  579. break;
  580. default:
  581. // bug.
  582. TRACE( MTrace::SEVERE_ERROR, "unidentified protocol\n" );
  583. throw _com_error( WBEM_E_UNEXPECTED );
  584. break;
  585. }
  586. portsD->push_back( MNLBPortRuleDisabled( long (StartPort.getValue() ),
  587. long( EndPort.getValue() ),
  588. trafficToHandle ) );
  589. }
  590. return MNLBProviderSetting_SUCCESS;
  591. }
  592. // addPortRuleLoadBalanced
  593. //
  594. MNLBProviderSetting::MNLBProviderSetting_Error
  595. MNLBProviderSetting::addPortRuleLoadBalanced( const MNLBPortRuleLoadBalanced& portRuleLB )
  596. {
  597. _bstr_t clusterIP;
  598. _bstr_t hostID;
  599. getClusterIPAndHostID( clusterIP, hostID );
  600. // set the name as "clusterip:hostid"
  601. _bstr_t str;
  602. str = clusterIP + L":" + hostID;
  603. vector<MWmiParameter *> instanceParameter;
  604. MWmiParameter name(L"Name");
  605. name.setValue( str );
  606. instanceParameter.push_back( &name );
  607. MWmiParameter sp(L"StartPort");
  608. sp.setValue( portRuleLB._startPort );
  609. instanceParameter.push_back( &sp );
  610. MWmiParameter EndPort(L"EndPort");
  611. EndPort.setValue( portRuleLB._endPort );
  612. instanceParameter.push_back( &EndPort );
  613. long protocolValue;
  614. MWmiParameter protocol(L"Protocol");
  615. switch( portRuleLB._trafficToHandle )
  616. {
  617. case MNLBPortRule::both:
  618. protocolValue = 3;
  619. protocol.setValue( protocolValue );
  620. break;
  621. case MNLBPortRule::tcp:
  622. protocolValue = 1;
  623. protocol.setValue( protocolValue );
  624. break;
  625. case MNLBPortRule::udp:
  626. protocolValue = 2;
  627. protocol.setValue( protocolValue );
  628. break;
  629. default:
  630. // bug.
  631. TRACE( MTrace::SEVERE_ERROR, "unidentified protocol\n" );
  632. throw _com_error( WBEM_E_UNEXPECTED );
  633. break;
  634. }
  635. instanceParameter.push_back( &protocol );
  636. MWmiParameter el(L"EqualLoad");
  637. el.setValue( portRuleLB._isEqualLoadBalanced );
  638. instanceParameter.push_back( &el );
  639. MWmiParameter lw(L"LoadWeight");
  640. lw.setValue( portRuleLB._load );
  641. instanceParameter.push_back( &lw );
  642. MWmiParameter affinity(L"Affinity");
  643. long affinityValue;
  644. switch( portRuleLB._affinity )
  645. {
  646. case MNLBPortRule::none:
  647. affinityValue = 0;
  648. affinity.setValue(affinityValue);
  649. break;
  650. case MNLBPortRule::single:
  651. affinityValue = 1;
  652. affinity.setValue(affinityValue);
  653. break;
  654. case MNLBPortRule::classC:
  655. affinityValue = 2;
  656. affinity.setValue(affinityValue);
  657. break;
  658. default:
  659. // bug.
  660. TRACE( MTrace::SEVERE_ERROR, "unidentified affinity\n" );
  661. throw _com_error( WBEM_E_UNEXPECTED );
  662. break;
  663. }
  664. instanceParameter.push_back( &affinity );
  665. p_machine->createInstance( L"MicrosoftNLB_PortRuleLoadBalanced",
  666. instanceParameter
  667. );
  668. // sync up the driver with these changes.
  669. unsigned long retVal;
  670. reload( &retVal );
  671. return MNLBProviderSetting_SUCCESS;
  672. }
  673. // addPortRuleFailover
  674. //
  675. MNLBProviderSetting::MNLBProviderSetting_Error
  676. MNLBProviderSetting::addPortRuleFailover( const MNLBPortRuleFailover& portRuleF )
  677. {
  678. _bstr_t clusterIP;
  679. _bstr_t hostID;
  680. getClusterIPAndHostID( clusterIP, hostID );
  681. // set the name as "clusterip:hostid"
  682. _bstr_t str;
  683. str = clusterIP + L":" + hostID;
  684. vector<MWmiParameter *> instanceParameter;
  685. MWmiParameter name(L"Name");
  686. name.setValue( str );
  687. instanceParameter.push_back( &name );
  688. MWmiParameter sp(L"StartPort");
  689. sp.setValue( portRuleF._startPort );
  690. instanceParameter.push_back( &sp );
  691. MWmiParameter EndPort(L"EndPort");
  692. EndPort.setValue( portRuleF._endPort );
  693. instanceParameter.push_back( &EndPort );
  694. long protocolValue;
  695. MWmiParameter protocol(L"Protocol");
  696. switch( portRuleF._trafficToHandle )
  697. {
  698. case MNLBPortRule::both:
  699. protocolValue = 3;
  700. protocol.setValue( protocolValue );
  701. break;
  702. case MNLBPortRule::tcp:
  703. protocolValue = 1;
  704. protocol.setValue( protocolValue );
  705. break;
  706. case MNLBPortRule::udp:
  707. protocolValue = 2;
  708. protocol.setValue( protocolValue );
  709. break;
  710. default:
  711. TRACE( MTrace::SEVERE_ERROR, "unidentified protocol\n" );
  712. throw _com_error( WBEM_E_UNEXPECTED );
  713. break;
  714. }
  715. instanceParameter.push_back( &protocol );
  716. MWmiParameter p("Priority");
  717. p.setValue( portRuleF._priority);
  718. instanceParameter.push_back( &p );
  719. p_machine->createInstance( L"MicrosoftNLB_PortRuleFailover",
  720. instanceParameter
  721. );
  722. // sync up the driver with these changes.
  723. unsigned long retVal;
  724. reload( &retVal );
  725. return MNLBProviderSetting_SUCCESS;
  726. }
  727. // addPortRuleDisabled
  728. //
  729. MNLBProviderSetting::MNLBProviderSetting_Error
  730. MNLBProviderSetting::addPortRuleDisabled( const MNLBPortRuleDisabled& portRuleD )
  731. {
  732. _bstr_t clusterIP;
  733. _bstr_t hostID;
  734. getClusterIPAndHostID( clusterIP, hostID );
  735. // set the name as "clusterip:hostid"
  736. _bstr_t str;
  737. str = clusterIP + L":" + hostID;
  738. vector<MWmiParameter *> instanceParameter;
  739. MWmiParameter name(L"Name");
  740. name.setValue( str );
  741. instanceParameter.push_back( &name );
  742. MWmiParameter sp(L"StartPort");
  743. sp.setValue( portRuleD._startPort );
  744. instanceParameter.push_back( &sp );
  745. MWmiParameter ep(L"EndPort");
  746. ep.setValue( portRuleD._endPort );
  747. instanceParameter.push_back( &ep );
  748. long protocolValue;
  749. MWmiParameter protocol(L"Protocol");
  750. switch( portRuleD._trafficToHandle )
  751. {
  752. case MNLBPortRule::both:
  753. protocolValue = 3;
  754. protocol.setValue( protocolValue );
  755. break;
  756. case MNLBPortRule::tcp:
  757. protocolValue = 1;
  758. protocol.setValue( protocolValue );
  759. break;
  760. case MNLBPortRule::udp:
  761. protocolValue = 2;
  762. protocol.setValue( protocolValue );
  763. break;
  764. default:
  765. // bug.
  766. TRACE( MTrace::SEVERE_ERROR, "unidentified protocol\n" );
  767. throw _com_error( WBEM_E_UNEXPECTED );
  768. break;
  769. }
  770. instanceParameter.push_back( &protocol );
  771. p_machine->createInstance( L"MicrosoftNLB_PortRuleDisabled",
  772. instanceParameter
  773. );
  774. // sync up the driver with these changes.
  775. unsigned long retVal;
  776. reload( &retVal );
  777. return MNLBProviderSetting_SUCCESS;
  778. }
  779. // removePortRuleLoadBalanced
  780. //
  781. MNLBProviderSetting::MNLBProviderSetting_Error
  782. MNLBProviderSetting::removePortRuleLoadBalanced( const MNLBPortRuleLoadBalanced& portRuleLB )
  783. {
  784. _bstr_t clusterIP;
  785. _bstr_t hostID;
  786. getClusterIPAndHostID( clusterIP, hostID );
  787. _bstr_t myName = clusterIP + L":" + hostID;
  788. wchar_t startPortBuffer[Common::BUF_SIZE];
  789. swprintf( startPortBuffer, L"%d", portRuleLB._startPort );
  790. vector<MWmiInstance > instanceStorePortRuleLoadBalanced;
  791. _bstr_t relPath = L"MicrosoftNLB_PortRuleLoadBalanced.Name=\""
  792. + clusterIP + L":" + hostID + L"\"" + L"," + L"StartPort=" + startPortBuffer;
  793. p_machine->getSpecificInstance( L"MicrosoftNlb_PortRuleLoadBalanced",
  794. relPath,
  795. &instanceStorePortRuleLoadBalanced );
  796. p_machine->deleteInstance( instanceStorePortRuleLoadBalanced[0] );
  797. // sync up the driver with these changes.
  798. unsigned long retVal;
  799. reload( &retVal );
  800. return MNLBProviderSetting_SUCCESS;
  801. }
  802. // removePortRuleFailover
  803. //
  804. MNLBProviderSetting::MNLBProviderSetting_Error
  805. MNLBProviderSetting::removePortRuleFailover( const MNLBPortRuleFailover& portRuleF )
  806. {
  807. _bstr_t clusterIP;
  808. _bstr_t hostID;
  809. getClusterIPAndHostID( clusterIP, hostID );
  810. _bstr_t myName = clusterIP + L":" + hostID;
  811. wchar_t startPortBuffer[Common::BUF_SIZE];
  812. swprintf( startPortBuffer, L"%d", portRuleF._startPort );
  813. vector<MWmiInstance > instanceStorePortRuleFailover;
  814. _bstr_t relPath = L"MicrosoftNLB_PortRuleFailover.Name=\""
  815. + clusterIP + L":" + hostID + L"\"" + L"," + L"StartPort=" + startPortBuffer;
  816. p_machine->getSpecificInstance( L"MicrosoftNlb_PortRuleFailover",
  817. relPath,
  818. &instanceStorePortRuleFailover );
  819. p_machine->deleteInstance( instanceStorePortRuleFailover[0] );
  820. // sync up the driver with these changes.
  821. unsigned long retVal;
  822. reload( &retVal );
  823. return MNLBProviderSetting_SUCCESS;
  824. }
  825. // removePortRuleDisabled
  826. //
  827. MNLBProviderSetting::MNLBProviderSetting_Error
  828. MNLBProviderSetting::removePortRuleDisabled( const MNLBPortRuleDisabled& portRuleD )
  829. {
  830. _bstr_t clusterIP;
  831. _bstr_t hostID;
  832. getClusterIPAndHostID( clusterIP, hostID );
  833. _bstr_t myName = clusterIP + L":" + hostID;
  834. wchar_t startPortBuffer[Common::BUF_SIZE];
  835. swprintf( startPortBuffer, L"%d", portRuleD._startPort );
  836. vector<MWmiInstance > instanceStorePortRuleDisabled;
  837. _bstr_t relPath = L"MicrosoftNLB_PortRuleDisabled.Name=\""
  838. + clusterIP + L":" + hostID + L"\"" + L"," + L"StartPort=" + startPortBuffer;
  839. p_machine->getSpecificInstance( L"MicrosoftNlb_PortRuleDisabled",
  840. relPath,
  841. &instanceStorePortRuleDisabled );
  842. p_machine->deleteInstance( instanceStorePortRuleDisabled[0] );
  843. // sync up the driver with these changes.
  844. unsigned long retVal;
  845. reload( &retVal );
  846. return MNLBProviderSetting_SUCCESS;
  847. }
  848. // getClusterIPAndHostID
  849. //
  850. MNLBProviderSetting::MNLBProviderSetting_Error
  851. MNLBProviderSetting::getClusterIPAndHostID( _bstr_t& clusterIP,
  852. _bstr_t& hostID )
  853. {
  854. //
  855. // this ensures that nic is present, and bound to nlbs
  856. // on nic specified at construction time.
  857. //
  858. _bstr_t guid;
  859. checkNicBinding( guid );
  860. //
  861. // find clustersettingclass mapping to this nic.
  862. //
  863. // set parameters to get.
  864. //
  865. vector<MWmiParameter* > parameterStore;
  866. MWmiParameter Name(L"Name");
  867. parameterStore.push_back( &Name );
  868. // get guid
  869. // This parameter not present on win2k nlbs provider.
  870. //
  871. MWmiParameter AdapterGuid(L"AdapterGuid");
  872. parameterStore.push_back( &AdapterGuid );
  873. // get instances of clustersetting class.
  874. //
  875. vector< MWmiInstance > instanceStore;
  876. bool found = false;
  877. int i;
  878. p_machine->getInstances( L"Microsoftnlb_ClusterSetting",
  879. &instanceStore );
  880. found = false;
  881. for( i = 0; i < instanceStore.size(); ++i )
  882. {
  883. try
  884. {
  885. instanceStore[i].getParameters( parameterStore );
  886. }
  887. catch( _com_error e )
  888. {
  889. // the above operation can fail on win2k machines.
  890. // if so we need to handle exception. This clustersetting is the actual one
  891. // required.
  892. found = true;
  893. break; // get out of for loop.
  894. }
  895. if( guid == _bstr_t( AdapterGuid.getValue() ) )
  896. {
  897. // right object found
  898. found = true;
  899. break;
  900. }
  901. }
  902. if( found == false )
  903. {
  904. TRACE(MTrace::SEVERE_ERROR, L"this is unexpected and a bug. NlbsNic and ClusterSetting class guids may not be matching\n");
  905. throw _com_error( WBEM_E_UNEXPECTED );
  906. }
  907. _bstr_t name = _bstr_t( Name.getValue() );
  908. WTokens tok;
  909. vector<wstring> tokens;
  910. tok.init( wstring( name ),
  911. L":" );
  912. tokens = tok.tokenize();
  913. clusterIP = tokens[0].c_str();
  914. hostID = tokens[1].c_str();
  915. return MNLBProviderSetting_SUCCESS;
  916. }
  917. // connectToMachine
  918. //
  919. MNLBProviderSetting::MNLBProviderSetting_Error
  920. MNLBProviderSetting::connectToMachine()
  921. {
  922. // we want to connect to self machine.
  923. p_machine = auto_ptr< MWmiObject > ( new MWmiObject( L"root\\microsoftnlb") );
  924. // check if nic is bound to nlbs.
  925. _bstr_t guid;
  926. checkNicBinding( guid );
  927. return MNLBProviderSetting_SUCCESS;
  928. }
  929. // checkNicBinding
  930. //
  931. MNLBProviderSetting::MNLBProviderSetting_Error
  932. MNLBProviderSetting::checkNicBinding( _bstr_t& guid )
  933. {
  934. bool found = false;
  935. vector< NICCard::Info > nicList;
  936. NICCard::getNics( &nicList );
  937. for( int i = 0; i < nicList.size(); ++i )
  938. {
  939. if( _bstr_t( nicList[i].fullName.c_str() ) == nic )
  940. {
  941. // nic specified found.
  942. guid = nicList[i].guid.c_str();
  943. found = true;
  944. break;
  945. }
  946. }
  947. if( found != true )
  948. {
  949. TRACE(MTrace::SEVERE_ERROR, L"nic specified not found on machine\n");
  950. throw _com_error( WBEM_E_NOT_FOUND );
  951. }
  952. return MNLBProviderSetting_SUCCESS;
  953. }
  954. // reload
  955. //
  956. MNLBProviderSetting::MNLBProviderSetting_Error
  957. MNLBProviderSetting::reload( unsigned long* retVal )
  958. {
  959. _bstr_t clusterIP;
  960. _bstr_t hostID;
  961. getClusterIPAndHostID( clusterIP, hostID );
  962. // form path
  963. _bstr_t relPath = L"MicrosoftNLB_ClusterSetting.Name=\"" + clusterIP + L":" + hostID + L"\"";
  964. vector<MWmiInstance > instanceStoreClusterSetting;
  965. p_machine->getSpecificInstance( L"MicrosoftNLB_ClusterSetting",
  966. relPath,
  967. &instanceStoreClusterSetting );
  968. // input parameters are none.
  969. //
  970. vector<MWmiParameter *> inputParameters;
  971. // output parameters which are of interest.
  972. //
  973. vector<MWmiParameter *> outputParameters;
  974. MWmiParameter returnValue(L"ReturnValue");
  975. outputParameters.push_back( &returnValue );
  976. instanceStoreClusterSetting[0].runMethod( L"LoadAllSettings",
  977. inputParameters,
  978. outputParameters );
  979. *retVal = ( long ) returnValue.getValue();
  980. return MNLBProviderSetting_SUCCESS;
  981. }
  982. // setPassword
  983. //
  984. MNLBProviderSetting::MNLBProviderSetting_Error
  985. MNLBProviderSetting::setPassword( const _bstr_t& password,
  986. unsigned long* retVal
  987. )
  988. {
  989. _bstr_t clusterIP;
  990. _bstr_t hostID;
  991. getClusterIPAndHostID( clusterIP, hostID );
  992. // form path
  993. _bstr_t relPath = L"MicrosoftNLB_ClusterSetting.Name=\"" + clusterIP + L":" + hostID + L"\"";
  994. vector<MWmiInstance > instanceStoreClusterSetting;
  995. p_machine->getSpecificInstance( L"MicrosoftNLB_ClusterSetting",
  996. relPath,
  997. &instanceStoreClusterSetting );
  998. // input parameters is password
  999. //
  1000. vector<MWmiParameter *> inputParameters;
  1001. MWmiParameter Password(L"Password");
  1002. Password.setValue( password );
  1003. inputParameters.push_back( &Password );
  1004. // output parameters which are of interest.
  1005. // none.
  1006. //
  1007. vector<MWmiParameter *> outputParameters;
  1008. instanceStoreClusterSetting[0].runMethod( L"SetPassword",
  1009. inputParameters,
  1010. outputParameters );
  1011. reload( retVal );
  1012. return MNLBProviderSetting_SUCCESS;
  1013. }