#include <omnetpp.h>
//using namespace omnetpp; //for Omnet++ ver. 5
class Server : public cSimpleModule
{
private:
cQueue queue; //the queue of jobs; it is assumed that the first job in the queue is the one being serviced
cMessage *departure; //special message; it reminds about the end of service and the need for job departure
simtime_t departure_time; //time of the next departure
int bufforSize;
int lostPackages = 0;
int packages = 0;
int lostPackegesOneByOne = 0;
simtime_t overflowTime;
cDoubleHistogram hisOverflowTime;
cLongHistogram hisOverflowTimeOneByOne;
protected:
virtual void initialize();
virtual void handleMessage(cMessage *msgin);
};
Define_Module(Server);
void Server::initialize()
{
departure = new cMessage("Departure");
bufforSize = par("buffor_size");
//hisOverflowTime.setRange(0, 2.5);
}
void Server::handleMessage(cMessage *msgin) //two types of messages may arrive: a job from the source, or the special message initiating job departure
{
if (msgin==departure) //job departure
{
cMessage *msg = (cMessage *)queue.pop(); //remove the finished job from the head of the queue
send(msg,"out");
if(queue.length() == bufforSize - 1){
hisOverflowTime.collect(simTime() - overflowTime);
if(lostPackegesOneByOne != 0){
hisOverflowTimeOneByOne.collect(lostPackegesOneByOne);
}
}
if (!queue.isEmpty()) //if the queue is not empty, initiate the next service, i.e. schedule the next departure event in the future
{
departure_time=simTime()+par("service_time");
scheduleAt(departure_time,departure);
}
}
else //job arrival
{
packages++;
if (queue.isEmpty()) //if the queue is empty, the job that has just arrived has to be served immediately, i.e. the departure event of this job has to be scheduled in the future
{
departure_time=simTime()+par("service_time");
scheduleAt(departure_time,departure);
}
if(queue.length() < bufforSize){
queue.insert(msgin); //insert the job at the end of the queue
if(queue.length() == bufforSize){
overflowTime = simTime();
}
else{
lostPackeges
}
}else{
lostPackages++;
delete msgin;
lostPackegesOneByOne++;
}
double L = (lostPackages * 1.0) / packages;
ev << "L = " << L;
}
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}