summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVadim Yanitskiy <axilirator@gmail.com>2019-01-14 08:15:17 +0700
committerVadim Yanitskiy <axilirator@gmail.com>2019-01-14 23:52:31 +0000
commitc09894924a3e5bea4d162051a8c0a417ebb2c801 (patch)
tree3c3837894a18ebf6fa85da9c4c6da7295fd7d6f8
parent21d99e65fb5e28b20ac86386d2654a10d2134bde (diff)
trx_toolkit/transceiver.py: add optional transceiver name
Since fake_trx.py can handle multiple transceivers, it may be useful to name transceivers. If transceiver has some name, it will appear in logging messages, for example: [INFO] transceiver.py:104 Init transceiver 'BTS@127.0.0.1:5700' [INFO] transceiver.py:104 Init transceiver 'MS@127.0.0.1:6700' [INFO] transceiver.py:104 Init transceiver '127.0.0.1:5700/1' This change additionally assigns names to the both default transceivers, and extends the '--trx' option with ability to specify some name, for example: --trx foo@127.0.0.1:5700 or --trx bar@127.0.0.1:5700/1 --trx ipv6@[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:6700 Change-Id: I2f58f02e7819bb008b8aab1a8bf9e0adeb2e44ec
-rwxr-xr-xsrc/target/trx_toolkit/fake_trx.py32
-rw-r--r--src/target/trx_toolkit/transceiver.py7
2 files changed, 26 insertions, 13 deletions
diff --git a/src/target/trx_toolkit/fake_trx.py b/src/target/trx_toolkit/fake_trx.py
index 294a8192..928333f6 100755
--- a/src/target/trx_toolkit/fake_trx.py
+++ b/src/target/trx_toolkit/fake_trx.py
@@ -288,31 +288,34 @@ class Application(ApplicationBase):
self.fake_pm.trx_list = self.trx_list
# Init TRX instance for BTS
- self.append_trx(self.argv.bts_addr, self.argv.bts_base_port)
+ self.append_trx(self.argv.bts_addr,
+ self.argv.bts_base_port, name = "BTS")
# Init TRX instance for BB
- self.append_trx(self.argv.bb_addr, self.argv.bb_base_port)
+ self.append_trx(self.argv.bb_addr,
+ self.argv.bb_base_port, name = "MS")
# Additional transceivers (optional)
if self.argv.trx_list is not None:
for trx_def in self.argv.trx_list:
- (addr, port, idx) = trx_def
- self.append_child_trx(addr, port, idx)
+ (name, addr, port, idx) = trx_def
+ self.append_child_trx(addr, port, idx, name)
# Burst forwarding between transceivers
self.burst_fwd = BurstForwarder(self.trx_list)
log.info("Init complete")
- def append_trx(self, remote_addr, base_port):
+ def append_trx(self, remote_addr, base_port, name = None):
trx = FakeTRX(self.argv.trx_bind_addr, remote_addr, base_port,
- clck_gen = self.clck_gen, pwr_meas = self.fake_pm)
+ clck_gen = self.clck_gen, pwr_meas = self.fake_pm,
+ name = name)
self.trx_list.add_trx(trx)
- def append_child_trx(self, remote_addr, base_port, child_idx):
+ def append_child_trx(self, remote_addr, base_port, child_idx, name = None):
# Index 0 corresponds to the first transceiver
if child_idx is 0:
- self.append_trx(remote_addr, base_port)
+ self.append_trx(remote_addr, base_port, name)
return
# Find 'parent' transceiver for a new child
@@ -323,7 +326,7 @@ class Application(ApplicationBase):
# Allocate a new child
trx_child = FakeTRX(self.argv.trx_bind_addr, remote_addr, base_port,
- child_idx = child_idx, pwr_meas = self.fake_pm)
+ child_idx = child_idx, pwr_meas = self.fake_pm, name = name)
self.trx_list.add_trx(trx_child)
# Link a new 'child' with its 'parent'
@@ -363,11 +366,12 @@ class Application(ApplicationBase):
# format: REMOTE_ADDR:BIND_PORT[/TRX_NUM]
# e.g. [2001:0db8:85a3:0000:0000:8a2e:0370:7334]:5700/5
# e.g. 127.0.0.1:5700 or 127.0.0.1:5700/1
+ # e.g. foo@127.0.0.1:5700 or bar@127.0.0.1:5700/1
@staticmethod
def trx_def(val):
try:
- result = re.match("(.+):([0-9]+)(\/[0-9]+)?", val)
- (addr, port, idx) = result.groups()
+ result = re.match("(.+@)?(.+):([0-9]+)(\/[0-9]+)?", val)
+ (name, addr, port, idx) = result.groups()
except:
raise argparse.ArgumentTypeError("Invalid TRX definition: %s" % val)
@@ -376,7 +380,11 @@ class Application(ApplicationBase):
else:
idx = 0
- return (addr, int(port), idx)
+ # Cut '@' from TRX name
+ if name is not None:
+ name = name[:-1]
+
+ return (name, addr, int(port), idx)
def parse_argv(self):
parser = argparse.ArgumentParser(prog = "fake_trx",
diff --git a/src/target/trx_toolkit/transceiver.py b/src/target/trx_toolkit/transceiver.py
index 6c72a26f..9c234fd4 100644
--- a/src/target/trx_toolkit/transceiver.py
+++ b/src/target/trx_toolkit/transceiver.py
@@ -90,7 +90,7 @@ class Transceiver:
"""
- def __init__(self, bind_addr, remote_addr, base_port,
+ def __init__(self, bind_addr, remote_addr, base_port, name = None,
child_idx = 0, clck_gen = None, pwr_meas = None):
# Connection info
self.remote_addr = remote_addr
@@ -98,6 +98,9 @@ class Transceiver:
self.base_port = base_port
self.child_idx = child_idx
+ # Meta info
+ self.name = name
+
log.info("Init transceiver '%s'" % self)
# Child transceiver cannot have its own clock
@@ -141,6 +144,8 @@ class Transceiver:
desc = "%s:%d" % (self.remote_addr, self.base_port)
if self.child_idx > 0:
desc += "/%d" % self.child_idx
+ if self.name is not None:
+ desc = "%s@%s" % (self.name, desc)
return desc