Update generated binapi to v22.02 & makefile changes
[govpp.git] / internal / testbinapi / binapi2001 / pppoe / pppoe.ba.go
1 // Code generated by GoVPP's binapi-generator. DO NOT EDIT.
2 // versions:
3 //  binapi-generator: v0.5.0-dev
4 //  VPP:              20.01
5 // source: .vppapi/plugins/pppoe.api.json
6
7 // Package pppoe contains generated bindings for API file pppoe.api.
8 //
9 // Contents:
10 //   7 aliases
11 //  10 enums
12 //   6 structs
13 //   1 union
14 //   4 messages
15 //
16 package pppoe
17
18 import (
19         "fmt"
20         "net"
21         "strconv"
22         "strings"
23
24         api "git.fd.io/govpp.git/api"
25         codec "git.fd.io/govpp.git/codec"
26 )
27
28 // This is a compile-time assertion to ensure that this generated file
29 // is compatible with the GoVPP api package it is being compiled against.
30 // A compilation error at this line likely means your copy of the
31 // GoVPP api package needs to be updated.
32 const _ = api.GoVppAPIPackageIsVersion2
33
34 const (
35         APIFile    = "pppoe"
36         APIVersion = "2.0.0"
37         VersionCrc = 0xb83e4d5f
38 )
39
40 // AddressFamily defines enum 'address_family'.
41 type AddressFamily uint32
42
43 const (
44         ADDRESS_IP4 AddressFamily = 0
45         ADDRESS_IP6 AddressFamily = 1
46 )
47
48 var (
49         AddressFamily_name = map[uint32]string{
50                 0: "ADDRESS_IP4",
51                 1: "ADDRESS_IP6",
52         }
53         AddressFamily_value = map[string]uint32{
54                 "ADDRESS_IP4": 0,
55                 "ADDRESS_IP6": 1,
56         }
57 )
58
59 func (x AddressFamily) String() string {
60         s, ok := AddressFamily_name[uint32(x)]
61         if ok {
62                 return s
63         }
64         return "AddressFamily(" + strconv.Itoa(int(x)) + ")"
65 }
66
67 // IfStatusFlags defines enum 'if_status_flags'.
68 type IfStatusFlags uint32
69
70 const (
71         IF_STATUS_API_FLAG_ADMIN_UP IfStatusFlags = 1
72         IF_STATUS_API_FLAG_LINK_UP  IfStatusFlags = 2
73 )
74
75 var (
76         IfStatusFlags_name = map[uint32]string{
77                 1: "IF_STATUS_API_FLAG_ADMIN_UP",
78                 2: "IF_STATUS_API_FLAG_LINK_UP",
79         }
80         IfStatusFlags_value = map[string]uint32{
81                 "IF_STATUS_API_FLAG_ADMIN_UP": 1,
82                 "IF_STATUS_API_FLAG_LINK_UP":  2,
83         }
84 )
85
86 func (x IfStatusFlags) String() string {
87         s, ok := IfStatusFlags_name[uint32(x)]
88         if ok {
89                 return s
90         }
91         str := func(n uint32) string {
92                 s, ok := IfStatusFlags_name[uint32(n)]
93                 if ok {
94                         return s
95                 }
96                 return "IfStatusFlags(" + strconv.Itoa(int(n)) + ")"
97         }
98         for i := uint32(0); i <= 32; i++ {
99                 val := uint32(x)
100                 if val&(1<<i) != 0 {
101                         if s != "" {
102                                 s += "|"
103                         }
104                         s += str(1 << i)
105                 }
106         }
107         if s == "" {
108                 return str(uint32(x))
109         }
110         return s
111 }
112
113 // IfType defines enum 'if_type'.
114 type IfType uint32
115
116 const (
117         IF_API_TYPE_HARDWARE IfType = 1
118         IF_API_TYPE_SUB      IfType = 2
119         IF_API_TYPE_P2P      IfType = 3
120         IF_API_TYPE_PIPE     IfType = 4
121 )
122
123 var (
124         IfType_name = map[uint32]string{
125                 1: "IF_API_TYPE_HARDWARE",
126                 2: "IF_API_TYPE_SUB",
127                 3: "IF_API_TYPE_P2P",
128                 4: "IF_API_TYPE_PIPE",
129         }
130         IfType_value = map[string]uint32{
131                 "IF_API_TYPE_HARDWARE": 1,
132                 "IF_API_TYPE_SUB":      2,
133                 "IF_API_TYPE_P2P":      3,
134                 "IF_API_TYPE_PIPE":     4,
135         }
136 )
137
138 func (x IfType) String() string {
139         s, ok := IfType_name[uint32(x)]
140         if ok {
141                 return s
142         }
143         return "IfType(" + strconv.Itoa(int(x)) + ")"
144 }
145
146 // IPDscp defines enum 'ip_dscp'.
147 type IPDscp uint8
148
149 const (
150         IP_API_DSCP_CS0  IPDscp = 0
151         IP_API_DSCP_CS1  IPDscp = 8
152         IP_API_DSCP_AF11 IPDscp = 10
153         IP_API_DSCP_AF12 IPDscp = 12
154         IP_API_DSCP_AF13 IPDscp = 14
155         IP_API_DSCP_CS2  IPDscp = 16
156         IP_API_DSCP_AF21 IPDscp = 18
157         IP_API_DSCP_AF22 IPDscp = 20
158         IP_API_DSCP_AF23 IPDscp = 22
159         IP_API_DSCP_CS3  IPDscp = 24
160         IP_API_DSCP_AF31 IPDscp = 26
161         IP_API_DSCP_AF32 IPDscp = 28
162         IP_API_DSCP_AF33 IPDscp = 30
163         IP_API_DSCP_CS4  IPDscp = 32
164         IP_API_DSCP_AF41 IPDscp = 34
165         IP_API_DSCP_AF42 IPDscp = 36
166         IP_API_DSCP_AF43 IPDscp = 38
167         IP_API_DSCP_CS5  IPDscp = 40
168         IP_API_DSCP_EF   IPDscp = 46
169         IP_API_DSCP_CS6  IPDscp = 48
170         IP_API_DSCP_CS7  IPDscp = 50
171 )
172
173 var (
174         IPDscp_name = map[uint8]string{
175                 0:  "IP_API_DSCP_CS0",
176                 8:  "IP_API_DSCP_CS1",
177                 10: "IP_API_DSCP_AF11",
178                 12: "IP_API_DSCP_AF12",
179                 14: "IP_API_DSCP_AF13",
180                 16: "IP_API_DSCP_CS2",
181                 18: "IP_API_DSCP_AF21",
182                 20: "IP_API_DSCP_AF22",
183                 22: "IP_API_DSCP_AF23",
184                 24: "IP_API_DSCP_CS3",
185                 26: "IP_API_DSCP_AF31",
186                 28: "IP_API_DSCP_AF32",
187                 30: "IP_API_DSCP_AF33",
188                 32: "IP_API_DSCP_CS4",
189                 34: "IP_API_DSCP_AF41",
190                 36: "IP_API_DSCP_AF42",
191                 38: "IP_API_DSCP_AF43",
192                 40: "IP_API_DSCP_CS5",
193                 46: "IP_API_DSCP_EF",
194                 48: "IP_API_DSCP_CS6",
195                 50: "IP_API_DSCP_CS7",
196         }
197         IPDscp_value = map[string]uint8{
198                 "IP_API_DSCP_CS0":  0,
199                 "IP_API_DSCP_CS1":  8,
200                 "IP_API_DSCP_AF11": 10,
201                 "IP_API_DSCP_AF12": 12,
202                 "IP_API_DSCP_AF13": 14,
203                 "IP_API_DSCP_CS2":  16,
204                 "IP_API_DSCP_AF21": 18,
205                 "IP_API_DSCP_AF22": 20,
206                 "IP_API_DSCP_AF23": 22,
207                 "IP_API_DSCP_CS3":  24,
208                 "IP_API_DSCP_AF31": 26,
209                 "IP_API_DSCP_AF32": 28,
210                 "IP_API_DSCP_AF33": 30,
211                 "IP_API_DSCP_CS4":  32,
212                 "IP_API_DSCP_AF41": 34,
213                 "IP_API_DSCP_AF42": 36,
214                 "IP_API_DSCP_AF43": 38,
215                 "IP_API_DSCP_CS5":  40,
216                 "IP_API_DSCP_EF":   46,
217                 "IP_API_DSCP_CS6":  48,
218                 "IP_API_DSCP_CS7":  50,
219         }
220 )
221
222 func (x IPDscp) String() string {
223         s, ok := IPDscp_name[uint8(x)]
224         if ok {
225                 return s
226         }
227         return "IPDscp(" + strconv.Itoa(int(x)) + ")"
228 }
229
230 // IPEcn defines enum 'ip_ecn'.
231 type IPEcn uint8
232
233 const (
234         IP_API_ECN_NONE IPEcn = 0
235         IP_API_ECN_ECT0 IPEcn = 1
236         IP_API_ECN_ECT1 IPEcn = 2
237         IP_API_ECN_CE   IPEcn = 3
238 )
239
240 var (
241         IPEcn_name = map[uint8]string{
242                 0: "IP_API_ECN_NONE",
243                 1: "IP_API_ECN_ECT0",
244                 2: "IP_API_ECN_ECT1",
245                 3: "IP_API_ECN_CE",
246         }
247         IPEcn_value = map[string]uint8{
248                 "IP_API_ECN_NONE": 0,
249                 "IP_API_ECN_ECT0": 1,
250                 "IP_API_ECN_ECT1": 2,
251                 "IP_API_ECN_CE":   3,
252         }
253 )
254
255 func (x IPEcn) String() string {
256         s, ok := IPEcn_name[uint8(x)]
257         if ok {
258                 return s
259         }
260         return "IPEcn(" + strconv.Itoa(int(x)) + ")"
261 }
262
263 // IPProto defines enum 'ip_proto'.
264 type IPProto uint32
265
266 const (
267         IP_API_PROTO_HOPOPT   IPProto = 0
268         IP_API_PROTO_ICMP     IPProto = 1
269         IP_API_PROTO_IGMP     IPProto = 2
270         IP_API_PROTO_TCP      IPProto = 6
271         IP_API_PROTO_UDP      IPProto = 17
272         IP_API_PROTO_GRE      IPProto = 47
273         IP_API_PROTO_AH       IPProto = 50
274         IP_API_PROTO_ESP      IPProto = 51
275         IP_API_PROTO_EIGRP    IPProto = 88
276         IP_API_PROTO_OSPF     IPProto = 89
277         IP_API_PROTO_SCTP     IPProto = 132
278         IP_API_PROTO_RESERVED IPProto = 255
279 )
280
281 var (
282         IPProto_name = map[uint32]string{
283                 0:   "IP_API_PROTO_HOPOPT",
284                 1:   "IP_API_PROTO_ICMP",
285                 2:   "IP_API_PROTO_IGMP",
286                 6:   "IP_API_PROTO_TCP",
287                 17:  "IP_API_PROTO_UDP",
288                 47:  "IP_API_PROTO_GRE",
289                 50:  "IP_API_PROTO_AH",
290                 51:  "IP_API_PROTO_ESP",
291                 88:  "IP_API_PROTO_EIGRP",
292                 89:  "IP_API_PROTO_OSPF",
293                 132: "IP_API_PROTO_SCTP",
294                 255: "IP_API_PROTO_RESERVED",
295         }
296         IPProto_value = map[string]uint32{
297                 "IP_API_PROTO_HOPOPT":   0,
298                 "IP_API_PROTO_ICMP":     1,
299                 "IP_API_PROTO_IGMP":     2,
300                 "IP_API_PROTO_TCP":      6,
301                 "IP_API_PROTO_UDP":      17,
302                 "IP_API_PROTO_GRE":      47,
303                 "IP_API_PROTO_AH":       50,
304                 "IP_API_PROTO_ESP":      51,
305                 "IP_API_PROTO_EIGRP":    88,
306                 "IP_API_PROTO_OSPF":     89,
307                 "IP_API_PROTO_SCTP":     132,
308                 "IP_API_PROTO_RESERVED": 255,
309         }
310 )
311
312 func (x IPProto) String() string {
313         s, ok := IPProto_name[uint32(x)]
314         if ok {
315                 return s
316         }
317         return "IPProto(" + strconv.Itoa(int(x)) + ")"
318 }
319
320 // LinkDuplex defines enum 'link_duplex'.
321 type LinkDuplex uint32
322
323 const (
324         LINK_DUPLEX_API_UNKNOWN LinkDuplex = 0
325         LINK_DUPLEX_API_HALF    LinkDuplex = 1
326         LINK_DUPLEX_API_FULL    LinkDuplex = 2
327 )
328
329 var (
330         LinkDuplex_name = map[uint32]string{
331                 0: "LINK_DUPLEX_API_UNKNOWN",
332                 1: "LINK_DUPLEX_API_HALF",
333                 2: "LINK_DUPLEX_API_FULL",
334         }
335         LinkDuplex_value = map[string]uint32{
336                 "LINK_DUPLEX_API_UNKNOWN": 0,
337                 "LINK_DUPLEX_API_HALF":    1,
338                 "LINK_DUPLEX_API_FULL":    2,
339         }
340 )
341
342 func (x LinkDuplex) String() string {
343         s, ok := LinkDuplex_name[uint32(x)]
344         if ok {
345                 return s
346         }
347         return "LinkDuplex(" + strconv.Itoa(int(x)) + ")"
348 }
349
350 // MtuProto defines enum 'mtu_proto'.
351 type MtuProto uint32
352
353 const (
354         MTU_PROTO_API_L3   MtuProto = 1
355         MTU_PROTO_API_IP4  MtuProto = 2
356         MTU_PROTO_API_IP6  MtuProto = 3
357         MTU_PROTO_API_MPLS MtuProto = 4
358         MTU_PROTO_API_N    MtuProto = 5
359 )
360
361 var (
362         MtuProto_name = map[uint32]string{
363                 1: "MTU_PROTO_API_L3",
364                 2: "MTU_PROTO_API_IP4",
365                 3: "MTU_PROTO_API_IP6",
366                 4: "MTU_PROTO_API_MPLS",
367                 5: "MTU_PROTO_API_N",
368         }
369         MtuProto_value = map[string]uint32{
370                 "MTU_PROTO_API_L3":   1,
371                 "MTU_PROTO_API_IP4":  2,
372                 "MTU_PROTO_API_IP6":  3,
373                 "MTU_PROTO_API_MPLS": 4,
374                 "MTU_PROTO_API_N":    5,
375         }
376 )
377
378 func (x MtuProto) String() string {
379         s, ok := MtuProto_name[uint32(x)]
380         if ok {
381                 return s
382         }
383         return "MtuProto(" + strconv.Itoa(int(x)) + ")"
384 }
385
386 // RxMode defines enum 'rx_mode'.
387 type RxMode uint32
388
389 const (
390         RX_MODE_API_UNKNOWN   RxMode = 0
391         RX_MODE_API_POLLING   RxMode = 1
392         RX_MODE_API_INTERRUPT RxMode = 2
393         RX_MODE_API_ADAPTIVE  RxMode = 3
394         RX_MODE_API_DEFAULT   RxMode = 4
395 )
396
397 var (
398         RxMode_name = map[uint32]string{
399                 0: "RX_MODE_API_UNKNOWN",
400                 1: "RX_MODE_API_POLLING",
401                 2: "RX_MODE_API_INTERRUPT",
402                 3: "RX_MODE_API_ADAPTIVE",
403                 4: "RX_MODE_API_DEFAULT",
404         }
405         RxMode_value = map[string]uint32{
406                 "RX_MODE_API_UNKNOWN":   0,
407                 "RX_MODE_API_POLLING":   1,
408                 "RX_MODE_API_INTERRUPT": 2,
409                 "RX_MODE_API_ADAPTIVE":  3,
410                 "RX_MODE_API_DEFAULT":   4,
411         }
412 )
413
414 func (x RxMode) String() string {
415         s, ok := RxMode_name[uint32(x)]
416         if ok {
417                 return s
418         }
419         return "RxMode(" + strconv.Itoa(int(x)) + ")"
420 }
421
422 // SubIfFlags defines enum 'sub_if_flags'.
423 type SubIfFlags uint32
424
425 const (
426         SUB_IF_API_FLAG_NO_TAGS           SubIfFlags = 1
427         SUB_IF_API_FLAG_ONE_TAG           SubIfFlags = 2
428         SUB_IF_API_FLAG_TWO_TAGS          SubIfFlags = 4
429         SUB_IF_API_FLAG_DOT1AD            SubIfFlags = 8
430         SUB_IF_API_FLAG_EXACT_MATCH       SubIfFlags = 16
431         SUB_IF_API_FLAG_DEFAULT           SubIfFlags = 32
432         SUB_IF_API_FLAG_OUTER_VLAN_ID_ANY SubIfFlags = 64
433         SUB_IF_API_FLAG_INNER_VLAN_ID_ANY SubIfFlags = 128
434         SUB_IF_API_FLAG_MASK_VNET         SubIfFlags = 254
435         SUB_IF_API_FLAG_DOT1AH            SubIfFlags = 256
436 )
437
438 var (
439         SubIfFlags_name = map[uint32]string{
440                 1:   "SUB_IF_API_FLAG_NO_TAGS",
441                 2:   "SUB_IF_API_FLAG_ONE_TAG",
442                 4:   "SUB_IF_API_FLAG_TWO_TAGS",
443                 8:   "SUB_IF_API_FLAG_DOT1AD",
444                 16:  "SUB_IF_API_FLAG_EXACT_MATCH",
445                 32:  "SUB_IF_API_FLAG_DEFAULT",
446                 64:  "SUB_IF_API_FLAG_OUTER_VLAN_ID_ANY",
447                 128: "SUB_IF_API_FLAG_INNER_VLAN_ID_ANY",
448                 254: "SUB_IF_API_FLAG_MASK_VNET",
449                 256: "SUB_IF_API_FLAG_DOT1AH",
450         }
451         SubIfFlags_value = map[string]uint32{
452                 "SUB_IF_API_FLAG_NO_TAGS":           1,
453                 "SUB_IF_API_FLAG_ONE_TAG":           2,
454                 "SUB_IF_API_FLAG_TWO_TAGS":          4,
455                 "SUB_IF_API_FLAG_DOT1AD":            8,
456                 "SUB_IF_API_FLAG_EXACT_MATCH":       16,
457                 "SUB_IF_API_FLAG_DEFAULT":           32,
458                 "SUB_IF_API_FLAG_OUTER_VLAN_ID_ANY": 64,
459                 "SUB_IF_API_FLAG_INNER_VLAN_ID_ANY": 128,
460                 "SUB_IF_API_FLAG_MASK_VNET":         254,
461                 "SUB_IF_API_FLAG_DOT1AH":            256,
462         }
463 )
464
465 func (x SubIfFlags) String() string {
466         s, ok := SubIfFlags_name[uint32(x)]
467         if ok {
468                 return s
469         }
470         str := func(n uint32) string {
471                 s, ok := SubIfFlags_name[uint32(n)]
472                 if ok {
473                         return s
474                 }
475                 return "SubIfFlags(" + strconv.Itoa(int(n)) + ")"
476         }
477         for i := uint32(0); i <= 32; i++ {
478                 val := uint32(x)
479                 if val&(1<<i) != 0 {
480                         if s != "" {
481                                 s += "|"
482                         }
483                         s += str(1 << i)
484                 }
485         }
486         if s == "" {
487                 return str(uint32(x))
488         }
489         return s
490 }
491
492 // AddressWithPrefix defines alias 'address_with_prefix'.
493 type AddressWithPrefix Prefix
494
495 func ParseAddressWithPrefix(s string) (AddressWithPrefix, error) {
496         prefix, err := ParsePrefix(s)
497         if err != nil {
498                 return AddressWithPrefix{}, err
499         }
500         return AddressWithPrefix(prefix), nil
501 }
502
503 func (x AddressWithPrefix) String() string {
504         return Prefix(x).String()
505 }
506
507 func (x *AddressWithPrefix) MarshalText() ([]byte, error) {
508         return []byte(x.String()), nil
509 }
510
511 func (x *AddressWithPrefix) UnmarshalText(text []byte) error {
512         prefix, err := ParseAddressWithPrefix(string(text))
513         if err != nil {
514                 return err
515         }
516         *x = prefix
517         return nil
518 }
519
520 // InterfaceIndex defines alias 'interface_index'.
521 type InterfaceIndex uint32
522
523 // IP4Address defines alias 'ip4_address'.
524 type IP4Address [4]uint8
525
526 func ParseIP4Address(s string) (IP4Address, error) {
527         ip := net.ParseIP(s).To4()
528         if ip == nil {
529                 return IP4Address{}, fmt.Errorf("invalid IP address: %s", s)
530         }
531         var ipaddr IP4Address
532         copy(ipaddr[:], ip.To4())
533         return ipaddr, nil
534 }
535
536 func (x IP4Address) ToIP() net.IP {
537         return net.IP(x[:]).To4()
538 }
539
540 func (x IP4Address) String() string {
541         return x.ToIP().String()
542 }
543
544 func (x *IP4Address) MarshalText() ([]byte, error) {
545         return []byte(x.String()), nil
546 }
547
548 func (x *IP4Address) UnmarshalText(text []byte) error {
549         ipaddr, err := ParseIP4Address(string(text))
550         if err != nil {
551                 return err
552         }
553         *x = ipaddr
554         return nil
555 }
556
557 // IP4AddressWithPrefix defines alias 'ip4_address_with_prefix'.
558 type IP4AddressWithPrefix IP4Prefix
559
560 // IP6Address defines alias 'ip6_address'.
561 type IP6Address [16]uint8
562
563 func ParseIP6Address(s string) (IP6Address, error) {
564         ip := net.ParseIP(s).To16()
565         if ip == nil {
566                 return IP6Address{}, fmt.Errorf("invalid IP address: %s", s)
567         }
568         var ipaddr IP6Address
569         copy(ipaddr[:], ip.To16())
570         return ipaddr, nil
571 }
572
573 func (x IP6Address) ToIP() net.IP {
574         return net.IP(x[:]).To16()
575 }
576
577 func (x IP6Address) String() string {
578         return x.ToIP().String()
579 }
580
581 func (x *IP6Address) MarshalText() ([]byte, error) {
582         return []byte(x.String()), nil
583 }
584
585 func (x *IP6Address) UnmarshalText(text []byte) error {
586         ipaddr, err := ParseIP6Address(string(text))
587         if err != nil {
588                 return err
589         }
590         *x = ipaddr
591         return nil
592 }
593
594 // IP6AddressWithPrefix defines alias 'ip6_address_with_prefix'.
595 type IP6AddressWithPrefix IP6Prefix
596
597 // MacAddress defines alias 'mac_address'.
598 type MacAddress [6]uint8
599
600 func ParseMacAddress(s string) (MacAddress, error) {
601         var macaddr MacAddress
602         mac, err := net.ParseMAC(s)
603         if err != nil {
604                 return macaddr, err
605         }
606         copy(macaddr[:], mac[:])
607         return macaddr, nil
608 }
609
610 func (x MacAddress) ToMAC() net.HardwareAddr {
611         return net.HardwareAddr(x[:])
612 }
613
614 func (x MacAddress) String() string {
615         return x.ToMAC().String()
616 }
617
618 func (x *MacAddress) MarshalText() ([]byte, error) {
619         return []byte(x.String()), nil
620 }
621
622 func (x *MacAddress) UnmarshalText(text []byte) error {
623         mac, err := ParseMacAddress(string(text))
624         if err != nil {
625                 return err
626         }
627         *x = mac
628         return nil
629 }
630
631 // Address defines type 'address'.
632 type Address struct {
633         Af AddressFamily `binapi:"address_family,name=af" json:"af,omitempty"`
634         Un AddressUnion  `binapi:"address_union,name=un" json:"un,omitempty"`
635 }
636
637 func ParseAddress(s string) (Address, error) {
638         ip := net.ParseIP(s)
639         if ip == nil {
640                 return Address{}, fmt.Errorf("invalid address: %s", s)
641         }
642         return AddressFromIP(ip), nil
643 }
644
645 func AddressFromIP(ip net.IP) Address {
646         var addr Address
647         if ip.To4() == nil {
648                 addr.Af = ADDRESS_IP6
649                 var ip6 IP6Address
650                 copy(ip6[:], ip.To16())
651                 addr.Un.SetIP6(ip6)
652         } else {
653                 addr.Af = ADDRESS_IP4
654                 var ip4 IP4Address
655                 copy(ip4[:], ip.To4())
656                 addr.Un.SetIP4(ip4)
657         }
658         return addr
659 }
660
661 func (x Address) ToIP() net.IP {
662         if x.Af == ADDRESS_IP6 {
663                 ip6 := x.Un.GetIP6()
664                 return net.IP(ip6[:]).To16()
665         } else {
666                 ip4 := x.Un.GetIP4()
667                 return net.IP(ip4[:]).To4()
668         }
669 }
670
671 func (x Address) String() string {
672         return x.ToIP().String()
673 }
674
675 func (x *Address) MarshalText() ([]byte, error) {
676         return []byte(x.String()), nil
677 }
678
679 func (x *Address) UnmarshalText(text []byte) error {
680         addr, err := ParseAddress(string(text))
681         if err != nil {
682                 return err
683         }
684         *x = addr
685         return nil
686 }
687
688 // IP4Prefix defines type 'ip4_prefix'.
689 type IP4Prefix struct {
690         Address IP4Address `binapi:"ip4_address,name=address" json:"address,omitempty"`
691         Len     uint8      `binapi:"u8,name=len" json:"len,omitempty"`
692 }
693
694 func ParseIP4Prefix(s string) (prefix IP4Prefix, err error) {
695         hasPrefix := strings.Contains(s, "/")
696         if hasPrefix {
697                 ip, network, err := net.ParseCIDR(s)
698                 if err != nil {
699                         return IP4Prefix{}, fmt.Errorf("invalid IP %s: %s", s, err)
700                 }
701                 maskSize, _ := network.Mask.Size()
702                 prefix.Len = byte(maskSize)
703                 prefix.Address, err = ParseIP4Address(ip.String())
704                 if err != nil {
705                         return IP4Prefix{}, fmt.Errorf("invalid IP %s: %s", s, err)
706                 }
707         } else {
708                 ip := net.ParseIP(s)
709                 defaultMaskSize, _ := net.CIDRMask(32, 32).Size()
710                 if ip.To4() == nil {
711                         defaultMaskSize, _ = net.CIDRMask(128, 128).Size()
712                 }
713                 prefix.Len = byte(defaultMaskSize)
714                 prefix.Address, err = ParseIP4Address(ip.String())
715                 if err != nil {
716                         return IP4Prefix{}, fmt.Errorf("invalid IP %s: %s", s, err)
717                 }
718         }
719         return prefix, nil
720 }
721
722 func (x IP4Prefix) ToIPNet() *net.IPNet {
723         mask := net.CIDRMask(int(x.Len), 32)
724         ipnet := &net.IPNet{IP: x.Address.ToIP(), Mask: mask}
725         return ipnet
726 }
727
728 func (x IP4Prefix) String() string {
729         ip := x.Address.String()
730         return ip + "/" + strconv.Itoa(int(x.Len))
731 }
732
733 func (x *IP4Prefix) MarshalText() ([]byte, error) {
734         return []byte(x.String()), nil
735 }
736
737 func (x *IP4Prefix) UnmarshalText(text []byte) error {
738         prefix, err := ParseIP4Prefix(string(text))
739         if err != nil {
740                 return err
741         }
742         *x = prefix
743         return nil
744 }
745
746 // IP6Prefix defines type 'ip6_prefix'.
747 type IP6Prefix struct {
748         Address IP6Address `binapi:"ip6_address,name=address" json:"address,omitempty"`
749         Len     uint8      `binapi:"u8,name=len" json:"len,omitempty"`
750 }
751
752 func ParseIP6Prefix(s string) (prefix IP6Prefix, err error) {
753         hasPrefix := strings.Contains(s, "/")
754         if hasPrefix {
755                 ip, network, err := net.ParseCIDR(s)
756                 if err != nil {
757                         return IP6Prefix{}, fmt.Errorf("invalid IP %s: %s", s, err)
758                 }
759                 maskSize, _ := network.Mask.Size()
760                 prefix.Len = byte(maskSize)
761                 prefix.Address, err = ParseIP6Address(ip.String())
762                 if err != nil {
763                         return IP6Prefix{}, fmt.Errorf("invalid IP %s: %s", s, err)
764                 }
765         } else {
766                 ip := net.ParseIP(s)
767                 defaultMaskSize, _ := net.CIDRMask(32, 32).Size()
768                 if ip.To4() == nil {
769                         defaultMaskSize, _ = net.CIDRMask(128, 128).Size()
770                 }
771                 prefix.Len = byte(defaultMaskSize)
772                 prefix.Address, err = ParseIP6Address(ip.String())
773                 if err != nil {
774                         return IP6Prefix{}, fmt.Errorf("invalid IP %s: %s", s, err)
775                 }
776         }
777         return prefix, nil
778 }
779
780 func (x IP6Prefix) ToIPNet() *net.IPNet {
781         mask := net.CIDRMask(int(x.Len), 128)
782         ipnet := &net.IPNet{IP: x.Address.ToIP(), Mask: mask}
783         return ipnet
784 }
785
786 func (x IP6Prefix) String() string {
787         ip := x.Address.String()
788         return ip + "/" + strconv.Itoa(int(x.Len))
789 }
790
791 func (x *IP6Prefix) MarshalText() ([]byte, error) {
792         return []byte(x.String()), nil
793 }
794
795 func (x *IP6Prefix) UnmarshalText(text []byte) error {
796         prefix, err := ParseIP6Prefix(string(text))
797         if err != nil {
798                 return err
799         }
800         *x = prefix
801         return nil
802 }
803
804 // Mprefix defines type 'mprefix'.
805 type Mprefix struct {
806         Af               AddressFamily `binapi:"address_family,name=af" json:"af,omitempty"`
807         GrpAddressLength uint16        `binapi:"u16,name=grp_address_length" json:"grp_address_length,omitempty"`
808         GrpAddress       AddressUnion  `binapi:"address_union,name=grp_address" json:"grp_address,omitempty"`
809         SrcAddress       AddressUnion  `binapi:"address_union,name=src_address" json:"src_address,omitempty"`
810 }
811
812 // Prefix defines type 'prefix'.
813 type Prefix struct {
814         Address Address `binapi:"address,name=address" json:"address,omitempty"`
815         Len     uint8   `binapi:"u8,name=len" json:"len,omitempty"`
816 }
817
818 func ParsePrefix(ip string) (prefix Prefix, err error) {
819         hasPrefix := strings.Contains(ip, "/")
820         if hasPrefix {
821                 netIP, network, err := net.ParseCIDR(ip)
822                 if err != nil {
823                         return Prefix{}, fmt.Errorf("invalid IP %s: %s", ip, err)
824                 }
825                 maskSize, _ := network.Mask.Size()
826                 prefix.Len = byte(maskSize)
827                 prefix.Address, err = ParseAddress(netIP.String())
828                 if err != nil {
829                         return Prefix{}, fmt.Errorf("invalid IP %s: %s", ip, err)
830                 }
831         } else {
832                 netIP := net.ParseIP(ip)
833                 defaultMaskSize, _ := net.CIDRMask(32, 32).Size()
834                 if netIP.To4() == nil {
835                         defaultMaskSize, _ = net.CIDRMask(128, 128).Size()
836                 }
837                 prefix.Len = byte(defaultMaskSize)
838                 prefix.Address, err = ParseAddress(netIP.String())
839                 if err != nil {
840                         return Prefix{}, fmt.Errorf("invalid IP %s: %s", ip, err)
841                 }
842         }
843         return prefix, nil
844 }
845
846 func (x Prefix) ToIPNet() *net.IPNet {
847         var mask net.IPMask
848         if x.Address.Af == ADDRESS_IP4 {
849                 mask = net.CIDRMask(int(x.Len), 32)
850         } else {
851                 mask = net.CIDRMask(int(x.Len), 128)
852         }
853         ipnet := &net.IPNet{IP: x.Address.ToIP(), Mask: mask}
854         return ipnet
855 }
856
857 func (x Prefix) String() string {
858         ip := x.Address.String()
859         return ip + "/" + strconv.Itoa(int(x.Len))
860 }
861
862 func (x *Prefix) MarshalText() ([]byte, error) {
863         return []byte(x.String()), nil
864 }
865
866 func (x *Prefix) UnmarshalText(text []byte) error {
867         prefix, err := ParsePrefix(string(text))
868         if err != nil {
869                 return err
870         }
871         *x = prefix
872         return nil
873 }
874
875 // PrefixMatcher defines type 'prefix_matcher'.
876 type PrefixMatcher struct {
877         Le uint8 `binapi:"u8,name=le" json:"le,omitempty"`
878         Ge uint8 `binapi:"u8,name=ge" json:"ge,omitempty"`
879 }
880
881 // AddressUnion defines union 'address_union'.
882 type AddressUnion struct {
883         // AddressUnion can be one of:
884         // - IP4 *IP4Address
885         // - IP6 *IP6Address
886         XXX_UnionData [16]byte
887 }
888
889 func AddressUnionIP4(a IP4Address) (u AddressUnion) {
890         u.SetIP4(a)
891         return
892 }
893 func (u *AddressUnion) SetIP4(a IP4Address) {
894         buf := codec.NewBuffer(u.XXX_UnionData[:])
895         buf.EncodeBytes(a[:], 4)
896 }
897 func (u *AddressUnion) GetIP4() (a IP4Address) {
898         buf := codec.NewBuffer(u.XXX_UnionData[:])
899         copy(a[:], buf.DecodeBytes(4))
900         return
901 }
902
903 func AddressUnionIP6(a IP6Address) (u AddressUnion) {
904         u.SetIP6(a)
905         return
906 }
907 func (u *AddressUnion) SetIP6(a IP6Address) {
908         buf := codec.NewBuffer(u.XXX_UnionData[:])
909         buf.EncodeBytes(a[:], 16)
910 }
911 func (u *AddressUnion) GetIP6() (a IP6Address) {
912         buf := codec.NewBuffer(u.XXX_UnionData[:])
913         copy(a[:], buf.DecodeBytes(16))
914         return
915 }
916
917 // PppoeAddDelSession defines message 'pppoe_add_del_session'.
918 type PppoeAddDelSession struct {
919         IsAdd      bool       `binapi:"bool,name=is_add" json:"is_add,omitempty"`
920         SessionID  uint16     `binapi:"u16,name=session_id" json:"session_id,omitempty"`
921         ClientIP   Address    `binapi:"address,name=client_ip" json:"client_ip,omitempty"`
922         DecapVrfID uint32     `binapi:"u32,name=decap_vrf_id" json:"decap_vrf_id,omitempty"`
923         ClientMac  MacAddress `binapi:"mac_address,name=client_mac" json:"client_mac,omitempty"`
924 }
925
926 func (m *PppoeAddDelSession) Reset()               { *m = PppoeAddDelSession{} }
927 func (*PppoeAddDelSession) GetMessageName() string { return "pppoe_add_del_session" }
928 func (*PppoeAddDelSession) GetCrcString() string   { return "46ace853" }
929 func (*PppoeAddDelSession) GetMessageType() api.MessageType {
930         return api.RequestMessage
931 }
932
933 func (m *PppoeAddDelSession) Size() (size int) {
934         if m == nil {
935                 return 0
936         }
937         size += 1      // m.IsAdd
938         size += 2      // m.SessionID
939         size += 4      // m.ClientIP.Af
940         size += 1 * 16 // m.ClientIP.Un
941         size += 4      // m.DecapVrfID
942         size += 1 * 6  // m.ClientMac
943         return size
944 }
945 func (m *PppoeAddDelSession) Marshal(b []byte) ([]byte, error) {
946         if b == nil {
947                 b = make([]byte, m.Size())
948         }
949         buf := codec.NewBuffer(b)
950         buf.EncodeBool(m.IsAdd)
951         buf.EncodeUint16(m.SessionID)
952         buf.EncodeUint32(uint32(m.ClientIP.Af))
953         buf.EncodeBytes(m.ClientIP.Un.XXX_UnionData[:], 16)
954         buf.EncodeUint32(m.DecapVrfID)
955         buf.EncodeBytes(m.ClientMac[:], 6)
956         return buf.Bytes(), nil
957 }
958 func (m *PppoeAddDelSession) Unmarshal(b []byte) error {
959         buf := codec.NewBuffer(b)
960         m.IsAdd = buf.DecodeBool()
961         m.SessionID = buf.DecodeUint16()
962         m.ClientIP.Af = AddressFamily(buf.DecodeUint32())
963         copy(m.ClientIP.Un.XXX_UnionData[:], buf.DecodeBytes(16))
964         m.DecapVrfID = buf.DecodeUint32()
965         copy(m.ClientMac[:], buf.DecodeBytes(6))
966         return nil
967 }
968
969 // PppoeAddDelSessionReply defines message 'pppoe_add_del_session_reply'.
970 type PppoeAddDelSessionReply struct {
971         Retval    int32          `binapi:"i32,name=retval" json:"retval,omitempty"`
972         SwIfIndex InterfaceIndex `binapi:"interface_index,name=sw_if_index" json:"sw_if_index,omitempty"`
973 }
974
975 func (m *PppoeAddDelSessionReply) Reset()               { *m = PppoeAddDelSessionReply{} }
976 func (*PppoeAddDelSessionReply) GetMessageName() string { return "pppoe_add_del_session_reply" }
977 func (*PppoeAddDelSessionReply) GetCrcString() string   { return "5383d31f" }
978 func (*PppoeAddDelSessionReply) GetMessageType() api.MessageType {
979         return api.ReplyMessage
980 }
981
982 func (m *PppoeAddDelSessionReply) Size() (size int) {
983         if m == nil {
984                 return 0
985         }
986         size += 4 // m.Retval
987         size += 4 // m.SwIfIndex
988         return size
989 }
990 func (m *PppoeAddDelSessionReply) Marshal(b []byte) ([]byte, error) {
991         if b == nil {
992                 b = make([]byte, m.Size())
993         }
994         buf := codec.NewBuffer(b)
995         buf.EncodeInt32(m.Retval)
996         buf.EncodeUint32(uint32(m.SwIfIndex))
997         return buf.Bytes(), nil
998 }
999 func (m *PppoeAddDelSessionReply) Unmarshal(b []byte) error {
1000         buf := codec.NewBuffer(b)
1001         m.Retval = buf.DecodeInt32()
1002         m.SwIfIndex = InterfaceIndex(buf.DecodeUint32())
1003         return nil
1004 }
1005
1006 // PppoeSessionDetails defines message 'pppoe_session_details'.
1007 type PppoeSessionDetails struct {
1008         SwIfIndex    InterfaceIndex `binapi:"interface_index,name=sw_if_index" json:"sw_if_index,omitempty"`
1009         SessionID    uint16         `binapi:"u16,name=session_id" json:"session_id,omitempty"`
1010         ClientIP     Address        `binapi:"address,name=client_ip" json:"client_ip,omitempty"`
1011         EncapIfIndex InterfaceIndex `binapi:"interface_index,name=encap_if_index" json:"encap_if_index,omitempty"`
1012         DecapVrfID   uint32         `binapi:"u32,name=decap_vrf_id" json:"decap_vrf_id,omitempty"`
1013         LocalMac     MacAddress     `binapi:"mac_address,name=local_mac" json:"local_mac,omitempty"`
1014         ClientMac    MacAddress     `binapi:"mac_address,name=client_mac" json:"client_mac,omitempty"`
1015 }
1016
1017 func (m *PppoeSessionDetails) Reset()               { *m = PppoeSessionDetails{} }
1018 func (*PppoeSessionDetails) GetMessageName() string { return "pppoe_session_details" }
1019 func (*PppoeSessionDetails) GetCrcString() string   { return "332bc742" }
1020 func (*PppoeSessionDetails) GetMessageType() api.MessageType {
1021         return api.ReplyMessage
1022 }
1023
1024 func (m *PppoeSessionDetails) Size() (size int) {
1025         if m == nil {
1026                 return 0
1027         }
1028         size += 4      // m.SwIfIndex
1029         size += 2      // m.SessionID
1030         size += 4      // m.ClientIP.Af
1031         size += 1 * 16 // m.ClientIP.Un
1032         size += 4      // m.EncapIfIndex
1033         size += 4      // m.DecapVrfID
1034         size += 1 * 6  // m.LocalMac
1035         size += 1 * 6  // m.ClientMac
1036         return size
1037 }
1038 func (m *PppoeSessionDetails) Marshal(b []byte) ([]byte, error) {
1039         if b == nil {
1040                 b = make([]byte, m.Size())
1041         }
1042         buf := codec.NewBuffer(b)
1043         buf.EncodeUint32(uint32(m.SwIfIndex))
1044         buf.EncodeUint16(m.SessionID)
1045         buf.EncodeUint32(uint32(m.ClientIP.Af))
1046         buf.EncodeBytes(m.ClientIP.Un.XXX_UnionData[:], 16)
1047         buf.EncodeUint32(uint32(m.EncapIfIndex))
1048         buf.EncodeUint32(m.DecapVrfID)
1049         buf.EncodeBytes(m.LocalMac[:], 6)
1050         buf.EncodeBytes(m.ClientMac[:], 6)
1051         return buf.Bytes(), nil
1052 }
1053 func (m *PppoeSessionDetails) Unmarshal(b []byte) error {
1054         buf := codec.NewBuffer(b)
1055         m.SwIfIndex = InterfaceIndex(buf.DecodeUint32())
1056         m.SessionID = buf.DecodeUint16()
1057         m.ClientIP.Af = AddressFamily(buf.DecodeUint32())
1058         copy(m.ClientIP.Un.XXX_UnionData[:], buf.DecodeBytes(16))
1059         m.EncapIfIndex = InterfaceIndex(buf.DecodeUint32())
1060         m.DecapVrfID = buf.DecodeUint32()
1061         copy(m.LocalMac[:], buf.DecodeBytes(6))
1062         copy(m.ClientMac[:], buf.DecodeBytes(6))
1063         return nil
1064 }
1065
1066 // PppoeSessionDump defines message 'pppoe_session_dump'.
1067 type PppoeSessionDump struct {
1068         SwIfIndex InterfaceIndex `binapi:"interface_index,name=sw_if_index" json:"sw_if_index,omitempty"`
1069 }
1070
1071 func (m *PppoeSessionDump) Reset()               { *m = PppoeSessionDump{} }
1072 func (*PppoeSessionDump) GetMessageName() string { return "pppoe_session_dump" }
1073 func (*PppoeSessionDump) GetCrcString() string   { return "f9e6675e" }
1074 func (*PppoeSessionDump) GetMessageType() api.MessageType {
1075         return api.RequestMessage
1076 }
1077
1078 func (m *PppoeSessionDump) Size() (size int) {
1079         if m == nil {
1080                 return 0
1081         }
1082         size += 4 // m.SwIfIndex
1083         return size
1084 }
1085 func (m *PppoeSessionDump) Marshal(b []byte) ([]byte, error) {
1086         if b == nil {
1087                 b = make([]byte, m.Size())
1088         }
1089         buf := codec.NewBuffer(b)
1090         buf.EncodeUint32(uint32(m.SwIfIndex))
1091         return buf.Bytes(), nil
1092 }
1093 func (m *PppoeSessionDump) Unmarshal(b []byte) error {
1094         buf := codec.NewBuffer(b)
1095         m.SwIfIndex = InterfaceIndex(buf.DecodeUint32())
1096         return nil
1097 }
1098
1099 func init() { file_pppoe_binapi_init() }
1100 func file_pppoe_binapi_init() {
1101         api.RegisterMessage((*PppoeAddDelSession)(nil), "pppoe_add_del_session_46ace853")
1102         api.RegisterMessage((*PppoeAddDelSessionReply)(nil), "pppoe_add_del_session_reply_5383d31f")
1103         api.RegisterMessage((*PppoeSessionDetails)(nil), "pppoe_session_details_332bc742")
1104         api.RegisterMessage((*PppoeSessionDump)(nil), "pppoe_session_dump_f9e6675e")
1105 }
1106
1107 // Messages returns list of all messages in this module.
1108 func AllMessages() []api.Message {
1109         return []api.Message{
1110                 (*PppoeAddDelSession)(nil),
1111                 (*PppoeAddDelSessionReply)(nil),
1112                 (*PppoeSessionDetails)(nil),
1113                 (*PppoeSessionDump)(nil),
1114         }
1115 }