bts_osmotrx: Support configuring bts addr, trx_remote_ip and launch_trx

We may want to support running a device which runs its own TRX
(osmo-trx or different implementation). Furthermore, this TRX may be
available in some specific hwardare rather than on the main unit.

This makes it easy to configure OsmoBtsTrx to launch it's own
osmo-trx or not. In case it is launched, all IPs are configured correctly
to ensure connection can be established.

Before this commit, osmo-trx was binding to 127.0.0.1. Now we can
support multiple osmo-trx being launched on the main unit.

Change-Id: I825ed1fc0c3fe75d196db90c1508283fbd04acf8
diff --git a/src/osmo_gsm_tester/bts_osmotrx.py b/src/osmo_gsm_tester/bts_osmotrx.py
index 9795a58..b5262a2 100644
--- a/src/osmo_gsm_tester/bts_osmotrx.py
+++ b/src/osmo_gsm_tester/bts_osmotrx.py
@@ -41,8 +41,17 @@
         self.env = {}
 
     def remote_addr(self):
-        # FIXME
-        return '127.0.0.1'
+        return self.conf.get('addr')
+
+    def trx_remote_ip(self):
+        conf_ip = self.conf.get('trx_remote_ip', None)
+        if conf_ip is not None:
+            return conf_ip
+        # if 'trx_remote_ip' is not configured, use same IP as BTS
+        return self.remote_addr()
+
+    def launch_trx_enabled(self):
+        return util.str2bool(self.conf.get('launch_trx'))
 
     def start(self):
         if self.bsc is None:
@@ -53,10 +62,11 @@
         self.run_dir = util.Dir(self.suite_run.get_test_run_dir().new_dir(self.name()))
         self.configure()
 
-        self.trx = OsmoTrx(self.suite_run)
-        self.trx.start()
-        self.log('Waiting for osmo-trx to start up...')
-        event_loop.wait(self, self.trx.trx_ready)
+        if self.launch_trx_enabled():
+            self.trx = OsmoTrx(self.suite_run, self.trx_remote_ip(), self.remote_addr())
+            self.trx.start()
+            self.log('Waiting for osmo-trx to start up...')
+            event_loop.wait(self, self.trx.trx_ready)
 
         self.inst = util.Dir(os.path.abspath(self.suite_run.trial.get_inst(OsmoBtsTrx.BIN_BTS_TRX)))
         lib = self.inst.child('lib')
@@ -93,6 +103,8 @@
         config.overlay(values, {
                         'osmo_bts_trx': {
                             'oml_remote_ip': self.bsc.addr(),
+                            'trx_local_ip': self.remote_addr(),
+                            'trx_remote_ip': self.trx_remote_ip(),
                             'pcu_socket_path': os.path.join(str(self.run_dir), 'pcu_bts')
                         }
         })
@@ -124,17 +136,19 @@
 
     BIN_TRX = 'osmo-trx'
 
-    def __init__(self, suite_run):
+    def __init__(self, suite_run, listen_ip, bts_ip):
         super().__init__(log.C_RUN, OsmoTrx.BIN_TRX)
         self.suite_run = suite_run
         self.env = {}
+        self.listen_ip = listen_ip
+        self.bts_ip = bts_ip
 
     def start(self):
         self.run_dir = util.Dir(self.suite_run.get_test_run_dir().new_dir(self.name()))
         self.inst = util.Dir(os.path.abspath(self.suite_run.trial.get_inst(OsmoTrx.BIN_TRX)))
         lib = self.inst.child('lib')
         self.env = { 'LD_LIBRARY_PATH': util.prepend_library_path(lib) }
-        self.proc_trx = self.launch_process(OsmoTrx.BIN_TRX, '-x')
+        self.proc_trx = self.launch_process(OsmoTrx.BIN_TRX, '-x', '-j', self.listen_ip, '-i', self.bts_ip)
 
     def launch_process(self, binary_name, *args):
         binary = os.path.abspath(self.inst.child('bin', binary_name))