NDT client: first iteration #441

Merged
merged 182 commits into from May 23, 2016

Projects

None yet

3 participants

@bassosimone
Member
bassosimone commented Apr 4, 2016 edited

This branch has now reached the "ready for review state". It contains the initial implementation of the NDT client, already good enough to start testing with it and already tested enough (coverage super high for all files of this pull request) to stay in master. Issue #400 highlights future improvements that could be implemented as separate pull requests once this branch has been merged.

@bassosimone bassosimone added this to the release-0.3.0 milestone Apr 16, 2016
@bassosimone bassosimone referenced this pull request in neubot/neubot-project May 3, 2016
Closed

Write NDT test for MeasurementKit #1

bassosimone and others added some commits Apr 4, 2016
@bassosimone bassosimone Start working to NDT client implementation fc63740
@bassosimone bassosimone ndt: improve timeouts de94613
@bassosimone bassosimone ndt: fix upload speed computation e9f067e
@bassosimone bassosimone ndt: interactively print speed b9dab07
@bassosimone bassosimone ndt: reduce send buffer size e23da71
@bassosimone bassosimone print to stdout web100 data and results 26f4f2d
@bassosimone bassosimone Merge remote-tracking branch 'origin/master' into feature/ndt
Conflicts:
	include/measurement_kit/common/error_or.hpp
f1f3911
@bassosimone bassosimone Merge branch 'master' into feature/ndt
Conflicts:
	include/measurement_kit/common/funcs.hpp
f7885b4
@bassosimone bassosimone Merge remote-tracking branch 'origin/master' into feature/ndt
Conflicts:
	include/measurement_kit/net/error.hpp
09f20a4
@bassosimone bassosimone Merge remote-tracking branch 'origin/master' into feature/ndt
Conflicts:
	include/measurement_kit/common/logger.hpp
	include/measurement_kit/common/net_test.hpp
	src/common/logger.cpp
5a97b22
@bassosimone bassosimone Revert some more changes in example/ooni a159be6
@bassosimone bassosimone revert changes in i/m/c/logger.hpp 07e1384
@bassosimone bassosimone further reduce diff with respect to master 982eabe
@bassosimone bassosimone Merge remote-tracking branch 'origin/master' into feature/ndt 02a4a6b
@bassosimone bassosimone Remove debugging code 355f75a
@bassosimone bassosimone move code in src/net/transport.cpp 5955252
@bassosimone bassosimone Merge remote-tracking branch 'origin/master' into feature/ndt
Conflicts:
	include/measurement_kit/common/funcs.hpp
7b7b42a
@bassosimone bassosimone update ndt implementation to recent master changes fcaf81e
@bassosimone bassosimone Merge branch 'master' into feature/ndt 9f39bfc
@bassosimone bassosimone Repair compilation after Callback<T> => Callback<Error, T> change 325c06e
@bassosimone bassosimone Merge branch 'master' into feature/ndt 763f119
@bassosimone bassosimone Switch to master's continuation
d66398c
@bassosimone bassosimone Merge branch 'master' into feature/ndt
6db10ba
@bassosimone bassosimone Merge branch 'master' into feature/ndt c4ccdde
@bassosimone bassosimone use random printable string 86dfb88
@bassosimone bassosimone utils: change split to return a list
A list is more practical given that we are going to remove
from the front of the list inside of NDT code.
49bd2db
@bassosimone bassosimone Tweak verbosity to be optimal for NDT 9bfcd61
@bassosimone bassosimone Read granted suite from server
Removes one FIXME
859cc5b
@bassosimone bassosimone Merge branch 'master' into feature/ndt 5dffe03
@bassosimone bassosimone logger: granular verbosity level control
Initially implemented in the NDT branch, to be backported to master.
bb55f40
@bassosimone bassosimone Begin refactoring
5ebbb00
@AntonioLangiu AntonioLangiu Add a check for the ca-bundle certificate
3bd9db2
@bassosimone bassosimone Merge remote-tracking branch 'origin/master' into feature/ndt b146d6e
@bassosimone bassosimone more refactoring ccec585
@bassosimone bassosimone further refactoring e281d5f
@bassosimone bassosimone namespaces
41c5aed
@bassosimone bassosimone refactor
61c06fe
@bassosimone bassosimone minimize headers
ebdb578
@bassosimone bassosimone rename
23a1f21
@bassosimone bassosimone further simplify
e0517b8
@bassosimone bassosimone clang-format
ac80267
@bassosimone bassosimone simplify
682d3f0
@bassosimone bassosimone one less todo
d12c08b
@bassosimone bassosimone comment
796577f
@bassosimone bassosimone document
0633081
@bassosimone bassosimone format_any() is now static inline in messages_impl.hpp
5f901ba
@bassosimone bassosimone document
9adab2d
@bassosimone bassosimone move
76d7778
@bassosimone bassosimone comment
b710f77
@bassosimone bassosimone express doubt
b60d6a0
@AntonioLangiu AntonioLangiu Set the ssl-context
9ae29b0
@bassosimone bassosimone Merge branch 'master' into feature/ndt 04e7971
@bassosimone bassosimone Fix build
48b1393
@bassosimone bassosimone podspec: fix location of vendored frameworks 3ae39df
@bassosimone bassosimone ios: cross compile dependencies in advance bdd645c
@bassosimone bassosimone ios: speed up build using precompiled dependencies 4514576
@bassosimone bassosimone Merge branch 'master' into feature/faster-ios-build eeff956
@bassosimone bassosimone autogen.sh: make sure common/version.hpp is in common.hpp
4ad5791
@bassosimone bassosimone Merge branch 'master' into feature/faster-ios-build
f97d92d
@bassosimone bassosimone Merge branches 'feature/faster-ios-build' and 'fix/autogen' into feat…
…ure/ndt

 Conflicts:
	autogen.sh
