📄 stat-collector.cc
字号:
/* Copyright (c) University of Maryland, Baltimore County, 2003. * Original Authors: Ramakrishna Shenai, Sunil Gowda and Krishna Sivalingam. * * This software is developed at the University of Maryland, Baltimore County under * grants from Cisco Systems Inc and the University of Maryland, Baltimore County. * * Permission to use, copy, modify, and distribute this software and its * documentation in source and binary forms for non-commercial purposes * and without fee is hereby granted, provided that the above copyright * notice appear in all copies and that both the copyright notice and * this permission notice appear in supporting documentation. and that * any documentation, advertising materials, and other materials related * to such distribution and use acknowledge that the software was * developed by the University of Maryland, Baltimore County. The name of * the University may not be used to endorse or promote products derived from * this software without specific prior written permission. * * Copyright (C) 2000-2003 Washington State University. All rights reserved. * This software was originally developed at Alcatel USA and subsequently modified * at Washington State University, Pullman, WA through research work which was * supported by Alcatel USA, Inc and Cisco Systems Inc. * The following notice is in adherence to the Washington State University * copyright policy follows. * * License is granted to copy, to use, and to make and to use derivative * works for research and evaluation purposes, provided that Washington * State University is acknowledged in all documentation pertaining to any such * copy or derivative work. Washington State University grants no other * licenses expressed or implied. The Washington State University name * should not be used in any advertising without its written permission. * * WASHINGTON STATE UNIVERSITY MAKES NO REPRESENTATIONS CONCERNING EITHER * THE MERCHANTABILITY OF THIS SOFTWARE OR THE SUITABILITY OF THIS SOFTWARE * FOR ANY PARTICULAR PURPOSE. The software is provided "as is" * without express or implied warranty of any kind. These notices must * be retained in any copies of any part of this software. */#include "stat-collector.h"StatCollector *StatCollector::instance__ = NULL;map<string, StatEntry> StatEntry::mapList__;/* Base info list is essentially a string representation of the * 11 base statistics */// string StatEntry::baseInfoList[12] = {// "TCPSND", "TCPRCV", "BURSTSND", "BURSTDROP", "BURSTRCV", "BHPDROP",// "BHPSND", "BHPRCV", "TCPDROP", "ACKDROP", "PERFLOW", "OTHER"// };// GMG -- New statistics added/* Base info list is essentially a string representation of the * 14 base statistics */string StatEntry::baseInfoList[44] = { "TCPSND", "TCPBYTESSND", "TCPRCV", "TCPBYTESRCV", "TCPDLY", "BURSTSND", "BURSTDROP", "BURSTRCV", "BHPDROP", "BHPSND", "BHPRCV", "TCPDROP", "ACKDROP", "PERFLOW", "UDPSND", "UDPBYTESSND", "UDPRCV", "UDPBYTESRCV", "UDPDLY", "ACKSND", "ACKRCV", "CBRSND", "CBRBYTESSND", "CBRRCV", "CBRBYTESRCV", "CBRDLY", "EXPSND", "EXPBYTESSND", "EXPRCV", "EXPBYTESRCV", "EXPDLY", "PARSND", "PARBYTESSND", "PARRCV", "PARBYTESRCV", "PARDLY", "SSIMSND", "SSIMBYTESSND", "SSIMRCV", "SSIMBYTESRCV", "SSIMDLY", "BURSTDLY", "BHPDLY", "OTHER"};/* Add an Entry to the list of entries maintained */bool StatEntry::addStatEntry( StatEntry se ) { mapList__[se.infoStr()] = se; return true;}/* Add an Entry to the list of entries maintained */bool StatEntry::addStatEntry( statType st, string s, double value ) { StatEntry se( st, s, value ); return ( addStatEntry( se ) );}/* Add an Entry to the list of entries maintained */bool StatEntry::addStatEntry( string s, double value ) { return ( addStatEntry( OTHER, s, value ) );}/* Get the stat entry correspondign to key Str */StatEntry& StatEntry::getStatEntry( string keyStr ) { map<string, StatEntry>::iterator result = mapList__.find( keyStr ); return (*result).second;} /* Diagnostic display -content method */void StatEntry::displayEntry( StatEntry se ) { char s[100];//GMG -- added switch/case so that, for TCPDLY, average delay over all tcp pkts can// be calculated; must divide by total number of TCP pkts; note - ACKs not// included double pktrcv1; switch (se.type() ) { case TCPDLY: pktrcv1 = StatEntry::getStatEntry("TCPRCV").value(); sprintf( s, "Type: %d Str: %s Value: %lf ", se.type(), se.infoStr().c_str(), (pktrcv1 != 0.0 ? se.value()/pktrcv1 : 0.0) ); break; case UDPDLY: pktrcv1 = StatEntry::getStatEntry("UDPRCV").value(); sprintf( s, "Type: %d Str: %s Value: %lf ", se.type(), se.infoStr().c_str(), (pktrcv1 != 0.0 ? se.value()/pktrcv1 : 0.0) ); break; case CBRDLY: pktrcv1 = StatEntry::getStatEntry("CBRRCV").value(); sprintf( s, "Type: %d Str: %s Value: %lf ", se.type(), se.infoStr().c_str(), (pktrcv1 != 0.0 ? se.value()/pktrcv1 : 0.0) ); break; case EXPDLY: pktrcv1 = StatEntry::getStatEntry("EXPRCV").value(); sprintf( s, "Type: %d Str: %s Value: %lf ", se.type(), se.infoStr().c_str(), (pktrcv1 != 0.0 ? se.value()/pktrcv1 : 0.0) ); break; case PARDLY: pktrcv1 = StatEntry::getStatEntry("PARRCV").value(); sprintf( s, "Type: %d Str: %s Value: %lf ", se.type(), se.infoStr().c_str(), (pktrcv1 != 0.0 ? se.value()/pktrcv1 : 0.0) ); break; case SSIMDLY: pktrcv1 = StatEntry::getStatEntry("SSIMRCV").value(); sprintf( s, "Type: %d Str: %s Value: %lf ", se.type(), se.infoStr().c_str(), (pktrcv1 != 0.0 ? se.value()/pktrcv1 : 0.0) ); break; case BURSTDLY: pktrcv1 = StatEntry::getStatEntry("BURSTRCV").value(); sprintf( s, "Type: %d Str: %s Value: %lf ", se.type(), se.infoStr().c_str(), (pktrcv1 != 0.0 ? se.value()/pktrcv1 : 0.0) ); break; case BHPDLY: pktrcv1 = StatEntry::getStatEntry("BHPRCV").value(); sprintf( s, "Type: %d Str: %s Value: %lf ", se.type(), se.infoStr().c_str(), (pktrcv1 != 0.0 ? se.value()/pktrcv1 : 0.0) ); break; default: sprintf( s, "Type: %d Str: %s Value: %lf ", se.type(), se.infoStr().c_str(), se.value() ); break; } Debug::debug( s );}/* Diagnostic display-content method -- displays all the entries */void StatEntry::displayEntry() { map<string, StatEntry>::const_iterator iter; for( iter = mapList__.begin(); iter != mapList__.end(); iter++ ) displayEntry( (*iter).second );}/* Returns back the reference to this object */StatCollector& StatCollector::instance() { if( instance__ == NULL ) instance__ = new StatCollector(); return (*instance__);}/* Returns back a pointer to this object */StatCollector* StatCollector::getInstance() { if( instance__ == NULL ) instance__ = new StatCollector(); return instance__;}/* Construct a new StatCollector object */StatCollector::StatCollector() { /* Initialize stat entries for the predefined statEntry types */ for( int i = 0; i < 43; i++ ) { StatEntry::addStatEntry( (statType)i, StatEntry::baseInfoList[i], 0.0 ); }}/* add an entry to the stat table */void StatCollector::addEntry( statType type, string entry, double value ) { StatEntry::addStatEntry( type, entry, value );}/* add a custom entry to the stat table */void StatCollector::addEntry( string entry, double value ) { StatEntry::addStatEntry( entry, value );}/* Interface methods to the StatEntry object */void StatCollector::updateEntry( string entry, double value ) { StatEntry::getStatEntry( entry ).value() = value;}/* Get the value for the specific entry */double StatCollector::getValue( string entry ) { return (StatEntry::getStatEntry( entry ).value() );}/* tcl command */int StatCollector::command( int argc, const char*const* argv ) { if( argc == 2 ) { if( strcmp( argv[1], "display-sim-list" ) == 0 ) { StatEntry::displayEntry(); return (TCL_OK); } } else if( argc == 4 ) { if( strcmp( argv[1], "add-stat-type" ) == 0 ) { string s( argv[2] ); addEntry( s, atof( argv[3] ) ); return (TCL_OK); } else if( strcmp( argv[1], "update-stat" ) == 0 ) { string s( argv[2] ); updateEntry( s, atof( argv[3] ) ); return (TCL_OK); } } return NsObject::command( argc, argv );}// StatCollectorClass Definitionstatic class StatCollectorClass : public TclClass { public: StatCollectorClass() : TclClass( "StatCollector" ){} TclObject* create( int, const char*const* ) { // return (new StatCollector() ); return( StatCollector::getInstance() ); }} class_statCollectorClass;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -