Skip to content

Commit b132b62

Browse files
authored
Fix/ Routing Table and Payload View (#233)
This PR solves some minor visual changes on the simulator. ### Fewer data shown on payload As it was previously discussed, some information of the packet payloads reveal to much data of other layers different from the current one. On the Network layer, ICMP packets that hold a TCP packet on their payload just show the type of the payload, not the whole information. However, ICMP packets do show some data because they are only shown up to the Network layer ![image](https://github.com/user-attachments/assets/6c576794-a3cf-4903-b971-6ef06abb602a) ![image](https://github.com/user-attachments/assets/3327bb34-cff9-41db-b275-2114428fd0ee) ### Different CSS classes for different tables With the addition of the TCP Flags table, the modifications broke the styling of the Router Tables. Now there is a general class for tables and a separate class for each type of table. This allows to change the table configuration on each type. There is also a new class for the recently added ARP tables. ![image](https://github.com/user-attachments/assets/bf331d5e-22d2-46ed-bfb3-a2ca02fa094e) ![image](https://github.com/user-attachments/assets/886bf334-f9ab-483d-b39e-d4afdbafe837) ![image](https://github.com/user-attachments/assets/d70811bc-6573-49db-91e5-ee982c2bc68d)
1 parent d1c962a commit b132b62

File tree

9 files changed

+118
-51
lines changed

9 files changed

+118
-51
lines changed

src/graphics/basic_components/text_info.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ import { attachTooltip } from "../renderables/tooltip_manager";
33
import { Table } from "./table";
44
import { Flags, TCP_FLAGS_KEY } from "../../packets/tcp";
55

6+
const FLAGS_DATA = {
7+
tick: "✓",
8+
cross: "✗",
9+
tick_data: "1",
10+
cross_data: "0",
11+
};
12+
613
export interface InfoField {
714
key: string;
815
value: string | number | object;
@@ -168,8 +175,8 @@ export class TextInfo {
168175
const valueRow: string[] = [];
169176

170177
Object.entries(flags).forEach(([, value]) => {
171-
statusRow.push(value ? "✓" : "✗");
172-
valueRow.push(value ? "1" : "0");
178+
statusRow.push(value ? FLAGS_DATA.tick : FLAGS_DATA.cross);
179+
valueRow.push(value ? FLAGS_DATA.tick_data : FLAGS_DATA.cross_data);
173180
});
174181

175182
// Create headers for the table
@@ -186,7 +193,11 @@ export class TextInfo {
186193
),
187194
fieldsPerRow: Object.keys(flags).length,
188195
rows: [statusRow, valueRow],
189-
tableClasses: [CSS_CLASSES.TABLE, CSS_CLASSES.RIGHT_BAR_TABLE],
196+
tableClasses: [
197+
CSS_CLASSES.TABLE,
198+
CSS_CLASSES.RIGHT_BAR_TABLE,
199+
CSS_CLASSES.TCP_FLAGS_TABLE,
200+
],
190201
});
191202

192203
// Get the table element

src/graphics/renderables/arp_table.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ export class ArpTable {
4141
editableColumns: [false, true], // Make all columns non-editable
4242
onEdit: onEdit,
4343
onDelete: onDelete,
44-
tableClasses: [CSS_CLASSES.RIGHT_BAR_TABLE],
44+
tableClasses: [
45+
CSS_CLASSES.TABLE,
46+
CSS_CLASSES.RIGHT_BAR_TABLE,
47+
CSS_CLASSES.ARP_TABLE,
48+
],
4549
});
4650

