2 /////////////////////////////////////////////////////////////////////////////
4 // Module, which discards CLP=1 data items with prob PLOSS
5 // it does not support Start/Stop protocol
7 // PLOSS=<double>, // loss probability
8 // LOOSECLP0=0|1, // loose also CLP=0 cells
9 // BURSTLEN=<int>, // loose bursts of this size
11 /////////////////////////////////////////////////////////////////////////////
13 class lossclp1
: public in1out
15 typedef in1out baseclass
;
18 double ploss
; // loss probability
19 int LooseClp0
; // loose also CLP0 cells
20 int BurstLen
; // loose Bursts of this length
21 int Loosing
; // am I loosing now
22 int CurrentLen
; // data items currently lost or served
23 int StartLoosing
; // when to start with Loosing
24 int received
; // received data items
26 double uniform(){return my_rand() / (32767.0+1.0);} // interval = [0,1) !
28 rec_typ
REC(data
*, int);
32 CONSTRUCTOR(Lossclp1
, lossclp1
);
33 USERCLASS("LossCLP1",Lossclp1
);
35 /////////////////////////////////////////////////////////////////////////////
37 /////////////////////////////////////////////////////////////////////////////
38 void lossclp1::init(void)
44 ploss
= read_double("PLOSS");
45 if(ploss
< 0 || ploss
> 1)
46 syntax0("PLOSS must be >=0 and <=1");
49 LooseClp0
= read_int("LOOSECLP0");
50 if(LooseClp0
!= 0 && LooseClp0
!= 1)
51 syntax0("LOOSECLP0 must be 0 or 1");
54 BurstLen
= read_int("BURSTLEN");
56 syntax0("BURSTLEN must be >=1");
59 if(test_word("STARTLOOSING"))
61 StartLoosing
= read_int("STARTLOOSING");
63 syntax0("STARTLOOSING must be >=1");
81 /////////////////////////////////////////////////////////////////////////////
83 /////////////////////////////////////////////////////////////////////////////
84 rec_typ
lossclp1::REC(data
*pd
,int)
89 // serve CLP=0 items (if not LosseCLP0 is set)
90 if(received
< StartLoosing
|| (pd
->clp
== 0 && !LooseClp0
))
96 // now, we have a low priority cell
97 // if the Burstlen for CLP=1 is over, decide, if to drop
99 if(CurrentLen
>= BurstLen
)
104 if(uniform() < ploss
)