github.com/gopacket/gopacket@v1.1.0/layers/mldv1_test.go (about)

     1  // Copyright 2018 GoPacket Authors. All rights reserved.
     2  //
     3  // Use of this source code is governed by a BSD-style license
     4  // that can be found in the LICENSE file in the root of the source
     5  // tree.
     6  
     7  package layers
     8  
     9  import (
    10  	"testing"
    11  
    12  	"github.com/gopacket/gopacket"
    13  )
    14  
    15  // Adapted from https://github.com/the-tcpdump-group/tcpdump/blob/master/tests/icmpv6.pcap
    16  // BSD licensed content
    17  //
    18  // Frame 3: 90 bytes on wire (720 bits), 90 bytes captured (720 bits)
    19  // Ethernet II, Src: JuniperN_0c:d4:e8 (b0:a8:6e:0c:d4:e8), Dst: IPv6mcast_01 (33:33:00:00:00:01)
    20  // Internet Protocol Version 6, Src: fe80::b2a8:6eff:fe0c:d4e8, Dst: ff02::1
    21  //
    22  //	0110 .... = Version: 6
    23  //	.... 0000 0000 .... .... .... .... .... = Traffic Class: 0x00 (DSCP: CS0, ECN: Not-ECT)
    24  //	.... .... .... 0000 0000 0000 0000 0000 = Flow Label: 0x00000
    25  //	Payload Length: 36
    26  //	Next Header: IPv6 Hop-by-Hop Option (0)
    27  //	Hop Limit: 1
    28  //	Source: fe80::b2a8:6eff:fe0c:d4e8
    29  //	Destination: ff02::1
    30  //	[Source SA MAC: JuniperN_0c:d4:e8 (b0:a8:6e:0c:d4:e8)]
    31  //	IPv6 Hop-by-Hop Option
    32  //
    33  // Internet Control Message Protocol v6
    34  //
    35  //	Type: Multicast Listener Query (130)
    36  //	Code: 0
    37  //	Checksum: 0x623a [correct]
    38  //	[Checksum Status: Good]
    39  //	Maximum Response Code: 10000
    40  //	Reserved: 0000
    41  //	Multicast Address: ::
    42  var testPacketMulticastListenerQueryMessageV1 = []byte{
    43  	0x33, 0x33, 0x00, 0x00, 0x00, 0x01, 0xb0, 0xa8, 0x6e, 0x0c, 0xd4, 0xe8, 0x86, 0xdd, 0x60, 0x00,
    44  	0x00, 0x00, 0x00, 0x24, 0x00, 0x01, 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb2, 0xa8,
    45  	0x6e, 0xff, 0xfe, 0x0c, 0xd4, 0xe8, 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    46  	0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x3a, 0x00, 0x05, 0x02, 0x00, 0x00, 0x01, 0x00, 0x82, 0x00,
    47  	0x62, 0x3a, 0x27, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    48  	0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    49  }
    50  
    51  func TestPacketMulticastListenerQueryMessageV1(t *testing.T) {
    52  	p := gopacket.NewPacket(testPacketMulticastListenerQueryMessageV1, LinkTypeEthernet, gopacket.Default)
    53  	if p.ErrorLayer() != nil {
    54  		t.Error("Failed to decode packet:", p.ErrorLayer().Error())
    55  	}
    56  	checkLayers(p, []gopacket.LayerType{LayerTypeEthernet, LayerTypeIPv6, LayerTypeIPv6HopByHop, LayerTypeICMPv6, LayerTypeMLDv1MulticastListenerQuery}, t)
    57  	// See https://github.com/google/gopacket/issues/517
    58  	// checkSerialization(p, t)
    59  }
    60  
    61  // Adapted from https://github.com/the-tcpdump-group/tcpdump/blob/master/tests/icmpv6.pcap
    62  // BSD licensed content
    63  //
    64  // Ethernet II, Src: JuniperN_0c:d4:e8 (b0:a8:6e:0c:d4:e8), Dst: IPv6mcast_01 (33:33:00:00:00:01)
    65  // Internet Protocol Version 6, Src: fe80::b2a8:6eff:fe0c:d4e8, Dst: ff02::1
    66  //
    67  //	0110 .... = Version: 6
    68  //	.... 0000 0000 .... .... .... .... .... = Traffic Class: 0x00 (DSCP: CS0, ECN: Not-ECT)
    69  //	.... .... .... 0000 0000 0000 0000 0000 = Flow Label: 0x00000
    70  //	Payload Length: 36
    71  //	Next Header: IPv6 Hop-by-Hop Option (0)
    72  //	Hop Limit: 1
    73  //	Source: fe80::b2a8:6eff:fe0c:d4e8
    74  //	Destination: ff02::1
    75  //	[Source SA MAC: JuniperN_0c:d4:e8 (b0:a8:6e:0c:d4:e8)]
    76  //	IPv6 Hop-by-Hop Option
    77  //
    78  // Internet Control Message Protocol v6
    79  //
    80  //	Type: Multicast Listener Report (131)
    81  //	Code: 0
    82  //	Checksum: 0x623a [incorrect]
    83  //	[Checksum Status: Invalid]
    84  //	Maximum Response Code: 10000
    85  //	Reserved: 0000
    86  //	Multicast Address: ff02::db8:1122:3344
    87  var testPacketMulticastListenerReportMessageV1 = []byte{
    88  	0x33, 0x33, 0x00, 0x00, 0x00, 0x01, 0xb0, 0xa8, 0x6e, 0x0c, 0xd4, 0xe8, 0x86, 0xdd, 0x60, 0x00,
    89  	0x00, 0x00, 0x00, 0x24, 0x00, 0x01, 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb2, 0xa8,
    90  	0x6e, 0xff, 0xfe, 0x0c, 0xd4, 0xe8, 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    91  	0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x3a, 0x00, 0x05, 0x02, 0x00, 0x00, 0x01, 0x00, 0x83, 0x00,
    92  	0x62, 0x3a, 0x27, 0x10, 0x00, 0x00, 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    93  	0x0d, 0xb8, 0x11, 0x22, 0x33, 0x44,
    94  }
    95  
    96  func TestPacketMulticastListenerReportMessageV1(t *testing.T) {
    97  	p := gopacket.NewPacket(testPacketMulticastListenerReportMessageV1, LinkTypeEthernet, gopacket.Default)
    98  	if p.ErrorLayer() != nil {
    99  		t.Error("Failed to decode packet:", p.ErrorLayer().Error())
   100  	}
   101  	checkLayers(p, []gopacket.LayerType{LayerTypeEthernet, LayerTypeIPv6, LayerTypeIPv6HopByHop, LayerTypeICMPv6, LayerTypeMLDv1MulticastListenerReport}, t)
   102  	// See https://github.com/google/gopacket/issues/517
   103  	// checkSerialization(p, t)
   104  }
   105  
   106  // Adapted from https://github.com/the-tcpdump-group/tcpdump/blob/master/tests/icmpv6.pcap
   107  // BSD licensed content
   108  //
   109  // Ethernet II, Src: JuniperN_0c:d4:e8 (b0:a8:6e:0c:d4:e8), Dst: IPv6mcast_01 (33:33:00:00:00:01)
   110  // Internet Protocol Version 6, Src: fe80::b2a8:6eff:fe0c:d4e8, Dst: ff02::1
   111  //
   112  //	0110 .... = Version: 6
   113  //	.... 0000 0000 .... .... .... .... .... = Traffic Class: 0x00 (DSCP: CS0, ECN: Not-ECT)
   114  //	.... .... .... 0000 0000 0000 0000 0000 = Flow Label: 0x00000
   115  //	Payload Length: 36
   116  //	Next Header: IPv6 Hop-by-Hop Option (0)
   117  //	Hop Limit: 1
   118  //	Source: fe80::b2a8:6eff:fe0c:d4e8
   119  //	Destination: ff02::1
   120  //	[Source SA MAC: JuniperN_0c:d4:e8 (b0:a8:6e:0c:d4:e8)]
   121  //	IPv6 Hop-by-Hop Option
   122  //
   123  // Internet Control Message Protocol v6
   124  //
   125  //	Type: Multicast Listener Done (132)
   126  //	Code: 0
   127  //	Checksum: 0x623a [incorrect]
   128  //	[Checksum Status: Invalid]
   129  //	Maximum Response Code: 10000
   130  //	Reserved: 0000
   131  //	Multicast Address: ff02::db8:1122:3344
   132  var testPacketMulticastListenerDoneMessageV1 = []byte{
   133  	0x33, 0x33, 0x00, 0x00, 0x00, 0x01, 0xb0, 0xa8, 0x6e, 0x0c, 0xd4, 0xe8, 0x86, 0xdd, 0x60, 0x00,
   134  	0x00, 0x00, 0x00, 0x24, 0x00, 0x01, 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb2, 0xa8,
   135  	0x6e, 0xff, 0xfe, 0x0c, 0xd4, 0xe8, 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   136  	0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x3a, 0x00, 0x05, 0x02, 0x00, 0x00, 0x01, 0x00, 0x84, 0x00,
   137  	0x62, 0x3a, 0x27, 0x10, 0x00, 0x00, 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   138  	0x0d, 0xb8, 0x11, 0x22, 0x33, 0x44,
   139  }
   140  
   141  func TestPacketMulticastListenerDoneMessageV1(t *testing.T) {
   142  	p := gopacket.NewPacket(testPacketMulticastListenerDoneMessageV1, LinkTypeEthernet, gopacket.Default)
   143  	if p.ErrorLayer() != nil {
   144  		t.Error("Failed to decode packet:", p.ErrorLayer().Error())
   145  	}
   146  	checkLayers(p, []gopacket.LayerType{LayerTypeEthernet, LayerTypeIPv6, LayerTypeIPv6HopByHop, LayerTypeICMPv6, LayerTypeMLDv1MulticastListenerDone}, t)
   147  	// See https://github.com/google/gopacket/issues/517
   148  	// checkSerialization(p, t)
   149  }