Project

General

Profile

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

Junxiao Shi, 07/26/2017 07:20 PM

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 27 Anonymous
## OS X 10.9, OS X 10.10.2, OS X 10.11, macOS 10.12
9 1 Anonymous
10
* Install Xcode.
11 6 Anonymous
* Install MacPorts from http://www.macports.org/install.php
12
13 7 Anonymous
In a new terminal, enter:
14 1 Anonymous
15
    sudo port install pkgconfig boost sqlite3 libcryptopp libpcap
16
17
To build NFD, we need `/usr/local/lib/pkgconfig` in the environment variable `PKG_CONFIG_PATH`, so we set it here. If you close your terminal before building NFD, you should set this again.
18
19
    export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
20
21
## Ubuntu 12.04
22
23
In a terminal, enter:
24
25 11 Anonymous
    sudo apt-get install build-essential git libssl-dev libsqlite3-dev libcrypto++-dev libpcap-dev libboost1.48-all-dev
26 1 Anonymous
27 28 Anonymous
## Ubuntu 13.10, 14.04, 15.04, 16.04, 16.10 and 17.04
28 1 Anonymous
29
In a terminal, enter:
30
31 12 Anonymous
    sudo apt-get install build-essential git libssl-dev libsqlite3-dev libcrypto++-dev libpcap-dev libboost-all-dev
32 1 Anonymous
33 20 Anonymous
## Raspbian Jessie (Rapberry Pi)
34
35
In a terminal, enter:
36
37 21 Anonymous
    sudo apt-get install build-essential git libssl-dev libsqlite3-dev libcrypto++-dev libpcap-dev libboost1.50-all-dev
38 1 Anonymous
39 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`:
40 1 Anonymous
41
    ipv6
42
43
Reboot your Raspberry Pi.
44
45
(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` .)
46
47
# Build/Install NFD
48
49 18 Anonymous
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:
50 1 Anonymous
51 4 Anonymous
    git clone https://github.com/named-data/ndn-cxx
52
    git clone --recursive https://github.com/named-data/NFD
53 1 Anonymous
    cd ndn-cxx
54
    ./waf configure
55
56
If waf says "program doxygen not found", "program sphinx-build not found" or "library rt not found", it is OK.
57
58
    ./waf
59
    sudo ./waf install
60
    cd ..
61
    cd NFD
62
    ./waf configure
63
64
If waf says "libndn-cxx not found", then set `PKG_CONFIG_PATH` as shown in the Prerequisites above.
65
66
    ./waf
67
    sudo ./waf install
68
    cd ..
69
70
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:
71
72
    sudo cp /usr/local/etc/ndn/nfd.conf.sample /usr/local/etc/ndn/nfd.conf
73 13 Anonymous
74 22 Anonymous
### Ubuntu and Raspbian (Raspberry Pi)
75 13 Anonymous
76 22 Anonymous
[Ubuntu and Raspbian only] Update the path to the shared libraries:
77 13 Anonymous
78 15 Anonymous
    sudo /sbin/ldconfig
79 1 Anonymous
80
# Configure NFD
81
82
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.
83
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).
84
85
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.**
86
87
## Start NFD
88
89
Open a new terminal window (so you can watch the NFD messages) and enter:
90
91
    nfd-start
92
93
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.
94
95
Later, you can stop NFD with `nfd-stop` .
96
97
## Add a route to another NFD host (optional)
98
99
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:
100
101 29 Junxiao Shi
    nfdc face create udp://<other host>
102
    nfdc route add /ndn udp://<other host>
103 1 Anonymous
104
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".
105
106
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).)
107
108
# Install the Common Client Library
109
110
If you haven't done so, get the library from GitHub and follow the INSTALL instructions for your language:
111
112 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)
113
* Python: [PyNDN2](https://github.com/named-data/PyNDN2) ([INSTALL](https://github.com/named-data/PyNDN2/blob/master/INSTALL.md) instructions)
114
* JavaScript: [NDN-JS](https://github.com/named-data/ndn-js) ([INSTALL](https://github.com/named-data/ndn-js/blob/master/INSTALL) instructions)
115
* JavaScript: [jNDN](https://github.com/named-data/jndn) ([INSTALL](https://github.com/named-data/jndn/blob/master/INSTALL.md) instructions)
116 1 Anonymous
117
# Send an Interest to receive a Data packet
118
119
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:
120
121
* C++: [`test-get-async.cpp`](https://github.com/named-data/ndn-cpp/blob/master/tests/test-get-async.cpp)
122
* Python: [`test_get_async.py`](https://github.com/named-data/PyNDN2/blob/master/tests/test_get_async.py)
123
* JavaScript (browser): [`test-get-async.html`](https://github.com/named-data/ndn-js/blob/master/tests/browser/test-get-async.html)
124
* JavaScript (node): [`fetch.js`](https://github.com/named-data/ndn-js/blob/master/tests/node/fetch.js)
125 5 Anonymous
* Java: [`TestGetAsync.java`](https://github.com/named-data/jndn/blob/master/tests/src/net/named_data/jndn/tests/TestGetAsync.java)
126 1 Anonymous
127
The main calls to the API are (using Python for example):
128
129
Call the [Face constructor](http://named-data.net/doc/ndn-ccl-api/face.html#face-constructors) and specify the host.
130
131
    face = Face("aleph.ndn.ucla.edu")
132
133
134
Create a [Name](http://named-data.net/doc/ndn-ccl-api/name.html#name-constructor-from-uri) for the Interest, using a Name URI.
135
136
    name1 = Name("/ndn/edu/ucla/remap/ndn-js-test/howdy.txt")
137
138
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.
139
140
    face.expressInterest(name1, counter.onData, counter.onTimeout)
141
142
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.
143
Your application should make sure that it calls processEvents in the same thread as expressInterest (which also modifies the pending interest table).
144
145
    while counter._callbackCount < 3:
146
        face.processEvents()
147
        # We need to sleep for a few milliseconds so we don't use 100% of the CPU.
148
        time.sleep(0.01)