From 1a52ebe772b2c483b5698215a757515f0ede0318 Mon Sep 17 00:00:00 2001 From: Roy Date: Sat, 21 Mar 2026 01:53:02 +0000 Subject: [PATCH] Map kernel counters to Lucius mtu counters. --- dataplane/saiserver/ports.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/dataplane/saiserver/ports.go b/dataplane/saiserver/ports.go index 8b67d9bd..b7cd6b28 100644 --- a/dataplane/saiserver/ports.go +++ b/dataplane/saiserver/ports.go @@ -612,6 +612,21 @@ func (port *port) GetPortStats(ctx context.Context, req *saipb.GetPortStatsReque counterMap[c.GetId()] = c.GetValue() } + var kernelRxDropped uint64 + if slices.Contains(req.GetCounterIds(), saipb.PortStat_PORT_STAT_IF_IN_ERRORS) || + slices.Contains(req.GetCounterIds(), saipb.PortStat_PORT_STAT_ETHER_RX_OVERSIZE_PKTS) { + attrReq := &saipb.GetPortAttributeRequest{Oid: req.GetOid(), AttrType: []saipb.PortAttr{saipb.PortAttr_PORT_ATTR_HW_LANE_LIST}} + portAttr := &saipb.GetPortAttributeResponse{} + + // Get rx_drop kernel statistic from the netdev (first lane of interface) + if err := port.mgr.PopulateAttributes(attrReq, portAttr); err == nil && len(portAttr.GetAttr().GetHwLaneList()) > 0 { + dev := fmt.Sprintf("eth%v", portAttr.GetAttr().GetHwLaneList()[0]) + if l, err := netlink.LinkByName(dev); err == nil && l.Attrs() != nil && l.Attrs().Statistics != nil { + kernelRxDropped = uint64(l.Attrs().Statistics.RxDropped) + } + } + } + for _, id := range req.GetCounterIds() { switch id { case saipb.PortStat_PORT_STAT_IF_IN_UCAST_PKTS: @@ -619,7 +634,7 @@ func (port *port) GetPortStats(ctx context.Context, req *saipb.GetPortStatsReque case saipb.PortStat_PORT_STAT_IF_IN_NON_UCAST_PKTS: resp.Values = append(resp.Values, counterMap[fwdpb.CounterId_COUNTER_ID_RX_NON_UCAST_PACKETS]) case saipb.PortStat_PORT_STAT_IF_IN_ERRORS: - resp.Values = append(resp.Values, counterMap[fwdpb.CounterId_COUNTER_ID_RX_ERROR_PACKETS]) + resp.Values = append(resp.Values, counterMap[fwdpb.CounterId_COUNTER_ID_RX_ERROR_PACKETS]+kernelRxDropped) case saipb.PortStat_PORT_STAT_IF_OUT_UCAST_PKTS: resp.Values = append(resp.Values, counterMap[fwdpb.CounterId_COUNTER_ID_TX_UCAST_PACKETS]) case saipb.PortStat_PORT_STAT_IF_OUT_NON_UCAST_PKTS: @@ -648,6 +663,8 @@ func (port *port) GetPortStats(ctx context.Context, req *saipb.GetPortStatsReque resp.Values = append(resp.Values, counterMap[fwdpb.CounterId_COUNTER_ID_RX_IPV6_DROP_PACKETS]) case saipb.PortStat_PORT_STAT_IPV6_OUT_UCAST_PKTS, saipb.PortStat_PORT_STAT_IPV6_OUT_NON_UCAST_PKTS, saipb.PortStat_PORT_STAT_IPV6_OUT_MCAST_PKTS: resp.Values = append(resp.Values, counterMap[fwdpb.CounterId_COUNTER_ID_TX_IPV6_PACKETS]) + case saipb.PortStat_PORT_STAT_ETHER_RX_OVERSIZE_PKTS: + resp.Values = append(resp.Values, kernelRxDropped) default: resp.Values = append(resp.Values, 0) }