Alexander Afanasyev | 0845c09 | 2012-07-13 17:45:33 -0700 | [diff] [blame] | 1 | /* -*- 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 | #ifndef LOAD_STATS_NODE_H |
| 22 | #define LOAD_STATS_NODE_H |
| 23 | |
| 24 | #include "load-stats-face.h" |
| 25 | #include <map> |
| 26 | #include "ns3/ptr.h" |
| 27 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 28 | namespace ns3 { |
| 29 | namespace ndn { |
| 30 | |
| 31 | class Face; |
Alexander Afanasyev | 0845c09 | 2012-07-13 17:45:33 -0700 | [diff] [blame] | 32 | |
| 33 | namespace ndnSIM |
| 34 | { |
| 35 | |
| 36 | // this thing is actually put into a tree node, associated with each "name entry" |
| 37 | |
| 38 | class LoadStatsNode |
| 39 | { |
| 40 | public: |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 41 | typedef std::map< ns3::Ptr<Face>, LoadStatsFace > stats_container; |
Alexander Afanasyev | 0845c09 | 2012-07-13 17:45:33 -0700 | [diff] [blame] | 42 | |
| 43 | LoadStatsNode () {} |
| 44 | LoadStatsNode (const LoadStatsNode &) {} |
| 45 | |
| 46 | void |
| 47 | Step (); |
| 48 | |
| 49 | /** |
| 50 | * Increment face-independent counter |
| 51 | */ |
| 52 | void |
| 53 | NewPitEntry (); |
| 54 | |
| 55 | /** |
| 56 | * Increment counter to incoming list |
| 57 | */ |
| 58 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 59 | AddIncoming (ns3::Ptr<Face> face); |
Alexander Afanasyev | 0845c09 | 2012-07-13 17:45:33 -0700 | [diff] [blame] | 60 | |
| 61 | /** |
| 62 | * Increment counter to outgoing list |
| 63 | */ |
| 64 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 65 | AddOutgoing (ns3::Ptr<Face> face); |
Alexander Afanasyev | 0845c09 | 2012-07-13 17:45:33 -0700 | [diff] [blame] | 66 | |
| 67 | /** |
| 68 | * Increment counter to both incoming and outgoing lists, for all faces |
| 69 | */ |
| 70 | void |
| 71 | Satisfy (); |
| 72 | |
| 73 | /** |
Alexander Afanasyev | c771961 | 2012-08-30 17:42:20 -0700 | [diff] [blame] | 74 | * Remove a packet from all stats |
| 75 | */ |
| 76 | void |
| 77 | RemoveFromStats (); |
| 78 | |
| 79 | /** |
Alexander Afanasyev | 0845c09 | 2012-07-13 17:45:33 -0700 | [diff] [blame] | 80 | * Increment counter to both incoming and outgoing lists, for all faces |
| 81 | */ |
| 82 | void |
| 83 | Timeout (); |
| 84 | |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 85 | /** |
| 86 | * Increment counter for Tx amount |
| 87 | */ |
| 88 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 89 | Rx (ns3::Ptr<Face> face, uint32_t amount); |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 90 | |
| 91 | /** |
| 92 | * Increment counter for Tx amount |
| 93 | */ |
| 94 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 95 | Tx (ns3::Ptr<Face> face, uint32_t amount); |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 96 | |
Alexander Afanasyev | 0845c09 | 2012-07-13 17:45:33 -0700 | [diff] [blame] | 97 | LoadStatsNode & |
| 98 | operator += (const LoadStatsNode &stats); |
| 99 | |
| 100 | inline const stats_container & |
| 101 | incoming () const; |
| 102 | |
| 103 | inline const stats_container & |
| 104 | outgoing () const; |
| 105 | |
| 106 | inline const LoadStatsFace & |
| 107 | pit () const; |
| 108 | |
| 109 | bool |
Alexander Afanasyev | 0560eec | 2012-07-16 15:44:31 -0700 | [diff] [blame] | 110 | IsZero () const; |
| 111 | |
| 112 | bool |
| 113 | operator == (const LoadStatsNode &other) const; |
| 114 | |
Alexander Afanasyev | 0845c09 | 2012-07-13 17:45:33 -0700 | [diff] [blame] | 115 | bool |
| 116 | operator != (const LoadStatsNode &other) const |
| 117 | { |
Alexander Afanasyev | 0560eec | 2012-07-16 15:44:31 -0700 | [diff] [blame] | 118 | return !(*this == other); |
Alexander Afanasyev | 0845c09 | 2012-07-13 17:45:33 -0700 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | LoadStatsNode & |
| 122 | operator = (const LoadStatsNode &other) |
| 123 | { |
| 124 | // don't do any copying at all |
| 125 | return *this; |
| 126 | } |
Alexander Afanasyev | 33364b6 | 2012-07-26 17:53:56 -0700 | [diff] [blame] | 127 | |
| 128 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 129 | RemoveFace (ns3::Ptr<Face> face); |
Alexander Afanasyev | 0845c09 | 2012-07-13 17:45:33 -0700 | [diff] [blame] | 130 | |
| 131 | private: |
| 132 | LoadStatsFace m_pit; |
| 133 | stats_container m_incoming; |
| 134 | stats_container m_outgoing; |
| 135 | |
| 136 | friend std::ostream& |
| 137 | operator << (std::ostream &os, const LoadStatsNode &node); |
| 138 | }; |
| 139 | |
| 140 | inline const LoadStatsNode::stats_container & |
| 141 | LoadStatsNode::incoming () const |
| 142 | { |
| 143 | return m_incoming; |
| 144 | } |
| 145 | |
| 146 | inline const LoadStatsNode::stats_container & |
| 147 | LoadStatsNode::outgoing () const |
| 148 | { |
| 149 | return m_outgoing; |
| 150 | } |
| 151 | |
| 152 | inline const LoadStatsFace & |
| 153 | LoadStatsNode::pit () const |
| 154 | { |
| 155 | return m_pit; |
| 156 | } |
| 157 | |
| 158 | std::ostream& |
| 159 | operator << (std::ostream &os, const LoadStatsNode &node); |
| 160 | |
Alexander Afanasyev | e77db79 | 2012-08-09 11:10:58 -0700 | [diff] [blame] | 161 | } // ndnSIM |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 162 | } // ndn |
Alexander Afanasyev | e77db79 | 2012-08-09 11:10:58 -0700 | [diff] [blame] | 163 | } // ns3 |
Alexander Afanasyev | 0845c09 | 2012-07-13 17:45:33 -0700 | [diff] [blame] | 164 | |
| 165 | #endif |