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
This commit is contained in:
Vadim Yanitskiy 2019-01-14 08:15:17 +07:00
parent 21d99e65fb
commit c09894924a
2 changed files with 26 additions and 13 deletions

View File

@ -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",

View File

@ -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