test suite reviews and discussions
 help / color / mirror / Atom feed
From: yufengmx <yufengx.mo@intel.com>
To: dts@dpdk.org
Cc: yufengmx <yufengx.mo@intel.com>
Subject: [dts] [next][PATCH V1 6/14] framework/pktgen: packet generator configure file parse
Date: Sun, 28 Apr 2019 10:49:03 +0800	[thread overview]
Message-ID: <1556419751-41723-7-git-send-email-yufengx.mo@intel.com> (raw)
In-Reply-To: <1556419751-41723-1-git-send-email-yufengx.mo@intel.com>

 class

packet generator configure file parse class

Class PktgenConf is used to parse config file pktgen.cfg. Ixia and trex
configuration content can be set in different section. Section name is case insensitive.

Signed-off-by: yufengmx <yufengx.mo@intel.com>
---
 framework/config.py | 107 +++++++++++++++++++++++++++++++++++-----------------
 1 file changed, 72 insertions(+), 35 deletions(-)

diff --git a/framework/config.py b/framework/config.py
index fb23c6e..abb1469 100644
--- a/framework/config.py
+++ b/framework/config.py
@@ -1,6 +1,6 @@
 # BSD LICENSE
 #
-# Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+# Copyright(c) 2010-2019 Intel Corporation. All rights reserved.
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -35,8 +35,9 @@ Generic port and crbs configuration file load function
 import os
 import re
 import ConfigParser  # config parse module
-import argparse      # prase arguments module
-from settings import IXIA, CONFIG_ROOT_PATH, SUITE_SECTION_NAME
+import argparse      # parse arguments module
+from settings import (IXIA, PKTGEN, PKTGEN_DPDK, PKTGEN_TREX, PKTGEN_IXIA,
+                      CONFIG_ROOT_PATH, SUITE_SECTION_NAME)
 from settings import load_global_setting, DTS_CFG_FOLDER
 from exception import ConfigParseException, VirtConfigParseException, PortConfigParseException
 
@@ -89,6 +90,7 @@ class UserConf():
             paramDict[key] = value
         return paramDict
 
+
 class GlobalConf(UserConf):
     def __init__(self):
         self.global_cfg = {}
@@ -115,6 +117,7 @@ class GlobalConf(UserConf):
         
         return global_cfg
         
+        
 class SuiteConf(UserConf):
     def __init__(self, suite_name=""):
         self.suite_cfg = GlobalConf().load_global_config()
@@ -262,6 +265,7 @@ class CrbsConf(UserConf):
     DEF_CRB = {'IP': '', 'board': 'default', 'user': '',
                'pass': '', 'tester IP': '', 'tester pass': '',
                IXIA: None, 'memory channels': 4,
+               PKTGEN: None,
                'bypass core0': True}
 
     def __init__(self, crbs_conf=CRBCONF):
@@ -305,6 +309,8 @@ class CrbsConf(UserConf):
                     if value.lower() == 'none':
                         value = None
                     crb[IXIA] = value
+                elif key == 'pktgen_group':
+                    crb[PKTGEN] = value.lower()
                 elif key == 'channels':
                     crb['memory channels'] = int(value)
                 elif key == 'bypass_core0':
@@ -381,9 +387,9 @@ class IxiaConf(UserConf):
 
 class PktgenConf(UserConf):
 
-    def __init__(self, pktgen_type='dpdk', pktgen_conf=PKTGENCONF):
+    def __init__(self, pktgen_type='ixia', pktgen_conf=PKTGENCONF):
         self.config_file = pktgen_conf
-        self.pktgen_type = pktgen_type
+        self.pktgen_type = pktgen_type.lower()
         self.pktgen_cfg = {}
         try:
             self.pktgen_conf = UserConf(self.config_file)
@@ -391,45 +397,76 @@ class PktgenConf(UserConf):
             self.pktgen_conf = None
             raise ConfigParseException
 
+    def load_pktgen_ixia_config(self, section):
+        port_reg = r'card=(\d+),port=(\d+)'
+        pktgen_confs = self.pktgen_conf.load_section(section)
+        if not pktgen_confs:
+            return
+        # convert file configuration to dts ixiacfg
+        ixia_group = {}
+        for conf in pktgen_confs:
+            key, value = conf
+            if key == 'ixia_version':
+                ixia_group['Version'] = value
+            elif key == 'ixia_ip':
+                ixia_group['IP'] = value
+            elif key == 'ixia_ports':
+                ports = self.pktgen_conf.load_config(value)
+                ixia_ports = []
+                for port in ports:
+                    m = re.match(port_reg, port)
+                    if m:
+                        ixia_port = {}
+                        ixia_port["card"] = int(m.group(1))
+                        ixia_port["port"] = int(m.group(2))
+                        ixia_ports.append(ixia_port)
+                ixia_group['Ports'] = ixia_ports
+            elif key == 'ixia_enable_rsfec':
+                ixia_group['enable_rsfec'] = value
+
+        if 'Version' not in ixia_group:
+            print 'ixia configuration file request ixia_version option!!!'
+            return
+        if 'IP' not in ixia_group:
+            print 'ixia configuration file request ixia_ip option!!!'
+            return
+        if 'Ports' not in ixia_group:
+            print 'ixia configuration file request ixia_ports option!!!'
+            return
+
+        self.pktgen_cfg[section.lower()] = ixia_group
+
     def load_pktgen_config(self):
         sections = self.pktgen_conf.get_sections()
         if not sections:
             return self.pktgen_cfg
 
         for section in sections:
