Harald Welte has submitted this change and it was merged. ( 
https://gerrit.osmocom.org/10305 )

Change subject: trx_toolkit/fake_trx: introduce basic path loss simulation
......................................................................

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
---
M src/target/trx_toolkit/burst_fwd.py
M src/target/trx_toolkit/ctrl_if_bb.py
M src/target/trx_toolkit/ctrl_if_bts.py
3 files changed, 123 insertions(+), 0 deletions(-)

Approvals:
  Jenkins Builder: Verified
  Harald Welte: Looks good to me, approved



diff --git a/src/target/trx_toolkit/burst_fwd.py 
b/src/target/trx_toolkit/burst_fwd.py
index bfbe0d6..3834849 100644
--- a/src/target/trx_toolkit/burst_fwd.py
+++ b/src/target/trx_toolkit/burst_fwd.py
@@ -66,6 +66,15 @@
        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 @@
                # 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 @@
                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 @@
                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)

diff --git a/src/target/trx_toolkit/ctrl_if_bb.py 
b/src/target/trx_toolkit/ctrl_if_bb.py
index 3de14ef..929caf4 100644
--- a/src/target/trx_toolkit/ctrl_if_bb.py
+++ b/src/target/trx_toolkit/ctrl_if_bb.py
@@ -150,6 +150,46 @@

                        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,
diff --git a/src/target/trx_toolkit/ctrl_if_bts.py 
b/src/target/trx_toolkit/ctrl_if_bts.py
index 1488617..72a0371 100644
--- a/src/target/trx_toolkit/ctrl_if_bts.py
+++ b/src/target/trx_toolkit/ctrl_if_bts.py
@@ -118,6 +118,46 @@

                        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,

--
To view, visit https://gerrit.osmocom.org/10305
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib210138a03e2377c79875a4ff2f2bb58a43cfa46
Gerrit-Change-Number: 10305
Gerrit-PatchSet: 1
Gerrit-Owner: Vadim Yanitskiy <[email protected]>
Gerrit-Reviewer: Harald Welte <[email protected]>
Gerrit-Reviewer: Jenkins Builder

Reply via email to