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