INET Framework for OMNeT++/OMNEST
inet::physicallayer::BerParseFile Class Reference

Radio model for IEEE 802.11. More...

#include <BerParseFile.h>

Classes

struct  LongBer
 
struct  SnrBer
 

Public Member Functions

void parseFile (const char *filename)
 
bool isFile ()
 
void setPhyOpMode (char p)
 
double getPer (double speed, double tsnr, int tlen)
 
 BerParseFile (char p)
 
 ~BerParseFile ()
 

Protected Types

typedef std::vector< SnrBerSnrBerList
 
typedef std::vector< LongBer * > BerList
 
typedef std::vector< BerListBerTable
 

Protected Member Functions

int getTablePosition (double speed)
 
void clearBerTable ()
 
double dB2fraction (double dB)
 

Protected Attributes

BerTable berTable
 
char phyOpMode
 
bool fileBer
 

Detailed Description

Radio model for IEEE 802.11.

The implementation is largely based on the Mobility Framework's SnrEval80211 and Decider80211 modules. See the NED file for more info.

Member Typedef Documentation

typedef std::vector<LongBer *> inet::physicallayer::BerParseFile::BerList
protected
typedef std::vector<BerList> inet::physicallayer::BerParseFile::BerTable
protected
typedef std::vector<SnrBer> inet::physicallayer::BerParseFile::SnrBerList
protected

Constructor & Destructor Documentation

inet::physicallayer::BerParseFile::BerParseFile ( char  p)
inline
80 { setPhyOpMode(p); fileBer = false; }
bool fileBer
Definition: BerParseFile.h:66
void setPhyOpMode(char p)
Definition: BerParseFile.cc:45
inet::physicallayer::BerParseFile::~BerParseFile ( )
357 {
358  clearBerTable();
359 }
void clearBerTable()
Definition: BerParseFile.cc:32

Member Function Documentation

void inet::physicallayer::BerParseFile::clearBerTable ( )
protected

Referenced by setPhyOpMode(), and ~BerParseFile().

33 {
34  while (!berTable.empty()) {
35  BerList *berList = &berTable.back();
36  while (!berList->empty()) {
37  delete berList->back();
38  berList->pop_back();
39  }
40  berTable.pop_back();
41  }
42  fileBer = false;
43 }
std::vector< LongBer * > BerList
Definition: BerParseFile.h:61
bool fileBer
Definition: BerParseFile.h:66
BerTable berTable
Definition: BerParseFile.h:64
double inet::physicallayer::BerParseFile::dB2fraction ( double  dB)
inlineprotected

Referenced by parseFile().

71  {
72  return pow(10.0, (dB / 10));
73  }
double inet::physicallayer::BerParseFile::getPer ( double  speed,
double  tsnr,
int  tlen 
)

Referenced by inet::physicallayer::Ieee80211BerTableErrorModel::computePacketErrorRate().

