mirror of
https://github.com/soypat/lneto.git
synced 2026-08-13 03:13:43 +00:00
add statistics and MTU method to stack
This commit is contained in:
+23
-4
@@ -47,8 +47,10 @@ type StackAsync struct {
|
||||
|
||||
sysprec int8 // NTP system precision.
|
||||
|
||||
prng uint32
|
||||
lastrecv uint16
|
||||
prng uint32
|
||||
|
||||
totalsent uint64
|
||||
totalrecv uint64
|
||||
}
|
||||
|
||||
type StackConfig struct {
|
||||
@@ -71,14 +73,21 @@ func (s *StackAsync) Hostname() string {
|
||||
func (s *StackAsync) Demux(carrierData []byte, etherOff int) error {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
s.lastrecv = uint16(len(carrierData))
|
||||
s.totalrecv += uint64(len(carrierData) - etherOff)
|
||||
return s.link.Demux(carrierData, etherOff)
|
||||
}
|
||||
|
||||
func (s *StackAsync) Encapsulate(carrierData []byte, etherOff int) (int, error) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
return s.link.Encapsulate(carrierData, etherOff)
|
||||
|
||||
n, err := s.link.Encapsulate(carrierData, etherOff)
|
||||
s.totalsent += uint64(n)
|
||||
return n, err
|
||||
}
|
||||
|
||||
func (s *StackAsync) MTU() int {
|
||||
return s.link.MTU()
|
||||
}
|
||||
|
||||
func (s *StackAsync) Reset(cfg StackConfig) error {
|
||||
@@ -425,6 +434,16 @@ func (s *StackAsync) ResultDHCP() (*DHCPResults, error) {
|
||||
return &s.dhcpResults, nil
|
||||
}
|
||||
|
||||
type Statistics struct {
|
||||
TotalSent uint64
|
||||
TotalReceived uint64
|
||||
}
|
||||
|
||||
func (s *StackAsync) ReadStatistics(stats *Statistics) {
|
||||
stats.TotalReceived = s.totalrecv
|
||||
stats.TotalSent = s.totalsent
|
||||
}
|
||||
|
||||
// AssimilateDHCPResults sets the stack's following parameters:
|
||||
// - IPv4 address.
|
||||
// - DNS server.
|
||||
|
||||
Reference in New Issue
Block a user