examples/ip_pipeline: move config files to separate directory
[dpdk.git] / examples / qos_sched / cfg_file.c
old mode 100755 (executable)
new mode 100644 (file)
index e8c481e..595e70b
@@ -1,13 +1,13 @@
 /*-
  *   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
@@ -17,7 +17,7 @@
  *     * 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
@@ -152,7 +152,7 @@ cfg_load(const char *filename, int flags)
                                goto error1;
                        }
 
-                       rte_snprintf(cfg->sections[curr_section]->name,
+                       snprintf(cfg->sections[curr_section]->name,
                                        sizeof(cfg->sections[0]->name),
                                        "%s", &buffer[1]);
                }
@@ -189,8 +189,8 @@ cfg_load(const char *filename, int flags)
                        }
 
                        struct cfg_entry *entry = sect->entries[curr_entry];
-                       rte_snprintf(entry->name, sizeof(entry->name), "%s", split[0]);
-                       rte_snprintf(entry->value, sizeof(entry->value), "%s", split[1]);
+                       snprintf(entry->name, sizeof(entry->name), "%s", split[0]);
+                       snprintf(entry->value, sizeof(entry->value), "%s", split[1]);
                        _strip(entry->name, strnlen(entry->name, sizeof(entry->name)));
                        _strip(entry->value, strnlen(entry->value, sizeof(entry->value)));
                }
@@ -233,92 +233,7 @@ int cfg_close(struct cfg_file *cfg)
 }
 
 int
-cfg_num_sections(struct cfg_file *cfg, const char *sectionname, size_t length)
-{
-       int i;
-       int num_sections = 0;
-       for (i = 0; i < cfg->num_sections; i++) {
-               if (strncmp(cfg->sections[i]->name, sectionname, length) == 0)
-                       num_sections++;
-       }
-       return num_sections;
-}
-
-int
-cfg_sections(struct cfg_file *cfg, char *sections[], int max_sections)
-{
-       int i;
-       for (i = 0; i < cfg->num_sections && i < max_sections; i++) {
-               rte_snprintf(sections[i], CFG_NAME_LEN, "%s",  cfg->sections[i]->name);
-       }
-       return i;
-}
-
-static const struct cfg_section *
-_get_section(struct cfg_file *cfg, const char *sectionname)
-{
-       int i;
-       for (i = 0; i < cfg->num_sections; i++) {
-               if (strncmp(cfg->sections[i]->name, sectionname,
-                               sizeof(cfg->sections[0]->name)) == 0)
-                       return cfg->sections[i];
-       }
-       return NULL;
-}
-
-int
-cfg_has_section(struct cfg_file *cfg, const char *sectionname)
-{
-       return (_get_section(cfg, sectionname) != NULL);
-}
-
-int
-cfg_section_num_entries(struct cfg_file *cfg, const char *sectionname)
-{
-       const struct cfg_section *s = _get_section(cfg, sectionname);
-       if (s == NULL)
-               return -1;
-       return s->num_entries;
-}
-
-
-int
-cfg_section_entries(struct cfg_file *cfg, const char *sectionname,
-               struct cfg_entry *entries, int max_entries)
-{
-       int i;
-       const struct cfg_section *sect = _get_section(cfg, sectionname);
-       if (sect == NULL)
-               return -1;
-       for (i = 0; i < max_entries && i < sect->num_entries; i++)
-               entries[i] = *sect->entries[i];
-       return i;
-}
-
-const char *
-cfg_get_entry(struct cfg_file *cfg, const char *sectionname,
-               const char *entryname)
-{
-       int i;
-       const struct cfg_section *sect = _get_section(cfg, sectionname);
-       if (sect == NULL)
-               return NULL;
-       for (i = 0; i < sect->num_entries; i++)
-               if (strncmp(sect->entries[i]->name, entryname, CFG_NAME_LEN) == 0)
-                       return sect->entries[i]->value;
-       return NULL;
-}
-
-int
-cfg_has_entry(struct cfg_file *cfg, const char *sectionname,
-               const char *entryname)
-{
-       return (cfg_get_entry(cfg, sectionname, entryname) != NULL);
-}
-
-
-int
-cfg_load_port(struct cfg_file *cfg, struct rte_sched_port_params *port_params)
+cfg_load_port(struct rte_cfgfile *cfg, struct rte_sched_port_params *port_params)
 {
        const char *entry;
        int j;
@@ -326,22 +241,22 @@ cfg_load_port(struct cfg_file *cfg, struct rte_sched_port_params *port_params)
        if (!cfg || !port_params)
                return -1;
 
-       entry = cfg_get_entry(cfg, "port", "frame overhead");
+       entry = rte_cfgfile_get_entry(cfg, "port", "frame overhead");
        if (entry)
                port_params->frame_overhead = (uint32_t)atoi(entry);
 
-       entry = cfg_get_entry(cfg, "port", "number of subports per port");
+       entry = rte_cfgfile_get_entry(cfg, "port", "number of subports per port");
        if (entry)
                port_params->n_subports_per_port = (uint32_t)atoi(entry);
-       
-       entry = cfg_get_entry(cfg, "port", "number of pipes per subport");
+
+       entry = rte_cfgfile_get_entry(cfg, "port", "number of pipes per subport");
        if (entry)
                port_params->n_pipes_per_subport = (uint32_t)atoi(entry);
 
-       entry = cfg_get_entry(cfg, "port", "queue sizes");
+       entry = rte_cfgfile_get_entry(cfg, "port", "queue sizes");
        if (entry) {
                char *next;
-               
+
                for(j = 0; j < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; j++) {
                        port_params->qsize[j] = (uint16_t)strtol(entry, &next, 10);
                        if (next == NULL)
@@ -355,8 +270,8 @@ cfg_load_port(struct cfg_file *cfg, struct rte_sched_port_params *port_params)
                char str[32];
 
                /* Parse WRED min thresholds */
