[PATCH] osmo-gsm-tester[master]: Add OsmoSgsn class

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
Thu Nov 23 16:39:43 UTC 2017


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

Add OsmoSgsn class

Change-Id: Iec370a444998c632b3615ad1a6d6f67e64e2bfeb
---
A src/osmo_gsm_tester/osmo_sgsn.py
M src/osmo_gsm_tester/suite.py
M src/osmo_gsm_tester/templates/osmo-sgsn.cfg.tmpl
3 files changed, 112 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-gsm-tester refs/changes/02/5002/1

diff --git a/src/osmo_gsm_tester/osmo_sgsn.py b/src/osmo_gsm_tester/osmo_sgsn.py
new file mode 100644
index 0000000..9865edb
--- /dev/null
+++ b/src/osmo_gsm_tester/osmo_sgsn.py
@@ -0,0 +1,94 @@
+# osmo_gsm_tester: specifics for running an osmo-sgsn
+#
+# Copyright (C) 2016-2017 by sysmocom - s.f.m.c. GmbH
+#
+# Author: Pau Espin Pedrol <pespin at sysmocom.de>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+import os
+import pprint
+
+from . import log, util, config, template, process, osmo_ctrl, pcap_recorder
+
+class OsmoSgsn(log.Origin):
+    suite_run = None
+    ip_address = None
+    run_dir = None
+    config_file = None
+    process = None
+    hlr = None
+    ggsn = None
+
+    def __init__(self, suite_run, hlr, ggsn, ip_address):
+        super().__init__(log.C_RUN, 'osmo-sgsn_%s' % ip_address.get('addr'))
+        self.suite_run = suite_run
+        self.hlr = hlr
+        self.ggsn = ggsn
+        self.ip_address = ip_address
+
+    def start(self):
+        self.log('Starting osmo-sgsn')
+        self.run_dir = util.Dir(self.suite_run.get_test_run_dir().new_dir(self.name()))
+        self.configure()
+
+        inst = util.Dir(os.path.abspath(self.suite_run.trial.get_inst('osmo-sgsn')))
+
+        binary = inst.child('bin', 'osmo-sgsn')
+        if not os.path.isfile(binary):
+            raise log.Error('Binary missing:', binary)
+        lib = inst.child('lib')
+        if not os.path.isdir(lib):
+            raise log.Error('No lib/ in', inst)
+
+        pcap_recorder.PcapRecorder(self.suite_run, self.run_dir.new_dir('pcap'), None,
+                                   'host %s' % self.addr())
+
+        env = { 'LD_LIBRARY_PATH': util.prepend_library_path(lib) }
+
+        self.dbg(run_dir=self.run_dir, binary=binary, env=env)
+        self.process = process.Process(self.name(), self.run_dir,
+                                       (binary,
+                                        '-c', os.path.abspath(self.config_file)),
+                                       env=env)
+        self.suite_run.remember_to_stop(self.process)
+        self.process.launch()
+
+    def configure(self):
+        self.config_file = self.run_dir.new_file('osmo-sgsn.cfg')
+        self.dbg(config_file=self.config_file)
+
+        values = dict(sgsn=config.get_defaults('sgsn'))
+        config.overlay(values, self.suite_run.config())
+        config.overlay(values, dict(sgsn=dict(ip_address=self.ip_address)))
+        config.overlay(values, self.hlr.conf_for_client())
+        config.overlay(values, dict(sgsn=dict(ggsn_tun_ip_address=self.ggsn.addr())))
+
+        self.dbg('SGSN CONFIG:\n' + pprint.pformat(values))
+
+        with open(self.config_file, 'w') as f:
+            r = template.render('osmo-sgsn.cfg', values)
+            self.dbg(r)
+            f.write(r)
+
+    def conf_for_client(self):
+        return dict(sgsn=dict(ip_address=self.ip_address))
+
+    def addr(self):
+        return self.ip_address.get('addr')
+
+    def running(self):
+        return not self.process.terminated()
+
+# vim: expandtab tabstop=4 shiftwidth=4
diff --git a/src/osmo_gsm_tester/suite.py b/src/osmo_gsm_tester/suite.py
index 8c1d38d..0d5f97a 100644
--- a/src/osmo_gsm_tester/suite.py
+++ b/src/osmo_gsm_tester/suite.py
@@ -22,7 +22,7 @@
 import time
 import pprint
 from . import config, log, template, util, resource, schema, event_loop, test
-from . import osmo_nitb, osmo_hlr, osmo_mgcpgw, osmo_mgw, osmo_msc, osmo_bsc, osmo_stp, osmo_ggsn, modem, esme
+from . import osmo_nitb, osmo_hlr, osmo_mgcpgw, osmo_mgw, osmo_msc, osmo_bsc, osmo_stp, osmo_ggsn, osmo_sgsn, modem, esme
 
 class Timeout(Exception):
     pass
@@ -235,6 +235,11 @@
             ip_address = self.ip_address()
         return osmo_ggsn.OsmoGgsn(self, ip_address)
 
+    def sgsn(self, hlr, ggsn, ip_address=None):
+        if ip_address is None:
+            ip_address = self.ip_address()
+        return osmo_sgsn.OsmoSgsn(self, hlr, ggsn, ip_address)
+
     def mgcpgw(self, ip_address=None, bts_ip=None):
         if ip_address is None:
             ip_address = self.ip_address()
diff --git a/src/osmo_gsm_tester/templates/osmo-sgsn.cfg.tmpl b/src/osmo_gsm_tester/templates/osmo-sgsn.cfg.tmpl
index 4955983..c4d45f6 100644
--- a/src/osmo_gsm_tester/templates/osmo-sgsn.cfg.tmpl
+++ b/src/osmo_gsm_tester/templates/osmo-sgsn.cfg.tmpl
@@ -2,13 +2,21 @@
 ! Osmocom SGSN configuration
 !
 !
+log stderr
+ logging filter all 1
+ logging color 1
+ logging print category 1
+ logging print extended-timestamp 1
+ logging level all debug
 line vty
  no login
-!
 sgsn
- gtp local-ip 127.0.0.1
- ggsn 0 remote-ip 127.0.0.1
+ gtp local-ip ${sgsn.ip_address.addr}
+ ggsn 0 remote-ip ${sgsn.ggsn_tun_ip_address}
  ggsn 0 gtp-version 1
+ auth-policy remote
+ gsup remote-ip ${hlr.ip_address.addr}
+ gsup remote-port 4222
 !
 ns
  timer tns-block 3
@@ -18,7 +26,7 @@
  timer tns-test 30
  timer tns-alive 3
  timer tns-alive-retries 10
- encapsulation udp local-ip 127.0.0.1
+ encapsulation udp local-ip ${sgsn.ip_address.addr}
  encapsulation udp local-port 23000
  encapsulation framerelay-gre enabled 0
 !

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iec370a444998c632b3615ad1a6d6f67e64e2bfeb
Gerrit-PatchSet: 1
Gerrit-Project: osmo-gsm-tester
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol <pespin at sysmocom.de>



More information about the gerrit-log mailing list