Skip to content

Commit

Permalink
Slim down common.hpp
Browse files Browse the repository at this point in the history
Change-Id: Ic9843a1b9ffc5b5b1fa6062c8250ba28c6aaa898
  • Loading branch information
Pesa committed Jan 26, 2024
1 parent 11fc3eb commit 5748e82
Show file tree
Hide file tree
Showing 55 changed files with 252 additions and 176 deletions.
23 changes: 2 additions & 21 deletions core/common.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2022, Regents of the University of California,
* Copyright (c) 2014-2024, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand Down Expand Up @@ -40,42 +40,23 @@

#include <cstddef>
#include <cstdint>
#include <functional>
#include <iostream>
#include <limits>
#include <iosfwd>
#include <memory>
#include <optional>
#include <stdexcept>
#include <string>
#include <string_view>
#include <utility>
#include <vector>

#include <boost/assert.hpp>
#include <boost/core/noncopyable.hpp>
#include <boost/lexical_cast.hpp>

#include <ndn-cxx/data.hpp>
#include <ndn-cxx/face.hpp>
#include <ndn-cxx/interest.hpp>
#include <ndn-cxx/name.hpp>
#include <ndn-cxx/security/key-chain.hpp>
#include <ndn-cxx/util/backports.hpp>
#include <ndn-cxx/util/exception.hpp>
#include <ndn-cxx/util/scheduler.hpp>
#include <ndn-cxx/util/time.hpp>

namespace ndn {

using std::shared_ptr;
using std::unique_ptr;
using std::make_shared;
using std::make_unique;

using std::size_t;

using boost::noncopyable;

} // namespace ndn

#define FORWARD_TO_MEM_FN(func) \
Expand Down
3 changes: 2 additions & 1 deletion core/program-options-ext.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2022, Regents of the University of California,
* Copyright (c) 2014-2024, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand Down Expand Up @@ -28,6 +28,7 @@

#include <ndn-cxx/name.hpp>
#include <boost/program_options/value_semantic.hpp>
#include <vector>

