mirror of
https://github.com/vishvananda/netlink
synced 2025-02-19 13:46:57 +00:00
VF stats struct and deserialization method added. VfStats now reported in the VfInfo struct
Co-authored-by: PatrickKutch <patrick.kutch@gmail.com>
This commit is contained in:
parent
abd6d09710
commit
e30b76407c
11
link.go
11
link.go
@ -65,6 +65,17 @@ type VfInfo struct {
|
||||
LinkState uint32
|
||||
MaxTxRate uint32 // IFLA_VF_RATE Max TxRate
|
||||
MinTxRate uint32 // IFLA_VF_RATE Min TxRate
|
||||
RxPackets uint64
|
||||
TxPackets uint64
|
||||
RxBytes uint64
|
||||
TxBytes uint64
|
||||
Multicast uint64
|
||||
Broadcast uint64
|
||||
RxDropped uint64
|
||||
TxDropped uint64
|
||||
|
||||
RssQuery uint32
|
||||
Trust uint32
|
||||
}
|
||||
|
||||
// LinkOperState represents the values of the IFLA_OPERSTATE link
|
||||
|
@ -2996,6 +2996,23 @@ func parseVfInfo(data []syscall.NetlinkRouteAttr, id int) VfInfo {
|
||||
vfr := nl.DeserializeVfRate(element.Value[:])
|
||||
vf.MaxTxRate = vfr.MaxTxRate
|
||||
vf.MinTxRate = vfr.MinTxRate
|
||||
case nl.IFLA_VF_STATS:
|
||||
vfstats := nl.DeserializeVfStats(element.Value[:])
|
||||
vf.RxPackets = vfstats.RxPackets
|
||||
vf.TxPackets = vfstats.TxPackets
|
||||
vf.RxBytes = vfstats.RxBytes
|
||||
vf.Multicast = vfstats.Multicast
|
||||
vf.Broadcast = vfstats.Broadcast
|
||||
vf.RxDropped = vfstats.RxDropped
|
||||
vf.TxDropped = vfstats.TxDropped
|
||||
|
||||
case nl.IFLA_VF_RSS_QUERY_EN:
|
||||
result := nl.DeserializeVfRssQueryEn(element.Value)
|
||||
vf.RssQuery = result.Setting
|
||||
|
||||
case nl.IFLA_VF_TRUST:
|
||||
result := nl.DeserializeVfTrust(element.Value)
|
||||
vf.Trust = result.Setting
|
||||
}
|
||||
}
|
||||
return vf
|
||||
|
@ -1,6 +1,8 @@
|
||||
package nl
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
@ -243,7 +245,9 @@ const (
|
||||
IFLA_VF_STATS_TX_BYTES
|
||||
IFLA_VF_STATS_BROADCAST
|
||||
IFLA_VF_STATS_MULTICAST
|
||||
IFLA_VF_STATS_MAX = IFLA_VF_STATS_MULTICAST
|
||||
IFLA_VF_STATS_RX_DROPPED
|
||||
IFLA_VF_STATS_TX_DROPPED
|
||||
IFLA_VF_STATS_MAX = IFLA_VF_STATS_TX_DROPPED
|
||||
)
|
||||
|
||||
const (
|
||||
@ -326,6 +330,59 @@ func (msg *VfTxRate) Serialize() []byte {
|
||||
return (*(*[SizeofVfTxRate]byte)(unsafe.Pointer(msg)))[:]
|
||||
}
|
||||
|
||||
//struct ifla_vf_stats {
|
||||
// __u64 rx_packets;
|
||||
// __u64 tx_packets;
|
||||
// __u64 rx_bytes;
|
||||
// __u64 tx_bytes;
|
||||
// __u64 broadcast;
|
||||
// __u64 multicast;
|
||||
//};
|
||||
|
||||
type VfStats struct {
|
||||
RxPackets uint64
|
||||
TxPackets uint64
|
||||
RxBytes uint64
|
||||
TxBytes uint64
|
||||
Multicast uint64
|
||||
Broadcast uint64
|
||||
RxDropped uint64
|
||||
TxDropped uint64
|
||||
}
|
||||
|
||||
func DeserializeVfStats(b []byte) VfStats {
|
||||
var vfstat VfStats
|
||||
stats, err := ParseRouteAttr(b)
|
||||
if err != nil {
|
||||
return vfstat
|
||||
}
|
||||
var valueVar uint64
|
||||
for _, stat := range stats {
|
||||
if err := binary.Read(bytes.NewBuffer(stat.Value), NativeEndian(), &valueVar); err != nil {
|
||||
break
|
||||
}
|
||||
switch stat.Attr.Type {
|
||||
case IFLA_VF_STATS_RX_PACKETS:
|
||||
vfstat.RxPackets = valueVar
|
||||
case IFLA_VF_STATS_TX_PACKETS:
|
||||
vfstat.TxPackets = valueVar
|
||||
case IFLA_VF_STATS_RX_BYTES:
|
||||
vfstat.RxBytes = valueVar
|
||||
case IFLA_VF_STATS_TX_BYTES:
|
||||
vfstat.TxBytes = valueVar
|
||||
case IFLA_VF_STATS_MULTICAST:
|
||||
vfstat.Multicast = valueVar
|
||||
case IFLA_VF_STATS_BROADCAST:
|
||||
vfstat.Broadcast = valueVar
|
||||
case IFLA_VF_STATS_RX_DROPPED:
|
||||
vfstat.RxDropped = valueVar
|
||||
case IFLA_VF_STATS_TX_DROPPED:
|
||||
vfstat.TxDropped = valueVar
|
||||
}
|
||||
}
|
||||
return vfstat
|
||||
}
|
||||
|
||||
// struct ifla_vf_rate {
|
||||
// __u32 vf;
|
||||
// __u32 min_tx_rate; /* Min Bandwidth in Mbps */
|
||||
|
Loading…
Reference in New Issue
Block a user