measurement_kit 0.1.2.1

measurement_kit 0.1.2.1

License BSD
ReleasedLast Release May 2016

Maintained by Lorenzo Primiterra, Antonio Langiu, Simone Basso.



  • By
  • Davide Allavena, Simone Basso, Arturo Filasto', Antonio Langiu, Lorenzo Primiterra and Alessandro Quaranta

MeasurementKit

MeasurementKit is a library that implements open network measurement methodologies (performance, censorship, etc.) and targets mobile platforms (Android and iOS).

It is meant to be embedeed by third party applications with specific network measurement needs and/or to be used by researchers as a basis to implement novel tools.

Currently it implements the following high-level tests:

It contains building-block functionalities useful to implement your own tests. More in detail it currently implements:

  • TCP connection (with which you can create a TCP connection towards and endpoint, receive and send data)

  • DNS client (with which you can resolve and reverse-resolve A and AAAA records using arbitrary name servers)

  • HTTP client (with which you can send HTTP/1.1 requests and receive and parse the corresponding responses)

  • traceroute for Android (with which you can send individual traceroute probes with a specified payload and TTL)

In the short term we plan to add to MeasurementKit:

Other functionalities that we would like to add are building-blocks functionalities such as uTP, and traceroute for iOS.

The following index illustrates the content of the remainder of this file:

How to clone the repository

To clone MeasurementKit repository, do:

git clone https://github.com/measurement-kit/measurement-kit

How to test a specific branch

If you need to checkout a specific branch (say feature/foo) for testing it, clone the repository and then type:

git fetch origin
git checkout feature/foo

Then proceed with the instruction to build and test MeasurementKit.

How to build MeasurementKit

How to build MeasurementKit on a Unix-like system

To build, MeasurementKit needs:

  • a C90 compiler (such as gcc or clang)
  • a C++11 compiler (such as g++ or clang++)
  • autoconf, automake, and libtool
  • a Unix environment (such as Linux or MacOS)

C++11 must be enabled, otherwise certain C++11 features such as std::function will not be recognized.

MeasurementKit includes and unconditionally compiles the sources of the following projects:

MeasurementKit also depends on the following projects (which are only conditionally compiled as explained below):

The ./configure script should check whether all the dependencies are in place and should configure the compilers properly. If a dependency is not found, ./configure will fall back to the copy of the dependency stored under the src/ext directory.

The vanilla build process is the following:

autoreconf -i
./configure
make

You can also force ./configure to select dependencies available at specific directories using the following flags:

  • --with-libevent=PREFIX that tells ./configure to use the libevent library and headers installed at PREFIX

  • --with-yaml-cpp=PREFIX that tells ./configure to use the yaml-cpp library and headers installed at PREFIX

  • --with-boost=PREFIX that tells ./configure to use the boost headers installed at PREFIX

  • --with-jansson=PREFIX that tells ./configure to use the jansson library and headers installed at PREFIX

  • --with-libmaxminddb=PREFIX that tells ./configure to use the libmaxminddb library and headers installed at PREFIX

In all the above cases you can also specify PREFIX equal to builtin to force ./configure to use builtin sources.

For example,

  • if libevent is installed at /opt/local (meaning that event.h is /opt/local/include/event.h and that libevent.a is /opt/local/lib/libevent.a), use
    ./configure --with-libevent=/opt/local
  • to force-compile the libevent distributed along with MeasurementKit, use
    ./configure --with-libevent=builtin

How to test MeasurementKit on a Unix-like system

Once you have built MeasurementKit, to compile and run the unit test programs, run:

make check

To tell make to produce less output (as in the Linux kernel build process) run:

make V=0

How to build MeasurementKit on Android

To compile MeasurementKit for Android, see the README.md file contained in the mobile/android directory of this repository.

How to build MeasurementKit on iOS

To compile and use MeasurementKit for iOS, do the following on a MacOSX system where XCode and its command line tools have been installed:

./mobile/ios/scripts/build.sh

How to add MeasurementKit to an Xcode project.

The Cocoapods podspec hasn't been submitted yet, but you can already use it in your project adding this line in your Podfile:

pod 'measurement_kit', :git => 'https://github.com/measurement-kit/measurement-kit.git'

You can include another branch with:

pod 'measurement_kit', 
  :git => 'https://github.com/measurement-kit/measurement-kit.git'
  :branch => 'branch_name'

Then type pod install and open .xcworkspace file (beware not to open the .xcodeproj file instead, because that alone won't compile).

How to use MeasurementKit

The following examples show how to use OONI library.

This first example show how to run a synchronous test. That is, in the following example, the run call is going to block until the test is complete. (Note that in this case the test may or may not run in the context of the same thread that called run).

#include <measurement_kit/ooni.hpp>

// Run sync test
mk::ooni::HttpInvalidRequestLineTest()
    .set_backend("http://127.0.0.1/")
    .set_verbose()
    .on_log([](const char *s) {
        // If needed, acquire the proper locks
        // Process incoming log line
    })
    .run();

// Note: run() returns when test is complete

In this second example, instead, we show how to run an asynchronous test. In this case, run returns immediately, the test runs in a background thread, and the callback passed as argument to run is invoked when the test completed.

// Run async test
mk::ooni::HttpInvalidRequestLineTest()
    .set_backend("http://127.0.0.1/")
    .set_verbose()
    .on_log([](const char *s) {
        // If needed, acquire the proper locks
        // Process incoming log line
    })
    .run([]() {
        // If needed, acquire the proper locks
        // Handle test completion
    });

// Note: run() returns immediately, callback called when done

In both cases, you need to be careful inside the callbacks, because in general they may be called from background threads.

You can find documentation of MeasurementKit C++ API in the doc/api folder of the repository.