Lanbench

@app.get("/api/v1/test_status/{test_id}") async def get_test_status(test_id: str): """Get test progress and results""" return get_test_results(test_id)

def setup_layout(self): self.app.layout = html.Div([ html.H1("LANBench - Live Network Monitor"), html.Div([ dcc.Graph(id='live-latency'), dcc.Graph(id='live-throughput'), dcc.Graph(id='bandwidth-heatmap'), dcc.Interval(id='interval-update', interval=1000) ]) ])

def register_node(self, node_id: str, ip_address: str): """Register a test node""" node_info = { 'id': node_id, 'ip': ip_address, 'status': 'active', 'last_heartbeat': time.time() } self.redis_client.hset('test_nodes', node_id, json.dumps(node_info)) async def run_distributed_test(self, test_config: Dict) -> Dict: """Run tests across multiple nodes""" results = {} tasks = [] for node in self.test_nodes: task = self.run_test_on_node(node, test_config) tasks.append(task) results = await asyncio.gather(*tasks) return self.aggregate_results(results) # advanced_tests.py from scapy.all import * import time class AdvancedNetworkTests: @staticmethod def test_qos_prioritization(host: str, port: int): """Test QoS and traffic prioritization""" # Generate different traffic classes traffic_classes = { 'voice': {'size': 64, 'interval': 0.02}, 'video': {'size': 1400, 'interval': 0.033}, 'data': {'size': 1500, 'interval': 0.1} } LANBench

@app.websocket("/ws/live") async def websocket_endpoint(websocket: WebSocket): """WebSocket for real-time updates""" await websocket.accept() while True: data = await websocket.receive_text() # Process real-time data await websocket.send_json({"status": "updating", "data": data}) # requirements.txt fastapi==0.104.1 uvicorn==0.24.0 dash==2.14.0 plotly==5.17.0 psutil==5.9.5 numpy==1.24.3 pandas==2.1.0 scapy==2.5.0 redis==5.0.1 websockets==12.0 python-socketio==5.10.0 reportlab==4.0.4 jinja2==3.1.2 Quick Start Example # main.py from fastapi import FastAPI import asyncio async def main(): # Initialize LANBench with all features dashboard = LiveDashboard() api_server = FastAPI() distributed_tester = DistributedTester()

results = {} for class_name, params in traffic_classes.items(): metrics = AdvancedNetworkTests.send_traffic_class( host, port, params ) results[class_name] = metrics return results interval=1000) ]) ]) def register_node(self

def generate_html_report(self) -> str: """Generate HTML report with charts""" template = Template(""" <html> <head><title>LANBench Test Report</title></head> <body> <h1>Network Performance Report</h1> <h2>Summary</h2> <table> <tr><th>Metric</th><th>Value</th></tr> <tr><td>Avg Throughput</td><td>{{ throughput }} Mbps</td></tr> <tr><td>Avg Latency</td><td>{{ latency }} ms</td></tr> <tr><td>Packet Loss</td><td>{{ packet_loss }}%</td></tr> </table> <img src="chart.png" alt="Performance Chart"> </body> </html> """) return template.render(**self.results)

# Implement throughput measurement pass

def calculate_statistics(self, data: List[float]) -> Dict: """Calculate statistical metrics""" return { 'mean': np.mean(data), 'std': np.std(data), 'min': np.min(data), 'max': np.max(data), 'p95': np.percentile(data, 95), 'p99': np.percentile(data, 99) } # dashboard.py import dash from dash import dcc, html, Input, Output import plotly.graph_objs as go import plotly.express as px from collections import deque import threading class LiveDashboard: def init (self): self.app = dash.Dash( name ) self.latency_data = deque(maxlen=100) self.throughput_data = deque(maxlen=100) self.setup_layout() self.setup_callbacks()

Loading...