aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: 952e6d2da72767e8637c9b6bd02ea7d10a412950 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# Bonsai Web

A simple web interface for the Bonsai.

## Local Development

### Prerequisites

- Python 3.9+
- Flask

### Installation

1. Clone this repository
2. Install dependencies:
   ```bash
   pip install -r requirements.txt
   ```

### Running Locally

```bash
python app.py
```

The application will be available at `http://localhost:5000`

### Environment Configuration

The application behavior can be controlled using the `BONSAI_TEST_MODE` environment variable:

- **Test Mode** (default for local development): `BONSAI_TEST_MODE=true`
  - If Bonsai fails or is not available, dummy files are generated for testing
  - Useful for development and testing the web interface
  
- **Production Mode**: `BONSAI_TEST_MODE=false`
  - If Bonsai fails, proper error messages are returned to the user
  - No dummy files are generated

```bash
# Run in production mode
BONSAI_TEST_MODE=false python app.py

# Run in test mode (default)
BONSAI_TEST_MODE=true python app.py
# or simply
python app.py
```

### Development Mode

For development, the application includes fallback dummy data generation when `BONSAI_TEST_MODE=true` and the actual Bonsai tool is not available. This allows you to test the web interface without having the full Bonsai installation.

**Error Handling**: When Bonsai fails in production mode, detailed error messages are displayed to the user in red text, including:
- Execution failures with return codes and stderr output
- Timeout errors (30-second limit)
- Missing Bonsai installation errors

## Container Deployment

### Building the Container

```bash
just build
# or `just --set image <custom image> build`
```

#### Pushing the container

```bash
just push
# or `just --set image <custom image> push`
```

### Running the Container

```bash
podman run -p 5000:5000 git.d464.sh/diogo464/bonsai-web:latest
```

## Usage

1. Open the web application in your browser
2. Enter your network configuration in YAML format in the text area
3. Click "Generate Network Files"
4. View or download the generated `edges.csv` and `nodes.csv` files

### Example Configuration

```yaml
network:
  nodes: 10
  density: 0.3
  latency_range: [1, 100]
```

## API

### POST /

Generates network files from a YAML configuration.

**Request Body:**
```json
{
  "config": "network:\n  nodes: 10\n  density: 0.3"
}
```

**Response:**
```json
{
  "edges.csv": "source,target,weight\nnode1,node2,0.5\n...",
  "nodes.csv": "id,label,x,y\nnode1,Node 1,0,0\n..."
}
```