blob: e2bf877436ee9d2d1f75f2b6b99fced582ab8592 [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 {
35
36CcnxConsumerWindowTracer::CcnxConsumerWindowTracer (std::ostream &os, Ptr<Node> node, const std::string &appId)
37 : m_appId (appId)
38 , m_nodePtr (node)
39 , m_os (os)
40{
41 m_node = boost::lexical_cast<string> (m_nodePtr->GetId ());
42
43 Connect ();
44
45 string name = Names::FindName (node);
46 if (!name.empty ())
47 {
48 m_node = name;
49 }
50}
51
52void
53CcnxConsumerWindowTracer::Connect ()
54{
55 Config::Connect ("/NodeList/"+m_node+"/ApplicationList/"+m_appId+"/$ns3::CcnxConsumerWindow/WindowTrace",
56 MakeCallback (&CcnxConsumerWindowTracer::OnWindowChange, this));
57}
58
59
60void
61CcnxConsumerWindowTracer::PrintHeader (std::ostream &os) const
62{
63 os << "Time\t"
64 << "Node\t"
65 << "AppId\t"
66 << "Window";
67}
68
69void
70CcnxConsumerWindowTracer::Print (std::ostream &os) const
71{
72 // do nothing
73}
74
75void
76CcnxConsumerWindowTracer::OnWindowChange (std::string context,
77 uint32_t oldValue, uint32_t newValue)
78{
79 m_os
80 << Simulator::Now ().ToDouble (Time::S) << "\t"
81 << m_node << "\t"
82 << m_appId << "\t"
83 << newValue << endl;
84}
85
86} // namespace ns3