RINASim  October 2016
Documentation of framework for OMNeT++
SM_Burst.cc
Go to the documentation of this file.
1 #include "SM_Burst.h"
2 
3 namespace ModularMonitor {
4 
6  duration = 0.0;
7  size = 1500;
8  currentSize = 0;
9 }
10 
11 SM_Burst::SM_Burst(simtime_t t, unsigned int s) {
12  duration = t;
13  size = s;
14  currentSize = 0;
15 }
16 
17 void SM_Burst::set(simtime_t t, unsigned int s) {
18  duration = t;
19  size = s;
20 }
21 
22 void SM_Burst::in(unsigned int s) {
23  pTimes.push_back(simTime()+duration);
24  pSizes.push_back(s);
25  currentSize += s;
26 }
27 
28 void SM_Burst::out() {
29  simtime_t c = simTime();
30 
31  while(!pTimes.empty() && c >= pTimes.front()){
32  currentSize -= pSizes.front();
33  pTimes.pop_front();
34  pSizes.pop_front();
35  }
36 
37 }
38 
39 double SM_Burst::tic() {
40  out();
41  return (double)currentSize/(double)size;
42 }
43 
44 double SM_Burst::tic(unsigned int s) {
45  out();
46  return (double)(currentSize+s)/(double)size;
47 }
48 
49 simtime_t SM_Burst::getTime(unsigned int s) {
50  unsigned int freeSize = size - currentSize;
51 
52  auto tIt = pTimes.begin();
53  auto sIt = pSizes.begin();
54 
55  while(tIt != pTimes.end() && sIt != pSizes.end()) {
56  freeSize += *sIt;
57 
58  if(freeSize >= s) { return *tIt; }
59 
60  tIt++;
61  sIt++;
62  }
63 
64  return 0;
65 }
66 
67 }
simtime_t getTime(unsigned int)
Definition: SM_Burst.cc:49
list< simtime_t > pTimes
Definition: SM_Burst.h:30
list< unsigned int > pSizes
Definition: SM_Burst.h:29
void in(unsigned int)
Definition: SM_Burst.cc:22
unsigned int currentSize
Definition: SM_Burst.h:28
unsigned int size
Definition: SM_Burst.h:26
void set(simtime_t, unsigned int)
Definition: SM_Burst.cc:17