HeaderInsertionTests.cpp 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432
  1. /*
  2. * Copyright (c) 2017-2018,2021 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 "RoutingDriverWrapper.h"
  30. #include "HeaderInsertion.h"
  31. #include "Filtering.h"
  32. #include "IPAFilteringTable.h"
  33. #include "hton.h" // for htonl
  34. #include "TestsUtils.h"
  35. #include <string.h>
  36. #include <unistd.h>
  37. #include <errno.h>
  38. #include <fcntl.h>
  39. #include <sys/ioctl.h>
  40. #define IPV4_DST_ADDR_OFFSET (16)
  41. class IPAHeaderInsertionTestFixture: public TestBase {
  42. public:
  43. IPAHeaderInsertionTestFixture() : m_uBufferSize(0)
  44. {
  45. memset(m_aBuffer, 0, sizeof(m_aBuffer));
  46. m_testSuiteName.push_back("Insertion");
  47. }
  48. virtual bool AddRules() = 0;
  49. virtual bool ModifyPackets() = 0;
  50. virtual bool TestLogic() = 0;
  51. bool Setup()
  52. {
  53. ConfigureScenario(PHASE_FIVE_TEST_CONFIGURATION);
  54. m_producer.Open(INTERFACE0_TO_IPA_DATA_PATH,
  55. INTERFACE0_FROM_IPA_DATA_PATH);
  56. m_Consumer1.Open(INTERFACE1_TO_IPA_DATA_PATH,
  57. INTERFACE1_FROM_IPA_DATA_PATH);
  58. m_Consumer2.Open(INTERFACE2_TO_IPA_DATA_PATH,
  59. INTERFACE2_FROM_IPA_DATA_PATH);
  60. m_Consumer3.Open(INTERFACE3_TO_IPA_DATA_PATH,
  61. INTERFACE3_FROM_IPA_DATA_PATH);
  62. if (!m_Routing.DeviceNodeIsOpened()) {
  63. LOG_MSG_ERROR(
  64. "Routing block is not ready for immediate commands!\n");
  65. return false;
  66. }
  67. if (!m_Filtering.DeviceNodeIsOpened()) {
  68. LOG_MSG_ERROR(
  69. "Filtering block is not ready for immediate commands!\n");
  70. return false;
  71. }
  72. if (!m_HeaderInsertion.DeviceNodeIsOpened())
  73. {
  74. LOG_MSG_ERROR("Header Insertion block is not ready for immediate commands!\n");
  75. return false;
  76. }
  77. m_HeaderInsertion.Reset();// resetting this component will reset both Routing and Filtering tables.
  78. return true;
  79. } // Setup()
  80. bool Run()
  81. {
  82. m_uBufferSize = BUFF_MAX_SIZE;
  83. LOG_MSG_STACK("Entering Function");
  84. // Add the relevant filtering rules
  85. if (!AddRules()) {
  86. LOG_MSG_ERROR("Failed adding filtering rules.");
  87. return false;
  88. }
  89. // Load input data (IP packet) from file
  90. if (!LoadDefaultPacket(m_eIP, m_aBuffer, m_uBufferSize)) {
  91. LOG_MSG_ERROR("Failed default Packet");
  92. return false;
  93. }
  94. if (!ModifyPackets()) {
  95. LOG_MSG_ERROR("Failed to modify packets.");
  96. return false;
  97. }
  98. if (!TestLogic()) {
  99. LOG_MSG_ERROR("Test failed, Input and expected output mismatch.");
  100. return false;
  101. }
  102. LOG_MSG_STACK("Leaving Function (Returning True)");
  103. return true;
  104. } // Run()
  105. bool Teardown()
  106. {
  107. m_HeaderInsertion.Reset();// resetting this component will reset both Routing and Filtering tables.
  108. m_producer.Close();
  109. m_Consumer1.Close();
  110. m_Consumer2.Close();
  111. m_Consumer3.Close();
  112. return true;
  113. } // Teardown()
  114. unsigned GetHdrSramSize()
  115. {
  116. int fd;
  117. struct ipa_test_mem_partition mem_part;
  118. fd = open("/dev/ipa_test", O_RDONLY);
  119. if (fd < 0) {
  120. printf("Failed opening %s. errno %d: %s\n", "/dev/ipa_test",
  121. errno, strerror(errno));
  122. return 0;
  123. }
  124. if (ioctl(fd, IPA_TEST_IOC_GET_MEM_PART, &mem_part) < 0) {
  125. printf("Failed ioctl IPA_TEST_IOC_GET_MEM_PART. errno %d: %s\n",
  126. errno, strerror(errno));
  127. close(fd);
  128. return 0;
  129. }
  130. close(fd);
  131. return mem_part.apps_hdr_size;
  132. }
  133. ~IPAHeaderInsertionTestFixture() {}
  134. static RoutingDriverWrapper m_Routing;
  135. static Filtering m_Filtering;
  136. static HeaderInsertion m_HeaderInsertion;
  137. InterfaceAbstraction m_producer;
  138. InterfaceAbstraction m_Consumer1;
  139. InterfaceAbstraction m_Consumer2;
  140. InterfaceAbstraction m_Consumer3;
  141. protected:
  142. static const size_t BUFF_MAX_SIZE = 1024;
  143. static const uint8_t MAX_HEADER_SIZE = 64; // 64Bytes - Max Header Length
  144. enum ipa_ip_type m_eIP;
  145. uint8_t m_aBuffer[BUFF_MAX_SIZE]; // Input file \ IP packet
  146. size_t m_uBufferSize;
  147. };
  148. RoutingDriverWrapper IPAHeaderInsertionTestFixture::m_Routing;
  149. Filtering IPAHeaderInsertionTestFixture::m_Filtering;
  150. HeaderInsertion IPAHeaderInsertionTestFixture::m_HeaderInsertion;
  151. //---------------------------------------------------------------------------/
  152. // Test002: Test that 802.3 header was inserted Correctly /
  153. //---------------------------------------------------------------------------/
  154. class IPAHeaderInsertionTest001: public IPAHeaderInsertionTestFixture {
  155. public:
  156. IPAHeaderInsertionTest001() {
  157. m_name = "IPAHeaderInsertionTest001";
  158. m_description =
  159. "Header Insertion Test 001 - Test RMNet Header Insertion\
  160. 1. Generate and commit RMNet.3 header Insertion \
  161. 2. Generate and commit routing table containing bypass rule. \
  162. 3. Generate and commit bypass filtering rule. \
  163. 4. Send a packet, and verify that the RMNet.3 Header was inserted correctly.";
  164. Register(*this);
  165. uint8_t aRMNetHeader[6] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06};
  166. m_nHeadertoAddSize = sizeof(aRMNetHeader);
  167. memcpy(m_aHeadertoAdd, aRMNetHeader, m_nHeadertoAddSize);
  168. }
  169. // Test Description:
  170. // 1. Generate and commit single bypass routing table.
  171. virtual bool AddRules() {
  172. m_eIP = IPA_IP_v4;
  173. const char bypass0[20] = "Bypass0";
  174. struct ipa_ioc_get_rt_tbl sRoutingTable;
  175. bool bRetVal = true;
  176. struct ipa_ioc_get_hdr sRetHeader;
  177. IPAFilteringTable cFilterTable;
  178. struct ipa_flt_rule_add sFilterRuleEntry;
  179. uint32_t nRTTableHdl=0;
  180. memset(&sRoutingTable, 0, sizeof(sRoutingTable));
  181. memset(&sRetHeader, 0, sizeof(sRetHeader));
  182. strlcpy(sRetHeader.name, "IEEE802_3", sizeof(sRetHeader.name));
  183. LOG_MSG_STACK("Entering Function");
  184. // Create Header:
  185. // Allocate Memory, populate it, and add in to the Header Insertion.
  186. struct ipa_ioc_add_hdr * pHeaderDescriptor = NULL;
  187. pHeaderDescriptor = (struct ipa_ioc_add_hdr *) calloc(1,
  188. sizeof(struct ipa_ioc_add_hdr)
  189. + 1 * sizeof(struct ipa_hdr_add));
  190. if (!pHeaderDescriptor) {
  191. LOG_MSG_ERROR("calloc failed to allocate pHeaderDescriptor");
  192. bRetVal = false;
  193. goto bail;
  194. }
  195. pHeaderDescriptor->commit = true;
  196. pHeaderDescriptor->num_hdrs = 1;
  197. strlcpy(pHeaderDescriptor->hdr[0].name, sRetHeader.name, sizeof(pHeaderDescriptor->hdr[0].name));
  198. memcpy(pHeaderDescriptor->hdr[0].hdr, m_aHeadertoAdd,
  199. m_nHeadertoAddSize); //Header's Data
  200. pHeaderDescriptor->hdr[0].hdr_len = m_nHeadertoAddSize;
  201. pHeaderDescriptor->hdr[0].hdr_hdl = -1; //Return Value
  202. pHeaderDescriptor->hdr[0].is_partial = false;
  203. pHeaderDescriptor->hdr[0].status = -1; // Return Parameter
  204. strlcpy(sRetHeader.name, pHeaderDescriptor->hdr[0].name, sizeof(sRetHeader.name));
  205. if (!m_HeaderInsertion.AddHeader(pHeaderDescriptor))
  206. {
  207. LOG_MSG_ERROR("m_HeaderInsertion.AddHeader(pHeaderDescriptor) Failed.");
  208. bRetVal = false;
  209. goto bail;
  210. }
  211. if (!m_HeaderInsertion.GetHeaderHandle(&sRetHeader))
  212. {
  213. LOG_MSG_ERROR(" Failed");
  214. bRetVal = false;
  215. goto bail;
  216. }
  217. if (!CreateBypassRoutingTable(&m_Routing, m_eIP, bypass0, IPA_CLIENT_TEST2_CONS,
  218. sRetHeader.hdl,&nRTTableHdl)) {
  219. LOG_MSG_ERROR("CreateBypassRoutingTable Failed\n");
  220. bRetVal = false;
  221. goto bail;
  222. }
  223. LOG_MSG_INFO("CreateBypassRoutingTable completed successfully");
  224. sRoutingTable.ip = m_eIP;
  225. strlcpy(sRoutingTable.name, bypass0, sizeof(sRoutingTable.name));
  226. if (!m_Routing.GetRoutingTable(&sRoutingTable)) {
  227. LOG_MSG_ERROR(
  228. "m_routing.GetRoutingTable(&sRoutingTable=0x%p) Failed.", &sRoutingTable);
  229. bRetVal = false;
  230. goto bail;
  231. }
  232. // Creating Filtering Rules
  233. cFilterTable.Init(m_eIP,IPA_CLIENT_TEST_PROD,false,1);
  234. LOG_MSG_INFO("Creation of filtering table completed successfully");
  235. // Configuring Filtering Rule No.1
  236. cFilterTable.GeneratePresetRule(0,sFilterRuleEntry);
  237. sFilterRuleEntry.at_rear = true;
  238. sFilterRuleEntry.flt_rule_hdl = -1; // return Value
  239. sFilterRuleEntry.status = -1; // return value
  240. sFilterRuleEntry.rule.action = IPA_PASS_TO_ROUTING;
  241. sFilterRuleEntry.rule.rt_tbl_hdl = nRTTableHdl; //put here the handle corresponding to Routing Rule 1
  242. if (
  243. ((uint8_t)-1 == cFilterTable.AddRuleToTable(sFilterRuleEntry)) ||
  244. !m_Filtering.AddFilteringRule(cFilterTable.GetFilteringTable())
  245. )
  246. {
  247. LOG_MSG_ERROR ("Adding Rule (0) to Filtering block Failed.");
  248. bRetVal = false;
  249. goto bail;
  250. } else
  251. {
  252. LOG_MSG_DEBUG("flt rule hdl0=0x%x, status=0x%x\n", cFilterTable.ReadRuleFromTable(0)->flt_rule_hdl,cFilterTable.ReadRuleFromTable(0)->status);
  253. }
  254. bail:
  255. Free(pHeaderDescriptor);
  256. LOG_MSG_STACK(
  257. "Leaving Function (Returning %s)", bRetVal?"True":"False");
  258. return bRetVal;
  259. } // AddRules()
  260. virtual bool ModifyPackets() {
  261. // This test doesn't modify the original IP Packet.
  262. return true;
  263. } // ModifyPacktes ()
  264. virtual bool TestLogic() {
  265. memset(m_aExpectedBuffer, 0, sizeof(m_aExpectedBuffer));
  266. m_aExpectedBufSize = 0;
  267. memcpy(m_aExpectedBuffer, m_aHeadertoAdd, m_nHeadertoAddSize);
  268. memcpy(m_aExpectedBuffer+m_nHeadertoAddSize,m_aBuffer,m_uBufferSize);
  269. m_aExpectedBufSize = m_nHeadertoAddSize + m_uBufferSize;
  270. if (!SendReceiveAndCompare(&m_producer, m_aBuffer, m_uBufferSize,
  271. &m_Consumer1, m_aExpectedBuffer, m_aExpectedBufSize)) {
  272. LOG_MSG_ERROR("SendReceiveAndCompare failed.");
  273. return false;
  274. }
  275. return true;
  276. }
  277. private:
  278. uint8_t m_aExpectedBuffer[BUFF_MAX_SIZE]; // Input file / IP packet
  279. size_t m_aExpectedBufSize;
  280. uint8_t m_aHeadertoAdd[MAX_HEADER_SIZE];
  281. size_t m_nHeadertoAddSize;
  282. };
  283. //---------------------------------------------------------------------------/
  284. // Test002: Test that 802.3 header was inserted Correctly /
  285. //---------------------------------------------------------------------------/
  286. class IPAHeaderInsertionTest002: public IPAHeaderInsertionTestFixture {
  287. public:
  288. IPAHeaderInsertionTest002() {
  289. m_name = "IPAHeaderInsertionTest002";
  290. m_description =
  291. "Header Insertion Test 002 - Test IEEE802.3 Header Insertion\
  292. 1. Generate and commit IEEE802.3 header Insertion \
  293. 2. Generate and commit routing table containing bypass rule. \
  294. 3. Generate and commit bypass filtering rule. \
  295. 4. Send a packet, and verify that the IEEE802.3 Header was inserted correctly \
  296. and that the header Length was updated as well";
  297. Register(*this);
  298. uint8_t aIEEE802_3Header[22] = { 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6,
  299. 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0x00, 0x46, 0xAE, 0xAF, 0xB0,// the correct size (00 46) is inserted here.
  300. 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6 };
  301. m_nHeadertoAddSize = sizeof(aIEEE802_3Header);
  302. memcpy(m_aHeadertoAdd, aIEEE802_3Header, m_nHeadertoAddSize);
  303. }
  304. // Test Description:
  305. // 1. Generate and commit single bypass routing table.
  306. virtual bool AddRules() {
  307. m_eIP = IPA_IP_v4;
  308. const char bypass0[20] = "Bypass0";
  309. struct ipa_ioc_get_rt_tbl sRoutingTable;
  310. bool bRetVal = true;
  311. struct ipa_ioc_get_hdr sRetHeader;
  312. IPAFilteringTable cFilterTable;
  313. struct ipa_flt_rule_add sFilterRuleEntry;
  314. uint32_t nRTTableHdl=0;
  315. memset(&sRoutingTable, 0, sizeof(sRoutingTable));
  316. memset(&sRetHeader, 0, sizeof(sRetHeader));
  317. strlcpy(sRetHeader.name, "IEEE802_3", sizeof(sRetHeader.name));
  318. LOG_MSG_STACK("Entering Function");
  319. // Create Header:
  320. // Allocate Memory, populate it, and add in to the Header Insertion.
  321. struct ipa_ioc_add_hdr * pHeaderDescriptor = NULL;
  322. pHeaderDescriptor = (struct ipa_ioc_add_hdr *) calloc(1,
  323. sizeof(struct ipa_ioc_add_hdr)
  324. + 1 * sizeof(struct ipa_hdr_add));
  325. if (!pHeaderDescriptor) {
  326. LOG_MSG_ERROR("calloc failed to allocate pHeaderDescriptor");
  327. bRetVal = false;
  328. goto bail;
  329. }
  330. pHeaderDescriptor->commit = true;
  331. pHeaderDescriptor->num_hdrs = 1;
  332. strlcpy(pHeaderDescriptor->hdr[0].name, sRetHeader.name, sizeof(pHeaderDescriptor->hdr[0].name)); // Header's Name
  333. memcpy(pHeaderDescriptor->hdr[0].hdr, m_aHeadertoAdd,
  334. m_nHeadertoAddSize); //Header's Data
  335. pHeaderDescriptor->hdr[0].hdr[12] = 0x00; //set length to zero, to confirm if ipa updates or not
  336. pHeaderDescriptor->hdr[0].hdr_len = m_nHeadertoAddSize;
  337. pHeaderDescriptor->hdr[0].hdr_hdl = -1; //Return Value
  338. pHeaderDescriptor->hdr[0].is_partial = false;
  339. pHeaderDescriptor->hdr[0].status = -1; // Return Parameter
  340. strlcpy(sRetHeader.name, pHeaderDescriptor->hdr[0].name, sizeof(sRetHeader.name));
  341. if (!m_HeaderInsertion.AddHeader(pHeaderDescriptor))
  342. {
  343. LOG_MSG_ERROR("m_HeaderInsertion.AddHeader(pHeaderDescriptor) Failed.");
  344. bRetVal = false;
  345. goto bail;
  346. }
  347. if (!m_HeaderInsertion.GetHeaderHandle(&sRetHeader))
  348. {
  349. LOG_MSG_ERROR(" Failed");
  350. bRetVal = false;
  351. goto bail;
  352. }
  353. if (!CreateBypassRoutingTable(&m_Routing, m_eIP, bypass0, IPA_CLIENT_TEST3_CONS,
  354. sRetHeader.hdl,&nRTTableHdl)) {
  355. LOG_MSG_ERROR("CreateBypassRoutingTable Failed\n");
  356. bRetVal = false;
  357. goto bail;
  358. }
  359. LOG_MSG_INFO("CreateBypassRoutingTable completed successfully");
  360. sRoutingTable.ip = m_eIP;
  361. strlcpy(sRoutingTable.name, bypass0, sizeof(sRoutingTable.name));
  362. if (!m_Routing.GetRoutingTable(&sRoutingTable)) {
  363. LOG_MSG_ERROR(
  364. "m_routing.GetRoutingTable(&sRoutingTable=0x%p) Failed.", &sRoutingTable);
  365. bRetVal = false;
  366. goto bail;
  367. }
  368. // Creating Filtering Rules
  369. cFilterTable.Init(m_eIP,IPA_CLIENT_TEST_PROD,false,1);
  370. LOG_MSG_INFO("Creation of filtering table completed successfully");
  371. // Configuring Filtering Rule No.1
  372. cFilterTable.GeneratePresetRule(0,sFilterRuleEntry);
  373. sFilterRuleEntry.at_rear = true;
  374. sFilterRuleEntry.flt_rule_hdl = -1; // return Value
  375. sFilterRuleEntry.status = -1; // return value
  376. sFilterRuleEntry.rule.action = IPA_PASS_TO_ROUTING;
  377. sFilterRuleEntry.rule.rt_tbl_hdl = nRTTableHdl; //put here the handle corresponding to Routing Rule 1
  378. if (
  379. ((uint8_t)-1 == cFilterTable.AddRuleToTable(sFilterRuleEntry)) ||
  380. !m_Filtering.AddFilteringRule(cFilterTable.GetFilteringTable())
  381. )
  382. {
  383. LOG_MSG_ERROR ("Adding Rule (0) to Filtering block Failed.");
  384. bRetVal = false;
  385. goto bail;
  386. } else
  387. {
  388. LOG_MSG_DEBUG("flt rule hdl0=0x%x, status=0x%x\n", cFilterTable.ReadRuleFromTable(0)->flt_rule_hdl,cFilterTable.ReadRuleFromTable(0)->status);
  389. }
  390. bail:
  391. Free(pHeaderDescriptor);
  392. LOG_MSG_STACK(
  393. "Leaving Function (Returning %s)", bRetVal?"True":"False");
  394. return bRetVal;
  395. } // AddRules()
  396. virtual bool ModifyPackets() {
  397. // This test doesn't modify the original IP Packet.
  398. return true;
  399. } // ModifyPacktes ()
  400. virtual bool TestLogic() {
  401. memset(m_aExpectedBuffer, 0, sizeof(m_aExpectedBuffer));
  402. m_aExpectedBufSize = 0;
  403. memcpy(m_aExpectedBuffer, m_aHeadertoAdd, m_nHeadertoAddSize);
  404. memcpy(m_aExpectedBuffer+m_nHeadertoAddSize,m_aBuffer,m_uBufferSize);
  405. m_aExpectedBufSize = m_nHeadertoAddSize + m_uBufferSize;
  406. if (!SendReceiveAndCompare(&m_producer, m_aBuffer, m_uBufferSize,
  407. &m_Consumer2, m_aExpectedBuffer, m_aExpectedBufSize)) {
  408. LOG_MSG_ERROR("SendReceiveAndCompare failed.");
  409. return false;
  410. }
  411. return true;
  412. }
  413. private:
  414. uint8_t m_aExpectedBuffer[BUFF_MAX_SIZE]; // Input file / IP packet
  415. size_t m_aExpectedBufSize;
  416. uint8_t m_aHeadertoAdd[MAX_HEADER_SIZE];
  417. size_t m_nHeadertoAddSize;
  418. };
  419. //---------------------------------------------------------------------------/
  420. // Test003: Test Three Different Header Insertions /
  421. //---------------------------------------------------------------------------/
  422. class IPAHeaderInsertionTest003: public IPAHeaderInsertionTestFixture {
  423. public:
  424. IPAHeaderInsertionTest003() :
  425. m_aExpectedBufSize(BUFF_MAX_SIZE),
  426. m_nHeadertoAddSize1(0),
  427. m_nHeadertoAddSize2(0),
  428. m_nHeadertoAddSize3(0)
  429. {
  430. m_name = "IPAHeaderInsertionTest003";
  431. m_description =
  432. "Header Insertion Test 003 - Test RmNet,IEEE802.3 and IEEE802.3 with const (1) addition to the length field\
  433. 1. Generate and commit two types of header Insertion RmNet and IEE802.3 \
  434. 2. Generate and commit three routing tables. \
  435. Each table contains a single \"bypass\" rule (all data goes to output pipe 0, 1 and 2 (accordingly)) \
  436. Routing table 1 is used to add RmNet Header \
  437. Routing table 2 is used to add IEEE802.3 Header (requires update of the Length field) \
  438. Routing table 3 is used to add IEEE802.3 Header with additional const (1) to the length field \
  439. 3. Generate and commit Three filtering rules (MASK = 0xFF..FF). \
  440. All DST_IP == 127.0.0.1 traffic goes to routing table 1 \
  441. All DST_IP == 192.169.1.1 traffic goes to routing table 2 \
  442. All DST_IP == 192.169.1.2 traffic goes to routing table 3";
  443. Register(*this);
  444. uint8_t aRMNetHeader[6] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06};
  445. uint8_t aIEEE802_3Header1[22] = { 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6,
  446. 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0x00, 0x46, 0xAE, 0xAF, 0xB0,
  447. 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6 };
  448. uint8_t aIEEE802_3Header2[22] = { 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6,
  449. 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0x00, 0x47, 0xAE, 0xAF, 0xB0,
  450. 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6 };
  451. m_nHeadertoAddSize1 = sizeof(aRMNetHeader);
  452. memcpy(m_aHeadertoAdd1, aRMNetHeader, m_nHeadertoAddSize1);
  453. m_nHeadertoAddSize2 = sizeof(aIEEE802_3Header1);
  454. memcpy(m_aHeadertoAdd2, aIEEE802_3Header1, m_nHeadertoAddSize2);
  455. m_nHeadertoAddSize3 = sizeof(aIEEE802_3Header2);
  456. memcpy(m_aHeadertoAdd3, aIEEE802_3Header2, m_nHeadertoAddSize3);
  457. }
  458. // Test Description:
  459. // 1. Generate and commit single bypass routing table.
  460. virtual bool AddRules() {
  461. m_eIP = IPA_IP_v4;
  462. const char aBypass1[20] = "Bypass1";
  463. const char aBypass2[20] = "Bypass2";
  464. const char aBypass3[20] = "Bypass3";
  465. uint32_t nTableHdl01, nTableHdl02, nTableHdl03;
  466. bool bRetVal = true;
  467. IPAFilteringTable cFilterTable0;
  468. struct ipa_flt_rule_add sFilterRuleEntry;
  469. struct ipa_ioc_get_hdr sGetHeader1,sGetHeader2;
  470. LOG_MSG_STACK("Entering Function");
  471. memset(&sFilterRuleEntry, 0, sizeof(sFilterRuleEntry));
  472. memset(&sGetHeader1, 0, sizeof(sGetHeader1));
  473. memset(&sGetHeader2, 0, sizeof(sGetHeader2));
  474. // Create Header:
  475. // Allocate Memory, populate it, and add in to the Header Insertion.
  476. struct ipa_ioc_add_hdr * pHeaderDescriptor = NULL;
  477. pHeaderDescriptor = (struct ipa_ioc_add_hdr *) calloc(1,
  478. sizeof(struct ipa_ioc_add_hdr)
  479. + 2 * sizeof(struct ipa_hdr_add));
  480. if (!pHeaderDescriptor) {
  481. LOG_MSG_ERROR("calloc failed to allocate pHeaderDescriptor");
  482. bRetVal = false;
  483. goto bail;
  484. }
  485. pHeaderDescriptor->commit = true;
  486. pHeaderDescriptor->num_hdrs = 2;
  487. // Adding Header No1.
  488. strlcpy(pHeaderDescriptor->hdr[0].name, "RMNet", sizeof(pHeaderDescriptor->hdr[0].name)); // Header's Name
  489. memcpy(pHeaderDescriptor->hdr[0].hdr, m_aHeadertoAdd1,
  490. m_nHeadertoAddSize1); //Header's Data
  491. pHeaderDescriptor->hdr[0].hdr_len = m_nHeadertoAddSize1;
  492. pHeaderDescriptor->hdr[0].hdr_hdl = -1; //Return Value
  493. pHeaderDescriptor->hdr[0].is_partial = false;
  494. pHeaderDescriptor->hdr[0].status = -1; // Return Parameter
  495. // Adding Header No2.
  496. strlcpy(pHeaderDescriptor->hdr[1].name, "IEEE_802_3", sizeof(pHeaderDescriptor->hdr[1].name)); // Header's Name
  497. memcpy(pHeaderDescriptor->hdr[1].hdr, m_aHeadertoAdd2,
  498. m_nHeadertoAddSize2); //Header's Data
  499. pHeaderDescriptor->hdr[1].hdr_len = m_nHeadertoAddSize2;
  500. pHeaderDescriptor->hdr[1].hdr_hdl = -1; //Return Value
  501. pHeaderDescriptor->hdr[1].is_partial = false;
  502. pHeaderDescriptor->hdr[1].status = -1; // Return Parameter
  503. strlcpy(sGetHeader1.name, pHeaderDescriptor->hdr[0].name, sizeof(sGetHeader1.name));
  504. strlcpy(sGetHeader2.name, pHeaderDescriptor->hdr[1].name, sizeof(sGetHeader2.name));
  505. if (!m_HeaderInsertion.AddHeader(pHeaderDescriptor))
  506. {
  507. LOG_MSG_ERROR("m_HeaderInsertion.AddHeader(pHeaderDescriptor) Failed.");
  508. bRetVal = false;
  509. goto bail;
  510. }
  511. if (!m_HeaderInsertion.GetHeaderHandle(&sGetHeader1))
  512. {
  513. LOG_MSG_ERROR(" Failed");
  514. bRetVal = false;
  515. goto bail;
  516. }
  517. LOG_MSG_DEBUG("Received Header1 Handle = 0x%x",sGetHeader1.hdl);
  518. if (!m_HeaderInsertion.GetHeaderHandle(&sGetHeader2))
  519. {
  520. LOG_MSG_ERROR(" Failed");
  521. bRetVal = false;
  522. goto bail;
  523. }
  524. LOG_MSG_DEBUG("Received Header2 Handle = 0x%x",sGetHeader2.hdl);
  525. if (!CreateBypassRoutingTable(&m_Routing, m_eIP, aBypass1, IPA_CLIENT_TEST2_CONS,
  526. sGetHeader1.hdl,&nTableHdl01)) {
  527. LOG_MSG_ERROR("CreateBypassRoutingTable Failed\n");
  528. bRetVal = false;
  529. goto bail;
  530. }
  531. if (!CreateBypassRoutingTable(&m_Routing, m_eIP, aBypass2, IPA_CLIENT_TEST3_CONS,
  532. sGetHeader2.hdl,&nTableHdl02)) {
  533. LOG_MSG_ERROR("CreateBypassRoutingTable Failed\n");
  534. bRetVal = false;
  535. goto bail;
  536. }
  537. if (!CreateBypassRoutingTable(&m_Routing, m_eIP, aBypass3, IPA_CLIENT_TEST4_CONS,
  538. sGetHeader2.hdl,&nTableHdl03)) {
  539. LOG_MSG_ERROR("CreateBypassRoutingTable Failed\n");
  540. bRetVal = false;
  541. goto bail;
  542. }
  543. LOG_MSG_INFO("Creation of three bypass routing tables completed successfully TblHdl1=0x%x, TblHdl2=0x%x, TblHdl3=0x%x",
  544. nTableHdl01,nTableHdl02,nTableHdl03);
  545. // Creating Filtering Rules
  546. cFilterTable0.Init(m_eIP,IPA_CLIENT_TEST_PROD,false,3);
  547. LOG_MSG_INFO("Creation of filtering table completed successfully");
  548. // Configuring Filtering Rule No.1
  549. cFilterTable0.GeneratePresetRule(1,sFilterRuleEntry);
  550. sFilterRuleEntry.at_rear = true;
  551. sFilterRuleEntry.flt_rule_hdl=-1; // return Value
  552. sFilterRuleEntry.status = -1; // return value
  553. sFilterRuleEntry.rule.action=IPA_PASS_TO_ROUTING;
  554. sFilterRuleEntry.rule.rt_tbl_hdl=nTableHdl01; //put here the handle corresponding to Routing Rule 1
  555. sFilterRuleEntry.rule.attrib.attrib_mask = IPA_FLT_DST_ADDR; // Destination IP Based Filtering
  556. sFilterRuleEntry.rule.attrib.u.v4.dst_addr_mask = 0xFF0000FF; // Mask
  557. sFilterRuleEntry.rule.attrib.u.v4.dst_addr = 0x7F000001; // Filter DST_IP == 127.0.0.1.
  558. if ((uint8_t)-1 == cFilterTable0.AddRuleToTable(sFilterRuleEntry))
  559. {
  560. LOG_MSG_ERROR ("Adding Rule (0) to Filtering table Failed.");
  561. bRetVal = false;
  562. goto bail;
  563. }
  564. // Configuring Filtering Rule No.2
  565. sFilterRuleEntry.flt_rule_hdl=-1; // return Value
  566. sFilterRuleEntry.status = -1; // return Value
  567. sFilterRuleEntry.rule.rt_tbl_hdl=nTableHdl02; //put here the handle corresponding to Routing Rule 2
  568. sFilterRuleEntry.rule.attrib.u.v4.dst_addr = 0xC0A80101; // Filter DST_IP == 192.168.1.1.
  569. if ((uint8_t)-1 == cFilterTable0.AddRuleToTable(sFilterRuleEntry))
  570. {
  571. LOG_MSG_ERROR ("Adding Rule(1) to Filtering table Failed.");
  572. bRetVal = false;
  573. goto bail;
  574. }
  575. // Configuring Filtering Rule No.3
  576. sFilterRuleEntry.flt_rule_hdl=-1; // return Value
  577. sFilterRuleEntry.status = -1; // return value
  578. sFilterRuleEntry.rule.rt_tbl_hdl=nTableHdl03; //put here the handle corresponding to Routing Rule 2
  579. sFilterRuleEntry.rule.attrib.u.v4.dst_addr = 0xC0A80102; // Filter DST_IP == 192.168.1.2.
  580. if ((uint8_t)-1 == cFilterTable0.AddRuleToTable(sFilterRuleEntry))
  581. {
  582. LOG_MSG_ERROR ("Adding Rule(2) to Filtering table Failed.");
  583. bRetVal = false;
  584. goto bail;
  585. }
  586. if (!m_Filtering.AddFilteringRule(cFilterTable0.GetFilteringTable())) {
  587. LOG_MSG_ERROR ("Failed to commit Filtering rules");
  588. bRetVal = false;
  589. goto bail;
  590. }
  591. LOG_MSG_DEBUG("flt rule hdl0=0x%x, status=0x%x\n", cFilterTable0.ReadRuleFromTable(0)->flt_rule_hdl,cFilterTable0.ReadRuleFromTable(0)->status);
  592. LOG_MSG_DEBUG("flt rule hdl0=0x%x, status=0x%x\n", cFilterTable0.ReadRuleFromTable(1)->flt_rule_hdl,cFilterTable0.ReadRuleFromTable(1)->status);
  593. LOG_MSG_DEBUG("flt rule hdl0=0x%x, status=0x%x\n", cFilterTable0.ReadRuleFromTable(2)->flt_rule_hdl,cFilterTable0.ReadRuleFromTable(2)->status);
  594. bail:
  595. Free(pHeaderDescriptor);
  596. LOG_MSG_STACK(
  597. "Leaving Function (Returning %s)", bRetVal?"True":"False");
  598. return bRetVal;
  599. } // AddRules()
  600. virtual bool ModifyPackets() {
  601. // This test doesn't modify the original IP Packet.
  602. return true;
  603. } // ModifyPacktes ()
  604. virtual bool TestLogic() {
  605. bool bRetVal = true;
  606. m_aExpectedBufSize = 0;
  607. uint32_t nIPv4DSTAddr;
  608. LOG_MSG_STACK("Entering Function");
  609. //Packet No. 1
  610. memset(m_aExpectedBuffer, 0, sizeof(m_aExpectedBuffer));
  611. nIPv4DSTAddr = ntohl(0x7F000001);
  612. memcpy (&m_aBuffer[IPV4_DST_ADDR_OFFSET],&nIPv4DSTAddr,sizeof(nIPv4DSTAddr));
  613. memcpy(m_aExpectedBuffer, m_aHeadertoAdd1, m_nHeadertoAddSize1);
  614. memcpy(m_aExpectedBuffer+m_nHeadertoAddSize1,m_aBuffer,m_uBufferSize);
  615. m_aExpectedBufSize = m_nHeadertoAddSize1 + m_uBufferSize;
  616. if (!SendReceiveAndCompare(&m_producer, m_aBuffer, m_uBufferSize,
  617. &m_Consumer1, m_aExpectedBuffer, m_aExpectedBufSize))
  618. {
  619. LOG_MSG_ERROR("SendReceiveAndCompare failed.");
  620. bRetVal=false;
  621. }
  622. //Packet No. 2
  623. memset(m_aExpectedBuffer, 0, sizeof(m_aExpectedBuffer));
  624. nIPv4DSTAddr = ntohl(0xC0A80101);//192.168.1.1
  625. memcpy (&m_aBuffer[IPV4_DST_ADDR_OFFSET],&nIPv4DSTAddr,sizeof(nIPv4DSTAddr));
  626. memcpy(m_aExpectedBuffer, m_aHeadertoAdd2, m_nHeadertoAddSize2);
  627. memcpy(m_aExpectedBuffer+m_nHeadertoAddSize2,m_aBuffer,m_uBufferSize);
  628. m_aExpectedBufSize = m_nHeadertoAddSize2 + m_uBufferSize;
  629. if (!SendReceiveAndCompare(&m_producer, m_aBuffer, m_uBufferSize,
  630. &m_Consumer2, m_aExpectedBuffer, m_aExpectedBufSize))
  631. {
  632. LOG_MSG_ERROR("SendReceiveAndCompare failed.");
  633. bRetVal=false;
  634. }
  635. //Packet No. 3
  636. nIPv4DSTAddr = ntohl(0xC0A80102);//192.168.1.2
  637. memcpy (&m_aBuffer[IPV4_DST_ADDR_OFFSET],&nIPv4DSTAddr,sizeof(nIPv4DSTAddr));
  638. memcpy(m_aExpectedBuffer, m_aHeadertoAdd3, m_nHeadertoAddSize3);
  639. memcpy(m_aExpectedBuffer+m_nHeadertoAddSize3,m_aBuffer,m_uBufferSize);
  640. m_aExpectedBufSize = m_nHeadertoAddSize3 + m_uBufferSize;
  641. if (!SendReceiveAndCompare(&m_producer, m_aBuffer, m_uBufferSize,
  642. &m_Consumer3, m_aExpectedBuffer, m_aExpectedBufSize))
  643. {
  644. LOG_MSG_ERROR("SendReceiveAndCompare failed.");
  645. bRetVal=false;
  646. }
  647. LOG_MSG_STACK("Leaving Function (Returning %s)",bRetVal?"True":"False");
  648. return bRetVal;
  649. }
  650. private:
  651. uint8_t m_aExpectedBuffer[BUFF_MAX_SIZE]; // Input file / IP packet
  652. size_t m_aExpectedBufSize;
  653. uint8_t m_aHeadertoAdd1[MAX_HEADER_SIZE],m_aHeadertoAdd2[MAX_HEADER_SIZE],m_aHeadertoAdd3[MAX_HEADER_SIZE];
  654. size_t m_nHeadertoAddSize1,m_nHeadertoAddSize2,m_nHeadertoAddSize3;
  655. };
  656. class IPAHeaderInsertionTest004: public IPAHeaderInsertionTestFixture {
  657. public:
  658. IPAHeaderInsertionTest004() {
  659. m_name = "IPAHeaderInsertionTest004";
  660. m_description =
  661. "Header Insertion Test 004 - Test header insertion with bad len values.";
  662. Register(*this);
  663. uint8_t aRMNetHeader[6] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06};
  664. m_nHeadertoAddSize = sizeof(aRMNetHeader);
  665. memcpy(m_aHeadertoAdd, aRMNetHeader, m_nHeadertoAddSize);
  666. }
  667. virtual bool AddRules() {
  668. // Not adding any rules here.
  669. return true;
  670. } // AddRules()
  671. virtual bool ModifyPackets() {
  672. // This test doesn't modify the original IP Packet.
  673. return true;
  674. } // ModifyPacktes ()
  675. bool AddSingleHeaderAndCheck(uint8_t len) {
  676. m_eIP = IPA_IP_v4;
  677. bool bRetVal = true;
  678. struct ipa_ioc_get_hdr sRetHeader;
  679. memset(&sRetHeader, 0, sizeof(sRetHeader));
  680. strlcpy(sRetHeader.name, "Generic", sizeof(sRetHeader.name));
  681. LOG_MSG_STACK("Entering Function");
  682. // Create Header:
  683. // Allocate Memory, populate it, and add in to the Header Insertion.
  684. struct ipa_ioc_add_hdr * pHeaderDescriptor = NULL;
  685. pHeaderDescriptor = (struct ipa_ioc_add_hdr *) calloc(1,
  686. sizeof(struct ipa_ioc_add_hdr)
  687. + 1 * sizeof(struct ipa_hdr_add));
  688. if (!pHeaderDescriptor) {
  689. LOG_MSG_ERROR("calloc failed to allocate pHeaderDescriptor");
  690. bRetVal = false;
  691. goto bail;
  692. }
  693. pHeaderDescriptor->commit = true;
  694. pHeaderDescriptor->num_hdrs = 1;
  695. strlcpy(pHeaderDescriptor->hdr[0].name, sRetHeader.name, sizeof(pHeaderDescriptor->hdr[0].name));
  696. memcpy(pHeaderDescriptor->hdr[0].hdr, m_aHeadertoAdd,
  697. m_nHeadertoAddSize); //Header's Data
  698. pHeaderDescriptor->hdr[0].hdr_len = len;
  699. pHeaderDescriptor->hdr[0].hdr_hdl = -1; //Return Value
  700. pHeaderDescriptor->hdr[0].is_partial = false;
  701. pHeaderDescriptor->hdr[0].status = -1; // Return Parameter
  702. strlcpy(sRetHeader.name, pHeaderDescriptor->hdr[0].name, sizeof(sRetHeader.name));
  703. if (!m_HeaderInsertion.AddHeader(pHeaderDescriptor))
  704. {
  705. LOG_MSG_ERROR("m_HeaderInsertion.AddHeader(pHeaderDescriptor) Failed.");
  706. bRetVal = false;
  707. goto bail;
  708. }
  709. if (!m_HeaderInsertion.GetHeaderHandle(&sRetHeader))
  710. {
  711. LOG_MSG_ERROR(" Failed");
  712. bRetVal = false;
  713. goto bail;
  714. }
  715. bail:
  716. Free(pHeaderDescriptor);
  717. LOG_MSG_STACK(
  718. "Leaving Function (Returning %s)", bRetVal?"True":"False");
  719. return bRetVal;
  720. } // AddSingleHeaderAndCheck()
  721. virtual bool TestLogic() {
  722. // Try to add headers with invalid values.
  723. // Valid values are between 1 to IPA_HDR_MAX_SIZE (64).
  724. // We expect the below functions to fail.
  725. if (AddSingleHeaderAndCheck(0)) {
  726. LOG_MSG_ERROR("This is unexpected, this can't succeed");
  727. return false;
  728. }
  729. if (AddSingleHeaderAndCheck(MAX_HEADER_SIZE + 1)) {
  730. LOG_MSG_ERROR("This is unexpected, this can't succeed");
  731. return false;
  732. }
  733. // Add one header which is OK
  734. if (!AddSingleHeaderAndCheck(m_nHeadertoAddSize)) {
  735. LOG_MSG_ERROR("This is unexpected, this can't succeed");
  736. return false;
  737. }
  738. return true;
  739. }
  740. private:
  741. uint8_t m_aHeadertoAdd[MAX_HEADER_SIZE];
  742. size_t m_nHeadertoAddSize;
  743. };
  744. class IPAHeaderInsertionTest005: public IPAHeaderInsertionTestFixture {
  745. public:
  746. IPAHeaderInsertionTest005() {
  747. m_name = "IPAHeaderInsertionTest005";
  748. m_description =
  749. "Header Insertion Test 005 - Test Multiple RMNet Header Insertion\
  750. - Stress test - Generate and commit multiple header Insertion";
  751. this->m_runInRegression = false;
  752. Register(*this);
  753. uint8_t aRMNetHeader[6] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06};
  754. m_nHeadertoAddSize = sizeof(aRMNetHeader);
  755. memcpy(m_aHeadertoAdd, aRMNetHeader, m_nHeadertoAddSize);
  756. }
  757. // Test Description:
  758. // 1. Generate and commit single bypass routing table.
  759. virtual bool AddRules() {
  760. m_eIP = IPA_IP_v4;
  761. bool bRetVal = true;
  762. struct ipa_ioc_get_hdr sRetHeader;
  763. char Name[] = "IEEE802_3\0";
  764. memset(&sRetHeader, 0, sizeof(sRetHeader));
  765. strlcpy (sRetHeader.name, Name, sizeof(sRetHeader.name));
  766. LOG_MSG_STACK("Entering Function");
  767. // Create Header:
  768. // Allocate Memory, populate it, and add in to the Header Insertion.
  769. struct ipa_ioc_add_hdr * pHeaderDescriptor = NULL;
  770. pHeaderDescriptor = (struct ipa_ioc_add_hdr *) calloc(1,
  771. sizeof(struct ipa_ioc_add_hdr)
  772. + 1 * sizeof(struct ipa_hdr_add));
  773. if (!pHeaderDescriptor) {
  774. LOG_MSG_ERROR("calloc failed to allocate pHeaderDescriptor");
  775. bRetVal = false;
  776. goto bail;
  777. }
  778. pHeaderDescriptor->commit = true;
  779. pHeaderDescriptor->num_hdrs = 1;
  780. strlcpy(pHeaderDescriptor->hdr[0].name, sRetHeader.name, sizeof(pHeaderDescriptor->hdr[0].name));
  781. memcpy(pHeaderDescriptor->hdr[0].hdr, m_aHeadertoAdd,
  782. m_nHeadertoAddSize); //Header's Data
  783. pHeaderDescriptor->hdr[0].hdr_len = m_nHeadertoAddSize;
  784. pHeaderDescriptor->hdr[0].hdr_hdl = -1; //Return Value
  785. pHeaderDescriptor->hdr[0].is_partial = false;
  786. pHeaderDescriptor->hdr[0].status = -1; // Return Parameter
  787. strlcpy(sRetHeader.name, pHeaderDescriptor->hdr[0].name, sizeof(sRetHeader.name));
  788. // stress test to check if the target crashes, failure is expected before reaching 500
  789. for (int i = 0; i < 500; i++) {
  790. LOG_MSG_DEBUG("IPAHeaderInsertionTest005::AddRules iter=%d\n",i);
  791. if (!m_HeaderInsertion.AddHeader(pHeaderDescriptor))
  792. {
  793. LOG_MSG_ERROR("m_HeaderInsertion.AddHeader(pHeaderDescriptor) Failed on %d iteration.\n",i);
  794. goto bail;
  795. }
  796. }
  797. bail:
  798. Free(pHeaderDescriptor);
  799. LOG_MSG_STACK(
  800. "Leaving Function (Returning %s)", bRetVal?"True":"False");
  801. return bRetVal;
  802. } // AddRules()
  803. virtual bool ModifyPackets() {
  804. // This test doesn't modify the original IP Packet.
  805. return true;
  806. } // ModifyPacktes ()
  807. virtual bool TestLogic() {
  808. return true;
  809. }
  810. private:
  811. uint8_t m_aHeadertoAdd[MAX_HEADER_SIZE];
  812. size_t m_nHeadertoAddSize;
  813. };
  814. class IPAHeaderInsertionTest006: public IPAHeaderInsertionTestFixture {
  815. public:
  816. IPAHeaderInsertionTest006() {
  817. m_name = "IPAHeaderInsertionTest006";
  818. m_description =
  819. "Header Insertion Test 006 - Test header distriburion between SRAM and DDR\
  820. - fill SRAM and some DDR, use DDR header";
  821. this->m_runInRegression = true;
  822. Register(*this);
  823. uint8_t aRMNetHeader[6] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06};
  824. m_nHeadertoAddSize = sizeof(aRMNetHeader);
  825. memcpy(m_aHeadertoAdd, aRMNetHeader, m_nHeadertoAddSize);
  826. m_minIPAHwType = IPA_HW_v5_0;
  827. // The bin size is 8
  828. // We are going to add number of headers to occupy twice the size of the SRAM buffer
  829. m_InitialHeadersNum = GetHdrSramSize() / 8 * 2;
  830. m_HeadersNumToDelete = 0;
  831. m_HeadersNumToAddAgain = 0;
  832. }
  833. virtual bool AddRules() {
  834. bool bRetVal = true;
  835. m_eIP = IPA_IP_v4;
  836. struct ipa_ioc_add_hdr *pHeaderDescriptor = NULL;
  837. struct ipa_ioc_del_hdr *pDelHeaderDescriptor = NULL;
  838. memset(&m_RetHeader, 0, sizeof(m_RetHeader));
  839. LOG_MSG_STACK("Entering Function");
  840. if (m_InitialHeadersNum <= 0)
  841. {
  842. LOG_MSG_ERROR("Initial headers number is set to 0!\n");
  843. bRetVal = false;
  844. goto bail;
  845. }
  846. pHeaderDescriptor = (struct ipa_ioc_add_hdr *) calloc(1,
  847. sizeof(struct ipa_ioc_add_hdr) + 1 * sizeof(struct ipa_hdr_add));
  848. if (m_HeadersNumToDelete > 0)
  849. pDelHeaderDescriptor = (struct ipa_ioc_del_hdr *)calloc(1,
  850. sizeof(struct ipa_ioc_del_hdr) + m_HeadersNumToDelete * sizeof(struct ipa_hdr_del));
  851. if (!pHeaderDescriptor || (m_HeadersNumToDelete > 0 && !pDelHeaderDescriptor))
  852. {
  853. LOG_MSG_ERROR("calloc failed to allocate ipa_ioc_add_hdr or ipa_ioc_del_hdr");
  854. bRetVal = false;
  855. goto bail;
  856. }
  857. // Add bunch of headers to SRAM and DDR
  858. pHeaderDescriptor->commit = true;
  859. pHeaderDescriptor->num_hdrs = 1;
  860. memcpy(pHeaderDescriptor->hdr[0].hdr, m_aHeadertoAdd, m_nHeadertoAddSize);
  861. pHeaderDescriptor->hdr[0].hdr_len = m_nHeadertoAddSize;
  862. pHeaderDescriptor->hdr[0].hdr_hdl = -1; //Return Value
  863. pHeaderDescriptor->hdr[0].is_partial = false;
  864. pHeaderDescriptor->hdr[0].status = -1; // Return Parameter
  865. fflush(stderr);
  866. fflush(stdout);
  867. ret = system("cat /sys/kernel/debug/ipa/hdr");
  868. for (int i = 0; i < m_InitialHeadersNum; i++)
  869. {
  870. LOG_MSG_DEBUG("%s::%s iter=%d\n", typeid(this).name(), __func__, i);
  871. snprintf(pHeaderDescriptor->hdr[0].name, sizeof(pHeaderDescriptor->hdr[0].name), "IEEE802_3_%03d", i);
  872. if (!m_HeaderInsertion.AddHeader(pHeaderDescriptor))
  873. {
  874. LOG_MSG_ERROR("m_HeaderInsertion.AddHeader(pHeaderDescriptor) Failed on %d iteration.\n", i);
  875. bRetVal = false;
  876. goto bail;
  877. }
  878. // Store header descriptors to delete
  879. if (m_HeadersNumToDelete > 0 && i < m_HeadersNumToDelete) {
  880. pDelHeaderDescriptor->hdl[i].hdl = pHeaderDescriptor->hdr[0].hdr_hdl;
  881. }
  882. }
  883. strlcpy(m_RetHeader.name, pHeaderDescriptor->hdr[0].name, sizeof(m_RetHeader.name));
  884. fflush(stderr);
  885. fflush(stdout);
  886. ret = system("cat /sys/kernel/debug/ipa/hdr");
  887. if (m_HeadersNumToDelete > 0)
  888. {
  889. // Delete few headers from SRAM
  890. pDelHeaderDescriptor->commit = true;
  891. pDelHeaderDescriptor->num_hdls = m_HeadersNumToDelete;
  892. for (int i = 0; i < m_HeadersNumToDelete; i++)
  893. pDelHeaderDescriptor->hdl[i].status = -1; // Return Parameter
  894. if (!m_HeaderInsertion.DeleteHeader(pDelHeaderDescriptor))
  895. {
  896. LOG_MSG_ERROR("m_HeaderInsertion.DeleteHeader(pDelHeaderDescriptor) Failed");
  897. bRetVal = false;
  898. goto bail;
  899. }
  900. fflush(stderr);
  901. fflush(stdout);
  902. ret = system("cat /sys/kernel/debug/ipa/hdr");
  903. }
  904. if (m_HeadersNumToAddAgain > 0)
  905. {
  906. // Add few new headers to SRAM
  907. pHeaderDescriptor->commit = true;
  908. pHeaderDescriptor->num_hdrs = 1;
  909. memcpy(pHeaderDescriptor->hdr[0].hdr, m_aHeadertoAdd, m_nHeadertoAddSize);
  910. pHeaderDescriptor->hdr[0].hdr_len = m_nHeadertoAddSize;
  911. pHeaderDescriptor->hdr[0].hdr_hdl = -1; //Return Value
  912. pHeaderDescriptor->hdr[0].is_partial = false;
  913. pHeaderDescriptor->hdr[0].status = -1; // Return Parameter
  914. for (int i = 0; i < m_HeadersNumToAddAgain; i++) {
  915. LOG_MSG_DEBUG("%s::%s iter=%d\n", typeid(this).name(), __func__, i);
  916. snprintf(pHeaderDescriptor->hdr[0].name, sizeof(pHeaderDescriptor->hdr[0].name), "IEEE802_3_%03d_2", i);
  917. if (!m_HeaderInsertion.AddHeader(pHeaderDescriptor))
  918. {
  919. LOG_MSG_ERROR("m_HeaderInsertion.AddHeader(pHeaderDescriptor) Failed on %d iteration.\n", i);
  920. bRetVal = false;
  921. goto bail;
  922. }
  923. }
  924. strlcpy(m_RetHeader.name, pHeaderDescriptor->hdr[0].name, sizeof(m_RetHeader.name));
  925. fflush(stderr);
  926. fflush(stdout);
  927. ret = system("cat /sys/kernel/debug/ipa/hdr");
  928. }
  929. // Use last added header for traffic
  930. if (!m_HeaderInsertion.GetHeaderHandle(&m_RetHeader))
  931. {
  932. LOG_MSG_ERROR(" Failed");
  933. bRetVal = false;
  934. goto bail;
  935. }
  936. bRetVal = CreateFilteringAndRouting();
  937. bail:
  938. Free(pHeaderDescriptor);
  939. if (pDelHeaderDescriptor)
  940. Free(pDelHeaderDescriptor);
  941. LOG_MSG_STACK("Leaving %s (Returning %s)", __func__, bRetVal ? "True" : "False");
  942. return bRetVal;
  943. } // AddRules()
  944. virtual bool CreateFilteringAndRouting() {
  945. uint32_t nRTTableHdl=0;
  946. const char bypass0[20] = "Bypass0";
  947. struct ipa_ioc_get_rt_tbl sRoutingTable;
  948. struct ipa_flt_rule_add sFilterRuleEntry;
  949. IPAFilteringTable cFilterTable;
  950. memset(&sRoutingTable, 0, sizeof(sRoutingTable));
  951. // Create RT table
  952. if (!CreateBypassRoutingTable(&m_Routing, m_eIP, bypass0, IPA_CLIENT_TEST2_CONS,
  953. m_RetHeader.hdl,&nRTTableHdl)) {
  954. LOG_MSG_ERROR("CreateBypassRoutingTable Failed\n");
  955. return false;
  956. }
  957. LOG_MSG_INFO("CreateBypassRoutingTable completed successfully");
  958. sRoutingTable.ip = m_eIP;
  959. strlcpy(sRoutingTable.name, bypass0, sizeof(sRoutingTable.name));
  960. if (!m_Routing.GetRoutingTable(&sRoutingTable)) {
  961. LOG_MSG_ERROR("m_routing.GetRoutingTable(&sRoutingTable=0x%p) Failed.",
  962. &sRoutingTable);
  963. return false;
  964. }
  965. // Creating Filtering Rules
  966. cFilterTable.Init(m_eIP, IPA_CLIENT_TEST_PROD, false, 1);
  967. LOG_MSG_INFO("Creation of filtering table completed successfully");
  968. // Configuring Filtering Rule No.1
  969. cFilterTable.GeneratePresetRule(0, sFilterRuleEntry);
  970. sFilterRuleEntry.at_rear = true;
  971. sFilterRuleEntry.flt_rule_hdl = -1; // return Value
  972. sFilterRuleEntry.status = -1; // return value
  973. sFilterRuleEntry.rule.action = IPA_PASS_TO_ROUTING;
  974. sFilterRuleEntry.rule.rt_tbl_hdl = nRTTableHdl; //put here the handle corresponding to Routing Rule 1
  975. if (((uint8_t)-1 == cFilterTable.AddRuleToTable(sFilterRuleEntry)) ||
  976. !m_Filtering.AddFilteringRule(cFilterTable.GetFilteringTable()))
  977. {
  978. LOG_MSG_ERROR ("Adding Rule (0) to Filtering block Failed.");
  979. return false;
  980. }
  981. else
  982. {
  983. LOG_MSG_DEBUG("flt rule hdl0=0x%x, status=0x%x\n",
  984. cFilterTable.ReadRuleFromTable(0)->flt_rule_hdl,
  985. cFilterTable.ReadRuleFromTable(0)->status);
  986. }
  987. return true;
  988. }
  989. virtual bool ModifyPackets() {
  990. return true;
  991. }
  992. virtual bool TestLogic() {
  993. memset(m_aExpectedBuffer, 0, sizeof(m_aExpectedBuffer));
  994. m_aExpectedBufSize = 0;
  995. memcpy(m_aExpectedBuffer, m_aHeadertoAdd, m_nHeadertoAddSize);
  996. memcpy(m_aExpectedBuffer+m_nHeadertoAddSize,m_aBuffer,m_uBufferSize);
  997. m_aExpectedBufSize = m_nHeadertoAddSize + m_uBufferSize;
  998. if (!SendReceiveAndCompare(&m_producer, m_aBuffer, m_uBufferSize,
  999. &m_Consumer1, m_aExpectedBuffer, m_aExpectedBufSize)) {
  1000. LOG_MSG_ERROR("SendReceiveAndCompare failed.");
  1001. return false;
  1002. }
  1003. return true;
  1004. }
  1005. protected:
  1006. struct ipa_ioc_get_hdr m_RetHeader;
  1007. int m_InitialHeadersNum;
  1008. int m_HeadersNumToDelete;
  1009. int m_HeadersNumToAddAgain;
  1010. private:
  1011. uint8_t m_aExpectedBuffer[BUFF_MAX_SIZE]; // Input file / IP packet
  1012. size_t m_aExpectedBufSize;
  1013. uint8_t m_aHeadertoAdd[MAX_HEADER_SIZE];
  1014. size_t m_nHeadertoAddSize;
  1015. int ret;
  1016. };
  1017. class IPAHeaderInsertionTest007: public IPAHeaderInsertionTest006 {
  1018. public:
  1019. IPAHeaderInsertionTest007() {
  1020. m_name = "IPAHeaderInsertionTest007";
  1021. m_description =
  1022. "Header Insertion Test 007 - Test header distriburion between SRAM and DDR\
  1023. - fill SRAM and some DDR, free some SRAM, use DDR header";
  1024. // We will delete half of the headers in the SRAM,
  1025. // which is quarter of the total initial headers number
  1026. m_HeadersNumToDelete = m_InitialHeadersNum / 4;
  1027. m_HeadersNumToAddAgain = 0;
  1028. }
  1029. };
  1030. class IPAHeaderInsertionTest008: public IPAHeaderInsertionTest006 {
  1031. public:
  1032. IPAHeaderInsertionTest008() {
  1033. m_name = "IPAHeaderInsertionTest008";
  1034. m_description =
  1035. "Header Insertion Test 008 - Test header distriburion between SRAM and DDR\
  1036. - fill SRAM and some DDR, free some SRAM, add few new SRAM headers, \
  1037. use last SRAM header";
  1038. // We will delete half of the headers in the SRAM,
  1039. // which is quarter of the total initial headers number
  1040. m_HeadersNumToDelete = m_InitialHeadersNum / 4;
  1041. // We will add again half of the number of headers we deleted
  1042. m_HeadersNumToAddAgain = m_HeadersNumToDelete / 2;
  1043. }
  1044. };
  1045. class IPAHeaderInsertionTest009: public IPAHeaderInsertionTest006 {
  1046. public:
  1047. IPAHeaderInsertionTest009() {
  1048. m_name = "IPAHeaderInsertionTest009";
  1049. m_description =
  1050. "Header Insertion Test 009 - Test header distriburion between SRAM and DDR \
  1051. - fill SRAM and some DDR, free some SRAM and DDR, \
  1052. add new SRAM and DDR headers, \
  1053. use last added DDR header";
  1054. // We will delete all the headers in SRAM and half of the headers in the DDR,
  1055. // which is 3/4 of the total initial headers number
  1056. m_HeadersNumToDelete = m_InitialHeadersNum - (m_InitialHeadersNum / 4);
  1057. // We will add again one less header than deleted
  1058. m_HeadersNumToAddAgain = m_InitialHeadersNum - m_HeadersNumToDelete - 1;
  1059. }
  1060. };
  1061. class IPAHeaderInsertionTest010: public IPAHeaderInsertionTestFixture {
  1062. public:
  1063. IPAHeaderInsertionTest010() :
  1064. m_aExpectedBufSize(BUFF_MAX_SIZE),
  1065. m_nHeadertoAddSize1(0),
  1066. m_nHeadertoAddSize2(0)
  1067. {
  1068. m_name = "IPAHeaderInsertionTest010";
  1069. m_description =
  1070. "Header Insertion Test 010 - Test header distriburion between SRAM and DDR\
  1071. - fill SRAM and some DDR, use one SRAM and one DDR header";
  1072. m_minIPAHwType = IPA_HW_v5_0;
  1073. Register(*this);
  1074. uint8_t aIEEE802_3Header1[22] = { 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6,
  1075. 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0x00, 0x46, 0xAE, 0xAF, 0xB0,
  1076. 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6 };
  1077. uint8_t aIEEE802_3Header2[22] = { 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6,
  1078. 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0x00, 0x47, 0xAE, 0xAF, 0xB0,
  1079. 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6 };
  1080. m_nHeadertoAddSize1 = sizeof(aIEEE802_3Header1);
  1081. memcpy(m_aHeadertoAdd1, aIEEE802_3Header1, m_nHeadertoAddSize1);
  1082. m_nHeadertoAddSize2 = sizeof(aIEEE802_3Header2);
  1083. memcpy(m_aHeadertoAdd2, aIEEE802_3Header2, m_nHeadertoAddSize2);
  1084. // The packet size is 22, therefore the bin size is 24
  1085. // We are going to add number of headers to occupy twice the size of the SRAM buffer
  1086. m_InitialHeadersNum = GetHdrSramSize() / 24 * 2;
  1087. }
  1088. virtual bool AddRules() {
  1089. m_eIP = IPA_IP_v4;
  1090. const char aBypass1[20] = "Bypass1";
  1091. const char aBypass2[20] = "Bypass2";
  1092. uint32_t nTableHdl01, nTableHdl02;
  1093. bool bRetVal = true;
  1094. IPAFilteringTable cFilterTable0;
  1095. struct ipa_flt_rule_add sFilterRuleEntry;
  1096. struct ipa_ioc_add_hdr *pHeaderDescriptor = NULL;
  1097. LOG_MSG_STACK("Entering Function");
  1098. if (m_InitialHeadersNum <= 0)
  1099. {
  1100. LOG_MSG_ERROR("Initial headers number is set to 0!\n");
  1101. bRetVal = false;
  1102. goto bail;
  1103. }
  1104. memset(&sFilterRuleEntry, 0, sizeof(sFilterRuleEntry));
  1105. memset(&m_RetHeader1, 0, sizeof(m_RetHeader1));
  1106. memset(&m_RetHeader2, 0, sizeof(m_RetHeader2));
  1107. pHeaderDescriptor = (struct ipa_ioc_add_hdr *) calloc(1,
  1108. sizeof(struct ipa_ioc_add_hdr) + 1 * sizeof(struct ipa_hdr_add));
  1109. if (!pHeaderDescriptor)
  1110. {
  1111. LOG_MSG_ERROR("calloc failed to allocate ipa_ioc_add_hdr");
  1112. bRetVal = false;
  1113. goto bail;
  1114. }
  1115. fflush(stderr);
  1116. fflush(stdout);
  1117. ret = system("cat /sys/kernel/debug/ipa/hdr");
  1118. // Add one header to SRAM
  1119. pHeaderDescriptor->commit = true;
  1120. pHeaderDescriptor->num_hdrs = 1;
  1121. pHeaderDescriptor->hdr[0].status = -1; // Return Parameter
  1122. pHeaderDescriptor->hdr[0].hdr_hdl = -1; //Return Value
  1123. pHeaderDescriptor->hdr[0].is_partial = false;
  1124. memcpy(pHeaderDescriptor->hdr[0].hdr, m_aHeadertoAdd1, m_nHeadertoAddSize1);
  1125. pHeaderDescriptor->hdr[0].hdr_len = m_nHeadertoAddSize1;
  1126. strlcpy(pHeaderDescriptor->hdr[0].name, "IEEE802_3_SRAM", sizeof(pHeaderDescriptor->hdr[0].name));
  1127. strlcpy(m_RetHeader1.name, pHeaderDescriptor->hdr[0].name, sizeof(m_RetHeader1.name));
  1128. if (!m_HeaderInsertion.AddHeader(pHeaderDescriptor))
  1129. {
  1130. LOG_MSG_ERROR("m_HeaderInsertion.AddHeader(pHeaderDescriptor) Failed\n");
  1131. bRetVal = false;
  1132. goto bail;
  1133. }
  1134. // Add bunch of headers to SRAM and DDR
  1135. for (int i = 1; i < m_InitialHeadersNum; i++)
  1136. {
  1137. LOG_MSG_DEBUG("%s::%s iter=%d\n", typeid(this).name(), __func__, i);
  1138. memcpy(pHeaderDescriptor->hdr[0].hdr, m_aHeadertoAdd2, m_nHeadertoAddSize2);
  1139. pHeaderDescriptor->hdr[0].hdr_len = m_nHeadertoAddSize2;
  1140. snprintf(pHeaderDescriptor->hdr[0].name, sizeof(pHeaderDescriptor->hdr[0].name),
  1141. "IEEE802_3_%03d", i);
  1142. if (!m_HeaderInsertion.AddHeader(pHeaderDescriptor))
  1143. {
  1144. LOG_MSG_ERROR("m_HeaderInsertion.AddHeader(pHeaderDescriptor) Failed on %d iteration.\n", i);
  1145. bRetVal = false;
  1146. goto bail;
  1147. }
  1148. }
  1149. strlcpy(m_RetHeader2.name, pHeaderDescriptor->hdr[0].name, sizeof(m_RetHeader2.name));
  1150. fflush(stderr);
  1151. fflush(stdout);
  1152. ret = system("cat /sys/kernel/debug/ipa/hdr");
  1153. if (!m_HeaderInsertion.GetHeaderHandle(&m_RetHeader1))
  1154. {
  1155. LOG_MSG_ERROR(" Failed");
  1156. bRetVal = false;
  1157. goto bail;
  1158. }
  1159. LOG_MSG_DEBUG("Received Header1 Handle = 0x%x", m_RetHeader1.hdl);
  1160. if (!m_HeaderInsertion.GetHeaderHandle(&m_RetHeader2))
  1161. {
  1162. LOG_MSG_ERROR(" Failed");
  1163. bRetVal = false;
  1164. goto bail;
  1165. }
  1166. LOG_MSG_DEBUG("Received Header2 Handle = 0x%x", m_RetHeader2.hdl);
  1167. if (!CreateBypassRoutingTable(&m_Routing, m_eIP, aBypass1, IPA_CLIENT_TEST3_CONS,
  1168. m_RetHeader1.hdl, &nTableHdl01)) {
  1169. LOG_MSG_ERROR("CreateBypassRoutingTable Failed\n");
  1170. bRetVal = false;
  1171. goto bail;
  1172. }
  1173. if (!CreateBypassRoutingTable(&m_Routing, m_eIP, aBypass2, IPA_CLIENT_TEST4_CONS,
  1174. m_RetHeader2.hdl, &nTableHdl02)) {
  1175. LOG_MSG_ERROR("CreateBypassRoutingTable Failed\n");
  1176. bRetVal = false;
  1177. goto bail;
  1178. }
  1179. LOG_MSG_INFO("Creation of two bypass routing tables completed successfully TblHdl1=0x%x, TblHdl2=0x%x",
  1180. nTableHdl01, nTableHdl02);
  1181. // Creating Filtering Rules
  1182. cFilterTable0.Init(m_eIP, IPA_CLIENT_TEST_PROD, false, 2);
  1183. LOG_MSG_INFO("Creation of filtering table completed successfully");
  1184. // Configuring common Filtering fields
  1185. cFilterTable0.GeneratePresetRule(1, sFilterRuleEntry);
  1186. sFilterRuleEntry.at_rear = true;
  1187. sFilterRuleEntry.rule.action = IPA_PASS_TO_ROUTING;
  1188. sFilterRuleEntry.rule.attrib.attrib_mask = IPA_FLT_DST_ADDR; // Destination IP Based Filtering
  1189. sFilterRuleEntry.rule.attrib.u.v4.dst_addr_mask = 0xFF0000FF; // Mask
  1190. // Configuring Filtering Rule No.1
  1191. sFilterRuleEntry.flt_rule_hdl = -1; // return Value
  1192. sFilterRuleEntry.status = -1; // return Value
  1193. sFilterRuleEntry.rule.rt_tbl_hdl = nTableHdl01; //put here the handle corresponding to Routing Rule 1
  1194. sFilterRuleEntry.rule.attrib.u.v4.dst_addr = 0xC0A80101; // Filter DST_IP == 192.168.1.1.
  1195. if ((uint8_t)-1 == cFilterTable0.AddRuleToTable(sFilterRuleEntry))
  1196. {
  1197. LOG_MSG_ERROR ("Adding Rule(1) to Filtering table Failed.");
  1198. bRetVal = false;
  1199. goto bail;
  1200. }
  1201. // Configuring Filtering Rule No.2
  1202. sFilterRuleEntry.flt_rule_hdl = -1; // return Value
  1203. sFilterRuleEntry.status = -1; // return value
  1204. sFilterRuleEntry.rule.rt_tbl_hdl = nTableHdl02; //put here the handle corresponding to Routing Rule 2
  1205. sFilterRuleEntry.rule.attrib.u.v4.dst_addr = 0xC0A80102; // Filter DST_IP == 192.168.1.2.
  1206. if ((uint8_t)-1 == cFilterTable0.AddRuleToTable(sFilterRuleEntry))
  1207. {
  1208. LOG_MSG_ERROR ("Adding Rule(2) to Filtering table Failed.");
  1209. bRetVal = false;
  1210. goto bail;
  1211. }
  1212. if (!m_Filtering.AddFilteringRule(cFilterTable0.GetFilteringTable())) {
  1213. LOG_MSG_ERROR ("Failed to commit Filtering rules");
  1214. bRetVal = false;
  1215. goto bail;
  1216. }
  1217. LOG_MSG_DEBUG("flt rule hdl0=0x%x, status=0x%x\n",
  1218. cFilterTable0.ReadRuleFromTable(0)->flt_rule_hdl,
  1219. cFilterTable0.ReadRuleFromTable(0)->status);
  1220. LOG_MSG_DEBUG("flt rule hdl0=0x%x, status=0x%x\n",
  1221. cFilterTable0.ReadRuleFromTable(1)->flt_rule_hdl,
  1222. cFilterTable0.ReadRuleFromTable(1)->status);
  1223. bail:
  1224. Free(pHeaderDescriptor);
  1225. LOG_MSG_STACK("Leaving Function (Returning %s)", bRetVal ? "True" : "False");
  1226. return bRetVal;
  1227. } // AddRules()
  1228. virtual bool ModifyPackets() {
  1229. // This test doesn't modify the original IP Packet.
  1230. return true;
  1231. } // ModifyPacktes ()
  1232. virtual bool TestLogic() {
  1233. bool bRetVal = true;
  1234. m_aExpectedBufSize = 0;
  1235. uint32_t nIPv4DSTAddr;
  1236. LOG_MSG_STACK("Entering Function");
  1237. //Packet No. 1
  1238. memset(m_aExpectedBuffer, 0, sizeof(m_aExpectedBuffer));
  1239. nIPv4DSTAddr = ntohl(0xC0A80101); //192.168.1.1
  1240. memcpy(&m_aBuffer[IPV4_DST_ADDR_OFFSET], &nIPv4DSTAddr, sizeof(nIPv4DSTAddr));
  1241. memcpy(m_aExpectedBuffer, m_aHeadertoAdd1, m_nHeadertoAddSize1);
  1242. memcpy(m_aExpectedBuffer+m_nHeadertoAddSize1,m_aBuffer,m_uBufferSize);
  1243. m_aExpectedBufSize = m_nHeadertoAddSize1 + m_uBufferSize;
  1244. if (!SendReceiveAndCompare(&m_producer, m_aBuffer, m_uBufferSize,
  1245. &m_Consumer2, m_aExpectedBuffer, m_aExpectedBufSize))
  1246. {
  1247. LOG_MSG_ERROR("SendReceiveAndCompare failed.");
  1248. bRetVal=false;
  1249. }
  1250. //Packet No. 2
  1251. memset(m_aExpectedBuffer, 0, sizeof(m_aExpectedBuffer));
  1252. nIPv4DSTAddr = ntohl(0xC0A80102); //192.168.1.2
  1253. memcpy (&m_aBuffer[IPV4_DST_ADDR_OFFSET], &nIPv4DSTAddr, sizeof(nIPv4DSTAddr));
  1254. memcpy(m_aExpectedBuffer, m_aHeadertoAdd2, m_nHeadertoAddSize2);
  1255. memcpy(m_aExpectedBuffer+m_nHeadertoAddSize2, m_aBuffer, m_uBufferSize);
  1256. m_aExpectedBufSize = m_nHeadertoAddSize2 + m_uBufferSize;
  1257. if (!SendReceiveAndCompare(&m_producer, m_aBuffer, m_uBufferSize,
  1258. &m_Consumer3, m_aExpectedBuffer, m_aExpectedBufSize))
  1259. {
  1260. LOG_MSG_ERROR("SendReceiveAndCompare failed.");
  1261. bRetVal=false;
  1262. }
  1263. LOG_MSG_STACK("Leaving Function (Returning %s)",bRetVal?"True":"False");
  1264. return bRetVal;
  1265. }
  1266. protected:
  1267. struct ipa_ioc_get_hdr m_RetHeader1, m_RetHeader2;
  1268. int m_InitialHeadersNum;
  1269. private:
  1270. uint8_t m_aExpectedBuffer[BUFF_MAX_SIZE]; // Input file / IP packet
  1271. size_t m_aExpectedBufSize;
  1272. uint8_t m_aHeadertoAdd1[MAX_HEADER_SIZE], m_aHeadertoAdd2[MAX_HEADER_SIZE];
  1273. size_t m_nHeadertoAddSize1, m_nHeadertoAddSize2;
  1274. int ret;
  1275. };
  1276. static IPAHeaderInsertionTest001 ipaHeaderInsertionTest001;
  1277. static IPAHeaderInsertionTest002 ipaHeaderInsertionTest002;
  1278. static IPAHeaderInsertionTest003 ipaHeaderInsertionTest003;
  1279. static IPAHeaderInsertionTest004 ipaHeaderInsertionTest004;
  1280. static IPAHeaderInsertionTest005 ipaHeaderInsertionTest005;
  1281. static IPAHeaderInsertionTest006 ipaHeaderInsertionTest006;
  1282. static IPAHeaderInsertionTest007 ipaHeaderInsertionTest007;
  1283. static IPAHeaderInsertionTest008 ipaHeaderInsertionTest008;
  1284. static IPAHeaderInsertionTest009 ipaHeaderInsertionTest009;
  1285. static IPAHeaderInsertionTest010 ipaHeaderInsertionTest010;