RINASim  October 2016
Documentation of framework for OMNeT++
TxControlPolicyLG.cc
Go to the documentation of this file.
1 // The MIT License (MIT)
2 //
3 // Copyright (c) 2014-2016 Brno University of Technology, PRISTINE project
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 // THE SOFTWARE.
30 #include "TxControlPolicyLG.h"
31 
32 const char * Tx_LG_RATE = "Tx_LG_RATE";
33 const char * Tx_FLIGHT_SIZE = "Tx_LG_FLIGHT_SIZE";
34 
36 
38 {
40  alpha = ALPHA;
41  flightSize = 0;
42 }
43 
45 {
46 }
47 
49  sigStatRate = registerSignal(Tx_LG_RATE);
50  sigStatFlightSize = registerSignal(Tx_FLIGHT_SIZE);
51 }
52 
53 void TxControlPolicyLG::updateRate(double load, double acked)
54 {
55  rate = rate * alpha * (1 - rate - load) + rate;
56  flightSize -= acked;
57 
58  emit(sigStatRate, rate);
59  emit(sigStatFlightSize, flightSize);
60 }
61 
63 {
64  return flightSize * SEGMENT_SIZE * 8 / dtpState->getRtt();//0.045; //dtpState->getRtt(); // segment size
65 }
66 
68 {
69  return rate * BANDWIDTH; // bandwidth
70 }
71 
72 bool TxControlPolicyLG::run(DTPState* dtpState, DTCPState* dtcpState)
73 {
74  Enter_Method("TxControlPolicyLG");
75 
76  if(getActualRate(dtpState) < getRate()) {
77  double addRate = (getRate() - getActualRate(dtpState));
78  sendCredit = addRate * dtpState->getRtt() / (SEGMENT_SIZE * 8);
79 
80  // ------------- adding packets to send queue
81  std::vector<DataTransferPDU*>::iterator it;
82  PDUQ_t* pduQ = NULL;
83  int sentNo = 1;
84 
85  for(int i = 1; i <= 2; i++) {
86  if (dtcpState->getClosedWinQueLen() > 0) {
87  pduQ = dtcpState->getClosedWindowQ();
88  } else
89  pduQ = dtpState->getGeneratedPDUQ();
90 
91  for (it = pduQ->begin(); it != pduQ->end() && (*it)->getSeqNum() <= dtcpState->getSndRightWinEdge() && sentNo <= sendCredit; sentNo++) {
92  dtpState->pushBackToPostablePDUQ((*it));
93  flightSize++;
95  it = pduQ->erase(it);
96  }
97  }
98  }
99 
100  dtcpState->setClosedWindow(true);
101 
102  return false;
103 }
This is an example policy class implementing LG Initial Sequence Number behavior .
virtual bool run(DTPState *dtpState, DTCPState *dtcpState)
#define BANDWIDTH
#define INITIAL_RATE
double getActualRate(DTPState *dtpState)
unsigned int getSndRightWinEdge() const
Definition: DTCPState.cc:142
simsignal_t sigStatRate
PDUQ_t * getGeneratedPDUQ()
Definition: DTPState.cc:409
unsigned int getClosedWinQueLen() const
Definition: DTCPState.cc:337
const char * Tx_LG_RATE
void updateRate(double load, double acked)
Register_Class(TxControlPolicyLG)
#define SEGMENT_SIZE
std::vector< DataTransferPDU * > PDUQ_t
void pushBackToPostablePDUQ(DataTransferPDU *pdu)
Definition: DTPState.cc:424
simsignal_t sigStatFlightSize
double getRtt() const
Definition: DTPState.cc:303
virtual ~TxControlPolicyLG()
std::vector< DataTransferPDU * > * getClosedWindowQ()
Definition: DTCPState.cc:312
void setClosedWindow(bool closedWindow)
Definition: DTCPState.cc:333
const char * Tx_FLIGHT_SIZE
#define ALPHA