diff --git a/srsue/hdr/stack/upper/tft_packet_filter.h b/srsue/hdr/stack/upper/tft_packet_filter.h index 41822c32d..385d67213 100644 --- a/srsue/hdr/stack/upper/tft_packet_filter.h +++ b/srsue/hdr/stack/upper/tft_packet_filter.h @@ -73,7 +73,7 @@ struct tft_packet_filter_t { uint32_t type_of_service; uint32_t flow_label; - tft_packet_filter_t(const LIBLTE_MME_PACKET_FILTER_STRUCT* tft); + tft_packet_filter_t(const LIBLTE_MME_PACKET_FILTER_STRUCT& tft); }; diff --git a/srsue/src/stack/upper/CMakeLists.txt b/srsue/src/stack/upper/CMakeLists.txt index ef7e8e190..30a9c3e7c 100644 --- a/srsue/src/stack/upper/CMakeLists.txt +++ b/srsue/src/stack/upper/CMakeLists.txt @@ -18,7 +18,7 @@ # and at http://www.gnu.org/licenses/. # -set(SOURCES gw.cc nas.cc usim_base.cc usim.cc) +set(SOURCES gw.cc nas.cc usim_base.cc usim.cc tft_packet_filter.cc) if(HAVE_PCSC) list(APPEND SOURCES "pcsc_usim.cc") @@ -30,4 +30,4 @@ if(HAVE_PCSC) target_link_libraries(srsue_upper ${PCSCLITE_LIBRARY}) endif(HAVE_PCSC) -install(TARGETS srsue_upper DESTINATION ${LIBRARY_DIR}) \ No newline at end of file +install(TARGETS srsue_upper DESTINATION ${LIBRARY_DIR}) diff --git a/srsue/src/stack/upper/tft_packet_filter.cc b/srsue/src/stack/upper/tft_packet_filter.cc index ed41b1172..1f7ce3148 100644 --- a/srsue/src/stack/upper/tft_packet_filter.cc +++ b/srsue/src/stack/upper/tft_packet_filter.cc @@ -23,27 +23,27 @@ namespace srsue { -tft_packet_filter_t::tft_packet_filter_t(const LIBLTE_MME_PACKET_FILTER_STRUCT* tft) : - id(tft->id), - eval_precedence(tft->eval_precedence), +tft_packet_filter_t::tft_packet_filter_t(const LIBLTE_MME_PACKET_FILTER_STRUCT& tft) : + id(tft.id), + eval_precedence(tft.eval_precedence), active_filters(0) { int idx = 0; - while (idx < tft->filter_size) { - switch (tft->filter[idx] & 0x0F) { + while (idx < tft.filter_size) { + switch (tft.filter[idx] & 0x0F) { case IPV4_REMOTE_ADDR_TYPE: active_filters = IPV4_REMOTE_ADDR_FLAG; - memcpy(&ipv4_remote_addr, &tft->filter[idx], 4); + memcpy(&ipv4_remote_addr, &tft.filter[idx], 4); idx += 4; break; case IPV4_LOCAL_ADDR_TYPE: active_filters = IPV4_LOCAL_ADDR_FLAG; - memcpy(&ipv4_local_addr, &tft->filter[idx], 4); + memcpy(&ipv4_local_addr, &tft.filter[idx], 4); idx += 4; break; case IPV6_REMOTE_ADDR_TYPE: active_filters = IPV6_REMOTE_ADDR_FLAG; - memcpy(&ipv4_local_addr, &tft->filter[idx], 16); + memcpy(&ipv4_local_addr, &tft.filter[idx], 16); idx += 16; break; case IPV6_REMOTE_ADDR_LENGTH_TYPE: @@ -54,7 +54,7 @@ tft_packet_filter_t::tft_packet_filter_t(const LIBLTE_MME_PACKET_FILTER_STRUCT* break; case SINGLE_LOCAL_PORT_TYPE: active_filters = SINGLE_LOCAL_PORT_FLAG; - memcpy(&single_local_port, &tft->filter[idx], 2); + memcpy(&single_local_port, &tft.filter[idx], 2); idx += 2; break; case LOCAL_PORT_RANGE_TYPE: @@ -75,6 +75,4 @@ tft_packet_filter_t::tft_packet_filter_t(const LIBLTE_MME_PACKET_FILTER_STRUCT* } } -tft_packet_filter_t::~tft_packet_filter_t() {} - } // namespace srsue diff --git a/srsue/test/upper/CMakeLists.txt b/srsue/test/upper/CMakeLists.txt index 9c169622c..7d10af05a 100644 --- a/srsue/test/upper/CMakeLists.txt +++ b/srsue/test/upper/CMakeLists.txt @@ -35,6 +35,10 @@ add_executable(nas_test nas_test.cc) target_link_libraries(nas_test srsue_upper srslte_upper srslte_phy rrc_asn1) add_test(nas_test nas_test) +add_executable(tft_test tft_test.cc) +target_link_libraries(tft_test srsue_upper srslte_upper srslte_phy) +add_test(tft_test tft_test) + ######################################################################## # Option to run command after build (useful for remote builds) ######################################################################## diff --git a/srsue/test/upper/tft_test.cc b/srsue/test/upper/tft_test.cc new file mode 100644 index 000000000..761c0e08d --- /dev/null +++ b/srsue/test/upper/tft_test.cc @@ -0,0 +1,87 @@ +/* + * Copyright 2013-2019 Software Radio Systems Limited + * + * This file is part of srsLTE. + * + * srsLTE is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * srsLTE is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * A copy of the GNU Affero General Public License can be found in + * the LICENSE file in the top-level directory of this distribution + * and at http://www.gnu.org/licenses/. + * + */ + +#include "srslte/asn1/liblte_mme.h" +#include "srslte/common/log_filter.h" +#include "srsue/hdr/stack/upper/tft_packet_filter.h" +#include +#include +#include +#include +#include + +#define TESTASSERT(cond) \ + { \ + if (!(cond)) { \ + std::cout << "[" << __FUNCTION__ << "][Line " << __LINE__ << "]: FAIL at " << (#cond) << std::endl; \ + return -1; \ + } \ + } +using namespace srsue; +using namespace srslte; + +int tft_filter_test() +{ + srslte::log_filter log1("NAS"); + log1.set_level(srslte::LOG_LEVEL_DEBUG); + log1.set_hex_limit(128); + + srslte::byte_buffer_pool *pool = srslte::byte_buffer_pool::get_instance(); + srslte::unique_byte_buffer_t tst_msg, out_msg; + tst_msg = allocate_unique_buffer(*pool); + out_msg = allocate_unique_buffer(*pool); + + LIBLTE_MME_ACTIVATE_DEDICATED_EPS_BEARER_CONTEXT_REQUEST_MSG_STRUCT ded_bearer_req; + + LIBLTE_ERROR_ENUM err; + uint8_t nas_message[] = {0x27, 0x35, 0x11, 0xfd, 0xf6, 0x07, 0x62, 0x00, 0xc5, 0x05, 0x01, 0x01, 0x07, 0x21, + 0x31, 0x00, 0x03, 0x40, 0x08, 0xae, 0x5d, 0x02, 0x00, 0xc2, 0x81, 0x34, 0x01, 0x4d}; + uint32_t nas_message_len = sizeof(nas_message); + + // Unpack Activate Dedicated EPS bearer context setup request + tst_msg->N_bytes = nas_message_len; + memcpy(tst_msg->msg, nas_message, nas_message_len); + log1.info_hex(tst_msg->msg, tst_msg->N_bytes, "NAS Activate Dedicated EPS Bearer Context Request original message\n"); + + // Traffic flow template + TESTASSERT(ded_bearer_req.tft.tft_op_code == LIBLTE_MME_TFT_OPERATION_CODE_CREATE_NEW_TFT); + TESTASSERT(ded_bearer_req.tft.parameter_list_size == 0); + TESTASSERT(ded_bearer_req.tft.packet_filter_list_size == 1); + TESTASSERT(ded_bearer_req.tft.packet_filter_list[0].dir == LIBLTE_MME_TFT_PACKET_FILTER_DIRECTION_BIDIRECTIONAL); + TESTASSERT(ded_bearer_req.tft.packet_filter_list[0].id == 1); // FIXME Should this be 2? + TESTASSERT(ded_bearer_req.tft.packet_filter_list[0].eval_precedence == 0); + TESTASSERT(ded_bearer_req.tft.packet_filter_list[0].filter_size == 3); + TESTASSERT(ded_bearer_req.tft.packet_filter_list[0].filter[0] == + LIBLTE_MME_TFT_PACKET_FILTER_COMPONENT_TYPE_ID_SINGLE_LOCAL_PORT_TYPE); + + srsue::tft_packet_filter_t filter(ded_bearer_req.tft.packet_filter_list[0]); + + printf("Test NAS Activate Dedicated EPS Bearer Context Request successfull\n"); + return 0; +} + +int main(int argc, char **argv) +{ + if (tft_filter_test()) { + return -1; + } + srslte::byte_buffer_pool::cleanup(); +}