From 440d648a4ae51c04aaa8918236fd88e06ae94fe4 Mon Sep 17 00:00:00 2001 From: Sonika Jindal Date: Mon, 24 Nov 2025 03:58:28 +0000 Subject: [PATCH 1/2] Fix broadcast packet counting in Lemming dataplane Define COUNTER_ID_RX_BROADCAST_PACKETS and COUNTER_ID_RX_MULTICAST_PACKETS in forwarding_common.proto. Regenerate forwarding_common.pb.go. Implement broadcast/multicast counting logic in fwdport/port.go. Map SAI broadcast/multicast stats in saiserver/ports.go. --- dataplane/forwarding/fwdport/port.go | 8 ++++++++ dataplane/saiserver/ports.go | 4 ++++ proto/forwarding/forwarding_common.pb.go | 23 +++++++++++++++++------ proto/forwarding/forwarding_common.proto | 2 ++ 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/dataplane/forwarding/fwdport/port.go b/dataplane/forwarding/fwdport/port.go index d46afe66c..69f14f4bc 100644 --- a/dataplane/forwarding/fwdport/port.go +++ b/dataplane/forwarding/fwdport/port.go @@ -69,6 +69,8 @@ var CounterList = []fwdpb.CounterId{ fwdpb.CounterId_COUNTER_ID_RX_NON_UCAST_PACKETS, fwdpb.CounterId_COUNTER_ID_TX_BROADCAST_PACKETS, fwdpb.CounterId_COUNTER_ID_TX_MULTICAST_PACKETS, + fwdpb.CounterId_COUNTER_ID_RX_BROADCAST_PACKETS, + fwdpb.CounterId_COUNTER_ID_RX_MULTICAST_PACKETS, } // A Port is an entry or exit point within the forwarding plane. Each port @@ -257,6 +259,12 @@ func Input(port Port, packet fwdpacket.Packet, dir fwdpb.PortAction, ctx *fwdcon port.Increment(fwdpb.CounterId_COUNTER_ID_RX_UCAST_PACKETS, 1) } else { port.Increment(fwdpb.CounterId_COUNTER_ID_RX_NON_UCAST_PACKETS, 1) + isBroadcastMac := (mac[0] == 0xFF && mac[1] == 0xFF && mac[2] == 0xFF && mac[3] == 0xFF && mac[4] == 0xFF && mac[5] == 0xFF) + if isBroadcastMac { // Broadcast address is when all bits are set to 1. + port.Increment(fwdpb.CounterId_COUNTER_ID_RX_BROADCAST_PACKETS, 1) + } else { // Multicast address is when least significant bit of the 1st octet is 1. + port.Increment(fwdpb.CounterId_COUNTER_ID_RX_MULTICAST_PACKETS, 1) + } } packet.Log().V(1).Info("input packet", "port", port.ID(), "frame", fwdpacket.IncludeFrameInLog) diff --git a/dataplane/saiserver/ports.go b/dataplane/saiserver/ports.go index 44c57221a..d95d09d75 100644 --- a/dataplane/saiserver/ports.go +++ b/dataplane/saiserver/ports.go @@ -550,6 +550,10 @@ func (port *port) GetPortStats(ctx context.Context, req *saipb.GetPortStatsReque resp.Values = append(resp.Values, counterMap[fwdpb.CounterId_COUNTER_ID_TX_MULTICAST_PACKETS]) case saipb.PortStat_PORT_STAT_IF_OUT_BROADCAST_PKTS: resp.Values = append(resp.Values, counterMap[fwdpb.CounterId_COUNTER_ID_TX_BROADCAST_PACKETS]) + case saipb.PortStat_PORT_STAT_IF_IN_BROADCAST_PKTS: + resp.Values = append(resp.Values, counterMap[fwdpb.CounterId_COUNTER_ID_RX_BROADCAST_PACKETS]) + case saipb.PortStat_PORT_STAT_IF_IN_MULTICAST_PKTS: + resp.Values = append(resp.Values, counterMap[fwdpb.CounterId_COUNTER_ID_RX_MULTICAST_PACKETS]) case saipb.PortStat_PORT_STAT_IF_OUT_ERRORS: resp.Values = append(resp.Values, counterMap[fwdpb.CounterId_COUNTER_ID_TX_ERROR_PACKETS]) case saipb.PortStat_PORT_STAT_IF_IN_OCTETS: diff --git a/proto/forwarding/forwarding_common.pb.go b/proto/forwarding/forwarding_common.pb.go index a60f9bbaa..07eca547a 100644 --- a/proto/forwarding/forwarding_common.pb.go +++ b/proto/forwarding/forwarding_common.pb.go @@ -482,6 +482,8 @@ const ( CounterId_COUNTER_ID_TX_NON_UCAST_PACKETS CounterId = 40 CounterId_COUNTER_ID_TX_BROADCAST_PACKETS CounterId = 41 CounterId_COUNTER_ID_TX_MULTICAST_PACKETS CounterId = 42 + CounterId_COUNTER_ID_RX_BROADCAST_PACKETS CounterId = 43 + CounterId_COUNTER_ID_RX_MULTICAST_PACKETS CounterId = 44 CounterId_COUNTER_ID_MAX CounterId = 255 ) @@ -531,6 +533,8 @@ var ( 40: "COUNTER_ID_TX_NON_UCAST_PACKETS", 41: "COUNTER_ID_TX_BROADCAST_PACKETS", 42: "COUNTER_ID_TX_MULTICAST_PACKETS", + 43: "COUNTER_ID_RX_BROADCAST_PACKETS", + 44: "COUNTER_ID_RX_MULTICAST_PACKETS", 255: "COUNTER_ID_MAX", } CounterId_value = map[string]int32{ @@ -577,6 +581,8 @@ var ( "COUNTER_ID_TX_NON_UCAST_PACKETS": 40, "COUNTER_ID_TX_BROADCAST_PACKETS": 41, "COUNTER_ID_TX_MULTICAST_PACKETS": 42, + "COUNTER_ID_RX_BROADCAST_PACKETS": 43, + "COUNTER_ID_RX_MULTICAST_PACKETS": 44, "COUNTER_ID_MAX": 255, } ) @@ -2758,7 +2764,7 @@ var file_proto_forwarding_forwarding_common_proto_rawDesc = string([]byte{ 0x50, 0x41, 0x43, 0x4b, 0x45, 0x54, 0x5f, 0x46, 0x49, 0x45, 0x4c, 0x44, 0x5f, 0x4e, 0x55, 0x4d, 0x5f, 0x50, 0x41, 0x43, 0x4b, 0x45, 0x54, 0x5f, 0x41, 0x43, 0x54, 0x49, 0x4f, 0x4e, 0x10, 0x46, 0x12, 0x1b, 0x0a, 0x16, 0x50, 0x41, 0x43, 0x4b, 0x45, 0x54, 0x5f, 0x46, 0x49, 0x45, 0x4c, 0x44, - 0x5f, 0x4e, 0x55, 0x4d, 0x5f, 0x43, 0x4f, 0x55, 0x4e, 0x54, 0x10, 0xe8, 0x07, 0x2a, 0xa4, 0x0b, + 0x5f, 0x4e, 0x55, 0x4d, 0x5f, 0x43, 0x4f, 0x55, 0x4e, 0x54, 0x10, 0xe8, 0x07, 0x2a, 0xee, 0x0b, 0x0a, 0x09, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x16, 0x43, 0x4f, 0x55, 0x4e, 0x54, 0x45, 0x52, 0x5f, 0x49, 0x44, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x19, 0x0a, 0x15, 0x43, 0x4f, 0x55, 0x4e, 0x54, @@ -2848,11 +2854,16 @@ var file_proto_forwarding_forwarding_common_proto_rawDesc = string([]byte{ 0x5f, 0x50, 0x41, 0x43, 0x4b, 0x45, 0x54, 0x53, 0x10, 0x29, 0x12, 0x23, 0x0a, 0x1f, 0x43, 0x4f, 0x55, 0x4e, 0x54, 0x45, 0x52, 0x5f, 0x49, 0x44, 0x5f, 0x54, 0x58, 0x5f, 0x4d, 0x55, 0x4c, 0x54, 0x49, 0x43, 0x41, 0x53, 0x54, 0x5f, 0x50, 0x41, 0x43, 0x4b, 0x45, 0x54, 0x53, 0x10, 0x2a, 0x12, - 0x13, 0x0a, 0x0e, 0x43, 0x4f, 0x55, 0x4e, 0x54, 0x45, 0x52, 0x5f, 0x49, 0x44, 0x5f, 0x4d, 0x41, - 0x58, 0x10, 0xff, 0x01, 0x42, 0x30, 0x5a, 0x2e, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, - 0x6f, 0x6d, 0x2f, 0x6f, 0x70, 0x65, 0x6e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2f, 0x6c, 0x65, - 0x6d, 0x6d, 0x69, 0x6e, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x66, 0x6f, 0x72, 0x77, - 0x61, 0x72, 0x64, 0x69, 0x6e, 0x67, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x23, 0x0a, 0x1f, 0x43, 0x4f, 0x55, 0x4e, 0x54, 0x45, 0x52, 0x5f, 0x49, 0x44, 0x5f, 0x52, 0x58, + 0x5f, 0x42, 0x52, 0x4f, 0x41, 0x44, 0x43, 0x41, 0x53, 0x54, 0x5f, 0x50, 0x41, 0x43, 0x4b, 0x45, + 0x54, 0x53, 0x10, 0x2b, 0x12, 0x23, 0x0a, 0x1f, 0x43, 0x4f, 0x55, 0x4e, 0x54, 0x45, 0x52, 0x5f, + 0x49, 0x44, 0x5f, 0x52, 0x58, 0x5f, 0x4d, 0x55, 0x4c, 0x54, 0x49, 0x43, 0x41, 0x53, 0x54, 0x5f, + 0x50, 0x41, 0x43, 0x4b, 0x45, 0x54, 0x53, 0x10, 0x2c, 0x12, 0x13, 0x0a, 0x0e, 0x43, 0x4f, 0x55, + 0x4e, 0x54, 0x45, 0x52, 0x5f, 0x49, 0x44, 0x5f, 0x4d, 0x41, 0x58, 0x10, 0xff, 0x01, 0x42, 0x30, + 0x5a, 0x2e, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6f, 0x70, 0x65, + 0x6e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2f, 0x6c, 0x65, 0x6d, 0x6d, 0x69, 0x6e, 0x67, 0x2f, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x66, 0x6f, 0x72, 0x77, 0x61, 0x72, 0x64, 0x69, 0x6e, 0x67, + 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, }) var ( diff --git a/proto/forwarding/forwarding_common.proto b/proto/forwarding/forwarding_common.proto index 01665712d..eaf41db11 100644 --- a/proto/forwarding/forwarding_common.proto +++ b/proto/forwarding/forwarding_common.proto @@ -289,6 +289,8 @@ enum CounterId { COUNTER_ID_TX_NON_UCAST_PACKETS = 40; COUNTER_ID_TX_BROADCAST_PACKETS = 41; COUNTER_ID_TX_MULTICAST_PACKETS = 42; + COUNTER_ID_RX_BROADCAST_PACKETS = 43; + COUNTER_ID_RX_MULTICAST_PACKETS = 44; COUNTER_ID_MAX = 255; // Maximum counter id. } From a6825bc08a711748f184a004083a8c78d0fdada2 Mon Sep 17 00:00:00 2001 From: Sonika Jindal Date: Mon, 24 Nov 2025 22:40:47 +0000 Subject: [PATCH 2/2] Add function for isBroadcast --- dataplane/forwarding/fwdport/port.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/dataplane/forwarding/fwdport/port.go b/dataplane/forwarding/fwdport/port.go index 69f14f4bc..d47fe4895 100644 --- a/dataplane/forwarding/fwdport/port.go +++ b/dataplane/forwarding/fwdport/port.go @@ -238,6 +238,11 @@ func Increment(port Port, octets int, packetID, octetID fwdpb.CounterId) { port.Increment(octetID, uint32(octets)+4) // Add 4 bytes per packet to account for FCS } +// isBroadcast checks if the MAC address is a broadcast address. +func isBroadcast(mac []byte) bool { + return mac[0] == 0xFF && mac[1] == 0xFF && mac[2] == 0xFF && mac[3] == 0xFF && mac[4] == 0xFF && mac[5] == 0xFF +} + // Input processes an incoming packet. The specified port actions are applied // to the packet, and if the packet has an output port, output actions are // performed on the packet. All appropriate counters are incremented. @@ -255,12 +260,11 @@ func Input(port Port, packet fwdpacket.Packet, dir fwdpb.PortAction, ctx *fwdcon Increment(port, packet.Length(), fwdpb.CounterId_COUNTER_ID_RX_ERROR_PACKETS, fwdpb.CounterId_COUNTER_ID_RX_ERROR_OCTETS) return err } - if mac[0]%2 == 0 { // Unicast address is when is least significant bit of the 1st octet is 0. + if mac[0]%2 == 0 { // Unicast address is when least significant bit of the 1st octet is 0. port.Increment(fwdpb.CounterId_COUNTER_ID_RX_UCAST_PACKETS, 1) } else { port.Increment(fwdpb.CounterId_COUNTER_ID_RX_NON_UCAST_PACKETS, 1) - isBroadcastMac := (mac[0] == 0xFF && mac[1] == 0xFF && mac[2] == 0xFF && mac[3] == 0xFF && mac[4] == 0xFF && mac[5] == 0xFF) - if isBroadcastMac { // Broadcast address is when all bits are set to 1. + if isBroadcast(mac) { // Broadcast address is when all bits are set to 1. port.Increment(fwdpb.CounterId_COUNTER_ID_RX_BROADCAST_PACKETS, 1) } else { // Multicast address is when least significant bit of the 1st octet is 1. port.Increment(fwdpb.CounterId_COUNTER_ID_RX_MULTICAST_PACKETS, 1) @@ -318,9 +322,7 @@ func Output(port Port, packet fwdpacket.Packet, dir fwdpb.PortAction, _ *fwdcont port.Increment(fwdpb.CounterId_COUNTER_ID_TX_UCAST_PACKETS, 1) } else { port.Increment(fwdpb.CounterId_COUNTER_ID_TX_NON_UCAST_PACKETS, 1) - - isBroadcastMac := (mac[0] == 0xFF && mac[1] == 0xFF && mac[2] == 0xFF && mac[3] == 0xFF && mac[4] == 0xFF && mac[5] == 0xFF) - if isBroadcastMac { // Broadcast address is when all bits are set to 1. + if isBroadcast(mac) { // Broadcast address is when all bits are set to 1. port.Increment(fwdpb.CounterId_COUNTER_ID_TX_BROADCAST_PACKETS, 1) } else { // Multicast address is when least significant bit of the 1st octet is 1. port.Increment(fwdpb.CounterId_COUNTER_ID_TX_MULTICAST_PACKETS, 1)