From cc80dbcaaaca8bf1b6042fead850d456cf589a4e Mon Sep 17 00:00:00 2001 From: Matus Mrekaj Date: Wed, 16 Oct 2019 15:13:44 +0200 Subject: add missing implementation for proxy Signed-off-by: Matus Mrekaj Change-Id: I1ab9efb9e575e7993501e7774628cbb60d16ec43 --- cmd/vpp-proxy/main.go | 8 +++++++ proxy/client.go | 63 ++++++++++++++++++++++++++++++++++++++++----------- proxy/server.go | 30 ++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 13 deletions(-) diff --git a/cmd/vpp-proxy/main.go b/cmd/vpp-proxy/main.go index 7aea885..de1b7b4 100644 --- a/cmd/vpp-proxy/main.go +++ b/cmd/vpp-proxy/main.go @@ -24,6 +24,7 @@ import ( "git.fd.io/govpp.git/adapter/socketclient" "git.fd.io/govpp.git/adapter/statsclient" "git.fd.io/govpp.git/api" + _ "git.fd.io/govpp.git/core" "git.fd.io/govpp.git/examples/binapi/interfaces" "git.fd.io/govpp.git/examples/binapi/vpe" "git.fd.io/govpp.git/proxy" @@ -84,6 +85,13 @@ func runClient() { if err != nil { log.Fatalln(err) } + log.Println("checking compatibility") + var msgs []api.Message + msgs = append(msgs, interfaces.AllMessages()...) + msgs = append(msgs, vpe.AllMessages()...) + if err := binapiChannel.CheckCompatiblity(msgs...); err != nil { + panic(err) + } // - using binapi message directly req := &vpe.CliInband{Cmd: "show version"} diff --git a/proxy/client.go b/proxy/client.go index 72ee9e9..4f2df0f 100644 --- a/proxy/client.go +++ b/proxy/client.go @@ -20,7 +20,7 @@ type Client struct { func Connect(addr string) (*Client, error) { client, err := rpc.DialHTTP("tcp", addr) if err != nil { - log.Fatal("Connection error: ", err) + return nil, fmt.Errorf("connection error:%v", err) } c := &Client{ serverAddr: addr, @@ -50,33 +50,56 @@ type StatsClient struct { } func (s *StatsClient) GetSystemStats(sysStats *api.SystemStats) error { + // we need to start with a clean, zeroed item before decoding + // 'cause if the new values are 'zero' for the type, they will be ignored + // by the decoder. (i.e the old values will be left unchanged). req := StatsRequest{StatsType: "system"} - resp := StatsResponse{SysStats: sysStats} - return s.rpc.Call("StatsRPC.GetStats", req, &resp) + resp := StatsResponse{SysStats: new(api.SystemStats)} + if err := s.rpc.Call("StatsRPC.GetStats", req, &resp); err != nil { + return err + } + *sysStats = *resp.SysStats + return nil } func (s *StatsClient) GetNodeStats(nodeStats *api.NodeStats) error { req := StatsRequest{StatsType: "node"} - resp := StatsResponse{NodeStats: nodeStats} - return s.rpc.Call("StatsRPC.GetStats", req, &resp) + resp := StatsResponse{NodeStats: new(api.NodeStats)} + if err := s.rpc.Call("StatsRPC.GetStats", req, &resp); err != nil { + return err + } + *nodeStats = *resp.NodeStats + return nil } func (s *StatsClient) GetInterfaceStats(ifaceStats *api.InterfaceStats) error { req := StatsRequest{StatsType: "interface"} - resp := StatsResponse{IfaceStats: ifaceStats} - return s.rpc.Call("StatsRPC.GetStats", req, &resp) + resp := StatsResponse{IfaceStats: new(api.InterfaceStats)} + if err := s.rpc.Call("StatsRPC.GetStats", req, &resp); err != nil { + return err + } + *ifaceStats = *resp.IfaceStats + return nil } func (s *StatsClient) GetErrorStats(errStats *api.ErrorStats) error { req := StatsRequest{StatsType: "error"} - resp := StatsResponse{ErrStats: errStats} - return s.rpc.Call("StatsRPC.GetStats", req, &resp) + resp := StatsResponse{ErrStats: new(api.ErrorStats)} + if err := s.rpc.Call("StatsRPC.GetStats", req, &resp); err != nil { + return err + } + *errStats = *resp.ErrStats + return nil } func (s *StatsClient) GetBufferStats(bufStats *api.BufferStats) error { req := StatsRequest{StatsType: "buffer"} - resp := StatsResponse{BufStats: bufStats} - return s.rpc.Call("StatsRPC.GetStats", req, &resp) + resp := StatsResponse{BufStats: new(api.BufferStats)} + if err := s.rpc.Call("StatsRPC.GetStats", req, &resp); err != nil { + return err + } + *bufStats = *resp.BufStats + return nil } type BinapiClient struct { @@ -166,11 +189,25 @@ func (b *BinapiClient) SubscribeNotification(notifChan chan api.Message, event a } func (b *BinapiClient) SetReplyTimeout(timeout time.Duration) { - panic("implement me") + req := BinapiTimeoutRequest{Timeout: timeout} + resp := BinapiTimeoutResponse{} + if err := b.rpc.Call("BinapiRPC.SetTimeout", req, &resp); err != nil { + log.Println(err) + } } func (b *BinapiClient) CheckCompatiblity(msgs ...api.Message) error { - return nil // TODO: proxy this + for _, msg := range msgs { + req := BinapiCompatibilityRequest{ + MsgName: msg.GetMessageName(), + Crc: msg.GetCrcString(), + } + resp := BinapiCompatibilityResponse{} + if err := b.rpc.Call("BinapiRPC.Compatibility", req, &resp); err != nil { + return err + } + } + return nil } func (b *BinapiClient) Close() { diff --git a/proxy/server.go b/proxy/server.go index df62356..20f01f0 100644 --- a/proxy/server.go +++ b/proxy/server.go @@ -4,6 +4,7 @@ import ( "fmt" "log" "reflect" + "time" "git.fd.io/govpp.git/api" ) @@ -66,6 +67,21 @@ type BinapiResponse struct { Msgs []api.Message } +type BinapiCompatibilityRequest struct { + MsgName string + Crc string +} + +type BinapiCompatibilityResponse struct { +} + +type BinapiTimeoutRequest struct { + Timeout time.Duration +} + +type BinapiTimeoutResponse struct { +} + // BinapiRPC is a RPC server for proxying client request to api.Channel. type BinapiRPC struct { binapi api.Channel @@ -107,3 +123,17 @@ func (s *BinapiRPC) Invoke(req BinapiRequest, resp *BinapiResponse) error { return nil } + +func (s *BinapiRPC) SetTimeout(req BinapiTimeoutRequest, _ *BinapiTimeoutResponse) error { + log.Printf("BinapiRPC.SetTimeout - REQ: %#v", req) + s.binapi.SetReplyTimeout(req.Timeout) + return nil +} + +func (s *BinapiRPC) Compatibility(req BinapiCompatibilityRequest, _ *BinapiCompatibilityResponse) error { + log.Printf("BinapiRPC.Compatiblity - REQ: %#v", req) + if val, ok := api.GetRegisteredMessages()[req.MsgName+"_"+req.Crc]; ok { + return s.binapi.CheckCompatiblity(val) + } + return fmt.Errorf("compatibility check failed for the message: %s", req.MsgName+"_"+req.Crc) +} -- cgit 1.2.3-korg