nas: fix airplane mode simulation

the current implementation was somehow broken after a
NAS refactor. It was undetected because we didn't really
use it.

this fixes the simulation by using a single timer to simulate
airplane mode transitions.
the timer is rearmed in the timer_expire() function
if the correspondig event is set.

Has been tested to work well with, e.g.:

--sim.airplane_t_on_ms 5000 --sim.airplane_t_off_ms 10000
master
Andre Puschmann 4 years ago
parent f927ccaf55
commit 082e002b67

@ -163,6 +163,7 @@ private:
// Airplane mode simulation
typedef enum { DISABLED = 0, ENABLED } airplane_mode_state_t;
airplane_mode_state_t airplane_mode_state = {};
srslte::timer_handler::unique_timer airplane_mode_sim_timer;
// PCAP
srslte::nas_pcap* pcap = nullptr;
@ -226,7 +227,6 @@ private:
// Other internal helpers
void enter_state(emm_state_t state_);
void handle_airplane_mode_sim();
void enter_emm_deregistered();
// security context persistence file

@ -245,6 +245,7 @@ nas::nas(srslte::task_sched_handle task_sched_) :
t3411(task_sched_.get_unique_timer()),
t3421(task_sched_.get_unique_timer()),
reattach_timer(task_sched_.get_unique_timer()),
airplane_mode_sim_timer(task_sched_.get_unique_timer()),
nas_log{"NAS"}
{}
@ -302,7 +303,10 @@ void nas::init(usim_interface_nas* usim_, rrc_interface_nas* rrc_, gw_interface_
t3421.set(t3421_duration_ms, [this](uint32_t tid) { timer_expired(tid); });
reattach_timer.set(reattach_timer_duration_ms, [this](uint32_t tid) { timer_expired(tid); });
handle_airplane_mode_sim();
if (cfg.sim.airplane_t_on_ms > 0) {
airplane_mode_sim_timer.set(cfg.sim.airplane_t_on_ms, [this](uint32_t tid) { timer_expired(tid); });
airplane_mode_sim_timer.run();
}
running = true;
}
@ -372,6 +376,26 @@ void nas::timer_expired(uint32_t timeout_id)
} else if (timeout_id == reattach_timer.id()) {
nas_log->info("Reattach timer expired: trying to attach again\n");
start_attach_proc(nullptr, srslte::establishment_cause_t::mo_sig);
} else if (timeout_id == airplane_mode_sim_timer.id()) {
if (airplane_mode_state == DISABLED) {
// Enabling air-plane mode
send_detach_request(true);
airplane_mode_state = ENABLED;
if (cfg.sim.airplane_t_on_ms > 0) {
airplane_mode_sim_timer.set(cfg.sim.airplane_t_on_ms, [this](uint32_t tid) { timer_expired(tid); });
airplane_mode_sim_timer.run();
}
} else if (airplane_mode_state == ENABLED) {
// Disabling airplane mode again
start_attach_proc(nullptr, srslte::establishment_cause_t::mo_sig);
airplane_mode_state = DISABLED;
if (cfg.sim.airplane_t_off_ms > 0) {
airplane_mode_sim_timer.set(cfg.sim.airplane_t_off_ms, [this](uint32_t tid) { timer_expired(tid); });
airplane_mode_sim_timer.run();
}
}
} else {
nas_log->error("Timeout from unknown timer id %d\n", timeout_id);
}
@ -2488,40 +2512,6 @@ void nas::send_close_ue_test_loop_complete()
ctxt.tx_count++;
}
/*
* Handles the airplane mode simulation by triggering a UE switch off/on
* in user-definable time intervals
*/
void nas::handle_airplane_mode_sim()
{
if (cfg.sim.airplane_t_on_ms > 0 && airplane_mode_state == DISABLED) {
// check if we're already attached, if so, schedule airplane mode command
if (state == EMM_STATE_REGISTERED) {
// NAS is attached
task_sched.defer_callback(cfg.sim.airplane_t_on_ms, [&]() {
// Enabling air-plane mode
send_detach_request(true);
airplane_mode_state = ENABLED;
});
}
} else if (cfg.sim.airplane_t_off_ms > 0 && airplane_mode_state == ENABLED) {
// check if we are already deregistered, if so, schedule command to turn off airplone mode again
if (state == EMM_STATE_DEREGISTERED) {
// NAS is deregistered
task_sched.defer_callback(cfg.sim.airplane_t_off_ms, [&]() {
// Disabling airplane mode again
start_attach_proc(nullptr, srslte::establishment_cause_t::mo_sig);
airplane_mode_state = DISABLED;
});
}
}
// schedule another call
if (cfg.sim.airplane_t_on_ms > 0 || cfg.sim.airplane_t_off_ms > 0) {
task_sched.defer_callback(1000, [&]() { handle_airplane_mode_sim(); });
}
}
/*******************************************************************************
* Security context persistence file
******************************************************************************/

Loading…
Cancel
Save