4751
this.toggleButton = new ToggleButton({

src/graphics/renderables/program_runner_info.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export class ProgramRunnerInfo implements Renderable {
117117
fieldsPerRow: maxRowLength,
118118
rows,
119119
onDelete,
120-
tableClasses: [CSS_CLASSES.RIGHT_BAR_TABLE], // CSS class for the table
120+
tableClasses: [CSS_CLASSES.TABLE, CSS_CLASSES.RIGHT_BAR_TABLE], // CSS class for the table
121121
});
122122

123123
return table.toHTML();

src/graphics/renderables/routing_table.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ export class RoutingTable {
4646
editableColumns: [false, true, true, false], // Make the last column non-editable
4747
onEdit: onEdit,
4848
onDelete: onDelete,
49-
tableClasses: [CSS_CLASSES.RIGHT_BAR_TABLE],
49+
tableClasses: [
50+
CSS_CLASSES.TABLE,
51+
CSS_CLASSES.RIGHT_BAR_TABLE,
52+
CSS_CLASSES.ROUTER_TABLE,
53+
],
5054
});
5155

5256
this.toggleButton = new ToggleButton({

src/packets/icmp.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,16 @@ class EchoMessage extends IcmpPacket {
104104
...this.data,
105105
]);
106106
}
107+
108+
getPayload(): Record<string, string | number | object> {
109+
return {
110+
Type: this.type,
111+
Code: this.code,
112+
Identifier: this.identifier,
113+
SequenceNumber: this.sequenceNumber,
114+
Data: this.data,
115+
};
116+
}
107117
}
108118

109119
export class EchoRequest extends EchoMessage {

src/packets/ip.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ export interface IpPayload {
142142
getDetails?(layer: Layer): Record<string, string | number | object>;
143143
// Get ports of the payload (if any)
144144
getPorts(): Ports;
145+
// Get the payload data for Network layer
146+
getPayload?(): Record<string, string | number | object> | string;
145147
}
146148

147149
// Info taken from the original RFC: https://datatracker.ietf.org/doc/html/rfc791#section-3.1
@@ -289,7 +291,7 @@ export class IPv4Packet implements FramePayload {
289291
"Time to Live": this.timeToLive,
290292
Protocol: this.protocol,
291293
"Header Checksum": this.headerChecksum,
292-
Payload: this.payload,
294+
Payload: this.payload.getPayload(),
293295
};
294296
} else {
295297
return this.payload.getDetails(layer);

src/packets/tcp.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,10 @@ export class TcpSegment implements IpPayload {
254254
destinationPort: this.destinationPort,
255255
};
256256
}
257+
258+
getPayload(): string {
259+
return "TCP";
260+
}
257261
}
258262

