Review at  https://gerrit.osmocom.org/6723

fake_trx: implement power measurement emulation

This change introduces a new class named FakePM, which is intended
to generate pseudo-random power levels for base stations and noise
levels inactive frequencies.

Also, there is a new command in BB CTRL, which instructs transceiver
to perform a power measurement on requested frequency. As we work in
virtual Um-interface, a FakePM instance is used to provide some fake
power levels.

Change-Id: If48c12fd0b1ba10e1cf76559b359e17a1256617d
---
M src/target/fake_trx/ctrl_if_bb.py
M src/target/fake_trx/ctrl_if_bts.py
A src/target/fake_trx/fake_pm.py
M src/target/fake_trx/fake_trx.py
4 files changed, 88 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/23/6723/1

diff --git a/src/target/fake_trx/ctrl_if_bb.py 
b/src/target/fake_trx/ctrl_if_bb.py
index 32b82d3..f840c09 100644
--- a/src/target/fake_trx/ctrl_if_bb.py
+++ b/src/target/fake_trx/ctrl_if_bb.py
@@ -29,6 +29,7 @@
        trx_started = False
        rx_freq = None
        tx_freq = None
+       pm = None
 
        def __init__(self, remote_addr, remote_port, bind_port):
                print("[i] Init CTRL interface for BB")
@@ -79,6 +80,19 @@
                        self.tx_freq = int(request[1]) * 1000
                        return 0
 
+               # Power measurement
+               elif self.verify_cmd(request, "MEASURE", 1):
+                       print("[i] Recv MEASURE cmd")
+
+                       if self.pm is None:
+                               return -1
+
+                       # TODO: check freq range
+                       meas_freq = int(request[1]) * 1000
+                       meas_dbm = str(self.pm.measure(meas_freq))
+
+                       return (0, [meas_dbm])
+
                # Wrong / unknown command
                else:
                        # We don't care about other commands,
diff --git a/src/target/fake_trx/ctrl_if_bts.py 
b/src/target/fake_trx/ctrl_if_bts.py
index d184f2e..a6b03cf 100644
--- a/src/target/fake_trx/ctrl_if_bts.py
+++ b/src/target/fake_trx/ctrl_if_bts.py
@@ -29,6 +29,7 @@
        trx_started = False
        rx_freq = None
        tx_freq = None
+       pm = None
 
        def __init__(self, remote_addr, remote_port, bind_port):
                print("[i] Init CTRL interface for BTS")
@@ -55,6 +56,11 @@
 
                        print("[i] Starting transceiver...")
                        self.trx_started = True
+
+                       # Power emulation
+                       if self.pm is not None:
+                               self.pm.add_bts_list([self.tx_freq])
+
                        return 0
 
                elif self.verify_cmd(request, "POWEROFF", 0):
@@ -62,6 +68,11 @@
 
                        print("[i] Stopping transceiver...")
                        self.trx_started = False
+
+                       # Power emulation
+                       if self.pm is not None:
+                               self.pm.del_bts_list([self.tx_freq])
+
                        return 0
 
                # Tuning Control
diff --git a/src/target/fake_trx/fake_pm.py b/src/target/fake_trx/fake_pm.py
new file mode 100644
index 0000000..1d76916
--- /dev/null
+++ b/src/target/fake_trx/fake_pm.py
@@ -0,0 +1,53 @@
+#!/usr/bin/env python2
+# -*- coding: utf-8 -*-
+
+# Virtual Um-interface (fake transceiver)
+# Power measurement emulation for BB
+#
+# (C) 2017 by Vadim Yanitskiy <axilira...@gmail.com>
+#
+# All Rights Reserved
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+from random import randint
+
+class FakePM:
+       # Freq. list for good power level
+       bts_list = []
+
+       def __init__(self, noise_min, noise_max, bts_min, bts_max):
+               # Save power level ranges
+               self.noise_min = noise_min
+               self.noise_max = noise_max
+               self.bts_min = bts_min
+               self.bts_max = bts_max
+
+       def measure(self, bts):
+               if bts in self.bts_list:
+                       return randint(self.bts_min, self.bts_max)
+               else:
+                       return randint(self.noise_min, self.noise_max)
+
+       def update_bts_list(self, new_list):
+               self.bts_list = new_list
+
+       def add_bts_list(self, add_list):
+               self.bts_list += add_list
+
+       def del_bts_list(self, del_list):
+               for item in del_list:
+                       if item in self.bts_list:
+                               self.bts_list.remove(item)
diff --git a/src/target/fake_trx/fake_trx.py b/src/target/fake_trx/fake_trx.py
index c30382b..724a520 100755
--- a/src/target/fake_trx/fake_trx.py
+++ b/src/target/fake_trx/fake_trx.py
@@ -30,6 +30,7 @@
 from ctrl_if_bts import CTRLInterfaceBTS
 from ctrl_if_bb import CTRLInterfaceBB
 from burst_fwd import BurstForwarder
+from fake_pm import FakePM
 
 from udp_link import UDPLink
 from clck_gen import CLCKGen
@@ -64,6 +65,15 @@
                self.bb_ctrl = CTRLInterfaceBB(self.bb_addr,
                        self.bb_base_port + 101, self.bb_base_port + 1)
 
+               # Power measurement emulation
+               # Noise: -120 .. -105
+               # BTS: -75 .. -50
+               self.pm = FakePM(-120, -105, -75, -50)
+
+               # Share a FakePM instance between both BTS and BB
+               self.bts_ctrl.pm = self.pm
+               self.bb_ctrl.pm = self.pm
+
                # BTS <-> BB burst forwarding
                self.bts_data = UDPLink(self.bts_addr,
                        self.bts_base_port + 102, self.bts_base_port + 2)

-- 
To view, visit https://gerrit.osmocom.org/6723
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If48c12fd0b1ba10e1cf76559b359e17a1256617d
Gerrit-PatchSet: 1
Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Owner: Harald Welte <lafo...@gnumonks.org>

Reply via email to