[Day #75 PyATS Series] Verify Interface Speed/Duplex Consistency Using pyATS for Cisco [Python for Network Engineer]
Table of Contents
Introduction on the Key Points
Maintaining interface speed and duplex consistency is fundamental in network operations to prevent bottlenecks, collisions, and degraded performance. Mismatches between connected devices can cause intermittent connectivity issues, high CPU utilization, and packet loss.
In this masterclass, we’ll explore how to automate interface speed and duplex consistency validation using pyATS, with a focus on Cisco IOS devices. This is a critical skill for network engineers who want to adopt automation and remove manual error-prone CLI checks.
We’ll build a step-by-step pyATS workflow that connects to a Cisco switch, extracts interface configurations, validates against expected configurations, and provides actionable PASS/FAIL reports. Both CLI and GUI validations are considered, delivering a complete auditing solution.
If you’re advancing your career toward Python for Network Engineer roles, this guide equips you with practical automation templates ready to integrate into daily operations and compliance checks.
Topology Overview
Our lab setup for interface consistency validation:

- Cisco Catalyst 9300 acts as the managed device.
- The automation server runs pyATS to interact via SSH.
- Multiple Ethernet interfaces are configured with different expected speed/duplex settings.
Objective:
- Validate configured interface speed and duplex settings.
- Detect and report mismatches compared to a predefined golden configuration.
Topology & Communications
Management Protocols:
- SSH CLI for
show interfaces status
andshow interfaces [interface]
. - Optional GUI snapshot for cross-verification.
Communication Workflow:
- pyATS connects to the Catalyst switch using credentials.
- Runs
show interfaces status
to extract the speed and duplex state of all interfaces. - Normalizes the output into structured data.
- Compares the extracted data with a predefined expected configuration.
- Outputs detailed reports with PASS/FAIL results for each interface.
Workflow Script
from genie.testbed import load from pyats.aetest import Testcase, test, main import re EXPECTED_INTERFACE_CONFIG = { "GigabitEthernet1/0/1": {"speed": "1000", "duplex": "full"}, "GigabitEthernet1/0/2": {"speed": "100", "duplex": "half"}, "GigabitEthernet1/0/3": {"speed": "1000", "duplex": "full"}, } class InterfaceConsistencyValidation(Testcase): @test def connect_and_extract(self, testbed): self.interface_status = {} device = testbed.devices['catalyst9300'] device.connect(log_stdout=False) # Extract interface status output = device.execute('show interfaces status') self.interface_status['status'] = output # Extract detailed interface info detailed_output = device.execute('show interfaces') self.interface_status['details'] = detailed_output @test def parse_and_validate_interfaces(self): status_output = self.interface_status['status'] details_output = self.interface_status['details'] # Parse 'show interfaces status' interface_data = {} for line in status_output.splitlines(): match = re.match(r'^(GigabitEthernet\S+)\s+(\S+)\s+\S+\s+(\S+)\s+(\S+)', line) if match: interface, status, vlan, duplex = match.groups() interface_data[interface] = {"status": status, "duplex": duplex} # Parse 'show interfaces' for speed speed_data = {} current_iface = "" for line in details_output.splitlines(): iface_match = re.match(r'^(\S+) is (up|down), line protocol is (up|down)', line) if iface_match: current_iface = iface_match.group(1) speed_match = re.search(r'(\d+) Mbps', line) if current_iface and speed_match: speed_data[current_iface] = speed_match.group(1) # Cross-check expected vs actual for iface, expected in EXPECTED_INTERFACE_CONFIG.items(): actual_duplex = interface_data.get(iface, {}).get('duplex', 'unknown') actual_speed = speed_data.get(iface, 'unknown') print(f"\nValidating Interface {iface}:") print(f"Expected Speed: {expected['speed']}, Actual Speed: {actual_speed}") print(f"Expected Duplex: {expected['duplex']}, Actual Duplex: {actual_duplex}") assert actual_speed == expected['speed'], f"FAIL: {iface} speed mismatch" assert actual_duplex == expected['duplex'], f"FAIL: {iface} duplex mismatch" print(f"PASS: {iface} configuration is consistent.") if __name__ == '__main__': main()
Explanation by Line
- EXPECTED_INTERFACE_CONFIG: Define golden config mapping for interface speed and duplex.
- connect_and_extract():
- Connects to Catalyst switch and runs
show interfaces status
+show interfaces
. - Stores CLI outputs.
- Connects to Catalyst switch and runs
- parse_and_validate_interfaces():
- Parses both CLI outputs.
- Uses regex to extract interface name, status, speed, and duplex.
- Cross-validates actual vs expected configurations and asserts with PASS/FAIL.
Optional extension: Capture GUI screenshots to support visual audits.
testbed.yml Example
testbed: name: interface_validation_testbed credentials: default: username: admin password: Cisco123 devices: catalyst9300: os: iosxe type: switch connections: cli: protocol: ssh ip: 192.168.100.20
Post-validation CLI (Real expected output)
show interfaces status
Example:
Port Name Status Vlan Duplex Speed Type Gi1/0/1 connected 10 full 1000 10/100/1000-TX Gi1/0/2 connected 20 half 100 10/100/1000-TX Gi1/0/3 connected 30 full 1000 10/100/1000-TX
show interfaces
Example Snippet:
GigabitEthernet1/0/1 is up, line protocol is up Hardware is Gigabit Ethernet, address is 001c.58b1.8301 MTU 1500 bytes, BW 1000000 Kbit/sec, DLY 10 usec ... GigabitEthernet1/0/2 is up, line protocol is up Hardware is Gigabit Ethernet, address is 001c.58b1.8302 MTU 1500 bytes, BW 100000 Kbit/sec, DLY 10 usec ...
Sample Automation Output:
Validating Interface GigabitEthernet1/0/1: Expected Speed: 1000, Actual Speed: 1000 Expected Duplex: full, Actual Duplex: full PASS: GigabitEthernet1/0/1 configuration is consistent. Validating Interface GigabitEthernet1/0/2: Expected Speed: 100, Actual Speed: 100 Expected Duplex: half, Actual Duplex: half PASS: GigabitEthernet1/0/2 configuration is consistent. All interface speed and duplex consistency checks PASSED.
FAQs
Q1. Why is verifying interface speed and duplex consistency important in network environments?
A1. Consistent speed and duplex settings prevent performance issues like collisions, packet drops, and connectivity degradation. Mismatches between connected devices (e.g., one side at full-duplex, the other at half-duplex) cause suboptimal performance and intermittent outages.
Q2. How does pyATS automate speed/duplex validation?
A2. pyATS connects to network devices via CLI or API, executes commands like show interfaces status
or show interfaces
, parses the output, and compares configured values versus operational status. Any mismatches are flagged in structured test reports.
Q3. Which CLI commands are typically used for speed/duplex checks on Cisco devices?
A3. Common Cisco commands include:
show interfaces status
show interfaces [interface-id]
These commands display the configured and operational speed/duplex settings for each interface.
Q4. Can pyATS validate interface consistency across multiple vendors?
A4. Yes. By creating vendor-specific parsers or using platform-agnostic test templates, pyATS can retrieve and validate speed/duplex settings for Cisco, Arista, Juniper, and other supported devices in a consistent manner.
Q5. How are inconsistencies reported in pyATS results?
A5. Inconsistencies are reported in detailed JSON or HTML reports. Each interface is listed with configured vs. operational speed/duplex values, and any mismatch is clearly highlighted along with device hostname, interface name, and timestamp.
Q6. Can pyATS automatically remediate speed/duplex mismatches?
A6. By itself, pyATS focuses on validation and reporting. However, it can be integrated with automation tools like Ansible to apply corrective configurations based on validation results, enabling automated remediation workflows.
Q7. What are the benefits of automating speed/duplex consistency checks versus manual methods?
A7. Automation provides scalability, speed, and accuracy. Instead of manually checking dozens or hundreds of interfaces, a single pyATS job validates all interfaces across the network, reducing human error and providing structured, auditable reports for compliance.
YouTube Link
Watch the Complete Python for Network Engineer: Verify Interface Speed/Duplex Consistency Using pyATS for Cisco [Python for Network Engineer] Lab Demo & Explanation on our channel:
Join Our Training
Congratulations on completing Day #75 of the pyATS Series. You’ve now learned how to automate and validate interface speed and duplex consistency using pyATS, removing the guesswork of manual CLI checks.
However, this is just one part of a much broader Python for Network Engineer skill set.
Join Trainer Sagar Dhawan’s 3-month Instructor-Led Training Program, where we teach structured automation, API integrations, Ansible playbooks, and advanced Python scripting for network engineers.
Full course outline here:
Python Ansible API Cisco DevNet for Network Engineers – 3-Month Training
Unlock the power of automation and future-proof your career today.
Enroll Now & Future‑Proof Your Career
Email: info@networkjourney.com
WhatsApp / Call: +91 97395 21088