Commit de37a02e authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen

Merge branch 'mobile_reachable_timer' into 'develop'

Mobile reachable timer

See merge request oai/cn5g/oai-cn5g-amf!71
parents 133c9190 d2dcc246
......@@ -55,6 +55,7 @@ static uint32_t amf_app_ue_ngap_id_generator = 1;
namespace amf_application {
#define TASK_AMF_APP_PERIODIC_STATISTICS (0)
#define TASK_AMF_MOBILE_REACHABLE_TIMER_EXPIRE (1)
class amf_app {
private:
......
......@@ -63,6 +63,7 @@
#include "nas_algorithms.hpp"
#include "sha256.hpp"
#include "comUt.hpp"
#include "3gpp_24.501.h"
extern "C" {
#include "bstrlib.h"
......@@ -111,6 +112,21 @@ void amf_n1_task(void*) {
dynamic_cast<itti_downlink_nas_transfer*>(msg);
amf_n1_inst->handle_itti_message(ref(*m));
} break;
case TIME_OUT: {
if (itti_msg_timeout* to = dynamic_cast<itti_msg_timeout*>(msg)) {
switch (to->arg1_user) {
case TASK_AMF_MOBILE_REACHABLE_TIMER_EXPIRE:
amf_n1_inst->mobile_reachable_timer_timeout(
to->timer_id, to->arg2_user);
break;
default:
Logger::amf_n1().info(
"No handler for timer(%d) with arg1_user(%d) ", to->timer_id,
to->arg1_user);
}
}
} break;
case TERMINATE: {
if (itti_msg_terminate* terminate =
dynamic_cast<itti_msg_terminate*>(msg)) {
......@@ -473,6 +489,8 @@ void amf_n1::nas_signalling_establishment_request_handle(
nc.get()->amf_ue_ngap_id = amf_ue_ngap_id;
nc.get()->ran_ue_ngap_id = ran_ue_ngap_id;
nc.get()->serving_network = snn;
// stop Mobile Reachable Timer
itti_inst->timer_remove(nc.get()->mobile_reachable_timer);
// stacs.UE_connected += 1;
// Trigger UE Reachability Status Notify
......@@ -659,6 +677,8 @@ void amf_n1::identity_response_handle(
nc.get()->imsi = supi;
supi2amfId[("imsi-" + nc.get()->imsi)] = amf_ue_ngap_id;
supi2ranId[("imsi-" + nc.get()->imsi)] = ran_ue_ngap_id;
// stop Mobile Reachable Timer
itti_inst->timer_remove(nc.get()->mobile_reachable_timer);
if (nc.get()->to_be_register_by_new_suci) {
run_registration_procedure(nc);
}
......@@ -912,6 +932,8 @@ void amf_n1::registration_request_handle(
nc.get()->amf_ue_ngap_id = amf_ue_ngap_id;
nc.get()->ran_ue_ngap_id = ran_ue_ngap_id;
nc.get()->serving_network = snn;
// stop Mobile Reachable Timer
itti_inst->timer_remove(nc.get()->mobile_reachable_timer);
}
nc.get()->is_imsi_present = true;
nc.get()->imsi = imsi.mcc + imsi.mnc + imsi.msin;
......@@ -997,6 +1019,8 @@ void amf_n1::registration_request_handle(
// nc.get()->imsi =
// supi2amfId[("imsi-"+nc.get()->imsi)] = amf_ue_ngap_id;
// supi2ranId[("imsi-"+nc.get()->imsi)] = ran_ue_ngap_id;
// stop Mobile Reachable Timer
itti_inst->timer_remove(nc.get()->mobile_reachable_timer);
}
} break;
......@@ -2166,7 +2190,7 @@ void amf_n1::security_mode_complete_handle(
// TODO: remove hardcoded values
regAccept->set_5GS_Network_Feature_Support(0x01, 0x00);
regAccept->setT3512_Value(0x5, 0x1e);
regAccept->setT3512_Value(0x5, T3512_TIMER_VALUE_MIN);
uint8_t buffer[BUFFER_SIZE_1024] = {0};
int encoded_size = regAccept->encode2buffer(buffer, BUFFER_SIZE_1024);
comUt::print_buffer(
......@@ -2997,6 +3021,20 @@ void amf_n1::get_5gmm_state(
state = nc.get()->_5gmm_state;
}
//------------------------------------------------------------------------------
void amf_n1::set_5gcm_state(
std::shared_ptr<nas_context>& nc, const cm_state_t& state) {
std::shared_lock lock(m_nas_context);
nc.get()->nas_status = state;
}
//------------------------------------------------------------------------------
void amf_n1::get_5gcm_state(
const std::shared_ptr<nas_context>& nc, cm_state_t& state) const {
std::shared_lock lock(m_nas_context);
state = nc.get()->nas_status;
}
//------------------------------------------------------------------------------
void amf_n1::handle_ue_reachability_status_change(
std::string supi, uint8_t http_version) {
......@@ -3072,8 +3110,8 @@ void amf_n1::initialize_registration_accept(
std::unique_ptr<nas::RegistrationAccept>& registration_accept) {
registration_accept->setHeader(PLAIN_5GS_MSG);
registration_accept->set_5GS_Registration_Result(
false, false, false, 0x01); // 3GPP Access
registration_accept->setT3512_Value(0x5, 0x1e); // TODO
false, false, false, 0x01); // 3GPP Access
registration_accept->setT3512_Value(0x5, T3512_TIMER_VALUE_MIN);
std::vector<p_tai_t> tai_list;
for (auto p : amf_cfg.plmn_list) {
......@@ -3153,3 +3191,45 @@ bool amf_n1::find_ue_context(
return true;
}
//------------------------------------------------------------------------------
void amf_n1::mobile_reachable_timer_timeout(
timer_id_t timer_id, uint64_t amf_ue_ngap_id) {
std::shared_ptr<nas_context> nc;
if (amf_n1_inst->is_amf_ue_id_2_nas_context(amf_ue_ngap_id))
nc = amf_n1_inst->amf_ue_id_2_nas_context(amf_ue_ngap_id);
else {
Logger::amf_n2().warn(
"No existed nas_context with amf_ue_ngap_id(0x%x)", amf_ue_ngap_id);
}
set_mobile_reachable_timer_timeout(nc, true);
// TODO: Start the implicit de-registration timer
}
//------------------------------------------------------------------------------
void amf_n1::set_mobile_reachable_timer(
std::shared_ptr<nas_context>& nc, const timer_id_t& t) {
std::unique_lock lock(m_nas_context);
nc.get()->mobile_reachable_timer = t;
}
//------------------------------------------------------------------------------
void amf_n1::set_mobile_reachable_timer_timeout(
std::shared_ptr<nas_context>& nc, const bool& b) {
std::unique_lock lock(m_nas_context);
nc.get()->is_mobile_reachable_timer_timeout = b;
}
//------------------------------------------------------------------------------
void amf_n1::get_mobile_reachable_timer_timeout(
const std::shared_ptr<nas_context>& nc, bool& b) const {
std::shared_lock lock(m_nas_context);
b = nc.get()->is_mobile_reachable_timer_timeout;
}
//------------------------------------------------------------------------------
bool amf_n1::get_mobile_reachable_timer_timeout(
const std::shared_ptr<nas_context>& nc) const {
std::shared_lock lock(m_nas_context);
return nc.get()->is_mobile_reachable_timer_timeout;
}
......@@ -47,6 +47,7 @@
#include "amf_event.hpp"
#include "RegistrationAccept.hpp"
#include "ue_context.hpp"
#include "itti.hpp"
namespace amf_application {
......@@ -162,6 +163,11 @@ class amf_n1 {
void set_5gmm_state(std::shared_ptr<nas_context> nc, _5gmm_state_t state);
void get_5gmm_state(std::shared_ptr<nas_context> nc, _5gmm_state_t& state);
void set_5gcm_state(
std::shared_ptr<nas_context>& nc, const cm_state_t& state);
void get_5gcm_state(
const std::shared_ptr<nas_context>& nc, cm_state_t& state) const;
void handle_ue_reachability_status_change(
std::string supi, uint8_t http_version);
......@@ -178,6 +184,17 @@ class amf_n1 {
uint32_t ran_ue_ngap_id, long amf_ue_ngap_id,
std::shared_ptr<ue_context>& uc);
void mobile_reachable_timer_timeout(
timer_id_t timer_id, uint64_t amf_ue_ngap_id);
void set_mobile_reachable_timer_timeout(
std::shared_ptr<nas_context>& nc, const bool& b);
void get_mobile_reachable_timer_timeout(
const std::shared_ptr<nas_context>& nc, bool& b) const;
bool get_mobile_reachable_timer_timeout(
const std::shared_ptr<nas_context>& nc) const;
void set_mobile_reachable_timer(
std::shared_ptr<nas_context>& nc, const timer_id_t& t);
private:
void ue_initiate_de_registration_handle(
uint32_t ran_ue_ngap_id, long amf_ue_ngap_id, bstring nas);
......
......@@ -53,6 +53,7 @@
#include "itti_msg_amf_app.hpp"
#include "logger.hpp"
#include "sctp_server.hpp"
#include "3gpp_24.501.h"
#include <boost/chrono.hpp>
#include <boost/chrono/chrono.hpp>
......@@ -261,6 +262,21 @@ void amf_n2::handle_itti_message(itti_paging& itti_msg) {
// TODO: check UE reachability status
// get NAS context
std::shared_ptr<nas_context> nc = {};
if (amf_n1_inst->is_amf_ue_id_2_nas_context(itti_msg.amf_ue_ngap_id))
nc = amf_n1_inst->amf_ue_id_2_nas_context(itti_msg.amf_ue_ngap_id);
else {
Logger::amf_n2().warn(
"No existed nas_context with amf_ue_ngap_id(0x%x)",
itti_msg.amf_ue_ngap_id);
}
// Network stops sending paging messages since the mobile reachable timer
// expires
if (amf_n1_inst->get_mobile_reachable_timer_timeout(nc)) {
return;
}
PagingMsg paging_msg = {};
paging_msg.setMessageType();
Logger::amf_n2().debug(
......@@ -1265,6 +1281,25 @@ void amf_n2::handle_itti_message(itti_ue_context_release_complete& itti_msg) {
Logger::amf_n2().debug("Handle UE Context Release Complete ...");
unsigned long amf_ue_ngap_id = itti_msg.ueCtxRelCmpl->getAmfUeNgapId();
uint32_t ran_ue_ngap_id = itti_msg.ueCtxRelCmpl->getRanUeNgapId();
// Change UE status from CM-CONNECTED to CM-IDLE
std::shared_ptr<nas_context> nc;
if (amf_n1_inst->is_amf_ue_id_2_nas_context(amf_ue_ngap_id))
nc = amf_n1_inst->amf_ue_id_2_nas_context(amf_ue_ngap_id);
else {
Logger::amf_n2().warn(
"No existed nas_context with amf_ue_ngap_id(0x%x)", amf_ue_ngap_id);
}
amf_n1_inst->set_5gcm_state(nc, CM_IDLE);
// Start/reset the Mobile Reachable Timer
timer_id_t tid = itti_inst->timer_setup(
MOBILE_REACHABLE_TIMER_NO_EMERGENCY_SERVICES_MIN * 60, 0, TASK_AMF_N1,
TASK_AMF_MOBILE_REACHABLE_TIMER_EXPIRE, amf_ue_ngap_id);
Logger::amf_app().startup("Started mobile reachable timer ( tid %d)", tid);
amf_n1_inst->set_mobile_reachable_timer(nc, tid);
amf_n1_inst->set_mobile_reachable_timer_timeout(nc, false);
// TODO: User Location Information IE
// TODO: Information on Recommended Cells & RAN Nodes for Paging IE
......
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the
* License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
#ifndef FILE_3GPP_24_501_SEEN
#define FILE_3GPP_24_501_SEEN
// Table 10.3.1 @3GPP TS 24.501 V16.1.0 (2019-06)
#define T3512_TIMER_VALUE_SEC 3240 // 54 minutes
#define T3512_TIMER_VALUE_MIN 54 // 54 minutes
#define MOBILE_REACHABLE_TIMER_NO_EMERGENCY_SERVICES_MIN \
(T3512_TIMER_VALUE_MIN + 4) // T3512 + 4, not for emergency services
#endif
......@@ -64,7 +64,9 @@ nas_context::nas_context() : _vector(), _5g_he_av(), _5g_av(), kamf() {
is_auth_vectors_present = false;
to_be_register_by_new_suci = false;
ueSecurityCaplen = 0;
nas_status = {};
nas_status = CM_IDLE;
is_mobile_reachable_timer_timeout = false;
mobile_reachable_timer = ITTI_INVALID_TIMER_ID;
}
//------------------------------------------------------------------------------
......
......@@ -37,6 +37,7 @@
#include "nas_security_context.hpp"
#include "security_def.hpp"
#include "struct.hpp"
#include "itti.hpp"
typedef enum {
_5GMM_STATE_MIN = 0,
......@@ -71,6 +72,8 @@ class nas_context {
uint32_t ran_ue_ngap_id;
cm_state_t nas_status;
_5gmm_state_t _5gmm_state;
bool is_mobile_reachable_timer_timeout;
timer_id_t mobile_reachable_timer;
// parameters from Registration request
uint8_t registration_type : 3;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment