blob: 8a63b30d346c0786b47dd0d9d46ee73c78bbb3a7 [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
8# it under the terms of the GNU Affero General Public License as
9# 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
15# GNU Affero General Public License for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# 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
29 def __init__(self, suite_run, run_dir, iface=None, addr=None):
30 self.suite_run = suite_run
31 self.run_dir = run_dir
32 self.iface = iface
33 if not self.iface:
34 self.iface = "any"
35 self.addr = addr
36 self.set_log_category(log.C_RUN)
37 self.set_name('pcap-recorder_%s' % self.iface)
38 self.start()
39
40 def start(self):
41 self.log('Recording pcap', self.run_dir, self.gen_filter())
42 dumpfile = os.path.join(os.path.abspath(self.run_dir), self.name() + ".pcap")
43 self.process = process.Process(self.name(), self.run_dir,
44 ('tcpdump', '-n',
45 '-i', self.iface,
46 '-w', dumpfile,
47 self.gen_filter())
48 )
49 self.suite_run.remember_to_stop(self.process)
50 self.process.launch()
51
52 def gen_filter(self):
53 filter = ""
54 if self.addr:
55 filter += 'host ' + self.addr
56 return filter
57
58 def running(self):
59 return not self.process.terminated()