IPv6CTTest.cpp 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781
  1. /*
  2. * Copyright (c) 2018 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 <stdio.h>
  30. #include <stdlib.h>
  31. #include <unistd.h>
  32. #include <string.h>
  33. #include <stdint.h>
  34. #include <cstring> // for memcpy
  35. #include "hton.h" // for htonl
  36. #include "InterfaceAbstraction.h"
  37. #include "Constants.h"
  38. #include "Logger.h"
  39. #include "TestsUtils.h"
  40. #include "Filtering.h"
  41. #include "RoutingDriverWrapper.h"
  42. #include "IPAFilteringTable.h"
  43. extern "C" {
  44. #include "ipa_ipv6ct.h"
  45. }
  46. #define IPV6_SRC_PORT_OFFSET (40)
  47. #define IPV6_SRC_ADDRESS_MSB_OFFSET (8)
  48. #define IPV6_SRC_ADDRESS_LSB_OFFSET (16)
  49. #define IPV6_DST_ADDRESS_MSB_OFFSET (24)
  50. #define IPV6_DST_ADDRESS_LSB_OFFSET (32)
  51. #define IPV6_DST_PORT_OFFSET (40+2)
  52. #define IPV6_LOW_32_MASK (0xFFFFFFFF)
  53. #define IPV6_HIGH_32_MASK (0xFFFFFFFF00000000)
  54. #define IPV6_BITS_IN_BYTE 8
  55. inline uint32_t GetHigh32(uint64_t in)
  56. {
  57. return static_cast<uint32_t>((in & IPV6_HIGH_32_MASK) >> 32);
  58. }
  59. inline uint32_t GetLow32(uint64_t in)
  60. {
  61. return static_cast<uint32_t>(in & IPV6_LOW_32_MASK);
  62. }
  63. template <typename T>
  64. T HostToNetwork(T in)
  65. {
  66. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  67. if (1 == htons(1))
  68. {
  69. return in;
  70. }
  71. static const T mask = 0xff;
  72. T ret;
  73. uint8_t* p = reinterpret_cast<uint8_t*>(&ret + 1);
  74. while (in)
  75. {
  76. *--p = static_cast<uint8_t>(in & mask);
  77. in >>= IPV6_BITS_IN_BYTE;
  78. }
  79. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  80. return ret;
  81. }
  82. extern Logger g_Logger;
  83. class IpaIPv6CTBlockTestFixture : public TestBase
  84. {
  85. public:
  86. IpaIPv6CTBlockTestFixture() :
  87. m_sendSize(BUFF_MAX_SIZE),
  88. m_sendSize2(BUFF_MAX_SIZE),
  89. m_sendSize3(BUFF_MAX_SIZE),
  90. m_outbound_dst_addr_msb(0XFF02000000000000),
  91. m_outbound_dst_addr_lsb(0x11223344556677AA),
  92. m_outbound_dst_port(1000),
  93. m_outbound_src_addr_msb(m_outbound_dst_addr_msb),
  94. m_outbound_src_addr_lsb(0x11223344556677CC),
  95. m_outbound_src_port(1001),
  96. m_direction_settings(IPA_IPV6CT_DIRECTION_ALLOW_ALL),
  97. m_tableHandle(0)
  98. {
  99. memset(m_sendBuffer, 0, sizeof(m_sendBuffer)); // First input file / IP packet
  100. memset(m_sendBuffer2, 0, sizeof(m_sendBuffer2)); // Second input file / IP packet
  101. memset(m_sendBuffer3, 0, sizeof(m_sendBuffer3)); // Third input file (default) / IP packet
  102. m_minIPAHwType = IPA_HW_v4_0;
  103. m_testSuiteName.push_back("IPv6CT");
  104. }
  105. static int SetupKernelModule(bool en_status = false)
  106. {
  107. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  108. int retval;
  109. struct ipa_channel_config from_ipa_channels[3];
  110. struct test_ipa_ep_cfg from_ipa_cfg[3];
  111. struct ipa_channel_config to_ipa_channels[1];
  112. struct test_ipa_ep_cfg to_ipa_cfg[1];
  113. struct ipa_test_config_header header = { 0 };
  114. struct ipa_channel_config *to_ipa_array[1];
  115. struct ipa_channel_config *from_ipa_array[3];
  116. /* From ipa configurations - 3 pipes */
  117. memset(&from_ipa_cfg[0], 0, sizeof(from_ipa_cfg[0]));
  118. prepare_channel_struct(&from_ipa_channels[0],
  119. header.from_ipa_channels_num++,
  120. IPA_CLIENT_TEST2_CONS,
  121. (void *)&from_ipa_cfg[0],
  122. sizeof(from_ipa_cfg[0]),
  123. en_status);
  124. from_ipa_array[0] = &from_ipa_channels[0];
  125. memset(&from_ipa_cfg[1], 0, sizeof(from_ipa_cfg[1]));
  126. prepare_channel_struct(&from_ipa_channels[1],
  127. header.from_ipa_channels_num++,
  128. IPA_CLIENT_TEST3_CONS,
  129. (void *)&from_ipa_cfg[1],
  130. sizeof(from_ipa_cfg[1]),
  131. en_status);
  132. from_ipa_array[1] = &from_ipa_channels[1];
  133. memset(&from_ipa_cfg[2], 0, sizeof(from_ipa_cfg[2]));
  134. prepare_channel_struct(&from_ipa_channels[2],
  135. header.from_ipa_channels_num++,
  136. IPA_CLIENT_TEST4_CONS,
  137. (void *)&from_ipa_cfg[2],
  138. sizeof(from_ipa_cfg[2]),
  139. en_status);
  140. from_ipa_array[2] = &from_ipa_channels[2];
  141. /* To ipa configurations - 1 pipes */
  142. memset(&to_ipa_cfg[0], 0, sizeof(to_ipa_cfg[0]));
  143. prepare_channel_struct(&to_ipa_channels[0],
  144. header.to_ipa_channels_num++,
  145. IPA_CLIENT_TEST_PROD,
  146. (void *)&to_ipa_cfg[0],
  147. sizeof(to_ipa_cfg[0]));
  148. to_ipa_array[0] = &to_ipa_channels[0];
  149. prepare_header_struct(&header, from_ipa_array, to_ipa_array);
  150. retval = GenericConfigureScenario(&header);
  151. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  152. return retval;
  153. }
  154. bool Setup()
  155. {
  156. bool bRetVal = true;
  157. if (SetupKernelModule() != true)
  158. return bRetVal;
  159. m_producer.Open(INTERFACE0_TO_IPA_DATA_PATH, INTERFACE0_FROM_IPA_DATA_PATH);
  160. m_consumer.Open(INTERFACE1_TO_IPA_DATA_PATH, INTERFACE1_FROM_IPA_DATA_PATH);
  161. m_consumer2.Open(INTERFACE2_TO_IPA_DATA_PATH, INTERFACE2_FROM_IPA_DATA_PATH);
  162. m_defaultConsumer.Open(INTERFACE3_TO_IPA_DATA_PATH, INTERFACE3_FROM_IPA_DATA_PATH);
  163. if (!m_routing.DeviceNodeIsOpened())
  164. {
  165. printf("Routing block is not ready for immediate commands!\n");
  166. return false;
  167. }
  168. if (!m_filtering.DeviceNodeIsOpened())
  169. {
  170. printf("Filtering block is not ready for immediate commands!\n");
  171. return false;
  172. }
  173. m_routing.Reset(IPA_IP_v4); // This will issue a Reset command to the Filtering as well
  174. m_routing.Reset(IPA_IP_v6); // This will issue a Reset command to the Filtering as well
  175. return true;
  176. } // Setup()
  177. bool Teardown()
  178. {
  179. ipa_ipv6ct_dump_table(m_tableHandle);
  180. ipa_ipv6ct_del_tbl(m_tableHandle);
  181. m_producer.Close();
  182. m_consumer.Close();
  183. m_consumer2.Close();
  184. m_defaultConsumer.Close();
  185. return true;
  186. } // Teardown()
  187. bool LoadFiles()
  188. {
  189. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  190. if (!LoadDefaultPacket(IPA_IP_v6, m_extHdrType, m_sendBuffer, m_sendSize))
  191. {
  192. LOG_MSG_ERROR("Failed default Packet\n");
  193. return false;
  194. }
  195. printf("Loaded %zu Bytes to Buffer 1\n", m_sendSize);
  196. if (!LoadDefaultPacket(IPA_IP_v6, m_extHdrType, m_sendBuffer2, m_sendSize2))
  197. {
  198. LOG_MSG_ERROR("Failed default Packet\n");
  199. return false;
  200. }
  201. printf("Loaded %zu Bytes to Buffer 2\n", m_sendSize2);
  202. if (!LoadDefaultPacket(IPA_IP_v6, m_extHdrType, m_sendBuffer3, m_sendSize3))
  203. {
  204. LOG_MSG_ERROR("Failed default Packet\n");
  205. return false;
  206. }
  207. printf("Loaded %zu Bytes to Buffer 3\n", m_sendSize3);
  208. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  209. return true;
  210. }
  211. // This function creates three IPv6 bypass routing entries and commits them.
  212. bool CreateThreeIPv6BypassRoutingTables(const char * bypass0, const char * bypass1, const char * bypass2)
  213. {
  214. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  215. struct ipa_ioc_add_rt_rule *rt_rule0 = 0, *rt_rule1 = 0, *rt_rule2 = 0;
  216. struct ipa_rt_rule_add *rt_rule_entry;
  217. rt_rule0 = (struct ipa_ioc_add_rt_rule *)
  218. calloc(1,
  219. sizeof(struct ipa_ioc_add_rt_rule) +
  220. 1 * sizeof(struct ipa_rt_rule_add)
  221. );
  222. if (!rt_rule0) {
  223. printf("calloc failed to allocate rt_rule0 in %s\n", __FUNCTION__);
  224. return false;
  225. }
  226. rt_rule1 = (struct ipa_ioc_add_rt_rule *)
  227. calloc(1,
  228. sizeof(struct ipa_ioc_add_rt_rule) +
  229. 1 * sizeof(struct ipa_rt_rule_add)
  230. );
  231. if (!rt_rule1) {
  232. printf("calloc failed to allocate rt_rule1 in %s\n", __FUNCTION__);
  233. Free(rt_rule0);
  234. return false;
  235. }
  236. rt_rule2 = (struct ipa_ioc_add_rt_rule *)
  237. calloc(1,
  238. sizeof(struct ipa_ioc_add_rt_rule) +
  239. 1 * sizeof(struct ipa_rt_rule_add)
  240. );
  241. if (!rt_rule2) {
  242. printf("calloc failed to allocate rt_rule2 in %s\n", __FUNCTION__);
  243. Free(rt_rule0);
  244. Free(rt_rule1);
  245. return false;
  246. }
  247. rt_rule0->num_rules = 1;
  248. rt_rule0->ip = IPA_IP_v6;
  249. rt_rule0->commit = true;
  250. strlcpy(rt_rule0->rt_tbl_name, bypass0, sizeof(rt_rule0->rt_tbl_name));
  251. rt_rule_entry = &rt_rule0->rules[0];
  252. rt_rule_entry->at_rear = false;
  253. rt_rule_entry->rule.dst = IPA_CLIENT_TEST2_CONS;
  254. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  255. rt_rule_entry->rule.attrib.u.v6.dst_addr[0] = 0xaabbccdd;
  256. rt_rule_entry->rule.attrib.u.v6.dst_addr[1] = 0xeeff0011;
  257. rt_rule_entry->rule.attrib.u.v6.dst_addr[2] = 0x22334455;
  258. rt_rule_entry->rule.attrib.u.v6.dst_addr[3] = 0x66778899;
  259. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[0] = 0x00000000;// All Packets will get a "Hit"
  260. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[1] = 0x00000000;
  261. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[2] = 0x00000000;
  262. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[3] = 0x00000000;
  263. if (false == m_routing.AddRoutingRule(rt_rule0))
  264. {
  265. printf("Routing rule addition(rt_rule0) failed!\n");
  266. Free(rt_rule2);
  267. Free(rt_rule1);
  268. Free(rt_rule0);
  269. return false;
  270. }
  271. rt_rule1->num_rules = 1;
  272. rt_rule1->ip = IPA_IP_v6;
  273. rt_rule1->commit = true;
  274. strlcpy(rt_rule1->rt_tbl_name, bypass1, sizeof(rt_rule1->rt_tbl_name));
  275. rt_rule_entry = &rt_rule1->rules[0];
  276. rt_rule_entry->at_rear = false;
  277. rt_rule_entry->rule.dst = IPA_CLIENT_TEST3_CONS;
  278. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  279. rt_rule_entry->rule.attrib.u.v6.dst_addr[0] = 0xaabbccdd;
  280. rt_rule_entry->rule.attrib.u.v6.dst_addr[1] = 0xeeff0011;
  281. rt_rule_entry->rule.attrib.u.v6.dst_addr[2] = 0x22334455;
  282. rt_rule_entry->rule.attrib.u.v6.dst_addr[3] = 0x66778899;
  283. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[0] = 0x00000000;// All Packets will get a "Hit"
  284. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[1] = 0x00000000;
  285. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[2] = 0x00000000;
  286. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[3] = 0x00000000;
  287. if (false == m_routing.AddRoutingRule(rt_rule1))
  288. {
  289. printf("Routing rule addition(rt_rule1) failed!\n");
  290. Free(rt_rule2);
  291. Free(rt_rule1);
  292. Free(rt_rule0);
  293. return false;
  294. }
  295. rt_rule2->num_rules = 1;
  296. rt_rule2->ip = IPA_IP_v6;
  297. rt_rule2->commit = true;
  298. strlcpy(rt_rule2->rt_tbl_name, bypass2, sizeof(rt_rule2->rt_tbl_name));
  299. rt_rule_entry = &rt_rule2->rules[0];
  300. rt_rule_entry->at_rear = false;
  301. rt_rule_entry->rule.dst = IPA_CLIENT_TEST4_CONS;
  302. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  303. rt_rule_entry->rule.attrib.u.v6.dst_addr[0] = 0xaabbccdd;
  304. rt_rule_entry->rule.attrib.u.v6.dst_addr[1] = 0xeeff0011;
  305. rt_rule_entry->rule.attrib.u.v6.dst_addr[2] = 0x22334455;
  306. rt_rule_entry->rule.attrib.u.v6.dst_addr[3] = 0x66778899;
  307. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[0] = 0x00000000;// All Packets will get a "Hit"
  308. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[1] = 0x00000000;
  309. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[2] = 0x00000000;
  310. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[3] = 0x00000000;
  311. if (false == m_routing.AddRoutingRule(rt_rule2))
  312. {
  313. printf("Routing rule addition(rt_rule2) failed!\n");
  314. Free(rt_rule2);
  315. Free(rt_rule1);
  316. Free(rt_rule0);
  317. return false;
  318. }
  319. Free(rt_rule2);
  320. Free(rt_rule1);
  321. Free(rt_rule0);
  322. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  323. return true;
  324. }
  325. bool GetThreeIPv6BypassRoutingTables(uint32_t *Hndl0, uint32_t *Hndl1, uint32_t *Hndl2)
  326. {
  327. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  328. const char bypass0[20] = "Bypass0";
  329. const char bypass1[20] = "Bypass1";
  330. const char bypass2[20] = "Bypass2";
  331. struct ipa_ioc_get_rt_tbl routing_table0, routing_table1, routing_table2;
  332. if (!CreateThreeIPv6BypassRoutingTables(bypass0, bypass1, bypass2))
  333. {
  334. printf("CreateThreeBypassRoutingTables Failed\n");
  335. return false;
  336. }
  337. printf("CreateThreeBypassRoutingTables completed successfully\n");
  338. routing_table0.ip = IPA_IP_v6;
  339. strlcpy(routing_table0.name, bypass0, sizeof(routing_table0.name));
  340. if (!m_routing.GetRoutingTable(&routing_table0))
  341. {
  342. printf("m_routing.GetRoutingTable(&routing_table0=0x%pK) Failed.\n", &routing_table0);
  343. return false;
  344. }
  345. routing_table1.ip = IPA_IP_v6;
  346. strlcpy(routing_table1.name, bypass1, sizeof(routing_table1.name));
  347. if (!m_routing.GetRoutingTable(&routing_table1))
  348. {
  349. printf("m_routing.GetRoutingTable(&routing_table1=0x%pK) Failed.\n", &routing_table1);
  350. return false;
  351. }
  352. routing_table2.ip = IPA_IP_v6;
  353. strlcpy(routing_table2.name, bypass2, sizeof(routing_table2.name));
  354. if (!m_routing.GetRoutingTable(&routing_table2))
  355. {
  356. printf("m_routing.GetRoutingTable(&routing_table2=0x%pK) Failed.\n", &routing_table2);
  357. return false;
  358. }
  359. *Hndl0 = routing_table0.hdl;
  360. *Hndl1 = routing_table1.hdl;
  361. *Hndl2 = routing_table2.hdl;
  362. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  363. return true;
  364. }
  365. bool AddIpv6ctTable()
  366. {
  367. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  368. const int total_entries = 20;
  369. int result = ipa_ipv6ct_add_tbl(total_entries, &m_tableHandle);
  370. if (result)
  371. {
  372. printf("Leaving %s, %s(), failed creating IPvC6T table with result %d\n", __FUNCTION__, __FILE__, result);
  373. return false;
  374. }
  375. printf("IPv6CT table added, hdl %d\n", m_tableHandle);
  376. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  377. return true;
  378. }
  379. bool AddIpv6ctRule(ipa_ipv6ct_rule& rule, uint32_t& rule_hdl) const
  380. {
  381. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  382. int result = ipa_ipv6ct_add_rule(m_tableHandle, &rule, &rule_hdl);
  383. if (result)
  384. {
  385. printf("Leaving %s, %s(), failed creating IPvC6T rule with result %d\n", __FUNCTION__, __FILE__, result);
  386. return false;
  387. }
  388. printf("IPv6CT rule added:\ndest lsb %llX, dest msb %llX, dest port %d\ndir %d, proto %d\nsrc lsb 0x%llX, src msb 0x%llX, src port %d\n",
  389. (long long unsigned int)rule.dest_ipv6_lsb, (long long unsigned int)rule.dest_ipv6_msb,
  390. rule.dest_port, rule.direction_settings,
  391. rule.protocol, (long long unsigned int)rule.src_ipv6_lsb, (long long unsigned int)rule.src_ipv6_msb,
  392. rule.src_port);
  393. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  394. return true;
  395. }
  396. void InitIpv6ctRule(ipa_ipv6ct_rule& rule, uint64_t change_bit) const
  397. {
  398. rule.dest_ipv6_lsb = m_outbound_dst_addr_lsb ^ change_bit;
  399. rule.dest_ipv6_msb = m_outbound_dst_addr_msb;
  400. rule.dest_port = m_outbound_dst_port;
  401. rule.direction_settings = m_direction_settings;
  402. rule.protocol = IPPROTO_TCP;
  403. rule.src_ipv6_lsb = m_outbound_src_addr_lsb ^ change_bit;
  404. rule.src_ipv6_msb = m_outbound_src_addr_msb;
  405. rule.src_port = m_outbound_src_port;
  406. }
  407. virtual bool AddIpv6ctRules()
  408. {
  409. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  410. ipa_ipv6ct_rule rule;
  411. InitIpv6ctRule(rule, 0);
  412. uint32_t rule_hdl;
  413. bool result = AddIpv6ctRule(rule, rule_hdl);
  414. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  415. return result;
  416. }
  417. virtual bool ModifyPackets() = 0;
  418. virtual bool AddRoutingFilteringRules() = 0;
  419. virtual bool ReceivePacketsAndCompare() = 0;
  420. bool Run()
  421. {
  422. bool res = false;
  423. bool isSuccess = false;
  424. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  425. res = AddRoutingFilteringRules();
  426. if (false == res) {
  427. printf("Failed adding routing and filtering rules.\n");
  428. return false;
  429. }
  430. res = AddIpv6ctTable();
  431. if (false == res)
  432. {
  433. printf("Failed adding IPv6 connection tracking table.\n");
  434. return false;
  435. }
  436. res = AddIpv6ctRules();
  437. if (false == res)
  438. {
  439. printf("Failed adding IPv6 connection tracking rules.\n");
  440. return false;
  441. }
  442. res = LoadFiles();
  443. if (false == res) {
  444. printf("Failed loading files.\n");
  445. return false;
  446. }
  447. res = ModifyPackets();
  448. if (false == res) {
  449. printf("Failed to modify packets.\n");
  450. return false;
  451. }
  452. // Send first packet
  453. isSuccess = m_producer.SendData(m_sendBuffer, m_sendSize);
  454. if (false == isSuccess)
  455. {
  456. printf("SendData failure.\n");
  457. return false;
  458. }
  459. // Receive packets from the channels and compare results
  460. isSuccess = ReceivePacketsAndCompare();
  461. printf("Leaving %s, %s(), Returning %d\n", __FUNCTION__, __FILE__, isSuccess);
  462. return isSuccess;
  463. } // Run()
  464. void ModifyPackets(uint64_t dstAddrLsb, uint64_t dstAddrMsb, uint16_t dstPort,
  465. uint64_t srcAddrLsb, uint64_t srcAddrMsb, uint16_t srcPort)
  466. {
  467. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  468. // destination
  469. uint64_t address = HostToNetwork(dstAddrLsb);
  470. memcpy(&m_sendBuffer[IPV6_DST_ADDRESS_LSB_OFFSET], &address, sizeof(address));
  471. address = HostToNetwork(dstAddrMsb);
  472. memcpy(&m_sendBuffer[IPV6_DST_ADDRESS_MSB_OFFSET], &address, sizeof(address));
  473. uint16_t port = ntohs(dstPort);
  474. memcpy(&m_sendBuffer[IPV6_DST_PORT_OFFSET], &port, sizeof(port));
  475. // source
  476. address = HostToNetwork(srcAddrLsb);
  477. memcpy(&m_sendBuffer[IPV6_SRC_ADDRESS_LSB_OFFSET], &address, sizeof(address));
  478. address = HostToNetwork(srcAddrMsb);
  479. memcpy(&m_sendBuffer[IPV6_SRC_ADDRESS_MSB_OFFSET], &address, sizeof(address));
  480. port = ntohs(srcPort);
  481. memcpy(&m_sendBuffer[IPV6_SRC_PORT_OFFSET], &port, sizeof(port));
  482. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  483. }// ModifyPacktes ()
  484. virtual bool AddRoutingFilteringRules(enum ipa_flt_action flt_action, uint64_t dst_addr_msb, uint64_t dst_addr_lsb)
  485. {
  486. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  487. const char bypass0[20] = "Bypass0";
  488. const char bypass1[20] = "Bypass1";
  489. const char bypass2[20] = "Bypass2";
  490. if (!CreateThreeIPv6BypassRoutingTables(bypass0, bypass1, bypass2))
  491. {
  492. printf("CreateThreeBypassRoutingTables Failed\n");
  493. return false;
  494. }
  495. printf("CreateThreeBypassRoutingTables completed successfully\n");
  496. ipa_ioc_get_rt_tbl routing_table0;
  497. routing_table0.ip = IPA_IP_v6;
  498. strlcpy(routing_table0.name, bypass0, sizeof(routing_table0.name));
  499. if (!m_routing.GetRoutingTable(&routing_table0))
  500. {
  501. printf("m_routing.GetRoutingTable(&routing_table0=0x%pK) Failed.\n", &routing_table0);
  502. return false;
  503. }
  504. ipa_ioc_get_rt_tbl routing_table1;
  505. routing_table1.ip = IPA_IP_v6;
  506. strlcpy(routing_table1.name, bypass1, sizeof(routing_table1.name));
  507. if (!m_routing.GetRoutingTable(&routing_table1))
  508. {
  509. printf("m_routing.GetRoutingTable(&routing_table1=0x%pK) Failed.\n", &routing_table1);
  510. return false;
  511. }
  512. IPAFilteringTable FilterTable0;
  513. ipa_flt_rule_add flt_rule_entry;
  514. FilterTable0.Init(IPA_IP_v6, IPA_CLIENT_TEST_PROD, false, 1);
  515. // Configuring Filtering Rule No.0
  516. FilterTable0.GeneratePresetRule(1, flt_rule_entry);
  517. flt_rule_entry.at_rear = true;
  518. flt_rule_entry.flt_rule_hdl = -1; // return Value
  519. flt_rule_entry.status = -1; // return value
  520. flt_rule_entry.rule.action = flt_action;
  521. flt_rule_entry.rule.rt_tbl_hdl = routing_table0.hdl; //put here the handle corresponding to Routing Rule 1
  522. flt_rule_entry.rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  523. flt_rule_entry.rule.attrib.u.v6.dst_addr_mask[0] = 0xFFFFFFFF;// Exact Match
  524. flt_rule_entry.rule.attrib.u.v6.dst_addr_mask[1] = 0xFFFFFFFF;// Exact Match
  525. flt_rule_entry.rule.attrib.u.v6.dst_addr_mask[2] = 0xFFFFFFFF;// Exact Match
  526. flt_rule_entry.rule.attrib.u.v6.dst_addr_mask[3] = 0xFFFFFFFF;// Exact Match
  527. flt_rule_entry.rule.attrib.u.v6.dst_addr[0] = GetHigh32(dst_addr_msb); // Filter DST_IP
  528. flt_rule_entry.rule.attrib.u.v6.dst_addr[1] = GetLow32(dst_addr_msb);
  529. flt_rule_entry.rule.attrib.u.v6.dst_addr[2] = GetHigh32(dst_addr_lsb);
  530. flt_rule_entry.rule.attrib.u.v6.dst_addr[3] = GetLow32(dst_addr_lsb);
  531. printf("flt_rule_entry was set successfully, preparing for insertion....\n");
  532. if (((uint8_t)-1 == FilterTable0.AddRuleToTable(flt_rule_entry)) ||
  533. !m_filtering.AddFilteringRule(FilterTable0.GetFilteringTable()))
  534. {
  535. printf("%s::Error Adding Rule to Filter Table, aborting...\n", __FUNCTION__);
  536. return false;
  537. }
  538. else
  539. {
  540. printf("flt rule hdl0=0x%x, status=0x%x\n",
  541. FilterTable0.ReadRuleFromTable(0)->flt_rule_hdl, FilterTable0.ReadRuleFromTable(0)->status);
  542. }
  543. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  544. return true;
  545. }// AddRoutingFilteringRules()
  546. virtual bool ReceivePacketsAndCompare(bool packetPassExpected)
  547. {
  548. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  549. // Receive results
  550. Byte rxBuff1[0x400];
  551. size_t receivedSize = m_consumer.ReceiveData(rxBuff1, 0x400);
  552. printf("Received %zu bytes on %s.\n", receivedSize, m_consumer.m_fromChannelName.c_str());
  553. bool isSuccess = true;
  554. if (packetPassExpected)
  555. {
  556. // Compare results
  557. if (!CompareResultVsGolden(m_sendBuffer, m_sendSize, rxBuff1, receivedSize))
  558. {
  559. printf("Comparison of Buffer0 Failed!\n");
  560. isSuccess = false;
  561. }
  562. }
  563. else
  564. {
  565. if (receivedSize)
  566. {
  567. isSuccess = false;
  568. printf("got data while expected packet to be blocked, failing\n");
  569. }
  570. }
  571. char recievedBuffer[256] = {0};
  572. char SentBuffer[256] = {0};
  573. size_t j;
  574. for (j = 0; j < m_sendSize; j++)
  575. {
  576. snprintf(&SentBuffer[3 * j], sizeof(SentBuffer)-(3 * j + 1), " %02X", m_sendBuffer[j]);
  577. }
  578. for (j = 0; j < receivedSize; j++)
  579. {
  580. snprintf(&recievedBuffer[3 * j], sizeof(recievedBuffer)-(3 * j + 1), " %02X", rxBuff1[j]);
  581. }
  582. printf("Expected Value1 (%zu)\n%s\n, Received Value1(%zu)\n%s\n",
  583. m_sendSize, SentBuffer, receivedSize, recievedBuffer);
  584. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  585. return isSuccess;
  586. }
  587. protected:
  588. static Filtering m_filtering;
  589. static RoutingDriverWrapper m_routing;
  590. InterfaceAbstraction m_producer;
  591. InterfaceAbstraction m_consumer;
  592. InterfaceAbstraction m_consumer2;
  593. InterfaceAbstraction m_defaultConsumer;
  594. static const size_t BUFF_MAX_SIZE = 1024;
  595. Byte m_sendBuffer[BUFF_MAX_SIZE]; // First input file / IP packet
  596. Byte m_sendBuffer2[BUFF_MAX_SIZE]; // Second input file / IP packet
  597. Byte m_sendBuffer3[BUFF_MAX_SIZE]; // Third input file (default) / IP packet
  598. size_t m_sendSize;
  599. size_t m_sendSize2;
  600. size_t m_sendSize3;
  601. static const ipv6_ext_hdr_type m_extHdrType = NONE;
  602. uint64_t m_outbound_dst_addr_msb;
  603. uint64_t m_outbound_dst_addr_lsb;
  604. uint16_t m_outbound_dst_port;
  605. uint64_t m_outbound_src_addr_msb;
  606. uint64_t m_outbound_src_addr_lsb;
  607. uint16_t m_outbound_src_port;
  608. ipa_ipv6_ct_direction_settings_type m_direction_settings;
  609. uint32_t m_tableHandle;
  610. };
  611. RoutingDriverWrapper IpaIPv6CTBlockTestFixture::m_routing;
  612. Filtering IpaIPv6CTBlockTestFixture::m_filtering;
  613. /*---------------------------------------------------------------------------------------------*/
  614. /* Test001: IPv6CT send outbound packet */
  615. /*---------------------------------------------------------------------------------------------*/
  616. class IpaIPV6CTBlockTest001 : public IpaIPv6CTBlockTestFixture
  617. {
  618. public:
  619. IpaIPV6CTBlockTest001()
  620. {
  621. m_name = "IpaIPV6CTBlockTest001";
  622. m_description =
  623. "IPv6CT block test 001 - IPv6CT passes successfully one packet in outbound direction\n"
  624. "1. Generate and commit three routing tables.\n"
  625. " Each table contains a single \"bypass\" rule (all data goes to output pipe 0, 1 and 2 (accordingly))\n"
  626. "2. Generate and commit one outbound filtering rule: Destination IP Exactly Match.\n"
  627. "3. Add IPv6CT rule for the packet\n";
  628. Register(*this);
  629. }
  630. virtual bool AddRoutingFilteringRules()
  631. {
  632. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  633. bool result = IpaIPv6CTBlockTestFixture::AddRoutingFilteringRules(IPA_PASS_TO_SRC_NAT,
  634. m_outbound_dst_addr_msb, m_outbound_dst_addr_lsb);
  635. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  636. return result;
  637. }// AddRoutingFilteringRules()
  638. virtual bool ModifyPackets()
  639. {
  640. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  641. IpaIPv6CTBlockTestFixture::ModifyPackets(m_outbound_dst_addr_lsb, m_outbound_dst_addr_msb, m_outbound_dst_port,
  642. m_outbound_src_addr_lsb, m_outbound_src_addr_msb, m_outbound_src_port);
  643. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  644. return true;
  645. }// ModifyPackets()
  646. virtual bool ReceivePacketsAndCompare()
  647. {
  648. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  649. bool result = IpaIPv6CTBlockTestFixture::ReceivePacketsAndCompare(true);
  650. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  651. return result;
  652. }
  653. };
  654. /*---------------------------------------------------------------------------------------------*/
  655. /* Test002: IPv6CT send inbound packet */
  656. /*---------------------------------------------------------------------------------------------*/
  657. class IpaIPV6CTBlockTest002 : public IpaIPv6CTBlockTestFixture
  658. {
  659. public:
  660. IpaIPV6CTBlockTest002()
  661. {
  662. m_name = "IpaIPV6CTBlockTest002";
  663. m_description =
  664. "IPv6CT block test 002 - IPv6CT passes successfully one packet in inbound direction\n"
  665. "1. Generate and commit three routing tables.\n"
  666. " Each table contains a single \"bypass\" rule (all data goes to output pipe 0, 1 and 2 (accordingly))\n"
  667. "2. Generate and commit one inbound filtering rule: Destination IP Exactly Match.\n"
  668. "3. Add IPv6CT rule for the packet\n";
  669. Register(*this);
  670. }
  671. virtual bool AddRoutingFilteringRules()
  672. {
  673. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  674. bool result = IpaIPv6CTBlockTestFixture::AddRoutingFilteringRules(IPA_PASS_TO_DST_NAT,
  675. m_outbound_src_addr_msb, m_outbound_src_addr_lsb);
  676. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  677. return result;
  678. }// AddRoutingFilteringRules()
  679. virtual bool ModifyPackets()
  680. {
  681. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  682. IpaIPv6CTBlockTestFixture::ModifyPackets(m_outbound_src_addr_lsb, m_outbound_src_addr_msb, m_outbound_src_port,
  683. m_outbound_dst_addr_lsb, m_outbound_dst_addr_msb, m_outbound_dst_port);
  684. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  685. return true;
  686. }// ModifyPackets()
  687. virtual bool ReceivePacketsAndCompare()
  688. {
  689. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  690. bool result = IpaIPv6CTBlockTestFixture::ReceivePacketsAndCompare(true);
  691. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  692. return result;
  693. }
  694. };
  695. /*---------------------------------------------------------------------------------------------*/
  696. /* Test003: IPv6CT send outbound packet - without IPV6CT rule */
  697. /*---------------------------------------------------------------------------------------------*/
  698. class IpaIPV6CTBlockTest003 : public IpaIPv6CTBlockTestFixture
  699. {
  700. public:
  701. IpaIPV6CTBlockTest003()
  702. {
  703. m_name = "IpaIPV6CTBlockTest003";
  704. m_description =
  705. "IPv6CT block test 003 - IPv6CT blocks one packet in outbound direction due to rule absence\n"
  706. "1. Generate and commit three routing tables.\n"
  707. " Each table contains a single \"bypass\" rule (all data goes to output pipe 0, 1 and 2 (accordingly))\n"
  708. "2. Generate and commit one outbound filtering rule: Destination IP Exactly Match.\n";
  709. Register(*this);
  710. }
  711. virtual bool AddIpv6ctRules()
  712. {
  713. printf("not adding IPv6CT rule for packet - blocking expected %s %s\n", __FUNCTION__, __FILE__);
  714. return true;
  715. }
  716. virtual bool AddRoutingFilteringRules()
  717. {
  718. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  719. bool result = IpaIPv6CTBlockTestFixture::AddRoutingFilteringRules(IPA_PASS_TO_SRC_NAT,
  720. m_outbound_dst_addr_msb, m_outbound_dst_addr_lsb);
  721. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  722. return result;
  723. }// AddRoutingFilteringRules()
  724. virtual bool ModifyPackets()
  725. {
  726. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  727. IpaIPv6CTBlockTestFixture::ModifyPackets(m_outbound_dst_addr_lsb, m_outbound_dst_addr_msb, m_outbound_dst_port,
  728. m_outbound_src_addr_lsb, m_outbound_src_addr_msb, m_outbound_src_port);
  729. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  730. return true;
  731. }// ModifyPackets()
  732. virtual bool ReceivePacketsAndCompare()
  733. {
  734. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  735. bool result = IpaIPv6CTBlockTestFixture::ReceivePacketsAndCompare(false);
  736. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  737. return result;
  738. }
  739. };
  740. /*---------------------------------------------------------------------------------------------*/
  741. /* Test004: IPv6CT send inbound packet - without IPV6CT rule */
  742. /*---------------------------------------------------------------------------------------------*/
  743. class IpaIPV6CTBlockTest004 : public IpaIPv6CTBlockTestFixture
  744. {
  745. public:
  746. IpaIPV6CTBlockTest004()
  747. {
  748. m_name = "IpaIPV6CTBlockTest004";
  749. m_description =
  750. "IPv6CT block test 004 - IPv6CT blocks one packet in inbound direction due to rule absence\n"
  751. "1. Generate and commit three routing tables.\n"
  752. " Each table contains a single \"bypass\" rule (all data goes to output pipe 0, 1 and 2 (accordingly))\n"
  753. "2. Generate and commit one inbound filtering rule: Destination IP Exactly Match.\n";
  754. Register(*this);
  755. }
  756. virtual bool AddIpv6ctRules()
  757. {
  758. printf("not adding IPv6CT rule for packet - blocking expected %s %s\n", __FUNCTION__, __FILE__);
  759. return true;
  760. }
  761. virtual bool AddRoutingFilteringRules()
  762. {
  763. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  764. bool result = IpaIPv6CTBlockTestFixture::AddRoutingFilteringRules(IPA_PASS_TO_DST_NAT,
  765. m_outbound_src_addr_msb, m_outbound_src_addr_lsb);
  766. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  767. return result;
  768. }// AddRoutingFilteringRules()
  769. virtual bool ModifyPackets()
  770. {
  771. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  772. IpaIPv6CTBlockTestFixture::ModifyPackets(m_outbound_src_addr_lsb, m_outbound_src_addr_msb, m_outbound_src_port,
  773. m_outbound_dst_addr_lsb, m_outbound_dst_addr_msb, m_outbound_dst_port);
  774. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  775. return true;
  776. }// ModifyPackets()
  777. virtual bool ReceivePacketsAndCompare()
  778. {
  779. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  780. bool result = IpaIPv6CTBlockTestFixture::ReceivePacketsAndCompare(false);
  781. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  782. return result;
  783. }
  784. };
  785. /*---------------------------------------------------------------------------------------------*/
  786. /* Test005: IPv6CT send outbound packet with inbound filtering rule */
  787. /*---------------------------------------------------------------------------------------------*/
  788. class IpaIPV6CTBlockTest005 : public IpaIPv6CTBlockTestFixture
  789. {
  790. public:
  791. IpaIPV6CTBlockTest005()
  792. {
  793. m_name = "IpaIPV6CTBlockTest005";
  794. m_description =
  795. "IPv6CT block test 005 - IPv6CT blocks one packet in outbound direction, because the filtering rule\n"
  796. " action is inbound\n"
  797. "1. Generate and commit three routing tables.\n"
  798. " Each table contains a single \"bypass\" rule (all data goes to output pipe 0, 1 and 2 (accordingly))\n"
  799. "2. Generate and commit one inbound filtering rule: Destination IP Exactly Match.\n"
  800. "3. Add IPv6CT rule for the packet\n";
  801. Register(*this);
  802. }
  803. virtual bool AddRoutingFilteringRules()
  804. {
  805. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  806. bool result = IpaIPv6CTBlockTestFixture::AddRoutingFilteringRules(IPA_PASS_TO_DST_NAT,
  807. m_outbound_dst_addr_msb, m_outbound_dst_addr_lsb);
  808. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  809. return result;
  810. }// AddRoutingFilteringRules()
  811. virtual bool ModifyPackets()
  812. {
  813. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  814. IpaIPv6CTBlockTestFixture::ModifyPackets(m_outbound_dst_addr_lsb, m_outbound_dst_addr_msb, m_outbound_dst_port,
  815. m_outbound_src_addr_lsb, m_outbound_src_addr_msb, m_outbound_src_port);
  816. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  817. return true;
  818. }// ModifyPackets()
  819. virtual bool ReceivePacketsAndCompare()
  820. {
  821. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  822. bool result = IpaIPv6CTBlockTestFixture::ReceivePacketsAndCompare(false);
  823. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  824. return result;
  825. }
  826. };
  827. /*---------------------------------------------------------------------------------------------*/
  828. /* Test006: IPv6CT send inbound packet with outbound filtering rule */
  829. /*---------------------------------------------------------------------------------------------*/
  830. class IpaIPV6CTBlockTest006 : public IpaIPv6CTBlockTestFixture
  831. {
  832. public:
  833. IpaIPV6CTBlockTest006()
  834. {
  835. m_name = "IpaIPV6CTBlockTest006";
  836. m_description =
  837. "IPv6CT block test 006 - IPv6CT blocks one packet in inbound direction, because the filtering rule\n"
  838. " action is outbound\n"
  839. "1. Generate and commit three routing tables.\n"
  840. " Each table contains a single \"bypass\" rule (all data goes to output pipe 0, 1 and 2 (accordingly))\n"
  841. "2. Generate and commit one outbound filtering rule: Destination IP Exactly Match.\n"
  842. "3. Add IPv6CT rule for the packet\n";
  843. Register(*this);
  844. }
  845. virtual bool AddRoutingFilteringRules()
  846. {
  847. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  848. bool result = IpaIPv6CTBlockTestFixture::AddRoutingFilteringRules(IPA_PASS_TO_SRC_NAT,
  849. m_outbound_src_addr_msb, m_outbound_src_addr_lsb);
  850. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  851. return result;
  852. }// AddRoutingFilteringRules()
  853. virtual bool ModifyPackets()
  854. {
  855. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  856. IpaIPv6CTBlockTestFixture::ModifyPackets(m_outbound_src_addr_lsb, m_outbound_src_addr_msb, m_outbound_src_port,
  857. m_outbound_dst_addr_lsb, m_outbound_dst_addr_msb, m_outbound_dst_port);
  858. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  859. return true;
  860. }// ModifyPackets()
  861. virtual bool ReceivePacketsAndCompare()
  862. {
  863. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  864. bool result = IpaIPv6CTBlockTestFixture::ReceivePacketsAndCompare(false);
  865. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  866. return result;
  867. }
  868. };
  869. /*---------------------------------------------------------------------------------------------*/
  870. /* Test007: IPv6CT block outbound packet while disabled outbound direction */
  871. /*---------------------------------------------------------------------------------------------*/
  872. class IpaIPV6CTBlockTest007 : public IpaIPv6CTBlockTestFixture
  873. {
  874. public:
  875. IpaIPV6CTBlockTest007()
  876. {
  877. m_name = "IpaIPV6CTBlockTest007";
  878. m_description =
  879. "IPv6CT block test 007 - IPv6CT blocks one packet in outbound direction, because the outbound direction\n"
  880. " is disabled\n"
  881. "1. Generate and commit three routing tables.\n"
  882. " Each table contains a single \"bypass\" rule (all data goes to output pipe 0, 1 and 2 (accordingly))\n"
  883. "2. Generate and commit one outbound filtering rule: Destination IP Exactly Match.\n"
  884. "3. Add IPv6CT rule for the packet with disabled outbound direction\n";
  885. m_direction_settings = IPA_IPV6CT_DIRECTION_ALLOW_IN;
  886. Register(*this);
  887. }
  888. virtual bool AddRoutingFilteringRules()
  889. {
  890. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  891. bool result = IpaIPv6CTBlockTestFixture::AddRoutingFilteringRules(IPA_PASS_TO_SRC_NAT,
  892. m_outbound_dst_addr_msb, m_outbound_dst_addr_lsb);
  893. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  894. return result;
  895. }// AddRoutingFilteringRules()
  896. virtual bool ModifyPackets()
  897. {
  898. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  899. IpaIPv6CTBlockTestFixture::ModifyPackets(m_outbound_dst_addr_lsb, m_outbound_dst_addr_msb, m_outbound_dst_port,
  900. m_outbound_src_addr_lsb, m_outbound_src_addr_msb, m_outbound_src_port);
  901. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  902. return true;
  903. }// ModifyPackets()
  904. virtual bool ReceivePacketsAndCompare()
  905. {
  906. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  907. bool result = IpaIPv6CTBlockTestFixture::ReceivePacketsAndCompare(false);
  908. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  909. return result;
  910. }
  911. };
  912. /*---------------------------------------------------------------------------------------------*/
  913. /* Test008: IPv6CT block inbound packet with disabled inbound direction */
  914. /*---------------------------------------------------------------------------------------------*/
  915. class IpaIPV6CTBlockTest008 : public IpaIPv6CTBlockTestFixture
  916. {
  917. public:
  918. IpaIPV6CTBlockTest008()
  919. {
  920. m_name = "IpaIPV6CTBlockTest008";
  921. m_description =
  922. "IPv6CT block test 008 - IPv6CT blocks one packet in inbound direction, because the inbound direction\n"
  923. " is disabled\n"
  924. "1. Generate and commit three routing tables.\n"
  925. " Each table contains a single \"bypass\" rule (all data goes to output pipe 0, 1 and 2 (accordingly))\n"
  926. "2. Generate and commit one inbound filtering rule: Destination IP Exactly Match.\n"
  927. "3. Add IPv6CT rule for the packet with disabled inbound direction\n";
  928. m_direction_settings = IPA_IPV6CT_DIRECTION_ALLOW_OUT;
  929. Register(*this);
  930. }
  931. virtual bool AddRoutingFilteringRules()
  932. {
  933. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  934. bool result = IpaIPv6CTBlockTestFixture::AddRoutingFilteringRules(IPA_PASS_TO_DST_NAT,
  935. m_outbound_src_addr_msb, m_outbound_src_addr_lsb);
  936. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  937. return result;
  938. }// AddRoutingFilteringRules()
  939. virtual bool ModifyPackets()
  940. {
  941. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  942. IpaIPv6CTBlockTestFixture::ModifyPackets(m_outbound_src_addr_lsb, m_outbound_src_addr_msb, m_outbound_src_port,
  943. m_outbound_dst_addr_lsb, m_outbound_dst_addr_msb, m_outbound_dst_port);
  944. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  945. return true;
  946. }// ModifyPackets()
  947. virtual bool ReceivePacketsAndCompare()
  948. {
  949. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  950. bool result = IpaIPv6CTBlockTestFixture::ReceivePacketsAndCompare(false);
  951. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  952. return result;
  953. }
  954. };
  955. class IpaIPv6CTBlockExpansionTableTestFixture : public IpaIPv6CTBlockTestFixture
  956. {
  957. public:
  958. virtual bool AddIpv6ctRules()
  959. {
  960. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  961. ipa_ipv6ct_rule rule;
  962. InitIpv6ctRule(rule, 8);
  963. uint32_t rule_hdl;
  964. if (!AddIpv6ctRule(rule, rule_hdl))
  965. {
  966. return false;
  967. }
  968. bool result = IpaIPv6CTBlockTestFixture::AddIpv6ctRules();
  969. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  970. return result;
  971. }
  972. };
  973. /*---------------------------------------------------------------------------------------------*/
  974. /* Test009: IPv6CT send outbound packet with rule in expansion table */
  975. /*---------------------------------------------------------------------------------------------*/
  976. class IpaIPV6CTBlockTest009 : public IpaIPv6CTBlockExpansionTableTestFixture
  977. {
  978. public:
  979. IpaIPV6CTBlockTest009()
  980. {
  981. m_name = "IpaIPV6CTBlockTest009";
  982. m_description =
  983. "IPv6CT block test 009 - IPv6CT passes successfully one packet in outbound direction with rule in\n"
  984. " expansion table\n"
  985. "1. Generate and commit three routing tables.\n"
  986. " Each table contains a single \"bypass\" rule (all data goes to output pipe 0, 1 and 2 (accordingly))\n"
  987. "2. Generate and commit one outbound filtering rule: Destination IP Exactly Match.\n"
  988. "3. Add an IPv6CT rule to occupy base table. This rule is not supposed to match a packet\n"
  989. "4. Add IPv6CT rule for the packet to the expansion table\n";
  990. Register(*this);
  991. }
  992. virtual bool AddRoutingFilteringRules()
  993. {
  994. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  995. bool result = IpaIPv6CTBlockTestFixture::AddRoutingFilteringRules(IPA_PASS_TO_SRC_NAT,
  996. m_outbound_dst_addr_msb, m_outbound_dst_addr_lsb);
  997. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  998. return result;
  999. }// AddRoutingFilteringRules()
  1000. virtual bool ModifyPackets()
  1001. {
  1002. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  1003. IpaIPv6CTBlockTestFixture::ModifyPackets(m_outbound_dst_addr_lsb, m_outbound_dst_addr_msb, m_outbound_dst_port,
  1004. m_outbound_src_addr_lsb, m_outbound_src_addr_msb, m_outbound_src_port);
  1005. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  1006. return true;
  1007. }// ModifyPackets()
  1008. virtual bool ReceivePacketsAndCompare()
  1009. {
  1010. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  1011. bool result = IpaIPv6CTBlockTestFixture::ReceivePacketsAndCompare(true);
  1012. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  1013. return result;
  1014. }
  1015. };
  1016. /*---------------------------------------------------------------------------------------------*/
  1017. /* Test010: IPv6CT send inbound packet with rule in expansion table */
  1018. /*---------------------------------------------------------------------------------------------*/
  1019. class IpaIPV6CTBlockTest010 : public IpaIPv6CTBlockExpansionTableTestFixture
  1020. {
  1021. public:
  1022. IpaIPV6CTBlockTest010()
  1023. {
  1024. m_name = "IpaIPV6CTBlockTest010";
  1025. m_description =
  1026. "IPv6CT block test 010 - IPv6CT passes successfully one packet in inbound direction with rule in\n"
  1027. " expansion table\n"
  1028. "1. Generate and commit three routing tables.\n"
  1029. " Each table contains a single \"bypass\" rule (all data goes to output pipe 0, 1 and 2 (accordingly))\n"
  1030. "2. Generate and commit one inbound filtering rule: Destination IP Exactly Match.\n"
  1031. "3. Add an IPv6CT rule to occupy base table. This rule is not supposed to match a packet\n"
  1032. "4. Add IPv6CT rule for the packet to the expansion table\n";
  1033. Register(*this);
  1034. }
  1035. virtual bool AddRoutingFilteringRules()
  1036. {
  1037. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  1038. bool result = IpaIPv6CTBlockTestFixture::AddRoutingFilteringRules(IPA_PASS_TO_DST_NAT,
  1039. m_outbound_src_addr_msb, m_outbound_src_addr_lsb);
  1040. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  1041. return result;
  1042. }// AddRoutingFilteringRules()
  1043. virtual bool ModifyPackets()
  1044. {
  1045. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  1046. IpaIPv6CTBlockTestFixture::ModifyPackets(m_outbound_src_addr_lsb, m_outbound_src_addr_msb, m_outbound_src_port,
  1047. m_outbound_dst_addr_lsb, m_outbound_dst_addr_msb, m_outbound_dst_port);
  1048. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  1049. return true;
  1050. }// ModifyPackets()
  1051. virtual bool ReceivePacketsAndCompare()
  1052. {
  1053. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  1054. bool result = IpaIPv6CTBlockTestFixture::ReceivePacketsAndCompare(true);
  1055. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  1056. return result;
  1057. }
  1058. };
  1059. class IpaIPv6CTBlockRuleDeleteTestFixture : public IpaIPv6CTBlockTestFixture
  1060. {
  1061. public:
  1062. virtual bool AddIpv6ctRules()
  1063. {
  1064. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  1065. ipa_ipv6ct_rule rule;
  1066. InitIpv6ctRule(rule, 0);
  1067. uint32_t rule_hdl;
  1068. if (!AddIpv6ctRule(rule, rule_hdl))
  1069. {
  1070. return false;
  1071. }
  1072. int result = ipa_ipv6ct_del_rule(m_tableHandle, rule_hdl);
  1073. if (result)
  1074. {
  1075. printf("Leaving %s, %s(), failed delete IPvC6T rule %d with result %d\n", __FUNCTION__, __FILE__,
  1076. rule_hdl, result);
  1077. return false;
  1078. }
  1079. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  1080. return true;
  1081. }
  1082. };
  1083. /*---------------------------------------------------------------------------------------------*/
  1084. /* Test011: IPv6CT block outbound packet while the rule was deleted */
  1085. /*---------------------------------------------------------------------------------------------*/
  1086. class IpaIPV6CTBlockTest011 : public IpaIPv6CTBlockRuleDeleteTestFixture
  1087. {
  1088. public:
  1089. IpaIPV6CTBlockTest011()
  1090. {
  1091. m_name = "IpaIPV6CTBlockTest011";
  1092. m_description =
  1093. "IPv6CT block test 011 - IPv6CT blocks one packet in outbound direction due to the rule deletion\n"
  1094. "1. Generate and commit three routing tables.\n"
  1095. " Each table contains a single \"bypass\" rule (all data goes to output pipe 0, 1 and 2 (accordingly))\n"
  1096. "2. Generate and commit one outbound filtering rule: Destination IP Exactly Match.\n"
  1097. "3. Add IPv6CT rule for the packet\n"
  1098. "4. Delete IPv6CT rule for the packet\n";
  1099. Register(*this);
  1100. }
  1101. virtual bool AddRoutingFilteringRules()
  1102. {
  1103. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  1104. bool result = IpaIPv6CTBlockTestFixture::AddRoutingFilteringRules(IPA_PASS_TO_SRC_NAT,
  1105. m_outbound_dst_addr_msb, m_outbound_dst_addr_lsb);
  1106. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  1107. return result;
  1108. }// AddRoutingFilteringRules()
  1109. virtual bool ModifyPackets()
  1110. {
  1111. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  1112. IpaIPv6CTBlockTestFixture::ModifyPackets(m_outbound_dst_addr_lsb, m_outbound_dst_addr_msb, m_outbound_dst_port,
  1113. m_outbound_src_addr_lsb, m_outbound_src_addr_msb, m_outbound_src_port);
  1114. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  1115. return true;
  1116. }// ModifyPackets()
  1117. virtual bool ReceivePacketsAndCompare()
  1118. {
  1119. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  1120. bool result = IpaIPv6CTBlockTestFixture::ReceivePacketsAndCompare(false);
  1121. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  1122. return result;
  1123. }
  1124. };
  1125. /*---------------------------------------------------------------------------------------------*/
  1126. /* Test012: IPv6CT block inbound packet while the rule was deleted */
  1127. /*---------------------------------------------------------------------------------------------*/
  1128. class IpaIPV6CTBlockTest012 : public IpaIPv6CTBlockRuleDeleteTestFixture
  1129. {
  1130. public:
  1131. IpaIPV6CTBlockTest012()
  1132. {
  1133. m_name = "IpaIPV6CTBlockTest012";
  1134. m_description =
  1135. "IPv6CT block test 012 - IPv6CT blocks one packet in inbound direction due to the rule deletion\n"
  1136. "1. Generate and commit three routing tables.\n"
  1137. " Each table contains a single \"bypass\" rule (all data goes to output pipe 0, 1 and 2 (accordingly))\n"
  1138. "2. Generate and commit one inbound filtering rule: Destination IP Exactly Match.\n"
  1139. "3. Add IPv6CT rule for the packet\n"
  1140. "4. Delete IPv6CT rule for the packet\n";
  1141. Register(*this);
  1142. }
  1143. virtual bool AddRoutingFilteringRules()
  1144. {
  1145. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  1146. bool result = IpaIPv6CTBlockTestFixture::AddRoutingFilteringRules(IPA_PASS_TO_DST_NAT,
  1147. m_outbound_src_addr_msb, m_outbound_src_addr_lsb);
  1148. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  1149. return result;
  1150. }// AddRoutingFilteringRules()
  1151. virtual bool ModifyPackets()
  1152. {
  1153. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  1154. IpaIPv6CTBlockTestFixture::ModifyPackets(m_outbound_src_addr_lsb, m_outbound_src_addr_msb, m_outbound_src_port,
  1155. m_outbound_dst_addr_lsb, m_outbound_dst_addr_msb, m_outbound_dst_port);
  1156. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  1157. return true;
  1158. }// ModifyPackets()
  1159. virtual bool ReceivePacketsAndCompare()
  1160. {
  1161. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  1162. bool result = IpaIPv6CTBlockTestFixture::ReceivePacketsAndCompare(false);
  1163. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  1164. return result;
  1165. }
  1166. };
  1167. class IpaIPv6CTBlockRuleDeleteExpansionTableTestFixture : public IpaIPv6CTBlockRuleDeleteTestFixture
  1168. {
  1169. public:
  1170. virtual bool AddIpv6ctRules()
  1171. {
  1172. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  1173. ipa_ipv6ct_rule rule;
  1174. InitIpv6ctRule(rule, 8);
  1175. uint32_t rule_hdl;
  1176. if (!AddIpv6ctRule(rule, rule_hdl))
  1177. {
  1178. return false;
  1179. }
  1180. bool result = IpaIPv6CTBlockRuleDeleteTestFixture::AddIpv6ctRules();
  1181. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  1182. return result;
  1183. }
  1184. };
  1185. /*---------------------------------------------------------------------------------------------*/
  1186. /* Test013: IPv6CT block outbound packet while the rule in expansion table was deleted */
  1187. /*---------------------------------------------------------------------------------------------*/
  1188. class IpaIPV6CTBlockTest013 : public IpaIPv6CTBlockRuleDeleteExpansionTableTestFixture
  1189. {
  1190. public:
  1191. IpaIPV6CTBlockTest013()
  1192. {
  1193. m_name = "IpaIPV6CTBlockTest013";
  1194. m_description =
  1195. "IPv6CT block test 013 - IPv6CT blocks one packet in outbound direction due to the rule deletion from\n"
  1196. " the expansion table\n"
  1197. "1. Generate and commit three routing tables.\n"
  1198. " Each table contains a single \"bypass\" rule (all data goes to output pipe 0, 1 and 2 (accordingly))\n"
  1199. "2. Generate and commit one outbound filtering rule: Destination IP Exactly Match.\n"
  1200. "3. Add an IPv6CT rule to occupy base table. This rule is not supposed to match a packet\n"
  1201. "4. Add IPv6CT rule for the packet to the expansion table\n"
  1202. "5. Delete IPv6CT rule for the packet from the expansion table\n";
  1203. Register(*this);
  1204. }
  1205. virtual bool AddRoutingFilteringRules()
  1206. {
  1207. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  1208. bool result = IpaIPv6CTBlockTestFixture::AddRoutingFilteringRules(IPA_PASS_TO_SRC_NAT,
  1209. m_outbound_dst_addr_msb, m_outbound_dst_addr_lsb);
  1210. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  1211. return result;
  1212. }// AddRoutingFilteringRules()
  1213. virtual bool ModifyPackets()
  1214. {
  1215. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  1216. IpaIPv6CTBlockTestFixture::ModifyPackets(m_outbound_dst_addr_lsb, m_outbound_dst_addr_msb, m_outbound_dst_port,
  1217. m_outbound_src_addr_lsb, m_outbound_src_addr_msb, m_outbound_src_port);
  1218. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  1219. return true;
  1220. }// ModifyPackets()
  1221. virtual bool ReceivePacketsAndCompare()
  1222. {
  1223. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  1224. bool result = IpaIPv6CTBlockTestFixture::ReceivePacketsAndCompare(false);
  1225. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  1226. return result;
  1227. }
  1228. };
  1229. /*---------------------------------------------------------------------------------------------*/
  1230. /* Test014: IPv6CT block inbound packet while the rule in expansion table was deleted */
  1231. /*---------------------------------------------------------------------------------------------*/
  1232. class IpaIPV6CTBlockTest014 : public IpaIPv6CTBlockRuleDeleteExpansionTableTestFixture
  1233. {
  1234. public:
  1235. IpaIPV6CTBlockTest014()
  1236. {
  1237. m_name = "IpaIPV6CTBlockTest014";
  1238. m_description =
  1239. "IPv6CT block test 014 - IPv6CT blocks one packet in inbound direction due to the rule deletion from\n"
  1240. " the expansion table\n"
  1241. "1. Generate and commit three routing tables.\n"
  1242. " Each table contains a single \"bypass\" rule (all data goes to output pipe 0, 1 and 2 (accordingly))\n"
  1243. "2. Generate and commit one inbound filtering rule: Destination IP Exactly Match.\n"
  1244. "3. Add an IPv6CT rule to occupy base table. This rule is not supposed to match a packet\n"
  1245. "4. Add IPv6CT rule for the packet to the expansion table\n"
  1246. "5. Delete IPv6CT rule for the packet from the expansion table\n";
  1247. Register(*this);
  1248. }
  1249. virtual bool AddRoutingFilteringRules()
  1250. {
  1251. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  1252. bool result = IpaIPv6CTBlockTestFixture::AddRoutingFilteringRules(IPA_PASS_TO_DST_NAT,
  1253. m_outbound_src_addr_msb, m_outbound_src_addr_lsb);
  1254. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  1255. return result;
  1256. }// AddRoutingFilteringRules()
  1257. virtual bool ModifyPackets()
  1258. {
  1259. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  1260. IpaIPv6CTBlockTestFixture::ModifyPackets(m_outbound_src_addr_lsb, m_outbound_src_addr_msb, m_outbound_src_port,
  1261. m_outbound_dst_addr_lsb, m_outbound_dst_addr_msb, m_outbound_dst_port);
  1262. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  1263. return true;
  1264. }// ModifyPackets()
  1265. virtual bool ReceivePacketsAndCompare()
  1266. {
  1267. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  1268. bool result = IpaIPv6CTBlockTestFixture::ReceivePacketsAndCompare(false);
  1269. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  1270. return result;
  1271. }
  1272. };
  1273. class IpaIPv6CTBlockHeadRuleDeleteTestFixture : public IpaIPv6CTBlockTestFixture
  1274. {
  1275. public:
  1276. virtual bool AddIpv6ctRules()
  1277. {
  1278. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  1279. ipa_ipv6ct_rule rule;
  1280. InitIpv6ctRule(rule, 8);
  1281. uint32_t rule_hdl;
  1282. if (!AddIpv6ctRule(rule, rule_hdl))
  1283. {
  1284. return false;
  1285. }
  1286. if (!IpaIPv6CTBlockTestFixture::AddIpv6ctRules())
  1287. {
  1288. return false;
  1289. }
  1290. int result = ipa_ipv6ct_del_rule(m_tableHandle, rule_hdl);
  1291. if (result)
  1292. {
  1293. printf("Leaving %s, %s(), failed delete IPvC6T rule %d with result %d\n", __FUNCTION__, __FILE__,
  1294. rule_hdl, result);
  1295. return false;
  1296. }
  1297. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  1298. return true;
  1299. }
  1300. };
  1301. /*---------------------------------------------------------------------------------------------------------------*/
  1302. /* Test015: IPv6CT send outbound packet with rule in expansion table while the rule in the list head was deleted */
  1303. /*---------------------------------------------------------------------------------------------------------------*/
  1304. class IpaIPV6CTBlockTest015 : public IpaIPv6CTBlockHeadRuleDeleteTestFixture
  1305. {
  1306. public:
  1307. IpaIPV6CTBlockTest015()
  1308. {
  1309. m_name = "IpaIPV6CTBlockTest015";
  1310. m_description =
  1311. "IPv6CT block test 015 - IPv6CT passes successfully one packet in outbound direction with rule in\n"
  1312. " expansion table, while the list head was deleted\n"
  1313. "1. Generate and commit three routing tables.\n"
  1314. " Each table contains a single \"bypass\" rule (all data goes to output pipe 0, 1 and 2 (accordingly))\n"
  1315. "2. Generate and commit one outbound filtering rule: Destination IP Exactly Match.\n"
  1316. "3. Add an IPv6CT rule to occupy base table. This rule is not supposed to match a packet\n"
  1317. "4. Add IPv6CT rule for the packet to the expansion table\n"
  1318. "5. Delete IPv6CT rule in the list head\n";
  1319. Register(*this);
  1320. }
  1321. virtual bool AddRoutingFilteringRules()
  1322. {
  1323. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  1324. bool result = IpaIPv6CTBlockTestFixture::AddRoutingFilteringRules(IPA_PASS_TO_SRC_NAT,
  1325. m_outbound_dst_addr_msb, m_outbound_dst_addr_lsb);
  1326. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  1327. return result;
  1328. }// AddRoutingFilteringRules()
  1329. virtual bool ModifyPackets()
  1330. {
  1331. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  1332. IpaIPv6CTBlockTestFixture::ModifyPackets(m_outbound_dst_addr_lsb, m_outbound_dst_addr_msb, m_outbound_dst_port,
  1333. m_outbound_src_addr_lsb, m_outbound_src_addr_msb, m_outbound_src_port);
  1334. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  1335. return true;
  1336. }// ModifyPackets()
  1337. virtual bool ReceivePacketsAndCompare()
  1338. {
  1339. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  1340. bool result = IpaIPv6CTBlockTestFixture::ReceivePacketsAndCompare(true);
  1341. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  1342. return result;
  1343. }
  1344. };
  1345. /*---------------------------------------------------------------------------------------------------------------*/
  1346. /* Test016: IPv6CT send inbound packet with rule in expansion table while the rule in the list head was deleted */
  1347. /*---------------------------------------------------------------------------------------------------------------*/
  1348. class IpaIPV6CTBlockTest016 : public IpaIPv6CTBlockHeadRuleDeleteTestFixture
  1349. {
  1350. public:
  1351. IpaIPV6CTBlockTest016()
  1352. {
  1353. m_name = "IpaIPV6CTBlockTest016";
  1354. m_description =
  1355. "IPv6CT block test 016 - IPv6CT passes successfully one packet in inbound direction with rule in\n"
  1356. " expansion table, while the list head was deleted\n"
  1357. "1. Generate and commit three routing tables.\n"
  1358. " Each table contains a single \"bypass\" rule (all data goes to output pipe 0, 1 and 2 (accordingly))\n"
  1359. "2. Generate and commit one inbound filtering rule: Destination IP Exactly Match.\n"
  1360. "3. Add an IPv6CT rule to occupy base table. This rule is not supposed to match a packet\n"
  1361. "4. Add IPv6CT rule for the packet to the expansion table\n"
  1362. "5. Delete IPv6CT rule in the list head\n";
  1363. Register(*this);
  1364. }
  1365. virtual bool AddRoutingFilteringRules()
  1366. {
  1367. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  1368. bool result = IpaIPv6CTBlockTestFixture::AddRoutingFilteringRules(IPA_PASS_TO_DST_NAT,
  1369. m_outbound_src_addr_msb, m_outbound_src_addr_lsb);
  1370. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  1371. return result;
  1372. }// AddRoutingFilteringRules()
  1373. virtual bool ModifyPackets()
  1374. {
  1375. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  1376. IpaIPv6CTBlockTestFixture::ModifyPackets(m_outbound_src_addr_lsb, m_outbound_src_addr_msb, m_outbound_src_port,
  1377. m_outbound_dst_addr_lsb, m_outbound_dst_addr_msb, m_outbound_dst_port);
  1378. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  1379. return true;
  1380. }// ModifyPackets()
  1381. virtual bool ReceivePacketsAndCompare()
  1382. {
  1383. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  1384. bool result = IpaIPv6CTBlockTestFixture::ReceivePacketsAndCompare(true);
  1385. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  1386. return result;
  1387. }
  1388. };
  1389. class IpaIPv6CTBlockMiddleRuleDeleteTestFixture : public IpaIPv6CTBlockHeadRuleDeleteTestFixture
  1390. {
  1391. public:
  1392. virtual bool AddIpv6ctRules()
  1393. {
  1394. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  1395. ipa_ipv6ct_rule rule;
  1396. InitIpv6ctRule(rule, 1);
  1397. uint32_t rule_hdl;
  1398. if (!AddIpv6ctRule(rule, rule_hdl))
  1399. {
  1400. return false;
  1401. }
  1402. bool result = IpaIPv6CTBlockHeadRuleDeleteTestFixture::AddIpv6ctRules();
  1403. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  1404. return result;
  1405. }
  1406. };
  1407. /*------------------------------------------------------------------------------------------------------------*/
  1408. /* Test017: IPv6CT send outbound packet with rule in expansion table while the rule in the middle of the list */
  1409. /* was deleted */
  1410. /*------------------------------------------------------------------------------------------------------------*/
  1411. class IpaIPV6CTBlockTest017 : public IpaIPv6CTBlockMiddleRuleDeleteTestFixture
  1412. {
  1413. public:
  1414. IpaIPV6CTBlockTest017()
  1415. {
  1416. m_name = "IpaIPV6CTBlockTest017";
  1417. m_description =
  1418. "IPv6CT block test 017 - IPv6CT passes successfully one packet in outbound direction with rule in\n"
  1419. " expansion table, while the rule in the middle of the list was deleted\n"
  1420. "1. Generate and commit three routing tables.\n"
  1421. " Each table contains a single \"bypass\" rule (all data goes to output pipe 0, 1 and 2 (accordingly))\n"
  1422. "2. Generate and commit one outbound filtering rule: Destination IP Exactly Match.\n"
  1423. "3. Add two IPv6CT rules: one to base table and other to expansion table. These rules are not supposed\n"
  1424. " to match a packet\n"
  1425. "4. Add IPv6CT rule for the packet to the expansion table\n"
  1426. "5. Delete IPv6CT rule in the middle of the list\n";
  1427. Register(*this);
  1428. }
  1429. virtual bool AddRoutingFilteringRules()
  1430. {
  1431. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  1432. bool result = IpaIPv6CTBlockTestFixture::AddRoutingFilteringRules(IPA_PASS_TO_SRC_NAT,
  1433. m_outbound_dst_addr_msb, m_outbound_dst_addr_lsb);
  1434. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  1435. return result;
  1436. }// AddRoutingFilteringRules()
  1437. virtual bool ModifyPackets()
  1438. {
  1439. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  1440. IpaIPv6CTBlockTestFixture::ModifyPackets(m_outbound_dst_addr_lsb, m_outbound_dst_addr_msb, m_outbound_dst_port,
  1441. m_outbound_src_addr_lsb, m_outbound_src_addr_msb, m_outbound_src_port);
  1442. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  1443. return true;
  1444. }// ModifyPackets()
  1445. virtual bool ReceivePacketsAndCompare()
  1446. {
  1447. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  1448. bool result = IpaIPv6CTBlockTestFixture::ReceivePacketsAndCompare(true);
  1449. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  1450. return result;
  1451. }
  1452. };
  1453. /*------------------------------------------------------------------------------------------------------------*/
  1454. /* Test018: IPv6CT send inbound packet with rule in expansion table while the rule in the middle of the list */
  1455. /* was deleted */
  1456. /*------------------------------------------------------------------------------------------------------------*/
  1457. class IpaIPV6CTBlockTest018 : public IpaIPv6CTBlockMiddleRuleDeleteTestFixture
  1458. {
  1459. public:
  1460. IpaIPV6CTBlockTest018()
  1461. {
  1462. m_name = "IpaIPV6CTBlockTest018";
  1463. m_description =
  1464. "IPv6CT block test 018 - IPv6CT passes successfully one packet in inbound direction with rule in\n"
  1465. " expansion table, while the rule in the middle of the list was deleted\n"
  1466. "1. Generate and commit three routing tables.\n"
  1467. " Each table contains a single \"bypass\" rule (all data goes to output pipe 0, 1 and 2 (accordingly))\n"
  1468. "2. Generate and commit one inbound filtering rule: Destination IP Exactly Match.\n"
  1469. "3. Add two IPv6CT rules to occupy base table and the middle of the list. These rules are not supposed\n"
  1470. " to match a packet\n"
  1471. "4. Add IPv6CT rule for the packet to the expansion table\n"
  1472. "5. Delete IPv6CT rule in the middle of the list\n";
  1473. Register(*this);
  1474. }
  1475. virtual bool AddRoutingFilteringRules()
  1476. {
  1477. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  1478. bool result = IpaIPv6CTBlockTestFixture::AddRoutingFilteringRules(IPA_PASS_TO_DST_NAT,
  1479. m_outbound_src_addr_msb, m_outbound_src_addr_lsb);
  1480. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  1481. return result;
  1482. }// AddRoutingFilteringRules()
  1483. virtual bool ModifyPackets()
  1484. {
  1485. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  1486. IpaIPv6CTBlockTestFixture::ModifyPackets(m_outbound_src_addr_lsb, m_outbound_src_addr_msb, m_outbound_src_port,
  1487. m_outbound_dst_addr_lsb, m_outbound_dst_addr_msb, m_outbound_dst_port);
  1488. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  1489. return true;
  1490. }// ModifyPackets()
  1491. virtual bool ReceivePacketsAndCompare()
  1492. {
  1493. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  1494. bool result = IpaIPv6CTBlockTestFixture::ReceivePacketsAndCompare(true);
  1495. printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__);
  1496. return result;
  1497. }
  1498. };
  1499. // IPv6CT outbound packet test
  1500. static class IpaIPV6CTBlockTest001 IpaIPV6CTBlockTest001;
  1501. // IPv6CT inbound packet test
  1502. static class IpaIPV6CTBlockTest002 IpaIPV6CTBlockTest002;
  1503. // IPv6CT block outbound packet test
  1504. static class IpaIPV6CTBlockTest003 IpaIPV6CTBlockTest003;
  1505. // IPv6CT block inbound packet test
  1506. static class IpaIPV6CTBlockTest004 IpaIPV6CTBlockTest004;
  1507. // IPv6CT block outbound packet on inbound filtering rule test
  1508. static class IpaIPV6CTBlockTest005 IpaIPV6CTBlockTest005;
  1509. // IPv6CT block inbound packet on outbound filtering rule test
  1510. static class IpaIPV6CTBlockTest006 IpaIPV6CTBlockTest006;
  1511. // IPv6CT block outbound packet while disabled outbound direction
  1512. static class IpaIPV6CTBlockTest007 IpaIPV6CTBlockTest007;
  1513. // IPv6CT block inbound packet with disabled inbound direction
  1514. static class IpaIPV6CTBlockTest008 IpaIPV6CTBlockTest008;
  1515. // IPv6CT send outbound packet with rule in expansion table
  1516. static class IpaIPV6CTBlockTest009 IpaIPV6CTBlockTest009;
  1517. // IPv6CT send inbound packet with rule in expansion table
  1518. static class IpaIPV6CTBlockTest010 IpaIPV6CTBlockTest010;
  1519. // IPv6CT block outbound packet while the rule was deleted
  1520. static class IpaIPV6CTBlockTest011 IpaIPV6CTBlockTest011;
  1521. // IPv6CT block inbound packet while the rule was deleted
  1522. static class IpaIPV6CTBlockTest012 IpaIPV6CTBlockTest012;
  1523. // IPv6CT block outbound packet while the rule in expansion table was deleted
  1524. static class IpaIPV6CTBlockTest013 IpaIPV6CTBlockTest013;
  1525. // IPv6CT block inbound packet while the rule in expansion table was deleted
  1526. static class IpaIPV6CTBlockTest014 IpaIPV6CTBlockTest014;
  1527. // IPv6CT send outbound packet with rule in expansion table while the rule in list head was deleted
  1528. static class IpaIPV6CTBlockTest015 IpaIPV6CTBlockTest015;
  1529. // IPv6CT send inbound packet with rule in expansion table while the rule in list head was deleted
  1530. static class IpaIPV6CTBlockTest016 IpaIPV6CTBlockTest016;
  1531. // IPv6CT send outbound packet with rule in expansion table while the rule in the middle of the list was deleted
  1532. static class IpaIPV6CTBlockTest017 IpaIPV6CTBlockTest017;
  1533. // IPv6CT send inbound packet with rule in expansion table while the rule in the middle of the list was deleted
  1534. static class IpaIPV6CTBlockTest018 IpaIPV6CTBlockTest018;