1 // Code generated by GoVPP's binapi-generator. DO NOT EDIT.
3 // binapi-generator: v0.4.0-dev
5 // source: /usr/share/vpp/api/core/ip_types.api.json
8 Package ip_types contains generated code for VPP API file ip_types.api (3.0.0).
29 api "git.fd.io/govpp.git/api"
30 codec "git.fd.io/govpp.git/codec"
31 struc "github.com/lunixbochs/struc"
34 // This is a compile-time assertion to ensure that this generated file
35 // is compatible with the GoVPP api package it is being compiled against.
36 // A compilation error at this line likely means your copy of the
37 // GoVPP api package needs to be updated.
38 const _ = api.GoVppAPIPackageIsVersion2 // please upgrade the GoVPP api package
41 // ModuleName is the name of this module.
42 ModuleName = "ip_types"
43 // APIVersion is the API version of this module.
45 // VersionCrc is the CRC of this module.
46 VersionCrc = 0x9cb1c2e2
49 // AddressFamily represents VPP binary API enum 'address_family'.
50 type AddressFamily uint8
53 ADDRESS_IP4 AddressFamily = 0
54 ADDRESS_IP6 AddressFamily = 1
58 AddressFamily_name = map[uint8]string{
62 AddressFamily_value = map[string]uint8{
68 func (x AddressFamily) String() string {
69 s, ok := AddressFamily_name[uint8(x)]
73 return "AddressFamily(" + strconv.Itoa(int(x)) + ")"
76 // IPDscp represents VPP binary API enum 'ip_dscp'.
80 IP_API_DSCP_CS0 IPDscp = 0
81 IP_API_DSCP_CS1 IPDscp = 8
82 IP_API_DSCP_AF11 IPDscp = 10
83 IP_API_DSCP_AF12 IPDscp = 12
84 IP_API_DSCP_AF13 IPDscp = 14
85 IP_API_DSCP_CS2 IPDscp = 16
86 IP_API_DSCP_AF21 IPDscp = 18
87 IP_API_DSCP_AF22 IPDscp = 20
88 IP_API_DSCP_AF23 IPDscp = 22
89 IP_API_DSCP_CS3 IPDscp = 24
90 IP_API_DSCP_AF31 IPDscp = 26
91 IP_API_DSCP_AF32 IPDscp = 28
92 IP_API_DSCP_AF33 IPDscp = 30
93 IP_API_DSCP_CS4 IPDscp = 32
94 IP_API_DSCP_AF41 IPDscp = 34
95 IP_API_DSCP_AF42 IPDscp = 36
96 IP_API_DSCP_AF43 IPDscp = 38
97 IP_API_DSCP_CS5 IPDscp = 40
98 IP_API_DSCP_EF IPDscp = 46
99 IP_API_DSCP_CS6 IPDscp = 48
100 IP_API_DSCP_CS7 IPDscp = 50
104 IPDscp_name = map[uint8]string{
105 0: "IP_API_DSCP_CS0",
106 8: "IP_API_DSCP_CS1",
107 10: "IP_API_DSCP_AF11",
108 12: "IP_API_DSCP_AF12",
109 14: "IP_API_DSCP_AF13",
110 16: "IP_API_DSCP_CS2",
111 18: "IP_API_DSCP_AF21",
112 20: "IP_API_DSCP_AF22",
113 22: "IP_API_DSCP_AF23",
114 24: "IP_API_DSCP_CS3",
115 26: "IP_API_DSCP_AF31",
116 28: "IP_API_DSCP_AF32",
117 30: "IP_API_DSCP_AF33",
118 32: "IP_API_DSCP_CS4",
119 34: "IP_API_DSCP_AF41",
120 36: "IP_API_DSCP_AF42",
121 38: "IP_API_DSCP_AF43",
122 40: "IP_API_DSCP_CS5",
123 46: "IP_API_DSCP_EF",
124 48: "IP_API_DSCP_CS6",
125 50: "IP_API_DSCP_CS7",
127 IPDscp_value = map[string]uint8{
128 "IP_API_DSCP_CS0": 0,
129 "IP_API_DSCP_CS1": 8,
130 "IP_API_DSCP_AF11": 10,
131 "IP_API_DSCP_AF12": 12,
132 "IP_API_DSCP_AF13": 14,
133 "IP_API_DSCP_CS2": 16,
134 "IP_API_DSCP_AF21": 18,
135 "IP_API_DSCP_AF22": 20,
136 "IP_API_DSCP_AF23": 22,
137 "IP_API_DSCP_CS3": 24,
138 "IP_API_DSCP_AF31": 26,
139 "IP_API_DSCP_AF32": 28,
140 "IP_API_DSCP_AF33": 30,
141 "IP_API_DSCP_CS4": 32,
142 "IP_API_DSCP_AF41": 34,
143 "IP_API_DSCP_AF42": 36,
144 "IP_API_DSCP_AF43": 38,
145 "IP_API_DSCP_CS5": 40,
146 "IP_API_DSCP_EF": 46,
147 "IP_API_DSCP_CS6": 48,
148 "IP_API_DSCP_CS7": 50,
152 func (x IPDscp) String() string {
153 s, ok := IPDscp_name[uint8(x)]
157 return "IPDscp(" + strconv.Itoa(int(x)) + ")"
160 // IPEcn represents VPP binary API enum 'ip_ecn'.
164 IP_API_ECN_NONE IPEcn = 0
165 IP_API_ECN_ECT0 IPEcn = 1
166 IP_API_ECN_ECT1 IPEcn = 2
167 IP_API_ECN_CE IPEcn = 3
171 IPEcn_name = map[uint8]string{
172 0: "IP_API_ECN_NONE",
173 1: "IP_API_ECN_ECT0",
174 2: "IP_API_ECN_ECT1",
177 IPEcn_value = map[string]uint8{
178 "IP_API_ECN_NONE": 0,
179 "IP_API_ECN_ECT0": 1,
180 "IP_API_ECN_ECT1": 2,
185 func (x IPEcn) String() string {
186 s, ok := IPEcn_name[uint8(x)]
190 return "IPEcn(" + strconv.Itoa(int(x)) + ")"
193 // IPProto represents VPP binary API enum 'ip_proto'.
197 IP_API_PROTO_HOPOPT IPProto = 0
198 IP_API_PROTO_ICMP IPProto = 1
199 IP_API_PROTO_IGMP IPProto = 2
200 IP_API_PROTO_TCP IPProto = 6
201 IP_API_PROTO_UDP IPProto = 17
202 IP_API_PROTO_GRE IPProto = 47
203 IP_API_PROTO_ESP IPProto = 50
204 IP_API_PROTO_AH IPProto = 51
205 IP_API_PROTO_ICMP6 IPProto = 58
206 IP_API_PROTO_EIGRP IPProto = 88
207 IP_API_PROTO_OSPF IPProto = 89
208 IP_API_PROTO_SCTP IPProto = 132
209 IP_API_PROTO_RESERVED IPProto = 255
213 IPProto_name = map[uint8]string{
214 0: "IP_API_PROTO_HOPOPT",
215 1: "IP_API_PROTO_ICMP",
216 2: "IP_API_PROTO_IGMP",
217 6: "IP_API_PROTO_TCP",
218 17: "IP_API_PROTO_UDP",
219 47: "IP_API_PROTO_GRE",
220 50: "IP_API_PROTO_ESP",
221 51: "IP_API_PROTO_AH",
222 58: "IP_API_PROTO_ICMP6",
223 88: "IP_API_PROTO_EIGRP",
224 89: "IP_API_PROTO_OSPF",
225 132: "IP_API_PROTO_SCTP",
226 255: "IP_API_PROTO_RESERVED",
228 IPProto_value = map[string]uint8{
229 "IP_API_PROTO_HOPOPT": 0,
230 "IP_API_PROTO_ICMP": 1,
231 "IP_API_PROTO_IGMP": 2,
232 "IP_API_PROTO_TCP": 6,
233 "IP_API_PROTO_UDP": 17,
234 "IP_API_PROTO_GRE": 47,
235 "IP_API_PROTO_ESP": 50,
236 "IP_API_PROTO_AH": 51,
237 "IP_API_PROTO_ICMP6": 58,
238 "IP_API_PROTO_EIGRP": 88,
239 "IP_API_PROTO_OSPF": 89,
240 "IP_API_PROTO_SCTP": 132,
241 "IP_API_PROTO_RESERVED": 255,
245 func (x IPProto) String() string {
246 s, ok := IPProto_name[uint8(x)]
250 return "IPProto(" + strconv.Itoa(int(x)) + ")"
253 // AddressWithPrefix represents VPP binary API alias 'address_with_prefix'.
254 type AddressWithPrefix Prefix
256 // IP4Address represents VPP binary API alias 'ip4_address'.
257 type IP4Address [4]uint8
259 // IP4AddressWithPrefix represents VPP binary API alias 'ip4_address_with_prefix'.
260 type IP4AddressWithPrefix IP4Prefix
262 // IP6Address represents VPP binary API alias 'ip6_address'.
263 type IP6Address [16]uint8
265 // IP6AddressWithPrefix represents VPP binary API alias 'ip6_address_with_prefix'.
266 type IP6AddressWithPrefix IP6Prefix
268 // Address represents VPP binary API type 'address'.
269 type Address struct {
270 Af AddressFamily `binapi:"address_family,name=af" json:"af,omitempty"`
271 Un AddressUnion `binapi:"address_union,name=un" json:"un,omitempty"`
274 func (*Address) GetTypeName() string { return "address" }
276 func ParseAddress(ip string) (Address, error) {
278 netIP := net.ParseIP(ip)
280 return address, fmt.Errorf("invalid address: %s", ip)
282 if ip4 := netIP.To4(); ip4 == nil {
283 address.Af = ADDRESS_IP6
284 var ip6addr IP6Address
285 copy(ip6addr[:], netIP.To16())
286 address.Un.SetIP6(ip6addr)
288 address.Af = ADDRESS_IP4
289 var ip4addr IP4Address
290 copy(ip4addr[:], netIP.To4())
291 address.Un.SetIP4(ip4addr)
296 func (a *Address) ToString() string {
298 if a.Af == ADDRESS_IP6 {
299 ip6Address := a.Un.GetIP6()
300 ip = net.IP(ip6Address[:]).To16().String()
302 ip4Address := a.Un.GetIP4()
303 ip = net.IP(ip4Address[:]).To4().String()
308 // IP4Prefix represents VPP binary API type 'ip4_prefix'.
309 type IP4Prefix struct {
310 Address IP4Address `binapi:"ip4_address,name=address" json:"address,omitempty"`
311 Len uint8 `binapi:"u8,name=len" json:"len,omitempty"`
314 func (*IP4Prefix) GetTypeName() string { return "ip4_prefix" }
316 // IP6Prefix represents VPP binary API type 'ip6_prefix'.
317 type IP6Prefix struct {
318 Address IP6Address `binapi:"ip6_address,name=address" json:"address,omitempty"`
319 Len uint8 `binapi:"u8,name=len" json:"len,omitempty"`
322 func (*IP6Prefix) GetTypeName() string { return "ip6_prefix" }
324 // Mprefix represents VPP binary API type 'mprefix'.
325 type Mprefix struct {
326 Af AddressFamily `binapi:"address_family,name=af" json:"af,omitempty"`
327 GrpAddressLength uint16 `binapi:"u16,name=grp_address_length" json:"grp_address_length,omitempty"`
328 GrpAddress AddressUnion `binapi:"address_union,name=grp_address" json:"grp_address,omitempty"`
329 SrcAddress AddressUnion `binapi:"address_union,name=src_address" json:"src_address,omitempty"`
332 func (*Mprefix) GetTypeName() string { return "mprefix" }
334 // Prefix represents VPP binary API type 'prefix'.
336 Address Address `binapi:"address,name=address" json:"address,omitempty"`
337 Len uint8 `binapi:"u8,name=len" json:"len,omitempty"`
340 func (*Prefix) GetTypeName() string { return "prefix" }
342 func ParsePrefix(ip string) (prefix Prefix, err error) {
343 hasPrefix := strings.Contains(ip, "/")
345 netIP, network, err := net.ParseCIDR(ip)
347 return Prefix{}, fmt.Errorf("invalid IP %s: %v", ip, err)
349 maskSize, _ := network.Mask.Size()
350 prefix.Len = byte(maskSize)
351 prefix.Address, err = ParseAddress(netIP.String())
353 return Prefix{}, fmt.Errorf("invalid IP %s: %v", ip, err)
356 netIP := net.ParseIP(ip)
357 defaultMaskSize, _ := net.CIDRMask(32, 32).Size()
358 if netIP.To4() == nil {
359 defaultMaskSize, _ = net.CIDRMask(128, 128).Size()
361 prefix.Len = byte(defaultMaskSize)
362 prefix.Address, err = ParseAddress(netIP.String())
364 return Prefix{}, fmt.Errorf("invalid IP %s: %v", ip, err)
370 func (p *Prefix) ToString() string {
371 ip := p.Address.ToString()
372 return ip + "/" + strconv.Itoa(int(p.Len))
375 // PrefixMatcher represents VPP binary API type 'prefix_matcher'.
376 type PrefixMatcher struct {
377 Le uint8 `binapi:"u8,name=le" json:"le,omitempty"`
378 Ge uint8 `binapi:"u8,name=ge" json:"ge,omitempty"`
381 func (*PrefixMatcher) GetTypeName() string { return "prefix_matcher" }
383 // AddressUnion represents VPP binary API union 'address_union'.
384 type AddressUnion struct {
385 XXX_UnionData [16]byte
388 func (*AddressUnion) GetTypeName() string { return "address_union" }
390 func AddressUnionIP4(a IP4Address) (u AddressUnion) {
394 func (u *AddressUnion) SetIP4(a IP4Address) {
395 var b = new(bytes.Buffer)
396 if err := struc.Pack(b, &a); err != nil {
399 copy(u.XXX_UnionData[:], b.Bytes())
401 func (u *AddressUnion) GetIP4() (a IP4Address) {
402 var b = bytes.NewReader(u.XXX_UnionData[:])
407 func AddressUnionIP6(a IP6Address) (u AddressUnion) {
411 func (u *AddressUnion) SetIP6(a IP6Address) {
412 var b = new(bytes.Buffer)
413 if err := struc.Pack(b, &a); err != nil {
416 copy(u.XXX_UnionData[:], b.Bytes())
418 func (u *AddressUnion) GetIP6() (a IP6Address) {
419 var b = bytes.NewReader(u.XXX_UnionData[:])
424 // Reference imports to suppress errors if they are not otherwise used.
425 var _ = api.RegisterMessage
426 var _ = codec.DecodeString
427 var _ = bytes.NewBuffer
428 var _ = context.Background
431 var _ = strings.Contains
433 var _ = binary.BigEndian
434 var _ = math.Float32bits