Alexander Afanasyev | e4c2ece | 2012-01-11 10:44:40 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2011 UCLA |
| 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 "ccnx-consumer-window-tracer.h" |
| 22 | #include "ns3/node.h" |
| 23 | #include "ns3/packet.h" |
| 24 | #include "ns3/config.h" |
| 25 | #include "ns3/callback.h" |
| 26 | #include "ns3/names.h" |
| 27 | #include "ns3/simulator.h" |
| 28 | |
| 29 | #include <boost/lexical_cast.hpp> |
| 30 | |
| 31 | using namespace std; |
| 32 | using namespace boost; |
| 33 | |
| 34 | namespace ns3 { |
Alexander Afanasyev | 06b42ec | 2012-01-11 19:05:36 -0800 | [diff] [blame] | 35 | |
| 36 | void |
| 37 | CcnxConsumerWindowTracer::Connect () |
| 38 | { |
| 39 | Config::Connect ("/NodeList/"+m_node+"/ApplicationList/"+m_appId+"/$ns3::CcnxConsumerWindow/WindowTrace", |
| 40 | MakeCallback (&WindowTracer::OnWindowChange, this)); |
| 41 | } |
| 42 | |
| 43 | void |
| 44 | TcpCongestionWindowTracer::Connect () |
| 45 | { |
| 46 | Config::Connect ("/NodeList/"+m_node+"/$ns3::TcpL4Protocol/SocketList/*/CongestionWindow", |
| 47 | MakeCallback (&WindowTracer::OnWindowChange, this)); |
| 48 | } |
| 49 | |
| 50 | |
| 51 | WindowTracer::WindowTracer (std::ostream &os, Ptr<Node> node, const std::string &appId) |
Alexander Afanasyev | e4c2ece | 2012-01-11 10:44:40 -0800 | [diff] [blame] | 52 | : m_appId (appId) |
| 53 | , m_nodePtr (node) |
| 54 | , m_os (os) |
| 55 | { |
| 56 | m_node = boost::lexical_cast<string> (m_nodePtr->GetId ()); |
| 57 | |
Alexander Afanasyev | e4c2ece | 2012-01-11 10:44:40 -0800 | [diff] [blame] | 58 | string name = Names::FindName (node); |
| 59 | if (!name.empty ()) |
| 60 | { |
Alexander Afanasyev | 06b42ec | 2012-01-11 19:05:36 -0800 | [diff] [blame] | 61 | m_nodeName = name; |
Alexander Afanasyev | e4c2ece | 2012-01-11 10:44:40 -0800 | [diff] [blame] | 62 | } |
Alexander Afanasyev | 06b42ec | 2012-01-11 19:05:36 -0800 | [diff] [blame] | 63 | else |
| 64 | m_nodeName = m_node; |
Alexander Afanasyev | e4c2ece | 2012-01-11 10:44:40 -0800 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | |
| 68 | void |
Alexander Afanasyev | 06b42ec | 2012-01-11 19:05:36 -0800 | [diff] [blame] | 69 | WindowTracer::PrintHeader (std::ostream &os) |
Alexander Afanasyev | e4c2ece | 2012-01-11 10:44:40 -0800 | [diff] [blame] | 70 | { |
| 71 | os << "Time\t" |
| 72 | << "Node\t" |
| 73 | << "AppId\t" |
| 74 | << "Window"; |
| 75 | } |
Alexander Afanasyev | e4c2ece | 2012-01-11 10:44:40 -0800 | [diff] [blame] | 76 | |
| 77 | void |
Alexander Afanasyev | 06b42ec | 2012-01-11 19:05:36 -0800 | [diff] [blame] | 78 | WindowTracer::OnWindowChange (std::string context, |
| 79 | uint32_t oldValue, uint32_t newValue) |
Alexander Afanasyev | e4c2ece | 2012-01-11 10:44:40 -0800 | [diff] [blame] | 80 | { |
| 81 | m_os |
| 82 | << Simulator::Now ().ToDouble (Time::S) << "\t" |
Alexander Afanasyev | 06b42ec | 2012-01-11 19:05:36 -0800 | [diff] [blame] | 83 | << m_nodeName << "\t" |
Alexander Afanasyev | e4c2ece | 2012-01-11 10:44:40 -0800 | [diff] [blame] | 84 | << m_appId << "\t" |
| 85 | << newValue << endl; |
| 86 | } |
| 87 | |
| 88 | } // namespace ns3 |