Change in osmocom-bb[master]: trx_toolkit/fake_trx.py: enrich TRX logging messages

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Vadim Yanitskiy gerrit-no-reply at lists.osmocom.org
Mon Jan 14 23:52:32 UTC 2019


Vadim Yanitskiy has submitted this change and it was merged. ( https://gerrit.osmocom.org/12546 )

Change subject: trx_toolkit/fake_trx.py: enrich TRX logging messages
......................................................................

trx_toolkit/fake_trx.py: enrich TRX logging messages

Since fake_trx.py can handle multiple transceivers, it makes sense
to print some info in logging messages about transceivers they
belong to. This acvieved by defining __str__() for Transceiver.

Some examples:

  [DEBUG] ctrl_if_trx.py:83 (127.0.0.1:5700) Recv POWEROFF cmd
  [INFO] ctrl_if_trx.py:85 (127.0.0.1:5700) Stopping transceiver...

  [DEBUG] ctrl_if_trx.py:95 (127.0.0.1:5700/1) Recv RXTUNE cmd
  [DEBUG] ctrl_if_trx.py:102 (127.0.0.1:5700/1) Recv TXTUNE cmd
  [DEBUG] ctrl_if_trx.py:155 (127.0.0.1:5700/1) Ignore CMD SETTSC
  [DEBUG] ctrl_if_trx.py:155 (127.0.0.1:5700/1) Ignore CMD SETPOWER

Change-Id: I1f706790a2da226f1418f89d2cfbb55baa6ea624
---
M src/target/trx_toolkit/ctrl_if_trx.py
M src/target/trx_toolkit/fake_trx.py
M src/target/trx_toolkit/transceiver.py
3 files changed, 41 insertions(+), 30 deletions(-)

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



diff --git a/src/target/trx_toolkit/ctrl_if_trx.py b/src/target/trx_toolkit/ctrl_if_trx.py
index 83d55db..0d4935d 100644
--- a/src/target/trx_toolkit/ctrl_if_trx.py
+++ b/src/target/trx_toolkit/ctrl_if_trx.py
@@ -59,19 +59,19 @@
 
 		# Power control
 		if self.verify_cmd(request, "POWERON", 0):
-			log.debug("Recv POWERON CMD")
+			log.debug("(%s) Recv POWERON CMD" % self.trx)
 
 			# Ensure transceiver isn't working
 			if self.trx.running:
-				log.error("Transceiver already started")
+				log.error("(%s) Transceiver already started" % self.trx)
 				return -1
 
 			# Ensure RX / TX freq. are set
 			if (self.trx.rx_freq is None) or (self.trx.tx_freq is None):
-				log.error("RX / TX freq. are not set")
+				log.error("(%s) RX / TX freq. are not set" % self.trx)
 				return -1
 
-			log.info("Starting transceiver...")
+			log.info("(%s) Starting transceiver..." % self.trx)
 			self.trx.running = True
 
 			# Notify transceiver about that
@@ -80,9 +80,9 @@
 			return 0
 
 		elif self.verify_cmd(request, "POWEROFF", 0):
-			log.debug("Recv POWEROFF cmd")
+			log.debug("(%s) Recv POWEROFF cmd" % self.trx)
 
-			log.info("Stopping transceiver...")
+			log.info("(%s) Stopping transceiver..." % self.trx)
 			self.trx.running = False
 
 			# Notify transceiver about that
@@ -92,26 +92,27 @@
 
 		# Tuning Control
 		elif self.verify_cmd(request, "RXTUNE", 1):
-			log.debug("Recv RXTUNE cmd")
+			log.debug("(%s) Recv RXTUNE cmd" % self.trx)
 
 			# TODO: check freq range
 			self.trx.rx_freq = int(request[1]) * 1000
 			return 0
 
 		elif self.verify_cmd(request, "TXTUNE", 1):
-			log.debug("Recv TXTUNE cmd")
+			log.debug("(%s) Recv TXTUNE cmd" % self.trx)
 
 			# TODO: check freq range
 			self.trx.tx_freq = int(request[1]) * 1000
 			return 0
 
 		elif self.verify_cmd(request, "SETSLOT", 2):
-			log.debug("Recv SETSLOT cmd")
+			log.debug("(%s) Recv SETSLOT cmd" % self.trx)
 
 			# Obtain TS index
 			ts = int(request[1])
 			if ts not in range(0, 8):
-				log.error("TS index should be in range: 0..7")
+				log.error("(%s) TS index should be in "
+					"range: 0..7" % self.trx)
 				return -1
 
 			# Parse TS type
@@ -132,13 +133,13 @@
 
 		# Power measurement
 		if self.verify_cmd(request, "MEASURE", 1):
-			log.debug("Recv MEASURE cmd")
+			log.debug("(%s) Recv MEASURE cmd" % self.trx)
 
 			# Power Measurement interface is optional
 			# for Transceiver, thus may be uninitialized
 			if self.trx.pwr_meas is None:
-				log.error("Power Measurement interface "
-					"is not initialized => rejecting command")
+				log.error("(%s) Power Measurement interface is not "
+					"initialized => rejecting command" % self.trx)
 				return -1
 
 			# TODO: check freq range
@@ -151,5 +152,5 @@
 		else:
 			# We don't care about other commands,
 			# so let's merely ignore them ;)
-			log.debug("Ignore CMD %s" % request[0])
+			log.debug("(%s) Ignore CMD %s" % (self.trx, request[0]))
 			return 0
diff --git a/src/target/trx_toolkit/fake_trx.py b/src/target/trx_toolkit/fake_trx.py
index 0bed29d..294a819 100755
--- a/src/target/trx_toolkit/fake_trx.py
+++ b/src/target/trx_toolkit/fake_trx.py
@@ -145,8 +145,8 @@
 			return False
 
 		if msg.fn % self.burst_drop_period == 0:
-			log.info("Simulation: dropping burst (fn=%u %% %u == 0)"
-				% (msg.fn, self.burst_drop_period))
+			log.info("(%s) Simulation: dropping burst (fn=%u %% %u == 0)"
+				% (self, msg.fn, self.burst_drop_period))
 			self.burst_drop_amount -= 1
 			return True
 
@@ -176,7 +176,7 @@
 		# Timing Advance
 		# Syntax: CMD SETTA <TA>
 		if self.ctrl_if.verify_cmd(request, "SETTA", 1):
-			log.debug("Recv SETTA cmd")
+			log.debug("(%s) Recv SETTA cmd" % self)
 
 			# Store indicated value
 			self.ta = int(request[1])
@@ -185,7 +185,7 @@
 		# Timing of Arrival simulation
 		# Absolute form: CMD FAKE_TOA <BASE> <THRESH>
 		elif self.ctrl_if.verify_cmd(request, "FAKE_TOA", 2):
-			log.debug("Recv FAKE_TOA cmd")
+			log.debug("(%s) Recv FAKE_TOA cmd" % self)
 
 			# Parse and apply both base and threshold
 			self.toa256_base = int(request[1])
@@ -195,7 +195,7 @@
 		# Timing of Arrival simulation
 		# Relative form: CMD FAKE_TOA <+-BASE_DELTA>
 		elif self.ctrl_if.verify_cmd(request, "FAKE_TOA", 1):
-			log.debug("Recv FAKE_TOA cmd")
+			log.debug("(%s) Recv FAKE_TOA cmd" % self)
 
 			# Parse and apply delta
 			self.toa256_base += int(request[1])
@@ -204,7 +204,7 @@
 		# RSSI simulation
 		# Absolute form: CMD FAKE_RSSI <BASE> <THRESH>
 		elif self.ctrl_if.verify_cmd(request, "FAKE_RSSI", 2):
-			log.debug("Recv FAKE_RSSI cmd")
+			log.debug("(%s) Recv FAKE_RSSI cmd" % self)
 
 			# Parse and apply both base and threshold
 			self.rssi_base = int(request[1])
@@ -214,7 +214,7 @@
 		# RSSI simulation
 		# Relative form: CMD FAKE_RSSI <+-BASE_DELTA>
 		elif self.ctrl_if.verify_cmd(request, "FAKE_RSSI", 1):
-			log.debug("Recv FAKE_RSSI cmd")
+			log.debug("(%s) Recv FAKE_RSSI cmd" % self)
 
 			# Parse and apply delta
 			self.rssi_base += int(request[1])
@@ -224,12 +224,13 @@
 		# Syntax: CMD FAKE_DROP <AMOUNT>
 		# Dropping pattern: fn % 1 == 0
 		elif self.ctrl_if.verify_cmd(request, "FAKE_DROP", 1):
-			log.debug("Recv FAKE_DROP cmd")
+			log.debug("(%s) Recv FAKE_DROP cmd" % self)
 
 			# Parse / validate amount of bursts
 			num = int(request[1])
 			if num < 0:
-				log.error("FAKE_DROP amount shall not be negative")
+				log.error("(%s) FAKE_DROP amount shall not "
+					"be negative" % self)
 				return -1
 
 			self.burst_drop_amount = num
@@ -240,18 +241,20 @@
 		# Syntax: CMD FAKE_DROP <AMOUNT> <FN_PERIOD>
 		# Dropping pattern: fn % period == 0
 		elif self.ctrl_if.verify_cmd(request, "FAKE_DROP", 2):
-			log.debug("Recv FAKE_DROP cmd")
+			log.debug("(%s) Recv FAKE_DROP cmd" % self)
 
 			# Parse / validate amount of bursts
 			num = int(request[1])
 			if num < 0:
-				log.error("FAKE_DROP amount shall not be negative")
+				log.error("(%s) FAKE_DROP amount shall not "
+					"be negative" % self)
 				return -1
 
 			# Parse / validate period
 			period = int(request[2])
 			if period <= 0:
-				log.error("FAKE_DROP period shall be greater than zero")
+				log.error("(%s) FAKE_DROP period shall "
+					"be greater than zero" % self)
 				return -1
 
 			self.burst_drop_amount = num
diff --git a/src/target/trx_toolkit/transceiver.py b/src/target/trx_toolkit/transceiver.py
index 57ca531..4eb210b 100644
--- a/src/target/trx_toolkit/transceiver.py
+++ b/src/target/trx_toolkit/transceiver.py
@@ -135,6 +135,13 @@
 		# List of child transceivers
 		self.child_trx_list = TRXList()
 
+	def __str__(self):
+		desc = "%s:%d" % (self.remote_addr, self.base_port)
+		if self.child_idx > 0:
+			desc += "/%d" % self.child_idx
+
+		return desc
+
 	# To be overwritten if required,
 	# no custom command handlers by default
 	def ctrl_cmd_handler(self, request):
@@ -173,14 +180,14 @@
 
 		# Make sure that transceiver is configured and running
 		if not self.running:
-			log.warning("RX DATA message (%s), but transceiver "
-				"is not running => dropping..." % msg.desc_hdr())
+			log.warning("(%s) RX DATA message (%s), but transceiver "
+				"is not running => dropping..." % (self, msg.desc_hdr()))
 			return None
 
 		# Make sure that indicated timeslot is configured
 		if msg.tn not in self.ts_list:
-			log.warning("RX DATA message (%s), but timeslot "
-				"is not configured => dropping..." % msg.desc_hdr())
+			log.warning("(%s) RX DATA message (%s), but timeslot is not "
+				"configured => dropping..." % (self, msg.desc_hdr()))
 			return None
 
 		return msg

-- 
To view, visit https://gerrit.osmocom.org/12546
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: I1f706790a2da226f1418f89d2cfbb55baa6ea624
Gerrit-Change-Number: 12546
Gerrit-PatchSet: 4
Gerrit-Owner: Vadim Yanitskiy <axilirator at gmail.com>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder (1000002)
Gerrit-Reviewer: Vadim Yanitskiy <axilirator at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190114/dcb6d5d8/attachment.htm>


More information about the gerrit-log mailing list