This file provides guidance to WARP (warp.dev) when working with code in this repository.
```bash
npm install
npm run dev
npm run build
npm run preview
npm run lint ```
- Currently no test suite configured - tests would typically be run with
npm test - ESLint is configured for code quality and React best practices
- The project uses modern React patterns with hooks and functional components
- Framework: React 19 with Vite as build tool
- Visualization: vis-network and vis-data for network topology rendering
- Styling: CSS with custom components, no CSS framework
- Additional Libraries: D3.js and @xyflow/react (available but not actively used)
The application follows a clean component-based architecture:
App.jsx: Root component managing global state (hovered nodes, mouse position) and rendering the main layoutNetworkMap.jsx: Core visualization component using vis-network libraryStatisticsDisplay.jsx: Floating tooltip component showing node statistics on hover
- Data Adapter Pattern:
NetworkDataAdapterclass provides flexible data format conversion - Event-driven UI: Uses callback props for node interactions (hover, click)
- Controlled Components: All interactive state managed in parent components
- Raw Data Input → Various formats supported (nodes/edges, topology, devices)
- NetworkDataAdapter → Normalizes data to vis-network format
- vis-network DataSet → Reactive data structures for visualization
- NetworkMap Component → Renders interactive network visualization
The NetworkDataAdapter can handle multiple input formats:
- Standard:
{nodes: [], edges: []} - Topology:
{topology: {devices: [], connections: []}} - Device-based:
{devices: [{id, name, connections: []}]}
- Interactive Network Topology: zoom, hover interactions
- Real-time Statistics: Node selection displays RX/TX rates, traffic, latency, uptime
- Color-coded Node Types: Source (green), Destination (pink), Intermediate (orange), Router/Switch (blue)
- Dynamic Edge Styling: Width and color based on traffic levels
- Uses React's built-in state management with hooks
- Global state limited to UI interactions (hover states, mouse position)
- Network data is immutable after initial load
- Event callbacks propagate user interactions up to parent components
To integrate with external data sources:
- Create new format handler in
NetworkDataAdapter - Add data processing logic in relevant
process*()methods - Ensure data includes required fields:
id,labelfor nodes;from,tofor edges
Key customization points in NetworkMap.jsx:
- Node styling: Modify
options.nodesandoptions.groups - Edge styling: Customize
options.edgesconfiguration - Physics behavior: Adjust
options.physicssettings (default: false) - Interaction behavior: Configure
options.interaction
The StatisticsDisplay component can be extended to show additional metrics by:
- Adding new properties to node data objects
- Updating
StatisticsDisplay.jsxto render new metrics - Modifying tooltip generation in
NetworkDataAdapter.generateNodeTooltip()
``` src/ ├── App.jsx # Main application component ├── components/ │ ├── NetworkMap.jsx # Core network visualization │ └── StatisticsDisplay.jsx # Hover statistics tooltip └── utils/ └── dataAdapter.js # Data format conversion utilities ```
- All network data should flow through
NetworkDataAdapterfor consistency - Node IDs must be unique across the entire network
- Edge definitions require valid
fromandtonode references - Statistics fields (rx, tx, traffic, latency) should include units in the string values
NetworkMapcomponent manages vis-network instance lifecycle - be careful with useEffect dependencies- Event handlers are set up once per network instance - avoid recreating them unnecessarily
- The vis-network instance is stored in a ref and should be cleaned up properly
- Uses inline styles for dynamic positioning (StatisticsDisplay)
- CSS classes for static styling in App.css and index.css
- vis-network styling configured through options object, not CSS
- vis-network handles large networks efficiently, but consider data pagination for 1000+ nodes
- Mouse event handlers are optimized with useCallback
The project integrates with a C++ backend service (confrpc.cpp) that processes real network routing data:
-
Network Files Processing: C++ service reads routing information from:
mroute.txt: Multicast routing table dataneigh.txt: Neighbor discovery informationifconfig.txt: Network interface configuration
-
Data Transformation: Processes IPv6 network topology using:
- Regex parsing for structured data extraction
- Hex-based node identification (last 4 hex digits of IPv6 addresses)
- Interface-to-neighbor mapping for network relationships
-
JSON Output: Generates
output.txtcontaining network topology in JSON format
```javascript // Example: Loading backend-generated network data fetch('/api/network-data') // or load from output.txt .then(response => response.json()) .then(backendData => { // Transform backend JSON to NetworkDataAdapter format const networkData = NetworkDataAdapter.convertFromBackend(backendData); // Use with NetworkMap component }); ```
- Node Identification: Uses 4-character hex strings (e.g., "1bf6", "ea6")
- IPv6 Focus: Designed for IPv6 network topologies
- Multicast Routing: Specifically processes multicast group
ff1e::112 - Interface Types: Supports eth0, eth1, usb0, usb1 network interfaces
- Protobuf Integration: Uses Protocol Buffers for structured data serialization
To integrate the C++ backend output, extend the NetworkDataAdapter class:
```javascript
// Add to NetworkDataAdapter class
static convertFromBackend(backendJson) {
// Transform backend JSON format to vis-network compatible format
const nodes = backendJson.network_map?.node_route_infos?.map(nodeInfo => ({
id: nodeInfo.node_name,
label: Node ${nodeInfo.node_name},
type: 'router',
// Map backend route and neighbor info to node properties
routes: nodeInfo.route_infos,
neighbors: nodeInfo.neigh_infos
})) || [];
// Generate edges from routing and neighbor information const edges = []; // Process backend routing data to create network connections
return { nodes, edges }; } ```
The backend processor can be used for:
- Live Network Topology: Regular processing of current routing tables
- Network Change Detection: Monitoring routing table updates
- Performance Metrics: Extracting network performance data from routing information
App.jsx: Main application with toggle between sample and backend dataBackendNetworkExample.jsx: Dedicated component for backend data visualization- Sample Data File:
public/sample-backend-data.jsoncontains example backend output
- Start the development server:
npm run dev - Toggle Data Sources: Use the "Switch to Backend Data" button in the UI
- Sample Backend Data: The app includes sample backend JSON for testing
- Console Logging: Check browser console for data conversion logs
Based on your actual output.txt, the system processes:
```json
{
"status": "SUCCESS",
"network_map": {
"node_route_infos": [
{
"node_name": "1493",
"neigh_infos": [
{"interface": "eth0", "neigh_node": "ea6"},
{"interface": "usb0", "neigh_node": "4b0a"}
],
"route_infos": [
{
"incoming_interface": "eth0",
"iif_neigh_node": "2001:db8::2b0:19ff:fe7a:ea6",
"source_node": "e78e"
}
]
}
]
}
}
```
To connect to your actual C++ backend:
- API Endpoint: Update
BackendNetworkExample.jsxfetch URL to your backend service - File Upload: Allow users to upload
output.txtfiles directly - WebSocket: For real-time updates from the C++ routing processor
- Polling: Regular API calls to fetch updated topology data