Hello Jenkins Builder, I'd like you to reexamine a change. Please visit
https://gerrit.osmocom.org/2541 to look at the new patch set (#3). Log network activity using tcpdump for nitb interface Change-Id: I4c5d0e2d9857160f905e743517e744f1a06368af --- M src/osmo_gsm_tester/osmo_nitb.py A src/osmo_gsm_tester/pcaprecorder.py M src/osmo_gsm_tester/util.py 3 files changed, 76 insertions(+), 2 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-gsm-tester refs/changes/41/2541/3 diff --git a/src/osmo_gsm_tester/osmo_nitb.py b/src/osmo_gsm_tester/osmo_nitb.py index 3ed48b2..b81d612 100644 --- a/src/osmo_gsm_tester/osmo_nitb.py +++ b/src/osmo_gsm_tester/osmo_nitb.py @@ -22,7 +22,7 @@ import re import socket -from . import log, util, config, template, process, osmo_ctrl +from . import log, util, config, template, process, osmo_ctrl, pcaprecorder class OsmoNitb(log.Origin): suite_run = None @@ -51,6 +51,10 @@ if not os.path.isdir(lib): raise RuntimeError('No lib/ in %r' % inst) + iface = util.ip_to_iface(self.addr()) + pcaprecorder.PcapRecorder(self.suite_run, self.run_dir.new_dir('pcap'), + iface, self.addr()) + env = { 'LD_LIBRARY_PATH': util.prepend_library_path(lib) } self.dbg(run_dir=self.run_dir, binary=binary, env=env) diff --git a/src/osmo_gsm_tester/pcaprecorder.py b/src/osmo_gsm_tester/pcaprecorder.py new file mode 100644 index 0000000..8a63b30 --- /dev/null +++ b/src/osmo_gsm_tester/pcaprecorder.py @@ -0,0 +1,59 @@ +# osmo_gsm_tester: specifics for running an osmo-nitb +# +# Copyright (C) 2016-2017 by sysmocom - s.f.m.c. GmbH +# +# Author: Pau Espin Pedrol <pes...@sysmocom.de> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +import os +import random +import re +import socket + +from . import log, util, config, template, process, osmo_ctrl + +class PcapRecorder(log.Origin): + + def __init__(self, suite_run, run_dir, iface=None, addr=None): + self.suite_run = suite_run + self.run_dir = run_dir + self.iface = iface + if not self.iface: + self.iface = "any" + self.addr = addr + self.set_log_category(log.C_RUN) + self.set_name('pcap-recorder_%s' % self.iface) + self.start() + + def start(self): + self.log('Recording pcap', self.run_dir, self.gen_filter()) + dumpfile = os.path.join(os.path.abspath(self.run_dir), self.name() + ".pcap") + self.process = process.Process(self.name(), self.run_dir, + ('tcpdump', '-n', + '-i', self.iface, + '-w', dumpfile, + self.gen_filter()) + ) + self.suite_run.remember_to_stop(self.process) + self.process.launch() + + def gen_filter(self): + filter = "" + if self.addr: + filter += 'host ' + self.addr + return filter + + def running(self): + return not self.process.terminated() diff --git a/src/osmo_gsm_tester/util.py b/src/osmo_gsm_tester/util.py index 9a4e728..12cdf2b 100644 --- a/src/osmo_gsm_tester/util.py +++ b/src/osmo_gsm_tester/util.py @@ -30,7 +30,7 @@ import fcntl import tty import readline - +import subprocess def prepend_library_path(path): lp = os.getenv('LD_LIBRARY_PATH') @@ -38,6 +38,17 @@ return path return path + ':' + lp +def ip_to_iface(ip): + try: + for iface in os.listdir('/sys/class/net'): + proc = subprocess.Popen(['ip', 'addr', 'show', 'dev', iface], stdout=subprocess.PIPE, universal_newlines=True) + for line in proc.stdout.readlines(): + if 'inet' in line and ' ' + ip + '/' in line: + return iface + except Exception as e: + pass + return None + class listdict: 'a dict of lists { "a": [1, 2, 3], "b": [1, 2] }' def __getattr__(ld, name): -- To view, visit https://gerrit.osmocom.org/2541 To unsubscribe, visit https://gerrit.osmocom.org/settings Gerrit-MessageType: newpatchset Gerrit-Change-Id: I4c5d0e2d9857160f905e743517e744f1a06368af Gerrit-PatchSet: 3 Gerrit-Project: osmo-gsm-tester Gerrit-Branch: master Gerrit-Owner: Pau Espin Pedrol <pes...@sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: Neels Hofmeyr <nhofm...@sysmocom.de> Gerrit-Reviewer: Pau Espin Pedrol <pes...@sysmocom.de> Gerrit-Reviewer: neels <nhofm...@sysmocom.de>