From f2aed8672204ef1779358a34eb7a741ec7c64d46 Mon Sep 17 00:00:00 2001 From: Teja Tamboli Date: Mon, 9 Feb 2026 18:43:31 +0000 Subject: [PATCH] Add support for new trap type HOSTIF_TRAP_TYPE_P4RT --- dataplane/saiserver/hostif.go | 3 +- dataplane/saiserver/hostif_test.go | 54 ++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/dataplane/saiserver/hostif.go b/dataplane/saiserver/hostif.go index 5d1b89674..940d8a761 100644 --- a/dataplane/saiserver/hostif.go +++ b/dataplane/saiserver/hostif.go @@ -299,7 +299,8 @@ func (hostif *hostif) CreateHostifTrap(ctx context.Context, req *saipb.CreateHos saipb.HostifTrapType_HOSTIF_TRAP_TYPE_NTPCLIENT, saipb.HostifTrapType_HOSTIF_TRAP_TYPE_NTPSERVER, saipb.HostifTrapType_HOSTIF_TRAP_TYPE_HTTPCLIENT, - saipb.HostifTrapType_HOSTIF_TRAP_TYPE_HTTPSERVER: + saipb.HostifTrapType_HOSTIF_TRAP_TYPE_HTTPSERVER, + saipb.HostifTrapType_HOSTIF_TRAP_TYPE_P4RT: // IP2ME routes are added to the FIB, do nothing here. return &saipb.CreateHostifTrapResponse{ Oid: id, diff --git a/dataplane/saiserver/hostif_test.go b/dataplane/saiserver/hostif_test.go index 64a7fbf75..f5b4bd2e4 100644 --- a/dataplane/saiserver/hostif_test.go +++ b/dataplane/saiserver/hostif_test.go @@ -287,6 +287,60 @@ func TestCPUPacketStream(t *testing.T) { }) } +func TestCreateHostifTrap(t *testing.T) { + tests := []struct { + desc string + req *saipb.CreateHostifTrapRequest + want *saipb.CreateHostifTrapResponse + wantErr string + }{{ + desc: "p4rt trap", + req: &saipb.CreateHostifTrapRequest{ + Switch: 1, + TrapType: saipb.HostifTrapType_HOSTIF_TRAP_TYPE_P4RT.Enum(), + PacketAction: saipb.PacketAction_PACKET_ACTION_TRAP.Enum(), + }, + want: &saipb.CreateHostifTrapResponse{ + Oid: 1, + }, + }, { + desc: "arp trap", + req: &saipb.CreateHostifTrapRequest{ + Switch: 1, + TrapType: saipb.HostifTrapType_HOSTIF_TRAP_TYPE_ARP_REQUEST.Enum(), + PacketAction: saipb.PacketAction_PACKET_ACTION_TRAP.Enum(), + }, + want: &saipb.CreateHostifTrapResponse{ + Oid: 1, + }, + }} + for _, tt := range tests { + t.Run(tt.desc, func(t *testing.T) { + dplane := &fakeSwitchDataplane{ + ctx: fwdcontext.New("foo", "foo"), + } + c, mgr, stopFn := newTestHostif(t, dplane) + defer stopFn() + + // CPU Port is required for CreateHostifTrap + mgr.StoreAttributes(1, &saipb.SwitchAttribute{ + CpuPort: proto.Uint64(10), + }) + + got, gotErr := c.CreateHostifTrap(context.TODO(), tt.req) + if diff := errdiff.Check(gotErr, tt.wantErr); diff != "" { + t.Fatalf("CreateHostifTrap() unexpected err: %s", diff) + } + if gotErr != nil { + return + } + if d := cmp.Diff(got, tt.want, protocmp.Transform()); d != "" { + t.Errorf("CreateHostifTrap() failed: diff(-got,+want)\n:%s", d) + } + }) + } +} + func createPacket(t testing.TB, nid uint64) fwdpacket.Packet { t.Helper() eth := &layers.Ethernet{