Skip to content
Snippets Groups Projects
Commit df250870 authored by rupumped's avatar rupumped
Browse files

Delays

parent 2b713811
Branches
No related tags found
No related merge requests found
Source diff could not be displayed: it is too large. Options to address this: view the blob.
...@@ -3,15 +3,25 @@ var net = require("./network"), ...@@ -3,15 +3,25 @@ var net = require("./network"),
const startupDelay = 100; const startupDelay = 100;
const connectDelay = 100; const connectDelay = 100;
const bufferCheckDelay = 1000; // The time it takes for a node to process a byte = DELAY_PKT +
const heartbeatPeriod = 400; // n*DELAY_TX_HB*DELAY_PKT/PERIOD_TX_HB +
// n*DELAY_RX_HB*DELAY_PKT/PERIOD_RX_HB +
// n*DELAY_TAKE_PULSE*DELAY_PKT/PERIOD_TAKE_PULSE,
// n=# of nearest neighbors
const DELAY_PKT = 500; // Baseline packet delay. Assuming no heartbeats, how long it takes to process a packet
const DELAY_TX_HB = 50; // How long it takes to transmit a single heartbeat to a single neighbor
const PERIOD_TX_HB = 240; // Period with which heartbeats are transmitted to all neighbors
const DELAY_RX_HB = 50; // How long it takes to receive and process a single heartbeat from a single neighbor
const PERIOD_RX_HB = PERIOD_TX_HB; // Period with which heartbeats are received from a single neighbor
const DELAY_TAKE_PULSE = 50; // How long it takes to process received heartbeats
const PERIOD_TAKE_PULSE = 2*PERIOD_RX_HB; // Period with which received heartbeats are processed
// INITIALIZE NETWORK TOPOLOGY HERE // INITIALIZE NETWORK TOPOLOGY HERE
var initTopology = []; var initTopology = [];
var rawFile = new XMLHttpRequest(); var rawFile = new XMLHttpRequest();
rawFile.open("GET", "js_code.txt", false); rawFile.open("GET", "js_code.txt", false);
rawFile.onreadystatechange = function () { rawFile.onreadystatechange = function () {
if(rawFile.readyState === 4 && (rawFile.status === 200 || rawFile.status == 0)) if(rawFile.readyState === 4 && (rawFile.status === 200 || rawFile.status === 0))
{ {
var allText = rawFile.responseText; var allText = rawFile.responseText;
allText = allText.split('\n'); allText = allText.split('\n');
...@@ -25,7 +35,7 @@ rawFile.onreadystatechange = function () { ...@@ -25,7 +35,7 @@ rawFile.onreadystatechange = function () {
initTopology.push(neighbors); initTopology.push(neighbors);
} }
} }
} };
rawFile.send(null); rawFile.send(null);
// Don't touch this code // Don't touch this code
...@@ -42,21 +52,20 @@ for (let i = 0; i < initTopology.length; i++) { ...@@ -42,21 +52,20 @@ for (let i = 0; i < initTopology.length; i++) {
this.delay(startupDelay, function() { this.delay(startupDelay, function() {
this.manager.setup(initTopology[i].length); this.manager.setup(initTopology[i].length);
}); });
this.delay(500, function() { this.tick(DELAY_PKT + initTopology[i].length*DELAY_TX_HB*DELAY_PKT/PERIOD_TX_HB
this.manager.printPorts(); + initTopology[i].length*DELAY_RX_HB*DELAY_PKT/PERIOD_RX_HB
}); + initTopology[i].length*DELAY_TAKE_PULSE*DELAY_PKT/PERIOD_TAKE_PULSE, function() {
this.tick(bufferCheckDelay, function() {
this.manager.checkBuffer(); this.manager.checkBuffer();
}); });
this.tick(heartbeatPeriod, function() { this.tick(PERIOD_TX_HB, function() {
this.manager.heartbeat(); this.manager.heartbeat();
}); });
this.tick(2*heartbeatPeriod, function() { this.tick(PERIOD_RX_HB, function() {
this.manager.takePulse(); this.manager.takePulse();
}); });
}); });
for (let j = 0; j < initTopology[i].length; j++) { for (let j = 0; j < initTopology[i].length; j++) {
if (initTopology[i][j] == -1) { if (initTopology[i][j] === -1) {
continue; continue;
} }
...@@ -70,7 +79,7 @@ for (let i = 0; i < initTopology.length; i++) { ...@@ -70,7 +79,7 @@ for (let i = 0; i < initTopology.length; i++) {
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
// PUT CUSTOM CODE HERE: // PUT CUSTOM CODE HERE:
sendPacket(0,9999,1,"Hello!",1000); sendPacket(0,99,1,"Hello!",1000);
// To test link failure, uncomment one. To test node failure, uncomment both. // To test link failure, uncomment one. To test node failure, uncomment both.
//disconnect(0,1,2,0,6000); //disconnect(0,1,2,0,6000);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment