/* * 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 #include #include #include #include #include // 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 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 class PacketModifier {public:virtual void operator()(PacketType& p) const = 0; virtual ~PacketModifier(){}}; template class NullPacketModifier: public PacketModifier {public:void operator()(PacketType& p) const override {}}; template class ZeroChecksumPacketModifier: public PacketModifier {public:void operator()(PacketType& p) const override {p.mQmapHeader.setmZeroChecksum(1);}}; template class OutOfBoundsPacketModifier: public PacketModifier {public:void operator()(PacketType& p) const override {p.mQmapHeader.setmIpIdCfg(0);p.setIpId(65530);}}; template>> class PacketsGeneratorClass { protected: using PacketType = UlsoPacket; public: vector operator()(){ vector outVec; Modifier m; for(size_t i=0; i(SegmentSizesArr[i] * SegmentsNumsArr[j]), true); m(p); outVec.emplace_back(p); } } return outVec; } }; template class UlsoTest: public UlsoTestFixture { private: using PacketType = UlsoPacket; 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 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 packetsVec = PacketsGenerator()(); for(auto& p: packetsVec){ if(!singlePacketRun(p)){ cout << "Failed With the following packet:" << endl; cout << p << endl; return false; } } return true; } }; template class UlsoHPCTest: public UlsoTestFixture { private: using PacketType = UlsoPacket; 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 segmentedPacketsVec = p.segment(); memset(m_segmentBuf, 0, sizeof(m_segmentBuf)); uint8_t *segmentBufPtr = m_segmentBuf; size_t totalSegmentsSize = 0; vector 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 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>> #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 ulsoTest0 {"Single Packet: IPV4 UDP"}; static UlsoTest ulsoTest1 {"Single Packet: IPV4 TCP"}; static UlsoTest ulsoTest2 {"Single Packet: IPV6 UDP"}; static UlsoTest 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 ulsoTest10 {"Segmentation No Segmentation IPV4 UDP"}; static UlsoTest ulsoTest11 {"Segmentation No Segmentation IPV4 TCP"}; static UlsoTest ulsoTest12 {"Segmentation No Segmentation IPV6 UDP"}; static UlsoTest 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 ulsoTest20 {"Zero Checksum IPV4 UDP"}; static UlsoTest ulsoTest21 {"Zero Checksum IPV4 TCP"}; static UlsoTest ulsoTest22 {"Zero Checksum IPV6 UDP"}; static UlsoTest 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 ulsoTest30 {"Payload Smaller Than MSS IPV4 UDP"}; static UlsoTest ulsoTest31 {"Payload Smaller Than MSS IPV4 TCP"}; static UlsoTest ulsoTest32 {"Payload Smaller Than MSS IPV6 UDP"}; static UlsoTest 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 ulsoTest40 {"Payload slightly Smaller Than MSS IPV4 UDP"}; static UlsoTest ulsoTest41 {"Payload slightly Smaller Than MSS IPV4 TCP"}; static UlsoTest ulsoTest42 {"Payload slightly Smaller Than MSS IPV6 UDP"}; static UlsoTest 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 ulsoTest50 {"Payload Equals MSS IPV4 UDP"}; static UlsoTest ulsoTest51 {"Payload Equals MSS IPV4 TCP"}; static UlsoTest ulsoTest52 {"Payload Equals MSS IPV6 UDP"}; static UlsoTest 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 ulsoTest60 {"Valid Segment Sizes IPV4 UDP"}; static UlsoTest ulsoTest61 {"Valid Segment Sizes IPV4 TCP"}; static UlsoTest ulsoTest62 {"Valid Segment Sizes IPV6 UDP"}; static UlsoTest 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 ulsoTest70 {"Big Segment Sizes IPV4 UDP"}; static UlsoTest ulsoTest71 {"Big Segment Sizes IPV4 TCP"}; static UlsoTest ulsoTest72 {"Big Segment Sizes IPV6 UDP"}; static UlsoTest 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 ulsoTest80 {"IPID CFG IPV4 UDP"}; static UlsoTest ulsoTest81 {"IPID CFG IPV4 UDP"}; //////////////////////////////////////////////////////////////////////////////// //////////////// HPC RNDIS Header Insertion ////////////////////// //////////////////////////////////////////////////////////////////////////////// static UlsoHPCTest Ipv4UdpHpcRndisTest {"Ipv4UdpHpcRndisTest", "IPv4 + UDP"}; static UlsoHPCTest Ipv4TcpHpcRndisTest {"Ipv4TcpHpcRndisTest", "IPv4 + TCP"}; static UlsoHPCTest Ipv6UdpHpcRndisTest {"Ipv6UdpHpcRndisTest", "IPv6 + UDP"}; static UlsoHPCTest Ipv6TcpHpcRndisTest {"Ipv6TcpHpcRndisTest", "IPv6 + TCP"};