This repository was archived by the owner on Jan 15, 2020. It is now read-only.
forked from mwarning/MeshNetSimulator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlink.js
45 lines (39 loc) · 1.46 KB
/
link.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
function Link(quality = 100, bandwidth = 50, channel = 0) {
/* Required fields */
/*
[0..100] Link quality in percent
The quality is 100% minus expected packet loss.
A wireless link usually has a medium packet loss of 25%. A wired link maybe 2%.
*/
this.quality = quality;
/*
[0..] Number of packets
The bandwidth is the number of packets that can be transmitted in one simulation step
How this value is applied is decided in the transmit() method.
*/
this.bandwidth = bandwidth;
/*
[0..] Transmission medium
Channel 0 represents a link over its own medium. The link does not influence any other links.
Influence means that the packetCount for the transmit() method is not cumulated over multiple links.
With channels >0 link can be grouped together, e.g. as to simulate multiple (e.g. wireless) interfaces.
*/
this.channel = channel;
}
Link.prototype.reset = function () {
}
Link.prototype.getLinkLabel = function () {
return '';
}
// Move a packet to a target node
Link.prototype.transmit = function (packet, packetCount) {
// Calculate packet transmission probability
// The formula needs improvments!
var n = 100 * (Math.min(packetCount, this.bandwidth) / this.bandwidth);
var probability = (this.quality / 100) * Math.pow(0.999, n);
return probability > Math.random();
};
// For changing the implementation during simulation
Link.prototype.copyFromOldImplementation = function (oldLink) {
copyExistingFields(oldLink, this);
};