Skip to content
This repository has been archived by the owner on Jan 16, 2019. It is now read-only.

Commit

Permalink
Merge pull request #118 from jorgenbl/develop
Browse files Browse the repository at this point in the history
Fix broken regex and add support for discarded packets in get_interfaces_counters
  • Loading branch information
ktbyers authored Mar 7, 2017
2 parents b123c8b + fca5890 commit 36e7491
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 42 deletions.
23 changes: 20 additions & 3 deletions napalm_ios/ios.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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<IHQ>\d+)\s+(?P<IQD>\d+)\s+(?P<OHQ>\d+)" +\
r"\s+(?P<OQD>\d+)\s+(?P<RXBS>\d+)\s+(?P<RXPS>\d+)" + \
r"\s+(?P<TXBS>\d+)\s+(?P<TXPS>\d+)\s+(?P<TRTL>\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

Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
}
}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1,61 +1,60 @@
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
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 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
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 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
Expand All @@ -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

0 comments on commit 36e7491

Please sign in to comment.