Project

General

Profile

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

Anonymous, 12/23/2014 09:37 AM

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