8 "git.fd.io/govpp.git/api"
11 type StatsRequest struct {
15 type StatsResponse struct {
16 SysStats *api.SystemStats
17 NodeStats *api.NodeStats
18 IfaceStats *api.InterfaceStats
19 ErrStats *api.ErrorStats
20 BufStats *api.BufferStats
23 // StatsRPC is a RPC server for proxying client request to api.StatsProvider.
24 type StatsRPC struct {
25 stats api.StatsProvider
28 // NewStatsRPC returns new StatsRPC to be used as RPC server
29 // proxying request to given api.StatsProvider.
30 func NewStatsRPC(stats api.StatsProvider) *StatsRPC {
31 return &StatsRPC{stats: stats}
34 func (s *StatsRPC) GetStats(req StatsRequest, resp *StatsResponse) error {
35 log.Printf("StatsRPC.GetStats - REQ: %+v", req)
37 switch req.StatsType {
39 resp.SysStats = new(api.SystemStats)
40 return s.stats.GetSystemStats(resp.SysStats)
42 resp.NodeStats = new(api.NodeStats)
43 return s.stats.GetNodeStats(resp.NodeStats)
45 resp.IfaceStats = new(api.InterfaceStats)
46 return s.stats.GetInterfaceStats(resp.IfaceStats)
48 resp.ErrStats = new(api.ErrorStats)
49 return s.stats.GetErrorStats(resp.ErrStats)
51 resp.BufStats = new(api.BufferStats)
52 return s.stats.GetBufferStats(resp.BufStats)
54 return fmt.Errorf("unknown stats type: %s", req.StatsType)
58 type BinapiRequest struct {
64 type BinapiResponse struct {
69 // BinapiRPC is a RPC server for proxying client request to api.Channel.
70 type BinapiRPC struct {
74 // NewBinapiRPC returns new BinapiRPC to be used as RPC server
75 // proxying request to given api.Channel.
76 func NewBinapiRPC(binapi api.Channel) *BinapiRPC {
77 return &BinapiRPC{binapi: binapi}
80 func (s *BinapiRPC) Invoke(req BinapiRequest, resp *BinapiResponse) error {
81 log.Printf("BinapiRPC.Invoke - REQ: %#v", req)
84 multi := s.binapi.SendMultiRequest(req.Msg)
86 // create new message in response of type ReplyMsg
87 msg := reflect.New(reflect.TypeOf(req.ReplyMsg).Elem()).Interface().(api.Message)
89 stop, err := multi.ReceiveReply(msg)
96 resp.Msgs = append(resp.Msgs, msg)
99 // create new message in response of type ReplyMsg
100 resp.Msg = reflect.New(reflect.TypeOf(req.ReplyMsg).Elem()).Interface().(api.Message)
102 err := s.binapi.SendRequest(req.Msg).ReceiveReply(resp.Msg)