Skip to content

Commit

Permalink
Merge pull request #53 from fako1024/52-enforce-unsigned-uint64-for-s…
Browse files Browse the repository at this point in the history
…tats-packet-counters

[bugfix] Switch all packet stats / counters to uint64
  • Loading branch information
fako1024 authored Aug 4, 2023
2 parents a567eb3 + d6cd610 commit 6e647c8
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions capture/afpacket/afpacket/afpacket.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ func (s *Source) Stats() (capture.Stats, error) {
return capture.Stats{}, err
}
return capture.Stats{
PacketsReceived: int(ss.Packets),
PacketsDropped: int(ss.Drops),
PacketsReceived: uint64(ss.Packets),
PacketsDropped: uint64(ss.Drops),
}, nil
}

Expand Down
6 changes: 3 additions & 3 deletions capture/afpacket/afpacket/afpacket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func TestPipe(t *testing.T) {
require.Nil(t, <-errChan)
stats, err := mockSrc.Stats()
require.Nil(t, err)
require.Equal(t, capture.Stats{PacketsReceived: int(n * n)}, stats)
require.Equal(t, capture.Stats{PacketsReceived: uint64(n * n)}, stats)
require.Nil(t, mockSrc.Close())
}()

Expand All @@ -219,7 +219,7 @@ func TestPipe(t *testing.T) {
require.Nil(t, <-errChan2)
stats, err := mockSrc2.Stats()
require.Nil(t, err)
require.Equal(t, capture.Stats{PacketsReceived: int(n * n)}, stats)
require.Equal(t, capture.Stats{PacketsReceived: uint64(n * n)}, stats)
require.Nil(t, mockSrc2.Close())
}

Expand Down Expand Up @@ -342,7 +342,7 @@ func testCaptureMethods(t *testing.T, fn func(t *testing.T, src *MockSource, i,
// Evaluate packet statistics
stats, err := mockSrc.Stats()
require.Nil(t, err)
require.Equal(t, capture.Stats{PacketsReceived: int(n * n)}, stats)
require.Equal(t, capture.Stats{PacketsReceived: uint64(n * n)}, stats)

// Close the mock source
require.Nil(t, mockSrc.Close())
Expand Down
6 changes: 3 additions & 3 deletions capture/afpacket/afring/afring.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,9 @@ func (s *Source) Stats() (capture.Stats, error) {
return capture.Stats{}, err
}
return capture.Stats{
PacketsReceived: int(ss.Packets),
PacketsDropped: int(ss.Drops),
QueueFreezes: int(ss.QueueFreezes),
PacketsReceived: uint64(ss.Packets),
PacketsDropped: uint64(ss.Drops),
QueueFreezes: uint64(ss.QueueFreezes),
}, nil
}

Expand Down
6 changes: 3 additions & 3 deletions capture/afpacket/afring/afring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ func TestPipe(t *testing.T) {
require.Nil(t, <-errChan)
stats, err := mockSrc.Stats()
require.Nil(t, err)
require.Equal(t, capture.Stats{PacketsReceived: int(n * n)}, stats)
require.Equal(t, capture.Stats{PacketsReceived: uint64(n * n)}, stats)
require.Nil(t, mockSrc.Close())
}()

Expand Down Expand Up @@ -390,7 +390,7 @@ func TestPipe(t *testing.T) {
require.Nil(t, <-errChan2)
stats, err := mockSrc2.Stats()
require.Nil(t, err)
require.Equal(t, capture.Stats{PacketsReceived: int(n * n)}, stats)
require.Equal(t, capture.Stats{PacketsReceived: uint64(n * n)}, stats)
require.Nil(t, mockSrc2.Close())
}

Expand Down Expand Up @@ -561,7 +561,7 @@ func testCaptureMethods(t *testing.T, fn func(t *testing.T, _ *MockSource, _, _
// Evaluate packet statistics
stats, err := mockSrc.Stats()
require.Nil(t, err)
require.Equal(t, capture.Stats{PacketsReceived: int(n * n)}, stats)
require.Equal(t, capture.Stats{PacketsReceived: uint64(n * n)}, stats)

// Close the mock source
require.Nil(t, mockSrc.Close())
Expand Down
6 changes: 3 additions & 3 deletions capture/capture.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ var (

// Stats denotes a packet capture stats structure providing basic counters
type Stats struct {
PacketsReceived int
PacketsDropped int
QueueFreezes int
PacketsReceived uint64
PacketsDropped uint64
QueueFreezes uint64
}

// PacketType denotes the packet type (indicating traffic direction)
Expand Down
2 changes: 1 addition & 1 deletion capture/pcap/pcap.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Source struct {

link *link.Link

nPackets int
nPackets uint64
swapEndianess bool

packetAddCallbackFn func(payload []byte, totalLen uint32, pktType, ipLayerOffset byte)
Expand Down

0 comments on commit 6e647c8

Please sign in to comment.