Skip to content

Commit 55dccb5

Browse files
fix: network info table and node info
1 parent 3647f73 commit 55dccb5

16 files changed

Lines changed: 350 additions & 139 deletions

File tree

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
# Tauri + React + Typescript
1+
# Simulation Controller
22

3-
This template should help get you started developing with Tauri, React and Typescript in Vite.
3+
## Introduction
4+
This repository provides the RustBusters implementation for the Simulation Controller for the Advanced Programming Course 2024-2025 at the University of Trento.
5+
6+
## Description
7+
Questo software è stato sviluppato utilizzando Tauri, per combinare le performance e le potenzialità di Rust con la flessibilità e la semplicità di JavaScript per fare interfaccie altamente personalizzabili. Per il frontend è stato utilizzato React, appoggiandosi a Shadcn e tailwind per la parte grafica.
48

5-
## Recommended IDE Setup
69

7-
- [VS Code](https://code.visualstudio.com/) + [Tauri](https://marketplace.visualstudio.com/items?itemName=tauri-apps.tauri-vscode) + [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "react-sc",
2+
"name": "simulation-controller",
33
"private": true,
44
"version": "0.1.0",
55
"type": "module",

src-tauri/src/commands/topology.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub fn add_node(
6868
node_type: String, // Drone, Client, Server
6969
) -> Result<(), NetworkError> {
7070
let mut sim_state = state.lock();
71-
71+
7272
let node_type = match node_type.as_str() {
7373
"Drone" => NodeType::Drone,
7474
"Client" => NodeType::Client,
@@ -214,10 +214,11 @@ pub fn get_network_nodes(state: State<Arc<Mutex<SimulationState>>>) -> Result<Va
214214
return Err(NetworkError::NetworkNotRunning);
215215
}
216216

217-
let nodes_json: Vec<Value> = sim_state
218-
.get_graph()
219-
.get_nodes_info()
220-
.iter()
217+
let mut nodes_info: Vec<_> = sim_state.get_graph().get_nodes_info().into_iter().collect();
218+
nodes_info.sort_by_key(|(node_id, _)| *node_id);
219+
220+
let nodes_json: Vec<Value> = nodes_info
221+
.into_iter()
221222
.map(|(node_id, metadata)| match metadata {
222223
crate::simulation::topology::NodeMetadata::Drone(drone) => {
223224
json!({

src-tauri/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub fn run() {
2727
if cfg!(debug_assertions) {
2828
app.handle().plugin(
2929
tauri_plugin_log::Builder::default()
30-
.level(log::LevelFilter::Info)
30+
.level(log::LevelFilter::Off)
3131
// .filter(|metadata| metadata.target().starts_with("reactsc"))
3232
.build(),
3333
)?;

src-tauri/src/simulation/initializer/network_initializer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use server::utils::traits::Runnable;
1212
use server::{RustBustersServer, RustBustersServerController};
1313
use std::collections::HashMap;
1414
use std::net::Ipv4Addr;
15-
use std::{env, thread};
15+
use std::{thread};
1616
use wg_2024::controller::{DroneCommand, DroneEvent};
1717
use wg_2024::drone::Drone;
1818
use wg_2024::network::NodeId;

src-tauri/src/simulation/metrics/metrics_handler.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use crate::simulation::metrics::{DroneMetrics, HostMetrics, HostMetricsTimePoint, Metrics, MetricsTimePoint, PacketTypeLabel};
1+
use crate::simulation::metrics::{
2+
DroneMetrics, HostMetrics, HostMetricsTimePoint, Metrics, MetricsTimePoint, PacketTypeLabel,
3+
};
24
use common_utils::PacketTypeHeader;
35
use std::time::{Duration, SystemTime, UNIX_EPOCH};
46
use wg_2024::network::NodeId;
@@ -51,7 +53,7 @@ impl Metrics {
5153
pub fn update_host_message_sent(
5254
&mut self,
5355
node_id: NodeId,
54-
destination: NodeId,
56+
_destination: NodeId,
5557
latency: Duration,
5658
) {
5759
if let Some(host_metrics) = self.host_metrics.get_mut(&node_id) {
@@ -85,7 +87,6 @@ impl Metrics {
8587
}
8688
}
8789

88-
8990
impl crate::simulation::metrics::HostMetrics {
9091
pub fn record_packet(&mut self, dest: NodeId, packet_type: PacketTypeLabel) {
9192
let entry = self.dest_stats.entry(dest).or_insert((0, 0));
@@ -145,7 +146,6 @@ impl crate::simulation::metrics::HostMetrics {
145146
}
146147
}
147148

148-
149149
impl crate::simulation::metrics::DroneMetrics {
150150
pub fn number_of_packets_sent(&self) -> u64 {
151151
self.packet_type_counts.values().sum()
@@ -198,4 +198,4 @@ impl crate::simulation::metrics::DroneMetrics {
198198
pub fn record_shortcut(&mut self) {
199199
self.shortcuts += 1;
200200
}
201-
}
201+
}

src-tauri/src/simulation/metrics/mod.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::time::Duration;
77
use wg_2024::network::NodeId;
88
use wg_2024::packet::PacketType;
99

10-
const ROLLING_WINDOW_SIZE: usize = 100;
10+
const ROLLING_WINDOW_SIZE: usize = 1000;
1111

1212
#[derive(Debug, Default)]
1313
pub struct Metrics {
@@ -52,16 +52,22 @@ impl From<&PacketType> for crate::simulation::metrics::PacketTypeLabel {
5252
PacketType::MsgFragment(_) => crate::simulation::metrics::PacketTypeLabel::MsgFragment,
5353
PacketType::Ack(_) => crate::simulation::metrics::PacketTypeLabel::Ack,
5454
PacketType::Nack(_) => crate::simulation::metrics::PacketTypeLabel::Nack,
55-
PacketType::FloodRequest(_) => crate::simulation::metrics::PacketTypeLabel::FloodRequest,
56-
PacketType::FloodResponse(_) => crate::simulation::metrics::PacketTypeLabel::FloodResponse,
55+
PacketType::FloodRequest(_) => {
56+
crate::simulation::metrics::PacketTypeLabel::FloodRequest
57+
}
58+
PacketType::FloodResponse(_) => {
59+
crate::simulation::metrics::PacketTypeLabel::FloodResponse
60+
}
5761
}
5862
}
5963
}
6064

6165
impl From<&PacketTypeHeader> for crate::simulation::metrics::PacketTypeLabel {
6266
fn from(pt: &PacketTypeHeader) -> Self {
6367
match pt {
64-
PacketTypeHeader::MsgFragment => crate::simulation::metrics::PacketTypeLabel::MsgFragment,
68+
PacketTypeHeader::MsgFragment => {
69+
crate::simulation::metrics::PacketTypeLabel::MsgFragment
70+
}
6571
PacketTypeHeader::Ack => crate::simulation::metrics::PacketTypeLabel::Ack,
6672
PacketTypeHeader::FloodRequest => {
6773
crate::simulation::metrics::PacketTypeLabel::FloodRequest

src-tauri/tauri.conf.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"$schema": "https://schema.tauri.app/config/2",
3-
"productName": "react-sc",
4-
"version": "0.1.0",
5-
"identifier": "com.react-sc.app",
3+
"productName": "Simulation Controller",
4+
"version": "1.0.0",
5+
"identifier": "com.riccardobenevelli.simulation-controller",
66
"build": {
77
"beforeDevCommand": "bun run dev",
88
"devUrl": "http://localhost:1420",
@@ -12,7 +12,7 @@
1212
"app": {
1313
"windows": [
1414
{
15-
"title": "react-sc",
15+
"title": "Simulation Controller",
1616
"width": 1200,
1717
"height": 800
1818
}

src/components/GraphComponent.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
} from "@/components/ui/dialog";
1616
import { Input } from "@/components/ui/input";
1717
import { Checkbox } from "@/components/ui/checkbox";
18-
import { getCssVariableAsRGB } from "@/lib/utils";
18+
import { extractErrorMessage, getCssVariableAsRGB } from "@/lib/utils";
1919
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
2020

2121
interface GraphComponentProps {
@@ -342,7 +342,7 @@ const GraphComponent = ({ onNodeSelect, setRefreshGraph }: GraphComponentProps)
342342
await loadGraphData();
343343
} catch (error: any) {
344344
console.error("Error while adding the node:", error);
345-
const errorMessage = error?.message || "Error while adding the node.";
345+
const errorMessage = extractErrorMessage(error);
346346
toast.error(errorMessage);
347347
}
348348
};
@@ -422,9 +422,9 @@ const GraphComponent = ({ onNodeSelect, setRefreshGraph }: GraphComponentProps)
422422
<div className="flex flex-wrap gap-2 mt-1">
423423
{ cy &&
424424
cy.nodes().sort((a, b) => {
425-
const idA = parseInt(a.id(), 10); // Converti l'ID in numero
425+
const idA = parseInt(a.id(), 10);
426426
const idB = parseInt(b.id(), 10);
427-
return idA - idB; // Ordine numerico crescente
427+
return idA - idB;
428428
}).map((node) => (
429429
<label key={ node.id() } className="flex items-center gap-2">
430430
<Checkbox

0 commit comments

Comments
 (0)