Automating MPLS VPN Verification With Python
From CE to PE to PE to CE — automated, repeatable verification.
MPLS L3VPN has many moving parts: VRFs, route distinguishers, route targets, MP-BGP VPNv4, and PE-CE routing. Manual verification is slow and error-prone. Python makes it a repeatable check.
What to verify
- VRF exists on both PEs with the correct RD.
- Route targets import/export match the design.
- MP-BGP VPNv4 sessions are Established between PEs.
- PE-CE adjacency is up and routes are exchanged.
- End-to-end reachability across the customer sites.
Pulling VRF state
from netmiko import ConnectHandler
pe = ConnectHandler(device_type="cisco_xr", host="10.0.0.1",
username="netops", password="***")
vrf = pe.send_command("show vrf CUSTOMER_A detail")
routes = pe.send_command("show bgp vpnv4 unicast vrf CUSTOMER_A summary")
print(vrf)
print(routes)Asserting the design
Compare observed RTs and neighbor states against the intended design and emit a finding for each mismatch. A green run across both PEs is a powerful change-window artifact.
Was this helpful?
Generate scripts for the task covered in this post
Describe what you need and NAPT writes production-ready automation in Netmiko, NAPALM, or Nornir.
Open Script Generator →Related posts
Compliance Without the Spreadsheet: Continuous Posture for Network Devices
The Compliance panel runs your hardening rule packs across the fleet, scores devices, and tracks drift so audits start with evidence, not promises.
Read →Inventory & IPAM: The Source of Truth Your Scripts Actually Trust
Upload a CSV, connect to NetBox, or generate an IP range — Inventory normalises every source into the same validated row shape for the platform.
Read →Runbooks: Living Documents That Run
Runbooks combine narrative, parameters, and executable scripts so on-call engineers stop choosing between reading the doc and fixing the problem.
Read →