servlib/prophet/Stats.h
changeset 0 2b3e5ec03512
equal deleted inserted replaced
-1:000000000000 0:2b3e5ec03512
       
     1 /*
       
     2  *    Copyright 2007 Baylor University
       
     3  *
       
     4  *    Licensed under the Apache License, Version 2.0 (the "License");
       
     5  *    you may not use this file except in compliance with the License.
       
     6  *    You may obtain a copy of the License at
       
     7  *
       
     8  *        http://www.apache.org/licenses/LICENSE-2.0
       
     9  *
       
    10  *    Unless required by applicable law or agreed to in writing, software
       
    11  *    distributed under the License is distributed on an "AS IS" BASIS,
       
    12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       
    13  *    See the License for the specific language governing permissions and
       
    14  *    limitations under the License.
       
    15  */
       
    16 
       
    17 #ifndef _PROPHET_STATS_H_
       
    18 #define _PROPHET_STATS_H_
       
    19 
       
    20 #include <map>
       
    21 #include "Bundle.h"
       
    22 
       
    23 namespace prophet
       
    24 {
       
    25 
       
    26 /**
       
    27  * Statistics to gather per Bundle as described in 
       
    28  * section 3.7 regarding Queuing Policies
       
    29  */
       
    30 struct StatsEntry
       
    31 {
       
    32     StatsEntry()
       
    33         : p_max_(0.0), mopr_(0.0), lmopr_(0.0) {}
       
    34 
       
    35     double p_max_;
       
    36     double mopr_;
       
    37     double lmopr_;
       
    38 }; // StatsEntry
       
    39 
       
    40 /**
       
    41  * Container for Bundle statistics, indexed by Bundle identifier.
       
    42  * Not thread-safe, requires external locking mechanism.
       
    43  */
       
    44 class Stats
       
    45 {
       
    46 public:
       
    47     /**
       
    48      * Default constructor
       
    49      */
       
    50     Stats()
       
    51         : dropped_(0) {}
       
    52 
       
    53     /**
       
    54      * Destructor
       
    55      */
       
    56     ~Stats();
       
    57 
       
    58     /**
       
    59      * Given a Bundle and a predictability value, update
       
    60      * the stats kept for that Bundle
       
    61      */
       
    62     void update_stats(const Bundle* b, double p);
       
    63 
       
    64     /**
       
    65      * Given a Bundle, return the max predictability for
       
    66      * any route over which this Bundle has been forwarded
       
    67      */
       
    68     double get_p_max(const Bundle* b) const;
       
    69 
       
    70     /**
       
    71      * Given a Bundle, return the predictability favor for
       
    72      * the routes over which this Bundle has been forwarded,
       
    73      * according to Eq. 7, Section 3.7
       
    74      */
       
    75     double get_mopr(const Bundle* b) const;
       
    76 
       
    77     /**
       
    78      * Given a Bundle, return the linear predictability favor
       
    79      * for the routes over which this Bundle has been forwarded,
       
    80      * according to Eq. 8, Section 3.7
       
    81      */ 
       
    82     double get_lmopr(const Bundle* b) const;
       
    83 
       
    84     /**
       
    85      * Bundle is no longer with us, so get rid of its stats
       
    86      */
       
    87     void drop_bundle(const Bundle* b);
       
    88 
       
    89     /**
       
    90      * Return count of how many Bundle stats have been dropped
       
    91      * so far
       
    92      */
       
    93     u_int dropped() const { return dropped_; }
       
    94 
       
    95     /**
       
    96      * Return count of Bundles currently rep'd in Stats
       
    97      */
       
    98     size_t size() const { return pstats_.size(); }
       
    99 
       
   100 protected:
       
   101     typedef std::map<u_int32_t,StatsEntry*> pstats;
       
   102     typedef std::map<u_int32_t,StatsEntry*>::iterator iterator;
       
   103     typedef std::map<u_int32_t,StatsEntry*>::const_iterator
       
   104         const_iterator;
       
   105 
       
   106     /**
       
   107      * Convenience function for finding the StatEntry per bundle id
       
   108      */
       
   109     StatsEntry* find(const Bundle* b);
       
   110 
       
   111     u_int  dropped_;
       
   112     mutable pstats pstats_;
       
   113 }; // Stats
       
   114 
       
   115 }; // namespace prophet
       
   116 
       
   117 #endif // _PROPHET_STATS_H_