57bec48
@bassosimone bassosimone Merge branch 'master' into fix/autogen
8b8ab18
@bassosimone bassosimone Merge branch 'master' into feature/ndt b5b8b02
@bassosimone bassosimone make sure we install common/version.hpp 1292ff3
@bassosimone bassosimone Merge branch 'fix/autogen' into feature/ndt 435d718
@bassosimone bassosimone This time better fix
02e7951
@bassosimone bassosimone Merge branch 'fix/autogen' into feature/ndt
09919b4
@bassosimone bassosimone Merge branch 'master' into feature/ndt
26b484c
@bassosimone bassosimone Teach mlabns to honour net/ca_bundle_path
While there simplify implementation to receive input from a Settings
object rather than from a special purpose object.

This diff is best viewed appending `?w=1` to github diff URL because I
run `clang-format` over the file and formatting changed.

This diff assumes that @AntonioLangiu has already implemented the
default-ca-path diff, therefore it does not bother with setting default
values for the CA path in the example.
8ca7a98
@bassosimone bassosimone Merge branch 'fix/mlabns' into feature/ndt
2d9811d
@bassosimone bassosimone All tests now use the same DSL ca1389b
@bassosimone bassosimone Merge branch 'feature/flowed' into feature/ndt e3d6976
@bassosimone bassosimone fix regress tests
3d1113c
@bassosimone bassosimone Merge branch 'feature/flowed' into feature/ndt aa99be8
@bassosimone bassosimone refactor ddcc64b
@bassosimone bassosimone let emitter print at DEBUG2 level 3488fba
@bassosimone bassosimone ndt: use logger for all output 88068b5
@bassosimone bassosimone allow to specify mk::split() pattern 2ac9ead
@bassosimone bassosimone add support for detecting broken pipe 25f12aa
@bassosimone bassosimone Tolerate EPIPE at end of upload bda6d99
@bassosimone bassosimone split output f5f98c8
@bassosimone bassosimone Implement run() that uses mlabns
8ac6673
@bassosimone bassosimone settings: implement get_noexcept() f28873a
@bassosimone bassosimone run: use get_noexcept() 9427bb9
@bassosimone bassosimone refactor e1de61b
@bassosimone bassosimone Tweak verbosity 884da3e
@bassosimone bassosimone dsl: add macro to declare net test dsl 96123f0
@bassosimone bassosimone dsl: add macro to declare net test dsl
7e1d0b4
@bassosimone bassosimone mv settings, reactor from OoniTestImpl to NetTest 845f5f3
@bassosimone bassosimone Tweak previous 1046248
@bassosimone bassosimone net_test_dsl.hpp: allow to increase verbosity cf4df3d
@bassosimone bassosimone implement ndt dsl 06f524a
@bassosimone bassosimone net_test_dsl.hpp: allow to increase verbosity
29c8932
@bassosimone bassosimone mv settings, reactor from OoniTestImpl to NetTest 5182761
@bassosimone bassosimone Tweak previous a7740fc
@bassosimone bassosimone fix mlabns verbosity bf891d2
@bassosimone bassosimone fix mlabns verbosity
3a1f770
bassosimone and others added some commits May 13, 2016
@bassosimone bassosimone fix debug message
c7d634c
@bassosimone bassosimone Merge remote-tracking branches 'origin/master' and 'origin/fix/mlabns…
…' into feature/ndt
c5dde81
@bassosimone bassosimone "fix embarassing bug" (cit.)
027904e
@bassosimone bassosimone Merge remote-tracking branch 'origin/feature/net-test' into feature/ndt
Conflicts:
	include/measurement_kit/common/net_test.hpp
	src/ooni/ooni_test_impl.hpp
