diff options
author | Ole Troan <ot@cisco.com> | 2020-10-07 18:05:37 +0200 |
---|---|---|
committer | Neale Ranns <nranns@cisco.com> | 2020-10-13 11:42:58 +0000 |
commit | 148c7b768721231325a349fa82db693190513b53 (patch) | |
tree | 94e0a9768eda3bc4923b1b3cc727dc637d877381 /src/tools/vppapigen/vppapigen_c.py | |
parent | e7c8396982607634b4c747870499671ffa53868e (diff) |
stats: counters data model
This adds a new data model for counters.
Specifying the errors severity and unit.
A later patch will update vpp_get_stats to take advantage of this.
Only the map plugin is updates as an example.
New .api language:
A new "counters" keyword to define counter sets.
counters map {
none {
severity info;
type counter64;
units "packets";
description "valid MAP packets";
};
bad_protocol {
severity error;
type counter64;
units "packets";
description "bad protocol";
};
};
Each counter has 4 keywords. severity, which is one of error, info or warn.
A type, which is one of counter64 or gauge64.
units, which is a text field using units from YANG.
paths {
"/err/ip4-map" "map";
"/err/ip6-map" "map";
"/err/ip4-t-map" "map";
"/err/ip6-t-map" "map";
};
A new paths keyword that maps the counter-set to a path in the stats segment KV store.
Updated VPP CLI to include severity so user can see error counter severity.
DBGvpp# show errors
Count Node Reason Severity
13 ethernet-input no error error
Type: feature
Signed-off-by: Ole Troan <ot@cisco.com>
Change-Id: Ib2177543f49d4c3aef4d7fa72476cff2068f7771
Signed-off-by: Ole Troan <ot@cisco.com>
Diffstat (limited to 'src/tools/vppapigen/vppapigen_c.py')
-rw-r--r-- | src/tools/vppapigen/vppapigen_c.py | 53 |
1 files changed, 49 insertions, 4 deletions
diff --git a/src/tools/vppapigen/vppapigen_c.py b/src/tools/vppapigen/vppapigen_c.py index 020a880c868..07975ce23b4 100644 --- a/src/tools/vppapigen/vppapigen_c.py +++ b/src/tools/vppapigen/vppapigen_c.py @@ -516,6 +516,22 @@ def generate_include_enum(s, module, stream): write('}} vl_api_{}_enum_t;\n'.format(module)) +def generate_include_counters(s, module, stream): + write = stream.write + + for counters in s: + csetname = counters.name + write('typedef enum {\n') + for c in counters.block: + write(' {}_ERROR_{},\n' + .format(csetname.upper(), c['name'].upper())) + write(' {}_N_ERROR\n'.format(csetname.upper())) + write('}} vl_counter_{}_enum_t;\n'.format(csetname)) + + # write('extern char *{}_error_strings[];\n'.format(csetname)) + # write('extern char *{}_description_strings[];\n'.format(csetname)) + write('extern vl_counter_t {}_error_counters[];\n'.format(csetname)) + # # Generate separate API _types file. # @@ -603,9 +619,10 @@ def generate_include_types(s, module, stream): write("\n#endif\n") -def generate_c_boilerplate(services, defines, file_crc, module, stream): +def generate_c_boilerplate(services, defines, counters, file_crc, + module, stream): write = stream.write - define_hash = {d.name:d for d in defines} + define_hash = {d.name: d for d in defines} hdr = '''\ #define vl_endianfun /* define message structures */ @@ -661,6 +678,30 @@ def generate_c_boilerplate(services, defines, file_crc, module, stream): write(' return msg_id_base;\n') write('}\n') + severity = {'error': 'VL_COUNTER_SEVERITY_ERROR', + 'info': 'VL_COUNTER_SEVERITY_INFO', + 'warn': 'VL_COUNTER_SEVERITY_WARN'} + + for cnt in counters: + csetname = cnt.name + ''' + write('char *{}_error_strings[] = {{\n'.format(csetname)) + for c in cnt.block: + write(' "{}",\n'.format(c['name'])) + write('};\n') + write('char *{}_description_strings[] = {{\n'.format(csetname)) + for c in cnt.block: + write(' "{}",\n'.format(c['description'])) + write('};\n') + ''' + write('vl_counter_t {}_error_counters[] = {{\n'.format(csetname)) + for c in cnt.block: + write(' {\n') + write(' .name = "{}",\n'.format(c['name'])) + write(' .desc = "{}",\n'.format(c['description'])) + write(' .severity = {},\n'.format(severity[c['severity']])) + write(' },\n') + write('};\n') def generate_c_test_boilerplate(services, defines, file_crc, module, plugin, stream): write = stream.write @@ -788,7 +829,11 @@ def run(args, input_filename, s): # Generate separate enum file st = StringIO() + st.write('#ifndef included_{}_api_enum_h\n'.format(modulename)) + st.write('#define included_{}_api_enum_h\n'.format(modulename)) generate_include_enum(s, modulename, st) + generate_include_counters(s['Counters'], modulename, st) + st.write('#endif\n') with open (filename_enum, 'w') as fd: st.seek (0) shutil.copyfileobj (st, fd) @@ -796,8 +841,8 @@ def run(args, input_filename, s): # Generate separate C file st = StringIO() - generate_c_boilerplate(s['Service'], s['Define'], s['file_crc'], - modulename, st) + generate_c_boilerplate(s['Service'], s['Define'], s['Counters'], + s['file_crc'], modulename, st) with open (filename_c, 'w') as fd: st.seek (0) shutil.copyfileobj(st, fd) |