diff options
author | Milan Lenco <milan.lenco@pantheon.tech> | 2017-10-11 16:40:58 +0200 |
---|---|---|
committer | Milan Lenco <milan.lenco@pantheon.tech> | 2017-10-13 08:40:37 +0200 |
commit | 3f1edad4e6ba0a7876750aea55507fae14d8badf (patch) | |
tree | a473997249d9ba7deb70b1076d14e4c4ed029a43 /vendor/github.com/google/gopacket/layers/vrrp_test.go | |
parent | 8b66677c2382a8e739d437621de4473d5ec0b9f1 (diff) |
ODPM 266: Go-libmemif + 2 examples.
Change-Id: Icdb9b9eb2314eff6c96afe7996fcf2728291de4a
Signed-off-by: Milan Lenco <milan.lenco@pantheon.tech>
Diffstat (limited to 'vendor/github.com/google/gopacket/layers/vrrp_test.go')
-rw-r--r-- | vendor/github.com/google/gopacket/layers/vrrp_test.go | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/vendor/github.com/google/gopacket/layers/vrrp_test.go b/vendor/github.com/google/gopacket/layers/vrrp_test.go new file mode 100644 index 0000000..bc6b7e4 --- /dev/null +++ b/vendor/github.com/google/gopacket/layers/vrrp_test.go @@ -0,0 +1,55 @@ +// Copyright 2016 Google, Inc. All rights reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the LICENSE file in the root of the source +// tree. +package layers + +import ( + "github.com/google/gopacket" + "testing" +) + +// vrrpPacketPriority100 is the packet: +// 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 +// 0x0000: 0100 5e00 0012 0000 5e00 0101 0800 45c0 ..^.....^.....E. +// 0x0010: 0028 0000 0000 ff70 19cd c0a8 001e e000 .(.....p........ +// 0x0020: 0012 2101 6401 0001 ba52 c0a8 0001 0000 ..!.d....R...... +// 0x0030: 0000 0000 0000 0000 0000 0000 ............ +var vrrpPacketPriority100 = []byte{ + 0x01, 0x00, 0x5e, 0x00, 0x00, 0x12, 0x00, 0x00, 0x5e, 0x00, 0x01, 0x01, 0x08, 0x00, 0x45, 0xc0, + 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0xff, 0x70, 0x19, 0xcd, 0xc0, 0xa8, 0x00, 0x1e, 0xe0, 0x00, + 0x00, 0x12, 0x21, 0x01, 0x64, 0x01, 0x00, 0x01, 0xba, 0x52, 0xc0, 0xa8, 0x00, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +} + +func TestVRRPPacketPacket0(t *testing.T) { + p := gopacket.NewPacket(vrrpPacketPriority100, LinkTypeEthernet, gopacket.Default) + if p.ErrorLayer() != nil { + t.Error("Failed to decode packet", p.ErrorLayer().Error()) + } + checkLayers(p, []gopacket.LayerType{LayerTypeEthernet, LayerTypeIPv4, LayerTypeVRRP}, t) + + // Version=2 Type=VRRPv2 Advertisement VirtualRtrID=1 Priority=100 + vrrp := p.Layer(LayerTypeVRRP).(*VRRPv2) + if vrrp.Version != 2 { + t.Fatalf("Unable to decode VRRPv2 version. Received %d, expected %d", vrrp.Version, 2) + } + + if vrrp.Type != 1 { + t.Fatalf("Unable to decode VRRPv2 type. Received %d, expected %d", vrrp.Type, 1) + } + + if vrrp.Priority != 100 { + t.Fatalf("Unable to decode VRRPv2 priority. Received %d, expected %d", vrrp.Priority, 100) + } + + if vrrp.Checksum != 47698 { + t.Fatalf("Unable to decode VRRPv2 checksum. Received %d, expected %d", vrrp.Checksum, 47698) + } +} +func BenchmarkDecodeVRRPPacket0(b *testing.B) { + for i := 0; i < b.N; i++ { + gopacket.NewPacket(vrrpPacketPriority100, LayerTypeEthernet, gopacket.NoCopy) + } +} |