//=========================================================================== // $Name: arts++-1-1-a12 $ // $Id: ArtsNetMatrixData.cc,v 1.2 2004/04/21 23:51:33 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 #include "ArtsNetMatrixData.hh" #include "ArtsPrimitive.hh" using namespace std; static const std::string rcsid = "@(#) $Name: arts++-1-1-a12 $ $Id: ArtsNetMatrixData.cc,v 1.2 2004/04/21 23:51:33 kkeys Exp $"; //---------------------------------------------------------------------------- // ArtsNetMatrixData::ArtsNetMatrixData() //............................................................................ // //---------------------------------------------------------------------------- ArtsNetMatrixData::ArtsNetMatrixData() { this->_sampleInterval = 1; this->_count = 0; this->_totpkts = 0; this->_totbytes = 0; this->_orphans = 0; #ifndef NDEBUG ++this->_numObjects; #endif } //---------------------------------------------------------------------------- // ArtsNetMatrixData::~ArtsNetMatrixData() //............................................................................ // //---------------------------------------------------------------------------- ArtsNetMatrixData::~ArtsNetMatrixData() { #ifndef NDEBUG --this->_numObjects; #endif } //------------------------------------------------------------------------- // istream & ArtsNetMatrixData::read(istream& is, uint8_t version) //......................................................................... // //------------------------------------------------------------------------- istream & ArtsNetMatrixData::read(istream& is, uint8_t version) { uint32_t entryNum; ArtsNetMatrixEntry netEntry; 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->_netEntries.reserve(this->_count); for (entryNum = 0; entryNum < this->_count; ++entryNum) { netEntry.read(is,version); this->_netEntries.push_back(netEntry); } return(is); } //------------------------------------------------------------------------- // int ArtsNetMatrixData::read(int fd, uint8_t version) //......................................................................... // //------------------------------------------------------------------------- int ArtsNetMatrixData::read(int fd, uint8_t version) { uint32_t entryNum; ArtsNetMatrixEntry netEntry; 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->_netEntries.reserve(this->_count); for (entryNum = 0; entryNum < this->_count; ++entryNum) { if ((rc = netEntry.read(fd,version)) < 0) { return(-1); } bytesRead += rc; this->_netEntries.push_back(netEntry); } return(bytesRead); } //------------------------------------------------------------------------- // ostream & ArtsNetMatrixData::write(ostream& os, uint8_t version) //......................................................................... // //------------------------------------------------------------------------- ostream & ArtsNetMatrixData::write(ostream& os, uint8_t version) { uint32_t entryNum; g_ArtsLibInternal_Primitive.WriteUint16(os,this->_sampleInterval,2); this->_count = this->NetEntries().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->_netEntries[entryNum].write(os); } return(os); } //------------------------------------------------------------------------- // int ArtsNetMatrixData::write(int fd, uint8_t version) //......................................................................... // //------------------------------------------------------------------------- int ArtsNetMatrixData::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->NetEntries().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->_netEntries[entryNum].write(fd,version)) < 0) { return(-1); } bytesWritten += rc; } return(bytesWritten); } //------------------------------------------------------------------------- // uint32_t ArtsNetMatrixData::Length(uint8_t version) const //......................................................................... // //------------------------------------------------------------------------- uint32_t ArtsNetMatrixData::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 netEntryIter; for (netEntryIter = this->NetEntries().begin(); netEntryIter != this->NetEntries().end(); ++netEntryIter) { length += netEntryIter->Length(version); } return(length); } //------------------------------------------------------------------------- // ostream& operator << (ostream& os, // const ArtsNetMatrixData & artsNetMatrixData) //......................................................................... // //------------------------------------------------------------------------- ostream& operator << (ostream& os, const ArtsNetMatrixData & artsNetMatrixData) { os << "NETMATRIX OBJECT DATA" << endl; os << "\tsample_interval: " << artsNetMatrixData.SampleInterval() << endl; os << "\tcount: " << artsNetMatrixData.Count() << endl; os << "\ttotpkts: " << artsNetMatrixData.TotalPkts() << endl; os << "\ttotbytes: " << artsNetMatrixData.TotalBytes() << endl; os << "\torphans: " << artsNetMatrixData.Orphans() << endl; vector::const_iterator netEntryIter; for (netEntryIter = artsNetMatrixData.NetEntries().begin(); netEntryIter != artsNetMatrixData.NetEntries().end(); ++netEntryIter) { os << (*netEntryIter); } return(os); } //------------------------------------------------------------------------- // void ArtsNetMatrixData::SortEntriesByBytes() //......................................................................... // //------------------------------------------------------------------------- void ArtsNetMatrixData::SortEntriesByBytes() { sort(this->_netEntries.begin(),this->_netEntries.end(), ArtsNetMatrixEntryGreaterBytes()); return; } //------------------------------------------------------------------------- // void ArtsNetMatrixData::SortEntriesByPkts() //......................................................................... // //------------------------------------------------------------------------- void ArtsNetMatrixData::SortEntriesByPkts() { sort(this->_netEntries.begin(),this->_netEntries.end(), ArtsNetMatrixEntryGreaterPkts()); return; } uint32_t ArtsNetMatrixData::_numObjects = 0;