/* Copyright (c) 2003 RIPE NCC All Rights Reserved Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of the author not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ /* ------------------------------------------------------------------------------- Module Header Filename : CSVdump.C Author : Rene Wilhelm Date : 17-JAN-2003 Description : CSVdump Class defintion Language Version : C++ OSs Tested : Linux gcc3.0 The CSVdump class provides an interface to output TTM data in CSV (comma seperated values) format. The interface to the outside is provided by two methods: Open() - initaliaze output file Dump() - output one data record Upon deletion output file is closed. $Id: CSVdump.C,v 1.2 2003/05/16 13:57:41 ttraffic Exp $ ------------------------------------------------------------------------------- */ #include "CSVdump.h" #include "iomanip.h" #include "string.h" static char const rcsid[] = "$Id: CSVdump.C,v 1.2 2003/05/16 13:57:41 ttraffic Exp $"; static char const *rcsid_p = rcsid; // Prevent g++ from optimizing out rcsid /* ------------------------------------------------------------------------------- Subroutine Header Purpose : CSVdump creator ------------------------------------------------------------------------------- */ CSVdump::CSVdump() { pathname = NULL; } /* ------------------------------------------------------------------------------- Subroutine Header Purpose : Object destructor, close file ------------------------------------------------------------------------------- */ CSVdump::~CSVdump() { if (pathname != NULL) { csvfile.close(); } delete[] pathname; } /* ------------------------------------------------------------------------------- Subroutine Header Purpose : Open CSV file ------------------------------------------------------------------------------- */ void CSVdump::Open(char *outdir, char *src, char *tgt, char *prefix, csvtype type) { // /..csv int pathlen = strlen(outdir) + strlen(prefix) + strlen(src) + strlen(tgt) + 16; pathname = new char[pathlen]; strcpy(pathname, outdir); strcat(pathname, "/"); strcat(pathname, prefix); if (type == trends) { strcat(pathname, "trends."); } strcat(pathname, src); strcat(pathname, "."); strcat(pathname, tgt); strcat(pathname, ".csv"); csvfile.open(pathname); if ((csvfile.rdstate() & ofstream::failbit) != 0) { cerr << "ERROR: Could not open " << pathname << " for CSV output" << endl; } if (type == delays) { csvfile << "Src,Dst,Size,Arrival,Delay,SrcClk," << "TrgClk,Nhops,Route,SrcErr,TrgErr" << endl; } else if (type == trends) { csvfile << "header for trends ..." << endl; } } /* ------------------------------------------------------------------------------- Subroutine Header Purpose : Output Delay data ------------------------------------------------------------------------------- */ void CSVdump::Dump(Delay* packet) { csvfile << packet->GetSourceId() << "," << packet->GetTargetId() << "," << packet->GetPacketSize() << "," << setprecision(12) << packet->GetArrivalTime() << "," << setprecision(5) << packet->GetPacketDelay() << "," << hex << packet->GetSourceClock() << "," << packet->GetTargetClock() << "," << dec << packet->GetNhops() << "," << packet->GetRouteId() << "," << packet->GetSourceNtp() << "," << packet->GetTargetNtp() << endl; }