From 61d9438f0e5d0215d98695c5fac25adbf9680b17 Mon Sep 17 00:00:00 2001 From: Teja Tamboli Date: Sat, 14 Feb 2026 00:25:16 +0000 Subject: [PATCH] Added support for RemoveACLGroupMember and RemoveAclTable --- dataplane/saiserver/acl.go | 21 ++++++++ dataplane/saiserver/acl_test.go | 93 +++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+) diff --git a/dataplane/saiserver/acl.go b/dataplane/saiserver/acl.go index 4e00795ef..e026e8bd8 100644 --- a/dataplane/saiserver/acl.go +++ b/dataplane/saiserver/acl.go @@ -122,6 +122,22 @@ func (a *acl) CreateAclTableGroupMember(_ context.Context, req *saipb.CreateAclT return &saipb.CreateAclTableGroupMemberResponse{Oid: memberID}, nil } +func (a *acl) RemoveAclTableGroupMember(_ context.Context, req *saipb.RemoveAclTableGroupMemberRequest) (*saipb.RemoveAclTableGroupMemberResponse, error) { + var tableID uint64 + found := false + for tid, loc := range a.tableToLocation { + if loc.memberID == req.GetOid() { + tableID = tid + found = true + break + } + } + if found { + delete(a.tableToLocation, tableID) + } + return &saipb.RemoveAclTableGroupMemberResponse{}, nil +} + // CreateAclTable is noop as the table is already created in the group. func (a *acl) CreateAclTable(context.Context, *saipb.CreateAclTableRequest) (*saipb.CreateAclTableResponse, error) { id := a.mgr.NextID() @@ -134,6 +150,11 @@ func (a *acl) CreateAclTable(context.Context, *saipb.CreateAclTableRequest) (*sa return &saipb.CreateAclTableResponse{Oid: id}, nil } +// RemoveAclTable is noop as the table is not created in the datapalne. +func (a *acl) RemoveAclTable(context.Context, *saipb.RemoveAclTableRequest) (*saipb.RemoveAclTableResponse, error) { + return &saipb.RemoveAclTableResponse{}, nil +} + func (a *acl) createAclEntryFields(req *saipb.CreateAclEntryRequest, id uint64, gid string, bank int) (*fwdpb.TableEntryAddRequest, error) { aReq := &fwdpb.TableEntryAddRequest{ ContextId: &fwdpb.ContextId{Id: a.dataplane.ID()}, diff --git a/dataplane/saiserver/acl_test.go b/dataplane/saiserver/acl_test.go index c9fe91147..3fc4a31e2 100644 --- a/dataplane/saiserver/acl_test.go +++ b/dataplane/saiserver/acl_test.go @@ -735,6 +735,99 @@ func TestGetAclCounterAttribute(t *testing.T) { } } +func TestRemoveAclTableGroupMember(t *testing.T) { + tests := []struct { + desc string + req *saipb.RemoveAclTableGroupMemberRequest + wantErr string + setup func(*acl) + wantState map[uint64]tableLocation + }{{ + desc: "success", + req: &saipb.RemoveAclTableGroupMemberRequest{ + Oid: 10, + }, + setup: func(a *acl) { + a.tableToLocation[5] = tableLocation{ + groupID: "1", + bank: 0, + memberID: 10, + } + a.mgr.StoreAttributes(10, &saipb.CreateAclTableGroupMemberRequest{ + Priority: proto.Uint32(100), + }) + }, + wantState: map[uint64]tableLocation{}, + }, { + desc: "not found", + req: &saipb.RemoveAclTableGroupMemberRequest{ + Oid: 11, + }, + setup: func(a *acl) { + a.tableToLocation[5] = tableLocation{ + groupID: "1", + bank: 0, + memberID: 10, + } + a.mgr.StoreAttributes(11, &saipb.CreateAclTableGroupMemberRequest{ + Priority: proto.Uint32(100), + }) + }, + wantState: map[uint64]tableLocation{ + 5: { + groupID: "1", + bank: 0, + memberID: 10, + }, + }, + }} + for _, tt := range tests { + t.Run(tt.desc, func(t *testing.T) { + dplane := &fakeSwitchDataplane{} + c, a, stopFn := newTestACL(t, dplane) + defer stopFn() + if tt.setup != nil { + tt.setup(a) + } + _, gotErr := c.RemoveAclTableGroupMember(context.TODO(), tt.req) + if diff := errdiff.Check(gotErr, tt.wantErr); diff != "" { + t.Fatalf("RemoveAclTableGroupMember() unexpected err: %s", diff) + } + if gotErr != nil { + return + } + if d := cmp.Diff(a.tableToLocation, tt.wantState, cmp.AllowUnexported(tableLocation{})); d != "" { + t.Errorf("RemoveAclTableGroupMember() failed: diff(-got,+want)\n:%s", d) + } + }) + } +} + +func TestRemoveAclTable(t *testing.T) { + tests := []struct { + desc string + req *saipb.RemoveAclTableRequest + wantErr string + }{{ + desc: "success", + req: &saipb.RemoveAclTableRequest{Oid: 1}, + }} + for _, tt := range tests { + t.Run(tt.desc, func(t *testing.T) { + dplane := &fakeSwitchDataplane{} + c, a, stopFn := newTestACL(t, dplane) + a.mgr.StoreAttributes(1, &saipb.CreateAclTableRequest{ + AclStage: saipb.AclStage_ACL_STAGE_INGRESS.Enum(), + }) + defer stopFn() + _, gotErr := c.RemoveAclTable(context.TODO(), tt.req) + if diff := errdiff.Check(gotErr, tt.wantErr); diff != "" { + t.Fatalf("RemoveAclTable() unexpected err: %s", diff) + } + }) + } +} + func newTestACL(t testing.TB, api switchDataplaneAPI) (saipb.AclClient, *acl, func()) { var a *acl conn, _, stopFn := newTestServer(t, func(mgr *attrmgr.AttrMgr, srv *grpc.Server) {