//=========================================================================== // $Name: arts++-1-1-a12 $ // $Id: ArtsInterfaceMatrixData.cc,v 1.2 2004/04/21 23:51:32 kkeys Exp $ //=========================================================================== // Copyright Notice // // By accessing this software, arts++, you are duly informed // of and agree to be bound by the conditions described below in this // notice: // // This software product, arts++, is developed by Daniel W. McRobb, and // copyrighted(C) 1998 by the University of California, San Diego // (UCSD), with all rights reserved. UCSD administers the CAIDA grant, // NCR-9711092, under which part of this code was developed. // // There is no charge for arts++ software. You can redistribute it // and/or modify it under the terms of the GNU Lesser General Public // License, Version 2.1, February 1999, which is incorporated by // reference herein. // // arts++ is distributed WITHOUT ANY WARRANTY, IMPLIED OR EXPRESS, OF // MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE or that the use // of it will not infringe on any third party's intellectual // property rights. // // You should have received a copy of the GNU Lesser General Public // License along with arts++. Copies can also be obtained from: // // http://www.gnu.org/copyleft/lesser.html // // or by writing to: // // Free Software Foundation, Inc. // 59 Temple Place, Suite 330 // Boston, MA 02111-1307 // USA // // Or contact: // // info@caida.org //=========================================================================== #include #include "ArtsInterfaceMatrixData.hh" #include "ArtsPrimitive.hh" using namespace std; static const std::string rcsid = "@(#) $Name: arts++-1-1-a12 $ $Id: ArtsInterfaceMatrixData.cc,v 1.2 2004/04/21 23:51:32 kkeys Exp $"; //---------------------------------------------------------------------------- // ArtsInterfaceMatrixData::ArtsInterfaceMatrixData() //............................................................................ // //---------------------------------------------------------------------------- ArtsInterfaceMatrixData::ArtsInterfaceMatrixData() { this->_sampleInterval = 1; this->_count = 0; this->_totpkts = 0; this->_totbytes = 0; this->_orphans = 0; #ifndef NDEBUG ++this->_numObjects; #endif } //---------------------------------------------------------------------------- // ArtsInterfaceMatrixData::~ArtsInterfaceMatrixData() //............................................................................ // //---------------------------------------------------------------------------- ArtsInterfaceMatrixData::~ArtsInterfaceMatrixData() { #ifndef NDEBUG --this->_numObjects; #endif } //------------------------------------------------------------------------- // istream & ArtsInterfaceMatrixData::read(istream& is, uint8_t version) //......................................................................... // //------------------------------------------------------------------------- istream & ArtsInterfaceMatrixData::read(istream& is, uint8_t version) { uint32_t entryNum; ArtsInterfaceMatrixEntry interfaceEntry; g_ArtsLibInternal_Primitive.ReadUint16(is,this->_sampleInterval,2); g_ArtsLibInternal_Primitive.ReadUint32(is,this->_count,4); g_ArtsLibInternal_Primitive.ReadUint64(is,this->_totpkts,8); g_ArtsLibInternal_Primitive.ReadUint64(is,this->_totbytes,8); g_ArtsLibInternal_Primitive.ReadUint64(is,this->_orphans,8); this->_interfaceEntries.reserve(this->_count); for (entryNum = 0; entryNum < this->_count; entryNum++) { interfaceEntry.read(is,version); this->_interfaceEntries.push_back(interfaceEntry); } return(is); } //------------------------------------------------------------------------- // int ArtsInterfaceMatrixData::read(int fd, uint8_t version) //......................................................................... // //------------------------------------------------------------------------- int ArtsInterfaceMatrixData::read(int fd, uint8_t version) { uint32_t entryNum; // ArtsPrimitive ioHelper; ArtsInterfaceMatrixEntry interfaceEntry; int rc; int bytesRead = 0; rc = g_ArtsLibInternal_Primitive.ReadUint16(fd,this->_sampleInterval,2); if (rc < 2) { return(-1); } bytesRead += rc; rc = g_ArtsLibInternal_Primitive.ReadUint32(fd,this->_count,4); if (rc < 4) { return(-1); } bytesRead += rc; rc = g_ArtsLibInternal_Primitive.ReadUint64(fd,this->_totpkts,8); if (rc < 8) { return(-1); } bytesRead += rc; rc = g_ArtsLibInternal_Primitive.ReadUint64(fd,this->_totbytes,8); if (rc < 8) { return(-1); } bytesRead += rc; rc = g_ArtsLibInternal_Primitive.ReadUint64(fd,this->_orphans,8); if (rc < 8) { return(-1); } bytesRead += rc; this->_interfaceEntries.reserve(this->_count); for (entryNum = 0; entryNum < this->_count; entryNum++) { if ((rc = interfaceEntry.read(fd,version)) < 0) { return(-1); } bytesRead += rc; this->_interfaceEntries.push_back(interfaceEntry); } return(bytesRead); } //------------------------------------------------------------------------- // ostream & ArtsInterfaceMatrixData::write(ostream& os, // uint8_t version) //......................................................................... // //------------------------------------------------------------------------- ostream & ArtsInterfaceMatrixData::write(ostream& os, uint8_t version) { uint32_t entryNum; g_ArtsLibInternal_Primitive.WriteUint16(os,this->_sampleInterval,2); this->_count = this->_interfaceEntries.size(); g_ArtsLibInternal_Primitive.WriteUint32(os,this->_count,4); g_ArtsLibInternal_Primitive.WriteUint64(os,this->_totpkts,8); g_ArtsLibInternal_Primitive.WriteUint64(os,this->_totbytes,8); g_ArtsLibInternal_Primitive.WriteUint64(os,this->_orphans,8); for (entryNum = 0; entryNum < this->_count; entryNum++) { this->_interfaceEntries[entryNum].write(os); } return(os); } //------------------------------------------------------------------------- // int ArtsInterfaceMatrixData::write(int fd, uint8_t version) //......................................................................... // //------------------------------------------------------------------------- int ArtsInterfaceMatrixData::write(int fd, uint8_t version) { uint32_t entryNum; int rc; int bytesWritten = 0; rc = g_ArtsLibInternal_Primitive.WriteUint16(fd,this->_sampleInterval,2); if (rc < 2) { return(-1); } bytesWritten += rc; this->_count = this->_interfaceEntries.size(); rc = g_ArtsLibInternal_Primitive.WriteUint32(fd,this->_count,4); if (rc < 4) { return(-1); } bytesWritten += rc; rc = g_ArtsLibInternal_Primitive.WriteUint64(fd,this->_totpkts,8); if (rc < 8) { return(-1); } bytesWritten += rc; rc = g_ArtsLibInternal_Primitive.WriteUint64(fd,this->_totbytes,8); if (rc < 8) { return(-1); } bytesWritten += rc; rc = g_ArtsLibInternal_Primitive.WriteUint64(fd,this->_orphans,8); if (rc < 8) { return(-1); bytesWritten += rc; } for (entryNum = 0; entryNum < this->_count; entryNum++) { if ((rc = this->_interfaceEntries[entryNum].write(fd,version)) < 0) { return(-1); } bytesWritten += rc; } return(bytesWritten); } //------------------------------------------------------------------------- // uint32_t ArtsInterfaceMatrixData::Length(uint8_t version) const //......................................................................... // //------------------------------------------------------------------------- uint32_t ArtsInterfaceMatrixData::Length(uint8_t version) const { uint32_t length = 0; length += (sizeof(this->_sampleInterval) + sizeof(this->_count) + sizeof(this->_totpkts) + sizeof(this->_totbytes) + sizeof(this->_orphans)); vector::const_iterator interfaceEntryIter; for (interfaceEntryIter = this->InterfaceEntries().begin(); interfaceEntryIter != this->InterfaceEntries().end(); interfaceEntryIter++) { length += interfaceEntryIter->Length(version); } return(length); } //------------------------------------------------------------------------- // ostream & // operator << (ostream& os, // const ArtsInterfaceMatrixData & artsInterfaceMatrixData) //......................................................................... // //------------------------------------------------------------------------- ostream & operator << (ostream& os, const ArtsInterfaceMatrixData & artsInterfaceMatrixData) { os << "INTERFACEMATRIX OBJECT DATA" << endl; os << "\tsample_interval: " << artsInterfaceMatrixData.SampleInterval() << endl; os << "\tcount: " << artsInterfaceMatrixData.Count() << endl; os << "\ttotpkts: " << artsInterfaceMatrixData.TotalPkts() << endl; os << "\ttotbytes: " << artsInterfaceMatrixData.TotalBytes() << endl; os << "\torphans: " << artsInterfaceMatrixData.Orphans() << endl; vector::const_iterator interfaceEntryIter; for (interfaceEntryIter = artsInterfaceMatrixData.InterfaceEntries().begin(); interfaceEntryIter != artsInterfaceMatrixData.InterfaceEntries().end(); interfaceEntryIter++) { os << (*interfaceEntryIter); } return(os); } //------------------------------------------------------------------------- // void ArtsInterfaceMatrixData::SortEntriesByBytes() //......................................................................... // //------------------------------------------------------------------------- void ArtsInterfaceMatrixData::SortEntriesByBytes() { sort(this->_interfaceEntries.begin(),this->_interfaceEntries.end(), ArtsInterfaceMatrixEntryGreaterBytes()); return; } //------------------------------------------------------------------------- // void ArtsInterfaceMatrixData::SortEntriesByPkts() //......................................................................... // //------------------------------------------------------------------------- void ArtsInterfaceMatrixData::SortEntriesByPkts() { sort(this->_interfaceEntries.begin(),this->_interfaceEntries.end(), ArtsInterfaceMatrixEntryGreaterPkts()); return; } uint32_t ArtsInterfaceMatrixData::_numObjects = 0;