89 {
90  BerList *berlist;
91  berlist = &berTable[getTablePosition(speed)];
92  LongBer *pre = nullptr;
93  LongBer *pos = nullptr;
94  unsigned int j;
95  for (j = 0; j < berlist->size(); j++) {
96  pos = *(berlist->begin() + j);
97  if (pos->longpkt >= tlen) {
98  break;
99  }
100  }
101  if (j == 0)
102  pre = nullptr;
103  else {
104  if (j == berlist->size())
105  pre = *(berlist->begin() + j - 2);
106  else
107  pre = *(berlist->begin() + j - 1);
108  }
109  SnrBer snrdata1;
110  SnrBer snrdata2;
111  SnrBer snrdata3;
112  SnrBer snrdata4;
113  snrdata1.snr = -1;
114  snrdata1.ber = -1;
115  snrdata2.snr = -1;
116  snrdata2.ber = -1;
117  snrdata3.snr = -1;
118  snrdata3.ber = -1;
119  snrdata4.snr = -1;
120  snrdata4.ber = -1;
121 
122  if (pos->snrlist.size() < 1)
123  throw cRuntimeError("model error: pos->snrlist is empty");
124  if (tsnr > pos->snrlist[pos->snrlist.size() - 1].snr) {
125  snrdata1 = pos->snrlist[pos->snrlist.size() - 1];
126  snrdata2 = pos->snrlist[pos->snrlist.size() - 1];
127  }
128  else {
129  for (j = 0; j < pos->snrlist.size(); j++) {
130  snrdata1 = pos->snrlist[j];
131  if (tsnr <= snrdata1.snr)
132  break;
133  }
134  if (j == 0) {
135  snrdata2.snr = -1;
136  snrdata2.ber = -1;
137  }
138  else {
139  if (j == pos->snrlist.size()) {
140  if (j < 2)
141  throw cRuntimeError("model error: pos->snrlist is too short, should be 2 or more elements");
142  snrdata2 = pos->snrlist[j - 2];
143  }
144  else
145  snrdata2 = pos->snrlist[j - 1];
146  }
147  }
148 
149  if (pre == nullptr)
150  pre = pos;
151  if (tsnr > pre->snrlist[pre->snrlist.size() - 1].snr) {
152  snrdata3 = pre->snrlist[pre->snrlist.size() - 1];
153  snrdata4 = pre->snrlist[pre->snrlist.size() - 1];
154  }
155  else {
156  for (j = 0; j < pre->snrlist.size(); j++) {
157  snrdata3 = pre->snrlist[j];
158  if (tsnr <= snrdata3.snr)
159  break;
160  }
161  if (j != 0) {
162  if (j == pre->snrlist.size())
163  snrdata4 = pre->snrlist[j - 2];
164  else
165  snrdata4 = pre->snrlist[j - 1];
166  }
167  }
168  if (snrdata2.snr == -1) {
169  snrdata2.snr = snrdata1.snr;
170  snrdata2.ber = snrdata1.ber;
171  }
172  if (snrdata4.snr == -1) {
173  snrdata4.snr = snrdata3.snr;
174  snrdata4.ber = snrdata3.ber;
175  }
176  double per1, per2, per;
177  per1 = snrdata1.ber;
178  per2 = snrdata3.ber;
179 
180  if (tsnr <= snrdata1.snr) {
181  if (snrdata2.snr != snrdata1.snr)
182  per1 = snrdata1.ber + (snrdata2.ber - snrdata1.ber) / (snrdata2.snr - snrdata1.snr) * (tsnr - snrdata1.snr);
183  }
184  if (tsnr <= snrdata3.snr) {
185  if (snrdata3.snr != snrdata4.snr)
186  per2 = snrdata3.ber + (snrdata4.ber - snrdata3.ber) / (snrdata4.snr - snrdata3.snr) * (tsnr - snrdata3.snr);
187  }
188  if (per1 != -1 && per2 != -1) {
189  if (pos->longpkt != pre->longpkt)
190  per = per2 + (per1 - per2) / (pos->longpkt - pre->longpkt) * (tlen - pre->longpkt);
191  else
192  per = per2;
193  }
194  else {
195  if (per1 != -1) {
196  per = per1;
197  }
198  else {
199  if (per2 != -1) {
200  per = per2;
201  }
202  else {
203  EV << "No PER available";
204  per = 0;
205  }
206  }
207  }
208  return per;
209 }
std::vector< LongBer * > BerList
Definition: BerParseFile.h:61
BerTable berTable
Definition: BerParseFile.h:64
int getTablePosition(double speed)
Definition: BerParseFile.cc:55
int inet::physicallayer::BerParseFile::getTablePosition ( double  speed)
protected

Referenced by getPer().

56 {
57  speed /= 1000000;
58  if (phyOpMode == 'b') {
59  if (speed < 2)
60  return 0;
61  else if (speed < 5)
62  return 1;
63  else if (speed < 11)
64  return 2;
65  else
66  return 3;
67  }
68  else {
69  if (speed < 9)
70  return 0;
71  else if (speed < 12)
72  return 1;
73  else if (speed < 18)
74  return 2;
75  else if (speed < 24)
76  return 3;
77  else if (speed < 36)
78  return 4;
79  else if (speed < 48)
80  return 5;
81  else if (speed < 54)
82  return 6;
83  else
84  return 7;
85  }
86 }
char phyOpMode
Definition: BerParseFile.h:65
bool inet::physicallayer::BerParseFile::isFile ( )
inline
77 { return fileBer; }
bool fileBer
Definition: BerParseFile.h:66
void inet::physicallayer::BerParseFile::parseFile ( const char *  filename)

Referenced by inet::physicallayer::Ieee80211BerTableErrorModel::initialize().