259263
function checkUint(n: number, numBits: number): void {

src/styles/table.css

Lines changed: 72 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,89 @@
1-
.right-bar-table {
2-
display: table; /* Cambiado a table para mejor comportamiento de columnas */
3-
width: 100%; /* Ocupa todo el ancho disponible */
4-
border-collapse: collapse; /* Elimina espacios entre bordes */
5-
font-size: 1rem; /* Tamaño de fuente legible */
6-
text-align: center; /* Centra el texto en las celdas */
7-
border-radius: 1rem; /* Bordes redondeados */
8-
box-shadow: 0 0.5vh 1vh rgba(0, 0, 0, 0.1); /* Sombra para profundidad */
9-
table-layout: auto; /* Cambiado a auto para ancho dinámico de columnas */
10-
overflow-x: auto; /* Mantiene el scroll horizontal si es necesario */
11-
clip-path: inset(
12-
0 round 1rem
13-
); /* Recorta el área del scroll respetando el border-radius */
1+
/* Common styles for both tables */
2+
.table-base {
3+
width: 100%;
4+
border-collapse: collapse;
5+
font-size: 1rem;
6+
text-align: center;
7+
border-radius: 1rem;
8+
box-shadow: 0 0.5vh 1vh rgba(0, 0, 0, 0.1);
9+
clip-path: inset(0 round 1rem);
10+
overflow-x: auto;
11+
}
12+
13+
/* Common cell styles */
14+
.table-base th,
15+
.table-base td {
16+
word-wrap: break-word;
17+
overflow-wrap: break-word;
18+
white-space: normal;
19+
padding: 1vh;
20+
border: 0.2vh solid #ddd;
21+
text-align: center;
1422
}
1523

16-
/* Ensures columns do not overflow */
17-
.right-bar-table th,
18-
.right-bar-table td {
19-
word-wrap: break-word; /* Wraps long words */
20-
overflow-wrap: break-word; /* Ensures proper text wrapping */
21-
white-space: normal; /* Allows text to wrap naturally */
24+
.table-base th {
25+
background-color: #333;
26+
color: white;
27+
box-sizing: border-box;
2228
}
2329

24-
.right-bar-table th {
25-
background-color: #333; /* Dark background for contrast */
26-
color: white; /* White text for readability */
27-
padding: 1vh; /* Adds spacing inside header cells */
28-
border: 0.2vh solid #ddd; /* Adds subtle borders */
29-
text-align: center; /* Centers text */
30-
/* Eliminado el width fijo del 33% */
31-
box-sizing: border-box; /* Ensures width includes padding and borders */
30+
.table-base td {
31+
transition: background-color 0.3s ease-in-out;
3232
}
3333

34-
.right-bar-table td {
35-
padding: 1vh; /* Adds spacing inside table cells */
36-
border: 0.2vh solid #ddd; /* Adds subtle borders */
37-
text-align: center; /* Centers text */
38-
transition: background-color 0.3s ease-in-out; /* Smooth hover effect */
34+
.table-base td:hover {
35+
background-color: #f0f0f0;
36+
cursor: pointer;
3937
}
4038

41-
/* Hover effect for table cells */
42-
.right-bar-table td:hover {
43-
background-color: #f0f0f0; /* Light gray on hover */
44-
cursor: pointer; /* Indicates interactivity */
39+
/* TCP FLAGS TABLE specific styles */
40+
.tcp-flags-table {
41+
display: table;
42+
table-layout: auto;
4543
}
4644

47-
/* Alternating row colors for better readability */
48-
.right-bar-table tr:nth-child(even) {
49-
background-color: #f9f9f9; /* Light gray for even rows */
45+
.tcp-flags-table tr:nth-child(even) {
46+
background-color: #f9f9f9;
5047
}
5148

52-
.right-bar-table tr:nth-child(odd) {
53-
background-color: #fff; /* White for odd rows */
49+
.tcp-flags-table tr:nth-child(odd) {
50+
background-color: #fff;
5451
}
5552

56-
/* Para asegurar que el contenedor de la tabla permita scroll horizontal */
57-
.right-bar-table-container {
53+
/* TCP table container for proper scrolling */
54+
.tcp-flags-table-container {
5855
overflow-x: auto;
5956
border-radius: 1rem;
6057
}
58+
59+
/* ROUTER TABLE specific styles */
60+
.router-table {
61+
display: block;
62+
table-layout: fixed;
63+
}
64+
65+
.router-table th {
66+
width: 33%;
67+
}
68+
69+
/* ARP TABLE specific styles */
70+
.arp-table {
71+
width: 100%;
72+
table-layout: fixed;
73+
}
74+
75+
/* Define consistent column widths for ARP table */
76+
.arp-table th:nth-child(1),
77+
.arp-table td:nth-child(1) {
78+
width: 33%;
79+
}
80+
81+
.arp-table th:nth-child(2),
82+
.arp-table td:nth-child(2) {
83+
width: 57%;
84+
}
85+
86+
.arp-table th:nth-child(3),
87+
.arp-table td:nth-child(3) {
88+
width: 10%; /* Ensure consistent width for remove button column */
89+
}

src/utils/constants/css_constants.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ export const CSS_CLASSES = {
2020
RIGHT_BAR_START_BUTTON: "right-bar-start-button",
2121

2222
// Table
23-
TABLE: "table",
23+
TABLE: "table-base",
24+
TCP_FLAGS_TABLE: "tcp-flags-table",
25+
ROUTER_TABLE: "router-table",
26+
ARP_TABLE: "arp-table",
2427
RIGHT_BAR_TABLE: "right-bar-table",
2528
TOGGLE_TABLE: "toggle-table",
2629
TABLE_WRAPPER: "table-wrapper",

0 commit comments

Comments
 (0)