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