# briyithnarvaez04/sdn_ryu_dijkstra_ml_enfa3 architecture

> Architecture diagram of the GitHub repository briyithnarvaez04/sdn_ryu_dijkstra_ml_enfa3, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/briyithnarvaez04/sdn_ryu_dijkstra_ml_enfa3
- Repository: https://github.com/briyithnarvaez04/sdn_ryu_dijkstra_ml_enfa3

## Overview

#### 1. Purpose and Runtime Topology
This repository implements an SDN monitoring, traffic-classification, and dynamic-routing demonstrator over an emulated 23-switch GÉANT topology. It runs as distributed processes: Mininet/OVS produces traffic and speaks OpenFlow to Ryu; Ryu hosts control, ML inference, routing, and Flask APIs; Node.js serves a browser dashboard and proxies API calls.
- `códigos/modelo/icmpgeant.py`
- `códigos/sdnWeb/geant_controller.py`
- `códigos/sdnWeb/server.js`

#### 2. Network Emulation and Traffic Sources
Four Mininet topology entry points instantiate the same GÉANT-style Open vSwitch network and produce distinct traffic profiles: ICMP, HTTP, RTP/video, and low-latency gaming. They connect to the remote controller through OpenFlow 1.3, normally TCP 6633. Run one topology script after Ryu starts.
- `códigos/modelo/icmpgeant.py`
- `códigos/modelo/httpgeant.py`
- `códigos/modelo/rtpgeant.py`
- `códigos/modelo/gaminggeant.py`

#### 3. Unified SDN Controller
`GEANTUnifiedController` is the architectural center. It receives OpenFlow packet, port-statistics, switch, and link-discovery events; maintains shared controller state; discovers hosts; installs forwarding/blocking rules; and converts topology events into an in-memory NetworkX graph. Ryu topology discovery (`ryu.topology.switches` with `--observe-links`) is a required boundary: without discovered edges, route calculation cannot operate.
- `códigos/sdnWeb/geant_controller.py`
- `códigos/sdnWeb/html/classgeant__controller_1_1_g_e_a_n_t_unified_controller.html`
- `códigos/sdnWeb/html/classgeant__controller_1_1_shared_state.html`

#### 4. Metrics-to-ML-to-Routing Loop
At each port-statistics sampling interval, the controller derives throughput, utilization, packet size/rate, jitter, burstiness, RX/TX asymmetry, and error-related features. It aligns these features using the persisted feature-order contract, predicts one of VIDEO/HTTP/GAMING/ICMP, then updates link costs according to class-specific QoS policy factors. Dijkstra runs over the updated NetworkX graph; results drive forwarding decisions and cached route responses.
- `códigos/modelo/TrafficModel.pkl`
- `códigos/modelo/LabelEncoder.pkl`
- `códigos/modelo/feature_columns.pkl`
- `códigos/sdnWeb/geant_controller.py`

#### 5. Offline Data and Model Pipeline
Captured class-specific metric CSVs are cleaned, stripped of OpenFlow/control and counter-overflow artifacts, balanced across classes, and consolidated. Training uses the balanced dataset to produce the RandomForest model, label encoder, and ordered feature list consumed at controller startup. This is an offline artifact-generation boundary; inference occurs only in the controller.
- `códigos/modelo/build_dataset.py`
- `códigos/modelo/entrenamiento.py`
- `códigos/modelo/dataset_balanced.csv`
- `códigos/modelo/datasets/`

#### 6. API, Proxy, and Dashboard
The controller exposes Flask REST endpoints for status, topology, metrics, predictions, routes, hosts, policies, debugging, and snapshots on port 8888. The Express server proxies these under `/api/*`, serves static UI assets, and discovers LAN access addresses; this isolates the browser from controller host/CORS configuration. The frontend polls APIs, renders topology with D3, and renders metrics/ML/control views with Chart.js.
- `códigos/sdnWeb/server.js`
- `códigos/sdnWeb/index.html`
- `códigos/sdnWeb/script.js`
- `códigos/sdnWeb/style.css`

#### 7. External Infrastructure and Startup Order
Material dependencies are Linux, Mininet, Open vSwitch, Python/Ryu, Flask, NetworkX, scikit-learn/joblib/pandas/numpy, and Node.js/Express. Chart.js and D3.js load from CDNs unless locally substituted. Start Ryu plus required topology modules, then one Mininet traffic topology, then the Node server. Primary ports are OpenFlow 6633, Ryu REST 8080, controller Flask 8888, and dashboard/proxy 3000.
- `códigos/sdnWeb/package.json`
- `códigos/sdnWeb/geant_controller.py`
- `códigos/modelo/Doxyfile`

