aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2017-05-26 12:45:33 +0200
committerPau Espin Pedrol <pespin@sysmocom.de>2017-06-06 19:23:18 +0000
commit8a8d73a691c709403be4adbe8f2a7150b4d5998a (patch)
tree2413af79c7ba5aa51b7163fe22277e7ad3a9e62e /src
parentd36b3a84638d6db940387f0e18c98855202f554d (diff)
trx: Allow BTS and TRX to be on different IPs
Diffstat (limited to 'src')
-rw-r--r--src/osmo-bts-trx/main.c3
-rw-r--r--src/osmo-bts-trx/trx_if.c43
-rw-r--r--src/osmo-bts-trx/trx_if.h3
-rw-r--r--src/osmo-bts-trx/trx_vty.c38
4 files changed, 45 insertions, 42 deletions
diff --git a/src/osmo-bts-trx/main.c b/src/osmo-bts-trx/main.c
index 0148e5bb..b2cbb39e 100644
--- a/src/osmo-bts-trx/main.c
+++ b/src/osmo-bts-trx/main.c
@@ -113,7 +113,8 @@ int bts_model_init(struct gsm_bts *bts)
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 989e77a7..c676d11c 100644
--- a/src/osmo-bts-trx/trx_if.c
+++ b/src/osmo-bts-trx/trx_if.c
@@ -57,14 +57,10 @@ int setbsic_enabled = 0;
*/
/* 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,32 +68,12 @@ static int trx_udp_open(void *priv, struct osmo_fd *ofd, const char *host,
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 @@ int bts_model_phy_link_open(struct phy_link *plink)
/* 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 @@ int trx_if_open(struct trx_l1h *l1h)
/* 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 fdc8a8d3..05e8bff5 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 3822b0f7..123ca803 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_phyinst_no_maxdlynb, cfg_phyinst_no_maxdlynb_cmd,
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 @@ DEFUN(cfg_phy_base_port, cfg_phy_base_port_cmd,
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 @@ int bts_model_vty_init(struct gsm_bts *bts)
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);