9 "git.fd.io/govpp.git/api"
12 type StatsRequest struct {
16 type StatsResponse struct {
17 SysStats *api.SystemStats
18 NodeStats *api.NodeStats
19 IfaceStats *api.InterfaceStats
20 ErrStats *api.ErrorStats
21 BufStats *api.BufferStats
24 // StatsRPC is a RPC server for proxying client request to api.StatsProvider.
25 type StatsRPC struct {
26 stats api.StatsProvider
29 // NewStatsRPC returns new StatsRPC to be used as RPC server
30 // proxying request to given api.StatsProvider.
31 func NewStatsRPC(stats api.StatsProvider) *StatsRPC {
32 return &StatsRPC{stats: stats}
35 func (s *StatsRPC) GetStats(req StatsRequest, resp *StatsResponse) error {
36 log.Printf("StatsRPC.GetStats - REQ: %+v", req)
38 switch req.StatsType {
40 resp.SysStats = new(api.SystemStats)
41 return s.stats.GetSystemStats(resp.SysStats)
43 resp.NodeStats = new(api.NodeStats)
44 return s.stats.GetNodeStats(resp.NodeStats)
46 resp.IfaceStats = new(api.InterfaceStats)
47 return s.stats.GetInterfaceStats(resp.IfaceStats)
49 resp.ErrStats = new(api.ErrorStats)
50 return s.stats.GetErrorStats(resp.ErrStats)
52 resp.BufStats = new(api.BufferStats)
53 return s.stats.GetBufferStats(resp.BufStats)
55 return fmt.Errorf("unknown stats type: %s", req.StatsType)
59 type BinapiRequest struct {
65 type BinapiResponse struct {
70 type BinapiCompatibilityRequest struct {
75 type BinapiCompatibilityResponse struct {
78 type BinapiTimeoutRequest struct {
82 type BinapiTimeoutResponse struct {
85 // BinapiRPC is a RPC server for proxying client request to api.Channel.
86 type BinapiRPC struct {
90 // NewBinapiRPC returns new BinapiRPC to be used as RPC server
91 // proxying request to given api.Channel.
92 func NewBinapiRPC(binapi api.Channel) *BinapiRPC {
93 return &BinapiRPC{binapi: binapi}
96 func (s *BinapiRPC) Invoke(req BinapiRequest, resp *BinapiResponse) error {
97 log.Printf("BinapiRPC.Invoke - REQ: %#v", req)
100 multi := s.binapi.SendMultiRequest(req.Msg)
102 // create new message in response of type ReplyMsg
103 msg := reflect.New(reflect.TypeOf(req.ReplyMsg).Elem()).Interface().(api.Message)
105 stop, err := multi.ReceiveReply(msg)
112 resp.Msgs = append(resp.Msgs, msg)
115 // create new message in response of type ReplyMsg
116 resp.Msg = reflect.New(reflect.TypeOf(req.ReplyMsg).Elem()).Interface().(api.Message)
118 err := s.binapi.SendRequest(req.Msg).ReceiveReply(resp.Msg)
127 func (s *BinapiRPC) SetTimeout(req BinapiTimeoutRequest, _ *BinapiTimeoutResponse) error {
128 log.Printf("BinapiRPC.SetTimeout - REQ: %#v", req)
129 s.binapi.SetReplyTimeout(req.Timeout)
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)
138 return fmt.Errorf("compatibility check failed for the message: %s", req.MsgName+"_"+req.Crc)