Skip to content

Commit

Permalink
address p4 related comments
Browse files Browse the repository at this point in the history
  • Loading branch information
zak-pawel committed Sep 4, 2024
1 parent b610683 commit c874f6c
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 99 deletions.
20 changes: 10 additions & 10 deletions plugins/inputs/p4runtime/p4runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"sync"

p4_config "github.com/p4lang/p4runtime/go/p4/config/v1"
"github.com/p4lang/p4runtime/go/p4/v1"
p4 "github.com/p4lang/p4runtime/go/p4/v1"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
Expand All @@ -39,7 +39,7 @@ type P4runtime struct {
common_tls.ClientConfig

conn *grpc.ClientConn
client v1.P4RuntimeClient
client p4.P4RuntimeClient
wg sync.WaitGroup
}

Expand Down Expand Up @@ -137,9 +137,9 @@ func initConnection(endpoint string, tlscfg *tls.Config) (*grpc.ClientConn, erro
}

func (p *P4runtime) getP4Info() (*p4_config.P4Info, error) {
req := &v1.GetForwardingPipelineConfigRequest{
req := &p4.GetForwardingPipelineConfigRequest{
DeviceId: p.DeviceID,
ResponseType: v1.GetForwardingPipelineConfigRequest_ALL,
ResponseType: p4.GetForwardingPipelineConfigRequest_ALL,
}
resp, err := p.client.GetForwardingPipelineConfig(context.Background(), req)
if err != nil {
Expand Down Expand Up @@ -197,16 +197,16 @@ func (p *P4runtime) newP4RuntimeClient() error {
return fmt.Errorf("cannot connect to the server: %w", err)
}
p.conn = conn
p.client = v1.NewP4RuntimeClient(conn)
p.client = p4.NewP4RuntimeClient(conn)
return nil
}

func (p *P4runtime) readAllEntries(counterID uint32) ([]*v1.Entity, error) {
readRequest := &v1.ReadRequest{
func (p *P4runtime) readAllEntries(counterID uint32) ([]*p4.Entity, error) {
readRequest := &p4.ReadRequest{
DeviceId: p.DeviceID,
Entities: []*v1.Entity{{
Entity: &v1.Entity_CounterEntry{
CounterEntry: &v1.CounterEntry{
Entities: []*p4.Entity{{
Entity: &p4.Entity_CounterEntry{
CounterEntry: &p4.CounterEntry{
CounterId: counterID}}}}}

stream, err := p.client.Read(context.Background(), readRequest)
Expand Down
52 changes: 26 additions & 26 deletions plugins/inputs/p4runtime/p4runtime_fake_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,49 @@ package p4runtime
import (
"context"

"github.com/p4lang/p4runtime/go/p4/v1"
p4 "github.com/p4lang/p4runtime/go/p4/v1"
"google.golang.org/grpc"
)

type fakeP4RuntimeClient struct {
writeFn func(
ctx context.Context,
in *v1.WriteRequest,
in *p4.WriteRequest,
opts ...grpc.CallOption,
) (*v1.WriteResponse, error)
) (*p4.WriteResponse, error)

readFn func(
in *v1.ReadRequest,
) (v1.P4Runtime_ReadClient, error)
in *p4.ReadRequest,
) (p4.P4Runtime_ReadClient, error)

setForwardingPipelineConfigFn func(
ctx context.Context,
in *v1.SetForwardingPipelineConfigRequest,
in *p4.SetForwardingPipelineConfigRequest,
opts ...grpc.CallOption,
) (*v1.SetForwardingPipelineConfigResponse, error)
) (*p4.SetForwardingPipelineConfigResponse, error)

getForwardingPipelineConfigFn func() (*v1.GetForwardingPipelineConfigResponse, error)
getForwardingPipelineConfigFn func() (*p4.GetForwardingPipelineConfigResponse, error)

streamChannelFn func(
ctx context.Context,
opts ...grpc.CallOption,
) (v1.P4Runtime_StreamChannelClient, error)
) (p4.P4Runtime_StreamChannelClient, error)

capabilitiesFn func(
ctx context.Context,
in *v1.CapabilitiesRequest,
in *p4.CapabilitiesRequest,
opts ...grpc.CallOption,
) (*v1.CapabilitiesResponse, error)
) (*p4.CapabilitiesResponse, error)
}

// fakeP4RuntimeClient implements the v1.P4RuntimeClient interface
var _ v1.P4RuntimeClient = &fakeP4RuntimeClient{}
var _ p4.P4RuntimeClient = &fakeP4RuntimeClient{}

func (c *fakeP4RuntimeClient) Write(
ctx context.Context,
in *v1.WriteRequest,
in *p4.WriteRequest,
opts ...grpc.CallOption,
) (*v1.WriteResponse, error) {
) (*p4.WriteResponse, error) {
if c.writeFn == nil {
panic("No mock defined for Write RPC")
}
Expand All @@ -54,9 +54,9 @@ func (c *fakeP4RuntimeClient) Write(

func (c *fakeP4RuntimeClient) Read(
_ context.Context,
in *v1.ReadRequest,
in *p4.ReadRequest,
_ ...grpc.CallOption,
) (v1.P4Runtime_ReadClient, error) {
) (p4.P4Runtime_ReadClient, error) {
if c.readFn == nil {
panic("No mock defined for Read RPC")
}
Expand All @@ -65,9 +65,9 @@ func (c *fakeP4RuntimeClient) Read(

func (c *fakeP4RuntimeClient) SetForwardingPipelineConfig(
ctx context.Context,
in *v1.SetForwardingPipelineConfigRequest,
in *p4.SetForwardingPipelineConfigRequest,
opts ...grpc.CallOption,
) (*v1.SetForwardingPipelineConfigResponse, error) {
) (*p4.SetForwardingPipelineConfigResponse, error) {
if c.setForwardingPipelineConfigFn == nil {
panic("No mock defined for SetForwardingPipelineConfig RPC")
}
Expand All @@ -76,9 +76,9 @@ func (c *fakeP4RuntimeClient) SetForwardingPipelineConfig(

func (c *fakeP4RuntimeClient) GetForwardingPipelineConfig(
context.Context,
*v1.GetForwardingPipelineConfigRequest,
*p4.GetForwardingPipelineConfigRequest,
...grpc.CallOption,
) (*v1.GetForwardingPipelineConfigResponse, error) {
) (*p4.GetForwardingPipelineConfigResponse, error) {
if c.getForwardingPipelineConfigFn == nil {
panic("No mock defined for GetForwardingPipelineConfig RPC")
}
Expand All @@ -88,7 +88,7 @@ func (c *fakeP4RuntimeClient) GetForwardingPipelineConfig(
func (c *fakeP4RuntimeClient) StreamChannel(
ctx context.Context,
opts ...grpc.CallOption,
) (v1.P4Runtime_StreamChannelClient, error) {
) (p4.P4Runtime_StreamChannelClient, error) {
if c.streamChannelFn == nil {
panic("No mock defined for StreamChannel")
}
Expand All @@ -97,9 +97,9 @@ func (c *fakeP4RuntimeClient) StreamChannel(

func (c *fakeP4RuntimeClient) Capabilities(
ctx context.Context,
in *v1.CapabilitiesRequest,
in *p4.CapabilitiesRequest,
opts ...grpc.CallOption,
) (*v1.CapabilitiesResponse, error) {
) (*p4.CapabilitiesResponse, error) {
if c.capabilitiesFn == nil {
panic("No mock defined for Capabilities RPC")
}
Expand All @@ -108,13 +108,13 @@ func (c *fakeP4RuntimeClient) Capabilities(

type fakeP4RuntimeReadClient struct {
grpc.ClientStream
recvFn func() (*v1.ReadResponse, error)
recvFn func() (*p4.ReadResponse, error)
}

// fakeP4RuntimeReadClient implements the v1.P4Runtime_ReadClient interface
var _ v1.P4Runtime_ReadClient = &fakeP4RuntimeReadClient{}
var _ p4.P4Runtime_ReadClient = &fakeP4RuntimeReadClient{}

func (c *fakeP4RuntimeReadClient) Recv() (*v1.ReadResponse, error) {
func (c *fakeP4RuntimeReadClient) Recv() (*p4.ReadResponse, error) {
if c.recvFn == nil {
panic("No mock provided for Recv function")
}
Expand Down
Loading

0 comments on commit c874f6c

Please sign in to comment.