Skip to content

Commit 3ed7ab5

Browse files
committed
Merge branch 'release/v2.0.0'
2 parents db73d71 + 861e02d commit 3ed7ab5

18 files changed

Lines changed: 977 additions & 449 deletions
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,11 @@ This guide helps developers set up, test, and deploy the Flex Net Sim Backend AP
4343
# Test help endpoint
4444
curl http://127.0.0.1:5000/help
4545

46-
# Test simulation endpoint
46+
# Test standard simulation endpoint
4747
curl -X POST -H "Content-Type: application/json" -d '{}' http://127.0.0.1:5000/run_simulation
48+
49+
# Test streaming simulation endpoint
50+
curl -N -X POST -H "Content-Type: application/json" -d '{"goalConnections": 50000}' http://127.0.0.1:5000/run_simulation_stream
4851
```
4952

5053
## Testing
@@ -119,7 +122,11 @@ Follow the Google Cloud setup steps from the video, focusing on:
119122
Use the `curl` command with the `ENDPOINT-URL` you obtained from the previous steps to test your deployed API. Replace `YOUR-ENDPOINT-URL` with the actual `ENDPOINT-URL`.
120123

121124
```bash
125+
# Test standard endpoint
122126
curl -X POST -H "Content-Type: application/json" -d '{"algorithm": "FirstFit", "networkType": 1, "bitrate": "fixed-rate"}' <YOUR-ENDPOINT-URL>/run_simulation
127+
128+
# Test streaming endpoint
129+
curl -N -X POST -H "Content-Type: application/json" -d '{"algorithm": "FirstFit", "goalConnections": 5000000}' <YOUR-ENDPOINT-URL>/run_simulation_stream
123130
```
124131

125132
Remember that depending on the authetification preferences you might need to authetificate to send request to the Endpoint just created.

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@ simulation.out
1010
# Test files
1111
.coverage
1212
htmlcov
13-
.pytest_cache
13+
.pytest_cache
14+
15+
# Claude Code
16+
CLAUDE.md

CHANGELOG.md

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,37 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## [Unreleased]
9-
108
### ROADMAP
11-
- Switch to Flex Net Sim v0.8.2.
12-
- Enhance previous algorithms.
13-
- Add algorithm BestFit.
149
- Switch to new domain.
1510

16-
## [1.1.1] - 2023-03-01
11+
## [2.0.0] - 2025-03-03
12+
13+
### Added
14+
- New `/run_simulation_stream` endpoint for streaming simulation results in real-time:
15+
- Streaming responses include event types and structured JSON data.
16+
- Refactored backend code to reduce duplication and improve maintainability.
17+
- Added unit tests for the streaming endpoint.
18+
- Modified `simulator.hpp` to flush `stdout` after each line for better streaming support (see `src/README.md`).
19+
- Improved the `\help` endpoint with more concise documentation.
20+
- Enabled CORS only for the `/run_simulation_stream` endpoint to allow controlled API access.
21+
22+
### Changed
23+
- Switched to Flex Net Sim v0.8.2.
24+
- Standardized API response format for better consistency:
25+
- Success responses now use `status: "success"` with data in a `data` field.
26+
- Error responses now use `status: "error"` with a `message` and detailed `error` fields.
27+
- Reorganized the test suite into separate files for better maintainability.
28+
- Improved parameter validation with descriptive error messages.
29+
- Changed the error response code from `500` to `400` for invalid parameters.
30+
- Moved parameter validation from C++ to the API layer for a better user experience.
31+
- Replaced the `ExactFit` algorithm with `BestFit`.
32+
- Enhanced algorithms
33+
34+
### Fixed
35+
- Fixed error in main.cpp always using FirstFit
36+
- Fixed error in main.cpp always using Fixed-Rate
37+
38+
## [1.1.1] - 2025-03-01
1739

1840
### Added
1941
- Deployed coverage to pages
@@ -47,7 +69,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4769
- This API hopefully serves as playground to all new users of Flex Net Sim C++ simulation library.
4870
- The current version utilizes Flex Net Sim v0.8.1.
4971
- `/run_simulation` endpoint for simulation includes parameters such as:
50-
- `algorithm`: FirstFit, ExactFit.
72+
- `algorithm`: FirstFit, BestFit.
5173
- `networkType`: Only 1 (EON) available for now.
5274
- `goalConnections`: 1 to 10,000,000.
5375
- `confidence`: significance level (alpha) greater than zero.
@@ -60,5 +82,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6082
- API allocated in cloud run.
6183
- Documentation README for the process of develop/deployment located in [workflows](https://github.com/MirkoZETA/FlexNetSim-API/tree/master/.github/workflows/README_DEV.md).
6284

63-
[1.1.0]: https://github.com/MirkoZETA/FlexNetSim-API/releases/tag/v1.1.0
6485
[1.0.0]: https://github.com/MirkoZETA/FlexNetSim-API/releases/tag/v1.0.0
86+
[1.1.0]: https://github.com/MirkoZETA/FlexNetSim-API/releases/tag/v1.1.0
87+
[1.1.1]: https://github.com/MirkoZETA/FlexNetSim-API/releases/tag/pipeline-fix
88+
[2.0.0]: https://github.com/MirkoZETA/FlexNetSim-API/releases/tag/v2.0.0

README.md

Lines changed: 80 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Flex Net Sim Backend API
22

3-
[![Static Badge](https://img.shields.io/badge/version-1.1.0-blue)](https://github.com/MirkoZETA/FlexNetSim-API)
3+
[![Static Badge](https://img.shields.io/badge/version-2.0.0-blue)](https://github.com/MirkoZETA/FlexNetSim-API)
44
![Static Badge](https://img.shields.io/badge/language-python-blue)
55
[![Static Badge](https://img.shields.io/badge/licese-MIT-green)](https://github.com/MirkoZETA/FlexNetSim-API/blob/master/LICENSE)
66
[![Static Badge](https://github.com/MirkoZETA/FlexNetSim-API/actions/workflows/fns-api-workflow.yml/badge.svg)](https://github.com/MirkoZETA/FlexNetSim-API/actions/workflows/fns-api-workflow.yml)
7-
[![Static Badge](https://img.shields.io/badge/coverage-94%25-brightgreen)](https://mirkozeta.github.io/FlexNetSim-API/coverage/)
7+
[![Static Badge](https://img.shields.io/badge/coverage-95%25-brightgreen)](https://mirkozeta.github.io/FlexNetSim-API/coverage/)
88

99
A lightweight API for running optical network simulations with [Flex Net Sim C++](https://gitlab.com/DaniloBorquez/flex-net-sim).
1010

@@ -34,13 +34,13 @@ For development and deployment instructions for this API, refer to [README_DEV.m
3434

3535
### `/run_simulation` (POST)
3636

37-
Runs a network simulation with the provided parameters.
37+
Runs a network simulation with the provided parameters and returns complete results.
3838

3939
#### Request Parameters
4040

4141
| Parameter | Type | Description | Allowed Values & Constraints | Default |
4242
|---------------|---------|----------------------------|-------------------------------------------------|-----------|
43-
| `algorithm` | `string` | RSA algorithm | `FirstFit`, `ExactFit` | `FirstFit` |
43+
| `algorithm` | `string` | RSA algorithm | `FirstFit`, `BestFit` | `FirstFit` |
4444
| `networkType` | `integer` | Network type | Only `1` (EON) supported | `1` |
4545
| `goalConnections` | `integer` | Target connection requests | Must be > 0 and < 10,000,000 | `100000` |
4646
| `confidence` | `float` | Confidence level | Must be > 0 and < 1.0 | `0.05` |
@@ -74,9 +74,84 @@ curl -X POST -H "Content-Type: application/json" \
7474
https://fns-api-cloud-run-787143541358.us-central1.run.app/run_simulation
7575
```
7676