cc77846
@bassosimone bassosimone Tweak again verbosity
6c7a2ec
@bassosimone bassosimone Merge remote-tracking branch 'origin/master' into feature/ndt 35f1c77
@bassosimone bassosimone tweak verbosity
9f7fff5
@bassosimone bassosimone Merge remote-tracking branch 'origin/master' into feature/faster-ios-…
…build
909d768
@bassosimone bassosimone build/ios/archive-deps: trim content of final tarball 628531c
@bassosimone bassosimone build/spec/all: make sure build order makes sense 1e6463d
@AntonioLangiu AntonioLangiu Remove --without-ca-bundle and add some fixes
2212975
@bassosimone bassosimone further tweak build/ios/archive-deps
e43fcfd
@bassosimone bassosimone Merge remote-tracking branch 'origin/feature/faster-ios-build' into f…
…eature/ndt
8e3c578
@AntonioLangiu AntonioLangiu Add licence of cURL for the acinclude.m4 script because it is derivat…
…ive work

and add some fixes
cb23fd0
@AntonioLangiu AntonioLangiu fixes
c32336f
@AntonioLangiu AntonioLangiu Merge branch 'master' into feature/ca-bundle
8b057f1
@AntonioLangiu AntonioLangiu Merge branch 'master' into feature/flowed 6fcbbe8
@bassosimone bassosimone Merge remote-tracking branch 'origin/feature/ca-bundle' into feature/ndt d1951c0
@bassosimone bassosimone Tweaks before merging
9f04f80
@bassosimone bassosimone Tweak previous 013523b
@bassosimone bassosimone More commits preparing for merging d41fe3f
@bassosimone bassosimone Merge remote-tracking branch 'origin/feature/ca-bundle' into feature/ndt ca67753
@AntonioLangiu AntonioLangiu fix set_backend
19b16d6
@bassosimone bassosimone changed the title from Start working to NDT client implementation to Full fledged NDT client May 14, 2016
@bassosimone bassosimone referenced this pull request May 14, 2016
Open

TODO list for integrating NDT #400

5 of 12 tasks complete
bassosimone added some commits May 14, 2016
@bassosimone bassosimone Merge remote-tracking branch 'origin/master' into feature/ndt
Conflicts:
	acinclude.m4
863d783
@bassosimone bassosimone Add basic NDT regress test aa391e0
@bassosimone bassosimone Merge remote-tracking branch 'origin/feature/flowed' into feature/ndt
9ff2df3
@bassosimone bassosimone add tests for run_impl.hpp 9bac4bf
@bassosimone bassosimone Attempt to repair build 61527ea
@bassosimone bassosimone changed the title from Full fledged NDT client to NDT client: first iteration May 14, 2016
bassosimone added some commits May 14, 2016
@bassosimone bassosimone Merge branch 'master' into feature/ndt ddca948
@bassosimone bassosimone finally fix test/ndt/run
74f579c
@bassosimone bassosimone Tell Valgrind to always generate suppressions
288c8e4
@bassosimone bassosimone Add suppression for OpenSSL 399ad14
@bassosimone bassosimone one more test
69533a9
@bassosimone bassosimone Merge remote-tracking branch 'origin/master' into feature/ndt 7e21226
@bassosimone bassosimone add some tests for test_s2c
eec85a5
@bassosimone bassosimone finish test test_s2c 6949ebf
@bassosimone bassosimone Merge remote-tracking branch 'origin/master' into feature/ndt
70c1612
@bassosimone bassosimone test_s2c: hopefully reached 100% of coverage
b59a09e
@bassosimone bassosimone more regress 5efd192
@bassosimone bassosimone fix compile
6f581a3
@bassosimone bassosimone cover most of s/n/protocol_impl.hpp
943f54f
@bassosimone bassosimone regress tests for s/n/messages_impl.hpp
239e471
@bassosimone bassosimone coverage of test_meta
6472aff
@bassosimone bassosimone more fixes for t/n/protocol
d63efbb
@bassosimone bassosimone MK_MOCK_NAMESPACE: prepend namespace to name
39da144
@bassosimone bassosimone Merge branch 'feature/mock' into feature/ndt
Conflicts:
	.gitignore
