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>
diff --git a/src/plugins/cdp/test/test_cdp.py b/src/plugins/cdp/test/test_cdp.py
index 1bc67c4..46751e8 100644
--- a/src/plugins/cdp/test/test_cdp.py
+++ b/src/plugins/cdp/test/test_cdp.py
@@ -108,18 +108,9 @@
self.logger.info(self.vapi.cdp_enable_disable(enable_disable=1))
self.send_packet(self.create_bad_packet(l, v))
- errors = list(self.show_errors())
- self.assertTrue(errors)
-
- expected_errors = False
- for count, node, reason in errors:
- if (node == u'cdp-input' and
- reason == u'cdp packets with bad TLVs' and
- int(count) >= 1):
-
- expected_errors = True
- break
- self.assertTrue(expected_errors, "CDP didn't drop bad packet")
+ err = self.statistics.get_err_counter(
+ '/err/cdp-input/cdp packets with bad TLVs')
+ self.assertTrue(err >= 1, "CDP didn't drop bad packet")
def send_packet(self, packet):
self.logger.debug(ppp("Sending packet:", packet))
@@ -162,12 +153,3 @@
pass
else:
yield port, system
-
- def show_errors(self):
- for pack in self.process_cli("show errors", self.err_ptr):
- try:
- count, node, reason = pack
- except ValueError:
- pass
- else:
- yield count, node, reason
diff --git a/src/plugins/map/ip4_map.c b/src/plugins/map/ip4_map.c
index a488962..1ab5cc2 100644
--- a/src/plugins/map/ip4_map.c
+++ b/src/plugins/map/ip4_map.c
@@ -325,13 +325,6 @@
return frame->n_vectors;
}
-static char *map_error_strings[] = {
-#define _(sym,string) string,
- foreach_map_error
-#undef _
-};
-
-
/* *INDENT-OFF* */
VNET_FEATURE_INIT (ip4_map_feature, static) =
{
@@ -349,7 +342,7 @@
.type = VLIB_NODE_TYPE_INTERNAL,
.n_errors = MAP_N_ERROR,
- .error_strings = map_error_strings,
+ .error_counters = map_error_counters,
.n_next_nodes = IP4_MAP_N_NEXT,
.next_nodes = {
diff --git a/src/plugins/map/ip4_map_t.c b/src/plugins/map/ip4_map_t.c
index 7d16d7a..8ae76f3 100644
--- a/src/plugins/map/ip4_map_t.c
+++ b/src/plugins/map/ip4_map_t.c
@@ -684,12 +684,6 @@
return frame->n_vectors;
}
-static char *map_t_error_strings[] = {
-#define _(sym,string) string,
- foreach_map_error
-#undef _
-};
-
/* *INDENT-OFF* */
VNET_FEATURE_INIT (ip4_map_t_feature, static) = {
.arc_name = "ip4-unicast",
@@ -706,7 +700,7 @@
.type = VLIB_NODE_TYPE_INTERNAL,
.n_errors = MAP_N_ERROR,
- .error_strings = map_t_error_strings,
+ .error_counters = map_error_counters,
.n_next_nodes = IP4_MAPT_FRAGMENTED_N_NEXT,
.next_nodes = {
@@ -727,7 +721,7 @@
.type = VLIB_NODE_TYPE_INTERNAL,
.n_errors = MAP_N_ERROR,
- .error_strings = map_t_error_strings,
+ .error_counters = map_error_counters,
.n_next_nodes = IP4_MAPT_ICMP_N_NEXT,
.next_nodes = {
@@ -748,7 +742,7 @@
.type = VLIB_NODE_TYPE_INTERNAL,
.n_errors = MAP_N_ERROR,
- .error_strings = map_t_error_strings,
+ .error_counters = map_error_counters,
.n_next_nodes = IP4_MAPT_TCP_UDP_N_NEXT,
.next_nodes = {
@@ -769,7 +763,7 @@
.type = VLIB_NODE_TYPE_INTERNAL,
.n_errors = MAP_N_ERROR,
- .error_strings = map_t_error_strings,
+ .error_counters = map_error_counters,
.n_next_nodes = IP4_MAPT_N_NEXT,
.next_nodes = {
diff --git a/src/plugins/map/ip6_map.c b/src/plugins/map/ip6_map.c
index 136f548..1193dda 100644
--- a/src/plugins/map/ip6_map.c
+++ b/src/plugins/map/ip6_map.c
@@ -803,12 +803,6 @@
}
-static char *map_error_strings[] = {
-#define _(sym,string) string,
- foreach_map_error
-#undef _
-};
-
/* *INDENT-OFF* */
VNET_FEATURE_INIT (ip6_map_feature, static) =
{
@@ -826,7 +820,7 @@
.type = VLIB_NODE_TYPE_INTERNAL,
.n_errors = MAP_N_ERROR,
- .error_strings = map_error_strings,
+ .error_counters = map_error_counters,
.n_next_nodes = IP6_MAP_N_NEXT,
.next_nodes = {
@@ -852,7 +846,7 @@
.format_trace = format_ip6_map_post_ip4_reass_trace,
.type = VLIB_NODE_TYPE_INTERNAL,
.n_errors = MAP_N_ERROR,
- .error_strings = map_error_strings,
+ .error_counters = map_error_counters,
.n_next_nodes = IP6_MAP_POST_IP4_REASS_N_NEXT,
.next_nodes = {
[IP6_MAP_POST_IP4_REASS_NEXT_IP4_LOOKUP] = "ip4-lookup",
@@ -870,7 +864,7 @@
.format_trace = format_map_trace, //FIXME
.type = VLIB_NODE_TYPE_INTERNAL,
.n_errors = MAP_N_ERROR,
- .error_strings = map_error_strings,
+ .error_counters = map_error_counters,
.n_next_nodes = IP6_ICMP_RELAY_N_NEXT,
.next_nodes = {
[IP6_ICMP_RELAY_NEXT_IP4_LOOKUP] = "ip4-lookup",
diff --git a/src/plugins/map/ip6_map_t.c b/src/plugins/map/ip6_map_t.c
index 874a14c..861c049 100644
--- a/src/plugins/map/ip6_map_t.c
+++ b/src/plugins/map/ip6_map_t.c
@@ -687,12 +687,6 @@
return frame->n_vectors;
}
-static char *map_t_error_strings[] = {
-#define _(sym, string) string,
- foreach_map_error
-#undef _
-};
-
/* *INDENT-OFF* */
VLIB_REGISTER_NODE(ip6_map_t_fragmented_node) = {
.function = ip6_map_t_fragmented,
@@ -702,7 +696,7 @@
.type = VLIB_NODE_TYPE_INTERNAL,
.n_errors = MAP_N_ERROR,
- .error_strings = map_t_error_strings,
+ .error_counters = map_error_counters,
.n_next_nodes = IP6_MAPT_FRAGMENTED_N_NEXT,
.next_nodes =
@@ -724,7 +718,7 @@
.type = VLIB_NODE_TYPE_INTERNAL,
.n_errors = MAP_N_ERROR,
- .error_strings = map_t_error_strings,
+ .error_counters = map_error_counters,
.n_next_nodes = IP6_MAPT_ICMP_N_NEXT,
.next_nodes =
@@ -746,7 +740,7 @@
.type = VLIB_NODE_TYPE_INTERNAL,
.n_errors = MAP_N_ERROR,
- .error_strings = map_t_error_strings,
+ .error_counters = map_error_counters,
.n_next_nodes = IP6_MAPT_TCP_UDP_N_NEXT,
.next_nodes =
@@ -775,7 +769,7 @@
.type = VLIB_NODE_TYPE_INTERNAL,
.n_errors = MAP_N_ERROR,
- .error_strings = map_t_error_strings,
+ .error_counters = map_error_counters,
.n_next_nodes = IP6_MAPT_N_NEXT,
.next_nodes =
diff --git a/src/plugins/map/map.api b/src/plugins/map/map.api
index fa32978..dfe255b 100644
--- a/src/plugins/map/map.api
+++ b/src/plugins/map/map.api
@@ -349,3 +349,117 @@
bool tc_copy;
u8 tc_class;
};
+
+/*
+ * MAP Error counters/messages
+ */
+counters map {
+ none {
+ severity info;
+ type counter64;
+ units "packets";
+ description "valid MAP packets";
+ };
+ bad_protocol {
+ severity error;
+ type counter64;
+ units "packets";
+ description "bad protocol";
+ };
+ sec_check {
+ severity error;
+ type counter64;
+ units "packets";
+ description "security check failed";
+ };
+ encap_sec_check {
+ severity error;
+ type counter64;
+ units "packets";
+ description "encap security check failed";
+ };
+ decap_sec_check {
+ severity error;
+ type counter64;
+ units "packets";
+ description "decap security check failed";
+ };
+ icmp {
+ severity error;
+ type counter64;
+ units "packets";
+ description "unable to translate ICMP";
+ };
+ icmp_relay {
+ severity error;
+ type counter64;
+ units "packets";
+ description "unable to relay ICMP";
+ };
+ unknown {
+ severity error;
+ type counter64;
+ units "packets";
+ description "unknown";
+ };
+ no_binding {
+ severity error;
+ type counter64;
+ units "packets";
+ description "no binding";
+ };
+ no_domain {
+ severity error;
+ type counter64;
+ units "packets";
+ description "no domain";
+ };
+ fragmented {
+ severity error;
+ type counter64;
+ units "packets";
+ description "packet is a fragment";
+ };
+ fragment_memory {
+ severity error;
+ type counter64;
+ units "packets";
+ description "could not cache fragment";
+ };
+ fragment_malformed {
+ severity error;
+ type counter64;
+ units "packets";
+ description "fragment has unexpected format";
+ };
+ fragment_dropped {
+ severity error;
+ type counter64;
+ units "packets";
+ description "dropped cached fragment";
+ };
+ malformed {
+ severity error;
+ type counter64;
+ units "packets";
+ description "malformed packet";
+ };
+ df_set {
+ severity error;
+ type counter64;
+ units "packets";
+ description "can't fragment, DF set";
+ };
+ time_exceeded {
+ severity error;
+ type counter64;
+ units "packets";
+ description "time exceeded";
+ };
+};
+paths {
+ "/err/ip4-map" "map";
+ "/err/ip6-map" "map";
+ "/err/ip4-t-map" "map";
+ "/err/ip6-t-map" "map";
+};
diff --git a/src/plugins/map/map.h b/src/plugins/map/map.h
index 16fc604..215a832 100644
--- a/src/plugins/map/map.h
+++ b/src/plugins/map/map.h
@@ -23,6 +23,7 @@
#include <vnet/dpo/load_balance.h>
#include "lpm.h"
#include <vppinfra/lock.h>
+#include <map/map.api_enum.h>
#define MAP_SKIP_IP6_LOOKUP 1
@@ -205,37 +206,7 @@
uword ip4_sv_reass_custom_next_index;
} map_main_t;
-/*
- * MAP Error counters/messages
- */
-#define foreach_map_error \
- /* Must be first. */ \
- _(NONE, "valid MAP packets") \
- _(BAD_PROTOCOL, "bad protocol") \
- _(SEC_CHECK, "security check failed") \
- _(ENCAP_SEC_CHECK, "encap security check failed") \
- _(DECAP_SEC_CHECK, "decap security check failed") \
- _(ICMP, "unable to translate ICMP") \
- _(ICMP_RELAY, "unable to relay ICMP") \
- _(UNKNOWN, "unknown") \
- _(NO_BINDING, "no binding") \
- _(NO_DOMAIN, "no domain") \
- _(FRAGMENTED, "packet is a fragment") \
- _(FRAGMENT_MEMORY, "could not cache fragment") \
- _(FRAGMENT_MALFORMED, "fragment has unexpected format")\
- _(FRAGMENT_DROPPED, "dropped cached fragment") \
- _(MALFORMED, "malformed packet") \
- _(DF_SET, "can't fragment, DF set") \
- _(TIME_EXCEEDED, "time exceeded") \
-
-typedef enum
-{
-#define _(sym,str) MAP_ERROR_##sym,
- foreach_map_error
-#undef _
- MAP_N_ERROR,
-} map_error_t;
-
+typedef vl_counter_map_enum_t map_error_t;
u64 map_error_counter_get (u32 node_index, map_error_t map_error);
typedef struct
diff --git a/src/tools/vppapigen/vppapigen.py b/src/tools/vppapigen/vppapigen.py
index fbb0f27..5219bfd 100755
--- a/src/tools/vppapigen/vppapigen.py
+++ b/src/tools/vppapigen/vppapigen.py
@@ -8,7 +8,6 @@
import logging
import binascii
import os
-import sys
from subprocess import Popen, PIPE
assert sys.version_info >= (3, 5), \
@@ -80,6 +79,12 @@
'true': 'TRUE',
'false': 'FALSE',
'union': 'UNION',
+ 'counters': 'COUNTERS',
+ 'paths': 'PATHS',
+ 'units': 'UNITS',
+ 'severity': 'SEVERITY',
+ 'type': 'TYPE',
+ 'description': 'DESCRIPTION',
}
tokens = ['STRING_LITERAL',
@@ -191,7 +196,6 @@
self.manual_print = True
elif f == 'manual_endian':
self.manual_endian = True
-
global_type_add(name, self)
self.vla = vla_is_last_check(name, block)
@@ -413,6 +417,19 @@
return str([self.fieldtype, self.fieldname])
+class Counter():
+ def __init__(self, path, counter):
+ self.type = 'Counter'
+ self.name = path
+ self.block = counter
+
+
+class Paths():
+ def __init__(self, pathset):
+ self.type = 'Paths'
+ self.paths = pathset
+
+
class Coord(object):
""" Coordinates of a syntactic element. Consists of:
- File name
@@ -487,13 +504,68 @@
| import
| enum
| union
- | service'''
+ | service
+ | paths
+ | counters'''
p[0] = p[1]
def p_import(self, p):
'''import : IMPORT STRING_LITERAL ';' '''
p[0] = Import(p[2], revision=self.revision)
+ def p_path_elements(self, p):
+ '''path_elements : path_element
+ | path_elements path_element'''
+ if len(p) == 2:
+ p[0] = p[1]
+ else:
+ if type(p[1]) is dict:
+ p[0] = [p[1], p[2]]
+ else:
+ p[0] = p[1] + [p[2]]
+
+ def p_path_element(self, p):
+ '''path_element : STRING_LITERAL STRING_LITERAL ';' '''
+ p[0] = {'path': p[1], 'counter': p[2]}
+
+ def p_paths(self, p):
+ '''paths : PATHS '{' path_elements '}' ';' '''
+ p[0] = Paths(p[3])
+
+ def p_counters(self, p):
+ '''counters : COUNTERS ID '{' counter_elements '}' ';' '''
+ p[0] = Counter(p[2], p[4])
+
+ def p_counter_elements(self, p):
+ '''counter_elements : counter_element
+ | counter_elements counter_element'''
+ if len(p) == 2:
+ p[0] = p[1]
+ else:
+ if type(p[1]) is dict:
+ p[0] = [p[1], p[2]]
+ else:
+ p[0] = p[1] + [p[2]]
+
+ def p_counter_element(self, p):
+ '''counter_element : ID '{' counter_statements '}' ';' '''
+ p[0] = {**{'name': p[1]}, **p[3]}
+
+ def p_counter_statements(self, p):
+ '''counter_statements : counter_statement
+ | counter_statements counter_statement'''
+ if len(p) == 2:
+ p[0] = p[1]
+ else:
+ p[0] = {**p[1], **p[2]}
+
+ def p_counter_statement(self, p):
+ '''counter_statement : SEVERITY ID ';'
+ | UNITS STRING_LITERAL ';'
+ | DESCRIPTION STRING_LITERAL ';'
+ | TYPE ID ';' '''
+ p[0] = {p[1]: p[2]}
+
def p_service(self, p):
'''service : SERVICE '{' service_statements '}' ';' '''
p[0] = p[3]
@@ -666,9 +738,20 @@
else:
p[0] = {p[1]: p[3]}
+ def p_variable_name(self, p):
+ '''variable_name : ID
+ | TYPE
+ | SEVERITY
+ | DESCRIPTION
+ | COUNTERS
+ | PATHS
+ '''
+ p[0] = p[1]
+
def p_declaration(self, p):
- '''declaration : type_specifier ID ';'
- | type_specifier ID '[' field_options ']' ';' '''
+ '''declaration : type_specifier variable_name ';'
+ | type_specifier variable_name '[' field_options ']' ';'
+ '''
if len(p) == 7:
p[0] = Field(p[1], p[2], p[4])
elif len(p) == 4:
@@ -678,12 +761,12 @@
self.fields.append(p[2])
def p_declaration_array_vla(self, p):
- '''declaration : type_specifier ID '[' ']' ';' '''
+ '''declaration : type_specifier variable_name '[' ']' ';' '''
p[0] = Array(p[1], p[2], 0, modern_vla=True)
def p_declaration_array(self, p):
- '''declaration : type_specifier ID '[' NUM ']' ';'
- | type_specifier ID '[' ID ']' ';' '''
+ '''declaration : type_specifier variable_name '[' NUM ']' ';'
+ | type_specifier variable_name '[' ID ']' ';' '''
if len(p) != 7:
return self._parse_error(
@@ -814,6 +897,8 @@
s['Service'] = []
s['types'] = []
s['Import'] = []
+ s['Counters'] = []
+ s['Paths'] = []
crc = 0
for o in objs:
tname = o.__class__.__name__
@@ -836,6 +921,10 @@
isinstance(o, Using) or
isinstance(o, Union)):
s['types'].append(o)
+ elif (isinstance(o, Counter)):
+ s['Counters'].append(o)
+ elif (isinstance(o, Paths)):
+ s['Paths'].append(o)
else:
if tname not in s:
raise ValueError('Unknown class type: {} {}'
diff --git a/src/tools/vppapigen/vppapigen_c.py b/src/tools/vppapigen/vppapigen_c.py
index 020a880..07975ce 100644
--- a/src/tools/vppapigen/vppapigen_c.py
+++ b/src/tools/vppapigen/vppapigen_c.py
@@ -516,6 +516,22 @@
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 @@
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 @@
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 @@
# 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 @@
# 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)
diff --git a/src/tools/vppapigen/vppapigen_json.py b/src/tools/vppapigen/vppapigen_json.py
index 6e7aaa2..f41bfb0 100644
--- a/src/tools/vppapigen/vppapigen_json.py
+++ b/src/tools/vppapigen/vppapigen_json.py
@@ -1,6 +1,7 @@
# JSON generation
import json
+
def walk_imports(s):
r = []
for e in s:
@@ -8,6 +9,19 @@
return r
+def walk_counters(s, pathset):
+ r = []
+ for e in s:
+ r2 = {'name': e.name, 'elements': e.block}
+ r.append(r2)
+
+ r3 = []
+ for p in pathset:
+ r3.append(p.paths)
+
+ return r, r3
+
+
def walk_enums(s):
r = []
for e in s:
@@ -66,6 +80,7 @@
r.append(d)
return r
+
#
# Plugin entry point
#
@@ -84,4 +99,5 @@
j['aliases'] = {o.name:o.alias for o in s['types'] if o.__class__.__name__ == 'Using'}
j['vl_api_version'] = hex(s['file_crc'])
j['imports'] = walk_imports(i for i in s['Import'])
+ j['counters'], j['paths'] = walk_counters(s['Counters'], s['Paths'])
return json.dumps(j, indent=4, separators=(',', ': '))
diff --git a/src/vlib/drop.c b/src/vlib/drop.c
index e29195a..3971123 100644
--- a/src/vlib/drop.c
+++ b/src/vlib/drop.c
@@ -93,7 +93,7 @@
error_node = vlib_get_node (vm, vlib_error_get_node (&vm->node_main, e[0]));
i = counter_index (vm, vlib_error_get_code (&vm->node_main, e[0])) +
error_node->error_heap_index;
- s = format (s, "%v: %s", error_node->name, em->error_strings_heap[i]);
+ s = format (s, "%v: %s", error_node->name, em->counters_heap[i].name);
return s;
}
diff --git a/src/vlib/error.c b/src/vlib/error.c
index 7357f17..1b3f378 100644
--- a/src/vlib/error.c
+++ b/src/vlib/error.c
@@ -115,7 +115,8 @@
/* Reserves given number of error codes for given node. */
void
vlib_register_errors (vlib_main_t * vm,
- u32 node_index, u32 n_errors, char *error_strings[])
+ u32 node_index, u32 n_errors, char *error_strings[],
+ vl_counter_t counters[])
{
vlib_error_main_t *em = &vm->error_main;
vlib_node_main_t *nm = &vm->node_main;
@@ -128,21 +129,33 @@
/* Free up any previous error strings. */
if (n->n_errors > 0)
- heap_dealloc (em->error_strings_heap, n->error_heap_handle);
-
- n->n_errors = n_errors;
- n->error_strings = error_strings;
+ heap_dealloc (em->counters_heap, n->error_heap_handle);
if (n_errors == 0)
return;
+ n->n_errors = n_errors;
+
+ /* Legacy node */
+ if (!counters)
+ {
+ counters = clib_mem_alloc (sizeof (counters[0]) * n_errors);
+ int i;
+ for (i = 0; i < n_errors; i++)
+ {
+ counters[i].name = error_strings[i]; // XXX Make name saner
+ counters[i].desc = error_strings[i];
+ counters[i].severity = VL_COUNTER_SEVERITY_ERROR;
+ }
+ }
+
+ n->error_counters = counters;
+
n->error_heap_index =
- heap_alloc (em->error_strings_heap, n_errors, n->error_heap_handle);
-
- l = vec_len (em->error_strings_heap);
-
- clib_memcpy (vec_elt_at_index (em->error_strings_heap, n->error_heap_index),
- error_strings, n_errors * sizeof (error_strings[0]));
+ heap_alloc (em->counters_heap, n_errors, n->error_heap_handle);
+ l = vec_len (em->counters_heap);
+ clib_memcpy (vec_elt_at_index (em->counters_heap, n->error_heap_index),
+ counters, n_errors * sizeof (counters[0]));
vec_validate (vm->error_elog_event_types, l - 1);
@@ -170,7 +183,7 @@
{
vec_reset_length (error_name);
error_name =
- format (error_name, "/err/%v/%s%c", n->name, error_strings[i], 0);
+ format (error_name, "/err/%v/%s%c", n->name, counters[i].name, 0);
vlib_stats_register_error_index (oldheap, error_name, em->counters,
n->error_heap_index + i);
}
@@ -191,13 +204,29 @@
for (i = 0; i < n_errors; i++)
{
t.format = (char *) format (0, "%v %s: %%d",
- n->name, error_strings[i]);
+ n->name, counters[i].name);
vm->error_elog_event_types[n->error_heap_index + i] = t;
nm->node_by_error[n->error_heap_index + i] = n->index;
}
}
}
+static char *
+sev2str (enum vl_counter_severity_e s)
+{
+ switch (s)
+ {
+ case VL_COUNTER_SEVERITY_ERROR:
+ return "error";
+ case VL_COUNTER_SEVERITY_WARN:
+ return "warn";
+ case VL_COUNTER_SEVERITY_INFO:
+ return "info";
+ default:
+ return "unknown";
+ }
+}
+
static clib_error_t *
show_errors (vlib_main_t * vm,
unformat_input_t * input, vlib_cli_command_t * cmd)
@@ -218,10 +247,11 @@
vec_validate (sums, vec_len (em->counters));
if (verbose)
- vlib_cli_output (vm, "%=10s%=40s%=20s%=6s", "Count", "Node", "Reason",
- "Index");
+ vlib_cli_output (vm, "%=10s%=30s%=20s%=10s%=6s", "Count", "Node",
+ "Reason", "Severity", "Index");
else
- vlib_cli_output (vm, "%=10s%=40s%=6s", "Count", "Node", "Reason");
+ vlib_cli_output (vm, "%=10s%=30s%=20s%=10s", "Count", "Node", "Reason",
+ "Severity");
/* *INDENT-OFF* */
@@ -247,11 +277,13 @@
continue;
if (verbose)
- vlib_cli_output (vm, "%10lu%=40v%=20s%=6d", c, n->name,
- em->error_strings_heap[i], i);
+ vlib_cli_output (vm, "%10lu%=30v%=20s%=10s%=6d", c, n->name,
+ em->counters_heap[i].name,
+ sev2str(em->counters_heap[i].severity), i);
else
- vlib_cli_output (vm, "%10lu%=40v%s", c, n->name,
- em->error_strings_heap[i]);
+ vlib_cli_output (vm, "%10lu%=30v%=20s%=10s", c, n->name,
+ em->counters_heap[i].name,
+ sev2str(em->counters_heap[i].severity));
}
}
index++;
@@ -271,7 +303,7 @@
{
if (verbose)
vlib_cli_output (vm, "%10lu%=40v%=20s%=10d", sums[i], n->name,
- em->error_strings_heap[i], i);
+ em->counters_heap[i].name, i);
}
}
}
diff --git a/src/vlib/error.h b/src/vlib/error.h
index 0da3a18..11757e0 100644
--- a/src/vlib/error.h
+++ b/src/vlib/error.h
@@ -42,6 +42,20 @@
typedef u16 vlib_error_t;
+enum vl_counter_severity_e
+{
+ VL_COUNTER_SEVERITY_ERROR,
+ VL_COUNTER_SEVERITY_WARN,
+ VL_COUNTER_SEVERITY_INFO,
+};
+
+typedef struct
+{
+ char *name;
+ char *desc;
+ enum vl_counter_severity_e severity;
+} vl_counter_t;
+
typedef struct
{
/* Error counters. */
@@ -50,15 +64,16 @@
/* Counter values as of last counter clear. */
u64 *counters_last_clear;
- /* Error name strings in heap. Heap index
+ /* Counter structures in heap. Heap index
indexes counter vector. */
- char **error_strings_heap;
+ vl_counter_t *counters_heap;
} vlib_error_main_t;
/* Per node error registration. */
void vlib_register_errors (struct vlib_main_t *vm,
u32 node_index,
- u32 n_errors, char *error_strings[]);
+ u32 n_errors, char *error_strings[],
+ vl_counter_t counters[]);
#endif /* included_vlib_error_h */
diff --git a/src/vlib/node.c b/src/vlib/node.c
index 0066037..2c48643 100644
--- a/src/vlib/node.c
+++ b/src/vlib/node.c
@@ -380,7 +380,8 @@
_(validate_frame);
/* Register error counters. */
- vlib_register_errors (vm, n->index, r->n_errors, r->error_strings);
+ vlib_register_errors (vm, n->index, r->n_errors, r->error_strings,
+ r->error_counters);
node_elog_init (vm, n->index);
_(runtime_data_bytes);
diff --git a/src/vlib/node.h b/src/vlib/node.h
index f7155ae..6b9a2df 100644
--- a/src/vlib/node.h
+++ b/src/vlib/node.h
@@ -116,6 +116,7 @@
/* Error strings indexed by error code for this node. */
char **error_strings;
+ vl_counter_t *error_counters;
/* Buffer format/unformat for this node. */
format_function_t *format_buffer;
@@ -323,8 +324,8 @@
u32 error_heap_handle;
u32 error_heap_index;
- /* Error strings indexed by error code for this node. */
- char **error_strings;
+ /* Counter structures indexed by counter code for this node. */
+ vl_counter_t *error_counters;
/* Vector of next node names.
Only used before next_nodes array is initialized. */
diff --git a/src/vnet/interface.c b/src/vnet/interface.c
index 8ca9c1a..1cf63c7 100644
--- a/src/vnet/interface.c
+++ b/src/vnet/interface.c
@@ -736,9 +736,10 @@
n->function = dev_class->tx_function;
n->format_trace = dev_class->format_tx_trace;
+ /// XXX: Update this to use counter structure
vlib_register_errors (vm, node_index,
dev_class->tx_function_n_errors,
- dev_class->tx_function_error_strings);
+ dev_class->tx_function_error_strings, 0);
}
static void
diff --git a/src/vnet/interface_output.c b/src/vnet/interface_output.c
index cb13f53..913bac6 100644
--- a/src/vnet/interface_output.c
+++ b/src/vnet/interface_output.c
@@ -967,7 +967,7 @@
vlib_node_t *n;
/* Length of the error string */
int error_string_len =
- clib_strnlen (em->error_strings_heap[b0->error], 128);
+ clib_strnlen (em->counters_heap[b0->error].name, 128);
/* Dig up the drop node */
error_node_index = vm->node_main.node_by_error[b0->error];
@@ -996,7 +996,7 @@
": ", 2);
clib_memcpy_fast (last->data + last->current_data +
last->current_length + vec_len (n->name) +
- 2, em->error_strings_heap[b0->error],
+ 2, em->counters_heap[b0->error].name,
error_string_len);
last->current_length += drop_string_len;
b0->flags &= ~(VLIB_BUFFER_TOTAL_LENGTH_VALID);