Skip to content

Commit 1a0778f

Browse files
authored
Merge pull request #653 from tejatamboli02/acl
Added support for RemoveACLGroupMember and RemoveAclTable
2 parents f7e1235 + 61d9438 commit 1a0778f

2 files changed

Lines changed: 114 additions & 0 deletions

File tree

dataplane/saiserver/acl.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,22 @@ func (a *acl) CreateAclTableGroupMember(_ context.Context, req *saipb.CreateAclT
122122
return &saipb.CreateAclTableGroupMemberResponse{Oid: memberID}, nil
123123
}
124124

125+
func (a *acl) RemoveAclTableGroupMember(_ context.Context, req *saipb.RemoveAclTableGroupMemberRequest) (*saipb.RemoveAclTableGroupMemberResponse, error) {
126+
var tableID uint64
127+
found := false
128+
for tid, loc := range a.tableToLocation {
129+
if loc.memberID == req.GetOid() {
130+
tableID = tid
131+
found = true
132+
break
133+
}
134+
}
135+
if found {
136+
delete(a.tableToLocation, tableID)
137+
}
138+
return &saipb.RemoveAclTableGroupMemberResponse{}, nil
139+
}
140+
125141
// CreateAclTable is noop as the table is already created in the group.
126142
func (a *acl) CreateAclTable(context.Context, *saipb.CreateAclTableRequest) (*saipb.CreateAclTableResponse, error) {
127143
id := a.mgr.NextID()
@@ -134,6 +150,11 @@ func (a *acl) CreateAclTable(context.Context, *saipb.CreateAclTableRequest) (*sa
134150
return &saipb.CreateAclTableResponse{Oid: id}, nil
135151
}
136152

153+
// RemoveAclTable is noop as the table is not created in the datapalne.
154+
func (a *acl) RemoveAclTable(context.Context, *saipb.RemoveAclTableRequest) (*saipb.RemoveAclTableResponse, error) {
155+
return &saipb.RemoveAclTableResponse{}, nil
156+
}
157+
137158
func (a *acl) createAclEntryFields(req *saipb.CreateAclEntryRequest, id uint64, gid string, bank int) (*fwdpb.TableEntryAddRequest, error) {
138159
aReq := &fwdpb.TableEntryAddRequest{
139160
ContextId: &fwdpb.ContextId{Id: a.dataplane.ID()},

dataplane/saiserver/acl_test.go

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,99 @@ func TestGetAclCounterAttribute(t *testing.T) {
735735
}
736736
}
737737

738+
func TestRemoveAclTableGroupMember(t *testing.T) {
739+
tests := []struct {
740+
desc string
741+
req *saipb.RemoveAclTableGroupMemberRequest
742+
wantErr string
743+
setup func(*acl)
744+
wantState map[uint64]tableLocation
745+
}{{
746+
desc: "success",
747+
req: &saipb.RemoveAclTableGroupMemberRequest{
748+
Oid: 10,
749+
},
750+
setup: func(a *acl) {
751+
a.tableToLocation[5] = tableLocation{
752+
groupID: "1",
753+
bank: 0,
754+
memberID: 10,
755+
}
756+
a.mgr.StoreAttributes(10, &saipb.CreateAclTableGroupMemberRequest{
757+
Priority: proto.Uint32(100),
758+
})
759+
},
760+
wantState: map[uint64]tableLocation{},
761+
}, {
762+
desc: "not found",
763+
req: &saipb.RemoveAclTableGroupMemberRequest{
764+
Oid: 11,
765+
},
766+
setup: func(a *acl) {
767+
a.tableToLocation[5] = tableLocation{
768+
groupID: "1",
769+
bank: 0,
770+
memberID: 10,
771+
}
772+
a.mgr.StoreAttributes(11, &saipb.CreateAclTableGroupMemberRequest{
773+
Priority: proto.Uint32(100),
774+
})
775+
},
776+
wantState: map[uint64]tableLocation{
777+
5: {
778+
groupID: "1",
779+
bank: 0,
780+
memberID: 10,
781+
},
782+
},
783+
}}
784+
for _, tt := range tests {
785+
t.Run(tt.desc, func(t *testing.T) {
786+
dplane := &fakeSwitchDataplane{}
787+
c, a, stopFn := newTestACL(t, dplane)
788+
defer stopFn()
789+
if tt.setup != nil {
790+
tt.setup(a)
791+
}
792+
_, gotErr := c.RemoveAclTableGroupMember(context.TODO(), tt.req)
793+
if diff := errdiff.Check(gotErr, tt.wantErr); diff != "" {
794+
t.Fatalf("RemoveAclTableGroupMember() unexpected err: %s", diff)
795+
}
796+
if gotErr != nil {
797+
return
798+
}
799+
if d := cmp.Diff(a.tableToLocation, tt.wantState, cmp.AllowUnexported(tableLocation{})); d != "" {
800+
t.Errorf("RemoveAclTableGroupMember() failed: diff(-got,+want)\n:%s", d)
801+
}
802+
})
803+
}
804+
}
805+
806+
func TestRemoveAclTable(t *testing.T) {
807+
tests := []struct {
808+
desc string
809+
req *saipb.RemoveAclTableRequest
810+
wantErr string
811+
}{{
812+
desc: "success",
813+
req: &saipb.RemoveAclTableRequest{Oid: 1},
814+
}}
815+
for _, tt := range tests {
816+
t.Run(tt.desc, func(t *testing.T) {
817+
dplane := &fakeSwitchDataplane{}
818+
c, a, stopFn := newTestACL(t, dplane)
819+
a.mgr.StoreAttributes(1, &saipb.CreateAclTableRequest{
820+
AclStage: saipb.AclStage_ACL_STAGE_INGRESS.Enum(),
821+
})
822+
defer stopFn()
823+
_, gotErr := c.RemoveAclTable(context.TODO(), tt.req)
824+
if diff := errdiff.Check(gotErr, tt.wantErr); diff != "" {
825+
t.Fatalf("RemoveAclTable() unexpected err: %s", diff)
826+
}
827+
})
828+
}
829+
}
830+
738831
func newTestACL(t testing.TB, api switchDataplaneAPI) (saipb.AclClient, *acl, func()) {
739832
var a *acl
740833
conn, _, stopFn := newTestServer(t, func(mgr *attrmgr.AttrMgr, srv *grpc.Server) {

0 commit comments

Comments
 (0)