Generate Draw.io network topology diagrams from Cisco router and switch configurations. Use when asked to visualize network topology, create network diagrams, map network infrastructure, or generate visual representations from Cisco device configs. Supports parsing show commands, configuration files, CDP/LLDP neighbor data, and routing protocol information to automatically create professional network diagrams.
Generate professional Draw.io network topology diagrams from Cisco device configurations using the drawio-network-plot Python library.
This skill automates the creation of network topology diagrams by:
Assumption: Device configurations have already been collected. This skill focuses on parsing and visualization, not SSH access or data collection.
Install required library:
pip install drawio-network-plot --break-system-packages
/mnt/user-data/outputs/network-diagram.drawioExtract these elements from Cisco configs:
Device Information:
hostname <name>interface <mgmt> + ip addressInterface Details:
switchport access vlan, switchport trunk allowed vlandescription <text>Layer 2 Connections:
show cdp neighbors detail outputshow lldp neighbors detail outputinterface Port-channel, member interfacesLayer 3 Information:
ip routerouter ospf, network statements, areasrouter bgp, neighbors, AS numbersrouter eigrp, network statementsstandby, vrrp configurationsImportant: Use references/cisco-parser.md for detailed parsing patterns and regular expressions for each configuration type.
from drawio_network_plot import create_graph, Node, Edge
# Create graph
graph = create_graph(filename="network.drawio", direction="LR")
# Add devices as nodes
router = Node(
id="rtr1",
label="Core-Router-01",
device_type="router",
ip_address="10.0.0.1"
)
graph.add_node(router)
# Add connections as edges
link = Edge(
source="rtr1",
target="sw1",
label="Gi0/0/0 → Gi1/0/1\n10.1.1.0/30"
)
graph.add_edge(link)
# Generate diagram
graph.draw()
Map Cisco devices to appropriate icons:
device_type="router" - Routers, multilayer switches doing L3device_type="switch" - L2 switches, access switchesdevice_type="firewall" - ASA, Firepowerdevice_type="server" - Services, appliancesdevice_type="cloud" - Internet, WAN, external networksdevice_type="pc" - End devices, workstationsHierarchical (Top-Down):
graph = create_graph(filename="network.drawio", direction="TB")
Best for: Core → Distribution → Access topologies
Left-to-Right:
graph = create_graph(filename="network.drawio", direction="LR")
Best for: Service chains, data flows, sequential processing
Manual Positioning:
node = Node(id="sw1", label="Switch", x=100, y=200, width=120, height=80)
Best for: Complex topologies, specific physical layouts, data center rows
Include relevant information on connection labels:
# L3 Point-to-Point
Edge(label="Gi0/0 → Gi0/1\n10.1.1.0/30\nOSPF Area 0")
# L2 Trunk
Edge(label="Trunk\nVLANs: 10,20,30,100\n1Gbps")
# Port Channel
Edge(label="Po1 (LACP)\nGi0/1-2\n2Gbps")
Use scripts/generate_network_diagram.py for a complete implementation:
python scripts/generate_network_diagram.py <config_directory> <output_file>
Or follow this manual workflow:
import re
from drawio_network_plot import create_graph, Node, Edge
# 1. Parse configurations
devices = {}
connections = []
for config_file in config_files:
# Parse device info
hostname = extract_hostname(config_file)
device_type = infer_device_type(config_file)
mgmt_ip = extract_mgmt_ip(config_file)
devices[hostname] = {
'type': device_type,
'mgmt_ip': mgmt_ip,
'interfaces': extract_interfaces(config_file)
}
# Parse CDP neighbors to find connections
cdp_neighbors = parse_cdp_neighbors(config_file)
for neighbor in cdp_neighbors:
connections.append({
'source': hostname,
'source_int': neighbor['local_interface'],
'target': neighbor['device_id'],
'target_int': neighbor['remote_interface']
})
# 2. Create graph
graph = create_graph(filename="network.drawio", direction="TB")
# 3. Add devices
for hostname, info in devices.items():
node = Node(
id=hostname,
label=f"{hostname}\n{info['mgmt_ip']}",
device_type=info['type']
)
graph.add_node(node)
# 4. Add connections (deduplicate bidirectional links)
seen_connections = set()
for conn in connections:
conn_key = tuple(sorted([
f"{conn['source']}:{conn['source_int']}",
f"{conn['target']}:{conn['target_int']}"
]))
if conn_key not in seen_connections:
edge = Edge(
source=conn['source'],
target=conn['target'],
label=f"{conn['source_int']} ↔ {conn['target_int']}"
)
graph.add_edge(edge)
seen_connections.add(conn_key)
# 5. Generate diagram
graph.draw()
Create separate diagrams for different network layers:
Physical Layer: All devices and physical connections Logical Layer: VLANs, broadcast domains, subnets Layer 3: Routers, routing protocols, subnets Security Zones: Firewalls, ACLs, security boundaries
Use containers for logical grouping:
from drawio_network_plot import Container
# Create data center container
dc1 = Container(
id="dc1",
label="Data Center 1",
children=["rtr1", "sw1", "sw2", "fw1"]
)
graph.add_container(dc1)
Customize colors for different device roles:
node = Node(
id="core-rtr",
label="Core Router",
device_type="router",
fill_color="#FF6B6B", # Red for core devices
font_color="#FFFFFF"
)
Include additional information as node properties:
node = Node(
id="rtr1",
label="Core-Router-01",
device_type="router",
metadata={
"model": "ISR4451-X",
"ios_version": "17.6.3",
"location": "Building A - MDF",
"serial": "FDO2148B0X1"
}
)
For large topologies:
Show redundancy clearly:
# Primary path
edge1 = Edge(source="rtr1", target="rtr2", label="Primary\nGi0/0", style="solid")
# Backup path
edge2 = Edge(source="rtr1", target="rtr2", label="Backup\nGi0/1", style="dashed")
Represent virtual connections:
# VPN tunnel
vpn_edge = Edge(
source="site1-rtr",
target="site2-rtr",
label="IPsec VPN\n10.100.0.0/24",
style="dashed",
color="#0066CC"
)
import shutil
shutil.move("network.drawio", "/mnt/user-data/outputs/network-diagram.drawio")
Generate multiple formats if needed:
.drawio (editable XML)Provide user with link:
print("[View your network diagram](computer:///mnt/user-data/outputs/network-diagram.drawio)")
Issue: Overlapping nodes Solution: Use manual positioning or adjust layout direction
Issue: Missing connections
Solution: Verify CDP/LLDP data parsing, check for hostname mismatches
Issue: Incorrect device types Solution: Review device type inference logic, use explicit type mapping
Issue: Too much information on diagram Solution: Create multiple focused diagrams (L2, L3, security) instead of one complex diagram
references/cisco-parser.md: Detailed regex patterns and parsing functions for all Cisco configuration typesreferences/drawio-examples.md: Complete working examples for different network scenariosscripts/generate_network_diagram.py: Production-ready script with full parsing and generation logicUse Case 1: Data Center Topology
# Create top-down diagram with core, aggregation, and access layers
# Group servers by rack, show redundant uplinks
Use Case 2: Branch Office WAN
# Show hub-and-spoke topology with MPLS/VPN connections
# Highlight primary and backup WAN links
Use Case 3: VLAN Visualization
# Create L2 diagram showing VLAN trunks and access ports
# Color-code by VLAN or security zone
Use Case 4: Routing Protocol View
# Show OSPF areas, BGP peerings, route reflectors
# Label edges with metrics and next-hops