Skip to content

Commit cc80dbc

Browse files
matus-mrekajondrej-fabry
authored andcommitted
add missing implementation for proxy
Signed-off-by: Matus Mrekaj <[email protected]> Change-Id: I1ab9efb9e575e7993501e7774628cbb60d16ec43
1 parent 9bf7175 commit cc80dbc

File tree

3 files changed

+88
-13
lines changed

3 files changed

+88
-13
lines changed

cmd/vpp-proxy/main.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"git.fd.io/govpp.git/adapter/socketclient"
2525
"git.fd.io/govpp.git/adapter/statsclient"
2626
"git.fd.io/govpp.git/api"
27+
_ "git.fd.io/govpp.git/core"
2728
"git.fd.io/govpp.git/examples/binapi/interfaces"
2829
"git.fd.io/govpp.git/examples/binapi/vpe"
2930
"git.fd.io/govpp.git/proxy"
@@ -84,6 +85,13 @@ func runClient() {
8485
if err != nil {
8586
log.Fatalln(err)
8687
}
88+
log.Println("checking compatibility")
89+
var msgs []api.Message
90+
msgs = append(msgs, interfaces.AllMessages()...)
91+
msgs = append(msgs, vpe.AllMessages()...)
92+
if err := binapiChannel.CheckCompatiblity(msgs...); err != nil {
93+
panic(err)
94+
}
8795

8896
// - using binapi message directly
8997
req := &vpe.CliInband{Cmd: "show version"}

proxy/client.go

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type Client struct {
2020
func Connect(addr string) (*Client, error) {
2121
client, err := rpc.DialHTTP("tcp", addr)
2222
if err != nil {
23-
log.Fatal("Connection error: ", err)
23+
return nil, fmt.Errorf("connection error:%v", err)
2424
}
2525
c := &Client{
2626
serverAddr: addr,
@@ -50,33 +50,56 @@ type StatsClient struct {
5050
}
5151

5252
func (s *StatsClient) GetSystemStats(sysStats *api.SystemStats) error {
53+
// we need to start with a clean, zeroed item before decoding
54+
// 'cause if the new values are 'zero' for the type, they will be ignored
55+
// by the decoder. (i.e the old values will be left unchanged).
5356
req := StatsRequest{StatsType: "system"}
54-
resp := StatsResponse{SysStats: sysStats}
55-
return s.rpc.Call("StatsRPC.GetStats", req, &resp)
57+
resp := StatsResponse{SysStats: new(api.SystemStats)}
58+
if err := s.rpc.Call("StatsRPC.GetStats", req, &resp); err != nil {
59+
return err
60+
}
61+
*sysStats = *resp.SysStats
62+
return nil
5663
}
5764

5865
func (s *StatsClient) GetNodeStats(nodeStats *api.NodeStats) error {
5966
req := StatsRequest{StatsType: "node"}
60-
resp := StatsResponse{NodeStats: nodeStats}
61-
return s.rpc.Call("StatsRPC.GetStats", req, &resp)
67+
resp := StatsResponse{NodeStats: new(api.NodeStats)}
68+
if err := s.rpc.Call("StatsRPC.GetStats", req, &resp); err != nil {
69+
return err
70+
}
71+
*nodeStats = *resp.NodeStats
72+
return nil
6273
}
6374

6475
func (s *StatsClient) GetInterfaceStats(ifaceStats *api.InterfaceStats) error {
6576
req := StatsRequest{StatsType: "interface"}
66-
resp := StatsResponse{IfaceStats: ifaceStats}
67-
return s.rpc.Call("StatsRPC.GetStats", req, &resp)
77+
resp := StatsResponse{IfaceStats: new(api.InterfaceStats)}
78+
if err := s.rpc.Call("StatsRPC.GetStats", req, &resp); err != nil {
79+
return err
80+
}
81+
*ifaceStats = *resp.IfaceStats
82+
return nil
6883
}
6984

7085
func (s *StatsClient) GetErrorStats(errStats *api.ErrorStats) error {
7186
req := StatsRequest{StatsType: "error"}
72-
resp := StatsResponse{ErrStats: errStats}
73-
return s.rpc.Call("StatsRPC.GetStats", req, &resp)
87+
resp := StatsResponse{ErrStats: new(api.ErrorStats)}
88+
if err := s.rpc.Call("StatsRPC.GetStats", req, &resp); err != nil {
89+
return err
90+
}
91+
*errStats = *resp.ErrStats
92+
return nil
7493
}
7594

7695
func (s *StatsClient) GetBufferStats(bufStats *api.BufferStats) error {
7796
req := StatsRequest{StatsType: "buffer"}
78-
resp := StatsResponse{BufStats: bufStats}
79-
return s.rpc.Call("StatsRPC.GetStats", req, &resp)
97+
resp := StatsResponse{BufStats: new(api.BufferStats)}
98+
if err := s.rpc.Call("StatsRPC.GetStats", req, &resp); err != nil {
99+
return err
100+
}
101+
*bufStats = *resp.BufStats
102+
return nil
80103
}
81104

82105
type BinapiClient struct {
@@ -166,11 +189,25 @@ func (b *BinapiClient) SubscribeNotification(notifChan chan api.Message, event a
166189
}
167190

168191
func (b *BinapiClient) SetReplyTimeout(timeout time.Duration) {
169-
panic("implement me")
192+
req := BinapiTimeoutRequest{Timeout: timeout}
193+
resp := BinapiTimeoutResponse{}
194+
if err := b.rpc.Call("BinapiRPC.SetTimeout", req, &resp); err != nil {
195+
log.Println(err)
196+
}
170197
}
171198

172199
func (b *BinapiClient) CheckCompatiblity(msgs ...api.Message) error {
173-
return nil // TODO: proxy this
200+
for _, msg := range msgs {
201+
req := BinapiCompatibilityRequest{
202+
MsgName: msg.GetMessageName(),
203+
Crc: msg.GetCrcString(),
204+
}
205+
resp := BinapiCompatibilityResponse{}
206+
if err := b.rpc.Call("BinapiRPC.Compatibility", req, &resp); err != nil {
207+
return err
208+
}
209+
}
210+
return nil
174211
}
175212

176213
func (b *BinapiClient) Close() {

proxy/server.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"log"
66
"reflect"
7+
"time"
78

89
"git.fd.io/govpp.git/api"
910
)
@@ -66,6 +67,21 @@ type BinapiResponse struct {
6667
Msgs []api.Message
6768
}
6869

70+
type BinapiCompatibilityRequest struct {
71+
MsgName string
72+
Crc string
73+
}
74+
75+
type BinapiCompatibilityResponse struct {
76+
}
77+
78+
type BinapiTimeoutRequest struct {
79+
Timeout time.Duration
80+
}
81+
82+
type BinapiTimeoutResponse struct {
83+
}
84+
6985
// BinapiRPC is a RPC server for proxying client request to api.Channel.
7086
type BinapiRPC struct {
7187
binapi api.Channel
@@ -107,3 +123,17 @@ func (s *BinapiRPC) Invoke(req BinapiRequest, resp *BinapiResponse) error {
107123

108124
return nil
109125
}
126+
127+
func (s *BinapiRPC) SetTimeout(req BinapiTimeoutRequest, _ *BinapiTimeoutResponse) error {
128+
log.Printf("BinapiRPC.SetTimeout - REQ: %#v", req)
129+
s.binapi.SetReplyTimeout(req.Timeout)
130+
return nil
131+
}
132+
133+
func (s *BinapiRPC) Compatibility(req BinapiCompatibilityRequest, _ *BinapiCompatibilityResponse) error {
134+
log.Printf("BinapiRPC.Compatiblity - REQ: %#v", req)
135+
if val, ok := api.GetRegisteredMessages()[req.MsgName+"_"+req.Crc]; ok {
136+
return s.binapi.CheckCompatiblity(val)
137+
}
138+
return fmt.Errorf("compatibility check failed for the message: %s", req.MsgName+"_"+req.Crc)
139+
}

0 commit comments

Comments
 (0)