Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2013 University of California, Los Angeles |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation; |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | * |
| 18 | * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 19 | */ |
| 20 | |
| 21 | #include "ndn-app-delay-tracer.h" |
| 22 | #include "ns3/node.h" |
| 23 | #include "ns3/packet.h" |
| 24 | #include "ns3/config.h" |
| 25 | #include "ns3/names.h" |
| 26 | #include "ns3/callback.h" |
| 27 | |
| 28 | #include "ns3/ndn-app.h" |
| 29 | #include "ns3/ndn-interest.h" |
| 30 | #include "ns3/ndn-content-object.h" |
| 31 | #include "ns3/simulator.h" |
| 32 | #include "ns3/node-list.h" |
| 33 | #include "ns3/log.h" |
| 34 | |
| 35 | #include <boost/lexical_cast.hpp> |
| 36 | #include <boost/make_shared.hpp> |
| 37 | |
| 38 | #include <fstream> |
| 39 | |
| 40 | NS_LOG_COMPONENT_DEFINE ("ndn.AppDelayTracer"); |
| 41 | |
| 42 | using namespace std; |
| 43 | |
| 44 | namespace ns3 { |
| 45 | namespace ndn { |
| 46 | |
| 47 | |
| 48 | boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<AppDelayTracer> > > |
| 49 | AppDelayTracer::InstallAll (const std::string &file) |
| 50 | { |
| 51 | using namespace boost; |
| 52 | using namespace std; |
| 53 | |
| 54 | std::list<Ptr<AppDelayTracer> > tracers; |
| 55 | boost::shared_ptr<std::ofstream> outputStream = make_shared<std::ofstream> (); |
| 56 | |
| 57 | outputStream->open (file.c_str (), std::ios_base::out | std::ios_base::trunc); |
| 58 | if (!outputStream->is_open ()) |
| 59 | return boost::make_tuple (outputStream, tracers); |
| 60 | |
| 61 | for (NodeList::Iterator node = NodeList::Begin (); |
| 62 | node != NodeList::End (); |
| 63 | node++) |
| 64 | { |
| 65 | NS_LOG_DEBUG ("Node: " << (*node)->GetId ()); |
| 66 | |
| 67 | Ptr<AppDelayTracer> trace = Create<AppDelayTracer> (outputStream, *node); |
| 68 | tracers.push_back (trace); |
| 69 | } |
| 70 | |
| 71 | if (tracers.size () > 0) |
| 72 | { |
| 73 | // *m_l3RateTrace << "# "; // not necessary for R's read.table |
| 74 | tracers.front ()->PrintHeader (*outputStream); |
| 75 | *outputStream << "\n"; |
| 76 | } |
| 77 | |
| 78 | return boost::make_tuple (outputStream, tracers); |
| 79 | } |
| 80 | |
| 81 | ////////////////////////////////////////////////////////////////////////////// |
| 82 | ////////////////////////////////////////////////////////////////////////////// |
| 83 | ////////////////////////////////////////////////////////////////////////////// |
| 84 | |
| 85 | AppDelayTracer::AppDelayTracer (boost::shared_ptr<std::ostream> os, Ptr<Node> node) |
| 86 | : m_nodePtr (node) |
| 87 | , m_os (os) |
| 88 | { |
| 89 | m_node = boost::lexical_cast<string> (m_nodePtr->GetId ()); |
| 90 | |
| 91 | Connect (); |
| 92 | |
| 93 | string name = Names::FindName (node); |
| 94 | if (!name.empty ()) |
| 95 | { |
| 96 | m_node = name; |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | AppDelayTracer::AppDelayTracer (boost::shared_ptr<std::ostream> os, const std::string &node) |
| 101 | : m_node (node) |
| 102 | , m_os (os) |
| 103 | { |
| 104 | Connect (); |
| 105 | } |
| 106 | |
| 107 | AppDelayTracer::~AppDelayTracer () |
| 108 | { |
| 109 | }; |
| 110 | |
| 111 | |
| 112 | void |
| 113 | AppDelayTracer::Connect () |
| 114 | { |
| 115 | Config::ConnectWithoutContext ("/NodeList/"+m_node+"/ApplicationList/*/LastRetransmittedInterestDataDelay", |
| 116 | MakeCallback (&AppDelayTracer::LastRetransmittedInterestDataDelay, this)); |
| 117 | |
Alexander Afanasyev | b9faa44 | 2013-01-18 19:53:43 -0800 | [diff] [blame] | 118 | Config::ConnectWithoutContext ("/NodeList/"+m_node+"/ApplicationList/*/FirstInterestDataDelay", |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 119 | MakeCallback (&AppDelayTracer::FirstInterestDataDelay, this)); |
| 120 | } |
| 121 | |
| 122 | void |
| 123 | AppDelayTracer::PrintHeader (std::ostream &os) const |
| 124 | { |
| 125 | os << "Node" << "\t" |
| 126 | << "AppId" << "\t" |
| 127 | << "SeqNo" << "\t" |
| 128 | |
| 129 | << "Type" << "\t" |
| 130 | << "DelayS" << "\t" |
Alexander Afanasyev | 400aae1 | 2013-01-19 13:27:52 -0800 | [diff] [blame] | 131 | << "DelayUS" << "\t" |
Alexander Afanasyev | 1a0fff6 | 2013-01-19 14:29:51 -0800 | [diff] [blame] | 132 | << "RetxCount" << "\t" |
| 133 | << "HopCount" << ""; |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | void |
Alexander Afanasyev | 1a0fff6 | 2013-01-19 14:29:51 -0800 | [diff] [blame] | 137 | AppDelayTracer::LastRetransmittedInterestDataDelay (Ptr<App> app, uint32_t seqno, Time delay, int32_t hopCount) |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 138 | { |
| 139 | *m_os << m_node << "\t" |
| 140 | << app->GetId () << "\t" |
| 141 | << seqno << "\t" |
| 142 | << "LastDelay" << "\t" |
| 143 | << delay.ToDouble (Time::S) << "\t" |
Alexander Afanasyev | 400aae1 | 2013-01-19 13:27:52 -0800 | [diff] [blame] | 144 | << delay.ToDouble (Time::US) << "\t" |
Alexander Afanasyev | 1a0fff6 | 2013-01-19 14:29:51 -0800 | [diff] [blame] | 145 | << 1 << "\t" |
| 146 | << hopCount << "\n"; |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | void |
Alexander Afanasyev | 1a0fff6 | 2013-01-19 14:29:51 -0800 | [diff] [blame] | 150 | AppDelayTracer::FirstInterestDataDelay (Ptr<App> app, uint32_t seqno, Time delay, uint32_t retxCount, int32_t hopCount) |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 151 | { |
| 152 | *m_os << m_node << "\t" |
| 153 | << app->GetId () << "\t" |
| 154 | << seqno << "\t" |
| 155 | << "FullDelay" << "\t" |
| 156 | << delay.ToDouble (Time::S) << "\t" |
Alexander Afanasyev | 400aae1 | 2013-01-19 13:27:52 -0800 | [diff] [blame] | 157 | << delay.ToDouble (Time::US) << "\t" |
Alexander Afanasyev | 1a0fff6 | 2013-01-19 14:29:51 -0800 | [diff] [blame] | 158 | << retxCount << "\t" |
| 159 | << hopCount << "\n"; |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | |
| 163 | } // namespace ndn |
| 164 | } // namespace ns3 |