212 {
213  std::ifstream in(filename, std::ios::in);
214  if (in.fail())
215  throw cRuntimeError("Cannot open file '%s'", filename);
216  std::string line;
217  std::string subline;
218 
219  while (std::getline(in, line)) {
220  // '#' line
221  std::string::size_type found = line.find('#');
222  if (found == 0)
223  continue;
224  if (found != std::string::npos)
225  subline = line;
226  else
227  subline = line.substr(0, found);
228  found = subline.find("$self");
229  if (found == std::string::npos)
230  continue;
231  // Node Id
232  found = subline.find("add");
233  if (found == std::string::npos)
234  continue;
235  // Initial position
236 
237  std::string::size_type pos1 = subline.find("Mode");
238  std::string::size_type pos2 = subline.find("Mb");
239  BerList *berlist;
240  std::string substr = subline.substr(pos1 + 4, pos2 - (pos1 + 4));
241 // int speed = std::atof (subline.substr(pos1+4,pos2).c_str());
242 
243  int position = -1;
244  if (phyOpMode == 'b') {
245  if (!strcmp(substr.c_str(), "1"))
246  position = 0;
247  else if (!strcmp(substr.c_str(), "2"))
248  position = 1;
249  else if (!strcmp(substr.c_str(), "5_5"))
250  position = 2;
251  else if (!strcmp(substr.c_str(), "11"))
252  position = 3;
253  else
254  continue;
255  }
256  else {
257  if (!strcmp(substr.c_str(), "6"))
258  position = 0;
259  else if (!strcmp(substr.c_str(), "9"))
260  position = 1;
261  else if (!strcmp(substr.c_str(), "12"))
262  position = 2;
263  else if (!strcmp(substr.c_str(), "18"))
264  position = 3;
265  else if (!strcmp(substr.c_str(), "24"))
266  position = 4;
267  else if (!strcmp(substr.c_str(), "36"))
268  position = 5;
269  else if (!strcmp(substr.c_str(), "48"))
270  position = 6;
271  else if (!strcmp(substr.c_str(), "54"))
272  position = 7;
273  else
274  continue;
275  }
276 
277  if (position < 0)
278  throw cRuntimeError("ber parse file error");
279 
280  berlist = &berTable[position];
281 
282  std::string parameters = subline.substr(pos2 + 3, std::string::npos);
283  std::stringstream linestream(parameters);
284  int pkSize;
285  double snr;
286  double ber;
287  linestream >> pkSize;
288  linestream >> snr;
289  linestream >> ber;
290  snr = dB2fraction(snr);
291  if (pkSize < 128)
292  pkSize = 128;
293  else if (128 <= pkSize && pkSize < 256)
294  pkSize = 128;
295  else if (256 <= pkSize && pkSize < 512)
296  pkSize = 256;
297  else if (512 <= pkSize && pkSize < 1024)
298  pkSize = 512;
299  else if (1024 <= pkSize && pkSize < 1500)
300  pkSize = 1024;
301  else
302  pkSize = 1500;
303  if (berlist->size() == 0) {
304  LongBer *l = new LongBer;
305  l->longpkt = pkSize;
306  berlist->push_back(l);
307  }
308  LongBer *l;
309  bool inList = false;
310  for (unsigned int j = 0; j < berlist->size(); j++) {
311  l = *(berlist->begin() + j);
312  if (l->longpkt == pkSize) {
313  inList = true;
314  break;
315  }
316  }
317  if (!inList) {
318  l = new LongBer;
319  l->longpkt = pkSize;
320 
321  unsigned int position = 0;
322  for (position = 0; position < berlist->size(); position++) {
323  LongBer *aux = *(berlist->begin() + position);
324 
325  if (l->longpkt < aux->longpkt)
326  break;
327  }
328  if (position == berlist->size())
329  berlist->push_back(l);
330  else
331  berlist->insert(berlist->begin() + position, l);
332  }
333  SnrBer snrdata;
334  snrdata.snr = snr;
335  snrdata.ber = ber;
336  l->snrlist.push_back(snrdata);
337  std::stable_sort(l->snrlist.begin(), l->snrlist.end(), std::less<SnrBer>());
338  }
339  in.close();
340 
341  // exist data?
342  if (phyOpMode == 'b') {
343  for (int i = 0; i < 4; i++)
344  if (berTable[i].size() == 0)
345  throw cRuntimeError("Error in ber class B file, speed not present");
346 
347  }
348  else {
349  for (int i = 0; i < 8; i++)
350  if (berTable[i].size() == 0)
351  throw cRuntimeError("Error in ber class A/G file, speed not present");
352 
353  }
354 }
std::vector< LongBer * > BerList
Definition: BerParseFile.h:61
double dB2fraction(double dB)
Definition: BerParseFile.h:70
BerTable berTable
Definition: BerParseFile.h:64
char phyOpMode
Definition: BerParseFile.h:65
void inet::physicallayer::BerParseFile::setPhyOpMode ( char  p)
46 {
47  clearBerTable();
48  phyOpMode = p;
49  if (phyOpMode == 'b')
50  berTable.resize(4);
51  else
52  berTable.resize(8);
53 }
BerTable berTable
Definition: BerParseFile.h:64
char phyOpMode
Definition: BerParseFile.h:65
void clearBerTable()
Definition: BerParseFile.cc:32

Member Data Documentation

BerTable inet::physicallayer::BerParseFile::berTable
protected
bool inet::physicallayer::BerParseFile::fileBer
protected

Referenced by clearBerTable().

char inet::physicallayer::BerParseFile::phyOpMode
protected

The documentation for this class was generated from the following files: