[MERGED] osmo-bts[master]: trx: Allow BTS and TRX to be on different IPs

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

Pau Espin Pedrol gerrit-no-reply at lists.osmocom.org
Tue Jun 6 19:48:26 UTC 2017


Pau Espin Pedrol has submitted this change and it was merged.

Change subject: trx: Allow BTS and TRX to be on different IPs
......................................................................


trx: Allow BTS and TRX to be on different IPs

Depends on libosmocore I3c655a4af64fb80497a5aaa811cce8005dba9cd9

Change-Id: I0bd34b7b02c1a9b0c6f6f89f327b486e5620c8d5
---
M doc/examples/trx/osmo-bts.cfg
M include/osmo-bts/phy_link.h
M src/osmo-bts-trx/main.c
M src/osmo-bts-trx/trx_if.c
M src/osmo-bts-trx/trx_if.h
M src/osmo-bts-trx/trx_vty.c
6 files changed, 49 insertions(+), 43 deletions(-)

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



diff --git a/doc/examples/trx/osmo-bts.cfg b/doc/examples/trx/osmo-bts.cfg
index 29d5655..e455540 100644
--- a/doc/examples/trx/osmo-bts.cfg
+++ b/doc/examples/trx/osmo-bts.cfg
@@ -23,6 +23,8 @@
 phy 0
  instance 0
  osmotrx rx-gain 1
+ osmotrx ip local 127.0.0.1
+ osmotrx ip remote 127.0.0.1
 bts 0
  band 1800
  ipa unit-id 6969 0
