Skip to content

Commit

Permalink
Add multicast and broadcast counter support to Lucius.
Browse files Browse the repository at this point in the history
  • Loading branch information
royyi8 committed Jan 6, 2025
1 parent 1857c60 commit 3951f5a
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 12 deletions.
2 changes: 2 additions & 0 deletions dataplane/dplanerc/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion dataplane/forwarding/fwdaction/actions/mirror_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
15 changes: 12 additions & 3 deletions dataplane/forwarding/fwdport/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Check failure on line 236 in dataplane/forwarding/fwdport/port.go

View workflow job for this annotation

GitHub Actions / lint

File is not properly formatted (gofmt)
}

// Input processes an incoming packet. The specified port actions are applied
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions dataplane/saiserver/ports.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
25 changes: 18 additions & 7 deletions proto/forwarding/forwarding_common.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion proto/forwarding/forwarding_common.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}

Expand Down Expand Up @@ -411,4 +413,4 @@ message ObjectNIDRequest {

message ObjectNIDReply {
uint64 nid = 1;
}
}

0 comments on commit 3951f5a

Please sign in to comment.