mirror of
https://github.com/thatmattlove/hyperglass.git
synced 2026-04-17 21:38:27 +00:00
MAJOR NEW ARCHITECTURE - STRUCTURED TRACEROUTE: - Complete rewrite of traceroute data processing with structured output - Dedicated TracerouteResult and TracerouteHop data models - Platform-specific parsers with unified output format - Rich metadata including ASN, organization, country, and prefix information - AS path visualization with organization names in React Flow charts SUPPORTED PLATFORMS: - TraceroutePluginMikrotik: Handles MikroTik's complex multi-table format * Progressive statistics parsing with deduplication * Timeout hop handling and continuation line processing * Loss percentage and RTT statistics extraction - TraceroutePluginHuawei: Unix-style traceroute format parser * Standard hop_number ip_address rtt format support * Timeout hop detection with * notation * Automatic cleanup of excessive trailing timeouts COMPREHENSIVE IP ENRICHMENT SYSTEM: - Offline enrichment using BGP.tools bulk data (1.3M+ CIDR entries) - PeeringDB integration for IXP detection and ASN organization data - Ultra-fast pickle cache system with combined data files - Integer-based bitwise IP matching for maximum performance - Bulk ASN organization lookup capabilities - Private/reserved IP handling with AS0 fallbacks - Country code mapping from ASN database - Graceful fallbacks for missing enrichment data FRONTEND ENHANCEMENTS: - New traceroute table components with consistent formatting - Enhanced AS path visualization with organization names - Improved copy-to-clipboard functionality with structured data - Unified table styling across BGP and traceroute results - Better error handling and loading states CONCURRENT PROCESSING INFRASTRUCTURE: - Thread executor implementation for blocking I/O operations - Query deduplication system to prevent resource conflicts - Non-blocking Redis cache operations using asyncio executors - Event coordination for waiting requests - Background cleanup for completed operations - Prevents website hangs during long-running queries PLUGIN ARCHITECTURE IMPROVEMENTS: - Platform-aware plugin system with proper execution restrictions - Enhanced MikroTik garbage output cleaning - IP enrichment plugins for both BGP routes and traceroute - Conditional plugin execution based on platform detection - Proper async/sync plugin method handling CRITICAL BUG FIXES: - Fixed double AS prefix bug (ASAS123456 → AS123456) - Resolved TracerouteHop avg_rtt field/property conflicts - Corrected Huawei traceroute source field validation - Fixed plugin platform restriction enforcement - Eliminated blocking I/O causing UI freezes - Proper timeout and empty response caching prevention - Enhanced private IP range detection and handling PERFORMANCE OPTIMIZATIONS: - Pickle cache system reduces startup time from seconds to milliseconds - Bulk processing for ASN organization lookups - Simplified IXP detection using single PeeringDB API call - Efficient CIDR network sorting and integer-based lookups - Reduced external API calls by 90%+ - Optimized memory usage for large datasets API & ROUTING ENHANCEMENTS: - Enhanced API routes with proper error handling - Improved middleware for concurrent request processing - Better state management and event handling - Enhanced task processing with thread pool execution This represents a complete transformation of hyperglass traceroute capabilities, moving from basic text output to rich, structured data with comprehensive network intelligence and concurrent processing support.
199 lines
5.8 KiB
TypeScript
199 lines
5.8 KiB
TypeScript
import dagre from 'dagre';
|
|
import { useMemo } from 'react';
|
|
import isEqual from 'react-fast-compare';
|
|
|
|
import type { Edge, Node } from 'reactflow';
|
|
import type { NodeData } from './chart';
|
|
|
|
interface BasePath {
|
|
asn: string;
|
|
name: string;
|
|
}
|
|
|
|
type FlowElement<T> = Node<T> | Edge<T>;
|
|
|
|
const NODE_WIDTH = 128;
|
|
const NODE_HEIGHT = 48;
|
|
|
|
export function useElements(base: BasePath, data: AllStructuredResponses): FlowElement<NodeData>[] {
|
|
return useMemo(() => {
|
|
return [...buildElements(base, data)];
|
|
}, [base, data]);
|
|
}
|
|
|
|
/**
|
|
* Check if data contains BGP routes
|
|
*/
|
|
function isBGPData(data: AllStructuredResponses): data is BGPStructuredOutput {
|
|
return 'routes' in data && Array.isArray(data.routes);
|
|
}
|
|
|
|
/**
|
|
* Check if data contains traceroute hops
|
|
*/
|
|
function isTracerouteData(data: AllStructuredResponses): data is TracerouteStructuredOutput {
|
|
return 'hops' in data && Array.isArray(data.hops);
|
|
}
|
|
|
|
/**
|
|
* Calculate the positions for each AS Path.
|
|
* @see https://github.com/MrBlenny/react-flow-chart/issues/61
|
|
*/
|
|
function* buildElements(
|
|
base: BasePath,
|
|
data: AllStructuredResponses,
|
|
): Generator<FlowElement<NodeData>> {
|
|
let asPaths: string[][] = [];
|
|
let asnOrgs: Record<string, { name: string; country: string }> = {};
|
|
|
|
if (isBGPData(data)) {
|
|
// Handle BGP routes with AS paths
|
|
const { routes } = data;
|
|
asPaths = routes
|
|
.filter(r => r.as_path.length !== 0)
|
|
.map(r => {
|
|
const uniqueAsns = [...new Set(r.as_path.map(asn => String(asn)))];
|
|
// Remove the base ASN if it's the first hop to avoid duplication
|
|
return uniqueAsns[0] === base.asn ? uniqueAsns.slice(1) : uniqueAsns;
|
|
})
|
|
.filter(path => path.length > 0); // Remove empty paths
|
|
|
|
// Get ASN organization mapping if available
|
|
asnOrgs = (data as any).asn_organizations || {};
|
|
|
|
// Debug: Log BGP ASN organization data
|
|
if (Object.keys(asnOrgs).length > 0) {
|
|
console.debug('BGP ASN organizations loaded:', asnOrgs);
|
|
} else {
|
|
console.warn('BGP ASN organizations not found or empty');
|
|
}
|
|
} else if (isTracerouteData(data)) {
|
|
// Handle traceroute hops - build AS path from hop ASNs
|
|
const hopAsns: string[] = [];
|
|
let currentAsn = '';
|
|
|
|
for (const hop of data.hops) {
|
|
if (hop.asn && hop.asn !== 'None' && hop.asn !== currentAsn) {
|
|
currentAsn = hop.asn;
|
|
hopAsns.push(hop.asn);
|
|
}
|
|
}
|
|
|
|
if (hopAsns.length > 0) {
|
|
// Remove the base ASN if it's the first hop to avoid duplication
|
|
const filteredAsns = hopAsns[0] === base.asn ? hopAsns.slice(1) : hopAsns;
|
|
if (filteredAsns.length > 0) {
|
|
asPaths = [filteredAsns];
|
|
}
|
|
}
|
|
|
|
// Get ASN organization mapping if available
|
|
asnOrgs = (data as any).asn_organizations || {};
|
|
|
|
// Debug: Log traceroute ASN organization data
|
|
if (Object.keys(asnOrgs).length > 0) {
|
|
console.debug('Traceroute ASN organizations loaded:', asnOrgs);
|
|
} else {
|
|
console.warn('Traceroute ASN organizations not found or empty');
|
|
}
|
|
}
|
|
|
|
if (asPaths.length === 0) {
|
|
return;
|
|
}
|
|
|
|
const totalPaths = asPaths.length - 1;
|
|
|
|
const g = new dagre.graphlib.Graph();
|
|
g.setGraph({ marginx: 20, marginy: 20 });
|
|
g.setDefaultEdgeLabel(() => ({}));
|
|
|
|
// Set the origin (i.e., the hyperglass user) at the base.
|
|
g.setNode(base.asn, { width: NODE_WIDTH, height: NODE_HEIGHT });
|
|
|
|
for (const [groupIdx, pathGroup] of asPaths.entries()) {
|
|
// For each ROUTE's AS Path:
|
|
|
|
// Find the route after this one.
|
|
const nextGroup = groupIdx < totalPaths ? asPaths[groupIdx + 1] : [];
|
|
|
|
// Connect the first hop in the AS Path to the base (for dagre).
|
|
g.setEdge(base.asn, `${groupIdx}-${pathGroup[0]}`);
|
|
|
|
// Eliminate duplicate AS Paths.
|
|
if (!isEqual(pathGroup, nextGroup)) {
|
|
for (const [idx, asn] of pathGroup.entries()) {
|
|
// For each ASN in the ROUTE:
|
|
|
|
const node = `${groupIdx}-${asn}`;
|
|
const endIdx = pathGroup.length - 1;
|
|
|
|
// Add the AS as a node.
|
|
g.setNode(node, { width: NODE_WIDTH, height: NODE_HEIGHT });
|
|
|
|
// Connect the first hop in the AS Path to the base (for react-flow).
|
|
if (idx === 0) {
|
|
yield {
|
|
id: `e${base.asn}-${node}`,
|
|
source: base.asn,
|
|
target: node,
|
|
};
|
|
}
|
|
// Connect every intermediate hop to each other.
|
|
if (idx !== endIdx) {
|
|
const next = `${groupIdx}-${pathGroup[idx + 1]}`;
|
|
g.setEdge(node, next);
|
|
yield {
|
|
id: `e${node}-${next}`,
|
|
source: node,
|
|
target: next,
|
|
};
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Now that that nodes are added, create the layout.
|
|
dagre.layout(g, { rankdir: 'BT', align: 'UR' });
|
|
|
|
// Get the base ASN's positions.
|
|
const x = g.node(base.asn).x - NODE_WIDTH / 2;
|
|
const y = g.node(base.asn).y + NODE_HEIGHT * 6;
|
|
|
|
yield {
|
|
id: base.asn,
|
|
type: 'ASNode',
|
|
position: { x, y },
|
|
data: {
|
|
asn: base.asn,
|
|
name: asnOrgs[base.asn]?.name || base.name,
|
|
hasChildren: true,
|
|
hasParents: false
|
|
},
|
|
};
|
|
|
|
for (const [groupIdx, pathGroup] of asPaths.entries()) {
|
|
const nextGroup = groupIdx < totalPaths ? asPaths[groupIdx + 1] : [];
|
|
if (!isEqual(pathGroup, nextGroup)) {
|
|
for (const [idx, asn] of pathGroup.entries()) {
|
|
const node = `${groupIdx}-${asn}`;
|
|
const endIdx = pathGroup.length - 1;
|
|
const x = g.node(node).x - NODE_WIDTH / 2;
|
|
const y = g.node(node).y - NODE_HEIGHT * (idx * 6);
|
|
|
|
// Get each ASN's positions.
|
|
yield {
|
|
id: node,
|
|
type: 'ASNode',
|
|
position: { x, y },
|
|
data: {
|
|
asn: `${asn}`,
|
|
name: asn === 'IXP' ? 'IXP' : asnOrgs[asn]?.name || (asn === '0' ? 'Private/Unknown' : `AS${asn}`),
|
|
hasChildren: idx < endIdx,
|
|
hasParents: true,
|
|
},
|
|
};
|
|
}
|
|
}
|
|
}
|
|
}
|