sm8750: init kernel modules repo
This commit is contained in:
66
qcom/opensource/dataipa/kernel-tests/Android.bp
Normal file
66
qcom/opensource/dataipa/kernel-tests/Android.bp
Normal file
@@ -0,0 +1,66 @@
|
||||
cc_binary {
|
||||
name: "ipa-kernel-tests",
|
||||
|
||||
cflags: ["-Wno-missing-field-initializers"] + ["-Wno-int-to-pointer-cast"] + ["-Wno-int-conversion"],
|
||||
|
||||
header_libs: ["device_kernel_headers"]+["qti_kernel_headers"]+["qti_ipa_kernel_headers"]+["qti_ipa_test_kernel_headers"],
|
||||
|
||||
srcs: [
|
||||
"DataPathTestFixture.cpp",
|
||||
"DataPathTests.cpp",
|
||||
"ExceptionsTestFixture.cpp",
|
||||
"ExceptionsTests.cpp",
|
||||
"ExceptionTests.cpp",
|
||||
"Feature.cpp",
|
||||
"Filtering.cpp",
|
||||
"FilteringEthernetBridgingTestFixture.cpp",
|
||||
"FilteringEthernetBridgingTests.cpp",
|
||||
"FilteringTest.cpp",
|
||||
"HeaderInsertion.cpp",
|
||||
"HeaderInsertionTests.cpp",
|
||||
"HeaderProcessingContextTestFixture.cpp",
|
||||
"HeaderProcessingContextTests.cpp",
|
||||
"HeaderRemovalTestFixture.cpp",
|
||||
"HeaderRemovalTests.cpp",
|
||||
"InterfaceAbstraction.cpp",
|
||||
"IPAFilteringTable.cpp",
|
||||
"IPAInterruptsTestFixture.cpp",
|
||||
"IPAInterruptsTests.cpp",
|
||||
"IPv4Packet.cpp",
|
||||
"IPv6CTTest.cpp",
|
||||
"Logger.cpp",
|
||||
"main.cpp",
|
||||
"MBIMAggregationTestFixtureConf11.cpp",
|
||||
"MBIMAggregationTests.cpp",
|
||||
"NatTest.cpp",
|
||||
"Pipe.cpp",
|
||||
"PipeTestFixture.cpp",
|
||||
"PipeTests.cpp",
|
||||
"RNDISAggregationTestFixture.cpp",
|
||||
"RNDISAggregationTests.cpp",
|
||||
"RoutingDriverWrapper.cpp",
|
||||
"RoutingTests.cpp",
|
||||
"TestBase.cpp",
|
||||
"TestManager.cpp",
|
||||
"TestsUtils.cpp",
|
||||
"TLPAggregationTestFixture.cpp",
|
||||
"TLPAggregationTests.cpp",
|
||||
],
|
||||
|
||||
vendor: true,
|
||||
rtti: true,
|
||||
|
||||
shared_libs:
|
||||
["libc++",
|
||||
"libipanat"],
|
||||
|
||||
relative_install_path: "ipa-kernel-tests",
|
||||
|
||||
|
||||
}
|
||||
|
||||
IPA_KERNEL_TESTS_FILE_LIST = [
|
||||
"README.txt",
|
||||
"run.sh",
|
||||
]
|
||||
|
||||
395
qcom/opensource/dataipa/kernel-tests/Constants.h
Normal file
395
qcom/opensource/dataipa/kernel-tests/Constants.h
Normal file
@@ -0,0 +1,395 @@
|
||||
/*
|
||||
* Copyright (c) 2017,2019 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef CONSTANTS_H_
|
||||
#define CONSTANTS_H_
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define PRE_PHASE_ZERO_TEST_CONFIGURATION 0
|
||||
/*----------------------------------------------------------------------
|
||||
*Configuration 1 (see configure_system_1 )
|
||||
*-----USB_PROD--->[IPA DMA]----USB_CONS--->
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
#define PHASE_ZERO_TEST_CONFIGURATION 1
|
||||
/*----------------------------------------------------------------------
|
||||
*Configuration 2 (see configure_system_2 )
|
||||
* [IPA]----USB2_CONS-->
|
||||
*-----USB_PROD--->[IPA]----USB3_CONS--->
|
||||
* [IPA]----USB4_CONS--->
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
#define PHASE_TWO_TEST_CONFIGURATION 2
|
||||
/*----------------------------------------------------------------------
|
||||
*Configuration 3 (see configure_system_3 )
|
||||
* [IPA]----USB_CONS------>
|
||||
*-----USB2_PROD--->[IPA]----USB2_CONS--->
|
||||
* [IPA]----USB4_CONS---->
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
#define PHASE_THREE_TEST_CONFIGURATION 3
|
||||
/*Configuration 5 (see configure_system_5 )
|
||||
* [IPA]----USB2_CONS + Header Insertion (6Bytes) -->
|
||||
*-----USB_PROD--->[IPA]----USB3_CONS +
|
||||
*Header Insertion (22Bytes) + Length offset (11Bytes) -->
|
||||
* [IPA]----USB4_CONS +
|
||||
*Header Insertion (22Bytes) + Length offset (11Bytes) + Const(1Byte)-->
|
||||
*/
|
||||
|
||||
/* This Cfg is only for USB Integration Phase I*/
|
||||
#define PHASE_FIVE_TEST_CONFIGURATION 5
|
||||
#define PHASE_SIX_TEST_CONFIGURATION 6
|
||||
/*Configuration 7 (see configure_system_7 )
|
||||
* [IPA]----USB2_CONS-->
|
||||
*-----USB_PROD--->[IPA]----USB3_CONS--->
|
||||
* [IPA]----USB4_CONS--->
|
||||
* [IPA]----A5 - Exception Pipe--->
|
||||
*/
|
||||
#define PHASE_SEVEN_TEST_CONFIGURATION 7
|
||||
/*----------------------------------------------------------------------
|
||||
*Configuration 8 (see configure_system_8 )
|
||||
*-----USB3_CONS--->[IPA DMA]----USB_CONS (TLP aggregation byte limit)--->
|
||||
*-----USB_PROD (TLP deaggregation)--->[IPA DMA]----USB3_CONS--->
|
||||
*-----USB2_PROD (TLP deaggregation)--->
|
||||
*-----[IPA DMA]----USB_CONS (TLP aggregation byte limit)--->
|
||||
*-----USB4_PROD--->[IPA DMA]----USB2_CONS (TLP aggregation time limit)--->
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
#define PHASE_EIGHT_TEST_CONFIGURATION 8
|
||||
/*----------------------------------------------------------------------
|
||||
*Configuration 9 (see configure_system_9 )
|
||||
*-----USB3_PROD--->[IPA DMA]----USB_CONS (MBIM aggregation byte limit)--->
|
||||
*-----USB_PROD (MBIM deaggregation)--->[IPA DMA]----USB3_CONS--->
|
||||
*-----USB2_PROD (MBIM deaggregation)--->
|
||||
*-----[IPA DMA]----USB_CONS (MBIM aggregation byte limit)--->
|
||||
*-----USB4_PROD--->[IPA DMA]----USB2_CONS (MBIM aggregation time limit)--->
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
#define PHASE_NINE_TEST_CONFIGURATION 9
|
||||
/*----------------------------------------------------------------------
|
||||
*Configuration 10 (see configure_system_10 )
|
||||
*-----USB_PROD--->[IPA DMA]----USB_CONS (MBIM aggregation no limits)--->
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
#define PHASE_TEN_TEST_CONFIGURATION 10
|
||||
/*----------------------------------------------------------------------
|
||||
*Configuration 11 (see configure_system_11 )
|
||||
*-----USB_PROD----->[IPA]----
|
||||
* USB2_CONS(MBIM aggregation byte limit)--->
|
||||
*-USB2_PROD (MBIM deaggregation)->[IPA]----USB3_CONS--->
|
||||
*------------------>[IPA]----
|
||||
*USB_CONS (MBIM aggregation time limit)----------->
|
||||
*------------------>[IPA]----
|
||||
*A5_LAN_WAN_CONS (MBIM aggregation no limits)---->
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
#define PHASE_ELEVEN_TEST_CONFIGURATION 11
|
||||
/*----------------------------------------------------------------------
|
||||
*Configuration 12 (see configure_system_12 )
|
||||
*-----USB_PROD----->[IPA]----USB2_CONS (MBIM aggregation byte limit)--->
|
||||
*-USB2_PROD (MBIM deaggregation)->[IPA]----USB3_CONS--->
|
||||
*------------------>[IPA]----
|
||||
* USB_CONS (MBIM aggregation time limit)----------->
|
||||
*------------------>[IPA]----
|
||||
* A5_LAN_WAN_CONS (MBIM aggregation no limits)---->
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
#define PHASE_TWELVE_TEST_CONFIGURATION 12
|
||||
/*----------------------------------------------------------------------
|
||||
*Configuration 9 (see configure_system_17 )
|
||||
*-----USB3_PROD--->[IPA DMA]----USB_CONS (RNDIS aggregation byte limit)--->
|
||||
*-----USB_PROD (RNDIS deaggregation)--->[IPA DMA]----USB3_CONS--->
|
||||
*-----USB2_PROD (RNDIS deaggregation)--->
|
||||
*-----[IPA DMA]----USB_CONS (RNDIS aggregation byte limit)--->
|
||||
*-----USB4--->[IPA DMA]----USB2_CONS (RNDIS aggregation time limit)--->
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
#define PHASE_SEVENTEEN_TEST_CONFIGURATION 17
|
||||
|
||||
/*
|
||||
* Data path test
|
||||
*/
|
||||
#define PHASE_EIGHTEEN_TEST_CONFIGURATION 18
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
*Configuration 19 (see configure_system_19 )
|
||||
*-----USB_PROD--->[IPA DMA]----USB_CONS--->
|
||||
*-----suspend [IPA DMA]----USB_CONS (for testing suspend interrupt)--->
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
#define PHASE_NINETEEN_TEST_CONFIGURATION 19
|
||||
|
||||
#define PHASE_TWENTY_TEST_CONFIGURATION 20
|
||||
/*----------------------------------------------------------------------
|
||||
*Configuration 20 (see configure_system_20 )
|
||||
*-----PROD (WLAN header removal)--------------------->[IPA]----CONS---->
|
||||
*-----PROD (RNDIS de-aggregation + Header removal)--->[IPA]
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
enum IPATestConfiguration {
|
||||
IPA_TEST_CONFIFURATION_0 = PRE_PHASE_ZERO_TEST_CONFIGURATION,
|
||||
IPA_TEST_CONFIFURATION_1 = PHASE_ZERO_TEST_CONFIGURATION,
|
||||
IPA_TEST_CONFIFURATION_2 = PHASE_TWO_TEST_CONFIGURATION,
|
||||
IPA_TEST_CONFIFURATION_3 = PHASE_THREE_TEST_CONFIGURATION,
|
||||
IPA_TEST_CONFIFURATION_5 = PHASE_FIVE_TEST_CONFIGURATION,
|
||||
IPA_TEST_CONFIFURATION_6 = PHASE_SIX_TEST_CONFIGURATION,
|
||||
IPA_TEST_CONFIFURATION_7 = PHASE_SEVEN_TEST_CONFIGURATION,
|
||||
IPA_TEST_CONFIGURATION_8 = PHASE_EIGHT_TEST_CONFIGURATION,
|
||||
IPA_TEST_CONFIGURATION_9 = PHASE_NINE_TEST_CONFIGURATION,
|
||||
IPA_TEST_CONFIGURATION_10 = PHASE_TEN_TEST_CONFIGURATION,
|
||||
IPA_TEST_CONFIGURATION_11 = PHASE_ELEVEN_TEST_CONFIGURATION,
|
||||
IPA_TEST_CONFIGURATION_12 = PHASE_TWELVE_TEST_CONFIGURATION,
|
||||
IPA_TEST_CONFIGURATION_17 = PHASE_SEVENTEEN_TEST_CONFIGURATION,
|
||||
IPA_TEST_CONFIGURATION_18 = PHASE_EIGHTEEN_TEST_CONFIGURATION,
|
||||
IPA_TEST_CONFIGURATION_19 = PHASE_NINETEEN_TEST_CONFIGURATION,
|
||||
IPA_TEST_CONFIGURATION_20 = PHASE_NINETEEN_TEST_CONFIGURATION,
|
||||
};
|
||||
#define CONFIGURATION_NODE_PATH "/dev/ipa_test"
|
||||
|
||||
/*producer*/
|
||||
#define INTERFACE0_TO_IPA_DATA_PATH "/dev/to_ipa_0"
|
||||
#define INTERFACE0_FROM_IPA_DATA_PATH NULL
|
||||
|
||||
/*producer*/
|
||||
#define INTERFACE4_TO_IPA_DATA_PATH "/dev/to_ipa_1"
|
||||
#define INTERFACE4_FROM_IPA_DATA_PATH NULL
|
||||
|
||||
/*producer*/
|
||||
#define INTERFACE5_TO_IPA_DATA_PATH "/dev/to_ipa_2"
|
||||
#define INTERFACE5_FROM_IPA_DATA_PATH NULL
|
||||
|
||||
/*consumer*/
|
||||
#define INTERFACE1_TO_IPA_DATA_PATH NULL
|
||||
#define INTERFACE1_FROM_IPA_DATA_PATH "/dev/from_ipa_0"
|
||||
|
||||
/*consumer 2*/
|
||||
#define INTERFACE2_TO_IPA_DATA_PATH NULL
|
||||
#define INTERFACE2_FROM_IPA_DATA_PATH "/dev/from_ipa_1"
|
||||
|
||||
/*Default consumer*/
|
||||
#define INTERFACE3_TO_IPA_DATA_PATH NULL
|
||||
#define INTERFACE3_FROM_IPA_DATA_PATH "/dev/from_ipa_2"
|
||||
|
||||
/*Exceptions producer*/
|
||||
#define INTERFACE_TO_IPA_EXCEPTION_PATH NULL
|
||||
#define INTERFACE_FROM_IPA_EXCEPTION_PATH "/dev/ipa_exception_pipe"
|
||||
|
||||
/*The next configuration should be used by the ITAKEM as well.*/
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
*Configuration 1 (see configure_system_1 )
|
||||
*-----USB_PROD--->[IPA DMA]----USB_CONS--->
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
#define CONFIG_1_FROM_USB1_TO_IPA_DMA "/dev/to_ipa_0"
|
||||
#define CONFIG_1_FROM_IPA_TO_USB1_DMA "/dev/from_ipa_0"
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
*Configuration 2 (see configure_system_2 )
|
||||
* [IPA]----USB2_CONS-->
|
||||
*-----USB_PROD--->[IPA]----USB3_CONS--->
|
||||
* [IPA]----Q6_LAN_CONS--->
|
||||
*---------------------------------------------------------------------
|
||||
*/
|
||||
#define CONFIG_2_FROM_USB_TO_IPA "/dev/to_ipa_0"
|
||||
#define CONFIG_2_FROM_IPA_TO_A2_NDUN "/dev/from_ipa_0"
|
||||
#define CONFIG_2_FROM_IPA_TO_A2_DUN "/dev/from_ipa_1"
|
||||
#define CONFIG_2_FROM_IPA_TO_Q6_LAN "/dev/from_ipa_2"
|
||||
|
||||
/*USB1 is an EthernetII Client*/
|
||||
#define FROM_USB1_TO_IPA "/dev/to_ipa_0"
|
||||
#define FROM_IPA_TO_USB1 "/dev/from_ipa_0"
|
||||
#define USB1_CLIENT_HEADER_LENGTH 14
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
*Configuration 3 (see configure_system_3 )
|
||||
* [IPA]----USB_CONS------>
|
||||
*-----USB2_PROD--->[IPA]----USB2_CONS--->
|
||||
* [IPA]----Q6_LAN_CONS---->
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
#define CONFIG_3_FROM_A2_NDUN_TO_IPA "/dev/to_ipa_0"
|
||||
#define CONFIG_3_FROM_IPA_TO_USB1 "/dev/from_ipa_0"
|
||||
#define CONFIG_3_FROM_IPA_TO_A2_NDUN "/dev/from_ipa_1"
|
||||
#define CONFIG_3_FROM_IPA_TO_Q6_LAN "/dev/from_ipa_2"
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
*Configuration 8 (see configure_system_8 )
|
||||
*-----USB3_PROD--->[IPA DMA]----
|
||||
*-----USB_CONS (TLP aggregation byte limit)--->
|
||||
*-----USB_PROD (TLP deaggregation)--->[IPA DMA]----USB3_CONS--->
|
||||
*-----USB2_PROD (TLP deaggregation)--->
|
||||
* [IPA DMA]----USB_CONS (TLP aggregation byte limit)--->
|
||||
*-----USB4--->[IPA DMA]----USB2_CONS (TLP aggregation time limit)--->
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
#define CONFIG_8_NO_AGG_TO_IPA_AGG "/dev/to_ipa_0"
|
||||
#define CONFIG_8_DEAGG_TO_IPA_NO_AGG "/dev/to_ipa_1"
|
||||
#define CONFIG_8_DEAGG_TO_IPA_AGG "/dev/to_ipa_2"
|
||||
#define CONFIG_8_NO_AGG_TO_IPA_AGG_TIME "/dev/to_ipa_3"
|
||||
#define CONFIG_8_FROM_IPA_AGG "/dev/from_ipa_0"
|
||||
#define CONFIG_8_FROM_IPA_NO_AGG "/dev/from_ipa_1"
|
||||
#define CONFIG_8_DEAGG_FROM_IPA_AGG "/dev/from_ipa_2"
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
*Configuration 9 (see configure_system_9 )
|
||||
*-----USB3_PROD--->[IPA DMA]----
|
||||
* USB_CONS (MBIM aggregation byte limit)--->
|
||||
*-----USB_PROD (MBIM deaggregation)--->[IPA DMA]----USB3_CONS--->
|
||||
*-----USB2_PROD (MBIM deaggregation)--->
|
||||
* [IPA DMA]----USB_CONS (MBIM aggregation byte limit)--->
|
||||
*-----USB4--->[IPA DMA]----
|
||||
* USB2_CONS (MBIM aggregation time limit)--->
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
#define CONFIG_9_NO_AGG_TO_IPA_AGG "/dev/to_ipa_0"
|
||||
#define CONFIG_9_DEAGG_TO_IPA_NO_AGG "/dev/to_ipa_1"
|
||||
#define CONFIG_9_DEAGG_TO_IPA_AGG "/dev/to_ipa_2"
|
||||
#define CONFIG_9_NO_AGG_TO_IPA_AGG_TIME "/dev/to_ipa_3"
|
||||
#define CONFIG_9_FROM_IPA_AGG "/dev/from_ipa_0"
|
||||
#define CONFIG_9_FROM_IPA_NO_AGG "/dev/from_ipa_1"
|
||||
#define CONFIG_9_DEAGG_FROM_IPA_AGG "/dev/from_ipa_2"
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
*Configuration 10 (see configure_system_10 )
|
||||
*-----USB_PROD--->[IPA DMA]----
|
||||
* USB_CONS (MBIM aggregation no limits)--->
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
#define CONFIG_10_TO_IPA_AGG_ZERO_LIMITS "/dev/to_ipa_0"
|
||||
#define CONFIG_10_FROM_IPA_AGG_ZERO_LIMITS "/dev/from_ipa_0"
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
*Configuration 11 (see configure_system_11 )
|
||||
*-----USB_PROD----->[IPA]----
|
||||
* USB2_CONS (MBIM aggregation byte limit)--->
|
||||
* USB2_PROD (MBIM deaggregation)->[IPA]----USB3_CONS--->
|
||||
*------------------>[IPA]----
|
||||
* USB_CONS (MBIM aggregation time limit)----------->
|
||||
*------------------>[IPA
|
||||
* A5_LAN_WAN_CONS (MBIM aggregation no limits)---->
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
#define CONFIG_11_TO_IPA "/dev/to_ipa_0"
|
||||
#define CONFIG_11_TO_IPA_DEAGG "/dev/to_ipa_1"
|
||||
#define CONFIG_11_FROM_IPA_AGG "/dev/from_ipa_0"
|
||||
#define CONFIG_11_FROM_IPA "/dev/from_ipa_1"
|
||||
#define CONFIG_11_FROM_IPA_AGG_TIME "/dev/from_ipa_2"
|
||||
#define CONFIG_11_FROM_IPA_ZERO_LIMITS "/dev/from_ipa_3"
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
*Configuration 12 (see configure_system_12 )
|
||||
*-----USB_PROD----->[IPA]----
|
||||
* USB2_CONS (MBIM aggregation byte limit)--->
|
||||
*-USB2_PROD (MBIM deaggregation)->[IPA]----USB3_CONS--->
|
||||
*------------------>[IPA]----
|
||||
* USB_CONS (MBIM aggregation time limit)----------->
|
||||
*------------------>[IPA]----
|
||||
* A5_LAN_WAN_CONS (MBIM aggregation no limits)---->
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
#define CONFIG_12_TO_IPA "/dev/to_ipa_0"
|
||||
#define CONFIG_12_TO_IPA_DEAGG "/dev/to_ipa_1"
|
||||
#define CONFIG_12_FROM_IPA_AGG "/dev/from_ipa_0"
|
||||
#define CONFIG_12_FROM_IPA "/dev/from_ipa_1"
|
||||
#define CONFIG_12_FROM_IPA_AGG_TIME "/dev/from_ipa_2"
|
||||
#define CONFIG_12_FROM_IPA_ZERO_LIMITS "/dev/from_ipa_3"
|
||||
|
||||
/*Configuration 7 (see configure_system_7 )
|
||||
* [IPA]----USB2_CONS-->
|
||||
*-----USB_PROD--->[IPA]----USB3_CONS--->
|
||||
* [IPA]----Q6_LAN_CONS--->
|
||||
* [IPA]----A5 - Exception Pipe--->
|
||||
*/
|
||||
#define CONFIG_7_FROM_USB1_TO_IPA "/dev/to_ipa_0"
|
||||
#define CONFIG_7_FROM_IPA_TO_A5_EXCEPTION "/dev/ipa_exception_pipe"
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
*Configuration 17 (see configure_system_17 )
|
||||
*-----USB_PROD----->[IPA]----
|
||||
* USB2_CONS (RNDIS aggregation byte limit)--->
|
||||
* USB2_PROD (RNDIS deaggregation)->[IPA]----USB3_CONS--->
|
||||
*------------------>[IPA]----
|
||||
* USB_CONS (RNDIS aggregation time limit)----------->
|
||||
*------------------>[IPA]----
|
||||
* A5_LAN_WAN_CONS (RNDIS aggregation no limits)---->
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
#define CONFIG_17_TO_IPA "/dev/to_ipa_0"
|
||||
#define CONFIG_17_TO_IPA_NO_HDR "/dev/to_ipa_1"
|
||||
#define CONFIG_17_TO_IPA_DEAGG "/dev/to_ipa_2"
|
||||
#define CONFIG_17_FROM_IPA_AGG "/dev/from_ipa_0"
|
||||
#define CONFIG_17_FROM_IPA "/dev/from_ipa_1"
|
||||
#define CONFIG_17_FROM_IPA_AGG_TIME "/dev/from_ipa_2"
|
||||
#define CONFIG_17_FROM_IPA_ZERO_LIMITS "/dev/from_ipa_3"
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
*Configuration 18 (see configure_system_18 )---------------------------
|
||||
*-----USB_PROD----->[IPA]--------------->USB_CONS--------->A5----------
|
||||
*-----USB_PROD2 is a dummy endpoint handle for packet handling between-
|
||||
*-----user space and kernel space in the IPA driver--------------------
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
#define CONFIG_18_TO_IPA "/dev/to_ipa_0"
|
||||
#define CONFIG_18_DUMMY_ENDPOINT "/dev/to_ipa_1"
|
||||
#define CONFIG_18_FROM_IPA "/dev/from_ipa_0"
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
*Configuration 19 (see configure_system_19 )
|
||||
*-----USB_PROD--->[IPA DMA]----USB_CONS--->
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
#define CONFIG_19_FROM_USB_TO_IPA_DMA "/dev/to_ipa_0"
|
||||
#define CONFIG_19_FROM_IPA_TO_USB_DMA "/dev/from_ipa_0"
|
||||
|
||||
enum ipv6_ext_hdr_type {
|
||||
HOP_BY_HOP_OPT = 0,
|
||||
DEST_OPT = 60,
|
||||
ROUTING = 43,
|
||||
FRAGMENT = 44,
|
||||
AH = 51,
|
||||
ESP = 50,
|
||||
DEST_OPT_UL = 60,
|
||||
Mobility = 135,
|
||||
NONE = 59
|
||||
};
|
||||
/*File that are being used by the test application:*/
|
||||
|
||||
#define IPV4_FILE_PATH "Input/IPV4_3"
|
||||
|
||||
/*---------------------------------------------------------------------
|
||||
*XUnit tests results format file name
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
#define XUNIT_REPORT_PATH_AND_NAME "junit_result.xml"
|
||||
|
||||
#endif /* CONSTANTS_H_ */
|
||||
105
qcom/opensource/dataipa/kernel-tests/DataPathTestFixture.cpp
Normal file
105
qcom/opensource/dataipa/kernel-tests/DataPathTestFixture.cpp
Normal file
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright (c) 2017 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "DataPathTestFixture.h"
|
||||
|
||||
Pipe DataPathTestFixture::m_FromIPAPipe(IPA_CLIENT_TEST_CONS,
|
||||
IPA_TEST_CONFIGURATION_18);
|
||||
Pipe DataPathTestFixture::m_ToIpaPipe(IPA_CLIENT_TEST_PROD,
|
||||
IPA_TEST_CONFIGURATION_18);
|
||||
Pipe DataPathTestFixture::m_IpaDriverPipe(IPA_CLIENT_TEST2_PROD,
|
||||
IPA_TEST_CONFIGURATION_18);
|
||||
|
||||
|
||||
RoutingDriverWrapper DataPathTestFixture::m_Routing;
|
||||
Filtering DataPathTestFixture::m_Filtering;
|
||||
HeaderInsertion DataPathTestFixture::m_HeaderInsertion;
|
||||
|
||||
DataPathTestFixture::DataPathTestFixture()
|
||||
{
|
||||
m_testSuiteName.push_back("DataPath");
|
||||
Register(*this);
|
||||
}
|
||||
|
||||
bool DataPathTestFixture::Setup()
|
||||
{
|
||||
bool bRetVal = true;
|
||||
|
||||
/*Set the configuration to support USB->IPA and IPA->USB pipes.*/
|
||||
ConfigureScenario(IPA_TEST_CONFIGURATION_18);
|
||||
|
||||
bRetVal &= m_ToIpaPipe.Init();
|
||||
bRetVal &= m_FromIPAPipe.Init();
|
||||
bRetVal &= m_IpaDriverPipe.Init();
|
||||
|
||||
if (!m_Routing.DeviceNodeIsOpened()) {
|
||||
LOG_MSG_ERROR(
|
||||
"Routing block is not ready for immediate commands!\n");
|
||||
return false;
|
||||
}
|
||||
if (!m_Filtering.DeviceNodeIsOpened()) {
|
||||
LOG_MSG_ERROR(
|
||||
"Filtering block is not ready for immediate commands!\n");
|
||||
return false;
|
||||
}
|
||||
if (!m_HeaderInsertion.DeviceNodeIsOpened())
|
||||
{
|
||||
LOG_MSG_ERROR("Header Insertion block is not ready for immediate commands!\n");
|
||||
return false;
|
||||
}\
|
||||
/*resetting this component will reset both Routing and Filtering tables*/
|
||||
m_HeaderInsertion.Reset();
|
||||
|
||||
return bRetVal;
|
||||
}
|
||||
|
||||
bool DataPathTestFixture::Teardown()
|
||||
{
|
||||
/*The Destroy method will close the inode.*/
|
||||
m_FromIPAPipe.Destroy();
|
||||
m_ToIpaPipe.Destroy();
|
||||
m_IpaDriverPipe.Destroy();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DataPathTestFixture::Run()
|
||||
{
|
||||
LOG_MSG_DEBUG("Entering Function");
|
||||
|
||||
if (!TestLogic()) {
|
||||
LOG_MSG_ERROR(
|
||||
"Test failed, Input and expected output mismatch.");
|
||||
return false;
|
||||
}
|
||||
|
||||
LOG_MSG_DEBUG("Leaving Function (Returning True)");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
82
qcom/opensource/dataipa/kernel-tests/DataPathTestFixture.h
Normal file
82
qcom/opensource/dataipa/kernel-tests/DataPathTestFixture.h
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (c) 2017 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef DATAPATHTESTFIXTURE_H_
|
||||
#define DATAPATHTESTFIXTURE_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <linux/if_ether.h>
|
||||
|
||||
#include "Constants.h"
|
||||
#include "Logger.h"
|
||||
#include "linux/msm_ipa.h"
|
||||
#include "TestsUtils.h"
|
||||
#include "TestBase.h"
|
||||
#include "Pipe.h"
|
||||
#include "RoutingDriverWrapper.h"
|
||||
#include "HeaderInsertion.h"
|
||||
#include "Filtering.h"
|
||||
#include "IPAFilteringTable.h"
|
||||
|
||||
class DataPathTestFixture:public TestBase
|
||||
{
|
||||
public:
|
||||
/*
|
||||
* This Constructor will register each instance
|
||||
* that it creates.
|
||||
*/
|
||||
DataPathTestFixture();
|
||||
|
||||
/*
|
||||
* This method will create and initialize two Pipe object for the USB
|
||||
* (Ethernet) Pipes, one as input and the other as output.
|
||||
*/
|
||||
virtual bool Setup();
|
||||
|
||||
/*This method will destroy the pipes.*/
|
||||
virtual bool Teardown();
|
||||
|
||||
virtual bool Run();
|
||||
|
||||
virtual bool TestLogic() = 0;
|
||||
|
||||
/*The client type are set from the peripheral perspective*/
|
||||
static Pipe m_FromIPAPipe;
|
||||
static Pipe m_ToIpaPipe;
|
||||
static Pipe m_IpaDriverPipe;
|
||||
|
||||
static RoutingDriverWrapper m_Routing;
|
||||
static Filtering m_Filtering;
|
||||
static HeaderInsertion m_HeaderInsertion;
|
||||
};
|
||||
#endif /* DATAPATHTESTFIXTURE_H_ */
|
||||
391
qcom/opensource/dataipa/kernel-tests/DataPathTests.cpp
Normal file
391
qcom/opensource/dataipa/kernel-tests/DataPathTests.cpp
Normal file
@@ -0,0 +1,391 @@
|
||||
/*
|
||||
* Copyright (c) 2017,2020 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include "hton.h" /* for htonl*/
|
||||
#include "DataPathTestFixture.h"
|
||||
#include "Constants.h"
|
||||
#include "TestsUtils.h"
|
||||
#include "linux/msm_ipa.h"
|
||||
|
||||
#define PACKET_SIZE ((10)*(4))
|
||||
|
||||
class IpaTxDpTest:public DataPathTestFixture {
|
||||
|
||||
public:
|
||||
IpaTxDpTest() {
|
||||
m_name = "IpaTxDpTest";
|
||||
m_description = "Sending one SKB via ipa_tx_dp() and checking"
|
||||
"if it was received";
|
||||
m_runInRegression = true;
|
||||
}
|
||||
|
||||
bool TestLogic() {
|
||||
LOG_MSG_DEBUG("Entering %s\n", __func__);
|
||||
int ret;
|
||||
unsigned char *input, *output;
|
||||
unsigned char pkt[PACKET_SIZE] = {
|
||||
0x59, 0x61, 0x6e, 0x69,
|
||||
0x76, 0x5f, 0x48 ,0x61,
|
||||
0x73 ,0x62 ,0x61 ,0x6e,
|
||||
0x69 ,0x5f ,0x54 ,0x68,
|
||||
0x65 ,0x5f ,0x47 ,0x72,
|
||||
0x65 ,0x61 ,0x74 ,0x16,
|
||||
0x32 ,0x49 ,0x0c ,0x3f,
|
||||
0x37 ,0x23 ,0x6d ,0x15,
|
||||
0x50 ,0x10 ,0x3f ,0xbd,
|
||||
0xcc ,0xd8 ,0x00, 0x00
|
||||
};
|
||||
|
||||
input = (unsigned char *)malloc(PACKET_SIZE);
|
||||
if(!input) {
|
||||
LOG_MSG_ERROR("Error in allocation\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
output = (unsigned char *)malloc(PACKET_SIZE);
|
||||
if(!output) {
|
||||
LOG_MSG_ERROR("Error in allocation\n");
|
||||
free(input);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
memcpy(input, pkt, PACKET_SIZE);
|
||||
LOG_MSG_DEBUG("Sending packet through ipa_tx_dp() in func %s\n", __func__);
|
||||
ret = m_IpaDriverPipe.Send(input, PACKET_SIZE);
|
||||
|
||||
if (ret != PACKET_SIZE) {
|
||||
LOG_MSG_ERROR(
|
||||
"Amount of bits sent are: %d instead of %d\nExiting..\n"
|
||||
, ret
|
||||
, PACKET_SIZE);
|
||||
free(input);
|
||||
free(output);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = m_FromIPAPipe.Receive(output, PACKET_SIZE);
|
||||
if (ret != PACKET_SIZE) {
|
||||
LOG_MSG_ERROR(
|
||||
"Amount of bits sent are: %d instead of %d\nExiting..\n",
|
||||
ret,
|
||||
PACKET_SIZE);
|
||||
free(input);
|
||||
free(output);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
LOG_MSG_INFO("Input buff:\n");
|
||||
print_buff(input, PACKET_SIZE);
|
||||
LOG_MSG_INFO("Output buff:\n");
|
||||
print_buff(output, PACKET_SIZE);
|
||||
if (memcmp(input,output, PACKET_SIZE)) {
|
||||
free(input);
|
||||
free(output);
|
||||
return false;
|
||||
}
|
||||
|
||||
free(input);
|
||||
free(output);
|
||||
return true;
|
||||
fail:
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
class IpaTxDpMultipleTest:public DataPathTestFixture {
|
||||
|
||||
public:
|
||||
IpaTxDpMultipleTest() {
|
||||
m_name = "IpaTxDpMultipleTest";
|
||||
m_description = "Sending multiple SKB via ipa_tx_dp() and checking"
|
||||
"if it was received";
|
||||
m_runInRegression = false;
|
||||
}
|
||||
|
||||
bool TestLogic() {
|
||||
int packet_to_send = 10;
|
||||
int loop_size = 100;
|
||||
int i;
|
||||
int j;
|
||||
|
||||
LOG_MSG_DEBUG("Entering %s\n", __func__);
|
||||
int ret;
|
||||
unsigned char *input, *output;
|
||||
unsigned char pkt[PACKET_SIZE] = {
|
||||
0x59, 0x61, 0x6e, 0x69,
|
||||
0x76, 0x5f, 0x48 ,0x61,
|
||||
0x73 ,0x62 ,0x61 ,0x6e,
|
||||
0x69 ,0x5f ,0x54 ,0x68,
|
||||
0x65 ,0x5f ,0x47 ,0x72,
|
||||
0x65 ,0x61 ,0x74 ,0x16,
|
||||
0x32 ,0x49 ,0x0c ,0x3f,
|
||||
0x37 ,0x23 ,0x6d ,0x15,
|
||||
0x50 ,0x10 ,0x3f ,0xbd,
|
||||
0xcc ,0xd8 ,0x00, 0x00
|
||||
};
|
||||
|
||||
input = (unsigned char *)malloc(PACKET_SIZE);
|
||||
if(!input) {
|
||||
LOG_MSG_ERROR("Error in allocation\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
output = (unsigned char *)malloc(PACKET_SIZE);
|
||||
if(!output) {
|
||||
LOG_MSG_ERROR("Error in allocation\n");
|
||||
free(input);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
memcpy(input, pkt, PACKET_SIZE);
|
||||
for (i = 0; i < loop_size; i++) {
|
||||
for (j = 0; j < packet_to_send; j++) {
|
||||
input[0] = i;
|
||||
input[1] = j;
|
||||
LOG_MSG_DEBUG("Sending packet through ipa_tx_dp() in func %s\n", __func__);
|
||||
ret = m_IpaDriverPipe.Send(input, PACKET_SIZE);
|
||||
if (ret != PACKET_SIZE) {
|
||||
LOG_MSG_ERROR(
|
||||
"Amount of bits sent are: %d instead of %d\nExiting..\n"
|
||||
, ret
|
||||
, PACKET_SIZE);
|
||||
free(input);
|
||||
free(output);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
for (j = 0; j < packet_to_send; j++) {
|
||||
ret = m_FromIPAPipe.Receive(output, PACKET_SIZE);
|
||||
if (ret != PACKET_SIZE) {
|
||||
LOG_MSG_ERROR(
|
||||
"Amount of bits sent are: %d instead of %d\nExiting..\n",
|
||||
ret,
|
||||
PACKET_SIZE);
|
||||
free(input);
|
||||
free(output);
|
||||
goto fail;
|
||||
}
|
||||
input[0] = i;
|
||||
input[1] = j;
|
||||
LOG_MSG_INFO("Input buff:\n");
|
||||
print_buff(input, PACKET_SIZE);
|
||||
LOG_MSG_INFO("Output buff:\n");
|
||||
print_buff(output, PACKET_SIZE);
|
||||
if (memcmp(input,output, PACKET_SIZE)) {
|
||||
free(input);
|
||||
free(output);
|
||||
LOG_MSG_ERROR("Failed in buffers comparison");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
free(input);
|
||||
free(output);
|
||||
return true;
|
||||
fail:
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
class IPAToAppsTest:public DataPathTestFixture {
|
||||
|
||||
public:
|
||||
IPAToAppsTest() {
|
||||
m_name = "IPAToApps";
|
||||
m_description = "Sending one SKB via USB_PROD pipe and checking"
|
||||
"if it was received";
|
||||
m_runInRegression = true;
|
||||
}
|
||||
|
||||
bool TestLogic() {
|
||||
int ret;
|
||||
unsigned char *input, *output;
|
||||
unsigned char pkt[PACKET_SIZE] = {
|
||||
0x59, 0x61, 0x6e, 0x69,
|
||||
0x76, 0x5f, 0x48 ,0x61,
|
||||
0x73 ,0x62 ,0x61 ,0x6e,
|
||||
0x69 ,0x5f ,0x54 ,0x68,
|
||||
0x65 ,0x5f ,0x47 ,0x72,
|
||||
0x65 ,0x61 ,0x74 ,0x16,
|
||||
0x32 ,0x49 ,0x0c ,0x3f,
|
||||
0x37 ,0x23 ,0x6d ,0x15,
|
||||
0x50 ,0x10 ,0x3f ,0xbd,
|
||||
0xcc ,0xd8 ,0x00, 0x00
|
||||
};
|
||||
|
||||
input = (unsigned char *)malloc(PACKET_SIZE);
|
||||
if(!input) {
|
||||
LOG_MSG_ERROR("Error in allocation\n");
|
||||
goto fail;
|
||||
}
|
||||
output = (unsigned char *)malloc(PACKET_SIZE);
|
||||
if(!output) {
|
||||
LOG_MSG_ERROR("Error in allocation\n");
|
||||
free(input);
|
||||
goto fail;
|
||||
}
|
||||
memcpy(input, pkt, PACKET_SIZE);
|
||||
|
||||
LOG_MSG_DEBUG("Sending packet through USB_PROD pipe in func %s\n", __func__);
|
||||
ret = m_ToIpaPipe.Send(input, PACKET_SIZE);
|
||||
if (ret != PACKET_SIZE) {
|
||||
LOG_MSG_ERROR(
|
||||
"Amount of bits sent are: %d instead of %d\nExiting..\n",
|
||||
ret,
|
||||
PACKET_SIZE);
|
||||
goto fail;
|
||||
}
|
||||
LOG_MSG_DEBUG("Reading packet through Dummy Endpoint pipe in func %s\n", __func__);
|
||||
ret = m_IpaDriverPipe.Receive(output, PACKET_SIZE);
|
||||
if (ret != 0) {
|
||||
LOG_MSG_ERROR("Failed in reading buffer. %d error", ret);
|
||||
free(input);
|
||||
free(output);
|
||||
goto fail;
|
||||
}
|
||||
LOG_MSG_DEBUG("SKB original packet:\n");
|
||||
print_buff(input, PACKET_SIZE);
|
||||
LOG_MSG_DEBUG("SKB received packet:\n");
|
||||
print_buff(output, PACKET_SIZE);
|
||||
if (memcmp(input,output, PACKET_SIZE)) {
|
||||
free(input);
|
||||
free(output);
|
||||
return false;
|
||||
}
|
||||
free(input);
|
||||
free(output);
|
||||
return true;
|
||||
fail:
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
class IPAToAppsMultipleTest:public DataPathTestFixture {
|
||||
|
||||
public:
|
||||
IPAToAppsMultipleTest() {
|
||||
m_name = "IPAToAppsMultipleTest";
|
||||
m_description = "Sending multiple SKB via USB_PROD pipe and checking"
|
||||
"if they was received";
|
||||
m_runInRegression = false;
|
||||
}
|
||||
|
||||
bool TestLogic() {
|
||||
int packet_to_send = 10;
|
||||
int loop_size = 100;
|
||||
int i;
|
||||
int j;
|
||||
int ret;
|
||||
unsigned char *input, *output;
|
||||
unsigned char pkt[PACKET_SIZE] = {
|
||||
0x59, 0x61, 0x6e, 0x69,
|
||||
0x76, 0x5f, 0x48 ,0x61,
|
||||
0x73 ,0x62 ,0x61 ,0x6e,
|
||||
0x69 ,0x5f ,0x54 ,0x68,
|
||||
0x65 ,0x5f ,0x47 ,0x72,
|
||||
0x65 ,0x61 ,0x74 ,0x16,
|
||||
0x32 ,0x49 ,0x0c ,0x3f,
|
||||
0x37 ,0x23 ,0x6d ,0x15,
|
||||
0x50 ,0x10 ,0x3f ,0xbd,
|
||||
0xcc ,0xd8 ,0x00, 0x00
|
||||
};
|
||||
|
||||
input = (unsigned char *)malloc(PACKET_SIZE);
|
||||
if(!input) {
|
||||
LOG_MSG_ERROR("Error in allocation\n");
|
||||
goto fail;
|
||||
}
|
||||
output = (unsigned char *)malloc(PACKET_SIZE);
|
||||
if(!output) {
|
||||
LOG_MSG_ERROR("Error in allocation\n");
|
||||
free(input);
|
||||
goto fail;
|
||||
}
|
||||
memcpy(input, pkt, PACKET_SIZE);
|
||||
for (i = 0; i < loop_size; i++) {
|
||||
for (j = 0; j < packet_to_send; j++) {
|
||||
input[0] = i;
|
||||
input[1] = j;
|
||||
|
||||
LOG_MSG_DEBUG("Sending packet through USB_PROD pipe in func %s\n", __func__);
|
||||
ret = m_ToIpaPipe.Send(input, PACKET_SIZE);
|
||||
if (ret != PACKET_SIZE) {
|
||||
LOG_MSG_ERROR(
|
||||
"Amount of bits sent are: %d instead of %d\nExiting..\n",
|
||||
ret,
|
||||
PACKET_SIZE);
|
||||
free(input);
|
||||
free(output);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
for (j = 0; j < packet_to_send; j++) {
|
||||
input[0] = i;
|
||||
input[1] = j;
|
||||
LOG_MSG_DEBUG("Reading packet through Dummy Endpoint pipe in func %s\n", __func__);
|
||||
ret = m_IpaDriverPipe.Receive(output, PACKET_SIZE);
|
||||
if (ret != 0) {
|
||||
LOG_MSG_ERROR("Failed in reading buffer. %d error", ret);
|
||||
free(input);
|
||||
free(output);
|
||||
goto fail;
|
||||
}
|
||||
LOG_MSG_DEBUG("SKB original packet:\n");
|
||||
print_buff(input, PACKET_SIZE);
|
||||
LOG_MSG_DEBUG("SKB received packet:\n");
|
||||
print_buff(output, PACKET_SIZE);
|
||||
if (memcmp(input,output, PACKET_SIZE)) {
|
||||
free(input);
|
||||
free(output);
|
||||
LOG_MSG_ERROR("Failed in buffers comparison");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
free(input);
|
||||
free(output);
|
||||
return true;
|
||||
fail:
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
static IpaTxDpTest ipaTxDpTest;
|
||||
static IpaTxDpMultipleTest ipaTxDpMultipleTest;
|
||||
static IPAToAppsTest ipaToApps;
|
||||
static IPAToAppsMultipleTest iPAToAppsMultipleTestApps;
|
||||
506
qcom/opensource/dataipa/kernel-tests/ExceptionTests.cpp
Normal file
506
qcom/opensource/dataipa/kernel-tests/ExceptionTests.cpp
Normal file
@@ -0,0 +1,506 @@
|
||||
/*
|
||||
* Copyright (c) 2017 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* Changes from Qualcomm Innovation Center are provided under the following license:
|
||||
*
|
||||
* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted (subject to the limitations in the
|
||||
* disclaimer below) provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* * Neither the name of Qualcomm Innovation Center, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
|
||||
* GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
|
||||
* HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
|
||||
*/
|
||||
|
||||
#include "TestsUtils.h"
|
||||
#include "RoutingDriverWrapper.h"
|
||||
#include "HeaderInsertion.h"
|
||||
#include "Filtering.h"
|
||||
#include "IPAFilteringTable.h"
|
||||
#include "IPv4Packet.h"
|
||||
#include <string.h>
|
||||
|
||||
using namespace IPA;
|
||||
|
||||
class IPAExceptionTestFixture: public TestBase {
|
||||
public:
|
||||
|
||||
IPAExceptionTestFixture() :
|
||||
m_uBufferSize(0) {
|
||||
memset(m_aBuffer, 0, sizeof(m_aBuffer));
|
||||
m_testSuiteName.push_back("Exception");
|
||||
}
|
||||
|
||||
virtual bool AddRules() = 0;
|
||||
virtual bool ModifyPackets() = 0;
|
||||
virtual bool TestLogic() = 0;
|
||||
|
||||
bool Setup() {
|
||||
|
||||
ConfigureScenario(PHASE_SEVEN_TEST_CONFIGURATION);
|
||||
|
||||
m_producer.Open(INTERFACE0_TO_IPA_DATA_PATH,
|
||||
INTERFACE0_FROM_IPA_DATA_PATH);
|
||||
m_Consumer1.Open(INTERFACE1_TO_IPA_DATA_PATH,
|
||||
INTERFACE1_FROM_IPA_DATA_PATH);
|
||||
m_Consumer2.Open(INTERFACE2_TO_IPA_DATA_PATH,
|
||||
INTERFACE2_FROM_IPA_DATA_PATH);
|
||||
m_Consumer3.Open(INTERFACE3_TO_IPA_DATA_PATH,
|
||||
INTERFACE3_FROM_IPA_DATA_PATH);
|
||||
m_Exceptions.Open(INTERFACE_TO_IPA_EXCEPTION_PATH,
|
||||
INTERFACE_FROM_IPA_EXCEPTION_PATH);
|
||||
|
||||
|
||||
if (!m_Routing.DeviceNodeIsOpened()) {
|
||||
LOG_MSG_ERROR(
|
||||
"Routing block is not ready for immediate commands!\n");
|
||||
return false;
|
||||
}
|
||||
if (!m_Filtering.DeviceNodeIsOpened()) {
|
||||
LOG_MSG_ERROR(
|
||||
"Filtering block is not ready for immediate commands!\n");
|
||||
return false;
|
||||
}
|
||||
if (!m_HeaderInsertion.DeviceNodeIsOpened())
|
||||
{
|
||||
LOG_MSG_ERROR("Header Insertion block is not ready for immediate commands!\n");
|
||||
return false;
|
||||
}
|
||||
m_HeaderInsertion.Reset();
|
||||
|
||||
return true;
|
||||
} // Setup()
|
||||
|
||||
bool Run() {
|
||||
m_uBufferSize = BUFF_MAX_SIZE;
|
||||
LOG_MSG_STACK("Entering Function");
|
||||
|
||||
// Configure the system by adding Routing / Filtering / HDR
|
||||
if (!AddRules()) {
|
||||
LOG_MSG_ERROR("Failed adding Routing / Filtering / HDR.");
|
||||
return false;
|
||||
}
|
||||
// Load input data (IP packet) from file
|
||||
if (!LoadDefaultPacket(m_eIP, m_aBuffer, m_uBufferSize)) {
|
||||
LOG_MSG_ERROR("Failed default Packet");
|
||||
return false;
|
||||
}
|
||||
if (!ModifyPackets()) {
|
||||
LOG_MSG_ERROR("Failed to modify packets.");
|
||||
return false;
|
||||
}
|
||||
if (!TestLogic()) {
|
||||
LOG_MSG_ERROR("Test failed, Input and expected output mismatch.");
|
||||
return false;
|
||||
}
|
||||
LOG_MSG_STACK("Leaving Function (Returning True)");
|
||||
return true;
|
||||
} // Run()
|
||||
|
||||
bool Teardown() {
|
||||
m_producer.Close();
|
||||
m_Consumer1.Close();
|
||||
m_Consumer2.Close();
|
||||
m_Consumer3.Close();
|
||||
m_Exceptions.Close();
|
||||
return true;
|
||||
} // Teardown()
|
||||
|
||||
~IPAExceptionTestFixture() {
|
||||
}
|
||||
|
||||
static RoutingDriverWrapper m_Routing;
|
||||
static Filtering m_Filtering;
|
||||
static HeaderInsertion m_HeaderInsertion;
|
||||
InterfaceAbstraction m_producer;
|
||||
InterfaceAbstraction m_Consumer1;
|
||||
InterfaceAbstraction m_Consumer2;
|
||||
InterfaceAbstraction m_Consumer3;
|
||||
InterfaceAbstraction m_Exceptions;
|
||||
|
||||
protected:
|
||||
static const size_t BUFF_MAX_SIZE = 1024;
|
||||
static const uint8_t MAX_HEADER_SIZE = 64; // 64Bytes - Max Header Length
|
||||
enum ipa_ip_type m_eIP;
|
||||
uint8_t m_aBuffer[BUFF_MAX_SIZE]; // Input file \ IP packet
|
||||
size_t m_uBufferSize;
|
||||
|
||||
};
|
||||
RoutingDriverWrapper IPAExceptionTestFixture::m_Routing;
|
||||
Filtering IPAExceptionTestFixture::m_Filtering;
|
||||
HeaderInsertion IPAExceptionTestFixture::m_HeaderInsertion;
|
||||
|
||||
//----------------------------------------------------------------------------------------------------------------------------------------/
|
||||
// Test001: Test that when a packet with (IPVer != 4) && (IPVer Ver != 6) , an exception packet is created and received & exception_pipe /
|
||||
//----------------------------------------------------------------------------------------------------------------------------------------/
|
||||
class IPAExceptionPacketTest001: public IPAExceptionTestFixture {
|
||||
public:
|
||||
IPAExceptionPacketTest001() {
|
||||
m_name = "IPAExceptionPacketTest001";
|
||||
m_description = "\
|
||||
IPA Exception Test 001 - Test that when a packet with (IPVer != 4) && (IPVer Ver != 6) , an exception packet is created and received & exception_pipe \
|
||||
Test Generates send NUM_OF_EXCEPTION_PKTS packets with IP Version changing from 0 to 9.\
|
||||
First IP Version == 4, hence it is not considered as exception (same goes for IP Ver == 6) \
|
||||
";
|
||||
m_eIP = IPA_IP_v4;
|
||||
Register(*this);
|
||||
}
|
||||
|
||||
virtual bool AddRules() {
|
||||
// Clear All Rules
|
||||
bool bRetVal = true;
|
||||
LOG_MSG_STACK("Entering Function");
|
||||
|
||||
const char bypass0[20] = "Bypass0";
|
||||
struct ipa_ioc_get_rt_tbl sRoutingTable;
|
||||
IPAFilteringTable cFilterTable;
|
||||
struct ipa_flt_rule_add sFilterRuleEntry;
|
||||
uint32_t nRTTableHdl=0;
|
||||
memset(&sRoutingTable, 0, sizeof(sRoutingTable));
|
||||
|
||||
LOG_MSG_STACK("Entering Function");
|
||||
if (!CreateBypassRoutingTable(&m_Routing, m_eIP, bypass0, IPA_CLIENT_TEST2_CONS,
|
||||
0,&nRTTableHdl)) {
|
||||
LOG_MSG_ERROR("CreateBypassRoutingTable Failed\n");
|
||||
bRetVal = false;
|
||||
goto bail;
|
||||
}
|
||||
LOG_MSG_INFO("CreateBypassRoutingTable completed successfully");
|
||||
sRoutingTable.ip = m_eIP;
|
||||
strlcpy(sRoutingTable.name, bypass0, sizeof(sRoutingTable.name));
|
||||
if (!m_Routing.GetRoutingTable(&sRoutingTable)) {
|
||||
LOG_MSG_ERROR(
|
||||
"m_routing.GetRoutingTable(&sRoutingTable=0x%p) Failed.", &sRoutingTable);
|
||||
bRetVal = false;
|
||||
goto bail;
|
||||
}
|
||||
// Creating Filtering Rules
|
||||
cFilterTable.Init(m_eIP,IPA_CLIENT_TEST_PROD,true,1);
|
||||
LOG_MSG_INFO("Creation of filtering table completed successfully");
|
||||
|
||||
// Configuring Filtering Rule No.1
|
||||
cFilterTable.GeneratePresetRule(0,sFilterRuleEntry);
|
||||
sFilterRuleEntry.at_rear = true;
|
||||
sFilterRuleEntry.flt_rule_hdl = -1; // return Value
|
||||
sFilterRuleEntry.status = -1; // return value
|
||||
sFilterRuleEntry.rule.action = IPA_PASS_TO_ROUTING;
|
||||
sFilterRuleEntry.rule.rt_tbl_hdl = nRTTableHdl;
|
||||
if (
|
||||
((uint8_t)-1 == cFilterTable.AddRuleToTable(sFilterRuleEntry)) ||
|
||||
!m_Filtering.AddFilteringRule(cFilterTable.GetFilteringTable())
|
||||
)
|
||||
{
|
||||
LOG_MSG_ERROR ("Adding Rule (0) to Filtering block Failed.");
|
||||
bRetVal = false;
|
||||
goto bail;
|
||||
} else
|
||||
{
|
||||
LOG_MSG_DEBUG("flt rule hdl0=0x%x, status=0x%x\n", cFilterTable.ReadRuleFromTable(0)->flt_rule_hdl,cFilterTable.ReadRuleFromTable(0)->status);
|
||||
}
|
||||
|
||||
bail:
|
||||
LOG_MSG_STACK(
|
||||
"Leaving Function (Returning %s)", bRetVal?"True":"False");
|
||||
return bRetVal;
|
||||
} // AddRules()
|
||||
|
||||
virtual bool ModifyPackets() {
|
||||
m_eIP = IPA_IP_v6;
|
||||
|
||||
AddRules(); // Need to add Routing / Filtering rules for IPv6 as well.
|
||||
return true;
|
||||
} // ModifyPacktes ()
|
||||
|
||||
virtual bool TestLogic() {
|
||||
int i = 0, nIPVer = 0;;
|
||||
memset(m_aExpectedBuffer, 0, sizeof(m_aExpectedBuffer));
|
||||
m_aExpectedBuffer[2] = 0x0b;
|
||||
m_aExpectedBuffer[3] = 0x80;
|
||||
|
||||
memcpy(m_aExpectedBuffer+8, m_aBuffer, m_uBufferSize);
|
||||
m_aExpectedBufSize = m_uBufferSize+8;
|
||||
|
||||
for (i=0;i<NUM_OF_EXCEPTION_PKTS;i++)
|
||||
{
|
||||
LOG_MSG_INFO("Packet %d\n",i);
|
||||
nIPVer = i+4 % 10;
|
||||
m_aBuffer[0] = (m_aBuffer[0] & 0x0F)+0x10*nIPVer;// Change to Invalid IP version
|
||||
m_aExpectedBuffer[8] = (m_aExpectedBuffer[8] & 0x0F)+0x10*nIPVer;
|
||||
if (4 == nIPVer || 6 == nIPVer)
|
||||
{
|
||||
if (!SendReceiveAndCompare(&m_producer, m_aBuffer, m_uBufferSize,
|
||||
&m_Consumer1, m_aExpectedBuffer+8, m_aExpectedBufSize-8))
|
||||
{
|
||||
LOG_MSG_ERROR("SendReceiveAndCompare failed. IPVer = %d",nIPVer);
|
||||
return false;
|
||||
}
|
||||
} else
|
||||
{
|
||||
if (!SendReceiveAndCompare(&m_producer, m_aBuffer, m_uBufferSize,
|
||||
&m_Exceptions, m_aExpectedBuffer, m_aExpectedBufSize))
|
||||
{
|
||||
LOG_MSG_ERROR("SendReceiveAndCompare failed. IPVer = %d",nIPVer);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
static const int NUM_OF_EXCEPTION_PKTS = 9;
|
||||
uint8_t m_aExpectedBuffer[BUFF_MAX_SIZE];
|
||||
size_t m_aExpectedBufSize;
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------------------------------/
|
||||
// Test003: Test that when Filtering Routes the Packet to the Exception Pipe, an exception packet is created and received & exception_pipe /
|
||||
//------------------------------------------------------------------------------------------------------------------------------------------/
|
||||
class IPAExceptionPacketTest003: public IPAExceptionTestFixture {
|
||||
public:
|
||||
IPAExceptionPacketTest003() {
|
||||
m_name = "IPAExceptionPacketTest003";
|
||||
m_description = "\
|
||||
IPA Exception Test 003 - Test that when Filtering Routes the Packet to the Exception Pipe, an exception packet is created and received & exception_pipe \
|
||||
Test Generates a Filtering Table that routes all packets to the Exception Pipe. \
|
||||
and verify that the packet is recieved @ the Exception Pipe. \
|
||||
";
|
||||
m_eIP = IPA_IP_v4;
|
||||
Register(*this);
|
||||
}
|
||||
|
||||
virtual bool AddRules() {
|
||||
// Clear All Rules
|
||||
bool bRetVal = true;
|
||||
LOG_MSG_STACK("Entering Function");
|
||||
|
||||
const char bypass0[20] = "Bypass0";
|
||||
struct ipa_ioc_get_rt_tbl sRoutingTable;
|
||||
IPAFilteringTable cFilterTable;
|
||||
struct ipa_flt_rule_add sFilterRuleEntry;
|
||||
uint32_t nRTTableHdl=0;
|
||||
memset(&sRoutingTable, 0, sizeof(sRoutingTable));
|
||||
|
||||
LOG_MSG_STACK("Entering Function");
|
||||
if (!CreateBypassRoutingTable(&m_Routing, m_eIP, bypass0, IPA_CLIENT_TEST2_CONS,
|
||||
0,&nRTTableHdl)) {
|
||||
LOG_MSG_ERROR("CreateBypassRoutingTable Failed\n");
|
||||
bRetVal = false;
|
||||
goto bail;
|
||||
}
|
||||
LOG_MSG_INFO("CreateBypassRoutingTable completed successfully");
|
||||
sRoutingTable.ip = m_eIP;
|
||||
strlcpy(sRoutingTable.name, bypass0, sizeof(sRoutingTable.name));
|
||||
if (!m_Routing.GetRoutingTable(&sRoutingTable)) {
|
||||
LOG_MSG_ERROR(
|
||||
"m_routing.GetRoutingTable(&sRoutingTable=0x%p) Failed.", &sRoutingTable);
|
||||
bRetVal = false;
|
||||
goto bail;
|
||||
}
|
||||
// Creating Filtering Rules
|
||||
cFilterTable.Init(m_eIP,IPA_CLIENT_TEST_PROD,true,1);
|
||||
LOG_MSG_INFO("Creation of filtering table completed successfully");
|
||||
|
||||
// Configuring Filtering Rule No.1
|
||||
cFilterTable.GeneratePresetRule(0,sFilterRuleEntry);
|
||||
sFilterRuleEntry.at_rear = true;
|
||||
sFilterRuleEntry.flt_rule_hdl = -1; // return Value
|
||||
sFilterRuleEntry.status = -1; // return value
|
||||
sFilterRuleEntry.rule.action = IPA_PASS_TO_EXCEPTION;
|
||||
sFilterRuleEntry.rule.rt_tbl_hdl = nRTTableHdl;
|
||||
if (
|
||||
((uint8_t)-1 == cFilterTable.AddRuleToTable(sFilterRuleEntry)) ||
|
||||
!m_Filtering.AddFilteringRule(cFilterTable.GetFilteringTable())
|
||||
)
|
||||
{
|
||||
LOG_MSG_ERROR ("Adding Rule (0) to Filtering block Failed.");
|
||||
bRetVal = false;
|
||||
goto bail;
|
||||
} else
|
||||
{
|
||||
LOG_MSG_DEBUG("flt rule hdl0=0x%x, status=0x%x\n", cFilterTable.ReadRuleFromTable(0)->flt_rule_hdl,cFilterTable.ReadRuleFromTable(0)->status);
|
||||
}
|
||||
|
||||
bail:
|
||||
LOG_MSG_STACK(
|
||||
"Leaving Function (Returning %s)", bRetVal?"True":"False");
|
||||
return bRetVal;
|
||||
} // AddRules()
|
||||
|
||||
virtual bool ModifyPackets() {
|
||||
return true;
|
||||
} // ModifyPacktes ()
|
||||
|
||||
virtual bool TestLogic() {
|
||||
memset(m_aExpectedBuffer, 0, sizeof(m_aExpectedBuffer));
|
||||
m_aExpectedBuffer[2] = 0x0b;
|
||||
m_aExpectedBuffer[3] = 0x20;
|
||||
|
||||
memcpy(m_aExpectedBuffer+8, m_aBuffer, m_uBufferSize);
|
||||
m_aExpectedBufSize = m_uBufferSize+8;
|
||||
|
||||
if (!SendReceiveAndCompare(&m_producer, m_aBuffer, m_uBufferSize,
|
||||
&m_Exceptions, m_aExpectedBuffer, m_aExpectedBufSize))
|
||||
{
|
||||
LOG_MSG_ERROR("SendReceiveAndCompare failed.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
uint8_t m_aExpectedBuffer[BUFF_MAX_SIZE];
|
||||
size_t m_aExpectedBufSize;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------------------------------------------------------------------/
|
||||
// Test006: Test that when a packet with Internet Header Length < 5 Arrives, an exception packet is created and received & exception_pipe /
|
||||
//-----------------------------------------------------------------------------------------------------------------------------------------/
|
||||
class IPAExceptionPacketTest006: public IPAExceptionTestFixture {
|
||||
public:
|
||||
IPAExceptionPacketTest006() {
|
||||
m_name = "IPAExceptionPacketTest006";
|
||||
m_description = "\
|
||||
IPA Exception Test 006 - Test that when a packet with Internet Header Length < 5 Arrives, an exception packet is created and received & exception_pipe \
|
||||
Test Generates a Packet with Internet Header Length (IHL == 4). \
|
||||
and verifies that the packet is recieved @ the Exception Pipe. \
|
||||
";
|
||||
m_eIP = IPA_IP_v4;
|
||||
Register(*this);
|
||||
}
|
||||
|
||||
virtual bool AddRules() {
|
||||
// Clear All Rules
|
||||
bool bRetVal = true;
|
||||
LOG_MSG_STACK("Entering Function");
|
||||
|
||||
const char bypass0[20] = "Bypass0";
|
||||
struct ipa_ioc_get_rt_tbl sRoutingTable;
|
||||
IPAFilteringTable cFilterTable;
|
||||
struct ipa_flt_rule_add sFilterRuleEntry;
|
||||
uint32_t nRTTableHdl=0;
|
||||
memset(&sRoutingTable, 0, sizeof(sRoutingTable));
|
||||
|
||||
LOG_MSG_STACK("Entering Function");
|
||||
if (!CreateBypassRoutingTable(&m_Routing, m_eIP, bypass0, IPA_CLIENT_TEST2_CONS,
|
||||
0,&nRTTableHdl)) {
|
||||
LOG_MSG_ERROR("CreateBypassRoutingTable Failed\n");
|
||||
bRetVal = false;
|
||||
goto bail;
|
||||
}
|
||||
LOG_MSG_INFO("CreateBypassRoutingTable completed successfully");
|
||||
sRoutingTable.ip = m_eIP;
|
||||
strlcpy(sRoutingTable.name, bypass0, sizeof(sRoutingTable.name));
|
||||
if (!m_Routing.GetRoutingTable(&sRoutingTable)) {
|
||||
LOG_MSG_ERROR(
|
||||
"m_routing.GetRoutingTable(&sRoutingTable=0x%p) Failed.", &sRoutingTable);
|
||||
bRetVal = false;
|
||||
goto bail;
|
||||
}
|
||||
// Creating Filtering Rules
|
||||
cFilterTable.Init(m_eIP,IPA_CLIENT_TEST_PROD,true,1);
|
||||
LOG_MSG_INFO("Creation of filtering table completed successfully");
|
||||
|
||||
// Configuring Filtering Rule No.1
|
||||
cFilterTable.GeneratePresetRule(0,sFilterRuleEntry);
|
||||
sFilterRuleEntry.at_rear = true;
|
||||
sFilterRuleEntry.flt_rule_hdl = -1; // return Value
|
||||
sFilterRuleEntry.status = -1; // return value
|
||||
sFilterRuleEntry.rule.action = IPA_PASS_TO_ROUTING;
|
||||
sFilterRuleEntry.rule.rt_tbl_hdl = nRTTableHdl;
|
||||
if (
|
||||
((uint8_t)-1 == cFilterTable.AddRuleToTable(sFilterRuleEntry)) ||
|
||||
!m_Filtering.AddFilteringRule(cFilterTable.GetFilteringTable())
|
||||
)
|
||||
{
|
||||
LOG_MSG_ERROR ("Adding Rule (0) to Filtering block Failed.");
|
||||
bRetVal = false;
|
||||
goto bail;
|
||||
} else
|
||||
{
|
||||
LOG_MSG_DEBUG("flt rule hdl0=0x%x, status=0x%x\n", cFilterTable.ReadRuleFromTable(0)->flt_rule_hdl,cFilterTable.ReadRuleFromTable(0)->status);
|
||||
}
|
||||
|
||||
bail:
|
||||
LOG_MSG_STACK(
|
||||
"Leaving Function (Returning %s)", bRetVal?"True":"False");
|
||||
return bRetVal;
|
||||
} // AddRules()
|
||||
|
||||
virtual bool ModifyPackets() {
|
||||
m_aBuffer[0] =(m_aBuffer[0] & 0xF0)+0x04;// Change the IHL to 4
|
||||
return true;
|
||||
} // ModifyPacktes ()
|
||||
|
||||
virtual bool TestLogic() {
|
||||
memset(m_aExpectedBuffer, 0, sizeof(m_aExpectedBuffer));
|
||||
m_aExpectedBuffer[2] = 0x0b;
|
||||
m_aExpectedBuffer[3] = 0x04;
|
||||
|
||||
memcpy(m_aExpectedBuffer+8, m_aBuffer, m_uBufferSize);
|
||||
m_aExpectedBufSize = m_uBufferSize+8;
|
||||
|
||||
if (!SendReceiveAndCompare(&m_producer, m_aBuffer, m_uBufferSize,
|
||||
&m_Exceptions, m_aExpectedBuffer, m_aExpectedBufSize))
|
||||
{
|
||||
LOG_MSG_ERROR("SendReceiveAndCompare failed.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
uint8_t m_aExpectedBuffer[BUFF_MAX_SIZE];
|
||||
size_t m_aExpectedBufSize;
|
||||
};
|
||||
|
||||
static IPAExceptionPacketTest001 ipaExceptionPacketTest001;
|
||||
static IPAExceptionPacketTest003 ipaExceptionPacketTest003;
|
||||
static IPAExceptionPacketTest006 ipaExceptionPacketTest006;
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 2017 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "RoutingDriverWrapper.h"
|
||||
#include "HeaderInsertion.h"
|
||||
#include "Filtering.h"
|
||||
#include "IPAFilteringTable.h"
|
||||
#include "TestsUtils.h"
|
||||
#include <string.h>
|
||||
#include "ExceptionsTestFixture.h"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Pipe ExceptionsTestFixture::m_USB1ToIpaPipe(IPA_CLIENT_TEST_PROD, IPA_TEST_CONFIFURATION_7);
|
||||
Pipe ExceptionsTestFixture::m_IpaToA5ExceptionPipe(IPA_TEST_CONFIFURATION_7);//Exception pipe
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ExceptionsTestFixture::ExceptionsTestFixture(){
|
||||
Register(*this);
|
||||
m_testSuiteName.push_back("Exceptions");
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
/////// EOF ///////
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
88
qcom/opensource/dataipa/kernel-tests/ExceptionsTestFixture.h
Normal file
88
qcom/opensource/dataipa/kernel-tests/ExceptionsTestFixture.h
Normal file
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright (c) 2017 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* Changes from Qualcomm Innovation Center are provided under the following license:
|
||||
*
|
||||
* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted (subject to the limitations in the
|
||||
* disclaimer below) provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* * Neither the name of Qualcomm Innovation Center, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
|
||||
* GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
|
||||
* HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
|
||||
*/
|
||||
|
||||
#include "RoutingDriverWrapper.h"
|
||||
#include "HeaderInsertion.h"
|
||||
#include "Filtering.h"
|
||||
#include "IPAFilteringTable.h"
|
||||
#include "TestsUtils.h"
|
||||
#include "Pipe.h"
|
||||
#include <string.h>
|
||||
|
||||
#ifndef _EXCEPTION_TESTS_FIXTURE_
|
||||
#define _EXCEPTION_TESTS_FIXTURE_
|
||||
|
||||
class ExceptionsTestFixture:public TestBase {
|
||||
public:
|
||||
/*This Constructor will register the
|
||||
*exception tests and set the suit name
|
||||
*/
|
||||
ExceptionsTestFixture();
|
||||
protected:
|
||||
static Pipe m_USB1ToIpaPipe;
|
||||
/*from the test application into the IPA(DMUX header)*/
|
||||
static Pipe m_IpaToA5ExceptionPipe;
|
||||
/*from the IPA back to the test application(Exception pipe)*/
|
||||
};
|
||||
|
||||
#endif
|
||||
298
qcom/opensource/dataipa/kernel-tests/ExceptionsTests.cpp
Normal file
298
qcom/opensource/dataipa/kernel-tests/ExceptionsTests.cpp
Normal file
@@ -0,0 +1,298 @@
|
||||
/*
|
||||
* Copyright (c) 2017 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* Changes from Qualcomm Innovation Center are provided under the following license:
|
||||
*
|
||||
* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted (subject to the limitations in the
|
||||
* disclaimer below) provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* * Neither the name of Qualcomm Innovation Center, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
|
||||
* GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
|
||||
* HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
|
||||
*/
|
||||
|
||||
#include "RoutingDriverWrapper.h"
|
||||
#include "HeaderInsertion.h"
|
||||
#include "Filtering.h"
|
||||
#include "IPAFilteringTable.h"
|
||||
#include "TestsUtils.h"
|
||||
#include "ExceptionsTestFixture.h"
|
||||
#include "IPv4Packet.h"
|
||||
#include <string.h>
|
||||
|
||||
#define MAX_SENT_BUFFER_SIZE 1500
|
||||
#define MAX_RECEIVE_BUFFER_SIZE 1500
|
||||
#define VALIDATE_WITH_MSG_AND_RETVAL(bRetVal,msg) \
|
||||
if (false == bRetVal){ \
|
||||
LOG_MSG_ERROR(msg); \
|
||||
return false; \
|
||||
}
|
||||
|
||||
using namespace IPA;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class ExceptionsTestNonIpPacket: public ExceptionsTestFixture {
|
||||
public:
|
||||
//The packet size to be sent
|
||||
size_t m_nPacketSize;
|
||||
//A buffer to hold the non-IP(V4/V6) packet
|
||||
Byte *m_pSendBuffer;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//Set the tests name and description
|
||||
ExceptionsTestNonIpPacket() :
|
||||
m_nPacketSize(0), m_pSendBuffer(NULL) {
|
||||
m_name = "ExceptionsTestNonIpPacket";
|
||||
m_description =
|
||||
"Create a non-IP packet(version!=4 && version !=6) and \
|
||||
expect exception from Filter block";
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
virtual bool Run() {
|
||||
bool bRetVal = true;
|
||||
Byte *pReceiveBuffer = new Byte[MAX_RECEIVE_BUFFER_SIZE];
|
||||
//Send the non-IPV4/IPV6 packet to the IPA
|
||||
LOG_MSG_DEBUG("Send the non-IPV4/IPV6 packet to the IPA");
|
||||
size_t nBytesSent = m_USB1ToIpaPipe.Send(m_pSendBuffer, m_nPacketSize);
|
||||
if (nBytesSent != m_nPacketSize) {
|
||||
LOG_MSG_ERROR("Not all data was sent into the IPA");
|
||||
return false;
|
||||
}
|
||||
|
||||
//Read from the exception pipe(from IPA to A5) - try to read as much as we can
|
||||
size_t nBytesRead = m_IpaToA5ExceptionPipe.Receive(pReceiveBuffer,
|
||||
MAX_RECEIVE_BUFFER_SIZE);
|
||||
if (nBytesRead != nBytesSent) {
|
||||
LOG_MSG_ERROR("Not all data was read:");
|
||||
print_buff(pReceiveBuffer, nBytesRead);
|
||||
return false;
|
||||
}
|
||||
|
||||
//check the exception packet against the one that we sent
|
||||
bRetVal = !memcmp(m_pSendBuffer, pReceiveBuffer, nBytesSent);
|
||||
if (false == bRetVal) {
|
||||
LOG_MSG_ERROR("Received packet is not equal, Received:");
|
||||
print_buff(pReceiveBuffer, nBytesRead);
|
||||
LOG_MSG_ERROR("Received packet is not equal, Sent:");
|
||||
print_buff(m_pSendBuffer, m_nPacketSize);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//build the non-IP packet
|
||||
virtual bool Setup() {
|
||||
bool bRetVal = true;
|
||||
m_pSendBuffer = new Byte[MAX_SENT_BUFFER_SIZE];
|
||||
//Load some default IPV4 packet and save its size
|
||||
m_nPacketSize = MAX_SENT_BUFFER_SIZE; //This parameter is In/Out
|
||||
bRetVal = LoadDefaultPacket(IPA_IP_v4, m_pSendBuffer, m_nPacketSize);
|
||||
VALIDATE_WITH_MSG_AND_RETVAL(bRetVal, "Load failed");
|
||||
//Set the version field to non-IPV4/IPV6(version = 5)
|
||||
m_pSendBuffer[0] &= 0x0F;
|
||||
m_pSendBuffer[0] |= 0x50;
|
||||
|
||||
//initialize Pipes
|
||||
bRetVal = m_USB1ToIpaPipe.Init();
|
||||
VALIDATE_WITH_MSG_AND_RETVAL(bRetVal, "Pipe Initialization failed");
|
||||
bRetVal = m_IpaToA5ExceptionPipe.Init();
|
||||
VALIDATE_WITH_MSG_AND_RETVAL(bRetVal, "Pipe Initialization failed");
|
||||
return true;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
virtual bool Teardown() {
|
||||
bool bRetVal = true;
|
||||
delete[] m_pSendBuffer;
|
||||
m_USB1ToIpaPipe.Destroy();
|
||||
m_IpaToA5ExceptionPipe.Destroy();
|
||||
return bRetVal;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
};
|
||||
//ExceptionTestNoneIpPacket
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class ExceptionsTestFragmentedException: public ExceptionsTestFixture {
|
||||
public:
|
||||
//The packet size to be sent
|
||||
size_t m_nPacketSize;
|
||||
//A buffer to hold the non-IP(V4/V6) packet
|
||||
Byte *m_pSendBuffer;
|
||||
Byte *m_pReceiveBuffer;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//Set the tests name and description
|
||||
ExceptionsTestFragmentedException():m_nPacketSize(0), m_pSendBuffer(NULL),
|
||||
m_pReceiveBuffer(NULL){
|
||||
m_name = "ExceptionsTestFragmentedException";
|
||||
m_description =
|
||||
"Send IP packet with MF set, create global Filter rule \
|
||||
that will hit it as Exception";
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
virtual bool Run() {
|
||||
bool bRetVal = true;
|
||||
//configuring the Filter block to catch the fragmented packet:
|
||||
ConfigureFilterGlobalRuleForMF();
|
||||
//Send the non-IPV4/IPV6 packet to the IPA
|
||||
LOG_MSG_DEBUG("Send the IP packet with the MF bit set(size = %d)", m_nPacketSize);
|
||||
size_t nBytesSent = m_USB1ToIpaPipe.Send(m_pSendBuffer, m_nPacketSize);
|
||||
if (nBytesSent != m_nPacketSize) {
|
||||
LOG_MSG_ERROR("Not all data was sent into the IPA(only %d)", nBytesSent);
|
||||
return false;
|
||||
}
|
||||
//Read from the exception pipe(from IPA to A5) - try to read as much as we can
|
||||
size_t nBytesRead = m_IpaToA5ExceptionPipe.Receive(m_pReceiveBuffer,
|
||||
MAX_RECEIVE_BUFFER_SIZE);
|
||||
if (nBytesRead != nBytesSent) {
|
||||
LOG_MSG_ERROR("Not all data was read:");
|
||||
print_buff(m_pReceiveBuffer, nBytesRead);
|
||||
return false;
|
||||
}
|
||||
//check the exception packet against the one that we sent
|
||||
bRetVal = !memcmp(m_pSendBuffer, m_pReceiveBuffer, nBytesSent);
|
||||
if (false == bRetVal) {
|
||||
LOG_MSG_ERROR("Received packet is not equal, Received:");
|
||||
print_buff(m_pReceiveBuffer, nBytesRead);
|
||||
LOG_MSG_ERROR("Received packet is not equal, Sent:");
|
||||
print_buff(m_pSendBuffer, m_nPacketSize);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//build the non-IP packet
|
||||
virtual bool Setup() {
|
||||
bool bRetVal = true;
|
||||
m_pReceiveBuffer = new Byte[MAX_RECEIVE_BUFFER_SIZE];
|
||||
m_pSendBuffer = new Byte[MAX_RECEIVE_BUFFER_SIZE];
|
||||
//Load some default TCP packet
|
||||
TCPPacket tcpPacket;
|
||||
//Set the MF bit
|
||||
tcpPacket.SetMF(true);
|
||||
//copy the packet to the send buffer
|
||||
m_nPacketSize = tcpPacket.GetSize();
|
||||
tcpPacket.ToNetworkByteStream(m_pSendBuffer);
|
||||
//initialize Pipes
|
||||
bRetVal = m_USB1ToIpaPipe.Init();
|
||||
VALIDATE_WITH_MSG_AND_RETVAL(bRetVal, "Pipe Initialization failed");
|
||||
bRetVal = m_IpaToA5ExceptionPipe.Init();
|
||||
VALIDATE_WITH_MSG_AND_RETVAL(bRetVal, "Pipe Initialization failed");
|
||||
return true;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
virtual bool Teardown() {
|
||||
bool bRetVal = true;
|
||||
delete[] m_pSendBuffer;
|
||||
m_USB1ToIpaPipe.Destroy();
|
||||
m_IpaToA5ExceptionPipe.Destroy();
|
||||
return bRetVal;
|
||||
}
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void ConfigureFilterGlobalRuleForMF(){
|
||||
//struct ipa_ioc_add_flt_rule *pRuleTable;
|
||||
//Allocate memory for a table with one rule.
|
||||
|
||||
//Instruct the Driver to write this table(with its one rule) to the HW
|
||||
|
||||
//Continue from here - build the rule to catch the fragmented packet
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
};
|
||||
//ExceptionsTestFragmentedException
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class ExceptionsTestNonTCPUDP: public ExceptionsTestFixture {
|
||||
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//Classes instances:
|
||||
static ExceptionsTestNonIpPacket exceptionsTestNonIpPacket;
|
||||
static ExceptionsTestFragmentedException exceptionsTestFragmentedException;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
////////////// EOF ////////
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
99
qcom/opensource/dataipa/kernel-tests/Feature.cpp
Normal file
99
qcom/opensource/dataipa/kernel-tests/Feature.cpp
Normal file
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (c) 2017,2020 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* Changes from Qualcomm Innovation Center are provided under the following license:
|
||||
*
|
||||
* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted (subject to the limitations in the
|
||||
* disclaimer below) provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* * Neither the name of Qualcomm Innovation Center, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
|
||||
* GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
|
||||
* HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <cstring>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "Feature.h"
|
||||
|
||||
/*
|
||||
* All interaction through the driver are
|
||||
* made through this inode.
|
||||
*/
|
||||
static const char* DEVICE_NAME = "/dev/ipa";
|
||||
|
||||
Feature::Feature()
|
||||
{
|
||||
m_fd = open(DEVICE_NAME, O_RDWR);
|
||||
if (!m_fd)
|
||||
{
|
||||
cout << "Failed to open " << DEVICE_NAME << endl;
|
||||
}
|
||||
}
|
||||
|
||||
Feature::~Feature()
|
||||
{
|
||||
if (m_fd)
|
||||
{
|
||||
close(m_fd);
|
||||
}
|
||||
}
|
||||
|
||||
bool Feature::DeviceNodeIsOpened()
|
||||
{
|
||||
return (m_fd > 0 && fcntl(m_fd, F_GETFL) >= 0);
|
||||
}
|
||||
86
qcom/opensource/dataipa/kernel-tests/Feature.h
Normal file
86
qcom/opensource/dataipa/kernel-tests/Feature.h
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (c) 2017,2020 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* Changes from Qualcomm Innovation Center are provided under the following license:
|
||||
*
|
||||
* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted (subject to the limitations in the
|
||||
* disclaimer below) provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* * Neither the name of Qualcomm Innovation Center, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
|
||||
* GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
|
||||
* HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
|
||||
*/
|
||||
|
||||
#ifndef FEATURE_H_
|
||||
#define FEATURE_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include "linux/msm_ipa.h"
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
class Feature
|
||||
{
|
||||
public:
|
||||
Feature();
|
||||
~Feature();
|
||||
bool DeviceNodeIsOpened();
|
||||
|
||||
protected:
|
||||
int m_fd;
|
||||
};
|
||||
|
||||
#endif
|
||||
142
qcom/opensource/dataipa/kernel-tests/Filtering.cpp
Normal file
142
qcom/opensource/dataipa/kernel-tests/Filtering.cpp
Normal file
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
* Copyright (c) 2017,2020 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* Changes from Qualcomm Innovation Center are provided under the following license:
|
||||
*
|
||||
* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted (subject to the limitations in the
|
||||
* disclaimer below) provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* * Neither the name of Qualcomm Innovation Center, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
|
||||
* GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
|
||||
* HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
|
||||
*/
|
||||
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "Filtering.h"
|
||||
|
||||
bool Filtering::AddFilteringRule(struct ipa_ioc_add_flt_rule const * ruleTable)
|
||||
{
|
||||
int retval = 0;
|
||||
|
||||
retval = ioctl(m_fd, IPA_IOC_ADD_FLT_RULE, ruleTable);
|
||||
if (retval) {
|
||||
printf("%s(), failed adding Filtering rule table %p\n", __FUNCTION__, ruleTable);
|
||||
return false;
|
||||
}
|
||||
|
||||
printf("%s(), Added Filtering rule to table %p\n", __FUNCTION__, ruleTable);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Filtering::AddFilteringRule(struct ipa_ioc_add_flt_rule_v2 const * ruleTable)
|
||||
{
|
||||
int retval = 0;
|
||||
|
||||
retval = ioctl(m_fd, IPA_IOC_ADD_FLT_RULE_V2, ruleTable);
|
||||
if (retval) {
|
||||
printf("%s(), failed adding Filtering rule table %p\n", __FUNCTION__, ruleTable);
|
||||
return false;
|
||||
}
|
||||
|
||||
printf("%s(), Added Filtering rule to table %p\n", __FUNCTION__, ruleTable);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Filtering::DeleteFilteringRule(struct ipa_ioc_del_flt_rule *ruleTable)
|
||||
{
|
||||
int retval = 0;
|
||||
|
||||
retval = ioctl(m_fd, IPA_IOC_DEL_FLT_RULE, ruleTable);
|
||||
if (retval) {
|
||||
printf("%s(), failed deleting Filtering rule in table %p\n", __FUNCTION__, ruleTable);
|
||||
return false;
|
||||
}
|
||||
|
||||
printf("%s(), Deleted Filtering rule in table %p\n", __FUNCTION__, ruleTable);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Filtering::Commit(enum ipa_ip_type ip)
|
||||
{
|
||||
int retval = 0;
|
||||
|
||||
retval = ioctl(m_fd, IPA_IOC_COMMIT_FLT, ip);
|
||||
if (retval) {
|
||||
printf("%s(), failed committing Filtering rules.\n", __FUNCTION__);
|
||||
return false;
|
||||
}
|
||||
|
||||
printf("%s(), Committed Filtering rules to IPA HW.\n", __FUNCTION__);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Filtering::Reset(enum ipa_ip_type ip)
|
||||
{
|
||||
int retval = 0;
|
||||
|
||||
retval = ioctl(m_fd, IPA_IOC_RESET_FLT, ip);
|
||||
retval |= ioctl(m_fd, IPA_IOC_COMMIT_FLT, ip);
|
||||
if (retval) {
|
||||
printf("%s(), failed resetting Filtering block.\n", __FUNCTION__);
|
||||
return false;
|
||||
}
|
||||
|
||||
printf("%s(), Reset command issued to IPA Filtering block.\n", __FUNCTION__);
|
||||
return true;
|
||||
}
|
||||
|
||||
82
qcom/opensource/dataipa/kernel-tests/Filtering.h
Normal file
82
qcom/opensource/dataipa/kernel-tests/Filtering.h
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (c) 2017,2020 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* Changes from Qualcomm Innovation Center are provided under the following license:
|
||||
*
|
||||
* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted (subject to the limitations in the
|
||||
* disclaimer below) provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* * Neither the name of Qualcomm Innovation Center, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
|
||||
* GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
|
||||
* HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
|
||||
*/
|
||||
|
||||
#ifndef FILTERING_H_
|
||||
#define FILTERING_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include "linux/msm_ipa.h"
|
||||
#include "Feature.h"
|
||||
|
||||
class Filtering: public Feature
|
||||
{
|
||||
public:
|
||||
bool AddFilteringRule(struct ipa_ioc_add_flt_rule const *ruleTable);
|
||||
bool AddFilteringRule(ipa_ioc_add_flt_rule_v2 const *ruleTable);
|
||||
bool DeleteFilteringRule(struct ipa_ioc_del_flt_rule *ruleTable);
|
||||
bool Commit(enum ipa_ip_type ip);
|
||||
bool Reset(enum ipa_ip_type ip);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,513 @@
|
||||
/*
|
||||
* Copyright (c) 2017 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "FilteringEthernetBridgingTestFixture.h"
|
||||
|
||||
IpaFilteringEthernetBridgingTestFixture::IpaFilteringEthernetBridgingTestFixture():
|
||||
m_sendSize1 (m_BUFF_MAX_SIZE),
|
||||
m_sendSize2 (m_BUFF_MAX_SIZE),
|
||||
m_sendSize3 (m_BUFF_MAX_SIZE),
|
||||
m_IpaIPType(IPA_IP_v4)
|
||||
{
|
||||
memset(m_sendBuffer1, 0, sizeof(m_sendBuffer1));
|
||||
memset(m_sendBuffer2, 0, sizeof(m_sendBuffer2));
|
||||
memset(m_sendBuffer3, 0, sizeof(m_sendBuffer3));
|
||||
m_testSuiteName.push_back("FilteringEth");
|
||||
}
|
||||
|
||||
bool IpaFilteringEthernetBridgingTestFixture::Setup()
|
||||
{
|
||||
ConfigureScenario(PHASE_TWO_TEST_CONFIGURATION);
|
||||
|
||||
m_producer.Open(INTERFACE0_TO_IPA_DATA_PATH, INTERFACE0_FROM_IPA_DATA_PATH);
|
||||
m_producer2.Open(INTERFACE4_TO_IPA_DATA_PATH, INTERFACE4_FROM_IPA_DATA_PATH);
|
||||
|
||||
m_consumer.Open(INTERFACE1_TO_IPA_DATA_PATH, INTERFACE1_FROM_IPA_DATA_PATH);
|
||||
m_consumer2.Open(INTERFACE2_TO_IPA_DATA_PATH, INTERFACE2_FROM_IPA_DATA_PATH);
|
||||
m_defaultConsumer.Open(INTERFACE3_TO_IPA_DATA_PATH, INTERFACE3_FROM_IPA_DATA_PATH);
|
||||
|
||||
if (!m_routing.DeviceNodeIsOpened())
|
||||
{
|
||||
LOG_MSG_ERROR("Routing block is not ready for immediate commands!\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!m_filtering.DeviceNodeIsOpened())
|
||||
{
|
||||
LOG_MSG_ERROR("Filtering block is not ready for immediate commands!\n");
|
||||
return false;
|
||||
}
|
||||
m_routing.Reset(IPA_IP_v4);
|
||||
m_routing.Reset(IPA_IP_v6);
|
||||
return true;
|
||||
} // Setup()
|
||||
|
||||
bool IpaFilteringEthernetBridgingTestFixture::Teardown()
|
||||
{
|
||||
m_producer.Close();
|
||||
m_producer2.Close();
|
||||
m_consumer.Close();
|
||||
m_consumer2.Close();
|
||||
m_defaultConsumer.Close();
|
||||
return true;
|
||||
} // Teardown()
|
||||
|
||||
bool IpaFilteringEthernetBridgingTestFixture::LoadFiles(enum ipa_ip_type ip)
|
||||
{
|
||||
if (!LoadDefaultEth2Packet(ip, m_sendBuffer1, m_sendSize1)) {
|
||||
LOG_MSG_ERROR("Failed default Packet\n");
|
||||
return false;
|
||||
}
|
||||
LOG_MSG_DEBUG ("Loaded %zu Bytes to Buffer 1\n",m_sendSize1);
|
||||
|
||||
if (!LoadDefaultEth2Packet(ip, m_sendBuffer2, m_sendSize2)) {
|
||||
LOG_MSG_ERROR("Failed default Packet\n");
|
||||
return false;
|
||||
}
|
||||
LOG_MSG_DEBUG ("Loaded %zu Bytes to Buffer 2\n",m_sendSize2);
|
||||
|
||||
if (!LoadDefaultEth2Packet(ip, m_sendBuffer3, m_sendSize3)) {
|
||||
LOG_MSG_ERROR("Failed default Packet\n");
|
||||
return false;
|
||||
}
|
||||
LOG_MSG_DEBUG ("Loaded %zu Bytes to Buffer 3\n",m_sendSize3);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IpaFilteringEthernetBridgingTestFixture::ReceivePacketsAndCompare()
|
||||
{
|
||||
size_t receivedSize = 0;
|
||||
size_t receivedSize2 = 0;
|
||||
size_t receivedSize3 = 0;
|
||||
bool isSuccess = true;
|
||||
|
||||
// Receive results
|
||||
Byte *rxBuff1 = new Byte[m_BUFF_MAX_SIZE];
|
||||
Byte *rxBuff2 = new Byte[m_BUFF_MAX_SIZE];
|
||||
Byte *rxBuff3 = new Byte[m_BUFF_MAX_SIZE];
|
||||
|
||||
if (NULL == rxBuff1 || NULL == rxBuff2 || NULL == rxBuff3)
|
||||
{
|
||||
printf("Memory allocation error.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
receivedSize = m_consumer.ReceiveData(rxBuff1,
|
||||
m_BUFF_MAX_SIZE);
|
||||
LOG_MSG_DEBUG("Received %zu bytes on %s.\n",
|
||||
receivedSize,
|
||||
m_consumer.m_fromChannelName.c_str());
|
||||
|
||||
receivedSize2 = m_consumer2.ReceiveData(rxBuff2,
|
||||
m_BUFF_MAX_SIZE);
|
||||
LOG_MSG_DEBUG("Received %zu bytes on %s.\n",
|
||||
receivedSize2,
|
||||
m_consumer2.m_fromChannelName.c_str());
|
||||
|
||||
receivedSize3 = m_defaultConsumer.ReceiveData(rxBuff3,
|
||||
m_BUFF_MAX_SIZE);
|
||||
LOG_MSG_DEBUG("Received %zu bytes on %s.\n",
|
||||
receivedSize3,
|
||||
m_defaultConsumer.m_fromChannelName.c_str());
|
||||
|
||||
// Compare results
|
||||
if (!CompareResultVsGolden(m_sendBuffer1,
|
||||
m_sendSize1,
|
||||
rxBuff1,
|
||||
receivedSize))
|
||||
{
|
||||
LOG_MSG_ERROR("Comparison of Buffer0 Failed!");
|
||||
isSuccess = false;
|
||||
}
|
||||
|
||||
char recievedBuffer[256] = {0};
|
||||
char SentBuffer[256] = {0};
|
||||
|
||||
size_t j;
|
||||
for(j = 0; j < m_sendSize1; j++)
|
||||
snprintf(&SentBuffer[3*j], sizeof(SentBuffer) - (3*j + 1), " %02X", m_sendBuffer1[j]);
|
||||
for(j = 0; j < receivedSize; j++)
|
||||
snprintf(&recievedBuffer[3*j], sizeof(recievedBuffer) - (3*j + 1), " %02X", rxBuff1[j]);
|
||||
printf("Expected Value1 (%zu)\n%s\n, Received Value1(%zu)\n%s\n",
|
||||
m_sendSize1,SentBuffer,receivedSize,recievedBuffer);
|
||||
recievedBuffer[0] = 0;
|
||||
|
||||
for(j = 0; j < m_sendSize2; j++)
|
||||
snprintf(&SentBuffer[3 * j], sizeof(SentBuffer) - (3*j + 1), " %02X", m_sendBuffer2[j]);
|
||||
for(j = 0; j < receivedSize2; j++)
|
||||
snprintf(&recievedBuffer[3*j], sizeof(recievedBuffer) - (3*j + 1), " %02X", rxBuff2[j]);
|
||||
printf("Expected Value2 (%zu)\n%s\n, Received Value2(%zu)\n%s\n",
|
||||
m_sendSize2,SentBuffer,receivedSize2,recievedBuffer);
|
||||
recievedBuffer[0] = 0;
|
||||
|
||||
for(j = 0; j < m_sendSize3; j++)
|
||||
snprintf(&SentBuffer[3*j], sizeof(SentBuffer) - (3*j + 1), " %02X", m_sendBuffer3[j]);
|
||||
for(j = 0; j < receivedSize3; j++)
|
||||
snprintf(&recievedBuffer[3*j], sizeof(recievedBuffer) - (3*j + 1), " %02X", rxBuff3[j]);
|
||||
printf("Expected Value3 (%zu)\n%s\n, Received Value3(%zu)\n%s\n",
|
||||
m_sendSize3,SentBuffer,receivedSize3,recievedBuffer);
|
||||
recievedBuffer[0] = 0;
|
||||
|
||||
isSuccess &= CompareResultVsGolden(m_sendBuffer2,
|
||||
m_sendSize2, rxBuff2, receivedSize2);
|
||||
isSuccess &= CompareResultVsGolden(m_sendBuffer3,
|
||||
m_sendSize3, rxBuff3, receivedSize3);
|
||||
|
||||
delete[] rxBuff1;
|
||||
delete[] rxBuff2;
|
||||
delete[] rxBuff3;
|
||||
|
||||
return isSuccess;
|
||||
}
|
||||
|
||||
// This function creates three IPv4 bypass routing entries and commits them.
|
||||
bool IpaFilteringEthernetBridgingTestFixture::CreateThreeIPv4BypassRoutingTables(const char *bypass0, const char *bypass1,
|
||||
const char *bypass2)
|
||||
{
|
||||
LOG_MSG_DEBUG("Entering");
|
||||
struct ipa_ioc_add_rt_rule *rt_rule0 = 0, *rt_rule1 = 0,*rt_rule2 = 0;
|
||||
struct ipa_rt_rule_add *rt_rule_entry;
|
||||
|
||||
rt_rule0 = (struct ipa_ioc_add_rt_rule *)
|
||||
calloc(1, sizeof(struct ipa_ioc_add_rt_rule) +
|
||||
1*sizeof(struct ipa_rt_rule_add));
|
||||
if(!rt_rule0) {
|
||||
LOG_MSG_ERROR("calloc failed to allocate rt_rule0");
|
||||
return false;
|
||||
}
|
||||
rt_rule1 = (struct ipa_ioc_add_rt_rule *)
|
||||
calloc(1, sizeof(struct ipa_ioc_add_rt_rule) +
|
||||
1*sizeof(struct ipa_rt_rule_add));
|
||||
if(!rt_rule1) {
|
||||
LOG_MSG_ERROR("calloc failed to allocate rt_rule1");
|
||||
Free(rt_rule0);
|
||||
return false;
|
||||
}
|
||||
rt_rule2 = (struct ipa_ioc_add_rt_rule *)
|
||||
calloc(1, sizeof(struct ipa_ioc_add_rt_rule) +
|
||||
1*sizeof(struct ipa_rt_rule_add));
|
||||
if(!rt_rule2) {
|
||||
LOG_MSG_ERROR("calloc failed to allocate rt_rule2");
|
||||
Free(rt_rule0);
|
||||
Free(rt_rule1);
|
||||
return false;
|
||||
}
|
||||
|
||||
rt_rule0->num_rules = 1;
|
||||
rt_rule0->ip = IPA_IP_v4;
|
||||
rt_rule0->commit = true;
|
||||
strlcpy(rt_rule0->rt_tbl_name, bypass0, sizeof(rt_rule0->rt_tbl_name));
|
||||
|
||||
rt_rule_entry = &rt_rule0->rules[0];
|
||||
rt_rule_entry->at_rear = 0;
|
||||
rt_rule_entry->rule.dst = IPA_CLIENT_TEST2_CONS;
|
||||
|
||||
rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
|
||||
rt_rule_entry->rule.attrib.u.v4.dst_addr = 0xaabbccdd;
|
||||
rt_rule_entry->rule.attrib.u.v4.dst_addr_mask = 0x00000000;// All Packets will get a "Hit"
|
||||
if (false == m_routing.AddRoutingRule(rt_rule0))
|
||||
{
|
||||
LOG_MSG_ERROR("Routing rule addition(rt_rule0) failed!\n");
|
||||
Free (rt_rule2);
|
||||
Free (rt_rule1);
|
||||
Free (rt_rule0);
|
||||
return false;
|
||||
}
|
||||
|
||||
rt_rule1->num_rules = 1;
|
||||
rt_rule1->ip = IPA_IP_v4;
|
||||
rt_rule1->commit = true;
|
||||
strlcpy(rt_rule1->rt_tbl_name, bypass1, sizeof(rt_rule1->rt_tbl_name));
|
||||
rt_rule_entry = &rt_rule1->rules[0];
|
||||
rt_rule_entry->at_rear = 0;
|
||||
rt_rule_entry->rule.dst = IPA_CLIENT_TEST3_CONS;
|
||||
rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
|
||||
rt_rule_entry->rule.attrib.u.v4.dst_addr = 0xaabbccdd;
|
||||
rt_rule_entry->rule.attrib.u.v4.dst_addr_mask = 0x00000000;// All Packets will get a "Hit"
|
||||
if (false == m_routing.AddRoutingRule(rt_rule1))
|
||||
{
|
||||
LOG_MSG_ERROR("Routing rule addition(rt_rule1) failed!\n");
|
||||
Free (rt_rule2);
|
||||
Free (rt_rule1);
|
||||
Free (rt_rule0);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
rt_rule2->num_rules = 1;
|
||||
rt_rule2->ip = IPA_IP_v4;
|
||||
rt_rule2->commit = true;
|
||||
strlcpy(rt_rule2->rt_tbl_name, bypass2, sizeof(rt_rule2->rt_tbl_name));
|
||||
rt_rule_entry = &rt_rule2->rules[0];
|
||||
rt_rule_entry->at_rear = 0;
|
||||
rt_rule_entry->rule.dst = IPA_CLIENT_TEST4_CONS;
|
||||
rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
|
||||
rt_rule_entry->rule.attrib.u.v4.dst_addr = 0xaabbccdd;
|
||||
rt_rule_entry->rule.attrib.u.v4.dst_addr_mask = 0x00000000;// All Packets will get a "Hit"
|
||||
if (false == m_routing.AddRoutingRule(rt_rule2))
|
||||
{
|
||||
LOG_MSG_ERROR("Routing rule addition(rt_rule2)\n");
|
||||
Free (rt_rule2);
|
||||
Free (rt_rule1);
|
||||
Free (rt_rule0);
|
||||
return false;
|
||||
}
|
||||
|
||||
Free (rt_rule2);
|
||||
Free (rt_rule1);
|
||||
Free (rt_rule0);
|
||||
LOG_MSG_DEBUG("Leaving");
|
||||
return true;
|
||||
}
|
||||
|
||||
// This function creates three IPv6 bypass routing entries and commits them.
|
||||
bool IpaFilteringEthernetBridgingTestFixture::CreateThreeIPv6BypassRoutingTables (const char *bypass0, const char *bypass1,
|
||||
const char *bypass2)
|
||||
{
|
||||
LOG_MSG_DEBUG("Entering");
|
||||
struct ipa_ioc_add_rt_rule *rt_rule0 = 0, *rt_rule1 = 0,
|
||||
*rt_rule2 = 0;
|
||||
struct ipa_rt_rule_add *rt_rule_entry;
|
||||
|
||||
rt_rule0 = (struct ipa_ioc_add_rt_rule *)
|
||||
calloc(1,sizeof(struct ipa_ioc_add_rt_rule) +
|
||||
1*sizeof(struct ipa_rt_rule_add));
|
||||
if(!rt_rule0) {
|
||||
LOG_MSG_ERROR("calloc failed to allocate rt_rule0\n");
|
||||
return false;
|
||||
}
|
||||
rt_rule1 = (struct ipa_ioc_add_rt_rule *)
|
||||
calloc(1,sizeof(struct ipa_ioc_add_rt_rule) +
|
||||
1*sizeof(struct ipa_rt_rule_add));
|
||||
if(!rt_rule1) {
|
||||
LOG_MSG_ERROR("calloc failed to allocate rt_rule1\n");
|
||||
Free(rt_rule0);
|
||||
return false;
|
||||
}
|
||||
rt_rule2 = (struct ipa_ioc_add_rt_rule *)
|
||||
calloc(1,sizeof(struct ipa_ioc_add_rt_rule) +
|
||||
1*sizeof(struct ipa_rt_rule_add));
|
||||
if(!rt_rule2) {
|
||||
LOG_MSG_ERROR("calloc failed to allocate rt_rule2\n");
|
||||
Free(rt_rule0);
|
||||
Free(rt_rule1);
|
||||
return false;
|
||||
}
|
||||
|
||||
rt_rule0->num_rules = 1;
|
||||
rt_rule0->ip = IPA_IP_v6;
|
||||
rt_rule0->commit = true;
|
||||
strlcpy(rt_rule0->rt_tbl_name, bypass0, sizeof(rt_rule0->rt_tbl_name));
|
||||
|
||||
rt_rule_entry = &rt_rule0->rules[0];
|
||||
rt_rule_entry->at_rear = 0;
|
||||
rt_rule_entry->rule.dst = IPA_CLIENT_TEST2_CONS;
|
||||
rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
|
||||
rt_rule_entry->rule.attrib.u.v6.dst_addr[0] = 0xaabbccdd;
|
||||
rt_rule_entry->rule.attrib.u.v6.dst_addr[1] = 0xeeff0011;
|
||||
rt_rule_entry->rule.attrib.u.v6.dst_addr[2] = 0x22334455;
|
||||
rt_rule_entry->rule.attrib.u.v6.dst_addr[3] = 0x66778899;
|
||||
rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[0] = 0x00000000;// All Packets will get a "Hit"
|
||||
rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[1] = 0x00000000;
|
||||
rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[2] = 0x00000000;
|
||||
rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[3] = 0x00000000;
|
||||
if (false == m_routing.AddRoutingRule(rt_rule0))
|
||||
{
|
||||
LOG_MSG_ERROR("Routing rule addition(rt_rule0)");
|
||||
Free (rt_rule2);
|
||||
Free (rt_rule1);
|
||||
Free (rt_rule0);
|
||||
return false;
|
||||
}
|
||||
|
||||
rt_rule1->num_rules = 1;
|
||||
rt_rule1->ip = IPA_IP_v6;
|
||||
rt_rule1->commit = true;
|
||||
strlcpy(rt_rule1->rt_tbl_name, bypass1, sizeof(rt_rule1->rt_tbl_name));
|
||||
rt_rule_entry = &rt_rule1->rules[0];
|
||||
rt_rule_entry->at_rear = 0;
|
||||
rt_rule_entry->rule.dst = IPA_CLIENT_TEST3_CONS;
|
||||
rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
|
||||
rt_rule_entry->rule.attrib.u.v6.dst_addr[0] = 0xaabbccdd;
|
||||
rt_rule_entry->rule.attrib.u.v6.dst_addr[1] = 0xeeff0011;
|
||||
rt_rule_entry->rule.attrib.u.v6.dst_addr[2] = 0x22334455;
|
||||
rt_rule_entry->rule.attrib.u.v6.dst_addr[3] = 0x66778899;
|
||||
rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[0] = 0x00000000;// All Packets will get a "Hit"
|
||||
rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[1] = 0x00000000;
|
||||
rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[2] = 0x00000000;
|
||||
rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[3] = 0x00000000;
|
||||
if (false == m_routing.AddRoutingRule(rt_rule1))
|
||||
{
|
||||
LOG_MSG_ERROR("Routing rule addition(rt_rule1)");
|
||||
Free (rt_rule2);
|
||||
Free (rt_rule1);
|
||||
Free (rt_rule0);
|
||||
return false;
|
||||
}
|
||||
|
||||
rt_rule2->num_rules = 1;
|
||||
rt_rule2->ip = IPA_IP_v6;
|
||||
rt_rule2->commit = true;
|
||||
strlcpy(rt_rule2->rt_tbl_name, bypass2, sizeof(rt_rule2->rt_tbl_name));
|
||||
rt_rule_entry = &rt_rule2->rules[0];
|
||||
rt_rule_entry->at_rear = 0;
|
||||
rt_rule_entry->rule.dst = IPA_CLIENT_TEST4_CONS;
|
||||
rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
|
||||
rt_rule_entry->rule.attrib.u.v6.dst_addr[0] = 0xaabbccdd;
|
||||
rt_rule_entry->rule.attrib.u.v6.dst_addr[1] = 0xeeff0011;
|
||||
rt_rule_entry->rule.attrib.u.v6.dst_addr[2] = 0x22334455;
|
||||
rt_rule_entry->rule.attrib.u.v6.dst_addr[3] = 0x66778899;
|
||||
rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[0] = 0x00000000;// All Packets will get a "Hit"
|
||||
rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[1] = 0x00000000;
|
||||
rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[2] = 0x00000000;
|
||||
rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[3] = 0x00000000;
|
||||
if (false == m_routing.AddRoutingRule(rt_rule2))
|
||||
{
|
||||
LOG_MSG_ERROR("Routing rule addition(rt_rule2)");
|
||||
Free (rt_rule2);
|
||||
Free (rt_rule1);
|
||||
Free (rt_rule0);
|
||||
return false;
|
||||
}
|
||||
|
||||
Free (rt_rule2);
|
||||
Free (rt_rule1);
|
||||
Free (rt_rule0);
|
||||
LOG_MSG_DEBUG("Leaving function\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IpaFilteringEthernetBridgingTestFixture::Run()
|
||||
{
|
||||
bool res = false;
|
||||
bool isSuccess = false;
|
||||
|
||||
LOG_MSG_DEBUG("Entering");
|
||||
|
||||
// Add the relevant filtering rules
|
||||
res = AddRules();
|
||||
if (false == res) {
|
||||
LOG_MSG_ERROR("Failed adding filtering rules");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Load input data (IP packet) from file
|
||||
res = LoadFiles(m_IpaIPType);
|
||||
if (false == res) {
|
||||
LOG_MSG_ERROR("Failed loading files");
|
||||
return false;
|
||||
}
|
||||
|
||||
res = ModifyPackets();
|
||||
if (false == res) {
|
||||
LOG_MSG_ERROR("Failed to modify packets");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Send first packet
|
||||
isSuccess = m_pCurrentProducer->SendData(m_sendBuffer1,
|
||||
m_sendSize1);
|
||||
if (false == isSuccess)
|
||||
{
|
||||
LOG_MSG_ERROR("SendData failure");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Send second packet
|
||||
isSuccess = m_pCurrentProducer->SendData(m_sendBuffer2,
|
||||
m_sendSize2);
|
||||
if (false == isSuccess)
|
||||
{
|
||||
LOG_MSG_ERROR("SendData failure");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Send third packet
|
||||
isSuccess = m_pCurrentProducer->SendData(m_sendBuffer3,
|
||||
m_sendSize3);
|
||||
if (false == isSuccess)
|
||||
{
|
||||
LOG_MSG_ERROR("SendData failure");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Receive packets from the channels and compare results
|
||||
isSuccess = ReceivePacketsAndCompare();
|
||||
|
||||
LOG_MSG_DEBUG("Leaving function returning %d", isSuccess);
|
||||
|
||||
return isSuccess;
|
||||
} // Run()
|
||||
|
||||
|
||||
IpaFilteringEthernetBridgingTestFixture::~IpaFilteringEthernetBridgingTestFixture()
|
||||
{
|
||||
m_sendSize1 = 0;
|
||||
m_sendSize2 = 0;
|
||||
m_sendSize3 = 0;
|
||||
}
|
||||
|
||||
static const size_t m_BUFF_MAX_SIZE = 1024;
|
||||
static Filtering m_filtering;
|
||||
static RoutingDriverWrapper m_routing;
|
||||
|
||||
InterfaceAbstraction m_producer;
|
||||
InterfaceAbstraction m_producer2; // Pipe with ETH2 header removal
|
||||
InterfaceAbstraction *m_pCurrentProducer;
|
||||
InterfaceAbstraction m_consumer;
|
||||
InterfaceAbstraction m_consumer2;
|
||||
InterfaceAbstraction m_defaultConsumer;
|
||||
|
||||
Byte m_sendBuffer1[m_BUFF_MAX_SIZE];
|
||||
Byte m_sendBuffer2[m_BUFF_MAX_SIZE];
|
||||
Byte m_sendBuffer3[m_BUFF_MAX_SIZE];
|
||||
size_t m_sendSize1;
|
||||
size_t m_sendSize2;
|
||||
size_t m_sendSize3;
|
||||
enum ipa_ip_type m_IpaIPType;
|
||||
|
||||
RoutingDriverWrapper IpaFilteringEthernetBridgingTestFixture::m_routing;
|
||||
Filtering IpaFilteringEthernetBridgingTestFixture::m_filtering;
|
||||
|
||||
const uint8_t IpaFilteringEthernetBridgingTestFixture::m_ETH2_DST_ADDR[ETH_ALEN] =
|
||||
{
|
||||
0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0x11
|
||||
};
|
||||
|
||||
const uint8_t IpaFilteringEthernetBridgingTestFixture::m_ETH2_SRC_ADDR[ETH_ALEN] =
|
||||
{
|
||||
0x22, 0xee, 0xdd, 0xcc, 0xbb, 0xaa
|
||||
};
|
||||
|
||||
const uint8_t IpaFilteringEthernetBridgingTestFixture::m_MAC_ADDR_MASK_ALL[ETH_ALEN] =
|
||||
{
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff
|
||||
};
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (c) 2017 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <cstring> // for memcpy
|
||||
#include "hton.h" // for htonl
|
||||
#include "InterfaceAbstraction.h"
|
||||
#include "Constants.h"
|
||||
#include "Logger.h"
|
||||
#include "TestsUtils.h"
|
||||
#include "Filtering.h"
|
||||
#include "RoutingDriverWrapper.h"
|
||||
#include "IPAFilteringTable.h"
|
||||
|
||||
#define IPV4_DST_ADDR_OFFSET (16)
|
||||
#define IPV4_SRC_PORT_OFFSET (20)
|
||||
#define IPV4_DST_PORT_OFFSET (20+2)
|
||||
|
||||
#define DST_ADDR_LSB_OFFSET_IPV4 (19)
|
||||
#define DST_ADDR_LSB_OFFSET_IPV6 (39)
|
||||
|
||||
class IpaFilteringEthernetBridgingTestFixture : public TestBase
|
||||
{
|
||||
public:
|
||||
virtual bool ModifyPackets() = 0;
|
||||
virtual bool AddRules() = 0;
|
||||
|
||||
IpaFilteringEthernetBridgingTestFixture();
|
||||
|
||||
bool Setup();
|
||||
|
||||
bool Teardown();
|
||||
|
||||
virtual bool LoadFiles(enum ipa_ip_type ip);
|
||||
|
||||
bool ReceivePacketsAndCompare();
|
||||
|
||||
// This function creates three IPv4 bypass routing entries and commits them.
|
||||
bool CreateThreeIPv4BypassRoutingTables (const char *bypass0, const char *bypass1,
|
||||
const char *bypass2);
|
||||
|
||||
// This function creates three IPv6 bypass routing entries and commits them.
|
||||
bool CreateThreeIPv6BypassRoutingTables (const char *bypass0, const char *bypass1,
|
||||
const char *bypass2);
|
||||
|
||||
bool Run();
|
||||
|
||||
~IpaFilteringEthernetBridgingTestFixture();
|
||||
|
||||
static const size_t m_BUFF_MAX_SIZE = 1024;
|
||||
static const uint8_t m_ETH2_DST_ADDR[ETH_ALEN];
|
||||
static const uint8_t m_ETH2_SRC_ADDR[ETH_ALEN];
|
||||
static const uint8_t m_MAC_ADDR_MASK_ALL[ETH_ALEN];
|
||||
static Filtering m_filtering;
|
||||
static RoutingDriverWrapper m_routing;
|
||||
|
||||
InterfaceAbstraction m_producer;
|
||||
InterfaceAbstraction m_producer2; // Pipe with ETH2 header removal
|
||||
InterfaceAbstraction *m_pCurrentProducer;
|
||||
InterfaceAbstraction m_consumer;
|
||||
InterfaceAbstraction m_consumer2;
|
||||
InterfaceAbstraction m_defaultConsumer;
|
||||
|
||||
Byte m_sendBuffer1[m_BUFF_MAX_SIZE];
|
||||
Byte m_sendBuffer2[m_BUFF_MAX_SIZE];
|
||||
Byte m_sendBuffer3[m_BUFF_MAX_SIZE];
|
||||
size_t m_sendSize1;
|
||||
size_t m_sendSize2;
|
||||
size_t m_sendSize3;
|
||||
enum ipa_ip_type m_IpaIPType;
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
@@ -0,0 +1,700 @@
|
||||
/*
|
||||
* Copyright (c) 2017 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "FilteringEthernetBridgingTestFixture.h"
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Test 00: Destination IP address and subnet mask match against LAN subnet */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
class IpaFilterEthIPv4Test00 : public IpaFilteringEthernetBridgingTestFixture
|
||||
{
|
||||
public:
|
||||
IpaFilterEthIPv4Test00()
|
||||
{
|
||||
m_name = "IpaFilterEthIPv4Test00";
|
||||
m_description =
|
||||
"Filtering block test 01 - Ethernet Bridge, ETH2 filters, \
|
||||
IPv4 address (EP Filtering Table, \
|
||||
Insert all rules in a single commit) \
|
||||
1. Generate and commit three routing tables. \
|
||||
Each table contains a single \"bypass\" rule \
|
||||
(all data goes to output pipe 0, 1 and 2 (accordingly)) \
|
||||
2. Generate and commit 3 ETH2 filtering rules: \
|
||||
All MAC DST == (aabbccddee11) traffic goes to routing table 0 \
|
||||
All MAC SRC == (22eeddccbbaa) traffic goes to routing table 1 \
|
||||
All (1) traffic goes to routing table 2";
|
||||
m_minIPAHwType = IPA_HW_v2_5;
|
||||
m_maxIPAHwType = IPA_HW_MAX;
|
||||
Register(*this);
|
||||
m_pCurrentProducer = &m_producer2;
|
||||
}
|
||||
|
||||
virtual bool AddRules()
|
||||
{
|
||||
LOG_MSG_DEBUG("Entering");
|
||||
|
||||
const char bypass0[] = "bypass0";
|
||||
const char bypass1[] = "bypass1";
|
||||
const char bypass2[] = "bypass2";
|
||||
struct ipa_ioc_get_rt_tbl routing_table0,routing_table1,routing_table2;
|
||||
|
||||
if (!CreateThreeIPv4BypassRoutingTables (bypass0,bypass1,bypass2))
|
||||
{
|
||||
printf("CreateThreeIPv4BypassRoutingTables");
|
||||
return false;
|
||||
}
|
||||
|
||||
routing_table0.ip = IPA_IP_v4;
|
||||
strlcpy(routing_table0.name, bypass0, sizeof(routing_table0.name));
|
||||
if (!m_routing.GetRoutingTable(&routing_table0))
|
||||
{
|
||||
LOG_MSG_ERROR(
|
||||
"m_routing.GetRoutingTable(&routing_table0=0x%p)",
|
||||
&routing_table0);
|
||||
return false;
|
||||
}
|
||||
routing_table1.ip = IPA_IP_v4;
|
||||
strlcpy(routing_table1.name, bypass1, sizeof(routing_table1.name));
|
||||
if (!m_routing.GetRoutingTable(&routing_table1))
|
||||
{
|
||||
LOG_MSG_ERROR(
|
||||
"m_routing.GetRoutingTable(&routing_table1=0x%p)",
|
||||
&routing_table1);
|
||||
return false;
|
||||
}
|
||||
|
||||
routing_table2.ip = IPA_IP_v4;
|
||||
strlcpy(routing_table2.name, bypass2, sizeof(routing_table2.name));
|
||||
if (!m_routing.GetRoutingTable(&routing_table2))
|
||||
{
|
||||
LOG_MSG_ERROR(
|
||||
"m_routing.GetRoutingTable(&routing_table2=0x%p)",
|
||||
&routing_table2);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create 3 filter rules
|
||||
IPAFilteringTable FilterTable0;
|
||||
struct ipa_flt_rule_add flt_rule_entry;
|
||||
FilterTable0.Init(IPA_IP_v4,IPA_CLIENT_TEST2_PROD,false,3);
|
||||
|
||||
// Configuring Filtering Rule 0 - ETH2 DST
|
||||
FilterTable0.GeneratePresetRule(1,flt_rule_entry);
|
||||
flt_rule_entry.at_rear = true;
|
||||
flt_rule_entry.rule.retain_hdr = 1; // retain header removed in producer pipe
|
||||
flt_rule_entry.flt_rule_hdl = -1; // return value
|
||||
flt_rule_entry.status = -1; // return value
|
||||
flt_rule_entry.rule.action = IPA_PASS_TO_ROUTING;
|
||||
flt_rule_entry.rule.rt_tbl_hdl = routing_table0.hdl; // Handle corresponding to routing table 0
|
||||
flt_rule_entry.rule.attrib.attrib_mask = IPA_FLT_MAC_DST_ADDR_ETHER_II; // Filter using ETH2 DST address
|
||||
memcpy(flt_rule_entry.rule.attrib.dst_mac_addr_mask,
|
||||
m_MAC_ADDR_MASK_ALL,
|
||||
sizeof(flt_rule_entry.rule.attrib.dst_mac_addr_mask)); // ETH2 DST address mask
|
||||
memcpy(flt_rule_entry.rule.attrib.dst_mac_addr,
|
||||
m_ETH2_DST_ADDR,
|
||||
sizeof(flt_rule_entry.rule.attrib.dst_mac_addr)); // ETH2 DST address
|
||||
|
||||
if ((uint8_t)-1 == FilterTable0.AddRuleToTable(flt_rule_entry))
|
||||
{
|
||||
LOG_MSG_ERROR ("Adding RuleTable(0) to Filtering");
|
||||
return false;
|
||||
} else
|
||||
{
|
||||
LOG_MSG_DEBUG("flt rule hdl0=0x%x, status=0x%x",
|
||||
FilterTable0.ReadRuleFromTable(0)->flt_rule_hdl,
|
||||
FilterTable0.ReadRuleFromTable(0)->status);
|
||||
}
|
||||
|
||||
// Configuring Filtering Rule 1 - ETH2 SRC
|
||||
flt_rule_entry.rule.rt_tbl_hdl=routing_table1.hdl; // Handle corresponding to routing table 1
|
||||
flt_rule_entry.rule.attrib.attrib_mask = IPA_FLT_MAC_SRC_ADDR_ETHER_II; // Filter using ETH2 SRC address
|
||||
memcpy(flt_rule_entry.rule.attrib.src_mac_addr_mask,
|
||||
m_MAC_ADDR_MASK_ALL,
|
||||
sizeof(flt_rule_entry.rule.attrib.src_mac_addr_mask)); // ETH2 SRC address mask
|
||||
memcpy(flt_rule_entry.rule.attrib.src_mac_addr,
|
||||
m_ETH2_SRC_ADDR,
|
||||
sizeof(flt_rule_entry.rule.attrib.src_mac_addr)); // ETH2 SRC address
|
||||
if ((uint8_t)-1 == FilterTable0.AddRuleToTable(flt_rule_entry))
|
||||
{
|
||||
LOG_MSG_ERROR ("Adding RuleTable(1) to Filtering");
|
||||
return false;
|
||||
} else
|
||||
{
|
||||
LOG_MSG_DEBUG("flt rule hdl0=0x%x, status=0x%x",
|
||||
FilterTable0.ReadRuleFromTable(1)->flt_rule_hdl,
|
||||
FilterTable0.ReadRuleFromTable(1)->status);
|
||||
}
|
||||
|
||||
// Configuring Filtering Rule 2 - Accept all
|
||||
flt_rule_entry.rule.rt_tbl_hdl = routing_table2.hdl;
|
||||
flt_rule_entry.rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
|
||||
flt_rule_entry.rule.attrib.u.v4.dst_addr_mask = 0x00000000; // Accept all
|
||||
flt_rule_entry.rule.attrib.u.v4.dst_addr = 0x00000000; // Has no effect
|
||||
if (((uint8_t)-1 == FilterTable0.AddRuleToTable(flt_rule_entry)) ||
|
||||
!m_filtering.AddFilteringRule(FilterTable0.GetFilteringTable()))
|
||||
{
|
||||
LOG_MSG_ERROR ("Adding RuleTable(2) to Filtering");
|
||||
return false;
|
||||
} else
|
||||
{
|
||||
LOG_MSG_DEBUG("flt rule hdl0=0x%x, status=0x%x",
|
||||
FilterTable0.ReadRuleFromTable(2)->flt_rule_hdl,
|
||||
FilterTable0.ReadRuleFromTable(2)->status);
|
||||
}
|
||||
LOG_MSG_DEBUG("Leaving function\n");
|
||||
return true;
|
||||
|
||||
}// AddRules()
|
||||
|
||||
virtual bool ModifyPackets()
|
||||
{
|
||||
memcpy(&m_sendBuffer1[ETH2_DST_ADDR_OFFSET],
|
||||
m_ETH2_DST_ADDR, ETH_ALEN);
|
||||
|
||||
memcpy(&m_sendBuffer2[ETH2_DST_ADDR_OFFSET],
|
||||
m_ETH2_DST_ADDR, ETH_ALEN);
|
||||
m_sendBuffer2[ETH2_DST_ADDR_OFFSET] = 0x00;
|
||||
memcpy(&m_sendBuffer2[ETH2_SRC_ADDR_OFFSET],
|
||||
m_ETH2_SRC_ADDR, ETH_ALEN);
|
||||
|
||||
// swap destination and source addresses so that both
|
||||
// rule0 and rule1 are miss and rule2 (accept all) is hit
|
||||
memcpy(&m_sendBuffer3[ETH2_DST_ADDR_OFFSET],
|
||||
m_ETH2_SRC_ADDR, ETH_ALEN);
|
||||
memcpy(&m_sendBuffer3[ETH2_SRC_ADDR_OFFSET],
|
||||
m_ETH2_DST_ADDR, ETH_ALEN);
|
||||
|
||||
return true;
|
||||
}// ModifyPacktes ()
|
||||
};
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Test 01: Destination IP address and subnet mask match against LAN subnet */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
class IpaFilterEthIPv4Test01 : public IpaFilteringEthernetBridgingTestFixture
|
||||
{
|
||||
public:
|
||||
IpaFilterEthIPv4Test01()
|
||||
{
|
||||
m_name = "IpaFilterEthIPv4Test01";
|
||||
m_description =
|
||||
"Filtering block test 01 - Ethernet Bridge, ETH2 filters, \
|
||||
IPv4 address (EP Filtering Table, \
|
||||
Insert all rules in a single commit) \
|
||||
1. Generate and commit three routing tables. \
|
||||
Each table contains a single \"bypass\" rule \
|
||||
(all data goes to output pipe 0, 1 and 2 (accordingly)) \
|
||||
2. Generate and commit 3 ETH2 filtering rules: \
|
||||
All MAC DST == (aabbccddee11) traffic goes to routing table 0 \
|
||||
All MAC ETH TYPE == (0800) traffic goes to routing table 1 \
|
||||
All (1) traffic goes to routing table 2";
|
||||
m_minIPAHwType = IPA_HW_v2_5;
|
||||
m_maxIPAHwType = IPA_HW_MAX;
|
||||
Register(*this);
|
||||
m_pCurrentProducer = &m_producer2;
|
||||
}
|
||||
|
||||
virtual bool AddRules()
|
||||
{
|
||||
LOG_MSG_DEBUG("Entering");
|
||||
|
||||
const char bypass0[] = "bypass0";
|
||||
const char bypass1[] = "bypass1";
|
||||
const char bypass2[] = "bypass2";
|
||||
struct ipa_ioc_get_rt_tbl routing_table0,routing_table1,routing_table2;
|
||||
|
||||
if (!CreateThreeIPv4BypassRoutingTables (bypass0,bypass1,bypass2))
|
||||
{
|
||||
printf("CreateThreeIPv4BypassRoutingTables");
|
||||
return false;
|
||||
}
|
||||
|
||||
routing_table0.ip = IPA_IP_v4;
|
||||
strlcpy(routing_table0.name, bypass0, sizeof(routing_table0.name));
|
||||
if (!m_routing.GetRoutingTable(&routing_table0))
|
||||
{
|
||||
LOG_MSG_ERROR(
|
||||
"m_routing.GetRoutingTable(&routing_table0=0x%p)",
|
||||
&routing_table0);
|
||||
return false;
|
||||
}
|
||||
routing_table1.ip = IPA_IP_v4;
|
||||
strlcpy(routing_table1.name, bypass1, sizeof(routing_table1.name));
|
||||
if (!m_routing.GetRoutingTable(&routing_table1))
|
||||
{
|
||||
LOG_MSG_ERROR("m_routing.GetRoutingTable(&routing_table1=0x%p)",
|
||||
&routing_table1);
|
||||
return false;
|
||||
}
|
||||
|
||||
routing_table2.ip = IPA_IP_v4;
|
||||
strlcpy(routing_table2.name, bypass2, sizeof(routing_table2.name));
|
||||
if (!m_routing.GetRoutingTable(&routing_table2))
|
||||
{
|
||||
LOG_MSG_ERROR(
|
||||
"m_routing.GetRoutingTable(&routing_table2=0x%p)",
|
||||
&routing_table2);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create 3 filter rules
|
||||
IPAFilteringTable FilterTable0;
|
||||
struct ipa_flt_rule_add flt_rule_entry;
|
||||
FilterTable0.Init(IPA_IP_v4,IPA_CLIENT_TEST2_PROD,false,3);
|
||||
|
||||
// Configuring Filtering Rule 0 - ETH2 DST
|
||||
FilterTable0.GeneratePresetRule(1,flt_rule_entry);
|
||||
flt_rule_entry.at_rear = true;
|
||||
flt_rule_entry.rule.retain_hdr = 1; // retain header removed in producer pipe
|
||||
flt_rule_entry.flt_rule_hdl = -1; // return value
|
||||
flt_rule_entry.status = -1; // return value
|
||||
flt_rule_entry.rule.action = IPA_PASS_TO_ROUTING;
|
||||
flt_rule_entry.rule.rt_tbl_hdl = routing_table0.hdl;
|
||||
|
||||
// DST
|
||||
flt_rule_entry.rule.attrib.attrib_mask = IPA_FLT_MAC_DST_ADDR_ETHER_II;
|
||||
memcpy(flt_rule_entry.rule.attrib.dst_mac_addr_mask,
|
||||
m_MAC_ADDR_MASK_ALL,
|
||||
sizeof(flt_rule_entry.rule.attrib.dst_mac_addr_mask));
|
||||
memcpy(flt_rule_entry.rule.attrib.dst_mac_addr,
|
||||
m_ETH2_DST_ADDR,
|
||||
sizeof(flt_rule_entry.rule.attrib.dst_mac_addr));
|
||||
if ((uint8_t)-1 == FilterTable0.AddRuleToTable(flt_rule_entry))
|
||||
{
|
||||
LOG_MSG_ERROR ("Adding RuleTable(0) to Filtering");
|
||||
return false;
|
||||
} else
|
||||
{
|
||||
LOG_MSG_DEBUG("flt rule hdl0=0x%x, status=0x%x",
|
||||
FilterTable0.ReadRuleFromTable(0)->flt_rule_hdl,
|
||||
FilterTable0.ReadRuleFromTable(0)->status);
|
||||
}
|
||||
|
||||
// Configuring Filtering Rule 1 - ETH2 type
|
||||
flt_rule_entry.rule.rt_tbl_hdl=routing_table1.hdl;
|
||||
flt_rule_entry.rule.attrib.attrib_mask = IPA_FLT_MAC_ETHER_TYPE;
|
||||
flt_rule_entry.rule.attrib.ether_type = ETH_P_IP;
|
||||
if ((uint8_t)-1 == FilterTable0.AddRuleToTable(flt_rule_entry))
|
||||
{
|
||||
LOG_MSG_ERROR ("Adding RuleTable(1) to Filtering");
|
||||
return false;
|
||||
} else
|
||||
{
|
||||
LOG_MSG_DEBUG("flt rule hdl0=0x%x, status=0x%x",
|
||||
FilterTable0.ReadRuleFromTable(1)->flt_rule_hdl,
|
||||
FilterTable0.ReadRuleFromTable(1)->status);
|
||||
}
|
||||
|
||||
// Configuring Filtering Rule 2 - Accept all
|
||||
flt_rule_entry.rule.rt_tbl_hdl = routing_table2.hdl;
|
||||
flt_rule_entry.rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
|
||||
flt_rule_entry.rule.attrib.u.v4.dst_addr_mask = 0x00000000; // Accept all
|
||||
flt_rule_entry.rule.attrib.u.v4.dst_addr = 0x00000000; // Has no effect
|
||||
if (((uint8_t)-1 == FilterTable0.AddRuleToTable(flt_rule_entry)) ||
|
||||
!m_filtering.AddFilteringRule(FilterTable0.GetFilteringTable()))
|
||||
{
|
||||
LOG_MSG_ERROR ("Adding RuleTable(2) to Filtering");
|
||||
return false;
|
||||
} else
|
||||
{
|
||||
LOG_MSG_DEBUG("flt rule hdl0=0x%x, status=0x%x",
|
||||
FilterTable0.ReadRuleFromTable(2)->flt_rule_hdl,
|
||||
FilterTable0.ReadRuleFromTable(2)->status);
|
||||
}
|
||||
LOG_MSG_DEBUG("Leaving function\n");
|
||||
return true;
|
||||
|
||||
}// AddRules()
|
||||
|
||||
virtual bool ModifyPackets()
|
||||
{
|
||||
uint16_t ether_type = ETH_P_IP;
|
||||
uint16_t wrong_ether_type = 0x1234;
|
||||
|
||||
// DST && SRC correct
|
||||
memcpy(&m_sendBuffer1[ETH2_DST_ADDR_OFFSET],
|
||||
m_ETH2_DST_ADDR, ETH_ALEN);
|
||||
memcpy(&m_sendBuffer1[ETH2_SRC_ADDR_OFFSET],
|
||||
m_ETH2_SRC_ADDR, ETH_ALEN);
|
||||
|
||||
// DST is wrong, ETH2 type is correct
|
||||
memcpy(&m_sendBuffer2[ETH2_DST_ADDR_OFFSET],
|
||||
m_ETH2_DST_ADDR, ETH_ALEN);
|
||||
m_sendBuffer2[ETH2_DST_ADDR_OFFSET] = 0x00;
|
||||
memcpy(&m_sendBuffer2[ETH2_ETH_TYPE_OFFSET],
|
||||
ðer_type, sizeof(ether_type));
|
||||
|
||||
// DST is wrong, ETH2 type is wrong
|
||||
memcpy(&m_sendBuffer3[ETH2_DST_ADDR_OFFSET],
|
||||
m_ETH2_DST_ADDR, ETH_ALEN);
|
||||
m_sendBuffer3[ETH2_DST_ADDR_OFFSET] = 0x00;
|
||||
memcpy(&m_sendBuffer3[ETH2_ETH_TYPE_OFFSET],
|
||||
&wrong_ether_type, sizeof(wrong_ether_type));
|
||||
|
||||
return true;
|
||||
}// ModifyPacktes ()
|
||||
};
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Test 02: Destination IP address and subnet mask match against LAN subnet */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
class IpaFilterEthIPv4Test02 : public IpaFilteringEthernetBridgingTestFixture
|
||||
{
|
||||
public:
|
||||
IpaFilterEthIPv4Test02()
|
||||
{
|
||||
m_name = "IpaFilterEthIPv4Test02";
|
||||
m_description =
|
||||
"Filtering block test 02 - Ethernet Bridge, ETH2 filters, \
|
||||
IPv4 address (EP Filtering Table, \
|
||||
Insert all rules in a single commit) \
|
||||
1. Generate and commit three routing tables. \
|
||||
Each table contains a single \"bypass\" rule \
|
||||
(all data goes to output pipe 0, 1 and 2 (accordingly)) \
|
||||
2. Generate and commit 3 ETH2 filtering rules: \
|
||||
All MAC SRC == (22eeddccbbaa) traffic goes to routing table 0 \
|
||||
All MAC ETH TYPE == (0801) traffic goes to routing table 1 \
|
||||
All (1) traffic goes to routing table 2";
|
||||
m_minIPAHwType = IPA_HW_v2_5;
|
||||
m_maxIPAHwType = IPA_HW_MAX;
|
||||
Register(*this);
|
||||
m_pCurrentProducer = &m_producer2;
|
||||
}
|
||||
|
||||
virtual bool AddRules()
|
||||
{
|
||||
LOG_MSG_DEBUG("Entering");
|
||||
|
||||
const char bypass0[] = "bypass0";
|
||||
const char bypass1[] = "bypass1";
|
||||
const char bypass2[] = "bypass2";
|
||||
struct ipa_ioc_get_rt_tbl routing_table0,routing_table1,routing_table2;
|
||||
|
||||
if (!CreateThreeIPv4BypassRoutingTables (bypass0,bypass1,bypass2))
|
||||
{
|
||||
printf("CreateThreeIPv4BypassRoutingTables");
|
||||
return false;
|
||||
}
|
||||
|
||||
routing_table0.ip = IPA_IP_v4;
|
||||
strlcpy(routing_table0.name, bypass0, sizeof(routing_table0.name));
|
||||
if (!m_routing.GetRoutingTable(&routing_table0))
|
||||
{
|
||||
LOG_MSG_ERROR(
|
||||
"m_routing.GetRoutingTable(&routing_table0=0x%p)",
|
||||
&routing_table0);
|
||||
return false;
|
||||
}
|
||||
routing_table1.ip = IPA_IP_v4;
|
||||
strlcpy(routing_table1.name, bypass1, sizeof(routing_table1.name));
|
||||
if (!m_routing.GetRoutingTable(&routing_table1))
|
||||
{
|
||||
LOG_MSG_ERROR("m_routing.GetRoutingTable(&routing_table1=0x%p)",
|
||||
&routing_table1);
|
||||
return false;
|
||||
}
|
||||
|
||||
routing_table2.ip = IPA_IP_v4;
|
||||
strlcpy(routing_table2.name, bypass2, sizeof(routing_table2.name));
|
||||
if (!m_routing.GetRoutingTable(&routing_table2))
|
||||
{
|
||||
LOG_MSG_ERROR(
|
||||
"m_routing.GetRoutingTable(&routing_table2=0x%p)",
|
||||
&routing_table2);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create 3 filter rules
|
||||
IPAFilteringTable FilterTable0;
|
||||
struct ipa_flt_rule_add flt_rule_entry;
|
||||
FilterTable0.Init(IPA_IP_v4,IPA_CLIENT_TEST2_PROD,false,3);
|
||||
|
||||
// Configuring Filtering Rule 0 - ETH2 SRC
|
||||
FilterTable0.GeneratePresetRule(1,flt_rule_entry);
|
||||
flt_rule_entry.at_rear = true;
|
||||
flt_rule_entry.rule.retain_hdr = 1; // retain header removed in producer pipe
|
||||
flt_rule_entry.flt_rule_hdl = -1; // return value
|
||||
flt_rule_entry.status = -1; // return value
|
||||
flt_rule_entry.rule.action = IPA_PASS_TO_ROUTING;
|
||||
flt_rule_entry.rule.rt_tbl_hdl = routing_table0.hdl;
|
||||
flt_rule_entry.rule.attrib.attrib_mask = IPA_FLT_MAC_SRC_ADDR_ETHER_II;
|
||||
memcpy(flt_rule_entry.rule.attrib.src_mac_addr_mask,
|
||||
m_MAC_ADDR_MASK_ALL,
|
||||
sizeof(flt_rule_entry.rule.attrib.src_mac_addr_mask));
|
||||
memcpy(flt_rule_entry.rule.attrib.src_mac_addr,
|
||||
m_ETH2_SRC_ADDR,
|
||||
sizeof(flt_rule_entry.rule.attrib.src_mac_addr));
|
||||
|
||||
if ((uint8_t)-1 == FilterTable0.AddRuleToTable(flt_rule_entry))
|
||||
{
|
||||
LOG_MSG_ERROR ("Adding RuleTable(0) to Filtering");
|
||||
return false;
|
||||
} else
|
||||
{
|
||||
LOG_MSG_DEBUG("flt rule hdl0=0x%x, status=0x%x",
|
||||
FilterTable0.ReadRuleFromTable(0)->flt_rule_hdl,
|
||||
FilterTable0.ReadRuleFromTable(0)->status);
|
||||
}
|
||||
|
||||
// Configuring Filtering Rule 1 - ETH2 type
|
||||
flt_rule_entry.rule.rt_tbl_hdl=routing_table1.hdl;
|
||||
flt_rule_entry.rule.attrib.attrib_mask = IPA_FLT_MAC_ETHER_TYPE;
|
||||
flt_rule_entry.rule.attrib.ether_type = ETH_P_IP + 1;
|
||||
if ((uint8_t)-1 == FilterTable0.AddRuleToTable(flt_rule_entry))
|
||||
{
|
||||
LOG_MSG_ERROR ("Adding RuleTable(1) to Filtering");
|
||||
return false;
|
||||
} else
|
||||
{
|
||||
LOG_MSG_DEBUG("flt rule hdl0=0x%x, status=0x%x",
|
||||
FilterTable0.ReadRuleFromTable(1)->flt_rule_hdl,
|
||||
FilterTable0.ReadRuleFromTable(1)->status);
|
||||
}
|
||||
|
||||
// Configuring Filtering Rule 2 - Accept all
|
||||
flt_rule_entry.rule.rt_tbl_hdl = routing_table2.hdl;
|
||||
flt_rule_entry.rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
|
||||
flt_rule_entry.rule.attrib.u.v4.dst_addr_mask = 0x00000000; // Accept all
|
||||
flt_rule_entry.rule.attrib.u.v4.dst_addr = 0x00000000; // Has no effect
|
||||
if (((uint8_t)-1 == FilterTable0.AddRuleToTable(flt_rule_entry)) ||
|
||||
!m_filtering.AddFilteringRule(FilterTable0.GetFilteringTable()))
|
||||
{
|
||||
LOG_MSG_ERROR ("Adding RuleTable(2) to Filtering");
|
||||
return false;
|
||||
} else
|
||||
{
|
||||
LOG_MSG_DEBUG("flt rule hdl0=0x%x, status=0x%x",
|
||||
FilterTable0.ReadRuleFromTable(2)->flt_rule_hdl,
|
||||
FilterTable0.ReadRuleFromTable(2)->status);
|
||||
}
|
||||
LOG_MSG_DEBUG("Leaving function\n");
|
||||
return true;
|
||||
|
||||
}// AddRules()
|
||||
|
||||
virtual bool ModifyPackets()
|
||||
{
|
||||
uint16_t ether_type = ETH_P_IP;
|
||||
uint16_t wrong_ether_type = 0x1234;
|
||||
|
||||
memcpy(&m_sendBuffer1[ETH2_SRC_ADDR_OFFSET],
|
||||
m_ETH2_SRC_ADDR, ETH_ALEN);
|
||||
memcpy(&m_sendBuffer1[ETH2_ETH_TYPE_OFFSET],
|
||||
ðer_type, sizeof(ether_type));
|
||||
|
||||
memcpy(&m_sendBuffer2[ETH2_SRC_ADDR_OFFSET],
|
||||
m_ETH2_SRC_ADDR, ETH_ALEN);
|
||||
m_sendBuffer2[ETH2_SRC_ADDR_OFFSET] = 0x00;
|
||||
memcpy(&m_sendBuffer2[ETH2_DST_ADDR_OFFSET],
|
||||
m_ETH2_DST_ADDR, ETH_ALEN);
|
||||
ether_type++;
|
||||
memcpy(&m_sendBuffer2[ETH2_ETH_TYPE_OFFSET],
|
||||
ðer_type, sizeof(ether_type));
|
||||
|
||||
memcpy(&m_sendBuffer3[ETH2_DST_ADDR_OFFSET],
|
||||
m_ETH2_SRC_ADDR, ETH_ALEN);
|
||||
memcpy(&m_sendBuffer3[ETH2_SRC_ADDR_OFFSET],
|
||||
m_ETH2_DST_ADDR, ETH_ALEN);
|
||||
memcpy(&m_sendBuffer3[ETH2_ETH_TYPE_OFFSET],
|
||||
&wrong_ether_type, sizeof(wrong_ether_type));
|
||||
|
||||
return true;
|
||||
}// ModifyPacktes ()
|
||||
};
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Test 03: Destination IP address and subnet mask match against LAN subnet */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
class IpaFilterEthIPv4Test03 : public IpaFilteringEthernetBridgingTestFixture
|
||||
{
|
||||
public:
|
||||
IpaFilterEthIPv4Test03()
|
||||
{
|
||||
m_name = "IpaFilterEthIPv4Test03";
|
||||
m_description =
|
||||
"Filtering block test 03 - Ethernet Bridge, ETH2 filters, \
|
||||
IPv4 address (EP Filtering Table, \
|
||||
Insert all rules in a single commit) \
|
||||
1. Generate and commit three routing tables. \
|
||||
Each table contains a single \"bypass\" rule \
|
||||
(all data goes to output pipe 0, 1 and 2 (accordingly)) \
|
||||
2. Generate and commit 3 ETH2 filtering rules: \
|
||||
All MAC SRC == (22eeddccbbaa) traffic goes to routing table 0 \
|
||||
All MAC ETH TYPE == (0800) traffic goes to routing table 1 \
|
||||
All (1) traffic goes to routing table 2";
|
||||
m_minIPAHwType = IPA_HW_v2_5;
|
||||
m_maxIPAHwType = IPA_HW_MAX;
|
||||
Register(*this);
|
||||
m_pCurrentProducer = &m_producer2;
|
||||
}
|
||||
|
||||
virtual bool AddRules()
|
||||
{
|
||||
LOG_MSG_DEBUG("Entering");
|
||||
|
||||
const char bypass0[] = "bypass0";
|
||||
const char bypass1[] = "bypass1";
|
||||
const char bypass2[] = "bypass2";
|
||||
struct ipa_ioc_get_rt_tbl routing_table0,routing_table1,routing_table2;
|
||||
|
||||
if (!CreateThreeIPv4BypassRoutingTables (bypass0,bypass1,bypass2))
|
||||
{
|
||||
printf("CreateThreeIPv4BypassRoutingTables");
|
||||
return false;
|
||||
}
|
||||
|
||||
routing_table0.ip = IPA_IP_v4;
|
||||
strlcpy(routing_table0.name, bypass0, sizeof(routing_table0.name));
|
||||
if (!m_routing.GetRoutingTable(&routing_table0))
|
||||
{
|
||||
LOG_MSG_ERROR(
|
||||
"m_routing.GetRoutingTable(&routing_table0=0x%p)",
|
||||
&routing_table0);
|
||||
return false;
|
||||
}
|
||||
routing_table1.ip = IPA_IP_v4;
|
||||
strlcpy(routing_table1.name, bypass1, sizeof(routing_table1.name));
|
||||
if (!m_routing.GetRoutingTable(&routing_table1))
|
||||
{
|
||||
LOG_MSG_ERROR("m_routing.GetRoutingTable(&routing_table1=0x%p)",
|
||||
&routing_table1);
|
||||
return false;
|
||||
}
|
||||
|
||||
routing_table2.ip = IPA_IP_v4;
|
||||
strlcpy(routing_table2.name, bypass2, sizeof(routing_table2.name));
|
||||
if (!m_routing.GetRoutingTable(&routing_table2))
|
||||
{
|
||||
LOG_MSG_ERROR(
|
||||
"m_routing.GetRoutingTable(&routing_table2=0x%p)",
|
||||
&routing_table2);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create 3 filter rules
|
||||
IPAFilteringTable FilterTable0;
|
||||
struct ipa_flt_rule_add flt_rule_entry;
|
||||
FilterTable0.Init(IPA_IP_v4,IPA_CLIENT_TEST2_PROD,false,3);
|
||||
|
||||
// Configuring Filtering Rule 0 - ETH2 DST
|
||||
FilterTable0.GeneratePresetRule(1,flt_rule_entry);
|
||||
flt_rule_entry.at_rear = true;
|
||||
flt_rule_entry.rule.retain_hdr = 1; // retain header removed in producer pipe
|
||||
flt_rule_entry.flt_rule_hdl = -1; // return value
|
||||
flt_rule_entry.status = -1; // return value
|
||||
flt_rule_entry.rule.action = IPA_PASS_TO_ROUTING;
|
||||
flt_rule_entry.rule.rt_tbl_hdl = routing_table0.hdl;
|
||||
|
||||
// SRC
|
||||
flt_rule_entry.rule.attrib.attrib_mask = IPA_FLT_MAC_SRC_ADDR_ETHER_II;
|
||||
memcpy(flt_rule_entry.rule.attrib.src_mac_addr_mask,
|
||||
m_MAC_ADDR_MASK_ALL,
|
||||
sizeof(flt_rule_entry.rule.attrib.src_mac_addr_mask));
|
||||
memcpy(flt_rule_entry.rule.attrib.src_mac_addr,
|
||||
m_ETH2_SRC_ADDR,
|
||||
sizeof(flt_rule_entry.rule.attrib.src_mac_addr));
|
||||
if ((uint8_t)-1 == FilterTable0.AddRuleToTable(flt_rule_entry))
|
||||
{
|
||||
LOG_MSG_ERROR ("Adding RuleTable(0) to Filtering");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Configuring Filtering Rule 1 - ETH2 type
|
||||
flt_rule_entry.rule.rt_tbl_hdl=routing_table1.hdl;
|
||||
flt_rule_entry.rule.attrib.attrib_mask = IPA_FLT_MAC_ETHER_TYPE;
|
||||
flt_rule_entry.rule.attrib.ether_type = ETH_P_IP;
|
||||
if ((uint8_t)-1 == FilterTable0.AddRuleToTable(flt_rule_entry))
|
||||
{
|
||||
LOG_MSG_ERROR ("Adding RuleTable(1) to Filtering");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Configuring Filtering Rule 2 - Accept all
|
||||
flt_rule_entry.rule.rt_tbl_hdl = routing_table2.hdl;
|
||||
flt_rule_entry.rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
|
||||
flt_rule_entry.rule.attrib.u.v4.dst_addr_mask = 0x00000000; // Accept all
|
||||
flt_rule_entry.rule.attrib.u.v4.dst_addr = 0x00000000; // Has no effect
|
||||
if (((uint8_t)-1 == FilterTable0.AddRuleToTable(flt_rule_entry)) ||
|
||||
!m_filtering.AddFilteringRule(FilterTable0.GetFilteringTable()))
|
||||
{
|
||||
LOG_MSG_ERROR ("Adding RuleTable(2) to Filtering");
|
||||
return false;
|
||||
}
|
||||
|
||||
LOG_MSG_DEBUG("flt rule status: s0=0x%x, s1=0x%x s2=0x%x",
|
||||
FilterTable0.ReadRuleFromTable(0)->status,
|
||||
FilterTable0.ReadRuleFromTable(1)->status,
|
||||
FilterTable0.ReadRuleFromTable(2)->status);
|
||||
|
||||
LOG_MSG_DEBUG("Leaving function\n");
|
||||
return true;
|
||||
|
||||
}// AddRules()
|
||||
|
||||
virtual bool ModifyPackets()
|
||||
{
|
||||
uint16_t ether_type = ETH_P_IP;
|
||||
uint16_t wrong_ether_type = 0x1234;
|
||||
|
||||
// SRC correct, DST wrong, ETH type wrong
|
||||
memcpy(&m_sendBuffer1[ETH2_SRC_ADDR_OFFSET],
|
||||
m_ETH2_SRC_ADDR, ETH_ALEN);
|
||||
memcpy(&m_sendBuffer1[ETH2_DST_ADDR_OFFSET],
|
||||
m_ETH2_DST_ADDR, ETH_ALEN);
|
||||
m_sendBuffer1[ETH2_DST_ADDR_OFFSET] = 0x00;
|
||||
memcpy(&m_sendBuffer1[ETH2_ETH_TYPE_OFFSET],
|
||||
&wrong_ether_type, sizeof(wrong_ether_type));
|
||||
|
||||
// SRC wrong, DST wrong, ETH type correct
|
||||
memcpy(&m_sendBuffer2[ETH2_SRC_ADDR_OFFSET],
|
||||
m_ETH2_SRC_ADDR, ETH_ALEN);
|
||||
m_sendBuffer2[ETH2_SRC_ADDR_OFFSET] = 0x00;
|
||||
memcpy(&m_sendBuffer2[ETH2_DST_ADDR_OFFSET],
|
||||
m_ETH2_DST_ADDR, ETH_ALEN);
|
||||
m_sendBuffer2[ETH2_DST_ADDR_OFFSET] = 0x00;
|
||||
memcpy(&m_sendBuffer2[ETH2_ETH_TYPE_OFFSET],
|
||||
ðer_type, sizeof(ether_type));
|
||||
|
||||
// SRC wrong, DST correct, ETH type wrong
|
||||
memcpy(&m_sendBuffer3[ETH2_SRC_ADDR_OFFSET],
|
||||
m_ETH2_SRC_ADDR, ETH_ALEN);
|
||||
m_sendBuffer3[ETH2_SRC_ADDR_OFFSET] = 0x00;
|
||||
memcpy(&m_sendBuffer3[ETH2_DST_ADDR_OFFSET],
|
||||
m_ETH2_DST_ADDR, ETH_ALEN);
|
||||
memcpy(&m_sendBuffer3[ETH2_ETH_TYPE_OFFSET],
|
||||
&wrong_ether_type, sizeof(wrong_ether_type));
|
||||
|
||||
return true;
|
||||
}// ModifyPacktes ()
|
||||
};
|
||||
|
||||
static IpaFilterEthIPv4Test00 ipaFilterEthIPv4Test00;
|
||||
static IpaFilterEthIPv4Test01 ipaFilterEthIPv4Test01;
|
||||
static IpaFilterEthIPv4Test02 ipaFilterEthIPv4Test02;
|
||||
static IpaFilterEthIPv4Test03 ipaFilterEthIPv4Test03;
|
||||
10803
qcom/opensource/dataipa/kernel-tests/FilteringTest.cpp
Normal file
10803
qcom/opensource/dataipa/kernel-tests/FilteringTest.cpp
Normal file
File diff suppressed because it is too large
Load Diff
273
qcom/opensource/dataipa/kernel-tests/HeaderInsertion.cpp
Normal file
273
qcom/opensource/dataipa/kernel-tests/HeaderInsertion.cpp
Normal file
@@ -0,0 +1,273 @@
|
||||
/*
|
||||
* Copyright (c) 2017 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* Changes from Qualcomm Innovation Center are provided under the following license:
|
||||
*
|
||||
* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted (subject to the limitations in the
|
||||
* disclaimer below) provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* * Neither the name of Qualcomm Innovation Center, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
|
||||
* GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
|
||||
* HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <cstring>
|
||||
|
||||
#include "HeaderInsertion.h"
|
||||
#include "TestsUtils.h"
|
||||
|
||||
#define LOG_IOCTL_RETURN_VALUE(nRetVal) \
|
||||
printf("%s()- %s\n", __func__, \
|
||||
(-1 == nRetVal) ? "Fail" : "Success");
|
||||
|
||||
bool HeaderInsertion::AddHeader(struct ipa_ioc_add_hdr *pHeaderTableToAdd)
|
||||
{
|
||||
int nRetVal = 0;
|
||||
/*call the Driver ioctl in order to add header*/
|
||||
nRetVal = ioctl(m_fd, IPA_IOC_ADD_HDR, pHeaderTableToAdd);
|
||||
LOG_IOCTL_RETURN_VALUE(nRetVal);
|
||||
return (-1 != nRetVal);
|
||||
}
|
||||
|
||||
bool HeaderInsertion::addHeaderHpc(const string& name, uint8_t* header, const size_t headerLen, bool isPartial, enum ipa_client_type ipaClient){
|
||||
if(name.empty() || name.size() >= IPA_RESOURCE_NAME_MAX){
|
||||
return false;
|
||||
}
|
||||
int fd = open(CONFIGURATION_NODE_PATH, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
cout << "failed to open " << CONFIGURATION_NODE_PATH << endl;
|
||||
return false;
|
||||
}
|
||||
struct ipa_ioc_add_hdr *iocH = static_cast<struct ipa_ioc_add_hdr*>(calloc(1, sizeof(*iocH) + sizeof(struct ipa_hdr_add)));
|
||||
if(!iocH){
|
||||
return false;
|
||||
}
|
||||
iocH->commit = 1;
|
||||
iocH->num_hdrs = 1;
|
||||
struct ipa_hdr_add *h = &iocH->hdr[0];
|
||||
strlcpy(h->name, name.c_str(), IPA_RESOURCE_NAME_MAX);
|
||||
memcpy(h->hdr, header, headerLen);
|
||||
h->hdr_len = headerLen;
|
||||
h->hdr_hdl = -1;
|
||||
h->status = -1;
|
||||
h->is_partial = isPartial;
|
||||
cout << "h->name=" << h->name << ", h->is_partial=" << h->is_partial << endl;
|
||||
int result = ioctl(fd, IPA_TEST_IOC_ADD_HDR_HPC, iocH);
|
||||
if(result || h->status){
|
||||
free(iocH);
|
||||
close(fd);
|
||||
return false;
|
||||
}
|
||||
cout << "result=" << result << ", status=" << h->status << ", ipaClient=" << ipaClient << endl;
|
||||
struct ipa_pkt_init_ex_hdr_ofst_set lookup;
|
||||
lookup.ep = ipaClient;
|
||||
strlcpy(lookup.name, name.c_str(), IPA_RESOURCE_NAME_MAX);
|
||||
result = ioctl(fd, IPA_TEST_IOC_PKT_INIT_EX_SET_HDR_OFST , &lookup);
|
||||
if (result) {
|
||||
free(iocH);
|
||||
close(fd);
|
||||
return false;
|
||||
}
|
||||
free(iocH);
|
||||
close(fd);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool HeaderInsertion::DeleteHeader(struct ipa_ioc_del_hdr *pHeaderTableToDelete)
|
||||
{
|
||||
int nRetVal = 0;
|
||||
/*call the Driver ioctl in order to remove header*/
|
||||
nRetVal = ioctl(m_fd, IPA_IOC_DEL_HDR , pHeaderTableToDelete);
|
||||
LOG_IOCTL_RETURN_VALUE(nRetVal);
|
||||
return (-1 != nRetVal);
|
||||
}
|
||||
|
||||
bool HeaderInsertion::DeleteHeader(const string& name){
|
||||
if(name.empty() || name.size() >= IPA_RESOURCE_NAME_MAX){
|
||||
return false;
|
||||
}
|
||||
int hdl = GetHeaderHandle(name);
|
||||
if(hdl == -1){
|
||||
return false;
|
||||
}
|
||||
struct ipa_ioc_del_hdr *iocD = static_cast<struct ipa_ioc_del_hdr*>(calloc(1, sizeof(*iocD) + sizeof(struct ipa_hdr_del)));
|
||||
if(!iocD){
|
||||
return false;
|
||||
}
|
||||
iocD->commit = 1;
|
||||
iocD->num_hdls = 1;
|
||||
struct ipa_hdr_del *h = &iocD->hdl[0];
|
||||
h->hdl = hdl;
|
||||
h->status = -1;
|
||||
cout << "h->hdl=" << h->hdl << endl;
|
||||
if(!DeleteHeader(iocD)){
|
||||
free(iocD);
|
||||
return false;
|
||||
}
|
||||
free(iocD);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool HeaderInsertion::AddProcCtx(struct ipa_ioc_add_hdr_proc_ctx *procCtxTable)
|
||||
{
|
||||
int retval = 0;
|
||||
|
||||
retval = ioctl(m_fd, IPA_IOC_ADD_HDR_PROC_CTX, procCtxTable);
|
||||
if (retval) {
|
||||
printf("%s(), failed adding ProcCtx rule table %p\n", __FUNCTION__, procCtxTable);
|
||||
return false;
|
||||
}
|
||||
|
||||
printf("%s(), Added ProcCtx rule to table %p\n", __FUNCTION__, procCtxTable);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool HeaderInsertion::DeleteProcCtx(struct ipa_ioc_del_hdr_proc_ctx *procCtxTable)
|
||||
{
|
||||
int retval = 0;
|
||||
|
||||
retval = ioctl(m_fd, IPA_IOC_DEL_HDR_PROC_CTX, procCtxTable);
|
||||
if (retval) {
|
||||
printf("%s(), failed deleting ProcCtx rule in table %p\n", __FUNCTION__, procCtxTable);
|
||||
return false;
|
||||
}
|
||||
|
||||
printf("%s(), Deleted ProcCtx rule in table %p\n", __FUNCTION__, procCtxTable);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool HeaderInsertion::Commit()
|
||||
{
|
||||
int nRetVal = 0;
|
||||
nRetVal = ioctl(m_fd, IPA_IOC_COMMIT_HDR);
|
||||
LOG_IOCTL_RETURN_VALUE(nRetVal);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool HeaderInsertion::Reset()
|
||||
{
|
||||
int nRetVal = 0;
|
||||
|
||||
nRetVal = ioctl(m_fd, IPA_IOC_RESET_HDR);
|
||||
nRetVal |= ioctl(m_fd, IPA_IOC_COMMIT_HDR);
|
||||
LOG_IOCTL_RETURN_VALUE(nRetVal);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool HeaderInsertion::GetHeaderHandle(struct ipa_ioc_get_hdr *pHeaderStruct)
|
||||
{
|
||||
int retval = 0;
|
||||
|
||||
if (!DeviceNodeIsOpened())
|
||||
return false;
|
||||
|
||||
retval = ioctl(m_fd, IPA_IOC_GET_HDR, pHeaderStruct);
|
||||
if (retval) {
|
||||
printf(
|
||||
"%s(), IPA_IOC_GET_HDR ioctl failed, routingTable =0x%p, retval=0x%x.\n"
|
||||
, __func__,
|
||||
pHeaderStruct,
|
||||
retval);
|
||||
return false;
|
||||
}
|
||||
|
||||
printf(
|
||||
"%s(), IPA_IOC_GET_HDR ioctl issued to IPA header insertion block.\n",
|
||||
__func__);
|
||||
return true;
|
||||
}
|
||||
|
||||
int HeaderInsertion::GetHeaderHandle(const string& name){
|
||||
if(name.empty() || name.size() >= IPA_RESOURCE_NAME_MAX){
|
||||
return false;
|
||||
}
|
||||
struct ipa_ioc_get_hdr retHeader;
|
||||
memset(&retHeader, 0, sizeof(retHeader));
|
||||
strlcpy(retHeader.name, name.c_str(), IPA_RESOURCE_NAME_MAX);
|
||||
retHeader.hdl = -1;
|
||||
printf("retHeader.name=%s\n", retHeader.name);
|
||||
if(!GetHeaderHandle(&retHeader)){
|
||||
cout << "GetHeaderHandle(&retHeader) Failed" << endl;
|
||||
return -1;
|
||||
}
|
||||
cout << "retHeader.hdl=" << retHeader.hdl << endl;
|
||||
return retHeader.hdl;
|
||||
}
|
||||
|
||||
bool HeaderInsertion::CopyHeader(struct ipa_ioc_copy_hdr *pCopyHeaderStruct)
|
||||
{
|
||||
int retval = 0;
|
||||
|
||||
if (!DeviceNodeIsOpened())
|
||||
return false;
|
||||
|
||||
retval = ioctl(m_fd, IPA_IOC_COPY_HDR, pCopyHeaderStruct);
|
||||
if (retval) {
|
||||
printf(
|
||||
"%s(), IPA_IOC_COPY_HDR ioctl failed, retval=0x%x.\n",
|
||||
__func__,
|
||||
retval);
|
||||
return false;
|
||||
}
|
||||
|
||||
printf(
|
||||
"%s(), IPA_IOC_COPY_HDR ioctl issued to IPA header insertion block.\n",
|
||||
__func__);
|
||||
return true;
|
||||
}
|
||||
|
||||
98
qcom/opensource/dataipa/kernel-tests/HeaderInsertion.h
Normal file
98
qcom/opensource/dataipa/kernel-tests/HeaderInsertion.h
Normal file
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright (c) 2017 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* Changes from Qualcomm Innovation Center are provided under the following license:
|
||||
*
|
||||
* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted (subject to the limitations in the
|
||||
* disclaimer below) provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* * Neither the name of Qualcomm Innovation Center, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
|
||||
* GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
|
||||
* HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
|
||||
*/
|
||||
|
||||
#ifndef HEADER_INSERTION_H_
|
||||
#define HEADER_INSERTION_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include "linux/msm_ipa.h"
|
||||
#include "ipa_test_module.h"
|
||||
#include "Constants.h"
|
||||
#include "Feature.h"
|
||||
|
||||
using std::string;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
class HeaderInsertion: public Feature
|
||||
{
|
||||
public:
|
||||
bool AddHeader(struct ipa_ioc_add_hdr *pHeaderTable);
|
||||
bool addHeaderHpc(const string& name, uint8_t* header, const size_t headerLen, bool isPartial, enum ipa_client_type ipaClient);
|
||||
bool DeleteHeader(struct ipa_ioc_del_hdr *pHeaderTable);
|
||||
bool DeleteHeader(const string& name);
|
||||
bool GetHeaderHandle(struct ipa_ioc_get_hdr *pHeaderStruct);
|
||||
int GetHeaderHandle(const string& name);
|
||||
bool CopyHeader(struct ipa_ioc_copy_hdr *pCopyHeaderStruct);
|
||||
|
||||
// Processing context
|
||||
bool AddProcCtx(struct ipa_ioc_add_hdr_proc_ctx *procCtxTable);
|
||||
bool DeleteProcCtx(struct ipa_ioc_del_hdr_proc_ctx *procCtxTable);
|
||||
|
||||
bool Commit();
|
||||
bool Reset();
|
||||
};
|
||||
|
||||
#endif
|
||||
1463
qcom/opensource/dataipa/kernel-tests/HeaderInsertionTests.cpp
Normal file
1463
qcom/opensource/dataipa/kernel-tests/HeaderInsertionTests.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,618 @@
|
||||
/*
|
||||
* Copyright (c) 2017-2019 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "HeaderProcessingContextTestFixture.h"
|
||||
#include "TestsUtils.h"
|
||||
|
||||
const Byte IpaHdrProcCtxTestFixture::WLAN_ETH2_HDR[WLAN_ETH2_HDR_SIZE] =
|
||||
{
|
||||
// WLAN hdr - 4 bytes
|
||||
0xa1, 0xb2, 0xc3, 0xd4,
|
||||
|
||||
// ETH2 - 14 bytes
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00
|
||||
};
|
||||
|
||||
const Byte IpaHdrProcCtxTestFixture::ETH2_HDR[ETH_HLEN] =
|
||||
{
|
||||
// ETH2 - 14 bytes
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00
|
||||
};
|
||||
|
||||
const Byte IpaHdrProcCtxTestFixture::ETH2_8021Q_HDR[ETH8021Q_HEADER_LEN] =
|
||||
{
|
||||
// 802_1Q - 18 bytes
|
||||
// src and dst MAC - 6 + 6 bytes
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
|
||||
// 802_1Q tag - VLAN ID 3
|
||||
0x81, 0x00, 0x00, 0x03,
|
||||
// ethertype
|
||||
0x00, 0x00
|
||||
};
|
||||
|
||||
const Byte IpaHdrProcCtxTestFixture::WLAN_802_3_HDR[WLAN_802_3_HDR_SIZE] =
|
||||
{
|
||||
// WLAN hdr - 4 bytes
|
||||
0x0a, 0x0b, 0x0c, 0x0d,
|
||||
|
||||
// 802_3 - 26 bytes
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00
|
||||
};
|
||||
|
||||
IpaHdrProcCtxTestFixture::IpaHdrProcCtxTestFixture():
|
||||
m_procCtxHandleId(PROC_CTX_HANDLE_ID_MAX),
|
||||
m_pCurrentProducer(NULL),
|
||||
m_pCurrentConsumer(NULL),
|
||||
m_sendSize1 (m_BUFF_MAX_SIZE),
|
||||
m_sendSize2 (m_BUFF_MAX_SIZE),
|
||||
m_expectedBufferSize1(0),
|
||||
m_IpaIPType(IPA_IP_v4)
|
||||
{
|
||||
memset(m_headerHandles, 0, sizeof(m_headerHandles));
|
||||
memset(m_procCtxHHandles, 0, sizeof(m_procCtxHHandles));
|
||||
memset(m_sendBuffer1, 0, sizeof(m_sendBuffer1));
|
||||
memset(m_sendBuffer2, 0, sizeof(m_sendBuffer2));
|
||||
memset(m_expectedBuffer1, 0, sizeof(m_expectedBuffer1));
|
||||
m_testSuiteName.push_back("HdrProcCtx");
|
||||
}
|
||||
|
||||
bool IpaHdrProcCtxTestFixture::Setup()
|
||||
{
|
||||
ConfigureScenario(PHASE_TWENTY_TEST_CONFIGURATION);
|
||||
|
||||
// init producers
|
||||
m_rndisEth2Producer.Open(INTERFACE0_TO_IPA_DATA_PATH,
|
||||
INTERFACE0_FROM_IPA_DATA_PATH);
|
||||
m_wlanEth2producer.Open(INTERFACE4_TO_IPA_DATA_PATH,
|
||||
INTERFACE4_FROM_IPA_DATA_PATH);
|
||||
m_eth2Producer.Open(INTERFACE5_TO_IPA_DATA_PATH,
|
||||
INTERFACE5_FROM_IPA_DATA_PATH);
|
||||
|
||||
// init consumers
|
||||
m_defaultConsumer.Open(INTERFACE1_TO_IPA_DATA_PATH,
|
||||
INTERFACE1_FROM_IPA_DATA_PATH);
|
||||
m_rndisEth2Consumer.Open(INTERFACE2_TO_IPA_DATA_PATH,
|
||||
INTERFACE2_FROM_IPA_DATA_PATH);
|
||||
|
||||
if (!m_headerInsertion.DeviceNodeIsOpened())
|
||||
{
|
||||
LOG_MSG_ERROR("HeaderInsertion block is not ready "
|
||||
"for immediate commands!\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!m_routing.DeviceNodeIsOpened())
|
||||
{
|
||||
LOG_MSG_ERROR("Routing block is not ready "
|
||||
"for immediate commands!\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!m_filtering.DeviceNodeIsOpened())
|
||||
{
|
||||
LOG_MSG_ERROR("Filtering block is not ready "
|
||||
"for immediate commands!\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
// resetting this component will reset
|
||||
// both Routing and Filtering tables
|
||||
m_headerInsertion.Reset();
|
||||
|
||||
return true;
|
||||
} // Setup()
|
||||
|
||||
bool IpaHdrProcCtxTestFixture::Teardown()
|
||||
{
|
||||
m_rndisEth2Producer.Close();
|
||||
m_wlanEth2producer.Close();
|
||||
m_eth2Producer.Close();
|
||||
m_defaultConsumer.Close();
|
||||
m_rndisEth2Consumer.Close();
|
||||
return true;
|
||||
} // Teardown()
|
||||
|
||||
void IpaHdrProcCtxTestFixture::AddAllHeaders()
|
||||
{
|
||||
for (int i = 0; i < HEADER_HANDLE_ID_MAX; i++) {
|
||||
AddHeader(static_cast<HeaderHandleId>(i));
|
||||
}
|
||||
}
|
||||
|
||||
// Insert a single header
|
||||
void IpaHdrProcCtxTestFixture::AddHeader(HeaderHandleId handleId)
|
||||
{
|
||||
static const int NUM_OF_HEADERS = 1;
|
||||
struct ipa_ioc_add_hdr *hdrTable = NULL;
|
||||
struct ipa_hdr_add *hdr = NULL;
|
||||
|
||||
// init hdr table
|
||||
hdrTable = (struct ipa_ioc_add_hdr *) calloc(1,
|
||||
sizeof(struct ipa_ioc_add_hdr)
|
||||
+ NUM_OF_HEADERS * sizeof(struct ipa_hdr_add));
|
||||
if (!hdrTable)
|
||||
{
|
||||
LOG_MSG_ERROR(
|
||||
"calloc failed to allocate pHeaderDescriptor");
|
||||
return;
|
||||
}
|
||||
hdrTable->commit = true;
|
||||
hdrTable->num_hdrs = NUM_OF_HEADERS;
|
||||
|
||||
// init the hdr common fields
|
||||
hdr = &hdrTable->hdr[0];
|
||||
hdr->hdr_hdl = -1; //Return Value
|
||||
hdr->is_partial = false;
|
||||
hdr->status = -1; // Return Parameter
|
||||
|
||||
// init hdr specific fields
|
||||
switch (handleId)
|
||||
{
|
||||
case HEADER_HANDLE_ID_WLAN_ETH2:
|
||||
memcpy(hdr->hdr, WLAN_ETH2_HDR, WLAN_ETH2_HDR_SIZE);
|
||||
hdr->hdr_len = WLAN_ETH2_HDR_SIZE;
|
||||
|
||||
strlcpy(hdr->name, "WLAN_ETH2", sizeof(hdr->name));
|
||||
hdr->type = IPA_HDR_L2_ETHERNET_II;
|
||||
break;
|
||||
|
||||
case HEADER_HANDLE_ID_RNDIS_ETH2:
|
||||
if (!RNDISAggregationHelper::LoadRNDISEth2IP4Header(
|
||||
hdr->hdr,
|
||||
IPA_HDR_MAX_SIZE,
|
||||
0,
|
||||
(size_t*)&hdr->hdr_len))
|
||||
return;
|
||||
|
||||
strlcpy(hdr->name, "RNDIS_ETH2", sizeof(hdr->name));
|
||||
hdr->type = IPA_HDR_L2_ETHERNET_II;
|
||||
break;
|
||||
|
||||
case HEADER_HANDLE_ID_ETH2:
|
||||
strlcpy(hdr->name, "ETH2", sizeof(hdr->name));
|
||||
memcpy(hdr->hdr, ETH2_HDR, ETH_HLEN);
|
||||
hdr->type = IPA_HDR_L2_ETHERNET_II;
|
||||
hdr->hdr_len = ETH_HLEN;
|
||||
|
||||
break;
|
||||
|
||||
case HEADER_HANDLE_ID_WLAN_802_3:
|
||||
strlcpy(hdr->name, "WLAN_802_3", sizeof(hdr->name));
|
||||
memcpy(hdr->hdr, WLAN_802_3_HDR, WLAN_802_3_HDR_SIZE);
|
||||
hdr->type = IPA_HDR_L2_802_3;
|
||||
hdr->hdr_len = WLAN_802_3_HDR_SIZE;
|
||||
|
||||
LOG_MSG_DEBUG(
|
||||
"HEADER_HANDLE_ID_WLAN_802_3 NOT supported for now");
|
||||
return;
|
||||
|
||||
break;
|
||||
case HEADER_HANDLE_ID_VLAN_802_1Q:
|
||||
strlcpy(hdr->name, "VLAN_8021Q", sizeof(hdr->name));
|
||||
memcpy(hdr->hdr, ETH2_8021Q_HDR, ETH8021Q_HEADER_LEN);
|
||||
hdr->type = IPA_HDR_L2_802_1Q;
|
||||
hdr->hdr_len = ETH8021Q_HEADER_LEN;
|
||||
break;
|
||||
|
||||
default:
|
||||
LOG_MSG_ERROR("header handleId not supported.");
|
||||
return;
|
||||
}
|
||||
|
||||
// commit header to HW
|
||||
if (!m_headerInsertion.AddHeader(hdrTable))
|
||||
{
|
||||
LOG_MSG_ERROR("m_headerInsertion.AddHeader() failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
// save header handle
|
||||
m_headerHandles[handleId] = hdr->hdr_hdl;
|
||||
}
|
||||
|
||||
void IpaHdrProcCtxTestFixture::AddAllProcCtx()
|
||||
{
|
||||
for (int i = 0; i <PROC_CTX_HANDLE_ID_MAX; i++)
|
||||
{
|
||||
AddProcCtx(static_cast<ProcCtxHandleId>(i));
|
||||
}
|
||||
}
|
||||
|
||||
// Insert a single proc_ctx
|
||||
void IpaHdrProcCtxTestFixture::AddProcCtx(ProcCtxHandleId handleId)
|
||||
{
|
||||
static const int NUM_OF_PROC_CTX = 1;
|
||||
struct ipa_ioc_add_hdr_proc_ctx *procCtxTable = NULL;
|
||||
struct ipa_hdr_proc_ctx_add *procCtx = NULL;
|
||||
|
||||
// init proc ctx table
|
||||
procCtxTable = (struct ipa_ioc_add_hdr_proc_ctx *)calloc(1,
|
||||
sizeof(struct ipa_ioc_add_hdr_proc_ctx)
|
||||
+ NUM_OF_PROC_CTX *
|
||||
sizeof(struct ipa_hdr_proc_ctx_add));
|
||||
if (!procCtxTable)
|
||||
{
|
||||
LOG_MSG_ERROR("calloc failed to allocate procCtxTable");
|
||||
return;
|
||||
}
|
||||
|
||||
procCtxTable->commit = true;
|
||||
procCtxTable->num_proc_ctxs = NUM_OF_PROC_CTX;
|
||||
|
||||
// init proc_ctx common fields
|
||||
procCtx = &procCtxTable->proc_ctx[0];
|
||||
procCtx->proc_ctx_hdl = -1; // return value
|
||||
procCtx->status = -1; // Return parameter
|
||||
|
||||
// init proc_ctx specific fields
|
||||
switch (handleId)
|
||||
{
|
||||
case PROC_CTX_HANDLE_ID_ETH2_2_WLAN_ETH2:
|
||||
procCtx->type = IPA_HDR_PROC_ETHII_TO_ETHII;
|
||||
procCtx->hdr_hdl =
|
||||
m_headerHandles[HEADER_HANDLE_ID_WLAN_ETH2];
|
||||
break;
|
||||
|
||||
case PROC_CTX_HANDLE_ID_ETH2_2_RNDIS_ETH2:
|
||||
procCtx->type = IPA_HDR_PROC_ETHII_TO_ETHII;
|
||||
procCtx->hdr_hdl =
|
||||
m_headerHandles[HEADER_HANDLE_ID_RNDIS_ETH2];
|
||||
break;
|
||||
|
||||
case PROC_CTX_HANDLE_ID_ETH2_ETH2_2_ETH2:
|
||||
procCtx->type = IPA_HDR_PROC_ETHII_TO_ETHII;
|
||||
procCtx->hdr_hdl =
|
||||
m_headerHandles[HEADER_HANDLE_ID_ETH2];
|
||||
break;
|
||||
|
||||
case PROC_CTX_HANDLE_ID_WLAN_ETH2_2_802_3:
|
||||
procCtx->type = IPA_HDR_PROC_ETHII_TO_802_3;
|
||||
procCtx->hdr_hdl =
|
||||
m_headerHandles[HEADER_HANDLE_ID_WLAN_802_3];
|
||||
break;
|
||||
|
||||
case PROC_CTX_HANDLE_ID_RNDIS_802_3_2_ETH2:
|
||||
procCtx->type = IPA_HDR_PROC_802_3_TO_ETHII;
|
||||
procCtx->hdr_hdl =
|
||||
m_headerHandles[HEADER_HANDLE_ID_RNDIS_ETH2];
|
||||
break;
|
||||
|
||||
case PROC_CTX_HANDLE_ID_WLAN_802_3_2_ETH2:
|
||||
procCtx->type = IPA_HDR_PROC_802_3_TO_802_3;
|
||||
procCtx->hdr_hdl =
|
||||
m_headerHandles[HEADER_HANDLE_ID_WLAN_802_3];
|
||||
break;
|
||||
case PROC_CTX_HANDLE_ID_802_1Q_2_802_1Q:
|
||||
procCtx->type = IPA_HDR_PROC_ETHII_TO_ETHII_EX;
|
||||
procCtx->hdr_hdl =
|
||||
m_headerHandles[HEADER_HANDLE_ID_VLAN_802_1Q];
|
||||
procCtx->generic_params.input_ethhdr_negative_offset = 18;
|
||||
procCtx->generic_params.output_ethhdr_negative_offset = 18;
|
||||
break;
|
||||
case PROC_CTX_HANDLE_ID_802_1Q_2_ETH2:
|
||||
procCtx->type = IPA_HDR_PROC_ETHII_TO_ETHII_EX;
|
||||
procCtx->hdr_hdl =
|
||||
m_headerHandles[HEADER_HANDLE_ID_ETH2];
|
||||
procCtx->generic_params.input_ethhdr_negative_offset = 18;
|
||||
procCtx->generic_params.output_ethhdr_negative_offset = 14;
|
||||
break;
|
||||
case PROC_CTX_HANDLE_ID_ETH2_2_802_1Q:
|
||||
procCtx->type = IPA_HDR_PROC_ETHII_TO_ETHII_EX;
|
||||
procCtx->hdr_hdl =
|
||||
m_headerHandles[HEADER_HANDLE_ID_VLAN_802_1Q];
|
||||
procCtx->generic_params.input_ethhdr_negative_offset = 14;
|
||||
procCtx->generic_params.output_ethhdr_negative_offset = 18;
|
||||
break;
|
||||
case PROC_CTX_HANDLE_ID_ETH2_ETH2_2_ETH2_EX:
|
||||
procCtx->type = IPA_HDR_PROC_ETHII_TO_ETHII_EX;
|
||||
procCtx->hdr_hdl =
|
||||
m_headerHandles[HEADER_HANDLE_ID_ETH2];
|
||||
procCtx->generic_params.input_ethhdr_negative_offset = 14;
|
||||
procCtx->generic_params.output_ethhdr_negative_offset = 14;
|
||||
break;
|
||||
|
||||
default:
|
||||
LOG_MSG_ERROR("proc ctx handleId %d not supported.", handleId);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!m_headerInsertion.AddProcCtx(procCtxTable))
|
||||
{
|
||||
LOG_MSG_ERROR("m_headerInsertion.AddProcCtx(procCtxTable) failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
// save proc_ctx handle
|
||||
m_procCtxHHandles[handleId] = procCtx->proc_ctx_hdl;
|
||||
}
|
||||
|
||||
void IpaHdrProcCtxTestFixture::AddRtBypassRule(uint32_t hdrHdl, uint32_t procCtxHdl)
|
||||
{
|
||||
static const char bypass0[] = "bypass0";
|
||||
struct ipa_ioc_get_rt_tbl routing_table0;
|
||||
|
||||
if (!CreateIPv4BypassRoutingTable (
|
||||
bypass0,
|
||||
hdrHdl,
|
||||
procCtxHdl))
|
||||
{
|
||||
LOG_MSG_ERROR("CreateIPv4BypassRoutingTable Failed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
routing_table0.ip = IPA_IP_v4;
|
||||
strlcpy(routing_table0.name, bypass0, sizeof(routing_table0.name));
|
||||
if (!m_routing.GetRoutingTable(&routing_table0))
|
||||
{
|
||||
LOG_MSG_ERROR("m_routing.GetRoutingTable() Failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
m_routingTableHdl = routing_table0.hdl;
|
||||
}
|
||||
|
||||
void IpaHdrProcCtxTestFixture::AddFltBypassRule()
|
||||
{
|
||||
IPAFilteringTable FilterTable0;
|
||||
struct ipa_flt_rule_add flt_rule_entry;
|
||||
|
||||
FilterTable0.Init(IPA_IP_v4,m_currProducerClient,false,1);
|
||||
printf("FilterTable*.Init Completed Successfully..\n");
|
||||
|
||||
// Configuring Filtering Rule No.0
|
||||
FilterTable0.GeneratePresetRule(1,flt_rule_entry);
|
||||
flt_rule_entry.at_rear = true;
|
||||
flt_rule_entry.flt_rule_hdl=-1; // return Value
|
||||
flt_rule_entry.status = -1; // return value
|
||||
flt_rule_entry.rule.action=IPA_PASS_TO_ROUTING;
|
||||
flt_rule_entry.rule.rt_tbl_hdl=m_routingTableHdl;
|
||||
flt_rule_entry.rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
|
||||
flt_rule_entry.rule.attrib.u.v4.dst_addr_mask = 0x00000000; // Mask - Bypass rule
|
||||
flt_rule_entry.rule.attrib.u.v4.dst_addr = 0x12345678; // Filter is irrelevant.
|
||||
if (((uint8_t)-1 == FilterTable0.AddRuleToTable(flt_rule_entry)) ||
|
||||
!m_filtering.AddFilteringRule(
|
||||
FilterTable0.GetFilteringTable()))
|
||||
{
|
||||
LOG_MSG_ERROR(
|
||||
"%s::m_filtering.AddFilteringRule() failed",
|
||||
__FUNCTION__);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("flt rule hdl0=0x%x, status=0x%x\n",
|
||||
FilterTable0.ReadRuleFromTable(0)->flt_rule_hdl,
|
||||
FilterTable0.ReadRuleFromTable(0)->status);
|
||||
}
|
||||
}
|
||||
|
||||
bool IpaHdrProcCtxTestFixture::ReceivePacketsAndCompare()
|
||||
{
|
||||
size_t receivedBufferSize1 = 0;
|
||||
bool isSuccess = true;
|
||||
|
||||
// Receive results
|
||||
Byte *receivedBuffer1 = new Byte[m_BUFF_MAX_SIZE];
|
||||
|
||||
if (NULL == receivedBuffer1)
|
||||
{
|
||||
printf("Memory allocation error.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
receivedBufferSize1 = m_pCurrentConsumer->ReceiveData(
|
||||
receivedBuffer1,
|
||||
m_BUFF_MAX_SIZE);
|
||||
printf("Received %zu bytes on %s.\n",
|
||||
receivedBufferSize1,
|
||||
m_pCurrentConsumer->m_fromChannelName.c_str());
|
||||
|
||||
// Compare results
|
||||
if (!CompareResultVsGolden(
|
||||
m_expectedBuffer1,
|
||||
m_expectedBufferSize1,
|
||||
receivedBuffer1,
|
||||
receivedBufferSize1))
|
||||
{
|
||||
printf("Comparison of Buffer Failed!\n");
|
||||
isSuccess = false;
|
||||
}
|
||||
|
||||
printf("Expected buffer 1 - %zu bytes\n", m_expectedBufferSize1);
|
||||
print_buff(m_expectedBuffer1, m_expectedBufferSize1);
|
||||
|
||||
printf("Received buffer 1 - %zu bytes\n", receivedBufferSize1);
|
||||
print_buff(receivedBuffer1, receivedBufferSize1);
|
||||
|
||||
delete[] receivedBuffer1;
|
||||
|
||||
return isSuccess;
|
||||
}
|
||||
|
||||
// Create 1 IPv4 bypass routing entry and commits it
|
||||
bool IpaHdrProcCtxTestFixture::CreateIPv4BypassRoutingTable (
|
||||
const char *name,
|
||||
uint32_t hdrHdl,
|
||||
uint32_t procCtxHdl)
|
||||
{
|
||||
printf("Entering %s, %s()\n",__FUNCTION__, __FILE__);
|
||||
struct ipa_ioc_add_rt_rule *rt_table = 0;
|
||||
struct ipa_rt_rule_add *rt_rule_entry = NULL;
|
||||
|
||||
// Verify that only one is nonzero
|
||||
if ((hdrHdl == 0 && procCtxHdl == 0) ||
|
||||
(hdrHdl != 0 && procCtxHdl != 0))
|
||||
{
|
||||
LOG_MSG_ERROR("Error: hdrHdl = %u, procCtxHdl = %u\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
rt_table = (struct ipa_ioc_add_rt_rule *)
|
||||
calloc(1, sizeof(struct ipa_ioc_add_rt_rule) +
|
||||
1*sizeof(struct ipa_rt_rule_add));
|
||||
if(!rt_table) {
|
||||
LOG_MSG_ERROR("calloc failed to allocate rt_table\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
rt_table->num_rules = 1;
|
||||
rt_table->ip = IPA_IP_v4;
|
||||
rt_table->commit = true;
|
||||
strlcpy(rt_table->rt_tbl_name, name, sizeof(rt_table->rt_tbl_name));
|
||||
|
||||
rt_rule_entry = &rt_table->rules[0];
|
||||
rt_rule_entry->at_rear = 0;
|
||||
rt_rule_entry->rule.dst = m_currConsumerPipeNum;
|
||||
rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
|
||||
rt_rule_entry->rule.attrib.u.v4.dst_addr = 0xaabbccdd;
|
||||
|
||||
// All Packets will get a "Hit"
|
||||
rt_rule_entry->rule.attrib.u.v4.dst_addr_mask = 0x00000000;
|
||||
rt_rule_entry->rule.hdr_hdl = hdrHdl;
|
||||
rt_rule_entry->rule.hdr_proc_ctx_hdl = procCtxHdl;
|
||||
if (false == m_routing.AddRoutingRule(rt_table))
|
||||
{
|
||||
printf("Routing rule addition(rt_table) failed!\n");
|
||||
Free (rt_table);
|
||||
return false;
|
||||
}
|
||||
|
||||
Free (rt_table);
|
||||
printf("Leaving %s, %s()\n",__FUNCTION__, __FILE__);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IpaHdrProcCtxTestFixture::AddRules()
|
||||
{
|
||||
printf("Entering %s, %s()\n",__FUNCTION__, __FILE__);
|
||||
|
||||
if (m_procCtxHandleId == PROC_CTX_HANDLE_ID_MAX)
|
||||
{
|
||||
LOG_MSG_ERROR("Test developer didn't implement "
|
||||
"AddRules() or didn't set m_procCtxHandleId");
|
||||
return false;
|
||||
}
|
||||
|
||||
AddAllHeaders();
|
||||
|
||||
AddAllProcCtx();
|
||||
|
||||
AddRtBypassRule(0, m_procCtxHHandles[m_procCtxHandleId]);
|
||||
|
||||
AddFltBypassRule();
|
||||
|
||||
printf("Leaving %s, %s()\n",__FUNCTION__, __FILE__);
|
||||
return true;
|
||||
|
||||
}// AddRules()
|
||||
|
||||
bool IpaHdrProcCtxTestFixture::SendPackets()
|
||||
{
|
||||
|
||||
bool isSuccess = false;
|
||||
|
||||
// Send first packet
|
||||
isSuccess = m_pCurrentProducer->SendData(
|
||||
m_sendBuffer1,
|
||||
m_sendSize1);
|
||||
if (false == isSuccess)
|
||||
{
|
||||
LOG_MSG_ERROR("SendPackets Buffer1 failed on client %d\n", m_currProducerClient);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IpaHdrProcCtxTestFixture::Run()
|
||||
{
|
||||
bool res = false;
|
||||
bool isSuccess = false;
|
||||
|
||||
printf("Entering %s, %s()\n",__FUNCTION__, __FILE__);
|
||||
|
||||
res = AddRules();
|
||||
if (false == res) {
|
||||
printf("Failed adding filtering rules.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Load input data - IP packets
|
||||
res = LoadPackets(m_IpaIPType);
|
||||
if (false == res) {
|
||||
printf("Failed loading packets.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
res = GenerateExpectedPackets();
|
||||
if (false == res) {
|
||||
printf("GenerateExpectedPackets failed\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
res = SendPackets();
|
||||
if (false == res) {
|
||||
printf("SendPackets failed\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Receive packets from the channels and compare results
|
||||
isSuccess = ReceivePacketsAndCompare();
|
||||
|
||||
printf("Leaving %s, %s(), Returning %d\n",
|
||||
__FUNCTION__,
|
||||
__FILE__,
|
||||
isSuccess);
|
||||
|
||||
return isSuccess;
|
||||
} // Run()
|
||||
|
||||
IpaHdrProcCtxTestFixture::~IpaHdrProcCtxTestFixture()
|
||||
{
|
||||
m_sendSize1 = 0;
|
||||
}
|
||||
|
||||
RoutingDriverWrapper IpaHdrProcCtxTestFixture::m_routing;
|
||||
Filtering IpaHdrProcCtxTestFixture::m_filtering;
|
||||
HeaderInsertion IpaHdrProcCtxTestFixture::m_headerInsertion;
|
||||
|
||||
@@ -0,0 +1,218 @@
|
||||
/*
|
||||
* Copyright (c) 2017-2019 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <cstring> // for memcpy
|
||||
#include "hton.h" // for htonl
|
||||
#include "InterfaceAbstraction.h"
|
||||
#include "Constants.h"
|
||||
#include "Logger.h"
|
||||
#include "TestsUtils.h"
|
||||
#include "Filtering.h"
|
||||
#include "HeaderInsertion.h"
|
||||
#include "RoutingDriverWrapper.h"
|
||||
#include "IPAFilteringTable.h"
|
||||
|
||||
/*
|
||||
Processing context test design:
|
||||
|
||||
1. 1 Producer with RNDIS de-aggregation and ETH2 header removal.
|
||||
2. 1 Producer with WLAN and ETH2 header removal.
|
||||
3. 1 default consumer.
|
||||
4. 1 RNDIS aggregation consumer.
|
||||
5. 1 FLT rule accept all - points to 1 RT rule.
|
||||
6. 1 RT rule accept all - points to specific test relevant proc_ctx.
|
||||
7. All tests add all proc_ctx (for all tests).
|
||||
8. Proc_ctx to be added: 1 for each test 3 altogether.
|
||||
Proc_ctx of test 01 and 03 are the same.
|
||||
9. Each test will send 1 packet and check that the packet is good
|
||||
except test 03.
|
||||
10. Test 03 the same as Test 01 but will send multiple packets
|
||||
and expect 1 (RNDIS aggregation test).
|
||||
|
||||
List of tests:
|
||||
00. Header insertion scenario of [RNDIS][ETH_II][IP] -> [WLAN][ETH_II][IP]
|
||||
01. Header insertion scenario of [WLAN][ETH_II][IP] -> [RNDIS][ETH_II][IP]
|
||||
02. Header insertion scenario of [WLAN][ETH_II][IP] -> [WLAN][ETH_II][IP]
|
||||
03. Header insertion of [WLAN][ETH_II][IP] -> [RNDIS][ETH_II][IP]
|
||||
with RNDIS aggregation.
|
||||
04. Header insertion scenario when adding total header sizes > 2048
|
||||
05. Header insertion scenario of [ETH_II][IP] -> [WLAN][ETH_II][IP]
|
||||
06. Header insertion scenario of [WLAN][ETH_II][IP] -> [ETH_II][IP
|
||||
07. Header insertion scenario of [ETH_II][IP] -> [ETH_II][IP]
|
||||
08. Header insertion scenario of [RNDIS][ETH_II][IP] -> [WLAN][802.3][IP]
|
||||
09. Header insertion scenario of [WLAN][802.3][IP] -> [RNDIS][ETH_II][IP]
|
||||
10. Header insertion scenario of [ETH_II][IP] -> [WLAN][802.3][IP]
|
||||
11. Header insertion scenario of [WLAN][802.3][IP] -> [WLAN][802.3][IP]
|
||||
*/
|
||||
class IpaHdrProcCtxTestFixture : public TestBase
|
||||
{
|
||||
public:
|
||||
enum HeaderHandleId
|
||||
{
|
||||
HEADER_HANDLE_ID_WLAN_ETH2,
|
||||
HEADER_HANDLE_ID_RNDIS_ETH2,
|
||||
HEADER_HANDLE_ID_ETH2,
|
||||
HEADER_HANDLE_ID_WLAN_802_3,
|
||||
HEADER_HANDLE_ID_VLAN_802_1Q,
|
||||
HEADER_HANDLE_ID_MAX
|
||||
};
|
||||
|
||||
enum ProcCtxHandleId
|
||||
{
|
||||
PROC_CTX_HANDLE_ID_ETH2_2_WLAN_ETH2,
|
||||
PROC_CTX_HANDLE_ID_ETH2_2_RNDIS_ETH2,
|
||||
PROC_CTX_HANDLE_ID_ETH2_ETH2_2_ETH2,
|
||||
PROC_CTX_HANDLE_ID_WLAN_ETH2_2_802_3,
|
||||
PROC_CTX_HANDLE_ID_RNDIS_802_3_2_ETH2,
|
||||
PROC_CTX_HANDLE_ID_WLAN_802_3_2_ETH2,
|
||||
PROC_CTX_HANDLE_ID_802_1Q_2_802_1Q,
|
||||
PROC_CTX_HANDLE_ID_ETH2_2_802_1Q,
|
||||
PROC_CTX_HANDLE_ID_802_1Q_2_ETH2,
|
||||
PROC_CTX_HANDLE_ID_ETH2_ETH2_2_ETH2_EX,
|
||||
PROC_CTX_HANDLE_ID_MAX
|
||||
};
|
||||
|
||||
// header table consist of 9 bits and 4B units -> 2048
|
||||
static const int m_ALL_HEADER_SIZE_LIMIT = 2048;
|
||||
|
||||
static const size_t m_BUFF_MAX_SIZE =
|
||||
2 * RNDISAggregationHelper::RNDIS_AGGREGATION_BYTE_LIMIT;
|
||||
|
||||
// [WLAN][ETH2] header
|
||||
static const Byte WLAN_ETH2_HDR[WLAN_ETH2_HDR_SIZE];
|
||||
|
||||
// [ETH2] header
|
||||
static const Byte ETH2_HDR[ETH_HLEN];
|
||||
|
||||
// [ETH2_802_1Q] vlan header
|
||||
static const Byte ETH2_8021Q_HDR[ETH8021Q_HEADER_LEN];
|
||||
|
||||
// [WLAN][802.3] header
|
||||
static const Byte WLAN_802_3_HDR[WLAN_802_3_HDR_SIZE];
|
||||
|
||||
static Filtering m_filtering;
|
||||
static RoutingDriverWrapper m_routing;
|
||||
static HeaderInsertion m_headerInsertion;
|
||||
|
||||
// For each header type the handle is saved
|
||||
// to be used by the processing context
|
||||
uint32_t m_headerHandles[HEADER_HANDLE_ID_MAX];
|
||||
|
||||
// For each prco_ctx type the handle is saved
|
||||
// to be used by the routing rule
|
||||
uint32_t m_procCtxHHandles[PROC_CTX_HANDLE_ID_MAX];
|
||||
|
||||
// proc_ctx handle ID
|
||||
ProcCtxHandleId m_procCtxHandleId;
|
||||
|
||||
// routing table handle
|
||||
uint32_t m_routingTableHdl;
|
||||
|
||||
// Pipe with RNDIS and ETH2 header removal
|
||||
InterfaceAbstraction m_rndisEth2Producer;
|
||||
|
||||
// Pipe with WLAN and ETH2 header removal
|
||||
InterfaceAbstraction m_wlanEth2producer;
|
||||
|
||||
// Pipe with ETH2 header removal
|
||||
InterfaceAbstraction m_eth2Producer;
|
||||
|
||||
// TODO: Pipe with WLAN and 802.3 header removal
|
||||
InterfaceAbstraction m_wlan802_3producer;
|
||||
|
||||
// Pointer to current producer pipe used in the test
|
||||
InterfaceAbstraction *m_pCurrentProducer;
|
||||
ipa_client_type m_currProducerClient;
|
||||
|
||||
// Pipe of the WLAN ETH2 consumer
|
||||
InterfaceAbstraction m_defaultConsumer;
|
||||
|
||||
// Pipe of the RNDIS ETH2 consumer
|
||||
InterfaceAbstraction m_rndisEth2Consumer;
|
||||
|
||||
// Pointer to current consumer pipe used in the test
|
||||
InterfaceAbstraction *m_pCurrentConsumer;
|
||||
ipa_client_type m_currConsumerPipeNum;
|
||||
|
||||
// First input packet
|
||||
Byte m_sendBuffer1[m_BUFF_MAX_SIZE];
|
||||
size_t m_sendSize1;
|
||||
|
||||
// Second input packet
|
||||
Byte m_sendBuffer2[m_BUFF_MAX_SIZE];
|
||||
size_t m_sendSize2;
|
||||
|
||||
// First expected packet
|
||||
Byte m_expectedBuffer1[m_BUFF_MAX_SIZE];
|
||||
size_t m_expectedBufferSize1;
|
||||
|
||||
enum ipa_ip_type m_IpaIPType;
|
||||
|
||||
IpaHdrProcCtxTestFixture();
|
||||
|
||||
virtual bool Setup();
|
||||
virtual bool Teardown();
|
||||
virtual void AddAllHeaders();
|
||||
|
||||
// Insert a single header
|
||||
virtual void AddHeader(HeaderHandleId handleId);
|
||||
virtual void AddAllProcCtx();
|
||||
|
||||
// Insert a single proc_ctx
|
||||
virtual void AddProcCtx(ProcCtxHandleId handleId);
|
||||
virtual void AddRtBypassRule(uint32_t hdrHdl, uint32_t procCtxHdl);
|
||||
virtual void AddFltBypassRule();
|
||||
virtual bool LoadPackets(enum ipa_ip_type ip) = 0;
|
||||
|
||||
virtual bool ReceivePacketsAndCompare();
|
||||
|
||||
// Create 1 IPv4 bypass routing entry and commits it
|
||||
virtual bool CreateIPv4BypassRoutingTable (
|
||||
const char *name,
|
||||
uint32_t hdrHdl,
|
||||
uint32_t procCtxHdl);
|
||||
|
||||
virtual bool GenerateExpectedPackets() = 0;
|
||||
|
||||
virtual bool AddRules();
|
||||
|
||||
virtual bool SendPackets();
|
||||
|
||||
virtual bool Run();
|
||||
|
||||
~IpaHdrProcCtxTestFixture();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
@@ -0,0 +1,780 @@
|
||||
/*
|
||||
* Copyright (c) 2017-2019 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "HeaderProcessingContextTestFixture.h"
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Test00: Header insertion scenario of [RNDIS][ETH_II][IP] -> */
|
||||
/* [WLAN][ETH_II][IP] */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
class IpaHdrProcCtxTest00 : public IpaHdrProcCtxTestFixture
|
||||
{
|
||||
public:
|
||||
IpaHdrProcCtxTest00()
|
||||
{
|
||||
m_name = "IpaHdrProcCtxTest00";
|
||||
m_description =
|
||||
"Processing Context test 00 - \
|
||||
of [RNDIS][ETH_II][IP] -> [WLAN][ETH_II][IP] \
|
||||
1. Generate and commit all headers for all tests. \
|
||||
2. Generate and commit all processing context rules \
|
||||
for all tests.\
|
||||
3. Generate and commit routing table 0. \
|
||||
The table contains 1 \"bypass\" rule. \
|
||||
All data goes to output pipe TEST2. \
|
||||
Routing rule will use processing context ETH2_2_WLAN_ETH2 \
|
||||
4. Generate and commit 1 filtering rule. \
|
||||
All traffic goes to routing table 0";
|
||||
m_pCurrentProducer = &m_rndisEth2Producer;
|
||||
m_currProducerClient = IPA_CLIENT_TEST_PROD;
|
||||
m_pCurrentConsumer = &m_defaultConsumer;
|
||||
m_currConsumerPipeNum = IPA_CLIENT_TEST2_CONS;
|
||||
m_procCtxHandleId = PROC_CTX_HANDLE_ID_ETH2_2_WLAN_ETH2;
|
||||
m_minIPAHwType = IPA_HW_v2_5;
|
||||
m_maxIPAHwType = IPA_HW_MAX;
|
||||
m_runInRegression = false;
|
||||
Register(*this);
|
||||
}
|
||||
|
||||
virtual bool LoadPackets(enum ipa_ip_type ip)
|
||||
{
|
||||
if (!RNDISAggregationHelper::LoadRNDISPacket(
|
||||
ip,
|
||||
m_sendBuffer1,
|
||||
m_sendSize1))
|
||||
{
|
||||
LOG_MSG_ERROR("Failed default Packet\n");
|
||||
return false;
|
||||
}
|
||||
printf ("Loaded %zu Bytes to Packet 1\n",m_sendSize1);
|
||||
|
||||
add_buff(m_sendBuffer1+RNDIS_HDR_SIZE, ETH_HLEN, 2);
|
||||
print_buff(m_sendBuffer1, m_sendSize1);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool GenerateExpectedPackets()
|
||||
{
|
||||
m_expectedBufferSize1 = WLAN_ETH2_HDR_SIZE +
|
||||
IP4_PACKET_SIZE;
|
||||
|
||||
// copy WLAN header to the beginning of the buffer
|
||||
memcpy(m_expectedBuffer1, WLAN_ETH2_HDR, WLAN_HDR_SIZE);
|
||||
|
||||
// copy ETH+IP packet right after WLAN header
|
||||
memcpy(m_expectedBuffer1 + WLAN_HDR_SIZE,
|
||||
m_sendBuffer1 + RNDIS_HDR_SIZE,
|
||||
ETH_HLEN + IP4_PACKET_SIZE);
|
||||
|
||||
return true;
|
||||
} // GenerateExpectedPackets()
|
||||
};
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Test01: Header insertion scenario of [WLAN][ETH_II][IP] -> */
|
||||
/* [RNDIS][ETH_II][IP] */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
class IpaHdrProcCtxTest01 : public IpaHdrProcCtxTestFixture
|
||||
{
|
||||
public:
|
||||
IpaHdrProcCtxTest01()
|
||||
{
|
||||
m_name = "IpaHdrProcCtxTest01";
|
||||
m_description =
|
||||
"Processing context test 01 - \
|
||||
of [WLAN][ETH_II][IP] -> [RNDIS][ETH_II][IP] \
|
||||
1. Generate and commit all headers for all tests. \
|
||||
2. Generate and commit all processing context rules \
|
||||
for all tests.\
|
||||
3. Generate and commit routing table 0. \
|
||||
The table contains 1 \"bypass\" rule. \
|
||||
All data goes to output pipe TEST3. \
|
||||
Routing rule will use processing context ETH2_2_RNDIS_ETH2 \
|
||||
4. Generate and commit 1 filtering rule. \
|
||||
All traffic goes to routing table 0";
|
||||
m_pCurrentProducer = &m_wlanEth2producer;
|
||||
m_currProducerClient = IPA_CLIENT_TEST2_PROD;
|
||||
m_pCurrentConsumer = &m_rndisEth2Consumer;
|
||||
m_currConsumerPipeNum = IPA_CLIENT_TEST3_CONS;
|
||||
m_procCtxHandleId = PROC_CTX_HANDLE_ID_ETH2_2_RNDIS_ETH2;
|
||||
m_minIPAHwType = IPA_HW_v2_5;
|
||||
m_maxIPAHwType = IPA_HW_MAX;
|
||||
m_runInRegression = false;
|
||||
Register(*this);
|
||||
}
|
||||
|
||||
virtual bool LoadPackets(enum ipa_ip_type ip)
|
||||
{
|
||||
// load WLAN ETH2 IP4 packet of size 1kB + 1 byte
|
||||
// This size will trigger RNDIS aggregation later
|
||||
m_sendSize1 =
|
||||
RNDISAggregationHelper::RNDIS_AGGREGATION_BYTE_LIMIT + 1;
|
||||
|
||||
if (!WlanHelper::LoadWlanEth2IP4PacketByLength(
|
||||
m_sendBuffer1,
|
||||
m_BUFF_MAX_SIZE,
|
||||
m_sendSize1,
|
||||
0x01))
|
||||
return false;
|
||||
|
||||
printf ("Loaded %zu Bytes to Packet 1\n",m_sendSize1);
|
||||
|
||||
add_buff(m_sendBuffer1+WLAN_HDR_SIZE, ETH_HLEN, 3);
|
||||
|
||||
print_buff(m_sendBuffer1, m_sendSize1);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool GenerateExpectedPackets()
|
||||
{
|
||||
size_t len = 0;
|
||||
size_t eth2PacketSize = m_sendSize1 - WLAN_HDR_SIZE;
|
||||
|
||||
m_expectedBufferSize1 = eth2PacketSize + RNDIS_HDR_SIZE;
|
||||
|
||||
// copy RNDIS header
|
||||
if (!RNDISAggregationHelper::LoadRNDISHeader(
|
||||
m_expectedBuffer1,
|
||||
m_BUFF_MAX_SIZE,
|
||||
m_expectedBufferSize1,
|
||||
&len))
|
||||
{
|
||||
LOG_MSG_ERROR("Failed default Packet\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
// copy ETH2 packet after RNDIS header
|
||||
memcpy(m_expectedBuffer1 + len,
|
||||
m_sendBuffer1 + WLAN_HDR_SIZE,
|
||||
eth2PacketSize);
|
||||
|
||||
return true;
|
||||
} // GenerateExpectedPackets()
|
||||
};
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Test02: Header insertion scenario of [WLAN][ETH_II][IP] -> */
|
||||
/* [WLAN'][ETH_II][IP] */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
class IpaHdrProcCtxTest02 : public IpaHdrProcCtxTestFixture
|
||||
{
|
||||
public:
|
||||
IpaHdrProcCtxTest02()
|
||||
{
|
||||
m_name = "IpaHdrProcCtxTest02";
|
||||
m_description =
|
||||
"Processing context test 02 - \
|
||||
of [WLAN][ETH_II][IP] -> [WLAN'][ETH_II][IP] \
|
||||
1. Generate and commit all headers for all tests. \
|
||||
2. Generate and commit all processing context rules \
|
||||
for all tests.\
|
||||
3. Generate and commit routing table 0. \
|
||||
The table contains 1 \"bypass\" rule. \
|
||||
All data goes to output pipe TEST2. \
|
||||
Routing rule will use processing context ETH2_2_WLAN_ETH2 \
|
||||
4. Generate and commit 1 filtering rule. \
|
||||
All traffic goes to routing table 0";
|
||||
m_pCurrentProducer = &m_wlanEth2producer;
|
||||
m_currProducerClient = IPA_CLIENT_TEST2_PROD;
|
||||
m_pCurrentConsumer = &m_defaultConsumer;
|
||||
m_currConsumerPipeNum = IPA_CLIENT_TEST2_CONS;
|
||||
m_procCtxHandleId = PROC_CTX_HANDLE_ID_ETH2_2_WLAN_ETH2;
|
||||
m_minIPAHwType = IPA_HW_v2_5;
|
||||
m_maxIPAHwType = IPA_HW_MAX;
|
||||
m_runInRegression = false;
|
||||
Register(*this);
|
||||
}
|
||||
|
||||
virtual bool LoadPackets(enum ipa_ip_type ip)
|
||||
{
|
||||
// load WLAN ETH2 IP4 packet of size 1kB
|
||||
// This size will trigger RNDIS aggregation later
|
||||
if (!WlanHelper::LoadWlanEth2IP4Packet(
|
||||
m_sendBuffer1,
|
||||
m_BUFF_MAX_SIZE,
|
||||
&m_sendSize1))
|
||||
return false;
|
||||
|
||||
printf ("Loaded %zu Bytes to Packet 1\n",m_sendSize1);
|
||||
|
||||
add_buff(m_sendBuffer1+WLAN_HDR_SIZE, ETH_HLEN, 5);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool GenerateExpectedPackets()
|
||||
{
|
||||
m_expectedBufferSize1 = m_sendSize1;
|
||||
memcpy(m_expectedBuffer1, m_sendBuffer1, m_expectedBufferSize1);
|
||||
memcpy(m_expectedBuffer1, WLAN_ETH2_HDR, WLAN_HDR_SIZE);
|
||||
|
||||
return true;
|
||||
} // GenerateExpectedPackets()
|
||||
};
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Test03: Header insertion scenario of [WLAN][ETH_II][IP] -> */
|
||||
/* [RNDIS][ETH_II][IP] with RNDIS aggregation */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
class IpaHdrProcCtxTest03 : public IpaHdrProcCtxTestFixture
|
||||
{
|
||||
public:
|
||||
IpaHdrProcCtxTest03()
|
||||
{
|
||||
m_name = "IpaHdrProcCtxTest03";
|
||||
m_description =
|
||||
"Processing Context test 03 - \
|
||||
of [RNDIS][ETH_II][IP] -> [WLAN][ETH_II][IP] \
|
||||
with RNDIS aggregation \
|
||||
1. Generate and commit all headers for all tests. \
|
||||
2. Generate and commit all processing context rules \
|
||||
for all tests.\
|
||||
3. Generate and commit routing table 0. \
|
||||
The table contains 1 \"bypass\" rule. \
|
||||
All data goes to output pipe TEST3. \
|
||||
Routing rule will use processing context ETH2_2_RNDIS_ETH2 \
|
||||
4. Generate and commit 1 filtering rule. \
|
||||
All traffic goes to routing table 0";
|
||||
m_pCurrentProducer = &m_wlanEth2producer;
|
||||
m_currProducerClient = IPA_CLIENT_TEST2_PROD;
|
||||
m_pCurrentConsumer = &m_rndisEth2Consumer;
|
||||
m_currConsumerPipeNum = IPA_CLIENT_TEST3_CONS;
|
||||
m_procCtxHandleId = PROC_CTX_HANDLE_ID_ETH2_2_RNDIS_ETH2;
|
||||
m_minIPAHwType = IPA_HW_v2_5;
|
||||
m_maxIPAHwType = IPA_HW_MAX;
|
||||
m_runInRegression = false;
|
||||
Register(*this);
|
||||
}
|
||||
|
||||
virtual bool LoadPackets(enum ipa_ip_type ip)
|
||||
{
|
||||
// choose this size so that 2 such buffers would be aggregated
|
||||
m_sendSize1 = RNDISAggregationHelper::
|
||||
RNDIS_AGGREGATION_BYTE_LIMIT / 2 + 200;
|
||||
|
||||
if (!WlanHelper::LoadWlanEth2IP4PacketByLength(
|
||||
m_sendBuffer1,
|
||||
m_BUFF_MAX_SIZE,
|
||||
m_sendSize1,
|
||||
1))
|
||||
return false;
|
||||
|
||||
printf ("Loaded %zu Bytes to Packet 1\n", m_sendSize1);
|
||||
|
||||
add_buff(m_sendBuffer1+WLAN_HDR_SIZE, ETH_HLEN, 7);
|
||||
|
||||
// choose this size so that 2 such buffers would be aggregated
|
||||
m_sendSize2 = RNDISAggregationHelper::
|
||||
RNDIS_AGGREGATION_BYTE_LIMIT / 2 + 200;
|
||||
|
||||
if (!WlanHelper::LoadWlanEth2IP4PacketByLength(
|
||||
m_sendBuffer2,
|
||||
m_BUFF_MAX_SIZE,
|
||||
m_sendSize2,
|
||||
2))
|
||||
return false;
|
||||
|
||||
printf ("Loaded %zu Bytes to Packet 2\n", m_sendSize2);
|
||||
|
||||
add_buff(m_sendBuffer2+WLAN_HDR_SIZE, ETH_HLEN, 11);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool SendPackets()
|
||||
{
|
||||
bool isSuccess = false;
|
||||
|
||||
// Send packet 1
|
||||
isSuccess = m_pCurrentProducer->SendData(
|
||||
m_sendBuffer1,
|
||||
m_sendSize1);
|
||||
if (false == isSuccess)
|
||||
{
|
||||
LOG_MSG_ERROR(
|
||||
"SendData Buffer 1 failed on producer %d\n", m_currProducerClient);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Send packet 2
|
||||
isSuccess = m_pCurrentProducer->SendData(
|
||||
m_sendBuffer2,
|
||||
m_sendSize2);
|
||||
if (false == isSuccess)
|
||||
{
|
||||
LOG_MSG_ERROR(
|
||||
"SendData Buffer 2 failed on producer %d\n", m_currProducerClient);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool GenerateExpectedPackets()
|
||||
{
|
||||
size_t len = 0;
|
||||
size_t eth2PacketSize1 = m_sendSize1 - WLAN_HDR_SIZE;
|
||||
size_t rndisPacketSize1 = eth2PacketSize1 + RNDIS_HDR_SIZE;
|
||||
size_t eth2PacketSize2 = m_sendSize2 - WLAN_HDR_SIZE;
|
||||
size_t rndisPacketSize2 = eth2PacketSize2 + RNDIS_HDR_SIZE;
|
||||
Byte *currBuffLocation = NULL;
|
||||
|
||||
m_expectedBufferSize1 = rndisPacketSize1 + rndisPacketSize2;
|
||||
|
||||
currBuffLocation = m_expectedBuffer1;
|
||||
|
||||
// copy first RNDIS header
|
||||
if (!RNDISAggregationHelper::LoadRNDISHeader(
|
||||
currBuffLocation,
|
||||
m_BUFF_MAX_SIZE,
|
||||
rndisPacketSize1,
|
||||
&len))
|
||||
return false;
|
||||
|
||||
// copy ETH2 packet 1 after RNDIS header
|
||||
currBuffLocation += len;
|
||||
memcpy(currBuffLocation,
|
||||
m_sendBuffer1 + WLAN_HDR_SIZE,
|
||||
eth2PacketSize1);
|
||||
|
||||
// copy second RNDIS header
|
||||
currBuffLocation += eth2PacketSize1;
|
||||
if (!RNDISAggregationHelper::LoadRNDISHeader(
|
||||
currBuffLocation,
|
||||
m_BUFF_MAX_SIZE - rndisPacketSize1,
|
||||
rndisPacketSize2,
|
||||
&len))
|
||||
return false;
|
||||
|
||||
// copy ETH2 packet 2 after RNDIS header
|
||||
currBuffLocation += len;
|
||||
memcpy(currBuffLocation,
|
||||
m_sendBuffer2 + WLAN_HDR_SIZE,
|
||||
eth2PacketSize2);
|
||||
|
||||
return true;
|
||||
} // GenerateExpectedPackets()
|
||||
};
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Test04: Header insertion scenario when adding total header sizes > 2048 */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
class IpaHdrProcCtxTest04 : public IpaHdrProcCtxTestFixture
|
||||
{
|
||||
public:
|
||||
IpaHdrProcCtxTest04()
|
||||
{
|
||||
m_name = "IpaHdrProcCtxTest04";
|
||||
m_description =
|
||||
"Processing context test 04 - \
|
||||
Header insertion scenario when adding \
|
||||
total header sizes > 2048 \
|
||||
1. Generate and commit all headers for all tests. \
|
||||
2. Generate and commit all processing context rules \
|
||||
for all tests.\
|
||||
3. Generate and commit routing table 0. \
|
||||
The table contains 1 \"bypass\" rule. \
|
||||
All data goes to output pipe TEST2. \
|
||||
Routing rule will use header WLAN_ETH2 \
|
||||
4. Generate and commit 1 filtering rule. \
|
||||
All traffic goes to routing table 0";
|
||||
m_pCurrentProducer = &m_wlanEth2producer;
|
||||
m_currProducerClient = IPA_CLIENT_TEST2_PROD;
|
||||
m_pCurrentConsumer = &m_defaultConsumer;
|
||||
m_currConsumerPipeNum = IPA_CLIENT_TEST2_CONS;
|
||||
m_minIPAHwType = IPA_HW_v2_5;
|
||||
m_maxIPAHwType = IPA_HW_MAX;
|
||||
m_runInRegression = false;
|
||||
Register(*this);
|
||||
}
|
||||
|
||||
virtual void AddAllHeaders()
|
||||
{
|
||||
int cnt = 0;
|
||||
int allHeadersSize = 0;
|
||||
|
||||
while (allHeadersSize <= m_ALL_HEADER_SIZE_LIMIT)
|
||||
{
|
||||
AddHeader(HEADER_HANDLE_ID_ETH2);
|
||||
/* header bins are power of 2 */
|
||||
allHeadersSize += ETH_HLEN + 2;
|
||||
cnt++;
|
||||
}
|
||||
|
||||
AddHeader(HEADER_HANDLE_ID_WLAN_ETH2);
|
||||
}
|
||||
|
||||
virtual bool AddRules()
|
||||
{
|
||||
printf("Entering %s, %s()\n",__FUNCTION__, __FILE__);
|
||||
|
||||
AddAllHeaders();
|
||||
|
||||
AddRtBypassRule(m_headerHandles[HEADER_HANDLE_ID_WLAN_ETH2], 0);
|
||||
|
||||
AddFltBypassRule();
|
||||
|
||||
printf("Leaving %s, %s()\n",__FUNCTION__, __FILE__);
|
||||
return true;
|
||||
|
||||
}// AddRules()
|
||||
|
||||
virtual bool LoadPackets(enum ipa_ip_type ip)
|
||||
{
|
||||
// load WLAN ETH2 IP4 packet of size 1kB
|
||||
// This size will trigger RNDIS aggregation later
|
||||
if (!WlanHelper::LoadWlanEth2IP4Packet(
|
||||
m_sendBuffer1,
|
||||
m_BUFF_MAX_SIZE,
|
||||
&m_sendSize1))
|
||||
return false;
|
||||
|
||||
printf ("Loaded %zu Bytes to Packet 1\n",m_sendSize1);
|
||||
|
||||
add_buff(m_sendBuffer1+WLAN_HDR_SIZE, ETH_HLEN, 13);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool GenerateExpectedPackets()
|
||||
{
|
||||
m_expectedBufferSize1 = m_sendSize1;
|
||||
memcpy(m_expectedBuffer1, m_sendBuffer1, m_expectedBufferSize1);
|
||||
memcpy(m_expectedBuffer1, WLAN_ETH2_HDR, WLAN_ETH2_HDR_SIZE);
|
||||
|
||||
return true;
|
||||
} // GenerateExpectedPackets()
|
||||
};
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Test05: Header insertion scenario of [ETH_II_802_1Q][IP] -> */
|
||||
/* [ETH_II_802_1Q][IP] */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
class IpaHdrProcCtxTest05 : public IpaHdrProcCtxTestFixture
|
||||
{
|
||||
public:
|
||||
IpaHdrProcCtxTest05()
|
||||
{
|
||||
m_name = "IpaHdrProcCtxTest05";
|
||||
m_description =
|
||||
"Processing Context test 05 - \
|
||||
of [ETH_II_802_1Q][IP] -> [ETH_II_802_1Q][IP] \
|
||||
1. Generate and commit all headers for all tests. \
|
||||
2. Generate and commit all processing context rules \
|
||||
for all tests.\
|
||||
3. Generate and commit routing table 0. \
|
||||
The table contains 1 \"bypass\" rule. \
|
||||
All data goes to output pipe TEST2. \
|
||||
Routing rule will use processing context 802_1Q_2_802_1Q \
|
||||
4. Generate and commit 1 filtering rule. \
|
||||
All traffic goes to routing table 0";
|
||||
/*
|
||||
* NOTE: we use the wlan + ETH header prod pipe since the header
|
||||
* length shall be equal to 8021Q ETH_II length
|
||||
*/
|
||||
m_pCurrentProducer = &m_wlanEth2producer;
|
||||
m_currProducerClient = IPA_CLIENT_TEST2_PROD;
|
||||
m_pCurrentConsumer = &m_defaultConsumer;
|
||||
m_currConsumerPipeNum = IPA_CLIENT_TEST2_CONS;
|
||||
m_procCtxHandleId = PROC_CTX_HANDLE_ID_802_1Q_2_802_1Q;
|
||||
m_minIPAHwType = IPA_HW_v4_0;
|
||||
m_maxIPAHwType = IPA_HW_MAX;
|
||||
m_runInRegression = false;
|
||||
Register(*this);
|
||||
}
|
||||
|
||||
virtual bool LoadPackets(enum ipa_ip_type ip)
|
||||
{
|
||||
if (!LoadDefault802_1Q(ip,
|
||||
m_sendBuffer1,
|
||||
m_sendSize1)) {
|
||||
LOG_MSG_ERROR("Failed default Packet\n");
|
||||
return false;
|
||||
}
|
||||
printf("Loaded %zu Bytes to Packet 1\n", m_sendSize1);
|
||||
|
||||
// modify the MAC addresses only
|
||||
add_buff(m_sendBuffer1, 12, 14);
|
||||
|
||||
//change vlan ID to 9
|
||||
m_sendBuffer1[15] = 0x9;
|
||||
|
||||
print_buff(m_sendBuffer1, m_sendSize1);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool GenerateExpectedPackets()
|
||||
{
|
||||
m_expectedBufferSize1 = m_sendSize1;
|
||||
|
||||
// we actually expect the same packet to come out (but after uCP)
|
||||
memcpy(m_expectedBuffer1, m_sendBuffer1, m_expectedBufferSize1);
|
||||
|
||||
return true;
|
||||
} // GenerateExpectedPackets()
|
||||
};
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Test06: Header insertion scenario of [ETH_II][IP] -> */
|
||||
/* [ETH_II_802_1Q][IP] */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
class IpaHdrProcCtxTest06 : public IpaHdrProcCtxTestFixture
|
||||
{
|
||||
public:
|
||||
IpaHdrProcCtxTest06()
|
||||
{
|
||||
m_name = "IpaHdrProcCtxTest06";
|
||||
m_description =
|
||||
"Processing Context test 06 - \
|
||||
of [ETH_II][IP] -> [ETH_II_802_1Q][IP] \
|
||||
1. Generate and commit all headers for all tests. \
|
||||
2. Generate and commit all processing context rules \
|
||||
for all tests.\
|
||||
3. Generate and commit routing table 0. \
|
||||
The table contains 1 \"bypass\" rule. \
|
||||
All data goes to output pipe TEST2. \
|
||||
Routing rule will use processing context ETH2_2_802_1Q \
|
||||
4. Generate and commit 1 filtering rule. \
|
||||
All traffic goes to routing table 0";
|
||||
|
||||
m_pCurrentProducer = &m_eth2Producer;
|
||||
m_currProducerClient = IPA_CLIENT_TEST3_PROD;
|
||||
m_pCurrentConsumer = &m_defaultConsumer;
|
||||
m_currConsumerPipeNum = IPA_CLIENT_TEST2_CONS;
|
||||
m_procCtxHandleId = PROC_CTX_HANDLE_ID_ETH2_2_802_1Q;
|
||||
m_minIPAHwType = IPA_HW_v4_0;
|
||||
m_maxIPAHwType = IPA_HW_MAX;
|
||||
m_runInRegression = false;
|
||||
Register(*this);
|
||||
}
|
||||
|
||||
virtual bool LoadPackets(enum ipa_ip_type ip)
|
||||
{
|
||||
if (!Eth2Helper::LoadEth2IP4Packet(
|
||||
m_sendBuffer1,
|
||||
m_BUFF_MAX_SIZE,
|
||||
&m_sendSize1)) {
|
||||
LOG_MSG_ERROR("Failed default Packet\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
printf("Loaded %zu Bytes to Packet 1\n", m_sendSize1);
|
||||
|
||||
// modify the MAC addresses only
|
||||
add_buff(m_sendBuffer1, 12, 15);
|
||||
|
||||
print_buff(m_sendBuffer1, m_sendSize1);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool GenerateExpectedPackets()
|
||||
{
|
||||
size_t len;
|
||||
|
||||
m_expectedBufferSize1 = ETH8021Q_HEADER_LEN +
|
||||
IP4_PACKET_SIZE;
|
||||
// copy the VLAN header to expected buffer
|
||||
memcpy(m_expectedBuffer1, ETH2_8021Q_HDR, ETH8021Q_HEADER_LEN);
|
||||
|
||||
// fill src and dst mac and ethertype
|
||||
memcpy(m_expectedBuffer1, m_sendBuffer1, 2 * ETH_ALEN);
|
||||
memcpy(m_expectedBuffer1 + ETH8021Q_ETH_TYPE_OFFSET,
|
||||
m_sendBuffer1 + ETH2_ETH_TYPE_OFFSET, ETH2_ETH_TYPE_LEN);
|
||||
|
||||
len = m_BUFF_MAX_SIZE - ETH8021Q_HEADER_LEN;
|
||||
if (!LoadDefaultPacket(IPA_IP_v4,
|
||||
m_expectedBuffer1 + ETH8021Q_HEADER_LEN,
|
||||
len)) {
|
||||
LOG_MSG_ERROR("Failed default Packet\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} // GenerateExpectedPackets()
|
||||
};
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Test07: Header insertion scenario of [ETH_II_802_1Q][IP] -> */
|
||||
/* [ETH_II][IP] */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
class IpaHdrProcCtxTest07 : public IpaHdrProcCtxTestFixture
|
||||
{
|
||||
public:
|
||||
IpaHdrProcCtxTest07()
|
||||
{
|
||||
m_name = "IpaHdrProcCtxTest07";
|
||||
m_description =
|
||||
"Processing Context test 07 - \
|
||||
of [ETH_II_802_1Q][IP] -> [ETH_II][IP] \
|
||||
1. Generate and commit all headers for all tests. \
|
||||
2. Generate and commit all processing context rules \
|
||||
for all tests.\
|
||||
3. Generate and commit routing table 0. \
|
||||
The table contains 1 \"bypass\" rule. \
|
||||
All data goes to output pipe TEST2. \
|
||||
Routing rule will use processing context 802_1Q_2_ETH2 \
|
||||
4. Generate and commit 1 filtering rule. \
|
||||
All traffic goes to routing table 0";
|
||||
|
||||
m_pCurrentProducer = &m_wlanEth2producer;
|
||||
m_currProducerClient = IPA_CLIENT_TEST2_PROD;
|
||||
m_pCurrentConsumer = &m_defaultConsumer;
|
||||
m_currConsumerPipeNum = IPA_CLIENT_TEST2_CONS;
|
||||
m_procCtxHandleId = PROC_CTX_HANDLE_ID_802_1Q_2_ETH2;
|
||||
m_minIPAHwType = IPA_HW_v4_0;
|
||||
m_maxIPAHwType = IPA_HW_MAX;
|
||||
m_runInRegression = false;
|
||||
Register(*this);
|
||||
}
|
||||
|
||||
virtual bool LoadPackets(enum ipa_ip_type ip)
|
||||
{
|
||||
if (!LoadDefault802_1Q(ip,
|
||||
m_sendBuffer1,
|
||||
m_sendSize1)) {
|
||||
LOG_MSG_ERROR("Failed default Packet\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
printf("Loaded %zu Bytes to Packet 1\n", m_sendSize1);
|
||||
|
||||
// modify the MAC addresses only
|
||||
add_buff(m_sendBuffer1, ETH8021Q_METADATA_OFFSET, 16);
|
||||
|
||||
print_buff(m_sendBuffer1, m_sendSize1);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool GenerateExpectedPackets()
|
||||
{
|
||||
size_t len;
|
||||
|
||||
m_expectedBufferSize1 = m_sendSize1 - ETH8021Q_8021Q_TAG_LEN;
|
||||
|
||||
// copy the ETH2 header to expected buffer
|
||||
memcpy(m_expectedBuffer1, ETH2_HDR, ETH_HLEN);
|
||||
|
||||
// fill src and dst mac and ethertype
|
||||
memcpy(m_expectedBuffer1, m_sendBuffer1, 2 * ETH_ALEN);
|
||||
memcpy(m_expectedBuffer1 + ETH2_ETH_TYPE_OFFSET,
|
||||
m_sendBuffer1 + ETH8021Q_ETH_TYPE_OFFSET,
|
||||
ETH2_ETH_TYPE_LEN);
|
||||
|
||||
len = m_BUFF_MAX_SIZE - ETH_HLEN;
|
||||
if (!LoadDefaultPacket(IPA_IP_v4,
|
||||
m_expectedBuffer1 + ETH_HLEN,
|
||||
len)) {
|
||||
LOG_MSG_ERROR("Failed default Packet\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} // GenerateExpectedPackets()
|
||||
};
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Test08: Header insertion scenario of [ETH_II][IP] -> */
|
||||
/* [ETH_II][IP] with generic ucp command */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
class IpaHdrProcCtxTest08 : public IpaHdrProcCtxTestFixture
|
||||
{
|
||||
public:
|
||||
IpaHdrProcCtxTest08()
|
||||
{
|
||||
m_name = "IpaHdrProcCtxTest08";
|
||||
m_description =
|
||||
"Processing Context test 08 - \
|
||||
of [ETH_II][IP] -> [ETH_II][IP] with generic ucp \
|
||||
1. Generate and commit all headers for all tests. \
|
||||
2. Generate and commit all processing context rules \
|
||||
for all tests.\
|
||||
3. Generate and commit routing table 0. \
|
||||
The table contains 1 \"bypass\" rule. \
|
||||
All data goes to output pipe TEST2. \
|
||||
Routing rule will use processing context ETH2_2_ETH2_EX \
|
||||
4. Generate and commit 1 filtering rule. \
|
||||
All traffic goes to routing table 0";
|
||||
|
||||
m_pCurrentProducer = &m_eth2Producer;
|
||||
m_currProducerClient = IPA_CLIENT_TEST3_PROD;
|
||||
m_pCurrentConsumer = &m_defaultConsumer;
|
||||
m_currConsumerPipeNum = IPA_CLIENT_TEST2_CONS;
|
||||
m_procCtxHandleId = PROC_CTX_HANDLE_ID_ETH2_ETH2_2_ETH2_EX;
|
||||
m_minIPAHwType = IPA_HW_v4_0;
|
||||
m_maxIPAHwType = IPA_HW_MAX;
|
||||
m_runInRegression = false;
|
||||
Register(*this);
|
||||
}
|
||||
|
||||
virtual bool LoadPackets(enum ipa_ip_type ip)
|
||||
{
|
||||
if (!Eth2Helper::LoadEth2IP4Packet(
|
||||
m_sendBuffer1,
|
||||
m_BUFF_MAX_SIZE,
|
||||
&m_sendSize1)) {
|
||||
LOG_MSG_ERROR("Failed default Packet\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
printf("Loaded %zu Bytes to Packet 1\n", m_sendSize1);
|
||||
|
||||
// modify the MAC addresses only
|
||||
add_buff(m_sendBuffer1, 12, 17);
|
||||
|
||||
print_buff(m_sendBuffer1, m_sendSize1);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool GenerateExpectedPackets()
|
||||
{
|
||||
m_expectedBufferSize1 = m_sendSize1;
|
||||
|
||||
// we actually expect the same packet to come out (but after uCP)
|
||||
memcpy(m_expectedBuffer1, m_sendBuffer1, m_expectedBufferSize1);
|
||||
|
||||
return true;
|
||||
} // GenerateExpectedPackets()
|
||||
};
|
||||
|
||||
static IpaHdrProcCtxTest00 ipaHdrProcCtxTest00;
|
||||
static IpaHdrProcCtxTest01 ipaHdrProcCtxTest01;
|
||||
static IpaHdrProcCtxTest02 ipaHdrProcCtxTest02;
|
||||
static IpaHdrProcCtxTest03 ipaHdrProcCtxTest03;
|
||||
static IpaHdrProcCtxTest04 ipaHdrProcCtxTest04;
|
||||
static IpaHdrProcCtxTest05 ipaHdrProcCtxTest05;
|
||||
static IpaHdrProcCtxTest06 ipaHdrProcCtxTest06;
|
||||
static IpaHdrProcCtxTest07 ipaHdrProcCtxTest07;
|
||||
static IpaHdrProcCtxTest08 ipaHdrProcCtxTest08;
|
||||
@@ -0,0 +1,404 @@
|
||||
/*
|
||||
* Copyright (c) 2017 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "HeaderRemovalTestFixture.h"
|
||||
|
||||
#include "Constants.h"
|
||||
#include "Logger.h"
|
||||
#include "IPAFilteringTable.h"
|
||||
|
||||
#define IPA_TEST_DMUX_HEADER_LENGTH 8
|
||||
#define IPA_TEST_META_DATA_IS_VALID 1
|
||||
#define IPA_TEST_DMUX_HEADER_META_DATA_OFFSET 4
|
||||
|
||||
extern Logger g_Logger;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//define the static Pipes which will be used by all derived tests.
|
||||
Pipe HeaderRemovalTestFixture::m_A2NDUNToIpaPipe(IPA_CLIENT_TEST2_PROD, IPA_TEST_CONFIFURATION_3);
|
||||
Pipe HeaderRemovalTestFixture::m_IpaToUsbPipe(IPA_CLIENT_TEST_CONS, IPA_TEST_CONFIFURATION_3);
|
||||
Pipe HeaderRemovalTestFixture::m_IpaToA2NDUNPipe(IPA_CLIENT_TEST2_CONS, IPA_TEST_CONFIFURATION_3);
|
||||
Pipe HeaderRemovalTestFixture::m_IpaToQ6LANPipe(IPA_CLIENT_TEST4_CONS, IPA_TEST_CONFIFURATION_3);
|
||||
RoutingDriverWrapper HeaderRemovalTestFixture::m_routing;
|
||||
Filtering HeaderRemovalTestFixture::m_filtering;
|
||||
const char HeaderRemovalTestFixture_bypass0[20] = "Bypass0";
|
||||
const char HeaderRemovalTestFixture_bypassIPv60[20] = "BypassIPv60";
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
HeaderRemovalTestFixture::HeaderRemovalTestFixture()
|
||||
{
|
||||
m_testSuiteName.push_back("Removal");
|
||||
Register(*this);
|
||||
}
|
||||
|
||||
static int SetupKernelModule(void)
|
||||
{
|
||||
int retval;
|
||||
struct ipa_channel_config from_ipa_channels[3];
|
||||
struct test_ipa_ep_cfg from_ipa_cfg[3];
|
||||
struct ipa_channel_config to_ipa_channels[1];
|
||||
struct test_ipa_ep_cfg to_ipa_cfg[1];
|
||||
|
||||
struct ipa_test_config_header header = {0};
|
||||
struct ipa_channel_config *to_ipa_array[1];
|
||||
struct ipa_channel_config *from_ipa_array[3];
|
||||
|
||||
/* From ipa configurations - 3 pipes */
|
||||
memset(&from_ipa_cfg[0], 0, sizeof(from_ipa_cfg[0]));
|
||||
prepare_channel_struct(&from_ipa_channels[0],
|
||||
header.from_ipa_channels_num++,
|
||||
IPA_CLIENT_TEST_CONS,
|
||||
(void *)&from_ipa_cfg[0],
|
||||
sizeof(from_ipa_cfg[0]));
|
||||
from_ipa_array[0] = &from_ipa_channels[0];
|
||||
|
||||
memset(&from_ipa_cfg[1], 0, sizeof(from_ipa_cfg[1]));
|
||||
prepare_channel_struct(&from_ipa_channels[1],
|
||||
header.from_ipa_channels_num++,
|
||||
IPA_CLIENT_TEST2_CONS,
|
||||
(void *)&from_ipa_cfg[1],
|
||||
sizeof(from_ipa_cfg[1]));
|
||||
from_ipa_array[1] = &from_ipa_channels[1];
|
||||
|
||||
memset(&from_ipa_cfg[2], 0, sizeof(from_ipa_cfg[2]));
|
||||
prepare_channel_struct(&from_ipa_channels[2],
|
||||
header.from_ipa_channels_num++,
|
||||
IPA_CLIENT_TEST4_CONS,
|
||||
(void *)&from_ipa_cfg[2],
|
||||
sizeof(from_ipa_cfg[2]));
|
||||
from_ipa_array[2] = &from_ipa_channels[2];
|
||||
|
||||
/* To ipa configurations - 1 pipes */
|
||||
memset(&to_ipa_cfg[0], 0, sizeof(to_ipa_cfg[0]));
|
||||
to_ipa_cfg[0].hdr.hdr_len = IPA_TEST_DMUX_HEADER_LENGTH;
|
||||
to_ipa_cfg[0].hdr.hdr_ofst_metadata_valid = IPA_TEST_META_DATA_IS_VALID;
|
||||
to_ipa_cfg[0].hdr.hdr_ofst_metadata =
|
||||
IPA_TEST_DMUX_HEADER_META_DATA_OFFSET;
|
||||
prepare_channel_struct(&to_ipa_channels[0],
|
||||
header.to_ipa_channels_num++,
|
||||
IPA_CLIENT_TEST2_PROD,
|
||||
(void *)&to_ipa_cfg[0],
|
||||
sizeof(to_ipa_cfg[0]));
|
||||
to_ipa_array[0] = &to_ipa_channels[0];
|
||||
|
||||
header.head_marker = IPA_TEST_CONFIG_MARKER;
|
||||
header.tail_marker = IPA_TEST_CONFIG_MARKER;
|
||||
|
||||
prepare_header_struct(&header, from_ipa_array, to_ipa_array);
|
||||
|
||||
retval = GenericConfigureScenario(&header);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool HeaderRemovalTestFixture::Setup()
|
||||
{
|
||||
bool bRetVal = true;
|
||||
|
||||
//Set the configuration to support USB->IPA and IPA->USB pipes.
|
||||
//ConfigureScenario(PHASE_THREE_TEST_CONFIGURATION);
|
||||
|
||||
bRetVal = SetupKernelModule();
|
||||
if (bRetVal != true) {
|
||||
return bRetVal;
|
||||
}
|
||||
|
||||
//Initialize the pipe for all the tests - this will open the inode which represents the pipe.
|
||||
bRetVal &= m_A2NDUNToIpaPipe.Init();
|
||||
bRetVal &= m_IpaToUsbPipe.Init();
|
||||
bRetVal &= m_IpaToA2NDUNPipe.Init();
|
||||
bRetVal &= m_IpaToQ6LANPipe.Init();
|
||||
|
||||
// remove default "LAN" routing table (as we want to pass to USB pipe)
|
||||
m_routing.Reset(IPA_IP_v4);
|
||||
m_routing.Reset(IPA_IP_v6);
|
||||
|
||||
return bRetVal;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool HeaderRemovalTestFixture::Teardown()
|
||||
{
|
||||
//The Destroy method will close the inode.
|
||||
m_A2NDUNToIpaPipe.Destroy();
|
||||
m_IpaToUsbPipe.Destroy();
|
||||
m_IpaToA2NDUNPipe.Destroy();
|
||||
m_IpaToQ6LANPipe.Destroy();
|
||||
return true;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Byte* HeaderRemovalTestFixture::CreateA2NDUNPacket(
|
||||
unsigned int magicNumber,
|
||||
unsigned int nID,
|
||||
string sPayloadFileName,
|
||||
unsigned int *nTotalLength)
|
||||
{
|
||||
size_t nIpv4ByteSize = 1024;
|
||||
bool bRetVal = false;
|
||||
Byte *pA2NDUNPacket = 0;
|
||||
unsigned int nA2NDUNPacketByteSize = 0;
|
||||
Byte *pIpv4Packet = (Byte*) malloc(1024);
|
||||
|
||||
if(0 == pIpv4Packet)
|
||||
{
|
||||
LOG_MSG_ERROR("Cannot allocate the memory for IPv4 packet");
|
||||
return 0;
|
||||
}
|
||||
|
||||
bRetVal = LoadDefaultPacket(IPA_IP_v4, pIpv4Packet, nIpv4ByteSize);
|
||||
if(false == bRetVal)
|
||||
{
|
||||
LOG_MSG_ERROR("Cannot load the packet");
|
||||
pA2NDUNPacket = 0;
|
||||
goto bail;
|
||||
}
|
||||
//Magic Number(4 Bytes) Logical Channel ID(2 Bytes) Length(2 Bytes)
|
||||
nA2NDUNPacketByteSize = m_A2NDUNToIpaPipe.GetHeaderLengthAdd() + nIpv4ByteSize;
|
||||
|
||||
pA2NDUNPacket = new Byte[ nA2NDUNPacketByteSize ];
|
||||
|
||||
//htobe32 for the magic number:
|
||||
pA2NDUNPacket[0] = (magicNumber & 0xFF000000) >> 24;//MSB
|
||||
pA2NDUNPacket[1] = (magicNumber & 0x00FF0000) >> 16;
|
||||
pA2NDUNPacket[2] = (magicNumber & 0x0000FF00) >> 8;
|
||||
pA2NDUNPacket[3] = (magicNumber & 0x000000FF) >> 0;//LSB
|
||||
|
||||
//htobe16 for the Logical Channel ID:
|
||||
pA2NDUNPacket[4] = (nID & 0xFF00) >> 8;//MSB
|
||||
pA2NDUNPacket[5] = (nID & 0x00FF) >> 0;//LSB
|
||||
|
||||
//htobe16 for the Length of the packet:
|
||||
pA2NDUNPacket[6] = (nA2NDUNPacketByteSize & 0xFF00) >> 8;//MSB
|
||||
pA2NDUNPacket[7] = (nA2NDUNPacketByteSize & 0x00FF) >> 0;//LSB
|
||||
|
||||
//add the payload to the A2NDUN packet
|
||||
memcpy(&pA2NDUNPacket[8], pIpv4Packet, nIpv4ByteSize);
|
||||
|
||||
*nTotalLength = nA2NDUNPacketByteSize;
|
||||
|
||||
/* fall through */
|
||||
|
||||
bail:
|
||||
|
||||
Free(pIpv4Packet);
|
||||
|
||||
return pA2NDUNPacket;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool HeaderRemovalTestFixture::SetIPATablesToPassAllToSpecificClient(
|
||||
enum ipa_client_type nClientTypeSrc,
|
||||
enum ipa_client_type nClientTypeDst)
|
||||
{
|
||||
bool bRetVal = true;
|
||||
|
||||
bRetVal = SetRoutingTableToPassAllToSpecificClient(nClientTypeDst);
|
||||
if(false == bRetVal)
|
||||
goto bail;
|
||||
bRetVal = SetFilterTableToPassAllToSpecificClient(nClientTypeSrc);
|
||||
if(false == bRetVal)
|
||||
goto bail;
|
||||
bRetVal = SetHeaderInsertionTableAddEmptyHeaderForTheClient(nClientTypeSrc);
|
||||
if(false == bRetVal)
|
||||
goto bail;
|
||||
/* fall through */
|
||||
|
||||
bail:
|
||||
return bRetVal;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool HeaderRemovalTestFixture::SetFilterTableToPassAllToSpecificClient(
|
||||
enum ipa_client_type nClientType)
|
||||
{
|
||||
IPAFilteringTable FilterTable;
|
||||
struct ipa_flt_rule_add flt_rule_entry;
|
||||
struct ipa_ioc_get_rt_tbl sRoutingTable;
|
||||
|
||||
sRoutingTable.ip = IPA_IP_v4;
|
||||
strlcpy(sRoutingTable.name, "Bypass0", sizeof(sRoutingTable.name));
|
||||
|
||||
if (false == m_routing.GetRoutingTable(&sRoutingTable)) {
|
||||
LOG_MSG_ERROR("Configure the routing block first");
|
||||
return false;
|
||||
}
|
||||
|
||||
FilterTable.Init(IPA_IP_v4, nClientType, false, 1);
|
||||
FilterTable.GeneratePresetRule(0, flt_rule_entry);
|
||||
flt_rule_entry.at_rear = true;
|
||||
flt_rule_entry.flt_rule_hdl = -1;
|
||||
flt_rule_entry.status = -1;
|
||||
flt_rule_entry.rule.action = IPA_PASS_TO_ROUTING;
|
||||
flt_rule_entry.rule.rt_tbl_hdl = sRoutingTable.hdl;
|
||||
flt_rule_entry.rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
|
||||
flt_rule_entry.rule.attrib.u.v4.dst_addr_mask = 0x00000000;
|
||||
flt_rule_entry.rule.attrib.u.v4.dst_addr = 0x00000000;
|
||||
if ((-1 == FilterTable.AddRuleToTable(flt_rule_entry)) ||
|
||||
!m_filtering.AddFilteringRule(FilterTable.GetFilteringTable())) {
|
||||
LOG_MSG_INFO ("%s::Error Adding RuleTable(0) to Filtering, aborting...");
|
||||
return false;
|
||||
} else {
|
||||
LOG_MSG_INFO( "flt rule hdl0=0x%x, status=0x%x",
|
||||
FilterTable.ReadRuleFromTable(0)->flt_rule_hdl,
|
||||
FilterTable.ReadRuleFromTable(0)->status);
|
||||
}
|
||||
LOG_MSG_INFO("Leaving ");
|
||||
|
||||
return true;
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool HeaderRemovalTestFixture::SetRoutingTableToPassAllToSpecificClient(
|
||||
enum ipa_client_type nClientType)
|
||||
{
|
||||
if (!CreateBypassRoutingTablesIPv4(
|
||||
HeaderRemovalTestFixture_bypass0,
|
||||
nClientType)) {
|
||||
LOG_MSG_INFO("CreateThreeBypassRoutingTables Failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool HeaderRemovalTestFixture::SetHeaderInsertionTableAddEmptyHeaderForTheClient(
|
||||
enum ipa_client_type nClientType)
|
||||
{
|
||||
//TODO Header Removal: add header insertion data
|
||||
return true;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// This function creates IPv4 bypass routing entry and commits it.
|
||||
bool HeaderRemovalTestFixture::CreateBypassRoutingTablesIPv4(
|
||||
const char * bypass0,
|
||||
enum ipa_client_type nClientType)
|
||||
{
|
||||
struct ipa_ioc_add_rt_rule *rt_rule0 = 0;
|
||||
struct ipa_rt_rule_add *rt_rule_entry;
|
||||
|
||||
LOG_MSG_INFO("Entering");
|
||||
|
||||
rt_rule0 = (struct ipa_ioc_add_rt_rule *)
|
||||
calloc(1, sizeof(struct ipa_ioc_add_rt_rule) +
|
||||
1*sizeof(struct ipa_rt_rule_add));
|
||||
if (!rt_rule0) {
|
||||
LOG_MSG_INFO("calloc failed to allocate rt_rule0");
|
||||
return false;
|
||||
}
|
||||
|
||||
rt_rule0->num_rules = 1;
|
||||
rt_rule0->ip = IPA_IP_v4;
|
||||
rt_rule0->commit = true;
|
||||
strlcpy(rt_rule0->rt_tbl_name, bypass0, sizeof(rt_rule0->rt_tbl_name));
|
||||
|
||||
rt_rule_entry = &rt_rule0->rules[0];
|
||||
rt_rule_entry->at_rear = 0;
|
||||
rt_rule_entry->rule.dst = nClientType;
|
||||
// rt_rule_entry->rule.hdr_hdl = hdr_entry->hdr_hdl; // gidons, there is no support for header insertion / removal yet.
|
||||
rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
|
||||
rt_rule_entry->rule.attrib.u.v4.dst_addr = 0xaabbccdd;
|
||||
rt_rule_entry->rule.attrib.u.v4.dst_addr_mask = 0x00000000;// All Packets will get a "Hit"
|
||||
if (false == m_routing.AddRoutingRule(rt_rule0)) {
|
||||
LOG_MSG_INFO("Routing rule addition(rt_rule0) failed!");
|
||||
Free (rt_rule0);
|
||||
return false;
|
||||
}
|
||||
|
||||
Free (rt_rule0);
|
||||
LOG_MSG_INFO("Leaving ");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool HeaderRemovalTestFixture::ConfigureFilteringBlockWithMetaDataEq(
|
||||
enum ipa_client_type nClientType,
|
||||
unsigned int nMetaData,
|
||||
unsigned int nMetaDataMask)
|
||||
{
|
||||
const char bypass0[20] = "Bypass0";
|
||||
struct ipa_ioc_get_rt_tbl routing_table0;
|
||||
IPAFilteringTable FilterTable0;
|
||||
struct ipa_flt_rule_add flt_rule_entry;
|
||||
|
||||
LOG_MSG_INFO("Entering ");
|
||||
|
||||
if (!CreateBypassRoutingTablesIPv4(
|
||||
HeaderRemovalTestFixture_bypass0,
|
||||
nClientType)) {
|
||||
LOG_MSG_INFO("CreateBypassRoutingTablesIPv4 Failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
LOG_MSG_INFO("CreateBypassRoutingTablesIPv4 completed successfully");
|
||||
routing_table0.ip = IPA_IP_v4;
|
||||
strlcpy(routing_table0.name, bypass0, sizeof(routing_table0.name));
|
||||
if (!m_routing.GetRoutingTable(&routing_table0)) {
|
||||
LOG_MSG_INFO(
|
||||
"m_routing.GetRoutingTable(&routing_table0=0x%p) Failed."
|
||||
,&routing_table0);
|
||||
return false;
|
||||
}
|
||||
|
||||
FilterTable0.Init(IPA_IP_v4, IPA_CLIENT_TEST2_PROD, false, 1);
|
||||
|
||||
LOG_MSG_INFO("FilterTable*.Init Completed Successfully..");
|
||||
|
||||
// Configuring Filtering Rule No.0
|
||||
FilterTable0.GeneratePresetRule(1,flt_rule_entry);
|
||||
flt_rule_entry.at_rear = true;
|
||||
flt_rule_entry.flt_rule_hdl = -1; // return Value
|
||||
flt_rule_entry.status = -1; // return value
|
||||
flt_rule_entry.rule.action = IPA_PASS_TO_ROUTING;
|
||||
flt_rule_entry.rule.rt_tbl_hdl = routing_table0.hdl; //put here the handle corresponding to Routing Rule 1
|
||||
flt_rule_entry.rule.attrib.attrib_mask = IPA_FLT_META_DATA;
|
||||
flt_rule_entry.rule.attrib.meta_data = nMetaData;
|
||||
flt_rule_entry.rule.attrib.meta_data_mask = nMetaDataMask;
|
||||
if ( (-1 == FilterTable0.AddRuleToTable(flt_rule_entry)) ||
|
||||
!m_filtering.AddFilteringRule(FilterTable0.GetFilteringTable()))
|
||||
{
|
||||
LOG_MSG_INFO ("%s::Error Adding RuleTable(0) to Filtering, aborting...");
|
||||
return false;
|
||||
} else {
|
||||
LOG_MSG_INFO("flt rule hdl0=0x%x, status=0x%x", FilterTable0.ReadRuleFromTable(0)->flt_rule_hdl,FilterTable0.ReadRuleFromTable(0)->status);
|
||||
}
|
||||
|
||||
LOG_MSG_INFO("Leaving ");
|
||||
|
||||
return true;
|
||||
}
|
||||
111
qcom/opensource/dataipa/kernel-tests/HeaderRemovalTestFixture.h
Normal file
111
qcom/opensource/dataipa/kernel-tests/HeaderRemovalTestFixture.h
Normal file
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Copyright (c) 2017 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _IPA_LINUX_TESTS_HR_TEST_FIXTURE_H_
|
||||
#define _IPA_LINUX_TESTS_HR_TEST_FIXTURE_H_
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "Constants.h"
|
||||
#include "Logger.h"
|
||||
#include "linux/msm_ipa.h"
|
||||
#include "TestsUtils.h"
|
||||
#include "TestBase.h"
|
||||
#include "Pipe.h"
|
||||
#include "RoutingDriverWrapper.h"
|
||||
#include "Filtering.h"
|
||||
|
||||
/*This class will be the base class of all HeaderRemoval tests.
|
||||
*Any method other than the test case itself can
|
||||
*be declared in this Fixture thus allowing the derived classes to
|
||||
*implement only the test case.
|
||||
*All the test of the HeaderRemovalTestFixture
|
||||
*uses one input and two output.
|
||||
*/
|
||||
class HeaderRemovalTestFixture:public TestBase
|
||||
{
|
||||
public:
|
||||
/*This Constructor will register each instance
|
||||
* that it creates.*/
|
||||
HeaderRemovalTestFixture();
|
||||
|
||||
/*This method will create and initialize two Pipe object for the USB
|
||||
*(Ethernet) Pipes, one as input and the other as output.
|
||||
*/
|
||||
virtual bool Setup();
|
||||
|
||||
/*This method will destroy the pipes.*/
|
||||
virtual bool Teardown();
|
||||
|
||||
/*The client type are set from the peripheral perspective
|
||||
*(TODO Pipe:in case the Driver will change its perspective
|
||||
*of ipa_connect this should be changed).
|
||||
*/
|
||||
static Pipe m_A2NDUNToIpaPipe;
|
||||
/*from the test application into the IPA(DMUX header)*/
|
||||
static Pipe m_IpaToUsbPipe;
|
||||
/*from the IPA back to the test application(Ethernet header)*/
|
||||
static Pipe m_IpaToA2NDUNPipe;
|
||||
/*from the IPA back to the test application(DMUX header)*/
|
||||
static Pipe m_IpaToQ6LANPipe;
|
||||
|
||||
static RoutingDriverWrapper m_routing;
|
||||
static Filtering m_filtering;
|
||||
|
||||
protected:
|
||||
unsigned char *CreateA2NDUNPacket(unsigned int magicNumber,
|
||||
unsigned int ID,
|
||||
string sPayloadFileName,
|
||||
unsigned int *nTotalLength);
|
||||
bool SetIPATablesToPassAllToSpecificClient(
|
||||
enum ipa_client_type nClientTypeSrc,
|
||||
enum ipa_client_type nClientTypeDst);
|
||||
bool SetFilterTableToPassAllToSpecificClient(
|
||||
enum ipa_client_type nClientType);
|
||||
bool SetRoutingTableToPassAllToSpecificClient(
|
||||
enum ipa_client_type nClientType);
|
||||
bool SetHeaderInsertionTableAddEmptyHeaderForTheClient(
|
||||
enum ipa_client_type nClientType);
|
||||
bool CreateBypassRoutingTablesIPv4(
|
||||
const char *bypass0,
|
||||
enum ipa_client_type nClientType
|
||||
);
|
||||
bool ConfigureFilteringBlockWithMetaDataEq(
|
||||
enum ipa_client_type nClientType,
|
||||
unsigned int nMetaData,
|
||||
unsigned int nMetaDataMask);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
218
qcom/opensource/dataipa/kernel-tests/HeaderRemovalTests.cpp
Normal file
218
qcom/opensource/dataipa/kernel-tests/HeaderRemovalTests.cpp
Normal file
@@ -0,0 +1,218 @@
|
||||
/*
|
||||
* Copyright (c) 2017 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "HeaderRemovalTests.h"
|
||||
#include "TestsUtils.h"
|
||||
#include <stdio.h>
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static const unsigned int HEADER_REMOVAL_TEST_MAX_PACKET_BYTE_SIZE = 1024;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
HeaderRemovalTOSCheck::HeaderRemovalTOSCheck()
|
||||
{
|
||||
m_name = "HeaderRemovalTOSCheck";
|
||||
m_description = "HeaderRemovalTOSCheck: Remove the header from the A2NDUN pipe and check the TOS field of the IP packet";
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool HeaderRemovalTOSCheck::Run()
|
||||
{
|
||||
bool bTestResult = true;
|
||||
Byte pPacketReceiveBuffer[HEADER_REMOVAL_TEST_MAX_PACKET_BYTE_SIZE] = {0};//This buffer will be used in order to store the received packet.
|
||||
|
||||
unsigned int nMagicNumber = 0x12345678; //arbitrary number
|
||||
unsigned int nChannelID = 0xABCD;//arbitrary number
|
||||
unsigned int nA2NDUNPacketByteSize = 0;
|
||||
unsigned int nBytesSent = 0;
|
||||
int nBytesReceived = 0;
|
||||
Byte *pA2NDUNPacket = CreateA2NDUNPacket(nMagicNumber, nChannelID, IPV4_FILE_PATH, &nA2NDUNPacketByteSize);
|
||||
if(0 == pA2NDUNPacket) {
|
||||
LOG_MSG_ERROR("Cannot load file to memory, exiting");
|
||||
return false;
|
||||
}
|
||||
LOG_MSG_INFO("A2 Packet was successfully created (%d bytes)", nA2NDUNPacketByteSize);
|
||||
|
||||
if ( false == SetIPATablesToPassAllToSpecificClient(IPA_CLIENT_TEST2_PROD, IPA_CLIENT_TEST_CONS)) {
|
||||
LOG_MSG_ERROR("SetIPATablesToPassAllToSpecificClient failed, exiting test case");
|
||||
bTestResult = false;
|
||||
goto bail;
|
||||
}
|
||||
|
||||
LOG_MSG_INFO("All tables were configured in order to output the packet to the correct pipe");
|
||||
|
||||
LOG_MSG_INFO("Sending packet into the A2NDUN pipe(%d bytes) and the Pipe will add an header",
|
||||
nA2NDUNPacketByteSize);
|
||||
|
||||
nBytesSent = m_A2NDUNToIpaPipe.Send(pA2NDUNPacket, nA2NDUNPacketByteSize);
|
||||
if (nA2NDUNPacketByteSize != nBytesSent)
|
||||
{
|
||||
bTestResult = false;
|
||||
goto bail;
|
||||
}
|
||||
//Receive the raw IP packet(which is a 4 arbitrary bytes) without header removal by the Pipe
|
||||
LOG_MSG_INFO("Reading packet from the USB pipe");
|
||||
|
||||
nBytesReceived = m_IpaToUsbPipe.Receive(pPacketReceiveBuffer, HEADER_REMOVAL_TEST_MAX_PACKET_BYTE_SIZE);
|
||||
//TODO Header Removal: at this point the success scenario is that data came to the correct pipe - change this to
|
||||
//packet memory compare after header insertion is enabled.
|
||||
if (0 == nBytesReceived)
|
||||
{
|
||||
bTestResult = false;
|
||||
goto bail;
|
||||
}
|
||||
|
||||
LOG_MSG_INFO("Read buffer : ");
|
||||
//Print the output
|
||||
for (int i = 0 ; i < nBytesReceived ; i++)
|
||||
{
|
||||
printf("0x%02x", pPacketReceiveBuffer[i]);
|
||||
}
|
||||
LOG_MSG_INFO("End of Read buffer.");
|
||||
|
||||
if(0 != memcmp((const void *)pPacketReceiveBuffer,
|
||||
(const void *)(pA2NDUNPacket + (nBytesSent - nBytesReceived)),
|
||||
nBytesReceived)) {
|
||||
LOG_MSG_ERROR("Memory contains don't match");
|
||||
bTestResult = false;
|
||||
goto bail;
|
||||
}
|
||||
/* fall through */
|
||||
|
||||
bail:
|
||||
|
||||
delete pA2NDUNPacket;
|
||||
return bTestResult;
|
||||
}
|
||||
|
||||
HeaderRemovalMetaDataFiltering::HeaderRemovalMetaDataFiltering()
|
||||
{
|
||||
m_name = "HeaderRemovalMetaDataFiltering";
|
||||
m_description =
|
||||
"HeaderRemovalMetaDataFiltering: check meta data based filtering";
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool HeaderRemovalMetaDataFiltering::Run()
|
||||
{
|
||||
bool bTestResult = true;
|
||||
Byte pPacketReceiveBuffer[HEADER_REMOVAL_TEST_MAX_PACKET_BYTE_SIZE] = {0};//This buffer will be used in order to store the received packet.
|
||||
|
||||
unsigned int nMagicNumber = 0x12345678; //arbitrary number
|
||||
unsigned int nChannelID = 0xABCD;//arbitrary number
|
||||
unsigned int nA2NDUNPacketByteSize = 0;
|
||||
unsigned int nMetaData = 0;
|
||||
unsigned int nMetaDataMask = 0xFFFF;
|
||||
unsigned int nBytesSent = 0;
|
||||
int nBytesReceived = 0;
|
||||
|
||||
|
||||
Byte *pA2NDUNPacket = CreateA2NDUNPacket(nMagicNumber, nChannelID, IPV4_FILE_PATH, &nA2NDUNPacketByteSize);
|
||||
if(0 == pA2NDUNPacket) {
|
||||
LOG_MSG_ERROR("Cannot load file to memory, exiting");
|
||||
return false;
|
||||
}
|
||||
|
||||
nMetaData = (nChannelID << 16) | (0xFFFF & nA2NDUNPacketByteSize);
|
||||
LOG_MSG_INFO("*************nMetaData == (0x%x)", nMetaData);
|
||||
|
||||
LOG_MSG_INFO("A2 Packet was successfully created (%d bytes)", nA2NDUNPacketByteSize);
|
||||
|
||||
SetRoutingTableToPassAllToSpecificClient(IPA_CLIENT_TEST_CONS);
|
||||
SetHeaderInsertionTableAddEmptyHeaderForTheClient(IPA_CLIENT_TEST_CONS);
|
||||
|
||||
LOG_MSG_INFO("Configuring Filtering module...");
|
||||
|
||||
if (false ==
|
||||
ConfigureFilteringBlockWithMetaDataEq(
|
||||
IPA_CLIENT_TEST_CONS,
|
||||
nMetaData,
|
||||
nMetaDataMask)) {
|
||||
bTestResult = false;
|
||||
goto bail;
|
||||
}
|
||||
|
||||
LOG_MSG_INFO("Sending packet into the A2NDUN pipe(%d bytes) and the Pipe will add an header",
|
||||
nA2NDUNPacketByteSize);
|
||||
nBytesSent = m_A2NDUNToIpaPipe.Send(pA2NDUNPacket, nA2NDUNPacketByteSize);
|
||||
if (nA2NDUNPacketByteSize != nBytesSent) {
|
||||
bTestResult = false;
|
||||
goto bail;
|
||||
}
|
||||
|
||||
//Receive the raw IP packet(which is a 4 arbitrary bytes) without header removal by the Pipe
|
||||
LOG_MSG_INFO("Reading packet from the USB pipe");
|
||||
nBytesReceived = m_IpaToUsbPipe.Receive(pPacketReceiveBuffer, HEADER_REMOVAL_TEST_MAX_PACKET_BYTE_SIZE);
|
||||
//TODO Header Removal: at this point the success scenario is that data came to the correct pipe - change this to
|
||||
//packet memory compare after header insertion is enabled.
|
||||
if (0 == nBytesReceived) {
|
||||
bTestResult = false;
|
||||
goto bail;
|
||||
}
|
||||
|
||||
LOG_MSG_INFO("Read buffer : ");
|
||||
//Print the output
|
||||
for (int i = 0 ; i < nBytesReceived ; i++) {
|
||||
printf("0x%02x", pPacketReceiveBuffer[i]);
|
||||
}
|
||||
LOG_MSG_INFO("End of Read buffer.");
|
||||
|
||||
if(0 != memcmp((const void *)pPacketReceiveBuffer,
|
||||
(const void *)(pA2NDUNPacket + (nBytesSent - nBytesReceived)),
|
||||
nBytesReceived)) {
|
||||
LOG_MSG_ERROR("Memory contains don't match");
|
||||
bTestResult = false;
|
||||
goto bail;
|
||||
}
|
||||
|
||||
/* fall through */
|
||||
|
||||
bail:
|
||||
|
||||
delete pA2NDUNPacket;
|
||||
return bTestResult;
|
||||
}
|
||||
|
||||
static HeaderRemovalTOSCheck headerRemovalTOSCheck;
|
||||
static HeaderRemovalMetaDataFiltering headerRemovalMetaDataFiltering;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
73
qcom/opensource/dataipa/kernel-tests/HeaderRemovalTests.h
Normal file
73
qcom/opensource/dataipa/kernel-tests/HeaderRemovalTests.h
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (c) 2017 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _IPA_LINUX_TESTS_HR_TESTS_H_
|
||||
#define _IPA_LINUX_TESTS_HR_TESTS_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "Constants.h"
|
||||
#include "linux/msm_ipa.h"
|
||||
#include "TestsUtils.h"
|
||||
#include "HeaderRemovalTestFixture.h"
|
||||
|
||||
/*This test will send a DMUX with IP packet and check it TOS field thus
|
||||
*validating the the header was removed.
|
||||
*/
|
||||
class HeaderRemovalTOSCheck:public HeaderRemovalTestFixture
|
||||
{
|
||||
public:
|
||||
/*This Constructor will be use to specify some test description.*/
|
||||
HeaderRemovalTOSCheck();
|
||||
|
||||
/*This method will send a an IP packet with
|
||||
* DMUX header and create a rule
|
||||
* */
|
||||
virtual bool Run();
|
||||
};
|
||||
|
||||
/*This test will send a DMUX with IP packet and see if it filtered
|
||||
*by meta data contained in link layer header as expected
|
||||
*/
|
||||
class HeaderRemovalMetaDataFiltering:HeaderRemovalTestFixture
|
||||
{
|
||||
public:
|
||||
/* his Constructor will be use to specify
|
||||
* some test description.*/
|
||||
HeaderRemovalMetaDataFiltering();
|
||||
|
||||
virtual bool Run();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
313
qcom/opensource/dataipa/kernel-tests/IPAFilteringTable.cpp
Normal file
313
qcom/opensource/dataipa/kernel-tests/IPAFilteringTable.cpp
Normal file
@@ -0,0 +1,313 @@
|
||||
/*
|
||||
* Copyright (c) 2017,2020-2021 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "IPAFilteringTable.h"
|
||||
#include <cstring>
|
||||
#include "TestsUtils.h"
|
||||
|
||||
IPAFilteringTable::IPAFilteringTable () : // C'tor
|
||||
m_pFilteringTable(NULL),
|
||||
nextRuleIndex(0) {}
|
||||
|
||||
bool IPAFilteringTable::Init(ipa_ip_type ipFamily, ipa_client_type pipeNo, uint8_t isGlobal, uint8_t numOfRulesInTable, uint8_t commit)
|
||||
{
|
||||
if (NULL != m_pFilteringTable) {
|
||||
char message[256] = {0};
|
||||
snprintf(message, sizeof(message), "Error in Function %s, m_pFilteringTable==0x%p, must be NULL, Please call D'tor prior to calling () %s.",
|
||||
__FUNCTION__,m_pFilteringTable,__FUNCTION__);
|
||||
ReportError(message);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (numOfRulesInTable < 1) {
|
||||
char message[256] = {0};
|
||||
snprintf(message, sizeof(message),"Error in Function %s, numberOfRulesInTable==%d must be > 0",
|
||||
__FUNCTION__,numOfRulesInTable);
|
||||
ReportError(message);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_pFilteringTable = (struct ipa_ioc_add_flt_rule *)
|
||||
calloc(1, sizeof(struct ipa_ioc_add_flt_rule) +
|
||||
numOfRulesInTable *sizeof(struct ipa_flt_rule_add));
|
||||
|
||||
if (NULL == m_pFilteringTable) {
|
||||
char message[256] = {0};
|
||||
snprintf(message, sizeof(message),"Error in Function %s, Failed to allocate %d filter rules in Filtering Table",__FUNCTION__,numOfRulesInTable);
|
||||
ReportError(message);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_pFilteringTable->commit = commit;
|
||||
m_pFilteringTable->ep = pipeNo;
|
||||
m_pFilteringTable->global = isGlobal;
|
||||
m_pFilteringTable->ip = ipFamily;
|
||||
m_pFilteringTable->num_rules = (uint8_t)(numOfRulesInTable);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IPAFilteringTable::GeneratePresetRule(uint8_t preset,ipa_flt_rule_add &flt_rule_entry)
|
||||
{
|
||||
memset(&flt_rule_entry,0,sizeof(ipa_flt_rule_add)); // Zero All Fields
|
||||
|
||||
switch (preset)
|
||||
{
|
||||
case 0: // in Preset 0 the Filtering Rule is matches all (bypass)
|
||||
flt_rule_entry.flt_rule_hdl=-1; // return Value
|
||||
flt_rule_entry.status = -1; // return value
|
||||
break;
|
||||
case 1:
|
||||
flt_rule_entry.at_rear = true;
|
||||
flt_rule_entry.flt_rule_hdl=-1; // return Value
|
||||
flt_rule_entry.status = -1; // return value
|
||||
flt_rule_entry.rule.action=IPA_PASS_TO_ROUTING;
|
||||
//flt_rule_entry.rule.rt_tbl_hdl=routing_table0.hdl; //put here the handle corresponding to Routing Rule 1
|
||||
flt_rule_entry.rule.attrib.attrib_mask = IPA_FLT_PROTOCOL;
|
||||
flt_rule_entry.rule.attrib.u.v4.protocol = 17; // Filter only UDP Packets.
|
||||
break;
|
||||
default:
|
||||
char message[256] = {0};
|
||||
snprintf(message, sizeof(message),"Error in Function %s, preset=%d, is not supported.",__FUNCTION__,preset);
|
||||
ReportError(message);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t IPAFilteringTable::AddRuleToTable(ipa_flt_rule_add flt_rule_entry)
|
||||
{
|
||||
if (NULL == m_pFilteringTable) {
|
||||
char message[256] = {0};
|
||||
snprintf(message, sizeof(message),"Error in Function %s, m_pFilteringTable==NULL, Please call Init() prior to calling %s().",__FUNCTION__,__FUNCTION__);
|
||||
ReportError(message);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (nextRuleIndex >= m_pFilteringTable->num_rules) {
|
||||
char message[256] = {0};
|
||||
snprintf(message, sizeof(message),"Error in Function %s, ruleIindex==%d while, No. of Rules in Filtering Table is %d. Please use IPAFilteringTable::WriteRule().",
|
||||
__FUNCTION__,nextRuleIndex,m_pFilteringTable->num_rules);
|
||||
ReportError(message);
|
||||
return -1;
|
||||
}
|
||||
struct ipa_flt_rule_add *pFilteringRule = &(m_pFilteringTable->rules[nextRuleIndex]);
|
||||
memcpy(pFilteringRule,&flt_rule_entry,sizeof(ipa_flt_rule_add));
|
||||
nextRuleIndex++;
|
||||
return(nextRuleIndex-1);
|
||||
}
|
||||
|
||||
const ipa_flt_rule_add * IPAFilteringTable::ReadRuleFromTable(uint8_t index)
|
||||
{
|
||||
if (index < nextRuleIndex)
|
||||
return (&(m_pFilteringTable->rules[index]));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool IPAFilteringTable::WriteRuleToEndOfTable(const ipa_flt_rule_add *flt_rule_entry) {
|
||||
ipa_ioc_add_flt_rule *prev_flt;
|
||||
|
||||
if (NULL == m_pFilteringTable) {
|
||||
char message[256] = { 0 };
|
||||
snprintf(message, sizeof(message), "Error in Function %s, m_pFilteringTable==NULL, Please call Init() prior to calling %s().", __FUNCTION__, __FUNCTION__);
|
||||
ReportError(message);
|
||||
return false;
|
||||
}
|
||||
|
||||
prev_flt = m_pFilteringTable;
|
||||
m_pFilteringTable = NULL;
|
||||
m_pFilteringTable = (struct ipa_ioc_add_flt_rule *)calloc(
|
||||
1, sizeof(struct ipa_ioc_add_flt_rule) +
|
||||
((prev_flt->num_rules + 1) * sizeof(struct ipa_flt_rule_add)));
|
||||
|
||||
if (NULL == m_pFilteringTable) {
|
||||
char message[256] = { 0 };
|
||||
snprintf(
|
||||
message, sizeof(message),
|
||||
"Error in Function %s, Failed to allocate %d filter rules in Filtering Table",
|
||||
__FUNCTION__, prev_flt->num_rules + 1);
|
||||
ReportError(message);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_pFilteringTable->commit = prev_flt->commit;
|
||||
m_pFilteringTable->ep = prev_flt->ep;
|
||||
m_pFilteringTable->global = prev_flt->global;
|
||||
m_pFilteringTable->ip = prev_flt->ip;
|
||||
m_pFilteringTable->num_rules = prev_flt->num_rules + 1;
|
||||
|
||||
for (int i = 0; i < prev_flt->num_rules; i++) {
|
||||
memcpy(&(m_pFilteringTable->rules[i]), &(prev_flt->rules[i]),
|
||||
sizeof(ipa_flt_rule_add));
|
||||
}
|
||||
free(prev_flt);
|
||||
|
||||
struct ipa_flt_rule_add *pFilteringRule = &(m_pFilteringTable->rules[nextRuleIndex]);
|
||||
memcpy(pFilteringRule, flt_rule_entry, sizeof(ipa_flt_rule_add));
|
||||
nextRuleIndex++;
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
//This Function Frees the Filtering Table and all it's content.
|
||||
//This Function will always return TRUE;
|
||||
void IPAFilteringTable::Destructor()
|
||||
{
|
||||
if (NULL != m_pFilteringTable) {
|
||||
free (m_pFilteringTable);
|
||||
printf("Filtering Table Freed\n");
|
||||
}
|
||||
m_pFilteringTable = NULL;
|
||||
nextRuleIndex = 0;
|
||||
}
|
||||
|
||||
IPAFilteringTable::~IPAFilteringTable()
|
||||
{
|
||||
Destructor();
|
||||
}
|
||||
|
||||
/* V2 */
|
||||
|
||||
IPAFilteringTable_v2::IPAFilteringTable_v2() : // C'tor
|
||||
m_pFilteringTable_v2(NULL),
|
||||
nextRuleIndex(0)
|
||||
{
|
||||
}
|
||||
|
||||
bool IPAFilteringTable_v2::Init(ipa_ip_type ipFamily, ipa_client_type pipeNo, uint8_t isGlobal, uint8_t numOfRulesInTable, uint8_t commit)
|
||||
{
|
||||
if (NULL != m_pFilteringTable_v2) {
|
||||
char message[256] = { 0 };
|
||||
snprintf(message, sizeof(message), "Error in Function %s, m_pFilteringTable_v2==0x%p, must be NULL, Please call D'tor prior to calling () %s.",
|
||||
__FUNCTION__, m_pFilteringTable_v2, __FUNCTION__);
|
||||
ReportError(message);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (numOfRulesInTable < 1) {
|
||||
char message[256] = { 0 };
|
||||
snprintf(message, sizeof(message), "Error in Function %s, numberOfRulesInTable==%d must be > 0",
|
||||
__FUNCTION__, numOfRulesInTable);
|
||||
ReportError(message);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_pFilteringTable_v2 = (struct ipa_ioc_add_flt_rule_v2 *)
|
||||
calloc(1, sizeof(struct ipa_ioc_add_flt_rule_v2));
|
||||
m_pFilteringTable_v2->rules = (uint64_t)calloc(numOfRulesInTable, sizeof(struct ipa_flt_rule_add_v2));
|
||||
|
||||
if (NULL == m_pFilteringTable_v2) {
|
||||
char message[256] = { 0 };
|
||||
snprintf(message, sizeof(message), "Error in Function %s, Failed to allocate %d filter rules in Filtering Table V2", __FUNCTION__, numOfRulesInTable);
|
||||
ReportError(message);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_pFilteringTable_v2->commit = commit;
|
||||
m_pFilteringTable_v2->ep = pipeNo;
|
||||
m_pFilteringTable_v2->global = isGlobal;
|
||||
m_pFilteringTable_v2->ip = ipFamily;
|
||||
m_pFilteringTable_v2->num_rules = (uint8_t)(numOfRulesInTable);
|
||||
m_pFilteringTable_v2->flt_rule_size = sizeof(struct ipa_flt_rule_add_v2);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IPAFilteringTable_v2::GeneratePresetRule(uint8_t preset, ipa_flt_rule_add_v2 &flt_rule_entry)
|
||||
{
|
||||
memset(&flt_rule_entry, 0, sizeof(ipa_flt_rule_add_v2)); // Zero All Fields
|
||||
|
||||
switch (preset) {
|
||||
case 0: // in Preset 0 the Filtering Rule is matches all (bypass)
|
||||
flt_rule_entry.flt_rule_hdl = -1; // return Value
|
||||
flt_rule_entry.status = -1; // return value
|
||||
break;
|
||||
case 1:
|
||||
flt_rule_entry.at_rear = true;
|
||||
flt_rule_entry.flt_rule_hdl = -1; // return Value
|
||||
flt_rule_entry.status = -1; // return value
|
||||
flt_rule_entry.rule.action = IPA_PASS_TO_ROUTING;
|
||||
//flt_rule_entry.rule.rt_tbl_hdl=routing_table0.hdl; //put here the handle corresponding to Routing Rule 1
|
||||
flt_rule_entry.rule.attrib.attrib_mask = IPA_FLT_PROTOCOL;
|
||||
flt_rule_entry.rule.attrib.u.v4.protocol = 17; // Filter only UDP Packets.
|
||||
break;
|
||||
default:
|
||||
char message[256] = { 0 };
|
||||
snprintf(message, sizeof(message), "Error in Function %s, preset=%d, is not supported.", __FUNCTION__, preset);
|
||||
ReportError(message);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t IPAFilteringTable_v2::AddRuleToTable(ipa_flt_rule_add_v2 flt_rule_entry)
|
||||
{
|
||||
if (NULL == m_pFilteringTable_v2) {
|
||||
char message[256] = { 0 };
|
||||
snprintf(message, sizeof(message), "Error in Function %s, m_pFilteringTable_v2==NULL, Please call Init() prior to calling %s().", __FUNCTION__, __FUNCTION__);
|
||||
ReportError(message);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (nextRuleIndex >= m_pFilteringTable_v2->num_rules) {
|
||||
char message[256] = { 0 };
|
||||
snprintf(message, sizeof(message), "Error in Function %s, ruleIindex==%d while, No. of Rules in Filtering Table is %d. Please use IPAFilteringTable::WriteRule().",
|
||||
__FUNCTION__, nextRuleIndex, m_pFilteringTable_v2->num_rules);
|
||||
ReportError(message);
|
||||
return -1;
|
||||
}
|
||||
struct ipa_flt_rule_add_v2 *pFilteringRule = &(((struct ipa_flt_rule_add_v2 *)(m_pFilteringTable_v2->rules))[nextRuleIndex]);
|
||||
memcpy(pFilteringRule, &flt_rule_entry, sizeof(ipa_flt_rule_add_v2));
|
||||
nextRuleIndex++;
|
||||
return(nextRuleIndex - 1);
|
||||
}
|
||||
|
||||
const ipa_flt_rule_add_v2 *IPAFilteringTable_v2::ReadRuleFromTable(uint8_t index)
|
||||
{
|
||||
if (index < nextRuleIndex)
|
||||
return (&(((struct ipa_flt_rule_add_v2*)m_pFilteringTable_v2->rules)[index]));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//This Function Frees the Filtering Table and all it's content.
|
||||
//This Function will always return TRUE;
|
||||
void IPAFilteringTable_v2::Destructor()
|
||||
{
|
||||
if (NULL != m_pFilteringTable_v2) {
|
||||
free(m_pFilteringTable_v2);
|
||||
printf("Filtering Table Freed\n");
|
||||
}
|
||||
m_pFilteringTable_v2 = NULL;
|
||||
nextRuleIndex = 0;
|
||||
}
|
||||
|
||||
IPAFilteringTable_v2::~IPAFilteringTable_v2()
|
||||
{
|
||||
Destructor();
|
||||
}
|
||||
|
||||
136
qcom/opensource/dataipa/kernel-tests/IPAFilteringTable.h
Normal file
136
qcom/opensource/dataipa/kernel-tests/IPAFilteringTable.h
Normal file
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
* Copyright (c) 2017,2020-2021 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _FILTERING_TABLE_
|
||||
#define _FILTERING_TABLE_
|
||||
|
||||
#include "Constants.h"
|
||||
#include "Filtering.h"
|
||||
|
||||
/*This Class Encapsulate Filtering Table and Filtering Rules.
|
||||
*It allows the user to easily manipulate rules and Tables.
|
||||
*/
|
||||
class IPAFilteringTable {
|
||||
public:
|
||||
IPAFilteringTable();
|
||||
~IPAFilteringTable();
|
||||
|
||||
bool Init(ipa_ip_type ipFamily, ipa_client_type pipeNo,
|
||||
uint8_t isGlobal, uint8_t numOfRulesInTable,
|
||||
uint8_t commit = true);
|
||||
|
||||
/*This Function Frees the Filtering Table and all it's content.
|
||||
*This Function will always return TRUE;
|
||||
*/
|
||||
void Destructor();
|
||||
|
||||
bool GeneratePresetRule(uint8_t preset,
|
||||
ipa_flt_rule_add &flt_rule_entry);
|
||||
bool GeneratePresetRule(uint8_t preset,
|
||||
ipa_flt_rule_add_v2 &flt_rule_entry);
|
||||
uint8_t AddRuleToTable(ipa_flt_rule_add flt_rule_entry);
|
||||
uint8_t AddRuleToTable(ipa_flt_rule_add_v2 flt_rule_entry);
|
||||
bool WriteRuleToEndOfTable(const ipa_flt_rule_add *flt_rule_entry);
|
||||
|
||||
/*Warning!!!
|
||||
*Take care when using this function.
|
||||
*The Returned pointer existence is guaranteed only as
|
||||
*long as no other method of this class is called.
|
||||
*/
|
||||
const ipa_flt_rule_add *ReadRuleFromTable(uint8_t index);
|
||||
|
||||
/*Warning!!!
|
||||
*Take care when using this function
|
||||
*The Returned pointer existence is guaranteed only
|
||||
*as long as no other method of this class is called.
|
||||
*/
|
||||
const ipa_ioc_add_flt_rule *GetFilteringTable()
|
||||
{
|
||||
return m_pFilteringTable;
|
||||
}
|
||||
|
||||
uint8_t size()
|
||||
{
|
||||
return nextRuleIndex;
|
||||
}
|
||||
|
||||
private:
|
||||
void ReportError(char *message)
|
||||
{
|
||||
printf("%s\n", message);
|
||||
}
|
||||
ipa_ioc_add_flt_rule *m_pFilteringTable;
|
||||
uint8_t nextRuleIndex;
|
||||
};
|
||||
|
||||
class IPAFilteringTable_v2 {
|
||||
public:
|
||||
IPAFilteringTable_v2();
|
||||
~IPAFilteringTable_v2();
|
||||
|
||||
bool Init(ipa_ip_type ipFamily, ipa_client_type pipeNo,
|
||||
uint8_t isGlobal, uint8_t numOfRulesInTable,
|
||||
uint8_t commit = true);
|
||||
|
||||
/*This Function Frees the Filtering Table and all it's content.
|
||||
*This Function will always return TRUE;
|
||||
*/
|
||||
void Destructor();
|
||||
|
||||
bool GeneratePresetRule(uint8_t preset,
|
||||
ipa_flt_rule_add_v2 &flt_rule_entry);
|
||||
uint8_t AddRuleToTable(ipa_flt_rule_add_v2 flt_rule_entry);
|
||||
|
||||
/*Warning!!!
|
||||
*Take care when using this function.
|
||||
*The Returned pointer existence is guaranteed only as
|
||||
*long as no other method of this class is called.
|
||||
*/
|
||||
const ipa_flt_rule_add_v2 *ReadRuleFromTable(uint8_t index);
|
||||
|
||||
/*Warning!!!
|
||||
*Take care when using this function
|
||||
*The Returned pointer existence is guaranteed only
|
||||
*as long as no other method of this class is called.
|
||||
*/
|
||||
const ipa_ioc_add_flt_rule_v2 *GetFilteringTable()
|
||||
{
|
||||
return m_pFilteringTable_v2;
|
||||
}
|
||||
|
||||
private:
|
||||
void ReportError(char *message)
|
||||
{
|
||||
printf("%s\n", message);
|
||||
}
|
||||
ipa_ioc_add_flt_rule_v2 *m_pFilteringTable_v2;
|
||||
uint8_t nextRuleIndex;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (c) 2017 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "IPAInterruptsTestFixture.h"
|
||||
|
||||
/*define the static Pipes which will be used by all derived tests.*/
|
||||
Pipe IPAInterruptsTestFixture::m_IpaToUsbPipe(IPA_CLIENT_TEST_CONS, IPA_TEST_CONFIGURATION_19);
|
||||
Pipe IPAInterruptsTestFixture::m_UsbToIpaPipe(IPA_CLIENT_TEST_PROD, IPA_TEST_CONFIGURATION_19);
|
||||
|
||||
IPAInterruptsTestFixture::IPAInterruptsTestFixture()
|
||||
{
|
||||
m_testSuiteName.push_back("Interrupts");
|
||||
}
|
||||
|
||||
bool IPAInterruptsTestFixture::Setup()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IPAInterruptsTestFixture::Run()
|
||||
{
|
||||
bool bTestResult = true;
|
||||
Byte pIpPacket[] = { 0x01, 0x02, 0x03, 0x04 }; //This packet will be sent(It can be replaced by a real IP packet).
|
||||
Byte pIpPacketReceive[sizeof(pIpPacket)] = { 0 }; //This buffer will be used in order to store the received packet.
|
||||
|
||||
//Send the raw IP packet(which is a 4 arbitrary bytes) without header addition by the Pipe
|
||||
LOG_MSG_DEBUG(
|
||||
"Sending packet into the USB pipe(%d bytes)\n", sizeof(pIpPacket));
|
||||
int nBytesSent = m_UsbToIpaPipe.Send(pIpPacket, sizeof(pIpPacket));
|
||||
if (sizeof(pIpPacket) != nBytesSent) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//Receive the raw IP packet(which is a 4 arbitrary bytes) without header removal by the Pipe
|
||||
LOG_MSG_DEBUG(
|
||||
"Reading packet from the USB pipe(%d bytes should be there)\n", sizeof(pIpPacketReceive));
|
||||
int nBytesReceived = m_IpaToUsbPipe.Receive(pIpPacketReceive,
|
||||
sizeof(pIpPacketReceive));
|
||||
if (sizeof(pIpPacketReceive) != nBytesReceived) {
|
||||
LOG_MSG_DEBUG("sizes mismatch\n");
|
||||
for (int i = 0; i < nBytesReceived && i < (int)sizeof(pIpPacketReceive) ; i++) {
|
||||
LOG_MSG_DEBUG("0x%02x\n", pIpPacketReceive[i]);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < nBytesReceived; i++) {
|
||||
LOG_MSG_DEBUG("0x%02x\n", pIpPacketReceive[i]);
|
||||
}
|
||||
|
||||
//Check that the sent IP packet is equal to the received IP packet.
|
||||
LOG_MSG_DEBUG("Checking sent.vs.received packet\n");
|
||||
bTestResult &= !memcmp(pIpPacket, pIpPacketReceive, sizeof(pIpPacket));
|
||||
|
||||
return bTestResult;
|
||||
}
|
||||
|
||||
bool IPAInterruptsTestFixture::Teardown()
|
||||
{
|
||||
/* unregister the test framework suspend handler */
|
||||
RegSuspendHandler(false, false, 0);
|
||||
|
||||
/*The Destroy method will close the inode.*/
|
||||
m_IpaToUsbPipe.Destroy();
|
||||
m_UsbToIpaPipe.Destroy();
|
||||
ConfigureScenario(-1);
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (c) 2017 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "Constants.h"
|
||||
#include "Logger.h"
|
||||
#include "linux/msm_ipa.h"
|
||||
#include "TestsUtils.h"
|
||||
#include "TestBase.h"
|
||||
#include "Pipe.h"
|
||||
|
||||
/*This class will be the base class of all Pipe tests.
|
||||
*Any method other than the test case itself can be
|
||||
*declared in this Fixture thus allowing the derived classes to
|
||||
*implement only the test case.
|
||||
*All the test of the pipe uses one input and one output in DMA mode.
|
||||
*/
|
||||
class IPAInterruptsTestFixture:public TestBase
|
||||
{
|
||||
public:
|
||||
/*This Constructor will register each instance that it creates.*/
|
||||
IPAInterruptsTestFixture();
|
||||
|
||||
/*This method will create and initialize two Pipe object for the USB
|
||||
* (Ethernet) Pipes, one as input and the other as output.
|
||||
*/
|
||||
virtual bool Setup();
|
||||
|
||||
/*Run test logic*/
|
||||
bool Run();
|
||||
|
||||
/*This method will destroy the pipes.*/
|
||||
virtual bool Teardown();
|
||||
|
||||
/*The client type are set from the peripheral perspective
|
||||
* (TODO Pipe:in case the Driver will change its perspective
|
||||
* of ipa_connect this should be changed).
|
||||
*/
|
||||
static Pipe m_IpaToUsbPipe;
|
||||
static Pipe m_UsbToIpaPipe;
|
||||
};
|
||||
104
qcom/opensource/dataipa/kernel-tests/IPAInterruptsTests.cpp
Normal file
104
qcom/opensource/dataipa/kernel-tests/IPAInterruptsTests.cpp
Normal file
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (c) 2017 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "IPAInterruptsTestFixture.h"
|
||||
#include "Constants.h"
|
||||
#include "TestsUtils.h"
|
||||
#include "linux/msm_ipa.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class SuspendTestDeferred: public IPAInterruptsTestFixture {
|
||||
public:
|
||||
|
||||
SuspendTestDeferred() {
|
||||
m_name = "SuspendTestDeferred";
|
||||
m_description = "This test will send data on a suspended pipe(Deferred context) ";
|
||||
Register(*this);
|
||||
}
|
||||
|
||||
bool Setup()
|
||||
{
|
||||
bool bRetVal = true;
|
||||
|
||||
/*Set the configuration to support USB->IPA and IPA->USB pipes.*/
|
||||
ConfigureScenario(IPA_TEST_CONFIGURATION_19);
|
||||
|
||||
RegSuspendHandler(true,true,0);
|
||||
|
||||
/*Initialize the pipe for all the tests -
|
||||
* this will open the inode which represents the pipe.
|
||||
*/
|
||||
bRetVal &= m_IpaToUsbPipe.Init();
|
||||
bRetVal &= m_UsbToIpaPipe.Init();
|
||||
return bRetVal;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class SuspendTest: public IPAInterruptsTestFixture {
|
||||
public:
|
||||
|
||||
SuspendTest() {
|
||||
m_name = "SuspendTest";
|
||||
m_description = "This test will send data on a suspended pipe";
|
||||
Register(*this);
|
||||
}
|
||||
|
||||
bool Setup()
|
||||
{
|
||||
bool bRetVal = true;
|
||||
|
||||
/*Set the configuration to support USB->IPA and IPA->USB pipes.*/
|
||||
ConfigureScenario(IPA_TEST_CONFIGURATION_19);
|
||||
|
||||
RegSuspendHandler(false,true,0);
|
||||
|
||||
/*Initialize the pipe for all the tests -
|
||||
* this will open the inode which represents the pipe.
|
||||
*/
|
||||
bRetVal &= m_IpaToUsbPipe.Init();
|
||||
bRetVal &= m_UsbToIpaPipe.Init();
|
||||
return bRetVal;
|
||||
}
|
||||
};
|
||||
|
||||
static SuspendTest suspendTest;
|
||||
static SuspendTestDeferred suspendTestDeferred;
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// EOF ////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
409
qcom/opensource/dataipa/kernel-tests/IPv4Packet.cpp
Normal file
409
qcom/opensource/dataipa/kernel-tests/IPv4Packet.cpp
Normal file
@@ -0,0 +1,409 @@
|
||||
/*
|
||||
* Copyright (c) 2017-2018 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "TestsUtils.h"
|
||||
#include "IPv4Packet.h"
|
||||
#include "memory.h"
|
||||
|
||||
using namespace IPA;
|
||||
|
||||
static const unsigned char TCP_IP_PACKET_DUMP[] = { 0x45, // IPv4, IHL = 5
|
||||
0x00, // ToS = 0
|
||||
0x00, 0x28, // Total length
|
||||
0x11, 0xc2, // ID
|
||||
0x40, 0x00, //ID + Fragment Offset
|
||||
0x80, // TTL
|
||||
0x06, // Protocol = TCP
|
||||
0x70, 0x3a, //Checksum
|
||||
0x0a, 0x05, 0x07, 0x46, // Source IP 10.5.7.70
|
||||
0x81, 0x2e, 0xe6, 0x5a, // Destination IP 129.46.230.90
|
||||
0xf3, 0xa2, // Source Port 62370
|
||||
0x01, 0xbd, // Destination Port 445
|
||||
0x26, 0x26, 0x1d, 0x7d, // Seq Number
|
||||
0x15, 0xaa, 0xbc, 0xdb, // Ack Num
|
||||
0x50, 0x10, 0x80, 0xd4, // TCP Params
|
||||
0xaa, 0xa3, // TCP Checksum
|
||||
0x00, 0x00 // Urgent PTR
|
||||
};
|
||||
|
||||
static const unsigned char UDP_IP_PACKET_DUMP[] = {
|
||||
0x45, // IPv4, IHL = 5
|
||||
0x00, // ToS = 0
|
||||
0x00,
|
||||
0x34, // Total Length
|
||||
0x12,
|
||||
0xa2, // ID
|
||||
0x00,
|
||||
0x00, //ID + fragment offset
|
||||
0x80, // TTL
|
||||
0x11, // Protocol = UDP
|
||||
0xe4,
|
||||
0x92, // Checksum
|
||||
0x0a, 0x05, 0x07,
|
||||
0x46, // Source IP 10.5.7.70
|
||||
0x0a, 0x2b, 0x28,
|
||||
0x0f, // Destination IP 10.43.40.15
|
||||
0x03,
|
||||
0x4a, // Source port 842
|
||||
0x1b,
|
||||
0x4f, // Destination Port 6991
|
||||
0x00,
|
||||
0x20, // UDP length
|
||||
0x36,
|
||||
0xac, // UDP checksum
|
||||
0x00, 0x05, 0x20,
|
||||
0x6d, // Data
|
||||
0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x01, 0x13, 0x05, 0x20, 0x6c };
|
||||
static unsigned char ICMP_IP_PACKET_DUMP[] = {
|
||||
//IP
|
||||
0x45, 0x00, 0x00, 0xdc, 0x03, 0xfe, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00,
|
||||
0x81, 0x2e, 0xe4, 0xf6, 0x81, 0x2e, 0xe6, 0xd4,
|
||||
//ICMP
|
||||
0x00, 0x00, 0xa9, 0xcd, 0x28, 0xa3, 0x01, 0x00,
|
||||
//DATA
|
||||
0xee, 0x7c, 0xf7, 0x90, 0x39, 0x06, 0xd4, 0x41, 0x51, 0x51, 0x51, 0x51,
|
||||
0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51,
|
||||
0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51,
|
||||
0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51,
|
||||
0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51,
|
||||
0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51,
|
||||
0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51,
|
||||
0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51,
|
||||
0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51,
|
||||
0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51,
|
||||
0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51,
|
||||
0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51,
|
||||
0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51,
|
||||
0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51,
|
||||
0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51,
|
||||
0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51 };
|
||||
|
||||
static void LittleToBigEndianUint32(unsigned char *pBigEndianBuffer,
|
||||
unsigned int nUint32LittleEndianValue) {
|
||||
unsigned char nLsb = nUint32LittleEndianValue & 0xff;
|
||||
unsigned char nLsbMsbLow = (nUint32LittleEndianValue >> 8) & 0xff;
|
||||
unsigned char nLsbMsbHigh = (nUint32LittleEndianValue >> 16) & 0xff;
|
||||
unsigned char nMsb = (nUint32LittleEndianValue >> 24) & 0xff;
|
||||
|
||||
pBigEndianBuffer[0] = nMsb;
|
||||
pBigEndianBuffer[1] = nLsbMsbHigh;
|
||||
pBigEndianBuffer[2] = nLsbMsbLow;
|
||||
pBigEndianBuffer[3] = nLsb;
|
||||
}
|
||||
|
||||
static unsigned short BigToLittleEndianUint16(unsigned char *pBigEndianStart) {
|
||||
unsigned char nMsb = pBigEndianStart[0];
|
||||
unsigned char nLsb = pBigEndianStart[1];
|
||||
|
||||
return (nMsb << 8 | nLsb << 0);
|
||||
}
|
||||
|
||||
static unsigned int BigToLittleEndianUint32(unsigned char *pBigEndianStart) {
|
||||
unsigned char nMsb = pBigEndianStart[0];
|
||||
unsigned char nMsbLsbHigh = pBigEndianStart[1];
|
||||
unsigned char nMsbLsbLow = pBigEndianStart[2];
|
||||
unsigned char nLsb = pBigEndianStart[3];
|
||||
|
||||
return (nMsb << 24 | nMsbLsbHigh << 16 | nMsbLsbLow << 8 | nLsb << 0);
|
||||
}
|
||||
|
||||
static void LittleToBigEndianUint16(unsigned char *pBigEndianBuffer,
|
||||
unsigned int nUint16LittleEndianValue) {
|
||||
unsigned char nLsb = nUint16LittleEndianValue & 0xff;
|
||||
unsigned char nMsb = (nUint16LittleEndianValue >> 8) & 0xff;
|
||||
|
||||
pBigEndianBuffer[0] = nMsb;
|
||||
pBigEndianBuffer[1] = nLsb;
|
||||
}
|
||||
|
||||
static unsigned short Get2BBIGEndian(const unsigned char *pBuff, int offset) {
|
||||
unsigned char upperByte = 0;
|
||||
unsigned char lowerByte = 0;
|
||||
|
||||
memcpy(&upperByte, pBuff + offset, 1);
|
||||
memcpy(&lowerByte, pBuff + offset + 1, 1);
|
||||
|
||||
return (upperByte << 8 | lowerByte);
|
||||
}
|
||||
|
||||
IPv4Packet::IPv4Packet(unsigned int size) :
|
||||
m_PacketSize(size) {
|
||||
}
|
||||
|
||||
IPv4Packet::~IPv4Packet(void) {
|
||||
if (0 != m_Packet) {
|
||||
delete[] m_Packet;
|
||||
m_Packet = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void IPv4Packet::ToNetworkByteStream(unsigned char *buffer) {
|
||||
if (0 == buffer) {
|
||||
LOG_MSG_ERROR("IPv4Packet::ToNetworkByteStream : NULL arguments");
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(buffer, m_Packet, GetSize());
|
||||
}
|
||||
|
||||
unsigned int IPv4Packet::GetSrcAddr(void) {
|
||||
return BigToLittleEndianUint32(m_Packet + 12);
|
||||
}
|
||||
|
||||
void IPv4Packet::SetSrcAddr(unsigned int addr) {
|
||||
LittleToBigEndianUint32(m_Packet + 12, addr);
|
||||
RecalculateChecksum();
|
||||
}
|
||||
|
||||
unsigned int IPv4Packet::GetDstAddr(void) {
|
||||
|
||||
return BigToLittleEndianUint32(m_Packet + 16);
|
||||
}
|
||||
|
||||
void IPv4Packet::SetDstAddr(unsigned int addr) {
|
||||
LittleToBigEndianUint32(m_Packet + 16, addr);
|
||||
RecalculateChecksum();
|
||||
}
|
||||
|
||||
unsigned char IPv4Packet::GetProtocol(void) {
|
||||
unsigned char retVal = 0;
|
||||
memcpy(&retVal, m_Packet + 9, sizeof(unsigned char));
|
||||
return retVal;
|
||||
}
|
||||
|
||||
unsigned short IPv4Packet::GetSrcPort(void) {
|
||||
return BigToLittleEndianUint16(m_Packet + 20);
|
||||
}
|
||||
|
||||
unsigned short IPv4Packet::GetDstPort(void) {
|
||||
return BigToLittleEndianUint16(m_Packet + 22);
|
||||
}
|
||||
|
||||
void IPv4Packet::SetDstPort(unsigned short port) {
|
||||
|
||||
LittleToBigEndianUint16(m_Packet + 22, port);
|
||||
RecalculateChecksum();
|
||||
}
|
||||
|
||||
void IPv4Packet::SetSrcPort(unsigned short port) {
|
||||
LittleToBigEndianUint16(m_Packet + 20, port);
|
||||
RecalculateChecksum();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//Set the third MSB bit of the IPV4_FLAGS_BYTE_OFFSET's byte
|
||||
void IPv4Packet::SetMF(bool bValue) {
|
||||
|
||||
Byte * pFlags = m_Packet + IPV4_FLAGS_BYTE_OFFSET;
|
||||
//clear the bit
|
||||
if (true == bValue) {
|
||||
*pFlags |= (0x20);
|
||||
} else {
|
||||
*pFlags &= (~0x20);
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void IPv4Packet::RecalculateChecksum(void) {
|
||||
RecalculateIPChecksum();
|
||||
RecalculateTCPChecksum();
|
||||
RecalculateUDPChecksum();
|
||||
}
|
||||
|
||||
void IPv4Packet::RecalculateIPChecksum(void) {
|
||||
unsigned short pUint16[100];
|
||||
int headerLen = (m_Packet[0] & 0x0F) * 2;
|
||||
int checksum = 0;
|
||||
unsigned short result = 0;
|
||||
|
||||
memset(&pUint16, 0, 100 * sizeof(unsigned short));
|
||||
|
||||
//clear the IP checksum field first
|
||||
memset(m_Packet + 10, 0, sizeof(unsigned short));
|
||||
|
||||
memcpy(&pUint16, m_Packet, headerLen * sizeof(unsigned short));
|
||||
|
||||
for (int i = 0; i < headerLen; i++) {
|
||||
checksum += pUint16[i];
|
||||
checksum = (checksum & 0xFFFF) + (checksum >> 16);
|
||||
}
|
||||
|
||||
result = (~checksum & 0xFFFF);
|
||||
|
||||
memcpy(m_Packet + 10, &result, sizeof(unsigned short));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void TCPPacket::RecalculateTCPChecksum(void) {
|
||||
unsigned short *pUint16 = new unsigned short[100];
|
||||
int checksum = 0;
|
||||
int headerLen = 0;
|
||||
unsigned short *pTemp = 0;
|
||||
unsigned short result = 0;
|
||||
|
||||
headerLen = Get2BBIGEndian(m_Packet, 2) - (m_Packet[0] & 0x0F) * 4;
|
||||
|
||||
memset(pUint16, 0, 100);
|
||||
|
||||
//clear the TCP checksum field first
|
||||
memset(m_Packet + 36, 0, sizeof(unsigned short));
|
||||
|
||||
memcpy(pUint16, m_Packet, headerLen * sizeof(unsigned short));
|
||||
|
||||
pTemp = pUint16;
|
||||
|
||||
// Pseudo Header
|
||||
pUint16 += 6; // Source IP
|
||||
for (int i = 0; i < 4; i++) {
|
||||
checksum += pUint16[i];
|
||||
checksum = (checksum & 0xFFFF) + (checksum >> 16);
|
||||
}
|
||||
|
||||
checksum += 0x0600; // TCP Protocol
|
||||
checksum += Get2BBIGEndian((unsigned char*) &headerLen, 0);
|
||||
|
||||
pUint16 = pTemp + (m_Packet[0] & 0x0F) * 2;
|
||||
headerLen /= 2;
|
||||
for (int i = 0; i < headerLen; i++) {
|
||||
checksum += pUint16[i];
|
||||
checksum = (checksum & 0xFFFF) + (checksum >> 16);
|
||||
}
|
||||
|
||||
result = (~checksum & 0xFFFF);
|
||||
|
||||
memcpy(m_Packet + 36, &result, sizeof(unsigned short));
|
||||
|
||||
delete[] pTemp;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void UDPPacket::RecalculateUDPChecksum(void) {
|
||||
unsigned short *pUint16 = new unsigned short[100];
|
||||
int checksum = 0;
|
||||
int headerLen = 0;
|
||||
unsigned short *pTemp = 0;
|
||||
unsigned short result = 0;
|
||||
|
||||
headerLen = Get2BBIGEndian(m_Packet, (m_Packet[0] & 0x0F) * 4 + 4);
|
||||
|
||||
memset(pUint16, 0, 100);
|
||||
|
||||
//clear the UDP checksum field first
|
||||
memset(m_Packet + 26, 0, sizeof(unsigned short));
|
||||
|
||||
memcpy(pUint16, m_Packet, headerLen * sizeof(unsigned short));
|
||||
|
||||
pTemp = pUint16;
|
||||
|
||||
// Pseudo Header
|
||||
pUint16 += 6; // Source IP
|
||||
for (int i = 0; i < 4; i++) {
|
||||
checksum += pUint16[i];
|
||||
checksum = (checksum & 0xFFFF) + (checksum >> 16);
|
||||
}
|
||||
|
||||
checksum += 0x1100; // UDP Protocol
|
||||
checksum += Get2BBIGEndian((unsigned char*) &headerLen, 0);
|
||||
|
||||
pUint16 = pTemp + (m_Packet[0] & 0x0F) * 2;
|
||||
headerLen /= 2;
|
||||
for (int i = 0; i < headerLen; i++) {
|
||||
checksum += pUint16[i];
|
||||
checksum = (checksum & 0xFFFF) + (checksum >> 16);
|
||||
}
|
||||
|
||||
result = (~checksum & 0xFFFF);
|
||||
|
||||
memcpy(m_Packet + 26, &result, sizeof(unsigned short));
|
||||
|
||||
delete[] pTemp;
|
||||
return;
|
||||
}
|
||||
|
||||
TCPPacket::TCPPacket(void) :
|
||||
IPv4Packet(sizeof(TCP_IP_PACKET_DUMP)) {
|
||||
size_t length = GetSize();
|
||||
|
||||
m_Packet = new unsigned char[length];
|
||||
if (0 == m_Packet) {
|
||||
LOG_MSG_ERROR("TCPPacket : packet allocation failed");
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(m_Packet, TCP_IP_PACKET_DUMP, length);
|
||||
}
|
||||
|
||||
UDPPacket::UDPPacket(void) :
|
||||
IPv4Packet(sizeof(UDP_IP_PACKET_DUMP)) {
|
||||
size_t length = GetSize();
|
||||
|
||||
m_Packet = new unsigned char[length];
|
||||
if (0 == m_Packet) {
|
||||
LOG_MSG_ERROR("UDPPacket : packet allocation failed");
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(m_Packet, UDP_IP_PACKET_DUMP, length);
|
||||
}
|
||||
|
||||
ICMPPacket::ICMPPacket(void) :
|
||||
IPv4Packet(sizeof(ICMP_IP_PACKET_DUMP)) {
|
||||
size_t length = GetSize();
|
||||
|
||||
m_Packet = new unsigned char[length];
|
||||
if (0 == m_Packet) {
|
||||
LOG_MSG_ERROR("ICMPPacket : packet allocation failed");
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(m_Packet, ICMP_IP_PACKET_DUMP, length);
|
||||
}
|
||||
|
||||
unsigned short ICMPPacket::GetSrcPort(void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned short ICMPPacket::GetDstPort(void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ICMPPacket::SetDstPort(unsigned short port) {
|
||||
(void) port;
|
||||
return;
|
||||
}
|
||||
|
||||
void ICMPPacket::SetSrcPort(unsigned short port) {
|
||||
(void) port;
|
||||
return;
|
||||
}
|
||||
215
qcom/opensource/dataipa/kernel-tests/IPv4Packet.h
Normal file
215
qcom/opensource/dataipa/kernel-tests/IPv4Packet.h
Normal file
@@ -0,0 +1,215 @@
|
||||
/*
|
||||
* Copyright (c) 2017 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* Changes from Qualcomm Innovation Center are provided under the following license:
|
||||
*
|
||||
* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted (subject to the limitations in the
|
||||
* disclaimer below) provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* * Neither the name of Qualcomm Innovation Center, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
|
||||
* GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
|
||||
* HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
|
||||
*/
|
||||
|
||||
#ifndef __IPA_TESTS_IPV4_PACKET__H__
|
||||
#define __IPA_TESTS_IPV4_PACKET__H__
|
||||
|
||||
namespace IPA
|
||||
{
|
||||
|
||||
#define IPV4_FLAGS_BYTE_OFFSET 6
|
||||
|
||||
/**
|
||||
@brief
|
||||
IPv4Packet abstract class.
|
||||
|
||||
@details
|
||||
new setters should call to RecalculateChecksum();
|
||||
*/
|
||||
class IPv4Packet
|
||||
{
|
||||
public:
|
||||
|
||||
IPv4Packet(unsigned int size);
|
||||
|
||||
virtual ~IPv4Packet(void);
|
||||
|
||||
void FromByteStream(unsigned char *buffer, unsigned int length);
|
||||
|
||||
void ToNetworkByteStream(unsigned char *addr);
|
||||
|
||||
unsigned int GetSrcAddr(void);
|
||||
|
||||
void SetSrcAddr(unsigned int addr);
|
||||
|
||||
unsigned int GetDstAddr(void);
|
||||
|
||||
void SetDstAddr(unsigned int addr);
|
||||
|
||||
unsigned char GetProtocol(void);
|
||||
|
||||
unsigned int GetSize(void)
|
||||
{
|
||||
return m_PacketSize;
|
||||
}
|
||||
|
||||
virtual unsigned short GetSrcPort(void);
|
||||
|
||||
virtual unsigned short GetDstPort(void);
|
||||
|
||||
virtual void SetDstPort(unsigned short port);
|
||||
|
||||
virtual void SetSrcPort(unsigned short port);
|
||||
|
||||
void SetMF(bool bValue);
|
||||
|
||||
protected:
|
||||
|
||||
virtual void RecalculateTCPChecksum(void) {}
|
||||
|
||||
virtual void RecalculateUDPChecksum(void) {}
|
||||
|
||||
virtual void RecalculateICMPChecksum(void) {}
|
||||
|
||||
unsigned char *m_Packet;
|
||||
|
||||
private:
|
||||
|
||||
unsigned int m_PacketSize;
|
||||
|
||||
void RecalculateChecksum(void);
|
||||
|
||||
void RecalculateIPChecksum(void);
|
||||
};
|
||||
|
||||
/**
|
||||
@brief
|
||||
TCPPacket implementation.
|
||||
|
||||
@details
|
||||
new setters should call to RecalculateChecksum();
|
||||
*/
|
||||
class TCPPacket:public IPv4Packet
|
||||
{
|
||||
public:
|
||||
|
||||
TCPPacket(void);
|
||||
|
||||
virtual ~TCPPacket(void) {}
|
||||
|
||||
protected:
|
||||
|
||||
virtual void RecalculateTCPChecksum(void);
|
||||
};
|
||||
|
||||
/**
|
||||
@brief
|
||||
UDPPacket implementation.
|
||||
|
||||
@details
|
||||
new setters should call to RecalculateChecksum();
|
||||
*/
|
||||
class UDPPacket:public IPv4Packet
|
||||
{
|
||||
public:
|
||||
UDPPacket(void);
|
||||
|
||||
virtual ~UDPPacket(void) {}
|
||||
|
||||
protected:
|
||||
|
||||
virtual void RecalculateUDPChecksum(void);
|
||||
};
|
||||
|
||||
/**
|
||||
@brief
|
||||
ICMPPacket implementation.
|
||||
|
||||
@details
|
||||
new setters should call to RecalculateChecksum();
|
||||
*/
|
||||
class ICMPPacket:public IPv4Packet
|
||||
{
|
||||
public:
|
||||
ICMPPacket(void);
|
||||
|
||||
virtual ~ICMPPacket(void) {}
|
||||
|
||||
virtual unsigned short GetSrcPort(void);
|
||||
|
||||
virtual unsigned short GetDstPort(void);
|
||||
|
||||
virtual void SetDstPort(unsigned short port);
|
||||
|
||||
virtual void SetSrcPort(unsigned short port);
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
@brief
|
||||
RecalculateICMPChecksum method.
|
||||
|
||||
@details
|
||||
ICMP checksum recalculation is not needed now
|
||||
and by so is not implemented yet
|
||||
TODO: implement if needed
|
||||
*/
|
||||
virtual void RecalculateICMPChecksum(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
} /* namespace IPA */
|
||||
|
||||
#endif
|
||||
2439
qcom/opensource/dataipa/kernel-tests/IPv6CTTest.cpp
Normal file
2439
qcom/opensource/dataipa/kernel-tests/IPv6CTTest.cpp
Normal file
File diff suppressed because it is too large
Load Diff
183
qcom/opensource/dataipa/kernel-tests/InterfaceAbstraction.cpp
Normal file
183
qcom/opensource/dataipa/kernel-tests/InterfaceAbstraction.cpp
Normal file
@@ -0,0 +1,183 @@
|
||||
/*
|
||||
* Copyright (c) 2017 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <iostream>
|
||||
#include "InterfaceAbstraction.h"
|
||||
|
||||
#define MAX_OPEN_RETRY 10000
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
bool InterfaceAbstraction::Open(const char * toIPAPath, const char * fromIPAPath)
|
||||
{
|
||||
int tries_cnt = MAX_OPEN_RETRY;
|
||||
if (NULL == toIPAPath && NULL == fromIPAPath)
|
||||
{
|
||||
printf("InterfaceAbstraction constructor got 2 null arguments.\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (NULL != toIPAPath) {
|
||||
while (tries_cnt > 0) {
|
||||
printf("trying to open %s %d/%d\n", toIPAPath, MAX_OPEN_RETRY - tries_cnt, MAX_OPEN_RETRY);
|
||||
// Sleep for 5 msec
|
||||
usleep(5000);
|
||||
m_toIPADescriptor = open(toIPAPath, O_WRONLY);
|
||||
if (-1 != m_toIPADescriptor) {
|
||||
printf("Success!\n");
|
||||
break;
|
||||
}
|
||||
tries_cnt--;
|
||||
}
|
||||
printf("open retries_cnt=%d\n", MAX_OPEN_RETRY - tries_cnt);
|
||||
if (-1 == m_toIPADescriptor) {
|
||||
printf("InterfaceAbstraction failed while opening %s.\n", toIPAPath);
|
||||
exit(0);
|
||||
}
|
||||
m_toChannelName = toIPAPath;
|
||||
printf("%s device node opened, fd = %d.\n", toIPAPath, m_toIPADescriptor);
|
||||
}
|
||||
tries_cnt = MAX_OPEN_RETRY;
|
||||
if (NULL != fromIPAPath) {
|
||||
while (tries_cnt > 0) {
|
||||
printf("trying to open %s %d/%d\n", fromIPAPath, MAX_OPEN_RETRY - tries_cnt, MAX_OPEN_RETRY);
|
||||
// Sleep for 5 msec
|
||||
usleep(5000);
|
||||
m_fromIPADescriptor = open(fromIPAPath, O_RDONLY);
|
||||
if (-1 != m_fromIPADescriptor) {
|
||||
printf("Success!\n");
|
||||
break;
|
||||
}
|
||||
tries_cnt--;
|
||||
}
|
||||
printf("open retries_cnt=%d\n", MAX_OPEN_RETRY - tries_cnt);
|
||||
if (-1 == m_fromIPADescriptor)
|
||||
{
|
||||
printf("InterfaceAbstraction failed on opening %s.\n", fromIPAPath);
|
||||
exit(0);
|
||||
}
|
||||
m_fromChannelName = fromIPAPath;
|
||||
printf("%s device node opened, fd = %d.\n", fromIPAPath, m_fromIPADescriptor);
|
||||
}
|
||||
|
||||
return true;
|
||||
}/*Ctor*/
|
||||
|
||||
void InterfaceAbstraction::Close()
|
||||
{
|
||||
close(m_toIPADescriptor);
|
||||
close(m_fromIPADescriptor);
|
||||
}
|
||||
|
||||
long InterfaceAbstraction::SendData(unsigned char *buf, size_t size)
|
||||
{
|
||||
long bytesWritten = 0;
|
||||
|
||||
printf("Trying to write %zu bytes to %d.\n", size, m_toIPADescriptor);
|
||||
|
||||
bytesWritten = write(m_toIPADescriptor, buf, size);
|
||||
if (-1 == bytesWritten)
|
||||
{
|
||||
int err = errno;
|
||||
printf(
|
||||
"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");
|
||||
printf(
|
||||
"Failed to execute command\n write(m_toIPADescriptor, buf, size);\n "
|
||||
"m_toIPADescriptor=%d, buf=0x%p, size=%zu",m_toIPADescriptor,
|
||||
buf,
|
||||
size);
|
||||
printf("Error on write execution, errno=%d, Quitting!\n", err);
|
||||
printf(
|
||||
"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
cout << "bytesWritten = " << bytesWritten << endl;
|
||||
|
||||
return bytesWritten;
|
||||
}
|
||||
|
||||
int InterfaceAbstraction::ReceiveData(unsigned char *buf, size_t size)
|
||||
{
|
||||
size_t bytesRead = 0;
|
||||
size_t totalBytesRead = 0;
|
||||
bool continueRead = false;
|
||||
|
||||
do
|
||||
{
|
||||
printf("Trying to read %zu bytes from %d.\n", size, m_fromIPADescriptor);
|
||||
|
||||
bytesRead = read(m_fromIPADescriptor, (void*)buf, size);
|
||||
printf("Read %zu bytes.\n", bytesRead);
|
||||
totalBytesRead += bytesRead;
|
||||
if (bytesRead == size)
|
||||
continueRead = true;
|
||||
else
|
||||
continueRead = false;
|
||||
} while (continueRead);
|
||||
|
||||
return totalBytesRead;
|
||||
}
|
||||
|
||||
int InterfaceAbstraction::ReceiveSingleDataChunk(unsigned char *buf, size_t size){
|
||||
size_t bytesRead = 0;
|
||||
printf("Trying to read %zu bytes from %d.\n", size, m_fromIPADescriptor);
|
||||
bytesRead = read(m_fromIPADescriptor, (void*)buf, size);
|
||||
printf("Read %zu bytes.\n", bytesRead);
|
||||
return bytesRead;
|
||||
}
|
||||
|
||||
int InterfaceAbstraction::setReadNoBlock(){
|
||||
int flags = fcntl(m_fromIPADescriptor, F_GETFL, 0);
|
||||
if(flags == -1){
|
||||
return -1;
|
||||
}
|
||||
return fcntl(m_fromIPADescriptor, F_SETFL, flags | O_NONBLOCK);
|
||||
}
|
||||
|
||||
int InterfaceAbstraction::clearReadNoBlock(){
|
||||
int flags = fcntl(m_fromIPADescriptor, F_GETFL, 0);
|
||||
if(flags == -1){
|
||||
return -1;
|
||||
}
|
||||
return fcntl(m_fromIPADescriptor, F_SETFL, flags & ~O_NONBLOCK);
|
||||
}
|
||||
|
||||
InterfaceAbstraction::~InterfaceAbstraction()
|
||||
{
|
||||
close(m_fromIPADescriptor);
|
||||
m_fromChannelName = "";
|
||||
|
||||
close(m_toIPADescriptor);
|
||||
m_toChannelName = "";
|
||||
}
|
||||
62
qcom/opensource/dataipa/kernel-tests/InterfaceAbstraction.h
Normal file
62
qcom/opensource/dataipa/kernel-tests/InterfaceAbstraction.h
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 2017 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef INTERFACE_ABSTRACTION_H_
|
||||
#define INTERFACE_ABSTRACTION_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string>
|
||||
|
||||
typedef unsigned char Byte;
|
||||
|
||||
using namespace std;
|
||||
|
||||
class InterfaceAbstraction
|
||||
{
|
||||
|
||||
public:
|
||||
~InterfaceAbstraction();
|
||||
bool Open(const char *toIPAPath, const char *fromIPAPath);
|
||||
void Close();
|
||||
long SendData(unsigned char *buffer, size_t size);
|
||||
int ReceiveData(unsigned char *buf, size_t size);
|
||||
int ReceiveSingleDataChunk(unsigned char *buf, size_t size);
|
||||
int setReadNoBlock();
|
||||
int clearReadNoBlock();
|
||||
|
||||
string m_toChannelName;
|
||||
string m_fromChannelName;
|
||||
|
||||
private:
|
||||
int m_toIPADescriptor;
|
||||
int m_fromIPADescriptor;
|
||||
};
|
||||
|
||||
#endif
|
||||
59
qcom/opensource/dataipa/kernel-tests/Logger.cpp
Normal file
59
qcom/opensource/dataipa/kernel-tests/Logger.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 2017 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "Logger.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//The trace level of the system will be used to choose the system printing level
|
||||
Logger::Logger(TraceLevel nTraceLevel)
|
||||
{
|
||||
m_nTraceLevelToPresent = nTraceLevel;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//This method will be use to print messages. it will also gie a trace level for each message.
|
||||
void Logger::AddMessage(TraceLevel nTraceLevel, const char *format, ...)
|
||||
{
|
||||
|
||||
//in case the trace level is not "high" no print should be made.
|
||||
if (nTraceLevel < m_nTraceLevelToPresent)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
vprintf(format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
60
qcom/opensource/dataipa/kernel-tests/Logger.h
Normal file
60
qcom/opensource/dataipa/kernel-tests/Logger.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) 2017 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef LOGGER_H_
|
||||
#define LOGGER_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
typedef enum{
|
||||
LOG_DEVELOPMENT = 0,
|
||||
LOG_ERROR = 0,
|
||||
LOG_VERBOSE = 1
|
||||
} TraceLevel;
|
||||
|
||||
/*This class will controll all the printing in the test application
|
||||
*In each test there will be many printing while each
|
||||
*specific print will define it's "importancy"(TraceLevel)
|
||||
*During the development of the test it is
|
||||
*strongly suggested to use LOG_DEVELOPMENT.
|
||||
*/
|
||||
|
||||
class Logger
|
||||
{
|
||||
public:
|
||||
Logger(TraceLevel nTraceLevelToPresent);
|
||||
void AddMessage(TraceLevel nTraceLevel, const char *format, ...);
|
||||
private:
|
||||
int m_nTraceLevelToPresent;
|
||||
};
|
||||
|
||||
#endif /* LOGGER_H_ */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Copyright (c) 2017,2020 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "Constants.h"
|
||||
#include "Logger.h"
|
||||
#include "linux/msm_ipa.h"
|
||||
#include "TestsUtils.h"
|
||||
#include "TestBase.h"
|
||||
#include "Pipe.h"
|
||||
#include "RoutingDriverWrapper.h"
|
||||
#include "HeaderInsertion.h"
|
||||
#include "Filtering.h"
|
||||
#include "IPAFilteringTable.h"
|
||||
|
||||
|
||||
#define NUM_PACKETS 5
|
||||
#define NUM_PACKETS_FC 4
|
||||
#define MAX_PACKET_SIZE 1024
|
||||
#define MAX_PACKETS_IN_MBIM_TESTS 10
|
||||
#define MAX_PACKETS_IN_NDP 8
|
||||
#define MAX_NDPS_IN_PACKET 8
|
||||
|
||||
/*This class will be the base class of MBIM Aggregation tests.
|
||||
*Any method other than the test case itself
|
||||
*can be declared in this Fixture thus allowing the derived classes to
|
||||
*implement only the test case.
|
||||
*All the test of the Aggregation uses one input and one output in DMA mode.
|
||||
*/
|
||||
class MBIMAggregationTestFixtureConf11:public TestBase
|
||||
{
|
||||
public:
|
||||
/*This Constructor will register each instance that it creates.*/
|
||||
MBIMAggregationTestFixtureConf11(bool generic_agg);
|
||||
|
||||
virtual int SetupKernelModule();
|
||||
|
||||
/*This method will create and initialize two Pipe object
|
||||
*for the USB (Ethernet) Pipes, one
|
||||
*for as input and the other as output.
|
||||
*/
|
||||
virtual bool Setup();
|
||||
|
||||
/*This method will destroy the pipes.*/
|
||||
virtual bool Teardown();
|
||||
|
||||
virtual bool Run();
|
||||
|
||||
virtual bool AddRules() = 0;
|
||||
|
||||
virtual bool TestLogic() = 0;
|
||||
|
||||
bool AddRules1HeaderAggregation();
|
||||
|
||||
bool AddRules1HeaderAggregation(bool bAggForceClose);
|
||||
|
||||
bool AddRulesDeaggregation();
|
||||
|
||||
bool AddRules1HeaderAggregationTime();
|
||||
|
||||
bool AddRules1HeaderAggregation0Limits();
|
||||
|
||||
bool AddRulesAggDualFC(Pipe *input, Pipe *output1, Pipe *output2);
|
||||
|
||||
bool AddRulesAggDualFcRoutingBased(Pipe *input, Pipe *output1, Pipe *output2);
|
||||
|
||||
/*The client type are set from the
|
||||
* peripheral perspective
|
||||
*/
|
||||
static Pipe m_IpaToUsbPipeAgg;
|
||||
static Pipe m_UsbToIpaPipe;
|
||||
static Pipe m_IpaToUsbPipe;
|
||||
static Pipe m_UsbToIpaPipeDeagg;
|
||||
static Pipe m_IpaToUsbPipeAggTime;
|
||||
static Pipe m_IpaToUsbPipeAgg0Limits;
|
||||
|
||||
static RoutingDriverWrapper m_Routing;
|
||||
static Filtering m_Filtering;
|
||||
static HeaderInsertion m_HeaderInsertion;
|
||||
|
||||
protected:
|
||||
enum ipa_ip_type m_eIP;
|
||||
bool mGenericAgg;
|
||||
};
|
||||
3366
qcom/opensource/dataipa/kernel-tests/MBIMAggregationTests.cpp
Normal file
3366
qcom/opensource/dataipa/kernel-tests/MBIMAggregationTests.cpp
Normal file
File diff suppressed because it is too large
Load Diff
53
qcom/opensource/dataipa/kernel-tests/Makefile.am
Normal file
53
qcom/opensource/dataipa/kernel-tests/Makefile.am
Normal file
@@ -0,0 +1,53 @@
|
||||
ACLOCAL_AMFLAGS = -Im4
|
||||
EXTRA_CFLAGS = -DDEBUG
|
||||
AM_CXXFLAGS = -Wall -Wundef -Wno-trigraphs -Werror -std=c++14
|
||||
|
||||
if USE_GLIB
|
||||
ipa_kernel_tests_CPPFLAGS = $(AM_CFLAGS) -DUSE_GLIB -Dstrlcpy=g_strlcpy @GLIB_CFLAGS@
|
||||
ipa_kernel_tests_LDFLAGS = -lpthread @GLIB_LIBS@
|
||||
endif
|
||||
|
||||
requiredlibs = -lipanat
|
||||
ipa_kernel_tests_LDADD = $(requiredlibs)
|
||||
|
||||
ipa_kernel_testsdir = $(prefix)
|
||||
ipa_kernel_tests_PROGRAMS = ipa_kernel_tests
|
||||
dist_ipa_kernel_tests_SCRIPTS = run.sh
|
||||
ipa_kernel_tests_SOURCES =\
|
||||
TestManager.cpp \
|
||||
TestBase.cpp \
|
||||
InterfaceAbstraction.cpp \
|
||||
Pipe.cpp \
|
||||
PipeTestFixture.cpp \
|
||||
PipeTests.cpp \
|
||||
TLPAggregationTestFixture.cpp \
|
||||
TLPAggregationTests.cpp \
|
||||
MBIMAggregationTestFixtureConf11.cpp \
|
||||
MBIMAggregationTests.cpp \
|
||||
Logger.cpp \
|
||||
RoutingDriverWrapper.cpp \
|
||||
RoutingTests.cpp \
|
||||
IPAFilteringTable.cpp \
|
||||
Filtering.cpp \
|
||||
FilteringTest.cpp \
|
||||
HeaderInsertion.cpp \
|
||||
HeaderInsertionTests.cpp \
|
||||
TestsUtils.cpp \
|
||||
HeaderRemovalTestFixture.cpp \
|
||||
HeaderRemovalTests.cpp \
|
||||
IPv4Packet.cpp \
|
||||
RNDISAggregationTestFixture.cpp \
|
||||
RNDISAggregationTests.cpp \
|
||||
DataPathTestFixture.cpp \
|
||||
DataPathTests.cpp \
|
||||
IPAInterruptsTestFixture.cpp \
|
||||
IPAInterruptsTests.cpp \
|
||||
HeaderProcessingContextTestFixture.cpp \
|
||||
HeaderProcessingContextTests.cpp \
|
||||
FilteringEthernetBridgingTestFixture.cpp \
|
||||
FilteringEthernetBridgingTests.cpp \
|
||||
NatTest.cpp \
|
||||
IPv6CTTest.cpp \
|
||||
UlsoTest.cpp \
|
||||
Feature.cpp \
|
||||
main.cpp
|
||||
26
qcom/opensource/dataipa/kernel-tests/NOTICE
Normal file
26
qcom/opensource/dataipa/kernel-tests/NOTICE
Normal file
@@ -0,0 +1,26 @@
|
||||
Copyright (c) 2021 The Linux Foundation. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following
|
||||
disclaimer in the documentation and/or other materials provided
|
||||
with the distribution.
|
||||
* Neither the name of The Linux Foundation nor the names of its
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
5154
qcom/opensource/dataipa/kernel-tests/NatTest.cpp
Normal file
5154
qcom/opensource/dataipa/kernel-tests/NatTest.cpp
Normal file
File diff suppressed because it is too large
Load Diff
729
qcom/opensource/dataipa/kernel-tests/Pipe.cpp
Normal file
729
qcom/opensource/dataipa/kernel-tests/Pipe.cpp
Normal file
@@ -0,0 +1,729 @@
|
||||
/*
|
||||
* Copyright (c) 2017-2018,2020 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "Pipe.h"
|
||||
#include "TestsUtils.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//Do not change those default values due to the fact that some test may relay on those default values.
|
||||
//In case you need a change of the field do this in a derived class.
|
||||
|
||||
//Dest MAC(6 bytes) Src MAC(6 Bytes) EtherType(2 Bytes)
|
||||
unsigned char Pipe::m_pUsbHeader[] = { 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xB1, 0xB2,
|
||||
0xB3, 0xB4, 0xB5, 0xB6, 0xC1, 0xC2 };
|
||||
unsigned char Pipe::m_pA2NDUNHeader[] =
|
||||
{ 0xA1, 0xA2, 0xA3, 0xA4, 0xB1, 0xB2, 0xC1, 0xC2 };
|
||||
//unsigned char Pipe::m_pA2DUNHeader[] = {};
|
||||
//unsigned char Pipe::m_pQ6LANHeader[] = {};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Pipe::Pipe(enum ipa_client_type nClientType,
|
||||
IPATestConfiguration eConfiguration) :
|
||||
m_Fd(-1), m_nHeaderLengthRemove(0),
|
||||
m_nHeaderLengthAdd(0), m_pHeader(NULL), m_pInodePath(NULL),
|
||||
m_bInitialized(false), m_ExceptionPipe(false) {
|
||||
m_nClientType = nClientType;
|
||||
m_eConfiguration = eConfiguration;
|
||||
}
|
||||
|
||||
Pipe::Pipe(IPATestConfiguration eConfiguration) :
|
||||
m_Fd(-1), m_nHeaderLengthRemove(0),
|
||||
m_nHeaderLengthAdd(0), m_pHeader(NULL), m_pInodePath(NULL),
|
||||
m_bInitialized(false), m_ExceptionPipe(true) {
|
||||
m_eConfiguration = eConfiguration;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Pipe::~Pipe() {
|
||||
//Nothing to be done at this point...
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool Pipe::Init() {
|
||||
int tries_cnt = 1;
|
||||
SetSpecificClientParameters(m_nClientType, m_eConfiguration);
|
||||
//By examining the Client type we will map the inode device name
|
||||
while (tries_cnt <= 10000) {
|
||||
m_Fd = open(m_pInodePath, O_RDWR);
|
||||
if (-1 != m_Fd)
|
||||
break;
|
||||
|
||||
// Sleep for 5 msec
|
||||
usleep(5000);
|
||||
++tries_cnt;
|
||||
}
|
||||
LOG_MSG_DEBUG("open retries_cnt=%d\n", tries_cnt);
|
||||
if (-1 == m_Fd) {
|
||||
LOG_MSG_ERROR("Failed to open %s", m_pInodePath);
|
||||
return false;
|
||||
}
|
||||
m_bInitialized = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Pipe::Destroy() {
|
||||
if (false == m_bInitialized) {
|
||||
LOG_MSG_ERROR("Pipe is being used without being initialized!");
|
||||
return;
|
||||
}
|
||||
close(m_Fd);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int Pipe::Send(unsigned char * pBuffer, size_t nBytesToSend) {
|
||||
if (false == m_bInitialized) {
|
||||
LOG_MSG_ERROR("Pipe is being used without being initialized!");
|
||||
return 0;
|
||||
}
|
||||
size_t nBytesWritten = 0;
|
||||
nBytesWritten = write(m_Fd, pBuffer, nBytesToSend);
|
||||
return nBytesWritten;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int Pipe::AddHeaderAndSend(unsigned char * pIpPacket, size_t nIpPacketSize) {
|
||||
int retval;
|
||||
|
||||
if (false == m_bInitialized) {
|
||||
LOG_MSG_ERROR("Pipe is being used without being initialized!");
|
||||
return 0;
|
||||
}
|
||||
size_t nBytesToWrite = nIpPacketSize + m_nHeaderLengthAdd;
|
||||
//Allocate new buffer for the Header and IP packet:
|
||||
unsigned char *pLinkLayerAndIpPacket = new unsigned char[nBytesToWrite];
|
||||
if (!pLinkLayerAndIpPacket) {
|
||||
LOG_MSG_ERROR("Memory allocation failure.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
//put the header first:
|
||||
memcpy(pLinkLayerAndIpPacket, m_pHeader, m_nHeaderLengthAdd);
|
||||
//Then add the IP packet:
|
||||
memcpy(pLinkLayerAndIpPacket + m_nHeaderLengthAdd, pIpPacket,
|
||||
nIpPacketSize);
|
||||
//Call the Send method which will send the new created buffer(which contains the IP packet with the Header):
|
||||
retval = Send(pLinkLayerAndIpPacket, nBytesToWrite);
|
||||
delete[] pLinkLayerAndIpPacket;
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int Pipe::Receive(unsigned char *pBuffer, size_t nBytesToReceive) {
|
||||
if (false == m_bInitialized) {
|
||||
LOG_MSG_ERROR("Pipe is being used without being initialized!");
|
||||
return 0;
|
||||
}
|
||||
size_t nBytesRead = 0;
|
||||
nBytesRead = read(m_Fd, (void*) pBuffer, nBytesToReceive);
|
||||
return nBytesRead;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int Pipe::ReceiveAndRemoveHeader(unsigned char *pIpPacket, size_t nIpPacketSize) {
|
||||
if (false == m_bInitialized) {
|
||||
LOG_MSG_ERROR("Pipe is being used without being initialized!");
|
||||
return 0;
|
||||
}
|
||||
size_t nBytesToRead = nIpPacketSize + m_nHeaderLengthRemove;
|
||||
unsigned char *pPacket = new unsigned char[nBytesToRead];
|
||||
if (!pPacket) {
|
||||
LOG_MSG_ERROR("Memory allocation failure.");
|
||||
return 0;
|
||||
}
|
||||
size_t nReceivedBytes = Receive(pPacket, nBytesToRead);
|
||||
if (nReceivedBytes != nBytesToRead) {
|
||||
LOG_MSG_ERROR("Pipe was asked to receive an IP packet "
|
||||
"of size %d, however only %d bytes were read "
|
||||
"while the header size is %d",
|
||||
nIpPacketSize,
|
||||
nReceivedBytes,
|
||||
m_nHeaderLengthRemove);
|
||||
delete[] pPacket;
|
||||
return nReceivedBytes - m_nHeaderLengthRemove;
|
||||
}
|
||||
|
||||
memcpy(pIpPacket, pPacket + m_nHeaderLengthRemove, nIpPacketSize);
|
||||
delete[] pPacket;
|
||||
|
||||
return (nReceivedBytes - m_nHeaderLengthRemove);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
enum ipa_client_type Pipe::GetClientType() {
|
||||
if (false == m_bInitialized) {
|
||||
LOG_MSG_ERROR("Pipe is being used without being initialized!");
|
||||
return IPA_CLIENT_HSIC1_PROD;
|
||||
}
|
||||
return m_nClientType;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Pipe::SetSpecificClientParameters(
|
||||
enum ipa_client_type nClientType,
|
||||
IPATestConfiguration eConfiguration) {
|
||||
switch (eConfiguration) {
|
||||
case IPA_TEST_CONFIFURATION_0:
|
||||
break;
|
||||
case IPA_TEST_CONFIFURATION_1:
|
||||
switch (nClientType) {
|
||||
case (IPA_CLIENT_TEST_PROD):
|
||||
m_pInodePath = CONFIG_1_FROM_USB1_TO_IPA_DMA;
|
||||
m_nHeaderLengthAdd = sizeof(m_pUsbHeader);
|
||||
m_nHeaderLengthRemove = sizeof(m_pUsbHeader);
|
||||
m_pHeader = m_pUsbHeader;
|
||||
LOG_MSG_INFO("Setting parameters for IPA_CLIENT_TEST_PROD ");
|
||||
break;
|
||||
case (IPA_CLIENT_TEST_CONS):
|
||||
m_pInodePath = CONFIG_1_FROM_IPA_TO_USB1_DMA;
|
||||
m_nHeaderLengthAdd = sizeof(m_pUsbHeader);
|
||||
m_nHeaderLengthRemove = sizeof(m_pUsbHeader);
|
||||
m_pHeader = m_pUsbHeader;
|
||||
LOG_MSG_INFO("Setting parameters for IPA_CLIENT_TEST_CONS");
|
||||
break;
|
||||
default:
|
||||
LOG_MSG_ERROR("IPA_TEST_CONFIFURATION_1 switch in default "
|
||||
"nClientType = %d is not supported ", nClientType);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case IPA_TEST_CONFIFURATION_2:
|
||||
switch (nClientType) {
|
||||
case (IPA_CLIENT_TEST_PROD):
|
||||
m_pInodePath = CONFIG_2_FROM_USB_TO_IPA;
|
||||
m_nHeaderLengthAdd = sizeof(m_pUsbHeader);
|
||||
m_nHeaderLengthRemove = sizeof(m_pUsbHeader);
|
||||
m_pHeader = m_pUsbHeader;
|
||||
LOG_MSG_INFO("Setting parameters for IPA_CLIENT_TEST_PROD");
|
||||
break;
|
||||
case (IPA_CLIENT_TEST2_CONS):
|
||||
m_pInodePath = CONFIG_2_FROM_IPA_TO_A2_NDUN;
|
||||
m_nHeaderLengthAdd = sizeof(m_pA2NDUNHeader);
|
||||
m_nHeaderLengthRemove = sizeof(m_pA2NDUNHeader);
|
||||
m_pHeader = m_pA2NDUNHeader;
|
||||
LOG_MSG_INFO("Setting parameters for IPA_CLIENT_TEST2_CONS");
|
||||
break;
|
||||
default:
|
||||
LOG_MSG_ERROR("IPA_TEST_CONFIFURATION_2 switch in default "
|
||||
"nClientType = %d is not supported ", nClientType);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case IPA_TEST_CONFIFURATION_3:
|
||||
switch (nClientType) {
|
||||
case IPA_CLIENT_TEST2_PROD:
|
||||
m_pInodePath = CONFIG_3_FROM_A2_NDUN_TO_IPA;
|
||||
m_nHeaderLengthAdd = sizeof(m_pA2NDUNHeader);
|
||||
m_nHeaderLengthRemove = sizeof(m_pA2NDUNHeader);
|
||||
m_pHeader = m_pA2NDUNHeader;
|
||||
LOG_MSG_INFO("Setting parameters for IPA_CLIENT_TEST2_PROD");
|
||||
break;
|
||||
case IPA_CLIENT_TEST_CONS:
|
||||
m_pInodePath = CONFIG_3_FROM_IPA_TO_USB1;
|
||||
m_nHeaderLengthAdd = sizeof(m_pUsbHeader);
|
||||
m_nHeaderLengthRemove = sizeof(m_pUsbHeader);
|
||||
m_pHeader = m_pUsbHeader;
|
||||
LOG_MSG_INFO("Setting parameters for IPA_CLIENT_TEST_CONS");
|
||||
break;
|
||||
case IPA_CLIENT_TEST2_CONS:
|
||||
m_pInodePath = CONFIG_3_FROM_IPA_TO_A2_NDUN;
|
||||
m_nHeaderLengthAdd = sizeof(m_pA2NDUNHeader);
|
||||
m_nHeaderLengthRemove = sizeof(m_pA2NDUNHeader);
|
||||
m_pHeader = m_pA2NDUNHeader;
|
||||
LOG_MSG_INFO("Setting parameters for IPA_CLIENT_TEST2_CONS");
|
||||
break;
|
||||
case IPA_CLIENT_TEST4_CONS:
|
||||
//TODO add when applicable
|
||||
m_pInodePath = CONFIG_3_FROM_IPA_TO_Q6_LAN;
|
||||
m_nHeaderLengthAdd = 0;
|
||||
m_nHeaderLengthRemove = 0;
|
||||
m_pHeader = 0;
|
||||
LOG_MSG_INFO("IPA_CLIENT_TEST4_CONS is not supported yet");
|
||||
break;
|
||||
default:
|
||||
LOG_MSG_INFO("IPA_TEST_CONFIFURATION_3 switch in default "
|
||||
"nClientType = %d is not supported ", nClientType);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case IPA_TEST_CONFIFURATION_7:
|
||||
if (m_ExceptionPipe) {
|
||||
m_pInodePath = CONFIG_7_FROM_IPA_TO_A5_EXCEPTION;
|
||||
m_nHeaderLengthAdd = 0; //No send
|
||||
m_nHeaderLengthRemove = 8; //A5Mux header size without retained source header
|
||||
m_pHeader = NULL; //No header to send
|
||||
LOG_MSG_INFO("Setting parameters for A5_Exception ");
|
||||
break;
|
||||
}
|
||||
|
||||
if (nClientType == IPA_CLIENT_TEST_PROD) {
|
||||
m_pInodePath = CONFIG_7_FROM_USB1_TO_IPA;
|
||||
m_nHeaderLengthAdd = 0;
|
||||
m_nHeaderLengthRemove = 0;
|
||||
m_pHeader = NULL;
|
||||
LOG_MSG_INFO(
|
||||
"Setting parameters for FROM_USB1_TO_IPA - no header addition/removal");
|
||||
} else {
|
||||
LOG_MSG_INFO("IPA_TEST_CONFIFURATION_7 switch in default "
|
||||
"nClientType = %d is not supported ", nClientType);
|
||||
}
|
||||
break;
|
||||
case IPA_TEST_CONFIGURATION_8:
|
||||
switch(nClientType)
|
||||
{
|
||||
case (IPA_CLIENT_TEST_PROD):
|
||||
m_pInodePath = CONFIG_8_DEAGG_TO_IPA_NO_AGG;
|
||||
m_nHeaderLengthAdd = sizeof(m_pUsbHeader);
|
||||
m_nHeaderLengthRemove = sizeof(m_pUsbHeader);
|
||||
m_pHeader = m_pUsbHeader;
|
||||
LOG_MSG_INFO("Setting parameters for IPA_CLIENT_TEST_PROD ");
|
||||
break;
|
||||
case (IPA_CLIENT_TEST_CONS):
|
||||
m_pInodePath = CONFIG_8_FROM_IPA_AGG;
|
||||
m_nHeaderLengthAdd = sizeof(m_pUsbHeader);
|
||||
m_nHeaderLengthRemove = sizeof(m_pUsbHeader);
|
||||
m_pHeader = m_pUsbHeader;
|
||||
LOG_MSG_INFO("Setting parameters for IPA_CLIENT_TEST_CONS");
|
||||
break;
|
||||
case (IPA_CLIENT_TEST3_PROD):
|
||||
m_pInodePath = CONFIG_8_NO_AGG_TO_IPA_AGG;
|
||||
m_nHeaderLengthAdd = sizeof(m_pUsbHeader);
|
||||
m_nHeaderLengthRemove = sizeof(m_pUsbHeader);
|
||||
m_pHeader = m_pUsbHeader;
|
||||
LOG_MSG_INFO("Setting parameters for IPA_CLIENT_TEST3_PROD ");
|
||||
break;
|
||||
case (IPA_CLIENT_TEST3_CONS):
|
||||
m_pInodePath = CONFIG_8_FROM_IPA_NO_AGG;
|
||||
m_nHeaderLengthAdd = sizeof(m_pUsbHeader);
|
||||
m_nHeaderLengthRemove = sizeof(m_pUsbHeader);
|
||||
m_pHeader = m_pUsbHeader;
|
||||
LOG_MSG_INFO("Setting parameters for IPA_CLIENT_TEST3_CONS");
|
||||
break;
|
||||
case (IPA_CLIENT_TEST2_PROD):
|
||||
m_pInodePath = CONFIG_8_DEAGG_TO_IPA_AGG;
|
||||
m_nHeaderLengthAdd = sizeof(m_pUsbHeader);
|
||||
m_nHeaderLengthRemove = sizeof(m_pUsbHeader);
|
||||
m_pHeader = m_pUsbHeader;
|
||||
LOG_MSG_INFO("Setting parameters for IPA_CLIENT_TEST2_PROD");
|
||||
break;
|
||||
case (IPA_CLIENT_TEST2_CONS):
|
||||
m_pInodePath = CONFIG_8_DEAGG_FROM_IPA_AGG;
|
||||
m_nHeaderLengthAdd = sizeof(m_pUsbHeader);
|
||||
m_nHeaderLengthRemove = sizeof(m_pUsbHeader);
|
||||
m_pHeader = m_pUsbHeader;
|
||||
LOG_MSG_INFO("Setting parameters for IPA_CLIENT_TEST2_CONS");
|
||||
break;
|
||||
case (IPA_CLIENT_TEST4_PROD):
|
||||
m_pInodePath = CONFIG_8_NO_AGG_TO_IPA_AGG_TIME;
|
||||
m_nHeaderLengthAdd = sizeof(m_pUsbHeader);
|
||||
m_nHeaderLengthRemove = sizeof(m_pUsbHeader);
|
||||
m_pHeader = m_pUsbHeader;
|
||||
LOG_MSG_INFO("Setting parameters for IPA_CLIENT_TEST4_PROD");
|
||||
break;
|
||||
default:
|
||||
LOG_MSG_ERROR("IPA_TEST_CONFIFURATION_8 switch in default "
|
||||
"nClientType = %d is not supported ",
|
||||
nClientType);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case IPA_TEST_CONFIGURATION_9:
|
||||
switch(nClientType)
|
||||
{
|
||||
case (IPA_CLIENT_TEST_PROD):
|
||||
m_pInodePath = CONFIG_9_DEAGG_TO_IPA_NO_AGG;
|
||||
m_nHeaderLengthAdd = sizeof(m_pUsbHeader);
|
||||
m_nHeaderLengthRemove = sizeof(m_pUsbHeader);
|
||||
m_pHeader = m_pUsbHeader;
|
||||
LOG_MSG_INFO("Setting parameters for IPA_CLIENT_TEST_PROD ");
|
||||
break;
|
||||
case (IPA_CLIENT_TEST_CONS):
|
||||
m_pInodePath = CONFIG_9_FROM_IPA_AGG;
|
||||
m_nHeaderLengthAdd = sizeof(m_pUsbHeader);
|
||||
m_nHeaderLengthRemove = sizeof(m_pUsbHeader);
|
||||
m_pHeader = m_pUsbHeader;
|
||||
LOG_MSG_INFO("Setting parameters for IPA_CLIENT_TEST_CONS");
|
||||
break;
|
||||
case (IPA_CLIENT_TEST3_PROD):
|
||||
m_pInodePath = CONFIG_9_NO_AGG_TO_IPA_AGG;
|
||||
m_nHeaderLengthAdd = sizeof(m_pUsbHeader);
|
||||
m_nHeaderLengthRemove = sizeof(m_pUsbHeader);
|
||||
m_pHeader = m_pUsbHeader;
|
||||
LOG_MSG_INFO("Setting parameters for IPA_CLIENT_TEST3_PROD ");
|
||||
break;
|
||||
case (IPA_CLIENT_TEST3_CONS):
|
||||
m_pInodePath = CONFIG_9_FROM_IPA_NO_AGG;
|
||||
m_nHeaderLengthAdd = sizeof(m_pUsbHeader);
|
||||
m_nHeaderLengthRemove = sizeof(m_pUsbHeader);
|
||||
m_pHeader = m_pUsbHeader;
|
||||
LOG_MSG_INFO("Setting parameters for IPA_CLIENT_TEST3_CONS");
|
||||
break;
|
||||
case (IPA_CLIENT_TEST2_PROD):
|
||||
m_pInodePath = CONFIG_9_DEAGG_TO_IPA_AGG;
|
||||
m_nHeaderLengthAdd = sizeof(m_pUsbHeader);
|
||||
m_nHeaderLengthRemove = sizeof(m_pUsbHeader);
|
||||
m_pHeader = m_pUsbHeader;
|
||||
LOG_MSG_INFO("Setting parameters for IPA_CLIENT_TEST2_PROD");
|
||||
break;
|
||||
case (IPA_CLIENT_TEST2_CONS):
|
||||
m_pInodePath = CONFIG_9_DEAGG_FROM_IPA_AGG;
|
||||
m_nHeaderLengthAdd = sizeof(m_pUsbHeader);
|
||||
m_nHeaderLengthRemove = sizeof(m_pUsbHeader);
|
||||
m_pHeader = m_pUsbHeader;
|
||||
LOG_MSG_INFO("Setting parameters for IPA_CLIENT_TEST2_CONS");
|
||||
break;
|
||||
case (IPA_CLIENT_TEST4_PROD):
|
||||
m_pInodePath = CONFIG_9_NO_AGG_TO_IPA_AGG_TIME;
|
||||
m_nHeaderLengthAdd = sizeof(m_pUsbHeader);
|
||||
m_nHeaderLengthRemove = sizeof(m_pUsbHeader);
|
||||
m_pHeader = m_pUsbHeader;
|
||||
LOG_MSG_INFO("Setting parameters for IPA_CLIENT_TEST4_PROD");
|
||||
break;
|
||||
default:
|
||||
LOG_MSG_ERROR("IPA_TEST_CONFIFURATION_9 switch in default "
|
||||
"nClientType = %d is not supported ",
|
||||
nClientType);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case IPA_TEST_CONFIGURATION_10:
|
||||
switch(nClientType)
|
||||
{
|
||||
case (IPA_CLIENT_TEST_PROD):
|
||||
m_pInodePath = CONFIG_10_TO_IPA_AGG_ZERO_LIMITS;
|
||||
m_nHeaderLengthAdd = sizeof(m_pUsbHeader);
|
||||
m_nHeaderLengthRemove = sizeof(m_pUsbHeader);
|
||||
m_pHeader = m_pUsbHeader;
|
||||
LOG_MSG_INFO("Setting parameters for IPA_CLIENT_TEST_PROD");
|
||||
break;
|
||||
case (IPA_CLIENT_TEST_CONS):
|
||||
m_pInodePath = CONFIG_10_FROM_IPA_AGG_ZERO_LIMITS;
|
||||
m_nHeaderLengthAdd = sizeof(m_pUsbHeader);
|
||||
m_nHeaderLengthRemove = sizeof(m_pUsbHeader);
|
||||
m_pHeader = m_pUsbHeader;
|
||||
LOG_MSG_INFO("Setting parameters for IPA_CLIENT_TEST_CONS");
|
||||
break;
|
||||
default:
|
||||
LOG_MSG_ERROR("IPA_TEST_CONFIFURATION_10 switch in default "
|
||||
"nClientType = %d is not supported ",
|
||||
nClientType);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case IPA_TEST_CONFIGURATION_11:
|
||||
switch(nClientType)
|
||||
{
|
||||
case (IPA_CLIENT_TEST_PROD):
|
||||
m_pInodePath = CONFIG_11_TO_IPA;
|
||||
m_nHeaderLengthAdd = sizeof(m_pUsbHeader);
|
||||
m_nHeaderLengthRemove = sizeof(m_pUsbHeader);
|
||||
m_pHeader = m_pUsbHeader;
|
||||
LOG_MSG_INFO("Setting parameters for IPA_CLIENT_TEST_PROD");
|
||||
break;
|
||||
case (IPA_CLIENT_TEST2_CONS):
|
||||
m_pInodePath = CONFIG_11_FROM_IPA_AGG;
|
||||
m_nHeaderLengthAdd = sizeof(m_pUsbHeader);
|
||||
m_nHeaderLengthRemove = sizeof(m_pUsbHeader);
|
||||
m_pHeader = m_pUsbHeader;
|
||||
LOG_MSG_INFO("Setting parameters for IPA_CLIENT_TEST2_CONS");
|
||||
break;
|
||||
case (IPA_CLIENT_TEST2_PROD):
|
||||
m_pInodePath = CONFIG_11_TO_IPA_DEAGG;
|
||||
m_nHeaderLengthAdd = sizeof(m_pUsbHeader);
|
||||
m_nHeaderLengthRemove = sizeof(m_pUsbHeader);
|
||||
m_pHeader = m_pUsbHeader;
|
||||
LOG_MSG_INFO("Setting parameters for IPA_CLIENT_TEST2_PROD");
|
||||
break;
|
||||
case (IPA_CLIENT_TEST3_CONS):
|
||||
m_pInodePath = CONFIG_11_FROM_IPA;
|
||||
m_nHeaderLengthAdd = sizeof(m_pUsbHeader);
|
||||
m_nHeaderLengthRemove = sizeof(m_pUsbHeader);
|
||||
m_pHeader = m_pUsbHeader;
|
||||
LOG_MSG_INFO("Setting parameters for IPA_CLIENT_TEST3_CONS");
|
||||
break;
|
||||
case (IPA_CLIENT_TEST_CONS):
|
||||
m_pInodePath = CONFIG_11_FROM_IPA_AGG_TIME;
|
||||
m_nHeaderLengthAdd = sizeof(m_pUsbHeader);
|
||||
m_nHeaderLengthRemove = sizeof(m_pUsbHeader);
|
||||
m_pHeader = m_pUsbHeader;
|
||||
LOG_MSG_INFO("Setting parameters for IPA_CLIENT_TEST_CONS");
|
||||
break;
|
||||
case (IPA_CLIENT_TEST4_CONS):
|
||||
m_pInodePath = CONFIG_11_FROM_IPA_ZERO_LIMITS;
|
||||
m_nHeaderLengthAdd = sizeof(m_pUsbHeader);
|
||||
m_nHeaderLengthRemove = sizeof(m_pUsbHeader);
|
||||
m_pHeader = m_pUsbHeader;
|
||||
LOG_MSG_INFO("Setting parameters for IPA_CLIENT_TEST4_CONS");
|
||||
break;
|
||||
default:
|
||||
LOG_MSG_ERROR("IPA_TEST_CONFIFURATION_11 switch in default "
|
||||
"nClientType = %d is not supported ",
|
||||
nClientType);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case IPA_TEST_CONFIGURATION_12:
|
||||
switch(nClientType)
|
||||
{
|
||||
case (IPA_CLIENT_TEST_PROD):
|
||||
m_pInodePath = CONFIG_12_TO_IPA;
|
||||
m_nHeaderLengthAdd = sizeof(m_pUsbHeader);
|
||||
m_nHeaderLengthRemove = sizeof(m_pUsbHeader);
|
||||
m_pHeader = m_pUsbHeader;
|
||||
LOG_MSG_INFO("Setting parameters for IPA_CLIENT_TEST_PROD");
|
||||
break;
|
||||
case (IPA_CLIENT_TEST2_CONS):
|
||||
m_pInodePath = CONFIG_12_FROM_IPA_AGG;
|
||||
m_nHeaderLengthAdd = sizeof(m_pUsbHeader);
|
||||
m_nHeaderLengthRemove = sizeof(m_pUsbHeader);
|
||||
m_pHeader = m_pUsbHeader;
|
||||
LOG_MSG_INFO("Setting parameters for IPA_CLIENT_TEST2_CONS");
|
||||
break;
|
||||
case (IPA_CLIENT_TEST2_PROD):
|
||||
m_pInodePath = CONFIG_12_TO_IPA_DEAGG;
|
||||
m_nHeaderLengthAdd = sizeof(m_pUsbHeader);
|
||||
m_nHeaderLengthRemove = sizeof(m_pUsbHeader);
|
||||
m_pHeader = m_pUsbHeader;
|
||||
LOG_MSG_INFO("Setting parameters for IPA_CLIENT_TEST2_PROD");
|
||||
break;
|
||||
case (IPA_CLIENT_TEST3_CONS):
|
||||
m_pInodePath = CONFIG_12_FROM_IPA;
|
||||
m_nHeaderLengthAdd = sizeof(m_pUsbHeader);
|
||||
m_nHeaderLengthRemove = sizeof(m_pUsbHeader);
|
||||
m_pHeader = m_pUsbHeader;
|
||||
LOG_MSG_INFO("Setting parameters for IPA_CLIENT_TEST3_CONS");
|
||||
break;
|
||||
case (IPA_CLIENT_TEST_CONS):
|
||||
m_pInodePath = CONFIG_12_FROM_IPA_AGG_TIME;
|
||||
m_nHeaderLengthAdd = sizeof(m_pUsbHeader);
|
||||
m_nHeaderLengthRemove = sizeof(m_pUsbHeader);
|
||||
m_pHeader = m_pUsbHeader;
|
||||
LOG_MSG_INFO("Setting parameters for IPA_CLIENT_TEST_CONS");
|
||||
break;
|
||||
case (IPA_CLIENT_TEST4_CONS):
|
||||
m_pInodePath = CONFIG_12_FROM_IPA_ZERO_LIMITS;
|
||||
m_nHeaderLengthAdd = sizeof(m_pUsbHeader);
|
||||
m_nHeaderLengthRemove = sizeof(m_pUsbHeader);
|
||||
m_pHeader = m_pUsbHeader;
|
||||
LOG_MSG_INFO("Setting parameters for IPA_CLIENT_TEST4_CONS");
|
||||
break;
|
||||
default:
|
||||
LOG_MSG_ERROR("IPA_TEST_CONFIFURATION_12 switch in default "
|
||||
"nClientType = %d is not supported ",
|
||||
nClientType);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case IPA_TEST_CONFIGURATION_17:
|
||||
switch(nClientType)
|
||||
{
|
||||
case (IPA_CLIENT_TEST_PROD):
|
||||
m_pInodePath = CONFIG_17_TO_IPA;
|
||||
m_nHeaderLengthAdd = sizeof(m_pUsbHeader);
|
||||
m_nHeaderLengthRemove = sizeof(m_pUsbHeader);
|
||||
m_pHeader = m_pUsbHeader;
|
||||
LOG_MSG_INFO("Setting parameters for IPA_CLIENT_TEST_PROD ");
|
||||
break;
|
||||
case (IPA_CLIENT_TEST3_PROD):
|
||||
m_pInodePath = CONFIG_17_TO_IPA_NO_HDR;
|
||||
m_nHeaderLengthAdd = sizeof(m_pUsbHeader);
|
||||
m_nHeaderLengthRemove = sizeof(m_pUsbHeader);
|
||||
m_pHeader = m_pUsbHeader;
|
||||
LOG_MSG_INFO("Setting parameters for IPA_CLIENT_TEST3_PROD ");
|
||||
break;
|
||||
case (IPA_CLIENT_TEST2_CONS):
|
||||
m_pInodePath = CONFIG_17_FROM_IPA_AGG;
|
||||
m_nHeaderLengthAdd = sizeof(m_pUsbHeader);
|
||||
m_nHeaderLengthRemove = sizeof(m_pUsbHeader);
|
||||
m_pHeader = m_pUsbHeader;
|
||||
LOG_MSG_INFO("Setting parameters for IPA_CLIENT_TEST2_CONS");
|
||||
break;
|
||||
case (IPA_CLIENT_TEST2_PROD):
|
||||
m_pInodePath = CONFIG_17_TO_IPA_DEAGG;
|
||||
m_nHeaderLengthAdd = sizeof(m_pUsbHeader);
|
||||
m_nHeaderLengthRemove = sizeof(m_pUsbHeader);
|
||||
m_pHeader = m_pUsbHeader;
|
||||
LOG_MSG_INFO("Setting parameters for IPA_CLIENT_TEST2_PROD ");
|
||||
break;
|
||||
case (IPA_CLIENT_TEST3_CONS):
|
||||
m_pInodePath = CONFIG_17_FROM_IPA;
|
||||
m_nHeaderLengthAdd = sizeof(m_pUsbHeader);
|
||||
m_nHeaderLengthRemove = sizeof(m_pUsbHeader);
|
||||
m_pHeader = m_pUsbHeader;
|
||||
LOG_MSG_INFO("Setting parameters for IPA_CLIENT_TEST3_CONS");
|
||||
break;
|
||||
case (IPA_CLIENT_TEST_CONS):
|
||||
m_pInodePath = CONFIG_17_FROM_IPA_AGG_TIME;
|
||||
m_nHeaderLengthAdd = sizeof(m_pUsbHeader);
|
||||
m_nHeaderLengthRemove = sizeof(m_pUsbHeader);
|
||||
m_pHeader = m_pUsbHeader;
|
||||
LOG_MSG_INFO("Setting parameters for IPA_CLIENT_TEST_CONS");
|
||||
break;
|
||||
case (IPA_CLIENT_TEST4_CONS):
|
||||
m_pInodePath = CONFIG_17_FROM_IPA_ZERO_LIMITS;
|
||||
m_nHeaderLengthAdd = sizeof(m_pUsbHeader);
|
||||
m_nHeaderLengthRemove = sizeof(m_pUsbHeader);
|
||||
m_pHeader = m_pUsbHeader;
|
||||
LOG_MSG_INFO("Setting parameters for IPA_CLIENT_TEST4_CONS");
|
||||
break;
|
||||
default:
|
||||
LOG_MSG_ERROR("IPA_TEST_CONFIFURATION_17 switch in default "
|
||||
"nClientType = %d is not supported ",
|
||||
nClientType);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case IPA_TEST_CONFIGURATION_18:
|
||||
switch (nClientType)
|
||||
{
|
||||
case (IPA_CLIENT_TEST_PROD):
|
||||
m_pInodePath = CONFIG_18_TO_IPA;
|
||||
m_nHeaderLengthAdd = sizeof(m_pUsbHeader);
|
||||
m_nHeaderLengthRemove = sizeof(m_pUsbHeader);
|
||||
m_pHeader = m_pUsbHeader;
|
||||
LOG_MSG_INFO("Setting parameters for IPA_CLIENT_TEST_PROD ");
|
||||
break;
|
||||
case (IPA_CLIENT_TEST2_PROD):
|
||||
m_pInodePath = CONFIG_18_DUMMY_ENDPOINT;
|
||||
m_nHeaderLengthAdd = sizeof(m_pUsbHeader);
|
||||
m_nHeaderLengthRemove = sizeof(m_pUsbHeader);
|
||||
m_pHeader = m_pUsbHeader;
|
||||
LOG_MSG_INFO("Setting parameters for IPA_CLIENT_TEST2_PROD ");
|
||||
break;
|
||||
case (IPA_CLIENT_TEST_CONS):
|
||||
m_pInodePath = CONFIG_18_FROM_IPA;
|
||||
m_nHeaderLengthAdd = sizeof(m_pUsbHeader);
|
||||
m_nHeaderLengthRemove = sizeof(m_pUsbHeader);
|
||||
m_pHeader = m_pUsbHeader;
|
||||
LOG_MSG_INFO("Setting parameters for IPA_CLIENT_TEST_CONS");
|
||||
break;
|
||||
default:
|
||||
LOG_MSG_ERROR(
|
||||
"IPA_TEST_CONFIFURATION_18 switch in default "
|
||||
"nClientType = %d is not supported ",
|
||||
nClientType);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case IPA_TEST_CONFIGURATION_19:
|
||||
switch (nClientType)
|
||||
{
|
||||
case (IPA_CLIENT_TEST_PROD):
|
||||
m_pInodePath = CONFIG_19_FROM_USB_TO_IPA_DMA;
|
||||
m_nHeaderLengthAdd = sizeof(m_pUsbHeader);
|
||||
m_nHeaderLengthRemove = sizeof(m_pUsbHeader);
|
||||
m_pHeader = m_pUsbHeader;
|
||||
LOG_MSG_INFO("Setting parameters for IPA_CLIENT_TEST_PROD ");
|
||||
break;
|
||||
case (IPA_CLIENT_TEST_CONS):
|
||||
m_pInodePath = CONFIG_19_FROM_IPA_TO_USB_DMA;
|
||||
m_nHeaderLengthAdd = sizeof(m_pUsbHeader);
|
||||
m_nHeaderLengthRemove = sizeof(m_pUsbHeader);
|
||||
m_pHeader = m_pUsbHeader;
|
||||
LOG_MSG_INFO("Setting parameters for TEST_CONS");
|
||||
break;
|
||||
default:
|
||||
LOG_MSG_ERROR("IPA_TEST_CONFIFURATION_19 switch in default "
|
||||
"nClientType = %d is not supported ", nClientType);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_MSG_ERROR("Pipe::SetSpecificClientParameters "
|
||||
"switch in default eConfiguration = %d ", eConfiguration);
|
||||
break;
|
||||
}
|
||||
}/* Pipe::SetSpecificClientParameters() */
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int Pipe::GetHeaderLengthAdd() {
|
||||
if (false == m_bInitialized) {
|
||||
LOG_MSG_ERROR("Pipe is being used without being initialized!");
|
||||
return 0;
|
||||
}
|
||||
return m_nHeaderLengthAdd;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int Pipe::GetHeaderLengthRemove() {
|
||||
if (false == m_bInitialized) {
|
||||
LOG_MSG_ERROR("Pipe is being used without being initialized!");
|
||||
return 0;
|
||||
}
|
||||
return m_nHeaderLengthRemove;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool Pipe::ConfigureHolb(unsigned short enable, unsigned timerValue) {
|
||||
if (false == m_bInitialized) {
|
||||
LOG_MSG_ERROR("Pipe is being used without being initialized!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (IPA_CLIENT_IS_PROD(m_nClientType)) {
|
||||
LOG_MSG_ERROR("Can't configure HOLB on a producer pipe!");
|
||||
return false;
|
||||
}
|
||||
|
||||
struct ipa_test_holb_config test_holb_config;
|
||||
|
||||
test_holb_config.client = m_nClientType;
|
||||
test_holb_config.tmr_val = timerValue;
|
||||
test_holb_config.en = enable;
|
||||
|
||||
LOG_MSG_DEBUG("Sending: client=%d tmr_val=%d en=%d",
|
||||
test_holb_config.client,
|
||||
test_holb_config.tmr_val,
|
||||
test_holb_config.en);
|
||||
|
||||
return configure_holb(&test_holb_config);
|
||||
}
|
||||
|
||||
bool Pipe::EnableHolb(unsigned timerValue) {
|
||||
return ConfigureHolb(1, timerValue);
|
||||
}
|
||||
|
||||
bool Pipe::DisableHolb() {
|
||||
return ConfigureHolb(0, 0);
|
||||
}
|
||||
|
||||
151
qcom/opensource/dataipa/kernel-tests/Pipe.h
Normal file
151
qcom/opensource/dataipa/kernel-tests/Pipe.h
Normal file
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
* Copyright (c) 2017,2020 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _PIPE_H_
|
||||
#define _PIPE_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include "linux/msm_ipa.h"
|
||||
#include "Constants.h"
|
||||
#include "Logger.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
/*This class will be used to interact with the system pipes
|
||||
*by only referring to Client type.
|
||||
*It will allow "raw" data transfer to/from the IPA and
|
||||
*will allow a encapsulation of the header addition/
|
||||
*removal of a packets thus allowing
|
||||
*the test to deal only with IP packet.
|
||||
*/
|
||||
class Pipe
|
||||
{
|
||||
|
||||
public:
|
||||
/* see Constants.h for nClientType / eConfiguration */
|
||||
Pipe(enum ipa_client_type nClientType,
|
||||
IPATestConfiguration eConfiguration);
|
||||
/* exception pipe Ctor */
|
||||
Pipe(IPATestConfiguration eConfiguration);
|
||||
~Pipe();
|
||||
|
||||
/*In this method the actual inode openning will occur.*/
|
||||
bool Init();
|
||||
|
||||
/*The close of the inode*/
|
||||
void Destroy();
|
||||
|
||||
/*Send the pBuffer(which is an ip[ packet)
|
||||
*after adding the header to the packet.*/
|
||||
int AddHeaderAndSend(
|
||||
unsigned char *pBuffer,
|
||||
size_t nIPPacketSize);
|
||||
|
||||
/*Send raw data as is - no header removal
|
||||
*- nBytesToSend bytes will be added*/
|
||||
int Send(
|
||||
unsigned char *pBuffer,
|
||||
size_t nBytesToSend);
|
||||
|
||||
/*Receive data from the IPA and remove its header*/
|
||||
int ReceiveAndRemoveHeader(
|
||||
unsigned char *pBuffer,
|
||||
size_t nIPPacketSize);
|
||||
|
||||
/*Receive data from the IPA as is*/
|
||||
int Receive(unsigned char *pBuffer, size_t nBytesToReceive);
|
||||
|
||||
/*return the Client type of this pipe.*/
|
||||
enum ipa_client_type GetClientType();
|
||||
|
||||
/*Return the length of the header to be added to an
|
||||
*IP packet before it is being sent to the pipe
|
||||
*(This length will be determine by the Pipe's ClientType).
|
||||
*/
|
||||
int GetHeaderLengthAdd();
|
||||
|
||||
/*Return the length of the header to be removed from a
|
||||
*packet before it is being sent to the user
|
||||
*(thus returning only the IP packet).
|
||||
*(This length will be determine by the Pipe's ClientType).
|
||||
*/
|
||||
int GetHeaderLengthRemove();
|
||||
|
||||
bool EnableHolb(unsigned timerValue);
|
||||
bool DisableHolb();
|
||||
|
||||
private:
|
||||
void SetSpecificClientParameters(
|
||||
enum ipa_client_type nClientType,
|
||||
IPATestConfiguration eConfiguration);
|
||||
|
||||
bool ConfigureHolb(unsigned short enable, unsigned timerValue);
|
||||
|
||||
public:
|
||||
/*efault Headers(Can be changed in Derived classes).*/
|
||||
static unsigned char m_pUsbHeader[];
|
||||
static unsigned char m_pHSICHeader[];
|
||||
static unsigned char m_pA2DUNHeader[];
|
||||
static unsigned char m_pA2NDUNHeader[];
|
||||
static unsigned char m_pQ6LANHeader[];
|
||||
|
||||
|
||||
private:
|
||||
int m_Fd;
|
||||
/*The file descriptor which will be used to transfer data
|
||||
* via the inode(this inode will be created by the ITAKEM)
|
||||
*/
|
||||
enum ipa_client_type m_nClientType;
|
||||
int m_nHeaderLengthRemove;
|
||||
/*this length will be set in the
|
||||
* constructor in corresponds to m_nClientType
|
||||
*/
|
||||
int m_nHeaderLengthAdd;
|
||||
/*this length will be set in the constructor
|
||||
* in corresponds to m_nClientType
|
||||
*/
|
||||
unsigned char *m_pHeader;
|
||||
/*this pointer will be set to the current pipe used*/
|
||||
const char *m_pInodePath;
|
||||
/*this pointer will be set to the current pipe used*/
|
||||
bool m_bInitialized;
|
||||
IPATestConfiguration m_eConfiguration;
|
||||
/*The Pipes configuration env*/
|
||||
bool m_ExceptionPipe;
|
||||
/* Is this the exception pipe */
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
107
qcom/opensource/dataipa/kernel-tests/PipeTestFixture.cpp
Normal file
107
qcom/opensource/dataipa/kernel-tests/PipeTestFixture.cpp
Normal file
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Copyright (c) 2017,2020 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "PipeTestFixture.h"
|
||||
|
||||
extern Logger g_Logger;
|
||||
|
||||
/*define the static Pipes which will be used by all derived tests.*/
|
||||
Pipe PipeTestFixture::m_IpaToUsbPipe(IPA_CLIENT_TEST_CONS, IPA_TEST_CONFIFURATION_1);
|
||||
Pipe PipeTestFixture::m_UsbToIpaPipe(IPA_CLIENT_TEST_PROD, IPA_TEST_CONFIFURATION_1);
|
||||
|
||||
PipeTestFixture::PipeTestFixture()
|
||||
{
|
||||
m_testSuiteName.push_back("Pipes");
|
||||
Register(*this);
|
||||
}
|
||||
|
||||
static int SetupKernelModule(void)
|
||||
{
|
||||
int retval;
|
||||
struct ipa_channel_config from_ipa_0 = {0};
|
||||
struct test_ipa_ep_cfg from_ipa_0_cfg;
|
||||
struct ipa_channel_config to_ipa_0 = {0};
|
||||
struct test_ipa_ep_cfg to_ipa_0_cfg;
|
||||
|
||||
struct ipa_test_config_header header = {0};
|
||||
struct ipa_channel_config *to_ipa_array[1];
|
||||
struct ipa_channel_config *from_ipa_array[1];
|
||||
|
||||
|
||||
/* From ipa configurations - 1 pipes */
|
||||
memset(&from_ipa_0_cfg, 0 , sizeof(from_ipa_0_cfg));
|
||||
prepare_channel_struct(&from_ipa_0,
|
||||
header.from_ipa_channels_num++,
|
||||
IPA_CLIENT_TEST_CONS,
|
||||
(void *)&from_ipa_0_cfg,
|
||||
sizeof(from_ipa_0_cfg));
|
||||
from_ipa_array[0] = &from_ipa_0;
|
||||
|
||||
/* To ipa configurations - 1 pipes */
|
||||
memset(&to_ipa_0_cfg, 0 , sizeof(to_ipa_0_cfg));
|
||||
to_ipa_0_cfg.mode.mode = IPA_DMA;
|
||||
to_ipa_0_cfg.mode.dst = IPA_CLIENT_TEST_CONS;
|
||||
prepare_channel_struct(&to_ipa_0,
|
||||
header.to_ipa_channels_num++,
|
||||
IPA_CLIENT_TEST_PROD,
|
||||
(void *)&to_ipa_0_cfg,
|
||||
sizeof(to_ipa_0_cfg));
|
||||
to_ipa_array[0] = &to_ipa_0;
|
||||
|
||||
prepare_header_struct(&header, from_ipa_array, to_ipa_array);
|
||||
|
||||
retval = GenericConfigureScenario(&header);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
bool PipeTestFixture::Setup()
|
||||
{
|
||||
bool bRetVal = true;
|
||||
|
||||
if (SetupKernelModule() == false)
|
||||
return false;
|
||||
|
||||
/*Initialize the pipe for all the tests -
|
||||
* this will open the inode which represents the pipe.
|
||||
*/
|
||||
bRetVal &= m_IpaToUsbPipe.Init();
|
||||
bRetVal &= m_UsbToIpaPipe.Init();
|
||||
|
||||
return bRetVal;
|
||||
}
|
||||
|
||||
bool PipeTestFixture::Teardown()
|
||||
{
|
||||
/*The Destroy method will close the inode.*/
|
||||
m_IpaToUsbPipe.Destroy();
|
||||
m_UsbToIpaPipe.Destroy();
|
||||
|
||||
return true;
|
||||
}
|
||||
69
qcom/opensource/dataipa/kernel-tests/PipeTestFixture.h
Normal file
69
qcom/opensource/dataipa/kernel-tests/PipeTestFixture.h
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (c) 2017 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "Constants.h"
|
||||
#include "Logger.h"
|
||||
#include "linux/msm_ipa.h"
|
||||
#include "TestsUtils.h"
|
||||
#include "TestBase.h"
|
||||
#include "Pipe.h"
|
||||
|
||||
/*This class will be the base class of all Pipe tests.
|
||||
*Any method other than the test case itself can be
|
||||
*declared in this Fixture thus allowing the derived classes to
|
||||
*implement only the test case.
|
||||
*All the test of the pipe uses one input and one output in DMA mode.
|
||||
*/
|
||||
class PipeTestFixture:public TestBase
|
||||
{
|
||||
public:
|
||||
/*This Constructor will register each instance that it creates.*/
|
||||
PipeTestFixture();
|
||||
|
||||
/*This method will create and initialize two Pipe object for the USB
|
||||
* (Ethernet) Pipes, one as input and the other as output.
|
||||
*/
|
||||
virtual bool Setup();
|
||||
|
||||
/*This method will destroy the pipes.*/
|
||||
virtual bool Teardown();
|
||||
|
||||
/*The client type are set from the peripheral perspective
|
||||
* (TODO Pipe:in case the Driver will change its perspective
|
||||
* of ipa_connect this should be changed).
|
||||
*/
|
||||
static Pipe m_IpaToUsbPipe;
|
||||
static Pipe m_UsbToIpaPipe;
|
||||
};
|
||||
478
qcom/opensource/dataipa/kernel-tests/PipeTests.cpp
Normal file
478
qcom/opensource/dataipa/kernel-tests/PipeTests.cpp
Normal file
@@ -0,0 +1,478 @@
|
||||
/*
|
||||
* Copyright (c) 2017,2020 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "PipeTestFixture.h"
|
||||
#include "Constants.h"
|
||||
#include "TestsUtils.h"
|
||||
#include "linux/msm_ipa.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class PipeTestRawTransfer: public PipeTestFixture {
|
||||
public:
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
PipeTestRawTransfer() {
|
||||
m_name = "PipeTestRawTransfer";
|
||||
m_description = "This test will be using the Pipe raw transfer ability";
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool Run() {
|
||||
bool bTestResult = true;
|
||||
Byte pIpPacket[] = { 0x01, 0x02, 0x03, 0x04 }; //This packet will be sent(It can be replaced by a real IP packet).
|
||||
Byte pIpPacketReceive[sizeof(pIpPacket)] = { 0 }; //This buffer will be used in order to store the received packet.
|
||||
|
||||
//Send the raw IP packet(which is a 4 arbitrary bytes) without header addition by the Pipe
|
||||
LOG_MSG_DEBUG(
|
||||
"Sending packet into the USB pipe(%d bytes)\n", sizeof(pIpPacket));
|
||||
int nBytesSent = m_UsbToIpaPipe.Send(pIpPacket, sizeof(pIpPacket));
|
||||
if (sizeof(pIpPacket) != nBytesSent) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//Receive the raw IP packet(which is a 4 arbitrary bytes) without header removal by the Pipe
|
||||
LOG_MSG_DEBUG(
|
||||
"Reading packet from the USB pipe(%d bytes should be there)\n", sizeof(pIpPacketReceive));
|
||||
int nBytesReceived = m_IpaToUsbPipe.Receive(pIpPacketReceive,
|
||||
sizeof(pIpPacketReceive));
|
||||
if (sizeof(pIpPacketReceive) != nBytesReceived) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < nBytesReceived; i++) {
|
||||
LOG_MSG_DEBUG("0x%02x\n", pIpPacketReceive[i]);
|
||||
}
|
||||
|
||||
//Check that the sent IP packet is equal to the received IP packet.
|
||||
LOG_MSG_DEBUG("Checking sent.vs.received packet\n");
|
||||
bTestResult &= !memcmp(pIpPacket, pIpPacketReceive, sizeof(pIpPacket));
|
||||
|
||||
return bTestResult;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//This test will be using the Pipe Add-Header transfer ability(and not header insertion
|
||||
class PipeTestAddHeader: public PipeTestFixture {
|
||||
public:
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
PipeTestAddHeader() {
|
||||
m_name = "PipeTestAddHeader";
|
||||
m_description = "Add header to USB pipe and receive it without removing the header";
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool Run() {
|
||||
Byte pIpPacketSend[4] = { 0x01, 0x02, 0x03, 0x04 };
|
||||
int nReceivedPacketSize = sizeof(pIpPacketSend)
|
||||
+ m_IpaToUsbPipe.GetHeaderLengthAdd();
|
||||
Byte *pPacketReceive = new Byte[nReceivedPacketSize];
|
||||
|
||||
LOG_MSG_DEBUG("Sending packet into the USB pipe(%d bytes - no header size)\n", sizeof(pIpPacketSend));
|
||||
int nRetValSend = m_UsbToIpaPipe.AddHeaderAndSend(pIpPacketSend,
|
||||
sizeof(pIpPacketSend));
|
||||
LOG_MSG_DEBUG("Result of AddHeaderAndSend = %d\n", nRetValSend);
|
||||
|
||||
LOG_MSG_DEBUG("Reading packet from the USB pipe(%d bytes - including header)\n", nReceivedPacketSize);
|
||||
int nRetValReceive = m_IpaToUsbPipe.Receive(pPacketReceive,
|
||||
nReceivedPacketSize);
|
||||
LOG_MSG_DEBUG("Result of Receive = %d\n", nRetValReceive);
|
||||
|
||||
if (nReceivedPacketSize != nRetValReceive) {
|
||||
delete[] pPacketReceive;
|
||||
LOG_MSG_ERROR(
|
||||
"Size of received packet is not as expected - %d\n", nRetValReceive);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool bHeaderCmp = !memcmp(pPacketReceive, Pipe::m_pUsbHeader,
|
||||
m_IpaToUsbPipe.GetHeaderLengthAdd());
|
||||
LOG_MSG_DEBUG("bHeaderCmp - %s\n", bHeaderCmp ? "True" : "False");
|
||||
|
||||
bool bIpCmp = !memcmp(pPacketReceive + m_IpaToUsbPipe.GetHeaderLengthAdd(),
|
||||
pIpPacketSend, sizeof(pIpPacketSend));
|
||||
LOG_MSG_DEBUG("bIpCmp - %s\n", bIpCmp ? "True" : "False");
|
||||
|
||||
delete[] pPacketReceive;
|
||||
return bHeaderCmp && bIpCmp;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//This test will be using the Pipe Remove-Header transfer ability(and header addition)
|
||||
class PipeTestAddAndRemoveHeader: public PipeTestFixture {
|
||||
public:
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
PipeTestAddAndRemoveHeader() {
|
||||
m_name = "PipeTestAddAndRemoveHeader";
|
||||
m_description = "This test will be using the Pipe Remove-Header transfer ability(and header addition)";
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool Run() {
|
||||
Byte pIpPacketSend[4] = { 0x01, 0x02, 0x03, 0x04 };
|
||||
int nToBeReceivedPacketSize = sizeof(pIpPacketSend)
|
||||
+ m_IpaToUsbPipe.GetHeaderLengthAdd();
|
||||
Byte *pPacketReceive = new Byte[nToBeReceivedPacketSize];
|
||||
|
||||
LOG_MSG_DEBUG("Sending packet into the USB pipe(%d bytes - no header size)\n", sizeof(pIpPacketSend));
|
||||
int nBytesSent = m_UsbToIpaPipe.AddHeaderAndSend(pIpPacketSend,
|
||||
sizeof(pIpPacketSend));
|
||||
LOG_MSG_DEBUG("nBytesSent of AddHeaderAndSend = %d\n", nBytesSent);
|
||||
|
||||
LOG_MSG_DEBUG("Reading packet from the USB pipe(%d bytes - including header)\n", nToBeReceivedPacketSize);
|
||||
int nBytesReceived = m_IpaToUsbPipe.Receive(pPacketReceive,
|
||||
nToBeReceivedPacketSize);
|
||||
LOG_MSG_DEBUG("nBytesReceived = %d\n", nBytesReceived);
|
||||
|
||||
if (nToBeReceivedPacketSize != nBytesReceived) {
|
||||
delete[] pPacketReceive;
|
||||
LOG_MSG_ERROR("Size of received packet is not as expected - %d\n", nBytesReceived);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool bHeaderCmp = !memcmp(pPacketReceive, Pipe::m_pUsbHeader,
|
||||
m_IpaToUsbPipe.GetHeaderLengthAdd());
|
||||
LOG_MSG_DEBUG("bHeaderCmp - %s\n", bHeaderCmp ? "True" : "False");
|
||||
|
||||
bool bIpCmp = !memcmp(pPacketReceive + m_IpaToUsbPipe.GetHeaderLengthAdd(),
|
||||
pIpPacketSend, sizeof(pIpPacketSend));
|
||||
LOG_MSG_DEBUG("bIpCmp - %s\n", bIpCmp ? "True" : "False");
|
||||
|
||||
delete[] pPacketReceive;
|
||||
return bHeaderCmp && bIpCmp;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//This test will try to send big chuck of data and check if the Data FIFO is working correct
|
||||
class PipeTestDataFifoOverflow: public PipeTestFixture {
|
||||
public:
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
PipeTestDataFifoOverflow() {
|
||||
m_name = "PipeTestDataFifoOverflow";
|
||||
m_description = "Send many big packets over the IPA. there will be toggle of send/receive";
|
||||
m_runInRegression = false; // Test is very long thus makes a problem in regression testing
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool Run() {
|
||||
bool bTestResult = true;
|
||||
int nPacketByteSize;
|
||||
int nTotalDataSent = 0;
|
||||
int nTestsMaxDataSend = 3 * 0x6400;
|
||||
int nIterationNumber = 0;
|
||||
Byte *pIpPacket;
|
||||
Byte *pIpPacketReceive;
|
||||
srand(123); //set some constant seed value in order to be able to reproduce problems.
|
||||
|
||||
//send and receive many packets(nIterations)
|
||||
while (nTotalDataSent < nTestsMaxDataSend) {
|
||||
//get random values for this packet.
|
||||
nPacketByteSize = (rand() % 400) + 200;
|
||||
pIpPacket = new Byte[nPacketByteSize];
|
||||
|
||||
for (int j = 0; j < nPacketByteSize; j++) {
|
||||
pIpPacket[j] = rand() % 0x100;
|
||||
}
|
||||
|
||||
//Send the raw IP packet(which is a 4 arbitrary bytes) without header addition by the Pipe
|
||||
LOG_MSG_DEBUG(
|
||||
"Iteration number %d(0x%08x/0x%08x data):\n", nIterationNumber++, nTotalDataSent, nTestsMaxDataSend);
|
||||
LOG_MSG_DEBUG(
|
||||
"Sending packet into the USB pipe(%d bytes)\n", nPacketByteSize);
|
||||
int nBytesSent = m_UsbToIpaPipe.Send(pIpPacket, nPacketByteSize);
|
||||
if (nPacketByteSize != nBytesSent) {
|
||||
delete[] pIpPacket;
|
||||
LOG_MSG_ERROR("Could not send the whole packet - nTotalDataSent = 0x%08x\n", nTotalDataSent);
|
||||
return false;
|
||||
}
|
||||
|
||||
//Receive the raw IP packet(which is a 4 arbitrary bytes) without header removal by the Pipe
|
||||
pIpPacketReceive = new Byte[nPacketByteSize];
|
||||
LOG_MSG_DEBUG("Reading packet from the USB pipe(%d bytes should be there)\n", nPacketByteSize);
|
||||
int nBytesReceived = m_IpaToUsbPipe.Receive(pIpPacketReceive,
|
||||
nPacketByteSize);
|
||||
if (nPacketByteSize != nBytesReceived) {
|
||||
delete[] pIpPacket;
|
||||
delete[] pIpPacketReceive;
|
||||
LOG_MSG_ERROR("Could not read the whole packet - nTotalDataSent = 0x%08x\n", nTotalDataSent);
|
||||
return false;
|
||||
}
|
||||
for (int j = 0; j < nBytesReceived; j++) {
|
||||
LOG_MSG_DEBUG("0x%02x\n", pIpPacketReceive[j]);
|
||||
}
|
||||
|
||||
//Check that the sent IP packet is equal to the received IP packet.
|
||||
LOG_MSG_DEBUG("Checking sent.vs.received packet\n");
|
||||
bTestResult &= !memcmp(pIpPacket, pIpPacketReceive,
|
||||
nPacketByteSize);
|
||||
if (true != bTestResult) {
|
||||
delete[] pIpPacketReceive;
|
||||
delete[] pIpPacket;
|
||||
LOG_MSG_ERROR("Send != Received - nTotalDataSent = 0x%08x\n", nTotalDataSent);
|
||||
return false;
|
||||
}
|
||||
nTotalDataSent += nPacketByteSize;
|
||||
delete[] pIpPacket;
|
||||
delete[] pIpPacketReceive;
|
||||
}
|
||||
LOG_MSG_DEBUG("Great success - nTotalDataSent = 0x%08x\n", nTotalDataSent);
|
||||
return true;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//This test will try to many little chuck of data and check if the Descriptor FIFO is working correct
|
||||
class PipeTestDescriptorFifoOverflow: public PipeTestFixture {
|
||||
public:
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
PipeTestDescriptorFifoOverflow() {
|
||||
m_name = "PipeTestDescriptorFifoOverflow";
|
||||
m_description = "Send many small packets over the IPA. there will be toggle of send/receive";
|
||||
m_runInRegression = false; // Test is very long thus makes a problem in regression testing
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool Run() {
|
||||
bool bTestResult = true;
|
||||
int nPacketByteSize;
|
||||
int nTotalPacketSent = 0;
|
||||
int nTestsMaxDescriptors = 3 * 0x1000;
|
||||
int nIterationNumber = 0;
|
||||
Byte *pIpPacket;
|
||||
Byte *pIpPacketReceive;
|
||||
srand(123); //set some constant seed value in order to be able to reproduce problems.
|
||||
|
||||
//send and receive many packets(nIterations)
|
||||
while (nTotalPacketSent < nTestsMaxDescriptors) {
|
||||
//get random values for this packet.
|
||||
nPacketByteSize = (rand() % 10) + 1;
|
||||
pIpPacket = new Byte[nPacketByteSize];
|
||||
|
||||
for (int j = 0; j < nPacketByteSize; j++) {
|
||||
pIpPacket[j] = rand() % 0x100;
|
||||
}
|
||||
|
||||
//Send the raw IP packet(which is a 4 arbitrary bytes) without header addition by the Pipe
|
||||
LOG_MSG_DEBUG("Iteration number %d(0x%08x/0x%08x packets):\n", nIterationNumber++, nTotalPacketSent, nTestsMaxDescriptors);
|
||||
LOG_MSG_DEBUG("Sending packet into the USB pipe(%d bytes)\n", nPacketByteSize);
|
||||
int nBytesSent = m_UsbToIpaPipe.Send(pIpPacket, nPacketByteSize);
|
||||
if (nPacketByteSize != nBytesSent) {
|
||||
delete[] pIpPacket;
|
||||
LOG_MSG_ERROR("Could not send the whole packet - nTotalPacketSent = 0x%08x\n", nTotalPacketSent);
|
||||
return false;
|
||||
}
|
||||
|
||||
//Receive the raw IP packet(which is a 4 arbitrary bytes) without header removal by the Pipe
|
||||
pIpPacketReceive = new Byte[nPacketByteSize];
|
||||
LOG_MSG_DEBUG("Reading packet from the USB pipe(%d bytes should be there)\n", nPacketByteSize);
|
||||
int nBytesReceived = m_IpaToUsbPipe.Receive(pIpPacketReceive,
|
||||
nPacketByteSize);
|
||||
if (nPacketByteSize != nBytesReceived) {
|
||||
delete[] pIpPacketReceive;
|
||||
LOG_MSG_ERROR("Could not read the whole packet - nTotalPacketSent = 0x%08x\n", nTotalPacketSent);
|
||||
return false;
|
||||
}
|
||||
for (int j = 0; j < nBytesReceived; j++) {
|
||||
LOG_MSG_DEBUG("0x%02x\n", pIpPacketReceive[j]);
|
||||
}
|
||||
|
||||
//Check that the sent IP packet is equal to the received IP packet.
|
||||
LOG_MSG_DEBUG("Checking sent.vs.received packet\n");
|
||||
bTestResult &= !memcmp(pIpPacket, pIpPacketReceive,
|
||||
nPacketByteSize);
|
||||
if (true != bTestResult) {
|
||||
delete[] pIpPacketReceive;
|
||||
delete[] pIpPacket;
|
||||
LOG_MSG_ERROR("Send != Received - nTotalPacketSent = 0x%08x\n", nTotalPacketSent);
|
||||
return false;
|
||||
}
|
||||
nTotalPacketSent++;
|
||||
delete[] pIpPacket;
|
||||
delete[] pIpPacketReceive;
|
||||
}
|
||||
LOG_MSG_DEBUG("Great success - nTotalPacketSent = 0x%08x\n", nTotalPacketSent);
|
||||
return true;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define HOLB_TEST_PACKETS_MAX_NUM 50
|
||||
class PipeTestHolb: public PipeTestFixture {
|
||||
|
||||
public:
|
||||
|
||||
PipeTestHolb() {
|
||||
m_name = "PipeTestHolb";
|
||||
m_description = "This test will check the HOLB function";
|
||||
}
|
||||
|
||||
bool Run() {
|
||||
int nPacketsToSend = HOLB_TEST_PACKETS_MAX_NUM;
|
||||
int nBytesReceived;
|
||||
int nBytesSentInLastPacket;
|
||||
int i;
|
||||
Byte pIpPacket[] = { 0x01, 0x02, 0x03, 0x04 }; //This packet will be sent(It can be replaced by a real IP packet).
|
||||
Byte pIpPacketReceive[sizeof(pIpPacket) * HOLB_TEST_PACKETS_MAX_NUM] = { 0 }; //This buffer will be used in order to store the received packet.
|
||||
|
||||
m_IpaToUsbPipe.DisableHolb();
|
||||
|
||||
//Send the IP packets
|
||||
LOG_MSG_DEBUG("Sending %d packets of %d bytes into the USB pipe\n",
|
||||
nPacketsToSend, sizeof(pIpPacket));
|
||||
for (i = 0; i < nPacketsToSend; i++) {
|
||||
nBytesSentInLastPacket = m_UsbToIpaPipe.Send(pIpPacket, sizeof(pIpPacket));
|
||||
if (sizeof(pIpPacket) != nBytesSentInLastPacket) {
|
||||
LOG_MSG_ERROR("Failed sending the packet %d to m_UsbToIpaPipe", i);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//Receive all the raw IP packets (which are a 4 arbitrary bytes)
|
||||
LOG_MSG_DEBUG(
|
||||
"Reading packets from the USB pipe (%dx%d bytes should be there)\n",
|
||||
sizeof(pIpPacket), nPacketsToSend);
|
||||
for (i = 0; i < nPacketsToSend; i++) {
|
||||
nBytesReceived = m_IpaToUsbPipe.Receive(pIpPacketReceive, sizeof(pIpPacketReceive));
|
||||
if ((int)sizeof(pIpPacket) != nBytesReceived) {
|
||||
LOG_MSG_ERROR("Failed with HOLB disabled! Packet #%d: Expected %d Bytes, got %d Bytes",
|
||||
i, sizeof(pIpPacket), nBytesReceived);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Enable HOLB
|
||||
m_IpaToUsbPipe.EnableHolb(0);
|
||||
|
||||
//Send the IP packets
|
||||
LOG_MSG_DEBUG("Sending %d packets of %d bytes into the USB pipe\n",
|
||||
nPacketsToSend, sizeof(pIpPacket));
|
||||
for (i = 0; i < nPacketsToSend; i++) {
|
||||
nBytesSentInLastPacket = m_UsbToIpaPipe.Send(pIpPacket, sizeof(pIpPacket));
|
||||
if (sizeof(pIpPacket) != nBytesSentInLastPacket) {
|
||||
LOG_MSG_ERROR("Failed sending the packet %d to m_UsbToIpaPipe", i);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Receive the raw IP packets (which are a 4 arbitrary bytes)
|
||||
// that fit into the FIFO before the HOLB started dropping
|
||||
// and fail to receive the rest
|
||||
LOG_MSG_DEBUG(
|
||||
"Reading packets from the USB pipe(%dx%d bytes should be there)\n",
|
||||
sizeof(pIpPacket), nPacketsToSend);
|
||||
for (i = 0; i < nPacketsToSend; i++) {
|
||||
int nBytesReceived = m_IpaToUsbPipe.Receive(pIpPacketReceive,
|
||||
sizeof(pIpPacketReceive));
|
||||
if ((int)sizeof(pIpPacket) != nBytesReceived) {
|
||||
if (i == 0) {
|
||||
LOG_MSG_ERROR("First packet failed to receive ! Expected %d Bytes, got %d Bytes",
|
||||
sizeof(pIpPacket), nBytesReceived);
|
||||
return false;
|
||||
} else
|
||||
// Failed to receive a packet, but not the first one.
|
||||
// This is the desired result.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
LOG_MSG_ERROR("All packets were received successfully, which means the HOLB didn't work.");
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//Those tests should be run with configuration number 1 which has one input pipe and
|
||||
//one output pipe.
|
||||
//Please look at the Fixture for more configurations update.
|
||||
static PipeTestRawTransfer pipeTestRawTransfer;
|
||||
static PipeTestAddHeader pipeTestAddHeader;
|
||||
static PipeTestAddAndRemoveHeader pipeTestAddAndRemoveHeader;
|
||||
static PipeTestHolb pipeTestHolb;
|
||||
|
||||
//DO NOT UNCOMMENT THOSE LINES UNLESS YOU KNOW WHAT YOU ARE DOING!!!
|
||||
//those test takes 4ever and should be use for specific usecase!
|
||||
//static PipeTestDataFifoOverflow pipeTestDataFifoOverflow;
|
||||
//static PipeTestDescriptorFifoOverflow pipeTestDescriptorFifoOverflow;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// EOF ////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
11
qcom/opensource/dataipa/kernel-tests/README.txt
Normal file
11
qcom/opensource/dataipa/kernel-tests/README.txt
Normal file
@@ -0,0 +1,11 @@
|
||||
Subsystem: ipa-kernel-tests
|
||||
|
||||
Parameters:
|
||||
-n: Nominal test case (tests all the different use cases for ip_accelerator)
|
||||
-a: Adversarial test case (Currently holds no tests)
|
||||
-r: Repeatability test case (Currently holds no tests)
|
||||
-s: Stress test case (invokes many simultaneous threads that all try and access the device at once)
|
||||
--help: Specifies the params for run.sh
|
||||
|
||||
Description:
|
||||
This test module tests IPA driver, it holds a userspace module and a kernel space module.
|
||||
1097
qcom/opensource/dataipa/kernel-tests/RNDISAggregationTestFixture.cpp
Normal file
1097
qcom/opensource/dataipa/kernel-tests/RNDISAggregationTestFixture.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright (c) 2017,2020 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <linux/if_ether.h>
|
||||
|
||||
#include "Constants.h"
|
||||
#include "Logger.h"
|
||||
#include "linux/msm_ipa.h"
|
||||
#include "TestsUtils.h"
|
||||
#include "TestBase.h"
|
||||
#include "Pipe.h"
|
||||
#include "RoutingDriverWrapper.h"
|
||||
#include "HeaderInsertion.h"
|
||||
#include "Filtering.h"
|
||||
#include "IPAFilteringTable.h"
|
||||
#define MAX_PACKET_SIZE 1024
|
||||
|
||||
/*This class will be the base class of RNDIS Aggregation tests.
|
||||
*Any method other than the test case itself can be
|
||||
*declared in this Fixture thus allowing the derived classes to
|
||||
*implement only the test case.
|
||||
*All the test of the Aggregation uses one input and one output in DMA mode.
|
||||
*/
|
||||
class RNDISAggregationTestFixture:public TestBase
|
||||
{
|
||||
public:
|
||||
/*This Constructor will register each instance that it creates.*/
|
||||
RNDISAggregationTestFixture();
|
||||
|
||||
/*This method will create and initialize two Pipe object for the USB
|
||||
*(Ethernet) Pipes, one as input and the other as output.
|
||||
*/
|
||||
virtual bool Setup();
|
||||
|
||||
/*This method will destroy the pipes.*/
|
||||
virtual bool Teardown();
|
||||
|
||||
virtual bool Run();
|
||||
|
||||
virtual bool AddRules() = 0;
|
||||
|
||||
virtual bool TestLogic() = 0;
|
||||
|
||||
bool AddRulesNoAgg();
|
||||
|
||||
bool AddRulesDeAggEther();
|
||||
|
||||
bool AddRulesAggTimeLimit();
|
||||
|
||||
bool AddRulesAggByteLimit();
|
||||
|
||||
bool AddRulesAggByteLimit(bool bAggForceClose);
|
||||
|
||||
bool AddRulesAggPacketLimit();
|
||||
|
||||
bool AddRulesAggDualFC();
|
||||
|
||||
bool AddRulesAggDualFcRoutingBased();
|
||||
|
||||
/*The client type are set from the peripheral perspective*/
|
||||
static Pipe m_IpaToUsbPipeAgg;
|
||||
/*IPA_CLIENT_TEST2_CONS (pipe_num = 7)*/
|
||||
static Pipe m_UsbToIpaPipe;
|
||||
/* IPA_CLIENT_TEST_PROD (pipe_num = 11)*/
|
||||
static Pipe m_IpaToUsbPipe;
|
||||
/* IPA_CLIENT_TEST3_CONS (pipe_num = 9)*/
|
||||
static Pipe m_UsbToIpaPipeDeagg;
|
||||
/* IPA_CLIENT_TEST2_PROD (pipe_num = 6)*/
|
||||
static Pipe m_IpaToUsbPipeAggTime;
|
||||
/* IPA_CLIENT_TEST_CONS (pipe_num = 10)*/
|
||||
static Pipe m_IpaToUsbPipeAggPktLimit;
|
||||
/* IPA_CLIENT_TEST4_CONS (pipe_num = 4)*/
|
||||
static Pipe m_HsicToIpaPipe;
|
||||
/* IPA_CLIENT_TEST3_PROD (pipe_num = 13)*/
|
||||
|
||||
static RoutingDriverWrapper m_Routing;
|
||||
static Filtering m_Filtering;
|
||||
static HeaderInsertion m_HeaderInsertion;
|
||||
|
||||
protected:
|
||||
enum ipa_ip_type m_eIP;
|
||||
};
|
||||
1265
qcom/opensource/dataipa/kernel-tests/RNDISAggregationTests.cpp
Normal file
1265
qcom/opensource/dataipa/kernel-tests/RNDISAggregationTests.cpp
Normal file
File diff suppressed because it is too large
Load Diff
213
qcom/opensource/dataipa/kernel-tests/RoutingDriverWrapper.cpp
Normal file
213
qcom/opensource/dataipa/kernel-tests/RoutingDriverWrapper.cpp
Normal file
@@ -0,0 +1,213 @@
|
||||
/*
|
||||
* Copyright (c) 2017,2020 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* Changes from Qualcomm Innovation Center are provided under the following license:
|
||||
*
|
||||
* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted (subject to the limitations in the
|
||||
* disclaimer below) provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* * Neither the name of Qualcomm Innovation Center, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
|
||||
* GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
|
||||
* HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "RoutingDriverWrapper.h"
|
||||
#include "TestsUtils.h"
|
||||
|
||||
bool RoutingDriverWrapper::AddRoutingRule(struct ipa_ioc_add_rt_rule *ruleTable)
|
||||
{
|
||||
int retval = 0;
|
||||
|
||||
if (!DeviceNodeIsOpened())
|
||||
return false;
|
||||
|
||||
retval = ioctl(m_fd, IPA_IOC_ADD_RT_RULE, ruleTable);
|
||||
if (retval) {
|
||||
printf("%s(), failed adding routing rule table %p\n", __FUNCTION__, ruleTable);
|
||||
return false;
|
||||
}
|
||||
|
||||
printf("%s(), Added routing rule table %p\n", __FUNCTION__, ruleTable);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RoutingDriverWrapper::AddRoutingRule(struct ipa_ioc_add_rt_rule_v2 *ruleTable_v2)
|
||||
{
|
||||
int retval = 0;
|
||||
|
||||
if (!DeviceNodeIsOpened())
|
||||
return false;
|
||||
|
||||
retval = ioctl(m_fd, IPA_IOC_ADD_RT_RULE_V2, ruleTable_v2);
|
||||
if (retval) {
|
||||
printf("%s(), failed adding routing rule table %p\n", __FUNCTION__, ruleTable_v2);
|
||||
return false;
|
||||
}
|
||||
|
||||
printf("%s(), Added routing rule table %p\n", __FUNCTION__, ruleTable_v2);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RoutingDriverWrapper::DeleteRoutingRule(struct ipa_ioc_del_rt_rule *ruleTable)
|
||||
{
|
||||
int retval = 0;
|
||||
|
||||
if (!DeviceNodeIsOpened())
|
||||
return false;
|
||||
|
||||
retval = ioctl(m_fd, IPA_IOC_DEL_RT_RULE, ruleTable);
|
||||
if (retval) {
|
||||
printf("%s(), failed deleting routing rule table %p\n", __FUNCTION__, ruleTable);
|
||||
return false;
|
||||
}
|
||||
|
||||
printf("%s(), Deleted routing rule table %p\n", __FUNCTION__, ruleTable);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RoutingDriverWrapper::Commit(enum ipa_ip_type ip)
|
||||
{
|
||||
int retval = 0;
|
||||
|
||||
if (!DeviceNodeIsOpened())
|
||||
return false;
|
||||
|
||||
retval = ioctl(m_fd, IPA_IOC_COMMIT_RT, ip);
|
||||
if (retval) {
|
||||
printf("%s(), failed commiting routing rules.\n", __FUNCTION__);
|
||||
return false;
|
||||
}
|
||||
|
||||
printf("%s(), Commited routing rules to IPA HW.\n", __FUNCTION__);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RoutingDriverWrapper::Reset(enum ipa_ip_type ip)
|
||||
{
|
||||
int retval = 0;
|
||||
|
||||
if (!DeviceNodeIsOpened())
|
||||
return false;
|
||||
|
||||
retval = ioctl(m_fd, IPA_IOC_RESET_RT, ip);
|
||||
retval |= ioctl(m_fd, IPA_IOC_COMMIT_RT, ip);
|
||||
if (retval) {
|
||||
printf("%s(), failed reseting routing block.\n", __FUNCTION__);
|
||||
return false;
|
||||
}
|
||||
|
||||
printf("%s(), Reset command issued to IPA routing block.\n", __FUNCTION__);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RoutingDriverWrapper::GetRoutingTable(struct ipa_ioc_get_rt_tbl *routingTable)
|
||||
{
|
||||
int retval = 0;
|
||||
|
||||
if (!DeviceNodeIsOpened())
|
||||
return false;
|
||||
|
||||
retval = ioctl(m_fd, IPA_IOC_GET_RT_TBL, routingTable);
|
||||
if (retval) {
|
||||
printf("%s(), IPA_IOCTL_GET_RT_TBL ioctl failed, routingTable =0x%p, retval=0x%x.\n", __FUNCTION__, routingTable, retval);
|
||||
return false;
|
||||
}
|
||||
|
||||
printf("%s(), IPA_IOCTL_GET_RT_TBL ioctl issued to IPA routing block.\n", __FUNCTION__);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RoutingDriverWrapper::PutRoutingTable(uint32_t routingTableHandle)
|
||||
{
|
||||
int retval = 0;
|
||||
|
||||
if (!DeviceNodeIsOpened())
|
||||
return false;
|
||||
|
||||
retval = ioctl(m_fd, IPA_IOC_PUT_RT_TBL, routingTableHandle);
|
||||
if (retval) {
|
||||
printf("%s(), IPA_IOCTL_PUT_RT_TBL ioctl failed.\n", __FUNCTION__);
|
||||
return false;
|
||||
}
|
||||
|
||||
printf("%s(), IPA_IOCTL_PUT_RT_TBL ioctl issued to IPA routing block.\n", __FUNCTION__);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RoutingDriverWrapper::SetNatConntrackExcRoutingTable(uint32_t routingTableHandle, bool nat_or_conntrack)
|
||||
{
|
||||
int retval = 0;
|
||||
|
||||
if (!DeviceNodeIsOpened())
|
||||
return false;
|
||||
|
||||
if (nat_or_conntrack)
|
||||
retval = ioctl(m_fd, IPA_IOC_SET_NAT_EXC_RT_TBL_IDX, routingTableHandle);
|
||||
else
|
||||
retval = ioctl(m_fd, IPA_IOC_SET_CONN_TRACK_EXC_RT_TBL_IDX, routingTableHandle);
|
||||
|
||||
if (retval) {
|
||||
printf("%s(), IPA_IOC_SET_CONN_TRACK_EXC_RT_TBL_IDX ioctl failed.\n", __FUNCTION__);
|
||||
return false;
|
||||
}
|
||||
|
||||
printf("%s(), %s ioctl issued to IPA routing block.\n", __FUNCTION__,(nat_or_conntrack) ?
|
||||
"IPA_IOC_SET_NAT_EXC_RT_TBL_IDX" : "IPA_IOC_SET_CONN_TRACK_EXC_RT_TBL_IDX");
|
||||
return true;
|
||||
}
|
||||
|
||||
87
qcom/opensource/dataipa/kernel-tests/RoutingDriverWrapper.h
Normal file
87
qcom/opensource/dataipa/kernel-tests/RoutingDriverWrapper.h
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (c) 2017,2020 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* Changes from Qualcomm Innovation Center are provided under the following license:
|
||||
*
|
||||
* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted (subject to the limitations in the
|
||||
* disclaimer below) provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* * Neither the name of Qualcomm Innovation Center, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
|
||||
* GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
|
||||
* HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
|
||||
*/
|
||||
|
||||
#ifndef ROUTING_H_
|
||||
#define ROUTING_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include "linux/msm_ipa.h"
|
||||
#include "Feature.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
class RoutingDriverWrapper: public Feature
|
||||
{
|
||||
public:
|
||||
bool AddRoutingRule(struct ipa_ioc_add_rt_rule *ruleTable);
|
||||
bool AddRoutingRule(ipa_ioc_add_rt_rule_v2 *ruleTable_v2);
|
||||
bool DeleteRoutingRule(struct ipa_ioc_del_rt_rule *ruleTable);
|
||||
bool Commit(enum ipa_ip_type ip);
|
||||
bool Reset(enum ipa_ip_type ip);
|
||||
bool GetRoutingTable(struct ipa_ioc_get_rt_tbl *routingTable);
|
||||
bool PutRoutingTable(uint32_t routingTableHandle);
|
||||
bool SetNatConntrackExcRoutingTable(uint32_t routingTableHandle, bool nat_or_conntrack);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
6181
qcom/opensource/dataipa/kernel-tests/RoutingTests.cpp
Normal file
6181
qcom/opensource/dataipa/kernel-tests/RoutingTests.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright (c) 2017 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "TLPAggregationTestFixture.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//define the static Pipes which will be used by all derived tests.
|
||||
Pipe TLPAggregationTestFixture::m_IpaToUsbPipeNoAgg(IPA_CLIENT_TEST3_CONS,
|
||||
IPA_TEST_CONFIGURATION_8);
|
||||
Pipe TLPAggregationTestFixture::m_IpaToUsbPipeAggr(IPA_CLIENT_TEST_CONS,
|
||||
IPA_TEST_CONFIGURATION_8);
|
||||
Pipe TLPAggregationTestFixture::m_UsbNoAggToIpaPipeAgg(IPA_CLIENT_TEST3_PROD,
|
||||
IPA_TEST_CONFIGURATION_8);
|
||||
Pipe TLPAggregationTestFixture::m_UsbDeaggToIpaPipeNoAgg(IPA_CLIENT_TEST_PROD,
|
||||
IPA_TEST_CONFIGURATION_8);
|
||||
Pipe TLPAggregationTestFixture::m_UsbDeaggToIpaPipeAgg(IPA_CLIENT_TEST2_PROD,
|
||||
IPA_TEST_CONFIGURATION_8);
|
||||
Pipe TLPAggregationTestFixture::m_IpaToUsbPipeAggTime(IPA_CLIENT_TEST2_CONS,
|
||||
IPA_TEST_CONFIGURATION_8);
|
||||
Pipe TLPAggregationTestFixture::m_UsbNoAggToIpaPipeAggTime(IPA_CLIENT_TEST4_PROD,
|
||||
IPA_TEST_CONFIGURATION_8);
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TLPAggregationTestFixture::TLPAggregationTestFixture()
|
||||
{
|
||||
m_testSuiteName.push_back("TLPAgg");
|
||||
m_maxIPAHwType = IPA_HW_v2_6L;
|
||||
Register(*this);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool TLPAggregationTestFixture::Setup()
|
||||
{
|
||||
bool bRetVal = true;
|
||||
|
||||
//Set the configuration to support USB->IPA and IPA->USB pipes.
|
||||
ConfigureScenario(8);
|
||||
|
||||
//Initialize the pipe for all the tests - this will open the inode which represents the pipe.
|
||||
bRetVal &= m_IpaToUsbPipeNoAgg.Init();
|
||||
bRetVal &= m_IpaToUsbPipeAggr.Init();
|
||||
bRetVal &= m_UsbNoAggToIpaPipeAgg.Init();
|
||||
bRetVal &= m_UsbDeaggToIpaPipeNoAgg.Init();
|
||||
bRetVal &= m_UsbDeaggToIpaPipeAgg.Init();
|
||||
bRetVal &= m_IpaToUsbPipeAggTime.Init();
|
||||
bRetVal &= m_UsbNoAggToIpaPipeAggTime.Init();
|
||||
return bRetVal;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool TLPAggregationTestFixture::Teardown()
|
||||
{
|
||||
//The Destroy method will close the inode.
|
||||
m_IpaToUsbPipeNoAgg.Destroy();
|
||||
m_IpaToUsbPipeAggr.Destroy();
|
||||
m_UsbNoAggToIpaPipeAgg.Destroy();
|
||||
m_UsbDeaggToIpaPipeNoAgg.Destroy();
|
||||
m_UsbDeaggToIpaPipeAgg.Destroy();
|
||||
m_IpaToUsbPipeAggTime.Destroy();
|
||||
m_UsbNoAggToIpaPipeAggTime.Destroy();
|
||||
return true;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (c) 2017 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "Constants.h"
|
||||
#include "Logger.h"
|
||||
#include "linux/msm_ipa.h"
|
||||
#include "TestsUtils.h"
|
||||
#include "TestBase.h"
|
||||
#include "Pipe.h"
|
||||
|
||||
/*This class will be the base class of all TLP Aggregation tests.
|
||||
*Any method other than the test case itself can be declared in
|
||||
*this Fixture thus allowing the derived classes to
|
||||
*implement only the test case.
|
||||
*All the test of the Aggregation uses one
|
||||
*input and one output in DMA mode.
|
||||
*/
|
||||
class TLPAggregationTestFixture:public TestBase
|
||||
{
|
||||
public:
|
||||
/*This Constructor will register each instance that it creates.*/
|
||||
TLPAggregationTestFixture();
|
||||
|
||||
/*This method will create and initialize two Pipe object for the
|
||||
*USB (Ethernet) Pipes, one as input and the other as output.
|
||||
*/
|
||||
virtual bool Setup();
|
||||
|
||||
/*This method will destroy the pipes.*/
|
||||
virtual bool Teardown();
|
||||
|
||||
/*The client type are set from the peripheral perspective*/
|
||||
static Pipe m_IpaToUsbPipeNoAgg;
|
||||
static Pipe m_IpaToUsbPipeAggr;
|
||||
static Pipe m_UsbNoAggToIpaPipeAgg;
|
||||
static Pipe m_UsbDeaggToIpaPipeNoAgg;
|
||||
static Pipe m_UsbDeaggToIpaPipeAgg;
|
||||
static Pipe m_IpaToUsbPipeAggTime;
|
||||
static Pipe m_UsbNoAggToIpaPipeAggTime;
|
||||
};
|
||||
946
qcom/opensource/dataipa/kernel-tests/TLPAggregationTests.cpp
Normal file
946
qcom/opensource/dataipa/kernel-tests/TLPAggregationTests.cpp
Normal file
@@ -0,0 +1,946 @@
|
||||
/*
|
||||
* Copyright (c) 2017 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "TLPAggregationTestFixture.h"
|
||||
#include "Constants.h"
|
||||
#include "TestsUtils.h"
|
||||
#include "linux/msm_ipa.h"
|
||||
|
||||
#define NUM_PACKETS 5
|
||||
#define TIME_LIMIT_NUM_PACKETS 1
|
||||
#define MAX_PACKET_SIZE 1024
|
||||
#define AGGREGATION_LOOP 4
|
||||
|
||||
int test_num = 0;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class TLPAggregationTest: public TLPAggregationTestFixture {
|
||||
public:
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TLPAggregationTest()
|
||||
{
|
||||
m_name = "TLPAggregationTest";
|
||||
m_description = "TLP Aggregation test - sends 5 packets and receives 1 "
|
||||
"aggregated packet";
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool Run()
|
||||
{
|
||||
bool bTestResult = true;
|
||||
//The packets that will be sent
|
||||
Byte pPackets[NUM_PACKETS][MAX_PACKET_SIZE];
|
||||
//The real sizes of the packets that will be sent
|
||||
int pPacketsSizes[NUM_PACKETS];
|
||||
//Buffer for the packet that will be received
|
||||
Byte pReceivedPacket[MAX_PACKET_SIZE];
|
||||
//Total size of all sent packets (this is the max size of the aggregated packet
|
||||
//minus 2 bytes for each packet in the aggregated packet)
|
||||
int nTotalPacketsSize = MAX_PACKET_SIZE - (2 * NUM_PACKETS);
|
||||
//The expected aggregated packet
|
||||
Byte pExpectedAggregatedPacket[MAX_PACKET_SIZE] = {0};
|
||||
|
||||
//initialize the packets
|
||||
//example: for NUM_PACKETS = 5 and MAX_PACKET_SIZE = 1024:
|
||||
//nTotalPacketsSize will be 1024 - 5*2 = 1014
|
||||
//packets[0] size will be 1014/5 = 202 bytes of 0
|
||||
//packets[1] size will be (1014 - 202) / 5 = 162 bytes of 1
|
||||
//packets[2] size will be (1014 - 201 - 162) / 5 = 130 bytes of 2
|
||||
//packets[3] size will be (1014 - 201 - 162 - 130) / 5 = 104 bytes of 3
|
||||
//packets[4] size will be 1014 - 201 - 162 - 130 - 104 = 416 bytes of 4
|
||||
for (int i = 0; i < NUM_PACKETS; i++)
|
||||
{
|
||||
if (NUM_PACKETS - 1 == i)
|
||||
pPacketsSizes[i] = nTotalPacketsSize;
|
||||
else
|
||||
pPacketsSizes[i] = nTotalPacketsSize / NUM_PACKETS;
|
||||
nTotalPacketsSize -= pPacketsSizes[i];
|
||||
for (int j = 0; j < pPacketsSizes[i]; j++)
|
||||
pPackets[i][j] = i + 16*test_num;
|
||||
}
|
||||
test_num++;
|
||||
|
||||
//send the packets
|
||||
for (int i = 0; i < NUM_PACKETS; i++)
|
||||
{
|
||||
LOG_MSG_DEBUG("Sending packet %d into the USB pipe(%d bytes)\n", i,
|
||||
pPacketsSizes[i]);
|
||||
int nBytesSent = m_UsbNoAggToIpaPipeAgg.Send(pPackets[i],
|
||||
pPacketsSizes[i]);
|
||||
if (pPacketsSizes[i] != nBytesSent)
|
||||
{
|
||||
LOG_MSG_DEBUG("Sending packet %d into the USB pipe(%d bytes) "
|
||||
"failed!\n", i, pPacketsSizes[i]);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//receive the aggregated packet
|
||||
LOG_MSG_DEBUG("Reading packet from the USB pipe(%d bytes should be "
|
||||
"there)\n", MAX_PACKET_SIZE);
|
||||
int nBytesReceived = m_IpaToUsbPipeAggr.Receive(pReceivedPacket,
|
||||
MAX_PACKET_SIZE);
|
||||
if (MAX_PACKET_SIZE != nBytesReceived)
|
||||
{
|
||||
LOG_MSG_DEBUG("Receiving aggregated packet from the USB pipe(%d "
|
||||
"bytes) failed!\n", MAX_PACKET_SIZE);
|
||||
print_buff(pReceivedPacket, nBytesReceived);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//initializing the aggregated packet
|
||||
int k = 0;
|
||||
for (int i = 0; i < NUM_PACKETS; i++)
|
||||
{
|
||||
//the first 2 bytes are the packet length in little endian
|
||||
pExpectedAggregatedPacket[k] = pPacketsSizes[i] & 0x00FF;
|
||||
pExpectedAggregatedPacket[k+1] = pPacketsSizes[i] >> 8;
|
||||
k += 2;
|
||||
for (int j = 0; j < pPacketsSizes[i]; j++)
|
||||
{
|
||||
pExpectedAggregatedPacket[k] = pPackets[i][j];
|
||||
k++;
|
||||
}
|
||||
}
|
||||
|
||||
//comparing the received packet to the aggregated packet
|
||||
LOG_MSG_DEBUG("Checking sent.vs.received packet\n");
|
||||
|
||||
bTestResult &= !memcmp(pExpectedAggregatedPacket, pReceivedPacket,
|
||||
sizeof(pReceivedPacket));
|
||||
|
||||
return bTestResult;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class TLPDeaggregationTest: public TLPAggregationTestFixture {
|
||||
public:
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TLPDeaggregationTest()
|
||||
{
|
||||
m_name = "TLPDeaggregationTest";
|
||||
m_description = "TLP Deaggregation test - sends an aggregated packet made from"
|
||||
"5 packets and receives 5 packets";
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool Run()
|
||||
{
|
||||
bool bTestResult = true;
|
||||
//The packets that the aggregated packet will be made of
|
||||
Byte pExpectedPackets[NUM_PACKETS][MAX_PACKET_SIZE];
|
||||
//The real sizes of the packets that the aggregated packet will be made of
|
||||
int pPacketsSizes[NUM_PACKETS];
|
||||
//Buffers for the packets that will be received
|
||||
Byte pReceivedPackets[NUM_PACKETS][MAX_PACKET_SIZE];
|
||||
//Total size of all the packets that the aggregated packet will be made of
|
||||
//(this is the max size of the aggregated packet
|
||||
//minus 2 bytes for each packet in the aggregated packet)
|
||||
int nTotalPacketsSize = MAX_PACKET_SIZE - (2 * NUM_PACKETS);
|
||||
//The aggregated packet that will be sent
|
||||
Byte pAggregatedPacket[MAX_PACKET_SIZE] = {0};
|
||||
|
||||
//initialize the packets
|
||||
//example: for NUM_PACKETS = 5 and MAX_PACKET_SIZE = 1024:
|
||||
//nTotalPacketsSize will be 1024 - 5*2 = 1014
|
||||
//packets[0] size will be 1014/5 = 202 bytes of 0
|
||||
//packets[1] size will be (1014 - 202) / 5 = 162 bytes of 1
|
||||
//packets[2] size will be (1014 - 201 - 162) / 5 = 130 bytes of 2
|
||||
//packets[3] size will be (1014 - 201 - 162 - 130) / 5 = 104 bytes of 3
|
||||
//packets[4] size will be 1014 - 201 - 162 - 130 - 104 = 416 bytes of 4
|
||||
for (int i = 0; i < NUM_PACKETS; i++)
|
||||
{
|
||||
if (NUM_PACKETS - 1 == i)
|
||||
pPacketsSizes[i] = nTotalPacketsSize;
|
||||
else
|
||||
pPacketsSizes[i] = nTotalPacketsSize / NUM_PACKETS;
|
||||
nTotalPacketsSize -= pPacketsSizes[i];
|
||||
for (int j = 0; j < pPacketsSizes[i]; j++)
|
||||
pExpectedPackets[i][j] = i+ 16*test_num;
|
||||
}
|
||||
test_num++;
|
||||
|
||||
//initializing the aggregated packet
|
||||
int k = 0;
|
||||
for (int i = 0; i < NUM_PACKETS; i++)
|
||||
{
|
||||
//the first 2 bytes are the packet length in little endian
|
||||
pAggregatedPacket[k] = pPacketsSizes[i] & 0x00FF;
|
||||
pAggregatedPacket[k+1] = pPacketsSizes[i] >> 8;
|
||||
k += 2;
|
||||
for (int j = 0; j < pPacketsSizes[i]; j++)
|
||||
{
|
||||
pAggregatedPacket[k] = pExpectedPackets[i][j];
|
||||
k++;
|
||||
}
|
||||
}
|
||||
|
||||
//send the aggregated packet
|
||||
LOG_MSG_DEBUG("Sending aggregated packet into the USB pipe(%d bytes)\n",
|
||||
sizeof(pAggregatedPacket));
|
||||
int nBytesSent = m_UsbDeaggToIpaPipeNoAgg.Send(pAggregatedPacket,
|
||||
sizeof(pAggregatedPacket));
|
||||
if (sizeof(pAggregatedPacket) != nBytesSent)
|
||||
{
|
||||
LOG_MSG_DEBUG("Sending aggregated packet into the USB pipe(%d bytes) "
|
||||
"failed!\n", sizeof(pAggregatedPacket));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//receive the packets
|
||||
for (int i = 0; i < NUM_PACKETS; i++)
|
||||
{
|
||||
LOG_MSG_DEBUG("Reading packet %d from the USB pipe(%d bytes should be "
|
||||
"there)\n", i, pPacketsSizes[i]);
|
||||
int nBytesReceived = m_IpaToUsbPipeNoAgg.Receive(pReceivedPackets[i],
|
||||
pPacketsSizes[i]);
|
||||
if (pPacketsSizes[i] != nBytesReceived)
|
||||
{
|
||||
LOG_MSG_DEBUG("Receiving packet %d from the USB pipe(%d bytes) "
|
||||
"failed!\n", i, pPacketsSizes[i]);
|
||||
print_buff(pReceivedPackets[i], nBytesReceived);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//comparing the received packet to the aggregated packet
|
||||
LOG_MSG_DEBUG("Checking sent.vs.received packet\n");
|
||||
for (int i = 0; i < NUM_PACKETS; i++)
|
||||
bTestResult &= !memcmp(pExpectedPackets[i], pReceivedPackets[i], pPacketsSizes[i]);
|
||||
|
||||
return bTestResult;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
class TLPDeaggregationAndAggregationTest: public TLPAggregationTestFixture {
|
||||
public:
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TLPDeaggregationAndAggregationTest()
|
||||
{
|
||||
m_name = "TLPDeaggregationAndAggregationTest";
|
||||
m_description = "TLP Deaggregation and Aggregation test - sends an aggregated "
|
||||
"packet made from 5 packets and receives the same aggregated packet";
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool Run()
|
||||
{
|
||||
bool bTestResult = true;
|
||||
//The packets that the aggregated packet will be made of
|
||||
Byte pPackets[NUM_PACKETS][MAX_PACKET_SIZE];
|
||||
//The real sizes of the packets that the aggregated packet will be made of
|
||||
int pPacketsSizes[NUM_PACKETS];
|
||||
//Buffers for the packets that will be received
|
||||
Byte pReceivedPacket[MAX_PACKET_SIZE];
|
||||
//Total size of all the packets that the aggregated packet will be made of
|
||||
//(this is the max size of the aggregated packet
|
||||
//minus 2 bytes for each packet in the aggregated packet)
|
||||
int nTotalPacketsSize = MAX_PACKET_SIZE - (2 * NUM_PACKETS);
|
||||
//The aggregated packet that will be sent
|
||||
Byte pAggregatedPacket[MAX_PACKET_SIZE] = {0};
|
||||
|
||||
//initialize the packets
|
||||
//example: for NUM_PACKETS = 5 and MAX_PACKET_SIZE = 1024:
|
||||
//nTotalPacketsSize will be 1024 - 5*2 = 1014
|
||||
//packets[0] size will be 1014/5 = 202 bytes of 0
|
||||
//packets[1] size will be (1014 - 202) / 5 = 162 bytes of 1
|
||||
//packets[2] size will be (1014 - 201 - 162) / 5 = 130 bytes of 2
|
||||
//packets[3] size will be (1014 - 201 - 162 - 130) / 5 = 104 bytes of 3
|
||||
//packets[4] size will be 1014 - 201 - 162 - 130 - 104 = 416 bytes of 4
|
||||
for (int i = 0; i < NUM_PACKETS; i++)
|
||||
{
|
||||
if (NUM_PACKETS - 1 == i)
|
||||
pPacketsSizes[i] = nTotalPacketsSize;
|
||||
else
|
||||
pPacketsSizes[i] = nTotalPacketsSize / NUM_PACKETS;
|
||||
nTotalPacketsSize -= pPacketsSizes[i];
|
||||
for (int j = 0; j < pPacketsSizes[i]; j++)
|
||||
pPackets[i][j] = i+ 16*test_num;
|
||||
}
|
||||
test_num++;
|
||||
|
||||
//initializing the aggregated packet
|
||||
int k = 0;
|
||||
for (int i = 0; i < NUM_PACKETS; i++)
|
||||
{
|
||||
//the first 2 bytes are the packet length in little endian
|
||||
pAggregatedPacket[k] = pPacketsSizes[i] & 0x00FF;
|
||||
pAggregatedPacket[k+1] = pPacketsSizes[i] >> 8;
|
||||
k += 2;
|
||||
for (int j = 0; j < pPacketsSizes[i]; j++)
|
||||
{
|
||||
pAggregatedPacket[k] = pPackets[i][j];
|
||||
k++;
|
||||
}
|
||||
}
|
||||
|
||||
//send the aggregated packet
|
||||
LOG_MSG_DEBUG("Sending aggregated packet into the USB pipe(%d bytes)\n",
|
||||
sizeof(pAggregatedPacket));
|
||||
int nBytesSent = m_UsbDeaggToIpaPipeAgg.Send(pAggregatedPacket,
|
||||
sizeof(pAggregatedPacket));
|
||||
if (sizeof(pAggregatedPacket) != nBytesSent)
|
||||
{
|
||||
LOG_MSG_DEBUG("Sending aggregated packet into the USB pipe(%d bytes)"
|
||||
" failed!\n", sizeof(pAggregatedPacket));
|
||||
return false;
|
||||
}
|
||||
|
||||
//receive the aggregated packet
|
||||
LOG_MSG_DEBUG("Reading aggregated packet from the USB pipe(%d bytes "
|
||||
"should be there)\n", sizeof(pAggregatedPacket));
|
||||
int nBytesReceived = m_IpaToUsbPipeAggr.Receive(pReceivedPacket,
|
||||
sizeof(pAggregatedPacket));
|
||||
if (sizeof(pAggregatedPacket) != nBytesReceived)
|
||||
{
|
||||
LOG_MSG_DEBUG("Receiving aggregated packet from the USB pipe(%d "
|
||||
"bytes) failed!\n", sizeof(pAggregatedPacket));
|
||||
LOG_MSG_DEBUG("Received %d bytes\n", nBytesReceived);
|
||||
print_buff(pReceivedPacket, nBytesReceived);
|
||||
return false;
|
||||
}
|
||||
print_buff(pReceivedPacket, nBytesReceived);
|
||||
|
||||
//comparing the received packet to the aggregated packet
|
||||
LOG_MSG_DEBUG("Checking sent.vs.received packet\n");
|
||||
bTestResult &= !memcmp(pAggregatedPacket, pReceivedPacket,
|
||||
sizeof(pReceivedPacket));
|
||||
|
||||
|
||||
return bTestResult;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class TLPAggregationLoopTest: public TLPAggregationTestFixture {
|
||||
public:
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TLPAggregationLoopTest()
|
||||
{
|
||||
m_name = "TLPAggregationLoopTest";
|
||||
m_description = "TLP Aggregation Loop test - sends 5 packets and expects to"
|
||||
"receives 1 aggregated packet a few times";
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool Run()
|
||||
{
|
||||
//The packets that will be sent
|
||||
Byte pPackets[NUM_PACKETS][MAX_PACKET_SIZE];
|
||||
//The real sizes of the packets that will be sent
|
||||
int pPacketsSizes[NUM_PACKETS];
|
||||
//Buffer for the packet that will be received
|
||||
Byte pReceivedPacket[MAX_PACKET_SIZE];
|
||||
//Total size of all sent packets (this is the max size of the aggregated packet
|
||||
//minus 2 bytes for each packet in the aggregated packet)
|
||||
int nTotalPacketsSize = MAX_PACKET_SIZE - (2 * NUM_PACKETS);
|
||||
//The expected aggregated packet
|
||||
Byte pExpectedAggregatedPacket[MAX_PACKET_SIZE] = {0};
|
||||
|
||||
//initialize the packets
|
||||
//example: for NUM_PACKETS = 5 and MAX_PACKET_SIZE = 1024:
|
||||
//nTotalPacketsSize will be 1024 - 5*2 = 1014
|
||||
//packets[0] size will be 1014/5 = 202 bytes of 0
|
||||
//packets[1] size will be (1014 - 202) / 5 = 162 bytes of 1
|
||||
//packets[2] size will be (1014 - 201 - 162) / 5 = 130 bytes of 2
|
||||
//packets[3] size will be (1014 - 201 - 162 - 130) / 5 = 104 bytes of 3
|
||||
//packets[4] size will be 1014 - 201 - 162 - 130 - 104 = 416 bytes of 4
|
||||
for (int i = 0; i < NUM_PACKETS; i++)
|
||||
{
|
||||
if (NUM_PACKETS - 1 == i)
|
||||
pPacketsSizes[i] = nTotalPacketsSize;
|
||||
else
|
||||
pPacketsSizes[i] = nTotalPacketsSize / NUM_PACKETS;
|
||||
nTotalPacketsSize -= pPacketsSizes[i];
|
||||
for (int j = 0; j < pPacketsSizes[i]; j++)
|
||||
pPackets[i][j] = i+ 16*test_num;
|
||||
}
|
||||
test_num++;
|
||||
|
||||
//initializing the aggregated packet
|
||||
int k = 0;
|
||||
for (int i = 0; i < NUM_PACKETS; i++)
|
||||
{
|
||||
//the first 2 bytes are the packet length in little endian
|
||||
pExpectedAggregatedPacket[k] = pPacketsSizes[i] & 0x00FF;
|
||||
pExpectedAggregatedPacket[k+1] = pPacketsSizes[i] >> 8;
|
||||
k += 2;
|
||||
for (int j = 0; j < pPacketsSizes[i]; j++)
|
||||
{
|
||||
pExpectedAggregatedPacket[k] = pPackets[i][j];
|
||||
k++;
|
||||
}
|
||||
}
|
||||
|
||||
for (int j = 0; j < AGGREGATION_LOOP; j++)
|
||||
{
|
||||
//send the packets
|
||||
for (int i = 0; i < NUM_PACKETS; i++)
|
||||
{
|
||||
LOG_MSG_DEBUG("Sending packet %d into the USB pipe(%d bytes)\n",
|
||||
i, pPacketsSizes[i]);
|
||||
int nBytesSent = m_UsbNoAggToIpaPipeAgg.Send(pPackets[i],
|
||||
pPacketsSizes[i]);
|
||||
if (pPacketsSizes[i] != nBytesSent)
|
||||
{
|
||||
LOG_MSG_DEBUG("Sending packet %d into the USB pipe(%d bytes) "
|
||||
"failed!\n", i, pPacketsSizes[i]);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
memset(pReceivedPacket, 0, sizeof(pReceivedPacket));
|
||||
//receive the aggregated packet
|
||||
LOG_MSG_DEBUG("Reading packet from the USB pipe(%d bytes should be "
|
||||
"there)\n", MAX_PACKET_SIZE);
|
||||
int nBytesReceived = m_IpaToUsbPipeAggr.Receive(pReceivedPacket,
|
||||
MAX_PACKET_SIZE);
|
||||
if (MAX_PACKET_SIZE != nBytesReceived)
|
||||
{
|
||||
LOG_MSG_DEBUG("Receiving aggregated packet from the USB pipe(%d "
|
||||
"bytes) failed!\n", MAX_PACKET_SIZE);
|
||||
return false;
|
||||
}
|
||||
|
||||
//comparing the received packet to the aggregated packet
|
||||
LOG_MSG_DEBUG("Checking sent.vs.received packet\n");
|
||||
|
||||
if (0 != memcmp(pExpectedAggregatedPacket, pReceivedPacket,
|
||||
sizeof(pReceivedPacket)))
|
||||
{
|
||||
LOG_MSG_DEBUG("Comparison of packet %d failed!\n", j);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class TLPAggregationTimeLimitTest: public TLPAggregationTestFixture {
|
||||
public:
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TLPAggregationTimeLimitTest()
|
||||
{
|
||||
m_name = "TLPAggregationTimeLimitTest";
|
||||
m_description = "TLP Aggregation time limit test - sends 1 packet "
|
||||
"smaller than the byte limit and receives 1 aggregated packet";
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool Run()
|
||||
{
|
||||
bool bTestResult = true;
|
||||
//The packets that will be sent
|
||||
Byte pPackets[TIME_LIMIT_NUM_PACKETS][MAX_PACKET_SIZE];
|
||||
//The real sizes of the packets that will be sent
|
||||
int pPacketsSizes[TIME_LIMIT_NUM_PACKETS];
|
||||
//Buffer for the packet that will be received
|
||||
Byte pReceivedPacket[MAX_PACKET_SIZE] = {0};
|
||||
//The expected aggregated packet
|
||||
Byte pExpectedAggregatedPacket[MAX_PACKET_SIZE] = {0};
|
||||
//Size of aggregated packet
|
||||
int nTotalPacketsSize = 0;
|
||||
|
||||
//initialize the packets
|
||||
for (int i = 0; i < TIME_LIMIT_NUM_PACKETS; i++)
|
||||
{
|
||||
pPacketsSizes[i] = i + 1;
|
||||
nTotalPacketsSize += pPacketsSizes[i] + 2; //size of the packet + 2 bytes for length
|
||||
for (int j = 0; j < pPacketsSizes[i]; j++)
|
||||
pPackets[i][j] = i+ 16*test_num;
|
||||
}
|
||||
test_num++;
|
||||
|
||||
//send the packets
|
||||
for (int i = 0; i < TIME_LIMIT_NUM_PACKETS; i++)
|
||||
{
|
||||
LOG_MSG_DEBUG("Sending packet %d into the USB pipe(%d bytes)\n", i,
|
||||
pPacketsSizes[i]);
|
||||
int nBytesSent = m_UsbNoAggToIpaPipeAggTime.Send(pPackets[i],
|
||||
pPacketsSizes[i]);
|
||||
if (pPacketsSizes[i] != nBytesSent)
|
||||
{
|
||||
LOG_MSG_DEBUG("Sending packet %d into the USB pipe(%d bytes) "
|
||||
"failed!\n", i, pPacketsSizes[i]);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//receive the aggregated packet
|
||||
LOG_MSG_DEBUG("Reading packet from the USB pipe(%d bytes should be "
|
||||
"there)\n", nTotalPacketsSize);
|
||||
int nBytesReceived = m_IpaToUsbPipeAggTime.Receive(pReceivedPacket,
|
||||
nTotalPacketsSize);
|
||||
if (nTotalPacketsSize != nBytesReceived)
|
||||
{
|
||||
LOG_MSG_DEBUG("Receiving aggregated packet from the USB pipe(%d "
|
||||
"bytes) failed!\n", nTotalPacketsSize);
|
||||
print_buff(pReceivedPacket, nBytesReceived);
|
||||
return false;
|
||||
}
|
||||
|
||||
//initializing the aggregated packet
|
||||
int k = 0;
|
||||
for (int i = 0; i < TIME_LIMIT_NUM_PACKETS; i++)
|
||||
{
|
||||
//the first 2 bytes are the packet length in little endian
|
||||
pExpectedAggregatedPacket[k] = pPacketsSizes[i] & 0x00FF;
|
||||
pExpectedAggregatedPacket[k+1] = pPacketsSizes[i] >> 8;
|
||||
k += 2;
|
||||
for (int j = 0; j < pPacketsSizes[i]; j++)
|
||||
{
|
||||
pExpectedAggregatedPacket[k] = pPackets[i][j];
|
||||
k++;
|
||||
}
|
||||
}
|
||||
|
||||
//comparing the received packet to the aggregated packet
|
||||
LOG_MSG_DEBUG("Checking sent.vs.received packet\n");
|
||||
|
||||
bTestResult &= !memcmp(pExpectedAggregatedPacket, pReceivedPacket,
|
||||
sizeof(pReceivedPacket));
|
||||
|
||||
return bTestResult;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class TLPAggregationByteLimitTest: public TLPAggregationTestFixture {
|
||||
public:
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TLPAggregationByteLimitTest()
|
||||
{
|
||||
m_name = "TLPAggregationByteLimitTest";
|
||||
m_description = "TLP Aggregation byte limit test - sends 2 packets that together "
|
||||
"are larger than the byte limit ";
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool Run()
|
||||
{
|
||||
bool bTestResult = true;
|
||||
//The packets that will be sent
|
||||
Byte pPackets[2][MAX_PACKET_SIZE];
|
||||
//The real sizes of the packets that will be sent
|
||||
int pPacketsSizes[2];
|
||||
//Buffer for the packet that will be received
|
||||
Byte pReceivedPacket[2*MAX_PACKET_SIZE] = {0};
|
||||
//The expected aggregated packet
|
||||
Byte pExpectedAggregatedPacket[2*MAX_PACKET_SIZE] = {0};
|
||||
//Size of aggregated packet
|
||||
int nTotalPacketsSize = 0;
|
||||
|
||||
//initialize the packets
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
pPacketsSizes[i] = (MAX_PACKET_SIZE / 2) + 10;
|
||||
nTotalPacketsSize += pPacketsSizes[i] + 2;
|
||||
for (int j = 0; j < pPacketsSizes[i]; j++)
|
||||
pPackets[i][j] = i+ 16*test_num;
|
||||
}
|
||||
test_num++;
|
||||
|
||||
//send the packets
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
LOG_MSG_DEBUG("Sending packet %d into the USB pipe(%d bytes)\n", i,
|
||||
pPacketsSizes[i]);
|
||||
int nBytesSent = m_UsbNoAggToIpaPipeAgg.Send(pPackets[i],
|
||||
pPacketsSizes[i]);
|
||||
if (pPacketsSizes[i] != nBytesSent)
|
||||
{
|
||||
LOG_MSG_DEBUG("Sending packet %d into the USB pipe(%d bytes) "
|
||||
"failed!\n", i, pPacketsSizes[i]);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//receive the aggregated packet
|
||||
LOG_MSG_DEBUG("Reading packet from the USB pipe(%d bytes should be "
|
||||
"there)\n", nTotalPacketsSize);
|
||||
int nBytesReceived = m_IpaToUsbPipeAggr.Receive(pReceivedPacket,
|
||||
nTotalPacketsSize);
|
||||
if (nTotalPacketsSize != nBytesReceived)
|
||||
{
|
||||
LOG_MSG_DEBUG("Receiving aggregated packet from the USB pipe(%d"
|
||||
" bytes) failed!\n", nTotalPacketsSize);
|
||||
print_buff(pReceivedPacket, nBytesReceived);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//initializing the aggregated packet
|
||||
int k = 0;
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
//the first 2 bytes are the packet length in little endian
|
||||
pExpectedAggregatedPacket[k] = pPacketsSizes[i] & 0x00FF;
|
||||
pExpectedAggregatedPacket[k+1] = pPacketsSizes[i] >> 8;
|
||||
k += 2;
|
||||
for (int j = 0; j < pPacketsSizes[i]; j++)
|
||||
{
|
||||
pExpectedAggregatedPacket[k] = pPackets[i][j];
|
||||
k++;
|
||||
}
|
||||
}
|
||||
|
||||
//comparing the received packet to the aggregated packet
|
||||
LOG_MSG_DEBUG("Checking sent.vs.received packet\n");
|
||||
|
||||
bTestResult &= !memcmp(pExpectedAggregatedPacket, pReceivedPacket,
|
||||
sizeof(pReceivedPacket));
|
||||
|
||||
return bTestResult;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class TLPAggregation2PipesTest: public TLPAggregationTestFixture {
|
||||
public:
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TLPAggregation2PipesTest()
|
||||
{
|
||||
m_name = "TLPAggregation2PipesTest";
|
||||
m_description = "TLP Aggregation 2 pipes test - sends 3 packets from one pipe"
|
||||
"and an aggregated packet made of 2 packets from another pipe and "
|
||||
"receives 1 aggregated packet made of all 5 packets";
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool Run()
|
||||
{
|
||||
bool bTestResult = true;
|
||||
//The packets that will be sent
|
||||
Byte pPackets[NUM_PACKETS][MAX_PACKET_SIZE];
|
||||
//The real sizes of the packets that will be sent
|
||||
int pPacketsSizes[NUM_PACKETS];
|
||||
//Buffer for the packet that will be received
|
||||
Byte pReceivedPacket[MAX_PACKET_SIZE];
|
||||
//Total size of all sent packets (this is the max size of the aggregated packet
|
||||
//minus 2 bytes for each packet in the aggregated packet)
|
||||
int nTotalPacketsSize = MAX_PACKET_SIZE - (2 * NUM_PACKETS);
|
||||
//The expected aggregated packet
|
||||
Byte pExpectedAggregatedPacket[MAX_PACKET_SIZE] = {0};
|
||||
//The aggregated packet that will be sent
|
||||
Byte pAggregatedPacket[MAX_PACKET_SIZE] = {0};
|
||||
//The size of the sent aggregated packet
|
||||
int nAggregatedPacketSize = 0;
|
||||
|
||||
//initialize the packets
|
||||
//example: for NUM_PACKETS = 5 and MAX_PACKET_SIZE = 1024:
|
||||
//nTotalPacketsSize will be 1024 - 5*2 = 1014
|
||||
//packets[0] size will be 1014/5 = 202 bytes of 0
|
||||
//packets[1] size will be (1014 - 202) / 5 = 162 bytes of 1
|
||||
//packets[2] size will be (1014 - 201 - 162) / 5 = 130 bytes of 2
|
||||
//packets[3] size will be (1014 - 201 - 162 - 130) / 5 = 104 bytes of 3
|
||||
//packets[4] size will be 1014 - 201 - 162 - 130 - 104 = 416 bytes of 4
|
||||
for (int i = 0; i < NUM_PACKETS; i++)
|
||||
{
|
||||
if (NUM_PACKETS - 1 == i)
|
||||
pPacketsSizes[i] = nTotalPacketsSize;
|
||||
else
|
||||
pPacketsSizes[i] = nTotalPacketsSize / NUM_PACKETS;
|
||||
nTotalPacketsSize -= pPacketsSizes[i];
|
||||
for (int j = 0; j < pPacketsSizes[i]; j++)
|
||||
pPackets[i][j] = i+ 16*test_num;
|
||||
}
|
||||
test_num++;
|
||||
|
||||
//initializing the aggregated packet
|
||||
int k = 0;
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
nAggregatedPacketSize += pPacketsSizes[i] + 2;
|
||||
//the first 2 bytes are the packet length in little endian
|
||||
pAggregatedPacket[k] = pPacketsSizes[i] & 0x00FF;
|
||||
pAggregatedPacket[k+1] = pPacketsSizes[i] >> 8;
|
||||
k += 2;
|
||||
for (int j = 0; j < pPacketsSizes[i]; j++)
|
||||
{
|
||||
pAggregatedPacket[k] = pPackets[i][j];
|
||||
k++;
|
||||
}
|
||||
}
|
||||
|
||||
//send the aggregated packet
|
||||
LOG_MSG_DEBUG("Sending aggregated packet into the USB pipe(%d "
|
||||
"bytes)\n", nAggregatedPacketSize);
|
||||
int nBytesSent = m_UsbDeaggToIpaPipeAgg.Send(pAggregatedPacket,
|
||||
nAggregatedPacketSize);
|
||||
if (nAggregatedPacketSize != nBytesSent)
|
||||
{
|
||||
LOG_MSG_DEBUG("Sending aggregated packet into the USB pipe(%d "
|
||||
"bytes) failed!\n", nAggregatedPacketSize);
|
||||
return false;
|
||||
}
|
||||
|
||||
//send the packets
|
||||
for (int i = 2; i < NUM_PACKETS; i++)
|
||||
{
|
||||
LOG_MSG_DEBUG("Sending packet %d into the USB pipe(%d bytes)\n", i,
|
||||
pPacketsSizes[i]);
|
||||
int nBytesSent = m_UsbNoAggToIpaPipeAgg.Send(pPackets[i],
|
||||
pPacketsSizes[i]);
|
||||
if (pPacketsSizes[i] != nBytesSent)
|
||||
{
|
||||
LOG_MSG_DEBUG("Sending packet %d into the USB pipe(%d bytes) "
|
||||
"failed!\n", i, pPacketsSizes[i]);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//receive the aggregated packet
|
||||
LOG_MSG_DEBUG("Reading packet from the USB pipe(%d bytes should be "
|
||||
"there)\n", MAX_PACKET_SIZE);
|
||||
int nBytesReceived = m_IpaToUsbPipeAggr.Receive(pReceivedPacket,
|
||||
MAX_PACKET_SIZE);
|
||||
if (MAX_PACKET_SIZE != nBytesReceived)
|
||||
{
|
||||
LOG_MSG_DEBUG("Receiving aggregated packet from the USB pipe(%d "
|
||||
"bytes) failed!\n", MAX_PACKET_SIZE);
|
||||
print_buff(pReceivedPacket, nBytesReceived);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//initializing the aggregated packet
|
||||
k = 0;
|
||||
for (int i = 0; i < NUM_PACKETS; i++)
|
||||
{
|
||||
//the first 2 bytes are the packet length in little endian
|
||||
pExpectedAggregatedPacket[k] = pPacketsSizes[i] & 0x00FF;
|
||||
pExpectedAggregatedPacket[k+1] = pPacketsSizes[i] >> 8;
|
||||
k += 2;
|
||||
for (int j = 0; j < pPacketsSizes[i]; j++)
|
||||
{
|
||||
pExpectedAggregatedPacket[k] = pPackets[i][j];
|
||||
k++;
|
||||
}
|
||||
}
|
||||
|
||||
//comparing the received packet to the aggregated packet
|
||||
LOG_MSG_DEBUG("Checking sent.vs.received packet\n");
|
||||
|
||||
bTestResult &= !memcmp(pExpectedAggregatedPacket, pReceivedPacket,
|
||||
sizeof(pReceivedPacket));
|
||||
|
||||
return bTestResult;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class TLPAggregationTimeLimitLoopTest: public TLPAggregationTestFixture {
|
||||
public:
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TLPAggregationTimeLimitLoopTest()
|
||||
{
|
||||
m_name = "TLPAggregationTimeLimitLoopTest";
|
||||
m_description = "TLP Aggregation time limit loop test - sends 1 packet "
|
||||
"smaller than the byte limit and receives 1 aggregated packets";
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool Run()
|
||||
{
|
||||
//The packets that will be sent
|
||||
Byte pPackets[TIME_LIMIT_NUM_PACKETS][MAX_PACKET_SIZE];
|
||||
//The real sizes of the packets that will be sent
|
||||
int pPacketsSizes[TIME_LIMIT_NUM_PACKETS];
|
||||
//Buffer for the packet that will be received
|
||||
Byte pReceivedPacket[MAX_PACKET_SIZE] = {0};
|
||||
//The expected aggregated packet
|
||||
Byte pExpectedAggregatedPacket[MAX_PACKET_SIZE] = {0};
|
||||
//Size of aggregated packet
|
||||
int nTotalPacketsSize = 0;
|
||||
|
||||
//initialize the packets
|
||||
for (int i = 0; i < TIME_LIMIT_NUM_PACKETS; i++)
|
||||
{
|
||||
pPacketsSizes[i] = i + 1;
|
||||
nTotalPacketsSize += pPacketsSizes[i] + 2; //size of the packet + 2 bytes for length
|
||||
for (int j = 0; j < pPacketsSizes[i]; j++)
|
||||
pPackets[i][j] = i+ 16*test_num;
|
||||
}
|
||||
test_num++;
|
||||
|
||||
for (int n = 0; n < NUM_PACKETS; n++)
|
||||
{
|
||||
//send the packets
|
||||
for (int i = 0; i < TIME_LIMIT_NUM_PACKETS; i++)
|
||||
{
|
||||
LOG_MSG_DEBUG("Sending packet %d into the USB pipe(%d bytes)\n",
|
||||
i, pPacketsSizes[i]);
|
||||
int nBytesSent = m_UsbNoAggToIpaPipeAggTime.Send(pPackets[i],
|
||||
pPacketsSizes[i]);
|
||||
if (pPacketsSizes[i] != nBytesSent)
|
||||
{
|
||||
LOG_MSG_DEBUG("Sending packet %d into the USB pipe(%d "
|
||||
"bytes) failed!\n", i, pPacketsSizes[i]);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//receive the aggregated packet
|
||||
LOG_MSG_DEBUG("Reading packet from the USB pipe(%d bytes should be "
|
||||
"there)\n", nTotalPacketsSize);
|
||||
int nBytesReceived = m_IpaToUsbPipeAggTime.Receive(pReceivedPacket,
|
||||
nTotalPacketsSize);
|
||||
if (nTotalPacketsSize != nBytesReceived)
|
||||
{
|
||||
LOG_MSG_DEBUG("Receiving aggregated packet from the USB pipe(%d "
|
||||
"bytes) failed!\n", nTotalPacketsSize);
|
||||
print_buff(pReceivedPacket, nBytesReceived);
|
||||
return false;
|
||||
}
|
||||
|
||||
//initializing the aggregated packet
|
||||
int k = 0;
|
||||
for (int i = 0; i < TIME_LIMIT_NUM_PACKETS; i++)
|
||||
{
|
||||
//the first 2 bytes are the packet length in little endian
|
||||
pExpectedAggregatedPacket[k] = pPacketsSizes[i] & 0x00FF;
|
||||
pExpectedAggregatedPacket[k+1] = pPacketsSizes[i] >> 8;
|
||||
k += 2;
|
||||
for (int j = 0; j < pPacketsSizes[i]; j++)
|
||||
{
|
||||
pExpectedAggregatedPacket[k] = pPackets[i][j];
|
||||
k++;
|
||||
}
|
||||
}
|
||||
|
||||
//comparing the received packet to the aggregated packet
|
||||
LOG_MSG_DEBUG("Checking sent.vs.received packet\n");
|
||||
if (0 != memcmp(pExpectedAggregatedPacket, pReceivedPacket,
|
||||
sizeof(pReceivedPacket)))
|
||||
{
|
||||
LOG_MSG_DEBUG("Comparison of packet %d failed!\n", n);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
};
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//Those tests should be run with configuration number 8.
|
||||
//Please look at the Fixture for more configurations update.
|
||||
static TLPAggregationTest tlpAggregationTest;
|
||||
static TLPDeaggregationTest tlpDeaggregationTest;
|
||||
static TLPAggregationLoopTest tlpAggregationLoopTest;
|
||||
static TLPAggregationTimeLimitTest tlpAggregationTimeLimitTest;
|
||||
static TLPAggregationByteLimitTest tlpAggregationByteLimitTest;
|
||||
static TLPAggregation2PipesTest tlpAggregation2PipesTest;
|
||||
static TLPAggregationTimeLimitLoopTest tlpAggregationTimeLimitLoopTest;
|
||||
static TLPDeaggregationAndAggregationTest tlpDeaggregationAndAggregationTest;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// EOF ////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
74
qcom/opensource/dataipa/kernel-tests/TestBase.cpp
Normal file
74
qcom/opensource/dataipa/kernel-tests/TestBase.cpp
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (c) 2017,2020 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "TestBase.h"
|
||||
#include "TestManager.h"
|
||||
#include "linux/msm_ipa.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
TestBase::TestBase() :
|
||||
m_runInRegression(true),
|
||||
m_minIPAHwType(IPA_HW_v1_1),
|
||||
m_maxIPAHwType(IPA_HW_MAX)
|
||||
{
|
||||
m_mem_type = DFLT_NAT_MEM_TYPE;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
void TestBase::Register(TestBase &test)
|
||||
{
|
||||
TestManager::GetInstance()->Register(test);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
//Empty default implementation, a test does not have to implement Setup()
|
||||
bool TestBase::Setup()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
//Empty default implementation, a test does not have to implement Teardown()
|
||||
bool TestBase::Teardown()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
TestBase::~TestBase()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
74
qcom/opensource/dataipa/kernel-tests/TestBase.h
Normal file
74
qcom/opensource/dataipa/kernel-tests/TestBase.h
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (c) 2017,2020 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _TEST_BASE_H_
|
||||
#define _TEST_BASE_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#define DFLT_NAT_MEM_TYPE "HYBRID"
|
||||
|
||||
using namespace std;
|
||||
|
||||
class TestBase
|
||||
{
|
||||
public:
|
||||
virtual bool Setup();
|
||||
/* Empty default implementation,
|
||||
* a test does not have to implement Setup()
|
||||
*/
|
||||
virtual bool Run() = 0;
|
||||
/* A test must implement Run() */
|
||||
virtual bool Teardown();
|
||||
/* Empty default implementation,
|
||||
* a test does not have to implement Teardown()
|
||||
*/
|
||||
void Register(TestBase & test);
|
||||
virtual ~TestBase();
|
||||
TestBase();
|
||||
void SetMemType(
|
||||
const char* mem_type = DFLT_NAT_MEM_TYPE)
|
||||
{
|
||||
m_mem_type = mem_type;
|
||||
}
|
||||
|
||||
const char* m_mem_type;
|
||||
string m_name;
|
||||
string m_description;
|
||||
vector < string > m_testSuiteName;
|
||||
/* Every test can belong to multiple test suites */
|
||||
bool m_runInRegression;
|
||||
/* Should this test be run in a regression test ? (Default is yes) */
|
||||
int m_minIPAHwType;
|
||||
/* The minimal IPA HW version which this test can run on */
|
||||
int m_maxIPAHwType;
|
||||
/* The maximal IPA HW version which this test can run on */
|
||||
};
|
||||
#endif
|
||||
396
qcom/opensource/dataipa/kernel-tests/TestManager.cpp
Normal file
396
qcom/opensource/dataipa/kernel-tests/TestManager.cpp
Normal file
@@ -0,0 +1,396 @@
|
||||
/*
|
||||
* Copyright (c) 2017-2018,2020 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <algorithm> // std::find
|
||||
#include <vector> // std::vector
|
||||
#include <string>
|
||||
#include <errno.h>
|
||||
#include <ctime>
|
||||
#include <sstream>
|
||||
#include "TestManager.h"
|
||||
#include "TestsUtils.h"
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include "ipa_test_module.h"
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
/* Global static pointer used to ensure a single instance of the class. */
|
||||
TestManager* TestManager::m_instance = NULL;
|
||||
|
||||
|
||||
#ifdef HAVE_LIBXML
|
||||
|
||||
TestsXMLResult::TestsXMLResult()
|
||||
{
|
||||
xmlNodePtr node;
|
||||
|
||||
// initialize xml report document and add a root to node it
|
||||
m_XML_doc_ptr = xmlNewDoc(BAD_CAST "1.0");
|
||||
if (m_XML_doc_ptr == NULL){
|
||||
printf("error on allocation xml doc\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
node = xmlNewNode(NULL, BAD_CAST "testsuites");
|
||||
if (!node) {
|
||||
printf("failed to allocate XML node\n");
|
||||
exit (-1);
|
||||
}
|
||||
xmlDocSetRootElement(m_XML_doc_ptr, node);
|
||||
}
|
||||
|
||||
TestsXMLResult::~TestsXMLResult()
|
||||
{
|
||||
if (m_XML_doc_ptr)
|
||||
xmlFreeDoc(m_XML_doc_ptr);
|
||||
xmlCleanupParser();
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns xmlPtr to testsuite element node, if doesn't exist
|
||||
* creates one by that name
|
||||
*/
|
||||
xmlNodePtr TestsXMLResult::GetSuiteElement(const string& suite_name)
|
||||
{
|
||||
xmlNodePtr root_node, suite_node, new_child_node;
|
||||
|
||||
if (!m_XML_doc_ptr) {
|
||||
printf("no xml document\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
root_node = xmlDocGetRootElement(m_XML_doc_ptr);
|
||||
suite_node = xmlFirstElementChild(root_node);
|
||||
while (suite_node)
|
||||
{
|
||||
/* get suite name */
|
||||
xmlChar *val = xmlGetProp(suite_node, BAD_CAST "name");
|
||||
|
||||
/* change xmlCHar* to string */
|
||||
string node_suite_name(reinterpret_cast<char*>(val));
|
||||
xmlFree(val); //free val allocated memory
|
||||
|
||||
if (node_suite_name == suite_name)
|
||||
return suite_node;
|
||||
else suite_node = suite_node->next;
|
||||
}
|
||||
|
||||
/* If we got here no suitable suite name was found,
|
||||
* so we create a new suite element and return it
|
||||
*/
|
||||
new_child_node = xmlNewChild(root_node, NULL, BAD_CAST "testsuite", BAD_CAST "");
|
||||
if (!new_child_node) {
|
||||
printf("failed creating new XML node\n");
|
||||
return NULL;
|
||||
}
|
||||
xmlSetProp(new_child_node, BAD_CAST "name", BAD_CAST suite_name.c_str());
|
||||
|
||||
return xmlGetLastChild(root_node);
|
||||
}
|
||||
|
||||
/*
|
||||
* Creates new testcase element
|
||||
*/
|
||||
void TestsXMLResult::AddTestcase(const string &suite_nm, const string &test_nm,
|
||||
double runtime, bool pass)
|
||||
{
|
||||
xmlNodePtr suite_node, new_testcase, fail_node;
|
||||
ostringstream runtime_str;
|
||||
|
||||
if (!suite_nm.size() || !test_nm.size()) {
|
||||
printf("Input error: suite_nm size %d , test_nm size %d",
|
||||
suite_nm.size(), test_nm.size());
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
suite_node = GetSuiteElement(suite_nm);
|
||||
if (!suite_node) {
|
||||
printf("failed getting suite element\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
/* Create new testcase element as son to suite element */
|
||||
new_testcase = xmlNewChild(suite_node, NULL, BAD_CAST "testcase", NULL);
|
||||
if (!new_testcase) {
|
||||
printf("failed creating XML new child for testcase\n");
|
||||
exit(-1);
|
||||
}
|
||||
xmlSetProp(new_testcase, BAD_CAST "name", BAD_CAST test_nm.c_str());
|
||||
|
||||
runtime_str << runtime;
|
||||
xmlSetProp(new_testcase, BAD_CAST "time", BAD_CAST runtime_str.str().c_str());
|
||||
|
||||
if (!pass) {
|
||||
fail_node = xmlNewChild(new_testcase, NULL, BAD_CAST "failure", NULL);
|
||||
if (!fail_node) {
|
||||
printf("failed creating fail node\n");
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Prints the XML tree to file
|
||||
*/
|
||||
void TestsXMLResult::GenerateXMLReport(void)
|
||||
{
|
||||
if (!m_XML_doc_ptr) {
|
||||
printf("no xml document\n");
|
||||
return;
|
||||
}
|
||||
|
||||
xmlSaveFormatFileEnc(XUNIT_REPORT_PATH_AND_NAME, m_XML_doc_ptr, "UTF-8", 1);
|
||||
}
|
||||
|
||||
#else /* HAVE_LIBXML */
|
||||
|
||||
TestsXMLResult::TestsXMLResult() {}
|
||||
TestsXMLResult::~TestsXMLResult() {}
|
||||
void TestsXMLResult::AddTestcase(const string &suite_nm, const string &test_nm,
|
||||
double runtime, bool pass) {}
|
||||
void TestsXMLResult::GenerateXMLReport(void)
|
||||
{
|
||||
printf("No XML support\n");
|
||||
}
|
||||
|
||||
#endif /* HAVE_LIBXML */
|
||||
|
||||
TestManager::TestManager(
|
||||
const char* nat_mem_type_ptr)
|
||||
{
|
||||
m_testList.clear();
|
||||
m_failedTestsNames.clear();
|
||||
m_numTestsFailed = 0;
|
||||
m_numTestsRun = 0;
|
||||
FetchIPAHwType();
|
||||
m_nat_mem_type_ptr = nat_mem_type_ptr;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TestManager::~TestManager()
|
||||
{
|
||||
m_testList.clear();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TestManager* TestManager::GetInstance(
|
||||
const char* nat_mem_type_ptr)
|
||||
{
|
||||
if (!m_instance) // Only allow one instance of class to be generated.
|
||||
m_instance = new TestManager(nat_mem_type_ptr);
|
||||
|
||||
return m_instance;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void TestManager::Register(TestBase &test)
|
||||
{
|
||||
m_testList.push_back(&test);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool TestManager::Run(vector<string> testSuiteList, vector<string> testNameList)
|
||||
{
|
||||
TestBase *test = NULL;
|
||||
bool pass = true;
|
||||
vector<string>::iterator testIter;
|
||||
vector<string>::iterator testSuiteIter;
|
||||
bool runTest = false;
|
||||
clock_t begin_test_clk, end_test_clk;
|
||||
double test_runtime_sec = 0, total_time_sec = 0;
|
||||
TestsXMLResult xml_res;
|
||||
|
||||
if (m_testList.size() == 0)
|
||||
return false;
|
||||
|
||||
/* PrintRegisteredTests(); */
|
||||
|
||||
for (unsigned int i = 0 ; i < m_testList.size() ; i++ , runTest = false) {
|
||||
pass = true;
|
||||
test = m_testList[i];
|
||||
|
||||
// Run only tests from the list of test suites which is stated in the command
|
||||
// line. In case the list is empty, run all tests.
|
||||
if (testSuiteList.size() > 0) {
|
||||
for (unsigned int j = 0; j < test->m_testSuiteName.size(); j++) {
|
||||
testSuiteIter = find(testSuiteList.begin(), testSuiteList.end(), test->m_testSuiteName[j]);
|
||||
if (testSuiteIter != testSuiteList.end()) {
|
||||
runTest = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// We also support test by name
|
||||
if (testNameList.size() > 0) {
|
||||
testIter = find(testNameList.begin(), testNameList.end(), test->m_name);
|
||||
if (testIter != testNameList.end())
|
||||
runTest = true;
|
||||
}
|
||||
|
||||
// Run the test only if it's applicable to the current IPA HW type / version
|
||||
if (runTest) {
|
||||
if (!(m_IPAHwType >= test->m_minIPAHwType && m_IPAHwType <= test->m_maxIPAHwType))
|
||||
runTest = false;
|
||||
}
|
||||
|
||||
if (!runTest)
|
||||
continue;
|
||||
|
||||
printf("\n\nExecuting test %s\n", test->m_name.c_str());
|
||||
printf("Description: %s\n", test->m_description.c_str());
|
||||
|
||||
printf("Setup()\n");
|
||||
begin_test_clk = clock();
|
||||
test->SetMemType(GetMemType());
|
||||
pass &= test->Setup();
|
||||
|
||||
//In case the test's setup did not go well it will be a bad idea to try and run it.
|
||||
if (true == pass)
|
||||
{
|
||||
printf("Run()\n");
|
||||
pass &= test->Run();
|
||||
}
|
||||
|
||||
printf("Teardown()\n");
|
||||
pass &= test->Teardown();
|
||||
|
||||
end_test_clk = clock();
|
||||
test_runtime_sec = double(end_test_clk - begin_test_clk) / CLOCKS_PER_SEC;
|
||||
total_time_sec += test_runtime_sec;
|
||||
|
||||
if (pass)
|
||||
{
|
||||
m_numTestsRun++;
|
||||
PrintSeparator(test->m_name.size());
|
||||
printf("Test %s PASSED ! time:%g\n", test->m_name.c_str(), test_runtime_sec);
|
||||
PrintSeparator(test->m_name.size());
|
||||
}
|
||||
else
|
||||
{
|
||||
m_numTestsRun++;
|
||||
m_numTestsFailed++;
|
||||
m_failedTestsNames.push_back(test->m_name);
|
||||
PrintSeparator(test->m_name.size());
|
||||
printf("Test %s FAILED ! time:%g\n", test->m_name.c_str(), test_runtime_sec);
|
||||
PrintSeparator(test->m_name.size());
|
||||
}
|
||||
|
||||
xml_res.AddTestcase(test->m_testSuiteName[0], test->m_name, test_runtime_sec, pass);
|
||||
} // for
|
||||
|
||||
// Print summary
|
||||
printf("\n\n");
|
||||
printf("==================== RESULTS SUMMARY ========================\n");
|
||||
printf("%zu tests were run, %zu failed, total time:%g.\n", m_numTestsRun, m_numTestsFailed, total_time_sec);
|
||||
if (0 != m_numTestsFailed) {
|
||||
printf("Failed tests list:\n");
|
||||
for (size_t i = 0; i < m_numTestsFailed; i++) {
|
||||
printf(" %s\n", m_failedTestsNames[i].c_str());
|
||||
m_failedTestsNames.pop_back();
|
||||
}
|
||||
}
|
||||
printf("=============================================================\n");
|
||||
xml_res.GenerateXMLReport();
|
||||
|
||||
return pass;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void TestManager::PrintSeparator(size_t len)
|
||||
{
|
||||
string separator;
|
||||
|
||||
for (size_t i = 0; i < len + 15; i++) {
|
||||
separator += "-";
|
||||
}
|
||||
|
||||
printf("%s\n", separator.c_str());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TestManager::TestManager(TestManager const&)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TestManager& TestManager::operator=(TestManager const&)
|
||||
{
|
||||
return *m_instance;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void TestManager::PrintRegisteredTests()
|
||||
{
|
||||
printf("Test list: (%zu registered)\n", m_testList.size());
|
||||
for (unsigned int i = 0; i < m_testList.size(); i++) {
|
||||
printf("%d) name = %s, suite name = %s, regression = %d\n", i, m_testList[i]->m_name.c_str(),
|
||||
m_testList[i]->m_testSuiteName[0].c_str(), m_testList[i]->m_runInRegression);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void TestManager::FetchIPAHwType()
|
||||
{
|
||||
int fd;
|
||||
|
||||
// Open ipa_test device node
|
||||
fd = open("/dev/ipa_test" , O_RDONLY);
|
||||
if (fd < 0) {
|
||||
printf("Failed opening %s. errno %d: %s\n", "/dev/ipa_test", errno, strerror(errno));
|
||||
m_IPAHwType = IPA_HW_None;
|
||||
return;
|
||||
}
|
||||
|
||||
printf("%s(), fd is %d\n", __FUNCTION__, fd);
|
||||
|
||||
m_IPAHwType = (enum ipa_hw_type)ioctl(fd, IPA_TEST_IOC_GET_HW_TYPE);
|
||||
if (-1 == m_IPAHwType) {
|
||||
printf("%s(), IPA_TEST_IOC_GET_HW_TYPE ioctl failed\n", __FUNCTION__);
|
||||
m_IPAHwType = IPA_HW_None;
|
||||
}
|
||||
|
||||
printf("%s(), IPA HW type (version) = %d\n", __FUNCTION__, m_IPAHwType);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
103
qcom/opensource/dataipa/kernel-tests/TestManager.h
Normal file
103
qcom/opensource/dataipa/kernel-tests/TestManager.h
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright (c) 2017-2018,2020 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _TEST_MANAGER_H_
|
||||
#define _TEST_MANAGER_H_
|
||||
|
||||
#include "TestBase.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "linux/msm_ipa.h"
|
||||
|
||||
#ifdef HAVE_LIBXML
|
||||
#include <libxml/parser.h>
|
||||
#include <libxml/tree.h>
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
class TestsXMLResult
|
||||
{
|
||||
public:
|
||||
TestsXMLResult();
|
||||
~TestsXMLResult();
|
||||
void AddTestcase(const string &suite_nm, const string &test_nm,
|
||||
double runtime, bool pass);
|
||||
void GenerateXMLReport(void);
|
||||
private:
|
||||
#ifdef HAVE_LIBXML
|
||||
xmlNodePtr GetSuiteElement(const string& suite_name);
|
||||
xmlDocPtr m_XML_doc_ptr;
|
||||
#endif
|
||||
};
|
||||
|
||||
class TestManager /* Singleton */
|
||||
{
|
||||
public:
|
||||
static TestManager *GetInstance(
|
||||
const char* nat_mem_type_ptr = DFLT_NAT_MEM_TYPE);
|
||||
~TestManager();
|
||||
void Register(TestBase & test);
|
||||
bool Setup();
|
||||
/* This is the place to put initialization
|
||||
* for the whole test framework
|
||||
*/
|
||||
bool Run(vector <string> testSuiteList,
|
||||
vector <string> testNameList);
|
||||
/* This function will run all the tests in the system */
|
||||
bool Teardown();
|
||||
/* This is the place to put tear-down for the whole test framework */
|
||||
vector < TestBase * > m_testList;
|
||||
/* Holds pointers to all of the tests in the system */
|
||||
|
||||
enum ipa_hw_type GetIPAHwType() {return m_IPAHwType;}
|
||||
const char* GetMemType() { return m_nat_mem_type_ptr; }
|
||||
|
||||
private:
|
||||
TestManager(
|
||||
const char* nat_mem_type_ptr = DFLT_NAT_MEM_TYPE);
|
||||
TestManager(TestManager const &);
|
||||
TestManager & operator = (TestManager const &);
|
||||
void PrintSeparator(size_t len);
|
||||
void PrintRegisteredTests();
|
||||
void BuildRegressionTestSuite();
|
||||
void FetchIPAHwType();
|
||||
|
||||
static TestManager *m_instance;
|
||||
|
||||
size_t m_numTestsRun;
|
||||
size_t m_numTestsFailed;
|
||||
enum ipa_hw_type m_IPAHwType;
|
||||
const char* m_nat_mem_type_ptr;
|
||||
|
||||
vector < string > m_failedTestsNames;
|
||||
};
|
||||
|
||||
#endif
|
||||
1873
qcom/opensource/dataipa/kernel-tests/TestsUtils.cpp
Normal file
1873
qcom/opensource/dataipa/kernel-tests/TestsUtils.cpp
Normal file
File diff suppressed because it is too large
Load Diff
860
qcom/opensource/dataipa/kernel-tests/TestsUtils.h
Normal file
860
qcom/opensource/dataipa/kernel-tests/TestsUtils.h
Normal file
@@ -0,0 +1,860 @@
|
||||
/*
|
||||
* Copyright (c) 2017-2020 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef __TESTS_UTILS__H__
|
||||
#define __TESTS_UTILS__H__
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <linux/if_ether.h>
|
||||
#include <linux/msm_ipa.h>
|
||||
#include "TestBase.h"
|
||||
#include "Constants.h"
|
||||
#include "RoutingDriverWrapper.h"
|
||||
#include "InterfaceAbstraction.h"
|
||||
#include "ipa_test_module.h"
|
||||
#include "TestManager.h"
|
||||
#include "Logger.h"
|
||||
#include "Constants.h"
|
||||
extern "C" {
|
||||
#include "ipa_nat_utils.h"
|
||||
}
|
||||
|
||||
using namespace std;
|
||||
#define TEST_APP_VERSION "2.00"
|
||||
|
||||
#define Free(x) do { if (x) {free(x); x = NULL; } } while (0)
|
||||
|
||||
#define MAX3(_X, _Y, _Z) max(max((_X), (_Y)), (_Z))
|
||||
|
||||
#define ETH2_DST_ADDR_OFFSET (0)
|
||||
#define ETH2_SRC_ADDR_OFFSET (ETH_ALEN)
|
||||
#define ETH2_ETH_TYPE_OFFSET (ETH2_SRC_ADDR_OFFSET + ETH_ALEN)
|
||||
#define ETH2_ETH_TYPE_LEN (2)
|
||||
#define ETH2_PAYLOAD_OFFSET (ETH2_ETH_TYPE_OFFSET + ETH2_ETH_TYPE_LEN)
|
||||
|
||||
#define ETH8021Q_HEADER_LEN (18)
|
||||
#define ETH8021Q_METADATA_OFFSET (12)
|
||||
#define ETH8021Q_8021Q_TAG_LEN (4)
|
||||
#define ETH8021Q_ETH_TYPE_OFFSET (ETH8021Q_METADATA_OFFSET + ETH8021Q_8021Q_TAG_LEN)
|
||||
|
||||
#define WLAN_HDR_SIZE (4)
|
||||
#define RNDIS_HDR_SIZE (44)
|
||||
|
||||
// 26 ROME WLAN Frame =
|
||||
// 4 ROME WLAN header +
|
||||
// 14 IEEE 802.3 +
|
||||
// 8 802.2 LLC/SNAP
|
||||
#define _802_3_HDR_SIZE (26)
|
||||
|
||||
// [WLAN][ETH2] header
|
||||
#define WLAN_ETH2_HDR_SIZE (WLAN_HDR_SIZE + ETH_HLEN)
|
||||
|
||||
// [RNDIS][ETH2] header
|
||||
#define RNDIS_ETH2_HDR_SIZE (RNDIS_HDR_SIZE + ETH_HLEN)
|
||||
#define IP4_PACKET_SIZE (70) // Arbitrary number
|
||||
|
||||
// OFFSET = sizeof(struct rndis_pkt_hdr) - RNDIS_HDR_OFST(data_ofst)
|
||||
#define RNDIS_DATA_OFFSET (36)
|
||||
|
||||
// [WLAN][802.3] header
|
||||
#define WLAN_802_3_HDR_SIZE (WLAN_HDR_SIZE + _802_3_HDR_SIZE)
|
||||
|
||||
#define IPA_CLIENT_IS_PROD(x) \
|
||||
(x < IPA_CLIENT_MAX && (x & 0x1) == 0)
|
||||
#define IPA_CLIENT_IS_CONS(x) \
|
||||
(x < IPA_CLIENT_MAX && (x & 0x1) == 1)
|
||||
|
||||
enum msgType {
|
||||
ERROR = 0,
|
||||
DEBUG,
|
||||
INFO,
|
||||
STACK
|
||||
};
|
||||
|
||||
/**
|
||||
@brief
|
||||
Do not Use this function. Use MACROs instead.
|
||||
|
||||
@details
|
||||
Do not Use this function.
|
||||
Instead use the MACROs: LOG_MSG_ERROR, LOG_MSG_INFO & LOG_MSG_DEBUG
|
||||
*/
|
||||
void __log_msg(enum msgType,
|
||||
const char *filename,
|
||||
int line, const char *function,
|
||||
const char *format, ...);
|
||||
|
||||
#define LOG_MSG_ERROR(...) \
|
||||
__log_msg(ERROR, __FILE__, __LINE__, __func__, __VA_ARGS__)
|
||||
#define LOG_MSG_DEBUG(...) \
|
||||
__log_msg(DEBUG, __FILE__, __LINE__, __func__, __VA_ARGS__)
|
||||
#define LOG_MSG_INFO(...) \
|
||||
__log_msg(INFO, __FILE__, __LINE__, __func__, __VA_ARGS__)
|
||||
#define LOG_MSG_STACK(...) \
|
||||
__log_msg(STACK, __FILE__, __LINE__, __func__, __VA_ARGS__)
|
||||
|
||||
/*#define LOG_MSG_ERROR(x...)
|
||||
__log_msg(ERROR, __FILE__, __LINE__, __func__, x)
|
||||
#define LOG_MSG_DEBUG(x...)
|
||||
__log_msg(DEBUG, __FILE__, __LINE__, __func__, x)
|
||||
#define LOG_MSG_INFO(x...)
|
||||
__log_msg(INFO, __FILE__, __LINE__, __func__, x)
|
||||
#define LOG_MSG_STACK(x...)
|
||||
__log_msg(STACK, __FILE__, __LINE__, __func__, x)*/
|
||||
|
||||
/**
|
||||
@brief
|
||||
Function loads a default IPv4 / IPv6 Packet
|
||||
|
||||
@param [in] eIP - Type of Packet to load (IPA_IP_v4 / IPA_IP_v6)
|
||||
@param [in] pBuffer - pointer to the destination buffer
|
||||
@param [in,out] nMaxSize - The size of the buffer.
|
||||
Upon function return,
|
||||
the total number of bytes copied will be stored in this parameter.
|
||||
@return boolean indicating whether the
|
||||
operation completed successfully or not.
|
||||
|
||||
@details
|
||||
Function loads a default IPv4 / IPv6 packet into pBuffer.
|
||||
*/
|
||||
bool LoadDefaultPacket(
|
||||
enum ipa_ip_type eIP,
|
||||
uint8_t *pBuffer,
|
||||
size_t &nMaxSize);
|
||||
|
||||
bool LoadDefaultEth2Packet(
|
||||
enum ipa_ip_type eIP,
|
||||
uint8_t *pBuffer,
|
||||
size_t &nMaxSize);
|
||||
|
||||
bool LoadDefaultWLANEth2Packet(
|
||||
enum ipa_ip_type eIP,
|
||||
uint8_t *pBuffer,
|
||||
size_t &nMaxSize);
|
||||
|
||||
bool LoadDefaultWLAN802_32Packet(
|
||||
enum ipa_ip_type eIP,
|
||||
uint8_t *pBuffer,
|
||||
size_t &nMaxSize);
|
||||
|
||||
bool LoadNoPayloadPacket(
|
||||
enum ipa_ip_type eIP,
|
||||
uint8_t *pBuffer,
|
||||
size_t &nMaxSize);
|
||||
|
||||
bool LoadDefault802_1Q(
|
||||
enum ipa_ip_type eIP,
|
||||
uint8_t *pBuffer,
|
||||
size_t &nMaxSize);
|
||||
|
||||
/**
|
||||
@brief
|
||||
Function loads a default IPv4 / IPv6 Packet
|
||||
|
||||
@param [in] eIP - Type of Packet to load (IPA_IP_v4 / IPA_IP_v6)
|
||||
@param [in] extHdrType - Type of IPV6 extension header(FRAGMENT / NONE)
|
||||
@param [in] pBuffer - pointer to the destination buffer
|
||||
@param [in,out] nMaxSize - The size of the buffer.
|
||||
Upon function return,
|
||||
the total number of bytes copied will be stored in this parameter.
|
||||
@return boolean indicating whether the
|
||||
operation completed successfully or not.
|
||||
|
||||
@details
|
||||
Function loads a default IPv4 / IPv6 packet into pBuffer.
|
||||
*/
|
||||
bool LoadDefaultPacket(
|
||||
enum ipa_ip_type eIP,
|
||||
enum ipv6_ext_hdr_type extHdrType,
|
||||
uint8_t *pBuffer,
|
||||
size_t &nMaxSize);
|
||||
/**
|
||||
@brief
|
||||
Function Sends a Packet, Receive a packet
|
||||
and compares the received result with an expected buffer
|
||||
|
||||
@param [in] pSink - Destination to which a packet will be sent.
|
||||
@param [in] pSendBuffer -
|
||||
Pointer to a buffer containing the packet that will be sent.
|
||||
@param [in] nSendBuffSize - The size of the data in the packet.
|
||||
@param [in] pSource - Source from which a packet will be received.
|
||||
@param [in] pExpectedBuffer - Pointer a
|
||||
buffer containing the expected packet (from the receiver)
|
||||
@param [in] nExpectedBuffSize - The size of
|
||||
valid data within pExpectedBuffer.
|
||||
@return Boolean indicating whether the operation
|
||||
completed successfully and the buffers matching or not.
|
||||
|
||||
@details
|
||||
Function sends a packet to pSink, and receives a packet from pSource.
|
||||
The packet received from pSource
|
||||
is compared to the expected data from pExpectedBuffer.
|
||||
If ExpectData is identical to the
|
||||
received data, the function returns TRUE.
|
||||
*/
|
||||
bool SendReceiveAndCompare(
|
||||
InterfaceAbstraction * pSink,
|
||||
uint8_t *pSendBuffer,
|
||||
size_t nSendBuffSize,
|
||||
InterfaceAbstraction * pSource,
|
||||
uint8_t *pExpectedBuffer,
|
||||
size_t nExpectedBuffSize);
|
||||
|
||||
/**
|
||||
@brief
|
||||
This function creates a bypass rule within a table in the Routing block
|
||||
|
||||
@param [in] pRouting - pointer to the Routing Class
|
||||
@param [in] eIP - Type of Packet to load (IPA_IP_v4 / IPA_IP_v6)
|
||||
@param [in] pTableName - pointer to the Table's Name.
|
||||
@param [in] eRuleDestination - destination of the bypass rule.
|
||||
@param [in] uHeaderHandle -
|
||||
handle to the Header that should be Added (0 should be used as default).
|
||||
@param [out] pTableHdl -
|
||||
pointer to the table Handle (Can be Null)
|
||||
@return boolean indicating whether
|
||||
the operation completed successfully or not.
|
||||
|
||||
@details
|
||||
This function creates bypass rule within a table in the Routing block.
|
||||
*/
|
||||
bool CreateBypassRoutingTable(
|
||||
RoutingDriverWrapper * pRouting,
|
||||
enum ipa_ip_type eIP,
|
||||
const char *pTableName,
|
||||
enum ipa_client_type eRuleDestination,
|
||||
uint32_t uHeaderHandle,
|
||||
uint32_t *pTableHdl);
|
||||
|
||||
/**
|
||||
@brief
|
||||
This function creates a bypass rule within a table in the Routing block
|
||||
|
||||
@param [in] pRouting - pointer to the Routing Class
|
||||
@param [in] eIP - Type of Packet to load (IPA_IP_v4 / IPA_IP_v6)
|
||||
@param [in] pTableName - pointer to the Table's Name.
|
||||
@param [in] eRuleDestination - destination of the bypass rule.
|
||||
@param [in] uHeaderHandle -
|
||||
handle to the Header that should be Added (0 should be used as default).
|
||||
@param [out] pTableHdl -
|
||||
pointer to the table Handle (Can be Null)
|
||||
@return boolean indicating whether
|
||||
the operation completed successfully or not.
|
||||
|
||||
@details
|
||||
This function creates bypass rule within a table in the Routing block.
|
||||
*/
|
||||
bool CreateBypassRoutingTable_v2(
|
||||
RoutingDriverWrapper * pRouting,
|
||||
enum ipa_ip_type eIP,
|
||||
const char *pTableName,
|
||||
enum ipa_client_type eRuleDestination,
|
||||
uint32_t uHeaderHandle,
|
||||
uint32_t *pTableHdl,
|
||||
uint8_t uClsAggrIrqMod);
|
||||
|
||||
/**
|
||||
@brief
|
||||
Configures the sytem to one of the pre-determined
|
||||
configurations.
|
||||
|
||||
@param [in] testConfiguration - Configuration number
|
||||
@param [in] params - additional parameters
|
||||
@return void
|
||||
|
||||
@details
|
||||
Writes the configuration index to /dev/ipa_test. In case
|
||||
the system has already been configured, returns.
|
||||
*/
|
||||
void ConfigureScenario(int testConfiguration);
|
||||
void ConfigureScenario(int testConfiguration, const char *params);
|
||||
int GenericConfigureScenario(struct ipa_test_config_header *header,
|
||||
bool isUlso=false);
|
||||
int GenericConfigureScenarioDestory(void);
|
||||
int ConfigureSystem(int testConfiguration, int fd);
|
||||
int ConfigureSystem(int testConfiguration, int fd, const char *params);
|
||||
|
||||
void prepare_channel_struct(struct ipa_channel_config *channel,
|
||||
int index,
|
||||
enum ipa_client_type client,
|
||||
void *cfg,
|
||||
size_t config_size,
|
||||
bool en_status = 0);
|
||||
|
||||
void prepare_header_struct(struct ipa_test_config_header *header,
|
||||
struct ipa_channel_config **from,
|
||||
struct ipa_channel_config **to);
|
||||
|
||||
/**
|
||||
@brief
|
||||
Compares two data buffers.
|
||||
|
||||
@param [in] goldenBuffer - Pointer to the first data
|
||||
buffer
|
||||
@param [in] goldenSize - First data buffer size
|
||||
@param [in] receivedBuffer - Pointer to the second data
|
||||
buffer
|
||||
@param [in] receivedSize - Second data buffer size
|
||||
@return True - the buffers are identical. False
|
||||
otherwise.
|
||||
|
||||
@details
|
||||
In case the sizes are differnt, false is returned.
|
||||
*/
|
||||
bool CompareResultVsGolden(
|
||||
unsigned char *goldenBuffer,
|
||||
unsigned int goldenSize,
|
||||
unsigned char *receivedBuffer,
|
||||
unsigned int receivedSize);
|
||||
|
||||
/**
|
||||
@brief
|
||||
Compares two data buffers considering the returned status.
|
||||
|
||||
@param [in] goldenBuffer - Pointer to the first data
|
||||
buffer
|
||||
@param [in] goldenSize - First data buffer size
|
||||
@param [in] receivedBuffer - Pointer to the second data
|
||||
buffer
|
||||
@param [in] receivedSize - Second data buffer size
|
||||
@return True - the buffers are identical. False
|
||||
otherwise.
|
||||
|
||||
@details
|
||||
In case the sizes are differnt, false is returned.
|
||||
*/
|
||||
bool CompareResultVsGolden_w_Status(
|
||||
Byte *goldenBuffer,
|
||||
unsigned int goldenSize,
|
||||
Byte *receivedBuffer,
|
||||
unsigned int receivedSize);
|
||||
|
||||
|
||||
/**
|
||||
@brief
|
||||
Loads a file to memory
|
||||
|
||||
@param [in] fileFullPath
|
||||
@param [inout] sizeLoaded - returns the number of bytes
|
||||
which were read from the file
|
||||
@return Address of the loaded data buffer
|
||||
|
||||
@details
|
||||
Allocates memory by itself, user should free the memory
|
||||
|
||||
*/
|
||||
unsigned char *LoadFileToMemory(
|
||||
const string & fileFullPath,
|
||||
unsigned int *sizeLoaded);
|
||||
|
||||
/**
|
||||
@brief
|
||||
Checks whether a file exists on disk
|
||||
|
||||
@param [in] filename
|
||||
@return True if the file exists, false otherwise.
|
||||
|
||||
@details
|
||||
*/
|
||||
bool file_exists(const char *filename);
|
||||
|
||||
/**
|
||||
@brief
|
||||
Prints a data buffer.
|
||||
@param [in] data - Pointer to the data
|
||||
@param [in] size - How many bytes to print
|
||||
@return void
|
||||
|
||||
@details
|
||||
*/
|
||||
void print_buff(void *data, size_t size);
|
||||
|
||||
void add_buff(uint8_t *data, size_t size, uint8_t val);
|
||||
|
||||
/**
|
||||
@brief
|
||||
Performes ep control of a specific endpoint.
|
||||
@param [in] ep_ctrl - Pointer to ipa_test_ep_ctrl struct with
|
||||
the data of the requested operation
|
||||
@return bool
|
||||
|
||||
@details
|
||||
Suspend\Unsuspends\Delays\resumes an endpoint.
|
||||
*/
|
||||
bool configure_ep_ctrl(struct ipa_test_ep_ctrl *ep_ctrl);
|
||||
|
||||
/**
|
||||
@brief
|
||||
Performes holb config of a specific pipe.
|
||||
* @param [in] test_holb_config - Pointer to
|
||||
* ipa_test_holb_config struct with the data of
|
||||
* the requested operation
|
||||
@return bool
|
||||
|
||||
@details
|
||||
Configures HOLB parameters on a pipe.
|
||||
*/
|
||||
bool configure_holb(struct ipa_test_holb_config *test_holb_config);
|
||||
|
||||
/**
|
||||
@brief
|
||||
Register an alternative suspend handler
|
||||
@param [in] deferred_flag - should the handler execute in defer mode
|
||||
@param [in] reg - register or unregister the suspend handler
|
||||
@param [in] DevNum - the index of the ep that the handler is registered to
|
||||
@return bool
|
||||
|
||||
@details
|
||||
Register the test framework suspend handler for a given endpoint
|
||||
*/
|
||||
bool RegSuspendHandler(bool deferred_flag, bool reg, int DevNum);
|
||||
|
||||
class Eth2Helper {
|
||||
public:
|
||||
static const Byte m_ETH2_IP4_HDR[ETH_HLEN];
|
||||
|
||||
static bool LoadEth2IP4Header(
|
||||
uint8_t *pBuffer,
|
||||
size_t bufferSize,
|
||||
size_t *pLen);
|
||||
|
||||
static bool LoadEth2IP6Header(
|
||||
uint8_t *pBuffer,
|
||||
size_t bufferSize,
|
||||
size_t *pLen);
|
||||
|
||||
static bool LoadEth2IP4Packet(
|
||||
uint8_t *pBuffer,
|
||||
size_t bufferSize,
|
||||
size_t *pLen);
|
||||
|
||||
static bool LoadEth2IP6Packet(
|
||||
uint8_t *pBuffer,
|
||||
size_t bufferSize,
|
||||
size_t *pLen);
|
||||
};
|
||||
|
||||
class WlanHelper {
|
||||
public:
|
||||
static const Byte m_WLAN_HDR[WLAN_HDR_SIZE];
|
||||
|
||||
static bool LoadWlanHeader(
|
||||
uint8_t *pBuffer,
|
||||
size_t bufferSize,
|
||||
size_t *pLen);
|
||||
|
||||
static bool LoadWlanEth2IP4Header(
|
||||
uint8_t *pBuffer,
|
||||
size_t bufferSize,
|
||||
size_t *pLen);
|
||||
|
||||
static bool LoadWlanEth2IP6Header(
|
||||
uint8_t *pBuffer,
|
||||
size_t bufferSize,
|
||||
size_t *pLen);
|
||||
|
||||
static bool LoadWlanEth2IP4Packet(
|
||||
uint8_t *pBuffer,
|
||||
size_t bufferSize,
|
||||
size_t *pLen);
|
||||
|
||||
static bool LoadWlanEth2IP4PacketByLength(
|
||||
uint8_t *pBuffer,
|
||||
size_t bufferSize,
|
||||
size_t len,
|
||||
uint8_t padValue);
|
||||
|
||||
static bool LoadWlanEth2IP6Packet(
|
||||
uint8_t *pBuffer,
|
||||
size_t bufferSize,
|
||||
size_t *pLen);
|
||||
};
|
||||
|
||||
#pragma pack(push) /* push current alignment to stack */
|
||||
#pragma pack(1) /* set alignment to 1 byte boundary */
|
||||
struct RndisHeader {
|
||||
uint32_t MessageType;
|
||||
uint32_t MessageLength;
|
||||
uint32_t DataOffset;
|
||||
uint32_t DataLength;
|
||||
uint32_t OOBDataOffset;
|
||||
uint32_t OOBDataLength;
|
||||
uint32_t OOBNumber;
|
||||
uint32_t PacketInfoOffset;
|
||||
uint32_t PacketInfoLength;
|
||||
uint64_t Reserved;
|
||||
};
|
||||
|
||||
struct RndisEtherHeader {
|
||||
struct RndisHeader rndisHeader;
|
||||
struct ethhdr etherHeader;
|
||||
};
|
||||
#pragma pack(pop) /* restore original alignment from stack */
|
||||
|
||||
class RNDISAggregationHelper {
|
||||
public:
|
||||
static const size_t RNDIS_AGGREGATION_BYTE_LIMIT = 1024;
|
||||
|
||||
static bool LoadRNDISHeader(
|
||||
uint8_t *pBuffer,
|
||||
size_t bufferSize,
|
||||
uint32_t messageLength,
|
||||
size_t *pLen);
|
||||
|
||||
static bool LoadRNDISEth2IP4Header(
|
||||
uint8_t *pBuffer,
|
||||
size_t bufferSize,
|
||||
uint32_t messageLength,
|
||||
size_t *pLen);
|
||||
|
||||
static bool LoadRNDISPacket(
|
||||
enum ipa_ip_type eIP,
|
||||
uint8_t *pBuffer,
|
||||
size_t &nMaxSize);
|
||||
|
||||
static bool LoadEtherPacket(
|
||||
enum ipa_ip_type eIP,
|
||||
uint8_t *pBuffer,
|
||||
size_t &nMaxSize);
|
||||
|
||||
static bool ComparePackets(
|
||||
Byte *pPacket1,
|
||||
int pPacket1Size,
|
||||
Byte *pPacket2,
|
||||
int pPacket2Size);
|
||||
|
||||
static bool CompareEthervsRNDISPacket(
|
||||
Byte *pIPPacket,
|
||||
size_t ipPacketSize,
|
||||
Byte *pRNDISPacket,
|
||||
size_t rndisPacketSize);
|
||||
|
||||
static bool CompareIPvsRNDISPacket(
|
||||
Byte *pIPPacket,
|
||||
int ipPacketSize,
|
||||
Byte *pRNDISPacket,
|
||||
size_t rndisPacketSize);
|
||||
};
|
||||
|
||||
enum ipa_nat_en_type {
|
||||
IPA_BYPASS_NAT,
|
||||
IPA_SRC_NAT,
|
||||
IPA_DST_NAT,
|
||||
};
|
||||
|
||||
enum ipa_ipv6ct_en_type {
|
||||
IPA_BYPASS_IPV6CT,
|
||||
IPA_ENABLE_IPV6CT,
|
||||
};
|
||||
|
||||
enum ipa_mode_type {
|
||||
IPA_BASIC,
|
||||
IPA_ENABLE_FRAMING_HDLC,
|
||||
IPA_ENABLE_DEFRAMING_HDLC,
|
||||
IPA_DMA,
|
||||
};
|
||||
|
||||
enum ipa_aggr_en_type {
|
||||
IPA_BYPASS_AGGR,
|
||||
IPA_ENABLE_AGGR,
|
||||
IPA_ENABLE_DEAGGR,
|
||||
};
|
||||
|
||||
enum ipa_aggr_type {
|
||||
IPA_MBIM_16 = 0,
|
||||
IPA_HDLC = 1,
|
||||
IPA_TLP = 2,
|
||||
IPA_RNDIS = 3,
|
||||
IPA_GENERIC = 4,
|
||||
IPA_QCMAP = 6,
|
||||
};
|
||||
|
||||
enum ipa_aggr_mode {
|
||||
IPA_MBIM_AGGR,
|
||||
IPA_QCNCM_AGGR,
|
||||
};
|
||||
|
||||
enum hdr_total_len_or_pad_type {
|
||||
IPA_HDR_PAD = 0,
|
||||
IPA_HDR_TOTAL_LEN = 1,
|
||||
};
|
||||
|
||||
struct ipa_ep_cfg_nat {
|
||||
enum ipa_nat_en_type nat_en;
|
||||
bool nat_exc_suppress;
|
||||
};
|
||||
|
||||
struct ipa_ep_cfg_conn_track {
|
||||
enum ipa_ipv6ct_en_type conn_track_en;
|
||||
};
|
||||
|
||||
struct ipa_ep_cfg_hdr {
|
||||
uint32_t hdr_len;
|
||||
uint32_t hdr_ofst_metadata_valid;
|
||||
uint32_t hdr_ofst_metadata;
|
||||
uint32_t hdr_additional_const_len;
|
||||
uint32_t hdr_ofst_pkt_size_valid;
|
||||
uint32_t hdr_ofst_pkt_size;
|
||||
uint32_t hdr_a5_mux;
|
||||
uint32_t hdr_remove_additional;
|
||||
uint32_t hdr_metadata_reg_valid;
|
||||
};
|
||||
|
||||
struct ipa_ep_cfg_hdr_ext {
|
||||
uint32_t hdr_pad_to_alignment;
|
||||
uint32_t hdr_total_len_or_pad_offset;
|
||||
bool hdr_payload_len_inc_padding;
|
||||
enum hdr_total_len_or_pad_type hdr_total_len_or_pad;
|
||||
bool hdr_total_len_or_pad_valid;
|
||||
bool hdr_little_endian;
|
||||
struct ipa_ep_cfg_hdr *hdr;
|
||||
bool hdr_bytes_to_remove_valid;
|
||||
uint32_t hdr_bytes_to_remove;
|
||||
};
|
||||
|
||||
struct ipa_ep_cfg_mode {
|
||||
enum ipa_mode_type mode;
|
||||
enum ipa_client_type dst;
|
||||
};
|
||||
|
||||
struct ipa_ep_cfg_aggr {
|
||||
enum ipa_aggr_en_type aggr_en;
|
||||
enum ipa_aggr_type aggr;
|
||||
uint32_t aggr_byte_limit;
|
||||
uint32_t aggr_time_limit;
|
||||
uint32_t aggr_pkt_limit;
|
||||
uint32_t aggr_hard_byte_limit_en;
|
||||
bool aggr_sw_eof_active;
|
||||
uint8_t pulse_generator;
|
||||
uint8_t scaled_time;
|
||||
bool aggr_coal_l2;
|
||||
};
|
||||
|
||||
struct ipa_ep_cfg_route {
|
||||
uint32_t rt_tbl_hdl;
|
||||
};
|
||||
|
||||
struct ipa_ep_cfg_deaggr {
|
||||
uint32_t deaggr_hdr_len;
|
||||
bool syspipe_err_detection;
|
||||
bool packet_offset_valid;
|
||||
uint32_t packet_offset_location;
|
||||
bool ignore_min_pkt_err;
|
||||
uint32_t max_packet_len;
|
||||
};
|
||||
|
||||
enum ipa_cs_offload {
|
||||
IPA_DISABLE_CS_OFFLOAD,
|
||||
IPA_ENABLE_CS_OFFLOAD_UL,
|
||||
IPA_ENABLE_CS_OFFLOAD_DL,
|
||||
IPA_CS_RSVD
|
||||
};
|
||||
|
||||
struct ipa_ep_cfg_cfg {
|
||||
bool frag_offload_en;
|
||||
enum ipa_cs_offload cs_offload_en;
|
||||
uint8_t cs_metadata_hdr_offset;
|
||||
uint8_t gen_qmb_master_sel;
|
||||
uint8_t tx_instance;
|
||||
bool pipe_replicate_en;
|
||||
};
|
||||
|
||||
struct ipa_ep_cfg_metadata_mask {
|
||||
uint32_t metadata_mask;
|
||||
};
|
||||
|
||||
struct ipa_ep_cfg_metadata {
|
||||
uint32_t qmap_id;
|
||||
};
|
||||
|
||||
struct ipa_ep_cfg_seq {
|
||||
bool set_dynamic;
|
||||
int seq_type;
|
||||
};
|
||||
|
||||
struct ipa_ep_cfg_ulso {
|
||||
int ipid_min_max_idx;
|
||||
bool is_ulso_pipe;
|
||||
};
|
||||
|
||||
struct ipa_ep_cfg_holb {
|
||||
uint32_t tmr_val;
|
||||
uint32_t base_val;
|
||||
uint32_t scale;
|
||||
uint16_t en;
|
||||
uint8_t pulse_generator;
|
||||
uint8_t scaled_time;
|
||||
};
|
||||
|
||||
struct ipa_pkt_init_ex_hdr_ofst_set {
|
||||
char name[IPA_RESOURCE_NAME_MAX];
|
||||
enum ipa_client_type ep;
|
||||
};
|
||||
|
||||
struct ipa_ep_cfg_prod_cfg {
|
||||
uint8_t tx_instance;
|
||||
bool tsp_enable;
|
||||
bool max_output_size_drop_enable;
|
||||
uint8_t tsp_idx;
|
||||
uint8_t max_output_size;
|
||||
uint8_t egress_tc_lowest;
|
||||
uint8_t egress_tc_highest;
|
||||
};
|
||||
|
||||
/*
|
||||
* This struct is a mirroring of the ipa struct
|
||||
* the test module expect to get from user-space the
|
||||
* exact same struct as IPA driver defined.
|
||||
* In case of any change to IPA driver struct
|
||||
* this struct should be updated as well!
|
||||
*/
|
||||
struct test_ipa_ep_cfg {
|
||||
struct ipa_ep_cfg_nat nat;
|
||||
struct ipa_ep_cfg_conn_track conn_track;
|
||||
struct ipa_ep_cfg_hdr hdr;
|
||||
struct ipa_ep_cfg_hdr_ext hdr_ext;
|
||||
struct ipa_ep_cfg_mode mode;
|
||||
struct ipa_ep_cfg_aggr aggr;
|
||||
struct ipa_ep_cfg_deaggr deaggr;
|
||||
struct ipa_ep_cfg_route route;
|
||||
struct ipa_ep_cfg_cfg cfg;
|
||||
struct ipa_ep_cfg_metadata_mask metadata_mask;
|
||||
struct ipa_ep_cfg_metadata meta;
|
||||
struct ipa_ep_cfg_seq seq;
|
||||
struct ipa_ep_cfg_ulso ulso;
|
||||
struct ipa_ep_cfg_prod_cfg prod_cfg;
|
||||
};
|
||||
|
||||
/*! @brief Struct for the IPAv3.0 UL packet status header */
|
||||
struct ipa3_hw_pkt_status {
|
||||
uint64_t status_opcode:8;
|
||||
uint64_t exception:8;
|
||||
uint64_t status_mask:16;
|
||||
uint64_t pkt_len:16;
|
||||
uint64_t endp_src_idx:5;
|
||||
uint64_t reserved_1:3;
|
||||
uint64_t endp_dest_idx:5;
|
||||
uint64_t reserved_2:3;
|
||||
uint64_t metadata:32;
|
||||
uint64_t filt_local:1;
|
||||
uint64_t filt_hash:1;
|
||||
uint64_t filt_global:1;
|
||||
uint64_t ret_hdr:1;
|
||||
uint64_t filt_rule_id:10;
|
||||
uint64_t route_local:1;
|
||||
uint64_t route_hash:1;
|
||||
uint64_t ucp:1;
|
||||
uint64_t route_tbl_idx:5;
|
||||
uint64_t route_rule_id:10;
|
||||
uint64_t nat_hit:1;
|
||||
uint64_t nat_tbl_idx:13;
|
||||
uint64_t nat_type:2;
|
||||
uint64_t tag:48;
|
||||
uint64_t seq_num:8;
|
||||
uint64_t time_day_ctr:24;
|
||||
uint64_t hdr_local:1;
|
||||
uint64_t hdr_offset:10;
|
||||
uint64_t frag_hit:1;
|
||||
uint64_t frag_rule:4;
|
||||
uint64_t reserved_4:16;
|
||||
};
|
||||
|
||||
struct ipa3_hw_pkt_status_hw_v5_0 {
|
||||
uint64_t status_opcode : 8;
|
||||
uint64_t exception : 8;
|
||||
uint64_t status_mask : 16;
|
||||
uint64_t pkt_len : 16;
|
||||
uint64_t endp_src_idx : 8;
|
||||
uint64_t reserved_1 : 3;
|
||||
uint64_t route_local : 1;
|
||||
uint64_t route_hash : 1;
|
||||
uint64_t reserved_2 : 3;
|
||||
uint64_t metadata : 32;
|
||||
uint64_t filt_local : 1;
|
||||
uint64_t filt_hash : 1;
|
||||
uint64_t filt_global : 1;
|
||||
uint64_t ret_hdr : 1;
|
||||
uint64_t filt_rule_id : 10;
|
||||
uint64_t route_tbl_idx : 8;
|
||||
uint64_t route_rule_id : 10;
|
||||
uint64_t nat_hit : 1;
|
||||
uint64_t nat_tbl_idx : 13;
|
||||
uint64_t nat_type : 2;
|
||||
uint64_t tag : 48;
|
||||
uint64_t seq_num : 8;
|
||||
uint64_t time_day_ctr : 24;
|
||||
uint64_t hdr_local : 1;
|
||||
uint64_t hdr_offset : 10;
|
||||
uint64_t frag_hit : 1;
|
||||
uint64_t frag_rule : 4;
|
||||
uint64_t endp_dest_idx : 8;
|
||||
uint64_t reserved_4 : 7;
|
||||
uint64_t ucp : 1;
|
||||
};
|
||||
|
||||
struct ipa3_hw_pkt_status_hw_v5_5 {
|
||||
uint64_t status_opcode:8;
|
||||
uint64_t exception:8;
|
||||
uint64_t status_mask:16;
|
||||
uint64_t pkt_len:16;
|
||||
uint64_t endp_src_idx:8;
|
||||
uint64_t reserved_1:3;
|
||||
uint64_t rt_local:1;
|
||||
uint64_t rt_hash:1;
|
||||
uint64_t reserved_2:3;
|
||||
uint64_t metadata:32;
|
||||
uint64_t flt_local:1;
|
||||
uint64_t flt_hash:1;
|
||||
uint64_t flt_global:1;
|
||||
uint64_t flt_ret_hdr:1;
|
||||
uint64_t flt_rule_id:10;
|
||||
uint64_t rt_tbl_idx:8;
|
||||
uint64_t rt_rule_id:10;
|
||||
uint64_t nat_hit:1;
|
||||
uint64_t nat_entry_idx:13;
|
||||
uint64_t nat_type:2;
|
||||
uint64_t tag_info:36;
|
||||
uint64_t egress_tc:6;
|
||||
uint64_t ingress_tc:6;
|
||||
uint64_t seq_num:8;
|
||||
uint64_t time_of_day_ctr:24;
|
||||
uint64_t hdr_local:1;
|
||||
uint64_t hdr_offset:10;
|
||||
uint64_t frag_hit:1;
|
||||
uint64_t frag_rule:4;
|
||||
uint64_t endp_dest_idx:8;
|
||||
uint64_t hw_specific:4;
|
||||
uint64_t nat_exc_suppress:1;
|
||||
uint64_t tsp:1;
|
||||
uint64_t ttl_dec:1;
|
||||
uint64_t ucp:1;
|
||||
};
|
||||
#endif
|
||||
430
qcom/opensource/dataipa/kernel-tests/UlsoTest.cpp
Normal file
430
qcom/opensource/dataipa/kernel-tests/UlsoTest.cpp
Normal file
@@ -0,0 +1,430 @@
|
||||
/*
|
||||
* Copyright (c) 2021 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* Changes from Qualcomm Innovation Center are provided under the following license:
|
||||
*
|
||||
* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted (subject to the limitations in the
|
||||
* disclaimer below) provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* * Neither the name of Qualcomm Innovation Center, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
|
||||
* GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
|
||||
* HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <cstring> // for memcpy
|
||||
#include "hton.h" // for htonl
|
||||
#include "InterfaceAbstraction.h"
|
||||
#include "Constants.h"
|
||||
#include "Logger.h"
|
||||
#include "TestsUtils.h"
|
||||
#include "UlsoTestFixture.h"
|
||||
#include "HeaderInsertion.h"
|
||||
|
||||
#define ARRAY_SIZE(A) (sizeof(ArraySizeHelper(A)))
|
||||
|
||||
template <typename T, size_t N>
|
||||
char (&ArraySizeHelper(T (&a)[N]))[N];
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using std::string;
|
||||
|
||||
using I4 = IPv4Header;
|
||||
using I6 = IPv6Header;
|
||||
using UDPH = UdpHeader;
|
||||
using TCPH = TcpHeader;
|
||||
|
||||
/* Packet modification function objects */
|
||||
template<typename PacketType> class PacketModifier {public:virtual void operator()(PacketType& p) const = 0; virtual ~PacketModifier(){}};
|
||||
template<typename PacketType> class NullPacketModifier: public PacketModifier<PacketType> {public:void operator()(PacketType& p) const override {}};
|
||||
template<typename PacketType> class ZeroChecksumPacketModifier: public PacketModifier<PacketType>
|
||||
{public:void operator()(PacketType& p) const override {p.mQmapHeader.setmZeroChecksum(1);}};
|
||||
template<typename PacketType> class OutOfBoundsPacketModifier: public PacketModifier<PacketType>
|
||||
{public:void operator()(PacketType& p) const override {p.mQmapHeader.setmIpIdCfg(0);p.setIpId(65530);}};
|
||||
|
||||
template<typename Transport, typename Internet, const size_t* SegmentSizesArr, size_t SegmentSizesArrSize, const float* SegmentsNumsArr,
|
||||
size_t SegmentsNumsArrSize, typename Modifier = NullPacketModifier<UlsoPacket<Transport, Internet>>>
|
||||
class PacketsGeneratorClass {
|
||||
|
||||
protected:
|
||||
|
||||
using PacketType = UlsoPacket<Transport, Internet>;
|
||||
|
||||
public:
|
||||
|
||||
vector<PacketType> operator()(){
|
||||
vector<PacketType> outVec;
|
||||
Modifier m;
|
||||
for(size_t i=0; i<SegmentSizesArrSize; i++){
|
||||
for(size_t j=0; j<SegmentsNumsArrSize; j++){
|
||||
PacketType p(SegmentSizesArr[i], static_cast<size_t>(SegmentSizesArr[i] * SegmentsNumsArr[j]), true);
|
||||
m(p);
|
||||
outVec.emplace_back(p);
|
||||
}
|
||||
}
|
||||
return outVec;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Transport, typename Internet, typename PacketsGenerator>
|
||||
class UlsoTest: public UlsoTestFixture {
|
||||
|
||||
private:
|
||||
|
||||
using PacketType = UlsoPacket<Transport, Internet>;
|
||||
|
||||
bool singlePacketRun(PacketType& p){
|
||||
memset(m_sendBuf, 0, sizeof(m_sendBuf));
|
||||
size_t packetSize = p.asArray(m_sendBuf);
|
||||
size_t numSent = m_producer.SendData(m_sendBuf, packetSize);
|
||||
|
||||
if(numSent == 0){
|
||||
return false;
|
||||
}
|
||||
vector<PacketType> segmentedPacketsVec = p.segment();
|
||||
for(auto& segmentedPacket: segmentedPacketsVec){
|
||||
memset(m_receiveBuf, 0, sizeof(m_receiveBuf));
|
||||
memset(m_segmentBuf, 0, sizeof(m_segmentBuf));
|
||||
packetSize = segmentedPacket.asArray(m_segmentBuf);
|
||||
size_t recievedBytes = m_consumer.ReceiveSingleDataChunk(m_receiveBuf, packetSize);
|
||||
if(packetSize != recievedBytes || memcmp(m_segmentBuf, m_receiveBuf, packetSize)){
|
||||
return fail(numSent, packetSize, recievedBytes);
|
||||
}
|
||||
}
|
||||
return clearPipe() == 0;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
UlsoTest(const char* name){
|
||||
m_name = name;
|
||||
string title = string("ULSO Test");
|
||||
string packetStructure = string("Structure: ") + string ("QMAP + Ethernet 2 + ")
|
||||
+ string(Internet().name()) + string(" ") + string(Transport().name());
|
||||
string testProcess = string(
|
||||
"1. Config IPA->APPS test pipe\n"
|
||||
"2. Generate a vector of ULSO packets\n"
|
||||
"3. For each packet in the packets vector\n"
|
||||
" a. Send the packet over the APPS->IPA pipe using ipa_tx_dp\n"
|
||||
" b. Segment the packet using the software simulation and store it in a segments vector\n"
|
||||
" c. For each segment in the segments vector in order\n"
|
||||
" # Receive a segment over IPA->APPS test pipe\n"
|
||||
" # Compare the received segment to the software simulated segment\n"
|
||||
"4. Clear the IPA->USB pipe and verify there were no bytes left in the pipe");
|
||||
m_description = string(title + "\n" + packetStructure + "\n" + testProcess + "\n").c_str();
|
||||
m_minIPAHwType = IPA_HW_v5_0;
|
||||
Register(*this);
|
||||
}
|
||||
|
||||
virtual bool Run() override {
|
||||
vector<PacketType> packetsVec = PacketsGenerator()();
|
||||
for(auto& p: packetsVec){
|
||||
if(!singlePacketRun(p)){
|
||||
cout << "Failed With the following packet:" << endl;
|
||||
cout << p << endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Transport, typename Internet, typename PacketsGenerator>
|
||||
class UlsoHPCTest: public UlsoTestFixture {
|
||||
|
||||
private:
|
||||
|
||||
using PacketType = UlsoPacket<Transport, Internet>;
|
||||
static constexpr size_t rndisHdrLen {44};
|
||||
HeaderInsertion m_HeaderInsertion;
|
||||
uint8_t mRndisHeader[rndisHdrLen] = {0};
|
||||
|
||||
bool fail(size_t sendSize=0, size_t totalSegmentsSize=0, size_t recievedBytes=0){
|
||||
printBuf(m_sendBuf, sendSize, "Sent:");
|
||||
printBuf(m_receiveBuf, recievedBytes, string("Rceived ")
|
||||
+ std::to_string(recievedBytes) + string(" Bytes:"));
|
||||
printBuf(m_segmentBuf, totalSegmentsSize, string("Expected to receive ")
|
||||
+ std::to_string(totalSegmentsSize) + string(" Bytes:"));
|
||||
clearPipe();
|
||||
return false;
|
||||
}
|
||||
|
||||
bool singlePacketRun(PacketType& p){
|
||||
cout << p << endl;
|
||||
memset(m_sendBuf, 0, sizeof(m_sendBuf));
|
||||
size_t sendSize = p.asArray(m_sendBuf);
|
||||
if(!m_producer.SendData(m_sendBuf, sendSize)){
|
||||
return fail(sendSize);
|
||||
}
|
||||
vector<PacketType> segmentedPacketsVec = p.segment();
|
||||
memset(m_segmentBuf, 0, sizeof(m_segmentBuf));
|
||||
uint8_t *segmentBufPtr = m_segmentBuf;
|
||||
size_t totalSegmentsSize = 0;
|
||||
vector<size_t> comparisionIntervalsSizesVec;
|
||||
for(auto& segmentedPacket: segmentedPacketsVec){
|
||||
memcpy(segmentBufPtr, mRndisHeader, sizeof(mRndisHeader));
|
||||
segmentBufPtr += sizeof(mRndisHeader);
|
||||
comparisionIntervalsSizesVec.emplace_back(sizeof(mRndisHeader));
|
||||
totalSegmentsSize += sizeof(mRndisHeader);
|
||||
size_t n = segmentedPacket.asArray(segmentBufPtr);
|
||||
segmentBufPtr += n;
|
||||
totalSegmentsSize += n;
|
||||
comparisionIntervalsSizesVec.emplace_back(n);
|
||||
}
|
||||
memset(m_receiveBuf, 0, sizeof(m_receiveBuf));
|
||||
size_t recievedBytes = m_consumer.ReceiveSingleDataChunk(m_receiveBuf, totalSegmentsSize);
|
||||
if(totalSegmentsSize != recievedBytes){
|
||||
return fail(sendSize, totalSegmentsSize, recievedBytes);
|
||||
}
|
||||
segmentBufPtr = m_segmentBuf;
|
||||
uint8_t *recieveBufPtr = m_receiveBuf;
|
||||
while(!comparisionIntervalsSizesVec.empty()){
|
||||
size_t skipSize = comparisionIntervalsSizesVec.front();
|
||||
recieveBufPtr += skipSize;
|
||||
segmentBufPtr += skipSize;
|
||||
comparisionIntervalsSizesVec.erase(comparisionIntervalsSizesVec.begin());
|
||||
if(comparisionIntervalsSizesVec.empty()){
|
||||
return fail(sendSize, totalSegmentsSize, recievedBytes);
|
||||
}
|
||||
size_t compareSize = comparisionIntervalsSizesVec.front();
|
||||
if(memcmp(segmentBufPtr, recieveBufPtr, compareSize)){
|
||||
return fail(sendSize, totalSegmentsSize, recievedBytes);
|
||||
}
|
||||
segmentBufPtr += compareSize;
|
||||
recieveBufPtr += compareSize;
|
||||
comparisionIntervalsSizesVec.erase(comparisionIntervalsSizesVec.begin());
|
||||
}
|
||||
if(clearPipe()){
|
||||
return fail(sendSize, totalSegmentsSize, recievedBytes);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
virtual void configFromEp(struct test_ipa_ep_cfg *ep_cfg){
|
||||
ep_cfg->hdr.hdr_len = ETH_HLEN + rndisHdrLen;
|
||||
ep_cfg->hdr.hdr_additional_const_len = ETH_HLEN;
|
||||
ep_cfg->hdr.hdr_ofst_pkt_size_valid = true;
|
||||
ep_cfg->hdr.hdr_ofst_pkt_size = 3 * sizeof(uint32_t);
|
||||
ep_cfg->hdr_ext.hdr_total_len_or_pad_offset = sizeof(uint32_t);
|
||||
ep_cfg->hdr_ext.hdr_total_len_or_pad = IPA_HDR_TOTAL_LEN;
|
||||
ep_cfg->hdr_ext.hdr_total_len_or_pad_valid = true;
|
||||
ep_cfg->hdr_ext.hdr_little_endian = true;
|
||||
ep_cfg->aggr.aggr_en = IPA_ENABLE_AGGR;
|
||||
ep_cfg->aggr.aggr = IPA_GENERIC;
|
||||
ep_cfg->aggr.aggr_byte_limit = 4;
|
||||
ep_cfg->aggr.aggr_time_limit = 1000;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
UlsoHPCTest(const char* name, const char* description){
|
||||
m_name = name;
|
||||
m_description = description;
|
||||
m_minIPAHwType = IPA_HW_v5_0;
|
||||
for(size_t i=0; i<rndisHdrLen; i++){
|
||||
mRndisHeader[i] = i;
|
||||
}
|
||||
Register(*this);
|
||||
}
|
||||
|
||||
virtual bool Run() override {
|
||||
string headerName("rndis");
|
||||
if(!m_HeaderInsertion.addHeaderHpc(headerName, mRndisHeader, rndisHdrLen, false, IPA_CLIENT_TEST_CONS)){
|
||||
LOG_MSG_ERROR("!m_HeaderInsertion.addHeaderHpc(headerName, mRndisHeader, 44, false, true) Failed.");
|
||||
return false;
|
||||
}
|
||||
vector<PacketType> packetsVec = PacketsGenerator()();
|
||||
for(auto& p: packetsVec){
|
||||
if(!singlePacketRun(p)){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(!m_HeaderInsertion.DeleteHeader(headerName)){
|
||||
LOG_MSG_ERROR("Delete rndis header failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
/* Tests Macros */
|
||||
#define PACKETS_GEN_MODIFY(T, I, a, b, m) PacketsGeneratorClass<T, I, a, ARRAY_SIZE(a), b, ARRAY_SIZE(b), m<UlsoPacket<T, I>>>
|
||||
#define PACKETS_GEN(T, I, a, b) PACKETS_GEN_MODIFY(T, I, a, b, NullPacketModifier)//todo: change macro parameters to meaningfull names
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/////////// Simple Single Packet Tests //////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/*
|
||||
* Send a single packet and compare the received segments to the software simulation
|
||||
*/
|
||||
constexpr size_t segmentSizes1[] = {20};
|
||||
constexpr float segmentsNum1[] = {5};
|
||||
static UlsoTest<UDPH, I4, PACKETS_GEN(UDPH, I4, segmentSizes1, segmentsNum1)> ulsoTest0 {"Single Packet: IPV4 UDP"};
|
||||
static UlsoTest<TCPH, I4, PACKETS_GEN(TCPH, I4, segmentSizes1, segmentsNum1)> ulsoTest1 {"Single Packet: IPV4 TCP"};
|
||||
static UlsoTest<UDPH, I6, PACKETS_GEN(UDPH, I6, segmentSizes1, segmentsNum1)> ulsoTest2 {"Single Packet: IPV6 UDP"};
|
||||
static UlsoTest<TCPH, I6, PACKETS_GEN(TCPH, I6, segmentSizes1, segmentsNum1)> ulsoTest3 {"Single Packet: IPV6 TCP"};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/////////// Segmentation & Non-Segmentation mix //////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/*
|
||||
* Send a sequence of [large, small, large, small, ...] packets and compare the received segments to the software simulation
|
||||
*/
|
||||
constexpr size_t segmentSizes2[] = {10, 50, 100, 500, 1460};
|
||||
constexpr float segmentsNum2[] = {1, 4};
|
||||
static UlsoTest<UDPH, I4, PACKETS_GEN(UDPH, I4, segmentSizes2, segmentsNum2)> ulsoTest10 {"Segmentation No Segmentation IPV4 UDP"};
|
||||
static UlsoTest<TCPH, I4, PACKETS_GEN(TCPH, I4, segmentSizes2, segmentsNum2)> ulsoTest11 {"Segmentation No Segmentation IPV4 TCP"};
|
||||
static UlsoTest<UDPH, I6, PACKETS_GEN(UDPH, I6, segmentSizes2, segmentsNum2)> ulsoTest12 {"Segmentation No Segmentation IPV6 UDP"};
|
||||
static UlsoTest<TCPH, I6, PACKETS_GEN(TCPH, I6, segmentSizes2, segmentsNum2)> ulsoTest13 {"Segmentation No Segmentation IPV6 TCP"};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////// Zero Checksum ////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/*
|
||||
* Send a sequence of large packets with zero checksum=1 and compare the received segments to the software simulation
|
||||
*/
|
||||
constexpr size_t segmentSizes3[] = {10, 50, 100, 500, 1460};
|
||||
constexpr float numSegments3[] = {4};
|
||||
static UlsoTest<UDPH, I4, PACKETS_GEN_MODIFY(UDPH, I4, segmentSizes3, numSegments3, ZeroChecksumPacketModifier)>
|
||||
ulsoTest20 {"Zero Checksum IPV4 UDP"};
|
||||
static UlsoTest<TCPH, I4, PACKETS_GEN_MODIFY(TCPH, I4, segmentSizes3, numSegments3, ZeroChecksumPacketModifier)>
|
||||
ulsoTest21 {"Zero Checksum IPV4 TCP"};
|
||||
static UlsoTest<UDPH, I6, PACKETS_GEN_MODIFY(UDPH, I6, segmentSizes3, numSegments3, ZeroChecksumPacketModifier)>
|
||||
ulsoTest22 {"Zero Checksum IPV6 UDP"};
|
||||
static UlsoTest<TCPH, I6, PACKETS_GEN_MODIFY(TCPH, I6, segmentSizes3, numSegments3, ZeroChecksumPacketModifier)>
|
||||
ulsoTest23 {"Zero Checksum IPV6 TCP"};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
///////// Segment Size Greater Than Payload Size /////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/*
|
||||
* Send a single packet with payload size and MSS matching an edge case and edge case and compare the received segments to the software simulation.
|
||||
* Edge cases:
|
||||
* 1. payload size < MSS ==> No segmentation
|
||||
* 2. payload size == MSS - epsilon ==> No segmentation
|
||||
* 3. payload size == MSS ==> Segmentation
|
||||
*/
|
||||
/* Segment Size = 100 Payload Size = 50 */
|
||||
constexpr size_t segmentSizes4[] = {100};
|
||||
constexpr float numSegments4[] = {0.5};
|
||||
static UlsoTest<UDPH, I4, PACKETS_GEN(UDPH, I4, segmentSizes4, numSegments4)> ulsoTest30 {"Payload Smaller Than MSS IPV4 UDP"};
|
||||
static UlsoTest<TCPH, I4, PACKETS_GEN(TCPH, I4, segmentSizes4, numSegments4)> ulsoTest31 {"Payload Smaller Than MSS IPV4 TCP"};
|
||||
static UlsoTest<UDPH, I6, PACKETS_GEN(UDPH, I6, segmentSizes4, numSegments4)> ulsoTest32 {"Payload Smaller Than MSS IPV6 UDP"};
|
||||
static UlsoTest<TCPH, I6, PACKETS_GEN(TCPH, I6, segmentSizes4, numSegments4)> ulsoTest33 {"Payload Smaller Than MSS IPV6 TCP"};
|
||||
|
||||
/* Segment Size = 100 Payload Size = 99 */
|
||||
constexpr size_t segmentSizes5[] = {100};
|
||||
constexpr float numSegments5[] = {0.99};
|
||||
static UlsoTest<UDPH, I4, PACKETS_GEN(UDPH, I4, segmentSizes5, numSegments5)> ulsoTest40 {"Payload slightly Smaller Than MSS IPV4 UDP"};
|
||||
static UlsoTest<TCPH, I4, PACKETS_GEN(TCPH, I4, segmentSizes5, numSegments5)> ulsoTest41 {"Payload slightly Smaller Than MSS IPV4 TCP"};
|
||||
static UlsoTest<UDPH, I6, PACKETS_GEN(UDPH, I6, segmentSizes5, numSegments5)> ulsoTest42 {"Payload slightly Smaller Than MSS IPV6 UDP"};
|
||||
static UlsoTest<TCPH, I6, PACKETS_GEN(TCPH, I6, segmentSizes5, numSegments5)> ulsoTest43 {"Payload slightly Smaller Than MSS IPV6 TCP"};
|
||||
|
||||
/* Segment Size = 20 Payload Size = 20 */
|
||||
constexpr size_t segmentSizes6[] = {100};
|
||||
constexpr float numSegments6[] = {1};
|
||||
static UlsoTest<UDPH, I4, PACKETS_GEN(UDPH, I4, segmentSizes6, numSegments6)> ulsoTest50 {"Payload Equals MSS IPV4 UDP"};
|
||||
static UlsoTest<TCPH, I4, PACKETS_GEN(TCPH, I4, segmentSizes6, numSegments6)> ulsoTest51 {"Payload Equals MSS IPV4 TCP"};
|
||||
static UlsoTest<UDPH, I6, PACKETS_GEN(UDPH, I6, segmentSizes6, numSegments6)> ulsoTest52 {"Payload Equals MSS IPV6 UDP"};
|
||||
static UlsoTest<TCPH, I6, PACKETS_GEN(TCPH, I6, segmentSizes6, numSegments6)> ulsoTest53 {"Payload Equals MSS IPV6 TCP"};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////// Valid Segment Sizes /////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/*
|
||||
* Send a sequence of packets with different valid sizes and compare the received segments to the software simulation
|
||||
*/
|
||||
constexpr size_t segmentSizes7[] = {1460, 1220, 512, 1};
|
||||
static UlsoTest<UDPH, I4, PACKETS_GEN(UDPH, I4, segmentSizes7, segmentsNum1)> ulsoTest60 {"Valid Segment Sizes IPV4 UDP"};
|
||||
static UlsoTest<TCPH, I4, PACKETS_GEN(TCPH, I4, segmentSizes7, segmentsNum1)> ulsoTest61 {"Valid Segment Sizes IPV4 TCP"};
|
||||
static UlsoTest<UDPH, I6, PACKETS_GEN(UDPH, I6, segmentSizes7, segmentsNum1)> ulsoTest62 {"Valid Segment Sizes IPV6 UDP"};
|
||||
static UlsoTest<TCPH, I6, PACKETS_GEN(TCPH, I6, segmentSizes7, segmentsNum1)> ulsoTest63 {"Valid Segment Sizes IPV6 TCP"};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////// Big Segment Sizes /////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/*
|
||||
* Send a sequence of very large packets and compare the received segments to the software simulation
|
||||
*/
|
||||
constexpr size_t segmentSizes8[] = {2000, 3000, 4000, 5000, 6000, 10000};
|
||||
static UlsoTest<UDPH, I4, PACKETS_GEN(UDPH, I4, segmentSizes8, segmentsNum1)> ulsoTest70 {"Big Segment Sizes IPV4 UDP"};
|
||||
static UlsoTest<TCPH, I4, PACKETS_GEN(TCPH, I4, segmentSizes8, segmentsNum1)> ulsoTest71 {"Big Segment Sizes IPV4 TCP"};
|
||||
static UlsoTest<UDPH, I6, PACKETS_GEN(UDPH, I6, segmentSizes8, segmentsNum1)> ulsoTest72 {"Big Segment Sizes IPV6 UDP"};
|
||||
static UlsoTest<TCPH, I6, PACKETS_GEN(TCPH, I6, segmentSizes8, segmentsNum1)> ulsoTest73 {"Big Segment Sizes IPV6 TCP"};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////// IP ID wrapp around min/max bounds ///////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/*
|
||||
* Send a single packet such that:
|
||||
* IPID + #segments < MAX IPID
|
||||
* and compare the received segments to the software simulation
|
||||
*/
|
||||
constexpr size_t segmentSizes9[] = {2000};
|
||||
constexpr float numSegments9[] = {10};
|
||||
static UlsoTest<UDPH, I4, PACKETS_GEN_MODIFY(UDPH, I4, segmentSizes9, numSegments9, OutOfBoundsPacketModifier)> ulsoTest80 {"IPID CFG IPV4 UDP"};
|
||||
static UlsoTest<TCPH, I4, PACKETS_GEN_MODIFY(TCPH, I4, segmentSizes9, numSegments9, OutOfBoundsPacketModifier)> ulsoTest81 {"IPID CFG IPV4 UDP"};
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////// HPC RNDIS Header Insertion //////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static UlsoHPCTest<UDPH, I4, PACKETS_GEN(UDPH, I4, segmentSizes1, segmentsNum1)> Ipv4UdpHpcRndisTest {"Ipv4UdpHpcRndisTest", "IPv4 + UDP"};
|
||||
static UlsoHPCTest<TCPH, I4, PACKETS_GEN(TCPH, I4, segmentSizes1, segmentsNum1)> Ipv4TcpHpcRndisTest {"Ipv4TcpHpcRndisTest", "IPv4 + TCP"};
|
||||
static UlsoHPCTest<UDPH, I6, PACKETS_GEN(UDPH, I6, segmentSizes1, segmentsNum1)> Ipv6UdpHpcRndisTest {"Ipv6UdpHpcRndisTest", "IPv6 + UDP"};
|
||||
static UlsoHPCTest<TCPH, I6, PACKETS_GEN(TCPH, I6, segmentSizes1, segmentsNum1)> Ipv6TcpHpcRndisTest {"Ipv6TcpHpcRndisTest", "IPv6 + TCP"};
|
||||
176
qcom/opensource/dataipa/kernel-tests/UlsoTestFixture.h
Normal file
176
qcom/opensource/dataipa/kernel-tests/UlsoTestFixture.h
Normal file
@@ -0,0 +1,176 @@
|
||||
/*
|
||||
* Copyright (c) 2021 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef ULSOTESTFIXTURE_H_
|
||||
#define ULSOTESTFIXTURE_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <linux/if_ether.h>
|
||||
|
||||
#include "Constants.h"
|
||||
#include "Logger.h"
|
||||
#include "linux/msm_ipa.h"
|
||||
#include "TestsUtils.h"
|
||||
#include "TestBase.h"
|
||||
#include "network_traffic/UlsoPacket.h"
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using std::string;
|
||||
|
||||
class UlsoTestFixture: public TestBase {
|
||||
|
||||
public:
|
||||
|
||||
UlsoTestFixture(){
|
||||
m_testSuiteName.push_back("ULSO");
|
||||
memset(m_sendBuf, 0, sizeof(m_sendBuf));
|
||||
memset(m_receiveBuf, 0, sizeof(m_receiveBuf));
|
||||
memset(m_segmentBuf, 0, sizeof(m_segmentBuf));
|
||||
}
|
||||
|
||||
virtual bool Setup() {
|
||||
if(!setupKernelModule()){
|
||||
return false;
|
||||
}
|
||||
m_producer.Open(INTERFACE0_TO_IPA_DATA_PATH, INTERFACE0_FROM_IPA_DATA_PATH);
|
||||
m_consumer.Open(INTERFACE1_TO_IPA_DATA_PATH, INTERFACE1_FROM_IPA_DATA_PATH);
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool Teardown(){
|
||||
m_producer.Close();
|
||||
m_consumer.Close();
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool Run() = 0;
|
||||
|
||||
protected:
|
||||
|
||||
virtual void configFromEp(struct test_ipa_ep_cfg *ep_cfg){
|
||||
return;
|
||||
}
|
||||
|
||||
size_t clearPipe(){
|
||||
cout << "In clearPipe" << endl;
|
||||
if(m_consumer.setReadNoBlock() == -1){
|
||||
cout << "Error: setReadNoBlock returned -1" << endl;
|
||||
return 0;
|
||||
}
|
||||
size_t recievedBytes = m_consumer.ReceiveSingleDataChunk(m_receiveBuf, UlsoPacket<>::maxSize);
|
||||
size_t totalReceivedBytes = recievedBytes;
|
||||
if(recievedBytes > 0){
|
||||
unsigned count = 1;
|
||||
while(recievedBytes){
|
||||
cout << "Receive #" << count << endl;
|
||||
printBuf(m_receiveBuf, recievedBytes, string("Rceived ")
|
||||
+ std::to_string(recievedBytes) + string(" Bytes:"));
|
||||
recievedBytes = m_consumer.ReceiveSingleDataChunk(m_receiveBuf, UlsoPacket<>::maxSize);
|
||||
totalReceivedBytes += recievedBytes;
|
||||
count ++;
|
||||
}
|
||||
} else {
|
||||
cout << "There were no bytes left in the pipe" << endl;
|
||||
}
|
||||
m_consumer.clearReadNoBlock();
|
||||
return totalReceivedBytes;
|
||||
}
|
||||
|
||||
bool fail(size_t sendSize=0, size_t totalSegmentsSize=0, size_t recievedBytes=0){
|
||||
printBuf(m_sendBuf, sendSize, "Sent:");
|
||||
printBuf(m_receiveBuf, recievedBytes, string("Rceived ") + std::to_string(recievedBytes) + string(" Bytes:"));
|
||||
printBuf(m_segmentBuf, totalSegmentsSize, string("Expected to receive ") + std::to_string(totalSegmentsSize) + string(" Bytes:"));
|
||||
clearPipe();
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual int setupKernelModule(bool en_status = 0){
|
||||
struct ipa_channel_config from_ipa_channels[1];
|
||||
struct test_ipa_ep_cfg from_ipa_cfg[1];
|
||||
struct ipa_channel_config to_ipa_channels[1];
|
||||
struct test_ipa_ep_cfg to_ipa_cfg[1];
|
||||
|
||||
struct ipa_test_config_header header = {0};
|
||||
struct ipa_channel_config *to_ipa_array[1];
|
||||
struct ipa_channel_config *from_ipa_array[1];
|
||||
|
||||
/* From ipa configurations - 1 pipe */
|
||||
memset(&from_ipa_cfg[0], 0, sizeof(from_ipa_cfg[0]));
|
||||
from_ipa_cfg[0].ulso.is_ulso_pipe = true;
|
||||
configFromEp(&from_ipa_cfg[0]);
|
||||
|
||||
prepare_channel_struct(&from_ipa_channels[0],
|
||||
header.from_ipa_channels_num++,
|
||||
IPA_CLIENT_TEST_CONS,
|
||||
(void *)&from_ipa_cfg[0],
|
||||
sizeof(from_ipa_cfg[0]),
|
||||
en_status);
|
||||
from_ipa_array[0] = &from_ipa_channels[0];
|
||||
|
||||
/* To ipa configurations - 1 pipe */
|
||||
memset(&to_ipa_cfg[0], 0, sizeof(to_ipa_cfg[0]));
|
||||
to_ipa_cfg[0].ulso.ipid_min_max_idx = 0;
|
||||
to_ipa_cfg[0].ulso.is_ulso_pipe = true;
|
||||
prepare_channel_struct(&to_ipa_channels[0],
|
||||
header.to_ipa_channels_num++,
|
||||
IPA_CLIENT_TEST_PROD,
|
||||
(void *)&to_ipa_cfg[0],
|
||||
sizeof(to_ipa_cfg[0]));
|
||||
to_ipa_array[0] = &to_ipa_channels[0];
|
||||
|
||||
prepare_header_struct(&header, from_ipa_array, to_ipa_array);
|
||||
|
||||
return GenericConfigureScenario(&header, true);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
static void printBuf(uint8_t* buf, size_t bufSize, string title=""){
|
||||
if(bufSize == 0){
|
||||
return;
|
||||
}
|
||||
cout << title << endl << std::hex;
|
||||
for (size_t i = 0; i < bufSize-1; i++)
|
||||
cout << std::setfill('0') << std::setw(2) << static_cast<int>(buf[i]) << " ";
|
||||
cout << std::setfill('0') << std::setw(2) << static_cast<int>(buf[bufSize-1]) << std::dec << endl;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
InterfaceAbstraction m_producer;
|
||||
InterfaceAbstraction m_consumer;
|
||||
uint8_t m_sendBuf[UlsoPacket<>::maxSize];
|
||||
uint8_t m_receiveBuf[UlsoPacket<>::maxSize];
|
||||
uint8_t m_segmentBuf[UlsoPacket<>::maxSize];
|
||||
};
|
||||
#endif /* ULSOTESTFIXTURE_H_ */
|
||||
12
qcom/opensource/dataipa/kernel-tests/autogen.sh
Executable file
12
qcom/opensource/dataipa/kernel-tests/autogen.sh
Executable file
@@ -0,0 +1,12 @@
|
||||
#!/bin/sh
|
||||
|
||||
# autogen.sh -- Autotools bootstrapping
|
||||
#
|
||||
|
||||
AUTO_TOOLS_VER=$(automake --version | grep ^automake | sed 's/^.* //g' | cut -d'.' -f1-2)
|
||||
|
||||
aclocal-${AUTO_TOOLS_VER} &&\
|
||||
autoheader &&\
|
||||
autoconf &&\
|
||||
automake-${AUTO_TOOLS_VER} --add-missing --copy
|
||||
|
||||
129
qcom/opensource/dataipa/kernel-tests/build_kernel_tests.py
Normal file
129
qcom/opensource/dataipa/kernel-tests/build_kernel_tests.py
Normal file
@@ -0,0 +1,129 @@
|
||||
#! /usr/bin/env python
|
||||
|
||||
# Copyright (c) 2021, The Linux Foundation. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
# met:
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above
|
||||
# copyright notice, this list of conditions and the following
|
||||
# disclaimer in the documentation and/or other materials provided
|
||||
# with the distribution.
|
||||
# * Neither the name of The Linux Foundation nor the names of its
|
||||
# contributors may be used to endorse or promote products derived
|
||||
# from this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import os
|
||||
import os.path
|
||||
import subprocess
|
||||
import sys
|
||||
import shutil
|
||||
|
||||
install_dir = '/ipa-kernel-tests' # unlikely to ever change, so 'file constant'
|
||||
|
||||
|
||||
def get_args():
|
||||
class Args:
|
||||
pass
|
||||
|
||||
args = Args()
|
||||
|
||||
try:
|
||||
args.cc_path = os.path.dirname(os.environ['CROSS_COMPILE'])
|
||||
except:
|
||||
args.cc_path = None
|
||||
|
||||
try:
|
||||
args.arch = os.environ['ARCH']
|
||||
except:
|
||||
raise Exception("ARCH must be set")
|
||||
|
||||
try:
|
||||
args.kdir = os.environ['KDIR']
|
||||
except:
|
||||
raise Exception("KDIR must be set")
|
||||
|
||||
try:
|
||||
args.dest = os.environ['DESTDIR']
|
||||
except:
|
||||
raise Exception("DESTDIR must be set")
|
||||
|
||||
return args
|
||||
|
||||
|
||||
def do(cmd, wdir=None):
|
||||
cwd = None
|
||||
if wdir:
|
||||
cwd = os.getcwd()
|
||||
os.chdir(wdir)
|
||||
subprocess.check_call(cmd)
|
||||
if cwd:
|
||||
os.chdir(cwd)
|
||||
|
||||
|
||||
def build(args):
|
||||
|
||||
if args.cc_path:
|
||||
os.environ['PATH'] = args.cc_path + ':' + os.environ['PATH']
|
||||
|
||||
args.uapi = args.kdir + '/usr/include'
|
||||
args.src = args.kdir + '/techpack/dataipa/kernel-tests'
|
||||
args.inc = args.kdir + '/techpack/dataipa/drivers/platform/msm/ipa/ipa_test_module'
|
||||
|
||||
full_uapi = os.path.abspath(args.uapi)
|
||||
os.environ['CPPFLAGS'] = ('-I' + full_uapi)
|
||||
full_inc = os.path.abspath(args.inc)
|
||||
os.environ['CPPFLAGS'] += (' -I' + full_inc)
|
||||
|
||||
configure(args, args.src)
|
||||
|
||||
do(['make'], args.src)
|
||||
do(['make', 'DESTDIR=' + args.dest, 'install'], args.src)
|
||||
|
||||
|
||||
def configure(args, wdir):
|
||||
|
||||
if os.path.isfile(os.path.join(wdir, 'config.h')):
|
||||
return
|
||||
|
||||
do(['libtoolize'], wdir)
|
||||
do(['./autogen.sh'], wdir)
|
||||
|
||||
full_idir = os.path.abspath(os.path.join(wdir, install_dir))
|
||||
host_str = 'arm-linux-gnueabihf'
|
||||
config_extra = ''
|
||||
if args.arch == 'arm64':
|
||||
host_str = 'aarch64-linux-gnu'
|
||||
config_extra = '--disable-swp'
|
||||
do(['./configure',
|
||||
'--host=' + host_str,
|
||||
'--prefix=' + full_idir,
|
||||
config_extra], wdir)
|
||||
|
||||
|
||||
def main():
|
||||
rc = 0
|
||||
try:
|
||||
args = get_args()
|
||||
build(args)
|
||||
except Exception as e:
|
||||
rc = 1
|
||||
print(e)
|
||||
sys.exit(rc)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
56
qcom/opensource/dataipa/kernel-tests/configure.ac
Normal file
56
qcom/opensource/dataipa/kernel-tests/configure.ac
Normal file
@@ -0,0 +1,56 @@
|
||||
AC_PREREQ(2.64)
|
||||
|
||||
AC_INIT([ipa-kernel-tests],[1.0.0])
|
||||
AM_INIT_AUTOMAKE([-Wall -Werror gnu foreign])
|
||||
|
||||
AM_MAINTAINER_MODE
|
||||
|
||||
AC_CONFIG_HEADER([config.h])
|
||||
AC_CONFIG_MACRO_DIR([m4])
|
||||
|
||||
# Checks for programs.
|
||||
AC_PROG_CC
|
||||
AM_PROG_CC_C_O
|
||||
m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
|
||||
AC_PROG_LIBTOOL
|
||||
AC_PROG_CPP
|
||||
AC_PROG_INSTALL
|
||||
AC_PROG_MAKE_SET
|
||||
AC_PROG_CXX
|
||||
|
||||
|
||||
AS_CASE([$host],
|
||||
[aarch64*], [ARM64=yes],
|
||||
[ARM64=no]
|
||||
)
|
||||
|
||||
AM_CONDITIONAL(ARM64, [test "x$ARM64" = "xyes"])
|
||||
|
||||
AC_ARG_WITH([glib],
|
||||
AC_HELP_STRING([--with-glib],
|
||||
[enable glib, building HLOS systems which use glib]))
|
||||
|
||||
AC_ARG_WITH(ipanat-headers,
|
||||
AS_HELP_STRING([--with-ipanat-headers=DIR],
|
||||
[Specify the location of the ipanat headers]),
|
||||
[CPPFLAGS="$CPPFLAGS -idirafter $withval"])
|
||||
|
||||
if (test "x${with_glib}" = "xyes"); then
|
||||
AC_DEFINE(ENABLE_USEGLIB, 1, [Define if HLOS systems uses glib])
|
||||
PKG_CHECK_MODULES(GTHREAD, gthread-2.0 >= 2.16, dummy=yes,
|
||||
AC_MSG_ERROR(GThread >= 2.16 is required))
|
||||
PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.16, dummy=yes,
|
||||
AC_MSG_ERROR(GLib >= 2.16 is required))
|
||||
GLIB_CFLAGS="$GLIB_CFLAGS $GTHREAD_CFLAGS"
|
||||
GLIB_LIBS="$GLIB_LIBS $GTHREAD_LIBS"
|
||||
|
||||
AC_SUBST(GLIB_CFLAGS)
|
||||
AC_SUBST(GLIB_LIBS)
|
||||
fi
|
||||
|
||||
AM_CONDITIONAL(USE_GLIB, test "x${with_glib}" = "xyes")
|
||||
|
||||
AC_CONFIG_FILES([
|
||||
Makefile
|
||||
])
|
||||
AC_OUTPUT
|
||||
80
qcom/opensource/dataipa/kernel-tests/create_symlinks.sh
Executable file
80
qcom/opensource/dataipa/kernel-tests/create_symlinks.sh
Executable file
@@ -0,0 +1,80 @@
|
||||
# Copyright (c) 2021, The Linux Foundation. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
# met:
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above
|
||||
# copyright notice, this list of conditions and the following
|
||||
# disclaimer in the documentation and/or other materials provided
|
||||
# with the distribution.
|
||||
# * Neither the name of The Linux Foundation nor the names of its
|
||||
# contributors may be used to endorse or promote products derived
|
||||
# from this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
# This script creates symlinks for tests that are compiled as Soong modules, so
|
||||
# that they may be accessed from their old location in /data/kernel-tests
|
||||
|
||||
#!/bin/sh
|
||||
|
||||
NTEST_PATH="/data/nativetest"
|
||||
KTEST_PATH="/data/kernel-tests"
|
||||
|
||||
# Any test that is compiled as a cc_test module (which applies to any Soong
|
||||
# module in kernel-tests-internal) is given a directory, in to which the
|
||||
# compiled test and its supporting files are placed. This function iterates
|
||||
# over the test directories in $1 and creates symlinks to all the files
|
||||
# contained within a given test directory. $2 and later arguemnts can be used to
|
||||
# specify directores to skip.
|
||||
create_links()
|
||||
{
|
||||
BASE_PATH="$1"
|
||||
shift
|
||||
SKIP_FILES=$@ # These can also be directories
|
||||
|
||||
for TEST_DIR in `ls "$BASE_PATH"`; do
|
||||
# Filter out any file / directory in SKIP_FILES.
|
||||
SHOULD_SKIP=""
|
||||
for i in $SKIP_FILES; do
|
||||
if [ "$TEST_DIR" = "$i" ]; then
|
||||
SHOULD_SKIP="TRUE"
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [ ! "$SHOULD_SKIP" = "" ]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
|
||||
# Filter out any files that aren't directories (since every test we
|
||||
# compile is given a directory)
|
||||
if [ ! -d "$BASE_PATH/$TEST_DIR" ]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
# Now, create the symlinks for each test file inside of TEST_DIR
|
||||
for TEST_FILE in `ls "$BASE_PATH/$TEST_DIR"`; do
|
||||
ln -fs "$BASE_PATH/$TEST_DIR/$TEST_FILE" "$KTEST_PATH/$TEST_FILE"
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
# Create /data/kernel-tests, if it doesn't exist already
|
||||
mkdir -p "$KTEST_PATH"
|
||||
|
||||
# Create the symlinks
|
||||
create_links "$NTEST_PATH" "vendor"
|
||||
create_links "$NTEST_PATH/vendor"
|
||||
39
qcom/opensource/dataipa/kernel-tests/hton.h
Normal file
39
qcom/opensource/dataipa/kernel-tests/hton.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2017 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef HTON_H_
|
||||
#define HTON_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include "linux/msm_ipa.h"
|
||||
|
||||
#include <netinet/in.h>
|
||||
|
||||
#endif
|
||||
|
||||
439
qcom/opensource/dataipa/kernel-tests/main.cpp
Normal file
439
qcom/opensource/dataipa/kernel-tests/main.cpp
Normal file
@@ -0,0 +1,439 @@
|
||||
/*
|
||||
* Copyright (c) 2017-2018,2020 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* Changes from Qualcomm Innovation Center are provided under the following license:
|
||||
*
|
||||
* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted (subject to the limitations in the
|
||||
* disclaimer below) provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* * Neither the name of Qualcomm Innovation Center, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
|
||||
* GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
|
||||
* HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
|
||||
*/
|
||||
|
||||
#include <getopt.h>
|
||||
|
||||
#include "Logger.h"
|
||||
#include "TestManager.h"
|
||||
#include "TestsUtils.h"
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
#include <set>
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
Logger g_Logger(LOG_ERROR);
|
||||
#define CHOOSER_MODE "--chooser"
|
||||
#define SHOW_TEST_FLAG "--show_tests"
|
||||
#define SHOW_SUIT_FLAG "--show_suites"
|
||||
#define RUN_TEST_FLAG "--test"
|
||||
#define RUN_SUIT_FLAG "--suite"
|
||||
string sFormat = "ip_accelerator <control_flag> <suit/name>, ..., <suit/name>\n"
|
||||
"contorl_flag = " RUN_TEST_FLAG " or " RUN_SUIT_FLAG "\n"
|
||||
"ip_accelerator " SHOW_TEST_FLAG "\n"
|
||||
"ip_accelerator " SHOW_SUIT_FLAG "\n"
|
||||
"or ip_accelerator --chooser "
|
||||
"for menu chooser interface\n";
|
||||
#define MAX_SUITES 19
|
||||
|
||||
#undef strcasesame
|
||||
#define strcasesame(x, y) \
|
||||
(! strcasecmp((x), (y)))
|
||||
|
||||
#undef legal_nat_mem_type
|
||||
#define legal_nat_mem_type(mt) \
|
||||
( strcasesame(mt, "DDR") || \
|
||||
strcasesame(mt, "SRAM") || \
|
||||
strcasesame(mt, "HYBRID") )
|
||||
|
||||
TestManager *testmanager = NULL;
|
||||
|
||||
enum ipa_test_type{
|
||||
TEST = 1,
|
||||
SUITE,
|
||||
EXIT,
|
||||
MAX_TYPE
|
||||
};
|
||||
|
||||
const char *ipa_hw_type_name[] = {
|
||||
"None",
|
||||
"1.0",
|
||||
"1.1",
|
||||
"2.0",
|
||||
"2.1",
|
||||
"2.5/2.6",
|
||||
"2.6L",
|
||||
"Unused",
|
||||
"Unused",
|
||||
"Unused",
|
||||
"3.0",
|
||||
"3.1",
|
||||
"3.5",
|
||||
"3.5.1",
|
||||
"4.0",
|
||||
"4.1",
|
||||
"4.2",
|
||||
"4.5",
|
||||
"4.7",
|
||||
"4.9",
|
||||
"4.11",
|
||||
"5.0",
|
||||
"5.1",
|
||||
"5.5",
|
||||
"MAX"
|
||||
};
|
||||
|
||||
void BuildRegressionTestSuite()
|
||||
{
|
||||
TestBase *test;
|
||||
|
||||
for (unsigned int i = 0; i < testmanager->m_testList.size(); i++) {
|
||||
test = testmanager->m_testList[i];
|
||||
if (test->m_runInRegression) {
|
||||
test->m_testSuiteName.push_back("Regression");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
void showTests()
|
||||
{
|
||||
TestBase *test = testmanager->m_testList[0];
|
||||
|
||||
for (unsigned i = 0; i < testmanager->m_testList.size(); i++) {
|
||||
test = testmanager->m_testList[i];
|
||||
string name = test->m_name, index = test->m_testSuiteName[0];
|
||||
|
||||
printf("%d) %s (part of %s suite" ,i+1, name.c_str(), index.c_str());
|
||||
for (unsigned j = 0; j < test->m_testSuiteName.size(); ++j) {
|
||||
if ( test->m_testSuiteName[j] == index)
|
||||
continue;
|
||||
printf(", %s suite",
|
||||
test->m_testSuiteName[j].c_str());
|
||||
index = test->m_testSuiteName[j];
|
||||
}
|
||||
printf("), (%s <= HW Version <= %s)\n",
|
||||
ipa_hw_type_name[test->m_minIPAHwType],
|
||||
ipa_hw_type_name[test->m_maxIPAHwType]);
|
||||
}
|
||||
|
||||
// Example:
|
||||
// 15) DmaModeMBIMggregationLoopTest (part of DmaMbim16Agg suite), (1.0 <= HW Version <= 2.1)
|
||||
}
|
||||
|
||||
void showSuits()
|
||||
{
|
||||
TestBase *test;
|
||||
std::set<string> suiteSet;
|
||||
int suiteIndex = 1;
|
||||
|
||||
test = testmanager->m_testList[0];
|
||||
|
||||
for (unsigned i = 0; i < testmanager->m_testList.size(); i++) {
|
||||
test = testmanager->m_testList[i];
|
||||
for (unsigned j = 0; j < test->m_testSuiteName.size() ; j++)
|
||||
suiteSet.insert(test->m_testSuiteName[j]);
|
||||
}
|
||||
|
||||
for (std::set<string>::iterator i = suiteSet.begin();
|
||||
i != suiteSet.end(); suiteIndex++) {
|
||||
printf("%d) %s\n", suiteIndex, (*i).c_str());
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
void preparTests(int argc, char* argv[],
|
||||
vector<string>& list)
|
||||
{
|
||||
for (int i = 2; i < argc; i++)
|
||||
list.push_back(argv[i]);
|
||||
}
|
||||
|
||||
const char* getSuite(int suite_num) {
|
||||
int count = 0, suiteIndex = 1;
|
||||
string result = "error";
|
||||
TestBase *test = testmanager->m_testList[0];
|
||||
set<string> suiteSet;
|
||||
|
||||
if (testmanager->m_testList.size() < 1)
|
||||
return NULL;
|
||||
|
||||
if (count == suite_num)
|
||||
return testmanager->m_testList[0]->m_testSuiteName[0].c_str();
|
||||
|
||||
for (unsigned i = 0; i < testmanager->m_testList.size(); i++) {
|
||||
test = testmanager->m_testList[i];
|
||||
for (unsigned j = 0; j < test->m_testSuiteName.size() ; j++)
|
||||
suiteSet.insert(test->m_testSuiteName[j]);
|
||||
}
|
||||
|
||||
for (std::set<string>::iterator i = suiteSet.begin();
|
||||
i != suiteSet.end(); suiteIndex++) {
|
||||
printf("%d) %s\n", suiteIndex, (*i).c_str());
|
||||
if (suiteIndex == suite_num)
|
||||
return (*i).c_str();
|
||||
++i;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int chooserMode() {
|
||||
vector<string> testSuiteList;
|
||||
vector<string> testNameList;
|
||||
unsigned int test_num;
|
||||
int suite_num;
|
||||
int type;
|
||||
TestBase *test;
|
||||
const char* res;
|
||||
int result = 0;
|
||||
char input_str[4];
|
||||
char* temp;
|
||||
|
||||
printf("Welcome to the ip_accelerator\nChoose an option:\n");
|
||||
printf("1) Run tests\n2) Run suites\n3) Exit\nChoose an option: ");
|
||||
temp = fgets(input_str, sizeof(input_str), stdin);
|
||||
if (!temp) {
|
||||
printf("Error: fgets returned nullptr !!");
|
||||
return -1;
|
||||
}
|
||||
type = atoi(input_str);
|
||||
switch((enum ipa_test_type)type) {
|
||||
case TEST:
|
||||
BuildRegressionTestSuite();
|
||||
showTests();
|
||||
printf("Choose which test you wish to run: \n");
|
||||
fflush(stdin);
|
||||
temp = fgets(input_str, sizeof(input_str), stdin);
|
||||
if (!temp) {
|
||||
printf("Error: fgets returned nullptr !!");
|
||||
return -1;
|
||||
}
|
||||
test_num = atoi(input_str);
|
||||
if ( test_num > testmanager->m_testList.size()) {
|
||||
printf("Invalid test number. Try again\n");
|
||||
result = -1;
|
||||
break;
|
||||
}
|
||||
test = testmanager->m_testList[test_num-1];
|
||||
printf("Running Test %s\n",
|
||||
test->m_name.
|
||||
c_str());
|
||||
testNameList.push_back(test->m_name.c_str());
|
||||
BuildRegressionTestSuite();
|
||||
testmanager->Run(testSuiteList, testNameList);
|
||||
testNameList.clear();
|
||||
break;
|
||||
case SUITE:
|
||||
BuildRegressionTestSuite();
|
||||
showSuits();
|
||||
printf("Choose which suite you wish to run: \n");
|
||||
fflush(stdin);
|
||||
temp = fgets(input_str, sizeof(input_str), stdin);
|
||||
if (!temp) {
|
||||
printf("Error: fgets returned nullptr !!");
|
||||
return -1;
|
||||
}
|
||||
suite_num = atoi(input_str);
|
||||
if (suite_num < 0 || suite_num > MAX_SUITES) {
|
||||
printf("Invalid test number. Try again\n");
|
||||
result = -1;
|
||||
break;
|
||||
}
|
||||
res = getSuite(suite_num);
|
||||
if (!res) {
|
||||
printf("Error in getSuite. Exiting\n");
|
||||
result = -1;
|
||||
break;
|
||||
}
|
||||
testSuiteList.push_back(res);
|
||||
testmanager->Run(testSuiteList, testNameList);
|
||||
testSuiteList.clear();
|
||||
break;
|
||||
default:
|
||||
printf("Exiting\n");
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int scriptMode(int argc, char* argv[]) {
|
||||
vector<string> testSuiteList;
|
||||
vector<string> testNameList;
|
||||
string sControlFlag;
|
||||
|
||||
if (argc < 2) {
|
||||
printf("please use correct format:\n%s", sFormat.c_str());
|
||||
return -1;
|
||||
}
|
||||
|
||||
sControlFlag = argv[1];
|
||||
|
||||
if (sControlFlag.find("--") == string::npos) {
|
||||
printf("please use correct format:\n%s", sFormat.c_str());
|
||||
return -1;
|
||||
}
|
||||
|
||||
BuildRegressionTestSuite();
|
||||
|
||||
if (sControlFlag.compare(SHOW_TEST_FLAG) == 0) {
|
||||
showTests();
|
||||
return 0;
|
||||
} else if (sControlFlag.compare(SHOW_SUIT_FLAG) == 0) {
|
||||
showSuits();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (sControlFlag.compare(RUN_TEST_FLAG) == 0) {
|
||||
preparTests(argc, argv, testNameList);
|
||||
} else if (sControlFlag.compare(RUN_SUIT_FLAG) == 0) {
|
||||
preparTests(argc, argv, testSuiteList);
|
||||
} else {
|
||||
printf("please use correct format:\n%s", sFormat.c_str());
|
||||
return -1;
|
||||
}
|
||||
|
||||
testmanager->Run(testSuiteList, testNameList);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
string nat_mem_type = DFLT_NAT_MEM_TYPE;
|
||||
|
||||
int c, result = 0, what = 0;
|
||||
|
||||
int opt_idx = 0;
|
||||
|
||||
struct option opts[] = {
|
||||
/* These options set a flag. */
|
||||
{"chooser", no_argument, &what, 1},
|
||||
{"show_tests", no_argument, &what, 2},
|
||||
{"show_suites", no_argument, &what, 3},
|
||||
{"test", no_argument, &what, 4},
|
||||
{"suite", no_argument, &what, 5},
|
||||
{"mem", required_argument, 0, 'm'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
if (argc <= 1) {
|
||||
printf("please use correct format:\n%s", sFormat.c_str());
|
||||
return -1;
|
||||
}
|
||||
|
||||
while ( (c = getopt_long(argc, argv, "", opts, &opt_idx)) != -1 )
|
||||
{
|
||||
switch ( c )
|
||||
{
|
||||
case 0:
|
||||
break;
|
||||
case 'm':
|
||||
if ( legal_nat_mem_type(optarg) )
|
||||
{
|
||||
nat_mem_type = optarg;
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "Illegal: --mem %s\n", optarg);
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "Illegal command line argument passed\n");
|
||||
printf("please use correct format:\n%s", sFormat.c_str());
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if ( what == 0 ) {
|
||||
printf("please use correct format:\n%s", sFormat.c_str());
|
||||
return -1;
|
||||
}
|
||||
|
||||
argc = 2;
|
||||
|
||||
switch ( what )
|
||||
{
|
||||
case 1:
|
||||
argv[1] = (char*) CHOOSER_MODE;
|
||||
break;
|
||||
case 2:
|
||||
argv[1] = (char*) SHOW_TEST_FLAG;
|
||||
break;
|
||||
case 3:
|
||||
argv[1] = (char*) SHOW_SUIT_FLAG;
|
||||
break;
|
||||
case 4:
|
||||
argv[1] = (char*) RUN_TEST_FLAG;
|
||||
break;
|
||||
case 5:
|
||||
argv[1] = (char*) RUN_SUIT_FLAG;
|
||||
break;
|
||||
default:
|
||||
printf("please use correct format:\n%s", sFormat.c_str());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
testmanager = TestManager::GetInstance(nat_mem_type.c_str());
|
||||
|
||||
string sControlFlag = argv[1];
|
||||
|
||||
if (sControlFlag.compare(CHOOSER_MODE) == 0) {
|
||||
result = chooserMode();
|
||||
} else {
|
||||
result = scriptMode(argc, argv);
|
||||
}
|
||||
return result;
|
||||
}//main
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
cmake_minimum_required(VERSION 3.17)
|
||||
project(network_traffic)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
|
||||
add_executable(network_traffic main.cpp Header.h UdpHeader.h IPv4Header.h QmapHeader.h UlsoPacket.h bits_utils.h
|
||||
TransportHeader.h InternetHeader.h IPv6Header.h TcpHeader.h packets.h Ethernet2Header.h)
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (c) 2021 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef NETWORK_TRAFFIC_ETHERNET2HEADER_H
|
||||
#define NETWORK_TRAFFIC_ETHERNET2HEADER_H
|
||||
|
||||
|
||||
#include "Header.h"
|
||||
|
||||
#define ETHER_TYPE 16
|
||||
|
||||
class Ethernet2Header: public Header {
|
||||
|
||||
public:
|
||||
|
||||
const static unsigned int mSize {14};
|
||||
|
||||
DECLARE_BITSET(DestMac, 48, 0x54E1ADB47F9F);
|
||||
DECLARE_BITSET(SourceMac, 48, 0xA0E0AF89A93F);
|
||||
DECLARE_BITSET(EtherType, ETHER_TYPE, 0x0800);
|
||||
|
||||
vector<bool> asVector() const override {
|
||||
vector<bool> outVec;
|
||||
auto inserter = [](vector<bool>& vec, auto val){
|
||||
vector<bool> valAsVector = bitsetToVector<val.size()>(val);
|
||||
toggleLsbMsb(valAsVector, CHAR_BIT);
|
||||
vec.insert(vec.end(), valAsVector.begin(), valAsVector.end());};
|
||||
|
||||
inserter(outVec, mDestMac);
|
||||
inserter(outVec, mSourceMac);
|
||||
inserter(outVec, mEtherType);
|
||||
return outVec;
|
||||
}
|
||||
|
||||
size_t size() const override {
|
||||
return mSize;
|
||||
}
|
||||
|
||||
string name() const override {
|
||||
return string("Ethernet 2");
|
||||
}
|
||||
|
||||
void streamFields(std::ostream &out) const override {
|
||||
out << "mDestAddress: " << mDestMac.to_ullong() << ", "
|
||||
<< "SourceMac: " << mSourceMac.to_ullong() << ", "
|
||||
<< "mEtherType: " << mEtherType.to_ulong() << "\n";
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif //NETWORK_TRAFFIC_ETHERNET2HEADER_H
|
||||
131
qcom/opensource/dataipa/kernel-tests/network_traffic/Header.h
Normal file
131
qcom/opensource/dataipa/kernel-tests/network_traffic/Header.h
Normal file
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Copyright (c) 2021 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef NETWORK_TRAFFIC_HEADER_H
|
||||
#define NETWORK_TRAFFIC_HEADER_H
|
||||
|
||||
|
||||
#include <vector>
|
||||
#include <climits>
|
||||
#include <cassert>
|
||||
#include <ostream>
|
||||
#include <bitset>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <netinet/in.h>
|
||||
#include "bits_utils.h"
|
||||
|
||||
using std::vector;
|
||||
using std::bitset;
|
||||
using std::string;
|
||||
|
||||
// make a variable name fit for member variable name convention.
|
||||
#define MEMBERIZE_VAR(name) m##name
|
||||
// declare a bitset variable with any number of bits and also an integer setter method.
|
||||
#define DECLARE_BITSET(name, numBits, defaultVal) \
|
||||
bitset<numBits> MEMBERIZE_VAR(name) {defaultVal}; \
|
||||
void setm##name(unsigned int name) { \
|
||||
for(int i = 0; i < numBits; i++){ \
|
||||
MEMBERIZE_VAR(name)[i] = getUintNthBit(name, i); \
|
||||
} \
|
||||
} \
|
||||
static_assert(true, "")
|
||||
|
||||
class Header {
|
||||
/**
|
||||
* class Header is an abstract class that provides the interface that is needed for every protocol header.
|
||||
* It also provides implementation of common operations for all protocol headers.
|
||||
* Every protocol header class must inherit from this class directly or indirectly.
|
||||
*/
|
||||
public:
|
||||
|
||||
virtual vector<bool> asVector() const = 0;
|
||||
|
||||
virtual void streamFields(std::ostream &out) const = 0;
|
||||
|
||||
virtual size_t size() const = 0;
|
||||
|
||||
virtual string name() const = 0;
|
||||
|
||||
virtual size_t asArray(uint8_t* buf) const {
|
||||
vector<bool> vec = asVector();
|
||||
size_t resSize = vec.size() / CHAR_BIT + ((vec.size() % CHAR_BIT) > 0);
|
||||
|
||||
for(size_t i = 0; i < vec.size(); i++){
|
||||
changeNthBit(buf[i/8], (i%8), vec[i]);
|
||||
}
|
||||
return resSize;
|
||||
}
|
||||
|
||||
static uint16_t computeChecksum(uint16_t *buf, size_t count){
|
||||
uint32_t sum = 0;
|
||||
|
||||
while(count > 1){
|
||||
sum += *buf++;
|
||||
count -= 2;
|
||||
}
|
||||
if(count > 0){
|
||||
sum += ((*buf)&htons(0xFF00));
|
||||
}
|
||||
while(sum >> 16u){
|
||||
sum = (sum & 0xffffu) + (sum >> 16u);
|
||||
}
|
||||
sum = ~sum;
|
||||
return htons(static_cast<uint16_t>(sum));
|
||||
}
|
||||
|
||||
virtual ~Header() = default;
|
||||
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
inline std::ostream& operator<< (std::ostream &out, vector<T>const& v) {
|
||||
out << "#Bytes=" << v.size() << std::endl;
|
||||
for (size_t i = 0; i < v.size(); i++)
|
||||
out << std::hex << std::setfill('0') << std::setw(2) << static_cast<int>(v[i]) << " ";
|
||||
out << std::dec;
|
||||
return out;
|
||||
}
|
||||
|
||||
inline std::ostream& operator<< (std::ostream &out, Header const& h) {
|
||||
vector<bool> headerAsVec = h.asVector();
|
||||
size_t bufSize = headerAsVec.size() / CHAR_BIT + ((headerAsVec.size() % CHAR_BIT) > 0);
|
||||
uint8_t buf[bufSize];
|
||||
|
||||
out << h.name() + " Header" << std::endl;
|
||||
out << "#Bytes=" << h.size() << std::endl;
|
||||
h.streamFields(out);
|
||||
memset(buf, 0, bufSize);
|
||||
h.asArray(buf);
|
||||
for (size_t i = 0; i < bufSize; i++)
|
||||
out << std::hex << std::setfill('0') << std::setw(2) << static_cast<int>(buf[i]) << " ";
|
||||
out << std::dec;
|
||||
return out;
|
||||
}
|
||||
|
||||
#endif //NETWORK_TRAFFIC_HEADER_H
|
||||
@@ -0,0 +1,168 @@
|
||||
/*
|
||||
* Copyright (c) 2021 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef NETWORK_TRAFFIC_IPV4HEADER_H
|
||||
#define NETWORK_TRAFFIC_IPV4HEADER_H
|
||||
|
||||
#include "InternetHeader.h"
|
||||
|
||||
using std::bitset;
|
||||
|
||||
class IPv4Header: public InternetHeader {
|
||||
|
||||
public:
|
||||
|
||||
const static unsigned int mSize {20};
|
||||
|
||||
explicit IPv4Header(const uint8_t *start) {
|
||||
unsigned int bufIndex = 0;
|
||||
|
||||
setBitsFromArray<uint8_t, 4>(mVersion, start, bufIndex);
|
||||
setBitsFromArray<uint8_t, 4>(mIhl, start, bufIndex);
|
||||
setBitsFromArray<uint8_t, 6>(mDscp, start, bufIndex);
|
||||
setBitsFromArray<uint8_t, 2>(mEcn, start, bufIndex);
|
||||
setBitsFromArray<uint8_t, 16>(mTotalLength, start, bufIndex);
|
||||
setBitsFromArray<uint8_t, 16>(mId, start, bufIndex);
|
||||
setBitsFromArray<uint8_t, 3>(mFlags, start, bufIndex);
|
||||
setBitsFromArray<uint8_t, 13>(mFragmentOffset, start, bufIndex);
|
||||
setBitsFromArray<uint8_t, 8>(mTimeToLive, start, bufIndex);
|
||||
setBitsFromArray<uint8_t, 8>(mProtocol, start, bufIndex);
|
||||
setBitsFromArray<uint8_t, 16>(mHeaderChecksum, start, bufIndex);
|
||||
setBitsFromArray<uint8_t, 32>(mSourceIpAddress, start, bufIndex);
|
||||
setBitsFromArray<uint8_t, 32>(mDestIpAddress, start, bufIndex);
|
||||
}
|
||||
|
||||
DECLARE_BITSET(Version, 4, 4);
|
||||
DECLARE_BITSET(Ihl, 4, 5);
|
||||
DECLARE_BITSET(Dscp, 6, 0);
|
||||
DECLARE_BITSET(Ecn, 2, 0);
|
||||
DECLARE_BITSET(TotalLength, 16, mSize);
|
||||
DECLARE_BITSET(Id, 16, 65530);
|
||||
DECLARE_BITSET(Flags, 3, 2);
|
||||
DECLARE_BITSET(FragmentOffset, 13, 0);
|
||||
DECLARE_BITSET(TimeToLive, 8, 64);
|
||||
DECLARE_BITSET(Protocol, 8, 0);
|
||||
DECLARE_BITSET(HeaderChecksum, 16, 0);
|
||||
DECLARE_BITSET(SourceIpAddress, 32, 3232235793);
|
||||
DECLARE_BITSET(DestIpAddress, 32, 3232235816);
|
||||
|
||||
IPv4Header() = default;
|
||||
|
||||
IPv4Header(const IPv4Header& iPv4Header) = default;
|
||||
|
||||
vector<bool> asVector() const override {
|
||||
vector<bool> outVec;
|
||||
auto inserter = [](vector<bool>& vec, auto val){
|
||||
vector<bool> valAsVector = bitsetToVector<val.size()>(val);
|
||||
vec.insert(vec.end(), valAsVector.begin(), valAsVector.end());};
|
||||
|
||||
inserter(outVec, mVersion);
|
||||
inserter(outVec, mIhl);
|
||||
inserter(outVec, mDscp);
|
||||
inserter(outVec, mEcn);
|
||||
inserter(outVec, mTotalLength);
|
||||
inserter(outVec, mId);
|
||||
inserter(outVec, mFlags);
|
||||
inserter(outVec, mFragmentOffset);
|
||||
inserter(outVec, mTimeToLive);
|
||||
inserter(outVec, mProtocol);
|
||||
inserter(outVec, mHeaderChecksum);
|
||||
inserter(outVec, mSourceIpAddress);
|
||||
inserter(outVec, mDestIpAddress);
|
||||
toggleLsbMsb(outVec, 8);
|
||||
return outVec;
|
||||
}
|
||||
|
||||
size_t size() const override {
|
||||
return mSize;
|
||||
}
|
||||
|
||||
void adjust(size_t payloadSize, uint8_t protocol){
|
||||
mTotalLength = size() + payloadSize;
|
||||
mProtocol = protocol;
|
||||
fixChecksum();
|
||||
}
|
||||
|
||||
static size_t getEtherType(){
|
||||
return 0x0800;
|
||||
}
|
||||
|
||||
string name() const override {
|
||||
return string("IPV4");
|
||||
}
|
||||
|
||||
void streamFields(std::ostream &out) const override {
|
||||
out << "Version: " << mVersion.to_ulong() << ", "
|
||||
<< "IHL: " << mIhl.to_ulong() << ", "
|
||||
<< "DSCP: " << mDscp.to_ulong() << ", "
|
||||
<< "ECN: " << mEcn.to_ulong() << ", "
|
||||
<< "Total Length: " << mTotalLength.to_ulong() << ", "
|
||||
<< "ID: " << mId.to_ulong() << ", "
|
||||
<< "Flags: " << mFlags.to_ulong() << ", "
|
||||
<< "Fragment Offset: " << mFragmentOffset.to_ulong() << ", "
|
||||
<< "TTL: " << mTimeToLive.to_ulong() << ", "
|
||||
<< "Protocol: " << mProtocol.to_ulong() << ", "
|
||||
<< "Checksum: " << mHeaderChecksum.to_ulong() << ", "
|
||||
<< "Source IP Address: " << expandIpv4(mSourceIpAddress.to_ulong()) << ", "
|
||||
<< "Destination IP Address: " << expandIpv4(mDestIpAddress.to_ulong()) << "\n";
|
||||
}
|
||||
|
||||
void tcpChecksumPseudoHeader(uint8_t *pseudoHeaderBuf, const uint8_t *ipHeader) const {
|
||||
memcpy(pseudoHeaderBuf, ipHeader + 12, 8);
|
||||
pseudoHeaderBuf[8] = 0;
|
||||
pseudoHeaderBuf[9] = 6;
|
||||
*reinterpret_cast<uint16_t*>(pseudoHeaderBuf + 10) =
|
||||
htons(static_cast<uint16_t>(mTotalLength.to_ulong() - (mIhl.to_ulong() << 2u)));
|
||||
}
|
||||
|
||||
static size_t l3ChecksumPseudoHeaderSize(){
|
||||
return 12;
|
||||
}
|
||||
|
||||
void udpChecksumPseudoHeader(uint8_t *pseudoHeaderBuf, const uint8_t *ipHeader) const {
|
||||
memcpy(pseudoHeaderBuf, ipHeader + 12, 8);
|
||||
pseudoHeaderBuf[8] = 0;
|
||||
pseudoHeaderBuf[9] = 17;
|
||||
*reinterpret_cast<uint16_t*>(pseudoHeaderBuf + 10) =
|
||||
htons(static_cast<uint16_t>(mTotalLength.to_ulong() - (mIhl.to_ulong() << 2u)));
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
void fixChecksum(){
|
||||
mHeaderChecksum = 0;
|
||||
uint8_t arr[mSize];
|
||||
|
||||
asArray(arr);
|
||||
mHeaderChecksum = computeChecksum(reinterpret_cast<uint16_t*>(arr), mSize);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif //NETWORK_TRAFFIC_IPV4HEADER_H
|
||||
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
* Copyright (c) 2021 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef NETWORK_TRAFFIC_IPV6HEADER_H
|
||||
#define NETWORK_TRAFFIC_IPV6HEADER_H
|
||||
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include "InternetHeader.h"
|
||||
|
||||
class IPv6Header: public InternetHeader {
|
||||
|
||||
public:
|
||||
|
||||
const static unsigned int mSize {40};
|
||||
|
||||
explicit IPv6Header(const uint8_t *start) {
|
||||
unsigned int bufIndex = 0;
|
||||
setBitsFromArray<uint8_t, 4>(mVersion, start, bufIndex);
|
||||
setBitsFromArray<uint8_t, 8>(mTrafficClass, start, bufIndex);
|
||||
setBitsFromArray<uint8_t, 20>(mFlowLabel, start, bufIndex);
|
||||
setBitsFromArray<uint8_t, 16>(mPayloadLength, start, bufIndex);
|
||||
setBitsFromArray<uint8_t, 8>(mNextHeader, start, bufIndex);
|
||||
setBitsFromArray<uint8_t, 8>(mHopLimit, start, bufIndex);
|
||||
setBitsFromArray<uint8_t, 128>(mSourceIpAddress, start, bufIndex);
|
||||
setBitsFromArray<uint8_t, 128>(mDestIpAddress, start, bufIndex);
|
||||
}
|
||||
|
||||
DECLARE_BITSET(Version, 4, 6);
|
||||
DECLARE_BITSET(TrafficClass, 8, 0);
|
||||
DECLARE_BITSET(FlowLabel, 20, 377341);
|
||||
DECLARE_BITSET(PayloadLength, 16, 0);
|
||||
DECLARE_BITSET(NextHeader, 8, 0);
|
||||
DECLARE_BITSET(HopLimit, 8, 1);
|
||||
DECLARE_BITSET(SourceIpAddress, 128, 3232236051);
|
||||
DECLARE_BITSET(DestIpAddress, 128, 3232236136);
|
||||
|
||||
IPv6Header() = default;
|
||||
|
||||
vector<bool> asVector() const override {
|
||||
vector<bool> outVec;
|
||||
auto inserter = [](vector<bool>& vec, auto val){
|
||||
vector<bool> valAsVector = bitsetToVector<val.size()>(val);
|
||||
toggleLsbMsb(valAsVector, CHAR_BIT);
|
||||
vec.insert(vec.end(), valAsVector.begin(), valAsVector.end());};
|
||||
|
||||
vector<bool> v = bitsetToVector<4>(mVersion);
|
||||
vector<bool> v2 = bitsetToVector<8>(mTrafficClass);
|
||||
v.insert(v.end(), v2.begin(), v2.end());
|
||||
v2 = bitsetToVector<20>(mFlowLabel);
|
||||
v.insert(v.end(), v2.begin(), v2.end());
|
||||
toggleLsbMsb(v, CHAR_BIT);
|
||||
outVec.insert(outVec.end(), v.begin(), v.end());
|
||||
inserter(outVec, mPayloadLength);
|
||||
inserter(outVec, mNextHeader);
|
||||
inserter(outVec, mHopLimit);
|
||||
inserter(outVec, mSourceIpAddress);
|
||||
inserter(outVec, mDestIpAddress);
|
||||
return outVec;
|
||||
}
|
||||
|
||||
size_t size() const override {
|
||||
return mSize;
|
||||
}
|
||||
|
||||
void adjust(size_t payloadSize, uint8_t protocol){
|
||||
mPayloadLength = payloadSize;
|
||||
mNextHeader = protocol;
|
||||
}
|
||||
|
||||
void tcpChecksumPseudoHeader(uint8_t* pseudoHeaderBuf, uint8_t* ipHeader) const {
|
||||
memcpy(pseudoHeaderBuf, ipHeader + 8, 32);
|
||||
*reinterpret_cast<uint32_t*>(pseudoHeaderBuf + 32) =
|
||||
htons(static_cast<uint16_t>(mPayloadLength.to_ulong()));
|
||||
*reinterpret_cast<uint32_t*>(pseudoHeaderBuf + 36) = 0;
|
||||
pseudoHeaderBuf[39] = 6;
|
||||
}
|
||||
|
||||
void udpChecksumPseudoHeader(uint8_t* pseudoHeaderBuf, const uint8_t* ipHeader) const {
|
||||
memcpy(pseudoHeaderBuf, ipHeader + 8, 32);
|
||||
*reinterpret_cast<uint32_t*>(pseudoHeaderBuf + 32) = htons(static_cast<uint16_t>(mPayloadLength.to_ulong()));
|
||||
*reinterpret_cast<uint32_t*>(pseudoHeaderBuf + 36) = 0;
|
||||
pseudoHeaderBuf[39] = 17;
|
||||
}
|
||||
|
||||
static size_t l3ChecksumPseudoHeaderSize(){
|
||||
return 40;
|
||||
}
|
||||
|
||||
static size_t getEtherType(){
|
||||
return 0x86dd;
|
||||
}
|
||||
|
||||
string name() const override {
|
||||
return string("IPV6");
|
||||
}
|
||||
|
||||
void streamFields(std::ostream &out) const override {
|
||||
uint8_t buf[32];
|
||||
vector<bool> v = asVector();
|
||||
|
||||
v = vector<bool>(v.begin() + 8, v.end());
|
||||
toArray(v, buf);
|
||||
out << "Version: " << mVersion.to_ulong() << ", "
|
||||
<< "IHL: " << mTrafficClass.to_ulong() << ", "
|
||||
<< "DSCP: " << mFlowLabel.to_ulong() << ", "
|
||||
<< "ECN: " << mPayloadLength.to_ulong() << ", "
|
||||
<< "Total Length: " << mNextHeader.to_ulong() << ", "
|
||||
<< "ID: " << mHopLimit.to_ulong() << ", "
|
||||
<< "Source IP Address: " << expandIpv6(buf) << ", "
|
||||
<< "Destination IP Address: " << expandIpv6(buf) << "\n";
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif //NETWORK_TRAFFIC_IPV6HEADER_H
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (c) 2021 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef NETWORK_TRAFFIC_INTERNETHEADER_H
|
||||
#define NETWORK_TRAFFIC_INTERNETHEADER_H
|
||||
|
||||
|
||||
#include "Header.h"
|
||||
|
||||
using std::string;
|
||||
|
||||
class InternetHeader: public Header {
|
||||
/**
|
||||
* class InternetHeader is an abstract class that inherits from class Header. It provides identification for all
|
||||
* internet layer protocol headers and also some common functionality. Every internet layer protocol header must inherit
|
||||
* from it directly or indirectly.
|
||||
*/
|
||||
protected:
|
||||
|
||||
string expandIpv4(unsigned int ip) const {
|
||||
string ipString = std::to_string((ip >> 24u) & 0xffu);
|
||||
ipString += "." + std::to_string((ip >> 16u) & 0xfu);
|
||||
ipString += "." + std::to_string((ip >> 8u) & 0xffu);
|
||||
ipString += "." + std::to_string(ip & 0xffu);
|
||||
return ipString;
|
||||
}
|
||||
|
||||
string expandIpv6(const uint8_t* buf) const {
|
||||
char str[40];
|
||||
|
||||
snprintf(str, sizeof(str), "%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x",
|
||||
static_cast<int>(buf[0]), static_cast<int>(buf[1]),
|
||||
static_cast<int>(buf[2]), static_cast<int>(buf[3]),
|
||||
static_cast<int>(buf[4]), static_cast<int>(buf[5]),
|
||||
static_cast<int>(buf[6]), static_cast<int>(buf[7]),
|
||||
static_cast<int>(buf[8]), static_cast<int>(buf[9]),
|
||||
static_cast<int>(buf[10]), static_cast<int>(buf[11]),
|
||||
static_cast<int>(buf[12]), static_cast<int>(buf[13]),
|
||||
static_cast<int>(buf[14]), static_cast<int>(buf[15]));
|
||||
return string(str);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif //NETWORK_TRAFFIC_INTERNETHEADER_H
|
||||
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* Copyright (c) 2021 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef NETWORK_TRAFFIC_QMAPHEADER_H
|
||||
#define NETWORK_TRAFFIC_QMAPHEADER_H
|
||||
|
||||
#include "Header.h"
|
||||
|
||||
using std::bitset;
|
||||
|
||||
class QmapHeader: public Header {
|
||||
|
||||
public:
|
||||
|
||||
const static size_t mSize {8};
|
||||
|
||||
DECLARE_BITSET(Pad, 6, 0);
|
||||
DECLARE_BITSET(NextHdr, 1, 1);
|
||||
DECLARE_BITSET(Cd, 1, 0);
|
||||
DECLARE_BITSET(MuxId, 8, 0);
|
||||
DECLARE_BITSET(PacketLength, 16, 0);
|
||||
DECLARE_BITSET(ExtensionNextHeader, 1, 0);
|
||||
DECLARE_BITSET(HeaderType, 7, 3);
|
||||
DECLARE_BITSET(AdditionalHdrSize, 5, 0);
|
||||
DECLARE_BITSET(Res, 1, 0);
|
||||
DECLARE_BITSET(ZeroChecksum, 1, 0);
|
||||
DECLARE_BITSET(IpIdCfg, 1, 0);
|
||||
DECLARE_BITSET(SegmentSize, 16, 1);
|
||||
|
||||
explicit QmapHeader(const uint8_t *start) {
|
||||
unsigned int bufIndex = 0;
|
||||
setBitsFromArray<uint8_t, 6>(mPad, start, bufIndex);
|
||||
setBitsFromArray<uint8_t, 1>(mNextHdr, start, bufIndex);
|
||||
setBitsFromArray<uint8_t, 1>(mCd, start, bufIndex);
|
||||
setBitsFromArray<uint8_t, 8>(mMuxId, start, bufIndex);
|
||||
setBitsFromArray<uint8_t, 16>(mPacketLength, start, bufIndex);
|
||||
setBitsFromArray<uint8_t, 1>(mExtensionNextHeader, start, bufIndex);
|
||||
setBitsFromArray<uint8_t, 7>(mHeaderType, start, bufIndex);
|
||||
setBitsFromArray<uint8_t, 5>(mAdditionalHdrSize, start, bufIndex);
|
||||
setBitsFromArray<uint8_t, 1>(mRes, start, bufIndex);
|
||||
setBitsFromArray<uint8_t, 1>(mZeroChecksum, start, bufIndex);
|
||||
setBitsFromArray<uint8_t, 1>(mIpIdCfg, start, bufIndex);
|
||||
setBitsFromArray<uint8_t, 16>(mSegmentSize, start, bufIndex);
|
||||
}
|
||||
|
||||
QmapHeader() = default;
|
||||
|
||||
vector<bool> asVector() const override {
|
||||
vector<bool> outVec;
|
||||
auto inserter = [](vector<bool>& vec, auto val){
|
||||
vector<bool> valAsVector = bitsetToVector<val.size()>(val);
|
||||
vec.insert(vec.end(), valAsVector.begin(), valAsVector.end());};
|
||||
|
||||
inserter(outVec, mPad);
|
||||
inserter(outVec, mNextHdr);
|
||||
inserter(outVec, mCd);
|
||||
inserter(outVec, mMuxId);
|
||||
vector<bool> v = bitsetToVector<16>(mPacketLength);
|
||||
toggleLsbMsb(v, v.size());
|
||||
toggleEndianness(v, v.size());
|
||||
outVec.insert(outVec.end(), v.begin(), v.end());
|
||||
inserter(outVec, mExtensionNextHeader);
|
||||
v = bitsetToVector<7>(mHeaderType);
|
||||
toggleLsbMsb(v, v.size());
|
||||
outVec.insert(outVec.end(), v.begin(), v.end());
|
||||
inserter(outVec, mAdditionalHdrSize);
|
||||
inserter(outVec, mRes);
|
||||
inserter(outVec, mZeroChecksum);
|
||||
inserter(outVec, mIpIdCfg);
|
||||
v = bitsetToVector<16>(mSegmentSize);
|
||||
toggleLsbMsb(v, v.size());
|
||||
toggleEndianness(v, v.size());
|
||||
outVec.insert(outVec.end(), v.begin(), v.end());
|
||||
return outVec;
|
||||
}
|
||||
|
||||
size_t size() const override {
|
||||
return mSize;
|
||||
}
|
||||
|
||||
string name() const override {
|
||||
return string("QMAP");
|
||||
}
|
||||
|
||||
void streamFields(std::ostream &out) const override {
|
||||
out << "Padding: " << mPad.to_ulong() << ", "
|
||||
<< "Next Header: " << mNextHdr.to_ulong() << ", "
|
||||
<< "C\\D: " << mCd.to_ulong() << ", "
|
||||
<< "Mux ID: " << mMuxId.to_ulong() << ", "
|
||||
<< "Packet Length With Padding: " << mPacketLength.to_ulong() << ", "
|
||||
<< "Extension Next Header: " << mExtensionNextHeader.to_ulong() << ", "
|
||||
<< "Header Type: " << mHeaderType.to_ulong() << ", "
|
||||
<< "Additional Header Size: " << mAdditionalHdrSize.to_ulong() << ", "
|
||||
<< "Res: " << mRes.to_ulong() << ", "
|
||||
<< "Zero Checksum: " << mZeroChecksum.to_ulong() << ", "
|
||||
<< "IPID Cfg: " << mIpIdCfg.to_ulong() << ", "
|
||||
<< "Segment Size: " << mSegmentSize.to_ulong() << "\n";
|
||||
}
|
||||
};
|
||||
|
||||
#endif //NETWORK_TRAFFIC_QMAPHEADER_H
|
||||
207
qcom/opensource/dataipa/kernel-tests/network_traffic/TcpHeader.h
Normal file
207
qcom/opensource/dataipa/kernel-tests/network_traffic/TcpHeader.h
Normal file
@@ -0,0 +1,207 @@
|
||||
/*
|
||||
* Copyright (c) 2021 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef NETWORK_TRAFFIC_TCPHEADER_H
|
||||
#define NETWORK_TRAFFIC_TCPHEADER_H
|
||||
|
||||
|
||||
#include "TransportHeader.h"
|
||||
|
||||
class TcpHeader: public TransportHeader {
|
||||
|
||||
public:
|
||||
|
||||
const static unsigned int mSizeBits {160};
|
||||
const static unsigned int mSize {20};
|
||||
|
||||
DECLARE_BITSET(SourcePort, 16, 56789);
|
||||
DECLARE_BITSET(DestPort, 16, 64886);
|
||||
DECLARE_BITSET(SequenceNumber, 32, 1077280711);
|
||||
DECLARE_BITSET(AckNumber, 32, 3090542765);
|
||||
DECLARE_BITSET(DataOffset, 4, 5);
|
||||
DECLARE_BITSET(Reserved, 3, 0);
|
||||
DECLARE_BITSET(NS, 1, 0);
|
||||
DECLARE_BITSET(CWR, 1, 0);
|
||||
DECLARE_BITSET(ECE, 1, 0);
|
||||
DECLARE_BITSET(URG, 1, 0);
|
||||
DECLARE_BITSET(ACK, 1, 1);
|
||||
DECLARE_BITSET(PSH, 1, 1);
|
||||
DECLARE_BITSET(RST, 1, 0);
|
||||
DECLARE_BITSET(SYN, 1, 0);
|
||||
DECLARE_BITSET(FIN, 1, 0);
|
||||
DECLARE_BITSET(WindowSize, 16, 473);
|
||||
DECLARE_BITSET(Checksum, 16, 0);
|
||||
DECLARE_BITSET(UrgentPtr, 16, 0);
|
||||
|
||||
TcpHeader() = default;
|
||||
|
||||
explicit TcpHeader(const uint8_t *start) {
|
||||
unsigned int bufIndex = 0;
|
||||
|
||||
setBitsFromArray<uint8_t, 16>(mSourcePort, start, bufIndex);
|
||||
setBitsFromArray<uint8_t, 16>(mDestPort, start, bufIndex);
|
||||
setBitsFromArray<uint8_t, 32>(mSequenceNumber, start, bufIndex);
|
||||
setBitsFromArray<uint8_t, 32>(mAckNumber, start, bufIndex);
|
||||
setBitsFromArray<uint8_t, 4>(mDataOffset, start, bufIndex);
|
||||
setBitsFromArray<uint8_t, 3>(mReserved, start, bufIndex);
|
||||
setBitsFromArray<uint8_t, 1>(mNS, start, bufIndex);
|
||||
setBitsFromArray<uint8_t, 1>(mCWR, start, bufIndex);
|
||||
setBitsFromArray<uint8_t, 1>(mECE, start, bufIndex);
|
||||
setBitsFromArray<uint8_t, 1>(mURG, start, bufIndex);
|
||||
setBitsFromArray<uint8_t, 1>(mACK, start, bufIndex);
|
||||
setBitsFromArray<uint8_t, 1>(mPSH, start, bufIndex);
|
||||
setBitsFromArray<uint8_t, 1>(mRST, start, bufIndex);
|
||||
setBitsFromArray<uint8_t, 1>(mSYN, start, bufIndex);
|
||||
setBitsFromArray<uint8_t, 1>(mFIN, start, bufIndex);
|
||||
setBitsFromArray<uint8_t, 16>(mWindowSize, start, bufIndex);
|
||||
setBitsFromArray<uint8_t, 16>(mChecksum, start, bufIndex);
|
||||
setBitsFromArray<uint8_t, 16>(mUrgentPtr, start, bufIndex);
|
||||
}
|
||||
vector<bool> asVector() const override {
|
||||
vector<bool> outVec;
|
||||
auto inserter = [](vector<bool>& vec, auto val){
|
||||
vector<bool> valAsVector = bitsetToVector<val.size()>(val);
|
||||
vec.insert(vec.end(), valAsVector.begin(), valAsVector.end());};
|
||||
auto inserter2 = [](vector<bool>& vec, auto val){
|
||||
vector<bool> valAsVector = bitsetToVector<val.size()>(val);
|
||||
toggleLsbMsb(valAsVector, CHAR_BIT);
|
||||
vec.insert(vec.end(), valAsVector.begin(), valAsVector.end());};
|
||||
|
||||
inserter2(outVec, mSourcePort);
|
||||
inserter2(outVec, mDestPort);
|
||||
inserter2(outVec, mSequenceNumber);
|
||||
inserter2(outVec, mAckNumber);
|
||||
vector<bool> v = bitsetToVector<4>(mDataOffset);
|
||||
vector<bool> v2 = bitsetToVector<3>(mReserved);
|
||||
v.insert(v.end(), v2.begin(), v2.end());
|
||||
v2 = bitsetToVector<1>(mNS);
|
||||
v.insert(v.end(), v2.begin(), v2.end());
|
||||
outVec.insert(outVec.end(), v.rbegin(), v.rend());
|
||||
v = bitsetToVector<1>(mCWR);
|
||||
v2 = bitsetToVector<1>(mECE);
|
||||
v.insert(v.end(), v2.begin(), v2.end());
|
||||
v2 = bitsetToVector<1>(mURG);
|
||||
v.insert(v.end(), v2.begin(), v2.end());
|
||||
v2 = bitsetToVector<1>(mACK);
|
||||
v.insert(v.end(), v2.begin(), v2.end());
|
||||
v2 = bitsetToVector<1>(mPSH);
|
||||
v.insert(v.end(), v2.begin(), v2.end());
|
||||
v2 = bitsetToVector<1>(mRST);
|
||||
v.insert(v.end(), v2.begin(), v2.end());
|
||||
v2 = bitsetToVector<1>(mSYN);
|
||||
v.insert(v.end(), v2.begin(), v2.end());
|
||||
v2 = bitsetToVector<1>(mFIN);
|
||||
v.insert(v.end(), v2.begin(), v2.end());
|
||||
outVec.insert(outVec.end(), v.rbegin(), v.rend());
|
||||
inserter2(outVec, mWindowSize);
|
||||
inserter2(outVec, mChecksum);
|
||||
inserter(outVec, mUrgentPtr);
|
||||
return outVec;
|
||||
}
|
||||
|
||||
uint32_t getSeqNum() const {
|
||||
return static_cast<uint32_t>(mSequenceNumber.to_ulong());
|
||||
}
|
||||
|
||||
size_t size() const override {
|
||||
return TcpHeader::mSize;
|
||||
}
|
||||
|
||||
static uint8_t protocolNum(){
|
||||
return 6;
|
||||
}
|
||||
|
||||
void adjust(uint8_t *checksumBuf, size_t count){
|
||||
fixChecksum(checksumBuf, count);
|
||||
}
|
||||
|
||||
void zeroChecksum(){
|
||||
mChecksum = 0;
|
||||
}
|
||||
|
||||
string name() const override {
|
||||
return string("TCP");
|
||||
}
|
||||
|
||||
void streamFields(std::ostream &out) const override {
|
||||
out << "Source Port: " << mSourcePort.to_ulong() << ", "
|
||||
<< "Dest Port: " << mDestPort.to_ulong() << ", "
|
||||
<< "Sequence Number: " << mSequenceNumber.to_ulong() << ", "
|
||||
<< "Ack Number: " << mAckNumber.to_ulong() << ", "
|
||||
<< "Data Offset: " << mDataOffset.to_ulong() << ", "
|
||||
<< "Reserved: " << mReserved.to_ulong() << ", "
|
||||
<< "NS: " << mNS.to_ulong() << ", "
|
||||
<< "CWR: " << mCWR.to_ulong() << ", "
|
||||
<< "URG: " << mURG.to_ulong() << ", "
|
||||
<< "ACK: " << mACK.to_ulong() << ", "
|
||||
<< "PSH: " << mPSH.to_ulong() << ", "
|
||||
<< "RST: " << mRST.to_ulong() << ", "
|
||||
<< "SYN: " << mSYN.to_ulong() << ", "
|
||||
<< "FIN: " << mFIN.to_ulong() << ", "
|
||||
<< "Window Size: " << mWindowSize.to_ulong() << ", "
|
||||
<< "Checksum: " << mChecksum.to_ulong() << ", "
|
||||
<< "Urgent Ptr: " << mUrgentPtr << std::endl;
|
||||
}
|
||||
|
||||
struct flags {
|
||||
bool ns;
|
||||
bool cwr;
|
||||
bool ece;
|
||||
bool urg;
|
||||
bool ack;
|
||||
bool psh;
|
||||
bool rst;
|
||||
bool syn;
|
||||
bool fin;
|
||||
};
|
||||
|
||||
flags getFlags() const {
|
||||
return flags {
|
||||
.ns = mNS.test(0),
|
||||
.cwr = mCWR.test(0),
|
||||
.ece = mECE.test(0),
|
||||
.urg = mURG.test(0),
|
||||
.ack = mACK.test(0),
|
||||
.psh = mPSH.test(0),
|
||||
.rst = mRST.test(0),
|
||||
.syn = mSYN.test(0),
|
||||
.fin = mFIN.test(0)
|
||||
};
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
void fixChecksum(uint8_t *checksumBuf, size_t count){
|
||||
mChecksum = 0;
|
||||
mChecksum = computeChecksum(reinterpret_cast<uint16_t*>(checksumBuf), count);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif //NETWORK_TRAFFIC_TCPHEADER_H
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2021 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef NETWORK_TRAFFIC_TRANSPORTHEADER_H
|
||||
#define NETWORK_TRAFFIC_TRANSPORTHEADER_H
|
||||
|
||||
#include "Header.h"
|
||||
|
||||
|
||||
class TransportHeader: public Header {
|
||||
/**
|
||||
* class TransportHeader is an abstract class that inherits from class Header. It provides identification for all
|
||||
* transport layer protocol headers. Every transport layer protocol header must inherit from it directly or indirectly.
|
||||
*/
|
||||
};
|
||||
|
||||
|
||||
#endif //NETWORK_TRAFFIC_TRANSPORTHEADER_H
|
||||
119
qcom/opensource/dataipa/kernel-tests/network_traffic/UdpHeader.h
Normal file
119
qcom/opensource/dataipa/kernel-tests/network_traffic/UdpHeader.h
Normal file
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* Copyright (c) 2021 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef NETWORK_TRAFFIC_UDPHEADER_H
|
||||
#define NETWORK_TRAFFIC_UDPHEADER_H
|
||||
|
||||
#include "TransportHeader.h"
|
||||
|
||||
class UdpHeader: public TransportHeader {
|
||||
|
||||
public:
|
||||
|
||||
const static unsigned int mSize {8};
|
||||
|
||||
DECLARE_BITSET(SourcePort, 16, 1985);
|
||||
DECLARE_BITSET(DestPort, 16, 1985);
|
||||
DECLARE_BITSET(Length, 16, 0);
|
||||
DECLARE_BITSET(Checksum, 16, 0);
|
||||
|
||||
explicit UdpHeader(const uint8_t *start) {
|
||||
unsigned int bufIndex = 0;
|
||||
|
||||
setBitsFromArray<uint8_t, 16>(mSourcePort, start, bufIndex);
|
||||
setBitsFromArray<uint8_t, 16>(mDestPort, start, bufIndex);
|
||||
setBitsFromArray<uint8_t, 16>(mLength, start, bufIndex);
|
||||
setBitsFromArray<uint8_t, 16>(mChecksum, start, bufIndex);
|
||||
}
|
||||
|
||||
UdpHeader(uint16_t sourcePort, uint16_t destPort, uint16_t length, uint16_t checksum) :
|
||||
mSourcePort(sourcePort),
|
||||
mDestPort(destPort),
|
||||
mLength(length),
|
||||
mChecksum(checksum) {}
|
||||
|
||||
UdpHeader(const UdpHeader& udpHeader) = default;
|
||||
|
||||
UdpHeader() = default;
|
||||
|
||||
vector<bool> asVector() const override {
|
||||
vector<bool> outVec;
|
||||
auto inserter2 = [&outVec](bitset<16> val){
|
||||
vector<bool> valAsVector = bitsetToVector<16>(val);
|
||||
toggleLsbMsb(valAsVector, CHAR_BIT);
|
||||
outVec.insert(outVec.end(), valAsVector.begin(), valAsVector.end());};
|
||||
|
||||
inserter2(mSourcePort);
|
||||
inserter2(mDestPort);
|
||||
inserter2(mLength);
|
||||
inserter2(mChecksum);
|
||||
return outVec;
|
||||
}
|
||||
|
||||
size_t size() const override {
|
||||
return mSize;
|
||||
}
|
||||
|
||||
static uint8_t protocolNum(){
|
||||
return 17;
|
||||
}
|
||||
|
||||
void adjust(const size_t payloadSize){
|
||||
mLength = mSize + payloadSize;
|
||||
}
|
||||
|
||||
void adjust(uint8_t *checksumBuf, size_t count, size_t payloadSize){
|
||||
mLength = mSize + payloadSize;
|
||||
fixChecksum(checksumBuf, count);
|
||||
}
|
||||
|
||||
void zeroChecksum(){
|
||||
mChecksum = 0;
|
||||
}
|
||||
|
||||
string name() const override {
|
||||
return string("UDP");
|
||||
}
|
||||
|
||||
void streamFields(std::ostream &out) const override {
|
||||
out << "Source port: " << mSourcePort.to_ulong() << ", "
|
||||
<< "Destination port: " << mDestPort.to_ulong() << ", "
|
||||
<< "Length: " << mLength.to_ulong() << ", "
|
||||
<< "Checksum: " << mChecksum.to_ulong() << "\n";
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
void fixChecksum(uint8_t *checksumBuf, size_t count){
|
||||
mChecksum = 0;
|
||||
mChecksum = computeChecksum(reinterpret_cast<uint16_t*>(checksumBuf), count);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif //NETWORK_TRAFFIC_UDPHEADER_H
|
||||
@@ -0,0 +1,415 @@
|
||||
/*
|
||||
* Copyright (c) 2021 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef NETWORK_TRAFFIC_ULSOPACKET_H
|
||||
#define NETWORK_TRAFFIC_ULSOPACKET_H
|
||||
|
||||
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
#include <stdexcept>
|
||||
#include "QmapHeader.h"
|
||||
#include "UdpHeader.h"
|
||||
#include "TcpHeader.h"
|
||||
#include "IPv4Header.h"
|
||||
#include "IPv6Header.h"
|
||||
#include "packets.h"
|
||||
#include "Ethernet2Header.h"
|
||||
|
||||
template <typename Transport=UdpHeader, typename Internet=IPv4Header>
|
||||
class UlsoPacket {
|
||||
|
||||
static_assert(std::is_base_of<TransportHeader, Transport>::value,
|
||||
"Transport is not derived from TransportHeader");
|
||||
static_assert(std::is_base_of<InternetHeader, Internet>::value,
|
||||
"Internet is not derived from InternetHeader");
|
||||
|
||||
private:
|
||||
|
||||
static constexpr uint8_t qmapIPv4UdpPacketNoSeg[] = {
|
||||
//C=0,Next Header=1,PAD=b'63,MUXID=0,Packet length=30
|
||||
0X7f, 0x00, 0x00, 0x1e,//QMAP header
|
||||
//type=3,Next Header=0,IPIDCfg=1,Zero Checksum=1,Additional header size=0,segment size=2
|
||||
0X06, 0xc0, 0x00, 0x02,//QMAP header extension
|
||||
//IPv4 header
|
||||
0x45, 0x00, 0x00, 0x1e,//version=4,IHL=5,DSCP=0,ECN=0,length=30
|
||||
0x00, 0x00, 0x00, 0x00,//id=0,flags=0,fragment offset=0
|
||||
0xff, 0x11, 0x36, 0x03,//TTL=255,Protocol=17 (TCP),checksum=
|
||||
0xc0, 0xa8, 0x02, 0x13,//IPv4 SRC Addr 192.168.2.19
|
||||
0xc0, 0xa8, 0x02, 0x68,//IPv4 DST Addr 192.168.2.104
|
||||
//UDP header
|
||||
0x04, 0x57, 0x08, 0xae,//source port=1111, destination port=2222
|
||||
0x00, 0x0a, 0x00, 0x00,//length=10,checksum=
|
||||
//payload
|
||||
0x00, 0x01
|
||||
};
|
||||
|
||||
/**
|
||||
* Resembles ULSO related endpoint configurations.
|
||||
*/
|
||||
unsigned int mMinId {0};
|
||||
unsigned int mMaxId {65535};
|
||||
|
||||
bool mIsSegmented {false};
|
||||
|
||||
public:
|
||||
|
||||
static constexpr int maxSize {65536};//64 KB
|
||||
|
||||
QmapHeader mQmapHeader;
|
||||
Ethernet2Header mEthernetHeader;
|
||||
Internet mInternetHeader;
|
||||
bool mEthernetHeaderValid {false};
|
||||
Transport mTransportHeader;
|
||||
vector<uint8_t> mPayload {};
|
||||
|
||||
UlsoPacket(unsigned int segmentSize, unsigned int payloadSize, bool ethernetHeaderValid=true):
|
||||
mEthernetHeaderValid(ethernetHeaderValid){
|
||||
bool first = true;
|
||||
uint32_t seqNum = 0;
|
||||
|
||||
mQmapHeader.setmSegmentSize(segmentSize);
|
||||
if(mEthernetHeaderValid){
|
||||
mEthernetHeader.setmEtherType(mInternetHeader.getEtherType());
|
||||
}
|
||||
mPayload = vector<uint8_t>(payloadSize);
|
||||
for(unsigned int i = 0; i < payloadSize; i++){
|
||||
mPayload[i] = i % UINT8_MAX;
|
||||
}
|
||||
mInternetHeader.adjust(mTransportHeader.size() + mPayload.size(), mTransportHeader.protocolNum());
|
||||
mQmapHeader.setmPacketLength(mInternetHeader.size() + mTransportHeader.size() + mPayload.size());
|
||||
adjustHeader(mTransportHeader, seqNum, first);
|
||||
}
|
||||
|
||||
UlsoPacket(unsigned int segmentSize, uint8_t* payload, unsigned int payloadSize){
|
||||
bool first = true;
|
||||
uint32_t seqNum = 0;
|
||||
|
||||
mQmapHeader.setmSegmentSize(segmentSize);
|
||||
mPayload = vector<uint8_t>{payload, payload + payloadSize};
|
||||
mInternetHeader.adjust(mTransportHeader.size() + mPayload.size(), mTransportHeader.protocolNum());
|
||||
mQmapHeader.setmPacketLength(mInternetHeader.size() + mTransportHeader.size() + mPayload.size());
|
||||
adjustHeader(mTransportHeader, seqNum, first);
|
||||
}
|
||||
|
||||
size_t size() const {
|
||||
return (!isSegmented() * mQmapHeader.size()) + (mEthernetHeaderValid * mEthernetHeader.size())
|
||||
+ mInternetHeader.size() + mTransportHeader.size() + mPayload.size();
|
||||
}
|
||||
|
||||
UlsoPacket(const QmapHeader& qmapHeader, const Internet& iPv4Header, const Transport& udpHeader,
|
||||
const vector<uint8_t>& payload) :
|
||||
mQmapHeader(qmapHeader),
|
||||
mInternetHeader(iPv4Header),
|
||||
mTransportHeader(udpHeader),
|
||||
mPayload(payload) {}
|
||||
|
||||
explicit UlsoPacket(size_t bufLen, uint8_t *buf=const_cast<uint8_t *>(qmapIPv4UdpPacketNoSeg)) {
|
||||
size_t curIndex = 0;
|
||||
|
||||
mQmapHeader = QmapHeader(buf + curIndex);
|
||||
curIndex += mQmapHeader.size();
|
||||
mInternetHeader = Internet(buf + curIndex);
|
||||
curIndex += mInternetHeader.size();
|
||||
mTransportHeader = Transport(buf + curIndex);
|
||||
curIndex += mTransportHeader.size();
|
||||
mPayload = vector<uint8_t>();
|
||||
while(curIndex < bufLen){
|
||||
mPayload.emplace_back(buf[curIndex]);
|
||||
curIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
UlsoPacket(){
|
||||
mQmapHeader.setmPacketLength(mInternetHeader.size() + mTransportHeader.size() + mPayload.size());
|
||||
mInternetHeader.adjust(mTransportHeader.size() + mPayload.size(), mTransportHeader.protocolNum());
|
||||
adjustHeader(mTransportHeader, 0, true);
|
||||
}
|
||||
|
||||
vector<bool> asVector() const {
|
||||
vector<bool> outVec;
|
||||
auto concatenateFunc = [](vector<bool>& v1, const vector<bool>& v2){
|
||||
v1.insert(v1.end(), v2.begin(), v2.end());
|
||||
};
|
||||
|
||||
if(!mIsSegmented){
|
||||
concatenateFunc(outVec, mQmapHeader.asVector());
|
||||
}
|
||||
if(mEthernetHeaderValid){
|
||||
concatenateFunc(outVec, mEthernetHeader.asVector());
|
||||
}
|
||||
concatenateFunc(outVec, mInternetHeader.asVector());
|
||||
concatenateFunc(outVec, mTransportHeader.asVector());
|
||||
std::for_each(mPayload.cbegin(), mPayload.cend(), [&outVec](char c){
|
||||
for (int i = SIZE_OF_BITS(c) - 1; i >= 0; i--)
|
||||
outVec.emplace_back((c & ( 1 << i )) >> i); // NOLINT(hicpp-signed-bitwise)
|
||||
});
|
||||
return outVec;
|
||||
}
|
||||
|
||||
uint8_t* asArray() const {
|
||||
vector<bool> vec = asVector();
|
||||
size_t resSize = vec.size() / CHAR_BIT + ((vec.size() % CHAR_BIT) > 0);
|
||||
auto *outArr = new uint8_t[resSize];
|
||||
|
||||
asArray(outArr);
|
||||
return outArr;
|
||||
}
|
||||
|
||||
size_t asArray(uint8_t* buf) const {
|
||||
vector<bool> vec = asVector();
|
||||
size_t bufSize = vec.size() / CHAR_BIT + ((vec.size() % CHAR_BIT) > 0);
|
||||
|
||||
memset(buf, 0, bufSize);
|
||||
if(!isSegmented()){
|
||||
buf += mQmapHeader.asArray(buf);
|
||||
}
|
||||
if(mEthernetHeaderValid){
|
||||
buf += mEthernetHeader.asArray(buf);
|
||||
}
|
||||
buf += mInternetHeader.asArray(buf);
|
||||
buf += mTransportHeader.asArray(buf);
|
||||
for(auto val: mPayload){
|
||||
*buf++ = val;
|
||||
}
|
||||
return bufSize;
|
||||
}
|
||||
|
||||
vector<UlsoPacket> segment() const {
|
||||
bool first = true;
|
||||
uint32_t seqNum = 0;
|
||||
|
||||
if(isSegmented()){
|
||||
return vector<UlsoPacket>();
|
||||
}
|
||||
unsigned int segmentSize = mQmapHeader.mSegmentSize.to_ulong();
|
||||
vector<vector<uint8_t>> payloads = segmentPayload(segmentSize, mPayload);
|
||||
UlsoPacket ulsoCopy(*this);
|
||||
fixFlags(ulsoCopy.mTransportHeader);
|
||||
vector<UlsoPacket> outVec = vector<UlsoPacket>(payloads.size(), ulsoCopy);
|
||||
for(size_t i = 0; i < outVec.size(); i++){
|
||||
UlsoPacket& p = outVec[i];
|
||||
p.mPayload = payloads[i];
|
||||
}
|
||||
if(!outVec.empty()){
|
||||
fixLastSegmentFlags(outVec[outVec.size() - 1].mTransportHeader);
|
||||
}
|
||||
if(mQmapHeader.mIpIdCfg == 0){
|
||||
fixIpId(outVec, mMinId, mMaxId);
|
||||
}
|
||||
for(UlsoPacket& p: outVec){
|
||||
p.mInternetHeader.adjust(p.mTransportHeader.size() + p.mPayload.size(), p.mTransportHeader.protocolNum());
|
||||
p.adjustHeader(p.mTransportHeader, seqNum, first);
|
||||
p.mIsSegmented = true;
|
||||
}
|
||||
return outVec;
|
||||
}
|
||||
|
||||
bool isSegmented() const {
|
||||
return mIsSegmented;
|
||||
}
|
||||
|
||||
void setIpId(const uint16_t id){
|
||||
changeIpId(mInternetHeader, mTransportHeader);
|
||||
}
|
||||
|
||||
void changeIpId(IPv4Header& iPv4Header, UdpHeader& udpHeader){
|
||||
bool first = true;
|
||||
uint32_t seqNum = 0;
|
||||
|
||||
mInternetHeader.adjust(mTransportHeader.size() + mPayload.size(), mTransportHeader.protocolNum());
|
||||
adjustHeader(mTransportHeader, seqNum, first);
|
||||
}
|
||||
|
||||
void changeIpId(IPv4Header& iPv4Header, TcpHeader& tcpHeader){
|
||||
bool first = true;
|
||||
uint32_t seqNum = 0;
|
||||
|
||||
mInternetHeader.adjust(mTransportHeader.size() + mPayload.size(), mTransportHeader.protocolNum());
|
||||
adjustHeader(mTransportHeader, seqNum, first);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
static void fixFlags(TcpHeader& tcpHeader){
|
||||
tcpHeader.setmFIN(0);
|
||||
tcpHeader.setmPSH(0);
|
||||
tcpHeader.setmRST(0);
|
||||
tcpHeader.setmCWR(0);
|
||||
}
|
||||
|
||||
static void fixFlags(UdpHeader& udpHeader){}
|
||||
|
||||
void fixLastSegmentFlags(TcpHeader& tcpHeader) const {
|
||||
TcpHeader::flags flags = mTransportHeader.getFlags();
|
||||
|
||||
tcpHeader.setmFIN(flags.fin);
|
||||
tcpHeader.setmPSH(flags.psh);
|
||||
tcpHeader.setmRST(flags.rst);
|
||||
tcpHeader.setmCWR(flags.cwr);
|
||||
}
|
||||
|
||||
void fixLastSegmentFlags(UdpHeader& udpHeader) const {}
|
||||
|
||||
static vector<vector<uint8_t>> segmentPayload(unsigned long segmentSize, const vector<uint8_t>& payload) {
|
||||
vector<vector<uint8_t>> outVec;
|
||||
|
||||
for(size_t i = 0; i < payload.size(); i += segmentSize) {
|
||||
auto last = std::min<size_t>(static_cast<size_t>(payload.size()), i + segmentSize);
|
||||
auto index = i / segmentSize;
|
||||
|
||||
outVec.emplace_back(vector<uint8_t>());
|
||||
auto& vec = outVec[index];
|
||||
vec.reserve(last - i);
|
||||
move(payload.begin() + i, payload.begin() + last, back_inserter(vec));
|
||||
}
|
||||
return outVec;
|
||||
}
|
||||
|
||||
void adjustHeader(TcpHeader& tcpHeader, uint32_t& seqNum, bool& first){
|
||||
tcpHeader.zeroChecksum();
|
||||
if(first){
|
||||
seqNum = tcpHeader.getSeqNum();
|
||||
first = false;
|
||||
}
|
||||
tcpHeader.setmSequenceNumber(seqNum);
|
||||
seqNum += mPayload.size();
|
||||
size_t checksumBufSize = mInternetHeader.l3ChecksumPseudoHeaderSize() + mTransportHeader.size() + mPayload.size();
|
||||
uint8_t checksumBuf[checksumBufSize];
|
||||
memset(checksumBuf, 0, checksumBufSize);
|
||||
uint8_t *checksumBufPtr = checksumBuf;
|
||||
|
||||
size_t ulsoBufSize = size();
|
||||
uint8_t ulsoBuf[ulsoBufSize];
|
||||
memset(ulsoBuf, 0, ulsoBufSize);
|
||||
asArray(ulsoBuf);
|
||||
size_t ipOffset = mQmapHeader.size() + mEthernetHeaderValid * mEthernetHeader.size();
|
||||
mInternetHeader.tcpChecksumPseudoHeader(checksumBuf, ulsoBuf + ipOffset);
|
||||
checksumBufPtr += mInternetHeader.l3ChecksumPseudoHeaderSize();
|
||||
checksumBufPtr += tcpHeader.asArray(checksumBufPtr);
|
||||
for(auto val: mPayload){
|
||||
*checksumBufPtr++ = val;
|
||||
}
|
||||
mTransportHeader.adjust(checksumBuf, checksumBufSize);
|
||||
}
|
||||
|
||||
void adjustHeader(UdpHeader& udpHeader, uint32_t seqNum, bool first){
|
||||
udpHeader.zeroChecksum();
|
||||
if(mQmapHeader.mZeroChecksum.test(0)){
|
||||
mTransportHeader.adjust(mPayload.size());
|
||||
} else{
|
||||
udpHeader.setmLength(udpHeader.size() + mPayload.size());
|
||||
size_t checksumBufSize = mInternetHeader.l3ChecksumPseudoHeaderSize() + mTransportHeader.size() + mPayload.size();
|
||||
uint8_t checksumBuf[checksumBufSize];
|
||||
memset(checksumBuf, 0, checksumBufSize);
|
||||
uint8_t *checksumBufPtr = checksumBuf;
|
||||
|
||||
size_t ulsoBufSize = size();
|
||||
uint8_t ulsoBuf[ulsoBufSize];
|
||||
memset(ulsoBuf, 0, ulsoBufSize);
|
||||
asArray(ulsoBuf);
|
||||
size_t ipOffset = mQmapHeader.size() + mEthernetHeaderValid * mEthernetHeader.size();
|
||||
mInternetHeader.udpChecksumPseudoHeader(checksumBuf, ulsoBuf + ipOffset);
|
||||
checksumBufPtr += mInternetHeader.l3ChecksumPseudoHeaderSize();
|
||||
checksumBufPtr += udpHeader.asArray(checksumBufPtr);
|
||||
for(auto val: mPayload){
|
||||
*checksumBufPtr++ = val;
|
||||
}
|
||||
mTransportHeader.adjust(checksumBuf, checksumBufSize, mPayload.size());
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, typename I>
|
||||
friend std::ostream& operator<< (std::ostream &out, UlsoPacket<Transport, Internet> const& packet);
|
||||
};
|
||||
|
||||
template <typename Transport, typename Internet>
|
||||
constexpr uint8_t UlsoPacket<Transport, Internet>::qmapIPv4UdpPacketNoSeg[];
|
||||
|
||||
template <typename Transport, typename Internet>
|
||||
inline std::ostream& operator << (std::ostream &out, UlsoPacket<Transport, Internet> const& packet) {
|
||||
out << "ULSO Packet\n" << "#Bytes=" << packet.size() << std::endl;
|
||||
if(!packet.isSegmented()){
|
||||
out << packet.mQmapHeader << std::endl;
|
||||
} else {
|
||||
out << "QMAP header removed in segmentation\n";
|
||||
}
|
||||
if(packet.mEthernetHeaderValid){
|
||||
out << packet.mEthernetHeader << std::endl;
|
||||
}
|
||||
out << packet.mInternetHeader << std::endl;
|
||||
out << packet.mTransportHeader << std::endl;
|
||||
out << "Payload\n" << packet.mPayload;
|
||||
return out;
|
||||
}
|
||||
|
||||
template<typename Transport, typename Internet>
|
||||
void fixIpId(vector<UlsoPacket<Transport, Internet>>& v, unsigned int minId, unsigned int maxId) {
|
||||
return;
|
||||
}
|
||||
|
||||
template<>
|
||||
void fixIpId<UdpHeader, IPv4Header>(vector<UlsoPacket<UdpHeader, IPv4Header>>& v, unsigned int minId, unsigned int maxId) {
|
||||
unsigned int curId = 0;
|
||||
|
||||
if(!v.empty()){
|
||||
curId = std::max(static_cast<unsigned int>(v[0].mInternetHeader.mId.to_ulong()), minId) % (maxId + 1);
|
||||
}
|
||||
for (auto &p: v) {
|
||||
p.mInternetHeader.setmId(curId);
|
||||
curId++;
|
||||
if (curId == (maxId + 1)) curId = minId;
|
||||
}
|
||||
}
|
||||
|
||||
template<>
|
||||
void fixIpId<TcpHeader, IPv4Header>(vector<UlsoPacket<TcpHeader, IPv4Header>>& v, unsigned int minId, unsigned int maxId) {
|
||||
unsigned int curId = 0;
|
||||
|
||||
if(!v.empty()){
|
||||
curId = std::max(static_cast<unsigned int>(v[0].mInternetHeader.mId.to_ulong()), minId) % (maxId + 1);
|
||||
}
|
||||
for (auto &p: v) {
|
||||
p.mInternetHeader.setmId(curId);
|
||||
curId++;
|
||||
if (curId == (maxId + 1)) curId = minId;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Internet, typename Transport>
|
||||
bool changeIpId(Internet& ipHeader, uint16_t id){
|
||||
return false;
|
||||
}
|
||||
|
||||
template<>
|
||||
bool changeIpId<IPv4Header, UdpHeader>(IPv4Header& iPv4Header, uint16_t id){
|
||||
iPv4Header.setmId(id);
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif //NETWORK_TRAFFIC_ULSOPACKET_H
|
||||
@@ -0,0 +1,224 @@
|
||||
/*
|
||||
* Copyright (c) 2021 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* Changes from Qualcomm Innovation Center are provided under the following license:
|
||||
*
|
||||
* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted (subject to the limitations in the
|
||||
* disclaimer below) provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* * Neither the name of Qualcomm Innovation Center, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
|
||||
* GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
|
||||
* HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
|
||||
*/
|
||||
#ifndef NETWORK_TRAFFIC_BITS_UTILS_H
|
||||
#define NETWORK_TRAFFIC_BITS_UTILS_H
|
||||
|
||||
|
||||
#include <vector>
|
||||
#include <bitset>
|
||||
|
||||
|
||||
#define SIZE_OF_BITS(x) (sizeof(x) * CHAR_BIT)
|
||||
|
||||
|
||||
using std::vector;
|
||||
using std::bitset;
|
||||
|
||||
/**
|
||||
* bitwise get the n-th bit of val.
|
||||
* @tparam T - some unsigned integer type
|
||||
* @param num - number to get the bit from
|
||||
* @param n - index of bit to return
|
||||
* @return 1 if the n-th bit of val is 1, 0 otherwise
|
||||
*/
|
||||
template<typename T>
|
||||
bool getUintNthBit(T num, unsigned int n) {
|
||||
assert(n >= 0 && n < (SIZE_OF_BITS(num)));
|
||||
return (num & ( 1 << n )) >> n; // NOLINT(hicpp-signed-bitwise)
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms a vector<bool> from a bitset<N>.
|
||||
* @tparam N - Number of bits.
|
||||
* @param bits - Bits to transform.
|
||||
* @return vector<bool> that represents the bitset
|
||||
*/
|
||||
template<int N>
|
||||
static vector<bool> bitsetToVector(const bitset<N>& bits){
|
||||
vector<bool> outVec;
|
||||
|
||||
for(int i = N-1; i >= 0; i--){
|
||||
outVec.push_back(bits[i]);
|
||||
}
|
||||
return outVec;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static vector<bool> uintToVector(T n) {
|
||||
vector<bool> outVec;
|
||||
|
||||
for (int i = 0; i < SIZE_OF_BITS(n); i++) {
|
||||
outVec.insert(outVec.begin(), getUintNthBit(n, i));
|
||||
}
|
||||
return outVec;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies a range of bits in an array of integer-like elements to a bitset.
|
||||
* The range is [bufIndex, N-1]
|
||||
* @tparam T - The type of the elements in the array.
|
||||
* @tparam N - The size of the range.
|
||||
* @param bits - the bits object to copy into.
|
||||
* @param buf - Input array.
|
||||
* @param bufIndex - starting bit.
|
||||
*/
|
||||
template<typename T, unsigned int N>
|
||||
static void setBitsFromArray(bitset<N>& bits, const T* buf, unsigned int& bufIndex) {
|
||||
for (int i = N-1; i >= 0; i--) {
|
||||
unsigned int bitIndex = SIZE_OF_BITS(T) - 1 - (bufIndex % SIZE_OF_BITS(T));
|
||||
bool bit = getUintNthBit(*(buf + (bufIndex / 8)), bitIndex);
|
||||
bits.set(i, bit);
|
||||
bufIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T, unsigned int N>
|
||||
static void setBitsFromArray(bitset<N>& bits, const T* buf) {
|
||||
unsigned int idx = 0;
|
||||
|
||||
for (int i = N - 1; i >= 0; i--) {
|
||||
unsigned int bitIndex = SIZE_OF_BITS(T) - 1 - (idx % SIZE_OF_BITS(T));
|
||||
bool bit = getUintNthBit(*(buf + (idx / 8)), bitIndex);
|
||||
bits.set(i, bit);
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void setNthBit(T& num, unsigned int n){
|
||||
assert(n < SIZE_OF_BITS(num));
|
||||
num |= 1UL << n;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the n-th bit of num
|
||||
* @tparam T - the type of num
|
||||
* @param num - the number to clear a bit on
|
||||
* @param n - the index of the bit to clear
|
||||
*/
|
||||
template<typename T>
|
||||
void clearNthBit(T& num, unsigned int n){
|
||||
assert(n < SIZE_OF_BITS(num));
|
||||
num &= ~(1UL << n);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void changeNthBit(T& num, unsigned int n, bool bitVal){
|
||||
assert(n < SIZE_OF_BITS(num));
|
||||
if(bitVal){
|
||||
setNthBit(num, n);
|
||||
} else {
|
||||
clearNthBit(num, n);
|
||||
}
|
||||
}
|
||||
|
||||
void toggleLsbMsb(vector<bool>& v, unsigned int intervalSize){
|
||||
if(v.size() % intervalSize != 0){
|
||||
return;
|
||||
}
|
||||
for(size_t i = 0; i < v.size(); i += intervalSize){
|
||||
vector<bool> tmp(intervalSize);
|
||||
for(unsigned int j = 0; j < intervalSize; j++){
|
||||
tmp[j] = v[i + intervalSize - 1 - j];
|
||||
}
|
||||
for(unsigned int j = 0; j < intervalSize; j++){
|
||||
v[i + j] = tmp[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void toggleEndianness(vector<bool>& v, unsigned int wordSize){
|
||||
if(wordSize % CHAR_BIT != 0 || v.size() % wordSize != 0){
|
||||
return;
|
||||
}
|
||||
for(size_t i = 0; i < v.size(); i += wordSize){
|
||||
vector<bool> tmp(wordSize);
|
||||
for(size_t j = 0; j < wordSize; j += CHAR_BIT){
|
||||
for(size_t k = 0; k < CHAR_BIT; k++){
|
||||
unsigned int readIdx = i + wordSize - j - CHAR_BIT + k;
|
||||
unsigned int writeIdx = j + k;
|
||||
tmp[writeIdx] = v[readIdx];
|
||||
}
|
||||
}
|
||||
for(unsigned int j = 0; j < wordSize; j++){
|
||||
v[i + j] = tmp[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T, typename W>
|
||||
W bitWiseConcatenate(T left, T right){
|
||||
W wide = (static_cast<W>(left) << CHAR_BIT * (sizeof(W) - sizeof(T))) | right;
|
||||
return wide;
|
||||
}
|
||||
|
||||
template<typename IntType>
|
||||
void toArray(vector<bool>& v, IntType* buf){
|
||||
for(unsigned int i = 0; i < v.size(); i++){
|
||||
if(v[i]){
|
||||
setNthBit(buf[i / SIZE_OF_BITS(*buf)], i % SIZE_OF_BITS(*buf));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif //NETWORK_TRAFFIC_BITS_UTILS_H
|
||||
205
qcom/opensource/dataipa/kernel-tests/network_traffic/main.cpp
Normal file
205
qcom/opensource/dataipa/kernel-tests/network_traffic/main.cpp
Normal file
@@ -0,0 +1,205 @@
|
||||
/*
|
||||
* Copyright (c) 2021 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include "UlsoPacket.h"
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using std::string;
|
||||
|
||||
static uint8_t buf[UlsoPacket<UdpHeader>::maxSize];
|
||||
|
||||
static uint8_t qmapIPv4UdpPacketNoSeg[] = {
|
||||
//C=0,Next Header=1,PAD=b'63,MUXID=0,Packet length=30
|
||||
0X7f, 0x00, 0x00, 0x1e,//QMAP header
|
||||
//type=3,Next Header=0,IPIDCfg=1,Zero Checksum=1,Additional header size=0,segment size=2
|
||||
0X06, 0xc0, 0x00, 0x02,//QMAP header extension
|
||||
//IPv4 header
|
||||
0x45, 0x00, 0x00, 0x1e,//version=4,IHL=5,DSCP=0,ECN=0,length=30
|
||||
0x00, 0x00, 0x00, 0x00,//id=0,flags=0,fragment offset=0
|
||||
0xff, 0x11, 0x00, 0x00,//TTL=255,Protocol=17 (TCP),checksum=
|
||||
0xc0, 0xa8, 0x02, 0x13,//IPv4 SRC Addr 192.168.2.19
|
||||
0xc0, 0xa8, 0x02, 0x68,//IPv4 DST Addr 192.168.2.104
|
||||
//UDP header
|
||||
0x04, 0x57, 0x08, 0xae,//source port=1111, destination port=2222
|
||||
0x00, 0x0a, 0x00, 0x00,//length=10,checksum=
|
||||
//payload
|
||||
0x00, 0x01
|
||||
};
|
||||
|
||||
static uint8_t qmapIPv4UdpPacket[] = {
|
||||
//C=0,Next Header=1,PAD=b'63,MUXID=0,Packet length=30
|
||||
0X7f, 0x00, 0x00, 0x1e,//QMAP header
|
||||
//type=3,Next Header=0,IPIDCfg=1,Zero Checksum=1,Additional header size=0,segment size=1
|
||||
0X06, 0xc0, 0x00, 0x01,//QMAP header extension
|
||||
//IPv4 header
|
||||
0x45, 0x00, 0x00, 0x1e,//version=4,IHL=5,DSCP=0,ECN=0,length=30
|
||||
0x00, 0x00, 0x00, 0x00,//id=0,flags=0,fragment offset=0
|
||||
0xff, 0x11, 0x00, 0x00,//TTL=255,Protocol=17 (TCP),checksum=
|
||||
0xc0, 0xa8, 0x02, 0x13,//IPv4 SRC Addr 192.168.2.19
|
||||
0xc0, 0xa8, 0x02, 0x68,//IPv4 DST Addr 192.168.2.104
|
||||
//UDP header
|
||||
0x04, 0x57, 0x08, 0xae,//source port=1111, destination port=2222
|
||||
0x00, 0x0a, 0x00, 0x00,//length=10,checksum=
|
||||
//payload
|
||||
0x00, 0x01
|
||||
};
|
||||
|
||||
static uint8_t qmapIPv4UdpPacket2[] = {
|
||||
//C=0,Next Header=1,PAD=b'63,MUXID=0,Packet length=30
|
||||
0X7f, 0x00, 0x00, 0x20,//QMAP header
|
||||
//type=3,Next Header=0,IPIDCfg=0,Zero Checksum=1,Additional header size=0,segment size=1
|
||||
0X06, 0x00, 0x00, 0x01,//QMAP header extension
|
||||
//IPv4 header
|
||||
0x45, 0x00, 0x00, 0x20,//version=4,IHL=5,DSCP=0,ECN=0,length=30
|
||||
0x00, 0x00, 0x00, 0x00,//id=0,flags=0,fragment offset=0
|
||||
0xff, 0x11, 0x00, 0x00,//TTL=255,Protocol=17 (TCP),checksum=
|
||||
0xc0, 0xa8, 0x02, 0x13,//IPv4 SRC Addr 192.168.2.19
|
||||
0xc0, 0xa8, 0x02, 0x68,//IPv4 DST Addr 192.168.2.104
|
||||
//UDP header
|
||||
0x04, 0x57, 0x08, 0xae,//source port=1111, destination port=2222
|
||||
0x00, 0x0c, 0x00, 0x00,//length=10,checksum=
|
||||
//payload
|
||||
0x00, 0x01, 0x02, 0x03
|
||||
};
|
||||
|
||||
char sep[] = "---------------------------------------------"
|
||||
"---------------------------------------------"
|
||||
"---------------------------------------------"
|
||||
"---------------------------------------------"
|
||||
"---------------------------------------------";
|
||||
|
||||
void printDemoHeadline(const string& name) {
|
||||
string full = "###################################################"
|
||||
"###################################################";
|
||||
string side = "############################";
|
||||
string space = " ";
|
||||
cout << full << endl << side << space << "Demo " + name << space
|
||||
<< side << endl << full << endl;
|
||||
}
|
||||
|
||||
void demo(UlsoPacket<>& ulsoPacket, const string& name) {
|
||||
printDemoHeadline(name);
|
||||
cout << ulsoPacket << endl;
|
||||
cout << sep << endl;
|
||||
|
||||
vector<UlsoPacket<>> packets = ulsoPacket.segment();
|
||||
std::for_each(packets.begin(), packets.end(), [](const auto& p){cout << p << endl;
|
||||
cout << sep << endl;});
|
||||
}
|
||||
|
||||
void testIpv4Tcp(){
|
||||
using L2Type = IPv4Header;
|
||||
using L3Type = TcpHeader;
|
||||
using PacketType = UlsoPacket<L3Type, L2Type>;
|
||||
size_t payloadSize = 91, segmentSize = 32;
|
||||
size_t packetSize = QmapHeader::mSize + L2Type::mSize + L3Type::mSize + payloadSize;
|
||||
|
||||
PacketType p1(segmentSize, payloadSize);
|
||||
cout << p1 << endl;
|
||||
uint8_t ipv4HeaderBuf[packetSize];
|
||||
p1.asArray(ipv4HeaderBuf);
|
||||
uint8_t *ipv4HeaderPtr = ipv4HeaderBuf;
|
||||
uint8_t *goldBuf = QmapIpv4TcpPacket.l2Packet();
|
||||
for(unsigned int i=0; i<QmapIpv4TcpPacket.l2PacketSize(); i++){
|
||||
if(ipv4HeaderPtr[i] != goldBuf[i]){
|
||||
cout << "ipv4HeaderBuf[" << i << "]=" << std::hex << std::setfill('0') << std::setw(2) <<
|
||||
static_cast<int>(ipv4HeaderPtr[i]) << std::dec << ", goldBuf[" << i << "]=" << std::setfill('0') <<
|
||||
std::setw(2) << std::hex << static_cast<int>(goldBuf[i]) << std::dec << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void testIpv4Udp(){
|
||||
using L2Type = IPv4Header;
|
||||
using L3Type = UdpHeader;
|
||||
using PacketType = UlsoPacket<L3Type, L2Type>;
|
||||
size_t payloadSize = 80, segmentSize = 32;
|
||||
size_t packetSize = QmapHeader::mSize + L2Type::mSize + L3Type::mSize + payloadSize;
|
||||
|
||||
PacketType p1(segmentSize, payloadSize);
|
||||
cout << p1 << endl;
|
||||
uint8_t ipv4UdpHeaderBuf[packetSize];
|
||||
p1.asArray(ipv4UdpHeaderBuf);
|
||||
uint8_t *udpHeaderPtr = ipv4UdpHeaderBuf + QmapHeader::mSize + L2Type::mSize;
|
||||
uint8_t *goldBuf = udpPacket.l3Packet();
|
||||
for(unsigned int i=0; i<udpPacket.l3PacketSize(); i++){
|
||||
if(udpHeaderPtr[i] != goldBuf[i]){
|
||||
cout << "udpPayload[" << i << "]=" << std::hex << std::setfill('0') << std::setw(2) <<
|
||||
static_cast<int>(udpHeaderPtr[i]) << std::dec << ", goldBuf[" << i << "]=" << std::setfill('0') <<
|
||||
std::setw(2) << std::hex << static_cast<int>(goldBuf[i]) << std::dec << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<typename L3Type, typename L2Type>
|
||||
size_t packetTestOffset(const struct Packet& p){
|
||||
return QmapHeader::mSize + (p.l2Size == 0) * L2Type::mSize + (p.l3Size == 0) * L3Type::mSize;
|
||||
}
|
||||
|
||||
template<typename L3Type, typename L2Type>
|
||||
bool testPacketConstruction(struct Packet packet, size_t segmentSize=20){
|
||||
auto testOffsetFunc = packetTestOffset<L3Type, L2Type>;
|
||||
using PacketType = UlsoPacket<L3Type, L2Type>;
|
||||
size_t ipPacketSize = packet.l2PacketSize();
|
||||
PacketType ulsoPacket(segmentSize, packet.payload(), packet.payloadSize);
|
||||
if(ulsoPacket.size() - testOffsetFunc(packet) != ipPacketSize){
|
||||
cout << "Error: ULSO packet size = " << ulsoPacket.size() << " expected size = " << ipPacketSize << endl;
|
||||
return false;
|
||||
}
|
||||
uint8_t ulsoPacketBuf[ulsoPacket.size()];
|
||||
ulsoPacket.asArray(ulsoPacketBuf);
|
||||
uint8_t *ulsoCmpBuf = ulsoPacketBuf + testOffsetFunc(packet);
|
||||
uint8_t *goldBuf = packet.l2Packet();
|
||||
for(unsigned int i=0; i<ipPacketSize; i++){
|
||||
if(ulsoCmpBuf[i] != goldBuf[i]){
|
||||
cout << "afterQmapPtr[" << i << "]=" << std::hex << std::setfill('0') << std::setw(2) <<
|
||||
static_cast<int>(ulsoCmpBuf[i]) << std::dec << ", goldBuf[" << i << "]=" << std::setfill('0') <<
|
||||
std::setw(2) << std::hex << static_cast<int>(goldBuf[i]) << std::dec << endl;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
||||
uint8_t arr[UlsoPacket<>::maxSize] = {0};
|
||||
UlsoPacket<UdpHeader, IPv4Header> p(19, 100, false);
|
||||
p.mQmapHeader.setmIpIdCfg(0);
|
||||
cout << p << endl;
|
||||
auto v = p.segment();
|
||||
for(auto& pSeg: v){
|
||||
memset(arr, 0, UlsoPacket<>::maxSize);
|
||||
cout << pSeg << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
198
qcom/opensource/dataipa/kernel-tests/network_traffic/packets.h
Normal file
198
qcom/opensource/dataipa/kernel-tests/network_traffic/packets.h
Normal file
@@ -0,0 +1,198 @@
|
||||
/*
|
||||
* Copyright (c) 2021 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef NETWORK_TRAFFIC_PACKETS_H
|
||||
#define NETWORK_TRAFFIC_PACKETS_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
|
||||
struct Packet{
|
||||
size_t size;
|
||||
size_t preL2Size;
|
||||
size_t l2Size;
|
||||
size_t l3Size;
|
||||
size_t payloadSize;
|
||||
uint8_t* packet;
|
||||
|
||||
uint8_t* payload() const {
|
||||
return packet + preL2Size + l2Size + l3Size;
|
||||
}
|
||||
|
||||
uint8_t* l2Packet() const {
|
||||
return packet + preL2Size;
|
||||
}
|
||||
|
||||
size_t l2PacketSize() const {
|
||||
return size - preL2Size;
|
||||
}
|
||||
|
||||
uint8_t* l3Packet() const {
|
||||
return packet + preL2Size + l2Size;
|
||||
}
|
||||
|
||||
size_t l3PacketSize() const {
|
||||
return size - preL2Size - l2Size;
|
||||
}
|
||||
};
|
||||
|
||||
constexpr size_t qmapIpv4TcpPacketArrSize = 139;
|
||||
uint8_t qmapIpv4TcpPacketArr[qmapIpv4TcpPacketArrSize] = {
|
||||
0x40, 0x00, 0x00, 0x83,
|
||||
0x06, 0x80, 0x00, 0x20,
|
||||
0x45, 0x00, 0x00, 0x83,
|
||||
0xf5, 0x7a, 0x40, 0x00,
|
||||
0x40, 0x06, 0xc1, 0x70,
|
||||
0xc0, 0xa8, 0x01, 0x11,
|
||||
0xc0, 0xa8, 0x01, 0x28,
|
||||
0xdd, 0xd5, 0xfd, 0x76,
|
||||
0x40, 0x35, 0xff, 0xc7,
|
||||
0xb8, 0x35, 0xf0, 0xad,
|
||||
0x50, 0x18, 0x01, 0xd9,
|
||||
0x40, 0xa0, 0x00, 0x00,
|
||||
0x48, 0x54, 0x54, 0x50,
|
||||
0x2f, 0x31, 0x2e, 0x31,
|
||||
0x20, 0x34, 0x30, 0x34,
|
||||
0x20, 0x4e, 0x6f, 0x74,
|
||||
0x20, 0x46, 0x6f, 0x75,
|
||||
0x6e, 0x64, 0x0d, 0x0a,
|
||||
0x43, 0x6f, 0x6e, 0x74,
|
||||
0x65, 0x6e, 0x74, 0x2d,
|
||||
0x54, 0x79, 0x70, 0x65,
|
||||
0x3a, 0x20, 0x74, 0x65,
|
||||
0x78, 0x74, 0x2f, 0x70,
|
||||
0x6c, 0x61, 0x69, 0x6e,
|
||||
0x0d, 0x0a, 0x43, 0x6f,
|
||||
0x6e, 0x74, 0x65, 0x6e,
|
||||
0x74, 0x2d, 0x4c, 0x65,
|
||||
0x6e, 0x67, 0x74, 0x68,
|
||||
0x3a, 0x20, 0x33, 0x30,
|
||||
0x0d, 0x0a, 0x43, 0x6f,
|
||||
0x6e, 0x6e, 0x65, 0x63,
|
||||
0x74, 0x69, 0x6f, 0x6e,
|
||||
0x3a, 0x20, 0x63, 0x6c,
|
||||
0x6f, 0x73, 0x65, 0x0d,
|
||||
0x0a, 0x0d, 0x0a
|
||||
};
|
||||
constexpr size_t ipv4UdpPacketArrSize = 46;
|
||||
uint8_t ipv4UdpPacketArr[ipv4UdpPacketArrSize] = {
|
||||
0x45, 0x00, 0x00, 0x25,
|
||||
0xd7, 0xa9, 0x00, 0x00,
|
||||
0x72, 0x11, 0xeb, 0x8f,
|
||||
0x0a, 0x3f, 0x8d, 0xc4,
|
||||
0xac, 0x10, 0x41, 0x7b,
|
||||
0x0d, 0x3d, 0xe8, 0x19,
|
||||
0x00, 0x11, 0x88, 0xd7,
|
||||
0x00, 0x04, 0xc0, 0x1a,
|
||||
0x3b, 0x00, 0x00, 0xf0,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00
|
||||
};
|
||||
|
||||
constexpr size_t udpPacketArrSize = 80;
|
||||
uint8_t udpPacketArr[udpPacketArrSize] = {
|
||||
0x07, 0xc1, 0x07, 0xc1,
|
||||
0x00, 0x50, 0x39, 0x1a,
|
||||
0x01, 0x28, 0x02, 0x00,
|
||||
0x05, 0x04, 0x00, 0x03,
|
||||
0xa0, 0xe0, 0xaf, 0x89,
|
||||
0xb7, 0x3f, 0x00, 0x00,
|
||||
0x00, 0x5a, 0x00, 0x00,
|
||||
0x03, 0xe8, 0x00, 0x00,
|
||||
0x0b, 0xb8, 0xac, 0x10,
|
||||
0x41, 0x01, 0x61, 0x6e,
|
||||
0x2d, 0x72, 0x74, 0x2d,
|
||||
0x30, 0x32, 0x2e, 0x71,
|
||||
0x75, 0x61, 0x04, 0x1c,
|
||||
0x01, 0x00, 0x00, 0x00,
|
||||
0xac, 0x10, 0x41, 0x02,
|
||||
0x00, 0x00, 0x00, 0x01,
|
||||
0x74, 0x18, 0x26, 0xc7,
|
||||
0xa5, 0x29, 0x24, 0xa1,
|
||||
0xcc, 0x77, 0x76, 0xdc,
|
||||
0x6f, 0x52, 0xfb, 0xbf
|
||||
};
|
||||
|
||||
constexpr size_t ipv6UdpPacketArrSize = 64;
|
||||
uint8_t ipv6UdpPacketArr[ipv6UdpPacketArrSize] = {
|
||||
0x60, 0x05, 0xc1, 0xfd,
|
||||
0x00, 0x18, 0x11, 0x01,
|
||||
0xfe, 0x80, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x8a, 0x51, 0xfb, 0xff,
|
||||
0xfe, 0x41, 0xf5, 0xbd,
|
||||
0xff, 0x02, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x01,
|
||||
0x21, 0xa4, 0x21, 0xa4,
|
||||
0x00, 0x18, 0xb2, 0x04,
|
||||
0x42, 0x4a, 0x4e, 0x50,
|
||||
0x02, 0x01, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
Packet QmapIpv4TcpPacket{
|
||||
.size=qmapIpv4TcpPacketArrSize,
|
||||
.preL2Size=8,
|
||||
.l2Size=20,
|
||||
.l3Size=20,
|
||||
.payloadSize=91,
|
||||
.packet=qmapIpv4TcpPacketArr
|
||||
};
|
||||
|
||||
Packet ipv4UdpPacket{
|
||||
.size=ipv4UdpPacketArrSize,
|
||||
.preL2Size=0,
|
||||
.l2Size=20,
|
||||
.l3Size=8,
|
||||
.payloadSize=18,
|
||||
.packet=ipv4UdpPacketArr
|
||||
};
|
||||
|
||||
Packet udpPacket{
|
||||
.size=udpPacketArrSize,
|
||||
.preL2Size=0,
|
||||
.l2Size=0,
|
||||
.l3Size=8,
|
||||
.payloadSize=72,
|
||||
.packet=udpPacketArr
|
||||
};
|
||||
|
||||
Packet ipv6UdpPacket{
|
||||
.size=ipv6UdpPacketArrSize,
|
||||
.preL2Size=0,
|
||||
.l2Size=40,
|
||||
.l3Size=8,
|
||||
.payloadSize=16,
|
||||
.packet=ipv6UdpPacketArr
|
||||
};
|
||||
|
||||
#endif //NETWORK_TRAFFIC_PACKETS_H
|
||||
64
qcom/opensource/dataipa/kernel-tests/run.sh
Normal file
64
qcom/opensource/dataipa/kernel-tests/run.sh
Normal file
@@ -0,0 +1,64 @@
|
||||
#! /bin/sh
|
||||
|
||||
# Copyright (c) 2014,2017,2021, The Linux Foundation. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
# met:
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above
|
||||
# copyright notice, this list of conditions and the following
|
||||
# disclaimer in the documentation and/or other materials provided
|
||||
# with the distribution.
|
||||
# * Neither the name of The Linux Foundation nor the names of its
|
||||
# contributors may be used to endorse or promote products derived
|
||||
# from this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
set -e
|
||||
./test_env_setup.sh
|
||||
|
||||
echo "Starting test"
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
echo "No args\n"
|
||||
exec ./ipa_kernel_tests --suite_name Regression
|
||||
fi
|
||||
|
||||
#Parse the args for valid switches
|
||||
while [ $# -gt 0 ]; do
|
||||
case $1 in
|
||||
-n | --nominal)
|
||||
echo "Nominal\n"
|
||||
exec ./ipa_kernel_tests --suite_name Regression
|
||||
exit 0
|
||||
;;
|
||||
-a | --adversarial)
|
||||
echo "adversarial\n"
|
||||
echo "Currently no adversarial tests"
|
||||
exit 0
|
||||
;;
|
||||
-r | --repeatability)
|
||||
echo "Currently no repeatability tests"
|
||||
-s | --stress)
|
||||
echo "Currently no stress tests"
|
||||
exit 0
|
||||
;;
|
||||
-h | --help | *)
|
||||
echo "Usage: ./run.sh -[n][a][r][s]"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
Reference in New Issue
Block a user