Refactored binapi generator with message encoding
[govpp.git] / codec / marshaler_test.go
1 //  Copyright (c) 2020 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
15 package codec_test
16
17 import (
18         "bytes"
19         "encoding/binary"
20         "reflect"
21         "testing"
22
23         "github.com/lunixbochs/struc"
24
25         "git.fd.io/govpp.git/api"
26         "git.fd.io/govpp.git/codec"
27         "git.fd.io/govpp.git/examples/binapi/fib_types"
28         "git.fd.io/govpp.git/examples/binapi/interface_types"
29         "git.fd.io/govpp.git/examples/binapi/interfaces"
30         "git.fd.io/govpp.git/examples/binapi/ip"
31         "git.fd.io/govpp.git/examples/binapi/ip_types"
32         "git.fd.io/govpp.git/examples/binapi/sr"
33 )
34
35 /*func TestNewCodecEncodeDecode(t *testing.T) {
36         tests := []struct {
37                 name string
38                 msg  Codec
39         }{
40                 {
41                         "", &TestAllMsg{
42                                 Bool:        true,
43                                 AliasUint32: 5,
44                                 AliasArray:  MacAddress{0x11, 0x22, 0x33, 0x44, 0x55, 0x66},
45                                 BaseArray:   []uint32{0x00, 0x00, 0x00, 0x00},
46                                 Enum:        IF_STATUS_API_FLAG_LINK_UP,
47                                 Uint8:       8,
48                                 Uint16:      16,
49                                 Uint32:      32,
50                                 Int8:        88,
51                                 Int16:       1616,
52                                 Int32:       3232,
53                                 Slice:       []byte{10, 20, 30, 40, 0, 0, 0},
54                                 String:      "abcdefghikl",
55                                 SizeOf:      2,
56                                 VariableSlice: []SliceType{
57                                         {Proto: IP_API_PROTO_AH},
58                                         {Proto: IP_API_PROTO_ESP},
59                                 },
60                                 TypeUnion: Address{
61                                         Af: ADDRESS_IP4,
62                                         Un: AddressUnionIP4(IP4Address{1, 2, 3, 4}),
63                                 },
64                         },
65                 },
66         }
67         for _, test := range tests {
68                 t.Run(test.name, func(t *testing.T) {
69                         data, err := test.msg.Marshal()
70                         if err != nil {
71                                 t.Fatalf("expected nil error, got: %v", err)
72                         }
73
74                         var m2 TestAllMsg
75                         if err := m2.Unmarshal(data); err != nil {
76                                 t.Fatalf("expected nil error, got: %v", err)
77                         }
78
79                         t.Logf("Data:\nOLD: %+v\nNEW: %+v", m, &m2)
80
81                         if !reflect.DeepEqual(m, &m2) {
82                                 t.Fatalf("newData differs from oldData")
83                         }
84                 })
85         }
86 }*/
87
88 func NewTestAllMsg() *TestAllMsg {
89         return &TestAllMsg{
90                 Bool:        true,
91                 AliasUint32: 5,
92                 AliasArray:  MacAddress{0x11, 0x22, 0x33, 0x44, 0x55, 0x66},
93                 BaseArray:   []uint32{0x00, 0x00, 0x00, 0x00},
94                 Enum:        IF_STATUS_API_FLAG_LINK_UP,
95                 Uint8:       8,
96                 Uint16:      16,
97                 Uint32:      32,
98                 Int8:        88,
99                 Int16:       1616,
100                 Int32:       3232,
101                 Slice:       []byte{10, 20, 30, 40, 0, 0, 0},
102                 String:      "abcdefghikl",
103                 SizeOf:      2,
104                 VariableSlice: []SliceType{
105                         {Proto: IP_API_PROTO_AH},
106                         {Proto: IP_API_PROTO_ESP},
107                 },
108                 TypeUnion: Address{
109                         Af: ADDRESS_IP4,
110                         Un: AddressUnionIP4(IP4Address{1, 2, 3, 4}),
111                 },
112         }
113 }
114
115 func TestNewCodecEncodeDecode_(t *testing.T) {
116         m := NewTestAllMsg()
117
118         data, err := m.Marshal(nil)
119         if err != nil {
120                 t.Fatalf("expected nil error, got: %v", err)
121         }
122
123         var m2 TestAllMsg
124         if err := m2.Unmarshal(data); err != nil {
125                 t.Fatalf("expected nil error, got: %v", err)
126         }
127
128         t.Logf("Data:\nOLD: %+v\nNEW: %+v", m, &m2)
129
130         if !reflect.DeepEqual(m, &m2) {
131                 t.Fatalf("newData differs from oldData")
132         }
133 }
134
135 // -------------
136
137 func TestNewCodecEncodeDecode3(t *testing.T) {
138         m := NewTestAllMsg()
139         data, err := m.Marshal(nil)
140         if err != nil {
141                 t.Fatalf("expected nil error, got: %v", err)
142         }
143
144         var m2 TestAllMsg
145         if err := m2.Unmarshal(data); err != nil {
146                 t.Fatalf("expected nil error, got: %v", err)
147         }
148
149         t.Logf("Data:\nOLD: %+v\nNEW: %+v", m, &m2)
150
151         if !reflect.DeepEqual(m, &m2) {
152                 t.Fatalf("newData differs from oldData")
153         }
154 }
155 func TestNewCodecEncodeDecode4(t *testing.T) {
156         m := &interfaces.SwInterfaceSetRxMode{
157                 Mode:         interface_types.RX_MODE_API_POLLING,
158                 QueueID:      70000,
159                 QueueIDValid: true,
160                 SwIfIndex:    300,
161         }
162
163         b := make([]byte, 2+m.Size())
164
165         data, err := m.Marshal(b[2:])
166         if err != nil {
167                 t.Fatalf("expected nil error, got: %v", err)
168         }
169
170         t.Logf("ENCODED DATA(%d): % 03x", len(data), data)
171
172         var m2 interfaces.SwInterfaceSetRxMode
173         if err := m2.Unmarshal(b[2:]); err != nil {
174                 t.Fatalf("expected nil error, got: %v", err)
175         }
176
177         t.Logf("Data:\nOLD: %+v\nNEW: %+v", m, &m2)
178
179         if !reflect.DeepEqual(m, &m2) {
180                 t.Fatalf("newData differs from oldData")
181         }
182 }
183 func TestNewCodecEncodeDecode2(t *testing.T) {
184         m := &sr.SrPoliciesDetails{
185                 Bsid:        sr.IP6Address{00, 11, 22, 33, 44, 55, 66, 77, 88, 99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff},
186                 IsSpray:     true,
187                 IsEncap:     false,
188                 FibTable:    33,
189                 NumSidLists: 1,
190                 SidLists: []sr.Srv6SidList{
191                         {
192                                 Weight:  555,
193                                 NumSids: 2,
194                                 Sids: [16]sr.IP6Address{
195                                         {99},
196                                         {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16},
197                                 },
198                         },
199                 },
200         }
201
202         b := make([]byte, 0, m.Size())
203         data, err := m.Marshal(b)
204         if err != nil {
205                 t.Fatalf("expected nil error, got: %v", err)
206         }
207
208         t.Logf("ENCODED DATA(%d): % 03x", len(data), data)
209
210         var m2 sr.SrPoliciesDetails
211         if err := m2.Unmarshal(data); err != nil {
212                 t.Fatalf("expected nil error, got: %v", err)
213         }
214
215         t.Logf("Data:\nOLD: %+v\nNEW: %+v", m, &m2)
216
217         if !reflect.DeepEqual(m, &m2) {
218                 t.Fatalf("newData differs from oldData")
219         }
220 }
221
222 func TestNewCodecEncode(t *testing.T) {
223         //m := NewIPRouteLookupReply()
224         m := &sr.SrPoliciesDetails{
225                 Bsid:        sr.IP6Address{00, 11, 22, 33, 44, 55, 66, 77, 88, 99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff},
226                 IsSpray:     true,
227                 IsEncap:     false,
228                 FibTable:    33,
229                 NumSidLists: 1,
230                 SidLists: []sr.Srv6SidList{
231                         {
232                                 Weight:  555,
233                                 NumSids: 2,
234                                 Sids: [16]sr.IP6Address{
235                                         {99},
236                                         {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16},
237                                 },
238                         },
239                 },
240         }
241
242         size := m.Size()
243         t.Logf("size: %d", size)
244
245         var err error
246         var oldData, newData []byte
247         {
248                 var c codec.OldCodec
249                 oldData, err = c.Marshal(m)
250                 if err != nil {
251                         t.Fatalf("expected nil error, got: %v", err)
252                 }
253         }
254         {
255                 newData, err = m.Marshal(nil)
256                 if err != nil {
257                         t.Fatalf("expected nil error, got: %v", err)
258                 }
259         }
260         t.Logf("Data:\nOLD[%d]: % 03x\nNEW[%d]: % 03x", len(oldData), oldData, len(newData), newData)
261
262         if !bytes.Equal(oldData, newData) {
263                 t.Fatalf("newData differs from oldData")
264         }
265 }
266
267 func TestNewCodecDecode(t *testing.T) {
268         /*m := &ip.IPRouteLookupReply{}
269         size := m.Size()
270         t.Logf("size: %d", size)*/
271         data := []byte{
272                 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03,
273                 0x00, 0x00, 0x00, 0x05, 0x01, 0x00, 0x00, 0x00,
274                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
275                 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x01, 0x00,
276                 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x06, 0x00,
277                 0x00, 0x00, 0x08, 0x09, 0x0a, 0x00, 0x00, 0x00,
278                 0x0b, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
279                 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
280                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
281                 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
282                 0x01, 0x00, 0x00, 0x00, 0x02, 0x01, 0x09, 0x00,
283                 0x00, 0x00, 0x08, 0x07, 0x06, 0x00, 0x00, 0x00,
284                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
285                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
286                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
287                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
288                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
289                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
290                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
291                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
292                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
293                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
294                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
295                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
296                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
297         }
298
299         var err error
300         var oldData, newData ip.IPRouteLookupReply
301         {
302                 var c codec.OldCodec
303                 err = c.Unmarshal(data, &oldData)
304                 if err != nil {
305                         t.Errorf("expected nil error, got: %v", err)
306                 }
307         }
308         {
309                 err = newData.Unmarshal(data)
310                 if err != nil {
311                         t.Errorf("expected nil error, got: %v", err)
312                 }
313         }
314         t.Logf("Data:\nOLD: %+v\nNEW: %+v", oldData, newData)
315
316         if !reflect.DeepEqual(oldData, newData) {
317                 t.Fatalf("newData differs from oldData")
318         }
319 }
320
321 func NewIPRouteLookupReply() *ip.IPRouteLookupReply {
322         return &ip.IPRouteLookupReply{
323                 Retval: 1,
324                 Route: ip.IPRoute{
325                         TableID:    3,
326                         StatsIndex: 5,
327                         Prefix: ip.Prefix{
328                                 Address: ip_types.Address{
329                                         Af: fib_types.ADDRESS_IP6,
330                                         Un: ip_types.AddressUnion{},
331                                 },
332                                 Len: 24,
333                         },
334                         NPaths: 2,
335                         Paths: []ip.FibPath{
336                                 {
337                                         SwIfIndex:  5,
338                                         TableID:    6,
339                                         RpfID:      8,
340                                         Weight:     9,
341                                         Preference: 10,
342                                         Type:       11,
343                                         Flags:      1,
344                                         Proto:      2,
345                                         Nh: ip.FibPathNh{
346                                                 Address:            ip.AddressUnion{},
347                                                 ViaLabel:           3,
348                                                 ObjID:              1,
349                                                 ClassifyTableIndex: 2,
350                                         },
351                                         NLabels: 1,
352                                         LabelStack: [16]ip.FibMplsLabel{
353                                                 {
354                                                         IsUniform: 9,
355                                                         Label:     8,
356                                                         TTL:       7,
357                                                         Exp:       6,
358                                                 },
359                                         },
360                                 },
361                                 {
362                                         SwIfIndex:  7,
363                                         TableID:    6,
364                                         RpfID:      8,
365                                         Weight:     9,
366                                         Preference: 10,
367                                         Type:       11,
368                                         Flags:      1,
369                                         Proto:      1,
370                                         Nh: ip.FibPathNh{
371                                                 Address:            ip.AddressUnion{},
372                                                 ViaLabel:           3,
373                                                 ObjID:              1,
374                                                 ClassifyTableIndex: 2,
375                                         },
376                                         NLabels: 2,
377                                         LabelStack: [16]ip.FibMplsLabel{
378                                                 {
379                                                         IsUniform: 9,
380                                                         Label:     8,
381                                                         TTL:       7,
382                                                         Exp:       6,
383                                                 },
384                                                 {
385                                                         IsUniform: 10,
386                                                         Label:     8,
387                                                         TTL:       7,
388                                                         Exp:       6,
389                                                 },
390                                         },
391                                 },
392                         },
393                 },
394         }
395 }
396
397 func TestSize(t *testing.T) {
398         m := NewTestAllMsg()
399         size := binary.Size(*m)
400         t.Logf("size: %v", size)
401 }
402
403 func (m *TestAllMsg) Marshal(b []byte) ([]byte, error) {
404         order := binary.BigEndian
405         tmp := make([]byte, 143)
406         pos := 0
407
408         tmp[pos] = boolToUint(m.Bool)
409         pos += 1
410
411         tmp[pos] = m.Uint8
412         pos += 1
413
414         order.PutUint16(tmp[pos:pos+2], m.Uint16)
415         pos += 2
416
417         order.PutUint32(tmp[pos:pos+4], m.Uint32)
418         pos += 4
419
420         tmp[pos] = byte(m.Int8)
421         pos += 1
422
423         order.PutUint16(tmp[pos:pos+2], uint16(m.Int16))
424         pos += 2
425
426         order.PutUint32(tmp[pos:pos+4], uint32(m.Int32))
427         pos += 4
428
429         order.PutUint32(tmp[pos:pos+4], uint32(m.AliasUint32))
430         pos += 4
431
432         copy(tmp[pos:pos+6], m.AliasArray[:])
433         pos += 6
434
435         order.PutUint32(tmp[pos:pos+4], uint32(m.Enum))
436         pos += 4
437
438         for i := 0; i < 4; i++ {
439                 var x uint32
440                 if i < len(m.BaseArray) {
441                         x = m.BaseArray[i]
442                 }
443                 order.PutUint32(tmp[pos:pos+4], uint32(x))
444                 pos += 4
445         }
446
447         copy(tmp[pos:pos+7], m.Slice)
448         pos += 7
449
450         copy(tmp[pos:pos+64], m.String)
451         pos += 64
452
453         order.PutUint32(tmp[pos:pos+4], uint32(len(m.VlaStr)) /*m.SizeOf*/)
454         pos += 4
455
456         copy(tmp[pos:pos+len(m.VlaStr)], m.VlaStr[:])
457         pos += len(m.VlaStr)
458
459         order.PutUint32(tmp[pos:pos+4], uint32(len(m.VariableSlice)) /*m.SizeOf*/)
460         pos += 4
461
462         for i := range m.VariableSlice {
463                 tmp[pos+i*1] = uint8(m.VariableSlice[i].Proto)
464                 //copy(tmp[102+i:103+i], []byte{byte(m.VariableSlice[i].Proto)})
465         }
466         pos += len(m.VariableSlice) * 1
467
468         tmp[pos] = uint8(m.TypeUnion.Af)
469         pos += 1
470
471         copy(tmp[pos:pos+16], m.TypeUnion.Un.XXX_UnionData[:])
472         pos += 16
473
474         return tmp, nil
475
476         /*_, err := buf.Write(tmp)
477         if err != nil {
478                 return nil, err
479         }
480         return buf.Bytes(), nil*/
481 }
482
483 func (m *TestAllMsg) Unmarshal(tmp []byte) error {
484         order := binary.BigEndian
485
486         //tmp := make([]byte, 143)
487         pos := 0
488
489         m.Bool = tmp[pos] != 0
490         pos += 1
491
492         //tmp[pos] = m.Uint8
493         m.Uint8 = tmp[pos]
494         pos += 1
495
496         //order.PutUint16(tmp[pos:pos+2], m.Uint16)
497         m.Uint16 = order.Uint16(tmp[pos : pos+2])
498         pos += 2
499
500         //order.PutUint32(tmp[pos:pos+4], m.Uint32)
501         m.Uint32 = order.Uint32(tmp[pos : pos+4])
502         pos += 4
503
504         //tmp[pos] = byte(m.Int8)
505         m.Int8 = int8(tmp[pos])
506         pos += 1
507
508         //order.PutUint16(tmp[pos:pos+2], uint16(m.Int16))
509         m.Int16 = int16(order.Uint16(tmp[pos : pos+2]))
510         pos += 2
511
512         //order.PutUint32(tmp[pos:pos+4], uint32(m.Int32))
513         m.Int32 = int32(order.Uint32(tmp[pos : pos+4]))
514         pos += 4
515
516         //order.PutUint32(tmp[pos:pos+4], uint32(m.AliasUint32))
517         m.AliasUint32 = InterfaceIndex(order.Uint32(tmp[pos : pos+4]))
518         pos += 4
519
520         //copy(tmp[pos:pos+6], m.AliasArray[:])
521         copy(m.AliasArray[:], tmp[pos:pos+6])
522         pos += 6
523
524         //order.PutUint32(tmp[pos:pos+4], uint32(m.Enum))
525         m.Enum = IfStatusFlags(order.Uint32(tmp[pos : pos+4]))
526         pos += 4
527
528         m.BaseArray = make([]uint32, 4)
529         for i := 0; i < 4; i++ {
530                 /*var x uint32
531                 if i < len(m.BaseArray) {
532                         x = m.BaseArray[i]
533                 }
534                 order.PutUint32(tmp[pos:pos+4], uint32(x))*/
535                 m.BaseArray[i] = order.Uint32(tmp[pos : pos+4])
536                 pos += 4
537         }
538
539         m.Slice = make([]byte, 7)
540         copy(m.Slice[:7], tmp[pos:pos+7])
541         //copy(tmp[pos:pos+7], m.Slice)
542         pos += 7
543
544         i := bytes.Index(tmp[pos:pos+64], []byte{0x00})
545         m.String = string(tmp[pos : pos+i])
546         //copy(tmp[pos:pos+64], m.String)
547         pos += 64
548
549         //order.PutUint32(tmp[pos:pos+4], uint32(len(m.VlaStr)) /*m.SizeOf*/)
550         VlaStrLen := int(order.Uint32(tmp[pos : pos+4]))
551         pos += 4
552
553         m.VlaStr = string(tmp[pos : pos+VlaStrLen])
554         //copy(m.VlaStr[pos:pos+VlaStrLen], tmp[pos:pos+64])
555         pos += len(m.VlaStr)
556
557         m.SizeOf = uint32(order.Uint32(tmp[pos : pos+4]))
558         pos += 4
559
560         /*order.PutUint32(tmp[pos:pos+4], uint32(len(m.VariableSlice)))
561         m.VariableSlice = IfStatusFlags(order.Uint32(tmp[pos : pos+4]))
562         pos += 4*/
563
564         m.VariableSlice = make([]SliceType, m.SizeOf)
565         for i := range m.VariableSlice {
566                 //tmp[pos+i*1] = uint8(m.VariableSlice[i].Proto)
567                 m.VariableSlice[i].Proto = IPProto(tmp[pos+i*1])
568                 //copy(tmp[102+i:103+i], []byte{byte(m.VariableSlice[i].Proto)})
569         }
570         pos += len(m.VariableSlice) * 1
571
572         //tmp[pos] = uint8(m.TypeUnion.Af)
573         m.TypeUnion.Af = AddressFamily(tmp[pos])
574         pos += 1
575
576         //copy(tmp[pos:pos+16], m.TypeUnion.Un.XXX_UnionData[:])
577         copy(m.TypeUnion.Un.XXX_UnionData[:], tmp[pos:pos+16])
578         pos += 16
579
580         return nil
581         /*_, err := buf.Write(tmp)
582         if err != nil {
583                 return nil, err
584         }
585         return buf.Bytes(), nil*/
586 }
587
588 func boolToUint(b bool) uint8 {
589         if b {
590                 return 1
591         }
592         return 0
593 }
594
595 // SwInterfaceDetails represents VPP binary API message 'sw_interface_details'.
596 type TestAllMsg struct {
597         Bool          bool
598         Uint8         uint8
599         Uint16        uint16
600         Uint32        uint32
601         Int8          int8
602         Int16         int16
603         Int32         int32
604         AliasUint32   InterfaceIndex
605         AliasArray    MacAddress
606         Enum          IfStatusFlags
607         BaseArray     []uint32 `struc:"[4]uint32"`
608         Slice         []byte   `struc:"[7]byte"`
609         String        string   `struc:"[64]byte"`
610         XXX_VlaStrLen uint32   `struc:"sizeof=VlaStr"`
611         VlaStr        string
612         SizeOf        uint32 `struc:"sizeof=VariableSlice"`
613         VariableSlice []SliceType
614         TypeUnion     Address
615 }
616
617 type InterfaceIndex uint32
618 type MacAddress [6]uint8
619 type IfStatusFlags uint32
620
621 const (
622         IF_STATUS_API_FLAG_ADMIN_UP IfStatusFlags = 1
623         IF_STATUS_API_FLAG_LINK_UP  IfStatusFlags = 2
624 )
625
626 // Address represents VPP binary API type 'address'.
627 type Address struct {
628         Af AddressFamily
629         Un AddressUnion
630 }
631
632 // AddressFamily represents VPP binary API enum 'address_family'.
633 type AddressFamily uint8
634
635 const (
636         ADDRESS_IP4 AddressFamily = 0
637         ADDRESS_IP6 AddressFamily = 1
638 )
639
640 // AddressUnion represents VPP binary API union 'address_union'.
641 type AddressUnion struct {
642         XXX_UnionData [16]byte
643 }
644
645 func (*AddressUnion) GetTypeName() string { return "address_union" }
646
647 func AddressUnionIP4(a IP4Address) (u AddressUnion) {
648         u.SetIP4(a)
649         return
650 }
651 func (u *AddressUnion) SetIP4(a IP4Address) {
652         var b = new(bytes.Buffer)
653         if err := struc.Pack(b, &a); err != nil {
654                 return
655         }
656         copy(u.XXX_UnionData[:], b.Bytes())
657 }
658 func (u *AddressUnion) GetIP4() (a IP4Address) {
659         var b = bytes.NewReader(u.XXX_UnionData[:])
660         struc.Unpack(b, &a)
661         return
662 }
663
664 func AddressUnionIP6(a IP6Address) (u AddressUnion) {
665         u.SetIP6(a)
666         return
667 }
668 func (u *AddressUnion) SetIP6(a IP6Address) {
669         var b = new(bytes.Buffer)
670         if err := struc.Pack(b, &a); err != nil {
671                 return
672         }
673         copy(u.XXX_UnionData[:], b.Bytes())
674 }
675 func (u *AddressUnion) GetIP6() (a IP6Address) {
676         var b = bytes.NewReader(u.XXX_UnionData[:])
677         struc.Unpack(b, &a)
678         return
679 }
680
681 // IP4Address represents VPP binary API alias 'ip4_address'.
682 type IP4Address [4]uint8
683
684 // IP6Address represents VPP binary API alias 'ip6_address'.
685 type IP6Address [16]uint8
686
687 type SliceType struct {
688         Proto IPProto
689 }
690
691 type IPProto uint8
692
693 const (
694         IP_API_PROTO_HOPOPT   IPProto = 0
695         IP_API_PROTO_ICMP     IPProto = 1
696         IP_API_PROTO_IGMP     IPProto = 2
697         IP_API_PROTO_TCP      IPProto = 6
698         IP_API_PROTO_UDP      IPProto = 17
699         IP_API_PROTO_GRE      IPProto = 47
700         IP_API_PROTO_ESP      IPProto = 50
701         IP_API_PROTO_AH       IPProto = 51
702         IP_API_PROTO_ICMP6    IPProto = 58
703         IP_API_PROTO_EIGRP    IPProto = 88
704         IP_API_PROTO_OSPF     IPProto = 89
705         IP_API_PROTO_SCTP     IPProto = 132
706         IP_API_PROTO_RESERVED IPProto = 255
707 )
708
709 func (m *TestAllMsg) Reset()                        { *m = TestAllMsg{} }
710 func (*TestAllMsg) GetMessageName() string          { return "sw_interface_details" }
711 func (*TestAllMsg) GetCrcString() string            { return "17b69fa2" }
712 func (*TestAllMsg) GetMessageType() api.MessageType { return api.ReplyMessage }