Skip to content

Commit 7c778b2

Browse files
Update previous Router with forwarding information
When a new Router joins the network, inform the previous router (if applicable) about its new forwarding Address and Port
1 parent ef92ccf commit 7c778b2

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Server/src/Switcher.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,26 @@ Switcher.on('message', (msg, rinfo) => {
5757

5858
// Add Router to list of active connections
5959
Routers.add(newClient({ address, port, routerId }));
60+
61+
// Get Flow Table values of previous Router or Client, and update with address and port of forwarding Router
62+
if (routerCount > 1) {
63+
previousRouterId = `R${routerCount - 1}`;
64+
let flowTableValues = FlowTable.get(previousRouterId) ?? [];
65+
let previousAddress: string = flowTableValues[2] as string;
66+
let previousPort: number = flowTableValues[3] as unknown as number;
67+
68+
// Update Flow Table next hop values (forwardAddress and forwardPort)
69+
if (flowTableValues) {
70+
flowTableValues[4] = address.toString();
71+
flowTableValues[5] = port.toString();
72+
FlowTable.set(previousRouterId, flowTableValues);
73+
}
74+
75+
// Send message to previous Client / Router that its next router is active
76+
sendMessage = prepareMessage(6, { forwardAddress: address, forwardPort: port });
77+
sendMessageToRouter(sendMessage, previousAddress, previousPort);
78+
}
79+
6080
sendMessage = { routerId, message: "New Router", address, port };
6181
messageType = 0;
6282
break;

0 commit comments

Comments
 (0)