blob: 70833d0ef7f9d98fde723dcdb5534c89ef20d717 [file] [log] [blame]
Pau Espin Pedrol13143bc2017-05-08 17:07:28 +02001# osmo_gsm_tester: specifics for running an osmo-nitb
2#
3# Copyright (C) 2016-2017 by sysmocom - s.f.m.c. GmbH
4#
5# Author: Pau Espin Pedrol <pespin@sysmocom.de>
6#
7# This program is free software: you can redistribute it and/or modify
Harald Welte27205342017-06-03 09:51:45 +02008# it under the terms of the GNU General Public License as
Pau Espin Pedrol13143bc2017-05-08 17:07:28 +02009# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Harald Welte27205342017-06-03 09:51:45 +020015# GNU General Public License for more details.
Pau Espin Pedrol13143bc2017-05-08 17:07:28 +020016#
Harald Welte27205342017-06-03 09:51:45 +020017# You should have received a copy of the GNU General Public License
Pau Espin Pedrol13143bc2017-05-08 17:07:28 +020018# along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20import os
21import random
22import re
23import socket
24
25from . import log, util, config, template, process, osmo_ctrl
26
27class PcapRecorder(log.Origin):
28
Pau Espin Pedrol772b2b12018-10-26 15:53:35 +020029 def __init__(self, suite_run, run_dir, iface=None, filters='', netns=None):
Pau Espin Pedrol13143bc2017-05-08 17:07:28 +020030 self.iface = iface
31 if not self.iface:
32 self.iface = "any"
Neels Hofmeyr95fd6732017-05-15 14:03:07 +020033 self.filters = filters
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +020034 super().__init__(log.C_RUN, 'pcap-recorder_%s' % self.iface, filters=self.filters)
35 self.suite_run = suite_run
36 self.run_dir = run_dir
Pau Espin Pedrol772b2b12018-10-26 15:53:35 +020037 self.netns = netns
Pau Espin Pedrol13143bc2017-05-08 17:07:28 +020038 self.start()
39
40 def start(self):
Pau Espin Pedrol2c48c342018-02-23 17:25:39 +010041 self.dbg('Recording pcap', self.run_dir, self.filters)
Pau Espin Pedrol13143bc2017-05-08 17:07:28 +020042 dumpfile = os.path.join(os.path.abspath(self.run_dir), self.name() + ".pcap")
Pau Espin Pedrol772b2b12018-10-26 15:53:35 +020043 popen_args = ('tcpdump', '-n',
44 '-i', self.iface,
45 '-w', dumpfile,
46 self.filters)
47 if self.netns:
48 self.process = process.NetNSProcess(self.name(), self.run_dir, self.netns, popen_args)
49 else:
50 self.process = process.Process(self.name(), self.run_dir, popen_args)
Pau Espin Pedrol13143bc2017-05-08 17:07:28 +020051 self.suite_run.remember_to_stop(self.process)
52 self.process.launch()
53
Pau Espin Pedrol13143bc2017-05-08 17:07:28 +020054 def running(self):
55 return not self.process.terminated()
Neels Hofmeyr143ab812017-05-14 15:43:30 +020056
57# vim: expandtab tabstop=4 shiftwidth=4