DropTailQueue.cc

Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2005 Andras Varga
00003 //
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public License
00006 // as published by the Free Software Foundation; either version 2
00007 // of the License, or (at your option) any later version.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU Lesser General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU Lesser General Public License
00015 // along with this program; if not, see <http://www.gnu.org/licenses/>.
00016 //
00017 
00018 
00019 #include <omnetpp.h>
00020 #include "DropTailQueue.h"
00021 
00022 
00023 Define_Module(DropTailQueue);
00024 
00025 void DropTailQueue::initialize()
00026 {
00027     PassiveQueueBase::initialize();
00028     queue.setName("l2queue");
00029 
00030     qlenVec.setName("queue length");
00031     dropVec.setName("drops");
00032 
00033     outGate = gate("out");
00034 
00035     // configuration
00036     frameCapacity = par("frameCapacity");
00037 }
00038 
00039 bool DropTailQueue::enqueue(cMessage *msg)
00040 {
00041     if (frameCapacity && queue.length() >= frameCapacity)
00042     {
00043         EV << "Queue full, dropping packet.\n";
00044         delete msg;
00045         dropVec.record(1);
00046         return true;
00047     }
00048     else
00049     {
00050         queue.insert(msg);
00051         qlenVec.record(queue.length());
00052         return false;
00053     }
00054 }
00055 
00056 cMessage *DropTailQueue::dequeue()
00057 {
00058     if (queue.empty())
00059         return NULL;
00060 
00061    cMessage *pk = (cMessage *)queue.pop();
00062 
00063     // statistics
00064     qlenVec.record(queue.length());
00065 
00066     return pk;
00067 }
00068 
00069 void DropTailQueue::sendOut(cMessage *msg)
00070 {
00071     send(msg, outGate);
00072 }
00073 
00074