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
21 changes: 21 additions & 0 deletions dataplane/saiserver/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()},
Expand Down
93 changes: 93 additions & 0 deletions dataplane/saiserver/acl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading