diff --git a/napalm_ios/ios.py b/napalm_ios/ios.py old mode 100755 new mode 100644 index fec06f2..c84f9c5 --- a/napalm_ios/ios.py +++ b/napalm_ios/ios.py @@ -1194,11 +1194,12 @@ def get_interfaces_counters(self): 'rx_broadcast_packets': int, Currently doesn't determine output broadcasts, multicasts - Doesn't determine tx_discards or rx_discards """ counters = {} command = 'show interfaces' output = self._send_command(command) + sh_int_sum_cmd = 'show interface summary' + sh_int_sum_cmd_out = self._send_command(sh_int_sum_cmd) # Break output into per-interface sections interface_strings = re.split(r'.* line protocol is .*', output, flags=re.M) @@ -1223,7 +1224,7 @@ def get_interfaces_counters(self): for line in interface_str.splitlines(): if 'packets input' in line: # '0 packets input, 0 bytes, 0 no buffer' - match = re.search(r"(\d+) packets input.*(\d+) bytes", line) + match = re.search(r"(\d+) packets input.* (\d+) bytes", line) counters[interface]['rx_unicast_packets'] = int(match.group(1)) counters[interface]['rx_octets'] = int(match.group(2)) elif 'broadcast' in line: @@ -1243,7 +1244,7 @@ def get_interfaces_counters(self): counters[interface]['rx_multicast_packets'] = -1 elif 'packets output' in line: # '0 packets output, 0 bytes, 0 underruns' - match = re.search(r"(\d+) packets output.*(\d+) bytes", line) + match = re.search(r"(\d+) packets output.* (\d+) bytes", line) counters[interface]['tx_unicast_packets'] = int(match.group(1)) counters[interface]['tx_octets'] = int(match.group(2)) counters[interface]['tx_broadcast_packets'] = -1 @@ -1258,6 +1259,22 @@ def get_interfaces_counters(self): match = re.search(r"(\d+) output errors", line) counters[interface]['tx_errors'] = int(match.group(1)) counters[interface]['tx_discards'] = -1 + for line in sh_int_sum_cmd_out.splitlines(): + if interface in line: + # ' Interface IHQ IQD OHQ OQD' +\ + # ' RXBS RXPS TXBS TXPS TRTL' + # '---------------------------------------------------------------' +\ + # '--------------------------------------------------' + # ' FastEthernet0 0 0 0 0' +\ + # ' 0 0 0 0 0' + regex = r"\b" + interface +\ + r"\b\s+(?P\d+)\s+(?P\d+)\s+(?P\d+)" +\ + r"\s+(?P\d+)\s+(?P\d+)\s+(?P\d+)" + \ + r"\s+(?P\d+)\s+(?P\d+)\s+(?P\d+)" + match = re.search(regex, line) + if match: + counters[interface]['rx_discards'] = int(match.group("IQD")) + counters[interface]['tx_discards'] = int(match.group("OQD")) return counters diff --git a/test/unit/mocked_data/test_get_interfaces_counters/normal/expected_result.json b/test/unit/mocked_data/test_get_interfaces_counters/normal/expected_result.json index 65e00a0..c0caca3 100644 --- a/test/unit/mocked_data/test_get_interfaces_counters/normal/expected_result.json +++ b/test/unit/mocked_data/test_get_interfaces_counters/normal/expected_result.json @@ -1,44 +1,58 @@ { "GigabitEthernet1": { - "tx_discards": -1, - "tx_broadcast_packets": -1, - "rx_multicast_packets": 0, - "tx_unicast_packets": 9297, - "rx_octets": 2, + "rx_unicast_packets": 297, + "rx_octets": 25963, "rx_broadcast_packets": 0, + "rx_multicast_packets": 0, "rx_errors": 0, - "tx_octets": 1, - "rx_discards": -1, + "rx_discards": 0, + "tx_unicast_packets": 160, + "tx_octets": 26812, + "tx_broadcast_packets": -1, "tx_multicast_packets": -1, "tx_errors": 0, - "rx_unicast_packets": 13799 + "tx_discards": 0 }, "GigabitEthernet2": { - "tx_discards": -1, - "tx_broadcast_packets": -1, - "rx_multicast_packets": 0, - "tx_unicast_packets": 154, - "rx_octets": 3, + "rx_unicast_packets": 0, + "rx_octets": 0, "rx_broadcast_packets": 0, + "rx_multicast_packets": 0, "rx_errors": 0, - "tx_octets": 7, - "rx_discards": -1, + "rx_discards": 0, + "tx_unicast_packets": 0, + "tx_octets": 0, + "tx_broadcast_packets": -1, "tx_multicast_packets": -1, "tx_errors": 0, - "rx_unicast_packets": 105 + "tx_discards": 0 }, "GigabitEthernet3": { - "tx_discards": -1, - "tx_broadcast_packets": -1, + "rx_unicast_packets": 0, + "rx_octets": 0, + "rx_broadcast_packets": 0, "rx_multicast_packets": 0, - "tx_unicast_packets": 3, + "rx_errors": 0, + "rx_discards": 0, + "tx_unicast_packets": 0, + "tx_octets": 0, + "tx_broadcast_packets": -1, + "tx_multicast_packets": -1, + "tx_errors": 0, + "tx_discards": 0 + }, + "GigabitEthernet4": { + "rx_unicast_packets": 0, "rx_octets": 0, "rx_broadcast_packets": 0, + "rx_multicast_packets": 0, "rx_errors": 0, - "tx_octets": 8, - "rx_discards": -1, + "rx_discards": 0, + "tx_unicast_packets": 0, + "tx_octets": 0, + "tx_broadcast_packets": -1, "tx_multicast_packets": -1, "tx_errors": 0, - "rx_unicast_packets": 0 + "tx_discards": 0 } -} +} \ No newline at end of file diff --git a/test/unit/mocked_data/test_get_interfaces_counters/normal/show_interface_summary.txt b/test/unit/mocked_data/test_get_interfaces_counters/normal/show_interface_summary.txt new file mode 100644 index 0000000..c83f788 --- /dev/null +++ b/test/unit/mocked_data/test_get_interfaces_counters/normal/show_interface_summary.txt @@ -0,0 +1,14 @@ + + *: interface is up + IHQ: pkts in input hold queue IQD: pkts dropped from input queue + OHQ: pkts in output hold queue OQD: pkts dropped from output queue + RXBS: rx rate (bits/sec) RXPS: rx rate (pkts/sec) + TXBS: tx rate (bits/sec) TXPS: tx rate (pkts/sec) + TRTL: throttle count + + Interface IHQ IQD OHQ OQD RXBS RXPS TXBS TXPS TRTL +----------------------------------------------------------------------------------------------------------------- +* GigabitEthernet1 0 0 0 0 0 0 0 0 0 + GigabitEthernet2 0 0 0 0 0 0 0 0 0 + GigabitEthernet3 0 0 0 0 0 0 0 0 0 + GigabitEthernet4 0 0 0 0 0 0 0 0 0 \ No newline at end of file diff --git a/test/unit/mocked_data/test_get_interfaces_counters/normal/show_interfaces.txt b/test/unit/mocked_data/test_get_interfaces_counters/normal/show_interfaces.txt index 67ce552..720ef19 100644 --- a/test/unit/mocked_data/test_get_interfaces_counters/normal/show_interfaces.txt +++ b/test/unit/mocked_data/test_get_interfaces_counters/normal/show_interfaces.txt @@ -1,6 +1,6 @@ GigabitEthernet1 is up, line protocol is up - Hardware is CSR vNIC, address is 0800.27f8.e842 (bia 0800.27f8.e842) - Internet address is 10.0.2.15/24 + Hardware is CSR vNIC, address is 00d6.b8ea.fc00 (bia 00d6.b8ea.fc00) + Internet address is 172.16.152.201/24 MTU 1500 bytes, BW 1000000 Kbit/sec, DLY 10 usec, reliability 255/255, txload 1/255, rxload 1/255 Encapsulation ARPA, loopback not set @@ -8,27 +8,26 @@ GigabitEthernet1 is up, line protocol is up Full Duplex, 1000Mbps, link type is auto, media type is RJ45 output flow-control is unsupported, input flow-control is unsupported ARP type: ARPA, ARP Timeout 04:00:00 - Last input 00:39:57, output 00:00:00, output hang never + Last input 00:03:20, output 00:03:20, output hang never Last clearing of "show interface" counters never Input queue: 0/375/0/0 (size/max/drops/flushes); Total output drops: 0 Queueing strategy: fifo Output queue: 0/40 (size/max) - 5 minute input rate 1000 bits/sec, 1 packets/sec - 5 minute output rate 1000 bits/sec, 1 packets/sec - 13799 packets input, 1748592 bytes, 0 no buffer + 5 minute input rate 0 bits/sec, 0 packets/sec + 5 minute output rate 0 bits/sec, 0 packets/sec + 297 packets input, 25963 bytes, 0 no buffer Received 0 broadcasts (0 IP multicasts) 0 runts, 0 giants, 0 throttles 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored 0 watchdog, 0 multicast, 0 pause input - 9297 packets output, 1355261 bytes, 0 underruns + 160 packets output, 26812 bytes, 0 underruns 0 output errors, 0 collisions, 0 interface resets 0 unknown protocol drops 0 babbles, 0 late collision, 0 deferred 0 lost carrier, 0 no carrier, 0 pause output 0 output buffer failures, 0 output buffers swapped out -GigabitEthernet2 is up, line protocol is up - Hardware is CSR vNIC, address is 0800.2779.e896 (bia 0800.2779.e896) - Internet address is 192.168.0.1/24 +GigabitEthernet2 is administratively down, line protocol is down + Hardware is CSR vNIC, address is 00d6.b8ea.fc01 (bia 00d6.b8ea.fc01) MTU 1500 bytes, BW 1000000 Kbit/sec, DLY 10 usec, reliability 255/255, txload 1/255, rxload 1/255 Encapsulation ARPA, loopback not set @@ -36,26 +35,26 @@ GigabitEthernet2 is up, line protocol is up Full Duplex, 1000Mbps, link type is auto, media type is RJ45 output flow-control is unsupported, input flow-control is unsupported ARP type: ARPA, ARP Timeout 04:00:00 - Last input 00:00:25, output 00:00:04, output hang never + Last input never, output never, output hang never Last clearing of "show interface" counters never Input queue: 0/375/0/0 (size/max/drops/flushes); Total output drops: 0 Queueing strategy: fifo Output queue: 0/40 (size/max) 5 minute input rate 0 bits/sec, 0 packets/sec 5 minute output rate 0 bits/sec, 0 packets/sec - 105 packets input, 10383 bytes, 0 no buffer + 0 packets input, 0 bytes, 0 no buffer Received 0 broadcasts (0 IP multicasts) 0 runts, 0 giants, 0 throttles 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored 0 watchdog, 0 multicast, 0 pause input - 154 packets output, 16467 bytes, 0 underruns - 0 output errors, 0 collisions, 1 interface resets + 0 packets output, 0 bytes, 0 underruns + 0 output errors, 0 collisions, 0 interface resets 0 unknown protocol drops 0 babbles, 0 late collision, 0 deferred 0 lost carrier, 0 no carrier, 0 pause output 0 output buffer failures, 0 output buffers swapped out GigabitEthernet3 is administratively down, line protocol is down - Hardware is CSR vNIC, address is 0800.2782.516b (bia 0800.2782.516b) + Hardware is CSR vNIC, address is 00d6.b8ea.fc02 (bia 00d6.b8ea.fc02) MTU 1500 bytes, BW 1000000 Kbit/sec, DLY 10 usec, reliability 255/255, txload 1/255, rxload 1/255 Encapsulation ARPA, loopback not set @@ -75,9 +74,36 @@ GigabitEthernet3 is administratively down, line protocol is down 0 runts, 0 giants, 0 throttles 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored 0 watchdog, 0 multicast, 0 pause input - 3 packets output, 258 bytes, 0 underruns + 0 packets output, 0 bytes, 0 underruns 0 output errors, 0 collisions, 0 interface resets 0 unknown protocol drops 0 babbles, 0 late collision, 0 deferred 0 lost carrier, 0 no carrier, 0 pause output 0 output buffer failures, 0 output buffers swapped out +GigabitEthernet4 is administratively down, line protocol is down + Hardware is CSR vNIC, address is 00d6.b8ea.fc03 (bia 00d6.b8ea.fc03) + MTU 1500 bytes, BW 1000000 Kbit/sec, DLY 10 usec, + reliability 255/255, txload 1/255, rxload 1/255 + Encapsulation ARPA, loopback not set + Keepalive set (10 sec) + Full Duplex, 1000Mbps, link type is auto, media type is RJ45 + output flow-control is unsupported, input flow-control is unsupported + ARP type: ARPA, ARP Timeout 04:00:00 + Last input never, output never, output hang never + Last clearing of "show interface" counters never + Input queue: 0/375/0/0 (size/max/drops/flushes); Total output drops: 0 + Queueing strategy: fifo + Output queue: 0/40 (size/max) + 5 minute input rate 0 bits/sec, 0 packets/sec + 5 minute output rate 0 bits/sec, 0 packets/sec + 0 packets input, 0 bytes, 0 no buffer + Received 0 broadcasts (0 IP multicasts) + 0 runts, 0 giants, 0 throttles + 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored + 0 watchdog, 0 multicast, 0 pause input + 0 packets output, 0 bytes, 0 underruns + 0 output errors, 0 collisions, 0 interface resets + 0 unknown protocol drops + 0 babbles, 0 late collision, 0 deferred + 0 lost carrier, 0 no carrier, 0 pause output + 0 output buffer failures, 0 output buffers swapped out \ No newline at end of file