Review at  https://gerrit.osmocom.org/2745

trx: Allow BTS and TRX to be on different IPs

Depends on libosmocore I3c655a4af64fb80497a5aaa811cce8005dba9cd9

Change-Id: I0bd34b7b02c1a9b0c6f6f89f327b486e5620c8d5
---
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
5 files changed, 36 insertions(+), 44 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-bts refs/changes/45/2745/1

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..18e4788 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>
 
@@ -457,16 +458,22 @@
 }
 
 DEFUN(cfg_phy_transc_ip, cfg_phy_transc_ip_cmd,
-       "osmotrx ip HOST",
+       "osmotrx ip (local|remote) HOST",
        OSMOTRX_STR
-       "Set remote IP address\n"
-       "IP address of OsmoTRX\n")
+       "Set IP address\n" "Local IP address (BTS)\n"
+       "Remote IP address (OsmoTRX)\n" "IP address\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]);
+       if (!strcmp(argv[0], "local")) {
+               if (plink->u.osmotrx.local_ip)
+                       talloc_free(plink->u.osmotrx.local_ip);
+               plink->u.osmotrx.local_ip = talloc_strdup(plink, argv[1]);
+       } else {
+               if (plink->u.osmotrx.remote_ip)
+                       talloc_free(plink->u.osmotrx.remote_ip);
+               plink->u.osmotrx.remote_ip = talloc_strdup(plink, argv[1]);
+       }
 
        return CMD_SUCCESS;
 }
@@ -488,9 +495,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);

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0bd34b7b02c1a9b0c6f6f89f327b486e5620c8d5
Gerrit-PatchSet: 1
Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol <pes...@sysmocom.de>

Reply via email to