diff --git a/PSync/detail/user-prefixes.cpp b/PSync/detail/user-prefixes.cpp index cd6b961..db4855b 100644 --- a/PSync/detail/user-prefixes.cpp +++ b/PSync/detail/user-prefixes.cpp @@ -17,8 +17,8 @@ * PSync, e.g., in COPYING.md file. If not, see . **/ -#include #include "PSync/detail/user-prefixes.hpp" +#include namespace psync { @@ -28,7 +28,7 @@ bool UserPrefixes::addUserNode(const ndn::Name& prefix) { if (!isUserNode(prefix)) { - m_prefixes[prefix] = 0; + prefixes[prefix] = 0; return true; } else { @@ -39,9 +39,9 @@ UserPrefixes::addUserNode(const ndn::Name& prefix) void UserPrefixes::removeUserNode(const ndn::Name& prefix) { - auto it = m_prefixes.find(prefix); - if (it != m_prefixes.end()) { - m_prefixes.erase(it); + auto it = prefixes.find(prefix); + if (it != prefixes.end()) { + prefixes.erase(it); } } @@ -52,12 +52,12 @@ UserPrefixes::updateSeqNo oldSeqNo = 0; NDN_LOG_DEBUG("UpdateSeq: " << prefix << " " << seqNo); - auto it = m_prefixes.find(prefix); - if (it != m_prefixes.end()) { + auto it = prefixes.find(prefix); + if (it != prefixes.end()) { oldSeqNo = it->second; } else { - NDN_LOG_WARN("Prefix not found in m_prefixes"); + NDN_LOG_WARN("Prefix not found in prefixes"); return false; } diff --git a/PSync/detail/user-prefixes.hpp b/PSync/detail/user-prefixes.hpp index 23e13ad..9ab8596 100644 --- a/PSync/detail/user-prefixes.hpp +++ b/PSync/detail/user-prefixes.hpp @@ -26,7 +26,7 @@ namespace psync { /** - * @brief UserPrefixes holds the m_prefixes map from prefix to sequence number, + * @brief UserPrefixes holds the prefixes map from prefix to sequence number, * used by PartialProducer and FullProducer. * * Contains code common to both @@ -35,15 +35,15 @@ class UserPrefixes { public: /** - * @brief Check if the prefix is in m_prefixes. + * @brief Check if the prefix is in prefixes. * * @param prefix The prefix to check. - * @return True if the prefix is in m_prefixes. + * @return True if the prefix is in prefixes. */ bool isUserNode(const ndn::Name& prefix) const { - return m_prefixes.find(prefix) != m_prefixes.end(); + return prefixes.find(prefix) != prefixes.end(); } /** @@ -54,8 +54,8 @@ class UserPrefixes ndn::optional getSeqNo(const ndn::Name& prefix) const { - auto it = m_prefixes.find(prefix); - if (it == m_prefixes.end()) { + auto it = prefixes.find(prefix); + if (it == prefixes.end()) { return ndn::nullopt; } return it->second; @@ -64,18 +64,18 @@ class UserPrefixes /** * @brief Adds a user node for synchronization * - * Initializes m_prefixes[prefix] to zero + * Initializes prefixes[prefix] to zero * * @param prefix the user node to be added * @return true if the prefix was added, false if the prefix was already in - * m_prefixes. + * prefixes. */ bool addUserNode(const ndn::Name& prefix); /** * @brief Remove the user node from synchronization. If the prefix is not in - * m_prefixes, then do nothing. + * prefixes, then do nothing. * * The caller should first check isUserNode(prefix) and erase the prefix from * the IBLT and other maps if needed. @@ -86,7 +86,7 @@ class UserPrefixes removeUserNode(const ndn::Name& prefix); /** - * @brief Update m_prefixes with the given prefix and sequence number. This + * @brief Update prefixes with the given prefix and sequence number. This * does not update the IBLT. This logs a message for the update. * * Whoever calls this needs to make sure that isUserNode(prefix) is true. @@ -97,7 +97,7 @@ class UserPrefixes * prefix. If this method returns true and oldSeqNo is not zero, the caller * can remove the old prefix from the IBLT. * @return True if the sequence number was updated, false if the prefix was - * not in m_prefixes, or if the seqNo is less than or equal to the old + * not in prefixes, or if the seqNo is less than or equal to the old * sequence number. If this returns false, the caller should not update the * IBLT. */ @@ -105,7 +105,7 @@ class UserPrefixes updateSeqNo(const ndn::Name& prefix, uint64_t seqNo, uint64_t& oldSeqNo); // prefix and sequence number - std::map m_prefixes; + std::map prefixes; }; } // namespace psync diff --git a/PSync/full-producer-arbitrary.cpp b/PSync/full-producer-arbitrary.cpp index 3466e31..ca1d2d0 100644 --- a/PSync/full-producer-arbitrary.cpp +++ b/PSync/full-producer-arbitrary.cpp @@ -102,8 +102,8 @@ FullProducerArbitrary::sendSyncInterest() m_outstandingInterestName = syncInterestName; m_scheduledSyncInterestId = - m_scheduler.scheduleEvent(m_syncInterestLifetime / 2 + ndn::time::milliseconds(m_jitter(m_rng)), - [this] { sendSyncInterest(); }); + m_scheduler.schedule(m_syncInterestLifetime / 2 + ndn::time::milliseconds(m_jitter(m_rng)), + [this] { sendSyncInterest(); }); ndn::Interest syncInterest(syncInterestName); @@ -201,7 +201,7 @@ FullProducerArbitrary::onSyncInterest(const ndn::Name& prefixName, const ndn::In if (m_name2hash.find(name) != m_name2hash.end()) { if (!m_onShouldAddToSyncDataCallback || m_onShouldAddToSyncDataCallback(prefix.toUri(), negative)) { - state.addContent(name); + state.addContent(name); } } } @@ -216,7 +216,7 @@ FullProducerArbitrary::onSyncInterest(const ndn::Name& prefixName, const ndn::In } auto& entry = m_pendingEntries.emplace(interestName, PendingEntryInfoFull{iblt, {}}).first->second; - entry.expirationEvent = m_scheduler.scheduleEvent(interest.getInterestLifetime(), + entry.expirationEvent = m_scheduler.schedule(interest.getInterestLifetime(), [this, interest] { NDN_LOG_TRACE("Erase Pending Interest " << interest.getNonce()); m_pendingEntries.erase(interest.getName()); diff --git a/PSync/full-producer-arbitrary.hpp b/PSync/full-producer-arbitrary.hpp index 4843295..0956dc4 100644 --- a/PSync/full-producer-arbitrary.hpp +++ b/PSync/full-producer-arbitrary.hpp @@ -41,7 +41,7 @@ namespace psync { struct PendingEntryInfoFull { IBLT iblt; - ndn::util::scheduler::ScopedEventId expirationEvent; + ndn::scheduler::ScopedEventId expirationEvent; }; typedef std::function&)> ArbitraryUpdateCallback; @@ -116,7 +116,7 @@ class FullProducerArbitrary : public ProducerBase void sendSyncInterest(); -PUBLIC_WITH_TESTS_ELSE_PRIVATE: +PSYNC_PUBLIC_WITH_TESTS_ELSE_PRIVATE: /** * @brief Process sync interest from other parties * @@ -177,7 +177,7 @@ class FullProducerArbitrary : public ProducerBase void satisfyPendingInterests(); -PUBLIC_WITH_TESTS_ELSE_PRIVATE: +PSYNC_PUBLIC_WITH_TESTS_ELSE_PRIVATE: /** * @brief Delete pending sync interests that match given name */ @@ -189,7 +189,7 @@ class FullProducerArbitrary : public ProducerBase ndn::KeyChain m_keyChain; ndn::Scheduler m_scheduler; -PUBLIC_WITH_TESTS_ELSE_PROTECTED: +PSYNC_PUBLIC_WITH_TESTS_ELSE_PROTECTED: SegmentPublisher m_segmentPublisher; std::map m_pendingEntries; @@ -197,7 +197,7 @@ class FullProducerArbitrary : public ProducerBase ArbitraryUpdateCallback m_onArbitraryUpdateCallback; ShouldAddToSyncDataCallback m_onShouldAddToSyncDataCallback; CanAddName m_onCanAddName; - ndn::util::scheduler::ScopedEventId m_scheduledSyncInterestId; + ndn::scheduler::ScopedEventId m_scheduledSyncInterestId; std::uniform_int_distribution<> m_jitter; ndn::Name m_outstandingInterestName; ndn::ScopedRegisteredPrefixHandle m_registeredPrefix; diff --git a/PSync/full-producer.cpp b/PSync/full-producer.cpp index 22f852a..6c5a626 100644 --- a/PSync/full-producer.cpp +++ b/PSync/full-producer.cpp @@ -50,9 +50,9 @@ FullProducer::FullProducer(const size_t expectedNumEntries, ndn::Name prefix = name.getPrefix(-1); uint64_t seq = name.get(-1).toNumber(); - if (m_prefixes.m_prefixes.find(prefix) == m_prefixes.m_prefixes.end() || - m_prefixes.m_prefixes[prefix] < seq) { - uint64_t oldSeq = m_prefixes.m_prefixes[prefix]; + if (m_prefixes.prefixes.find(prefix) == m_prefixes.prefixes.end() || + m_prefixes.prefixes[prefix] < seq) { + uint64_t oldSeq = m_prefixes.prefixes[prefix]; if (oldSeq != 0) { m_producerArbitrary.removeName(ndn::Name(prefix).appendNumber(oldSeq)); } @@ -72,7 +72,7 @@ FullProducer::publishName(const ndn::Name& prefix, ndn::optional seq) return; } - uint64_t newSeq = seq.value_or(m_prefixes.m_prefixes[prefix] + 1); + uint64_t newSeq = seq.value_or(m_prefixes.prefixes[prefix] + 1); NDN_LOG_INFO("Publish: " << prefix << "/" << newSeq); @@ -99,7 +99,7 @@ bool FullProducer::isNotFutureHash(const ndn::Name& prefix, const std::set& negative) { uint32_t nextHash = murmurHash3(N_HASHCHECK, - ndn::Name(prefix).appendNumber(m_prefixes.m_prefixes[prefix] + 1).toUri()); + ndn::Name(prefix).appendNumber(m_prefixes.prefixes[prefix] + 1).toUri()); for (const auto& nHash : negative) { if (nHash == nextHash) { return false; @@ -120,8 +120,8 @@ FullProducer::arbitraryUpdateCallBack(const std::vector& names) NDN_LOG_INFO("Updates: " << prefix << " " << seq); - updates.push_back(MissingDataInfo{prefix, m_prefixes.m_prefixes[prefix] + 1, seq}); - m_prefixes.m_prefixes[prefix] = seq; + updates.push_back(MissingDataInfo{prefix, m_prefixes.prefixes[prefix] + 1, seq}); + m_prefixes.prefixes[prefix] = seq; } m_onUpdateCallback(updates); diff --git a/PSync/full-producer.hpp b/PSync/full-producer.hpp index 7f1a924..6bc56b9 100644 --- a/PSync/full-producer.hpp +++ b/PSync/full-producer.hpp @@ -112,7 +112,7 @@ class FullProducer removeUserNode(const ndn::Name& prefix) { if (m_prefixes.isUserNode(prefix)) { - uint64_t seqNo = m_prefixes.m_prefixes[prefix]; + uint64_t seqNo = m_prefixes.prefixes[prefix]; m_prefixes.removeUserNode(prefix); m_producerArbitrary.removeName(ndn::Name(prefix).appendNumber(seqNo)); } @@ -142,7 +142,7 @@ class FullProducer bool isNotFutureHash(const ndn::Name& prefix, const std::set& negative); -PUBLIC_WITH_TESTS_ELSE_PROTECTED: +PSYNC_PUBLIC_WITH_TESTS_ELSE_PROTECTED: void updateSeqNo(const ndn::Name& prefix, uint64_t seq); @@ -150,7 +150,7 @@ class FullProducer void arbitraryUpdateCallBack(const std::vector& names); -PUBLIC_WITH_TESTS_ELSE_PROTECTED: +PSYNC_PUBLIC_WITH_TESTS_ELSE_PROTECTED: FullProducerArbitrary m_producerArbitrary; UpdateCallback m_onUpdateCallback; diff --git a/PSync/partial-producer.cpp b/PSync/partial-producer.cpp index eb7c2cc..5c544d0 100644 --- a/PSync/partial-producer.cpp +++ b/PSync/partial-producer.cpp @@ -60,7 +60,7 @@ PartialProducer::publishName(const ndn::Name& prefix, ndn::optional se return; } - uint64_t newSeq = seq.value_or(m_prefixes.m_prefixes[prefix] + 1); + uint64_t newSeq = seq.value_or(m_prefixes.prefixes[prefix] + 1); NDN_LOG_INFO("Publish: " << prefix << "/" << newSeq); @@ -102,7 +102,7 @@ PartialProducer::onHelloInterest(const ndn::Name& prefix, const ndn::Interest& i State state; - for (const auto& prefix : m_prefixes.m_prefixes) { + for (const auto& prefix : m_prefixes.prefixes) { state.addContent(ndn::Name(prefix.first).appendNumber(prefix.second)); } NDN_LOG_DEBUG("sending content p: " << state); @@ -174,7 +174,7 @@ PartialProducer::onSyncInterest(const ndn::Name& prefix, const ndn::Interest& in std::set positive; std::set negative; - NDN_LOG_TRACE("Number elements in IBF: " << m_prefixes.m_prefixes.size()); + NDN_LOG_TRACE("Number elements in IBF: " << m_prefixes.prefixes.size()); bool peel = diff.listEntries(positive, negative); @@ -197,7 +197,7 @@ PartialProducer::onSyncInterest(const ndn::Name& prefix, const ndn::Interest& in if (bf.contains(prefix.toUri())) { // generate data state.addContent(name); - NDN_LOG_DEBUG("Content: " << prefix << " " << std::to_string(m_prefixes.m_prefixes[prefix])); + NDN_LOG_DEBUG("Content: " << prefix << " " << std::to_string(m_prefixes.prefixes[prefix])); } } @@ -237,7 +237,7 @@ PartialProducer::satisfyPendingSyncInterests(const ndn::Name& prefix) { NDN_LOG_TRACE("Result of listEntries on the difference: " << peel); - NDN_LOG_TRACE("Number elements in IBF: " << m_prefixes.m_prefixes.size()); + NDN_LOG_TRACE("Number elements in IBF: " << m_prefixes.prefixes.size()); NDN_LOG_TRACE("m_threshold: " << m_threshold << " Total: " << positive.size() + negative.size()); if (!peel) { @@ -249,8 +249,8 @@ PartialProducer::satisfyPendingSyncInterests(const ndn::Name& prefix) { State state; if (entry.bf.contains(prefix.toUri()) || positive.size() + negative.size() >= m_threshold) { if (entry.bf.contains(prefix.toUri())) { - state.addContent(ndn::Name(prefix).appendNumber(m_prefixes.m_prefixes[prefix])); - NDN_LOG_DEBUG("sending sync content " << prefix << " " << std::to_string(m_prefixes.m_prefixes[prefix])); + state.addContent(ndn::Name(prefix).appendNumber(m_prefixes.prefixes[prefix])); + NDN_LOG_DEBUG("sending sync content " << prefix << " " << std::to_string(m_prefixes.prefixes[prefix])); } else { NDN_LOG_DEBUG("Sending with empty content to send latest IBF to consumer"); diff --git a/PSync/partial-producer.hpp b/PSync/partial-producer.hpp index 4076495..e7ff487 100644 --- a/PSync/partial-producer.hpp +++ b/PSync/partial-producer.hpp @@ -113,7 +113,7 @@ class PartialProducer : public ProducerBase removeUserNode(const ndn::Name& prefix) { if (m_prefixes.isUserNode(prefix)) { - uint64_t seqNo = m_prefixes.m_prefixes[prefix]; + uint64_t seqNo = m_prefixes.prefixes[prefix]; m_prefixes.removeUserNode(prefix); removeFromIBF(ndn::Name(prefix).appendNumber(seqNo)); } diff --git a/tests/bk-test-bloom-filter.cpp.disable b/tests/bk-test-bloom-filter.cpp.disable new file mode 100644 index 0000000..eec8a7c --- /dev/null +++ b/tests/bk-test-bloom-filter.cpp.disable @@ -0,0 +1,100 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2014-2019, The University of Memphis + * + * This file is part of PSync. + * See AUTHORS.md for complete list of PSync authors and contributors. + * + * PSync is free software: you can redistribute it and/or modify it under the terms + * of the GNU Lesser General Public License as published by the Free Software Foundation, + * either version 3 of the License, or (at your option) any later version. + * + * PSync 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with + * PSync, e.g., in COPYING.md file. If not, see . + **/ + +#include "PSync/detail/bloom-filter.hpp" + +#include +#include + +#include + +#include +#include +#include +#include + +namespace psync { + +using namespace ndn; +namespace bio = boost::iostreams; + +BOOST_AUTO_TEST_SUITE(TestBloomFilter) + +BOOST_AUTO_TEST_CASE(Basic) +{ + BloomFilter bf(100, 0.001); + + std::string insertName("/memphis"); + bf.insert(insertName); + BOOST_CHECK(bf.contains(insertName)); +} + +BOOST_AUTO_TEST_CASE(NameAppendAndExtract) +{ + Name bfName("/test"); + BloomFilter bf(100, 0.001); + bf.insert("/memphis"); + + bf.appendToName(bfName); + + BloomFilter bfFromName(100, 0.001, bfName.get(-1)); + + BOOST_CHECK_EQUAL(bfName.get(1).toNumber(), 100); + BOOST_CHECK_EQUAL(bfName.get(2).toNumber(), 1); + BOOST_CHECK_EQUAL(bf, bfFromName); + + BOOST_CHECK_THROW(BloomFilter inCompatibleBf(200, 0.001, bfName.get(-1)), std::runtime_error); +} + +BOOST_AUTO_TEST_CASE(SizeTest) +{ + BloomFilter bf(1000, 0.01); + Name bfName("/test"); + + for(int i = 0; i < 1000; ++i) { + bf.insert("/memphis" + std::to_string(i)); + } + bf.appendToName(bfName); + std::cout << bfName << std::endl; + + std::cout << "Size of name: " << bfName.toUri() << std::endl; + std::cout << "Size of name: " << bfName.toUri().size() << std::endl; + // std::cout << "Size of name: " << bfName.wireEncode().size() << std::endl; + + std::vector table; + for (const auto i : bf.table()) { + table.push_back(i); + } + bio::filtering_streambuf in; + in.push(bio::zlib_compressor()); + in.push(bio::array_source(table.data(), table.size())); + + std::stringstream sstream; + bio::copy(in, sstream); + + Name bfName2("/test"); + std::string compressedIBF = sstream.str(); + bfName2.append(compressedIBF.begin(), compressedIBF.end()); + std::cout << "Size of compressed name: " << bfName2 << std::endl; + std::cout << "Size of compressed name: " << bfName2.toUri().size() << std::endl; +} + +BOOST_AUTO_TEST_SUITE_END() + +} // namespace psync diff --git a/tests/bk-test-iblt.cpp.disable b/tests/bk-test-iblt.cpp.disable new file mode 100644 index 0000000..c377978 --- /dev/null +++ b/tests/bk-test-iblt.cpp.disable @@ -0,0 +1,247 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2014-2019, The University of Memphis + * + * This file is part of PSync. + * See AUTHORS.md for complete list of PSync authors and contributors. + * + * PSync is free software: you can redistribute it and/or modify it under the terms + * of the GNU Lesser General Public License as published by the Free Software Foundation, + * either version 3 of the License, or (at your option) any later version. + * + * PSync 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with + * PSync, e.g., in COPYING.md file. If not, see . + **/ + +#include "PSync/detail/iblt.hpp" +#include "PSync/detail/util.hpp" + +#include +#include +#include + +#include + +namespace psync { + +using namespace ndn; + +BOOST_AUTO_TEST_SUITE(TestIBLT) + +BOOST_AUTO_TEST_CASE(Equal) +{ + int size = 10; + + IBLT iblt1(size); + IBLT iblt2(size); + BOOST_CHECK_EQUAL(iblt1, iblt2); + + std::string prefix = Name("/test/memphis").appendNumber(1).toUri(); + uint32_t newHash = murmurHash3(11, prefix); + iblt1.insert(newHash); + iblt2.insert(newHash); + + BOOST_CHECK_EQUAL(iblt1, iblt2); + + Name ibfName1("sync"), ibfName2("sync"); + iblt1.appendToName(ibfName1); + iblt2.appendToName(ibfName2); + BOOST_CHECK_EQUAL(ibfName1, ibfName2); +} + +BOOST_AUTO_TEST_CASE(NameAppendAndExtract) +{ + int size = 10; + + IBLT iblt(size); + std::string prefix = Name("/test/memphis").appendNumber(1).toUri(); + uint32_t newHash = murmurHash3(11, prefix); + iblt.insert(newHash); + + Name ibltName("sync"); + iblt.appendToName(ibltName); + + IBLT rcvd(size); + rcvd.initialize(ibltName.get(-1)); + + BOOST_CHECK_EQUAL(iblt, rcvd); + + IBLT rcvdDiffSize(20); + BOOST_CHECK_THROW(rcvdDiffSize.initialize(ibltName.get(-1)), std::runtime_error); +} + +BOOST_AUTO_TEST_CASE(CopyInsertErase) +{ + int size = 10; + + IBLT iblt1(size); + + std::string prefix = Name("/test/memphis").appendNumber(1).toUri(); + uint32_t hash1 = murmurHash3(11, prefix); + iblt1.insert(hash1); + + IBLT iblt2(iblt1); + iblt2.erase(hash1); + prefix = Name("/test/memphis").appendNumber(2).toUri(); + uint32_t hash3 = murmurHash3(11, prefix); + iblt2.insert(hash3); + + iblt1.erase(hash1); + prefix = Name("/test/memphis").appendNumber(5).toUri(); + uint32_t hash5 = murmurHash3(11, prefix); + iblt1.insert(hash5); + + iblt2.erase(hash3); + iblt2.insert(hash5); + + BOOST_CHECK_EQUAL(iblt1, iblt2); +} + +BOOST_AUTO_TEST_CASE(HigherSeqTest) +{ + // The case where we can't recognize if the rcvd IBF has higher sequence number + // Relevant to full sync case + int size = 10; + + IBLT ownIBF(size); + IBLT rcvdIBF(size); + + std::string prefix = Name("/test/memphis").appendNumber(3).toUri(); + uint32_t hash1 = murmurHash3(11, prefix); + ownIBF.insert(hash1); + + std::string prefix2 = Name("/test/memphis").appendNumber(4).toUri(); + uint32_t hash2 = murmurHash3(11, prefix2); + rcvdIBF.insert(hash2); + + IBLT diff = ownIBF - rcvdIBF; + std::set positive; + std::set negative; + + BOOST_CHECK(diff.listEntries(positive, negative)); + BOOST_CHECK(*positive.begin() == hash1); + BOOST_CHECK(*negative.begin() == hash2); +} + +BOOST_AUTO_TEST_CASE(Difference) +{ + int size = 10; + + IBLT ownIBF(size); + + IBLT rcvdIBF = ownIBF; + + IBLT diff = ownIBF - rcvdIBF; + + std::set positive; // non-empty Positive means we have some elements that the others don't + std::set negative; + + BOOST_CHECK(diff.listEntries(positive, negative)); + BOOST_CHECK_EQUAL(positive.size(), 0); + BOOST_CHECK_EQUAL(negative.size(), 0); + + std::string prefix = Name("/test/memphis").appendNumber(1).toUri(); + uint32_t newHash = murmurHash3(11, prefix); + ownIBF.insert(newHash); + + diff = ownIBF - rcvdIBF; + BOOST_CHECK(diff.listEntries(positive, negative)); + BOOST_CHECK_EQUAL(positive.size(), 1); + BOOST_CHECK_EQUAL(negative.size(), 0); + + prefix = Name("/test/csu").appendNumber(1).toUri(); + newHash = murmurHash3(11, prefix); + rcvdIBF.insert(newHash); + + diff = ownIBF - rcvdIBF; + BOOST_CHECK(diff.listEntries(positive, negative)); + BOOST_CHECK_EQUAL(positive.size(), 1); + BOOST_CHECK_EQUAL(negative.size(), 1); +} + +BOOST_AUTO_TEST_CASE(DifferenceBwOversizedIBFs) +{ + // Insert 50 elements into IBF of size 10 + // Check that we can still list the difference + // even though we can't list the IBFs itself + + int size = 10; + + IBLT ownIBF(size); + + for (int i = 0; i < 50; i++) { + std::string prefix = Name("/test/memphis" + std::to_string(i)).appendNumber(1).toUri(); + uint32_t newHash = murmurHash3(11, prefix); + ownIBF.insert(newHash); + } + + IBLT rcvdIBF = ownIBF; + + std::string prefix = Name("/test/ucla").appendNumber(1).toUri(); + uint32_t newHash = murmurHash3(11, prefix); + ownIBF.insert(newHash); + + IBLT diff = ownIBF - rcvdIBF; + + std::set positive; + std::set negative; + BOOST_CHECK(diff.listEntries(positive, negative)); + BOOST_CHECK_EQUAL(positive.size(), 1); + BOOST_CHECK_EQUAL(*positive.begin(), newHash); + BOOST_CHECK_EQUAL(negative.size(), 0); + + BOOST_CHECK(!ownIBF.listEntries(positive, negative)); + BOOST_CHECK(!rcvdIBF.listEntries(positive, negative)); +} + + +BOOST_AUTO_TEST_CASE(FindSameElements) +{ + int size = 10; + + IBLT ownIBF(size); + std::cout << "A: " << murmurHash3(11, std::string("A")) << std::endl; + std::cout << "B: " << murmurHash3(11, std::string("B")) << std::endl; + std::cout << "C: " << murmurHash3(11, std::string("C")) << std::endl; + ownIBF.insert(murmurHash3(11, std::string("A"))); + ownIBF.insert(murmurHash3(11, std::string("B"))); + ownIBF.insert(murmurHash3(11, std::string("C"))); + + IBLT rcvdIBF(size); + rcvdIBF.insert(murmurHash3(11, std::string("C"))); + rcvdIBF.insert(murmurHash3(11, std::string("D"))); + rcvdIBF.insert(murmurHash3(11, std::string("E"))); + std::cout << "D: " << murmurHash3(11, std::string("D")) << std::endl; + std::cout << "E: " << murmurHash3(11, std::string("E")) << std::endl; + + IBLT diff = rcvdIBF - (ownIBF - rcvdIBF); + + std::set positive; + std::set negative; + + diff.listEntries(positive, negative); + + for (const auto& p : positive) { + std::cout << " positive: " << p << std::endl; + } + + for (const auto& n : negative) { + std::cout << " negative: " << n << std::endl; + } + + // IBLT diff2 = ownIBF - ; +} + +BOOST_AUTO_TEST_CASE(IBFSize) +{ + int size = 10; + +} + +BOOST_AUTO_TEST_SUITE_END() + +} // namespace psync diff --git a/tests/test-partial-sync.cpp b/tests/test-partial-sync.cpp index abd28a6..76618ef 100644 --- a/tests/test-partial-sync.cpp +++ b/tests/test-partial-sync.cpp @@ -83,7 +83,7 @@ class PartialSyncFixture : public tests::UnitTestTimeFixture for (const auto& update : updates) { BOOST_CHECK(consumers[id]->isSubscribed(update.prefix)); BOOST_CHECK_EQUAL(oldSeqMap.at(update.prefix) + 1, update.lowSeq); - BOOST_CHECK_EQUAL(producer->m_prefixes.m_prefixes.at(update.prefix), update.highSeq); + BOOST_CHECK_EQUAL(producer->m_prefixes.prefixes.at(update.prefix), update.highSeq); BOOST_CHECK_EQUAL(consumers[id]->getSeqNo(update.prefix).value(), update.highSeq); } }, 40, 0.001); @@ -102,7 +102,7 @@ class PartialSyncFixture : public tests::UnitTestTimeFixture bool checkSubList(const vector& availableSubs) { - for (const auto& prefix : producer->m_prefixes.m_prefixes ) { + for (const auto& prefix : producer->m_prefixes.prefixes ) { if (std::find(availableSubs.begin(), availableSubs.end(), prefix.first) == availableSubs.end()) { return false; } @@ -122,7 +122,7 @@ class PartialSyncFixture : public tests::UnitTestTimeFixture void publishUpdateFor(const std::string& prefix) { - oldSeqMap = producer->m_prefixes.m_prefixes; + oldSeqMap = producer->m_prefixes.prefixes; producer->publishName(prefix); advanceClocks(ndn::time::milliseconds(10)); } @@ -130,7 +130,7 @@ class PartialSyncFixture : public tests::UnitTestTimeFixture void updateSeqFor(const std::string& prefix, uint64_t seq) { - oldSeqMap = producer->m_prefixes.m_prefixes; + oldSeqMap = producer->m_prefixes.prefixes; producer->updateSeqNo(prefix, seq); } @@ -326,7 +326,7 @@ BOOST_AUTO_TEST_CASE(ApplicationNack) publishUpdateFor("testUser-2"); BOOST_CHECK_EQUAL(numSyncDataRcvd, 1); - oldSeqMap = producer->m_prefixes.m_prefixes; + oldSeqMap = producer->m_prefixes.prefixes; for (int i = 0; i < 50; i++) { ndn::Name prefix("testUser-" + to_string(i)); producer->updateSeqNo(prefix, producer->getSeqNo(prefix).value() + 1); @@ -402,7 +402,7 @@ BOOST_AUTO_TEST_CASE(SegmentedSync) syncInterestName.appendVersion(); syncInterestName.appendSegment(1); - oldSeqMap = producer->m_prefixes.m_prefixes; + oldSeqMap = producer->m_prefixes.prefixes; for (int i = 1; i < 10; i++) { producer->updateSeqNo(longNameToExceedDataSize.toUri() + "-" + to_string(i), 1); } @@ -430,4 +430,4 @@ BOOST_AUTO_TEST_CASE(SegmentedSync) BOOST_AUTO_TEST_SUITE_END() -} // namespace psync \ No newline at end of file +} // namespace psync