Ethtool parsers

Classes to parse ethtool command information.

The interface information for a machine is stored as lists. Each interface is accessed by iterating through the shared parser list.

The interface classes all provide the following properties:

  • iface and ifname: the interface name (derived from the output file).

  • data: the data for that interface

Parsers provided by this module include:

CoalescingInfo - command /sbin/ethtool -c {interface}

Driver - command /sbin/ethtool -i {interface}

Ethtool - command /sbin/ethtool {interface}

Features - command /sbin/ethtool -k {interface}

Pause - command /sbin/ethtool -a {interface}

Ring - command /sbin/ethtool -g {interface}

Statistics - command /sbin/ethtool -S {interface}

TimeStamp - command /sbin/ethtool -T {interface}

class insights.parsers.ethtool.CoalescingInfo(context, extra_bad_lines=None)[source]

Bases: insights.core.CommandParser

Parse information for the ethtool -c command.

The parsing is fairly similar to other ethtool parsers - the interface name is available as the ifname and iface properties, and the data about the coalescing information is stored in the data property as a dictionary. The one difference is the ‘Adaptive RX’ data, which is stored as two keys - ‘adaptive-rx’ and ‘adaptive-tx’, for RX and TX respectively. Both these return a boolean for whether the respective state equals ‘on’.

Otherwise, all values are made available as keys in the data dictionary, and as properties with the hyphen transmuted to an underscore - e.g. obj.data['tx-usecs'] is available as obj.tx_usecs.

data

Dictionary of keys with values in a list.

Type

dict

iface

Interface name.

Type

str

Sample input for /sbin/ethtool -c eth0:

Coalesce parameters for eth0:
Adaptive RX: off  TX: off
stats-block-usecs: 0
sample-interval: 0
pkt-rate-low: 0
pkt-rate-high: 0

rx-usecs: 20
rx-frames: 5
rx-usecs-irq: 0
rx-frames-irq: 5

tx-usecs: 72
tx-frames: 53
tx-usecs-irq: 0
tx-frames-irq: 5

rx-usecs-low: 0
rx-frame-low: 0
tx-usecs-low: 0
tx-frame-low: 0

rx-usecs-high: 0
rx-frame-high: 0
tx-usecs-high: 0
tx-frame-high: 0

Examples

>>> len(coalesce) # All interfaces in a list
1
>>> type(coalesce[0])
<class 'insights.parsers.ethtool.CoalescingInfo'>
>>> eth0 = coalesce[0] # Would normally iterate through interfaces
>>> eth0.iface
'eth0'
>>> eth0.ifname
'eth0'
>>> eth0.data['adaptive-rx'] # Old-style accessor
False
>>> eth0.adaptive_rx # New-style accessor
False
>>> eth0.rx_usecs # Note integer value
20
property ifname

the interface name

Type

(str)

parse_content(content)[source]

Parse the output of ethtool -c into a dictionary.

If ethtool -c outputs an error or could not get the pause state for the device, the “iface” property will be set but the data dictionary will be blank.

class insights.parsers.ethtool.Driver(context, extra_bad_lines=None)[source]

Bases: insights.core.CommandParser

Parse information for the ethtool -i command.

All the ethtool -i outputs are stored as a list, in no particular order.

Each driver is stored as a dictionary in the data property. If the key starts with ‘supports’, then the value is a boolean test of whether the string is ‘yes’. If the value is not given on the string (e.g. ‘bus-info:’), the value is set to None.

All data is also set as attributes of the object with the attribute name being the key name with hyphens replaced with underscores.

data

Dictionary of keys with values in a list.

Type

dict

iface

Interface name.

Type

str

driver

The driver providing the interface.

Type

str

version

The version of the interface driver.

Type

str

firmware_version

The firmware version of the interface.

Type

str

supports_statistics

Does the interface support statistics gathering?

Type

bool

supports_test

Does the interface support internal self-tests?

Type

bool

supports_eeprom_access

Does the interface support access to the EEPROM?

Type

bool

supports_register_dump

Does the interface support dumping the internal registers?

Type

bool

supports_priv_flags

Does the interface support use of privileged flags?

Type

bool

Sample input for /sbin/ethtool -i bond0:

driver: bonding
version: 3.6.0
firmware-version: 2
bus-info:
supports-statistics: no
supports-test: no
supports-eeprom-access: no
supports-register-dump: no
supports-priv-flags: no
Examples::
>>> len(interfaces) # All interfaces in a list
1
>>> type(interfaces[0])
<class 'insights.parsers.ethtool.Driver'>
>>> bond0 = interfaces[0] # Would normally iterate through interfaces
>>> bond0.iface
'bond0'
>>> bond0.ifname
'bond0'
>>> bond0.data['driver'] # Old-style access
'bonding'
>>> bond0.driver # New-style access
'bonding'
>>> hasattr(bond0, 'bus_info')
True
>>> bond0.bus_info is None
True
>>> bond0.supports_statistics
False
property ifname

