[dts] [next][PATCH V1 6/14] framework/pktgen: packet generator configure file parse

yufengmx yufengx.mo at intel.com
Sun Apr 28 04:49:03 CEST 2019


 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 at 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



More information about the dts mailing list