blob: 34875c5798110d4e6b1c42d47e4402cb4927e00a [file] [log] [blame]
Alexander Afanasyev0845c092012-07-13 17:45:33 -07001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2011 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 "load-stats-node.h"
22#include "ns3/ccnx-face.h"
23
24using namespace ns3;
25
26namespace ndnSIM
27{
28
29void
30LoadStatsNode::Step ()
31{
32 m_pit.Step ();
33
34 for (stats_container::iterator item = m_incoming.begin ();
35 item != m_incoming.end ();
36 item ++)
37 {
38 item->second.Step ();
39 }
40
41 for (stats_container::iterator item = m_outgoing.begin ();
42 item != m_outgoing.end ();
43 item ++)
44 {
45 item->second.Step ();
46 }
47}
48
49void
50LoadStatsNode::NewPitEntry ()
51{
52 m_pit.count ()++;
53}
54
55void
56LoadStatsNode::AddIncoming (ns3::Ptr<ns3::CcnxFace> face)
57{
58 m_incoming [face].count ()++;
59}
60
61void
62LoadStatsNode::AddOutgoing (ns3::Ptr<ns3::CcnxFace> face)
63{
64 m_outgoing [face].count ()++;
65}
66
67void
68LoadStatsNode::Satisfy ()
69{
70 m_pit.satisfied ()++;
71
72 for (stats_container::iterator item = m_incoming.begin ();
73 item != m_incoming.end ();
74 item ++)
75 {
76 item->second.satisfied ()++;
77 }
78
79 for (stats_container::iterator item = m_outgoing.begin ();
80 item != m_outgoing.end ();
81 item ++)
82 {
83 item->second.satisfied ()++;
84 }
85}
86
87void
88LoadStatsNode::Timeout ()
89{
90 m_pit.unsatisfied ()++;
91
92 for (stats_container::iterator item = m_incoming.begin ();
93 item != m_incoming.end ();
94 item ++)
95 {
96 item->second.unsatisfied ()++;
97 }
98
99 for (stats_container::iterator item = m_outgoing.begin ();
100 item != m_outgoing.end ();
101 item ++)
102 {
103 item->second.unsatisfied ()++;
104 }
105}
106
107LoadStatsNode &
108LoadStatsNode::operator += (const LoadStatsNode &stats)
109{
110 m_pit += stats.m_pit;
111
112 // aggregate incoming
113 for (stats_container::const_iterator item = stats.m_incoming.begin ();
114 item != stats.m_incoming.end ();
115 item ++)
116 {
117 m_incoming [item->first] += item->second;
118 }
119
120 // aggregate outgoing
121 for (stats_container::const_iterator item = stats.m_outgoing.begin ();
122 item != stats.m_outgoing.end ();
123 item ++)
124 {
125 m_outgoing [item->first] += item->second;
126 }
127
128 return *this;
129}
130
131std::ostream&
132operator << (std::ostream &os, const LoadStatsNode &node)
133{
134 os << "PIT: " << node.m_pit << std::endl;
135 return os;
136}
137
138
139}