From patchwork Mon Feb 10 15:06:19 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Coelho X-Patchwork-Id: 318786 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from maxx.maxx.shmoo.com (maxx.shmoo.com [205.134.188.171]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3041E2C0091 for ; Tue, 11 Feb 2014 02:06:43 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 541C59C10E; Mon, 10 Feb 2014 10:06:41 -0500 (EST) X-Virus-Scanned: amavisd-new at maxx.shmoo.com Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PSJMb641vK+A; Mon, 10 Feb 2014 10:06:41 -0500 (EST) Received: from maxx.shmoo.com (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 372E19C10B; Mon, 10 Feb 2014 10:06:36 -0500 (EST) X-Original-To: mailman-post+hostap@maxx.shmoo.com Delivered-To: mailman-post+hostap@maxx.shmoo.com Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id AA1429C10B for ; Mon, 10 Feb 2014 10:06:32 -0500 (EST) X-Virus-Scanned: amavisd-new at maxx.shmoo.com Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id fN43Kss6gr8s for ; Mon, 10 Feb 2014 10:06:27 -0500 (EST) Received: from emh06.mail.saunalahti.fi (emh06.mail.saunalahti.fi [62.142.5.116]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "emh06.mail.saunalahti.fi", Issuer "emh06.mail.saunalahti.fi" (not verified)) by maxx.maxx.shmoo.com (Postfix) with ESMTPS id DCDE39C105 for ; Mon, 10 Feb 2014 10:06:26 -0500 (EST) Received: from porter.coelho.fi (a88-113-225-236.elisa-laajakaista.fi [88.113.225.236]) by emh06.mail.saunalahti.fi (Postfix) with ESMTP id 50FA1699FD; Mon, 10 Feb 2014 17:06:21 +0200 (EET) From: Luciano Coelho To: hostap@lists.shmoo.com Subject: [PATCH v2] hwsim tests: add support for the chanctx flag when creating radios Date: Mon, 10 Feb 2014 17:06:19 +0200 Message-Id: <1392044779-28372-1-git-send-email-luca@coelho.fi> X-Mailer: git-send-email 1.8.5.3 Cc: j@w1.fi, johannes@sipsolutions.net X-BeenThere: hostap@lists.shmoo.com X-Mailman-Version: 2.1.11 Precedence: list List-Id: HostAP Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: hostap-bounces@lists.shmoo.com Errors-To: hostap-bounces@lists.shmoo.com From: Luciano Coelho Add a new option to set the use_chanctx flag when creating a radio. While at it, refactor the arguments parsing code to use argparse. Signed-hostap: Luciano Coelho --- In v2: * use chanctx=False by default in create_radio() (thanks Johannes) --- tests/hwsim/hwsim.py | 47 +++++++++++++++++++++++++++++++++++++---------- tests/hwsim/netlink.py | 4 ++++ 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/tests/hwsim/hwsim.py b/tests/hwsim/hwsim.py index 55fa0c1..e9856e6 100644 --- a/tests/hwsim/hwsim.py +++ b/tests/hwsim/hwsim.py @@ -15,6 +15,7 @@ HWSIM_CMD_DESTROY_RADIO = 5 HWSIM_ATTR_CHANNELS = 9 HWSIM_ATTR_RADIO_ID = 10 +HWSIM_ATTR_USE_CHANCTX = 15 # the controller class class HWSimController(object): @@ -22,10 +23,13 @@ class HWSimController(object): self._conn = netlink.Connection(netlink.NETLINK_GENERIC) self._fid = netlink.genl_controller.get_family_id('MAC80211_HWSIM') - def create_radio(self, n_channels=None): + def create_radio(self, n_channels=None, use_chanctx=False): attrs = [] if n_channels: attrs.append(netlink.U32Attr(HWSIM_ATTR_CHANNELS, n_channels)) + if use_chanctx: + attrs.append(netlink.FlagAttr(HWSIM_ATTR_USE_CHANCTX)) + msg = netlink.GenlMessage(self._fid, HWSIM_CMD_CREATE_RADIO, flags = netlink.NLM_F_REQUEST | netlink.NLM_F_ACK, @@ -40,14 +44,37 @@ class HWSimController(object): attrs = attrs) msg.send_and_recv(self._conn) +def create(args): + print 'Created radio %d' % c.create_radio(n_channels=args.channels, + use_chanctx=args.chanctx) + +def destroy(args): + print c.destroy_radio(args.radio) + if __name__ == '__main__': - import sys + import argparse c = HWSimController() - if sys.argv[1] == 'create': - if len(sys.argv) > 2: - n_channels = int(sys.argv[2]) - else: - n_channels = 0 - print 'Created radio %d' % c.create_radio(n_channels=n_channels) - elif sys.argv[1] == 'destroy': - print c.destroy_radio(int(sys.argv[2])) + + parser = argparse.ArgumentParser(description='send hwsim control commands') + subparsers = parser.add_subparsers(help="Commands", dest='command') + parser_create = subparsers.add_parser('create', help='create a radio') + parser_create.add_argument('--channels', metavar='', type=int, + default=0, + help='Number of concurrent channels supported by the radio. ' + + 'If not specified, the number of channels specified in ' + + 'the mac80211_hwsim.channels module parameter is used') + parser_create.add_argument('--chanctx', action="store_true", + help='Use channel contexts, regardless of whether the number of ' + + 'channels is 1 or greater. By default channel contexts ' + + 'are only used if the number of channels is greater than 1.') + parser_create.set_defaults(func=create) + + parser_destroy = subparsers.add_parser('destroy', help='destroy a radio') + parser_destroy.add_argument('radio', metavar='', type=int, + default=0, + help='The number of the radio to be destroyed ' + + '(ie. 0 for phy0, 1 for phy1...)') + parser_destroy.set_defaults(func=destroy) + + args = parser.parse_args() + args.func(args) diff --git a/tests/hwsim/netlink.py b/tests/hwsim/netlink.py index 835c709..82b6fa2 100644 --- a/tests/hwsim/netlink.py +++ b/tests/hwsim/netlink.py @@ -69,6 +69,10 @@ class U8Attr(Attr): def __init__(self, attr_type, val): Attr.__init__(self, attr_type, "B", val) +class FlagAttr(Attr): + def __init__(self, attr_type): + Attr.__init__(self, attr_type, "") + class Nested(Attr): def __init__(self, attr_type, attrs): self.attrs = attrs