-               rte_snprintf(str, sizeof(str), "tc %d wred min", j);
-               entry = cfg_get_entry(cfg, "red", str);
+               snprintf(str, sizeof(str), "tc %d wred min", j);
+               entry = rte_cfgfile_get_entry(cfg, "red", str);
                if (entry) {
                        char *next;
                        int k;
@@ -371,8 +286,8 @@ cfg_load_port(struct cfg_file *cfg, struct rte_sched_port_params *port_params)
                }
 
                /* Parse WRED max thresholds */
-               rte_snprintf(str, sizeof(str), "tc %d wred max", j);
-               entry = cfg_get_entry(cfg, "red", str);
+               snprintf(str, sizeof(str), "tc %d wred max", j);
+               entry = rte_cfgfile_get_entry(cfg, "red", str);
                if (entry) {
                        char *next;
                        int k;
@@ -387,8 +302,8 @@ cfg_load_port(struct cfg_file *cfg, struct rte_sched_port_params *port_params)
                }
 
                /* Parse WRED inverse mark probabilities */
-               rte_snprintf(str, sizeof(str), "tc %d wred inv prob", j);
-               entry = cfg_get_entry(cfg, "red", str);
+               snprintf(str, sizeof(str), "tc %d wred inv prob", j);
+               entry = rte_cfgfile_get_entry(cfg, "red", str);
                if (entry) {
                        char *next;
                        int k;
@@ -404,8 +319,8 @@ cfg_load_port(struct cfg_file *cfg, struct rte_sched_port_params *port_params)
                }
 
                /* Parse WRED EWMA filter weights */
-               rte_snprintf(str, sizeof(str), "tc %d wred weight", j);
-               entry = cfg_get_entry(cfg, "red", str);
+               snprintf(str, sizeof(str), "tc %d wred weight", j);
+               entry = rte_cfgfile_get_entry(cfg, "red", str);
                if (entry) {
                        char *next;
                        int k;
@@ -420,12 +335,12 @@ cfg_load_port(struct cfg_file *cfg, struct rte_sched_port_params *port_params)
                }
        }
 #endif /* RTE_SCHED_RED */
-       
+
        return 0;
 }
 
 int
