Project

General

Profile

Step-By-Step - Common Client Libraries » History » Revision 39

Revision 38 (Anonymous, 02/12/2019 02:14 PM) → Revision 39/40 (Anonymous, 12/23/2019 03:39 AM)

Step-By-Step - Common Client Libraries 
 ====================================== 

 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), [NDN-DOT-NET](https://github.com/named-data/ndn-dot-net)). 

 # Prerequisites 

 ## OS X 10.11, macOS 10.12, 10.13 and 10.14 

 * Install Xcode. To install the command line tools, in a terminal enter: 

     xcode-select --install 

 * Install Brew from https://brew.sh 

 In a terminal, enter: 

     brew install boost openssl pkg-config 

 ## Ubuntu 13.10, 14.04, 15.04, 16.04, 16.10, 17.04, 17.10 and 18.04 

 In a terminal, enter: 

     sudo apt-get install build-essential git libssl-dev libsqlite3-dev libcrypto++-dev libpcap-dev libboost-all-dev pkg-config 

 ## Raspbian Jessie (Rapberry Pi) 

 In a terminal, enter: 

     sudo apt-get install build-essential git libssl-dev libsqlite3-dev libcrypto++-dev libpcap-dev libboost1.50-all-dev 

 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`: 

     ipv6 

 Reboot your Raspberry Pi. 

 (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` .) 

 # Build/Install NFD 

 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: 

     git clone https://github.com/named-data/ndn-cxx 
     git clone --recursive https://github.com/named-data/NFD 
     cd ndn-cxx 
     ./waf configure 

 It is OK if waf says "program not found" for doxygen, sphinx-build, rt, or rtnetlink. 

     ./waf 
     sudo ./waf install 
     cd .. 
     cd NFD 
     ./waf configure 
     ./waf 
     sudo ./waf install 
     cd .. 

 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: 

     sudo cp /usr/local/etc/ndn/nfd.conf.sample /usr/local/etc/ndn/nfd.conf 

 ### Ubuntu and Raspbian (Raspberry Pi) 

 [Ubuntu and Raspbian only] Update the path to the shared libraries: 

     sudo /sbin/ldconfig 

 # Configure NFD 

 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. 
 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). 

 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.** 

 ## Start NFD 

 Open a new terminal window (so you can watch the NFD messages) and enter: 

     nfd-start 

 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. 

 Later, you can stop NFD with `nfd-stop` . 

 

 ## Add a route to another NFD host (optional) 

 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: 

     nfdc face create remote udp://<other host> 
     nfdc route add /ndn <face id> udp://<other host> 

 where `<other host>` is the name or IP address of the other host (e.g., `spurs.cs.ucla.edu`), and the `<face id>` is printed by the `nfdc face create` command. `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". 

 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).) 

 

 # Install the Common Client Library 

 If you haven't done so, get the library from GitHub and follow the INSTALL instructions for your language: 

 * C++: [NDN-CPP](https://github.com/named-data/ndn-cpp) ([INSTALL](https://github.com/named-data/ndn-cpp/blob/master/INSTALL.md) instructions) 
 * Python: [PyNDN2](https://github.com/named-data/PyNDN2) ([INSTALL](https://github.com/named-data/PyNDN2/blob/master/INSTALL.md) instructions) 
 * JavaScript: [NDN-JS](https://github.com/named-data/ndn-js) ([INSTALL](https://github.com/named-data/ndn-js/blob/master/INSTALL) instructions) 
 * JavaScript: [jNDN](https://github.com/named-data/jndn) ([INSTALL](https://github.com/named-data/jndn/blob/master/INSTALL.md) instructions) 

 # Send an Interest to receive a Data packet 

 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: 

 * C++: [`test-get-async.cpp`](https://github.com/named-data/ndn-cpp/blob/master/tests/test-get-async.cpp) 
 * Python: [`test_get_async.py`](https://github.com/named-data/PyNDN2/blob/master/tests/test_get_async.py) 
 * JavaScript (browser): [`test-get-async.html`](https://github.com/named-data/ndn-js/blob/master/tests/browser/test-get-async.html) 
 * JavaScript (node): [`fetch.js`](https://github.com/named-data/ndn-js/blob/master/tests/node/fetch.js) 
 * Java: [`TestGetAsync.java`](https://github.com/named-data/jndn/blob/master/tests/src/net/named_data/jndn/tests/TestGetAsync.java) 

 The main calls to the API are (using Python for example): 

 Call the [Face constructor](http://named-data.net/doc/ndn-ccl-api/face.html#face-constructors) and specify the host. 

     face = Face("aleph.ndn.ucla.edu") 


 Create a [Name](http://named-data.net/doc/ndn-ccl-api/name.html#name-constructor-from-uri) for the Interest, using a Name URI. 

     name1 = Name("/ndn/edu/ucla/remap/ndn-js-test/howdy.txt") 

 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. 

     face.expressInterest(name1, counter.onData, counter.onTimeout) 

 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. 
 Your application should make sure that it calls processEvents in the same thread as expressInterest (which also modifies the pending interest table). 

     while counter._callbackCount < 3: 
         face.processEvents() 
         # We need to sleep for a few milliseconds so we don't use 100% of the CPU. 
         time.sleep(0.01)