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