From 5313fb99d6c065841b7464cb103146c55ec41145 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Tue, 22 Jun 2021 15:41:32 +0200 Subject: [PATCH] tft: add helper to delete all TFTs for EPS bearer when a EPS bearer is removed, all associated TFTs need to be removed as well. --- srsue/hdr/stack/upper/tft_packet_filter.h | 5 +++- srsue/src/stack/upper/tft_packet_filter.cc | 33 +++++++++++++++++++--- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/srsue/hdr/stack/upper/tft_packet_filter.h b/srsue/hdr/stack/upper/tft_packet_filter.h index 1f03f5434..04eb46584 100644 --- a/srsue/hdr/stack/upper/tft_packet_filter.h +++ b/srsue/hdr/stack/upper/tft_packet_filter.h @@ -64,7 +64,7 @@ public: bool match(const srsran::unique_byte_buffer_t& pdu); bool filter_contains(uint16_t filtertype); - uint8_t eps_bearer_id{}; + uint8_t eps_bearer_id = {}; uint8_t id = {}; uint8_t eval_precedence = {}; uint32_t active_filters = {}; @@ -106,9 +106,12 @@ public: explicit tft_pdu_matcher(srslog::basic_logger& logger) : logger(logger) {} ~tft_pdu_matcher(){}; + void reset(); + int check_tft_filter_match(const srsran::unique_byte_buffer_t& pdu, uint8_t& eps_bearer_id); int apply_traffic_flow_template(const uint8_t& erab_id, const LIBLTE_MME_TRAFFIC_FLOW_TEMPLATE_STRUCT* tft); + void delete_tft_for_eps_bearer(const uint8_t eps_bearer_id); private: srslog::basic_logger& logger; diff --git a/srsue/src/stack/upper/tft_packet_filter.cc b/srsue/src/stack/upper/tft_packet_filter.cc index eca72c8d3..d6fc6fd42 100644 --- a/srsue/src/stack/upper/tft_packet_filter.cc +++ b/srsue/src/stack/upper/tft_packet_filter.cc @@ -378,6 +378,11 @@ bool tft_packet_filter_t::match_port(const srsran::unique_byte_buffer_t& pdu) return true; } +void tft_pdu_matcher::reset() +{ + tft_filter_map.clear(); +} + /** * Checks whether the provided PDU matches any configured TFT. * If it finds a match, it updates the eps_bearer_id parameter. @@ -399,15 +404,35 @@ int tft_pdu_matcher::check_tft_filter_match(const srsran::unique_byte_buffer_t& return SRSRAN_ERROR; } -int tft_pdu_matcher::apply_traffic_flow_template(const uint8_t& erab_id, +/** + * @brief Deletes all registered TFT for a given EPS bearer ID + * + * @param eps_bearer_id The EPS bearer ID + */ +void tft_pdu_matcher::delete_tft_for_eps_bearer(const uint8_t eps_bearer_id) +{ + std::lock_guard lock(tft_mutex); + auto old_filter = std::find_if( + tft_filter_map.begin(), tft_filter_map.end(), [&](const std::pair& filter) { + return filter.second.eps_bearer_id == eps_bearer_id; + }); + if (old_filter != tft_filter_map.end()) { + logger.debug("Deleting TFT for EPS bearer %d", eps_bearer_id); + tft_filter_map.erase(old_filter); + } +} + +int tft_pdu_matcher::apply_traffic_flow_template(const uint8_t& eps_bearer_id, const LIBLTE_MME_TRAFFIC_FLOW_TEMPLATE_STRUCT* tft) { std::lock_guard lock(tft_mutex); switch (tft->tft_op_code) { case LIBLTE_MME_TFT_OPERATION_CODE_CREATE_NEW_TFT: for (int i = 0; i < tft->packet_filter_list_size; i++) { - logger.info("New packet filter for TFT"); - tft_packet_filter_t filter(erab_id, tft->packet_filter_list[i], logger); + logger.info("New TFT for eps_bearer_id=%d, eval_precedence=%d", + eps_bearer_id, + tft->packet_filter_list[i].eval_precedence); + tft_packet_filter_t filter(eps_bearer_id, tft->packet_filter_list[i], logger); auto it = tft_filter_map.insert(std::make_pair(filter.eval_precedence, filter)); if (it.second == false) { logger.error("Error inserting TFT Packet Filter"); @@ -431,7 +456,7 @@ int tft_pdu_matcher::apply_traffic_flow_template(const uint8_t& tft_filter_map.erase(old_filter); // Add new filter - tft_packet_filter_t new_filter(erab_id, tft->packet_filter_list[i], logger); + tft_packet_filter_t new_filter(eps_bearer_id, tft->packet_filter_list[i], logger); auto it = tft_filter_map.insert(std::make_pair(new_filter.eval_precedence, new_filter)); if (it.second == false) { logger.error("Error inserting TFT Packet Filter");