?? datasink.cc
字號:
// -*- C++ -*-
// Copyright (C) 2003 Leherstuh f黵 Betrieb System/ Verteilte System,
// Universitaet Dortmund
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// Author: Muddassar Farooq
// Informatik III, Universitaet Dortmund
// Germany
//-------------------------------------------------------------
// file: DataSink.cpp
// (part of AntNet Routing Simulation)
//-------------------------------------------------------------
#include <stdio.h>
#include "dataSink.h"
#include "Messages_m.h"
Define_Module( dataSink );
void dataSink::activity()
{
eePacketDelay.setName("End to End Packet Delay Statistics");
packetDelay.setName("End to End Packet Delay");
cumThroughPut.setName("Cum Through Put in bits/sec");
cPar& sleepTime = par("sleepTimeAtStart");
strcpy(sFileName,par("statFile"));
sPtr = statistics::Instance(sFileName);
debug = false;
logResults = par("logResults");
int i = 0;
wait( sleepTime );
double interval = (double) par("throughputInterval");
measureThroughPut = new cMessage("measureTPut");
double lastSimTime = simTime();
//schedule this message
scheduleAt( lastSimTime + interval, measureThroughPut);
for(;;)
{
// to determine throughput, we need to schedule an even every
// INTERVAL seconds
cMessage *msg = receive();
// packet received from network and increase the counter
if(dynamic_cast<samplePacket *> (msg) != NULL)
{
samplePacket *tmp = (samplePacket*) msg;
// if message is received is network packet then queue it
// and get the stastics
double eed = simTime() - tmp->creationTime();
int hops = tmp->getHops();
if(debug)
{
ev<< "Received Message" << tmp->name() << "End to End Packet Delay is" << eed << "sec"<< endl;
}
if(logResults)
{
packetDelay.record( eed );
tHops.collect( hops );
eePacketDelay.collect( eed );
}
sPtr->incrTotalBitsDelivered();
sPtr->insertPacketDelay( eed );
sPtr->incrNumHops( hops );
intervalBitsReceivedValue += msg->length();
delete tmp;
}
else if( msg == measureThroughPut ) //time to measure throughput
{
simtime_t currentSimTime = simTime();
double intervalThroughPutValue = ( intervalBitsReceivedValue )/(currentSimTime - lastSimTime);
lastSimTime = currentSimTime;
cumBitsReceivedValue += intervalBitsReceivedValue;
double cumThroughPutValue = cumBitsReceivedValue/currentSimTime;
//store the statistics
if(logResults)
{
cumThroughPut.record( intervalThroughPutValue );
}
intervalBitsReceivedValue = 0;
sPtr->insertThroughPut(intervalThroughPutValue,i);
i++;
// schedule next throughput measurement event
scheduleAt( currentSimTime + interval, measureThroughPut);
}
}
}
void dataSink::finish()
{
ev << "*** Module: " << fullPath() << "***" << endl;
ev << "Total Packets destined at this Router: "<< eePacketDelay.samples() << endl;
ev << "Avg Packet Delay: " << eePacketDelay.mean() << endl;
ev << "Max Packet Delay: " << eePacketDelay.max() << endl;
ev << "Standard deviation: " << eePacketDelay.stddev() << endl << endl;
ev << "Avg Hops: " << tHops.mean() << endl;
ev << "Maximum Hops: " << tHops.max() << endl;
ev << "Standard deviation of Hops: " << tHops.stddev() << endl;
ev << endl;
ev << "Stack allocated: " << stackSize() << " bytes";
ev << " (includes " << ev.extraStackForEnvir() << " bytes for environment)" << endl;
ev << "Stack actually used: " << stackUsage() << " bytes" << endl;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -