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

Send request to set oper status state for host interfaces. #525

Merged
merged 3 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion dataplane/dplanerc/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
35 changes: 30 additions & 5 deletions dataplane/saiserver/hostif.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -89,6 +88,18 @@ func (hostif *hostif) CreateHostif(ctx context.Context, req *saipb.CreateHostifR
Create: true,
DataplanePort: req.GetObjId(),
PortId: id,
royyi8 marked this conversation as resolved.
Show resolved Hide resolved
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() {
Expand Down Expand Up @@ -157,11 +168,12 @@ func (hostif *hostif) CreateHostif(ctx context.Context, req *saipb.CreateHostifR
if err := hostif.remotePortReq(ctlReq); err != nil {
return nil, err
}

attr := &saipb.HostifAttribute{
OperStatus: proto.Bool(true),
slog.Info("hostif created", "oid", id)
if err := hostif.remotePortReq(operReq); err != nil {
return nil, err
}
hostif.mgr.StoreAttributes(id, attr)

slog.Info("hostif status set", "oid", id, "op", operStatus)
hostif.remoteHostifs[id] = ctlReq

return &saipb.CreateHostifResponse{Oid: id}, nil
Expand Down Expand Up @@ -211,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
}

Expand Down
12 changes: 9 additions & 3 deletions dataplane/saiserver/hostif_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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{
Expand All @@ -118,7 +118,10 @@ func TestCreateHostif(t *testing.T) {
},
},
})
}()
}

go processRequest()
go processRequest()

defer stopFn()
got, gotErr := c.CreateHostif(context.TODO(), tt.req)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand All @@ -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{
Expand Down Expand Up @@ -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{
Expand Down
Loading