-            if self.pktgen_type=='dpdk':
-                if section == 'PKTGEN DPDK':
-                    pktgen_confs = self.pktgen_conf.load_section(section)
-                    if not pktgen_confs:
-                        continue
-
-                    # covert file configuration to dts pktgen cfg
-                    for conf in pktgen_confs:
-                        key, value = conf
-                        self.pktgen_cfg[key] = value
-            elif self.pktgen_type=='trex':
-                if section == 'TREX':
-                    pktgen_confs = self.pktgen_conf.load_section(section)
-                    if not pktgen_confs:
-                        continue
-
-                    # covert file configuration to dts pktgen cfg
-                    for conf in pktgen_confs:
-                        key, value = conf
-                        self.pktgen_cfg[key] = value
-            elif self.pktgen_type=='ixia':
-                if section == 'IXIA':
-                    pktgen_confs = self.pktgen_conf.load_section(section)
-                    if not pktgen_confs:
-                        continue
-
-                    # covert file configuration to dts pktgen cfg
-                    for conf in pktgen_confs:
-                        key, value = conf
-                        self.pktgen_cfg[key] = value
+            if self.pktgen_type == PKTGEN_DPDK and section.lower() == PKTGEN_DPDK:
+                pktgen_confs = self.pktgen_conf.load_section(section)
+                if not pktgen_confs:
+                    continue
+
+                # covert file configuration to dts pktgen cfg
+                for conf in pktgen_confs:
+                    key, value = conf
+                    self.pktgen_cfg[key] = value
+            elif self.pktgen_type == PKTGEN_TREX and section.lower() == PKTGEN_TREX:
+                pktgen_confs = self.pktgen_conf.load_section(section)
+                if not pktgen_confs:
+                    continue
+
+                # covert file configuration to dts pktgen cfg
+                for conf in pktgen_confs:
+                    key, value = conf
+                    self.pktgen_cfg[key] = value
+            elif self.pktgen_type == PKTGEN_IXIA and section.lower() == PKTGEN_IXIA:
+                # covert file configuration to dts pktgen cfg
+                self.load_pktgen_ixia_config(section)
 
         return self.pktgen_cfg
 
+
 if __name__ == '__main__':
     parser = argparse.ArgumentParser(
         description="Load DTS configuration files")
-- 
1.9.3


  parent reply	other threads:[~2019-04-28  2:45 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-28  2:48 [dts] [next][PATCH V1 0/14] [dts/pktgen]: dts packet generator api yufengmx
2019-04-28  2:48 ` [dts] [next][PATCH V1 1/14] conf/pktgen: add pktgen key word in crbs.cfg yufengmx
2019-04-28  2:48 ` [dts] [next][PATCH V1 2/14] conf/pktgen: packet generator configure file definition yufengmx
2019-04-28  2:49 ` [dts] [next][PATCH V1 3/14] doc/pktgen: trex tool known issues yufengmx
2019-04-28  2:49 ` [dts] [next][PATCH V1 4/14] doc/pktgen: migrate from etgen api to pktgen api yufengmx
2019-04-28  2:49 ` [dts] [next][PATCH V1 5/14] doc/pktgen: pktgen api program guide document yufengmx
2019-04-28  2:49 ` yufengmx [this message]
2019-04-28  2:49 ` [dts] [next][PATCH V1 7/14] framework/pktgen: initialize pktgen logger yufengmx
2019-04-28  2:49 ` [dts] [next][PATCH V1 8/14] framework/pktgen: packet generator base class yufengmx
2019-04-28  2:49 ` [dts] [next][PATCH V1 9/14] framework/pktgen: ixia packet generator relevant classes yufengmx
2019-04-28  2:49 ` [dts] [next][PATCH V1 0/14] framework/pktgen: trex " yufengmx
2019-04-28  2:49 ` [dts] [next][PATCH V1 1/14] framework/pktgen: pktgen instance creation and helper yufengmx
2019-04-28  2:49 ` [dts] [next][PATCH V1 2/14] framework/pktgen: packet generator types definition yufengmx
2019-04-28  2:49 ` [dts] [next][PATCH V1 3/14] framework/pktgen: packet generator init and trex port yufengmx
2019-04-28  2:49 ` [dts] [next][PATCH V1 4/14] framework/pktgen: utils methods yufengmx
2019-05-29  2:45 ` [dts] [next][PATCH V1 0/14] [dts/pktgen]: dts packet generator api Tu, Lijuan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1556419751-41723-7-git-send-email-yufengx.mo@intel.com \
    --to=yufengx.mo@intel.com \
    --cc=dts@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).