From 2332625ae308a8fade5e059d8359e0a291ebe185 Mon Sep 17 00:00:00 2001 From: Daniel Grau Date: Fri, 10 Jan 2025 22:25:37 +0000 Subject: [PATCH] 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{