diff --git a/dataplane/forwarding/fwdaction/actions/mirror_test.go b/dataplane/forwarding/fwdaction/actions/mirror_test.go index 5ca46b1d2..081cf3aaa 100644 --- a/dataplane/forwarding/fwdaction/actions/mirror_test.go +++ b/dataplane/forwarding/fwdaction/actions/mirror_test.go @@ -203,6 +203,7 @@ func TestMirror(t *testing.T) { 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_DST, 0)).Return([]byte{0}, nil).AnyTimes() + mirrored.EXPECT().Field(fwdpacket.NewFieldIDFromNum(fwdpb.PacketFieldNum_PACKET_FIELD_NUM_ETHER_TYPE, 0)).Return([]byte{0x08, 0x00}, 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), @@ -217,6 +218,7 @@ func TestMirror(t *testing.T) { original.EXPECT().Attributes().Return(nil).AnyTimes() original.EXPECT().Log().Return(testr.New(t)).AnyTimes() original.EXPECT().Field(fwdpacket.NewFieldIDFromNum(fwdpb.PacketFieldNum_PACKET_FIELD_NUM_ETHER_MAC_SRC, 0)).Return([]byte{0}, nil).AnyTimes() + original.EXPECT().Field(fwdpacket.NewFieldIDFromNum(fwdpb.PacketFieldNum_PACKET_FIELD_NUM_ETHER_TYPE, 0)).Return([]byte{0x08, 0x00}, nil).AnyTimes() original.EXPECT().Field(opFID).Return(make([]byte, protocol.SizeUint64), nil).AnyTimes() original.EXPECT().Field(inFID).Return(make([]byte, protocol.SizeUint64), nil).AnyTimes() diff --git a/dataplane/forwarding/fwdport/port.go b/dataplane/forwarding/fwdport/port.go index d47fe4895..d1a03dbae 100644 --- a/dataplane/forwarding/fwdport/port.go +++ b/dataplane/forwarding/fwdport/port.go @@ -71,6 +71,10 @@ var CounterList = []fwdpb.CounterId{ fwdpb.CounterId_COUNTER_ID_TX_MULTICAST_PACKETS, fwdpb.CounterId_COUNTER_ID_RX_BROADCAST_PACKETS, fwdpb.CounterId_COUNTER_ID_RX_MULTICAST_PACKETS, + fwdpb.CounterId_COUNTER_ID_RX_IPV6_PACKETS, + fwdpb.CounterId_COUNTER_ID_TX_IPV6_PACKETS, + fwdpb.CounterId_COUNTER_ID_RX_IPV6_DROP_PACKETS, + fwdpb.CounterId_COUNTER_ID_TX_IPV6_DROP_PACKETS, } // A Port is an entry or exit point within the forwarding plane. Each port @@ -271,6 +275,11 @@ func Input(port Port, packet fwdpacket.Packet, dir fwdpb.PortAction, ctx *fwdcon } } + ethType, err := packet.Field(fwdpacket.NewFieldIDFromNum(fwdpb.PacketFieldNum_PACKET_FIELD_NUM_ETHER_TYPE, 0)) + if err == nil && len(ethType) >= 2 && binary.BigEndian.Uint16(ethType) == 0x86dd { + port.Increment(fwdpb.CounterId_COUNTER_ID_RX_IPV6_PACKETS, 1) + } + packet.Log().V(1).Info("input packet", "port", port.ID(), "frame", fwdpacket.IncludeFrameInLog) state, err := fwdaction.ProcessPacket(packet, port.Actions(dir), port) if err != nil { @@ -282,6 +291,12 @@ func Input(port Port, packet fwdpacket.Packet, dir fwdpb.PortAction, ctx *fwdcon case fwdaction.DROP: packet.Log().V(1).Info("input dropped frame", "port", port.ID(), "frame", fwdpacket.IncludeFrameInLog) Increment(port, packet.Length(), fwdpb.CounterId_COUNTER_ID_RX_DROP_PACKETS, fwdpb.CounterId_COUNTER_ID_RX_DROP_OCTETS) + + ethType, err := packet.Field(fwdpacket.NewFieldIDFromNum(fwdpb.PacketFieldNum_PACKET_FIELD_NUM_ETHER_TYPE, 0)) + if err == nil && len(ethType) >= 2 && binary.BigEndian.Uint16(ethType) == 0x86dd { + port.Increment(fwdpb.CounterId_COUNTER_ID_RX_IPV6_DROP_PACKETS, 1) + } + return nil case fwdaction.CONSUME: @@ -292,6 +307,10 @@ func Input(port Port, packet fwdpacket.Packet, dir fwdpb.PortAction, ctx *fwdcon out, err := OutputPort(packet, ctx) if err != nil { Increment(port, packet.Length(), fwdpb.CounterId_COUNTER_ID_RX_DROP_PACKETS, fwdpb.CounterId_COUNTER_ID_RX_DROP_OCTETS) + ethType, err := packet.Field(fwdpacket.NewFieldIDFromNum(fwdpb.PacketFieldNum_PACKET_FIELD_NUM_ETHER_TYPE, 0)) + if err == nil && len(ethType) >= 2 && binary.BigEndian.Uint16(ethType) == 0x86dd { + port.Increment(fwdpb.CounterId_COUNTER_ID_RX_IPV6_DROP_PACKETS, 1) + } return nil } packet.Log().V(3).Info("transmitting packet", "port", out.ID()) @@ -329,6 +348,11 @@ func Output(port Port, packet fwdpacket.Packet, dir fwdpb.PortAction, _ *fwdcont } } + ethType, err := packet.Field(fwdpacket.NewFieldIDFromNum(fwdpb.PacketFieldNum_PACKET_FIELD_NUM_ETHER_TYPE, 0)) + if err == nil && len(ethType) >= 2 && binary.BigEndian.Uint16(ethType) == 0x86dd { + port.Increment(fwdpb.CounterId_COUNTER_ID_TX_IPV6_PACKETS, 1) + } + packet.Log().V(3).Info("output packet", "frame", fwdpacket.IncludeFrameInLog) state, err := fwdaction.ProcessPacket(packet, port.Actions(dir), port) if err == nil && state == fwdaction.CONTINUE { @@ -342,6 +366,12 @@ func Output(port Port, packet fwdpacket.Packet, dir fwdpb.PortAction, _ *fwdcont case fwdaction.DROP: packet.Log().V(1).Info("output dropped frame", "port", port.ID(), "frame", fwdpacket.IncludeFrameInLog) Increment(port, packet.Length(), fwdpb.CounterId_COUNTER_ID_TX_DROP_PACKETS, fwdpb.CounterId_COUNTER_ID_TX_DROP_OCTETS) + + ethType, err := packet.Field(fwdpacket.NewFieldIDFromNum(fwdpb.PacketFieldNum_PACKET_FIELD_NUM_ETHER_TYPE, 0)) + if err == nil && len(ethType) >= 2 && binary.BigEndian.Uint16(ethType) == 0x86dd { + port.Increment(fwdpb.CounterId_COUNTER_ID_TX_IPV6_DROP_PACKETS, 1) + } + return nil case fwdaction.CONSUME: packet.Log().V(1).Info("consumed frame", "port", port.ID(), "frame", fwdpacket.IncludeFrameInLog) diff --git a/dataplane/saiserver/ports.go b/dataplane/saiserver/ports.go index 9ca4ef5d9..5d4eb9bfa 100644 --- a/dataplane/saiserver/ports.go +++ b/dataplane/saiserver/ports.go @@ -623,6 +623,12 @@ func (port *port) GetPortStats(ctx context.Context, req *saipb.GetPortStatsReque resp.Values = append(resp.Values, counterMap[fwdpb.CounterId_COUNTER_ID_RX_DROP_PACKETS]) case saipb.PortStat_PORT_STAT_IF_OUT_DISCARDS: resp.Values = append(resp.Values, counterMap[fwdpb.CounterId_COUNTER_ID_TX_DROP_PACKETS]) + case saipb.PortStat_PORT_STAT_IPV6_IN_RECEIVES: + resp.Values = append(resp.Values, counterMap[fwdpb.CounterId_COUNTER_ID_RX_IPV6_PACKETS]) + case saipb.PortStat_PORT_STAT_IPV6_IN_DISCARDS: + 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]) default: resp.Values = append(resp.Values, 0) } diff --git a/proto/forwarding/forwarding_common.pb.go b/proto/forwarding/forwarding_common.pb.go index 07eca547a..4ef9bf9d8 100644 --- a/proto/forwarding/forwarding_common.pb.go +++ b/proto/forwarding/forwarding_common.pb.go @@ -484,6 +484,10 @@ const ( 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_RX_IPV6_PACKETS CounterId = 45 + CounterId_COUNTER_ID_TX_IPV6_PACKETS CounterId = 46 + CounterId_COUNTER_ID_RX_IPV6_DROP_PACKETS CounterId = 47 + CounterId_COUNTER_ID_TX_IPV6_DROP_PACKETS CounterId = 48 CounterId_COUNTER_ID_MAX CounterId = 255 ) @@ -535,6 +539,10 @@ var ( 42: "COUNTER_ID_TX_MULTICAST_PACKETS", 43: "COUNTER_ID_RX_BROADCAST_PACKETS", 44: "COUNTER_ID_RX_MULTICAST_PACKETS", + 45: "COUNTER_ID_RX_IPV6_PACKETS", + 46: "COUNTER_ID_TX_IPV6_PACKETS", + 47: "COUNTER_ID_RX_IPV6_DROP_PACKETS", + 48: "COUNTER_ID_TX_IPV6_DROP_PACKETS", 255: "COUNTER_ID_MAX", } CounterId_value = map[string]int32{ @@ -583,6 +591,10 @@ var ( "COUNTER_ID_TX_MULTICAST_PACKETS": 42, "COUNTER_ID_RX_BROADCAST_PACKETS": 43, "COUNTER_ID_RX_MULTICAST_PACKETS": 44, + "COUNTER_ID_RX_IPV6_PACKETS": 45, + "COUNTER_ID_TX_IPV6_PACKETS": 46, + "COUNTER_ID_RX_IPV6_DROP_PACKETS": 47, + "COUNTER_ID_TX_IPV6_DROP_PACKETS": 48, "COUNTER_ID_MAX": 255, } ) @@ -2764,7 +2776,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, 0xee, 0x0b, + 0x5f, 0x4e, 0x55, 0x4d, 0x5f, 0x43, 0x4f, 0x55, 0x4e, 0x54, 0x10, 0xe8, 0x07, 0x2a, 0xf8, 0x0c, 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, @@ -2858,12 +2870,21 @@ var file_proto_forwarding_forwarding_common_proto_rawDesc = string([]byte{ 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, + 0x50, 0x41, 0x43, 0x4b, 0x45, 0x54, 0x53, 0x10, 0x2c, 0x12, 0x1e, 0x0a, 0x1a, 0x43, 0x4f, 0x55, + 0x4e, 0x54, 0x45, 0x52, 0x5f, 0x49, 0x44, 0x5f, 0x52, 0x58, 0x5f, 0x49, 0x50, 0x56, 0x36, 0x5f, + 0x50, 0x41, 0x43, 0x4b, 0x45, 0x54, 0x53, 0x10, 0x2d, 0x12, 0x1e, 0x0a, 0x1a, 0x43, 0x4f, 0x55, + 0x4e, 0x54, 0x45, 0x52, 0x5f, 0x49, 0x44, 0x5f, 0x54, 0x58, 0x5f, 0x49, 0x50, 0x56, 0x36, 0x5f, + 0x50, 0x41, 0x43, 0x4b, 0x45, 0x54, 0x53, 0x10, 0x2e, 0x12, 0x23, 0x0a, 0x1f, 0x43, 0x4f, 0x55, + 0x4e, 0x54, 0x45, 0x52, 0x5f, 0x49, 0x44, 0x5f, 0x52, 0x58, 0x5f, 0x49, 0x50, 0x56, 0x36, 0x5f, + 0x44, 0x52, 0x4f, 0x50, 0x5f, 0x50, 0x41, 0x43, 0x4b, 0x45, 0x54, 0x53, 0x10, 0x2f, 0x12, 0x23, + 0x0a, 0x1f, 0x43, 0x4f, 0x55, 0x4e, 0x54, 0x45, 0x52, 0x5f, 0x49, 0x44, 0x5f, 0x54, 0x58, 0x5f, + 0x49, 0x50, 0x56, 0x36, 0x5f, 0x44, 0x52, 0x4f, 0x50, 0x5f, 0x50, 0x41, 0x43, 0x4b, 0x45, 0x54, + 0x53, 0x10, 0x30, 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 eaf41db11..2f9b09310 100644 --- a/proto/forwarding/forwarding_common.proto +++ b/proto/forwarding/forwarding_common.proto @@ -291,6 +291,10 @@ enum CounterId { COUNTER_ID_TX_MULTICAST_PACKETS = 42; COUNTER_ID_RX_BROADCAST_PACKETS = 43; COUNTER_ID_RX_MULTICAST_PACKETS = 44; + COUNTER_ID_RX_IPV6_PACKETS = 45; + COUNTER_ID_TX_IPV6_PACKETS = 46; + COUNTER_ID_RX_IPV6_DROP_PACKETS = 47; + COUNTER_ID_TX_IPV6_DROP_PACKETS = 48; COUNTER_ID_MAX = 255; // Maximum counter id. }