From patchwork Thu Apr 7 05:38:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz.Dziedzic@tieto.com X-Patchwork-Id: 607251 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3qgWcb24QPz9t4T for ; Thu, 7 Apr 2016 15:39:27 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=tieto.com header.i=@tieto.com header.b=Tvx+i8jn; dkim-atps=neutral Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ao2f0-00059d-C1; Thu, 07 Apr 2016 05:39:18 +0000 Received: from mail-lf0-x231.google.com ([2a00:1450:4010:c07::231]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ao2ei-0004z0-KY for hostap@lists.infradead.org; Thu, 07 Apr 2016 05:39:06 +0000 Received: by mail-lf0-x231.google.com with SMTP id c126so49057309lfb.2 for ; Wed, 06 Apr 2016 22:38:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tieto.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=S7ZCO68ibVgyg/5KlrxCcqM40Wi4/ertSZglDUDVt2w=; b=Tvx+i8jnV37cjFyWa8VPCtveNgLEAoet8J/bus7YEjZ978luVijGDly1t2x03XRLtx Wb+19VhcGwVd+zf5H4WpaLamc/W3gJqK0+fxoucZXxfeoYjbf4Wup8Xokv71XhXq1UnO oPWA5OzXOFwworQp5fYxH4hypiyZPSw9HSZiY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=S7ZCO68ibVgyg/5KlrxCcqM40Wi4/ertSZglDUDVt2w=; b=hyTtGnn5z2+dl0Dnga7/41RAazNQUMj36/GOMPU3/jyQ5dzaWpWDxwEGUVg2tnMEoJ j0AizgCGC3NmRA6TiZcqx1Sy+XZ7DbzLsEa5UstUqT6gbnH5yk+4Mfh/W/aHon5hT1v0 6BSxK91DFkF1TS6MP2dqC3HZgRV4uZTTJDUPlp+QmXxrXkoHl82NyjIAYcumKlhaQe4q aqQ4VfhDJ42IXC5d+zGXjBMLhkOgKtYO0lNZtiSjMprh2fkaXF6mRWwg0Ojn8rNqVaxH 9F8439GwHO1N3QQWbPwGDGIJ22gByA5N479vryqdzMUf385DGcAXrViTaOKbPVQP6gTf Rm3A== X-Gm-Message-State: AD7BkJKpyMFe3gz1IxIWuNJ1O8uNZUq0lsgNDlNbaFGk2xeItwCHhniyYNJ1hO4N8Nl2ektIqr6emj3TCJevsfaDMyriTWVkH7KhjFhUdgwG8T+CukNZ+LEpttiVKJSUTc+tCLuB0b3bSsbJ9U8S+k6ICANYdxfKP06brFWIbYcsxjdY73fcHlGltMPgzIBJ6XOV X-Received: by 10.25.146.206 with SMTP id u197mr517427lfd.139.1460007523662; Wed, 06 Apr 2016 22:38:43 -0700 (PDT) Received: from localhost.localdomain ([213.192.73.50]) by smtp.gmail.com with ESMTPSA id f134sm938018lff.34.2016.04.06.22.38.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 06 Apr 2016 22:38:43 -0700 (PDT) From: Janusz Dziedzic To: hostap@lists.infradead.org Subject: [PATCH v2 14/17] tests/remote: add monitor.py Date: Thu, 7 Apr 2016 07:38:12 +0200 Message-Id: <1460007495-17921-14-git-send-email-janusz.dziedzic@tieto.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1460007495-17921-1-git-send-email-janusz.dziedzic@tieto.com> References: <1460007495-17921-1-git-send-email-janusz.dziedzic@tieto.com> X-DomainID: tieto.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160406_223901_340199_F372C43A X-CRM114-Status: GOOD ( 15.83 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2a00:1450:4010:c07:0:0:0:231 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: hostap@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: j@w1.fi, Janusz Dziedzic MIME-Version: 1.0 Sender: "Hostap" Errors-To: hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Add monitor support. This will support monitors added to the current interfaces. This also support standallone monitor with multi interfaces support. This will allow to get logs from different channels at the same time to the one pcap file. Example of t3-monitor added to config.py file. Signed-off-by: Janusz Dziedzic --- tests/hwsim/remotehost.py | 10 +++ tests/remote/config.py | 1 + tests/remote/monitor.py | 177 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 188 insertions(+) create mode 100644 tests/remote/monitor.py diff --git a/tests/hwsim/remotehost.py b/tests/hwsim/remotehost.py index cab2045..f5e88ae 100644 --- a/tests/hwsim/remotehost.py +++ b/tests/hwsim/remotehost.py @@ -32,6 +32,9 @@ class Host(): self.host = host self.name = name self.user = user + self.monitors = [] + self.monitor_thread = None + self.logs = [] self.ifname = ifname self.port = port if self.name == "" and host != None: @@ -97,3 +100,10 @@ class Host(): logger.debug(self.name + " wait_execute_complete(" + wait_str + "): ") if t.isAlive(): t.join(wait) + + def get_logs(self, local_log_dir=None): + for log in self.logs: + if local_log_dir: + self.local_execute("scp " + self.user + "@[" + self.host + "]:" + log + " " + local_log_dir) + self.execute("rm " + log) + del self.logs[:] diff --git a/tests/remote/config.py b/tests/remote/config.py index 89de0fe..44efd2f 100644 --- a/tests/remote/config.py +++ b/tests/remote/config.py @@ -33,6 +33,7 @@ setup_params = {"setup_hw" : "./tests/setup_hw.sh", #devices = [{"hostname": "192.168.254.58", "ifname" : "wlan0", "port": "9877", "name" : "t2-ath9k", "flags" : "AP_HT40 STA_HT40"}, # {"hostname": "192.168.254.58", "ifname" : "wlan1", "port": "9877", "name" : "t2-ath10k", "flags" : "AP_VHT80"}, # {"hostname": "192.168.254.58", "ifname" : "wlan3", "port": "9877", "name" : "t2-intel7260", "flags" : "STA_VHT80"}, +# {"hostname": "192.168.254.55", "ifname" : "wlan0, wlan1, wlan2", "port": "", "name" : "t3-monitor"}, # {"hostname": "192.168.254.50", "ifname" : "wlan0", "port": "9877", "name" : "t1-ath9k"}, # {"hostname": "192.168.254.50", "ifname" : "wlan1", "port": "9877", "name" : "t1-ath10k"}] diff --git a/tests/remote/monitor.py b/tests/remote/monitor.py new file mode 100644 index 0000000..b25e8d7 --- /dev/null +++ b/tests/remote/monitor.py @@ -0,0 +1,177 @@ +# +# Monitor support +# Copyright (c) 2016, Tieto Corporation +# +# This software may be distributed under the terms of the BSD license. +# See README for more details. +import time +from remotehost import Host +import config +import re +import traceback +import logging +logger = logging.getLogger() +import hostapd + +# standalone monitor with multi iface support +def create(devices, setup_params, refs, duts, monitors): + mons= [] + mhosts = [] + hosts = duts + refs + + # choose only standalone monitors + for monitor in monitors: + if monitor not in hosts and monitor != "all": + mons.append(monitor) + + for mon in mons: + dev = config.get_device(devices, mon) + if dev is None: + continue + + host = Host(host = dev['hostname'], + ifname = dev['ifname'], + port = dev['port'], + name = dev['name']) + + try: + host.execute("iw reg set " + setup_params['country']) + setup_hw = setup_params['setup_hw'] + for iface in ifaces: + host.execute(setup_hw + " -I " + iface + " -R 1") + except: + pass + mhosts.append(host) + + return mhosts + +def destroy(devices, hosts): + for host in hosts: + stop(host) + for monitor in host.monitors: + host.execute("ifconfig " + monitor + " down") + +def setup(host, monitor_params): + if host is None: + return + + ifaces = re.split('; | |, ', host.ifname) + count = 0 + for param in monitor_params: + try: + iface = ifaces[count] + except: + logger.debug(traceback.format_exc()) + break + host.execute("ifconfig " + iface + " down") + host.execute("iw " + iface + " set type monitor") + host.execute("ifconfig " + iface + " up") + status, buf = host.execute("iw " + iface + " set freq " + param['freq'] + + " " + param['bw'] + " " + param['center_freq1'] + + " " + param['center_freq2']) + if status != 0: + logger.debug("Could not setup monitor interface: " + buf) + continue + host.monitors.append(iface) + count = count + 1 + +def run(host, setup_params): + monitor_res = [] + log_monitor = "" + if host is None: + return None + if len(host.monitors) == 0: + return None + try: + log_dir = setup_params['log_dir'] + tc_name = setup_params['tc_name'] + except: + return None + + tshark = "tshark" + for monitor in host.monitors: + host.execute("ifconfig " + monitor + " up") + tshark = tshark + " -i " + monitor + log_monitor = log_monitor + "_" + monitor + + log = log_dir + tc_name + "_" + host.name + log_monitor + ".pcap" + host.logs.append(log) + thread = host.execute_run(tshark + " -w " + log, monitor_res) + host.thread = thread + + +def stop(host): + if host is None: + return + if len(host.monitors) == 0: + return + if host.thread is None: + return + + host.execute("killall -s INT tshark") + host.wait_execute_complete(host.thread, 5) + if host.thread.isAlive(): + raise Exception("tshark still alive") + host.thread = None + +# Add monitor to existing interface +def add(host, monitors): + if host is None: + return + + for monitor in monitors: + if monitor != "all" and monitor != host.name: + continue + mon = "mon_" + host.ifname + status, buf = host.execute("iw " + host.ifname + " interface add " + mon + " type monitor") + if status == 0: + host.monitors.append(mon) + host.execute("ifconfig " + mon + " up") + else: + logger.debug("Could not add monitor for " + host.name) + +def remove(host): + stop(host) + for monitor in host.monitors: + host.execute("iw " + monitor + " del") + host.monitors.remove(monitor) + + +# get monitor params from hostapd +def get_monitor_params(hapd): + freq = hapd.get_status_field("freq") + bw = "20" + center_freq1="" + center_freq2="" + + vht_oper_chwidth = hapd.get_status_field("vht_oper_chwidth") + secondary_channel = hapd.get_status_field("secondary_channel") + vht_oper_centr_freq_seg0_idx = hapd.get_status_field("vht_oper_centr_freq_seg0_idx") + vht_oper_centr_freq_seg1_idx = hapd.get_status_field("vht_oper_centr_freq_seg1_idx") + if vht_oper_chwidth == "0" or vht_oper_chwidth is None: + if secondary_channel == "1": + bw = "40" + center_freq1 = str(int(freq) + 10) + elif secondary_channel == "-1": + center_freq1 = str(int(freq) - 10) + else: + pass + elif vht_oper_chwidth == "1": + bw = "80" + center_freq1 = str(int(vht_oper_centr_freq_seg0_idx) * 5 + 5000) + elif vht_oper_chwidth == "2": + bw = "160" + center_freq1 = str(int(vht_oper_centr_freq_seg0_idx) * 5 + 5000) + elif vht_oper_chwidth == "3": + bw = "80+80" + center_freq1 = str(int(vht_oper_centr_freq_seg0_idx) * 5 + 5000) + center_freq2 = str(int(vht_oper_centr_freq_seg1_idx) * 5 + 5000) + else: + pass + + monitor_params = { "freq" : freq, + "bw" : bw, + "center_freq1" : center_freq1, + "center_freq2" : center_freq2 } + + return monitor_params