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

     1  // Copyright 2016 Google, Inc. 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  package layers
     7  
     8  import (
     9  	"testing"
    10  
    11  	"github.com/gopacket/gopacket"
    12  )
    13  
    14  // vrrpPacketPriority100 is the packet:
    15  //
    16  //	06:12:21.813317 IP 192.168.0.30 > 224.0.0.18: VRRPv2, Advertisement, vrid 1, prio 100, authtype none, intvl 1s, length 20
    17  //		0x0000:  0100 5e00 0012 0000 5e00 0101 0800 45c0  ..^.....^.....E.
    18  //		0x0010:  0028 0000 0000 ff70 19cd c0a8 001e e000  .(.....p........
    19  //		0x0020:  0012 2101 6401 0001 ba52 c0a8 0001 0000  ..!.d....R......
    20  //		0x0030:  0000 0000 0000 0000 0000 0000            ............
    21  var vrrpPacketPriority100 = []byte{
    22  	0x01, 0x00, 0x5e, 0x00, 0x00, 0x12, 0x00, 0x00, 0x5e, 0x00, 0x01, 0x01, 0x08, 0x00, 0x45, 0xc0,
    23  	0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0xff, 0x70, 0x19, 0xcd, 0xc0, 0xa8, 0x00, 0x1e, 0xe0, 0x00,
    24  	0x00, 0x12, 0x21, 0x01, 0x64, 0x01, 0x00, 0x01, 0xba, 0x52, 0xc0, 0xa8, 0x00, 0x01, 0x00, 0x00,
    25  	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    26  }
    27  
    28  func TestVRRPPacketPacket0(t *testing.T) {
    29  	p := gopacket.NewPacket(vrrpPacketPriority100, LinkTypeEthernet, gopacket.Default)
    30  	if p.ErrorLayer() != nil {
    31  		t.Error("Failed to decode packet", p.ErrorLayer().Error())
    32  	}
    33  	checkLayers(p, []gopacket.LayerType{LayerTypeEthernet, LayerTypeIPv4, LayerTypeVRRP}, t)
    34  
    35  	// Version=2 Type=VRRPv2 Advertisement VirtualRtrID=1 Priority=100
    36  	vrrp := p.Layer(LayerTypeVRRP).(*VRRPv2)
    37  	if vrrp.Version != 2 {
    38  		t.Fatalf("Unable to decode VRRPv2 version. Received %d, expected %d", vrrp.Version, 2)
    39  	}
    40  
    41  	if vrrp.Type != 1 {
    42  		t.Fatalf("Unable to decode VRRPv2 type. Received %d, expected %d", vrrp.Type, 1)
    43  	}
    44  
    45  	if vrrp.Priority != 100 {
    46  		t.Fatalf("Unable to decode VRRPv2 priority. Received %d, expected %d", vrrp.Priority, 100)
    47  	}
    48  
    49  	if vrrp.Checksum != 47698 {
    50  		t.Fatalf("Unable to decode VRRPv2 checksum. Received %d, expected %d", vrrp.Checksum, 47698)
    51  	}
    52  }
    53  func BenchmarkDecodeVRRPPacket0(b *testing.B) {
    54  	for i := 0; i < b.N; i++ {
    55  		gopacket.NewPacket(vrrpPacketPriority100, LayerTypeEthernet, gopacket.NoCopy)
    56  	}
    57  }