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