diff --git a/drivers/platform/msm/ipa/ipa_test_module/ipa_test_module.h b/drivers/platform/msm/ipa/ipa_test_module/ipa_test_module.h index 236e845acc..223db248c1 100644 --- a/drivers/platform/msm/ipa/ipa_test_module/ipa_test_module.h +++ b/drivers/platform/msm/ipa/ipa_test_module/ipa_test_module.h @@ -22,6 +22,7 @@ enum { IPA_TEST_IOCTL_REG_SUSPEND_HNDL, IPA_TEST_IOCTL_HOLB_CONFIG, IPA_TEST_IOCTL_FLT_TBL_IN_SRAM, + IPA_TEST_IOCTL_GET_MEM_PART, IPA_TEST_IOCTL_NUM, }; @@ -43,6 +44,9 @@ enum { struct handle_holb_config_ioctl *) #define IPA_TEST_IOC_IS_TEST_PROD_FLT_IN_SRAM _IO(IPA_TEST_IOC_MAGIC, \ IPA_TEST_IOCTL_FLT_TBL_IN_SRAM) +#define IPA_TEST_IOC_GET_MEM_PART _IOWR(IPA_TEST_IOC_MAGIC, \ + IPA_TEST_IOCTL_GET_MEM_PART, \ + struct ipa_test_mem_partition *) #define IPA_TEST_CONFIG_MARKER 0x57 #define IPA_TEST_CHANNEL_CONFIG_MARKER 0x83 @@ -101,4 +105,104 @@ struct ipa_test_holb_config unsigned tmr_val; unsigned short en; }; + +struct ipa_test_mem_partition { + unsigned ofst_start; + unsigned v4_flt_hash_ofst; + unsigned v4_flt_hash_size; + unsigned v4_flt_hash_size_ddr; + unsigned v4_flt_nhash_ofst; + unsigned v4_flt_nhash_size; + unsigned v4_flt_nhash_size_ddr; + unsigned v6_flt_hash_ofst; + unsigned v6_flt_hash_size; + unsigned v6_flt_hash_size_ddr; + unsigned v6_flt_nhash_ofst; + unsigned v6_flt_nhash_size; + unsigned v6_flt_nhash_size_ddr; + unsigned v4_rt_num_index; + unsigned v4_modem_rt_index_lo; + unsigned v4_modem_rt_index_hi; + unsigned v4_apps_rt_index_lo; + unsigned v4_apps_rt_index_hi; + unsigned v4_rt_hash_ofst; + unsigned v4_rt_hash_size; + unsigned v4_rt_hash_size_ddr; + unsigned v4_rt_nhash_ofst; + unsigned v4_rt_nhash_size; + unsigned v4_rt_nhash_size_ddr; + unsigned v6_rt_num_index; + unsigned v6_modem_rt_index_lo; + unsigned v6_modem_rt_index_hi; + unsigned v6_apps_rt_index_lo; + unsigned v6_apps_rt_index_hi; + unsigned v6_rt_hash_ofst; + unsigned v6_rt_hash_size; + unsigned v6_rt_hash_size_ddr; + unsigned v6_rt_nhash_ofst; + unsigned v6_rt_nhash_size; + unsigned v6_rt_nhash_size_ddr; + unsigned modem_hdr_ofst; + unsigned modem_hdr_size; + unsigned apps_hdr_ofst; + unsigned apps_hdr_size; + unsigned apps_hdr_size_ddr; + unsigned modem_hdr_proc_ctx_ofst; + unsigned modem_hdr_proc_ctx_size; + unsigned apps_hdr_proc_ctx_ofst; + unsigned apps_hdr_proc_ctx_size; + unsigned apps_hdr_proc_ctx_size_ddr; + unsigned nat_tbl_ofst; + unsigned nat_tbl_size; + unsigned modem_comp_decomp_ofst; + unsigned modem_comp_decomp_size; + unsigned modem_ofst; + unsigned modem_size; + unsigned apps_v4_flt_hash_ofst; + unsigned apps_v4_flt_hash_size; + unsigned apps_v4_flt_nhash_ofst; + unsigned apps_v4_flt_nhash_size; + unsigned apps_v6_flt_hash_ofst; + unsigned apps_v6_flt_hash_size; + unsigned apps_v6_flt_nhash_ofst; + unsigned apps_v6_flt_nhash_size; + unsigned uc_info_ofst; + unsigned uc_info_size; + unsigned end_ofst; + unsigned apps_v4_rt_hash_ofst; + unsigned apps_v4_rt_hash_size; + unsigned apps_v4_rt_nhash_ofst; + unsigned apps_v4_rt_nhash_size; + unsigned apps_v6_rt_hash_ofst; + unsigned apps_v6_rt_hash_size; + unsigned apps_v6_rt_nhash_ofst; + unsigned apps_v6_rt_nhash_size; + unsigned uc_descriptor_ram_ofst; + unsigned uc_descriptor_ram_size; + unsigned pdn_config_ofst; + unsigned pdn_config_size; + unsigned stats_quota_q6_ofst; + unsigned stats_quota_q6_size; + unsigned stats_quota_ap_ofst; + unsigned stats_quota_ap_size; + unsigned stats_tethering_ofst; + unsigned stats_tethering_size; + unsigned stats_fnr_ofst; + unsigned stats_fnr_size; + unsigned uc_ofst; + unsigned uc_size; + + /* Irrelevant starting IPA4.5 */ + unsigned stats_flt_v4_ofst; + unsigned stats_flt_v4_size; + unsigned stats_flt_v6_ofst; + unsigned stats_flt_v6_size; + unsigned stats_rt_v4_ofst; + unsigned stats_rt_v4_size; + unsigned stats_rt_v6_ofst; + unsigned stats_rt_v6_size; + + unsigned stats_drop_ofst; + unsigned stats_drop_size; +}; #endif /* _IPA_TEST_MODULE_H_ */ diff --git a/drivers/platform/msm/ipa/ipa_test_module/ipa_test_module_impl.c b/drivers/platform/msm/ipa/ipa_test_module/ipa_test_module_impl.c index eb42502444..6a5300e2e0 100644 --- a/drivers/platform/msm/ipa/ipa_test_module/ipa_test_module_impl.c +++ b/drivers/platform/msm/ipa/ipa_test_module/ipa_test_module_impl.c @@ -4518,6 +4518,22 @@ static int handle_holb_config_ioctl(unsigned long ioctl_arg) return ipa3_cfg_ep_holb(clnt_hdl, &holb_cfg); } +static int ipa_test_get_mem_part(unsigned long ioctl_arg) +{ + unsigned long result; + + // Let's check that mirrored structure is of the same siz as the original + BUILD_BUG_ON(sizeof(struct ipa_test_mem_partition) != sizeof(struct ipa3_mem_partition)); + + result = copy_to_user((u8 *)ioctl_arg, + ipa3_ctx->ctrl->mem_partition, sizeof(struct ipa3_mem_partition)); + + if (result != 0) + return -EACCES; + + return 0; +} + static long ipa_test_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) { @@ -4550,6 +4566,8 @@ static long ipa_test_ioctl(struct file *filp, break; case IPA_TEST_IOC_IS_TEST_PROD_FLT_IN_SRAM: retval = ipa_is_test_prod_flt_in_sram_internal(arg); + case IPA_TEST_IOC_GET_MEM_PART: + retval = ipa_test_get_mem_part(arg); break; default: IPATEST_ERR("ioctl is not supported (%d)\n", cmd); diff --git a/kernel-tests/HeaderInsertionTests.cpp b/kernel-tests/HeaderInsertionTests.cpp index 299f616205..f12621096e 100644 --- a/kernel-tests/HeaderInsertionTests.cpp +++ b/kernel-tests/HeaderInsertionTests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2018 The Linux Foundation. All rights reserved. + * Copyright (c) 2017-2018,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 @@ -34,6 +34,10 @@ #include "hton.h" // for htonl #include "TestsUtils.h" #include +#include +#include +#include +#include #define IPV4_DST_ADDR_OFFSET (16) @@ -122,6 +126,30 @@ public: return true; } // Teardown() + unsigned GetHdrSramSize() + { + int fd; + struct ipa_test_mem_partition mem_part; + + fd = open("/dev/ipa_test", O_RDONLY); + if (fd < 0) { + printf("Failed opening %s. errno %d: %s\n", "/dev/ipa_test", + errno, strerror(errno)); + return 0; + } + + if (ioctl(fd, IPA_TEST_IOC_GET_MEM_PART, &mem_part) < 0) { + printf("Failed ioctl IPA_TEST_IOC_GET_MEM_PART. errno %d: %s\n", + errno, strerror(errno)); + close(fd); + return 0; + } + + close(fd); + + return mem_part.apps_hdr_size; + } + ~IPAHeaderInsertionTestFixture() {} static RoutingDriverWrapper m_Routing; @@ -867,9 +895,538 @@ private: size_t m_nHeadertoAddSize; }; +class IPAHeaderInsertionTest006: public IPAHeaderInsertionTestFixture { +public: + IPAHeaderInsertionTest006() { + m_name = "IPAHeaderInsertionTest006"; + m_description = + "Header Insertion Test 006 - Test header distriburion between SRAM and DDR\ + - fill SRAM and some DDR, use DDR header"; + this->m_runInRegression = true; + Register(*this); + uint8_t aRMNetHeader[6] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06}; + m_nHeadertoAddSize = sizeof(aRMNetHeader); + memcpy(m_aHeadertoAdd, aRMNetHeader, m_nHeadertoAddSize); + m_minIPAHwType = IPA_HW_v5_0; + + // The bin size is 8 + // We are going to add number of headers to occupy twice the size of the SRAM buffer + m_InitialHeadersNum = GetHdrSramSize() / 8 * 2; + m_HeadersNumToDelete = 0; + m_HeadersNumToAddAgain = 0; + } + + virtual bool AddRules() { + bool bRetVal = true; + m_eIP = IPA_IP_v4; + struct ipa_ioc_add_hdr *pHeaderDescriptor = NULL; + struct ipa_ioc_del_hdr *pDelHeaderDescriptor = NULL; + + memset(&m_RetHeader, 0, sizeof(m_RetHeader)); + LOG_MSG_STACK("Entering Function"); + + if (m_InitialHeadersNum <= 0) + { + LOG_MSG_ERROR("Initial headers number is set to 0!\n"); + bRetVal = false; + goto bail; + } + + pHeaderDescriptor = (struct ipa_ioc_add_hdr *) calloc(1, + sizeof(struct ipa_ioc_add_hdr) + 1 * sizeof(struct ipa_hdr_add)); + if (m_HeadersNumToDelete > 0) + pDelHeaderDescriptor = (struct ipa_ioc_del_hdr *)calloc(1, + sizeof(struct ipa_ioc_del_hdr) + m_HeadersNumToDelete * sizeof(struct ipa_hdr_del)); + if (!pHeaderDescriptor || (m_HeadersNumToDelete > 0 && !pDelHeaderDescriptor)) + { + LOG_MSG_ERROR("calloc failed to allocate ipa_ioc_add_hdr or ipa_ioc_del_hdr"); + bRetVal = false; + goto bail; + } + + // Add bunch of headers to SRAM and DDR + pHeaderDescriptor->commit = true; + pHeaderDescriptor->num_hdrs = 1; + memcpy(pHeaderDescriptor->hdr[0].hdr, m_aHeadertoAdd, m_nHeadertoAddSize); + pHeaderDescriptor->hdr[0].hdr_len = m_nHeadertoAddSize; + pHeaderDescriptor->hdr[0].hdr_hdl = -1; //Return Value + pHeaderDescriptor->hdr[0].is_partial = false; + pHeaderDescriptor->hdr[0].status = -1; // Return Parameter + + fflush(stderr); + fflush(stdout); + ret = system("cat /sys/kernel/debug/ipa/hdr"); + + for (int i = 0; i < m_InitialHeadersNum; i++) + { + LOG_MSG_DEBUG("%s::%s iter=%d\n", typeid(this).name(), __func__, i); + snprintf(pHeaderDescriptor->hdr[0].name, sizeof(pHeaderDescriptor->hdr[0].name), "IEEE802_3_%03d", i); + if (!m_HeaderInsertion.AddHeader(pHeaderDescriptor)) + { + LOG_MSG_ERROR("m_HeaderInsertion.AddHeader(pHeaderDescriptor) Failed on %d iteration.\n", i); + bRetVal = false; + goto bail; + } + // Store header descriptors to delete + if (m_HeadersNumToDelete > 0 && i < m_HeadersNumToDelete) { + pDelHeaderDescriptor->hdl[i].hdl = pHeaderDescriptor->hdr[0].hdr_hdl; + } + } + strlcpy(m_RetHeader.name, pHeaderDescriptor->hdr[0].name, sizeof(m_RetHeader.name)); + + fflush(stderr); + fflush(stdout); + ret = system("cat /sys/kernel/debug/ipa/hdr"); + + + if (m_HeadersNumToDelete > 0) + { + // Delete few headers from SRAM + pDelHeaderDescriptor->commit = true; + pDelHeaderDescriptor->num_hdls = m_HeadersNumToDelete; + for (int i = 0; i < m_HeadersNumToDelete; i++) + pDelHeaderDescriptor->hdl[i].status = -1; // Return Parameter + if (!m_HeaderInsertion.DeleteHeader(pDelHeaderDescriptor)) + { + LOG_MSG_ERROR("m_HeaderInsertion.DeleteHeader(pDelHeaderDescriptor) Failed"); + bRetVal = false; + goto bail; + } + + fflush(stderr); + fflush(stdout); + ret = system("cat /sys/kernel/debug/ipa/hdr"); + } + + if (m_HeadersNumToAddAgain > 0) + { + // Add few new headers to SRAM + pHeaderDescriptor->commit = true; + pHeaderDescriptor->num_hdrs = 1; + memcpy(pHeaderDescriptor->hdr[0].hdr, m_aHeadertoAdd, m_nHeadertoAddSize); + pHeaderDescriptor->hdr[0].hdr_len = m_nHeadertoAddSize; + pHeaderDescriptor->hdr[0].hdr_hdl = -1; //Return Value + pHeaderDescriptor->hdr[0].is_partial = false; + pHeaderDescriptor->hdr[0].status = -1; // Return Parameter + + for (int i = 0; i < m_HeadersNumToAddAgain; i++) { + LOG_MSG_DEBUG("%s::%s iter=%d\n", typeid(this).name(), __func__, i); + snprintf(pHeaderDescriptor->hdr[0].name, sizeof(pHeaderDescriptor->hdr[0].name), "IEEE802_3_%03d_2", i); + if (!m_HeaderInsertion.AddHeader(pHeaderDescriptor)) + { + LOG_MSG_ERROR("m_HeaderInsertion.AddHeader(pHeaderDescriptor) Failed on %d iteration.\n", i); + bRetVal = false; + goto bail; + } + } + strlcpy(m_RetHeader.name, pHeaderDescriptor->hdr[0].name, sizeof(m_RetHeader.name)); + + fflush(stderr); + fflush(stdout); + ret = system("cat /sys/kernel/debug/ipa/hdr"); + } + + // Use last added header for traffic + if (!m_HeaderInsertion.GetHeaderHandle(&m_RetHeader)) + { + LOG_MSG_ERROR(" Failed"); + bRetVal = false; + goto bail; + } + + bRetVal = CreateFilteringAndRouting(); + bail: + Free(pHeaderDescriptor); + if (pDelHeaderDescriptor) + Free(pDelHeaderDescriptor); + LOG_MSG_STACK("Leaving %s (Returning %s)", __func__, bRetVal ? "True" : "False"); + return bRetVal; + } // AddRules() + + virtual bool CreateFilteringAndRouting() { + uint32_t nRTTableHdl=0; + const char bypass0[20] = "Bypass0"; + struct ipa_ioc_get_rt_tbl sRoutingTable; + struct ipa_flt_rule_add sFilterRuleEntry; + IPAFilteringTable cFilterTable; + + memset(&sRoutingTable, 0, sizeof(sRoutingTable)); + + // Create RT table + if (!CreateBypassRoutingTable(&m_Routing, m_eIP, bypass0, IPA_CLIENT_TEST2_CONS, + m_RetHeader.hdl,&nRTTableHdl)) { + LOG_MSG_ERROR("CreateBypassRoutingTable Failed\n"); + return false; + } + 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); + return false; + } + + // Creating Filtering Rules + cFilterTable.Init(m_eIP, IPA_CLIENT_TEST_PROD, false, 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; //put here the handle corresponding to Routing Rule 1 + if (((uint8_t)-1 == cFilterTable.AddRuleToTable(sFilterRuleEntry)) || + !m_Filtering.AddFilteringRule(cFilterTable.GetFilteringTable())) + { + LOG_MSG_ERROR ("Adding Rule (0) to Filtering block Failed."); + return false; + } + else + { + LOG_MSG_DEBUG("flt rule hdl0=0x%x, status=0x%x\n", + cFilterTable.ReadRuleFromTable(0)->flt_rule_hdl, + cFilterTable.ReadRuleFromTable(0)->status); + } + return true; + } + + virtual bool ModifyPackets() { + return true; + } + + virtual bool TestLogic() { + memset(m_aExpectedBuffer, 0, sizeof(m_aExpectedBuffer)); + m_aExpectedBufSize = 0; + + memcpy(m_aExpectedBuffer, m_aHeadertoAdd, m_nHeadertoAddSize); + memcpy(m_aExpectedBuffer+m_nHeadertoAddSize,m_aBuffer,m_uBufferSize); + m_aExpectedBufSize = m_nHeadertoAddSize + m_uBufferSize; + if (!SendReceiveAndCompare(&m_producer, m_aBuffer, m_uBufferSize, + &m_Consumer1, m_aExpectedBuffer, m_aExpectedBufSize)) { + LOG_MSG_ERROR("SendReceiveAndCompare failed."); + return false; + } + return true; + } + +protected: + struct ipa_ioc_get_hdr m_RetHeader; + int m_InitialHeadersNum; + int m_HeadersNumToDelete; + int m_HeadersNumToAddAgain; + +private: + uint8_t m_aExpectedBuffer[BUFF_MAX_SIZE]; // Input file / IP packet + size_t m_aExpectedBufSize; + uint8_t m_aHeadertoAdd[MAX_HEADER_SIZE]; + size_t m_nHeadertoAddSize; + int ret; +}; + +class IPAHeaderInsertionTest007: public IPAHeaderInsertionTest006 { +public: + IPAHeaderInsertionTest007() { + m_name = "IPAHeaderInsertionTest007"; + m_description = + "Header Insertion Test 007 - Test header distriburion between SRAM and DDR\ + - fill SRAM and some DDR, free some SRAM, use DDR header"; + // We will delete half of the headers in the SRAM, + // which is quarter of the total initial headers number + m_HeadersNumToDelete = m_InitialHeadersNum / 4; + m_HeadersNumToAddAgain = 0; + } +}; + +class IPAHeaderInsertionTest008: public IPAHeaderInsertionTest006 { +public: + IPAHeaderInsertionTest008() { + m_name = "IPAHeaderInsertionTest008"; + m_description = + "Header Insertion Test 008 - Test header distriburion between SRAM and DDR\ + - fill SRAM and some DDR, free some SRAM, add few new SRAM headers, \ + use last SRAM header"; + // We will delete half of the headers in the SRAM, + // which is quarter of the total initial headers number + m_HeadersNumToDelete = m_InitialHeadersNum / 4; + // We will add again half of the number of headers we deleted + m_HeadersNumToAddAgain = m_HeadersNumToDelete / 2; + } +}; + +class IPAHeaderInsertionTest009: public IPAHeaderInsertionTest006 { +public: + IPAHeaderInsertionTest009() { + m_name = "IPAHeaderInsertionTest009"; + m_description = + "Header Insertion Test 009 - Test header distriburion between SRAM and DDR \ + - fill SRAM and some DDR, free some SRAM and DDR, \ + add new SRAM and DDR headers, \ + use last added DDR header"; + // We will delete all the headers in SRAM and half of the headers in the DDR, + // which is 3/4 of the total initial headers number + m_HeadersNumToDelete = m_InitialHeadersNum - (m_InitialHeadersNum / 4); + // We will add again one less header than deleted + m_HeadersNumToAddAgain = m_InitialHeadersNum - m_HeadersNumToDelete - 1; + } +}; + +class IPAHeaderInsertionTest010: public IPAHeaderInsertionTestFixture { +public: + IPAHeaderInsertionTest010() : + m_aExpectedBufSize(BUFF_MAX_SIZE), + m_nHeadertoAddSize1(0), + m_nHeadertoAddSize2(0) + { + m_name = "IPAHeaderInsertionTest010"; + m_description = + "Header Insertion Test 010 - Test header distriburion between SRAM and DDR\ + - fill SRAM and some DDR, use one SRAM and one DDR header"; + m_minIPAHwType = IPA_HW_v5_0; + + Register(*this); + uint8_t aIEEE802_3Header1[22] = { 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, + 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0x00, 0x46, 0xAE, 0xAF, 0xB0, + 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6 }; + uint8_t aIEEE802_3Header2[22] = { 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, + 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0x00, 0x47, 0xAE, 0xAF, 0xB0, + 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6 }; + m_nHeadertoAddSize1 = sizeof(aIEEE802_3Header1); + memcpy(m_aHeadertoAdd1, aIEEE802_3Header1, m_nHeadertoAddSize1); + m_nHeadertoAddSize2 = sizeof(aIEEE802_3Header2); + memcpy(m_aHeadertoAdd2, aIEEE802_3Header2, m_nHeadertoAddSize2); + + // The packet size is 22, therefore the bin size is 24 + // We are going to add number of headers to occupy twice the size of the SRAM buffer + m_InitialHeadersNum = GetHdrSramSize() / 24 * 2; + } + + virtual bool AddRules() { + m_eIP = IPA_IP_v4; + const char aBypass1[20] = "Bypass1"; + const char aBypass2[20] = "Bypass2"; + uint32_t nTableHdl01, nTableHdl02; + bool bRetVal = true; + IPAFilteringTable cFilterTable0; + struct ipa_flt_rule_add sFilterRuleEntry; + struct ipa_ioc_add_hdr *pHeaderDescriptor = NULL; + + LOG_MSG_STACK("Entering Function"); + + if (m_InitialHeadersNum <= 0) + { + LOG_MSG_ERROR("Initial headers number is set to 0!\n"); + bRetVal = false; + goto bail; + } + + memset(&sFilterRuleEntry, 0, sizeof(sFilterRuleEntry)); + memset(&m_RetHeader1, 0, sizeof(m_RetHeader1)); + memset(&m_RetHeader2, 0, sizeof(m_RetHeader2)); + + pHeaderDescriptor = (struct ipa_ioc_add_hdr *) calloc(1, + sizeof(struct ipa_ioc_add_hdr) + 1 * sizeof(struct ipa_hdr_add)); + if (!pHeaderDescriptor) + { + LOG_MSG_ERROR("calloc failed to allocate ipa_ioc_add_hdr"); + bRetVal = false; + goto bail; + } + + fflush(stderr); + fflush(stdout); + ret = system("cat /sys/kernel/debug/ipa/hdr"); + + // Add one header to SRAM + pHeaderDescriptor->commit = true; + pHeaderDescriptor->num_hdrs = 1; + pHeaderDescriptor->hdr[0].status = -1; // Return Parameter + pHeaderDescriptor->hdr[0].hdr_hdl = -1; //Return Value + pHeaderDescriptor->hdr[0].is_partial = false; + + memcpy(pHeaderDescriptor->hdr[0].hdr, m_aHeadertoAdd1, m_nHeadertoAddSize1); + pHeaderDescriptor->hdr[0].hdr_len = m_nHeadertoAddSize1; + strlcpy(pHeaderDescriptor->hdr[0].name, "IEEE802_3_SRAM", sizeof(pHeaderDescriptor->hdr[0].name)); + strlcpy(m_RetHeader1.name, pHeaderDescriptor->hdr[0].name, sizeof(m_RetHeader1.name)); + if (!m_HeaderInsertion.AddHeader(pHeaderDescriptor)) + { + LOG_MSG_ERROR("m_HeaderInsertion.AddHeader(pHeaderDescriptor) Failed\n"); + bRetVal = false; + goto bail; + } + + // Add bunch of headers to SRAM and DDR + for (int i = 1; i < m_InitialHeadersNum; i++) + { + LOG_MSG_DEBUG("%s::%s iter=%d\n", typeid(this).name(), __func__, i); + memcpy(pHeaderDescriptor->hdr[0].hdr, m_aHeadertoAdd2, m_nHeadertoAddSize2); + pHeaderDescriptor->hdr[0].hdr_len = m_nHeadertoAddSize2; + snprintf(pHeaderDescriptor->hdr[0].name, sizeof(pHeaderDescriptor->hdr[0].name), + "IEEE802_3_%03d", i); + if (!m_HeaderInsertion.AddHeader(pHeaderDescriptor)) + { + LOG_MSG_ERROR("m_HeaderInsertion.AddHeader(pHeaderDescriptor) Failed on %d iteration.\n", i); + bRetVal = false; + goto bail; + } + } + strlcpy(m_RetHeader2.name, pHeaderDescriptor->hdr[0].name, sizeof(m_RetHeader2.name)); + + fflush(stderr); + fflush(stdout); + ret = system("cat /sys/kernel/debug/ipa/hdr"); + + if (!m_HeaderInsertion.GetHeaderHandle(&m_RetHeader1)) + { + LOG_MSG_ERROR(" Failed"); + bRetVal = false; + goto bail; + } + LOG_MSG_DEBUG("Received Header1 Handle = 0x%x", m_RetHeader1.hdl); + + if (!m_HeaderInsertion.GetHeaderHandle(&m_RetHeader2)) + { + LOG_MSG_ERROR(" Failed"); + bRetVal = false; + goto bail; + } + LOG_MSG_DEBUG("Received Header2 Handle = 0x%x", m_RetHeader2.hdl); + + if (!CreateBypassRoutingTable(&m_Routing, m_eIP, aBypass1, IPA_CLIENT_TEST3_CONS, + m_RetHeader1.hdl, &nTableHdl01)) { + LOG_MSG_ERROR("CreateBypassRoutingTable Failed\n"); + bRetVal = false; + goto bail; + } + if (!CreateBypassRoutingTable(&m_Routing, m_eIP, aBypass2, IPA_CLIENT_TEST4_CONS, + m_RetHeader2.hdl, &nTableHdl02)) { + LOG_MSG_ERROR("CreateBypassRoutingTable Failed\n"); + bRetVal = false; + goto bail; + } + LOG_MSG_INFO("Creation of two bypass routing tables completed successfully TblHdl1=0x%x, TblHdl2=0x%x", + nTableHdl01, nTableHdl02); + + // Creating Filtering Rules + cFilterTable0.Init(m_eIP, IPA_CLIENT_TEST_PROD, false, 2); + LOG_MSG_INFO("Creation of filtering table completed successfully"); + + // Configuring common Filtering fields + cFilterTable0.GeneratePresetRule(1, sFilterRuleEntry); + sFilterRuleEntry.at_rear = true; + sFilterRuleEntry.rule.action = IPA_PASS_TO_ROUTING; + sFilterRuleEntry.rule.attrib.attrib_mask = IPA_FLT_DST_ADDR; // Destination IP Based Filtering + sFilterRuleEntry.rule.attrib.u.v4.dst_addr_mask = 0xFF0000FF; // Mask + + // Configuring Filtering Rule No.1 + sFilterRuleEntry.flt_rule_hdl = -1; // return Value + sFilterRuleEntry.status = -1; // return Value + sFilterRuleEntry.rule.rt_tbl_hdl = nTableHdl01; //put here the handle corresponding to Routing Rule 1 + sFilterRuleEntry.rule.attrib.u.v4.dst_addr = 0xC0A80101; // Filter DST_IP == 192.168.1.1. + if ((uint8_t)-1 == cFilterTable0.AddRuleToTable(sFilterRuleEntry)) + { + LOG_MSG_ERROR ("Adding Rule(1) to Filtering table Failed."); + bRetVal = false; + goto bail; + } + + // Configuring Filtering Rule No.2 + sFilterRuleEntry.flt_rule_hdl = -1; // return Value + sFilterRuleEntry.status = -1; // return value + sFilterRuleEntry.rule.rt_tbl_hdl = nTableHdl02; //put here the handle corresponding to Routing Rule 2 + sFilterRuleEntry.rule.attrib.u.v4.dst_addr = 0xC0A80102; // Filter DST_IP == 192.168.1.2. + if ((uint8_t)-1 == cFilterTable0.AddRuleToTable(sFilterRuleEntry)) + { + LOG_MSG_ERROR ("Adding Rule(2) to Filtering table Failed."); + bRetVal = false; + goto bail; + } + + if (!m_Filtering.AddFilteringRule(cFilterTable0.GetFilteringTable())) { + LOG_MSG_ERROR ("Failed to commit Filtering rules"); + bRetVal = false; + goto bail; + } + + LOG_MSG_DEBUG("flt rule hdl0=0x%x, status=0x%x\n", + cFilterTable0.ReadRuleFromTable(0)->flt_rule_hdl, + cFilterTable0.ReadRuleFromTable(0)->status); + LOG_MSG_DEBUG("flt rule hdl0=0x%x, status=0x%x\n", + cFilterTable0.ReadRuleFromTable(1)->flt_rule_hdl, + cFilterTable0.ReadRuleFromTable(1)->status); + + bail: + Free(pHeaderDescriptor); + LOG_MSG_STACK("Leaving Function (Returning %s)", bRetVal ? "True" : "False"); + return bRetVal; + } // AddRules() + + virtual bool ModifyPackets() { + // This test doesn't modify the original IP Packet. + return true; + } // ModifyPacktes () + + virtual bool TestLogic() { + bool bRetVal = true; + m_aExpectedBufSize = 0; + uint32_t nIPv4DSTAddr; + + LOG_MSG_STACK("Entering Function"); + + //Packet No. 1 + memset(m_aExpectedBuffer, 0, sizeof(m_aExpectedBuffer)); + nIPv4DSTAddr = ntohl(0xC0A80101); //192.168.1.1 + memcpy(&m_aBuffer[IPV4_DST_ADDR_OFFSET], &nIPv4DSTAddr, sizeof(nIPv4DSTAddr)); + memcpy(m_aExpectedBuffer, m_aHeadertoAdd1, m_nHeadertoAddSize1); + memcpy(m_aExpectedBuffer+m_nHeadertoAddSize1,m_aBuffer,m_uBufferSize); + m_aExpectedBufSize = m_nHeadertoAddSize1 + m_uBufferSize; + if (!SendReceiveAndCompare(&m_producer, m_aBuffer, m_uBufferSize, + &m_Consumer2, m_aExpectedBuffer, m_aExpectedBufSize)) + { + LOG_MSG_ERROR("SendReceiveAndCompare failed."); + bRetVal=false; + } + + //Packet No. 2 + memset(m_aExpectedBuffer, 0, sizeof(m_aExpectedBuffer)); + nIPv4DSTAddr = ntohl(0xC0A80102); //192.168.1.2 + memcpy (&m_aBuffer[IPV4_DST_ADDR_OFFSET], &nIPv4DSTAddr, sizeof(nIPv4DSTAddr)); + memcpy(m_aExpectedBuffer, m_aHeadertoAdd2, m_nHeadertoAddSize2); + memcpy(m_aExpectedBuffer+m_nHeadertoAddSize2, m_aBuffer, m_uBufferSize); + m_aExpectedBufSize = m_nHeadertoAddSize2 + m_uBufferSize; + if (!SendReceiveAndCompare(&m_producer, m_aBuffer, m_uBufferSize, + &m_Consumer3, m_aExpectedBuffer, m_aExpectedBufSize)) + { + LOG_MSG_ERROR("SendReceiveAndCompare failed."); + bRetVal=false; + } + + LOG_MSG_STACK("Leaving Function (Returning %s)",bRetVal?"True":"False"); + return bRetVal; + } + +protected: + struct ipa_ioc_get_hdr m_RetHeader1, m_RetHeader2; + int m_InitialHeadersNum; + +private: + uint8_t m_aExpectedBuffer[BUFF_MAX_SIZE]; // Input file / IP packet + size_t m_aExpectedBufSize; + uint8_t m_aHeadertoAdd1[MAX_HEADER_SIZE], m_aHeadertoAdd2[MAX_HEADER_SIZE]; + size_t m_nHeadertoAddSize1, m_nHeadertoAddSize2; + int ret; +}; + static IPAHeaderInsertionTest001 ipaHeaderInsertionTest001; static IPAHeaderInsertionTest002 ipaHeaderInsertionTest002; static IPAHeaderInsertionTest003 ipaHeaderInsertionTest003; static IPAHeaderInsertionTest004 ipaHeaderInsertionTest004; static IPAHeaderInsertionTest005 ipaHeaderInsertionTest005; +static IPAHeaderInsertionTest006 ipaHeaderInsertionTest006; +static IPAHeaderInsertionTest007 ipaHeaderInsertionTest007; +static IPAHeaderInsertionTest008 ipaHeaderInsertionTest008; +static IPAHeaderInsertionTest009 ipaHeaderInsertionTest009; +static IPAHeaderInsertionTest010 ipaHeaderInsertionTest010;