-
Notifications
You must be signed in to change notification settings - Fork 0
/
SlidingWindow.cc
116 lines (98 loc) · 3.31 KB
/
SlidingWindow.cc
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#ifndef CONGESTIONWINDOW
#define CONGESTIONWINDOW
#include <string.h>
#include <omnetpp.h>
#include "SlidingWindow.h"
using namespace omnetpp;
typedef std::map<int,packetMetadata>::iterator windowIterator;
SlidingWindow::SlidingWindow() {
}
SlidingWindow::~SlidingWindow() {
}
int SlidingWindow::getAck(int seqN) {
windowIterator pairIterator = slidingWindow.find(seqN);
if (pairIterator == slidingWindow.end()) {
// No existe en el diccionario
return -1;
}
return pairIterator->second->ackCounter;
}
void SlidingWindow::addAck(int seqN) {
windowIterator pairIterator = slidingWindow.find(seqN);
if (pairIterator != slidingWindow.end()) {
packetMetadata pair = pairIterator->second;
(pair->ackCounter)++;
std::cout << "SW :: ackCounter[" << seqN << "]++ " << pair->ackCounter << "\n";
slidingWindow[seqN] = pair;
}
}
void SlidingWindow::addVolt(Volt * volt) {
int seqN = volt->getSeqNumber();
std::cout << "SW :: Adding Volt " << seqN << " to Sliding Window\n";
packetMetadata newPair = new _packetMetadata();
newPair->ackCounter = 0;
newPair->volt = volt;
if(slidingWindow.find(seqN) != slidingWindow.end()) {
std::cout << "SW :: WARNING :: addVolt is overwriting a previous instance\n";
}
slidingWindow[seqN] = newPair;
bytesInFlight += volt->getByteLength();
std::cout << "SW :: Volt " << seqN << " added successfully\n";
}
Volt * SlidingWindow::popVolt(int seqN) {
Volt * volt = NULL;
windowIterator pairIterator = slidingWindow.find(seqN);
if (pairIterator != slidingWindow.end()) {
std::cout << "SW :: Removing Volt " << seqN << " from Sliding Window\n";
volt = pairIterator->second->volt;
delete(pairIterator->second);
slidingWindow.erase(pairIterator);
bytesInFlight -= volt->getByteLength();
} else {
std::cout << "SW :: WARNING :: popVolt could not find Volt " << seqN << "\n";
};
return volt;
}
Volt * SlidingWindow::dupVolt(int seqN) {
Volt * volt = NULL;
windowIterator pairIterator = slidingWindow.find(seqN);
if(pairIterator != slidingWindow.end()) {
std::cout << "SW :: Copying Volt " << seqN << "\n";
volt = pairIterator->second->volt->dup();
} else {
std::cout << "SW :: WARNING :: dupVolt could not find Volt " << seqN << "\n";
}
return volt;
}
bool SlidingWindow::isVoltInWindow(int seqN){
windowIterator pairIterator = slidingWindow.find(seqN);
return pairIterator != slidingWindow.end();
}
double SlidingWindow::getSendTime(int seqN){
windowIterator pairIterator = slidingWindow.find(seqN);
if (pairIterator == slidingWindow.end()) {
std::cout << "SW :: WARNING :: getSendTime(" << seqN << ") didn't found any packetMetadata\n";
return -1;
}
return pairIterator->second->sendTime;
}
void SlidingWindow::addSendTime(int seqN, double time){
windowIterator pairIterator = slidingWindow.find(seqN);
if (pairIterator != slidingWindow.end()) {
packetMetadata pair = pairIterator->second;
pair->sendTime = time;
slidingWindow[seqN] = pair;
}
}
int SlidingWindow::getBaseWindow() {
return baseWindow;
}
void SlidingWindow::setBaseWindow(int base) {
std::cout << "SW :: Moving Sliding Window from " << baseWindow << " to " << base << "\n";
baseWindow = base;
}
int SlidingWindow::amountBytesInFlight() {
std::cout << "SW :: " << bytesInFlight << " bytes in flight\n";
return bytesInFlight;
}
#endif /* CONGESTIONCONTROLLER */