HeaderProcessingContextTestFixture.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. /*
  2. * Copyright (c) 2017-2019 The Linux Foundation. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are
  6. * met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above
  10. * copyright notice, this list of conditions and the following
  11. * disclaimer in the documentation and/or other materials provided
  12. * with the distribution.
  13. * * Neither the name of The Linux Foundation nor the names of its
  14. * contributors may be used to endorse or promote products derived
  15. * from this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
  18. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
  20. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
  21. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  22. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  23. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  24. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  25. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  26. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  27. * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. #include "HeaderProcessingContextTestFixture.h"
  30. #include "TestsUtils.h"
  31. const Byte IpaHdrProcCtxTestFixture::WLAN_ETH2_HDR[WLAN_ETH2_HDR_SIZE] =
  32. {
  33. // WLAN hdr - 4 bytes
  34. 0xa1, 0xb2, 0xc3, 0xd4,
  35. // ETH2 - 14 bytes
  36. 0x00, 0x00, 0x00, 0x00,
  37. 0x00, 0x00, 0x00, 0x00,
  38. 0x00, 0x00, 0x00, 0x00,
  39. 0x00, 0x00
  40. };
  41. const Byte IpaHdrProcCtxTestFixture::ETH2_HDR[ETH_HLEN] =
  42. {
  43. // ETH2 - 14 bytes
  44. 0x00, 0x00, 0x00, 0x00,
  45. 0x00, 0x00, 0x00, 0x00,
  46. 0x00, 0x00, 0x00, 0x00,
  47. 0x00, 0x00
  48. };
  49. const Byte IpaHdrProcCtxTestFixture::ETH2_8021Q_HDR[ETH8021Q_HEADER_LEN] =
  50. {
  51. // 802_1Q - 18 bytes
  52. // src and dst MAC - 6 + 6 bytes
  53. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  54. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  55. // 802_1Q tag - VLAN ID 3
  56. 0x81, 0x00, 0x00, 0x03,
  57. // ethertype
  58. 0x00, 0x00
  59. };
  60. const Byte IpaHdrProcCtxTestFixture::WLAN_802_3_HDR[WLAN_802_3_HDR_SIZE] =
  61. {
  62. // WLAN hdr - 4 bytes
  63. 0x0a, 0x0b, 0x0c, 0x0d,
  64. // 802_3 - 26 bytes
  65. 0x00, 0x00, 0x00, 0x00,
  66. 0x00, 0x00, 0x00, 0x00,
  67. 0x00, 0x00, 0x00, 0x00,
  68. 0x00, 0x00, 0x00, 0x00,
  69. 0x00, 0x00, 0x00, 0x00,
  70. 0x00, 0x00, 0x00, 0x00,
  71. 0x00, 0x00
  72. };
  73. IpaHdrProcCtxTestFixture::IpaHdrProcCtxTestFixture():
  74. m_procCtxHandleId(PROC_CTX_HANDLE_ID_MAX),
  75. m_pCurrentProducer(NULL),
  76. m_pCurrentConsumer(NULL),
  77. m_sendSize1 (m_BUFF_MAX_SIZE),
  78. m_sendSize2 (m_BUFF_MAX_SIZE),
  79. m_expectedBufferSize1(0),
  80. m_IpaIPType(IPA_IP_v4)
  81. {
  82. memset(m_headerHandles, 0, sizeof(m_headerHandles));
  83. memset(m_procCtxHHandles, 0, sizeof(m_procCtxHHandles));
  84. memset(m_sendBuffer1, 0, sizeof(m_sendBuffer1));
  85. memset(m_sendBuffer2, 0, sizeof(m_sendBuffer2));
  86. memset(m_expectedBuffer1, 0, sizeof(m_expectedBuffer1));
  87. m_testSuiteName.push_back("HdrProcCtx");
  88. }
  89. bool IpaHdrProcCtxTestFixture::Setup()
  90. {
  91. ConfigureScenario(PHASE_TWENTY_TEST_CONFIGURATION);
  92. // init producers
  93. m_rndisEth2Producer.Open(INTERFACE0_TO_IPA_DATA_PATH,
  94. INTERFACE0_FROM_IPA_DATA_PATH);
  95. m_wlanEth2producer.Open(INTERFACE4_TO_IPA_DATA_PATH,
  96. INTERFACE4_FROM_IPA_DATA_PATH);
  97. m_eth2Producer.Open(INTERFACE5_TO_IPA_DATA_PATH,
  98. INTERFACE5_FROM_IPA_DATA_PATH);
  99. // init consumers
  100. m_defaultConsumer.Open(INTERFACE1_TO_IPA_DATA_PATH,
  101. INTERFACE1_FROM_IPA_DATA_PATH);
  102. m_rndisEth2Consumer.Open(INTERFACE2_TO_IPA_DATA_PATH,
  103. INTERFACE2_FROM_IPA_DATA_PATH);
  104. if (!m_headerInsertion.DeviceNodeIsOpened())
  105. {
  106. LOG_MSG_ERROR("HeaderInsertion block is not ready "
  107. "for immediate commands!\n");
  108. return false;
  109. }
  110. if (!m_routing.DeviceNodeIsOpened())
  111. {
  112. LOG_MSG_ERROR("Routing block is not ready "
  113. "for immediate commands!\n");
  114. return false;
  115. }
  116. if (!m_filtering.DeviceNodeIsOpened())
  117. {
  118. LOG_MSG_ERROR("Filtering block is not ready "
  119. "for immediate commands!\n");
  120. return false;
  121. }
  122. // resetting this component will reset
  123. // both Routing and Filtering tables
  124. m_headerInsertion.Reset();
  125. return true;
  126. } // Setup()
  127. bool IpaHdrProcCtxTestFixture::Teardown()
  128. {
  129. m_rndisEth2Producer.Close();
  130. m_wlanEth2producer.Close();
  131. m_eth2Producer.Close();
  132. m_defaultConsumer.Close();
  133. m_rndisEth2Consumer.Close();
  134. return true;
  135. } // Teardown()
  136. void IpaHdrProcCtxTestFixture::AddAllHeaders()
  137. {
  138. for (int i = 0; i < HEADER_HANDLE_ID_MAX; i++) {
  139. AddHeader(static_cast<HeaderHandleId>(i));
  140. }
  141. }
  142. // Insert a single header
  143. void IpaHdrProcCtxTestFixture::AddHeader(HeaderHandleId handleId)
  144. {
  145. static const int NUM_OF_HEADERS = 1;
  146. struct ipa_ioc_add_hdr *hdrTable = NULL;
  147. struct ipa_hdr_add *hdr = NULL;
  148. // init hdr table
  149. hdrTable = (struct ipa_ioc_add_hdr *) calloc(1,
  150. sizeof(struct ipa_ioc_add_hdr)
  151. + NUM_OF_HEADERS * sizeof(struct ipa_hdr_add));
  152. if (!hdrTable)
  153. {
  154. LOG_MSG_ERROR(
  155. "calloc failed to allocate pHeaderDescriptor");
  156. return;
  157. }
  158. hdrTable->commit = true;
  159. hdrTable->num_hdrs = NUM_OF_HEADERS;
  160. // init the hdr common fields
  161. hdr = &hdrTable->hdr[0];
  162. hdr->hdr_hdl = -1; //Return Value
  163. hdr->is_partial = false;
  164. hdr->status = -1; // Return Parameter
  165. // init hdr specific fields
  166. switch (handleId)
  167. {
  168. case HEADER_HANDLE_ID_WLAN_ETH2:
  169. memcpy(hdr->hdr, WLAN_ETH2_HDR, WLAN_ETH2_HDR_SIZE);
  170. hdr->hdr_len = WLAN_ETH2_HDR_SIZE;
  171. strlcpy(hdr->name, "WLAN_ETH2", sizeof(hdr->name));
  172. hdr->type = IPA_HDR_L2_ETHERNET_II;
  173. break;
  174. case HEADER_HANDLE_ID_RNDIS_ETH2:
  175. if (!RNDISAggregationHelper::LoadRNDISEth2IP4Header(
  176. hdr->hdr,
  177. IPA_HDR_MAX_SIZE,
  178. 0,
  179. (size_t*)&hdr->hdr_len))
  180. return;
  181. strlcpy(hdr->name, "RNDIS_ETH2", sizeof(hdr->name));
  182. hdr->type = IPA_HDR_L2_ETHERNET_II;
  183. break;
  184. case HEADER_HANDLE_ID_ETH2:
  185. strlcpy(hdr->name, "ETH2", sizeof(hdr->name));
  186. memcpy(hdr->hdr, ETH2_HDR, ETH_HLEN);
  187. hdr->type = IPA_HDR_L2_ETHERNET_II;
  188. hdr->hdr_len = ETH_HLEN;
  189. break;
  190. case HEADER_HANDLE_ID_WLAN_802_3:
  191. strlcpy(hdr->name, "WLAN_802_3", sizeof(hdr->name));
  192. memcpy(hdr->hdr, WLAN_802_3_HDR, WLAN_802_3_HDR_SIZE);
  193. hdr->type = IPA_HDR_L2_802_3;
  194. hdr->hdr_len = WLAN_802_3_HDR_SIZE;
  195. LOG_MSG_DEBUG(
  196. "HEADER_HANDLE_ID_WLAN_802_3 NOT supported for now");
  197. return;
  198. break;
  199. case HEADER_HANDLE_ID_VLAN_802_1Q:
  200. strlcpy(hdr->name, "VLAN_8021Q", sizeof(hdr->name));
  201. memcpy(hdr->hdr, ETH2_8021Q_HDR, ETH8021Q_HEADER_LEN);
  202. hdr->type = IPA_HDR_L2_802_1Q;
  203. hdr->hdr_len = ETH8021Q_HEADER_LEN;
  204. break;
  205. default:
  206. LOG_MSG_ERROR("header handleId not supported.");
  207. return;
  208. }
  209. // commit header to HW
  210. if (!m_headerInsertion.AddHeader(hdrTable))
  211. {
  212. LOG_MSG_ERROR("m_headerInsertion.AddHeader() failed.");
  213. return;
  214. }
  215. // save header handle
  216. m_headerHandles[handleId] = hdr->hdr_hdl;
  217. }
  218. void IpaHdrProcCtxTestFixture::AddAllProcCtx()
  219. {
  220. for (int i = 0; i <PROC_CTX_HANDLE_ID_MAX; i++)
  221. {
  222. AddProcCtx(static_cast<ProcCtxHandleId>(i));
  223. }
  224. }
  225. // Insert a single proc_ctx
  226. void IpaHdrProcCtxTestFixture::AddProcCtx(ProcCtxHandleId handleId)
  227. {
  228. static const int NUM_OF_PROC_CTX = 1;
  229. struct ipa_ioc_add_hdr_proc_ctx *procCtxTable = NULL;
  230. struct ipa_hdr_proc_ctx_add *procCtx = NULL;
  231. // init proc ctx table
  232. procCtxTable = (struct ipa_ioc_add_hdr_proc_ctx *)calloc(1,
  233. sizeof(struct ipa_ioc_add_hdr_proc_ctx)
  234. + NUM_OF_PROC_CTX *
  235. sizeof(struct ipa_hdr_proc_ctx_add));
  236. if (!procCtxTable)
  237. {
  238. LOG_MSG_ERROR("calloc failed to allocate procCtxTable");
  239. return;
  240. }
  241. procCtxTable->commit = true;
  242. procCtxTable->num_proc_ctxs = NUM_OF_PROC_CTX;
  243. // init proc_ctx common fields
  244. procCtx = &procCtxTable->proc_ctx[0];
  245. procCtx->proc_ctx_hdl = -1; // return value
  246. procCtx->status = -1; // Return parameter
  247. // init proc_ctx specific fields
  248. switch (handleId)
  249. {
  250. case PROC_CTX_HANDLE_ID_ETH2_2_WLAN_ETH2:
  251. procCtx->type = IPA_HDR_PROC_ETHII_TO_ETHII;
  252. procCtx->hdr_hdl =
  253. m_headerHandles[HEADER_HANDLE_ID_WLAN_ETH2];
  254. break;
  255. case PROC_CTX_HANDLE_ID_ETH2_2_RNDIS_ETH2:
  256. procCtx->type = IPA_HDR_PROC_ETHII_TO_ETHII;
  257. procCtx->hdr_hdl =
  258. m_headerHandles[HEADER_HANDLE_ID_RNDIS_ETH2];
  259. break;
  260. case PROC_CTX_HANDLE_ID_ETH2_ETH2_2_ETH2:
  261. procCtx->type = IPA_HDR_PROC_ETHII_TO_ETHII;
  262. procCtx->hdr_hdl =
  263. m_headerHandles[HEADER_HANDLE_ID_ETH2];
  264. break;
  265. case PROC_CTX_HANDLE_ID_WLAN_ETH2_2_802_3:
  266. procCtx->type = IPA_HDR_PROC_ETHII_TO_802_3;
  267. procCtx->hdr_hdl =
  268. m_headerHandles[HEADER_HANDLE_ID_WLAN_802_3];
  269. break;
  270. case PROC_CTX_HANDLE_ID_RNDIS_802_3_2_ETH2:
  271. procCtx->type = IPA_HDR_PROC_802_3_TO_ETHII;
  272. procCtx->hdr_hdl =
  273. m_headerHandles[HEADER_HANDLE_ID_RNDIS_ETH2];
  274. break;
  275. case PROC_CTX_HANDLE_ID_WLAN_802_3_2_ETH2:
  276. procCtx->type = IPA_HDR_PROC_802_3_TO_802_3;
  277. procCtx->hdr_hdl =
  278. m_headerHandles[HEADER_HANDLE_ID_WLAN_802_3];
  279. break;
  280. case PROC_CTX_HANDLE_ID_802_1Q_2_802_1Q:
  281. procCtx->type = IPA_HDR_PROC_ETHII_TO_ETHII_EX;
  282. procCtx->hdr_hdl =
  283. m_headerHandles[HEADER_HANDLE_ID_VLAN_802_1Q];
  284. procCtx->generic_params.input_ethhdr_negative_offset = 18;
  285. procCtx->generic_params.output_ethhdr_negative_offset = 18;
  286. break;
  287. case PROC_CTX_HANDLE_ID_802_1Q_2_ETH2:
  288. procCtx->type = IPA_HDR_PROC_ETHII_TO_ETHII_EX;
  289. procCtx->hdr_hdl =
  290. m_headerHandles[HEADER_HANDLE_ID_ETH2];
  291. procCtx->generic_params.input_ethhdr_negative_offset = 18;
  292. procCtx->generic_params.output_ethhdr_negative_offset = 14;
  293. break;
  294. case PROC_CTX_HANDLE_ID_ETH2_2_802_1Q:
  295. procCtx->type = IPA_HDR_PROC_ETHII_TO_ETHII_EX;
  296. procCtx->hdr_hdl =
  297. m_headerHandles[HEADER_HANDLE_ID_VLAN_802_1Q];
  298. procCtx->generic_params.input_ethhdr_negative_offset = 14;
  299. procCtx->generic_params.output_ethhdr_negative_offset = 18;
  300. break;
  301. case PROC_CTX_HANDLE_ID_ETH2_ETH2_2_ETH2_EX:
  302. procCtx->type = IPA_HDR_PROC_ETHII_TO_ETHII_EX;
  303. procCtx->hdr_hdl =
  304. m_headerHandles[HEADER_HANDLE_ID_ETH2];
  305. procCtx->generic_params.input_ethhdr_negative_offset = 14;
  306. procCtx->generic_params.output_ethhdr_negative_offset = 14;
  307. break;
  308. default:
  309. LOG_MSG_ERROR("proc ctx handleId %d not supported.", handleId);
  310. return;
  311. }
  312. if (!m_headerInsertion.AddProcCtx(procCtxTable))
  313. {
  314. LOG_MSG_ERROR("m_headerInsertion.AddProcCtx(procCtxTable) failed.");
  315. return;
  316. }
  317. // save proc_ctx handle
  318. m_procCtxHHandles[handleId] = procCtx->proc_ctx_hdl;
  319. }
  320. void IpaHdrProcCtxTestFixture::AddRtBypassRule(uint32_t hdrHdl, uint32_t procCtxHdl)
  321. {
  322. static const char bypass0[] = "bypass0";
  323. struct ipa_ioc_get_rt_tbl routing_table0;
  324. if (!CreateIPv4BypassRoutingTable (
  325. bypass0,
  326. hdrHdl,
  327. procCtxHdl))
  328. {
  329. LOG_MSG_ERROR("CreateIPv4BypassRoutingTable Failed\n");
  330. return;
  331. }
  332. routing_table0.ip = IPA_IP_v4;
  333. strlcpy(routing_table0.name, bypass0, sizeof(routing_table0.name));
  334. if (!m_routing.GetRoutingTable(&routing_table0))
  335. {
  336. LOG_MSG_ERROR("m_routing.GetRoutingTable() Failed.");
  337. return;
  338. }
  339. m_routingTableHdl = routing_table0.hdl;
  340. }
  341. void IpaHdrProcCtxTestFixture::AddFltBypassRule()
  342. {
  343. IPAFilteringTable FilterTable0;
  344. struct ipa_flt_rule_add flt_rule_entry;
  345. FilterTable0.Init(IPA_IP_v4,m_currProducerClient,false,1);
  346. printf("FilterTable*.Init Completed Successfully..\n");
  347. // Configuring Filtering Rule No.0
  348. FilterTable0.GeneratePresetRule(1,flt_rule_entry);
  349. flt_rule_entry.at_rear = true;
  350. flt_rule_entry.flt_rule_hdl=-1; // return Value
  351. flt_rule_entry.status = -1; // return value
  352. flt_rule_entry.rule.action=IPA_PASS_TO_ROUTING;
  353. flt_rule_entry.rule.rt_tbl_hdl=m_routingTableHdl;
  354. flt_rule_entry.rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  355. flt_rule_entry.rule.attrib.u.v4.dst_addr_mask = 0x00000000; // Mask - Bypass rule
  356. flt_rule_entry.rule.attrib.u.v4.dst_addr = 0x12345678; // Filter is irrelevant.
  357. if (((uint8_t)-1 == FilterTable0.AddRuleToTable(flt_rule_entry)) ||
  358. !m_filtering.AddFilteringRule(
  359. FilterTable0.GetFilteringTable()))
  360. {
  361. LOG_MSG_ERROR(
  362. "%s::m_filtering.AddFilteringRule() failed",
  363. __FUNCTION__);
  364. return;
  365. }
  366. else
  367. {
  368. printf("flt rule hdl0=0x%x, status=0x%x\n",
  369. FilterTable0.ReadRuleFromTable(0)->flt_rule_hdl,
  370. FilterTable0.ReadRuleFromTable(0)->status);
  371. }
  372. }
  373. bool IpaHdrProcCtxTestFixture::ReceivePacketsAndCompare()
  374. {
  375. size_t receivedBufferSize1 = 0;
  376. bool isSuccess = true;
  377. // Receive results
  378. Byte *receivedBuffer1 = new Byte[m_BUFF_MAX_SIZE];
  379. if (NULL == receivedBuffer1)
  380. {
  381. printf("Memory allocation error.\n");
  382. return false;
  383. }
  384. receivedBufferSize1 = m_pCurrentConsumer->ReceiveData(
  385. receivedBuffer1,
  386. m_BUFF_MAX_SIZE);
  387. printf("Received %zu bytes on %s.\n",
  388. receivedBufferSize1,
  389. m_pCurrentConsumer->m_fromChannelName.c_str());
  390. // Compare results
  391. if (!CompareResultVsGolden(
  392. m_expectedBuffer1,
  393. m_expectedBufferSize1,
  394. receivedBuffer1,
  395. receivedBufferSize1))
  396. {
  397. printf("Comparison of Buffer Failed!\n");
  398. isSuccess = false;
  399. }
  400. printf("Expected buffer 1 - %zu bytes\n", m_expectedBufferSize1);
  401. print_buff(m_expectedBuffer1, m_expectedBufferSize1);
  402. printf("Received buffer 1 - %zu bytes\n", receivedBufferSize1);
  403. print_buff(receivedBuffer1, receivedBufferSize1);
  404. delete[] receivedBuffer1;
  405. return isSuccess;
  406. }
  407. // Create 1 IPv4 bypass routing entry and commits it
  408. bool IpaHdrProcCtxTestFixture::CreateIPv4BypassRoutingTable (
  409. const char *name,
  410. uint32_t hdrHdl,
  411. uint32_t procCtxHdl)
  412. {
  413. printf("Entering %s, %s()\n",__FUNCTION__, __FILE__);
  414. struct ipa_ioc_add_rt_rule *rt_table = 0;
  415. struct ipa_rt_rule_add *rt_rule_entry = NULL;
  416. // Verify that only one is nonzero
  417. if ((hdrHdl == 0 && procCtxHdl == 0) ||
  418. (hdrHdl != 0 && procCtxHdl != 0))
  419. {
  420. LOG_MSG_ERROR("Error: hdrHdl = %u, procCtxHdl = %u\n");
  421. return false;
  422. }
  423. rt_table = (struct ipa_ioc_add_rt_rule *)
  424. calloc(1, sizeof(struct ipa_ioc_add_rt_rule) +
  425. 1*sizeof(struct ipa_rt_rule_add));
  426. if(!rt_table) {
  427. LOG_MSG_ERROR("calloc failed to allocate rt_table\n");
  428. return false;
  429. }
  430. rt_table->num_rules = 1;
  431. rt_table->ip = IPA_IP_v4;
  432. rt_table->commit = true;
  433. strlcpy(rt_table->rt_tbl_name, name, sizeof(rt_table->rt_tbl_name));
  434. rt_rule_entry = &rt_table->rules[0];
  435. rt_rule_entry->at_rear = 0;
  436. rt_rule_entry->rule.dst = m_currConsumerPipeNum;
  437. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  438. rt_rule_entry->rule.attrib.u.v4.dst_addr = 0xaabbccdd;
  439. // All Packets will get a "Hit"
  440. rt_rule_entry->rule.attrib.u.v4.dst_addr_mask = 0x00000000;
  441. rt_rule_entry->rule.hdr_hdl = hdrHdl;
  442. rt_rule_entry->rule.hdr_proc_ctx_hdl = procCtxHdl;
  443. if (false == m_routing.AddRoutingRule(rt_table))
  444. {
  445. printf("Routing rule addition(rt_table) failed!\n");
  446. Free (rt_table);
  447. return false;
  448. }
  449. Free (rt_table);
  450. printf("Leaving %s, %s()\n",__FUNCTION__, __FILE__);
  451. return true;
  452. }
  453. bool IpaHdrProcCtxTestFixture::AddRules()
  454. {
  455. printf("Entering %s, %s()\n",__FUNCTION__, __FILE__);
  456. if (m_procCtxHandleId == PROC_CTX_HANDLE_ID_MAX)
  457. {
  458. LOG_MSG_ERROR("Test developer didn't implement "
  459. "AddRules() or didn't set m_procCtxHandleId");
  460. return false;
  461. }
  462. AddAllHeaders();
  463. AddAllProcCtx();
  464. AddRtBypassRule(0, m_procCtxHHandles[m_procCtxHandleId]);
  465. AddFltBypassRule();
  466. printf("Leaving %s, %s()\n",__FUNCTION__, __FILE__);
  467. return true;
  468. }// AddRules()
  469. bool IpaHdrProcCtxTestFixture::SendPackets()
  470. {
  471. bool isSuccess = false;
  472. // Send first packet
  473. isSuccess = m_pCurrentProducer->SendData(
  474. m_sendBuffer1,
  475. m_sendSize1);
  476. if (false == isSuccess)
  477. {
  478. LOG_MSG_ERROR("SendPackets Buffer1 failed on client %d\n", m_currProducerClient);
  479. return false;
  480. }
  481. return true;
  482. }
  483. bool IpaHdrProcCtxTestFixture::Run()
  484. {
  485. bool res = false;
  486. bool isSuccess = false;
  487. printf("Entering %s, %s()\n",__FUNCTION__, __FILE__);
  488. res = AddRules();
  489. if (false == res) {
  490. printf("Failed adding filtering rules.\n");
  491. return false;
  492. }
  493. // Load input data - IP packets
  494. res = LoadPackets(m_IpaIPType);
  495. if (false == res) {
  496. printf("Failed loading packets.\n");
  497. return false;
  498. }
  499. res = GenerateExpectedPackets();
  500. if (false == res) {
  501. printf("GenerateExpectedPackets failed\n");
  502. return false;
  503. }
  504. res = SendPackets();
  505. if (false == res) {
  506. printf("SendPackets failed\n");
  507. return false;
  508. }
  509. // Receive packets from the channels and compare results
  510. isSuccess = ReceivePacketsAndCompare();
  511. printf("Leaving %s, %s(), Returning %d\n",
  512. __FUNCTION__,
  513. __FILE__,
  514. isSuccess);
  515. return isSuccess;
  516. } // Run()
  517. IpaHdrProcCtxTestFixture::~IpaHdrProcCtxTestFixture()
  518. {
  519. m_sendSize1 = 0;
  520. }
  521. RoutingDriverWrapper IpaHdrProcCtxTestFixture::m_routing;
  522. Filtering IpaHdrProcCtxTestFixture::m_filtering;
  523. HeaderInsertion IpaHdrProcCtxTestFixture::m_headerInsertion;