From 49df8a349d23bcf9d49017a977b4c2045e9ca368 Mon Sep 17 00:00:00 2001 From: Roy Date: Wed, 8 Jan 2025 18:52:00 +0000 Subject: [PATCH 1/3] Send request to set oper status state for host interfaces. --- dataplane/saiserver/hostif.go | 15 +++++++++++++++ dataplane/saiserver/hostif_test.go | 12 +++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/dataplane/saiserver/hostif.go b/dataplane/saiserver/hostif.go index f6e5789c..c942dbe4 100644 --- a/dataplane/saiserver/hostif.go +++ b/dataplane/saiserver/hostif.go @@ -89,6 +89,18 @@ func (hostif *hostif) CreateHostif(ctx context.Context, req *saipb.CreateHostifR Create: true, DataplanePort: req.GetObjId(), PortId: id, + Op: pktiopb.PortOperation_PORT_OPERATION_CREATE, + } + + operStatus := pktiopb.PortOperation_PORT_OPERATION_SET_DOWN + + if req.GetOperStatus() { + operStatus = pktiopb.PortOperation_PORT_OPERATION_SET_UP + } + + operReq := &pktiopb.HostPortControlMessage{ + PortId: id, + Op: operStatus, } switch req.GetType() { @@ -157,6 +169,9 @@ func (hostif *hostif) CreateHostif(ctx context.Context, req *saipb.CreateHostifR if err := hostif.remotePortReq(ctlReq); err != nil { return nil, err } + if err := hostif.remotePortReq(operReq); err != nil { + return nil, err + } attr := &saipb.HostifAttribute{ OperStatus: proto.Bool(true), diff --git a/dataplane/saiserver/hostif_test.go b/dataplane/saiserver/hostif_test.go index 3e32f85e..db0e87e5 100644 --- a/dataplane/saiserver/hostif_test.go +++ b/dataplane/saiserver/hostif_test.go @@ -98,7 +98,7 @@ func TestCreateHostif(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - msgCh := make(chan *pktiopb.HostPortControlMessage, 1) + msgCh := make(chan *pktiopb.HostPortControlMessage, 2) pc, err := c.HostPortControl(ctx) if err != nil { t.Fatal(err) @@ -107,7 +107,7 @@ func TestCreateHostif(t *testing.T) { t.Fatal(err) } time.Sleep(time.Millisecond) - go func() { + processRequest := func() { msg, _ := pc.Recv() msgCh <- msg pc.Send(&pktiopb.HostPortControlRequest{ @@ -118,7 +118,10 @@ func TestCreateHostif(t *testing.T) { }, }, }) - }() + } + + go processRequest() + go processRequest() defer stopFn() got, gotErr := c.CreateHostif(context.TODO(), tt.req) @@ -131,7 +134,10 @@ func TestCreateHostif(t *testing.T) { if d := cmp.Diff(got, tt.want, protocmp.Transform()); d != "" { t.Errorf("CreateHostif() failed: diff(-got,+want)\n:%s", d) } + _ = <-msgCh + _ = <-msgCh + attr := &saipb.HostifAttribute{} if err := mgr.PopulateAllAttributes("3", attr); err != nil { t.Fatal(err) From 2332625ae308a8fade5e059d8359e0a291ebe185 Mon Sep 17 00:00:00 2001 From: Daniel Grau Date: Fri, 10 Jan 2025 22:25:37 +0000 Subject: [PATCH 2/3] fix for lemming --- dataplane/dplanerc/interface.go | 2 +- dataplane/saiserver/hostif.go | 20 ++++++++++++++----- .../pkthandler/pktiohandler/pktiohandler.go | 8 ++++---- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/dataplane/dplanerc/interface.go b/dataplane/dplanerc/interface.go index 92653b50..fd60fac8 100644 --- a/dataplane/dplanerc/interface.go +++ b/dataplane/dplanerc/interface.go @@ -970,7 +970,7 @@ func (ni *Reconciler) setupPorts(ctx context.Context) error { Type: saipb.HostifType_HOSTIF_TYPE_NETDEV.Enum(), ObjId: &portResp.Oid, Name: []byte(hostifName), - OperStatus: proto.Bool(true), + OperStatus: proto.Bool(false), }) if err != nil { return fmt.Errorf("failed to create host interface %q: %w", hostifName, err) diff --git a/dataplane/saiserver/hostif.go b/dataplane/saiserver/hostif.go index c942dbe4..dfb4c24c 100644 --- a/dataplane/saiserver/hostif.go +++ b/dataplane/saiserver/hostif.go @@ -24,7 +24,6 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" - "google.golang.org/protobuf/proto" "github.com/openconfig/lemming/dataplane/dplaneopts" "github.com/openconfig/lemming/dataplane/forwarding/fwdconfig" @@ -169,14 +168,12 @@ func (hostif *hostif) CreateHostif(ctx context.Context, req *saipb.CreateHostifR if err := hostif.remotePortReq(ctlReq); err != nil { return nil, err } + slog.Info("hostif created", "oid", id) if err := hostif.remotePortReq(operReq); err != nil { return nil, err } - attr := &saipb.HostifAttribute{ - OperStatus: proto.Bool(true), - } - hostif.mgr.StoreAttributes(id, attr) + slog.Info("hostif status set", "oid", id, "op", operStatus) hostif.remoteHostifs[id] = ctlReq return &saipb.CreateHostifResponse{Oid: id}, nil @@ -226,6 +223,19 @@ func (hostif *hostif) RemoveHostif(ctx context.Context, req *saipb.RemoveHostifR // SetHostifAttribute sets the attributes in the request. func (hostif *hostif) SetHostifAttribute(ctx context.Context, req *saipb.SetHostifAttributeRequest) (*saipb.SetHostifAttributeResponse, error) { + if req.OperStatus != nil { + op := pktiopb.PortOperation_PORT_OPERATION_SET_DOWN + + if req.GetOperStatus() { + op = pktiopb.PortOperation_PORT_OPERATION_SET_UP + } + if err := hostif.remotePortReq(&pktiopb.HostPortControlMessage{ + PortId: req.GetOid(), + Op: op, + }); err != nil { + return nil, err + } + } return nil, nil } diff --git a/dataplane/standalone/pkthandler/pktiohandler/pktiohandler.go b/dataplane/standalone/pkthandler/pktiohandler/pktiohandler.go index 728eb8a5..37b81ac5 100644 --- a/dataplane/standalone/pkthandler/pktiohandler/pktiohandler.go +++ b/dataplane/standalone/pkthandler/pktiohandler/pktiohandler.go @@ -161,8 +161,8 @@ func (m *PacketIOMgr) ManagePorts(c pktiopb.PacketIO_HostPortControlClient) erro return err } log.Infof("received port control message: %+v", resp) - switch { - case (resp.Op == pktiopb.PortOperation_PORT_OPERATION_UNSPECIFIED && resp.Create) || resp.Op == pktiopb.PortOperation_PORT_OPERATION_CREATE: + switch resp.Op { + case pktiopb.PortOperation_PORT_OPERATION_CREATE: st := &status.Status{ Code: int32(codes.OK), } @@ -181,7 +181,7 @@ func (m *PacketIOMgr) ManagePorts(c pktiopb.PacketIO_HostPortControlClient) erro if err := m.writePorts(); err != nil { log.Warningf("failed to write file: %v", err) } - case resp.Op == pktiopb.PortOperation_PORT_OPERATION_UNSPECIFIED || resp.Op == pktiopb.PortOperation_PORT_OPERATION_DELETE: + case pktiopb.PortOperation_PORT_OPERATION_DELETE: p, ok := m.hostifs[resp.GetPortId()] if !ok { sendErr := c.Send(&pktiopb.HostPortControlRequest{Msg: &pktiopb.HostPortControlRequest_Status{ @@ -219,7 +219,7 @@ func (m *PacketIOMgr) ManagePorts(c pktiopb.PacketIO_HostPortControlClient) erro if err := m.writePorts(); err != nil { log.Warningf("failed to write file: %v", err) } - case resp.Op == pktiopb.PortOperation_PORT_OPERATION_SET_UP || resp.Op == pktiopb.PortOperation_PORT_OPERATION_SET_DOWN: + case pktiopb.PortOperation_PORT_OPERATION_SET_UP, pktiopb.PortOperation_PORT_OPERATION_SET_DOWN: p, ok := m.hostifs[resp.GetPortId()] if !ok { sendErr := c.Send(&pktiopb.HostPortControlRequest{Msg: &pktiopb.HostPortControlRequest_Status{ From 33318fc11ab006f71df112b86b47d4c56d3707b2 Mon Sep 17 00:00:00 2001 From: Daniel Grau Date: Fri, 10 Jan 2025 22:39:12 +0000 Subject: [PATCH 3/3] test --- dataplane/saiserver/hostif_test.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/dataplane/saiserver/hostif_test.go b/dataplane/saiserver/hostif_test.go index db0e87e5..7cc8e0f4 100644 --- a/dataplane/saiserver/hostif_test.go +++ b/dataplane/saiserver/hostif_test.go @@ -59,9 +59,8 @@ func TestCreateHostif(t *testing.T) { Oid: 3, }, wantAttr: &saipb.HostifAttribute{ - Type: saipb.HostifType_HOSTIF_TYPE_NETDEV.Enum(), - ObjId: proto.Uint64(2), - OperStatus: proto.Bool(true), + Type: saipb.HostifType_HOSTIF_TYPE_NETDEV.Enum(), + ObjId: proto.Uint64(2), }, }, { desc: "success cpu port", @@ -73,9 +72,8 @@ func TestCreateHostif(t *testing.T) { Oid: 3, }, wantAttr: &saipb.HostifAttribute{ - Type: saipb.HostifType_HOSTIF_TYPE_NETDEV.Enum(), - ObjId: proto.Uint64(10), - OperStatus: proto.Bool(true), + Type: saipb.HostifType_HOSTIF_TYPE_NETDEV.Enum(), + ObjId: proto.Uint64(10), }, }} for _, tt := range tests {