mirror of
https://github.com/soypat/lneto.git
synced 2026-09-10 00:29:34 +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.
|
sysprec int8 // NTP system precision.
|
||||||
|
|
||||||
prng uint32
|
prng uint32
|
||||||
lastrecv uint16
|
|
||||||
|
totalsent uint64
|
||||||
|
totalrecv uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
type StackConfig struct {
|
type StackConfig struct {
|
||||||
@@ -71,14 +73,21 @@ func (s *StackAsync) Hostname() string {
|
|||||||
func (s *StackAsync) Demux(carrierData []byte, etherOff int) error {
|
func (s *StackAsync) Demux(carrierData []byte, etherOff int) error {
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
s.lastrecv = uint16(len(carrierData))
|
s.totalrecv += uint64(len(carrierData) - etherOff)
|
||||||
return s.link.Demux(carrierData, etherOff)
|
return s.link.Demux(carrierData, etherOff)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StackAsync) Encapsulate(carrierData []byte, etherOff int) (int, error) {
|
func (s *StackAsync) Encapsulate(carrierData []byte, etherOff int) (int, error) {
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
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 {
|
func (s *StackAsync) Reset(cfg StackConfig) error {
|
||||||
@@ -425,6 +434,16 @@ func (s *StackAsync) ResultDHCP() (*DHCPResults, error) {
|
|||||||
return &s.dhcpResults, nil
|
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:
|
// AssimilateDHCPResults sets the stack's following parameters:
|
||||||
// - IPv4 address.
|
// - IPv4 address.
|
||||||
// - DNS server.
|
// - DNS server.
|
||||||
|
|||||||
Reference in New Issue
Block a user