the interface name

Type

(str)

parse_content(content)[source]

This method must be implemented by classes based on this class.

class insights.parsers.ethtool.Ethtool(context, extra_bad_lines=None)[source]

Bases: insights.core.CommandParser

Parses output of ethtool command.

Raises

ParseException -- Raised when any problem parsing the command output.

data

Dictionary of keys with values in a list.

Type

dict

iface

Interface name.

Type

str

A list of the ‘Supported link modes’ values, split into individual words.

Type

list

A list of the ‘Available link modes’ values, split into individual words.

Type

list

supported_ports

A list of the ‘Supported ports’ values, split into individual words.

Type

list

Sample input:

Settings for eth0:
        Supported ports: [ TP MII ]
        Supported link modes:   10baseT/Half 10baseT/Full
                               100baseT/Half 100baseT/Full
        Supported pause frame use: No
        Supports auto-negotiation: Yes
        Advertised link modes:  10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
        Advertised pause frame use: Symmetric
        Advertised auto-negotiation: Yes
        Link partner advertised link modes:  10baseT/Half 10baseT/Full
                                             100baseT/Half 100baseT/Full
        Link partner advertised pause frame use: Symmetric
        Link partner advertised auto-negotiation: No
        Speed: 100Mb/s
        Duplex: Full
        Port: MII
        PHYAD: 32
        Transceiver: internal
        Auto-negotiation: on
Cannot get wake-on-lan settings: Operation not permitted
        Current message level: 0x00000007 (7)
                               drv probe link
Cannot get link status: Operation not permitted

For historic reasons, values drawn from the data are stored as lists, with each item being the value on one line.

Examples

>>> len(ethers) # All interfaces in a list
1
>>> type(ethers[0])
<class 'insights.parsers.ethtool.Ethtool'>
>>> ethinfo = ethers[0] # Would normally iterate through interfaces
>>> ethinfo.ifname
'eth0'
>>> ethinfo.speed
['100Mb/s']
>>> ethinfo.link_detected
False
>>> 'Cannot get link status' in ethinfo.data
True
>>> ethinfo.data['Cannot get link status']  # Dictionary for all data
['Operation not permitted']
>>> ethinfo.data['Supported pause frame use']
['No']
>>> ethinfo.data['PHYAD']  # Values as lists of strings for historic reasons
['32']
>>> ethinfo.supported_link_modes  # This is collected across multiple lines and split
['10baseT/Half', '10baseT/Full', '100baseT/Half', '100baseT/Full']
>>> ethinfo.advertised_link_modes
['10baseT/Half', '10baseT/Full', '100baseT/Half', '100baseT/Full']
>>> ethinfo.supported_ports  # This is converted to a list of strings
['TP', 'MII']
property ifname

Return the name of network interface in content.

Type

str

Returns field in Link detected.

Type

boolean

parse_content(content)[source]

This method must be implemented by classes based on this class.

property speed

Return field in Speed.

Type

list (str)

class insights.parsers.ethtool.Features(context, extra_bad_lines=None)[source]

Bases: insights.core.LegacyItemAccess, insights.core.CommandParser

Parse information for the ethtool -k command.

Features are stored as a flat set of key: value pairs, with no hierarchy that the indentation of the input might imply. This means, that the output below will provide data for ‘tx-checksumming’ and ‘tx-checksum-ipv4’.

Each key stores a two-key dictionary:

  • ‘on’ (boolean) - whether the value (before any ‘[fixed]’) is ‘on’.

  • ‘fixed’ (boolean) - whether the value contains ‘fixed’.

data

Dictionary of keys with values in a list.

Type

dict

iface

Interface name.

Type

str

Sample input for /sbin/ethtool -k bond0:

Features for bond0:
rx-checksumming: off [fixed]
tx-checksumming: on
    tx-checksum-ipv4: off [fixed]
    tx-checksum-unneeded: on [fixed]
    tx-checksum-ip-generic: off [fixed]
    tx-checksum-ipv6: off [fixed]
    tx-checksum-fcoe-crc: off [fixed]
    tx-checksum-sctp: off [fixed]
scatter-gather: on
    tx-scatter-gather: on [fixed]
    tx-scatter-gather-fraglist: off [fixed]
tcp-segmentation-offload: on
    tx-tcp-segmentation: on [fixed]
    tx-tcp-ecn-segmentation: on [fixed]
    tx-tcp6-segmentation: on [fixed]
