ODPM 266: Go-libmemif + 2 examples.
[govpp.git] / vendor / github.com / google / gopacket / layers / icmp6_test.go
1 // Copyright 2012, Google, Inc. All rights reserved.
2 // Copyright 2009-2011 Andreas Krennmair. All rights reserved.
3 //
4 // Use of this source code is governed by a BSD-style license
5 // that can be found in the LICENSE file in the root of the source
6 // tree.
7
8 package layers
9
10 import (
11         "github.com/google/gopacket"
12         "net"
13         "reflect"
14         "testing"
15 )
16
17 // testPacketICMPv6 is the packet:
18 //   10:48:30.088384 IP6 2620:0:1005:0:26be:5ff:fe27:b17 > fe80::21f:caff:feb3:7640: ICMP6, neighbor advertisement, tgt is 2620:0:1005:0:26be:5ff:fe27:b17, length 24
19 //      0x0000:  001f cab3 7640 24be 0527 0b17 86dd 6000  ....v@$..'....`.
20 //      0x0010:  0000 0018 3aff 2620 0000 1005 0000 26be  ....:.&.......&.
21 //      0x0020:  05ff fe27 0b17 fe80 0000 0000 0000 021f  ...'............
22 //      0x0030:  caff feb3 7640 8800 1ed6 4000 0000 2620  ....v@....@...&.
23 //      0x0040:  0000 1005 0000 26be 05ff fe27 0b17       ......&....'..
24 var testPacketICMPv6 = []byte{
25         0x00, 0x1f, 0xca, 0xb3, 0x76, 0x40, 0x24, 0xbe, 0x05, 0x27, 0x0b, 0x17, 0x86, 0xdd, 0x60, 0x00,
26         0x00, 0x00, 0x00, 0x18, 0x3a, 0xff, 0x26, 0x20, 0x00, 0x00, 0x10, 0x05, 0x00, 0x00, 0x26, 0xbe,
27         0x05, 0xff, 0xfe, 0x27, 0x0b, 0x17, 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x1f,
28         0xca, 0xff, 0xfe, 0xb3, 0x76, 0x40, 0x88, 0x00, 0x1e, 0xd6, 0x40, 0x00, 0x00, 0x00, 0x26, 0x20,
29         0x00, 0x00, 0x10, 0x05, 0x00, 0x00, 0x26, 0xbe, 0x05, 0xff, 0xfe, 0x27, 0x0b, 0x17,
30 }
31
32 func TestPacketICMPv6(t *testing.T) {
33         p := gopacket.NewPacket(testPacketICMPv6, LinkTypeEthernet, gopacket.Default)
34         if p.ErrorLayer() != nil {
35                 t.Error("Failed to decode packet:", p.ErrorLayer().Error())
36         }
37         checkLayers(p, []gopacket.LayerType{LayerTypeEthernet, LayerTypeIPv6, LayerTypeICMPv6, gopacket.LayerTypePayload}, t)
38         if got, ok := p.Layer(LayerTypeIPv6).(*IPv6); ok {
39                 want := &IPv6{
40                         BaseLayer: BaseLayer{
41                                 Contents: []byte{0x60, 0x0, 0x0, 0x0, 0x0, 0x18,
42                                         0x3a, 0xff, 0x26, 0x20, 0x0, 0x0, 0x10, 0x5, 0x0, 0x0, 0x26, 0xbe, 0x5,
43                                         0xff, 0xfe, 0x27, 0xb, 0x17, 0xfe, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
44                                         0x2, 0x1f, 0xca, 0xff, 0xfe, 0xb3, 0x76, 0x40},
45                                 Payload: []byte{0x88, 0x0, 0x1e, 0xd6, 0x40, 0x0, 0x0, 0x0, 0x26, 0x20,
46                                         0x0, 0x0, 0x10, 0x5, 0x0, 0x0, 0x26, 0xbe, 0x5, 0xff, 0xfe, 0x27, 0xb,
47                                         0x17},
48                         },
49                         Version:      6,
50                         TrafficClass: 0,
51                         FlowLabel:    0,
52                         Length:       24,
53                         NextHeader:   IPProtocolICMPv6,
54                         HopLimit:     255,
55                         SrcIP:        net.IP{0x26, 0x20, 0x0, 0x0, 0x10, 0x5, 0x0, 0x0, 0x26, 0xbe, 0x5, 0xff, 0xfe, 0x27, 0xb, 0x17},
56                         DstIP:        net.IP{0xfe, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2, 0x1f, 0xca, 0xff, 0xfe, 0xb3, 0x76, 0x40},
57                 }
58                 if !reflect.DeepEqual(got, want) {
59                         t.Errorf("IPv6 packet processing failed:\ngot  :\n%#v\n\nwant :\n%#v\n\n", got, want)
60                 }
61         } else {
62                 t.Error("No IPv6 layer type found in packet")
63         }
64         if got, ok := p.Layer(LayerTypeICMPv6).(*ICMPv6); ok {
65                 want := &ICMPv6{
66                         BaseLayer: BaseLayer{
67                                 Contents: []byte{0x88, 0x0, 0x1e, 0xd6, 0x40, 0x0, 0x0, 0x0},
68                                 Payload: []byte{0x26, 0x20, 0x0, 0x0, 0x10,
69                                         0x5, 0x0, 0x0, 0x26, 0xbe, 0x5, 0xff, 0xfe, 0x27, 0xb, 0x17},
70                         },
71                         TypeCode:  0x8800,
72                         Checksum:  0x1ed6,
73                         TypeBytes: []byte{0x40, 0x0, 0x0, 0x0},
74                 }
75                 if !reflect.DeepEqual(got, want) {
76                         t.Errorf("ICMPv6 packet processing failed:\ngot  :\n%#v\n\nwant :\n%#v\n\n", got, want)
77                 }
78                 if got.TypeCode.String() != "NeighborAdvertisement" {
79                         t.Errorf("ICMPv6 type code, got %q want 'NeighborAdvertisement'", got.TypeCode.String())
80                 }
81         } else {
82                 t.Error("No ICMPv6 layer type found in packet")
83         }
84 }