HeaderProcessingContextTestFixture.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /*
  2. * Copyright (c) 2017-2019 The Linux Foundation. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are
  6. * met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above
  10. * copyright notice, this list of conditions and the following
  11. * disclaimer in the documentation and/or other materials provided
  12. * with the distribution.
  13. * * Neither the name of The Linux Foundation nor the names of its
  14. * contributors may be used to endorse or promote products derived
  15. * from this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
  18. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
  20. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
  21. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  22. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  23. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  24. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  25. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  26. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  27. * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. #include <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 "HeaderInsertion.h"
  42. #include "RoutingDriverWrapper.h"
  43. #include "IPAFilteringTable.h"
  44. /*
  45. Processing context test design:
  46. 1. 1 Producer with RNDIS de-aggregation and ETH2 header removal.
  47. 2. 1 Producer with WLAN and ETH2 header removal.
  48. 3. 1 default consumer.
  49. 4. 1 RNDIS aggregation consumer.
  50. 5. 1 FLT rule – accept all - points to 1 RT rule.
  51. 6. 1 RT rule – accept all - points to specific test relevant proc_ctx.
  52. 7. All tests add all proc_ctx (for all tests).
  53. 8. Proc_ctx to be added: 1 for each test – 3 altogether.
  54. Proc_ctx of test 01 and 03 are the same.
  55. 9. Each test will send 1 packet and check that the packet is good
  56. except test 03.
  57. 10. Test 03 the same as Test 01 but will send multiple packets
  58. and expect 1 (RNDIS aggregation test).
  59. List of tests:
  60. 00. Header insertion scenario of [RNDIS][ETH_II][IP] -> [WLAN][ETH_II][IP]
  61. 01. Header insertion scenario of [WLAN][ETH_II][IP] -> [RNDIS][ETH_II][IP]
  62. 02. Header insertion scenario of [WLAN][ETH_II][IP] -> [WLAN’][ETH_II][IP]
  63. 03. Header insertion of [WLAN][ETH_II][IP] -> [RNDIS][ETH_II][IP]
  64. with RNDIS aggregation.
  65. 04. Header insertion scenario when adding total header sizes > 2048
  66. 05. Header insertion scenario of [ETH_II][IP] -> [WLAN][ETH_II][IP]
  67. 06. Header insertion scenario of [WLAN][ETH_II][IP] -> [ETH_II][IP
  68. 07. Header insertion scenario of [ETH_II][IP] -> [ETH_II][IP]
  69. 08. Header insertion scenario of [RNDIS][ETH_II][IP] -> [WLAN][802.3][IP]
  70. 09. Header insertion scenario of [WLAN][802.3][IP] -> [RNDIS][ETH_II][IP]
  71. 10. Header insertion scenario of [ETH_II][IP] -> [WLAN][802.3][IP]
  72. 11. Header insertion scenario of [WLAN][802.3][IP] -> [WLAN’][802.3][IP]
  73. */
  74. class IpaHdrProcCtxTestFixture : public TestBase
  75. {
  76. public:
  77. enum HeaderHandleId
  78. {
  79. HEADER_HANDLE_ID_WLAN_ETH2,
  80. HEADER_HANDLE_ID_RNDIS_ETH2,
  81. HEADER_HANDLE_ID_ETH2,
  82. HEADER_HANDLE_ID_WLAN_802_3,
  83. HEADER_HANDLE_ID_VLAN_802_1Q,
  84. HEADER_HANDLE_ID_MAX
  85. };
  86. enum ProcCtxHandleId
  87. {
  88. PROC_CTX_HANDLE_ID_ETH2_2_WLAN_ETH2,
  89. PROC_CTX_HANDLE_ID_ETH2_2_RNDIS_ETH2,
  90. PROC_CTX_HANDLE_ID_ETH2_ETH2_2_ETH2,
  91. PROC_CTX_HANDLE_ID_WLAN_ETH2_2_802_3,
  92. PROC_CTX_HANDLE_ID_RNDIS_802_3_2_ETH2,
  93. PROC_CTX_HANDLE_ID_WLAN_802_3_2_ETH2,
  94. PROC_CTX_HANDLE_ID_802_1Q_2_802_1Q,
  95. PROC_CTX_HANDLE_ID_ETH2_2_802_1Q,
  96. PROC_CTX_HANDLE_ID_802_1Q_2_ETH2,
  97. PROC_CTX_HANDLE_ID_ETH2_ETH2_2_ETH2_EX,
  98. PROC_CTX_HANDLE_ID_MAX
  99. };
  100. // header table consist of 9 bits and 4B units -> 2048
  101. static const int m_ALL_HEADER_SIZE_LIMIT = 2048;
  102. static const size_t m_BUFF_MAX_SIZE =
  103. 2 * RNDISAggregationHelper::RNDIS_AGGREGATION_BYTE_LIMIT;
  104. // [WLAN][ETH2] header
  105. static const Byte WLAN_ETH2_HDR[WLAN_ETH2_HDR_SIZE];
  106. // [ETH2] header
  107. static const Byte ETH2_HDR[ETH_HLEN];
  108. // [ETH2_802_1Q] vlan header
  109. static const Byte ETH2_8021Q_HDR[ETH8021Q_HEADER_LEN];
  110. // [WLAN][802.3] header
  111. static const Byte WLAN_802_3_HDR[WLAN_802_3_HDR_SIZE];
  112. static Filtering m_filtering;
  113. static RoutingDriverWrapper m_routing;
  114. static HeaderInsertion m_headerInsertion;
  115. // For each header type the handle is saved
  116. // to be used by the processing context
  117. uint32_t m_headerHandles[HEADER_HANDLE_ID_MAX];
  118. // For each prco_ctx type the handle is saved
  119. // to be used by the routing rule
  120. uint32_t m_procCtxHHandles[PROC_CTX_HANDLE_ID_MAX];
  121. // proc_ctx handle ID
  122. ProcCtxHandleId m_procCtxHandleId;
  123. // routing table handle
  124. uint32_t m_routingTableHdl;
  125. // Pipe with RNDIS and ETH2 header removal
  126. InterfaceAbstraction m_rndisEth2Producer;
  127. // Pipe with WLAN and ETH2 header removal
  128. InterfaceAbstraction m_wlanEth2producer;
  129. // Pipe with ETH2 header removal
  130. InterfaceAbstraction m_eth2Producer;
  131. // TODO: Pipe with WLAN and 802.3 header removal
  132. InterfaceAbstraction m_wlan802_3producer;
  133. // Pointer to current producer pipe used in the test
  134. InterfaceAbstraction *m_pCurrentProducer;
  135. ipa_client_type m_currProducerClient;
  136. // Pipe of the WLAN ETH2 consumer
  137. InterfaceAbstraction m_defaultConsumer;
  138. // Pipe of the RNDIS ETH2 consumer
  139. InterfaceAbstraction m_rndisEth2Consumer;
  140. // Pointer to current consumer pipe used in the test
  141. InterfaceAbstraction *m_pCurrentConsumer;
  142. ipa_client_type m_currConsumerPipeNum;
  143. // First input packet
  144. Byte m_sendBuffer1[m_BUFF_MAX_SIZE];
  145. size_t m_sendSize1;
  146. // Second input packet
  147. Byte m_sendBuffer2[m_BUFF_MAX_SIZE];
  148. size_t m_sendSize2;
  149. // First expected packet
  150. Byte m_expectedBuffer1[m_BUFF_MAX_SIZE];
  151. size_t m_expectedBufferSize1;
  152. enum ipa_ip_type m_IpaIPType;
  153. IpaHdrProcCtxTestFixture();
  154. virtual bool Setup();
  155. virtual bool Teardown();
  156. virtual void AddAllHeaders();
  157. // Insert a single header
  158. virtual void AddHeader(HeaderHandleId handleId);
  159. virtual void AddAllProcCtx();
  160. // Insert a single proc_ctx
  161. virtual void AddProcCtx(ProcCtxHandleId handleId);
  162. virtual void AddRtBypassRule(uint32_t hdrHdl, uint32_t procCtxHdl);
  163. virtual void AddFltBypassRule();
  164. virtual bool LoadPackets(enum ipa_ip_type ip) = 0;
  165. virtual bool ReceivePacketsAndCompare();
  166. // Create 1 IPv4 bypass routing entry and commits it
  167. virtual bool CreateIPv4BypassRoutingTable (
  168. const char *name,
  169. uint32_t hdrHdl,
  170. uint32_t procCtxHdl);
  171. virtual bool GenerateExpectedPackets() = 0;
  172. virtual bool AddRules();
  173. virtual bool SendPackets();
  174. virtual bool Run();
  175. ~IpaHdrProcCtxTestFixture();
  176. private:
  177. };