From 3951f5ab5c2b5956c826fb012d365702a8657703 Mon Sep 17 00:00:00 2001 From: Roy Date: Wed, 18 Dec 2024 23:36:36 +0000 Subject: [PATCH] Add multicast and broadcast counter support to Lucius. --- dataplane/dplanerc/interface.go | 2 ++ .../fwdaction/actions/mirror_test.go | 2 +- dataplane/forwarding/fwdport/port.go | 15 ++++++++--- dataplane/saiserver/ports.go | 4 +++ proto/forwarding/forwarding_common.pb.go | 25 +++++++++++++------ proto/forwarding/forwarding_common.proto | 4 ++- 6 files changed, 40 insertions(+), 12 deletions(-) diff --git a/dataplane/dplanerc/interface.go b/dataplane/dplanerc/interface.go index 15e65922..92653b50 100644 --- a/dataplane/dplanerc/interface.go +++ b/dataplane/dplanerc/interface.go @@ -319,6 +319,8 @@ func (ni *Reconciler) startCounterUpdates(ctx context.Context) { saipb.PortStat_PORT_STAT_IF_OUT_NON_UCAST_PKTS, // 3 saipb.PortStat_PORT_STAT_IF_IN_OCTETS, // 4 saipb.PortStat_PORT_STAT_IF_OUT_OCTETS, // 5 + saipb.PortStat_PORT_STAT_IF_OUT_MULTICAST_PKTS, // 6 + saipb.PortStat_PORT_STAT_IF_OUT_BROADCAST_PKTS, // 7 }, }) log.V(2).Infof("querying counters for interface %q, got %v", intfName, stats) diff --git a/dataplane/forwarding/fwdaction/actions/mirror_test.go b/dataplane/forwarding/fwdaction/actions/mirror_test.go index 4b30d1ad..5ca46b1d 100644 --- a/dataplane/forwarding/fwdaction/actions/mirror_test.go +++ b/dataplane/forwarding/fwdaction/actions/mirror_test.go @@ -202,7 +202,7 @@ func TestMirror(t *testing.T) { mirrored.EXPECT().Attributes().Return(nil).AnyTimes() mirrored.EXPECT().Log().Return(testr.New(t)).AnyTimes() mirrored.EXPECT().LogMsgs().Return(nil).AnyTimes() - mirrored.EXPECT().Field(fwdpacket.NewFieldIDFromNum(fwdpb.PacketFieldNum_PACKET_FIELD_NUM_ETHER_MAC_SRC, 0)).Return([]byte{0}, nil).AnyTimes() + mirrored.EXPECT().Field(fwdpacket.NewFieldIDFromNum(fwdpb.PacketFieldNum_PACKET_FIELD_NUM_ETHER_MAC_DST, 0)).Return([]byte{0}, nil).AnyTimes() mirrored.EXPECT().Update(opFID, fwdpacket.OpSet, gomock.Any()).Return(nil).AnyTimes() mirrored.EXPECT().Update(inFID, fwdpacket.OpSet, gomock.Any()).Return(nil).AnyTimes() mirrored.EXPECT().Update(fwdpacket.NewFieldIDFromNum(fwdpb.PacketFieldNum_PACKET_FIELD_NUM_ETHER_MAC_DST, 0), diff --git a/dataplane/forwarding/fwdport/port.go b/dataplane/forwarding/fwdport/port.go index 9218820d..d6bd36fb 100644 --- a/dataplane/forwarding/fwdport/port.go +++ b/dataplane/forwarding/fwdport/port.go @@ -67,6 +67,8 @@ var CounterList = []fwdpb.CounterId{ fwdpb.CounterId_COUNTER_ID_TX_NON_UCAST_PACKETS, fwdpb.CounterId_COUNTER_ID_RX_UCAST_PACKETS, fwdpb.CounterId_COUNTER_ID_RX_NON_UCAST_PACKETS, + fwdpb.CounterId_COUNTER_ID_TX_BROADCAST_PACKETS, + fwdpb.CounterId_COUNTER_ID_TX_MULTICAST_PACKETS, } // A Port is an entry or exit point within the forwarding plane. Each port @@ -231,7 +233,7 @@ func SetOutputPort(packet fwdpacket.Packet, port Port) { // Increment increments a packet and octet counters on the port. func Increment(port Port, octets int, packetID, octetID fwdpb.CounterId) { port.Increment(packetID, 1) - port.Increment(octetID, uint32(octets)) + port.Increment(octetID, uint32(octets) + 4) // Add 4 bytes per packet to account for FCS } // Input processes an incoming packet. The specified port actions are applied @@ -299,15 +301,22 @@ func Output(port Port, packet fwdpacket.Packet, dir fwdpb.PortAction, _ *fwdcont }() Increment(port, packet.Length(), fwdpb.CounterId_COUNTER_ID_TX_PACKETS, fwdpb.CounterId_COUNTER_ID_TX_OCTETS) SetOutputPort(packet, port) - mac, err := packet.Field(fwdpacket.NewFieldIDFromNum(fwdpb.PacketFieldNum_PACKET_FIELD_NUM_ETHER_MAC_SRC, 0)) + mac, err := packet.Field(fwdpacket.NewFieldIDFromNum(fwdpb.PacketFieldNum_PACKET_FIELD_NUM_ETHER_MAC_DST, 0)) if err != nil { Increment(port, packet.Length(), fwdpb.CounterId_COUNTER_ID_TX_ERROR_PACKETS, fwdpb.CounterId_COUNTER_ID_TX_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_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. + 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) + } } packet.Log().V(3).Info("output packet", "frame", fwdpacket.IncludeFrameInLog) diff --git a/dataplane/saiserver/ports.go b/dataplane/saiserver/ports.go index bd6b562a..8041ba08 100644 --- a/dataplane/saiserver/ports.go +++ b/dataplane/saiserver/ports.go @@ -536,6 +536,10 @@ func (port *port) GetPortStats(ctx context.Context, req *saipb.GetPortStatsReque resp.Values = append(resp.Values, counterMap[fwdpb.CounterId_COUNTER_ID_TX_UCAST_PACKETS]) case saipb.PortStat_PORT_STAT_IF_OUT_NON_UCAST_PKTS: resp.Values = append(resp.Values, counterMap[fwdpb.CounterId_COUNTER_ID_TX_NON_UCAST_PACKETS]) + case saipb.PortStat_PORT_STAT_IF_OUT_MULTICAST_PKTS: + 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_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 1771f688..bce22ca0 100644 --- a/proto/forwarding/forwarding_common.pb.go +++ b/proto/forwarding/forwarding_common.pb.go @@ -473,6 +473,8 @@ const ( CounterId_COUNTER_ID_RX_NON_UCAST_PACKETS CounterId = 38 CounterId_COUNTER_ID_TX_UCAST_PACKETS CounterId = 39 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_MAX CounterId = 255 ) @@ -520,6 +522,8 @@ var ( 38: "COUNTER_ID_RX_NON_UCAST_PACKETS", 39: "COUNTER_ID_TX_UCAST_PACKETS", 40: "COUNTER_ID_TX_NON_UCAST_PACKETS", + 41: "COUNTER_ID_TX_BROADCAST_PACKETS", + 42: "COUNTER_ID_TX_MULTICAST_PACKETS", 255: "COUNTER_ID_MAX", } CounterId_value = map[string]int32{ @@ -564,6 +568,8 @@ var ( "COUNTER_ID_RX_NON_UCAST_PACKETS": 38, "COUNTER_ID_TX_UCAST_PACKETS": 39, "COUNTER_ID_TX_NON_UCAST_PACKETS": 40, + "COUNTER_ID_TX_BROADCAST_PACKETS": 41, + "COUNTER_ID_TX_MULTICAST_PACKETS": 42, "COUNTER_ID_MAX": 255, } ) @@ -2849,7 +2855,7 @@ var file_proto_forwarding_forwarding_common_proto_rawDesc = []byte{ 0x49, 0x45, 0x4c, 0x44, 0x5f, 0x4e, 0x55, 0x4d, 0x5f, 0x4d, 0x50, 0x4c, 0x53, 0x5f, 0x54, 0x54, 0x4c, 0x10, 0x44, 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, 0xda, 0x0a, 0x0a, 0x09, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1a, + 0x2a, 0xa4, 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, 0x45, 0x52, 0x5f, 0x49, 0x44, 0x5f, 0x52, 0x58, 0x5f, 0x50, 0x41, 0x43, 0x4b, @@ -2933,12 +2939,17 @@ var file_proto_forwarding_forwarding_common_proto_rawDesc = []byte{ 0x5f, 0x54, 0x58, 0x5f, 0x55, 0x43, 0x41, 0x53, 0x54, 0x5f, 0x50, 0x41, 0x43, 0x4b, 0x45, 0x54, 0x53, 0x10, 0x27, 0x12, 0x23, 0x0a, 0x1f, 0x43, 0x4f, 0x55, 0x4e, 0x54, 0x45, 0x52, 0x5f, 0x49, 0x44, 0x5f, 0x54, 0x58, 0x5f, 0x4e, 0x4f, 0x4e, 0x5f, 0x55, 0x43, 0x41, 0x53, 0x54, 0x5f, 0x50, - 0x41, 0x43, 0x4b, 0x45, 0x54, 0x53, 0x10, 0x28, 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, + 0x41, 0x43, 0x4b, 0x45, 0x54, 0x53, 0x10, 0x28, 0x12, 0x23, 0x0a, 0x1f, 0x43, 0x4f, 0x55, 0x4e, + 0x54, 0x45, 0x52, 0x5f, 0x49, 0x44, 0x5f, 0x54, 0x58, 0x5f, 0x42, 0x52, 0x4f, 0x41, 0x44, 0x43, + 0x41, 0x53, 0x54, 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, } var ( diff --git a/proto/forwarding/forwarding_common.proto b/proto/forwarding/forwarding_common.proto index 93abdaee..7deaf7d5 100644 --- a/proto/forwarding/forwarding_common.proto +++ b/proto/forwarding/forwarding_common.proto @@ -285,6 +285,8 @@ enum CounterId { COUNTER_ID_RX_NON_UCAST_PACKETS = 38; COUNTER_ID_TX_UCAST_PACKETS = 39; COUNTER_ID_TX_NON_UCAST_PACKETS = 40; + COUNTER_ID_TX_BROADCAST_PACKETS = 41; + COUNTER_ID_TX_MULTICAST_PACKETS = 42; COUNTER_ID_MAX = 255; // Maximum counter id. } @@ -411,4 +413,4 @@ message ObjectNIDRequest { message ObjectNIDReply { uint64 nid = 1; -} \ No newline at end of file +}