Skip to content

Commit 9cf7f82

Browse files
Fix returning message reply on retval errors (#147)
* fix handling of EAGAIN reply return value The new VPP binapi for stream can return a reply with the return value EAGAIN. This value signals, that VPP ends the transmition because the call has taken to long and is possibly blocking the master thread. The client is then expected to repeat the request, optimally providing the cursor to the last received data. Sofar, the implementation only returned an error without providing the cursor to the last received data point (in older versions, e.g., v0.4.0, govpp does not return an error and just accepts the incomplete response). * Revert converting retval field to error Signed-off-by: Ondrej Fabry <[email protected]> --------- Signed-off-by: Ondrej Fabry <[email protected]> Co-authored-by: Fabio Streun <[email protected]>
1 parent 5dcbc7f commit 9cf7f82

File tree

14 files changed

+68
-38
lines changed

14 files changed

+68
-38
lines changed

Diff for: api/errors.go

+30
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,21 @@ const (
169169
INVALID_VALUE_3 VPPApiError = -150
170170
NON_ETHERNET VPPApiError = -151
171171
BD_ALREADY_HAS_BVI VPPApiError = -152
172+
INVALID_PROTOCOL VPPApiError = -153
173+
INVALID_ALGORITHM VPPApiError = -154
174+
RSRC_IN_USE VPPApiError = -155
175+
KEY_LENGTH VPPApiError = -156
176+
FIB_PATH_UNSUPPORTED_NH_PROTO VPPApiError = -157
177+
API_ENDIAN_FAILED VPPApiError = -159
178+
NO_CHANGE VPPApiError = -160
179+
MISSING_CERT_KEY VPPApiError = -161
180+
LIMIT_EXCEEDED VPPApiError = -162
181+
IKE_NO_PORT VPPApiError = -163
182+
UDP_PORT_TAKEN VPPApiError = -164
183+
EAGAIN VPPApiError = -165
184+
INVALID_VALUE_4 VPPApiError = -166
185+
BUSY VPPApiError = -167
186+
BUG VPPApiError = -168
172187
)
173188

174189
var vppApiErrors = map[VPPApiError]string{
@@ -298,4 +313,19 @@ var vppApiErrors = map[VPPApiError]string{
298313
INVALID_VALUE_3: "Invalid value #3",
299314
NON_ETHERNET: "Interface is not an Ethernet interface",
300315
BD_ALREADY_HAS_BVI: "Bridge domain already has a BVI interface",
316+
INVALID_PROTOCOL: "Invalid Protocol",
317+
INVALID_ALGORITHM: "Invalid Algorithm",
318+
RSRC_IN_USE: "Resource In Use",
319+
KEY_LENGTH: "invalid Key Length",
320+
FIB_PATH_UNSUPPORTED_NH_PROTO: "Unsupported FIB Path protocol",
321+
API_ENDIAN_FAILED: "Endian mismatch detected",
322+
NO_CHANGE: "No change in table",
323+
MISSING_CERT_KEY: "Missing certifcate or key",
324+
LIMIT_EXCEEDED: "limit exceeded",
325+
IKE_NO_PORT: "port not managed by IKE",
326+
UDP_PORT_TAKEN: "UDP port already taken",
327+
EAGAIN: "Retry stream call with cursor",
328+
INVALID_VALUE_4: "Invalid value #4",
329+
BUSY: "Busy",
330+
BUG: "Bug",
301331
}

Diff for: binapi/graph/graph_rpc.ba.go

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: binapi/interface/interface_rpc.ba.go

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: binapi/ip/ip_rpc.ba.go

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: binapi/ipfix_export/ipfix_export_rpc.ba.go

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: binapi/lcp/lcp_rpc.ba.go

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: binapi/map/map_rpc.ba.go

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: binapi/mss_clamp/mss_clamp_rpc.ba.go

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: binapi/nat44_ed/nat44_ed_rpc.ba.go

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: binapi/nat44_ei/nat44_ei_rpc.ba.go

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: binapi/pnat/pnat_rpc.ba.go

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: binapi/tracedump/tracedump_rpc.ba.go

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: binapigen/binapigen.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,9 @@ func newMessage(gen *Generator, file *File, apitype vppapi.Message) *Message {
327327
var n int
328328
for _, fieldType := range apitype.Fields {
329329
if n == 0 {
330-
// skip header fields
331330
switch strings.ToLower(fieldType.Name) {
332331
case fieldMsgID, fieldClientIndex, fieldContext:
332+
// skip header fields
333333
continue
334334
}
335335
}

Diff for: binapigen/generate_rpc.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,9 @@ func genService(g *GenFile, svc *Service) {
169169
g.P(" case *", msgReply.GoIdent, ":")
170170
if msgReply != msgControlPingReply {
171171
if retvalField := getRetvalField(msgReply); retvalField != nil {
172-
s := fmt.Sprint("(m.", retvalField.GoName, ")")
173-
if fieldType := getFieldType(g, retvalField); fieldType != "int32" {
174-
s = fmt.Sprint("(int32(m.", retvalField.GoName, "))")
175-
}
176-
g.P("if err := ", govppApiPkg.Ident("RetvalToVPPApiError"), s, "; err != nil {")
172+
g.P("if err := ", retvalFieldToErr(g, "m", retvalField), "; err != nil {")
177173
if msgReply != msgControlPingReply {
178-
g.P(" return nil, nil, err")
174+
g.P(" return nil, m, err")
179175
} else {
180176
g.P(" return nil, err")
181177
}
@@ -184,7 +180,7 @@ func genService(g *GenFile, svc *Service) {
184180
}
185181
g.P(" err = c.Stream.Close()")
186182
if msgReply != msgControlPingReply {
187-
g.P(" if err != nil { return nil, nil, err }")
183+
g.P(" if err != nil { return nil, m, err }")
188184
} else {
189185
g.P(" if err != nil { return nil, err }")
190186
}
@@ -205,15 +201,11 @@ func genService(g *GenFile, svc *Service) {
205201
g.P("err := c.conn.Invoke(ctx, in, out)")
206202
g.P("if err != nil { return nil, err }")
207203
if retvalField := getRetvalField(rpc.MsgReply); retvalField != nil {
208-
if fieldType := getFieldType(g, retvalField); fieldType == "int32" {
209-
g.P("return out, ", govppApiPkg.Ident("RetvalToVPPApiError"), "(out.", retvalField.GoName, ")")
210-
} else {
211-
g.P("return out, ", govppApiPkg.Ident("RetvalToVPPApiError"), "(int32(out.", retvalField.GoName, "))")
212-
}
204+
g.P("return out, ", retvalFieldToErr(g, "out", retvalField))
213205
} else {
214206
g.P("return out, nil")
215207
}
216-
} else {
208+
} else { // MsgReply == nil
217209
g.P("stream, err := c.conn.NewStream(ctx)")
218210
g.P("if err != nil { return err }")
219211
g.P("err = stream.SendMsg(in)")
@@ -245,6 +237,14 @@ func genService(g *GenFile, svc *Service) {
245237
g.P()
246238
}
247239

240+
func retvalFieldToErr(g *GenFile, varName string, retvalField *Field) string {
241+
if getFieldType(g, retvalField) == "int32" {
242+
return g.GoIdent(govppApiPkg.Ident("RetvalToVPPApiError")) + "(" + varName + "." + retvalField.GoName + ")"
243+
} else {
244+
return g.GoIdent(govppApiPkg.Ident("RetvalToVPPApiError")) + "(int32(" + varName + "." + retvalField.GoName + "))"
245+
}
246+
}
247+
248248
func rpcMethodSignature(g *GenFile, rpc *RPC) string {
249249
s := rpc.GoName + "(ctx " + g.GoIdent(contextPkg.Ident("Context"))
250250
s += ", in *" + g.GoIdent(rpc.MsgRequest.GoIdent) + ") ("

0 commit comments

Comments
 (0)