From patchwork Fri Apr 29 05:07:34 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: 616605 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2001:1868:205::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 3qx1v02DWXz9t50 for ; Fri, 29 Apr 2016 15:08:44 +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=BRxiGgtW; 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 1aw0fM-0001n0-Qr; Fri, 29 Apr 2016 05:08:36 +0000 Received: from mail-lf0-x22b.google.com ([2a00:1450:4010:c07::22b]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aw0fH-0001iT-3U for hostap@lists.infradead.org; Fri, 29 Apr 2016 05:08:33 +0000 Received: by mail-lf0-x22b.google.com with SMTP id u64so106290761lff.3 for ; Thu, 28 Apr 2016 22:08:10 -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=wn1p0CMkO89HSf4dgoXdxitZ7KanFzpq+TZX3TS2/k4=; b=BRxiGgtWaXHEe01pgIp3tL7IVr26p/JQwWQvof+PjJSJ8CDFVNY/0dDJBgMH+8JCiP wMe9bBnPYg9mpT3Xj3i7Qu2VMnEaQM9n0qYgQQTT20rUahz7JrSc7ZEQSfox3bdu7wLx CN27if18A/rMC+H6Av2LWAylNQSVXn6FgkW1E= 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=wn1p0CMkO89HSf4dgoXdxitZ7KanFzpq+TZX3TS2/k4=; b=Ji5KNkg0It+X4dJMm4Kx/VbUJmHmF849jXZOvK4pULRwklWP5ZaG0J2+NPoCaHuzgZ FThWPTkoTVfnu8IM20OtNArZMLPtjxR1yLdtE8UN/eFAp0ZUy1SXgbwTC6tofwetvQC1 5XWhJufA21uhw6hTqXvsNjazP1aTIp9tgCqfVDyINrF/XruR1KXWpRWmd7JFE9Fbsuvc sAdWjioMoJug5EuDY3kL5p5I1euhb5Qocr16yl/Ejj9bPF36bcmHmZbA75uwSzZAHS81 Z589bo+fsZPiR5a0qZjMikvhGYzqbgbF4Sa65NWvAmhgb0mEGwGrfROZ/pjxpf5SSOCK y6rw== X-Gm-Message-State: AOPr4FWHgyX9kdW7hX04C/nfWqIN2gEo4c1SXes2ykCQ4mQ3RnS2uyt+rh5QEfcQyXbAQB5uftCiYXAQGcYjvF28eRmvsqsclVqw3Egy7ijtYO5HOzQN4FqRuR6el316iwTcfl8f6Lq/kcqGWgLBqWvcz18dj/4RoY4YSRzEmQKA7t7rpgXsgVQTgPrywvRL0ZnF X-Received: by 10.112.150.165 with SMTP id uj5mr7910744lbb.95.1461906488857; Thu, 28 Apr 2016 22:08:08 -0700 (PDT) Received: from dell.wifi.local ([91.198.246.8]) by smtp.gmail.com with ESMTPSA id wl7sm2046391lbb.45.2016.04.28.22.08.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 28 Apr 2016 22:08:08 -0700 (PDT) From: Janusz Dziedzic To: hostap@lists.infradead.org Subject: [PATCH v3 3/6] tests/remote: add monitor.py Date: Fri, 29 Apr 2016 07:07:34 +0200 Message-Id: <1461906457-18455-3-git-send-email-janusz.dziedzic@tieto.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1461906457-18455-1-git-send-email-janusz.dziedzic@tieto.com> References: <1461906457-18455-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-20160428_220831_598009_934B5EC5 X-CRM114-Status: GOOD ( 15.62 ) 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:22b 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 6895fc2..f86e972 100644 --- a/tests/hwsim/remotehost.py +++ b/tests/hwsim/remotehost.py @@ -31,6 +31,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: @@ -88,3 +91,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..e278f77 --- /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