Lanbench -
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()
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)
results = {} for class_name, params in traffic_classes.items(): metrics = AdvancedNetworkTests.send_traffic_class( host, port, params ) results[class_name] = metrics return results
def create_latency_chart(self): return go.Figure( data=[go.Scatter(y=list(self.latency_data), mode='lines+markers')], layout=go.Layout(title="Network Latency Over Time") ) # distributed.py import redis import json from typing import List, Dict from multiprocessing import Pool import asyncio class DistributedTester: def init (self, redis_host='localhost', redis_port=6379): self.redis_client = redis.Redis(host=redis_host, port=redis_port) self.test_nodes = [] LANBench
def export_to_csv(self, filename: str): """Export raw data to CSV""" df = pd.DataFrame(self.results['raw_data']) df.to_csv(filename, index=False)
@staticmethod async def udp_jitter_test(host: str, port: int, packet_size: int): """UDP latency and jitter measurement""" sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # Implement jitter calculation pass # metrics.py import psutil import time from dataclasses import dataclass from typing import List, Dict import numpy as np @dataclass class NetworkMetrics: throughput_mbps: float latency_ms: float jitter_ms: float packet_loss_percent: float tcp_retransmissions: int cpu_usage_percent: float memory_usage_mb: float
<script> const socket = io('http://localhost:5000'); let chart; function startTest() { const config = { type: document.getElementById('test-type').value, host: document.getElementById('target-host').value, duration: parseInt(document.getElementById('duration').value) }; socket.emit('start_test', config); } socket.on('test_update', (data) => { updateChart(data); updateResults(data); }); </script> </body> </html> # reporting.py import pandas as pd from jinja2 import Template import matplotlib.pyplot as plt from reportlab.lib import colors from reportlab.pdfgen import canvas class ReportGenerator: def init (self, test_results: Dict): self.results = test_results data: List[float]) ->
class ProtocolTest: @staticmethod async def tcp_bandwidth_test(host: str, port: int, duration: int): """TCP throughput testing""" sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock.bind(('', port)) sock.listen(5)
def collect_system_metrics(self) -> Dict: """Collect real-time system metrics""" return { 'cpu_percent': psutil.cpu_percent(interval=1), 'memory_percent': psutil.virtual_memory().percent, 'network_io': psutil.net_io_counters(), 'connections': len(psutil.net_connections()) }
class TestConfig(BaseModel): test_type: str target_host: str duration: int protocol: str = "tcp" packet_size: Optional[int] = 1400 LANBench Test Report<
class MetricsCollector: def (self): self.metrics_history: List[NetworkMetrics] = []
@app.post("/api/v1/start_test") async def start_test(config: TestConfig, background_tasks: BackgroundTasks): """Start a network test""" test_id = generate_test_id() background_tasks.add_task(run_network_test, test_id, config) return {"test_id": test_id, "status": "started"}
# Implement throughput measurement pass
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) ]) ])
@staticmethod def test_bufferbloat(host: str, duration: int = 60): """Test router bufferbloat""" # Measure latency under load idle_latency = AdvancedNetworkTests.measure_latency(host) # Generate high load AdvancedNetworkTests.generate_background_load(host, duration) # Measure loaded latency loaded_latency = AdvancedNetworkTests.measure_latency(host) return { 'idle_latency': idle_latency, 'loaded_latency': loaded_latency, 'bufferbloat_ms': loaded_latency - idle_latency } <!-- templates/dashboard.html --> <!DOCTYPE html> <html> <head> <title>LANBench Control Panel</title> <script src="https://cdn.socket.io/4.5.0/socket.io.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/chart.js"></script> </head> <body> <div class="container"> <h1>LANBench Network Testing Suite</h1> <div class="control-panel"> <select id="test-type"> <option value="bandwidth">Bandwidth Test</option> <option value="latency">Latency Test</option> <option value="packet-loss">Packet Loss Test</option> <option value="jitter">Jitter Test</option> </select> <input type="text" id="target-host" placeholder="Target IP/Hostname"> <input type="number" id="duration" placeholder="Duration (seconds)" value="30"> <button onclick="startTest()">Start Test</button> </div> <canvas id="real-time-chart"></canvas> <div id="results"></div> </div>