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
1 change: 1 addition & 0 deletions dataplane/saiserver/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go_library(
name = "saiserver",
srcs = [
"acl.go",
"debug_counter.go",
"fdb.go",
"hostif.go",
"isolation_group.go",
Expand Down
68 changes: 68 additions & 0 deletions dataplane/saiserver/debug_counter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package saiserver

import (
"context"

saipb "github.com/openconfig/lemming/dataplane/proto/sai"
"github.com/openconfig/lemming/dataplane/saiserver/attrmgr"
"google.golang.org/grpc"
"google.golang.org/protobuf/proto"
)

type debugCounter struct {
saipb.UnimplementedDebugCounterServer
mgr *attrmgr.AttrMgr
dataplane switchDataplaneAPI
}

func newDebugCounter(mgr *attrmgr.AttrMgr, engine switchDataplaneAPI, s *grpc.Server) *debugCounter {
d := &debugCounter{
mgr: mgr,
dataplane: engine,
}
saipb.RegisterDebugCounterServer(s, d)
return d
}

func (d *debugCounter) CreateDebugCounter(ctx context.Context, req *saipb.CreateDebugCounterRequest) (*saipb.CreateDebugCounterResponse, error) {
oid := d.mgr.NextID()
index := uint32(0)
for _, reason := range req.InDropReasonList {
if reason == saipb.InDropReason_IN_DROP_REASON_LPM4_MISS {
index = 0
break
}
if reason == saipb.InDropReason_IN_DROP_REASON_LPM6_MISS {
index = 1
break
}
}

d.mgr.StoreAttributes(oid, &saipb.DebugCounterAttribute{
Index: proto.Uint32(index),
})
return &saipb.CreateDebugCounterResponse{Oid: oid}, nil
}

func (d *debugCounter) RemoveDebugCounter(ctx context.Context, req *saipb.RemoveDebugCounterRequest) (*saipb.RemoveDebugCounterResponse, error) {
return &saipb.RemoveDebugCounterResponse{}, nil
}

func (d *debugCounter) SetDebugCounterAttribute(ctx context.Context, req *saipb.SetDebugCounterAttributeRequest) (*saipb.SetDebugCounterAttributeResponse, error) {
return &saipb.SetDebugCounterAttributeResponse{}, nil
}

30 changes: 30 additions & 0 deletions dataplane/saiserver/routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,21 @@ func (r *route) CreateRouteEntry(ctx context.Context, req *saipb.CreateRouteEntr
}
} else {
actions = append(actions, fwdconfig.UpdateAction(fwdpb.UpdateType_UPDATE_TYPE_BIT_WRITE, fwdpb.PacketFieldNum_PACKET_FIELD_NUM_PACKET_ACTION).WithBitOp(1, 0).WithValue([]byte{0}))

isZeroMask := true
for _, b := range req.GetEntry().GetDestination().GetMask() {
if b != 0 {
isZeroMask = false
break
}
}
if isZeroMask {
counterID := "LPM6_MISS_COUNTER"
if fib == FIBV4Table {
counterID = "LPM4_MISS_COUNTER"
}
actions = append(actions, fwdconfig.FlowCounterAction(counterID))
}
}
if req.MetaData != nil {
actions = append(actions, fwdconfig.UpdateAction(fwdpb.UpdateType_UPDATE_TYPE_SET, fwdpb.PacketFieldNum_PACKET_FIELD_NUM_PACKET_ATTRIBUTE_32).
Expand Down Expand Up @@ -829,6 +844,21 @@ func (r *route) SetRouteEntryAttribute(ctx context.Context, req *saipb.SetRouteE
}
} else {
actions = append(actions, fwdconfig.UpdateAction(fwdpb.UpdateType_UPDATE_TYPE_BIT_WRITE, fwdpb.PacketFieldNum_PACKET_FIELD_NUM_PACKET_ACTION).WithBitOp(1, 0).WithValue([]byte{0}))

isZeroMask := true
for _, b := range req.GetEntry().GetDestination().GetMask() {
if b != 0 {
isZeroMask = false
break
}
}
if isZeroMask {
counterID := "LPM6_MISS_COUNTER"
if fib == FIBV4Table {
counterID = "LPM4_MISS_COUNTER"
}
actions = append(actions, fwdconfig.FlowCounterAction(counterID))
}
}
if metaData != nil {
actions = append(actions, fwdconfig.UpdateAction(fwdpb.UpdateType_UPDATE_TYPE_SET, fwdpb.PacketFieldNum_PACKET_FIELD_NUM_PACKET_ATTRIBUTE_32).
Expand Down
6 changes: 1 addition & 5 deletions dataplane/saiserver/saiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ type counter struct {
saipb.UnimplementedCounterServer
}

type debugCounter struct {
saipb.UnimplementedDebugCounterServer
}

type dtel struct {
saipb.UnimplementedDtelServer
Expand Down Expand Up @@ -209,7 +206,7 @@ func New(ctx context.Context, mgr *attrmgr.AttrMgr, s *grpc.Server, opts *dplane
forwardingContext: fwdCtx,
bfd: &bfd{},
counter: &counter{},
debugCounter: &debugCounter{},
debugCounter: newDebugCounter(mgr, fwdCtx, s),
dtel: &dtel{},
fdb: fdb,
ipmcGroup: &ipmcGroup{},
Expand All @@ -232,7 +229,6 @@ func New(ctx context.Context, mgr *attrmgr.AttrMgr, s *grpc.Server, opts *dplane
saipb.RegisterEntrypointServer(s, srv)
saipb.RegisterBfdServer(s, srv.bfd)
saipb.RegisterCounterServer(s, srv.counter)
saipb.RegisterDebugCounterServer(s, srv.debugCounter)
saipb.RegisterDtelServer(s, srv.dtel)
saipb.RegisterIpmcGroupServer(s, srv.ipmcGroup)
saipb.RegisterIpmcServer(s, srv.ipmc)
Expand Down
117 changes: 114 additions & 3 deletions dataplane/saiserver/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,33 @@ func (sw *saiSwitch) CreateSwitch(ctx context.Context, _ *saipb.CreateSwitchRequ
swID := sw.mgr.NextID()
slog.InfoContext(ctx, "Creating new switch id", "id", swID)

// Create LPM miss flow counters if they don't exist.
qResp, err := sw.dataplane.FlowCounterQuery(ctx, &fwdpb.FlowCounterQueryRequest{
ContextId: &fwdpb.ContextId{Id: sw.dataplane.ID()},
Ids: []*fwdpb.FlowCounterId{{ObjectId: &fwdpb.ObjectId{Id: "LPM4_MISS_COUNTER"}}},
})
if err != nil || len(qResp.GetCounters()) == 0 {
if _, err := sw.dataplane.FlowCounterCreate(ctx, &fwdpb.FlowCounterCreateRequest{
ContextId: &fwdpb.ContextId{Id: sw.dataplane.ID()},
Id: &fwdpb.FlowCounterId{ObjectId: &fwdpb.ObjectId{Id: "LPM4_MISS_COUNTER"}},
}); err != nil {
return nil, err
}
}

qResp6, err := sw.dataplane.FlowCounterQuery(ctx, &fwdpb.FlowCounterQueryRequest{
ContextId: &fwdpb.ContextId{Id: sw.dataplane.ID()},
Ids: []*fwdpb.FlowCounterId{{ObjectId: &fwdpb.ObjectId{Id: "LPM6_MISS_COUNTER"}}},
})
if err != nil || len(qResp6.GetCounters()) == 0 {
if _, err := sw.dataplane.FlowCounterCreate(ctx, &fwdpb.FlowCounterCreateRequest{
ContextId: &fwdpb.ContextId{Id: sw.dataplane.ID()},
Id: &fwdpb.FlowCounterId{ObjectId: &fwdpb.ObjectId{Id: "LPM6_MISS_COUNTER"}},
}); err != nil {
return nil, err
}
}

// Setup forwarding tables.
ingressVRF := &fwdpb.TableCreateRequest{
ContextId: &fwdpb.ContextId{Id: sw.dataplane.ID()},
Expand Down Expand Up @@ -295,7 +322,17 @@ func (sw *saiSwitch) CreateSwitch(ctx context.Context, _ *saipb.CreateSwitchRequ
Desc: &fwdpb.TableDesc{
TableType: fwdpb.TableType_TABLE_TYPE_PREFIX,
TableId: &fwdpb.TableId{ObjectId: &fwdpb.ObjectId{Id: FIBV4Table}},
Actions: []*fwdpb.ActionDesc{fwdconfig.Action(fwdconfig.UpdateAction(fwdpb.UpdateType_UPDATE_TYPE_BIT_WRITE, fwdpb.PacketFieldNum_PACKET_FIELD_NUM_PACKET_ACTION).WithBitOp(1, 0).WithValue([]byte{0})).Build()},
Actions: []*fwdpb.ActionDesc{
fwdconfig.Action(fwdconfig.UpdateAction(fwdpb.UpdateType_UPDATE_TYPE_BIT_WRITE, fwdpb.PacketFieldNum_PACKET_FIELD_NUM_PACKET_ACTION).WithBitOp(1, 0).WithValue([]byte{0})).Build(),
{
ActionType: fwdpb.ActionType_ACTION_TYPE_FLOW_COUNTER,
Action: &fwdpb.ActionDesc_Flow{
Flow: &fwdpb.FlowCounterActionDesc{
CounterId: &fwdpb.FlowCounterId{ObjectId: &fwdpb.ObjectId{Id: "LPM4_MISS_COUNTER"}},
},
},
},
},
Table: &fwdpb.TableDesc_Prefix{
Prefix: &fwdpb.PrefixTableDesc{
FieldIds: []*fwdpb.PacketFieldId{{
Expand All @@ -319,7 +356,17 @@ func (sw *saiSwitch) CreateSwitch(ctx context.Context, _ *saipb.CreateSwitchRequ
Desc: &fwdpb.TableDesc{
TableType: fwdpb.TableType_TABLE_TYPE_PREFIX,
TableId: &fwdpb.TableId{ObjectId: &fwdpb.ObjectId{Id: FIBV6Table}},
Actions: []*fwdpb.ActionDesc{fwdconfig.Action(fwdconfig.UpdateAction(fwdpb.UpdateType_UPDATE_TYPE_BIT_WRITE, fwdpb.PacketFieldNum_PACKET_FIELD_NUM_PACKET_ACTION).WithBitOp(1, 0).WithValue([]byte{0})).Build()},
Actions: []*fwdpb.ActionDesc{
fwdconfig.Action(fwdconfig.UpdateAction(fwdpb.UpdateType_UPDATE_TYPE_BIT_WRITE, fwdpb.PacketFieldNum_PACKET_FIELD_NUM_PACKET_ACTION).WithBitOp(1, 0).WithValue([]byte{0})).Build(),
{
ActionType: fwdpb.ActionType_ACTION_TYPE_FLOW_COUNTER,
Action: &fwdpb.ActionDesc_Flow{
Flow: &fwdpb.FlowCounterActionDesc{
CounterId: &fwdpb.FlowCounterId{ObjectId: &fwdpb.ObjectId{Id: "LPM6_MISS_COUNTER"}},
},
},
},
},
Table: &fwdpb.TableDesc_Prefix{
Prefix: &fwdpb.PrefixTableDesc{
FieldIds: []*fwdpb.PacketFieldId{{
Expand Down Expand Up @@ -515,7 +562,7 @@ func (sw *saiSwitch) CreateSwitch(ctx context.Context, _ *saipb.CreateSwitchRequ
if _, err := sw.dataplane.TableCreate(ctx, nexthopAction); err != nil {
return nil, err
}
_, err := sw.dataplane.TableCreate(ctx, &fwdpb.TableCreateRequest{
_, err = sw.dataplane.TableCreate(ctx, &fwdpb.TableCreateRequest{
ContextId: &fwdpb.ContextId{Id: sw.dataplane.ID()},
Desc: &fwdpb.TableDesc{
TableId: &fwdpb.TableId{ObjectId: &fwdpb.ObjectId{Id: portToHostifTable}},
Expand Down Expand Up @@ -875,6 +922,26 @@ func (sw *saiSwitch) CreateSwitch(ctx context.Context, _ *saipb.CreateSwitchRequ
SwitchShellEnable: proto.Bool(false),
SwitchProfileId: proto.Uint32(0),
NatZoneCounterObjectId: proto.Uint64(0),
SupportedObjectTypeList: []saipb.ObjectType{
saipb.ObjectType_OBJECT_TYPE_PORT,
saipb.ObjectType_OBJECT_TYPE_VLAN,
saipb.ObjectType_OBJECT_TYPE_VIRTUAL_ROUTER,
saipb.ObjectType_OBJECT_TYPE_NEXT_HOP,
saipb.ObjectType_OBJECT_TYPE_NEXT_HOP_GROUP,
saipb.ObjectType_OBJECT_TYPE_ROUTE_ENTRY,
saipb.ObjectType_OBJECT_TYPE_FDB_ENTRY,
saipb.ObjectType_OBJECT_TYPE_ACL_TABLE,
saipb.ObjectType_OBJECT_TYPE_ACL_ENTRY,
saipb.ObjectType_OBJECT_TYPE_DEBUG_COUNTER,
},
SupportedDebugCounterTypeList: []saipb.DebugCounterType{
saipb.DebugCounterType_DEBUG_COUNTER_TYPE_SWITCH_IN_DROP_REASONS,
},
SupportedIngressDropReasonList: []saipb.InDropReason{
saipb.InDropReason_IN_DROP_REASON_LPM4_MISS,
saipb.InDropReason_IN_DROP_REASON_LPM6_MISS,
},
AvailableSwitchIngressDropCounters: proto.Uint32(2),
}
sw.mgr.StoreAttributes(swID, attrs)
return &saipb.CreateSwitchResponse{
Expand Down Expand Up @@ -1136,6 +1203,50 @@ func (sw *saiSwitch) Reset() {
sw.hostif.Reset()
}

// GetSwitchStats returns the statistics for the switch.
func (sw *saiSwitch) GetSwitchStats(ctx context.Context, req *saipb.GetSwitchStatsRequest) (*saipb.GetSwitchStatsResponse, error) {
slog.ErrorContext(ctx, "GetSwitchStats called", "req", req)
resp := &saipb.GetSwitchStatsResponse{}
for _, id := range req.GetCounterIds() {
var val uint64
switch id {
case saipb.SwitchStat_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_0_DROPPED_PKTS:
count, err := sw.dataplane.FlowCounterQuery(ctx, &fwdpb.FlowCounterQueryRequest{
ContextId: &fwdpb.ContextId{Id: sw.dataplane.ID()},
Ids: []*fwdpb.FlowCounterId{{ObjectId: &fwdpb.ObjectId{Id: "LPM4_MISS_COUNTER"}}},
})
if err != nil {
return nil, err
}
if len(count.GetCounters()) > 0 {
val = count.GetCounters()[0].GetPackets()
slog.ErrorContext(ctx, "GetSwitchStats: LPM4_MISS_COUNTER", "packets", val)
} else {
slog.InfoContext(ctx, "GetSwitchStats: LPM4_MISS_COUNTER not found in response")
}
case saipb.SwitchStat_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS:
count, err := sw.dataplane.FlowCounterQuery(ctx, &fwdpb.FlowCounterQueryRequest{
ContextId: &fwdpb.ContextId{Id: sw.dataplane.ID()},
Ids: []*fwdpb.FlowCounterId{{ObjectId: &fwdpb.ObjectId{Id: "LPM6_MISS_COUNTER"}}},
})
if err != nil {
return nil, err
}
if len(count.GetCounters()) > 0 {
val = count.GetCounters()[0].GetPackets()
slog.ErrorContext(ctx, "GetSwitchStats: LPM6_MISS_COUNTER", "packets", val)
} else {
slog.InfoContext(ctx, "GetSwitchStats: LPM6_MISS_COUNTER not found in response")
}
default:
val = 0
}
resp.Values = append(resp.Values, val)
}

return resp, nil
}

// createFIBSelector creates a table that controls which forwarding table is used.
func (sw *saiSwitch) createFIBSelector(ctx context.Context) error {
fieldID := &fwdpb.PacketFieldId{
Expand Down
Loading
Loading