Project

General

Profile

Actions

Task #2702

closed

ping: refactor for separate responsibility

Added by Junxiao Shi over 9 years ago. Updated over 9 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Start date:
Due date:
% Done:

100%

Estimated time:
6.00 h

Description

Refactor ndnping program to use the following structure:

           |------| -> Tracer
  Face  <- |      |
           | Ping | -> StatisticsCollector
Options -> |      |          |
           |      |          v
           |------| ->   printStatistics

  • An Options POD struct contains parameters parsed from command line.
  • Ping class constructor should take Face& and Options as argument; getter/setter for each option are deleted from the class.
  • Ping class shouldn't write to stdout directly; instead, it emits a signal for each successful/failed ping, and when all pings are completed.
  • A Tracer class connects to ping succeed/fail signals, and writes logs for each successful/failed ping.
  • A StatisticsCollector class connects to ping succeed/fail signals, and collects statistics.
  • A printStatistics function connects to completion signal, and prints statistics.

Benefits:

  • separate responsibility: Ping performs network operations, Tracer writes logs, StatisticsCollector collects statistics.
  • unit testing: passing DummyClientFace to Ping constructor allows unit testing.
  • simulation: Ping and StatisticsCollector can be reused in a ndnSIM scenario.

Related issues 1 (0 open1 closed)

Blocks ndn-tools - Feature #2796: Tests for Ping and PingServerClosedEric Newberry

Actions
Actions #1

Updated by Alex Afanasyev over 9 years ago

+1

I would also like convert to use Boost.ProgramOptions library instead of getopt.

Actions #2

Updated by Eric Newberry over 9 years ago

  • Status changed from New to In Progress
  • Assignee set to Eric Newberry
Actions #3

Updated by Junxiao Shi over 9 years ago

This is a complex Task.
It's recommended that Assignee should first design headers and submit for review, before writing implementation code.

Actions #4

Updated by Eric Newberry over 9 years ago

  • File ndn-ping.hpp added

Here's what I was thinking for the header file. I used the Boost::Signals2 library for signals.

Actions #5

Updated by Junxiao Shi over 9 years ago

  • Code reviews should be uploaded to Gerrit.
  • Have one .hpp (and .cpp) per component, not a big .hpp.
  • Use ndn::util::signal instead of Boost.Signals2. As benchmarked in #2116 note-35, Boost.Signals2 is too slow.
Actions #6

Updated by Eric Newberry over 9 years ago

Got it. Should I upload what I have to Gerrit, even if it's not finished?

Actions #7

Updated by Junxiao Shi over 9 years ago

Got it. Should I upload what I have to Gerrit, even if it's not finished?

Whenever you need feedback for some code, upload to Gerrit, even if it's just headers.

You may mark CodeReview-2 to prevent merging.

Actions #8

Updated by Eric Newberry over 9 years ago

  • File deleted (ndn-ping.hpp)
Actions #9

Updated by Eric Newberry over 9 years ago

  • % Done changed from 0 to 90

Everything is currently implemented on Gerrit with the exception of Boost.ProgramOptions, which I'm working on right now.

Actions #10

Updated by Eric Newberry over 9 years ago

I believe I misunderstood what the role of Face was. Should output to stdout be done through Tracer?

Actions #11

Updated by Junxiao Shi over 9 years ago

Should output to stdout be done through Tracer?

This depends on what is being written:

  • Banner, usage, version number, etc: written by the main function, or a helper function called by the main function.
  • Log line for each successful or failed probe: written by Tracer.
  • Statistics at end of the session: written by printStatistics function.
Actions #12

Updated by Junxiao Shi over 9 years ago

If anything, we should use uint32_t for m_nextPingNo, as that's what Interest::setNonce() expects as input.

No. ping reference number is not Nonce.

Ping uses startPingNo to determine whether to randomly generate the ping number (when set to -1, which is signed), so we have two options:

  1. Keep it as int64_t/int32_t
  2. Add another boolean value to options called shouldGenerateRandomPingNo and then use uint64_t/uint32_t

Which should I do?

It's better to be more explicit in Options struct.

/** \brief start sequence number
 */
uint32_t startSeq;

/** \brief whether to generate random start sequence number
 *
 *  If true, a random start sequence number is generated,
 *  and \p startSeq is ignored.
 */
bool wantRandomStartSeq;
Actions #13

Updated by Junxiao Shi over 9 years ago

In commit:cb4818c6ca423f11ae1e11c7daa5725c66d15dba, I notice that RTTs are printed as integers, but operators need to see higher precision.

Suggestion:

  • in ping.hpp, declare typedef time::duration<double, time::milliseconds::period> Rtt;
  • change second parameter of Ping::afterResponse signal to Rtt
  • don't use division in StatisticsCollector::recordResponse
  • don't use duration_cast in Tracer::onResponse
Actions #14

Updated by Eric Newberry over 9 years ago

  • Status changed from In Progress to Closed
  • % Done changed from 90 to 100

Code has been reviewed and merged.

Actions #15

Updated by Junxiao Shi over 9 years ago

Actions

Also available in: Atom PDF