[dts] [Patch V1] framework/config.py: Add the class of parsing the configuration file of packet generator sent this patch on behalf of chen hongli

wang fei feix.y.wang at intel.com
Wed Sep 20 14:03:21 CEST 2017


Signed-off-by: wang fei <feix.y.wang at intel.com>
---
 framework/config.py | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 52 insertions(+), 1 deletion(-)

diff --git a/framework/config.py b/framework/config.py
index 9e514a7..b3106ce 100644
--- a/framework/config.py
+++ b/framework/config.py
@@ -45,7 +45,7 @@ CRBCONF = "%s/crbs.cfg" % CONFIG_ROOT_PATH
 VIRTCONF = "%s/virt_global.cfg" % CONFIG_ROOT_PATH
 IXIACONF = "%s/ixia.cfg" % CONFIG_ROOT_PATH
 SUITECONF_SAMPLE = "%s/suite_sample.cfg" % CONFIG_ROOT_PATH
-
+PKTGENCONF = "%s/pktgen.cfg" % CONFIG_ROOT_PATH
 
 class UserConf():
 
@@ -352,6 +352,57 @@ class IxiaConf(UserConf):
 
         return self.ixia_cfg
 
+class PktgenConf(UserConf):
+
+    def __init__(self, pktgen_type='dpdk', pktgen_conf=PKTGENCONF):
+        self.config_file = pktgen_conf
+        self.pktgen_type = pktgen_type
+        self.pktgen_cfg = {}
+        try:
+            self.pktgen_conf = UserConf(self.config_file)
+        except ConfigParseException:
+            self.pktgen_conf = None
+            raise ConfigParseException
+
+    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
+
+        return self.pktgen_cfg
+
 if __name__ == '__main__':
     parser = argparse.ArgumentParser(
         description="Load DTS configuration files")
-- 
2.7.4



More information about the dts mailing list