-cfg_load_pipe(struct cfg_file *cfg, struct rte_sched_pipe_params *pipe_params)
+cfg_load_pipe(struct rte_cfgfile *cfg, struct rte_sched_pipe_params *pipe_params)
 {
        int i, j;
        char *next;
@@ -435,48 +350,48 @@ cfg_load_pipe(struct cfg_file *cfg, struct rte_sched_pipe_params *pipe_params)
        if (!cfg || !pipe_params)
                return -1;
 
-       profiles = cfg_num_sections(cfg, "pipe profile", sizeof("pipe profile") - 1);
+       profiles = rte_cfgfile_num_sections(cfg, "pipe profile", sizeof("pipe profile") - 1);
        port_params.n_pipe_profiles = profiles;
 
        for (j = 0; j < profiles; j++) {
                char pipe_name[32];
-               rte_snprintf(pipe_name, sizeof(pipe_name), "pipe profile %d", j);
+               snprintf(pipe_name, sizeof(pipe_name), "pipe profile %d", j);
 
-               entry = cfg_get_entry(cfg, pipe_name, "tb rate");
+               entry = rte_cfgfile_get_entry(cfg, pipe_name, "tb rate");
                if (entry)
                        pipe_params[j].tb_rate = (uint32_t)atoi(entry);
 
-               entry = cfg_get_entry(cfg, pipe_name, "tb size");
+               entry = rte_cfgfile_get_entry(cfg, pipe_name, "tb size");
                if (entry)
                        pipe_params[j].tb_size = (uint32_t)atoi(entry);
 
-               entry = cfg_get_entry(cfg, pipe_name, "tc period");
+               entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc period");
                if (entry)
                        pipe_params[j].tc_period = (uint32_t)atoi(entry);
 
-               entry = cfg_get_entry(cfg, pipe_name, "tc 0 rate");
+               entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 0 rate");
                if (entry)
                        pipe_params[j].tc_rate[0] = (uint32_t)atoi(entry);
-                       
-               entry = cfg_get_entry(cfg, pipe_name, "tc 1 rate");
+
+               entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 1 rate");
                if (entry)
                        pipe_params[j].tc_rate[1] = (uint32_t)atoi(entry);
-                       
-               entry = cfg_get_entry(cfg, pipe_name, "tc 2 rate");
+
+               entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 2 rate");
                if (entry)
                        pipe_params[j].tc_rate[2] = (uint32_t)atoi(entry);
-                       
-               entry = cfg_get_entry(cfg, pipe_name, "tc 3 rate");
+
+               entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 3 rate");
                if (entry)
                        pipe_params[j].tc_rate[3] = (uint32_t)atoi(entry);
 
 #ifdef RTE_SCHED_SUBPORT_TC_OV
-               entry = cfg_get_entry(cfg, pipe_name, "tc 3 oversubscription weight");
+               entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 3 oversubscription weight");
                if (entry)
                        pipe_params[j].tc_ov_weight = (uint8_t)atoi(entry);
 #endif
 
-               entry = cfg_get_entry(cfg, pipe_name, "tc 0 wrr weights");
+               entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 0 wrr weights");
                if (entry) {
                        for(i = 0; i < RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS; i++) {
                                pipe_params[j].wrr_weights[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE*0 + i] =
@@ -486,7 +401,7 @@ cfg_load_pipe(struct cfg_file *cfg, struct rte_sched_pipe_params *pipe_params)
                                entry = next;
                        }
                }
-               entry = cfg_get_entry(cfg, pipe_name, "tc 1 wrr weights");
+               entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 1 wrr weights");
                if (entry) {
                        for(i = 0; i < RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS; i++) {
                                pipe_params[j].wrr_weights[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE*1 + i] =
@@ -496,7 +411,7 @@ cfg_load_pipe(struct cfg_file *cfg, struct rte_sched_pipe_params *pipe_params)
                                entry = next;
                        }
                }
-               entry = cfg_get_entry(cfg, pipe_name, "tc 2 wrr weights");
+               entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 2 wrr weights");
                if (entry) {
                        for(i = 0; i < RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS; i++) {
                                pipe_params[j].wrr_weights[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE*2 + i] =
@@ -506,7 +421,7 @@ cfg_load_pipe(struct cfg_file *cfg, struct rte_sched_pipe_params *pipe_params)
                                entry = next;
                        }
                }
-               entry = cfg_get_entry(cfg, pipe_name, "tc 3 wrr weights");
+               entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 3 wrr weights");
                if (entry) {
                        for(i = 0; i < RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS; i++) {
                                pipe_params[j].wrr_weights[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE*3 + i] =
@@ -521,7 +436,7 @@ cfg_load_pipe(struct cfg_file *cfg, struct rte_sched_pipe_params *pipe_params)
 }
 
 int
-cfg_load_subport(struct cfg_file *cfg, struct rte_sched_subport_params *subport_params)
+cfg_load_subport(struct rte_cfgfile *cfg, struct rte_sched_subport_params *subport_params)
 {
        const char *entry;
        int i, j, k;
@@ -533,41 +448,41 @@ cfg_load_subport(struct cfg_file *cfg, struct rte_sched_subport_params *subport_
 
        for (i = 0; i < MAX_SCHED_SUBPORTS; i++) {
                char sec_name[CFG_NAME_LEN];
-               rte_snprintf(sec_name, sizeof(sec_name), "subport %d", i);
+               snprintf(sec_name, sizeof(sec_name), "subport %d", i);
 
-               if (cfg_has_section(cfg, sec_name)) {
-                       entry = cfg_get_entry(cfg, sec_name, "tb rate");
+               if (rte_cfgfile_has_section(cfg, sec_name)) {
+                       entry = rte_cfgfile_get_entry(cfg, sec_name, "tb rate");
                        if (entry)
                                subport_params[i].tb_rate = (uint32_t)atoi(entry);
 
-                       entry = cfg_get_entry(cfg, sec_name, "tb size");
+                       entry = rte_cfgfile_get_entry(cfg, sec_name, "tb size");
                        if (entry)
                                subport_params[i].tb_size = (uint32_t)atoi(entry);
 
-                       entry = cfg_get_entry(cfg, sec_name, "tc period");
+                       entry = rte_cfgfile_get_entry(cfg, sec_name, "tc period");
                        if (entry)
                                subport_params[i].tc_period = (uint32_t)atoi(entry);
 
-                       entry = cfg_get_entry(cfg, sec_name, "tc 0 rate");
+                       entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 0 rate");
                        if (entry)
                                subport_params[i].tc_rate[0] = (uint32_t)atoi(entry);
 
-                       entry = cfg_get_entry(cfg, sec_name, "tc 1 rate");
+                       entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 1 rate");
                        if (entry)
                                subport_params[i].tc_rate[1] = (uint32_t)atoi(entry);
 
-                       entry = cfg_get_entry(cfg, sec_name, "tc 2 rate");
+                       entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 2 rate");
                        if (entry)
                                subport_params[i].tc_rate[2] = (uint32_t)atoi(entry);
 
-                       entry = cfg_get_entry(cfg, sec_name, "tc 3 rate");
+                       entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 3 rate");
                        if (entry)
                                subport_params[i].tc_rate[3] = (uint32_t)atoi(entry);
 
-                       int n_entries = cfg_section_num_entries(cfg, sec_name);
-                       struct cfg_entry entries[n_entries];
+                       int n_entries = rte_cfgfile_section_num_entries(cfg, sec_name);
+                       struct rte_cfgfile_entry entries[n_entries];
 
-                       cfg_section_entries(cfg, sec_name, entries, n_entries);
+                       rte_cfgfile_section_entries(cfg, sec_name, entries, n_entries);
 
                        for (j = 0; j < n_entries; j++) {
                                if (strncmp("pipe", entries[j].name, sizeof("pipe") - 1) == 0) {
@@ -592,9 +507,9 @@ cfg_load_subport(struct cfg_file *cfg, struct rte_sched_subport_params *subport_
                                        for (k = begin; k <= end; k++) {
                                                char profile_name[CFG_NAME_LEN];
 
-                                               rte_snprintf(profile_name, sizeof(profile_name),
+                                               snprintf(profile_name, sizeof(profile_name),
                                                                "pipe profile %d", profile);
-                                               if (cfg_has_section(cfg, profile_name))
+                                               if (rte_cfgfile_has_section(cfg, profile_name))
                                                        app_pipe_to_profile[i][k] = profile;
                                                else
                                                        rte_exit(EXIT_FAILURE, "Wrong pipe profile %s\n",
@@ -608,5 +523,3 @@ cfg_load_subport(struct cfg_file *cfg, struct rte_sched_subport_params *subport_
 
        return 0;
 }
-
-