removed apps
[luayats.git] / src / user / lossclp1.c
blobfdbefc14aef461aa5aaf89f63b398f83fb9a7be3
1 #include "in1out.h"
2 /////////////////////////////////////////////////////////////////////////////
3 // LossCLP1
4 // Module, which discards CLP=1 data items with prob PLOSS
5 // it does not support Start/Stop protocol
6 // LossCLP1 <name>:
7 // PLOSS=<double>, // loss probability
8 // LOOSECLP0=0|1, // loose also CLP=0 cells
9 // BURSTLEN=<int>, // loose bursts of this size
10 // OUT=<suc>;
11 /////////////////////////////////////////////////////////////////////////////
13 class lossclp1: public in1out
15 typedef in1out baseclass;
16 public:
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) !
27 void init();
28 rec_typ REC(data *, int);
32 CONSTRUCTOR(Lossclp1, lossclp1);
33 USERCLASS("LossCLP1",Lossclp1);
35 /////////////////////////////////////////////////////////////////////////////
36 // init()
37 /////////////////////////////////////////////////////////////////////////////
38 void lossclp1::init(void)
40 skip(CLASS);
41 name = read_id(NULL);
42 skip(':');
44 ploss = read_double("PLOSS");
45 if(ploss < 0 || ploss > 1)
46 syntax0("PLOSS must be >=0 and <=1");
47 skip(',');
49 LooseClp0 = read_int("LOOSECLP0");
50 if(LooseClp0 != 0 && LooseClp0 != 1)
51 syntax0("LOOSECLP0 must be 0 or 1");
52 skip(',');
54 BurstLen = read_int("BURSTLEN");
55 if(BurstLen < 1)
56 syntax0("BURSTLEN must be >=1");
57 skip(',');
59 if(test_word("STARTLOOSING"))
61 StartLoosing = read_int("STARTLOOSING");
62 if(StartLoosing < 1)
63 syntax0("STARTLOOSING must be >=1");
64 skip(',');
66 else
67 StartLoosing = 1;
69 output("OUT");
70 stdinp();
72 CurrentLen = 0;
73 Loosing = 0;
74 if(uniform() < ploss)
75 Loosing = 1;
77 received = 0;
79 } // lossclp1:init()
81 /////////////////////////////////////////////////////////////////////////////
82 // rec()
83 /////////////////////////////////////////////////////////////////////////////
84 rec_typ lossclp1::REC(data *pd,int)
87 received++;
89 // serve CLP=0 items (if not LosseCLP0 is set)
90 if(received < StartLoosing || (pd->clp == 0 && !LooseClp0))
92 suc->rec(pd, shand);
93 return ContSend;
96 // now, we have a low priority cell
97 // if the Burstlen for CLP=1 is over, decide, if to drop
98 CurrentLen++;
99 if(CurrentLen >= BurstLen)
101 CurrentLen = 0;
102 Loosing = 0;
104 if(uniform() < ploss)
105 Loosing = 1;
108 if( Loosing)
109 delete pd;
110 else
111 suc->rec(pd, shand);
113 return ContSend;
115 } // lossclp1::REC()