src: Updating code style to conform (more or less) to ndn-cxx style
Also, adding .clang-format that describes the applied style. Note that
this style requires a slightly customized version of clang-format.
diff --git a/model/cs/content-store-impl.cpp b/model/cs/content-store-impl.cpp
index 225d137..b4d2eae 100644
--- a/model/cs/content-store-impl.cpp
+++ b/model/cs/content-store-impl.cpp
@@ -27,14 +27,14 @@
#include "../../utils/trie/multi-policy.hpp"
#include "../../utils/trie/aggregate-stats-policy.hpp"
-#define NS_OBJECT_ENSURE_REGISTERED_TEMPL(type, templ) \
- static struct X ## type ## templ ## RegistrationClass \
- { \
- X ## type ## templ ## RegistrationClass () { \
- ns3::TypeId tid = type<templ>::GetTypeId (); \
- tid.GetParent (); \
- } \
- } x_ ## type ## templ ## RegistrationVariable
+#define NS_OBJECT_ENSURE_REGISTERED_TEMPL(type, templ) \
+ static struct X##type##templ##RegistrationClass { \
+ X##type##templ##RegistrationClass() \
+ { \
+ ns3::TypeId tid = type<templ>::GetTypeId(); \
+ tid.GetParent(); \
+ } \
+ } x_##type##templ##RegistrationVariable
namespace ns3 {
namespace ndn {
@@ -69,15 +69,15 @@
NS_OBJECT_ENSURE_REGISTERED_TEMPL(ContentStoreImpl, fifo_policy_traits);
NS_OBJECT_ENSURE_REGISTERED_TEMPL(ContentStoreImpl, lfu_policy_traits);
-
-typedef multi_policy_traits< boost::mpl::vector2< lru_policy_traits,
- aggregate_stats_policy_traits > > LruWithCountsTraits;
-typedef multi_policy_traits< boost::mpl::vector2< random_policy_traits,
- aggregate_stats_policy_traits > > RandomWithCountsTraits;
-typedef multi_policy_traits< boost::mpl::vector2< fifo_policy_traits,
- aggregate_stats_policy_traits > > FifoWithCountsTraits;
-typedef multi_policy_traits< boost::mpl::vector2< lfu_policy_traits,
- aggregate_stats_policy_traits > > LfuWithCountsTraits;
+typedef multi_policy_traits<boost::mpl::vector2<lru_policy_traits, aggregate_stats_policy_traits>>
+ LruWithCountsTraits;
+typedef multi_policy_traits<boost::mpl::vector2<random_policy_traits,
+ aggregate_stats_policy_traits>>
+ RandomWithCountsTraits;
+typedef multi_policy_traits<boost::mpl::vector2<fifo_policy_traits, aggregate_stats_policy_traits>>
+ FifoWithCountsTraits;
+typedef multi_policy_traits<boost::mpl::vector2<lfu_policy_traits, aggregate_stats_policy_traits>>
+ LfuWithCountsTraits;
template class ContentStoreImpl<LruWithCountsTraits>;
NS_OBJECT_ENSURE_REGISTERED_TEMPL(ContentStoreImpl, LruWithCountsTraits);
@@ -95,25 +95,28 @@
// /**
// * \brief Content Store implementing LRU cache replacement policy
// */
-class Lru : public ContentStoreImpl<lru_policy_traits> { };
+class Lru : public ContentStoreImpl<lru_policy_traits> {
+};
/**
* \brief Content Store implementing FIFO cache replacement policy
*/
-class Fifo : public ContentStoreImpl<fifo_policy_traits> { };
+class Fifo : public ContentStoreImpl<fifo_policy_traits> {
+};
/**
* \brief Content Store implementing Random cache replacement policy
*/
-class Random : public ContentStoreImpl<random_policy_traits> { };
+class Random : public ContentStoreImpl<random_policy_traits> {
+};
/**
* \brief Content Store implementing Least Frequently Used cache replacement policy
*/
-class Lfu : public ContentStoreImpl<lfu_policy_traits> { };
+class Lfu : public ContentStoreImpl<lfu_policy_traits> {
+};
#endif
-
} // namespace cs
} // namespace ndn
} // namespace ns3
diff --git a/model/cs/content-store-impl.hpp b/model/cs/content-store-impl.hpp
index 1254bb2..b35fdb4 100644
--- a/model/cs/content-store-impl.hpp
+++ b/model/cs/content-store-impl.hpp
@@ -43,292 +43,293 @@
* @brief Cache entry implementation with additional references to the base container
*/
template<class CS>
-class EntryImpl : public Entry
-{
+class EntryImpl : public Entry {
public:
typedef Entry base_type;
public:
- EntryImpl (Ptr<ContentStore> cs, Ptr<const Data> data)
- : Entry (cs, data)
- , item_ (0)
+ EntryImpl(Ptr<ContentStore> cs, Ptr<const Data> data)
+ : Entry(cs, data)
+ , item_(0)
{
}
void
- SetTrie (typename CS::super::iterator item)
+ SetTrie(typename CS::super::iterator item)
{
item_ = item;
}
- typename CS::super::iterator to_iterator () { return item_; }
- typename CS::super::const_iterator to_iterator () const { return item_; }
+ typename CS::super::iterator
+ to_iterator()
+ {
+ return item_;
+ }
+ typename CS::super::const_iterator
+ to_iterator() const
+ {
+ return item_;
+ }
private:
typename CS::super::iterator item_;
};
-
-
/**
* @ingroup ndn-cs
* @brief Base implementation of NDN content store
*/
template<class Policy>
-class ContentStoreImpl : public ContentStore,
- protected ndnSIM::trie_with_policy< Name,
- ndnSIM::smart_pointer_payload_traits< EntryImpl< ContentStoreImpl< Policy > >, Entry >,
- Policy >
-{
+class ContentStoreImpl
+ : public ContentStore,
+ protected ndnSIM::
+ trie_with_policy<Name,
+ ndnSIM::smart_pointer_payload_traits<EntryImpl<ContentStoreImpl<Policy>>,
+ Entry>,
+ Policy> {
public:
- typedef ndnSIM::trie_with_policy< Name,
- ndnSIM::smart_pointer_payload_traits< EntryImpl< ContentStoreImpl< Policy > >, Entry >,
- Policy > super;
+ typedef ndnSIM::
+ trie_with_policy<Name, ndnSIM::smart_pointer_payload_traits<EntryImpl<ContentStoreImpl<Policy>>,
+ Entry>,
+ Policy> super;
- typedef EntryImpl< ContentStoreImpl< Policy > > entry;
+ typedef EntryImpl<ContentStoreImpl<Policy>> entry;
static TypeId
- GetTypeId ();
+ GetTypeId();
- ContentStoreImpl () { };
- virtual ~ContentStoreImpl () { };
+ ContentStoreImpl(){};
+ virtual ~ContentStoreImpl(){};
// from ContentStore
virtual inline Ptr<Data>
- Lookup (Ptr<const Interest> interest);
+ Lookup(Ptr<const Interest> interest);
virtual inline bool
- Add (Ptr<const Data> data);
+ Add(Ptr<const Data> data);
// virtual bool
// Remove (Ptr<Interest> header);
virtual inline void
- Print (std::ostream &os) const;
+ Print(std::ostream& os) const;
virtual uint32_t
- GetSize () const;
+ GetSize() const;
virtual Ptr<Entry>
- Begin ();
+ Begin();
virtual Ptr<Entry>
- End ();
+ End();
- virtual Ptr<Entry>
- Next (Ptr<Entry>);
+ virtual Ptr<Entry> Next(Ptr<Entry>);
- const typename super::policy_container &
- GetPolicy () const { return super::getPolicy (); }
+ const typename super::policy_container&
+ GetPolicy() const
+ {
+ return super::getPolicy();
+ }
- typename super::policy_container &
- GetPolicy () { return super::getPolicy (); }
-
+ typename super::policy_container&
+ GetPolicy()
+ {
+ return super::getPolicy();
+ }
+
private:
void
- SetMaxSize (uint32_t maxSize);
+ SetMaxSize(uint32_t maxSize);
uint32_t
- GetMaxSize () const;
+ GetMaxSize() const;
private:
static LogComponent g_log; ///< @brief Logging variable
- /// @brief trace of for entry additions (fired every time entry is successfully added to the cache): first parameter is pointer to the CS entry
- TracedCallback< Ptr<const Entry> > m_didAddEntry;
+ /// @brief trace of for entry additions (fired every time entry is successfully added to the
+ /// cache): first parameter is pointer to the CS entry
+ TracedCallback<Ptr<const Entry>> m_didAddEntry;
};
//////////////////////////////////////////
////////// Implementation ////////////////
//////////////////////////////////////////
-
template<class Policy>
-LogComponent ContentStoreImpl< Policy >::g_log = LogComponent (("ndn.cs." + Policy::GetName ()).c_str ());
-
+LogComponent
+ ContentStoreImpl<Policy>::g_log = LogComponent(("ndn.cs." + Policy::GetName()).c_str());
template<class Policy>
TypeId
-ContentStoreImpl< Policy >::GetTypeId ()
+ContentStoreImpl<Policy>::GetTypeId()
{
- static TypeId tid = TypeId (("ns3::ndn::cs::"+Policy::GetName ()).c_str ())
- .SetGroupName ("Ndn")
- .SetParent<ContentStore> ()
- .AddConstructor< ContentStoreImpl< Policy > > ()
- .AddAttribute ("MaxSize",
- "Set maximum number of entries in ContentStore. If 0, limit is not enforced",
- StringValue ("100"),
- MakeUintegerAccessor (&ContentStoreImpl< Policy >::GetMaxSize,
- &ContentStoreImpl< Policy >::SetMaxSize),
- MakeUintegerChecker<uint32_t> ())
+ static TypeId tid =
+ TypeId(("ns3::ndn::cs::" + Policy::GetName()).c_str())
+ .SetGroupName("Ndn")
+ .SetParent<ContentStore>()
+ .AddConstructor<ContentStoreImpl<Policy>>()
+ .AddAttribute("MaxSize",
+ "Set maximum number of entries in ContentStore. If 0, limit is not enforced",
+ StringValue("100"), MakeUintegerAccessor(&ContentStoreImpl<Policy>::GetMaxSize,
+ &ContentStoreImpl<Policy>::SetMaxSize),
+ MakeUintegerChecker<uint32_t>())
- .AddTraceSource ("DidAddEntry", "Trace fired every time entry is successfully added to the cache",
- MakeTraceSourceAccessor (&ContentStoreImpl< Policy >::m_didAddEntry))
- ;
+ .AddTraceSource("DidAddEntry",
+ "Trace fired every time entry is successfully added to the cache",
+ MakeTraceSourceAccessor(&ContentStoreImpl<Policy>::m_didAddEntry));
return tid;
}
-struct isNotExcluded
-{
- inline
- isNotExcluded (const Exclude &exclude)
- : m_exclude (exclude)
+struct isNotExcluded {
+ inline isNotExcluded(const Exclude& exclude)
+ : m_exclude(exclude)
{
}
-
+
bool
- operator () (const name::Component &comp) const
+ operator()(const name::Component& comp) const
{
- return !m_exclude.isExcluded (comp);
+ return !m_exclude.isExcluded(comp);
}
private:
- const Exclude &m_exclude;
+ const Exclude& m_exclude;
};
template<class Policy>
Ptr<Data>
-ContentStoreImpl<Policy>::Lookup (Ptr<const Interest> interest)
+ContentStoreImpl<Policy>::Lookup(Ptr<const Interest> interest)
{
- NS_LOG_FUNCTION (this << interest->GetName ());
+ NS_LOG_FUNCTION(this << interest->GetName());
typename super::const_iterator node;
- if (interest->GetExclude () == 0)
- {
- node = this->deepest_prefix_match (interest->GetName ());
- }
- else
- {
- node = this->deepest_prefix_match_if_next_level (interest->GetName (),
- isNotExcluded (*interest->GetExclude ()));
- }
+ if (interest->GetExclude() == 0) {
+ node = this->deepest_prefix_match(interest->GetName());
+ }
+ else {
+ node = this->deepest_prefix_match_if_next_level(interest->GetName(),
+ isNotExcluded(*interest->GetExclude()));
+ }
- if (node != this->end ())
- {
- this->m_cacheHitsTrace (interest, node->payload ()->GetData ());
+ if (node != this->end()) {
+ this->m_cacheHitsTrace(interest, node->payload()->GetData());
- Ptr<Data> copy = Create<Data> (*node->payload ()->GetData ());
- ConstCast<Packet> (copy->GetPayload ())->RemoveAllPacketTags ();
- return copy;
- }
- else
- {
- this->m_cacheMissesTrace (interest);
- return 0;
- }
+ Ptr<Data> copy = Create<Data>(*node->payload()->GetData());
+ ConstCast<Packet>(copy->GetPayload())->RemoveAllPacketTags();
+ return copy;
+ }
+ else {
+ this->m_cacheMissesTrace(interest);
+ return 0;
+ }
}
template<class Policy>
bool
-ContentStoreImpl<Policy>::Add (Ptr<const Data> data)
+ContentStoreImpl<Policy>::Add(Ptr<const Data> data)
{
- NS_LOG_FUNCTION (this << data->GetName ());
+ NS_LOG_FUNCTION(this << data->GetName());
- Ptr< entry > newEntry = Create< entry > (this, data);
- std::pair< typename super::iterator, bool > result = super::insert (data->GetName (), newEntry);
+ Ptr<entry> newEntry = Create<entry>(this, data);
+ std::pair<typename super::iterator, bool> result = super::insert(data->GetName(), newEntry);
- if (result.first != super::end ())
- {
- if (result.second)
- {
- newEntry->SetTrie (result.first);
+ if (result.first != super::end()) {
+ if (result.second) {
+ newEntry->SetTrie(result.first);
- m_didAddEntry (newEntry);
- return true;
- }
- else
- {
- // should we do anything?
- // update payload? add new payload?
- return false;
- }
+ m_didAddEntry(newEntry);
+ return true;
}
+ else {
+ // should we do anything?
+ // update payload? add new payload?
+ return false;
+ }
+ }
else
return false; // cannot insert entry
}
template<class Policy>
void
-ContentStoreImpl<Policy>::Print (std::ostream &os) const
+ContentStoreImpl<Policy>::Print(std::ostream& os) const
{
- for (typename super::policy_container::const_iterator item = this->getPolicy ().begin ();
- item != this->getPolicy ().end ();
- item++)
- {
- os << item->payload ()->GetName () << std::endl;
- }
+ for (typename super::policy_container::const_iterator item = this->getPolicy().begin();
+ item != this->getPolicy().end(); item++) {
+ os << item->payload()->GetName() << std::endl;
+ }
}
template<class Policy>
void
-ContentStoreImpl<Policy>::SetMaxSize (uint32_t maxSize)
+ContentStoreImpl<Policy>::SetMaxSize(uint32_t maxSize)
{
- this->getPolicy ().set_max_size (maxSize);
+ this->getPolicy().set_max_size(maxSize);
}
template<class Policy>
uint32_t
-ContentStoreImpl<Policy>::GetMaxSize () const
+ContentStoreImpl<Policy>::GetMaxSize() const
{
- return this->getPolicy ().get_max_size ();
+ return this->getPolicy().get_max_size();
}
template<class Policy>
uint32_t
-ContentStoreImpl<Policy>::GetSize () const
+ContentStoreImpl<Policy>::GetSize() const
{
- return this->getPolicy ().size ();
+ return this->getPolicy().size();
}
template<class Policy>
Ptr<Entry>
-ContentStoreImpl<Policy>::Begin ()
+ContentStoreImpl<Policy>::Begin()
{
- typename super::parent_trie::recursive_iterator item (super::getTrie ()), end (0);
- for (; item != end; item++)
- {
- if (item->payload () == 0) continue;
- break;
- }
+ typename super::parent_trie::recursive_iterator item(super::getTrie()), end(0);
+ for (; item != end; item++) {
+ if (item->payload() == 0)
+ continue;
+ break;
+ }
if (item == end)
- return End ();
+ return End();
else
- return item->payload ();
+ return item->payload();
}
template<class Policy>
Ptr<Entry>
-ContentStoreImpl<Policy>::End ()
+ContentStoreImpl<Policy>::End()
{
return 0;
}
template<class Policy>
Ptr<Entry>
-ContentStoreImpl<Policy>::Next (Ptr<Entry> from)
+ContentStoreImpl<Policy>::Next(Ptr<Entry> from)
{
- if (from == 0) return 0;
+ if (from == 0)
+ return 0;
- typename super::parent_trie::recursive_iterator
- item (*StaticCast< entry > (from)->to_iterator ()),
- end (0);
+ typename super::parent_trie::recursive_iterator item(*StaticCast<entry>(from)->to_iterator()),
+ end(0);
- for (item++; item != end; item++)
- {
- if (item->payload () == 0) continue;
- break;
- }
+ for (item++; item != end; item++) {
+ if (item->payload() == 0)
+ continue;
+ break;
+ }
if (item == end)
- return End ();
+ return End();
else
- return item->payload ();
+ return item->payload();
}
-
} // namespace cs
} // namespace ndn
} // namespace ns3
diff --git a/model/cs/content-store-nocache.cpp b/model/cs/content-store-nocache.cpp
index 61515c1..85505d1 100644
--- a/model/cs/content-store-nocache.cpp
+++ b/model/cs/content-store-nocache.cpp
@@ -17,7 +17,7 @@
*
* Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
* Ilya Moiseenko <iliamo@cs.ucla.edu>
- *
+ *
*/
#include "content-store-nocache.hpp"
@@ -25,72 +25,70 @@
#include "ns3/log.h"
#include "ns3/packet.h"
-NS_LOG_COMPONENT_DEFINE ("ndn.cs.Nocache");
+NS_LOG_COMPONENT_DEFINE("ndn.cs.Nocache");
namespace ns3 {
namespace ndn {
namespace cs {
-NS_OBJECT_ENSURE_REGISTERED (Nocache);
+NS_OBJECT_ENSURE_REGISTERED(Nocache);
-TypeId
-Nocache::GetTypeId (void)
+TypeId
+Nocache::GetTypeId(void)
{
- static TypeId tid = TypeId ("ns3::ndn::cs::Nocache")
- .SetGroupName ("Ndn")
- .SetParent<ContentStore> ()
- .AddConstructor< Nocache > ()
- ;
+ static TypeId tid = TypeId("ns3::ndn::cs::Nocache")
+ .SetGroupName("Ndn")
+ .SetParent<ContentStore>()
+ .AddConstructor<Nocache>();
return tid;
}
-Nocache::Nocache ()
+Nocache::Nocache()
{
}
-Nocache::~Nocache ()
+Nocache::~Nocache()
{
}
Ptr<Data>
-Nocache::Lookup (Ptr<const Interest> interest)
+Nocache::Lookup(Ptr<const Interest> interest)
{
- this->m_cacheMissesTrace (interest);
+ this->m_cacheMissesTrace(interest);
return 0;
}
bool
-Nocache::Add (Ptr<const Data> data)
+Nocache::Add(Ptr<const Data> data)
{
return false;
}
void
-Nocache::Print (std::ostream &os) const
+Nocache::Print(std::ostream& os) const
{
}
uint32_t
-Nocache::GetSize () const
+Nocache::GetSize() const
{
return 0;
}
Ptr<cs::Entry>
-Nocache::Begin ()
+Nocache::Begin()
{
return 0;
}
Ptr<cs::Entry>
-Nocache::End ()
+Nocache::End()
{
return 0;
}
-Ptr<cs::Entry>
-Nocache::Next (Ptr<cs::Entry>)
+Ptr<cs::Entry> Nocache::Next(Ptr<cs::Entry>)
{
return 0;
}
diff --git a/model/cs/content-store-nocache.hpp b/model/cs/content-store-nocache.hpp
index ac7ced7..5745821 100644
--- a/model/cs/content-store-nocache.hpp
+++ b/model/cs/content-store-nocache.hpp
@@ -20,7 +20,7 @@
*/
#ifndef NDN_CONTENT_STORE_NOCACHE_H
-#define NDN_CONTENT_STORE_NOCACHE_H
+#define NDN_CONTENT_STORE_NOCACHE_H
#include "ns3/ndnSIM/model/cs/ndn-content-store.hpp"
@@ -32,49 +32,45 @@
* @ingroup ndn-cs
* @brief Implementation of ContentStore that completely disables caching
*/
-class Nocache : public ContentStore
-{
+class Nocache : public ContentStore {
public:
/**
* \brief Interface ID
*
* \return interface ID
*/
- static
- TypeId GetTypeId ();
+ static TypeId
+ GetTypeId();
/**
* @brief Default constructor
*/
- Nocache ();
-
+ Nocache();
+
/**
* @brief Virtual destructor
*/
- virtual
- ~Nocache ();
+ virtual ~Nocache();
virtual Ptr<Data>
- Lookup (Ptr<const Interest> interest);
+ Lookup(Ptr<const Interest> interest);
virtual bool
- Add (Ptr<const Data> data);
+ Add(Ptr<const Data> data);
virtual void
- Print (std::ostream &os) const;
+ Print(std::ostream& os) const;
virtual uint32_t
- GetSize () const;
+ GetSize() const;
virtual Ptr<cs::Entry>
- Begin ();
+ Begin();
virtual Ptr<cs::Entry>
- End ();
+ End();
- virtual Ptr<cs::Entry>
- Next (Ptr<cs::Entry>);
-
+ virtual Ptr<cs::Entry> Next(Ptr<cs::Entry>);
};
} // namespace cs
diff --git a/model/cs/content-store-with-freshness.cpp b/model/cs/content-store-with-freshness.cpp
index e132a78..3fa39b9 100644
--- a/model/cs/content-store-with-freshness.cpp
+++ b/model/cs/content-store-with-freshness.cpp
@@ -25,14 +25,14 @@
#include "../../utils/trie/fifo-policy.hpp"
#include "../../utils/trie/lfu-policy.hpp"
-#define NS_OBJECT_ENSURE_REGISTERED_TEMPL(type, templ) \
- static struct X ## type ## templ ## RegistrationClass \
- { \
- X ## type ## templ ## RegistrationClass () { \
- ns3::TypeId tid = type<templ>::GetTypeId (); \
- tid.GetParent (); \
- } \
- } x_ ## type ## templ ## RegistrationVariable
+#define NS_OBJECT_ENSURE_REGISTERED_TEMPL(type, templ) \
+ static struct X##type##templ##RegistrationClass { \
+ X##type##templ##RegistrationClass() \
+ { \
+ ns3::TypeId tid = type<templ>::GetTypeId(); \
+ tid.GetParent(); \
+ } \
+ } x_##type##templ##RegistrationVariable
namespace ns3 {
namespace ndn {
@@ -62,7 +62,6 @@
**/
template class ContentStoreWithFreshness<lfu_policy_traits>;
-
NS_OBJECT_ENSURE_REGISTERED_TEMPL(ContentStoreWithFreshness, lru_policy_traits);
NS_OBJECT_ENSURE_REGISTERED_TEMPL(ContentStoreWithFreshness, random_policy_traits);
NS_OBJECT_ENSURE_REGISTERED_TEMPL(ContentStoreWithFreshness, fifo_policy_traits);
@@ -73,26 +72,29 @@
// /**
// * \brief Content Store with freshness implementing LRU cache replacement policy
// */
-class Freshness::Lru : public ContentStoreWithFreshness<lru_policy_traits> { };
+class Freshness::Lru : public ContentStoreWithFreshness<lru_policy_traits> {
+};
/**
* \brief Content Store with freshness implementing FIFO cache replacement policy
*/
-class Freshness::Fifo : public ContentStoreWithFreshness<fifo_policy_traits> { };
+class Freshness::Fifo : public ContentStoreWithFreshness<fifo_policy_traits> {
+};
/**
* \brief Content Store with freshness implementing Random cache replacement policy
*/
-class Freshness::Random : public ContentStoreWithFreshness<random_policy_traits> { };
+class Freshness::Random : public ContentStoreWithFreshness<random_policy_traits> {
+};
/**
* \brief Content Store with freshness implementing Least Frequently Used cache replacement policy
*/
-class Freshness::Lfu : public ContentStoreWithFreshness<lfu_policy_traits> { };
+class Freshness::Lfu : public ContentStoreWithFreshness<lfu_policy_traits> {
+};
#endif
-
} // namespace cs
} // namespace ndn
} // namespace ns3
diff --git a/model/cs/content-store-with-freshness.hpp b/model/cs/content-store-with-freshness.hpp
index 2bd74de..07aa56f 100644
--- a/model/cs/content-store-with-freshness.hpp
+++ b/model/cs/content-store-with-freshness.hpp
@@ -37,29 +37,34 @@
* @brief Special content store realization that honors Freshness parameter in Data packets
*/
template<class Policy>
-class ContentStoreWithFreshness :
- public ContentStoreImpl< ndnSIM::multi_policy_traits< boost::mpl::vector2< Policy, ndnSIM::freshness_policy_traits > > >
-{
+class ContentStoreWithFreshness
+ : public ContentStoreImpl<ndnSIM::
+ multi_policy_traits<boost::mpl::
+ vector2<Policy,
+ ndnSIM::freshness_policy_traits>>> {
public:
- typedef ContentStoreImpl< ndnSIM::multi_policy_traits< boost::mpl::vector2< Policy, ndnSIM::freshness_policy_traits > > > super;
+ typedef ContentStoreImpl<ndnSIM::multi_policy_traits<boost::mpl::
+ vector2<Policy,
+ ndnSIM::freshness_policy_traits>>>
+ super;
typedef typename super::policy_container::template index<1>::type freshness_policy_container;
static TypeId
- GetTypeId ();
+ GetTypeId();
virtual inline void
- Print (std::ostream &os) const;
+ Print(std::ostream& os) const;
virtual inline bool
- Add (Ptr<const Data> data);
+ Add(Ptr<const Data> data);
private:
inline void
- CleanExpired ();
+ CleanExpired();
inline void
- RescheduleCleaning ();
+ RescheduleCleaning();
private:
static LogComponent g_log; ///< @brief Logging variable
@@ -72,20 +77,18 @@
////////// Implementation ////////////////
//////////////////////////////////////////
-
template<class Policy>
-LogComponent
-ContentStoreWithFreshness< Policy >::g_log = LogComponent (("ndn.cs.Freshness." + Policy::GetName ()).c_str ());
-
+LogComponent ContentStoreWithFreshness<Policy>::g_log = LogComponent(("ndn.cs.Freshness."
+ + Policy::GetName()).c_str());
template<class Policy>
TypeId
-ContentStoreWithFreshness< Policy >::GetTypeId ()
+ContentStoreWithFreshness<Policy>::GetTypeId()
{
- static TypeId tid = TypeId (("ns3::ndn::cs::Freshness::"+Policy::GetName ()).c_str ())
- .SetGroupName ("Ndn")
- .SetParent<super> ()
- .template AddConstructor< ContentStoreWithFreshness< Policy > > ()
+ static TypeId tid = TypeId(("ns3::ndn::cs::Freshness::" + Policy::GetName()).c_str())
+ .SetGroupName("Ndn")
+ .SetParent<super>()
+ .template AddConstructor<ContentStoreWithFreshness<Policy>>()
// trace stuff here
;
@@ -93,95 +96,93 @@
return tid;
}
-
template<class Policy>
inline bool
-ContentStoreWithFreshness< Policy >::Add (Ptr<const Data> data)
+ContentStoreWithFreshness<Policy>::Add(Ptr<const Data> data)
{
- bool ok = super::Add (data);
- if (!ok) return false;
+ bool ok = super::Add(data);
+ if (!ok)
+ return false;
- NS_LOG_DEBUG (data->GetName () << " added to cache");
- RescheduleCleaning ();
+ NS_LOG_DEBUG(data->GetName() << " added to cache");
+ RescheduleCleaning();
return true;
}
template<class Policy>
inline void
-ContentStoreWithFreshness< Policy >::RescheduleCleaning ()
+ContentStoreWithFreshness<Policy>::RescheduleCleaning()
{
- const freshness_policy_container &freshness = this->getPolicy ().template get<freshness_policy_container> ();
+ const freshness_policy_container& freshness =
+ this->getPolicy().template get<freshness_policy_container>();
- if (freshness.size () > 0)
+ if (freshness.size() > 0) {
+ Time nextStateTime =
+ freshness_policy_container::policy_base::get_freshness(&(*freshness.begin()));
+
+ if (m_scheduledCleaningTime.IsZero() || // if not yet scheduled
+ m_scheduledCleaningTime > nextStateTime) // if new item expire sooner than already scheduled
{
- Time nextStateTime = freshness_policy_container::policy_base::get_freshness (&(*freshness.begin ()));
+ if (m_cleanEvent.IsRunning()) {
+ Simulator::Remove(m_cleanEvent); // just canceling would not clean up list of events
+ }
- if (m_scheduledCleaningTime.IsZero () || // if not yet scheduled
- m_scheduledCleaningTime > nextStateTime) // if new item expire sooner than already scheduled
- {
- if (m_cleanEvent.IsRunning ())
- {
- Simulator::Remove (m_cleanEvent); // just canceling would not clean up list of events
- }
-
- // NS_LOG_DEBUG ("Next event in: " << (nextStateTime - Now ()).ToDouble (Time::S) << "s");
- m_cleanEvent = Simulator::Schedule (nextStateTime - Now (), &ContentStoreWithFreshness< Policy >::CleanExpired, this);
- m_scheduledCleaningTime = nextStateTime;
- }
+ // NS_LOG_DEBUG ("Next event in: " << (nextStateTime - Now ()).ToDouble (Time::S) << "s");
+ m_cleanEvent = Simulator::Schedule(nextStateTime - Now(),
+ &ContentStoreWithFreshness<Policy>::CleanExpired, this);
+ m_scheduledCleaningTime = nextStateTime;
}
- else
- {
- if (m_cleanEvent.IsRunning ())
- {
- Simulator::Remove (m_cleanEvent); // just canceling would not clean up list of events
- }
+ }
+ else {
+ if (m_cleanEvent.IsRunning()) {
+ Simulator::Remove(m_cleanEvent); // just canceling would not clean up list of events
}
+ }
}
-
template<class Policy>
inline void
-ContentStoreWithFreshness< Policy >::CleanExpired ()
+ContentStoreWithFreshness<Policy>::CleanExpired()
{
- freshness_policy_container &freshness = this->getPolicy ().template get<freshness_policy_container> ();
+ freshness_policy_container& freshness =
+ this->getPolicy().template get<freshness_policy_container>();
- // NS_LOG_LOGIC (">> Cleaning: Total number of items:" << this->getPolicy ().size () << ", items with freshness: " << freshness.size ());
- Time now = Simulator::Now ();
+ // NS_LOG_LOGIC (">> Cleaning: Total number of items:" << this->getPolicy ().size () << ", items
+ // with freshness: " << freshness.size ());
+ Time now = Simulator::Now();
- while (!freshness.empty ())
+ while (!freshness.empty()) {
+ typename freshness_policy_container::iterator entry = freshness.begin();
+
+ if (freshness_policy_container::policy_base::get_freshness(&(*entry))
+ <= now) // is the record stale?
{
- typename freshness_policy_container::iterator entry = freshness.begin ();
-
- if (freshness_policy_container::policy_base::get_freshness (&(*entry)) <= now) // is the record stale?
- {
- super::erase (&(*entry));
- }
- else
- break; // nothing else to do. All later records will not be stale
+ super::erase(&(*entry));
}
- // NS_LOG_LOGIC ("<< Cleaning: Total number of items:" << this->getPolicy ().size () << ", items with freshness: " << freshness.size ());
+ else
+ break; // nothing else to do. All later records will not be stale
+ }
+ // NS_LOG_LOGIC ("<< Cleaning: Total number of items:" << this->getPolicy ().size () << ", items
+ // with freshness: " << freshness.size ());
- m_scheduledCleaningTime = Time ();
- RescheduleCleaning ();
+ m_scheduledCleaningTime = Time();
+ RescheduleCleaning();
}
template<class Policy>
void
-ContentStoreWithFreshness< Policy >::Print (std::ostream &os) const
+ContentStoreWithFreshness<Policy>::Print(std::ostream& os) const
{
- // const freshness_policy_container &freshness = this->getPolicy ().template get<freshness_policy_container> ();
+ // const freshness_policy_container &freshness = this->getPolicy ().template
+ // get<freshness_policy_container> ();
- for (typename super::policy_container::const_iterator item = this->getPolicy ().begin ();
- item != this->getPolicy ().end ();
- item++)
- {
- Time ttl = freshness_policy_container::policy_base::get_freshness (&(*item)) - Simulator::Now ();
- os << item->payload ()->GetName () << "(left: " << ttl.ToDouble (Time::S) << "s)" << std::endl;
- }
+ for (typename super::policy_container::const_iterator item = this->getPolicy().begin();
+ item != this->getPolicy().end(); item++) {
+ Time ttl = freshness_policy_container::policy_base::get_freshness(&(*item)) - Simulator::Now();
+ os << item->payload()->GetName() << "(left: " << ttl.ToDouble(Time::S) << "s)" << std::endl;
+ }
}
-
-
} // namespace cs
} // namespace ndn
} // namespace ns3
diff --git a/model/cs/content-store-with-probability.cpp b/model/cs/content-store-with-probability.cpp
index bf5c181..313cb36 100644
--- a/model/cs/content-store-with-probability.cpp
+++ b/model/cs/content-store-with-probability.cpp
@@ -25,14 +25,14 @@
#include "../../utils/trie/fifo-policy.hpp"
#include "../../utils/trie/lfu-policy.hpp"
-#define NS_OBJECT_ENSURE_REGISTERED_TEMPL(type, templ) \
- static struct X ## type ## templ ## RegistrationClass \
- { \
- X ## type ## templ ## RegistrationClass () { \
- ns3::TypeId tid = type<templ>::GetTypeId (); \
- tid.GetParent (); \
- } \
- } x_ ## type ## templ ## RegistrationVariable
+#define NS_OBJECT_ENSURE_REGISTERED_TEMPL(type, templ) \
+ static struct X##type##templ##RegistrationClass { \
+ X##type##templ##RegistrationClass() \
+ { \
+ ns3::TypeId tid = type<templ>::GetTypeId(); \
+ tid.GetParent(); \
+ } \
+ } x_##type##templ##RegistrationVariable
namespace ns3 {
namespace ndn {
@@ -62,7 +62,6 @@
**/
template class ContentStoreWithProbability<lfu_policy_traits>;
-
NS_OBJECT_ENSURE_REGISTERED_TEMPL(ContentStoreWithProbability, lru_policy_traits);
NS_OBJECT_ENSURE_REGISTERED_TEMPL(ContentStoreWithProbability, random_policy_traits);
NS_OBJECT_ENSURE_REGISTERED_TEMPL(ContentStoreWithProbability, fifo_policy_traits);
@@ -73,26 +72,29 @@
// /**
// * \brief Content Store with freshness implementing LRU cache replacement policy
// */
-class Probability::Lru : public ContentStoreWithProbability<lru_policy_traits> { };
+class Probability::Lru : public ContentStoreWithProbability<lru_policy_traits> {
+};
/**
* \brief Content Store with freshness implementing FIFO cache replacement policy
*/
-class Probability::Fifo : public ContentStoreWithProbability<fifo_policy_traits> { };
+class Probability::Fifo : public ContentStoreWithProbability<fifo_policy_traits> {
+};
/**
* \brief Content Store with freshness implementing Random cache replacement policy
*/
-class Probability::Random : public ContentStoreWithProbability<random_policy_traits> { };
+class Probability::Random : public ContentStoreWithProbability<random_policy_traits> {
+};
/**
* \brief Content Store with freshness implementing Least Frequently Used cache replacement policy
*/
-class Probability::Lfu : public ContentStoreWithProbability<lfu_policy_traits> { };
+class Probability::Lfu : public ContentStoreWithProbability<lfu_policy_traits> {
+};
#endif
-
} // namespace cs
} // namespace ndn
} // namespace ns3
diff --git a/model/cs/content-store-with-probability.hpp b/model/cs/content-store-with-probability.hpp
index 55266e8..cca50c1 100644
--- a/model/cs/content-store-with-probability.hpp
+++ b/model/cs/content-store-with-probability.hpp
@@ -39,34 +39,33 @@
* @brief Special content store realization that honors Freshness parameter in Data packets
*/
template<class Policy>
-class ContentStoreWithProbability :
- public ContentStoreImpl< ndnSIM::multi_policy_traits< boost::mpl::vector2< ndnSIM::probability_policy_traits, Policy > > >
-{
+class ContentStoreWithProbability
+ : public ContentStoreImpl<ndnSIM::multi_policy_traits<boost::mpl::
+ vector2<ndnSIM::probability_policy_traits,
+ Policy>>> {
public:
- typedef ContentStoreImpl< ndnSIM::multi_policy_traits< boost::mpl::vector2< ndnSIM::probability_policy_traits, Policy > > > super;
+ typedef ContentStoreImpl<ndnSIM::multi_policy_traits<boost::mpl::
+ vector2<ndnSIM::probability_policy_traits,
+ Policy>>> super;
typedef typename super::policy_container::template index<0>::type probability_policy_container;
- ContentStoreWithProbability () {};
-
- static TypeId
- GetTypeId ();
-private:
+ ContentStoreWithProbability(){};
- void SetCacheProbability (double probability)
+ static TypeId
+ GetTypeId();
+
+private:
+ void
+ SetCacheProbability(double probability)
{
- this->getPolicy ()
- .template get<probability_policy_container> ()
- .set_probability (probability);
+ this->getPolicy().template get<probability_policy_container>().set_probability(probability);
}
double
- GetCacheProbability () const
+ GetCacheProbability() const
{
- return
- this->getPolicy ()
- .template get<probability_policy_container> ()
- .get_probability ();
+ return this->getPolicy().template get<probability_policy_container>().get_probability();
}
};
@@ -76,26 +75,25 @@
template<class Policy>
TypeId
-ContentStoreWithProbability< Policy >::GetTypeId ()
+ContentStoreWithProbability<Policy>::GetTypeId()
{
- static TypeId tid = TypeId (("ns3::ndn::cs::Probability::"+Policy::GetName ()).c_str ())
- .SetGroupName ("Ndn")
- .SetParent<super> ()
- .template AddConstructor< ContentStoreWithProbability< Policy > > ()
+ static TypeId tid =
+ TypeId(("ns3::ndn::cs::Probability::" + Policy::GetName()).c_str())
+ .SetGroupName("Ndn")
+ .SetParent<super>()
+ .template AddConstructor<ContentStoreWithProbability<Policy>>()
- .AddAttribute ("CacheProbability",
- "Set probability of caching in ContentStore. "
- "If 1, every content is cached. If 0, no content is cached.",
- DoubleValue (1.0),//(+)
- MakeDoubleAccessor (&ContentStoreWithProbability< Policy >::GetCacheProbability,
- &ContentStoreWithProbability< Policy >::SetCacheProbability),
- MakeDoubleChecker<double> ())
- ;
+ .AddAttribute("CacheProbability",
+ "Set probability of caching in ContentStore. "
+ "If 1, every content is cached. If 0, no content is cached.",
+ DoubleValue(1.0), //(+)
+ MakeDoubleAccessor(&ContentStoreWithProbability<Policy>::GetCacheProbability,
+ &ContentStoreWithProbability<Policy>::SetCacheProbability),
+ MakeDoubleChecker<double>());
return tid;
}
-
} // namespace cs
} // namespace ndn
} // namespace ns3
diff --git a/model/cs/content-store-with-stats.cpp b/model/cs/content-store-with-stats.cpp
index 7d6e567..1a44e37 100644
--- a/model/cs/content-store-with-stats.cpp
+++ b/model/cs/content-store-with-stats.cpp
@@ -25,14 +25,14 @@
#include "../../utils/trie/fifo-policy.hpp"
#include "../../utils/trie/lfu-policy.hpp"
-#define NS_OBJECT_ENSURE_REGISTERED_TEMPL(type, templ) \
- static struct X ## type ## templ ## RegistrationClass \
- { \
- X ## type ## templ ## RegistrationClass () { \
- ns3::TypeId tid = type<templ>::GetTypeId (); \
- tid.GetParent (); \
- } \
- } x_ ## type ## templ ## RegistrationVariable
+#define NS_OBJECT_ENSURE_REGISTERED_TEMPL(type, templ) \
+ static struct X##type##templ##RegistrationClass { \
+ X##type##templ##RegistrationClass() \
+ { \
+ ns3::TypeId tid = type<templ>::GetTypeId(); \
+ tid.GetParent(); \
+ } \
+ } x_##type##templ##RegistrationVariable
namespace ns3 {
namespace ndn {
@@ -68,31 +68,33 @@
NS_OBJECT_ENSURE_REGISTERED_TEMPL(ContentStoreWithStats, lfu_policy_traits);
-
#ifdef DOXYGEN
// /**
// * \brief Content Store with stats implementing LRU cache replacement policy
// */
-class Stats::Lru : public ContentStoreWithStats<lru_policy_traits> { };
+class Stats::Lru : public ContentStoreWithStats<lru_policy_traits> {
+};
/**
* \brief Content Store with stats implementing FIFO cache replacement policy
*/
-class Stats::Fifo : public ContentStoreWithStats<fifo_policy_traits> { };
+class Stats::Fifo : public ContentStoreWithStats<fifo_policy_traits> {
+};
/**
* \brief Content Store with stats implementing Random cache replacement policy
*/
-class Stats::Random : public ContentStoreWithStats<random_policy_traits> { };
+class Stats::Random : public ContentStoreWithStats<random_policy_traits> {
+};
/**
* \brief Content Store with stats implementing Least Frequently Used cache replacement policy
*/
-class Stats::Lfu : public ContentStoreWithStats<lfu_policy_traits> { };
+class Stats::Lfu : public ContentStoreWithStats<lfu_policy_traits> {
+};
#endif
-
} // namespace cs
} // namespace ndn
} // namespace ns3
diff --git a/model/cs/content-store-with-stats.hpp b/model/cs/content-store-with-stats.hpp
index 542b88c..b5f7540 100644
--- a/model/cs/content-store-with-stats.hpp
+++ b/model/cs/content-store-with-stats.hpp
@@ -37,54 +37,62 @@
* @brief Special content store realization that provides ability to track stats of CS operations
*/
template<class Policy>
-class ContentStoreWithStats :
- public ContentStoreImpl< ndnSIM::multi_policy_traits< boost::mpl::vector2< Policy, ndnSIM::lifetime_stats_policy_traits > > >
-{
+class ContentStoreWithStats
+ : public ContentStoreImpl<ndnSIM::
+ multi_policy_traits<boost::mpl::
+ vector2<Policy,
+ ndnSIM::
+ lifetime_stats_policy_traits>>> {
public:
- typedef ContentStoreImpl< ndnSIM::multi_policy_traits< boost::mpl::vector2< Policy, ndnSIM::lifetime_stats_policy_traits > > > super;
+ typedef ContentStoreImpl<ndnSIM::
+ multi_policy_traits<boost::mpl::
+ vector2<Policy,
+ ndnSIM::lifetime_stats_policy_traits>>>
+ super;
typedef typename super::policy_container::template index<1>::type lifetime_stats_container;
- ContentStoreWithStats ()
+ ContentStoreWithStats()
{
// connect traceback to the policy
- super::getPolicy ().template get<1> ().set_traced_callback (&m_willRemoveEntry);
+ super::getPolicy().template get<1>().set_traced_callback(&m_willRemoveEntry);
}
static TypeId
- GetTypeId ();
+ GetTypeId();
virtual inline void
- Print (std::ostream &os) const;
+ Print(std::ostream& os) const;
private:
static LogComponent g_log; ///< @brief Logging variable
- /// @brief trace of for entry removal: first parameter is pointer to the CS entry, second is how long entry was in the cache
- TracedCallback< Ptr<const Entry>, Time > m_willRemoveEntry;
+ /// @brief trace of for entry removal: first parameter is pointer to the CS entry, second is how
+ /// long entry was in the cache
+ TracedCallback<Ptr<const Entry>, Time> m_willRemoveEntry;
};
//////////////////////////////////////////
////////// Implementation ////////////////
//////////////////////////////////////////
-
template<class Policy>
-LogComponent
-ContentStoreWithStats< Policy >::g_log = LogComponent (("ndn.cs.Stats." + Policy::GetName ()).c_str ());
-
+LogComponent ContentStoreWithStats<Policy>::g_log = LogComponent(("ndn.cs.Stats."
+ + Policy::GetName()).c_str());
template<class Policy>
TypeId
-ContentStoreWithStats< Policy >::GetTypeId ()
+ContentStoreWithStats<Policy>::GetTypeId()
{
- static TypeId tid = TypeId (("ns3::ndn::cs::Stats::"+Policy::GetName ()).c_str ())
- .SetGroupName ("Ndn")
- .SetParent<super> ()
- .template AddConstructor< ContentStoreWithStats< Policy > > ()
+ static TypeId tid =
+ TypeId(("ns3::ndn::cs::Stats::" + Policy::GetName()).c_str())
+ .SetGroupName("Ndn")
+ .SetParent<super>()
+ .template AddConstructor<ContentStoreWithStats<Policy>>()
- .AddTraceSource ("WillRemoveEntry", "Trace called just before content store entry will be removed",
- MakeTraceSourceAccessor (&ContentStoreWithStats< Policy >::m_willRemoveEntry))
+ .AddTraceSource("WillRemoveEntry",
+ "Trace called just before content store entry will be removed",
+ MakeTraceSourceAccessor(&ContentStoreWithStats<Policy>::m_willRemoveEntry))
// trace stuff here
;
@@ -94,21 +102,18 @@
template<class Policy>
void
-ContentStoreWithStats< Policy >::Print (std::ostream &os) const
+ContentStoreWithStats<Policy>::Print(std::ostream& os) const
{
- // const freshness_policy_container &freshness = this->getPolicy ().template get<freshness_policy_container> ();
+ // const freshness_policy_container &freshness = this->getPolicy ().template
+ // get<freshness_policy_container> ();
- for (typename super::policy_container::const_iterator item = this->getPolicy ().begin ();
- item != this->getPolicy ().end ();
- item++)
- {
- Time alive = lifetime_stats_container::policy_base::get_time (&(*item)) - Simulator::Now ();
- os << item->payload ()->GetName () << "(alive: " << alive.ToDouble (Time::S) << "s)" << std::endl;
- }
+ for (typename super::policy_container::const_iterator item = this->getPolicy().begin();
+ item != this->getPolicy().end(); item++) {
+ Time alive = lifetime_stats_container::policy_base::get_time(&(*item)) - Simulator::Now();
+ os << item->payload()->GetName() << "(alive: " << alive.ToDouble(Time::S) << "s)" << std::endl;
+ }
}
-
-
} // namespace cs
} // namespace ndn
} // namespace ns3
diff --git a/model/cs/custom-policies/freshness-policy.hpp b/model/cs/custom-policies/freshness-policy.hpp
index b85635e..999c61d 100644
--- a/model/cs/custom-policies/freshness-policy.hpp
+++ b/model/cs/custom-policies/freshness-policy.hpp
@@ -35,126 +35,127 @@
/**
* @brief Traits for freshness policy
*/
-struct freshness_policy_traits
-{
+struct freshness_policy_traits {
/// @brief Name that can be used to identify the policy (for NS-3 object model and logging)
- static std::string GetName () { return "Freshness"; }
-
- struct policy_hook_type : public boost::intrusive::set_member_hook<> { Time timeWhenShouldExpire; };
-
- template<class Container>
- struct container_hook
+ static std::string
+ GetName()
{
- typedef boost::intrusive::member_hook< Container,
- policy_hook_type,
- &Container::policy_hook_ > type;
+ return "Freshness";
+ }
+
+ struct policy_hook_type : public boost::intrusive::set_member_hook<> {
+ Time timeWhenShouldExpire;
};
- template<class Base,
- class Container,
- class Hook>
- struct policy
- {
- static Time& get_freshness (typename Container::iterator item)
+ template<class Container>
+ struct container_hook {
+ typedef boost::intrusive::member_hook<Container, policy_hook_type, &Container::policy_hook_>
+ type;
+ };
+
+ template<class Base, class Container, class Hook>
+ struct policy {
+ static Time&
+ get_freshness(typename Container::iterator item)
{
- return static_cast<typename policy_container::value_traits::hook_type*>
- (policy_container::value_traits::to_node_ptr(*item))->timeWhenShouldExpire;
+ return static_cast<typename policy_container::value_traits::hook_type*>(
+ policy_container::value_traits::to_node_ptr(*item))->timeWhenShouldExpire;
}
- static const Time& get_freshness (typename Container::const_iterator item)
+ static const Time&
+ get_freshness(typename Container::const_iterator item)
{
- return static_cast<const typename policy_container::value_traits::hook_type*>
- (policy_container::value_traits::to_node_ptr(*item))->timeWhenShouldExpire;
+ return static_cast<const typename policy_container::value_traits::hook_type*>(
+ policy_container::value_traits::to_node_ptr(*item))->timeWhenShouldExpire;
}
template<class Key>
- struct MemberHookLess
- {
- bool operator () (const Key &a, const Key &b) const
+ struct MemberHookLess {
+ bool
+ operator()(const Key& a, const Key& b) const
{
- return get_freshness (&a) < get_freshness (&b);
+ return get_freshness(&a) < get_freshness(&b);
}
};
- typedef boost::intrusive::multiset< Container,
- boost::intrusive::compare< MemberHookLess< Container > >,
- Hook > policy_container;
+ typedef boost::intrusive::multiset<Container,
+ boost::intrusive::compare<MemberHookLess<Container>>,
+ Hook> policy_container;
-
- class type : public policy_container
- {
+ class type : public policy_container {
public:
typedef policy policy_base; // to get access to get_freshness methods from outside
typedef Container parent_trie;
- type (Base &base)
- : base_ (base)
- , max_size_ (100)
+ type(Base& base)
+ : base_(base)
+ , max_size_(100)
{
}
inline void
- update (typename parent_trie::iterator item)
+ update(typename parent_trie::iterator item)
{
// do nothing
}
inline bool
- insert (typename parent_trie::iterator item)
+ insert(typename parent_trie::iterator item)
{
// get_time (item) = Simulator::Now ();
- Time freshness = item->payload ()->GetData ()->GetFreshness ();
- if (!freshness.IsZero ())
- {
- get_freshness (item) = Simulator::Now () + freshness;
+ Time freshness = item->payload()->GetData()->GetFreshness();
+ if (!freshness.IsZero()) {
+ get_freshness(item) = Simulator::Now() + freshness;
- // push item only if freshness is non zero. otherwise, this payload is not controlled by the policy
- // note that .size() on this policy would return only number of items with non-infinite freshness policy
- policy_container::insert (*item);
- }
+ // push item only if freshness is non zero. otherwise, this payload is not controlled by
+ // the policy
+ // note that .size() on this policy would return only number of items with non-infinite
+ // freshness policy
+ policy_container::insert(*item);
+ }
return true;
}
inline void
- lookup (typename parent_trie::iterator item)
+ lookup(typename parent_trie::iterator item)
{
// do nothing. it's random policy
}
inline void
- erase (typename parent_trie::iterator item)
+ erase(typename parent_trie::iterator item)
{
- if (!item->payload ()->GetData ()->GetFreshness ().IsZero ())
- {
- // erase only if freshness is non zero (otherwise an item is not in the policy
- policy_container::erase (policy_container::s_iterator_to (*item));
- }
+ if (!item->payload()->GetData()->GetFreshness().IsZero()) {
+ // erase only if freshness is non zero (otherwise an item is not in the policy
+ policy_container::erase(policy_container::s_iterator_to(*item));
+ }
}
inline void
- clear ()
+ clear()
{
- policy_container::clear ();
+ policy_container::clear();
}
inline void
- set_max_size (size_t max_size)
+ set_max_size(size_t max_size)
{
max_size_ = max_size;
}
inline size_t
- get_max_size () const
+ get_max_size() const
{
return max_size_;
}
private:
- type () : base_(*((Base*)0)) { };
+ type()
+ : base_(*((Base*)0)){};
private:
- Base &base_;
+ Base& base_;
size_t max_size_;
};
};
diff --git a/model/cs/custom-policies/lifetime-stats-policy.hpp b/model/cs/custom-policies/lifetime-stats-policy.hpp
index 905f532..1102ef1 100644
--- a/model/cs/custom-policies/lifetime-stats-policy.hpp
+++ b/model/cs/custom-policies/lifetime-stats-policy.hpp
@@ -35,119 +35,122 @@
/**
* @brief Traits for lifetime stats policy
*/
-struct lifetime_stats_policy_traits
-{
+struct lifetime_stats_policy_traits {
/// @brief Name that can be used to identify the policy (for NS-3 object model and logging)
- static std::string GetName () { return "LifetimeStats"; }
-
- struct policy_hook_type : public boost::intrusive::list_member_hook<> { Time timeWhenAdded; };
-
- template<class Container>
- struct container_hook
+ static std::string
+ GetName()
{
- typedef boost::intrusive::member_hook< Container,
- policy_hook_type,
- &Container::policy_hook_ > type;
+ return "LifetimeStats";
+ }
+
+ struct policy_hook_type : public boost::intrusive::list_member_hook<> {
+ Time timeWhenAdded;
};
- template<class Base,
- class Container,
- class Hook>
- struct policy
- {
- typedef typename boost::intrusive::list< Container, Hook > policy_container;
-
- static Time& get_time (typename Container::iterator item)
+ template<class Container>
+ struct container_hook {
+ typedef boost::intrusive::member_hook<Container, policy_hook_type, &Container::policy_hook_>
+ type;
+ };
+
+ template<class Base, class Container, class Hook>
+ struct policy {
+ typedef typename boost::intrusive::list<Container, Hook> policy_container;
+
+ static Time&
+ get_time(typename Container::iterator item)
{
- return static_cast<typename policy_container::value_traits::hook_type*>
- (policy_container::value_traits::to_node_ptr(*item))->timeWhenAdded;
- }
-
- static const Time& get_time (typename Container::const_iterator item)
- {
- return static_cast<const typename policy_container::value_traits::hook_type*>
- (policy_container::value_traits::to_node_ptr(*item))->timeWhenAdded;
+ return static_cast<typename policy_container::value_traits::hook_type*>(
+ policy_container::value_traits::to_node_ptr(*item))->timeWhenAdded;
}
- class type : public policy_container
+ static const Time&
+ get_time(typename Container::const_iterator item)
{
+ return static_cast<const typename policy_container::value_traits::hook_type*>(
+ policy_container::value_traits::to_node_ptr(*item))->timeWhenAdded;
+ }
+
+ class type : public policy_container {
public:
typedef policy policy_base; // to get access to get_time methods from outside
typedef Container parent_trie;
- type (Base &base)
- : base_ (base)
- , max_size_ (100)
- , m_willRemoveEntry (0)
+ type(Base& base)
+ : base_(base)
+ , max_size_(100)
+ , m_willRemoveEntry(0)
{
}
inline void
- update (typename parent_trie::iterator item)
+ update(typename parent_trie::iterator item)
{
// do nothing. it's random policy
}
-
- inline bool
- insert (typename parent_trie::iterator item)
- {
- get_time (item) = Simulator::Now ();
- policy_container::push_back (*item);
+ inline bool
+ insert(typename parent_trie::iterator item)
+ {
+ get_time(item) = Simulator::Now();
+
+ policy_container::push_back(*item);
return true;
}
-
+
inline void
- lookup (typename parent_trie::iterator item)
+ lookup(typename parent_trie::iterator item)
{
// do nothing. it's random policy
}
-
- inline void
- erase (typename parent_trie::iterator item)
- {
- Time lifetime = Simulator::Now () - get_time (item);
- if (m_willRemoveEntry != 0)
- {
- (*m_willRemoveEntry) (item->payload (), lifetime);
- }
-
- policy_container::erase (policy_container::s_iterator_to (*item));
+ inline void
+ erase(typename parent_trie::iterator item)
+ {
+ Time lifetime = Simulator::Now() - get_time(item);
+
+ if (m_willRemoveEntry != 0) {
+ (*m_willRemoveEntry)(item->payload(), lifetime);
+ }
+
+ policy_container::erase(policy_container::s_iterator_to(*item));
}
inline void
- clear ()
+ clear()
{
- policy_container::clear ();
+ policy_container::clear();
}
inline void
- set_max_size (size_t max_size)
+ set_max_size(size_t max_size)
{
max_size_ = max_size;
}
inline size_t
- get_max_size () const
+ get_max_size() const
{
return max_size_;
}
void
- set_traced_callback (TracedCallback< typename parent_trie::payload_traits::const_base_type, Time > *callback)
+ set_traced_callback(
+ TracedCallback<typename parent_trie::payload_traits::const_base_type, Time>* callback)
{
m_willRemoveEntry = callback;
}
-
+
private:
- type () : base_(*((Base*)0)) { };
-
+ type()
+ : base_(*((Base*)0)){};
+
private:
- Base &base_;
+ Base& base_;
size_t max_size_;
- TracedCallback< typename parent_trie::payload_traits::const_base_type, Time > *m_willRemoveEntry;
+ TracedCallback<typename parent_trie::payload_traits::const_base_type, Time>*
+ m_willRemoveEntry;
};
};
};
diff --git a/model/cs/custom-policies/probability-policy.hpp b/model/cs/custom-policies/probability-policy.hpp
index 0c3088c..57d6835 100644
--- a/model/cs/custom-policies/probability-policy.hpp
+++ b/model/cs/custom-policies/probability-policy.hpp
@@ -33,109 +33,106 @@
/**
* @brief Traits for freshness policy
*/
-struct probability_policy_traits
-{
- static std::string GetName () { return "ProbabilityImpl"; }
-
- struct policy_hook_type : public boost::intrusive::list_member_hook<> {};
-
- template<class Container>
- struct container_hook
+struct probability_policy_traits {
+ static std::string
+ GetName()
{
- typedef boost::intrusive::member_hook< Container,
- policy_hook_type,
- &Container::policy_hook_ > type;
+ return "ProbabilityImpl";
+ }
+
+ struct policy_hook_type : public boost::intrusive::list_member_hook<> {
};
- template<class Base,
- class Container,
- class Hook>
- struct policy
- {
- typedef typename boost::intrusive::list< Container, Hook > policy_container;
-
- class type : public policy_container
- {
+ template<class Container>
+ struct container_hook {
+ typedef boost::intrusive::member_hook<Container, policy_hook_type, &Container::policy_hook_>
+ type;
+ };
+
+ template<class Base, class Container, class Hook>
+ struct policy {
+ typedef typename boost::intrusive::list<Container, Hook> policy_container;
+
+ class type : public policy_container {
public:
typedef policy policy_base; // to get access to get_freshness methods from outside
typedef Container parent_trie;
- type (Base &base)
- : base_ (base)
- , max_size_ (100)
- , probability_ (1.0)
+ type(Base& base)
+ : base_(base)
+ , max_size_(100)
+ , probability_(1.0)
{
}
inline void
- update (typename parent_trie::iterator item)
+ update(typename parent_trie::iterator item)
{
}
inline bool
- insert (typename parent_trie::iterator item)
+ insert(typename parent_trie::iterator item)
{
- if (ns3_rand_.GetValue () < probability_)
- {
- policy_container::push_back (*item);
+ if (ns3_rand_.GetValue() < probability_) {
+ policy_container::push_back(*item);
- // allow caching
- return true;
- }
- else
- {
- // don't allow caching
- return false;
- }
+ // allow caching
+ return true;
+ }
+ else {
+ // don't allow caching
+ return false;
+ }
}
inline void
- lookup (typename parent_trie::iterator item)
+ lookup(typename parent_trie::iterator item)
{
// do nothing. it's random policy
}
inline void
- erase (typename parent_trie::iterator item)
+ erase(typename parent_trie::iterator item)
{
- policy_container::erase (policy_container::s_iterator_to (*item));
+ policy_container::erase(policy_container::s_iterator_to(*item));
}
inline void
- clear ()
+ clear()
{
- policy_container::clear ();
+ policy_container::clear();
}
inline void
- set_max_size (size_t max_size)
+ set_max_size(size_t max_size)
{
max_size_ = max_size;
}
inline size_t
- get_max_size () const
+ get_max_size() const
{
return max_size_;
}
inline void
- set_probability (double probability)
+ set_probability(double probability)
{
probability_ = probability;
}
inline double
- get_probability () const
+ get_probability() const
{
return probability_;
- }
+ }
private:
- type () : base_(*((Base*)0)) { };
+ type()
+ : base_(*((Base*)0)){};
private:
- Base &base_;
+ Base& base_;
size_t max_size_;
double probability_;
UniformVariable ns3_rand_;
diff --git a/model/cs/ndn-content-store.cpp b/model/cs/ndn-content-store.cpp
index 4d3bb65..3588eb9 100644
--- a/model/cs/ndn-content-store.cpp
+++ b/model/cs/ndn-content-store.cpp
@@ -17,7 +17,7 @@
*
* Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
* Ilya Moiseenko <iliamo@cs.ucla.edu>
- *
+ *
*/
#include "ndn-content-store.hpp"
@@ -25,32 +25,31 @@
#include "ns3/log.h"
#include "ns3/packet.h"
-NS_LOG_COMPONENT_DEFINE ("ndn.cs.ContentStore");
+NS_LOG_COMPONENT_DEFINE("ndn.cs.ContentStore");
namespace ns3 {
namespace ndn {
-NS_OBJECT_ENSURE_REGISTERED (ContentStore);
+NS_OBJECT_ENSURE_REGISTERED(ContentStore);
TypeId
-ContentStore::GetTypeId (void)
+ContentStore::GetTypeId(void)
{
- static TypeId tid = TypeId ("ns3::ndn::ContentStore")
- .SetGroupName ("Ndn")
- .SetParent<Object> ()
+ static TypeId tid =
+ TypeId("ns3::ndn::ContentStore")
+ .SetGroupName("Ndn")
+ .SetParent<Object>()
- .AddTraceSource ("CacheHits", "Trace called every time there is a cache hit",
- MakeTraceSourceAccessor (&ContentStore::m_cacheHitsTrace))
+ .AddTraceSource("CacheHits", "Trace called every time there is a cache hit",
+ MakeTraceSourceAccessor(&ContentStore::m_cacheHitsTrace))
- .AddTraceSource ("CacheMisses", "Trace called every time there is a cache miss",
- MakeTraceSourceAccessor (&ContentStore::m_cacheMissesTrace))
- ;
+ .AddTraceSource("CacheMisses", "Trace called every time there is a cache miss",
+ MakeTraceSourceAccessor(&ContentStore::m_cacheMissesTrace));
return tid;
}
-
-ContentStore::~ContentStore ()
+ContentStore::~ContentStore()
{
}
@@ -58,31 +57,30 @@
//////////////////////////////////////////////////////////////////////
-Entry::Entry (Ptr<ContentStore> cs, Ptr<const Data> data)
- : m_cs (cs)
- , m_data (data)
+Entry::Entry(Ptr<ContentStore> cs, Ptr<const Data> data)
+ : m_cs(cs)
+ , m_data(data)
{
}
const Name&
-Entry::GetName () const
+Entry::GetName() const
{
- return m_data->GetName ();
+ return m_data->GetName();
}
Ptr<const Data>
-Entry::GetData () const
+Entry::GetData() const
{
return m_data;
}
Ptr<ContentStore>
-Entry::GetContentStore ()
+Entry::GetContentStore()
{
return m_cs;
}
-
} // namespace cs
} // namespace ndn
} // namespace ns3
diff --git a/model/cs/ndn-content-store.hpp b/model/cs/ndn-content-store.hpp
index ae7c059..23266c4 100644
--- a/model/cs/ndn-content-store.hpp
+++ b/model/cs/ndn-content-store.hpp
@@ -20,7 +20,7 @@
*/
#ifndef NDN_CONTENT_STORE_H
-#define NDN_CONTENT_STORE_H
+#define NDN_CONTENT_STORE_H
#include "ns3/object.h"
#include "ns3/ptr.h"
@@ -54,8 +54,7 @@
* @ingroup ndn-cs
* @brief NDN content store entry
*/
-class Entry : public SimpleRefCount<Entry>
-{
+class Entry : public SimpleRefCount<Entry> {
public:
/**
* \brief Construct content store entry
@@ -66,27 +65,27 @@
* The constructor will make a copy of the supplied packet and calls
* RemoveHeader and RemoveTail on the copy.
*/
- Entry (Ptr<ContentStore> cs, Ptr<const Data> data);
+ Entry(Ptr<ContentStore> cs, Ptr<const Data> data);
/**
* \brief Get prefix of the stored entry
* \returns prefix of the stored entry
*/
const Name&
- GetName () const;
+ GetName() const;
/**
* \brief Get Data of the stored entry
* \returns Data of the stored entry
*/
Ptr<const Data>
- GetData () const;
+ GetData() const;
/**
* @brief Get pointer to access store, to which this entry is added
*/
Ptr<ContentStore>
- GetContentStore ();
+ GetContentStore();
private:
Ptr<ContentStore> m_cs; ///< \brief content store to which entry is added
@@ -95,29 +94,26 @@
} // namespace cs
-
/**
* @ingroup ndn-cs
* \brief Base class for NDN content store
*
* Particular implementations should implement Lookup, Add, and Print methods
*/
-class ContentStore : public Object
-{
+class ContentStore : public Object {
public:
/**
* \brief Interface ID
*
* \return interface ID
*/
- static
- TypeId GetTypeId ();
+ static TypeId
+ GetTypeId();
/**
* @brief Virtual destructor
*/
- virtual
- ~ContentStore ();
+ virtual ~ContentStore();
/**
* \brief Find corresponding CS entry for the given interest
@@ -129,7 +125,7 @@
* used entries index, \see m_contentStore
*/
virtual Ptr<Data>
- Lookup (Ptr<const Interest> interest) = 0;
+ Lookup(Ptr<const Interest> interest) = 0;
/**
* \brief Add a new content to the content store.
@@ -140,7 +136,7 @@
* @returns true if an existing entry was updated, false otherwise
*/
virtual bool
- Add (Ptr<const Data> data) = 0;
+ Add(Ptr<const Data> data) = 0;
// /*
// * \brief Add a new content to the content store.
@@ -155,32 +151,30 @@
* \brief Print out content store entries
*/
virtual void
- Print (std::ostream &os) const = 0;
-
+ Print(std::ostream& os) const = 0;
/**
* @brief Get number of entries in content store
*/
virtual uint32_t
- GetSize () const = 0;
+ GetSize() const = 0;
/**
* @brief Return first element of content store (no order guaranteed)
*/
virtual Ptr<cs::Entry>
- Begin () = 0;
+ Begin() = 0;
/**
* @brief Return item next after last (no order guaranteed)
*/
virtual Ptr<cs::Entry>
- End () = 0;
+ End() = 0;
/**
* @brief Advance the iterator
*/
- virtual Ptr<cs::Entry>
- Next (Ptr<cs::Entry>) = 0;
+ virtual Ptr<cs::Entry> Next(Ptr<cs::Entry>) = 0;
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
@@ -190,29 +184,28 @@
* @brief Static call to cheat python bindings
*/
static inline Ptr<ContentStore>
- GetContentStore (Ptr<Object> node);
+ GetContentStore(Ptr<Object> node);
protected:
TracedCallback<Ptr<const Interest>,
- Ptr<const Data> > m_cacheHitsTrace; ///< @brief trace of cache hits
+ Ptr<const Data>> m_cacheHitsTrace; ///< @brief trace of cache hits
- TracedCallback<Ptr<const Interest> > m_cacheMissesTrace; ///< @brief trace of cache misses
+ TracedCallback<Ptr<const Interest>> m_cacheMissesTrace; ///< @brief trace of cache misses
};
inline std::ostream&
-operator<< (std::ostream &os, const ContentStore &cs)
+operator<<(std::ostream& os, const ContentStore& cs)
{
- cs.Print (os);
+ cs.Print(os);
return os;
}
inline Ptr<ContentStore>
-ContentStore::GetContentStore (Ptr<Object> node)
+ContentStore::GetContentStore(Ptr<Object> node)
{
- return node->GetObject<ContentStore> ();
+ return node->GetObject<ContentStore>();
}
-
} // namespace ndn
} // namespace ns3