Project

General

Profile

Step-By-Step - Common Client Libraries » History » Version 34

Anonymous, 03/29/2018 01:50 PM
ndn-cxx no longer supports Ubuntu 12.04

1 1 Anonymous
Step-By-Step - Common Client Libraries
2
======================================
3
4 23 Anonymous
This document shows step-by-step how to get a minimal [NFD](https://github.com/named-data/NFD) running so you can start writing applications to use the NDN [Common Client Libraries](http://named-data.net/doc/ndn-ccl-api/) ([NDN-CPP](https://github.com/named-data/ndn-cpp), [NDN-JS](https://github.com/named-data/ndn-js), [PyNDN](https://github.com/named-data/PyNDN2), [jNDN](https://github.com/named-data/jndn)).
5 1 Anonymous
6
# Prerequisites
7
8 31 Anonymous
## OS X 10.11, macOS 10.12, macOS 10.13
9 1 Anonymous
10 32 Anonymous
* Install Xcode. To install the command line tools, in a terminal enter:
11 1 Anonymous
12 31 Anonymous
    xcode-select --install
13 1 Anonymous
14 31 Anonymous
* Install Brew from https://brew.sh
15 1 Anonymous
16 31 Anonymous
In a terminal, enter:
17 1 Anonymous
18 31 Anonymous
    brew install boost openssl pkg-config
19 1 Anonymous
20 33 Anonymous
## Ubuntu 13.10, 14.04, 15.04, 16.04, 16.10, 17.04 and 17.10
21 1 Anonymous
22
In a terminal, enter:
23
24 33 Anonymous
    sudo apt-get install build-essential git libssl-dev libsqlite3-dev libcrypto++-dev libpcap-dev libboost-all-dev pkg-config
25 1 Anonymous
26 20 Anonymous
## Raspbian Jessie (Rapberry Pi)
27
28
In a terminal, enter:
29
30 21 Anonymous
    sudo apt-get install build-essential git libssl-dev libsqlite3-dev libcrypto++-dev libpcap-dev libboost1.50-all-dev
31 1 Anonymous
32 3 Anonymous
To run NFD on the Raspberry Pi, you need to enable IPv6 support. Enter `sudo nano /etc/modules` (or use your favorite editor). Add the following line to `/etc/modules`:
33 1 Anonymous
34
    ipv6
35
36
Reboot your Raspberry Pi.
37
38
(If you don't want to enable IPv6 support on the Raspberry Pi, you can disable IPv6 in NFD. After installing NFD, replace `enable_v6 yes` with `enable_v6 no` in the `tcp` and `udp` sections of `/usr/local/etc/ndn/nfd.conf` .)
39
40
# Build/Install NFD
41
42
These are steps from [build/install NFD](http://named-data.net/doc/NFD/current/INSTALL.html) which work with the CCL.  In a terminal, enter:
43
44 4 Anonymous
    git clone https://github.com/named-data/ndn-cxx
45
    git clone --recursive https://github.com/named-data/NFD
46 1 Anonymous
    cd ndn-cxx
47
    ./waf configure
48
49 31 Anonymous
It is OK if waf says "program not found" for doxygen, sphinx-build, rt, or rtnetlink.
50 1 Anonymous
51
    ./waf
52
    sudo ./waf install
53
    cd ..
54
    cd NFD
55
    ./waf configure
56
    ./waf
57
    sudo ./waf install
58
    cd ..
59
60
The NFD programs are installed in `/usr/local/bin` . The NFD configuration file is in `/usr/local/etc/ndn` .  Copy the sample configuration file to make it the default:
61
62
    sudo cp /usr/local/etc/ndn/nfd.conf.sample /usr/local/etc/ndn/nfd.conf
63 13 Anonymous
64 22 Anonymous
### Ubuntu and Raspbian (Raspberry Pi)
65 13 Anonymous
66 22 Anonymous
[Ubuntu and Raspbian only] Update the path to the shared libraries:
67 13 Anonymous
68 15 Anonymous
    sudo /sbin/ldconfig
69 1 Anonymous
70
# Configure NFD
71
72
NFD provides mechanisms to enable strict authorization for all management commands.  In particular, one can authorize only a specific public key to create new Faces or to change the strategy choice for specific namespaces.
73
For more information about how to generate a private/public key pair, generate a self-signed certificate, and use this self-signed certificate to authorize NFD management commands, refer to [NFD Configuration Tips](http://named-data.net/doc/NFD/current/README.html).
74
75
In the sample configuration file, all authorization is disabled, effectively allowing anybody on the local machine to issue NFD management commands. **The sample file is intended only for demo purposes and MUST NOT be used in a production environment.**
76
77
## Start NFD
78
79
Open a new terminal window (so you can watch the NFD messages) and enter:
80
81
    nfd-start
82
83
On OS X it may ask for your keychain password or ask "nfd wants to sign using key in your keychain." Enter your keychain password and click Always Allow.
84
85
Later, you can stop NFD with `nfd-stop` .
86
87
## Add a route to another NFD host (optional)
88
89
The previous instructions are good for testing on the local host. If you want to route an interest to another NFD host, in a terminal enter:
90
91 29 Junxiao Shi
    nfdc face create udp://<other host>
92
    nfdc route add /ndn udp://<other host>
93 1 Anonymous
94
where `<other host>` is the name or IP address of the other host (e.g., `spurs.cs.ucla.edu`). The "/ndn" means that NFD will forward all interests that start with `/ndn` through the face to the other host.  If you only want to forward interests with a certain prefix then use it instead of "/ndn".
95
96
This only forwards interests to the other host, but there is no "back route" for the other host to forward interests to you. For that, you must go to the other host and use `nfdc` to add the route. (The "back route" can also be automatically configured with `nfd-autoreg`.  For more information refer to [nfd-autoreg manpage](http://named-data.net/doc/NFD/current/manpages/nfd-autoreg.html).)
97
98
# Install the Common Client Library
99
100
If you haven't done so, get the library from GitHub and follow the INSTALL instructions for your language:
101
102 5 Anonymous
* C++: [NDN-CPP](https://github.com/named-data/ndn-cpp) ([INSTALL](https://github.com/named-data/ndn-cpp/blob/master/INSTALL.md) instructions)
103
* Python: [PyNDN2](https://github.com/named-data/PyNDN2) ([INSTALL](https://github.com/named-data/PyNDN2/blob/master/INSTALL.md) instructions)
104
* JavaScript: [NDN-JS](https://github.com/named-data/ndn-js) ([INSTALL](https://github.com/named-data/ndn-js/blob/master/INSTALL) instructions)
105
* JavaScript: [jNDN](https://github.com/named-data/jndn) ([INSTALL](https://github.com/named-data/jndn/blob/master/INSTALL.md) instructions)
106 1 Anonymous
107
# Send an Interest to receive a Data packet
108
109
The example program "test get async" is a simple program to send some interests and get a data packet.  Here they are on the various languages:
110
111
* C++: [`test-get-async.cpp`](https://github.com/named-data/ndn-cpp/blob/master/tests/test-get-async.cpp)
112
* Python: [`test_get_async.py`](https://github.com/named-data/PyNDN2/blob/master/tests/test_get_async.py)
113
* JavaScript (browser): [`test-get-async.html`](https://github.com/named-data/ndn-js/blob/master/tests/browser/test-get-async.html)
114
* JavaScript (node): [`fetch.js`](https://github.com/named-data/ndn-js/blob/master/tests/node/fetch.js)
115 5 Anonymous
* Java: [`TestGetAsync.java`](https://github.com/named-data/jndn/blob/master/tests/src/net/named_data/jndn/tests/TestGetAsync.java)
116 1 Anonymous
117
The main calls to the API are (using Python for example):
118
119
Call the [Face constructor](http://named-data.net/doc/ndn-ccl-api/face.html#face-constructors) and specify the host.
120
121
    face = Face("aleph.ndn.ucla.edu")
122
123
124
Create a [Name](http://named-data.net/doc/ndn-ccl-api/name.html#name-constructor-from-uri) for the Interest, using a Name URI.
125
126
    name1 = Name("/ndn/edu/ucla/remap/ndn-js-test/howdy.txt")
127
128
Call [expressInterest](http://named-data.net/doc/ndn-ccl-api/face.html#face-expressinterest-method-from-name), passing in the callbacks for onData and onTimeout.
129
130
    face.expressInterest(name1, counter.onData, counter.onTimeout)
131
132
Start an event loop to keep calling [processEvents](http://named-data.net/doc/ndn-ccl-api/face.html#face-processevents-method) until the application is finished.
133
Your application should make sure that it calls processEvents in the same thread as expressInterest (which also modifies the pending interest table).
134
135
    while counter._callbackCount < 3:
136
        face.processEvents()
137
        # We need to sleep for a few milliseconds so we don't use 100% of the CPU.
138
        time.sleep(0.01)