From 1574892d10e87922de7b64fac81276a9bc5f8705 Mon Sep 17 00:00:00 2001 From: Aaron Conole Date: Wed, 2 Jul 2025 11:08:57 -0400 Subject: [PATCH] mac: Add counters for mac learning. Signed-off-by: Aaron Conole --- ovs/lib/mac-learning.c | 19 +++++++++++++++++++ ovs/ofproto/ofproto-dpif-xlate.c | 22 ++++++++++++++++++++-- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/ovs/lib/mac-learning.c b/ovs/lib/mac-learning.c index 5932e2709d..d7c0efc528 100644 --- a/ovs/lib/mac-learning.c +++ b/ovs/lib/mac-learning.c @@ -35,6 +35,15 @@ COVERAGE_DEFINE(mac_learning_expired); COVERAGE_DEFINE(mac_learning_evicted); COVERAGE_DEFINE(mac_learning_moved); COVERAGE_DEFINE(mac_learning_static_none_move); +COVERAGE_DEFINE(mac_learning_is_not_allowed); +COVERAGE_DEFINE(mac_learning_bond_reject); +COVERAGE_DEFINE(mac_learning_not_found); +COVERAGE_DEFINE(mac_learning_refresh); +COVERAGE_DEFINE(mac_learning_not_bonded); +COVERAGE_DEFINE(mac_learning_port_matched); +COVERAGE_DEFINE(mac_entry_lock); +COVERAGE_DEFINE(mac_entry_bond_locked); +COVERAGE_DEFINE(mac_learning_port_null); /* * This function will return age of mac entry in the fdb. @@ -463,12 +472,14 @@ is_mac_learning_update_needed(const struct mac_learning *ml, int age; if (!mac_learning_may_learn(ml, src, vlan)) { + COVERAGE_INC(mac_learning_is_not_allowed); return false; } mac = mac_learning_lookup(ml, src, vlan); /* If mac entry is missing it needs to be added to fdb. */ if (!mac) { + COVERAGE_INC(mac_learning_not_found); return true; } @@ -486,6 +497,7 @@ is_mac_learning_update_needed(const struct mac_learning *ml, /* If entry is still alive, just update the mac_entry so, that expires * gets updated. */ if (age > 0) { + COVERAGE_INC(mac_learning_refresh); return true; } @@ -494,8 +506,10 @@ is_mac_learning_update_needed(const struct mac_learning *ml, * reflected back over bond members so we lock the learning table. For * more detail, see the bigger comment in update_learning_table__(). */ if (!is_bond) { + COVERAGE_INC(mac_learning_not_bonded); return true; /* Need to set the gratuitous ARP lock. */ } else if (mac_entry_is_grat_arp_locked(mac)) { + COVERAGE_INC(mac_learning_bond_reject); return false; } } @@ -525,6 +539,7 @@ update_learning_table__(struct mac_learning *ml, struct eth_addr src, struct mac_entry *mac; if (!mac_learning_may_learn(ml, src, vlan)) { + COVERAGE_INC(mac_learning_port_matched); return false; } @@ -539,8 +554,10 @@ update_learning_table__(struct mac_learning *ml, struct eth_addr src, * 'ovs-vswitch Internals' document for more in-depth discussion on * this topic. */ if (!is_bond) { + COVERAGE_INC(mac_entry_lock); mac_entry_set_grat_arp_lock(mac); } else if (mac_entry_is_grat_arp_locked(mac)) { + COVERAGE_INC(mac_entry_bond_locked); return false; } } @@ -549,6 +566,8 @@ update_learning_table__(struct mac_learning *ml, struct eth_addr src, if (mac_entry_get_port(ml, mac) != NULL) { COVERAGE_INC(mac_learning_moved); ml->total_moved++; + } else { + COVERAGE_INC(mac_learning_port_null); } mac_entry_set_port(ml, mac, in_port); return true; diff --git a/ovs/ofproto/ofproto-dpif-xlate.c b/ovs/ofproto/ofproto-dpif-xlate.c index 818ef3a011..1090ce05d4 100644 --- a/ovs/ofproto/ofproto-dpif-xlate.c +++ b/ovs/ofproto/ofproto-dpif-xlate.c @@ -71,6 +71,14 @@ COVERAGE_DEFINE(xlate_actions); COVERAGE_DEFINE(xlate_actions_oversize); COVERAGE_DEFINE(xlate_actions_too_many_output); +COVERAGE_DEFINE(xlate_mac_learning_blocked_loopback); +COVERAGE_DEFINE(xlate_mac_learning_blocked_mirror); +COVERAGE_DEFINE(xlate_mac_learning_dropped); +COVERAGE_DEFINE(xlate_mac_learning_failed); +COVERAGE_DEFINE(xlate_mac_learning_flooded); +COVERAGE_DEFINE(xlate_mac_learning_forwarded); +COVERAGE_DEFINE(xlate_mac_learning_looped); +COVERAGE_DEFINE(xlate_learning_track); VLOG_DEFINE_THIS_MODULE(ofproto_dpif_xlate); @@ -2747,6 +2755,7 @@ is_admissible(struct xlate_ctx *ctx, struct xport *in_port, && mac_entry_get_port(xbridge->ml, mac) != in_xbundle->ofbundle && (!is_gratuitous_arp(flow, ctx->wc) || mac_entry_is_grat_arp_locked(mac))) { + COVERAGE_INC(xlate_mac_learning_blocked_loopback); ovs_rwlock_unlock(&xbridge->ml->rwlock); xlate_report(ctx, OFT_DETAIL, "SLB bond thinks this packet looped back, " @@ -3198,9 +3207,11 @@ xlate_normal(struct xlate_ctx *ctx) && flow->packet_type == htonl(PT_ETH) && in_port && in_port->pt_mode != NETDEV_PT_LEGACY_L3 ) { + COVERAGE_INC(xlate_learning_track); update_learning_table(ctx, in_xbundle, flow->dl_src, vlan, is_grat_arp); } + if (ctx->xin->xcache && in_xbundle != &ofpp_none_bundle) { struct xc_entry *entry; @@ -3335,24 +3346,29 @@ xlate_normal(struct xlate_ctx *ctx) if (mac_xbundle && xbundle_mirror_out(ctx->xbridge, mac_xbundle)) { xlate_report(ctx, OFT_WARN, "learned port is a mirror port, dropping"); + COVERAGE_INC(xlate_mac_learning_blocked_mirror); return; } if (mac_xbundle && mac_xbundle != in_xbundle && mac_xbundle->ofbundle != in_xbundle->ofbundle) { + COVERAGE_INC(xlate_mac_learning_forwarded); xlate_report(ctx, OFT_DETAIL, "forwarding to learned port"); output_normal(ctx, mac_xbundle, &xvlan); } else if (!mac_xbundle) { + COVERAGE_INC(xlate_mac_learning_dropped); xlate_report(ctx, OFT_WARN, "learned port is unknown, dropping"); } else { + COVERAGE_INC(xlate_mac_learning_looped); xlate_report(ctx, OFT_DETAIL, "learned port is input port, dropping"); } } else { xlate_report(ctx, OFT_DETAIL, "no learned MAC for destination, flooding"); + COVERAGE_INC(xlate_mac_learning_flooded); xlate_normal_flood(ctx, in_xbundle, &xvlan); } } @@ -8607,8 +8623,10 @@ xlate_mac_learning_update(const struct ofproto_dpif *ofproto, return; } - update_learning_table__(xbundle->xbridge, - xbundle, dl_src, vlan, is_grat_arp); + if (update_learning_table__(xbundle->xbridge, + xbundle, dl_src, vlan, is_grat_arp)) { + COVERAGE_INC(xlate_mac_learning_failed); + } } bool -- 2.49.0