/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ /* * Copyright (c) 2013 Trinity College of Dublin, Ireland * * * Author: Andriana Ioannou */ #include "ndn-producer-tracer.h"//~ #include "ns3/node.h" #include "ns3/packet.h" #include "ns3/config.h" #include "ns3/names.h" #include "ns3/callback.h" #include "ns3/ndn-app.h" #include "ns3/ndn-interest.h" #include "ns3/ndn-content-object.h" #include "ns3/simulator.h" #include "ns3/node-list.h" #include "ns3/log.h" #include #include //(+) #include NS_LOG_COMPONENT_DEFINE ("ndn.ProducerTracer");//~ using namespace std; namespace ns3 { namespace ndn { boost::tuple< boost::shared_ptr, std::list > >//~ ProducerTracer::InstallAll (const std::string &file, Time averagingPeriod) /* = Seconds (0.5)*/ //~ { using namespace boost; using namespace std; std::list > tracers;//~ boost::shared_ptr outputStream (new std::ofstream ()); outputStream->open (file.c_str (), std::ios_base::out | std::ios_base::trunc); if (!outputStream->is_open ()) return boost::make_tuple (outputStream, tracers); for (NodeList::Iterator node = NodeList::Begin (); node != NodeList::End (); node++) { NS_LOG_DEBUG ("Node: " << (*node)->GetId ()); Ptr trace = Create (outputStream, *node);//~ trace->SetAveragingPeriod (averagingPeriod); tracers.push_back (trace); } if (tracers.size () > 0) { // *m_l3RateTrace << "# "; // not necessary for R's read.table tracers.front ()->PrintHeader (*outputStream); *outputStream << "\n"; } return boost::make_tuple (outputStream, tracers); } ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// ProducerTracer::ProducerTracer (boost::shared_ptr os, Ptr node) : m_nodePtr (node) , m_os (os) { m_node = boost::lexical_cast (m_nodePtr->GetId ()); Connect (); string name = Names::FindName (node); if (!name.empty ()) { m_node = name; } } ProducerTracer::ProducerTracer (boost::shared_ptr os, const std::string &node) : m_node (node) , m_os (os) { Connect (); } ProducerTracer::~ProducerTracer () { }; void ProducerTracer::Connect () { Config::ConnectWithoutContext ("/NodeList/"+m_node+"/ServerHits", MakeCallback (&ProducerTracer::ServerHits, this)); Reset (); } void ProducerTracer::SetAveragingPeriod (const Time &period) { m_period = period; m_printEvent.Cancel (); m_printEvent = Simulator::Schedule (m_period, &ProducerTracer::PeriodicPrinter, this); } void ProducerTracer::PeriodicPrinter () { Print (*m_os); Reset (); m_printEvent = Simulator::Schedule (m_period, &ProducerTracer::PeriodicPrinter, this); } void ProducerTracer::PrintHeader (std::ostream &os) const { os << "Time" << "\t" << "Node" << "\t" << "Type" << "\t" << "Packets" << "\t"; } void ProducerTracer::Reset () { m_stats.Reset(); } #define PRINTER(printName, fieldName) \ os << time.ToDouble (Time::S) << "\t" \ << m_node << "\t" \ << printName << "\t" \ << m_stats.fieldName << "\n"; void ProducerTracer::Print (std::ostream &os) const { Time time = Simulator::Now (); PRINTER ("ServerHits", m_serverHits); } void ProducerTracer::ServerHits (Ptr) { std::cout << "Now i ma in the producer tracer! Hey Yo!" << std::endl;//(+) m_stats.m_serverHits ++; } } // namespace ndn } // namespace ns3