REST驱动的Cyperf CE控制器
一个基于FastAPI的web应用程序,通过SSH控制Keysight Cyperf CE客户端和服务器测试。
______________________________________________________________________
特性
- 通过REST API远程启动/停止Cyperf服务器和客户端
- 通过私钥或用户名/密码进行SSH身份验证
- Docker化,易于部署
- 收集并返回测试统计数据
______________________________________________________________________
需求
- Python 3.11+
- Docker(用于容器化部署)
- 访问安装了Cyperf的远程计算机
______________________________________________________________________
环境变量
应用程序是通过环境变量(或 .env 文件):
| 变量 | 描述 | 示例 |
|---|---|---|
| SERVER_IP | Cyperf服务器的IP地址 | 100.25.44.178 |
| CLIENT_IP | Cyperf客户端的IP地址 | 34.218.246.113 |
| SSH_USERNAME | 服务器和客户端的SSH用户名 | ubuntu |
| SSH_KEY_PATH | SSH私钥的路径(容器内) | /home/ubuntu/vibecode.pem |
| SSH_PASSWORD | (可选)用于身份验证的SSH密码 | yourpassword |
- 如果
SSH_PASSWORD设置后,应用程序将使用用户名/密码身份验证。 - 如果没有,则使用SSH密钥
SSH_KEY_PATH.
______________________________________________________________________
地方发展
- 安装依赖项:
pip install -r requirements.txt- 创建一个
.env文件:
SERVER_IP=100.25.44.178
CLIENT_IP=34.218.246.113
SSH_USERNAME=ubuntu
SSH_KEY_PATH=/path/to/vibecode.pem
# SSH_PASSWORD=yourpassword # Uncomment to use password auth- 运行应用程序:
uvicorn main:app --reload______________________________________________________________________
Docker使用
塑造形象:
docker build -t cyperf-app .运行容器:
docker run -d -p 8000:8000 \
-e SERVER_IP=100.25.44.178 \
-e CLIENT_IP=34.218.246.113 \
-e SSH_USERNAME=ubuntu \
-e SSH_KEY_PATH=/home/ubuntu/vibecode.pem \
-v /path/to/vibecode.pem:/home/ubuntu/vibecode.pem:ro \
cyperf-app- 要使用密码身份验证,请添加
-e SSH_PASSWORD=yourpassword并省略-v/SSH_KEY_PATH选项。
使用a .env 文件:
docker run -d -p 8000:8000 --env-file .env \
-v /path/to/vibecode.pem:/home/ubuntu/vibecode.pem:ro \
cyperf-app______________________________________________________________________
API
- API服务于:
http://localhost:8000/api/ - 交互式文档:
http://localhost:8000/docs
______________________________________________________________________
SSH身份验证
- 基于密钥: 将私钥装入容器并设置
SSH_KEY_PATH. - 基于密码: 集
SSH_PASSWORD(不设置SSH_KEY_PATH).
______________________________________________________________________
MCP(模型上下文协议)支持
此应用程序现在支持MCP(模型上下文协议),可与Claude Desktop、Cursor和其他AI助手等MCP客户端集成。
MCP服务器设置
MCP服务器封装FastAPI端点,并将其作为MCP客户端可以使用的工具公开。
可用的MCP工具:
- start_cyperf_server -启动Cyperf CE服务器
- start_cyperf_client -启动Cyperf CE客户端
- get_server_stats -获取服务器统计信息
- get_client_stats -获取客户端统计信息
- get_server_stats_image -以图像形式获取服务器统计信息
- get_client_stats_image -以图像形式获取客户端统计数据
- stop_server -停止所有服务器
使用Docker Compose(MCP+FastAPI)运行:
- 创建环境文件:
# .env file
SERVER_IP=100.25.44.178
CLIENT_IP=34.218.246.113
SSH_USERNAME=ubuntu
SSH_KEY_PATH=/home/ubuntu/vibecode.pem
SSH_KEY_HOST_PATH=/path/to/your/vibecode.pem
# SSH_PASSWORD=yourpassword # Optional: for password auth- 启动这两项服务:
docker-compose -f docker-compose.mcp.yml up -d这将开始:
- FastAPI服务已打开 http://localhost:8000 - MCP服务器已准备好进行stdio连接
独立运行MCP服务器:
# Build the image
docker build -f Dockerfile.mcp -t cyperf-mcp .
# Run MCP server
docker run -it --rm \
-e SERVER_IP=100.25.44.178 \
-e CLIENT_IP=34.218.246.113 \
-e SSH_USERNAME=ubuntu \
-e SSH_KEY_PATH=/home/ubuntu/vibecode.pem \
-v /path/to/vibecode.pem:/home/ubuntu/vibecode.pem:ro \
cyperf-mcp mcp与MCP客户端一起使用:
HTTP流式传输(推荐):
选项1:SSE(服务器发送事件)服务器
专用的SSE服务器提供最强大的流媒体体验:
# Start your main FastAPI app first
uvicorn main:app --host 0.0.0.0 --port 8000 &
# Start the MCP SSE server
python mcp_sse_server.py --host 0.0.0.0 --port 8001SSE的Claude桌面配置:
{
"mcpServers": {
"cyperf-ce-controller": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-everything"],
"env": {
"MCP_SERVER_URL": "http://localhost:8001/sse"
}
}
}
}选项2:直接HTTP端点
您的FastAPI应用程序包括 /api/mcp 基于HTTP的简单MCP的端点:
HTTP的Claude桌面配置:
{
"mcpServers": {
"cyperf-ce-controller": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-everything"],
"env": {
"MCP_SERVER_URL": "http://localhost:8000/api/mcp"
}
}
}
}直接输入(替代):
添加到您的 claude_desktop_config.json:
{
"mcpServers": {
"cyperf-ce-controller": {
"command": "docker",
"args": [
"run", "-i", "--rm",
"--env-file", "/path/to/.env",
"-v", "/path/to/vibecode.pem:/home/ubuntu/vibecode.pem:ro",
"cyperf-mcp", "mcp"
]
}
}
}直接执行Python:
# Make sure FastAPI is running first
uvicorn main:app --host 0.0.0.0 --port 8000 &
# Run MCP server
python mcp_server.pyMCP使用示例:
连接到MCP客户端后,您可以:
- 启动服务器测试:
Use the start_cyperf_server tool with port 5202 and csv_stats enabled- 连接客户端:
Use start_cyperf_client with the test_id from server, server IP, and run for 120 seconds- 获取统计数据:
Use get_server_stats or get_client_stats with the test_id- 可视化数据:
Use get_server_stats_image to get a visual table of the statistics测试MCP端点:
测试SSE服务器:
# Test SSE server health
curl http://localhost:8001/health
# Test SSE endpoint (requires SSE client or tools like curl with --no-buffer)
curl -X POST http://localhost:8001/sse \
-H "Content-Type: application/json" \
-H "Accept: text/event-stream" \
-N \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/list"
}'
# If you get the "Not Acceptable" error, make sure to include the Accept header:
curl -X POST http://localhost:8001/sse \
-H "Content-Type: application/json" \
-H "Accept: text/event-stream" \
-N \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {},
"clientInfo": {
"name": "test-client",
"version": "1.0.0"
}
}
}'测试直接HTTP端点:
您可以直接使用curl测试MCP端点:
# Test MCP initialization
curl -X POST http://localhost:8000/api/mcp \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {},
"clientInfo": {
"name": "test-client",
"version": "1.0.0"
}
}
}'
# List available tools
curl -X POST http://localhost:8000/api/mcp \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/list"
}'
# Call a tool (start server)
curl -X POST http://localhost:8000/api/mcp \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "start_cyperf_server",
"arguments": {
"port": 5202,
"csv_stats": true
}
}
}'______________________________________________________________________
许可证
麻省理工学院
