[MERGED] osmocom-bb[fixeria/trx]: fake_trx: Always send control responses to where commands ar...

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/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Thu Mar 1 11:03:13 UTC 2018


Harald Welte has submitted this change and it was merged.

Change subject: fake_trx: Always send control responses to where commands are from
......................................................................


fake_trx: Always send control responses to where commands are from

fake_trx is using locally bound and not connected UDP sockets for
control commands.

When we receive a control command, we should not simply send the
response to the default destination, but send it back to the exact
ip+prt from which the command originated.  This ensures correct routing
of responses even in case multiple programs are interfacing concurrently
with a control socket.

Change-Id: I24a0bba6eed059b101af95dac7d059f34dd715fc
---
M src/target/fake_trx/ctrl_if.py
M src/target/fake_trx/fake_trx.py
M src/target/fake_trx/udp_link.py
3 files changed, 13 insertions(+), 7 deletions(-)

Approvals:
  Vadim Yanitskiy: Looks good to me, but someone else must approve
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/src/target/fake_trx/ctrl_if.py b/src/target/fake_trx/ctrl_if.py
index e84c1c8..394c959 100644
--- a/src/target/fake_trx/ctrl_if.py
+++ b/src/target/fake_trx/ctrl_if.py
@@ -25,16 +25,16 @@
 from udp_link import UDPLink
 
 class CTRLInterface(UDPLink):
-	def handle_rx(self, data):
+	def handle_rx(self, data, remote):
 		# print(data)
 		if self.verify_req(data):
 			request = self.prepare_req(data)
 			rc = self.parse_cmd(request)
 
 			if type(rc) is tuple:
-				self.send_response(request, rc[0], rc[1])
+				self.send_response(request, remote, rc[0], rc[1])
 			else:
-				self.send_response(request, rc)
+				self.send_response(request, remote, rc)
 		else:
 			print("[!] Wrong data on CTRL interface")
 
@@ -66,7 +66,7 @@
 
 		return True
 
-	def send_response(self, request, response_code, params = None):
+	def send_response(self, request, remote, response_code, params = None):
 		# Include status code, for example ["TXTUNE", "0", "941600"]
 		request.insert(1, str(response_code))
 
@@ -77,7 +77,7 @@
 		# Add the response signature, and join back to string
 		response = "RSP " + " ".join(request) + "\0"
 		# Now we have something like "RSP TXTUNE 0 941600"
-		self.send(response)
+		self.sendto(response, remote)
 
 	def parse_cmd(self, request):
 		raise NotImplementedError
diff --git a/src/target/fake_trx/fake_trx.py b/src/target/fake_trx/fake_trx.py
index c9e427c..a0534fd 100755
--- a/src/target/fake_trx/fake_trx.py
+++ b/src/target/fake_trx/fake_trx.py
@@ -124,12 +124,12 @@
 			# CTRL commands from BTS
 			if self.bts_ctrl.sock in r_event:
 				data, addr = self.bts_ctrl.sock.recvfrom(128)
-				self.bts_ctrl.handle_rx(data.decode())
+				self.bts_ctrl.handle_rx(data.decode(), addr)
 
 			# CTRL commands from BB
 			if self.bb_ctrl.sock in r_event:
 				data, addr = self.bb_ctrl.sock.recvfrom(128)
-				self.bb_ctrl.handle_rx(data.decode())
+				self.bb_ctrl.handle_rx(data.decode(), addr)
 
 	def shutdown(self):
 		print("[i] Shutting down...")
diff --git a/src/target/fake_trx/udp_link.py b/src/target/fake_trx/udp_link.py
index c464802..dda901c 100644
--- a/src/target/fake_trx/udp_link.py
+++ b/src/target/fake_trx/udp_link.py
@@ -43,3 +43,9 @@
 			data = data.encode()
 
 		self.sock.sendto(data, (self.remote_addr, self.remote_port))
+
+	def sendto(self, data, remote):
+		if type(data) not in [bytearray, bytes]:
+			data = data.encode()
+
+		self.sock.sendto(data, remote)

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I24a0bba6eed059b101af95dac7d059f34dd715fc
Gerrit-PatchSet: 4
Gerrit-Project: osmocom-bb
Gerrit-Branch: fixeria/trx
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Vadim Yanitskiy <axilirator at gmail.com>



More information about the gerrit-log mailing list