[Day #39 PyATS Series] Check for Interface MTU Mismatches (Multi-Vendor) Using pyATS for Cisco [Python for Network Engineer]

Introduction

Interface MTU (Maximum Transmission Unit) mismatches are a common cause of packet drops and network performance degradation. Identifying and resolving MTU mismatches across a multi-vendor environment (Cisco, Arista, Palo Alto, Fortinet) ensures consistent communication and avoids fragmentation issues.

In this 101 Days of pyATS (Vendor-Agnostic) series post, Trainer Sagar Dhawan demonstrates how to automate MTU mismatch checks using pyATS. Designed for Python for Network Engineer learners, this article covers:

  • Parsing interface MTU settings on multiple devices
  • Detecting mismatched MTUs on connected interfaces
  • Generating actionable reports to fix inconsistencies

By the end, you’ll have a reusable script that proactively monitors MTU consistency across your network.


Topology Overview

Our lab setup includes:

  • R1 (Cisco IOS-XE), R2 (Arista EOS), FW1 (Palo Alto), and FGT1 (Fortinet)
  • Links interconnecting these devices with expected consistent MTU sizes (default 1500 bytes)
  • Goal: Detect any MTU mismatches on trunk and routed links

Topology & Communications

  • Protocols: Layer 2 and Layer 3 interfaces with standard MTU of 1500
  • Verification: show interfaces commands across vendors
  • Connectivity: SSH-based CLI sessions handled by pyATS testbed
  • Steps:
    1. Connect to each device
    2. Parse interface MTU settings
    3. Compare peer interface MTUs
    4. Generate a mismatch report

Workflow Script

from genie.testbed import load
import json

def get_interface_mtu(device):
    device.connect(log_stdout=False)
    intf_data = device.parse('show interfaces')
    device.disconnect()

    mtu_info = {}
    for intf, details in intf_data.items():
        mtu_info[intf] = details.get('mtu', None)

    return mtu_info

if __name__ == "__main__":
    testbed = load('testbed.yml')
    report = {}

    for name, device in testbed.devices.items():
        print(f"Collecting MTU data from {name}...")
        report[name] = get_interface_mtu(device)

    with open('mtu_report.json', 'w') as f:
        json.dump(report, f, indent=4)

    print(json.dumps(report, indent=4))

Explanation by Line

  • get_interface_mtu: Retrieves interface MTU values from each device
  • Main loop: Iterates over all multi-vendor devices
  • Output: JSON report for cross-device MTU analysis

testbed.yml Example

testbed:
  name: mtu_mismatch_test
  devices:
    R1:
      os: iosxe
      type: router
      connections:
        cli:
          protocol: ssh
          ip: 192.168.201.11
      credentials:
        default:
          username: admin
          password: cisco123

    R2:
      os: eos
      type: switch
      connections:
        cli:
          protocol: ssh
          ip: 192.168.201.12
      credentials:
        default:
          username: admin
          password: arista123

    FW1:
      os: panos
      type: firewall
      connections:
        cli:
          protocol: ssh
          ip: 192.168.201.13
      credentials:
        default:
          username: admin
          password: palo123

    FGT1:
      os: fortinet
      type: firewall
      connections:
        cli:
          protocol: ssh
          ip: 192.168.201.14
      credentials:
        default:
          username: admin
          password: forti123

Post-validation CLI Screenshots (Expected Output)

Cisco R1:

R1# show interfaces GigabitEthernet0/0
MTU 1500 bytes, BW 1000000 Kbit/sec

Arista R2:

R2# show interfaces Ethernet1
MTU 1500 bytes

Script Output:

{
  "R1": {"GigabitEthernet0/0": 1500},
  "R2": {"Ethernet1": 1500},
  "FW1": {"ethernet1/1": 1500},
  "FGT1": {"port1": 1500}
}

FAQs

1. Can this script detect MTU mismatches between two connected devices?

Yes. It collects MTU values from both ends of a link, making it easy to identify any mismatched configurations that could lead to packet drops.


2. Does it work with non-Cisco devices like Arista, Palo Alto, and Fortinet?

Yes. With the appropriate Genie parsers or custom extensions, the script supports multiple vendors, ensuring consistent MTU checks across diverse environments.


3. Is it safe to run this script in production networks?

Yes. The script only uses read-only show commands, meaning it won’t alter configurations or disrupt operations.


4. How scalable is this solution for large-scale networks?

pyATS is designed for scalability. It can handle hundreds of devices and interfaces efficiently by leveraging parallel connections and structured data parsing.


5. Can this script handle non-standard MTUs like jumbo frames?

Yes. The script captures the actual MTU configured on each interface, allowing you to validate both standard and jumbo frame MTU settings.


6. Does it support IPv6 MTU verification?

Yes. The MTU values collected are applicable to both IPv4 and IPv6 traffic, ensuring consistent validation across protocol types.


7. Can the results be integrated with dashboards or monitoring tools?

Absolutely. The JSON output can be easily imported into dashboards like Grafana or Kibana for visualization and alerting.


8. Can this be automated as part of a CI/CD pipeline?

Yes. The script can be integrated into automated workflows for pre- and post-change validation in DevOps environments.


YouTube Link

Watch the Complete Python for Network Engineer: Check for Interface MTU Mismatches (Multi-Vendor) Using pyATS for Cisco [Python for Network Engineer] Lab Demo & Explanation on our channel:

Master Python Network Automation, Ansible, REST API & Cisco DevNet
Master Python Network Automation, Ansible, REST API & Cisco DevNet
Master Python Network Automation, Ansible, REST API & Cisco DevNet
Why Robot Framework for Network Automation?

Join Our Training

Automating MTU mismatch checks eliminates manual verification and helps maintain consistent network performance. Trainer Sagar Dhawan offers a 3-month instructor-led program covering Python, Ansible, APIs, and Cisco DevNet for Network Engineers, teaching you how to automate multi-vendor operational tasks.

Join Our Training to gain hands-on experience and elevate your career with Python for Network Engineer skills.

Enroll Now & Future‑Proof Your Career
Emailinfo@networkjourney.com
WhatsApp / Call: +91 97395 21088