0109e17
@bassosimone bassosimone Adapt to new MK_MOCK_NAMESPACE ccaeee5
@bassosimone bassosimone properly mock function running tests 514aecb
@bassosimone bassosimone Rewrite function running tests 017f307
@bassosimone bassosimone simulate test failure
0359ee1
@bassosimone bassosimone mock.hpp: define macros with suffix f0fede1
@bassosimone bassosimone improve testability and coverage
72cbb09
@bassosimone bassosimone Merge branch 'master' into feature/ndt
Conflicts:
	include/measurement_kit/common/mock.hpp
f1bf2f8
@bassosimone bassosimone Three headers not one 427d364
@bassosimone bassosimone use define for port bfa1f26
@bassosimone bassosimone rename read_ndt as read_ll a48acb0
@bassosimone bassosimone changes after code review
f408f37
@bassosimone bassosimone more assert correctness 9f2289a
@bassosimone bassosimone Merge remote-tracking branch 'origin/master' into feature/ndt ecc955e
@bassosimone bassosimone remove unused include
f7331db
@bassosimone bassosimone more changes during code review
f7021f6
@bassosimone bassosimone more fixes during code review
b08dae0
@bassosimone bassosimone merge two tests and reindent
8404d0a
@bassosimone bassosimone more coding style
29e315a
@hellais hellais was assigned by bassosimone May 15, 2016
@hellais hellais and 1 other commented on an outdated diff May 18, 2016
src/ndt/run_impl.hpp
+ ctx->callback = callback;
+ ctx->logger = logger;
+ ctx->reactor = reactor;
+ ctx->port = port;
+ ctx->settings = settings;
+
+ dump_settings(ctx->settings, "ndt", ctx->logger);
+
+ // The following code implements this sequence diagram:
+ // https://raw.githubusercontent.com/wiki/ndt-project/ndt/NDTProtocol.images/ndt_10.png
+
+ connect(ctx, [ctx](Error err) {
+ if (err) {
+ disconnect_and_callback(ctx, err);
+ return;
+ }
@hellais
hellais May 18, 2016 Contributor

Maybe it would be cleaner to make this into a macro.

@bassosimone
bassosimone May 19, 2016 Member

Yeah! Implemented in cb884a7.

@hellais hellais commented on the diff May 18, 2016
src/ndt/protocol_impl.hpp
+ callback(ReadingTestsIdMessageError(err));
+ return;
+ }
+ if (type != MSG_LOGIN) {
+ callback(NotTestsIdMessageError());
+ return;
+ }
+ ctx->logger->info("Authorized tests: %s", s.c_str());
+ ctx->granted_suite = split(s);
+ callback(NoError());
+ });
+}
+
+template <MK_MOCK_NAMESPACE(test_c2s, run), MK_MOCK_NAMESPACE(test_meta, run),
+ MK_MOCK_NAMESPACE(test_s2c, run)>
+void run_tests_impl(Var<Context> ctx, Callback<Error> callback) {
@hellais
hellais May 18, 2016 Contributor

I am thinking that it may be useful for a user of the API to be able to run specific tests. My understanding of how this call works is that you look at the tests that are supported by the NDT server and run through them in the order by which they are returned from the server.

Wouldn't it be better instead to have the order, and the types of tests to run, be defined by a user of the NdtTest DSL?

Perhaps having a call to set the types of test to run.

@hellais
hellais May 18, 2016 Contributor

Edit:

I realise now that apparently

The tests MUST be performed in the order received from the Server

I guess then the above suggestion would be to instead of setting test_suite = TEST_STATUS | TEST_META | TEST_C2S | TEST_S2C make it possible to select also a subset of all tests.

I am thinking this could be particularly useful in the case where one wants to run a download test, but not an upload test or vice-versa.

@bassosimone
bassosimone May 19, 2016 Member

I agree. I have implemented the possibility to specify which test to run in d9bdd24.

@hellais hellais and 1 other commented on an outdated diff May 18, 2016
src/ndt/protocol_impl.hpp
+ callback(InvalidTestIdError(num.as_error()));
+ return;
+ }
+
+ std::function<void(Var<Context>, Callback<Error>)> func;
+ switch (*num) {
+ case TEST_C2S:
+ func = test_c2s_run;
+ break;
+ case TEST_META:
+ func = test_meta_run;
+ break;
+ case TEST_S2C:
+ func = test_s2c_run;
+ break;
+ }
@hellais
hellais May 18, 2016 Contributor