udp-fragmentation-offload: off [fixed]
generic-segmentation-offload: off [requested on]
generic-receive-offload: on
large-receive-offload: on
rx-vlan-offload: on
tx-vlan-offload: on
ntuple-filters: off
receive-hashing: off
highdma: on [fixed]
rx-vlan-filter: on [fixed]
vlan-challenged: off [fixed]
tx-lockless: on [fixed]
netns-local: off [fixed]
tx-gso-robust: off [fixed]
tx-fcoe-segmentation: off [fixed]
tx-gre-segmentation: on [fixed]
tx-udp_tnl-segmentation: on [fixed]
fcoe-mtu: off [fixed]
loopback: off [fixed]

Examples

>>> len(features) # All interfaces in a list
1
>>> type(features[0])
<class 'insights.parsers.ethtool.Features'>
>>> bond0 = features[0] # Would normally iterate through interfaces
>>> bond0.iface
'bond0'
>>> bond0.ifname
'bond0'
>>> bond0.data['rx-vlan-offload']['on'] # Traditional access
True
>>> bond0.data['rx-vlan-offload']['fixed']
False
>>> bond0.data['tx-checksum-sctp']['on']
False
>>> bond0.data['tx-checksum-sctp']['fixed']
True
>>> bond0.is_on('ntuple-filters')
False
>>> bond0.is_on('large-receive-offload')
True
>>> bond0.is_fixed('receive-hashing')
False
>>> bond0.is_fixed('fcoe-mtu')
True
property ifname

the interface name

Type

(str)

is_fixed(feature)[source]

(bool): Does this feature exist and is it fixed?

is_on(feature)[source]

(bool): Does this feature exist and is it on?

parse_content(content)[source]

This method must be implemented by classes based on this class.

class insights.parsers.ethtool.Pause(context, extra_bad_lines=None)[source]

Bases: insights.core.CommandParser

Parse information for the ethtool -a command.

Each parameter in the input is stored as a key in a dictionary, with the value being whether the found string equals ‘on’.

data

Dictionary of keys with values in a list.

Type

dict

iface

Interface name.

Type

str

autonegotiate

Is autonegotiate present and set to ‘on’?

Type

bool

rx

Is receive pausing present and set to ‘on’?

Type

bool

tx

Is transmit pausing present and set to ‘on’?

Type

bool

rx_negotiated

Is receive pause autonegotiate present and set to ‘on’?

Type

bool

tx_negotiated

Is transmit pause autonegotiate present and set to ‘on’?

Type

bool

Sample input from /sbin/ethtool -a 0:

Pause parameters for eth0:
Autonegotiate:  on
RX:             on
TX:             on
RX negotiated:  off
TX negotiated:  off

Examples

>>> len(pause) # All interfaces in a list
1
>>> type(pause[0])
<class 'insights.parsers.ethtool.Pause'>
>>> eth0 = pause[0] # Would normally iterate through interfaces
>>> eth0.iface
'eth0'
>>> eth0.ifname
'eth0'
>>> eth0.data['RX'] # Old-style accessor
True
>>> eth0.autonegotiate # New-style accessor
True
>>> eth0.rx_negotiated
False
parse_content(content)[source]

Return ethtool -a result as a dict.

If ethtool -a outputs an error or could not get the pause state for the device, the “iface” property will be set but the data dictionary will be blank and all properties will return False.

class insights.parsers.ethtool.Ring(context, extra_bad_lines=None)[source]

Bases: insights.core.CommandParser

Parse information for the ethtool -g command.

In addition to the standard iface and ifname parameters, as well as being available in the data property, the interface statistics are accessed using two parameters: max and current. Within each the interface settings are available as four parameters - rx, rx_mini, rx_jumbo and tx.

data

Dictionary of keys with values in a list.

Type

dict

iface

Interface name.

Type

str

max

Dictonary of maximum ring buffer settings.

Type

dict

current

Dictionary of current ring buffer settings.

Type

dict

Sample input for /sbin/ethtool -g eth0:

Ring parameters for eth0:
Pre-set maximums:
RX:             2047
RX Mini:        0
RX Jumbo:       0
TX:             511
Current hardware settings:
RX:             200
RX Mini:        0
RX Jumbo:       0
TX:             511

Examples

>>> len(ring) # All interfaces in a list
1
>>> type(ring[0])
<class 'insights.parsers.ethtool.Ring'>
>>> eth0 = ring[0] # Would normally iterate through interfaces
>>> eth0.iface
'eth0'
>>> eth0.ifname
'eth0'
>>> eth0.data['max'].rx # Old-style access
2047
>>> eth0.max.rx # New-style access
2047
class Parameters(rx, rx_mini, rx_jumbo, tx)

Bases: tuple

property rx
property rx_jumbo
property rx_mini
property tx
property ifname

Return the name of network interface in content.

parse_content(content)[source]

Parse ethtool -g info into a dictionary.

class insights.parsers.ethtool.Statistics(context, extra_bad_lines=None)[source]

Bases: insights.core.CommandParser

Parse information for the ethtool -S command.

All values are made available as keys in the data dictionary, and as properties - e.g. obj.data['rx_jabbers'] is available as obj.rx_jabbers.

data

Dictionary of keys with values in a list.

Type

dict

iface

Interface name.

Type

str

Sample partial input for /sbin/ethtool -S eth0:

NIC statistics:
     rx_octets: 808488730
     rx_fragments: 0
     rx_ucast_packets: 1510830
     rx_mcast_packets: 678653
     rx_bcast_packets: 9921
     rx_fcs_errors: 0
     rx_align_errors: 0
     rx_xon_pause_rcvd: 0
     rx_xoff_pause_rcvd: 0
     rx_mac_ctrl_rcvd: 0
     rx_xoff_entered: 0
     rx_frame_too_long_errors: 0
     rx_jabbers: 0

Examples

>>> len(stats) # All interfaces in a list
1
>>> type(stats[0])
<class 'insights.parsers.ethtool.Statistics'>
>>> eth0 = stats[0] # Would normally iterate through interfaces
>>> eth0.iface
'eth0'
>>> eth0.ifname
'eth0'
>>> eth0.data['rx_octets']  # Data as integers
808488730
>>> eth0.data['rx_fcs_errors']
0
property ifname

Return the name of network interface in content.

parse_content(content)[source]

Parse the output of ethtool -S.

search(pattern, flags=0)[source]

Finds all the parameters matching a given regular expression.

Parameters
  • pattern (raw) -- A regular expression

  • flags (int) -- Regular expression flags summed from re constants.

Returns

A dictionary of the key/value pairs where the key matches the given regular expression. An empty dictionary is returned if no keys matched.

Return type

(dict)

class insights.parsers.ethtool.TimeStamp(context, extra_bad_lines=None)[source]

Bases: insights.core.CommandParser

Parse information for the ethtool -T command.

Each parameter in the input is stored as a key in a dictionary.

data

Dictionary of keys with values.

Type

dict

Raises

ParseException -- Raised when any problem parsing the command output.

Sample partial input for /sbin/ethtool -T eno1:

Time stamping parameters for eno1:

Capabilities:
    hardware-transmit     (SOF_TIMESTAMPING_TX_HARDWARE)
    software-transmit     (SOF_TIMESTAMPING_TX_SOFTWARE)
    hardware-receive      (SOF_TIMESTAMPING_RX_HARDWARE)
    software-receive      (SOF_TIMESTAMPING_RX_SOFTWARE)
    software-system-clock (SOF_TIMESTAMPING_SOFTWARE)
    hardware-raw-clock    (SOF_TIMESTAMPING_RAW_HARDWARE)
PTP Hardware Clock: 0
Hardware Transmit Timestamp Modes:
    off                   (HWTSTAMP_TX_OFF)
    on                    (HWTSTAMP_TX_ON)
Hardware Receive Filter Modes:
    none                  (HWTSTAMP_FILTER_NONE)
    all                   (HWTSTAMP_FILTER_ALL)

Examples

>>> len(timestamp)
1
>>> type(timestamp[0])
<class 'insights.parsers.ethtool.TimeStamp'>
>>> eno1 = timestamp[0] # Would normally iterate through interfaces
>>> eno1.ifname
'eno1'
>>> eno1.data['Capabilities']['hardware-transmit']
'SOF_TIMESTAMPING_TX_HARDWARE'
>>> eno1.data['Capabilities']['hardware-raw-clock']
'SOF_TIMESTAMPING_RAW_HARDWARE'
>>> eno1.data['PTP Hardware Clock']
'0'
>>> eno1.data['Hardware Transmit Timestamp Modes']['off']
'HWTSTAMP_TX_OFF'
>>> eno1.data['Hardware Receive Filter Modes']['all']
'HWTSTAMP_FILTER_ALL'
property ifname

the interface name

Type

(str)

parse_content(content)[source]

This method must be implemented by classes based on this class.

insights.parsers.ethtool.extract_iface_name_from_content(content)[source]

Extract the interface name from the third item in the content, delimited by spaces, up to its second-last character. For example, this transmutes Features for bond0: to bond0.

insights.parsers.ethtool.extract_iface_name_from_path(path, name)[source]

Extract the ‘real’ interface name from the path name. Basically this puts the ‘@’ back in the name in place of the underscore, where the name contains a ‘.’ or contains ‘macvtap’ or ‘macvlan’.

Examples:

real name

path name

bond0.104@bond0

bond0.104_bond0

__tmp1111

__tmp1111

macvtap@bond0

macvlan_bond0

prod_bond

prod_bond