← All posts
How-To

Automating MPLS VPN Verification With Python

From CE to PE to PE to CE — automated, repeatable verification.

NAPT Team9 min read
MPLS L3VPNCEPEPECEMP-BGP VPNv4 (RD/RT)

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

  1. VRF exists on both PEs with the correct RD.
  2. Route targets import/export match the design.
  3. MP-BGP VPNv4 sessions are Established between PEs.
  4. PE-CE adjacency is up and routes are exchanged.
  5. End-to-end reachability across the customer sites.

Pulling VRF state

python
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.

Pro tip: Verify import and export RTs on both ends. A one-sided RT mismatch is the classic "VPN up but no routes" failure.
#mpls#how-to#python

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 →
New to NAPT? Start with the Setup Guide

Related posts