Skip to content

Commit

Permalink
VF stats Deserialization method and struct added. VfStats now reporte…
Browse files Browse the repository at this point in the history
…d in the VfInfo struct

Co-authored-by: PatrickKutch <patrick.kutch@gmail.com>
  • Loading branch information
root and PatrickKutch committed Oct 13, 2020
1 parent bca67df commit e870a2c
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 1 deletion.
11 changes: 11 additions & 0 deletions link.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions link_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -2916,6 +2916,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
Expand Down
59 changes: 58 additions & 1 deletion nl/link_linux.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package nl

import (
"bytes"
"encoding/binary"
"unsafe"
)

Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -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 */
Expand Down

0 comments on commit e870a2c

Please sign in to comment.