Davide Pesavento | 5118959 | 2021-10-02 22:34:34 -0400 | [diff] [blame] | 1 | Examples |
| 2 | ======== |
Ashlesh Gawande | 465d149 | 2019-01-10 15:12:01 -0600 | [diff] [blame] | 3 | |
| 4 | By default, examples in ``examples/`` folder are not built. To enable them, use |
| 5 | ``--with-examples`` configure option. For example: |
| 6 | |
| 7 | .. code-block:: bash |
| 8 | |
| 9 | ./waf configure --with-examples |
| 10 | ./waf |
| 11 | |
Davide Pesavento | 5118959 | 2021-10-02 22:34:34 -0400 | [diff] [blame] | 12 | Example binary can be found under ``build/examples``: |
Ashlesh Gawande | 465d149 | 2019-01-10 15:12:01 -0600 | [diff] [blame] | 13 | |
Davide Pesavento | 5118959 | 2021-10-02 22:34:34 -0400 | [diff] [blame] | 14 | * Full sync: ``psync-full-sync`` |
| 15 | * Partial sync: ``psync-producer`` and ``psync-consumer`` |
Ashlesh Gawande | 465d149 | 2019-01-10 15:12:01 -0600 | [diff] [blame] | 16 | |
| 17 | If the library is installed to the system using ``./waf install`` then the examples |
| 18 | are also installed and can be executed directly. |
| 19 | |
| 20 | Partial Sync Example |
| 21 | -------------------- |
| 22 | |
| 23 | Partial sync example of PSync has two parts: producer and consumer. |
| 24 | These can be run on a machine after starting NFD: |
| 25 | |
| 26 | Producer |
| 27 | ^^^^^^^^ |
| 28 | |
| 29 | * Enable the logs for producer: |
| 30 | |
| 31 | .. code-block:: bash |
| 32 | |
| 33 | export NDN_LOG=examples.PartialSyncProducerApp=INFO |
| 34 | |
| 35 | |
| 36 | * Start the producer that will listen on /sync and publish 1 update for /a-0 ... /a-9 each. |
| 37 | |
| 38 | .. code-block:: bash |
| 39 | |
| 40 | psync-producer /sync /a 10 1 |
| 41 | |
| 42 | |
| 43 | * Sample output: |
| 44 | |
Davide Pesavento | 5118959 | 2021-10-02 22:34:34 -0400 | [diff] [blame] | 45 | :: |
Ashlesh Gawande | 465d149 | 2019-01-10 15:12:01 -0600 | [diff] [blame] | 46 | |
| 47 | 1546280442.096296 INFO: [examples.PartialSyncProducerApp] Publish: /a-1/1 |
| 48 | 1546280456.053138 INFO: [examples.PartialSyncProducerApp] Publish: /a-6/1 |
| 49 | 1546280458.210415 INFO: [examples.PartialSyncProducerApp] Publish: /a-8/1 |
| 50 | 1546280469.954134 INFO: [examples.PartialSyncProducerApp] Publish: /a-5/1 |
| 51 | 1546280472.487425 INFO: [examples.PartialSyncProducerApp] Publish: /a-2/1 |
| 52 | 1546280473.466515 INFO: [examples.PartialSyncProducerApp] Publish: /a-7/1 |
| 53 | 1546280481.882258 INFO: [examples.PartialSyncProducerApp] Publish: /a-0/1 |
| 54 | 1546280484.201229 INFO: [examples.PartialSyncProducerApp] Publish: /a-4/1 |
| 55 | 1546280489.348968 INFO: [examples.PartialSyncProducerApp] Publish: /a-9/1 |
| 56 | 1546280491.420391 INFO: [examples.PartialSyncProducerApp] Publish: /a-3/1 |
| 57 | |
| 58 | Consumer |
| 59 | ^^^^^^^^ |
| 60 | |
| 61 | * In a new terminal, enable the logs for consumer: |
| 62 | |
| 63 | .. code-block:: bash |
| 64 | |
| 65 | export NDN_LOG=examples.PartialSyncConsumerApp=INFO |
| 66 | |
| 67 | |
| 68 | * Run the consumer to subscribe to 5 random prefixes from the publisher on /sync |
| 69 | |
| 70 | .. code-block:: bash |
| 71 | |
| 72 | psync-consumer /sync 5 |
| 73 | |
| 74 | |
| 75 | * Sample output from the consumer shows that it received updates only |
| 76 | for the subscribed prefixes: |
| 77 | |
Davide Pesavento | 5118959 | 2021-10-02 22:34:34 -0400 | [diff] [blame] | 78 | :: |
Ashlesh Gawande | 465d149 | 2019-01-10 15:12:01 -0600 | [diff] [blame] | 79 | |
| 80 | 1546280436.502769 INFO: [examples.PartialSyncConsumerApp] Subscribing to: /a-7 |
| 81 | 1546280436.502888 INFO: [examples.PartialSyncConsumerApp] Subscribing to: /a-9 |
| 82 | 1546280436.502911 INFO: [examples.PartialSyncConsumerApp] Subscribing to: /a-8 |
| 83 | 1546280436.502934 INFO: [examples.PartialSyncConsumerApp] Subscribing to: /a-4 |
| 84 | 1546280436.502956 INFO: [examples.PartialSyncConsumerApp] Subscribing to: /a-5 |
| 85 | 1546280458.211188 INFO: [examples.PartialSyncConsumerApp] Update: /a-8/1 |
| 86 | 1546280469.954886 INFO: [examples.PartialSyncConsumerApp] Update: /a-5/1 |
| 87 | 1546280473.467116 INFO: [examples.PartialSyncConsumerApp] Update: /a-7/1 |
| 88 | 1546280484.256181 INFO: [examples.PartialSyncConsumerApp] Update: /a-4/1 |
| 89 | 1546280489.349793 INFO: [examples.PartialSyncConsumerApp] Update: /a-9/1 |
| 90 | |
| 91 | Full Sync Example |
| 92 | ----------------- |
| 93 | |
| 94 | To demonstrate full sync mode of PSync, ``psync-full-sync`` |
| 95 | can be run on a machine after starting NFD: |
| 96 | |
| 97 | |
| 98 | * Enable the logs for full sync: |
| 99 | |
| 100 | .. code-block:: bash |
| 101 | |
| 102 | export NDN_LOG=examples.FullSyncApp=INFO |
| 103 | |
| 104 | |
| 105 | * Run the full sync example with sync prefix /sync, user prefix /a, |
| 106 | and publish three updates for each user prefix: /a-0 and /a-1. This will simulate node a. |
| 107 | |
| 108 | .. code-block:: bash |
| 109 | |
| 110 | psync-full-sync /sync /a 2 3 |
| 111 | |
| 112 | |
| 113 | * Repeat for another user prefix, to simulate node b: |
| 114 | |
| 115 | .. code-block:: bash |
| 116 | |
| 117 | psync-full-sync /sync /b 2 3 |
| 118 | |
| 119 | We should see that node a and node b have received each other's updates. |
| 120 | |
| 121 | |
| 122 | * Sample output from node a shows that it received all updates |
| 123 | from node b successfully: |
| 124 | |
Davide Pesavento | 5118959 | 2021-10-02 22:34:34 -0400 | [diff] [blame] | 125 | :: |
Ashlesh Gawande | 465d149 | 2019-01-10 15:12:01 -0600 | [diff] [blame] | 126 | |
| 127 | 1546282730.759387 INFO: [examples.FullSyncApp] Update /b-1/1 |
| 128 | 1546282741.143225 INFO: [examples.FullSyncApp] Publish: /a-1/1 |
| 129 | 1546282749.375854 INFO: [examples.FullSyncApp] Publish: /a-0/1 |
| 130 | 1546282750.263246 INFO: [examples.FullSyncApp] Update /b-0/1 |
| 131 | 1546282765.875118 INFO: [examples.FullSyncApp] Update /b-1/2 |
| 132 | 1546282783.777807 INFO: [examples.FullSyncApp] Publish: /a-0/2 |
| 133 | 1546282794.565507 INFO: [examples.FullSyncApp] Publish: /a-0/3 |
| 134 | 1546282794.896895 INFO: [examples.FullSyncApp] Publish: /a-1/2 |
| 135 | 1546282803.839416 INFO: [examples.FullSyncApp] Update /b-0/2 |
| 136 | 1546282804.785867 INFO: [examples.FullSyncApp] Update /b-1/3 |
| 137 | 1546282845.273772 INFO: [examples.FullSyncApp] Publish: /a-1/3 |
| 138 | 1546282855.102790 INFO: [examples.FullSyncApp] Update /b-0/3 |
| 139 | |
Ashlesh Gawande | 465d149 | 2019-01-10 15:12:01 -0600 | [diff] [blame] | 140 | * Sample output from node b: |
| 141 | |
Davide Pesavento | 5118959 | 2021-10-02 22:34:34 -0400 | [diff] [blame] | 142 | :: |
Ashlesh Gawande | 465d149 | 2019-01-10 15:12:01 -0600 | [diff] [blame] | 143 | |
| 144 | 1546282730.758296 INFO: [examples.FullSyncApp] Publish: /b-1/1 |
| 145 | 1546282741.144027 INFO: [examples.FullSyncApp] Update /a-1/1 |
| 146 | 1546282749.376543 INFO: [examples.FullSyncApp] Update /a-0/1 |
| 147 | 1546282750.262244 INFO: [examples.FullSyncApp] Publish: /b-0/1 |
| 148 | 1546282765.296005 INFO: [examples.FullSyncApp] Publish: /b-1/2 |
| 149 | 1546282783.778769 INFO: [examples.FullSyncApp] Update /a-0/2 |
| 150 | 1546282794.566485 INFO: [examples.FullSyncApp] Update /a-0/3 |
| 151 | 1546282795.374339 INFO: [examples.FullSyncApp] Update /a-1/2 |
| 152 | 1546282803.838394 INFO: [examples.FullSyncApp] Publish: /b-0/2 |
| 153 | 1546282804.033214 INFO: [examples.FullSyncApp] Publish: /b-1/3 |
| 154 | 1546282845.274680 INFO: [examples.FullSyncApp] Update /a-1/3 |
| 155 | 1546282855.101780 INFO: [examples.FullSyncApp] Publish: /b-0/3 |