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.

1300 lines
38 KiB

  1. #include "stdafx.h"
  2. #include "PortsPage.h"
  3. #include "ClusterPortsDlg.h"
  4. #include "HostPortsDlg.h"
  5. #include "Document.h"
  6. #include "wlbsparm.h"
  7. #include "ResourceString.h"
  8. #include "MNLBUIData.h"
  9. #include <vector>
  10. #include <map>
  11. #include <algorithm>
  12. using namespace std;
  13. BEGIN_MESSAGE_MAP(PortsPage, CPropertyPage)
  14. ON_BN_CLICKED(IDC_BUTTON_ADD, OnButtonAdd)
  15. ON_BN_CLICKED(IDC_BUTTON_DEL, OnButtonDel)
  16. ON_BN_CLICKED(IDC_BUTTON_MODIFY, OnButtonModify)
  17. ON_NOTIFY( NM_DBLCLK, IDC_LIST_PORT_RULE, OnDoubleClick )
  18. ON_NOTIFY( LVN_ITEMCHANGED, IDC_LIST_PORT_RULE, OnSelchanged )
  19. ON_NOTIFY( LVN_COLUMNCLICK, IDC_LIST_PORT_RULE, OnColumnClick )
  20. ON_WM_HELPINFO()
  21. ON_WM_CONTEXTMENU()
  22. END_MESSAGE_MAP()
  23. PortsPage::PortData::PortData()
  24. {
  25. wchar_t buf[Common::BUF_SIZE];
  26. swprintf( buf, L"%d", CVY_MIN_PORT );
  27. start_port = buf;
  28. swprintf( buf, L"%d", CVY_MAX_PORT );
  29. end_port = buf;
  30. protocol = GETRESOURCEIDSTRING( IDS_REPORT_PROTOCOL_BOTH );
  31. mode = GETRESOURCEIDSTRING( IDS_REPORT_MODE_MULTIPLE );
  32. load = GETRESOURCEIDSTRING( IDS_REPORT_LOAD_EQUAL );
  33. affinity = GETRESOURCEIDSTRING( IDS_REPORT_AFFINITY_SINGLE );
  34. }
  35. PortsPage::PortsPage( ClusterData* p_clusterData,
  36. UINT ID)
  37. : m_clusterData( p_clusterData ),
  38. m_isClusterLevel( true ),
  39. CPropertyPage(ID),
  40. m_sort_column( -1 )
  41. {}
  42. PortsPage::PortsPage( const _bstr_t& myMachineName,
  43. ClusterData* p_clusterData,
  44. UINT ID)
  45. : m_clusterData( p_clusterData ),
  46. machine( myMachineName ),
  47. m_isClusterLevel( false ),
  48. CPropertyPage(ID),
  49. m_sort_column( -1 )
  50. {}
  51. PortsPage:: ~PortsPage()
  52. {}
  53. void PortsPage::DoDataExchange(CDataExchange* pDX)
  54. {
  55. CPropertyPage::DoDataExchange(pDX);
  56. DDX_Control(pDX, IDC_LIST_PORT_RULE, m_portList);
  57. DDX_Control(pDX, IDC_BUTTON_ADD, buttonAdd );
  58. DDX_Control(pDX, IDC_BUTTON_MODIFY, buttonModify );
  59. DDX_Control(pDX, IDC_BUTTON_DEL, buttonDel );
  60. }
  61. void
  62. PortsPage::OnOK()
  63. {
  64. CPropertyPage::OnOK();
  65. }
  66. BOOL
  67. PortsPage::OnKillActive()
  68. {
  69. // get present port rules
  70. vector<PortData> ports;
  71. getPresentPorts( &ports );
  72. // now form the new port structure.
  73. PortDataELB elbPortRule;
  74. PortDataULB ulbPortRule;
  75. PortDataF fPortRule;
  76. PortDataD dPortRule;
  77. map< long, PortDataELB> portELB;
  78. map< long, PortDataULB> portULB;
  79. map< long, PortDataD> portD;
  80. map< long, PortDataF> portF;
  81. for( int i = 0; i < ports.size(); ++i )
  82. {
  83. // check which type of port rule it is.
  84. //
  85. if( ports[i].mode == GETRESOURCEIDSTRING( IDS_REPORT_MODE_MULTIPLE )
  86. &&
  87. ports[i].load == GETRESOURCEIDSTRING( IDS_REPORT_LOAD_EQUAL )
  88. )
  89. {
  90. // equal load balanced
  91. elbPortRule._startPort = _wtoi( ports[i].start_port );
  92. elbPortRule._endPort = _wtoi( ports[i].end_port );
  93. if( ports[i].protocol == GETRESOURCEIDSTRING( IDS_REPORT_PROTOCOL_BOTH ) )
  94. {
  95. elbPortRule._trafficToHandle = MNLBPortRule::both;
  96. }
  97. else if( ports[i].protocol == GETRESOURCEIDSTRING( IDS_REPORT_PROTOCOL_TCP ) )
  98. {
  99. elbPortRule._trafficToHandle = MNLBPortRule::tcp;
  100. }
  101. else if( ports[i].protocol == GETRESOURCEIDSTRING( IDS_REPORT_PROTOCOL_UDP ) )
  102. {
  103. elbPortRule._trafficToHandle = MNLBPortRule::udp;
  104. }
  105. if( ports[i].affinity == GETRESOURCEIDSTRING( IDS_REPORT_AFFINITY_NONE ) )
  106. {
  107. elbPortRule._affinity = MNLBPortRule::none;
  108. }
  109. else if( ports[i].affinity == GETRESOURCEIDSTRING( IDS_REPORT_AFFINITY_SINGLE ) )
  110. {
  111. elbPortRule._affinity = MNLBPortRule::single;
  112. }
  113. else if( ports[i].affinity == GETRESOURCEIDSTRING( IDS_REPORT_AFFINITY_CLASSC ) )
  114. {
  115. elbPortRule._affinity = MNLBPortRule::classC;
  116. }
  117. elbPortRule._key = elbPortRule._startPort;
  118. portELB[ elbPortRule._startPort ] = elbPortRule;
  119. }
  120. else if( ports[i].mode == GETRESOURCEIDSTRING( IDS_REPORT_MODE_MULTIPLE )
  121. &&
  122. ports[i].load != GETRESOURCEIDSTRING( IDS_REPORT_LOAD_EQUAL )
  123. )
  124. {
  125. // unequal load balanced
  126. ulbPortRule._startPort = _wtoi( ports[i].start_port );
  127. ulbPortRule._endPort = _wtoi( ports[i].end_port );
  128. if( ports[i].protocol == GETRESOURCEIDSTRING( IDS_REPORT_PROTOCOL_BOTH ) )
  129. {
  130. ulbPortRule._trafficToHandle = MNLBPortRule::both;
  131. }
  132. else if( ports[i].protocol == GETRESOURCEIDSTRING( IDS_REPORT_PROTOCOL_TCP ) )
  133. {
  134. ulbPortRule._trafficToHandle = MNLBPortRule::tcp;
  135. }
  136. else if( ports[i].protocol == GETRESOURCEIDSTRING( IDS_REPORT_PROTOCOL_UDP ) )
  137. {
  138. ulbPortRule._trafficToHandle = MNLBPortRule::udp;
  139. }
  140. if( ports[i].affinity == GETRESOURCEIDSTRING( IDS_REPORT_AFFINITY_NONE ) )
  141. {
  142. ulbPortRule._affinity = MNLBPortRule::none;
  143. }
  144. else if( ports[i].affinity == GETRESOURCEIDSTRING( IDS_REPORT_AFFINITY_SINGLE ) )
  145. {
  146. ulbPortRule._affinity = MNLBPortRule::single;
  147. }
  148. else if( ports[i].affinity == GETRESOURCEIDSTRING( IDS_REPORT_AFFINITY_CLASSC ) )
  149. {
  150. ulbPortRule._affinity = MNLBPortRule::classC;
  151. }
  152. if( ports[i].key == -1
  153. ||
  154. ( m_clusterData->portULB.find( ports[i].key )
  155. ==
  156. m_clusterData->portULB.end() )
  157. )
  158. {
  159. // new port rule.
  160. // user may change the rule completely if so
  161. // consider it as new.
  162. if( m_isClusterLevel == true )
  163. {
  164. map< _bstr_t, HostData >::iterator top;
  165. for( top = m_clusterData->hosts.begin();
  166. top != m_clusterData->hosts.end();
  167. ++top )
  168. {
  169. // default value is 50 load weight
  170. // for each machine
  171. ulbPortRule.machineMapToLoadWeight[(*top).first] = 50;
  172. }
  173. }
  174. else
  175. {
  176. ulbPortRule.machineMapToLoadWeight =
  177. m_clusterData->portULB[ ports[i].key ].machineMapToLoadWeight;
  178. ulbPortRule.machineMapToLoadWeight[machine]
  179. = _wtoi( ports[i].load );
  180. }
  181. }
  182. else
  183. {
  184. // existing port rule.
  185. ulbPortRule.machineMapToLoadWeight =
  186. m_clusterData->portULB[ ports[i].key ].machineMapToLoadWeight;
  187. if( m_isClusterLevel == false )
  188. {
  189. ulbPortRule.machineMapToLoadWeight[machine]
  190. = _wtoi( ports[i].load );
  191. }
  192. }
  193. ulbPortRule._key = ulbPortRule._startPort;
  194. portULB[ ulbPortRule._startPort ] = ulbPortRule;
  195. }
  196. else if( ports[i].mode == GETRESOURCEIDSTRING( IDS_REPORT_MODE_SINGLE ) )
  197. {
  198. // failover
  199. fPortRule._startPort = _wtoi( ports[i].start_port );
  200. fPortRule._endPort = _wtoi( ports[i].end_port );
  201. if( ports[i].protocol == GETRESOURCEIDSTRING( IDS_REPORT_PROTOCOL_BOTH ) )
  202. {
  203. fPortRule._trafficToHandle = MNLBPortRule::both;
  204. }
  205. else if( ports[i].protocol == GETRESOURCEIDSTRING( IDS_REPORT_PROTOCOL_TCP ) )
  206. {
  207. fPortRule._trafficToHandle = MNLBPortRule::tcp;
  208. }
  209. else if( ports[i].protocol == GETRESOURCEIDSTRING( IDS_REPORT_PROTOCOL_UDP ) )
  210. {
  211. fPortRule._trafficToHandle = MNLBPortRule::udp;
  212. }
  213. if( ports[i].key == -1
  214. ||
  215. ( m_clusterData->portF.find( ports[i].key )
  216. ==
  217. m_clusterData->portF.end() )
  218. )
  219. {
  220. // new port rule.
  221. // by default make priority equal to host id.
  222. if( m_isClusterLevel == true )
  223. {
  224. map< _bstr_t, HostData >::iterator top;
  225. for( top = m_clusterData->hosts.begin();
  226. top != m_clusterData->hosts.end();
  227. ++top )
  228. {
  229. fPortRule.machineMapToPriority[(*top).first] = (*top).second.hp.hID;
  230. }
  231. }
  232. else
  233. {
  234. fPortRule.machineMapToPriority =
  235. m_clusterData->portF[ ports[i].key ].machineMapToPriority;
  236. fPortRule.machineMapToPriority[machine]
  237. = _wtoi( ports[i].priority );
  238. }
  239. }
  240. else
  241. {
  242. fPortRule.machineMapToPriority =
  243. m_clusterData->portF[ ports[i].key ].machineMapToPriority;
  244. if( m_isClusterLevel == false )
  245. {
  246. fPortRule.machineMapToPriority[machine]
  247. = _wtoi( ports[i].priority );
  248. }
  249. }
  250. fPortRule._key = fPortRule._startPort;
  251. portF[ fPortRule._startPort ] = fPortRule;
  252. }
  253. else if( ports[i].mode == GETRESOURCEIDSTRING( IDS_REPORT_MODE_DISABLED ) )
  254. {
  255. // disabled
  256. dPortRule._startPort = _wtoi( ports[i].start_port );
  257. dPortRule._endPort = _wtoi( ports[i].end_port );
  258. if( ports[i].protocol == GETRESOURCEIDSTRING( IDS_REPORT_PROTOCOL_BOTH ) )
  259. {
  260. dPortRule._trafficToHandle = MNLBPortRule::both;
  261. }
  262. else if( ports[i].protocol == GETRESOURCEIDSTRING( IDS_REPORT_PROTOCOL_TCP ) )
  263. {
  264. dPortRule._trafficToHandle = MNLBPortRule::tcp;
  265. }
  266. else if( ports[i].protocol == GETRESOURCEIDSTRING( IDS_REPORT_PROTOCOL_UDP ) )
  267. {
  268. dPortRule._trafficToHandle = MNLBPortRule::udp;
  269. }
  270. dPortRule._key = dPortRule._startPort;
  271. portD[ dPortRule._startPort ] = dPortRule;
  272. }
  273. }
  274. m_clusterData->portELB = portELB;
  275. m_clusterData->portULB = portULB;
  276. m_clusterData->portF = portF;
  277. m_clusterData->portD = portD;
  278. return CPropertyPage::OnKillActive();
  279. }
  280. BOOL
  281. PortsPage::OnInitDialog()
  282. {
  283. CPropertyPage::OnInitDialog();
  284. // the size of columns is equal
  285. // to core. Wish there were some defines somewhere.
  286. //
  287. m_portList.InsertColumn( 0,
  288. GETRESOURCEIDSTRING( IDS_HEADER_P_START ) ,
  289. LVCFMT_LEFT,
  290. 43 );
  291. m_portList.InsertColumn( 1,
  292. GETRESOURCEIDSTRING( IDS_HEADER_P_END ),
  293. LVCFMT_LEFT,
  294. 43 );
  295. m_portList.InsertColumn( 2,
  296. GETRESOURCEIDSTRING( IDS_HEADER_P_PROTOCOL ),
  297. LVCFMT_LEFT,
  298. 51 );
  299. m_portList.InsertColumn( 3,
  300. GETRESOURCEIDSTRING( IDS_HEADER_P_MODE ),
  301. LVCFMT_LEFT,
  302. 53 );
  303. m_portList.InsertColumn( 4,
  304. GETRESOURCEIDSTRING( IDS_HEADER_P_PRIORITY ),
  305. LVCFMT_LEFT,
  306. 45 );
  307. // load is bigger than core size of 39, because we could be saying "unequal"
  308. m_portList.InsertColumn( 5,
  309. GETRESOURCEIDSTRING( IDS_HEADER_P_LOAD ),
  310. LVCFMT_LEFT,
  311. 53 );
  312. m_portList.InsertColumn( 6,
  313. GETRESOURCEIDSTRING( IDS_HEADER_P_AFFINITY ),
  314. LVCFMT_LEFT,
  315. 47 );
  316. m_portList.SetExtendedStyle( m_portList.GetExtendedStyle() | LVS_EX_FULLROWSELECT );
  317. SetControlData();
  318. int numItems = m_portList.GetItemCount();
  319. if( numItems > 0 )
  320. {
  321. buttonModify.EnableWindow( TRUE );
  322. buttonDel.EnableWindow( TRUE );
  323. if( numItems >= CVY_MAX_USABLE_RULES )
  324. {
  325. // greater should not happen,
  326. // but just to be sure.
  327. buttonAdd.EnableWindow( FALSE );
  328. }
  329. else
  330. {
  331. buttonAdd.EnableWindow( TRUE );
  332. }
  333. // make selection the first item in list.
  334. //
  335. m_portList.SetItemState( 0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED );
  336. }
  337. else
  338. {
  339. buttonAdd.EnableWindow( TRUE );
  340. // disable the edit and remove buttons.
  341. buttonModify.EnableWindow( FALSE );
  342. buttonDel.EnableWindow( FALSE );
  343. }
  344. return TRUE;
  345. }
  346. void
  347. PortsPage::SetControlData()
  348. {
  349. int index = 0;
  350. map< long, PortDataELB>::iterator topELB;
  351. for( topELB = m_clusterData->portELB.begin();
  352. topELB != m_clusterData->portELB.end();
  353. ++topELB )
  354. {
  355. wchar_t buf[Common::BUF_SIZE];
  356. // start port
  357. swprintf( buf, L"%d", (*topELB).second._startPort );
  358. LVITEM item;
  359. item.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
  360. item.iItem = index;
  361. item.iSubItem = 0;
  362. item.iImage = 2;
  363. item.pszText = buf;
  364. item.lParam = (*topELB).second._startPort;
  365. item.cchTextMax = Common::BUF_SIZE;
  366. m_portList.InsertItem( &item );
  367. // end port
  368. swprintf( buf, L"%d", (*topELB).second._endPort );
  369. item.mask = LVIF_TEXT;
  370. item.iItem = index;
  371. item.iSubItem = 1;
  372. item.pszText = buf;
  373. item.cchTextMax = Common::BUF_SIZE;
  374. m_portList.SetItem( &item );
  375. // protocol
  376. item.mask = LVIF_TEXT;
  377. item.iItem = index;
  378. item.iSubItem = 2;
  379. switch( (*topELB).second._trafficToHandle )
  380. {
  381. case MNLBPortRule::both :
  382. item.pszText = GETRESOURCEIDSTRING( IDS_REPORT_PROTOCOL_BOTH );
  383. break;
  384. case MNLBPortRule::tcp :
  385. item.pszText = GETRESOURCEIDSTRING( IDS_REPORT_PROTOCOL_TCP );
  386. break;
  387. case MNLBPortRule::udp :
  388. item.pszText = GETRESOURCEIDSTRING( IDS_REPORT_PROTOCOL_UDP );
  389. break;
  390. }
  391. item.cchTextMax = Common::BUF_SIZE;
  392. m_portList.SetItem( &item );
  393. // mode
  394. item.mask = LVIF_TEXT;
  395. item.iItem = index;
  396. item.iSubItem = 3;
  397. item.pszText = GETRESOURCEIDSTRING(IDS_REPORT_MODE_MULTIPLE );
  398. item.cchTextMax = Common::BUF_SIZE;
  399. m_portList.SetItem( &item );
  400. // priority
  401. item.mask = LVIF_TEXT;
  402. item.iItem = index;
  403. item.iSubItem = 4;
  404. item.pszText = GETRESOURCEIDSTRING(IDS_REPORT_EMPTY );
  405. item.cchTextMax = Common::BUF_SIZE;
  406. m_portList.SetItem( &item );
  407. // load
  408. item.mask = LVIF_TEXT;
  409. item.iItem = index;
  410. item.iSubItem = 5;
  411. item.pszText = GETRESOURCEIDSTRING( IDS_REPORT_LOAD_EQUAL );
  412. item.cchTextMax = Common::BUF_SIZE;
  413. m_portList.SetItem( &item );
  414. // affinity
  415. item.mask = LVIF_TEXT;
  416. item.iItem = index;
  417. item.iSubItem = 6;
  418. switch( (*topELB).second._affinity )
  419. {
  420. case MNLBPortRule::none :
  421. item.pszText = GETRESOURCEIDSTRING( IDS_REPORT_AFFINITY_NONE );
  422. break;
  423. case MNLBPortRule::single :
  424. item.pszText = GETRESOURCEIDSTRING( IDS_REPORT_AFFINITY_SINGLE );
  425. break;
  426. case MNLBPortRule::classC :
  427. item.pszText = GETRESOURCEIDSTRING( IDS_REPORT_AFFINITY_CLASSC );
  428. break;
  429. }
  430. item.cchTextMax = Common::BUF_SIZE;
  431. m_portList.SetItem( &item );
  432. ++index;
  433. }
  434. index = 0;
  435. map< long, PortDataULB>::iterator topULB;
  436. for( topULB = m_clusterData->portULB.begin();
  437. topULB != m_clusterData->portULB.end();
  438. ++topULB )
  439. {
  440. wchar_t buf[Common::BUF_SIZE];
  441. // start port
  442. swprintf( buf, L"%d", (*topULB).second._startPort );
  443. LVITEM item;
  444. item.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
  445. item.iItem = index;
  446. item.iSubItem = 0;
  447. item.iImage = 2;
  448. item.lParam = (*topULB).second._startPort;
  449. item.pszText = buf;
  450. item.cchTextMax = Common::BUF_SIZE;
  451. m_portList.InsertItem( &item );
  452. // end port
  453. swprintf( buf, L"%d", (*topULB).second._endPort );
  454. item.mask = LVIF_TEXT;
  455. item.iItem = index;
  456. item.iSubItem = 1;
  457. item.pszText = buf;
  458. item.cchTextMax = Common::BUF_SIZE;
  459. m_portList.SetItem( &item );
  460. // protocol
  461. item.mask = LVIF_TEXT;
  462. item.iItem = index;
  463. item.iSubItem = 2;
  464. switch( (*topULB).second._trafficToHandle )
  465. {
  466. case MNLBPortRule::both :
  467. item.pszText = GETRESOURCEIDSTRING( IDS_REPORT_PROTOCOL_BOTH );
  468. break;
  469. case MNLBPortRule::tcp :
  470. item.pszText = GETRESOURCEIDSTRING( IDS_REPORT_PROTOCOL_TCP );
  471. break;
  472. case MNLBPortRule::udp :
  473. item.pszText = GETRESOURCEIDSTRING( IDS_REPORT_PROTOCOL_UDP );
  474. break;
  475. }
  476. item.cchTextMax = Common::BUF_SIZE;
  477. m_portList.SetItem( &item );
  478. // mode
  479. item.mask = LVIF_TEXT;
  480. item.iItem = index;
  481. item.iSubItem = 3;
  482. item.pszText = GETRESOURCEIDSTRING(IDS_REPORT_MODE_MULTIPLE );
  483. item.cchTextMax = Common::BUF_SIZE;
  484. m_portList.SetItem( &item );
  485. // priority
  486. item.mask = LVIF_TEXT;
  487. item.iItem = index;
  488. item.iSubItem = 4;
  489. item.pszText = GETRESOURCEIDSTRING(IDS_REPORT_EMPTY );
  490. item.cchTextMax = Common::BUF_SIZE;
  491. m_portList.SetItem( &item );
  492. // load
  493. item.mask = LVIF_TEXT;
  494. item.iItem = index;
  495. item.iSubItem = 5;
  496. if( m_isClusterLevel == true )
  497. {
  498. item.pszText = GETRESOURCEIDSTRING(IDS_REPORT_LOAD_UNEQUAL );
  499. }
  500. else
  501. {
  502. swprintf( buf, L"%d", (*topULB).second.machineMapToLoadWeight[machine] );
  503. item.pszText = buf;
  504. }
  505. item.cchTextMax = Common::BUF_SIZE;
  506. m_portList.SetItem( &item );
  507. // affinity
  508. item.mask = LVIF_TEXT;
  509. item.iItem = index;
  510. item.iSubItem = 6;
  511. switch( (*topULB).second._affinity )
  512. {
  513. case MNLBPortRule::none :
  514. item.pszText = GETRESOURCEIDSTRING( IDS_REPORT_AFFINITY_NONE );
  515. break;
  516. case MNLBPortRule::single :
  517. item.pszText = GETRESOURCEIDSTRING( IDS_REPORT_AFFINITY_SINGLE );
  518. break;
  519. case MNLBPortRule::classC :
  520. item.pszText = GETRESOURCEIDSTRING( IDS_REPORT_AFFINITY_CLASSC );
  521. break;
  522. }
  523. item.cchTextMax = Common::BUF_SIZE;
  524. m_portList.SetItem( &item );
  525. ++index;
  526. }
  527. index = 0;
  528. map< long, PortDataF>::iterator topF;
  529. for( topF = m_clusterData->portF.begin();
  530. topF != m_clusterData->portF.end();
  531. ++topF )
  532. {
  533. wchar_t buf[Common::BUF_SIZE];
  534. // start port
  535. swprintf( buf, L"%d", (*topF).second._startPort );
  536. LVITEM item;
  537. item.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
  538. item.iItem = index;
  539. item.iSubItem = 0;
  540. item.iImage = 2;
  541. item.lParam = (*topF).second._startPort;
  542. item.pszText = buf;
  543. item.cchTextMax = Common::BUF_SIZE;
  544. m_portList.InsertItem( &item );
  545. // end port
  546. swprintf( buf, L"%d", (*topF).second._endPort );
  547. item.mask = LVIF_TEXT;
  548. item.iItem = index;
  549. item.iSubItem = 1;
  550. item.pszText = buf;
  551. item.cchTextMax = Common::BUF_SIZE;
  552. m_portList.SetItem( &item );
  553. // protocol
  554. item.mask = LVIF_TEXT;
  555. item.iItem = index;
  556. item.iSubItem = 2;
  557. switch( (*topF).second._trafficToHandle )
  558. {
  559. case MNLBPortRule::both :
  560. item.pszText = GETRESOURCEIDSTRING( IDS_REPORT_PROTOCOL_BOTH );
  561. break;
  562. case MNLBPortRule::tcp :
  563. item.pszText = GETRESOURCEIDSTRING( IDS_REPORT_PROTOCOL_TCP );
  564. break;
  565. case MNLBPortRule::udp :
  566. item.pszText = GETRESOURCEIDSTRING( IDS_REPORT_PROTOCOL_UDP );
  567. break;
  568. }
  569. item.cchTextMax = Common::BUF_SIZE;
  570. m_portList.SetItem( &item );
  571. // mode
  572. item.mask = LVIF_TEXT;
  573. item.iItem = index;
  574. item.iSubItem = 3;
  575. item.pszText = GETRESOURCEIDSTRING(IDS_REPORT_MODE_SINGLE );
  576. item.cchTextMax = Common::BUF_SIZE;
  577. m_portList.SetItem( &item );
  578. // priority
  579. item.mask = LVIF_TEXT;
  580. item.iItem = index;
  581. item.iSubItem = 4;
  582. if( m_isClusterLevel )
  583. {
  584. item.pszText = GETRESOURCEIDSTRING(IDS_REPORT_NA );
  585. }
  586. else
  587. {
  588. swprintf( buf, L"%d", (*topF).second.machineMapToPriority[machine] );
  589. item.pszText = buf;
  590. }
  591. item.cchTextMax = Common::BUF_SIZE;
  592. m_portList.SetItem( &item );
  593. // load
  594. item.mask = LVIF_TEXT;
  595. item.iItem = index;
  596. item.iSubItem = 5;
  597. item.pszText = GETRESOURCEIDSTRING(IDS_REPORT_EMPTY );
  598. item.cchTextMax = Common::BUF_SIZE;
  599. m_portList.SetItem( &item );
  600. // affinity
  601. item.mask = LVIF_TEXT;
  602. item.iItem = index;
  603. item.iSubItem = 6;
  604. item.pszText = GETRESOURCEIDSTRING(IDS_REPORT_EMPTY );
  605. item.cchTextMax = Common::BUF_SIZE;
  606. m_portList.SetItem( &item );
  607. ++index;
  608. }
  609. index = 0;
  610. map< long, PortDataD>::iterator topD;
  611. for( topD = m_clusterData->portD.begin();
  612. topD != m_clusterData->portD.end();
  613. ++topD )
  614. {
  615. wchar_t buf[Common::BUF_SIZE];
  616. // start port
  617. swprintf( buf, L"%d", (*topD).second._startPort );
  618. LVITEM item;
  619. item.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
  620. item.iItem = index;
  621. item.iSubItem = 0;
  622. item.iImage = 2;
  623. item.lParam = (*topD).second._startPort;
  624. item.pszText = buf;
  625. item.cchTextMax = Common::BUF_SIZE;
  626. m_portList.InsertItem( &item );
  627. // end port
  628. swprintf( buf, L"%d", (*topD).second._endPort );
  629. item.mask = LVIF_TEXT;
  630. item.iItem = index;
  631. item.iSubItem = 1;
  632. item.pszText = buf;
  633. item.cchTextMax = Common::BUF_SIZE;
  634. m_portList.SetItem( &item );
  635. // protocol
  636. item.mask = LVIF_TEXT;
  637. item.iItem = index;
  638. item.iSubItem = 2;
  639. switch( (*topD).second._trafficToHandle )
  640. {
  641. case MNLBPortRule::both :
  642. item.pszText = GETRESOURCEIDSTRING( IDS_REPORT_PROTOCOL_BOTH );
  643. break;
  644. case MNLBPortRule::tcp :
  645. item.pszText = GETRESOURCEIDSTRING( IDS_REPORT_PROTOCOL_TCP );
  646. break;
  647. case MNLBPortRule::udp :
  648. item.pszText = GETRESOURCEIDSTRING( IDS_REPORT_PROTOCOL_UDP );
  649. break;
  650. }
  651. item.cchTextMax = Common::BUF_SIZE;
  652. m_portList.SetItem( &item );
  653. // mode
  654. item.mask = LVIF_TEXT;
  655. item.iItem = index;
  656. item.iSubItem = 3;
  657. item.pszText = GETRESOURCEIDSTRING(IDS_REPORT_MODE_DISABLED );
  658. item.cchTextMax = Common::BUF_SIZE;
  659. m_portList.SetItem( &item );
  660. // priority
  661. item.mask = LVIF_TEXT;
  662. item.iItem = index;
  663. item.iSubItem = 4;
  664. item.pszText = GETRESOURCEIDSTRING(IDS_REPORT_EMPTY );
  665. item.cchTextMax = Common::BUF_SIZE;
  666. m_portList.SetItem( &item );
  667. // load
  668. item.mask = LVIF_TEXT;
  669. item.iItem = index;
  670. item.iSubItem = 5;
  671. item.pszText = GETRESOURCEIDSTRING( IDS_REPORT_EMPTY );
  672. item.cchTextMax = Common::BUF_SIZE;
  673. m_portList.SetItem( &item );
  674. // affinity
  675. item.mask = LVIF_TEXT;
  676. item.iItem = index;
  677. item.iSubItem = 6;
  678. item.pszText = GETRESOURCEIDSTRING( IDS_REPORT_EMPTY );
  679. item.cchTextMax = Common::BUF_SIZE;
  680. m_portList.SetItem( &item );
  681. ++index;
  682. }
  683. }
  684. void
  685. PortsPage::OnButtonAdd()
  686. {
  687. PortData portData;
  688. ClusterPortsDlg clusterPortRuleDialog( portData, this );
  689. int rc = clusterPortRuleDialog.DoModal();
  690. if( rc != IDOK )
  691. {
  692. return;
  693. }
  694. else
  695. {
  696. // add this port rule.
  697. int index = 0;
  698. // start port
  699. LVITEM item;
  700. item.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
  701. item.iItem = index;
  702. item.iSubItem = 0;
  703. item.iImage = 2;
  704. item.lParam = -1;
  705. item.pszText = portData.start_port;
  706. item.cchTextMax = Common::BUF_SIZE;
  707. m_portList.InsertItem( &item );
  708. // end port
  709. item.mask = LVIF_TEXT;
  710. item.iItem = index;
  711. item.iSubItem = 1;
  712. item.pszText = portData.end_port;
  713. item.cchTextMax = Common::BUF_SIZE;
  714. m_portList.SetItem( &item );
  715. // protocol
  716. item.mask = LVIF_TEXT;
  717. item.iItem = index;
  718. item.iSubItem = 2;
  719. item.pszText = portData.protocol;
  720. item.cchTextMax = Common::BUF_SIZE;
  721. m_portList.SetItem( &item );
  722. // mode
  723. item.mask = LVIF_TEXT;
  724. item.iItem = index;
  725. item.iSubItem = 3;
  726. item.pszText = portData.mode;
  727. item.cchTextMax = Common::BUF_SIZE;
  728. m_portList.SetItem( &item );
  729. // priority
  730. item.mask = LVIF_TEXT;
  731. item.iItem = index;
  732. item.iSubItem = 4;
  733. item.pszText = portData.priority;
  734. item.cchTextMax = Common::BUF_SIZE;
  735. m_portList.SetItem( &item );
  736. // load
  737. item.mask = LVIF_TEXT;
  738. item.iItem = index;
  739. item.iSubItem = 5;
  740. item.pszText = portData.load;
  741. item.cchTextMax = Common::BUF_SIZE;
  742. m_portList.SetItem( &item );
  743. // affinity
  744. item.mask = LVIF_TEXT;
  745. item.iItem = index;
  746. item.iSubItem = 6;
  747. item.pszText = portData.affinity;
  748. item.cchTextMax = Common::BUF_SIZE;
  749. m_portList.SetItem( &item );
  750. // check if max port limit reached.
  751. if( m_portList.GetItemCount() >= CVY_MAX_USABLE_RULES )
  752. {
  753. // as max port rule limit reached.
  754. // disable further additions.
  755. buttonAdd.EnableWindow( FALSE );
  756. buttonDel.EnableWindow( TRUE );
  757. buttonModify.EnableWindow( TRUE );
  758. buttonDel.SetFocus();
  759. }
  760. else
  761. {
  762. buttonAdd.EnableWindow( TRUE );
  763. buttonDel.EnableWindow( TRUE );
  764. buttonModify.EnableWindow( TRUE );
  765. }
  766. // set focus to this item
  767. m_portList.SetItemState( index, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED );
  768. }
  769. }
  770. void
  771. PortsPage::OnButtonDel()
  772. {
  773. // get the current selection.
  774. POSITION pos = m_portList.GetFirstSelectedItemPosition();
  775. if( pos == NULL )
  776. {
  777. return;
  778. }
  779. int index = m_portList.GetNextSelectedItem( pos );
  780. // delete it.
  781. m_portList.DeleteItem( index );
  782. // if this was the last port rule.
  783. if( m_portList.GetItemCount() == 0 )
  784. {
  785. // as no more port rules in list
  786. // disable modify and remove buttons.
  787. // also set focus to add button
  788. buttonAdd.EnableWindow( TRUE );
  789. buttonModify.EnableWindow( FALSE );
  790. buttonDel.EnableWindow( FALSE );
  791. buttonAdd.SetFocus();
  792. }
  793. else
  794. {
  795. // enable the add, modify button.
  796. buttonAdd.EnableWindow( TRUE );
  797. buttonModify.EnableWindow( TRUE );
  798. buttonDel.EnableWindow( TRUE );
  799. // make selection the first item in list.
  800. //
  801. m_portList.SetItemState( 0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED );
  802. }
  803. }
  804. void
  805. PortsPage::OnButtonModify()
  806. {
  807. // get the current selection.
  808. POSITION pos = m_portList.GetFirstSelectedItemPosition();
  809. if( pos == NULL )
  810. {
  811. return;
  812. }
  813. int index = m_portList.GetNextSelectedItem( pos );
  814. PortData portData;
  815. wchar_t buffer[Common::BUF_SIZE];
  816. m_portList.GetItemText( index, 0, buffer, Common::BUF_SIZE );
  817. portData.start_port = buffer;
  818. m_portList.GetItemText( index, 1, buffer, Common::BUF_SIZE );
  819. portData.end_port = buffer;
  820. m_portList.GetItemText( index, 2, buffer, Common::BUF_SIZE );
  821. portData.protocol = buffer;
  822. m_portList.GetItemText( index, 3, buffer, Common::BUF_SIZE );
  823. portData.mode = buffer;
  824. m_portList.GetItemText( index, 4, buffer, Common::BUF_SIZE );
  825. portData.priority = buffer;
  826. m_portList.GetItemText( index, 5, buffer, Common::BUF_SIZE );
  827. portData.load = buffer;
  828. m_portList.GetItemText( index, 6, buffer, Common::BUF_SIZE );
  829. portData.affinity = buffer;
  830. ClusterPortsDlg clusterPortRuleDialog( portData, this, index );
  831. HostPortsDlg hostPortRuleDialog( portData, this );
  832. int rc;
  833. if( m_isClusterLevel == true )
  834. {
  835. rc = clusterPortRuleDialog.DoModal();
  836. }
  837. else
  838. {
  839. rc = hostPortRuleDialog.DoModal();
  840. }
  841. if( rc != IDOK )
  842. {
  843. return;
  844. }
  845. else
  846. {
  847. // delete the old item and add the new item.
  848. // before you delete the old item find its param
  849. // value
  850. DWORD key = m_portList.GetItemData( index );
  851. m_portList.DeleteItem( index );
  852. // as this is being modified the
  853. // key remains the old one.
  854. // start port
  855. LVITEM item;
  856. item.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
  857. item.iItem = index;
  858. item.iSubItem = 0;
  859. item.iImage = 2;
  860. item.lParam = key;
  861. item.pszText = portData.start_port;
  862. item.cchTextMax = Common::BUF_SIZE;
  863. m_portList.InsertItem( &item );
  864. // end port
  865. item.mask = LVIF_TEXT;
  866. item.iItem = index;
  867. item.iSubItem = 1;
  868. item.pszText = portData.end_port;
  869. item.cchTextMax = Common::BUF_SIZE;
  870. m_portList.SetItem( &item );
  871. // protocol
  872. item.mask = LVIF_TEXT;
  873. item.iItem = index;
  874. item.iSubItem = 2;
  875. item.pszText = portData.protocol;
  876. item.cchTextMax = Common::BUF_SIZE;
  877. m_portList.SetItem( &item );
  878. // mode
  879. item.mask = LVIF_TEXT;
  880. item.iItem = index;
  881. item.iSubItem = 3;
  882. item.pszText = portData.mode;
  883. item.cchTextMax = Common::BUF_SIZE;
  884. m_portList.SetItem( &item );
  885. // priority
  886. item.mask = LVIF_TEXT;
  887. item.iItem = index;
  888. item.iSubItem = 4;
  889. item.pszText = portData.priority;
  890. item.cchTextMax = Common::BUF_SIZE;
  891. m_portList.SetItem( &item );
  892. // load
  893. item.mask = LVIF_TEXT;
  894. item.iItem = index;
  895. item.iSubItem = 5;
  896. item.pszText = portData.load;
  897. item.cchTextMax = Common::BUF_SIZE;
  898. m_portList.SetItem( &item );
  899. // affinity
  900. item.mask = LVIF_TEXT;
  901. item.iItem = index;
  902. item.iSubItem = 6;
  903. item.pszText = portData.affinity;
  904. item.cchTextMax = Common::BUF_SIZE;
  905. m_portList.SetItem( &item );
  906. // set focus to this item
  907. m_portList.SetItemState( index, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED );
  908. }
  909. }
  910. void
  911. PortsPage::OnDoubleClick( NMHDR * pNotifyStruct, LRESULT * result )
  912. {
  913. if( buttonModify.IsWindowEnabled() == TRUE )
  914. {
  915. OnButtonModify();
  916. }
  917. }
  918. void
  919. PortsPage::OnSelchanged( NMHDR * pNotifyStruct, LRESULT * result )
  920. {
  921. // if it is not cluster level, which means host level.
  922. if( m_isClusterLevel == false )
  923. {
  924. // get the current selection.
  925. POSITION pos = m_portList.GetFirstSelectedItemPosition();
  926. if( pos == NULL )
  927. {
  928. return;
  929. }
  930. // disable the add, and delete buttons.
  931. // enable the modify button only if the
  932. // selection is an unequal load balanced
  933. // or single host port rule.
  934. buttonAdd.EnableWindow( FALSE );
  935. buttonDel.EnableWindow( FALSE );
  936. // initially disable modify button
  937. buttonModify.EnableWindow( FALSE );
  938. int index = m_portList.GetNextSelectedItem( pos );
  939. PortData portData;
  940. wchar_t buffer[Common::BUF_SIZE];
  941. m_portList.GetItemText( index, 3, buffer, Common::BUF_SIZE );
  942. portData.mode = buffer;
  943. if( portData.mode == GETRESOURCEIDSTRING( IDS_REPORT_MODE_MULTIPLE ) )
  944. {
  945. m_portList.GetItemText( index, 5, buffer, Common::BUF_SIZE );
  946. portData.load = buffer;
  947. if( portData.load != GETRESOURCEIDSTRING( IDS_REPORT_LOAD_EQUAL ) )
  948. {
  949. buttonModify.EnableWindow( TRUE );
  950. }
  951. }
  952. else if( portData.mode == GETRESOURCEIDSTRING( IDS_REPORT_MODE_SINGLE ) )
  953. {
  954. buttonModify.EnableWindow( TRUE );
  955. }
  956. }
  957. }
  958. BOOL
  959. PortsPage::OnHelpInfo (HELPINFO* helpInfo )
  960. {
  961. if( helpInfo->iContextType == HELPINFO_WINDOW )
  962. {
  963. ::WinHelp( static_cast<HWND> ( helpInfo->hItemHandle ), CVY_CTXT_HELP_FILE, HELP_WM_HELP, (ULONG_PTR ) g_aHelpIDs_IDD_DIALOG_PORTS);
  964. }
  965. return TRUE;
  966. }
  967. void
  968. PortsPage::OnContextMenu( CWnd* pWnd, CPoint point )
  969. {
  970. ::WinHelp( m_hWnd, CVY_CTXT_HELP_FILE, HELP_CONTEXTMENU, (ULONG_PTR ) g_aHelpIDs_IDD_DIALOG_PORTS);
  971. }
  972. void
  973. PortsPage::OnColumnClick( NMHDR * pNotifyStruct, LRESULT * result )
  974. {
  975. // get present port rules in list.
  976. vector<PortData> ports;
  977. getPresentPorts( &ports );
  978. LPNMLISTVIEW lv = ( LPNMLISTVIEW) pNotifyStruct;
  979. // sort these port rules depending upon the header which has
  980. // been clicked.
  981. switch( lv->iSubItem )
  982. {
  983. case 0 :
  984. // user has clicked start port.
  985. sort( ports.begin(), ports.end(), comp_start_port() );
  986. break;
  987. case 1:
  988. // user has clicked end port
  989. sort( ports.begin(), ports.end(), comp_end_port() );
  990. break;
  991. case 2:
  992. // user has clicked protocol
  993. sort( ports.begin(), ports.end(), comp_protocol() );
  994. break;
  995. case 3:
  996. // user has clicked mode
  997. sort( ports.begin(), ports.end(), comp_mode() );
  998. break;
  999. case 4:
  1000. // user has clicked priority
  1001. if( m_isClusterLevel == true )
  1002. {
  1003. sort( ports.begin(), ports.end(), comp_priority_string() );
  1004. }
  1005. else
  1006. {
  1007. sort( ports.begin(), ports.end(), comp_priority_int() );
  1008. }
  1009. break;
  1010. case 5:
  1011. // user has clicked load
  1012. if( m_isClusterLevel == true )
  1013. {
  1014. sort( ports.begin(), ports.end(), comp_load_string() );
  1015. }
  1016. else
  1017. {
  1018. sort( ports.begin(), ports.end(), comp_load_int() );
  1019. }
  1020. break;
  1021. case 6:
  1022. // user has clicked affinity
  1023. sort( ports.begin(), ports.end(), comp_affinity() );
  1024. break;
  1025. default:
  1026. break;
  1027. }
  1028. /* If we are sorting by the same column we were previously sorting by,
  1029. then we reverse the sort order. */
  1030. if( m_sort_column == lv->iSubItem )
  1031. {
  1032. m_sort_ascending = !m_sort_ascending;
  1033. }
  1034. else
  1035. {
  1036. // default sort is ascending.
  1037. m_sort_ascending = true;
  1038. }
  1039. m_sort_column = lv->iSubItem;
  1040. int portIndex;
  1041. int itemCount = m_portList.GetItemCount();
  1042. for( int index = 0; index < itemCount; ++index )
  1043. {
  1044. if( m_sort_ascending == true )
  1045. {
  1046. portIndex = index;
  1047. }
  1048. else
  1049. {
  1050. portIndex = ( itemCount - 1 ) - index;
  1051. }
  1052. m_portList.SetItemData( index, ports[portIndex].key );
  1053. m_portList.SetItemText( index, 0, ports[portIndex].start_port );
  1054. m_portList.SetItemText( index, 1, ports[portIndex].end_port );
  1055. m_portList.SetItemText( index, 2, ports[portIndex].protocol );
  1056. m_portList.SetItemText( index, 3, ports[portIndex].mode );
  1057. m_portList.SetItemText( index, 4, ports[portIndex].priority );
  1058. m_portList.SetItemText( index, 5, ports[portIndex].load );
  1059. m_portList.SetItemText( index, 6, ports[portIndex].affinity );
  1060. }
  1061. return;
  1062. }
  1063. void
  1064. PortsPage::getPresentPorts( vector<PortData>* ports )
  1065. {
  1066. // get all the port rules presently in the list.
  1067. for( int index = 0; index < m_portList.GetItemCount(); ++index )
  1068. {
  1069. PortData portData;
  1070. wchar_t buffer[Common::BUF_SIZE];
  1071. portData.key = m_portList.GetItemData( index );
  1072. m_portList.GetItemText( index, 0, buffer, Common::BUF_SIZE );
  1073. portData.start_port = buffer;
  1074. m_portList.GetItemText( index, 1, buffer, Common::BUF_SIZE );
  1075. portData.end_port = buffer;
  1076. m_portList.GetItemText( index, 2, buffer, Common::BUF_SIZE );
  1077. portData.protocol = buffer;
  1078. m_portList.GetItemText( index, 3, buffer, Common::BUF_SIZE );
  1079. portData.mode = buffer;
  1080. m_portList.GetItemText( index, 4, buffer, Common::BUF_SIZE );
  1081. portData.priority = buffer;
  1082. m_portList.GetItemText( index, 5, buffer, Common::BUF_SIZE );
  1083. portData.load = buffer;
  1084. m_portList.GetItemText( index, 6, buffer, Common::BUF_SIZE );
  1085. portData.affinity = buffer;
  1086. ports->push_back( portData );
  1087. }
  1088. }