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

More tests with debugging. #391

Merged
merged 4 commits into from
Mar 29, 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
89 changes: 48 additions & 41 deletions dataplane/saiserver/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,36 +293,28 @@ func (a *acl) CreateAclEntry(ctx context.Context, req *saipb.CreateAclEntryReque
return &saipb.CreateAclEntryResponse{Oid: id}, nil
}

type myMacInfo struct {
priority *uint32
portID *uint64 // wildcard if not specified
vlanID *uint16 // wildcard if not specified
macAddress []byte
macAddressMask []byte
}

// ToEntryDesc returns the EntryDesc.
func (mi *myMacInfo) ToEntryDesc(m *myMac) (*fwdpb.EntryDesc, error) {
if mi.priority == nil {
// entryDescFromReq returns the EntryDesc based on req.
func entryDescFromReq(m *myMac, req *saipb.CreateMyMacRequest) (*fwdpb.EntryDesc, error) {
if req.Priority == nil {
return nil, fmt.Errorf("priority needs to be specified")
}
fields := []*fwdconfig.PacketFieldMaskedBytesBuilder{
fwdconfig.PacketFieldMaskedBytes(fwdpb.PacketFieldNum_PACKET_FIELD_NUM_ETHER_MAC_DST).
WithBytes(mi.macAddress, mi.macAddressMask),
WithBytes(req.GetMacAddress(), req.GetMacAddressMask()),
}

if mi.vlanID != nil {
if req.VlanId != nil {
fields = append(fields,
fwdconfig.PacketFieldMaskedBytes(fwdpb.PacketFieldNum_PACKET_FIELD_NUM_VLAN_TAG).
WithBytes(binary.BigEndian.AppendUint16(nil, *mi.vlanID), binary.BigEndian.AppendUint16(nil, 0x0FFF)))
WithBytes(binary.BigEndian.AppendUint16(nil, uint16(req.GetVlanId())), binary.BigEndian.AppendUint16(nil, 0x0FFF)))
}

if mi.portID != nil {
if req.PortId != nil {
fwdCtx, err := m.dataplane.FindContext(&fwdpb.ContextId{Id: m.dataplane.ID()})
if err != nil {
return nil, err
}
obj, err := fwdCtx.Objects.FindID(&fwdpb.ObjectId{Id: fmt.Sprint(*mi.portID)})
obj, err := fwdCtx.Objects.FindID(&fwdpb.ObjectId{Id: fmt.Sprint(req.GetPortId())})
if err != nil {
return nil, err
}
Expand All @@ -334,7 +326,7 @@ func (mi *myMacInfo) ToEntryDesc(m *myMac) (*fwdpb.EntryDesc, error) {
ed := &fwdpb.EntryDesc{
Entry: &fwdpb.EntryDesc_Flow{
Flow: &fwdpb.FlowEntryDesc{
Priority: *mi.priority,
Priority: req.GetPriority(),
Bank: 1,
},
},
Expand All @@ -347,37 +339,25 @@ func (mi *myMacInfo) ToEntryDesc(m *myMac) (*fwdpb.EntryDesc, error) {

type myMac struct {
saipb.UnimplementedMyMacServer
mgr *attrmgr.AttrMgr
dataplane switchDataplaneAPI
myMacTable map[uint64]*myMacInfo
mgr *attrmgr.AttrMgr
dataplane switchDataplaneAPI
}

func newMyMac(mgr *attrmgr.AttrMgr, dataplane switchDataplaneAPI, s *grpc.Server) *myMac {
m := &myMac{
mgr: mgr,
dataplane: dataplane,
myMacTable: map[uint64]*myMacInfo{},
mgr: mgr,
dataplane: dataplane,
}
saipb.RegisterMyMacServer(s, m)
return m
}

func (m *myMac) CreateMyMac(ctx context.Context, req *saipb.CreateMyMacRequest) (*saipb.CreateMyMacResponse, error) {
mi := &myMacInfo{
priority: req.Priority,
portID: req.PortId,
macAddress: req.GetMacAddress(),
macAddressMask: req.GetMacAddressMask(),
}
if req.VlanId != nil {
vid := (uint16)(req.GetVlanId())
mi.vlanID = &vid
}
if mi.macAddress == nil || mi.macAddressMask == nil {
if req.MacAddress == nil || req.MacAddressMask == nil {
return nil, status.Errorf(codes.InvalidArgument, "MAC address and MAC address mask cannot be empty")
}
id := m.mgr.NextID()
ed, err := mi.ToEntryDesc(m)
ed, err := entryDescFromReq(m, req)
if err != nil {
return nil, status.Errorf(codes.FailedPrecondition, "failed to create entry descriptor: %v", err)
}
Expand All @@ -390,7 +370,6 @@ func (m *myMac) CreateMyMac(ctx context.Context, req *saipb.CreateMyMacRequest)
if _, err := m.dataplane.TableEntryAdd(ctx, mReq); err != nil {
return nil, err
}
m.myMacTable[id] = mi
// Populate the switch attribute.
saReq := &saipb.GetSwitchAttributeRequest{
Oid: switchID,
Expand All @@ -410,22 +389,50 @@ func (m *myMac) CreateMyMac(ctx context.Context, req *saipb.CreateMyMacRequest)
}

func (m *myMac) RemoveMyMac(ctx context.Context, req *saipb.RemoveMyMacRequest) (*saipb.RemoveMyMacResponse, error) {
mi, ok := m.myMacTable[req.GetOid()]
if !ok {
return nil, status.Errorf(codes.FailedPrecondition, "%d does not exist", req.GetOid())
cReq := &saipb.CreateMyMacRequest{}
if err := m.mgr.PopulateAllAttributes(fmt.Sprint(req.GetOid()), cReq); err != nil {
return nil, err
}
ed, err := mi.ToEntryDesc(m)
ed, err := entryDescFromReq(m, cReq)
if err != nil {
return nil, status.Errorf(codes.FailedPrecondition, "failed to create entry descriptor: %v", err)
}

mReq := &fwdpb.TableEntryRemoveRequest{
ContextId: &fwdpb.ContextId{Id: m.dataplane.ID()},
TableId: &fwdpb.TableId{ObjectId: &fwdpb.ObjectId{Id: MyMacTable}},
EntryDesc: ed,
}

if _, err := m.dataplane.TableEntryRemove(ctx, mReq); err != nil {
return nil, err
}

// Populate the switch attribute.
saReq := &saipb.GetSwitchAttributeRequest{
Oid: switchID,
AttrType: []saipb.SwitchAttr{
saipb.SwitchAttr_SWITCH_ATTR_MY_MAC_LIST,
},
}
saResp := &saipb.GetSwitchAttributeResponse{}
if err := m.mgr.PopulateAttributes(saReq, saResp); err != nil {
return nil, fmt.Errorf("Failed to populate switch attributes: %v", err)
}
locate := func(uint64) int {
for i := range saResp.GetAttr().MyMacList {
if saResp.GetAttr().MyMacList[i] == req.GetOid() {
return i
}
}
return -1
}
if loc := locate(req.GetOid()); loc != -1 {
m.mgr.StoreAttributes(switchID, &saipb.SwitchAttribute{
MyMacList: append(saResp.GetAttr().MyMacList[:loc], saResp.GetAttr().MyMacList[loc+1:]...),
})
} else {
return nil, fmt.Errorf("Failed to store switch attributes: %v", err)
}

return &saipb.RemoveMyMacResponse{}, nil
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ require (
github.com/openconfig/gribi v1.0.0
github.com/openconfig/gribigo v0.0.0-20240314002941-b59d04db23bd
github.com/openconfig/kne v0.1.16
github.com/openconfig/magna v0.0.0-20240125181018-b59ccfe781f8
github.com/openconfig/magna v0.0.0-20240326180454-518e16696c84
github.com/openconfig/ondatra v0.5.2
github.com/openconfig/ygnmi v0.11.1
github.com/openconfig/ygot v0.29.18
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1560,8 +1560,8 @@ github.com/openconfig/kne v0.1.16 h1:3bvkinEoT4xo0c5kcqnotdboq3ZfFHoVRP1YZja97W0
github.com/openconfig/kne v0.1.16/go.mod h1:WROHtukCSPVMFEE8dfIec9RneqLDNqaFf92wTAVuAvk=
github.com/openconfig/lemming/operator v0.2.0 h1:dovZnR6lQkOHXcODli1NDOr/GVYrBY05KS5X11jxVbw=
github.com/openconfig/lemming/operator v0.2.0/go.mod h1:LKgEXSR5VK2CAeh2uKijKAXFj42uQuwakrCHVPF0iII=
github.com/openconfig/magna v0.0.0-20240125181018-b59ccfe781f8 h1:Li3oruOjubVSr+7UAc6ohpWeD0FKk+7t7SzEkMN66Qk=
github.com/openconfig/magna v0.0.0-20240125181018-b59ccfe781f8/go.mod h1:3B8JDwmq2vuR0J1JB4+XtpxC+FrVvtZa1129LJ+7AIw=
github.com/openconfig/magna v0.0.0-20240326180454-518e16696c84 h1:tiy1WDRRFuWXCA9o0We8x3an3vywDVowyertHgjEUXo=
github.com/openconfig/magna v0.0.0-20240326180454-518e16696c84/go.mod h1:HxoDKtQaYwLhAQCAGpq5F16kdtxTKD4Vj2NikVn8+Gw=
github.com/openconfig/ondatra v0.5.2 h1:AUBT+KlPzP/bgiCbdOY+PrJdmK4o/Upc1aD20VKWx20=
github.com/openconfig/ondatra v0.5.2/go.mod h1:Ez1STBlzUo+Zq5bONkE2R0lhnGArevnrXpoak8MiWAE=
github.com/openconfig/testt v0.0.0-20220311054427-efbb1a32ec07 h1:X631iD/B0ximGFb5P9LY5wHju4SiedxUhc5UZEo7VSw=
Expand Down
Loading
Loading