WorldUtilityStats.cc

00001 //
00002 // This program is free software: you can redistribute it and/or modify
00003 // it under the terms of the GNU Lesser General Public License as published by
00004 // the Free Software Foundation, either version 3 of the License, or
00005 // (at your option) any later version.
00006 //
00007 // This program is distributed in the hope that it will be useful,
00008 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00009 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010 // GNU Lesser General Public License for more details.
00011 //
00012 // You should have received a copy of the GNU Lesser General Public License
00013 // along with this program.  If not, see http://www.gnu.org/licenses/.
00014 //
00015 
00016 #include "WorldUtilityStats.h"
00017 #include "Packet.h"
00018 
00019 Define_Module(WorldUtilityStats);
00020 
00021 void WorldUtilityStats::initialize(int stage)
00022 {
00023   BaseWorldUtility::initialize(stage);
00024 
00025   if(stage == 0) {
00026     recordVectors = par("recordVectors");
00027     bitrate = par("bitrate");
00028 
00029     bitsSent = 0;
00030     bitsReceived = 0;
00031 
00032     //register for global stats to collect
00033     Packet tmp(10);
00034     catPacket = subscribe(this, &tmp);
00035 
00036     sent.setName("Bits generated");
00037     rcvd.setName("Bits received");
00038   }
00039 }
00040 
00041 
00042 void WorldUtilityStats::receiveBBItem(int category, const BBItem *details, int scopeModuleId)
00043 {
00044   Enter_Method_Silent();
00045 
00046   if(category == catPacket)
00047   {
00048     const Packet* p = static_cast<const Packet*>(details);
00049     double nbBitsSent = p->getNbBitsSent();
00050     double nbBitsRcvd = p->getNbBitsReceived();
00051     bitsSent += nbBitsSent;
00052     bitsReceived += nbBitsRcvd;
00053 
00054     if(recordVectors) {
00055       sent.record(bitsSent);
00056       rcvd.record(bitsReceived);
00057     }
00058   }
00059 }
00060 
00061 void WorldUtilityStats::finish()
00062 {
00063   recordScalar("GlobalTrafficGenerated", bitsSent, "bit");
00064   recordScalar("GlobalTrafficReceived", bitsReceived, "bit");
00065 
00066   recordScalar("Traffic", bitsSent / bitrate / simTime());
00067   double hosts = simulation.getSystemModule()->par("numHosts");
00068   if(!par("bcTraffic"))
00069     hosts = 2;
00070   recordScalar("Usage", bitsReceived / bitrate / simTime() / (hosts-1));
00071 }