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 "PassiveQueueBase.h" 00021 00022 00023 void PassiveQueueBase::initialize() 00024 { 00025 // state 00026 packetRequested = 0; 00027 WATCH(packetRequested); 00028 00029 // statistics 00030 numQueueReceived = 0; 00031 numQueueDropped = 0; 00032 WATCH(numQueueReceived); 00033 WATCH(numQueueDropped); 00034 } 00035 00036 void PassiveQueueBase::handleMessage(cMessage *msg) 00037 { 00038 numQueueReceived++; 00039 if (packetRequested>0) 00040 { 00041 packetRequested--; 00042 sendOut(msg); 00043 } 00044 else 00045 { 00046 bool dropped = enqueue(msg); 00047 if (dropped) 00048 numQueueDropped++; 00049 } 00050 00051 if (ev.isGUI()) 00052 { 00053 char buf[40]; 00054 sprintf(buf, "q rcvd: %d\nq dropped: %d", numQueueReceived, numQueueDropped); 00055 getDisplayString().setTagArg("t",0,buf); 00056 } 00057 } 00058 00059 void PassiveQueueBase::requestPacket() 00060 { 00061 Enter_Method("requestPacket()"); 00062 00063 cMessage *msg = dequeue(); 00064 if (msg==NULL) 00065 { 00066 packetRequested++; 00067 } 00068 else 00069 { 00070 sendOut(msg); 00071 } 00072 } 00073 00074 void PassiveQueueBase::finish() 00075 { 00076 recordScalar("packets received by queue", numQueueReceived); 00077 recordScalar("packets dropped by queue", numQueueDropped); 00078 } 00079