Skip to content

Commit

Permalink
Merge pull request #165 from cherifimehdi/master
Browse files Browse the repository at this point in the history
Add verify_eigrp_interfaces_timers API to verify.py ios/iosxe eigrp protocol
  • Loading branch information
lsheikal authored Jul 15, 2024
2 parents 9e1343b + b12c94c commit 9ee3d5c
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
--------------------------------------------------------------------------------
New
--------------------------------------------------------------------------------
* IOSXE
* Added verify_eigrp_interfaces_timers to verify.py:
* New API supporting IPv4 and IPv6 to verify EIGRP interfaces timers
70 changes: 70 additions & 0 deletions pkgs/sdk-pkg/src/genie/libs/sdk/apis/iosxe/eigrp/verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,73 @@ def verify_eigrp_router_id(
return set(router_id).issubset(eigrp_id)
log.error(f"Please, provid a valid format for auto_sys, router_id, vrf and/or ip")
continue

def verify_eigrp_interfaces_timers(
device,
timers_dict=None,
vrf="default",
auto_sys=None,
ip="ipv4",
max_time=60,
check_interval=10,
):
"""Verify hello interval and hold time of interfaces for a given vrf and active auto_sys for ipv4 or ipv6
Args:
device (obj): Device object
timers_dict (dict): dict to verify containing interfaces with their hello interval and hold time
# ex.) timers_dict = {'FastEthernet0/0': [{'hello_interval': 5}, {'hold_time': 15}]}
vrf (str) : Name of the vrf by default set to "default"
auto_sys (int) : Autonomous System
ip (str): Protocol ip, default: "ipv4" to change to "ipv6"
max_time (`int`): Max time, default: 30
check_interval (`int`): Check interval, default: 10
Returns:
result (bool): Verified result
"""
assert isinstance(auto_sys, int), "auto_sys must be int"
assert isinstance(vrf, str), "vrf must be str"
assert isinstance(timers_dict, dict), "timers_dict must be dict"
assert auto_sys != 0, "auto_sys must not be 0"
assert ip in ["ipv4", "ipv6"], "ip must be ipv4 or ipv6"
timeout = Timeout(max_time, check_interval)
while timeout.iterate():
if auto_sys and timers_dict:
try:
response = device.parse(
f"show {'ipv6' if ip!='ipv4' else 'ip'} eigrp interfaces detail"
)
except SchemaEmptyParserError:
timeout.sleep()
continue
inter_timers = {}
if (vrf not in response.q.get_values("vrf")) or (
str(auto_sys) not in response.q.get_values("eigrp_instance")
):
log.error(
f"Sorry, no data for the provided for 'auto_sys = {auto_sys}' and/or 'vrf = {vrf}'"
)
else:
interfaces = (
response.q.contains(vrf)
.contains_key_value("eigrp_instance", str(auto_sys))
.contains(ip)
.get_values("interface")
)
for interface in interfaces:
hello_interval = {
"hello_interval": (
response.q.contains(interface).get_values("hello_interval")
)[0]
}
hold_time = {
"hold_time": (
response.q.contains(interface).get_values("hold_time")
)[0]
}
inter_timers[interface] = [hello_interval, hold_time]
return set(timers_dict).issubset(inter_timers)
log.error(
f"Please, provide a valid format for auto_sys, timers_dict, vrf and/or ip"
)
continue

Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
configure:
commands:
end:
new_state: execute
line console 0:
new_state: configure_line
no logging console: ''
prompt: R1(config)#
configure_line:
commands:
end:
new_state: execute
exec-timeout 0: ''
prompt: R1(config-line)#
connect:
commands:
? ''
: new_state: execute
preface: 'Trying mock_device ...
Connected to mock_device.
Escape character is ''^]''.'
prompt: ''
execute:
commands:
config term:
new_state: configure
config-transaction:
new_state: configure
show ip eigrp interfaces detail:
response:
- "EIGRP-IPv4 Interfaces for AS(1)\r\n Xmit Queue\
\ PeerQ Mean Pacing Time Multicast Pending\r\nInterface \
\ Peers Un/Reliable Un/Reliable SRTT Un/Reliable Flow Timer\
\ Routes\r\nFa0/0 1 0/0 0/0 60\
\ 0/0 50 0\r\n Hello-interval is 5, Hold-time is\
\ 15\r\n Split-horizon is enabled\r\n Next xmit serial <none>\r\n Packetized\
\ sent/expedited: 1/0\r\n Hello's sent/expedited: 74/2\r\n Un/reliable mcasts:\
\ 0/1 Un/reliable ucasts: 1/2\r\n Mcast exceptions: 0 CR packets: 0 ACKs\
\ suppressed: 0\r\n Retransmissions sent: 1 Out-of-sequence rcvd: 0\r\n\
\ Topology-ids on interface - 0 \r\n Authentication mode is not set\r\n\
EIGRP-IPv4 Interfaces for AS(2)\r\n Xmit Queue\
\ PeerQ Mean Pacing Time Multicast Pending\r\nInterface \
\ Peers Un/Reliable Un/Reliable SRTT Un/Reliable Flow Timer\
\ Routes\r\nFa1/0 1 0/0 0/0 164\
\ 0/0 50 0\r\n Hello-interval is 5, Hold-time is\
\ 15\r\n Split-horizon is enabled\r\n Next xmit serial <none>\r\n Packetized\
\ sent/expedited: 1/0\r\n Hello's sent/expedited: 75/2\r\n Un/reliable mcasts:\
\ 0/1 Un/reliable ucasts: 1/2\r\n Mcast exceptions: 0 CR packets: 0 ACKs\
\ suppressed: 0\r\n Retransmissions sent: 1 Out-of-sequence rcvd: 1\r\n\
\ Topology-ids on interface - 0 \r\n Authentication mode is not set"
response_type: circular
show version: ''
show version | include operating mode: ''
term length 0: ''
term width 0: ''
prompt: R1#
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import os
import unittest
from pyats.topology import loader
from genie.libs.sdk.apis.iosxe.eigrp.verify import verify_eigrp_interfaces_timers


class TestVerifyEigrpInterfacesTimers(unittest.TestCase):

@classmethod
def setUpClass(self):
testbed = f"""
devices:
R1:
connections:
defaults:
class: unicon.Unicon
a:
command: mock_device_cli --os iosxe --mock_data_dir {os.path.dirname(__file__)}/mock_data --state connect
protocol: unknown
os: iosxe
platform: iosxe
type: iosxe
"""
self.testbed = loader.load(testbed)
self.device = self.testbed.devices['R1']
self.device.connect(
learn_hostname=True,
init_config_commands=[],
init_exec_commands=[]
)

def test_verify_eigrp_interfaces_timers(self):
result = verify_eigrp_interfaces_timers(self.device, {'FastEthernet0/0': [{'hello_interval': 5}, {'hold_time': 15}]}, 'default', 1, 'ipv4', 60, 10)
expected_output = True
self.assertEqual(result, expected_output)

0 comments on commit 9ee3d5c

Please sign in to comment.