Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions dataplane/forwarding/fwdport/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -236,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.
Expand All @@ -253,10 +260,15 @@ 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)
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)
}
}

packet.Log().V(1).Info("input packet", "port", port.ID(), "frame", fwdpacket.IncludeFrameInLog)
Expand Down Expand Up @@ -310,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)
Expand Down
4 changes: 4 additions & 0 deletions dataplane/saiserver/ports.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
23 changes: 17 additions & 6 deletions proto/forwarding/forwarding_common.pb.go

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

2 changes: 2 additions & 0 deletions proto/forwarding/forwarding_common.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}

Expand Down
Loading