77+
#### Response Format
78+
79+
```json
80+
{
81+
"status": "success",
82+
"data": "simulation results as text..."
83+
}
84+
```
85+
86+
#### Response Codes
87+
88+
- `200 OK`: Success
89+
- `400 Bad Request`: Invalid parameters
90+
- `500 Internal Server Error`: Server-side error
91+
92+
### `/run_simulation_stream` (POST)
93+
94+
Runs a network simulation with the provided parameters and streams results in real-time using Server-Sent Events (SSE).
95+
96+
#### Request Parameters
97+
98+
Same parameters as `/run_simulation` endpoint.
99+
100+
#### Example: Streaming with Default Parameters
101+
102+
```bash
103+
curl -N -X POST -H "Content-Type: application/json" -d '{}' \
104+
https://fns-api-cloud-run-787143541358.us-central1.run.app/run_simulation_stream
105+
```
106+
107+
#### Example: Streaming with Custom Parameters
108+
109+
```bash
110+
curl -N -X POST -H "Content-Type: application/json" \
111+
-d '{
112+
"algorithm": "FirstFit",
113+
"networkType": 1,
114+
"goalConnections": 5000000,
115+
"confidence": 0.05,
116+
"lambdaParam": 120,
117+
"mu": 1,
118+
"network": "NSFNet",
119+
"bitrate": "fixed-rate"
120+
}' \
121+
https://fns-api-cloud-run-787143541358.us-central1.run.app/run_simulation_stream
122+
```
123+
124+
#### Response Format
125+
126+
The endpoint returns a stream of Server-Sent Events with the following event types:
127+
128+
1. **Start Event**:
129+
```
130+
event: start
131+
data: {"status": "started", "message": "Simulation started"}
132+
```
133+
134+
2. **Data Events** (multiple events, one per line of output):
135+
```
136+
event: data
137+
data: {"status": "running", "message": "Line of simulation output"}
138+
```
139+
140+
3. **End Event**:
141+
```
142+
event: end
143+
data: {"status": "completed", "message": "Simulation completed"}
144+
```
145+
146+
4. **Error Event** (only if an error occurs):
147+
```
148+
event: error
149+
data: {"status": "error", "message": "Error description", "error": "Detailed error"}
150+
```
151+
77152
#### Response Codes
78153

79-
- `200 OK`: Success. Returns `{"output": "...", "error": ""}`
154+
- `200 OK`: Success (stream starts)
80155
- `400 Bad Request`: Invalid parameters
81156
- `500 Internal Server Error`: Server-side error
82157

0 commit comments

Comments
 (0)