Maybe it's good to add checks for all the supported NDT tests TEST_MID, TEST_SFW (even if they are not yet implemented in NDT) and as suggested by the NDT design doc:

The Client MUST drop the connection when it receives unknown test id, because such situation means an error on the Server's part

@bassosimone
bassosimone May 19, 2016 Member

Refactored the code in 77ef083 to simplify the flow and clarify that, on invalid test id, the connection with the server is closed. (Better to see the diff without considering space changes, for clarity.)

@bassosimone
bassosimone May 19, 2016 edited Member

Then also added 878db1c because 77ef083 was broken.

@hellais hellais and 1 other commented on an outdated diff May 18, 2016
src/ndt/test_c2s_impl.hpp
+ return;
+ }
+ logger->info("Connected to %s:%d", address.c_str(), port);
+ logger->debug("ndt: suspend coroutine");
+ cb(NoError(), [=](Callback<Error> cb) {
+ double begin = time_now();
+ Var<double> previous(new double(begin));
+ Var<size_t> count(new size_t(0));
+ logger->debug("ndt: resume coroutine");
+ logger->info("Starting upload");
+ txp->set_timeout(timeout);
+ txp->on_flush([=]() {
+ double now = time_now();
+ if (now - *previous > 0.5) {
+ double x =
+ (*count * 8) / 1000 / (now - *previous);
@hellais
hellais May 18, 2016 Contributor

Count is the result of calling size() on string, which is the size of the string in bytes so there is no need to multiply this by 8.

@hellais
hellais May 18, 2016 Contributor

On second thought, I guess it depends what is the unit of measure you have below.

If below you mean to use kilobits, then it's OK like this, but I would probably change the reading of the info log call to make the clearer, such as (Speed: %.2f kbit/s).

@bassosimone
bassosimone May 19, 2016 Member

I agree! Now using kbit/s, see e65cc9b!

bassosimone added some commits May 19, 2016
@bassosimone bassosimone Merge branch 'master' into feature/ndt d90c367
@bassosimone bassosimone src/ndt/run_impl.hpp: use macro for readability
Suggested by @hellais.

While there commit updated `.gitignore`.
cb884a7
@bassosimone bassosimone ndt: say explicitly kbit/s rather than kb/s
As suggested by @hellais, kbit/s is more easily readable and less
ambiguous than kb/s, when the unit of speed is bit/s.
e65cc9b
@bassosimone bassosimone protocol_impl.hpp: refactor test selection code
Refactor code selecting the test to run and eventually erroring out
such that it's easier to see what happens if a test id is not recognized.

Specifically, calling the callback of the stage with an error should
lead to the connection being closed by the client.

This diff is best read enabling the `-w` option to ignore space changes.
77ef083
@bassosimone bassosimone Purely cosmetic change
This should make a diff that is listed in the conversation on github
obsolete, thus facilitating code review.
966ac66
@bassosimone bassosimone better refactor of test selecting code
878db1c
@bassosimone bassosimone Allow to choose what steps to run
Suggested by @hellais.
d9bdd24
@bassosimone
Member

@hellais Thanks for all the comments! I think I have implemented all the recommended suggestions!

bassosimone and others added some commits May 19, 2016
@bassosimone bassosimone Fix headers for Linux
3b1250f
@bassosimone bassosimone Merge branch 'master' into feature/ndt
abef51e
@hellais hellais Merge branch 'master' into feature/ndt 8e07d1a
@hellais
Contributor
hellais commented May 23, 2016

Ok I have finished another pass of reviewing and testing of this branch and it looks good to me.

I think we can merge this into master!

🎉 👍 💯

@hellais
Contributor
hellais commented May 23, 2016 edited

As discussed with @bassosimone adding support for obtaining the result of a NDT test will be added in a PR on top of this one.

@bassosimone
Member
bassosimone commented May 23, 2016 edited

The build failed because a header needs to be changed to reflect #627. Apparently github is currently stuck; I've pushed the fix and a couple of reverts to trigger it, but the web interface (and their backend) has not updated yet. Will merge once the build resumes and is fixed.

bassosimone added some commits May 23, 2016
@bassosimone bassosimone Revert "Revert "How do I trigger travis?""
This reverts commit d1439c5.
7104533
@bassosimone bassosimone Merge branch 'master' into feature/ndt
e8a0180
@bassosimone
Member

Thanks for the review, @hellais! Now merging!

@bassosimone bassosimone merged commit c40e453 into master May 23, 2016

1 of 2 checks passed

coverage/coveralls Coverage decreased (-1.6%) to 90.271%
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
@bassosimone bassosimone deleted the feature/ndt branch May 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment