-
Notifications
You must be signed in to change notification settings - Fork 1
/
SparseBurstsErrorModel.hpp
76 lines (63 loc) · 2.26 KB
/
SparseBurstsErrorModel.hpp
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
#include "ErrorModel.hpp"
#include "Packet.hpp"
#include <iostream>
#include <bitset>
#include <iomanip>//setprecision setfixed
#define FIXED_FLOAT(p, x) std::fixed << std::setprecision(p) <<(x)
class SparseBurstsErrorModel: public ErrorModel {
private:
double BOR; //burst occurrence rate
uint16_t Fmin;
uint16_t Fmax;
public:
SparseBurstsErrorModel(double BOR, uint16_t F_):ErrorModel() {
this->BOR = BOR;
this->Fmin = F_;
this->Fmax = F_;
}
SparseBurstsErrorModel(double BOR, uint16_t Fmin_, uint16_t Fmax_):ErrorModel() {
this->BOR = BOR;
this->Fmin = Fmin_;
this->Fmax = Fmax_;
}
SparseBurstsErrorModel(double BOR, uint16_t F_, RNG* rng):ErrorModel(rng) {
this->BOR = BOR;
this->Fmin = F_;
this->Fmax = F_;
}
SparseBurstsErrorModel(double BOR, uint16_t Fmin_, uint16_t Fmax_, RNG* rng):ErrorModel(rng) {
this->BOR = BOR;
this->Fmin = Fmin_;
this->Fmax = Fmax_;
}
void printAttributes(){
std::cout << "Sparse Bursts Error Model: " << std::endl;
std::cout << "BOR: " << FIXED_FLOAT(5, this->BOR) << std::endl;
std::cout << "F: [" << this->Fmin << ", " << this->Fmax << "]" << std::endl;
}
uint16_t injectErrors(Packet* packet, bool forceError) {
uint16_t numberOfErrors = 0;
uint16_t i = 0, j = 7;
uint16_t eLength = 0;
bool lastError = false;
for(uint16_t i=0; i<packet->getLength(); ++i){
for(uint16_t j=7; j<8; --j){
if(eLength > 0){
numberOfErrors+=packet->injectErrorInChunk(i*8+j);
eLength--;
if (eLength == 0)
lastError = true;
}else if(lastError){
lastError = false;
}else if(getRNG()->trueFalseProb(this->BOR)){
eLength = this->rng->next(Fmin, Fmax)-1;
numberOfErrors+=packet->injectErrorInChunk(i*8+j);
}
}
}
if (numberOfErrors == 0 && forceError)
numberOfErrors+=packet->injectErrorInChunk(getRNG()->next(packet->getLength()));
packet->updateBuffers();
return numberOfErrors;
}
};