A semantic web validation system for KVM hardware topologies using RDF/OWL ontologies and SHACL constraints.
Repository: github.com/nkllon/kvm
This project models and validates hardware connections in a KVM (Keyboard, Video, Mouse) setup using semantic web technologies. It enforces critical constraints such as:
- Bidirectional cable requirements for Mac M4 Mini USB-C to DisplayPort connections
- Audio purity ensuring audio interfaces bypass KVMs (no digital switching)
- Active adapter enforcement for legacy Mini-DisplayPort connections
- Uptime-critical port prioritization for production Cloudflare hosts
nkllon-topology/
βββ src/nkllon/ # Python package
β βββ validate.py # pySHACL validation logic
β βββ query.py # SPARQL query utilities
β βββ cli.py # Command-line interface
βββ ontology/ # RDF/OWL definitions
β βββ hardware_ontology.ttl # Device classes and properties
β βββ system_constraints.shacl.ttl # SHACL validation rules
βββ data/ # Deployment data
β βββ physical_deployment.ttl # Actual hardware topology
βββ tests/ # Test suite
βββ Makefile # Common development tasks
- Python 3.11+
- uv package manager
# Using uv
uv pip install -e ".[dev]"
# Or using make
make installRun SHACL validation to ensure your hardware deployment conforms to all constraints:
# Using make
make validate
# Using CLI
uv run nkllon validate
# Using Python module
uv run python -m nkllon.validate
# With environment selection
uv run nkllon validate --env prod
# With verbose logging
uv run nkllon validate --verbose
# Export report to HTML
uv run nkllon validate --export report.html --format html
# Export report to JSON
uv run nkllon validate --export report.json --format jsonExample output:
================================================================================
NKLLON Hardware Topology Validation
================================================================================
Environment: prod
Ontology: hardware_ontology.ttl
SHACL: system_constraints.shacl.ttl
Data: physical_deployment.ttl
--------------------------------------------------------------------------------
β
VALIDATION PASSED
All SHACL constraints satisfied:
β Rule 1: eARC return path (SmartDisplay to PreAmp)
β Rule 2: Audio interfaces bypass KVMs (can connect to PreAmp)
β Rule 3: Bidirectional cables (USB-C to DisplayPort)
β Rule 4: Production uptime-critical ports
================================================================================
Run SPARQL queries to explore your hardware topology:
# Using make
make query
# Using CLI
uv run nkllon query
# Using Python module
uv run python -m nkllon.queryExample queries:
- Find all bidirectional cables and their connections
- List audio interface connections
- Check uptime-critical host configurations
- Display all devices by type
Generate an interactive D3.js visualization of your hardware topology:
# Using make
make visualize
# Using CLI
uv run nkllon visualize --output topology.html
# For specific environment
uv run nkllon visualize --env staging --output staging_topology.htmlThis creates an interactive HTML file with:
- Force-directed graph layout
- Color-coded device types
- Zoom and pan controls
- Drag-and-drop nodes
- Connection labels
Compare two topology configurations to see what changed:
# Compare two files
uv run nkllon diff data/old.ttl data/new.ttl
# Show only device-level changes
uv run nkllon diff data/old.ttl data/new.ttl --devices-only
# Using make (requires FILE1 and FILE2 variables)
make diff FILE1=data/old.ttl FILE2=data/new.ttl# Using make
make test
# Using pytest directly
uv run pytest tests/ -v
# With coverage report
make coverage# Run linter
make lint
# Auto-format code
make formatRun validation in a Docker container:
# Build image
make docker-build
# Run validation
make docker-run
# Use docker-compose for full stack
make docker-compose-upDevice- Base class for all hardwareHost- Computer hosts (Mac M4 Mini, Ubuntu server)KVM- KVM switches (ConnectPRO)AudioInterface- Audio devices (Motu M4)
Device β hasPort β Port β connectsVia β Cable β connectsTo β Port β belongsToDevice β Device
- Physical:
physicalForm(USB-C, DisplayPort, etc.) - Operational:
isBidirectional,isActive,isEncrypted - Priority:
portPriority,isUptimeCritical
Cables connecting Mac M4 (USB-C) to KVM (DisplayPort) must be bidirectional.
Rationale: USB-C to DisplayPort connections require bidirectional signal flow for proper operation.
Audio interfaces must bypass KVMs (no digital switching).
Rationale: Professional audio requires direct connections to avoid latency and signal degradation.
Legacy Mini-DisplayPort connections must use active adapters.
Rationale: Passive adapters cause signal loss on legacy ports.
Production Cloudflare hosts must connect to high-priority KVM ports.
Rationale: Critical infrastructure requires prioritized connections for reliability.
PREFIX : <http://nkllon.com/sys#>
SELECT ?cable ?srcDevice ?dstDevice WHERE {
?cable a :Cable ;
:isBidirectional true .
?srcPort :connectsVia ?cable .
?cable :connectsTo ?dstPort .
?srcPort :belongsToDevice ?srcDevice .
?dstPort :belongsToDevice ?dstDevice .
}PREFIX : <http://nkllon.com/sys#>
SELECT ?audioDevice ?connectedDevice WHERE {
?audioDevice a :AudioInterface ;
:hasPort ?port .
?port :connectsVia ?cable .
?cable :connectsTo ?otherPort .
?otherPort :belongsToDevice ?connectedDevice .
?connectedDevice a :KVM .
}
# Should return empty (Rule 2 compliance)PREFIX : <http://nkllon.com/sys#>
SELECT ?host ?kvmPort ?priority WHERE {
?host :isUptimeCritical true ;
:hasPort ?hostPort .
?hostPort :connectsVia ?cable .
?cable :connectsTo ?kvmPort .
?kvmPort :portPriority ?priority .
}- Define device in
data/physical_deployment.ttl:
:NewDevice a :Host ;
:hasPort :NewDevice_Port1 .- Define connections:
:NewDevice_Port1 a :Port ;
:physicalForm "HDMI" ;
:connectsVia :NewCable ;
:belongsToDevice :NewDevice .- Run validation:
make validate- Add SHACL shape to
ontology/system_constraints.shacl.ttl - Add corresponding test to
tests/test_validation.py - Run tests:
make test
- RDFLib - RDF graph manipulation
- pySHACL - SHACL constraint validation
- uv - Fast Python package manager
- pytest - Testing framework
- ruff - Linting and formatting
MIT