Skip to content

Commit

Permalink
Merge pull request #158 from cherifimehdi/master
Browse files Browse the repository at this point in the history
Add verify_eigrp_router_id API to verify.py  ios/iosxe eigrp protocol (my old contribution) supporting EIGRPv4 and EIGRPv6 for IOS/IOSXE
  • Loading branch information
omehrabi authored Apr 8, 2024
2 parents cdaa366 + 829211d commit 85616ca
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
--------------------------------------------------------------------------------
New
--------------------------------------------------------------------------------
* IOSXE
* Added verify_eigrp_router_id to verify.py:
* New API supporting IPv4 and IPv6 to verify EIGRP router IDs
56 changes: 56 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 @@ -122,3 +122,59 @@ def verify_eigrp_neighbors(
return set(neighbors).issubset(eigrp_neighbors)
log.error(f"Please, provide a valid format for AS, Neighbors, ip and/or vrf")
continue

def verify_eigrp_router_id(
device,
router_id=None,
vrf="default",
auto_sys=None,
ip="ipv4",
max_time=60,
check_interval=10,
):
"""verify EIGRP IDs for a given vrf and auto_sys active instance for ipv4 or ipv6
Args:
device (obj): Device object
router_id = None (list): List of router ID to check
vrf = "default" (str): Name of the vrf by default set to "default"
auto_sys = None (int) : Autonomous System
ip = "ipv4" (str): Protocol ip set by default to "ipv4" to change to "ipv6"
max_time (`int`): Max time, default: 30
check_interval (`int`): Check interval, default: 10
Returns:
True
False
"""
assert isinstance(auto_sys, int), "auto_sys must be int"
assert isinstance(vrf, str), "vrf must be str"
assert isinstance(router_id, list), "router_id must be list of router IDs"
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 router_id:
try:
response = device.parse(
f"show {'ipv6' if ip!='ipv4' else 'ip'} eigrp topology"
)
except SchemaEmptyParserError:
timeout.sleep()
continue
eigrp_id = []
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:
eigrp_id = (
response.q.contains_key_value("eigrp_instance", str(auto_sys))
.contains(vrf)
.contains((ip[0:2]).upper() + ip[2:])
.get_values("eigrp_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
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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 topology:
response:
- "EIGRP-IPv4 Topology Table for AS(1)/ID(1.1.1.1)\r\nCodes: P - Passive, A\
\ - Active, U - Update, Q - Query, R - Reply,\r\n r - reply Status,\
\ s - sia Status \r\n\r\nP 192.168.2.0/24, 1 successors, FD is 25856\r\n \
\ via Redistributed (25856/0)\r\nP 192.168.1.0/24, 1 successors, FD\
\ is 28160\r\n via Connected, FastEthernet0/0\r\n\r\nEIGRP-IPv4 Topology\
\ Table for AS(2)/ID(9.9.9.9)\r\nCodes: P - Passive, A - Active, U - Update,\
\ Q - Query, R - Reply,\r\n r - reply Status, s - sia Status \r\n\r\n\
P 192.168.2.0/24, 1 successors, FD is 28160\r\n via Connected, FastEthernet1/0\r\
\nP 192.168.1.0/24, 1 successors, FD is 25856\r\n via Redistributed\
\ (25856/0)"
response_type: circular
show version: ''
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_router_id


class TestVerifyEigrpRouterId(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_router_id(self):
result = verify_eigrp_router_id(self.device, ['1.1.1.1'], 'default', 1, 'ipv4', 60, 10)
expected_output = True
self.assertEqual(result, expected_output)

0 comments on commit 85616ca

Please sign in to comment.