-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathABP_NAK.cpp
More file actions
29 lines (27 loc) · 1.05 KB
/
Copy pathABP_NAK.cpp
File metadata and controls
29 lines (27 loc) · 1.05 KB
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
#include <iostream>
#include <fstream>
#include <math.h>
#include "ABP_NAK.h"
using namespace std;
// The only difference is in this function, which we are overriding
void ABP_NAK::finishSending(DiscreteEvent *event) {
DiscreteEvent timeOutEvent = DES.top();
if (event == NULL) {
currentTime = timeOutEvent.getTime();
} else {
DiscreteEvent ackEvent = *event;
DES.push(ackEvent);
if (!ackEvent.getErrorFlag() && ackEvent.getSequenceNumber() == nextExpectedAck) {
// Set the current time to the earliest event in the DES
currentTime = DES.top().getTime();
sequenceNumber = (sequenceNumber + 1) % 2;
nextExpectedAck = (nextExpectedAck + 1) % 2;
numberOfPacketsFinished++;
} else {
// The only line that changes, as there is no longer a timeout when a packet arrives in error. The packet is retransmitted and thus the current time will just be the ack time
currentTime = ackEvent.getTime();
}
DES.pop();
}
DES.pop();
}