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 | /** |
| 74 | * Increment counter to both incoming and outgoing lists, for all faces |
| 75 | */ |
| 76 | void |
| 77 | Timeout (); |
| 78 | |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 79 | /** |
| 80 | * Increment counter for Tx amount |
| 81 | */ |
| 82 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 83 | Rx (ns3::Ptr<Face> face, uint32_t amount); |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 84 | |
| 85 | /** |
| 86 | * Increment counter for Tx amount |
| 87 | */ |
| 88 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 89 | Tx (ns3::Ptr<Face> face, uint32_t amount); |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 90 | |
Alexander Afanasyev | 0845c09 | 2012-07-13 17:45:33 -0700 | [diff] [blame] | 91 | LoadStatsNode & |
| 92 | operator += (const LoadStatsNode &stats); |
| 93 | |
| 94 | inline const stats_container & |
| 95 | incoming () const; |
| 96 | |
| 97 | inline const stats_container & |
| 98 | outgoing () const; |
| 99 | |
| 100 | inline const LoadStatsFace & |
| 101 | pit () const; |
| 102 | |
| 103 | bool |
Alexander Afanasyev | 0560eec | 2012-07-16 15:44:31 -0700 | [diff] [blame] | 104 | IsZero () const; |
| 105 | |
| 106 | bool |
| 107 | operator == (const LoadStatsNode &other) const; |
| 108 | |
Alexander Afanasyev | 0845c09 | 2012-07-13 17:45:33 -0700 | [diff] [blame] | 109 | bool |
| 110 | operator != (const LoadStatsNode &other) const |
| 111 | { |
Alexander Afanasyev | 0560eec | 2012-07-16 15:44:31 -0700 | [diff] [blame] | 112 | return !(*this == other); |
Alexander Afanasyev | 0845c09 | 2012-07-13 17:45:33 -0700 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | LoadStatsNode & |
| 116 | operator = (const LoadStatsNode &other) |
| 117 | { |
| 118 | // don't do any copying at all |
| 119 | return *this; |
| 120 | } |
Alexander Afanasyev | 33364b6 | 2012-07-26 17:53:56 -0700 | [diff] [blame] | 121 | |
| 122 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 123 | RemoveFace (ns3::Ptr<Face> face); |
Alexander Afanasyev | 0845c09 | 2012-07-13 17:45:33 -0700 | [diff] [blame] | 124 | |
| 125 | private: |
| 126 | LoadStatsFace m_pit; |
| 127 | stats_container m_incoming; |
| 128 | stats_container m_outgoing; |
| 129 | |
| 130 | friend std::ostream& |
| 131 | operator << (std::ostream &os, const LoadStatsNode &node); |
| 132 | }; |
| 133 | |
| 134 | inline const LoadStatsNode::stats_container & |
| 135 | LoadStatsNode::incoming () const |
| 136 | { |
| 137 | return m_incoming; |
| 138 | } |
| 139 | |
| 140 | inline const LoadStatsNode::stats_container & |
| 141 | LoadStatsNode::outgoing () const |
| 142 | { |
| 143 | return m_outgoing; |
| 144 | } |
| 145 | |
| 146 | inline const LoadStatsFace & |
| 147 | LoadStatsNode::pit () const |
| 148 | { |
| 149 | return m_pit; |
| 150 | } |
| 151 | |
| 152 | std::ostream& |
| 153 | operator << (std::ostream &os, const LoadStatsNode &node); |
| 154 | |
Alexander Afanasyev | e77db79 | 2012-08-09 11:10:58 -0700 | [diff] [blame] | 155 | } // ndnSIM |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 156 | } // ndn |
Alexander Afanasyev | e77db79 | 2012-08-09 11:10:58 -0700 | [diff] [blame] | 157 | } // ns3 |
Alexander Afanasyev | 0845c09 | 2012-07-13 17:45:33 -0700 | [diff] [blame] | 158 | |
| 159 | #endif |