blob: 58e060e3029a75a3877183cde35e37912840d3c8 [file] [log] [blame]
Ilya Moiseenko1c570bc2011-08-17 19:18:02 -07001/* -*- 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: Ilya Moiseenko <iliamo@cs.ucla.edu>
19 */
20
21#ifndef ccnx_content_store_h
22#define ccnx_content_store_h
23
24#include <ns3/system-mutex.h>
25#include <list>
26#include <string>
27#include "hash-helper.h"
28
29using namespace std;
30
31namespace ns3
32{
33
34class CsEntry;
35typedef list<CsEntry*>::iterator CsLruIterator;
36
37//structure for CS entry
38struct CsEntry
39{
40 string contentName;
41 int contentSize;
42
43 CsLruIterator lruPosition;
44};
45
46typedef string_key_hash_t<CsEntry>::iterator CsIterator;
47typedef string_key_hash_t<CsEntry>::iterator CsRangeIterator;
48
49class CcnxContentStore
50{
51public:
52 CcnxContentStore( int max_size=NDN_CONTENT_STORE_SIZE );
53 virtual ~CcnxContentStore( );
54
55 // Find corresponding CS entry for the given content name
56 CsEntry* Lookup( const string prefix );
57 //bool isValid( const CsIterator &it ) { return it!=_cs.end(); }
58
59 // Add new content to the content store. Old content will be replaced
60 void Add( const string contentName, int contentSize );
61
62 // Dump content store entries
63 void Dump( );
64
65protected:
66 //move the given CS entry to the head of the list
67 void Promote( CsEntry &entry );
68
69private:
70 int m_maxSize; // maximum number of entries in cache
71
72 string_key_hash_t<CsEntry> m_contentStore; // actual content store
73 list<CsEntry*> m_LRU; // LRU index of the content store
74 SystemMutex m_csMutex; // just to make sure we are not
75};
76}
77#endif