From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id 5CBA8AD9D for ; Wed, 4 Feb 2015 07:44:02 +0100 (CET) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP; 03 Feb 2015 22:40:30 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.09,517,1418112000"; d="scan'208";a="680600815" Received: from shvmail01.sh.intel.com ([10.239.29.42]) by orsmga002.jf.intel.com with ESMTP; 03 Feb 2015 22:44:00 -0800 Received: from shecgisg003.sh.intel.com (shecgisg003.sh.intel.com [10.239.29.90]) by shvmail01.sh.intel.com with ESMTP id t146hv6S005738; Wed, 4 Feb 2015 14:43:57 +0800 Received: from shecgisg003.sh.intel.com (localhost [127.0.0.1]) by shecgisg003.sh.intel.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP id t146hta4019899; Wed, 4 Feb 2015 14:43:57 +0800 Received: (from yliu84x@localhost) by shecgisg003.sh.intel.com (8.13.6/8.13.6/Submit) id t146htJ5019895; Wed, 4 Feb 2015 14:43:55 +0800 From: Yong Liu To: dts@dpdk.org Date: Wed, 4 Feb 2015 14:43:31 +0800 Message-Id: <1423032214-19856-2-git-send-email-yong.liu@intel.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1423032214-19856-1-git-send-email-yong.liu@intel.com> References: <1423032214-19856-1-git-send-email-yong.liu@intel.com> Subject: [dts] [PATCH v2 1/4] framework: add new module for load port configuration file X-BeenThere: dts@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: test suite reviews and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 Feb 2015 06:44:03 -0000 Config module will load port configuration and parse port parameter. Port configuration will be used in the process of setting up DUT. User can assign port mac, numa or tester peer pci address of DUT port. Signed-off-by: Marvinliu --- conf/ports.cfg | 9 +++++ framework/config.py | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 conf/ports.cfg create mode 100755 framework/config.py diff --git a/conf/ports.cfg b/conf/ports.cfg new file mode 100644 index 0000000..55e26d8 --- /dev/null +++ b/conf/ports.cfg @@ -0,0 +1,9 @@ +# DUT Port Configuration +# [DUT IP] +# ports= +# pci=Pci BDF,intf=Kernel interface; +# pci=Pci BDF,mac=Mac address,peer=Tester Pci BDF,numa=Port Numa +[DUT IP] +ports = + pci=XX:XX.X,intf=eth0 + pci=YY:YY.Y,mac=XX:XX:XX:XX:XX:XX,peer=ZZ:ZZ.Z,numa=0 diff --git a/framework/config.py b/framework/config.py new file mode 100755 index 0000000..dc4f944 --- /dev/null +++ b/framework/config.py @@ -0,0 +1,96 @@ +# BSD LICENSE +# +# Copyright(c) 2010-2014 Intel Corporation. All rights reserved. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Intel Corporation nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +""" +Generic port and crbs configuration file load function +""" + +import ConfigParser # config parse module +import argparse # prase arguments module + +portconf = "../conf/ports.cfg" +crbconf = "../conf/crbs.cfg" + + +class UserConf(): + + def __init__(self, port_conf=portconf, crb_conf=crbconf): + self.port_config = port_conf + self.crb_config = crb_conf + self.ports_cfg = {} + try: + self.port_conf = ConfigParser.SafeConfigParser() + self.port_conf.read(self.port_config) + except Exception as e: + print "FAILED LOADING PORT CONFIG!!!" + + def load_ports_config(self, crbIP): + ports = [] + for crb in self.port_conf.sections(): + if crb != crbIP: + continue + ports = [port.strip() + for port in self.port_conf.get(crb, 'ports').split(';')] + + for port in ports: + port_cfg = self.parse_port_param(port) + if 'pci' not in port_cfg: + print "INVALID CONFIG FOR NO PCI ADDRESS!!!" + keys = port_cfg.keys() + keys.remove('pci') + self.ports_cfg[port_cfg['pci']] = {key: port_cfg[key] for key in keys} + + def check_port_available(self, pci_addr): + if pci_addr in self.ports_cfg.keys(): + return True + else: + return False + + def parse_port_param(self, port): + portDict = dict() + + for param in port.split(','): + (key, _, value) = param.partition('=') + if key == 'numa': + portDict[key] = int(value) + else: + portDict[key] = value + return portDict + + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description="Load DTS configuration files") + parser.add_argument("-p", "--portconf", default=portconf) + parser.add_argument("-c", "--crbconf", default=crbconf) + args = parser.parse_args() + conf = UserConf() + conf.load_ports_config('192.168.1.1') + conf.check_port_available('0000:86:00.0') -- 1.9.3