blob: eea664af7d2d6e488959aac45dca21dcf14df7dc [file] [log] [blame]
Alexander Afanasyeve4c2ece2012-01-11 10:44:40 -08001/* -*- 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
31using namespace std;
32using namespace boost;
33
34namespace ns3 {
Alexander Afanasyev06b42ec2012-01-11 19:05:36 -080035
36void
37CcnxConsumerWindowTracer::Connect ()
38{
39 Config::Connect ("/NodeList/"+m_node+"/ApplicationList/"+m_appId+"/$ns3::CcnxConsumerWindow/WindowTrace",
40 MakeCallback (&WindowTracer::OnWindowChange, this));
41}
42
43void
44TcpCongestionWindowTracer::Connect ()
45{
46 Config::Connect ("/NodeList/"+m_node+"/$ns3::TcpL4Protocol/SocketList/*/CongestionWindow",
47 MakeCallback (&WindowTracer::OnWindowChange, this));
48}
49
50
51WindowTracer::WindowTracer (std::ostream &os, Ptr<Node> node, const std::string &appId)
Alexander Afanasyeve4c2ece2012-01-11 10:44:40 -080052 : m_appId (appId)
53 , m_nodePtr (node)
54 , m_os (os)
55{
56 m_node = boost::lexical_cast<string> (m_nodePtr->GetId ());
57
Alexander Afanasyeve4c2ece2012-01-11 10:44:40 -080058 string name = Names::FindName (node);
59 if (!name.empty ())
60 {
Alexander Afanasyev06b42ec2012-01-11 19:05:36 -080061 m_nodeName = name;
Alexander Afanasyeve4c2ece2012-01-11 10:44:40 -080062 }
Alexander Afanasyev06b42ec2012-01-11 19:05:36 -080063 else
64 m_nodeName = m_node;
Alexander Afanasyeve4c2ece2012-01-11 10:44:40 -080065}
66
67
68void
Alexander Afanasyev06b42ec2012-01-11 19:05:36 -080069WindowTracer::PrintHeader (std::ostream &os)
Alexander Afanasyeve4c2ece2012-01-11 10:44:40 -080070{
71 os << "Time\t"
72 << "Node\t"
73 << "AppId\t"
74 << "Window";
75}
Alexander Afanasyeve4c2ece2012-01-11 10:44:40 -080076
77void
Alexander Afanasyev06b42ec2012-01-11 19:05:36 -080078WindowTracer::OnWindowChange (std::string context,
79 uint32_t oldValue, uint32_t newValue)
Alexander Afanasyeve4c2ece2012-01-11 10:44:40 -080080{
81 m_os
82 << Simulator::Now ().ToDouble (Time::S) << "\t"
Alexander Afanasyev06b42ec2012-01-11 19:05:36 -080083 << m_nodeName << "\t"
Alexander Afanasyeve4c2ece2012-01-11 10:44:40 -080084 << m_appId << "\t"
85 << newValue << endl;
86}
87
88} // namespace ns3