diff --git a/include/osmo-bts/phy_link.h b/include/osmo-bts/phy_link.h
index e8fd7eb..2164dfa 100644
--- a/include/osmo-bts/phy_link.h
+++ b/include/osmo-bts/phy_link.h
@@ -37,7 +37,8 @@
 		struct {
 		} sysmobts;
 		struct {
-			char *transceiver_ip;
+			char *local_ip;
+			char *remote_ip;
 			uint16_t base_port_local;
 			uint16_t base_port_remote;
 			struct osmo_fd trx_ofd_clk;
diff --git a/src/osmo-bts-trx/main.c b/src/osmo-bts-trx/main.c
index 0148e5b..b2cbb39 100644
--- a/src/osmo-bts-trx/main.c
+++ b/src/osmo-bts-trx/main.c
@@ -113,7 +113,8 @@
 
 void bts_model_phy_link_set_defaults(struct phy_link *plink)
 {
-	plink->u.osmotrx.transceiver_ip = talloc_strdup(plink, "127.0.0.1");
+	plink->u.osmotrx.local_ip = talloc_strdup(plink, "127.0.0.1");
+	plink->u.osmotrx.remote_ip = talloc_strdup(plink, "127.0.0.1");
 	plink->u.osmotrx.base_port_local = 5800;
 	plink->u.osmotrx.base_port_remote = 5700;
 	plink->u.osmotrx.clock_advance = 20;
diff --git a/src/osmo-bts-trx/trx_if.c b/src/osmo-bts-trx/trx_if.c
index 989e77a..c676d11 100644
--- a/src/osmo-bts-trx/trx_if.c
+++ b/src/osmo-bts-trx/trx_if.c
@@ -57,14 +57,10 @@
  */
 
 /* open socket */
-static int trx_udp_open(void *priv, struct osmo_fd *ofd, const char *host,
-			uint16_t port_local, uint16_t port_remote,
+static int trx_udp_open(void *priv, struct osmo_fd *ofd, const char *host_local,
+			uint16_t port_local, const char *host_remote, uint16_t port_remote,
 			int (*cb)(struct osmo_fd *fd, unsigned int what))
 {
-	struct sockaddr_storage sas;
-	struct sockaddr *sa = (struct sockaddr *)&sas;
-	socklen_t sa_len;
-
 	int rc;
 
 	/* Init */
@@ -72,30 +68,10 @@
 	ofd->cb = cb;
 	ofd->data = priv;
 
-	/* Listen / Binds */
-	rc = osmo_sock_init_ofd(ofd, AF_UNSPEC, SOCK_DGRAM, 0, host,
-		port_local, OSMO_SOCK_F_BIND);
+	/* Listen / Binds + Connect */
+	rc = osmo_sock_init2_ofd(ofd, AF_UNSPEC, SOCK_DGRAM, IPPROTO_UDP, host_local, port_local,
+				host_remote, port_remote, OSMO_SOCK_F_BIND | OSMO_SOCK_F_CONNECT);
 	if (rc < 0)
-		return rc;
-
-	/* Connect */
-	sa_len = sizeof(sas);
-	rc = getsockname(ofd->fd, sa, &sa_len);
-	if (rc)
-		return rc;
-
-	if (sa->sa_family == AF_INET) {
-		struct sockaddr_in *sin = (struct sockaddr_in *)sa;
-		sin->sin_port = htons(port_remote);
-	} else if (sa->sa_family == AF_INET6) {
-		struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
-		sin6->sin6_port = htons(port_remote);
-	} else {
-		return -EINVAL;
-	}
-
-	rc = connect(ofd->fd, sa, sa_len);
-	if (rc)
 		return rc;
 
 	return 0;
@@ -528,8 +504,9 @@
 
 	/* open the shared/common clock socket */
 	rc = trx_udp_open(plink, &plink->u.osmotrx.trx_ofd_clk,
-			  plink->u.osmotrx.transceiver_ip,
+			  plink->u.osmotrx.local_ip,
 			  plink->u.osmotrx.base_port_local,
+			  plink->u.osmotrx.remote_ip,
 			  plink->u.osmotrx.base_port_remote,
 			  trx_clk_read_cb);
 	if (rc < 0) {
@@ -588,14 +565,16 @@
 
 	/* open sockets */
 	rc = trx_udp_open(l1h, &l1h->trx_ofd_ctrl,
-			  plink->u.osmotrx.transceiver_ip,
+			  plink->u.osmotrx.local_ip,
 			  compute_port(pinst, 0, 0),
+			  plink->u.osmotrx.remote_ip,
 			  compute_port(pinst, 1, 0), trx_ctrl_read_cb);
 	if (rc < 0)
 		goto err;
 	rc = trx_udp_open(l1h, &l1h->trx_ofd_data,
-			  plink->u.osmotrx.transceiver_ip,
+			  plink->u.osmotrx.local_ip,
 			  compute_port(pinst, 0, 1),
+			  plink->u.osmotrx.remote_ip,
 			  compute_port(pinst, 1, 1), trx_data_read_cb);
 	if (rc < 0)
 		goto err;
diff --git a/src/osmo-bts-trx/trx_if.h b/src/osmo-bts-trx/trx_if.h
index fdc8a8d..05e8bff 100644
--- a/src/osmo-bts-trx/trx_if.h
+++ b/src/osmo-bts-trx/trx_if.h
@@ -2,7 +2,8 @@
 #define TRX_IF_H
 
 extern int transceiver_available;
-extern const char *transceiver_ip;
+extern const char *local_ip;
+extern const char *remote_ip;
 extern int settsc_enabled;
 extern int setbsic_enabled;
 
diff --git a/src/osmo-bts-trx/trx_vty.c b/src/osmo-bts-trx/trx_vty.c
index 3822b0f..123ca80 100644
--- a/src/osmo-bts-trx/trx_vty.c
+++ b/src/osmo-bts-trx/trx_vty.c
@@ -24,6 +24,7 @@
 #include <errno.h>
 #include <stdint.h>
 #include <ctype.h>
+#include <inttypes.h>
 
 #include <arpa/inet.h>
 
@@ -459,14 +460,31 @@
 DEFUN(cfg_phy_transc_ip, cfg_phy_transc_ip_cmd,
 	"osmotrx ip HOST",
 	OSMOTRX_STR
-	"Set remote IP address\n"
-	"IP address of OsmoTRX\n")
+	"Set local and remote IP address\n"
+	"IP address (for both OsmoBtsTrx and OsmoTRX)\n")
 {
 	struct phy_link *plink = vty->index;
 
-	if (plink->u.osmotrx.transceiver_ip)
-		talloc_free(plink->u.osmotrx.transceiver_ip);
-	plink->u.osmotrx.transceiver_ip = talloc_strdup(plink, argv[0]);
+	osmo_talloc_replace_string(plink, &plink->u.osmotrx.local_ip, argv[0]);
+	osmo_talloc_replace_string(plink, &plink->u.osmotrx.remote_ip, argv[0]);
+
+	return CMD_SUCCESS;
+}
+
+DEFUN(cfg_phy_osmotrx_ip, cfg_phy_osmotrx_ip_cmd,
+	"osmotrx ip (local|remote) A.B.C.D",
+	OSMOTRX_STR
+	"Set IP address\n" "Local IP address (BTS)\n"
+	"Remote IP address (OsmoTRX)\n" "IP address\n")
+{
+	struct phy_link *plink = vty->index;
+
+	if (!strcmp(argv[0], "local"))
+		osmo_talloc_replace_string(plink, &plink->u.osmotrx.local_ip, argv[1]);
+	else if (!strcmp(argv[0], "remote"))
+		osmo_talloc_replace_string(plink, &plink->u.osmotrx.remote_ip, argv[1]);
+	else
+		return CMD_WARNING;
 
 	return CMD_SUCCESS;
 }
@@ -488,9 +506,12 @@
 
 void bts_model_config_write_phy(struct vty *vty, struct phy_link *plink)
 {
-	if (plink->u.osmotrx.transceiver_ip)
-		vty_out(vty, " osmotrx ip %s%s",
-			plink->u.osmotrx.transceiver_ip, VTY_NEWLINE);
+	if (plink->u.osmotrx.local_ip)
+		vty_out(vty, " osmotrx ip local %s%s",
+			plink->u.osmotrx.local_ip, VTY_NEWLINE);
+	if (plink->u.osmotrx.remote_ip)
+		vty_out(vty, " osmotrx ip remote %s%s",
+			plink->u.osmotrx.remote_ip, VTY_NEWLINE);
 
 	vty_out(vty, " osmotrx fn-advance %d%s",
 		plink->u.osmotrx.clock_advance, VTY_NEWLINE);
@@ -568,6 +589,7 @@
 	install_element(PHY_NODE, &cfg_phy_fn_advance_cmd);
 	install_element(PHY_NODE, &cfg_phy_rts_advance_cmd);
 	install_element(PHY_NODE, &cfg_phy_transc_ip_cmd);
+	install_element(PHY_NODE, &cfg_phy_osmotrx_ip_cmd);
 
 	install_element(PHY_INST_NODE, &cfg_phyinst_rxgain_cmd);
 	install_element(PHY_INST_NODE, &cfg_phyinst_tx_atten_cmd);

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I0bd34b7b02c1a9b0c6f6f89f327b486e5620c8d5
Gerrit-PatchSet: 6
Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol <pespin at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Pau Espin Pedrol <pespin at sysmocom.de>



More information about the gerrit-log mailing list