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 "DropTailQoSQueue.h" 00021 00022 00023 Define_Module(DropTailQoSQueue); 00024 00025 DropTailQoSQueue::DropTailQoSQueue() 00026 { 00027 queues = NULL; 00028 numQueues = NULL; 00029 } 00030 00031 DropTailQoSQueue::~DropTailQoSQueue() 00032 { 00033 for (int i=0; i<numQueues; i++) 00034 delete queues[i]; 00035 delete [] queues; 00036 } 00037 00038 void DropTailQoSQueue::initialize() 00039 { 00040 PassiveQueueBase::initialize(); 00041 00042 // configuration 00043 frameCapacity = par("frameCapacity"); 00044 00045 const char *classifierClass = par("classifierClass"); 00046 classifier = check_and_cast<IQoSClassifier *>(createOne(classifierClass)); 00047 00048 outGate = gate("out"); 00049 00050 numQueues = classifier->getNumQueues(); 00051 queues = new cQueue *[numQueues]; 00052 for (int i=0; i<numQueues; i++) 00053 { 00054 char buf[32]; 00055 sprintf(buf, "queue-%d", i); 00056 queues[i] = new cQueue(buf); 00057 } 00058 } 00059 00060 bool DropTailQoSQueue::enqueue(cMessage *msg) 00061 { 00062 int queueIndex = classifier->classifyPacket(msg); 00063 cQueue *queue = queues[queueIndex]; 00064 00065 if (frameCapacity && queue->length() >= frameCapacity) 00066 { 00067 EV << "Queue " << queueIndex << " full, dropping packet.\n"; 00068 delete msg; 00069 return true; 00070 } 00071 else 00072 { 00073 queue->insert(msg); 00074 return false; 00075 } 00076 } 00077 00078 cMessage *DropTailQoSQueue::dequeue() 00079 { 00080 // queue 0 is highest priority 00081 for (int i=0; i<numQueues; i++) 00082 if (!queues[i]->empty()) 00083 return (cMessage *)queues[i]->pop(); 00084 return NULL; 00085 } 00086 00087 void DropTailQoSQueue::sendOut(cMessage *msg) 00088 { 00089 send(msg, outGate); 00090 } 00091 00092