From f34a5d4022c536484bcee4464c7e2c3e23a020c9 Mon Sep 17 00:00:00 2001 From: Eelco Chaudron Date: Mon, 25 Jun 2018 12:57:40 +0200 Subject: mac-learning: Add per mac learning instance counters This patch adds counters per mac_learning instance. The following counters are added: total_learned: Total number of learned MAC entries total_expired: Total number of expired MAC entries total_evicted: Total number of evicted MAC entries, i.e. entries moved out due to the table being full. total_moved : Total number of port moved MAC entries, i.e. entries where the MAC address moved to a different port. Signed-off-by: Eelco Chaudron Signed-off-by: Ben Pfaff --- lib/mac-learning.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'lib/mac-learning.c') diff --git a/lib/mac-learning.c b/lib/mac-learning.c index 8b7981dbb..c13a5fac8 100644 --- a/lib/mac-learning.c +++ b/lib/mac-learning.c @@ -153,6 +153,7 @@ evict_mac_entry_fairly(struct mac_learning *ml) e = CONTAINER_OF(ovs_list_front(&mlport->port_lrus), struct mac_entry, port_lru_node); COVERAGE_INC(mac_learning_evicted); + ml->total_evicted++; mac_learning_expire(ml, e); } @@ -180,6 +181,18 @@ normalize_idle_time(unsigned int idle_time) : idle_time); } +/* Clear all the mac_learning statistics */ +static void +mac_learning_clear_statistics(struct mac_learning *ml) +{ + if (ml != NULL) { + ml->total_learned = 0; + ml->total_expired = 0; + ml->total_evicted = 0; + ml->total_moved = 0; + } +} + /* Creates and returns a new MAC learning table with an initial MAC aging * timeout of 'idle_time' seconds and an initial maximum of MAC_DEFAULT_MAX * entries. */ @@ -200,6 +213,7 @@ mac_learning_create(unsigned int idle_time) heap_init(&ml->ports_by_usage); ovs_refcount_init(&ml->ref_cnt); ovs_rwlock_init(&ml->rwlock); + mac_learning_clear_statistics(ml); return ml; } @@ -323,6 +337,7 @@ mac_learning_insert(struct mac_learning *ml, e->grat_arp_lock = TIME_MIN; e->mlport = NULL; COVERAGE_INC(mac_learning_learned); + ml->total_learned++; } else { ovs_list_remove(&e->lru_node); } @@ -426,6 +441,7 @@ update_learning_table__(struct mac_learning *ml, struct eth_addr src, if (mac_entry_get_port(ml, mac) != in_port) { if (mac_entry_get_port(ml, mac) != NULL) { COVERAGE_INC(mac_learning_moved); + ml->total_moved++; } mac_entry_set_port(ml, mac, in_port); return true; @@ -524,6 +540,7 @@ mac_learning_run(struct mac_learning *ml) && (hmap_count(&ml->table) > ml->max_entries || time_now() >= e->expires)) { COVERAGE_INC(mac_learning_expired); + ml->total_expired++; mac_learning_expire(ml, e); } -- cgit v1.2.1