ipa_nat_test022.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. /*
  2. * Copyright (c) 2014, 2018-2019 The Linux Foundation. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are
  6. * met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above
  10. * copyright notice, this list of conditions and the following
  11. * disclaimer in the documentation and/or other materials provided
  12. * with the distribution.
  13. * * Neither the name of The Linux Foundation nor the names of its
  14. * contributors may be used to endorse or promote products derived
  15. * from this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
  18. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
  20. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
  21. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  22. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  23. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  24. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  25. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  26. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  27. * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. /*=========================================================================*/
  30. /*!
  31. @file
  32. ipa_nat_test022.c
  33. @brief
  34. Note: Verify the following scenario:
  35. 1. Add ipv4 table
  36. 2. Add ipv4 rules till filled
  37. 3. Print stats
  38. 4. Delete ipv4 table
  39. */
  40. /*=========================================================================*/
  41. #include "ipa_nat_test.h"
  42. int ipa_nat_test022(
  43. const char* nat_mem_type,
  44. u32 pub_ip_add,
  45. int total_entries,
  46. u32 tbl_hdl,
  47. int sep,
  48. void* arb_data_ptr)
  49. {
  50. int* tbl_hdl_ptr = (int*) arb_data_ptr;
  51. ipa_nat_ipv4_rule ipv4_rule;
  52. u32 rule_hdls[2048];
  53. ipa_nati_tbl_stats nstats, last_nstats;
  54. ipa_nati_tbl_stats istats, last_istats;
  55. u32 i, tot;
  56. bool switched = false;
  57. const char* mem_type;
  58. int ret;
  59. IPADBG("In\n");
  60. if ( sep )
  61. {
  62. ret = ipa_nat_add_ipv4_tbl(pub_ip_add, nat_mem_type, total_entries, &tbl_hdl);
  63. CHECK_ERR_TBL_STOP(ret, tbl_hdl);
  64. }
  65. ret = ipa_nati_clear_ipv4_tbl(tbl_hdl);
  66. CHECK_ERR_TBL_STOP(ret, tbl_hdl);
  67. ret = ipa_nati_ipv4_tbl_stats(tbl_hdl, &nstats, &istats);
  68. CHECK_ERR_TBL_STOP(ret, tbl_hdl);
  69. IPAINFO("Attempting rule adds to %s table of size: (%u)\n",
  70. ipa3_nat_mem_in_as_str(nstats.nmi),
  71. nstats.tot_ents);
  72. last_nstats = nstats;
  73. last_istats = istats;
  74. memset(rule_hdls, 0, sizeof(rule_hdls));
  75. for ( i = tot = 0; i < array_sz(rule_hdls); i++ )
  76. {
  77. IPADBG("Trying %d ipa_nat_add_ipv4_rule()\n", i);
  78. memset(&ipv4_rule, 0, sizeof(ipv4_rule));
  79. ipv4_rule.protocol = IPPROTO_TCP;
  80. ipv4_rule.public_port = RAN_PORT;
  81. ipv4_rule.target_ip = RAN_ADDR;
  82. ipv4_rule.target_port = RAN_PORT;
  83. ipv4_rule.private_ip = RAN_ADDR;
  84. ipv4_rule.private_port = RAN_PORT;
  85. ret = ipa_nat_add_ipv4_rule(tbl_hdl, &ipv4_rule, &rule_hdls[i]);
  86. CHECK_ERR_TBL_ACTION(ret, tbl_hdl, break);
  87. IPADBG("Success %d ipa_nat_add_ipv4_rule() -> rule_hdl(0x%08X)\n",
  88. i, rule_hdls[i]);
  89. ret = ipa_nati_ipv4_tbl_stats(tbl_hdl, &nstats, &istats);
  90. CHECK_ERR_TBL_ACTION(ret, tbl_hdl, break);
  91. /*
  92. * Are we in hybrid mode and have we switched memory type?
  93. * Check for it and print the appropriate stats.
  94. */
  95. if ( nstats.nmi != last_nstats.nmi )
  96. {
  97. mem_type = ipa3_nat_mem_in_as_str(last_nstats.nmi);
  98. switched = true;
  99. /*
  100. * NAT table stats...
  101. */
  102. IPAINFO("Able to add (%u) records to %s "
  103. "NAT table of size (%u) or (%f) percent\n",
  104. tot,
  105. mem_type,
  106. last_nstats.tot_ents,
  107. ((float) tot / (float) last_nstats.tot_ents) * 100.0);
  108. IPAINFO("Able to add (%u) records to %s "
  109. "NAT BASE table of size (%u) or (%f) percent\n",
  110. last_nstats.tot_base_ents_filled,
  111. mem_type,
  112. last_nstats.tot_base_ents,
  113. ((float) last_nstats.tot_base_ents_filled /
  114. (float) last_nstats.tot_base_ents) * 100.0);
  115. IPAINFO("Able to add (%u) records to %s "
  116. "NAT EXPN table of size (%u) or (%f) percent\n",
  117. last_nstats.tot_expn_ents_filled,
  118. mem_type,
  119. last_nstats.tot_expn_ents,
  120. ((float) last_nstats.tot_expn_ents_filled /
  121. (float) last_nstats.tot_expn_ents) * 100.0);
  122. IPAINFO("%s NAT table chains: tot_chains(%u) min_len(%u) max_len(%u) avg_len(%f)\n",
  123. mem_type,
  124. last_nstats.tot_chains,
  125. last_nstats.min_chain_len,
  126. last_nstats.max_chain_len,
  127. last_nstats.avg_chain_len);
  128. /*
  129. * INDEX table stats...
  130. */
  131. IPAINFO("Able to add (%u) records to %s "
  132. "IDX table of size (%u) or (%f) percent\n",
  133. tot,
  134. mem_type,
  135. last_istats.tot_ents,
  136. ((float) tot / (float) last_istats.tot_ents) * 100.0);
  137. IPAINFO("Able to add (%u) records to %s "
  138. "IDX BASE table of size (%u) or (%f) percent\n",
  139. last_istats.tot_base_ents_filled,
  140. mem_type,
  141. last_istats.tot_base_ents,
  142. ((float) last_istats.tot_base_ents_filled /
  143. (float) last_istats.tot_base_ents) * 100.0);
  144. IPAINFO("Able to add (%u) records to %s "
  145. "IDX EXPN table of size (%u) or (%f) percent\n",
  146. last_istats.tot_expn_ents_filled,
  147. mem_type,
  148. last_istats.tot_expn_ents,
  149. ((float) last_istats.tot_expn_ents_filled /
  150. (float) last_istats.tot_expn_ents) * 100.0);
  151. IPAINFO("%s IDX table chains: tot_chains(%u) min_len(%u) max_len(%u) avg_len(%f)\n",
  152. mem_type,
  153. last_istats.tot_chains,
  154. last_istats.min_chain_len,
  155. last_istats.max_chain_len,
  156. last_istats.avg_chain_len);
  157. }
  158. last_nstats = nstats;
  159. last_istats = istats;
  160. if ( switched )
  161. {
  162. switched = false;
  163. IPAINFO("Continuing rule adds to %s table of size: (%u)\n",
  164. ipa3_nat_mem_in_as_str(nstats.nmi),
  165. nstats.tot_ents);
  166. }
  167. tot++;
  168. }
  169. ret = ipa_nati_ipv4_tbl_stats(tbl_hdl, &nstats, &istats);
  170. CHECK_ERR_TBL_STOP(ret, tbl_hdl);
  171. mem_type = ipa3_nat_mem_in_as_str(nstats.nmi);
  172. /*
  173. * NAT table stats...
  174. */
  175. IPAINFO("Able to add (%u) records to %s "
  176. "NAT table of size (%u) or (%f) percent\n",
  177. tot,
  178. mem_type,
  179. nstats.tot_ents,
  180. ((float) tot / (float) nstats.tot_ents) * 100.0);
  181. IPAINFO("Able to add (%u) records to %s "
  182. "NAT BASE table of size (%u) or (%f) percent\n",
  183. nstats.tot_base_ents_filled,
  184. mem_type,
  185. nstats.tot_base_ents,
  186. ((float) nstats.tot_base_ents_filled /
  187. (float) nstats.tot_base_ents) * 100.0);
  188. IPAINFO("Able to add (%u) records to %s "
  189. "NAT EXPN table of size (%u) or (%f) percent\n",
  190. nstats.tot_expn_ents_filled,
  191. mem_type,
  192. nstats.tot_expn_ents,
  193. ((float) nstats.tot_expn_ents_filled /
  194. (float) nstats.tot_expn_ents) * 100.0);
  195. IPAINFO("%s NAT table chains: tot_chains(%u) min_len(%u) max_len(%u) avg_len(%f)\n",
  196. mem_type,
  197. nstats.tot_chains,
  198. nstats.min_chain_len,
  199. nstats.max_chain_len,
  200. nstats.avg_chain_len);
  201. /*
  202. * INDEX table stats...
  203. */
  204. IPAINFO("Able to add (%u) records to %s "
  205. "IDX table of size (%u) or (%f) percent\n",
  206. tot,
  207. mem_type,
  208. istats.tot_ents,
  209. ((float) tot / (float) istats.tot_ents) * 100.0);
  210. IPAINFO("Able to add (%u) records to %s "
  211. "IDX BASE table of size (%u) or (%f) percent\n",
  212. istats.tot_base_ents_filled,
  213. mem_type,
  214. istats.tot_base_ents,
  215. ((float) istats.tot_base_ents_filled /
  216. (float) istats.tot_base_ents) * 100.0);
  217. IPAINFO("Able to add (%u) records to %s "
  218. "IDX EXPN table of size (%u) or (%f) percent\n",
  219. istats.tot_expn_ents_filled,
  220. mem_type,
  221. istats.tot_expn_ents,
  222. ((float) istats.tot_expn_ents_filled /
  223. (float) istats.tot_expn_ents) * 100.0);
  224. IPAINFO("%s IDX table chains: tot_chains(%u) min_len(%u) max_len(%u) avg_len(%f)\n",
  225. mem_type,
  226. istats.tot_chains,
  227. istats.min_chain_len,
  228. istats.max_chain_len,
  229. istats.avg_chain_len);
  230. IPAINFO("Deleting all rules\n");
  231. for ( i = 0; i < tot; i++ )
  232. {
  233. IPADBG("Trying %d ipa_nat_del_ipv4_rule(0x%08X)\n",
  234. i, rule_hdls[i]);
  235. ret = ipa_nat_del_ipv4_rule(tbl_hdl, rule_hdls[i]);
  236. CHECK_ERR_TBL_STOP(ret, tbl_hdl);
  237. IPADBG("Success ipa_nat_del_ipv4_rule(%d)\n", i);
  238. }
  239. if ( sep )
  240. {
  241. ret = ipa_nat_del_ipv4_tbl(tbl_hdl);
  242. *tbl_hdl_ptr = 0;
  243. CHECK_ERR(ret);
  244. }
  245. IPADBG("Out\n");
  246. return 0;
  247. }