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
3 changes: 2 additions & 1 deletion dataplane/saiserver/hostif.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
54 changes: 54 additions & 0 deletions dataplane/saiserver/hostif_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
Loading