Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support copy action in ACL #488

Merged
merged 3 commits into from
Oct 25, 2024
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
18 changes: 18 additions & 0 deletions dataplane/saiserver/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"

saipb "github.com/openconfig/lemming/dataplane/proto/sai"
fwdpb "github.com/openconfig/lemming/proto/forwarding"
Expand Down Expand Up @@ -120,6 +121,12 @@ func (a *acl) CreateAclTableGroupMember(_ context.Context, req *saipb.CreateAclT
// 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()

a.mgr.StoreAttributes(id, &saipb.AclTableAttribute{
AvailableAclEntry: proto.Uint32(10000),
DanG100 marked this conversation as resolved.
Show resolved Hide resolved
AvailableAclCounter: proto.Uint32(10000),
})

return &saipb.CreateAclTableResponse{Oid: id}, nil
}

Expand Down Expand Up @@ -370,6 +377,17 @@ func (a *acl) CreateAclEntry(ctx context.Context, req *saipb.CreateAclEntryReque
aReq.Actions = append(aReq.Actions, &fwdpb.ActionDesc{ActionType: fwdpb.ActionType_ACTION_TYPE_DROP})
case saipb.PacketAction_PACKET_ACTION_TRAP: // COPY and DROP
aReq.Actions = append(aReq.Actions, fwdconfig.Action(fwdconfig.TransmitAction(fmt.Sprint(resp.GetAttr().GetCpuPort())).WithImmediate(true)).Build())
case saipb.PacketAction_PACKET_ACTION_COPY:
aReq.Actions = append(aReq.Actions, &fwdpb.ActionDesc{
ActionType: fwdpb.ActionType_ACTION_TYPE_MIRROR,
Action: &fwdpb.ActionDesc_Mirror{Mirror: &fwdpb.MirrorActionDesc{
PortId: &fwdpb.PortId{ObjectId: &fwdpb.ObjectId{Id: fmt.Sprint(resp.GetAttr().GetCpuPort())}},
FieldIds: []*fwdpb.PacketFieldId{{
Field: &fwdpb.PacketField{FieldNum: fwdpb.PacketFieldNum_PACKET_FIELD_NUM_TRAP_ID},
}},
PortAction: fwdpb.PortAction_PORT_ACTION_OUTPUT,
}},
})
case saipb.PacketAction_PACKET_ACTION_LOG: // COPY and FORWARD
mirror := &fwdpb.ActionDesc{
ActionType: fwdpb.ActionType_ACTION_TYPE_MIRROR,
Expand Down
6 changes: 3 additions & 3 deletions dataplane/saiserver/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -767,10 +767,10 @@ func (sw *saiSwitch) CreateSwitch(ctx context.Context, _ *saipb.CreateSwitchRequ
CpuPort: proto.Uint64(cpuPortID),
NumberOfActivePorts: proto.Uint32(0),
AclEntryMinimumPriority: proto.Uint32(1),
AclEntryMaximumPriority: proto.Uint32(100),
AclEntryMaximumPriority: proto.Uint32(10000),
AclTableMinimumPriority: proto.Uint32(1),
AclTableMaximumPriority: proto.Uint32(100),
MaxAclActionCount: proto.Uint32(50),
AclTableMaximumPriority: proto.Uint32(10000),
MaxAclActionCount: proto.Uint32(1000),
NumberOfEcmpGroups: proto.Uint32(1024),
PortList: []uint64{cpuPortID},
SwitchHardwareInfo: []int32{},
Expand Down
6 changes: 3 additions & 3 deletions dataplane/saiserver/switch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ func TestCreateSwitch(t *testing.T) {
CpuPort: proto.Uint64(2),
NumberOfActivePorts: proto.Uint32(0),
AclEntryMinimumPriority: proto.Uint32(1),
AclEntryMaximumPriority: proto.Uint32(100),
AclEntryMaximumPriority: proto.Uint32(10000),
AclTableMinimumPriority: proto.Uint32(1),
AclTableMaximumPriority: proto.Uint32(100),
MaxAclActionCount: proto.Uint32(50),
AclTableMaximumPriority: proto.Uint32(10000),
MaxAclActionCount: proto.Uint32(1000),
NumberOfEcmpGroups: proto.Uint32(1024),
PortList: []uint64{2},
SwitchHardwareInfo: []int32{},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func TestStreamPackets(t *testing.T) {
mgr.sendQueue.Write(pkt)
}
mgr.StreamPackets(ps)
time.Sleep(time.Millisecond) // Sleep long enough to drain the send queue.
time.Sleep(5 * time.Millisecond) // Sleep long enough to drain the send queue.

if d := cmp.Diff(ps.sendPackets, tt.wantSentPacket, protocmp.Transform()); d != "" {
t.Errorf("StreamPackets() failed: sent packet diff(-got,+want)\n:%s", d)
Expand Down Expand Up @@ -134,7 +134,7 @@ func TestManagePorts(t *testing.T) {
t.Fatalf("unexpected error on New(): %v", err)
}
builder[pktiopb.PortType_PORT_TYPE_NETDEV] = func(hpcm *pktiopb.HostPortControlMessage) (PortIO, error) {
return nil, nil
return &fakePort{}, nil
}
linkByName = func(name string) (netlink.Link, error) {
return &fakeLink{}, nil
Expand Down Expand Up @@ -162,6 +162,10 @@ type fakePort struct {
writtenData []*portWriteData
}

func (p *fakePort) Read([]byte) (int, error) {
return 0, nil
}

func (p *fakePort) Write(frame []byte, md *kernel.PacketMetadata) (int, error) {
p.writtenData = append(p.writtenData, &portWriteData{Frame: frame, MD: md})
return len(frame), nil
Expand Down
Loading