1 #include "leakybucket.h"
2 #include <math.h> // for ceil
5 /////////////////////////////////////////////////////////////////////////////
7 /////////////////////////////////////////////////////////////////////////////
9 // Issue: we need to change the code to be according to the ATMF GCRA
10 // and to be with integer logic!
12 // Issue: what is implemented now is a dual token bucket similar to the
13 // "Two-Rate Three Color Marker" defined in RFC2698
14 // the counter, however, counts up for each packet (in RFC2698 it counts down)
17 LeakyBucket::LeakyBucket(void)
22 } // LeakyBucket::LeakyBucket(void) - constructor
24 LeakyBucket::~LeakyBucket(void)
28 void LeakyBucket::SetParam(double rate
, int burstsize
)
30 decrement_per_slot
= rate
/ 8.0 * SlotLength
;
33 //printf("LeakyBucket::SetParam : decrement_per_slot=%f max=%f\n",
34 // decrement_per_slot, max);
36 } // LeakyBucket::SetParam(double rate, int burstsize)
38 /////////////////////////////////////////////////////////
39 // LeakyBucket::PacketArrivalConformance
40 // A packet of with framelength "bytes" has arrived, is
41 // this packet conforming?
42 // The buckets are increased
44 // 0 - packet is not conforming
45 // 1 - packet is conforming
46 /////////////////////////////////////////////////////////
47 int LeakyBucket::PacketArrivalConformance(int bytes
)
53 //printf("value=%f\n",value);
58 return 0; // not conforming
61 return 1; // conforming
63 }; // LeakyBucket::PacketArrivalConformance(int bytes)
65 /////////////////////////////////////////////////////////
66 // LeakyBucket::Update
67 // Update the LeakyBucket counter to the current time
68 // we decrement the counter by n*decrement_per_slot
69 // decrement_per_slot determines the data rate
70 /////////////////////////////////////////////////////////
71 void LeakyBucket::update(void)
74 n
= SimTime
- last_update
;
77 value
-= (double) (n
* decrement_per_slot
);
82 last_update
= SimTime
;
84 } // LeakyBucket::update(void)
87 /////////////////////////////////////////////////////////////////////////////
89 /////////////////////////////////////////////////////////////////////////////
90 DualLeakyBucket::DualLeakyBucket(root
* owner
)
95 CHECK(pLbCir
= new LeakyBucket());
96 CHECK(pLbPir
= new LeakyBucket());
99 DualLeakyBucket::~DualLeakyBucket(void)
107 /////////////////////////////////////////////////////////
108 // DualLeakyBucket::SetParam
109 // Set the parameters for a dual leaky bucket
110 /////////////////////////////////////////////////////////
111 void DualLeakyBucket::SetParam(double cir
, int cbs
, double pir
, int pbs
)
113 pLbCir
->SetParam(cir
, cbs
);
114 pLbPir
->SetParam(pir
, pbs
);
117 /////////////////////////////////////////////////////////
118 // DualLeakyBucket::PacketArrivalConformance(bytes)
119 // A packet of with framelength "bytes" has arrived, is
120 // this packet conforming?
121 // The buckets are increased
123 // TRUE if packet is conforming and need not be dropped
124 // FALSE if packet is not conforming and must be dropped
125 // *PDropPrec = 0 (green), 1 (yellow) or 2 (red)
126 /////////////////////////////////////////////////////////
127 int DualLeakyBucket::PacketArrivalConformance(int bytes
,int *pDropPrec
)
130 // issue: we need to add the color-aware mode
131 // issue: in the data processing spec I have defined separate handling
132 // for PIR and CIR, here it is combined
134 int confCir
, confPir
;
136 confCir
= pLbCir
->PacketArrivalConformance(bytes
);
137 confPir
= pLbPir
->PacketArrivalConformance(bytes
);
140 return TRUE
; //packet always conforming
141 else if(action
== 1) // mark - impelement 2-Rate 3color marker (RFC2698)
143 if(!confPir
) // PIR bucket not conforming
144 *pDropPrec
= 2; // red
145 else if(!confCir
) // CIR bucket not conforming
146 *pDropPrec
= 1; // yellow
148 *pDropPrec
= 0; // green
150 return TRUE
; // packet is conforming and not dropped
152 else if (action
== 2) // drop if CIR bucket not conforming
154 if(!confCir
) // not conforming to CIR
157 else if (action
== 3) // drop if PIR bucket not conforming
159 if(!confPir
) // PIR bucket not conforming
160 return FALSE
; // drop packet
164 errm2s2d("%s: (file %s, line %d) Internal error: policing action %d shall be applied but no rule exists",
165 pOwner
->name
, __FILE__
, __LINE__
, action
);
170 } // DualLeakyBucket::PacketArrivalConformance(int bytes,int *pDropPrec)