Sink.cc

Go to the documentation of this file.
00001 //
00002 // Copyright (C) 1992-2004 Andras Varga
00003 //
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU 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 #include "Sink.h"
00019 
00020 
00021 Define_Module(Sink);
00022 
00023 
00024 void Sink::initialize()
00025 {
00026     numPackets = 0;
00027     numBits = 0;
00028     throughput = 0;
00029     packetPerSec = 0;
00030 
00031     WATCH(numPackets);
00032     WATCH(numBits);
00033     WATCH(throughput);
00034     WATCH(packetPerSec);
00035 }
00036 
00037 void Sink::handleMessage(cMessage *msg)
00038 {
00039     numPackets++;
00040     numBits += PK(msg)->getBitLength();
00041 
00042     throughput = numBits / simTime();
00043     packetPerSec = numPackets / simTime();
00044 
00045     delete msg;
00046 }
00047 
00048 void Sink::finish()
00049 {
00050     recordScalar("numPackets", numPackets);
00051     recordScalar("numBits", numBits);
00052     recordScalar("throughput", throughput);
00053     recordScalar("packetPerSec", packetPerSec);
00054 }
00055 
00056