Skip to content

Commit

Permalink
Send request to set oper status state for host interfaces.
Browse files Browse the repository at this point in the history
  • Loading branch information
royyi8 committed Jan 10, 2025
1 parent 2eef855 commit ed62a5c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
14 changes: 14 additions & 0 deletions dataplane/saiserver/hostif.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@ func (hostif *hostif) CreateHostif(ctx context.Context, req *saipb.CreateHostifR
PortId: id,
}

oper_status := pktiopb.PortOperation_PORT_OPERATION_SET_DOWN

if req.GetOperStatus() {
oper_status = pktiopb.PortOperation_PORT_OPERATION_SET_UP
}

operReq := &pktiopb.HostPortControlMessage{
PortId: id,
Op: oper_status,
}

switch req.GetType() {
case saipb.HostifType_HOSTIF_TYPE_GENETLINK:
name := string(req.GetName()) // The name can be genl_packet_q0, but the netlink family is gen_packet.
Expand Down Expand Up @@ -157,6 +168,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),
Expand Down
13 changes: 10 additions & 3 deletions dataplane/saiserver/hostif_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
fwdpb "github.com/openconfig/lemming/proto/forwarding"
)


func TestCreateHostif(t *testing.T) {
tests := []struct {
desc string
Expand Down Expand Up @@ -98,7 +99,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 +108,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 +119,10 @@ func TestCreateHostif(t *testing.T) {
},
},
})
}()
}

go processRequest()
go processRequest()

defer stopFn()
got, gotErr := c.CreateHostif(context.TODO(), tt.req)
Expand All @@ -131,7 +135,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

0 comments on commit ed62a5c

Please sign in to comment.