-
Notifications
You must be signed in to change notification settings - Fork 0
/
base_cache.h
115 lines (92 loc) · 2.99 KB
/
base_cache.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
* ccnSim is a scalable chunk-level simulator for Content Centric
* Networks (CCN), that we developed in the context of ANR Connect
* (http://www.anr-connect.org/)
*
* People:
* Giuseppe Rossini (lead developer, mailto giuseppe.rossini@enst.fr)
* Raffaele Chiocchetti (developer, mailto raffaele.chiocchetti@gmail.com)
* Dario Rossi (occasional debugger, mailto dario.rossi@enst.fr)
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef B_CACHE_H_
#define B_CACHE_H_
#include "ccnsim.h"
class DecisionPolicy;
//Base cache class: it implements the basic behaviour of every cache by the mean of two abstract functions:
//
//-) data_store: stores chunks within the cache with a given policy
//-) data_lookup: return if the given chunk exists within the cache
//
struct cache_stat_entry{
unsigned int miss; //Total number of misses
unsigned int hit; //Totatle number of hit
cache_stat_entry():miss(0),hit(0){;}
double rate(){ return hit *1./(hit+miss);} //return the miss rate of the class
double req(){return miss+hit;}
};
class base_cache : public abstract_node{
friend class statistics;
protected:
void initialize();
void handleMessage (cMessage *){;}
void finish();
//Inteface function (depending by internal data structures of each cache)
virtual void data_store (chunk_t) = 0;
virtual bool data_lookup(chunk_t) = 0;
virtual void dump(){cout<<"Not implemented"<<endl;}
//<aa>
#ifdef SEVERE_DEBUG
bool initialized;
#endif
//</aa>
public:
#ifdef SEVERE_DEBUG
base_cache():abstract_node(){initialized=false; };
#endif
//Outside function behaviour
uint32_t get_size() { return cache_size; }
virtual bool fake_lookup(chunk_t);
bool lookup(chunk_t);
void store (cMessage *);
void clear_stat();
//<aa>
virtual uint32_t get_decision_yes();
virtual uint32_t get_decision_no();
virtual void set_decision_yes(uint32_t n);
virtual void set_decision_no(uint32_t n);
virtual const DecisionPolicy* get_decisor();
#ifdef SEVERE_DEBUG
virtual bool is_initialized();
#endif
//</aa>
virtual bool full() = 0; //<aa> moved from protected to public</aa>
private:
int cache_size;
int nodes;
int level;
DecisionPolicy *decisor;
//Average statistics
uint32_t miss;
uint32_t hit;
//<aa>
uint32_t decision_yes;
uint32_t decision_no;
//</aa>
//Per file statistics
cache_stat_entry *cache_stats;
};
#endif