trx_toolkit/fake_trx: introduce basic path loss simulation

This change introduces a couple of new CTRL commands for path loss
simulation, in particular a possibility to drop some amount of
bursts according to some TDMA frame period, separately for both
Uplink and Downlink directions.

Examples:

  FAKE_DROP 4 - drop 4 consistent (period=1) bursts,
  FAKE_DROP 16 2 - drop 16 even bursts (period=2).

Change-Id: Ib210138a03e2377c79875a4ff2f2bb58a43cfa46
Related: OS#3428
This commit is contained in:
Vadim Yanitskiy 2018-08-02 04:06:05 +07:00
parent b914cfd488
commit a50d3fff72
3 changed files with 123 additions and 0 deletions

View File

@ -66,6 +66,15 @@ class BurstForwarder:
rssi_dl_threshold = 10
rssi_ul_threshold = 5
# Path loss simulation: DL/UL burst dropping
# Indicates how many bursts should be dropped
# and which dropping period is used. By default,
# period is 1, i.e. every burst (fn % 1 is always 0)
burst_dl_drop_amount = 0
burst_ul_drop_amount = 0
burst_dl_drop_period = 1
burst_ul_drop_period = 1
def __init__(self, bts_link, bb_link):
self.bts_link = bts_link
self.bb_link = bb_link
@ -131,6 +140,30 @@ class BurstForwarder:
# Generate a random RSSI value
return random.randint(rssi_min, rssi_max)
# DL path loss simulation
def path_loss_sim_dl(self, msg):
# Burst dropping
if self.burst_dl_drop_amount > 0:
if msg.fn % self.burst_dl_drop_period == 0:
print("[~] Simulation: dropping DL burst (fn=%u %% %u == 0)"
% (msg.fn, self.burst_dl_drop_period))
self.burst_dl_drop_amount -= 1
return None
return msg
# UL path loss simulation
def path_loss_sim_ul(self, msg):
# Burst dropping
if self.burst_ul_drop_amount > 0:
if msg.fn % self.burst_ul_drop_period == 0:
print("[~] Simulation: dropping UL burst (fn=%u %% %u == 0)"
% (msg.fn, self.burst_ul_drop_period))
self.burst_ul_drop_amount -= 1
return None
return msg
# DL burst preprocessing
def preprocess_dl_burst(self, msg):
# Calculate both RSSI and ToA values
@ -180,6 +213,11 @@ class BurstForwarder:
if msg.tn != self.ts_pass:
return None
# Path loss simulation
msg = self.path_loss_sim_dl(msg)
if msg is None:
return None
# Burst preprocessing
self.preprocess_dl_burst(msg)
@ -211,6 +249,11 @@ class BurstForwarder:
if msg is None:
return None
# Path loss simulation
msg = self.path_loss_sim_ul(msg)
if msg is None:
return None
# Burst preprocessing
self.preprocess_ul_burst(msg)

View File

@ -150,6 +150,46 @@ class CTRLInterfaceBB(CTRLInterface):
return 0
# Path loss simulation for UL: burst dropping
# Syntax: CMD FAKE_DROP <AMOUNT>
# Dropping pattern: fn % 1 == 0
elif self.verify_cmd(request, "FAKE_DROP", 1):
print("[i] Recv FAKE_DROP cmd")
# Parse / validate amount of bursts
num = int(request[1])
if num < 0:
print("[!] FAKE_DROP amount shall not be negative")
return -1
self.burst_fwd.burst_ul_drop_amount = num
self.burst_fwd.burst_ul_drop_period = 1
return 0
# Path loss simulation for UL: burst dropping
# Syntax: CMD FAKE_DROP <AMOUNT> <FN_PERIOD>
# Dropping pattern: fn % period == 0
elif self.verify_cmd(request, "FAKE_DROP", 2):
print("[i] Recv FAKE_DROP cmd")
# Parse / validate amount of bursts
num = int(request[1])
if num < 0:
print("[!] FAKE_DROP amount shall not be negative")
return -1
# Parse / validate period
period = int(request[2])
if period <= 0:
print("[!] FAKE_DROP period shall be greater than zero")
return -1
self.burst_fwd.burst_ul_drop_amount = num
self.burst_fwd.burst_ul_drop_period = period
return 0
# Wrong / unknown command
else:
# We don't care about other commands,

View File

@ -118,6 +118,46 @@ class CTRLInterfaceBTS(CTRLInterface):
return 0
# Path loss simulation for DL: burst dropping
# Syntax: CMD FAKE_DROP <AMOUNT>
# Dropping pattern: fn % 1 == 0
elif self.verify_cmd(request, "FAKE_DROP", 1):
print("[i] Recv FAKE_DROP cmd")
# Parse / validate amount of bursts
num = int(request[1])
if num < 0:
print("[!] FAKE_DROP amount shall not be negative")
return -1
self.burst_fwd.burst_dl_drop_amount = num
self.burst_fwd.burst_dl_drop_period = 1
return 0
# Path loss simulation for DL: burst dropping
# Syntax: CMD FAKE_DROP <AMOUNT> <FN_PERIOD>
# Dropping pattern: fn % period == 0
elif self.verify_cmd(request, "FAKE_DROP", 2):
print("[i] Recv FAKE_DROP cmd")
# Parse / validate amount of bursts
num = int(request[1])
if num < 0:
print("[!] FAKE_DROP amount shall not be negative")
return -1
# Parse / validate period
period = int(request[2])
if period <= 0:
print("[!] FAKE_DROP period shall be greater than zero")
return -1
self.burst_fwd.burst_dl_drop_amount = num
self.burst_fwd.burst_dl_drop_period = period
return 0
# Wrong / unknown command
else:
# We don't care about other commands,