refactor airplane mode simulation and move to NAS

- move handling to NAS
- use switch off to enable airplane mode (don't wait for EPC response)
- add tiny FSM to control airplane mode activation/deactivation
- only start on/off counter after state has been entered
master
Andre Puschmann 5 years ago
parent 0e221f1317
commit 3f10224729

@ -57,11 +57,6 @@ typedef struct {
int usim_hex_limit; int usim_hex_limit;
} stack_log_args_t; } stack_log_args_t;
typedef struct {
int airplane_t_on_ms;
int airplane_t_off_ms;
} ue_sim_args_t;
typedef struct { typedef struct {
std::string type; std::string type;
pcap_args_t pcap; pcap_args_t pcap;
@ -72,7 +67,6 @@ typedef struct {
nas_args_t nas; nas_args_t nas;
gw_args_t gw; gw_args_t gw;
bool have_tti_time_stats; bool have_tti_time_stats;
ue_sim_args_t sim;
} stack_args_t; } stack_args_t;
class ue_stack_base class ue_stack_base

@ -141,6 +141,7 @@ private:
bool running; bool running;
srsue::stack_args_t args; srsue::stack_args_t args;
srslte::tti_point current_tti; srslte::tti_point current_tti;
// timers // timers

@ -152,6 +152,10 @@ private:
uint8_t k_nas_enc[32] = {}; uint8_t k_nas_enc[32] = {};
uint8_t k_nas_int[32] = {}; uint8_t k_nas_int[32] = {};
// Airplane mode simulation
typedef enum { DISABLED = 0, ENABLED } airplane_mode_state_t;
airplane_mode_state_t airplane_mode_state = {};
// PCAP // PCAP
srslte::nas_pcap* pcap = nullptr; srslte::nas_pcap* pcap = nullptr;
@ -209,6 +213,7 @@ private:
void send_activate_test_mode_complete(const uint8_t sec_hdr_type); void send_activate_test_mode_complete(const uint8_t sec_hdr_type);
// Other internal helpers // Other internal helpers
void handle_airplane_mode_sim();
void enter_emm_deregistered(); void enter_emm_deregistered();
// security context persistence file // security context persistence file

@ -24,6 +24,11 @@
namespace srsue { namespace srsue {
typedef struct {
int airplane_t_on_ms;
int airplane_t_off_ms;
} nas_sim_args_t;
class nas_args_t class nas_args_t
{ {
public: public:
@ -36,6 +41,7 @@ public:
bool force_imsi_attach; bool force_imsi_attach;
std::string eia; std::string eia;
std::string eea; std::string eea;
nas_sim_args_t sim;
}; };
// EMM states (3GPP 24.302 v10.0.0) // EMM states (3GPP 24.302 v10.0.0)

@ -370,11 +370,11 @@ static int parse_args(all_args_t* args, int argc, char* argv[])
// UE simulation args // UE simulation args
("sim.airplane_t_on_ms", ("sim.airplane_t_on_ms",
bpo::value<int>(&args->stack.sim.airplane_t_on_ms)->default_value(-1), bpo::value<int>(&args->stack.nas.sim.airplane_t_on_ms)->default_value(-1),
"On-time for airplane mode (in ms)") "On-time for airplane mode (in ms)")
("sim.airplane_t_off_ms", ("sim.airplane_t_off_ms",
bpo::value<int>(&args->stack.sim.airplane_t_off_ms)->default_value(-1), bpo::value<int>(&args->stack.nas.sim.airplane_t_off_ms)->default_value(-1),
"Off-time for airplane mode (in ms)") "Off-time for airplane mode (in ms)")
/* general options */ /* general options */

@ -176,14 +176,6 @@ bool ue_stack_lte::switch_on()
if (running) { if (running) {
pending_tasks.try_push(ue_queue_id, pending_tasks.try_push(ue_queue_id,
[this]() { nas.start_attach_request(nullptr, srslte::establishment_cause_t::mo_sig); }); [this]() { nas.start_attach_request(nullptr, srslte::establishment_cause_t::mo_sig); });
// schedule airplane mode on command
if (args.sim.airplane_t_on_ms > 0) {
timers.defer_callback(args.sim.airplane_t_on_ms, [&]() {
// Enable air-plane mode
disable_data();
});
}
return true; return true;
} }
return false; return false;
@ -221,16 +213,7 @@ bool ue_stack_lte::disable_data()
{ {
// generate detach request // generate detach request
stack_log->console("Turning on airplane mode.\n"); stack_log->console("Turning on airplane mode.\n");
int ret = nas.detach_request(false); return nas.detach_request(false);
// schedule airplane mode off command
if (args.sim.airplane_t_off_ms > 0) {
timers.defer_callback(args.sim.airplane_t_off_ms, [&]() {
// Disable airplane mode again
enable_data();
});
}
return ret;
} }
bool ue_stack_lte::get_metrics(stack_metrics_t* metrics) bool ue_stack_lte::get_metrics(stack_metrics_t* metrics)

@ -302,6 +302,8 @@ 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); }); 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); }); reattach_timer.set(reattach_timer_duration_ms, [this](uint32_t tid) { timer_expired(tid); });
handle_airplane_mode_sim();
running = true; running = true;
} }
@ -2323,6 +2325,40 @@ void nas::send_activate_test_mode_complete(const uint8_t sec_hdr_type)
ctxt.tx_count++; 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_handler->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_handler->defer_callback(cfg.sim.airplane_t_off_ms, [&]() {
// Disabling airplane mode again
start_attach_request(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_handler->defer_callback(1000, [&]() { handle_airplane_mode_sim(); });
}
}
/******************************************************************************* /*******************************************************************************
* Security context persistence file * Security context persistence file
******************************************************************************/ ******************************************************************************/

Loading…
Cancel
Save