Main entry points: [`códigos/sdnWeb/geant_controller.py`](https://github.com/briyithnarvaez04/sdn_ryu_dijkstra_ml_enfa3/blob/main/c%C3%B3digos/sdnWeb/geant_controller.py) (Shared controller state), [`códigos/modelo/dataset_balanced.csv`](https://github.com/briyithnarvaez04/sdn_ryu_dijkstra_ml_enfa3/blob/main/c%C3%B3digos/modelo/dataset_balanced.csv) (Balanced dataset), [`códigos/modelo/entrenamiento.py`](https://github.com/briyithnarvaez04/sdn_ryu_dijkstra_ml_enfa3/blob/main/c%C3%B3digos/modelo/entrenamiento.py) (Model training), [`códigos/modelo/TrafficModel.pkl`](https://github.com/briyithnarvaez04/sdn_ryu_dijkstra_ml_enfa3/blob/main/c%C3%B3digos/modelo/TrafficModel.pkl) (Model artifacts)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_offline["Offline ML pipeline"]
  node_dataset_build["Dataset builder<br/>Python pipeline<br/>[build_dataset.py]"]
  node_balanced_dataset[("Balanced dataset<br/>CSV dataset")]
  node_training["Model training<br/>Python training<br/>[entrenamiento.py]"]
  node_ml_artifacts["Model artifacts<br/>ML artifacts<br/>[TrafficModel.pkl]"]
end

subgraph group_emulation["Emulated network"]
  node_traffic_topologies["Traffic topology scripts<br/>Mininet entry points<br/>[icmpgeant.py]"]
  node_ovs_geant{{"23-switch GÉANT topology<br/>Mininet / Open vSwitch"}}
end

subgraph group_controller["Ryu controller"]
  node_ryu_discovery["Ryu link discovery<br/>Topology service"]
  node_controller_events["OpenFlow event handling<br/>Controller layer"]
  node_shared_state[("Shared controller state<br/>In-memory state")]
  node_feature_metrics["Metrics features<br/>Feature engineering"]
  node_ml_inference["Traffic inference<br/>ML inference"]
  node_qos_routing["QoS routing<br/>NetworkX / Dijkstra"]
  node_flow_rules["Forwarding and blocking rules<br/>OpenFlow rules"]
  node_flask_api["Controller REST API<br/>Flask API :8888"]
end

subgraph group_dashboard["Dashboard"]
  node_express_proxy["Dashboard server and proxy<br/>Node / Express :3000<br/>[server.js]"]
  node_browser_ui["Topology and metrics dashboard<br/>D3 / Chart.js frontend<br/>[script.js]"]
end

node_dataset_build -->|"produces"| node_balanced_dataset
node_balanced_dataset -->|"trains from"| node_training
node_training -->|"persists"| node_ml_artifacts
node_traffic_topologies -->|"instantiates"| node_ovs_geant
node_ovs_geant -->|"OpenFlow 1.3 :6633"| node_controller_events
node_ovs_geant -->|"switch and link events"| node_ryu_discovery
node_ryu_discovery -->|"topology graph"| node_shared_state
node_controller_events -->|"hosts and counters"| node_shared_state
node_controller_events -->|"port samples"| node_feature_metrics
node_feature_metrics -->|"ordered features"| node_ml_inference
node_ml_artifacts -->|"model and feature contract"| node_ml_inference
node_ml_inference -->|"traffic class"| node_qos_routing
node_shared_state -->|"topology and policy state"| node_qos_routing
node_qos_routing -->|"selected paths"| node_flow_rules
node_flow_rules -->|"flow mods"| node_ovs_geant
node_shared_state -->|"status and snapshots"| node_flask_api
node_qos_routing -->|"route responses"| node_flask_api
node_express_proxy -->|"proxies /api/*"| node_flask_api
node_browser_ui -->|"polls API and static assets"| node_express_proxy

click node_dataset_build "https://github.com/briyithnarvaez04/sdn_ryu_dijkstra_ml_enfa3/blob/main/c%C3%B3digos/modelo/build_dataset.py"
click node_balanced_dataset "https://github.com/briyithnarvaez04/sdn_ryu_dijkstra_ml_enfa3/blob/main/c%C3%B3digos/modelo/dataset_balanced.csv"
click node_training "https://github.com/briyithnarvaez04/sdn_ryu_dijkstra_ml_enfa3/blob/main/c%C3%B3digos/modelo/entrenamiento.py"
click node_ml_artifacts "https://github.com/briyithnarvaez04/sdn_ryu_dijkstra_ml_enfa3/blob/main/c%C3%B3digos/modelo/TrafficModel.pkl"
click node_traffic_topologies "https://github.com/briyithnarvaez04/sdn_ryu_dijkstra_ml_enfa3/blob/main/c%C3%B3digos/modelo/icmpgeant.py"
click node_ryu_discovery "https://github.com/briyithnarvaez04/sdn_ryu_dijkstra_ml_enfa3/blob/main/c%C3%B3digos/sdnWeb/geant_controller.py"
click node_controller_events "https://github.com/briyithnarvaez04/sdn_ryu_dijkstra_ml_enfa3/blob/main/c%C3%B3digos/sdnWeb/geant_controller.py"
click node_shared_state "https://github.com/briyithnarvaez04/sdn_ryu_dijkstra_ml_enfa3/blob/main/c%C3%B3digos/sdnWeb/geant_controller.py"
click node_feature_metrics "https://github.com/briyithnarvaez04/sdn_ryu_dijkstra_ml_enfa3/blob/main/c%C3%B3digos/sdnWeb/geant_controller.py"
click node_ml_inference "https://github.com/briyithnarvaez04/sdn_ryu_dijkstra_ml_enfa3/blob/main/c%C3%B3digos/sdnWeb/geant_controller.py"
click node_qos_routing "https://github.com/briyithnarvaez04/sdn_ryu_dijkstra_ml_enfa3/blob/main/c%C3%B3digos/sdnWeb/geant_controller.py"
click node_flow_rules "https://github.com/briyithnarvaez04/sdn_ryu_dijkstra_ml_enfa3/blob/main/c%C3%B3digos/sdnWeb/geant_controller.py"
click node_flask_api "https://github.com/briyithnarvaez04/sdn_ryu_dijkstra_ml_enfa3/blob/main/c%C3%B3digos/sdnWeb/geant_controller.py"
click node_express_proxy "https://github.com/briyithnarvaez04/sdn_ryu_dijkstra_ml_enfa3/blob/main/c%C3%B3digos/sdnWeb/server.js"
click node_browser_ui "https://github.com/briyithnarvaez04/sdn_ryu_dijkstra_ml_enfa3/blob/main/c%C3%B3digos/sdnWeb/script.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_dataset_build,node_balanced_dataset,node_training,node_ml_artifacts toneBlue
class node_traffic_topologies,node_ovs_geant toneAmber
class node_ryu_discovery,node_controller_events,node_shared_state,node_feature_metrics,node_ml_inference,node_qos_routing,node_flow_rules,node_flask_api toneMint
class node_express_proxy,node_browser_ui toneRose
```

## Components

### Offline ML pipeline

Builds artifacts consumed by controller inference.

- [Dataset builder](https://github.com/briyithnarvaez04/sdn_ryu_dijkstra_ml_enfa3/blob/main/c%C3%B3digos/modelo/build_dataset.py): Python pipeline · Cleans, filters, balances, and consolidates captured metrics. · `códigos/modelo/build_dataset.py`
- [Balanced dataset](https://github.com/briyithnarvaez04/sdn_ryu_dijkstra_ml_enfa3/blob/main/c%C3%B3digos/modelo/dataset_balanced.csv): CSV dataset · `códigos/modelo/dataset_balanced.csv`
- [Model training](https://github.com/briyithnarvaez04/sdn_ryu_dijkstra_ml_enfa3/blob/main/c%C3%B3digos/modelo/entrenamiento.py): Python training · Trains the classifier and persists its feature contract. · `códigos/modelo/entrenamiento.py`
- [Model artifacts](https://github.com/briyithnarvaez04/sdn_ryu_dijkstra_ml_enfa3/blob/main/c%C3%B3digos/modelo/TrafficModel.pkl): ML artifacts · RandomForest, label encoder, and ordered feature list. · `códigos/modelo/TrafficModel.pkl`

### Emulated network

One traffic topology runs against the remote controller.

- [Traffic topology scripts](https://github.com/briyithnarvaez04/sdn_ryu_dijkstra_ml_enfa3/blob/main/c%C3%B3digos/modelo/icmpgeant.py): Mininet entry points · ICMP, HTTP, RTP, or gaming traffic over the GÉANT OVS topology. · `códigos/modelo/icmpgeant.py`
- **23-switch GÉANT topology**: Mininet / Open vSwitch · Emulated switches and hosts generate traffic and OpenFlow events.

### Ryu controller

Control-plane, inference, routing, and Flask API runtime.

- [Ryu link discovery](https://github.com/briyithnarvaez04/sdn_ryu_dijkstra_ml_enfa3/blob/main/c%C3%B3digos/sdnWeb/geant_controller.py): Topology service · Observed links are required before routes can be calculated. · `códigos/sdnWeb/geant_controller.py`
- [OpenFlow event handling](https://github.com/briyithnarvaez04/sdn_ryu_dijkstra_ml_enfa3/blob/main/c%C3%B3digos/sdnWeb/geant_controller.py): Controller layer · Processes packets, port statistics, switches, links, and host discovery. · `códigos/sdnWeb/geant_controller.py`
- [Shared controller state](https://github.com/briyithnarvaez04/sdn_ryu_dijkstra_ml_enfa3/blob/main/c%C3%B3digos/sdnWeb/geant_controller.py): In-memory state · Tracks hosts, metrics, predictions, policies, and cached routes. · `códigos/sdnWeb/geant_controller.py`
- [Metrics features](https://github.com/briyithnarvaez04/sdn_ryu_dijkstra_ml_enfa3/blob/main/c%C3%B3digos/sdnWeb/geant_controller.py): Feature engineering · Derives throughput, utilization, rates, jitter, burstiness, asymmetry, and errors. · `códigos/sdnWeb/geant_controller.py`
- [Traffic inference](https://github.com/briyithnarvaez04/sdn_ryu_dijkstra_ml_enfa3/blob/main/c%C3%B3digos/sdnWeb/geant_controller.py): ML inference · Classifies VIDEO, HTTP, GAMING, or ICMP using the persisted feature order. · `códigos/sdnWeb/geant_controller.py`
- [QoS routing](https://github.com/briyithnarvaez04/sdn_ryu_dijkstra_ml_enfa3/blob/main/c%C3%B3digos/sdnWeb/geant_controller.py): NetworkX / Dijkstra · Updates class-sensitive link costs and calculates forwarding paths. · `códigos/sdnWeb/geant_controller.py`
- [Forwarding and blocking rules](https://github.com/briyithnarvaez04/sdn_ryu_dijkstra_ml_enfa3/blob/main/c%C3%B3digos/sdnWeb/geant_controller.py): OpenFlow rules · `códigos/sdnWeb/geant_controller.py`
- [Controller REST API](https://github.com/briyithnarvaez04/sdn_ryu_dijkstra_ml_enfa3/blob/main/c%C3%B3digos/sdnWeb/geant_controller.py): Flask API :8888 · Serves status, topology, metrics, predictions, routes, hosts, policies, and snapshots. · `códigos/sdnWeb/geant_controller.py`

### Dashboard

Browser UI is isolated from controller API access by Node proxy.

- [Dashboard server and proxy](https://github.com/briyithnarvaez04/sdn_ryu_dijkstra_ml_enfa3/blob/main/c%C3%B3digos/sdnWeb/server.js): Node / Express :3000 · Serves UI and proxies /api/* to the controller. · `códigos/sdnWeb/server.js`
- [Topology and metrics dashboard](https://github.com/briyithnarvaez04/sdn_ryu_dijkstra_ml_enfa3/blob/main/c%C3%B3digos/sdnWeb/script.js): D3 / Chart.js frontend · Polls API data and renders topology, ML, metrics, and controls. · `códigos/sdnWeb/script.js`

## Connections

- Dataset builder → Balanced dataset: produces
- Balanced dataset → Model training: trains from
- Model training → Model artifacts: persists
- Traffic topology scripts → 23-switch GÉANT topology: instantiates
- 23-switch GÉANT topology → OpenFlow event handling: OpenFlow 1.3 :6633
- 23-switch GÉANT topology → Ryu link discovery: switch and link events
- Ryu link discovery → Shared controller state: topology graph
- OpenFlow event handling → Shared controller state: hosts and counters
- OpenFlow event handling → Metrics features: port samples
- Metrics features → Traffic inference: ordered features
- Model artifacts → Traffic inference: model and feature contract
- Traffic inference → QoS routing: traffic class
- Shared controller state → QoS routing: topology and policy state
- QoS routing → Forwarding and blocking rules: selected paths
- Forwarding and blocking rules → 23-switch GÉANT topology: flow mods
- Shared controller state → Controller REST API: status and snapshots
- QoS routing → Controller REST API: route responses
- Dashboard server and proxy → Controller REST API: proxies /api/*
- Topology and metrics dashboard → Dashboard server and proxy: polls API and static assets
