|
1 /* |
|
2 * Copyright 2007-2008 Intel Corporation |
|
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 _BUNDLEINFOCACHE_H_ |
|
18 #define _BUNDLEINFOCACHE_H_ |
|
19 |
|
20 #include <oasys/debug/Logger.h> |
|
21 #include <oasys/util/Cache.h> |
|
22 #include <oasys/util/CacheCapacityHelper.h> |
|
23 #include "Bundle.h" |
|
24 #include "GbofId.h" |
|
25 |
|
26 namespace dtn { |
|
27 |
|
28 /** |
|
29 * Utility class for maintain a cache of recently received bundles, |
|
30 * indexed by GbofId. Used for routers to detect redundant BundleInfos |
|
31 * and to avoid duplicate deliveries to registrations. |
|
32 */ |
|
33 class BundleInfoCache { |
|
34 public: |
|
35 /** |
|
36 * Constructor that takes the logpath and the number of entries to |
|
37 * maintain in the cache. |
|
38 */ |
|
39 BundleInfoCache(const std::string& logpath, size_t capacity); |
|
40 |
|
41 /** |
|
42 * Try to add the bundle to the cache. If it already exists in the |
|
43 * cache, adding it again fails, and the method returns false. |
|
44 */ |
|
45 bool add_entry(const Bundle* bundle, const EndpointID& prevhop); |
|
46 |
|
47 /** |
|
48 * Check if the given bundle is in the cache, returning the EID of |
|
49 * the node from which it arrived (if known). |
|
50 */ |
|
51 bool lookup(const Bundle* bundle, EndpointID* prevhop); |
|
52 |
|
53 /** |
|
54 * Flush the cache. |
|
55 */ |
|
56 void evict_all(); |
|
57 |
|
58 protected: |
|
59 typedef oasys::CacheCapacityHelper<GbofId, EndpointID> CacheCapacityHelper; |
|
60 typedef oasys::Cache<GbofId, EndpointID, CacheCapacityHelper> Cache; |
|
61 Cache cache_; |
|
62 }; |
|
63 |
|
64 } // namespace dtn |
|
65 |
|
66 |
|
67 #endif /* _BUNDLEINFOCACHE_H_ */ |