1
+ // Copyright (c) 2019 Cisco and/or its affiliates.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at:
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
1
15
package proxy
2
16
3
17
import (
4
18
"fmt"
5
- "log "
19
+ "git.fd.io/govpp.git/core "
6
20
"net/rpc"
7
21
"reflect"
8
22
"time"
@@ -40,7 +54,8 @@ func (c *Client) NewStatsClient() (*StatsClient, error) {
40
54
// NewBinapiClient returns new BinapiClient which implements api.Channel.
41
55
func (c * Client ) NewBinapiClient () (* BinapiClient , error ) {
42
56
binapi := & BinapiClient {
43
- rpc : c .rpc ,
57
+ rpc : c .rpc ,
58
+ timeout : core .DefaultReplyTimeout ,
44
59
}
45
60
return binapi , nil
46
61
}
@@ -103,27 +118,31 @@ func (s *StatsClient) GetBufferStats(bufStats *api.BufferStats) error {
103
118
}
104
119
105
120
type BinapiClient struct {
106
- rpc * rpc.Client
121
+ rpc * rpc.Client
122
+ timeout time.Duration
107
123
}
108
124
109
125
func (b * BinapiClient ) SendRequest (msg api.Message ) api.RequestCtx {
110
126
req := & requestCtx {
111
- rpc : b .rpc ,
112
- req : msg ,
127
+ rpc : b .rpc ,
128
+ timeout : b .timeout ,
129
+ req : msg ,
113
130
}
114
- log .Printf ("SendRequest: %T %+v" , msg , msg )
131
+ log .Debugf ("SendRequest: %T %+v" , msg , msg )
115
132
return req
116
133
}
117
134
118
135
type requestCtx struct {
119
- rpc * rpc.Client
120
- req api.Message
136
+ rpc * rpc.Client
137
+ req api.Message
138
+ timeout time.Duration
121
139
}
122
140
123
141
func (r * requestCtx ) ReceiveReply (msg api.Message ) error {
124
142
req := BinapiRequest {
125
143
Msg : r .req ,
126
144
ReplyMsg : msg ,
145
+ Timeout : r .timeout ,
127
146
}
128
147
resp := BinapiResponse {}
129
148
@@ -140,16 +159,18 @@ func (r *requestCtx) ReceiveReply(msg api.Message) error {
140
159
141
160
func (b * BinapiClient ) SendMultiRequest (msg api.Message ) api.MultiRequestCtx {
142
161
req := & multiRequestCtx {
143
- rpc : b .rpc ,
144
- req : msg ,
162
+ rpc : b .rpc ,
163
+ timeout : b .timeout ,
164
+ req : msg ,
145
165
}
146
- log .Printf ("SendMultiRequest: %T %+v" , msg , msg )
166
+ log .Debugf ("SendMultiRequest: %T %+v" , msg , msg )
147
167
return req
148
168
}
149
169
150
170
type multiRequestCtx struct {
151
- rpc * rpc.Client
152
- req api.Message
171
+ rpc * rpc.Client
172
+ req api.Message
173
+ timeout time.Duration
153
174
154
175
index int
155
176
replies []api.Message
@@ -162,6 +183,7 @@ func (r *multiRequestCtx) ReceiveReply(msg api.Message) (stop bool, err error) {
162
183
Msg : r .req ,
163
184
ReplyMsg : msg ,
164
185
IsMulti : true ,
186
+ Timeout : r .timeout ,
165
187
}
166
188
resp := BinapiResponse {}
167
189
@@ -189,24 +211,23 @@ func (b *BinapiClient) SubscribeNotification(notifChan chan api.Message, event a
189
211
}
190
212
191
213
func (b * BinapiClient ) SetReplyTimeout (timeout time.Duration ) {
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
- }
214
+ b .timeout = timeout
197
215
}
198
216
199
217
func (b * BinapiClient ) CheckCompatiblity (msgs ... api.Message ) error {
218
+ msgNamesCrscs := make ([]string , 0 , len (msgs ))
219
+
200
220
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
- }
221
+ msgNamesCrscs = append (msgNamesCrscs , msg .GetMessageName ()+ "_" + msg .GetCrcString ())
209
222
}
223
+
224
+ req := BinapiCompatibilityRequest {MsgNameCrcs : msgNamesCrscs }
225
+ resp := BinapiCompatibilityResponse {}
226
+
227
+ if err := b .rpc .Call ("BinapiRPC.Compatibility" , req , & resp ); err != nil {
228
+ return err
229
+ }
230
+
210
231
return nil
211
232
}
212
233
0 commit comments