Fix encode/decode for []bool
[govpp.git] / api / errors.go
1 package api
2
3 import (
4         "fmt"
5         "strconv"
6 )
7
8 // CompatibilityError is the error type usually returned by CheckCompatibility
9 // method of Channel. It contains list of all the compatible/incompatible messages.
10 type CompatibilityError struct {
11         CompatibleMessages   []string
12         IncompatibleMessages []string
13 }
14
15 func (c *CompatibilityError) Error() string {
16         return fmt.Sprintf("%d/%d messages incompatible", len(c.IncompatibleMessages), len(c.CompatibleMessages)+len(c.IncompatibleMessages))
17 }
18
19 // RetvalToVPPApiError returns error for retval value.
20 // Retval 0 returns nil error.
21 func RetvalToVPPApiError(retval int32) error {
22         if retval == 0 {
23                 return nil
24         }
25         return VPPApiError(retval)
26 }
27
28 // VPPApiError represents VPP's vnet API error that is usually
29 // returned as Retval field in replies from VPP binary API.
30 type VPPApiError int32
31
32 func (e VPPApiError) Error() string {
33         errid := int64(e)
34         var errstr string
35         if s, ok := vppApiErrors[e]; ok {
36                 errstr = fmt.Sprintf("%s (%d)", s, errid)
37         } else {
38                 errstr = strconv.FormatInt(errid, 10)
39         }
40         return fmt.Sprintf("VPPApiError: %s", errstr)
41 }
42
43 // definitions from: vpp/src/vnet/api_errno.h
44 const (
45         _                                  VPPApiError = 0
46         UNSPECIFIED                                    = -1
47         INVALID_SW_IF_INDEX                            = -2
48         NO_SUCH_FIB                                    = -3
49         NO_SUCH_INNER_FIB                              = -4
50         NO_SUCH_LABEL                                  = -5
51         NO_SUCH_ENTRY                                  = -6
52         INVALID_VALUE                                  = -7
53         INVALID_VALUE_2                                = -8
54         UNIMPLEMENTED                                  = -9
55         INVALID_SW_IF_INDEX_2                          = -10
56         SYSCALL_ERROR_1                                = -11
57         SYSCALL_ERROR_2                                = -12
58         SYSCALL_ERROR_3                                = -13
59         SYSCALL_ERROR_4                                = -14
60         SYSCALL_ERROR_5                                = -15
61         SYSCALL_ERROR_6                                = -16
62         SYSCALL_ERROR_7                                = -17
63         SYSCALL_ERROR_8                                = -18
64         SYSCALL_ERROR_9                                = -19
65         SYSCALL_ERROR_10                               = -20
66         FEATURE_DISABLED                               = -30
67         INVALID_REGISTRATION                           = -31
68         NEXT_HOP_NOT_IN_FIB                            = -50
69         UNKNOWN_DESTINATION                            = -51
70         PREFIX_MATCHES_NEXT_HOP                        = -52
71         NEXT_HOP_NOT_FOUND_MP                          = -53
72         NO_MATCHING_INTERFACE                          = -54
73         INVALID_VLAN                                   = -55
74         VLAN_ALREADY_EXISTS                            = -56
75         INVALID_SRC_ADDRESS                            = -57
76         INVALID_DST_ADDRESS                            = -58
77         ADDRESS_LENGTH_MISMATCH                        = -59
78         ADDRESS_NOT_FOUND_FOR_INTERFACE                = -60
79         ADDRESS_NOT_DELETABLE                          = -61
80         IP6_NOT_ENABLED                                = -62
81         IN_PROGRESS                                    = 10
82         NO_SUCH_NODE                                   = -63
83         NO_SUCH_NODE2                                  = -64
84         NO_SUCH_TABLE                                  = -65
85         NO_SUCH_TABLE2                                 = -66
86         NO_SUCH_TABLE3                                 = -67
87         SUBIF_ALREADY_EXISTS                           = -68
88         SUBIF_CREATE_FAILED                            = -69
89         INVALID_MEMORY_SIZE                            = -70
90         INVALID_INTERFACE                              = -71
91         INVALID_VLAN_TAG_COUNT                         = -72
92         INVALID_ARGUMENT                               = -73
93         UNEXPECTED_INTF_STATE                          = -74
94         TUNNEL_EXIST                                   = -75
95         INVALID_DECAP_NEXT                             = -76
96         RESPONSE_NOT_READY                             = -77
97         NOT_CONNECTED                                  = -78
98         IF_ALREADY_EXISTS                              = -79
99         BOND_SLAVE_NOT_ALLOWED                         = -80
100         VALUE_EXIST                                    = -81
101         SAME_SRC_DST                                   = -82
102         IP6_MULTICAST_ADDRESS_NOT_PRESENT              = -83
103         SR_POLICY_NAME_NOT_PRESENT                     = -84
104         NOT_RUNNING_AS_ROOT                            = -85
105         ALREADY_CONNECTED                              = -86
106         UNSUPPORTED_JNI_VERSION                        = -87
107         FAILED_TO_ATTACH_TO_JAVA_THREAD                = -88
108         INVALID_WORKER                                 = -89
109         LISP_DISABLED                                  = -90
110         CLASSIFY_TABLE_NOT_FOUND                       = -91
111         INVALID_EID_TYPE                               = -92
112         CANNOT_CREATE_PCAP_FILE                        = -93
113         INCORRECT_ADJACENCY_TYPE                       = -94
114         EXCEEDED_NUMBER_OF_RANGES_CAPACITY             = -95
115         EXCEEDED_NUMBER_OF_PORTS_CAPACITY              = -96
116         INVALID_ADDRESS_FAMILY                         = -97
117         INVALID_SUB_SW_IF_INDEX                        = -98
118         TABLE_TOO_BIG                                  = -99
119         CANNOT_ENABLE_DISABLE_FEATURE                  = -100
120         BFD_EEXIST                                     = -101
121         BFD_ENOENT                                     = -102
122         BFD_EINUSE                                     = -103
123         BFD_NOTSUPP                                    = -104
124         ADDRESS_IN_USE                                 = -105
125         ADDRESS_NOT_IN_USE                             = -106
126         QUEUE_FULL                                     = -107
127         APP_UNSUPPORTED_CFG                            = -108
128         URI_FIFO_CREATE_FAILED                         = -109
129         LISP_RLOC_LOCAL                                = -110
130         BFD_EAGAIN                                     = -111
131         INVALID_GPE_MODE                               = -112
132         LISP_GPE_ENTRIES_PRESENT                       = -113
133         ADDRESS_FOUND_FOR_INTERFACE                    = -114
134         SESSION_CONNECT                                = -115
135         ENTRY_ALREADY_EXISTS                           = -116
136         SVM_SEGMENT_CREATE_FAIL                        = -117
137         APPLICATION_NOT_ATTACHED                       = -118
138         BD_ALREADY_EXISTS                              = -119
139         BD_IN_USE                                      = -120
140         BD_NOT_MODIFIABLE                              = -121
141         BD_ID_EXCEED_MAX                               = -122
142         SUBIF_DOESNT_EXIST                             = -123
143         L2_MACS_EVENT_CLINET_PRESENT                   = -124
144         INVALID_QUEUE                                  = -125
145         UNSUPPORTED                                    = -126
146         DUPLICATE_IF_ADDRESS                           = -127
147         APP_INVALID_NS                                 = -128
148         APP_WRONG_NS_SECRET                            = -129
149         APP_CONNECT_SCOPE                              = -130
150         APP_ALREADY_ATTACHED                           = -131
151         SESSION_REDIRECT                               = -132
152         ILLEGAL_NAME                                   = -133
153         NO_NAME_SERVERS                                = -134
154         NAME_SERVER_NOT_FOUND                          = -135
155         NAME_RESOLUTION_NOT_ENABLED                    = -136
156         NAME_SERVER_FORMAT_ERROR                       = -137
157         NAME_SERVER_NO_SUCH_NAME                       = -138
158         NAME_SERVER_NO_ADDRESSES                       = -139
159         NAME_SERVER_NEXT_SERVER                        = -140
160         APP_CONNECT_FILTERED                           = -141
161         ACL_IN_USE_INBOUND                             = -142
162         ACL_IN_USE_OUTBOUND                            = -143
163         INIT_FAILED                                    = -144
164         NETLINK_ERROR                                  = -145
165         BIER_BSL_UNSUP                                 = -146
166         INSTANCE_IN_USE                                = -147
167         INVALID_SESSION_ID                             = -148
168         ACL_IN_USE_BY_LOOKUP_CONTEXT                   = -149
169         INVALID_VALUE_3                                = -150
170         NON_ETHERNET                                   = -151
171         BD_ALREADY_HAS_BVI                             = -152
172 )
173
174 var vppApiErrors = map[VPPApiError]string{
175         UNSPECIFIED:                        "Unspecified Error",
176         INVALID_SW_IF_INDEX:                "Invalid sw_if_index",
177         NO_SUCH_FIB:                        "No such FIB / VRF",
178         NO_SUCH_INNER_FIB:                  "No such inner FIB / VRF",
179         NO_SUCH_LABEL:                      "No such label",
180         NO_SUCH_ENTRY:                      "No such entry",
181         INVALID_VALUE:                      "Invalid value",
182         INVALID_VALUE_2:                    "Invalid value #2",
183         UNIMPLEMENTED:                      "Unimplemented",
184         INVALID_SW_IF_INDEX_2:              "Invalid sw_if_index #2",
185         SYSCALL_ERROR_1:                    "System call error #1",
186         SYSCALL_ERROR_2:                    "System call error #2",
187         SYSCALL_ERROR_3:                    "System call error #3",
188         SYSCALL_ERROR_4:                    "System call error #4",
189         SYSCALL_ERROR_5:                    "System call error #5",
190         SYSCALL_ERROR_6:                    "System call error #6",
191         SYSCALL_ERROR_7:                    "System call error #7",
192         SYSCALL_ERROR_8:                    "System call error #8",
193         SYSCALL_ERROR_9:                    "System call error #9",
194         SYSCALL_ERROR_10:                   "System call error #10",
195         FEATURE_DISABLED:                   "Feature disabled by configuration",
196         INVALID_REGISTRATION:               "Invalid registration",
197         NEXT_HOP_NOT_IN_FIB:                "Next hop not in FIB",
198         UNKNOWN_DESTINATION:                "Unknown destination",
199         PREFIX_MATCHES_NEXT_HOP:            "Prefix matches next hop",
200         NEXT_HOP_NOT_FOUND_MP:              "Next hop not found (multipath)",
201         NO_MATCHING_INTERFACE:              "No matching interface for probe",
202         INVALID_VLAN:                       "Invalid VLAN",
203         VLAN_ALREADY_EXISTS:                "VLAN subif already exists",
204         INVALID_SRC_ADDRESS:                "Invalid src address",
205         INVALID_DST_ADDRESS:                "Invalid dst address",
206         ADDRESS_LENGTH_MISMATCH:            "Address length mismatch",
207         ADDRESS_NOT_FOUND_FOR_INTERFACE:    "Address not found for interface",
208         ADDRESS_NOT_DELETABLE:              "Address not deletable",
209         IP6_NOT_ENABLED:                    "ip6 not enabled",
210         IN_PROGRESS:                        "Operation in progress",
211         NO_SUCH_NODE:                       "No such graph node",
212         NO_SUCH_NODE2:                      "No such graph node #2",
213         NO_SUCH_TABLE:                      "No such table",
214         NO_SUCH_TABLE2:                     "No such table #2",
215         NO_SUCH_TABLE3:                     "No such table #3",
216         SUBIF_ALREADY_EXISTS:               "Subinterface already exists",
217         SUBIF_CREATE_FAILED:                "Subinterface creation failed",
218         INVALID_MEMORY_SIZE:                "Invalid memory size requested",
219         INVALID_INTERFACE:                  "Invalid interface",
220         INVALID_VLAN_TAG_COUNT:             "Invalid number of tags for requested operation",
221         INVALID_ARGUMENT:                   "Invalid argument",
222         UNEXPECTED_INTF_STATE:              "Unexpected interface state",
223         TUNNEL_EXIST:                       "Tunnel already exists",
224         INVALID_DECAP_NEXT:                 "Invalid decap-next",
225         RESPONSE_NOT_READY:                 "Response not ready",
226         NOT_CONNECTED:                      "Not connected to the data plane",
227         IF_ALREADY_EXISTS:                  "Interface already exists",
228         BOND_SLAVE_NOT_ALLOWED:             "Operation not allowed on slave of BondEthernet",
229         VALUE_EXIST:                        "Value already exists",
230         SAME_SRC_DST:                       "Source and destination are the same",
231         IP6_MULTICAST_ADDRESS_NOT_PRESENT:  "IP6 multicast address required",
232         SR_POLICY_NAME_NOT_PRESENT:         "Segement routing policy name required",
233         NOT_RUNNING_AS_ROOT:                "Not running as root",
234         ALREADY_CONNECTED:                  "Connection to the data plane already exists",
235         UNSUPPORTED_JNI_VERSION:            "Unsupported JNI version",
236         FAILED_TO_ATTACH_TO_JAVA_THREAD:    "Failed to attach to Java thread",
237         INVALID_WORKER:                     "Invalid worker thread",
238         LISP_DISABLED:                      "LISP is disabled",
239         CLASSIFY_TABLE_NOT_FOUND:           "Classify table not found",
240         INVALID_EID_TYPE:                   "Unsupported LSIP EID type",
241         CANNOT_CREATE_PCAP_FILE:            "Cannot create pcap file",
242         INCORRECT_ADJACENCY_TYPE:           "Invalid adjacency type for this operation",
243         EXCEEDED_NUMBER_OF_RANGES_CAPACITY: "Operation would exceed configured capacity of ranges",
244         EXCEEDED_NUMBER_OF_PORTS_CAPACITY:  "Operation would exceed capacity of number of ports",
245         INVALID_ADDRESS_FAMILY:             "Invalid address family",
246         INVALID_SUB_SW_IF_INDEX:            "Invalid sub-interface sw_if_index",
247         TABLE_TOO_BIG:                      "Table too big",
248         CANNOT_ENABLE_DISABLE_FEATURE:      "Cannot enable/disable feature",
249         BFD_EEXIST:                         "Duplicate BFD object",
250         BFD_ENOENT:                         "No such BFD object",
251         BFD_EINUSE:                         "BFD object in use",
252         BFD_NOTSUPP:                        "BFD feature not supported",
253         ADDRESS_IN_USE:                     "Address in use",
254         ADDRESS_NOT_IN_USE:                 "Address not in use",
255         QUEUE_FULL:                         "Queue full",
256         APP_UNSUPPORTED_CFG:                "Unsupported application config",
257         URI_FIFO_CREATE_FAILED:             "URI FIFO segment create failed",
258         LISP_RLOC_LOCAL:                    "RLOC address is local",
259         BFD_EAGAIN:                         "BFD object cannot be manipulated at this time",
260         INVALID_GPE_MODE:                   "Invalid GPE mode",
261         LISP_GPE_ENTRIES_PRESENT:           "LISP GPE entries are present",
262         ADDRESS_FOUND_FOR_INTERFACE:        "Address found for interface",
263         SESSION_CONNECT:                    "Session failed to connect",
264         ENTRY_ALREADY_EXISTS:               "Entry already exists",
265         SVM_SEGMENT_CREATE_FAIL:            "svm segment create fail",
266         APPLICATION_NOT_ATTACHED:           "application not attached",
267         BD_ALREADY_EXISTS:                  "Bridge domain already exists",
268         BD_IN_USE:                          "Bridge domain has member interfaces",
269         BD_NOT_MODIFIABLE:                  "Bridge domain 0 can't be deleted/modified",
270         BD_ID_EXCEED_MAX:                   "Bridge domain ID exceed 16M limit",
271         SUBIF_DOESNT_EXIST:                 "Subinterface doesn't exist",
272         L2_MACS_EVENT_CLINET_PRESENT:       "Client already exist for L2 MACs events",
273         INVALID_QUEUE:                      "Invalid queue",
274         UNSUPPORTED:                        "Unsupported",
275         DUPLICATE_IF_ADDRESS:               "Address already present on another interface",
276         APP_INVALID_NS:                     "Invalid application namespace",
277         APP_WRONG_NS_SECRET:                "Wrong app namespace secret",
278         APP_CONNECT_SCOPE:                  "Connect scope",
279         APP_ALREADY_ATTACHED:               "App already attached",
280         SESSION_REDIRECT:                   "Redirect failed",
281         ILLEGAL_NAME:                       "Illegal name",
282         NO_NAME_SERVERS:                    "No name servers configured",
283         NAME_SERVER_NOT_FOUND:              "Name server not found",
284         NAME_RESOLUTION_NOT_ENABLED:        "Name resolution not enabled",
285         NAME_SERVER_FORMAT_ERROR:           "Server format error (bug!)",
286         NAME_SERVER_NO_SUCH_NAME:           "No such name",
287         NAME_SERVER_NO_ADDRESSES:           "No addresses available",
288         NAME_SERVER_NEXT_SERVER:            "Retry with new server",
289         APP_CONNECT_FILTERED:               "Connect was filtered",
290         ACL_IN_USE_INBOUND:                 "Inbound ACL in use",
291         ACL_IN_USE_OUTBOUND:                "Outbound ACL in use",
292         INIT_FAILED:                        "Initialization Failed",
293         NETLINK_ERROR:                      "netlink error",
294         BIER_BSL_UNSUP:                     "BIER bit-string-length unsupported",
295         INSTANCE_IN_USE:                    "Instance in use",
296         INVALID_SESSION_ID:                 "session ID out of range",
297         ACL_IN_USE_BY_LOOKUP_CONTEXT:       "ACL in use by a lookup context",
298         INVALID_VALUE_3:                    "Invalid value #3",
299         NON_ETHERNET:                       "Interface is not an Ethernet interface",
300         BD_ALREADY_HAS_BVI:                 "Bridge domain already has a BVI interface",
301 }