Skip to content

Commit e76ac0e

Browse files
Manuel-Polpgallino
andauthored
fix speed multiplier when setting new network and change 'Switching Table' to 'Forwarding Table' (#263)
### Fix of the bug reported in issue #250 The bug was fixed by changing the method `GlobalContext.load()`. Now, in the `GlobalContext.load()` function, if a new `speedMultiplier` is not provided, the previous value is kept, ensuring the pause/resume state remains consistent. ### Rename of the "Switching Table" to "Forwarding Table" Renamed "Switching Table" to "Forwarding Table" to align with terminology used in official documentation and texts. Closes #250 Co-authored-by: Pedro Gallino <[email protected]>
1 parent 4576059 commit e76ac0e

File tree

12 files changed

+99
-98
lines changed

12 files changed

+99
-98
lines changed

src/context.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ export class GlobalContext {
8383
load(
8484
datagraph: DataGraph,
8585
layer: Layer = Layer.Link,
86-
speedMultiplier: SpeedMultiplier = new SpeedMultiplier(1),
86+
speedMultiplier?: SpeedMultiplier,
8787
) {
8888
this.setNetwork(datagraph, layer);
8989
this.viewport.restorePosition();
90-
this.setSpeedMultiplier(speedMultiplier);
90+
if (speedMultiplier) this.setSpeedMultiplier(speedMultiplier);
9191
this.setupAutoSave();
9292
this.saveToLocalStorage();
9393
urManager.reset();

src/graphics/renderables/device_info.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ import { LabeledProgressBar } from "../components/labeled_progress_bar";
1717
import { ArpTable } from "./arp_table";
1818
import { Layer } from "../../types/layer";
1919
import { DataNetworkDevice, DataSwitch } from "../../types/data-devices";
20-
import { SwitchingTable } from "./switching_table";
20+
import { ForwardingTable } from "./forwarding_table";
2121
import { getRoutingTable } from "../../types/network-modules/tables/routing_table";
2222
import { ToggleInfo } from "../components/toggle_info";
2323
import { getArpTable } from "../../types/network-modules/tables/arp_table";
24-
import { getSwitchingTable } from "../../types/network-modules/tables/switching_table";
24+
import { getForwardingTable } from "../../types/network-modules/tables/forwarding_table";
2525

2626
export class DeviceInfo extends BaseInfo {
2727
readonly device: ViewDevice;
@@ -218,28 +218,28 @@ export class DeviceInfo extends BaseInfo {
218218
}
219219
}
220220

221-
addSwitchingTable(viewgraph: ViewGraph, deviceId: number): void {
221+
addForwardingTable(viewgraph: ViewGraph, deviceId: number): void {
222222
const dataGraph = viewgraph.getDataGraph();
223-
const entries = getSwitchingTable(dataGraph, deviceId);
223+
const entries = getForwardingTable(dataGraph, deviceId);
224224

225225
const rows = entries.map((entry) => ({
226226
values: [entry.mac, entry.port.toString()],
227227
edited: entry.edited ?? false,
228228
}));
229229

230-
const switchingTable = new SwitchingTable({
230+
const forwardingTable = new ForwardingTable({
231231
rows,
232232
viewgraph,
233233
deviceId,
234234
});
235235

236-
this.inputFields.push(switchingTable.toHTML());
236+
this.inputFields.push(forwardingTable.toHTML());
237237

238238
const dataDevice = viewgraph.getDataGraph().getDevice(deviceId);
239239

240240
if (dataDevice instanceof DataSwitch) {
241-
dataDevice.setSwitchingTableChangeListener(() => {
242-
switchingTable.refreshTable();
241+
dataDevice.setForwardingTableChangeListener(() => {
242+
forwardingTable.refreshTable();
243243
});
244244
} else {
245245
console.warn(`Device with ID ${deviceId} is not a DataNetworkDevice.`);

src/graphics/renderables/switching_table.ts renamed to src/graphics/renderables/forwarding_table.ts

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,47 @@
11
import { DeviceId } from "../../types/graphs/datagraph";
22
import { ViewGraph } from "../../types/graphs/viewgraph";
33
import {
4-
clearSwitchingTable,
5-
getSwitchingTable,
6-
removeSwitchingTableEntry,
7-
saveSwitchingTableManualChange,
8-
} from "../../types/network-modules/tables/switching_table";
4+
clearForwardingTable,
5+
getForwardingTable,
6+
removeForwardingTableEntry,
7+
saveForwardingTableManualChange,
8+
} from "../../types/network-modules/tables/forwarding_table";
99
import { ALERT_MESSAGES } from "../../utils/constants/alert_constants";
1010
import { CSS_CLASSES } from "../../utils/constants/css_constants";
1111
import {
1212
InvalidMacError,
1313
InvalidPortError,
14-
SWITCHING_TABLE_CONSTANTS,
14+
FORWARDING_TABLE_CONSTANTS,
1515
} from "../../utils/constants/table_constants";
1616
import { TOOLTIP_KEYS } from "../../utils/constants/tooltips_constants";
1717
import { Button } from "../basic_components/button";
1818
import { Table, TableRow } from "../basic_components/table";
1919
import { ToggleButton } from "../basic_components/toggle_button";
2020
import { showError, showSuccess } from "./alert_manager";
2121

22-
export interface SwitchingTableProps {
22+
export interface ForwardingTableProps {
2323
rows: TableRow[]; // Rows for the table
2424
viewgraph: ViewGraph; // ViewGraph instance for callbacks
2525
deviceId: DeviceId; // Device ID for callbacks
2626
}
2727

28-
export class SwitchingTable {
28+
export class ForwardingTable {
2929
private container: HTMLElement;
3030
private table: Table;
3131
private toggleButton: ToggleButton;
3232

33-
constructor(private props: SwitchingTableProps) {
33+
constructor(private props: ForwardingTableProps) {
3434
this.container = document.createElement("div");
3535

3636
const { onEdit, onRegenerate, onDelete, onAddRow } =
37-
this.setSwitchingTableCallbacks();
37+
this.setForwardingTableCallbacks();
3838

3939
// Create the regenerate button
4040
const regenerateButton = this.createRegenerateButton(onRegenerate);
4141

4242
const headers = {
4343
[TOOLTIP_KEYS.MAC_ADDRESS]: TOOLTIP_KEYS.MAC_ADDRESS,
44-
[TOOLTIP_KEYS.PORT]: TOOLTIP_KEYS.PORT,
44+
[TOOLTIP_KEYS.INTERFACE]: TOOLTIP_KEYS.INTERFACE,
4545
[TOOLTIP_KEYS.REGENERATE]: regenerateButton, // Add the regenerate button to the header
4646
};
4747

@@ -57,13 +57,13 @@ export class SwitchingTable {
5757
});
5858

5959
this.toggleButton = new ToggleButton({
60-
text: TOOLTIP_KEYS.SWITCHING_TABLE,
60+
text: TOOLTIP_KEYS.FORWARDING_TABLE,
6161
className: CSS_CLASSES.RIGHT_BAR_TOGGLE_BUTTON,
6262
onToggle: (isToggled) => {
6363
const tableElement = this.table.toHTML();
6464
tableElement.style.display = isToggled ? "block" : "none";
6565
},
66-
tooltip: TOOLTIP_KEYS.SWITCHING_TABLE,
66+
tooltip: TOOLTIP_KEYS.FORWARDING_TABLE,
6767
});
6868

6969
// Initially hide the table
@@ -101,24 +101,24 @@ export class SwitchingTable {
101101
private OnRegenerate(): void {
102102
const dataGraph = this.props.viewgraph.getDataGraph();
103103

104-
// clear the current switching table
105-
clearSwitchingTable(dataGraph, this.props.deviceId);
104+
// clear the current forwarding table
105+
clearForwardingTable(dataGraph, this.props.deviceId);
106106

107107
this.updateRows([]);
108108

109-
showSuccess(ALERT_MESSAGES.SWITCHING_TABLE_REGENERATED);
109+
showSuccess(ALERT_MESSAGES.FORWARDING_TABLE_REGENERATED);
110110
}
111111

112-
private setSwitchingTableCallbacks() {
112+
private setForwardingTableCallbacks() {
113113
const dataGraph = this.props.viewgraph.getDataGraph();
114114
const onDelete = (mac: string) => {
115-
removeSwitchingTableEntry(dataGraph, this.props.deviceId, mac);
116-
showSuccess(ALERT_MESSAGES.SWITCHING_TABLE_ENTRY_DELETED);
115+
removeForwardingTableEntry(dataGraph, this.props.deviceId, mac);
116+
showSuccess(ALERT_MESSAGES.FORWARDING_TABLE_ENTRY_DELETED);
117117
return true;
118118
};
119119

120120
const onRegenerate = () => {
121-
console.log("Regenerating Switching Table...");
121+
console.log("Regenerating Forwarding Table...");
122122
this.OnRegenerate();
123123
};
124124

@@ -134,7 +134,7 @@ export class SwitchingTable {
134134
}
135135

136136
try {
137-
const changed = saveSwitchingTableManualChange(
137+
const changed = saveForwardingTableManualChange(
138138
dataGraph,
139139
this.props.deviceId,
140140
mac,
@@ -145,7 +145,7 @@ export class SwitchingTable {
145145
return false;
146146
}
147147
this.refreshTable();
148-
showSuccess(ALERT_MESSAGES.SWITCHING_TABLE_ENTRY_EDITED);
148+
showSuccess(ALERT_MESSAGES.FORWARDING_TABLE_ENTRY_EDITED);
149149
return true;
150150
} catch (e) {
151151
if (e instanceof InvalidMacError) {
@@ -163,18 +163,18 @@ export class SwitchingTable {
163163
const [mac, portStr] = values;
164164

165165
try {
166-
const changed = saveSwitchingTableManualChange(
166+
const changed = saveForwardingTableManualChange(
167167
this.props.viewgraph.getDataGraph(),
168168
this.props.deviceId,
169169
mac.trim(),
170-
SWITCHING_TABLE_CONSTANTS.PORT_COL_INDEX,
170+
FORWARDING_TABLE_CONSTANTS.PORT_COL_INDEX,
171171
portStr.trim(),
172172
);
173173
if (!changed) {
174174
return false;
175175
}
176176
this.refreshTable();
177-
showSuccess(ALERT_MESSAGES.SWITCHING_TABLE_ENTRY_ADDED);
177+
showSuccess(ALERT_MESSAGES.FORWARDING_TABLE_ENTRY_ADDED);
178178
return true;
179179
} catch (e) {
180180
if (e instanceof InvalidMacError) {
@@ -193,7 +193,7 @@ export class SwitchingTable {
193193

194194
refreshTable(): void {
195195
const dataGraph = this.props.viewgraph.getDataGraph();
196-
const updatedEntries = getSwitchingTable(dataGraph, this.props.deviceId);
196+
const updatedEntries = getForwardingTable(dataGraph, this.props.deviceId);
197197

198198
const updatedRows = updatedEntries.map((entry) => ({
199199
values: [entry.mac.toString(), entry.port.toString()],

src/types/data-devices/dSwitch.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ import { EthernetFrame, MacAddress } from "../../packets/ethernet";
44
import { DataGraph, DeviceId, SwitchDataNode } from "../graphs/datagraph";
55
import { EntryData, Table } from "../network-modules/tables/table";
66

7-
export interface SwitchingEntry extends EntryData {
7+
export interface ForwardingEntry extends EntryData {
88
mac: string;
99
port: number;
1010
}
1111

1212
export class DataSwitch extends DataDevice {
13-
switchingTable: Table<SwitchingEntry>;
14-
private switchingTableChangeListener: (() => void) | null = null;
13+
forwardingTable: Table<ForwardingEntry>;
14+
private forwardingTableChangeListener: (() => void) | null = null;
1515

1616
constructor(graphData: SwitchDataNode, datagraph: DataGraph) {
1717
super(graphData, datagraph);
18-
this.switchingTable = new Table<SwitchingEntry>(
18+
this.forwardingTable = new Table<ForwardingEntry>(
1919
"mac",
20-
graphData.switchingTable.map(([mac, port, edited, deleted]) => ({
20+
graphData.forwardingTable.map(([mac, port, edited, deleted]) => ({
2121
mac,
2222
port,
2323
edited,
@@ -30,24 +30,24 @@ export class DataSwitch extends DataDevice {
3030
return DeviceType.Switch;
3131
}
3232

33-
updateSwitchingTable(mac: MacAddress, iface: number): void {
34-
this.switchingTable.add({
33+
updateForwardingTable(mac: MacAddress, iface: number): void {
34+
this.forwardingTable.add({
3535
mac: mac.toString(),
3636
port: iface,
3737
});
38-
if (this.switchingTableChangeListener) {
39-
this.switchingTableChangeListener();
38+
if (this.forwardingTableChangeListener) {
39+
this.forwardingTableChangeListener();
4040
}
4141
}
4242

43-
setSwitchingTableChangeListener(listener: () => void): void {
44-
this.switchingTableChangeListener = listener;
43+
setForwardingTableChangeListener(listener: () => void): void {
44+
this.forwardingTableChangeListener = listener;
4545
}
4646

4747
getDataNode(): SwitchDataNode {
4848
return {
4949
...super.getDataNode(),
50-
switchingTable: this.switchingTable.serialize(
50+
forwardingTable: this.forwardingTable.serialize(
5151
(entry) =>
5252
[
5353
entry.mac,

src/types/edge.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
showTooltip,
1616
} from "../graphics/renderables/canvas_tooltip_manager";
1717
import { updateRoutingTableIface } from "./network-modules/tables/routing_table";
18-
import { updateSwitchingTablePort } from "./network-modules/tables/switching_table";
18+
import { updateForwardingTablePort } from "./network-modules/tables/forwarding_table";
1919

2020
export class Edge extends Graphics {
2121
private _data: DataEdge;
@@ -268,7 +268,7 @@ export class Edge extends Graphics {
268268
newIface,
269269
);
270270

271-
updateSwitchingTablePort(
271+
updateForwardingTablePort(
272272
this.viewgraph.getDataGraph(),
273273
deviceId,
274274
oldIface,

src/types/graphs/datagraph.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export interface NetworkInterfaceData {
4848
}
4949

5050
export interface SwitchDataNode extends CommonDataNode {
51-
switchingTable: [string, number, boolean, boolean][]; // [mac, port, edited, deleted]
51+
forwardingTable: [string, number, boolean, boolean][]; // [mac, port, edited, deleted]
5252
type: DeviceType.Switch;
5353
}
5454

0 commit comments

Comments
 (0)