Skip to content

Commit

Permalink
Add SACKs sent and packets stats
Browse files Browse the repository at this point in the history
  • Loading branch information
edaniels committed Feb 28, 2024
1 parent a5583a6 commit 93366c4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
15 changes: 11 additions & 4 deletions association.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,11 @@ func (a *Association) Close() error {
<-a.readLoopCloseCh

a.log.Debugf("[%s] association closed", a.name)
a.log.Debugf("[%s] stats nPackets (in) : %d", a.name, a.stats.getNumPackets())
a.log.Debugf("[%s] stats nPackets (out) : %d", a.name, a.stats.getNumPacketsSent())
a.log.Debugf("[%s] stats nDATAs (in) : %d", a.name, a.stats.getNumDATAs())
a.log.Debugf("[%s] stats nSACKs (in) : %d", a.name, a.stats.getNumSACKs())
a.log.Debugf("[%s] stats nSACKs (out) : %d\n", a.name, a.stats.getNumSACKsSent())
a.log.Debugf("[%s] stats nT3Timeouts : %d", a.name, a.stats.getNumT3Timeouts())
a.log.Debugf("[%s] stats nAckTimeouts: %d", a.name, a.stats.getNumAckTimeouts())
a.log.Debugf("[%s] stats nFastRetrans: %d", a.name, a.stats.getNumFastRetrans())
Expand Down Expand Up @@ -590,6 +593,7 @@ loop:
break loop
}
atomic.AddUint64(&a.bytesSent, uint64(len(raw)))
a.stats.incPacketsSent()
}

if !ok {
Expand Down Expand Up @@ -664,15 +668,15 @@ func (a *Association) handleInbound(raw []byte) error {
return nil
}

a.handleChunkStart()
a.handleChunksStart()

for _, c := range p.chunks {
if err := a.handleChunk(p, c); err != nil {
return err
}
}

a.handleChunkEnd()
a.handleChunksEnd()

return nil
}
Expand Down Expand Up @@ -819,6 +823,7 @@ func (a *Association) gatherOutboundSackPackets(rawPackets [][]byte) [][]byte {
if a.ackState == ackStateImmediate {
a.ackState = ackStateIdle
sack := a.createSelectiveAckChunk()
a.stats.incSACKsSent()
a.log.Debugf("[%s] sending SACK: %s", a.name, sack)
raw, err := a.marshalPacket(a.createPacket([]chunk{sack}))
if err != nil {
Expand Down Expand Up @@ -2373,15 +2378,17 @@ func pack(p *packet) []*packet {
return []*packet{p}
}

func (a *Association) handleChunkStart() {
func (a *Association) handleChunksStart() {
a.lock.Lock()
defer a.lock.Unlock()

a.stats.incPackets()

a.delayedAckTriggered = false
a.immediateAckTriggered = false
}

func (a *Association) handleChunkEnd() {
func (a *Association) handleChunksEnd() {
a.lock.Lock()
defer a.lock.Unlock()

Expand Down
30 changes: 30 additions & 0 deletions association_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,32 @@ import (
)

type associationStats struct {
nPackets uint64
nPacketsSent uint64
nDATAs uint64
nSACKs uint64
nSACKsSent uint64
nT3Timeouts uint64
nAckTimeouts uint64
nFastRetrans uint64
}

func (s *associationStats) incPackets() {
atomic.AddUint64(&s.nPackets, 1)
}

func (s *associationStats) getNumPackets() uint64 {
return atomic.LoadUint64(&s.nPackets)
}

func (s *associationStats) incPacketsSent() {
atomic.AddUint64(&s.nPacketsSent, 1)
}

func (s *associationStats) getNumPacketsSent() uint64 {
return atomic.LoadUint64(&s.nPacketsSent)
}

func (s *associationStats) incDATAs() {
atomic.AddUint64(&s.nDATAs, 1)
}
Expand All @@ -31,6 +50,14 @@ func (s *associationStats) getNumSACKs() uint64 {
return atomic.LoadUint64(&s.nSACKs)
}

func (s *associationStats) incSACKsSent() {
atomic.AddUint64(&s.nSACKsSent, 1)
}

func (s *associationStats) getNumSACKsSent() uint64 {
return atomic.LoadUint64(&s.nSACKsSent)
}

func (s *associationStats) incT3Timeouts() {
atomic.AddUint64(&s.nT3Timeouts, 1)
}
Expand All @@ -56,8 +83,11 @@ func (s *associationStats) getNumFastRetrans() uint64 {
}

func (s *associationStats) reset() {
atomic.StoreUint64(&s.nPackets, 0)
atomic.StoreUint64(&s.nPacketsSent, 0)
atomic.StoreUint64(&s.nDATAs, 0)
atomic.StoreUint64(&s.nSACKs, 0)
atomic.StoreUint64(&s.nSACKsSent, 0)
atomic.StoreUint64(&s.nT3Timeouts, 0)
atomic.StoreUint64(&s.nAckTimeouts, 0)
atomic.StoreUint64(&s.nFastRetrans, 0)
Expand Down

0 comments on commit 93366c4

Please sign in to comment.