namespace ndn {

Expand Down
4 changes: 1 addition & 3 deletions core/version.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2022, Arizona Board of Regents.
* Copyright (c) 2014-2024, Arizona Board of Regents.
*
* This file is part of ndn-tools (Named Data Networking Essential Tools).
* See AUTHORS.md for complete list of ndn-tools authors and contributors.
Expand All @@ -20,8 +20,6 @@
#ifndef NDN_TOOLS_CORE_VERSION_HPP
#define NDN_TOOLS_CORE_VERSION_HPP

#include "core/common.hpp"

namespace ndn::tools {

/**
Expand Down
8 changes: 4 additions & 4 deletions tests/chunks/consumer.t.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2016-2023, Regents of the University of California,
* Copyright (c) 2016-2024, Regents of the University of California,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University.
*
Expand Down Expand Up @@ -99,7 +99,7 @@ BOOST_AUTO_TEST_CASE(OutOfOrderData)
Consumer cons(security::getAcceptAllValidator(), output);

auto interest = makeInterest(name, true);
std::vector<shared_ptr<Data>> dataStore;
std::vector<std::shared_ptr<Data>> dataStore;

for (size_t i = 0; i < testStrings.size(); ++i) {
auto data = makeData(Name(name).appendVersion(1).appendSegment(i));
Expand Down Expand Up @@ -153,8 +153,8 @@ BOOST_FIXTURE_TEST_CASE(RunBasic, IoFixture)
Consumer consumer(security::getAcceptAllValidator());

Name prefix = Name("/ndn/chunks/test").appendVersion(1);
auto discover = make_unique<DiscoverVersion>(face, prefix, options);
auto pipeline = make_unique<PipelineInterestsDummy>(face, options);
auto discover = std::make_unique<DiscoverVersion>(face, prefix, options);
auto pipeline = std::make_unique<PipelineInterestsDummy>(face, options);
auto pipelinePtr = pipeline.get();

BOOST_CHECK_EQUAL(pipelinePtr->isPipelineRunning, false);
Expand Down
6 changes: 3 additions & 3 deletions tests/chunks/discover-version.t.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2016-2023, Regents of the University of California,
* Copyright (c) 2016-2024, Regents of the University of California,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University.
*
Expand Down Expand Up @@ -42,7 +42,7 @@ class DiscoverVersionFixture : public IoFixture, public KeyChainFixture
void
run(const Name& prefix)
{
discover = make_unique<DiscoverVersion>(face, prefix, opt);
discover = std::make_unique<DiscoverVersion>(face, prefix, opt);
discover->onDiscoverySuccess.connect([this] (const Name& versionedName) {
isDiscoveryFinished = true;
discoveredName = versionedName;
Expand All @@ -62,7 +62,7 @@ class DiscoverVersionFixture : public IoFixture, public KeyChainFixture
const uint64_t version = 1449227841747;
DummyClientFace face{m_io};
Options opt;
unique_ptr<DiscoverVersion> discover;
std::unique_ptr<DiscoverVersion> discover;
std::optional<Name> discoveredName;
std::optional<uint64_t> discoveredVersion;
bool isDiscoveryFinished = false;
Expand Down
12 changes: 7 additions & 5 deletions tests/chunks/pipeline-interests-aimd.t.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2016-2022, Regents of the University of California,
* Copyright (c) 2016-2024, Regents of the University of California,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University.
*
Expand Down Expand Up @@ -29,6 +29,8 @@

#include "pipeline-interests-fixture.hpp"

#include <cmath>

namespace ndn::chunks::tests {

using namespace ndn::tests;
Expand All @@ -45,16 +47,16 @@ class PipelineInterestAimdFixture : public PipelineInterestsFixture
void
createPipeline()
{
auto pline = make_unique<PipelineInterestsAimd>(face, rttEstimator, opt);
auto pline = std::make_unique<PipelineInterestsAimd>(face, rttEstimator, opt);
pipeline = pline.get();
setPipeline(std::move(pline));
}

private:
static shared_ptr<RttEstimatorWithStats::Options>
static std::shared_ptr<RttEstimatorWithStats::Options>
makeRttEstimatorOptions()
{
auto rttOptions = make_shared<RttEstimatorWithStats::Options>();
auto rttOptions = std::make_shared<RttEstimatorWithStats::Options>();
rttOptions->alpha = 0.125;
rttOptions->beta = 0.25;
rttOptions->k = 4;
Expand Down Expand Up @@ -118,7 +120,7 @@ BOOST_AUTO_TEST_CASE(CongestionAvoidance)
for (uint64_t i = pipeline->m_ssthresh; i < nDataSegments - 1; ++i) { // congestion avoidance
face.receive(*makeDataWithSegment(i));
advanceClocks(time::nanoseconds(1));
BOOST_CHECK_CLOSE(pipeline->m_cwnd - preCwnd, opt.aiStep / floor(preCwnd), MARGIN);
BOOST_CHECK_CLOSE(pipeline->m_cwnd - preCwnd, opt.aiStep / std::floor(preCwnd), MARGIN);
preCwnd = pipeline->m_cwnd;
}

Expand Down
8 changes: 4 additions & 4 deletions tests/chunks/pipeline-interests-cubic.t.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2016-2022, Regents of the University of California,
* Copyright (c) 2016-2024, Regents of the University of California,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University.
*
Expand Down Expand Up @@ -45,16 +45,16 @@ class PipelineInterestCubicFixture : public PipelineInterestsFixture
void
createPipeline()
{
auto pline = make_unique<PipelineInterestsCubic>(face, rttEstimator, opt);
auto pline = std::make_unique<PipelineInterestsCubic>(face, rttEstimator, opt);
pipeline = pline.get();
setPipeline(std::move(pline));
}

private:
static shared_ptr<RttEstimatorWithStats::Options>
static std::shared_ptr<RttEstimatorWithStats::Options>
makeRttEstimatorOptions()
{
auto rttOptions = make_shared<RttEstimatorWithStats::Options>();
auto rttOptions = std::make_shared<RttEstimatorWithStats::Options>();
rttOptions->alpha = 0.125;
rttOptions->beta = 0.25;
rttOptions->k = 8;
Expand Down
14 changes: 8 additions & 6 deletions tests/chunks/pipeline-interests-fixed.t.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2016-2022, Regents of the University of California,
* Copyright (c) 2016-2024, Regents of the University of California,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University.
*
Expand Down Expand Up @@ -29,6 +29,8 @@

#include "pipeline-interests-fixture.hpp"

#include <cmath>

namespace ndn::chunks::tests {

class PipelineInterestFixedFixture : public PipelineInterestsFixture
Expand All @@ -46,7 +48,7 @@ class PipelineInterestFixedFixture : public PipelineInterestsFixture
void
createPipeline()
{
auto pline = make_unique<PipelineInterestsFixed>(face, opt);
auto pline = std::make_unique<PipelineInterestsFixed>(face, opt);
pipeline = pline.get();
setPipeline(std::move(pline));
}
Expand Down Expand Up @@ -187,7 +189,7 @@ BOOST_AUTO_TEST_CASE(TimeoutBeforeFinalBlockIdReceived)
BOOST_REQUIRE_EQUAL(face.sentInterests.size(), opt.maxPipelineSize * 3 - 2);

// nack for the first pipeline element (segment #0)
auto nack = make_shared<lp::Nack>(face.sentInterests[opt.maxPipelineSize]);
auto nack = std::make_shared<lp::Nack>(face.sentInterests[opt.maxPipelineSize]);
nack->setReason(lp::NackReason::DUPLICATE);
face.receive(*nack);

Expand Down Expand Up @@ -232,7 +234,7 @@ BOOST_AUTO_TEST_CASE(SegmentReceivedAfterTimeout)
advanceClocks(opt.interestLifetime);

// nack for the first pipeline element (segment #0)
auto nack = make_shared<lp::Nack>(face.sentInterests[opt.maxPipelineSize]);
auto nack = std::make_shared<lp::Nack>(face.sentInterests[opt.maxPipelineSize]);
nack->setReason(lp::NackReason::DUPLICATE);
face.receive(*nack);
BOOST_CHECK_EQUAL(hasFailed, false);
Expand Down Expand Up @@ -261,7 +263,7 @@ BOOST_AUTO_TEST_CASE(CongestionAllSegments)

// send nack for all the pipeline elements first interest
for (size_t i = 0; i < opt.maxPipelineSize; i++) {
auto nack = make_shared<lp::Nack>(face.sentInterests[i]);
auto nack = std::make_shared<lp::Nack>(face.sentInterests[i]);
nack->setReason(lp::NackReason::CONGESTION);
face.receive(*nack);
advanceClocks(time::nanoseconds(1));
Expand All @@ -283,7 +285,7 @@ BOOST_AUTO_TEST_CASE(CongestionAllSegments)
}

for (size_t j = 0; j < opt.maxPipelineSize; j++) {
auto nack = make_shared<lp::Nack>(face.sentInterests[(opt.maxPipelineSize * i) + j]);
auto nack = std::make_shared<lp::Nack>(face.sentInterests[(opt.maxPipelineSize * i) + j]);
nack->setReason(lp::NackReason::CONGESTION);
face.receive(*nack);
advanceClocks(time::nanoseconds(1));
Expand Down
12 changes: 6 additions & 6 deletions tests/chunks/pipeline-interests-fixture.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2016-2023, Regents of the University of California,
* Copyright (c) 2016-2024, Regents of the University of California,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University.
*
Expand Down Expand Up @@ -44,21 +44,21 @@ class PipelineInterestsFixture : public IoFixture
{
protected:
void
setPipeline(unique_ptr<PipelineInterests> pline)
setPipeline(std::unique_ptr<PipelineInterests> pline)
{
m_pipeline = std::move(pline);
}

shared_ptr<Data>
std::shared_ptr<Data>
makeDataWithSegment(uint64_t segmentNo, bool setFinalBlockId = true) const
{
auto data = make_shared<Data>(Name(name).appendVersion(0).appendSegment(segmentNo));
auto data = std::make_shared<Data>(Name(name).appendVersion(0).appendSegment(segmentNo));
if (setFinalBlockId)
data->setFinalBlock(name::Component::fromSegment(nDataSegments - 1));
return signData(data);
}

shared_ptr<Data>
std::shared_ptr<Data>
makeDataWithSegmentAndCongMark(uint64_t segmentNo,
uint64_t congestionMark = 1,
bool setFinalBlockId = true) const
Expand All @@ -83,7 +83,7 @@ class PipelineInterestsFixture : public IoFixture
bool hasFailed = false;

private:
unique_ptr<PipelineInterests> m_pipeline;
std::unique_ptr<PipelineInterests> m_pipeline;
};

} // namespace ndn::chunks::tests
Expand Down
11 changes: 6 additions & 5 deletions tests/peek/ndnpeek.t.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2023, Arizona Board of Regents.
* Copyright (c) 2014-2024, Arizona Board of Regents.
*
* This file is part of ndn-tools (Named Data Networking Essential Tools).
* See AUTHORS.md for complete list of ndn-tools authors and contributors.
Expand All @@ -24,6 +24,7 @@

#include <ndn-cxx/util/dummy-client-face.hpp>

#include <boost/lexical_cast.hpp>
#include <boost/test/tools/output_test_stream.hpp>

namespace ndn::peek::tests {
Expand Down Expand Up @@ -63,13 +64,13 @@ class NdnPeekFixture : public IoFixture
void
initialize(const PeekOptions& opts = makeDefaultOptions())
{
peek = make_unique<NdnPeek>(face, opts);
peek = std::make_unique<NdnPeek>(face, opts);
}

protected:
DummyClientFace face{m_io};
output_test_stream output;
unique_ptr<NdnPeek> peek;
std::unique_ptr<NdnPeek> peek;
};

class OutputFull
Expand Down Expand Up @@ -232,7 +233,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(ReceiveNackWithoutReason, OutputCheck, OutputCheck
BOOST_AUTO_TEST_CASE(ApplicationParameters)
{
auto options = makeDefaultOptions();
options.applicationParameters = make_shared<Buffer>("hello", 5);
options.applicationParameters = std::make_shared<Buffer>("hello", 5);
initialize(options);

peek->start();
Expand Down Expand Up @@ -305,7 +306,7 @@ BOOST_AUTO_TEST_CASE(TimeoutGreaterThanLifetime)
BOOST_AUTO_TEST_CASE(OversizedPacket)
{
auto options = makeDefaultOptions();
options.applicationParameters = make_shared<Buffer>(MAX_NDN_PACKET_SIZE);
options.applicationParameters = std::make_shared<Buffer>(MAX_NDN_PACKET_SIZE);
initialize(options);

peek->start();
Expand Down
6 changes: 3 additions & 3 deletions tests/peek/ndnpoke.t.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2023, Regents of the University of California,
* Copyright (c) 2014-2024, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand Down Expand Up @@ -47,7 +47,7 @@ class NdnPokeFixture : public IoFixture, public KeyChainFixture
void
initialize(const PokeOptions& opts = makeDefaultOptions())
{
poke = make_unique<NdnPoke>(face, m_keyChain, payload, opts);
poke = std::make_unique<NdnPoke>(face, m_keyChain, payload, opts);
}

static PokeOptions
Expand All @@ -61,7 +61,7 @@ class NdnPokeFixture : public IoFixture, public KeyChainFixture
protected:
DummyClientFace face{m_io, m_keyChain, {true, WANT_PREFIX_REG_REPLY}};
std::stringstream payload{"Hello, world!\n"};
unique_ptr<NdnPoke> poke;
std::unique_ptr<NdnPoke> poke;
};

BOOST_AUTO_TEST_SUITE(Peek)
Expand Down
Loading

0 comments on commit 5748e82

Please sign in to comment.