Documentation update
[nfvbench.git] / docs / testing / user / userguide / server.rst
1 .. This work is licensed under a Creative Commons Attribution 4.0 International License.
2 .. SPDX-License-Identifier: CC-BY-4.0
3 .. (c) Cisco Systems, Inc
4
5 NFVbench Server mode and NFVbench client API
6 ============================================
7
8 NFVbench can run as an HTTP server to:
9
10 - optionally provide access to any arbitrary HTLM files (HTTP server function) - this is optional
11 - service fully parameterized aynchronous run requests using the HTTP protocol (REST/json with polling)
12 - service fully parameterized run requests with interval stats reporting using the WebSocket/SocketIO protocol.
13
14 Start the NFVbench server
15 -------------------------
16 To run in server mode, simply use the --server <http_root_path> and optionally the listen address to use (--host <ip>, default is 0.0.0.0) and listening port to use (--port <port>, default is 7555).
17
18
19 If HTTP files are to be serviced, they must be stored right under the http root path.
20 This root path must contain a static folder to hold static files (css, js) and a templates folder with at least an index.html file to hold the template of the index.html file to be used.
21 This mode is convenient when you do not already have a WEB server hosting the UI front end.
22 If HTTP files servicing is not needed (REST only or WebSocket/SocketIO mode), the root path can point to any dummy folder.
23
24 Once started, the NFVbench server will be ready to service HTTP or WebSocket/SocketIO requests at the advertised URL.
25
26 Example of NFVbench server start in a container:
27
28 .. code-block:: bash
29
30     # get to the container shell (assume the container name is "nfvbench")
31     docker exec -it nfvbench bash
32     # from the container shell start the NFVbench server in the background
33     nfvbench -c /tmp/nfvbench/nfvbench.cfg --server /tmp &
34     # exit container
35     exit
36
37
38
39 HTTP Interface
40 --------------
41
42 <http-url>/echo (GET)
43 ^^^^^^^^^^^^^^^^^^^^^
44
45 This request simply returns whatever content is sent in the body of the request (body should be in json format, only used for testing)
46
47 Example request: curl -XGET '127.0.0.1:7556/echo' -H "Content-Type: application/json" -d '{"nfvbench": "test"}'
48 Response:
49 {
50   "nfvbench": "test"
51 }
52
53
54 <http-url>/status (GET)
55 ^^^^^^^^^^^^^^^^^^^^^^^
56
57 This request fetches the status of an asynchronous run. It will return in json format:
58
59 - a request pending reply (if the run is still not completed)
60 - an error reply if there is no run pending
61 - or the complete result of the run
62
63 The client can keep polling until the run completes.
64
65 Example of return when the run is still pending:
66
67 .. code-block:: bash
68
69     {
70       "error_message": "nfvbench run still pending",
71       "status": "PENDING"
72     }
73
74 Example of return when the run completes:
75
76 .. code-block:: bash
77
78     {
79       "result": {...}
80       "status": "OK"
81     }
82
83
84 <http-url>/start_run (POST)
85 ^^^^^^^^^^^^^^^^^^^^^
86
87 This request starts an NFVBench run with passed configurations.
88
89 Example request: curl -XPOST 'localhost:7556/start_run' -H "Content-Type: application/json" -d @nfvbenchconfig.json
90
91 See "NFVbench configuration JSON parameter" below for details on how to format this parameter.
92
93 The request returns immediately with a json content indicating if there was an error (status=ERROR) or if the request was submitted successfully (status=PENDING).
94 Example of return when the submission is successful:
95
96 .. code-block:: bash
97
98     {
99       "error_message": "NFVbench run still pending",
100       "request_id": "42cccb7effdc43caa47f722f0ca8ec96",
101       "status": "PENDING"
102     }
103
104 If there is already an NFVBench running then it will return
105
106 .. code-block:: bash
107
108     {
109      "error_message": "there is already an NFVbench request running",
110      "status": "ERROR"
111     }
112
113 WebSocket/SocketIO events
114 -------------------------
115
116 List of SocketIO events supported:
117
118 Client to Server
119 ^^^^^^^^^^^^^^^^
120
121 start_run:
122
123     sent by client to start a new run with the configuration passed in argument (JSON).
124     The configuration can be any valid NFVbench configuration passed as a JSON document (see "NFVbench configuration JSON parameter" below)
125
126 Server to Client
127 ^^^^^^^^^^^^^^^^
128
129 run_interval_stats:
130
131     sent by server to report statistics during a run
132     the message contains the statistics {'time_ms': time_ms, 'tx_pps': tx_pps, 'rx_pps': rx_pps, 'drop_pct': drop_pct}
133
134 ndr_found:
135
136     (during NDR-PDR search)
137     sent by server when the NDR rate is found
138     the message contains the NDR value {'rate_pps': ndr_pps}
139
140 ndr_found:
141
142     (during NDR-PDR search)
143     sent by server when the PDR rate is found
144     the message contains the PDR value {'rate_pps': pdr_pps}
145
146
147 run_end:
148
149     sent by server to report the end of a run
150     the message contains the complete results in JSON format
151
152 NFVbench configuration JSON parameter
153 -------------------------------------
154 The NFVbench configuration describes the parameters of an NFVbench run and can be passed to the NFVbench server as a JSON document.
155
156 Default configuration
157 ^^^^^^^^^^^^^^^^^^^^^
158
159 The simplest JSON document is the empty dictionary "{}" which indicates to use the default NFVbench configuration:
160
161 - PVP
162 - NDR-PDR measurement
163 - 64 byte packets
164 - 1 flow per direction
165
166 The entire default configuration can be viewed using the --show-json-config option on the cli:
167
168 .. code-block:: bash
169
170     # nfvbench --show-config
171     {
172         "availability_zone": null,
173         "compute_node_user": "root",
174         "compute_nodes": null,
175         "debug": false,
176         "duration_sec": 60,
177         "flavor": {
178             "disk": 0,
179             "extra_specs": {
180                 "hw:cpu_policy": "dedicated",
181                 "hw:mem_page_size": 2048
182             },
183             "ram": 8192,
184             "vcpus": 2
185         },
186         "flavor_type": "nfv.medium",
187         "flow_count": 1,
188         "generic_poll_sec": 2,
189         "generic_retry_count": 100,
190         "inter_node": false,
191         "internal_networks": {
192             "left": {
193                 "name": "nfvbench-net0",
194                 "subnet": "nfvbench-subnet0",
195                 "cidr": "192.168.1.0/24",
196             },
197             "right": {
198                 "name": "nfvbench-net1",
199                 "subnet": "nfvbench-subnet1",
200                 "cidr": "192.168.2.0/24",
201             },
202             "middle": {
203                 "name": "nfvbench-net2",
204                 "subnet": "nfvbench-subnet2",
205                 "cidr": "192.168.3.0/24",
206             }
207         },
208         "interval_sec": 10,
209         "json": null,
210         "loop_vm_name": "nfvbench-loop-vm",
211         "measurement": {
212             "NDR": 0.001,
213             "PDR": 0.1,
214             "load_epsilon": 0.1
215         },
216         "name": "(built-in default config)",
217         "no_cleanup": false,
218         "no_int_config": false,
219         "no_reset": false,
220         "no_tor_access": false,
221         "no_traffic": false,
222         "no_vswitch_access": false,
223         "openrc_file": "/tmp/nfvbench/openstack/openrc",
224         "openstack_defaults": "/tmp/nfvbench/openstack/defaults.yaml",
225         "openstack_setup": "/tmp/nfvbench/openstack/setup_data.yaml",
226         "rate": "ndr_pdr",
227         "service_chain": "PVP",
228         "service_chain_count": 1,
229         "sriov": false,
230         "std_json": null,
231         "tor": {
232             "switches": [
233                 {
234                     "host": "172.26.233.12",
235                     "password": "lab",
236                     "port": 22,
237                     "username": "admin"
238                 }
239             ],
240             "type": "N9K"
241         },
242         "traffic": {
243             "bidirectional": true,
244             "profile": "traffic_profile_64B"
245         },
246         "traffic_generator": {
247             "default_profile": "trex-local",
248             "gateway_ip_addrs": [
249                 "1.1.0.2",
250                 "2.2.0.2"
251             ],
252             "gateway_ip_addrs_step": "0.0.0.1",
253             "generator_profile": [
254                 {
255                     "cores": 3,
256                     "interfaces": [
257                         {
258                             "pci": "0a:00.0",
259                             "port": 0,
260                             "switch_port": "Ethernet1/33",
261                             "vlan": null
262                         },
263                         {
264                             "pci": "0a:00.1",
265                             "port": 1,
266                             "switch_port": "Ethernet1/34",
267                             "vlan": null
268                         }
269                     ],
270                     "intf_speed": "10Gbps",
271                     "ip": "127.0.0.1",
272                     "name": "trex-local",
273                     "tool": "TRex"
274                 }
275             ],
276             "host_name": "nfvbench_tg",
277             "ip_addrs": [
278                 "10.0.0.0/8",
279                 "20.0.0.0/8"
280             ],
281             "ip_addrs_step": "0.0.0.1",
282             "mac_addrs": [
283                 "00:10:94:00:0A:00",
284                 "00:11:94:00:0A:00"
285             ],
286             "step_mac": null,
287             "tg_gateway_ip_addrs": [
288                 "1.1.0.100",
289                 "2.2.0.100"
290             ],
291             "tg_gateway_ip_addrs_step": "0.0.0.1"
292         },
293         "traffic_profile": [
294             {
295                 "l2frame_size": [
296                     "64"
297                 ],
298                 "name": "traffic_profile_64B"
299             },
300             {
301                 "l2frame_size": [
302                     "IMIX"
303                 ],
304                 "name": "traffic_profile_IMIX"
305             },
306             {
307                 "l2frame_size": [
308                     "1518"
309                 ],
310                 "name": "traffic_profile_1518B"
311             },
312             {
313                 "l2frame_size": [
314                     "64",
315                     "IMIX",
316                     "1518"
317                 ],
318                 "name": "traffic_profile_3sizes"
319             }
320         ],
321         "unidir_reverse_traffic_pps": 1,
322         "vlan_tagging": true,
323         "vts_ncs": {
324             "host": null,
325             "password": "secret",
326             "port": 22,
327             "username": "admin"
328         }
329     }
330
331
332 Common examples of JSON configuration
333 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
334
335 Use the default configuration but use 10000 flows per direction (instead of 1):
336
337 .. code-block:: bash
338
339     { "flow_count": 10000 }
340
341
342 Use default confguration but with 10000 flows, "EXT" chain and IMIX packet size:
343
344 .. code-block:: bash
345
346     {
347        "flow_count": 10000,
348        "service_chain": "EXT",
349         "traffic": {
350             "profile": "traffic_profile_IMIX"
351         },
352     }
353
354 A short run of 5 seconds at a fixed rate of 1Mpps (and everything else same as the default configuration):
355
356 .. code-block:: bash
357
358     {
359        "duration": 5,
360        "rate": "1Mpps"
361     }
362
363 Example of interaction with the NFVbench server using HTTP and curl
364 -------------------------------------------------------------------
365 HTTP requests can be sent directly to the NFVbench server from CLI using curl from any host that can connect to the server (here we run it from the local host).
366
367 This is a POST request to start a run using the default NFVbench configuration but with traffic generation disabled ("no_traffic" property is set to true):
368
369 .. code-block:: bash
370
371     [root@sjc04-pod3-mgmt ~]# curl -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"no_traffic":true}' http://127.0.0.1:7555/start_run
372     {
373       "error_message": "nfvbench run still pending",
374       "status": "PENDING"
375     }
376     [root@sjc04-pod3-mgmt ~]#
377
378 This request will return immediately with status set to "PENDING" if the request was started successfully.
379
380 The status can be polled until the run completes. Here the poll returns a "PENDING" status, indicating the run is still not completed:
381
382 .. code-block:: bash
383
384     [root@sjc04-pod3-mgmt ~]# curl -G http://127.0.0.1:7555/status
385     {
386       "error_message": "nfvbench run still pending",
387       "status": "PENDING"
388     }
389     [root@sjc04-pod3-mgmt ~]#
390
391 Finally, the status request returns a "OK" status along with the full results (truncated here):
392
393 .. code-block:: bash
394
395     [root@sjc04-pod3-mgmt ~]# curl -G http://127.0.0.1:7555/status
396     {
397       "result": {
398         "benchmarks": {
399           "network": {
400             "service_chain": {
401               "PVP": {
402                 "result": {
403                   "bidirectional": true,
404                   "compute_nodes": {
405                     "nova:sjc04-pod3-compute-4": {
406                       "bios_settings": {
407                         "Adjacent Cache Line Prefetcher": "Disabled",
408                         "All Onboard LOM Ports": "Enabled",
409                         "All PCIe Slots OptionROM": "Enabled",
410                         "Altitude": "300 M",
411     ...
412
413         "date": "2017-03-31 22:15:41",
414         "nfvbench_version": "0.3.5",
415         "openstack_spec": {
416           "encaps": "VxLAN",
417           "vswitch": "VTS"
418         }
419       },
420       "status": "OK"
421     }
422     [root@sjc04-pod3-mgmt ~]#
423
424
425
426 Example of interaction with the NFVbench server using a python CLI app (nfvbench_client)
427 ----------------------------------------------------------------------------------------
428 The module client/client.py contains an example of python class that can be used to control the NFVbench server from a python app using HTTP or WebSocket/SocketIO.
429
430 The module client/nfvbench_client.py has a simple main application to control the NFVbench server from CLI.
431 The "nfvbench_client" wrapper script can be used to invoke the client front end (this wrapper is pre-installed in the NFVbench container)
432
433 Example of invocation of the nfvbench_client front end, from the host (assume the name of the NFVbench container is "nfvbench"),
434 use the default NFVbench configuration but do not generate traffic (no_traffic property set to true, the full json result is truncated here):
435
436 .. code-block:: bash
437
438     [root@sjc04-pod3-mgmt ~]# docker exec -it nfvbench nfvbench_client -c '{"no_traffic":true}' http://127.0.0.1:7555
439     {u'status': u'PENDING', u'error_message': u'nfvbench run still pending'}
440     {u'status': u'PENDING', u'error_message': u'nfvbench run still pending'}
441     {u'status': u'PENDING', u'error_message': u'nfvbench run still pending'}
442
443     {u'status': u'OK', u'result': {u'date': u'2017-03-31 22:04:59', u'nfvbench_version': u'0.3.5',
444     u'config': {u'compute_nodes': None, u'compute_node_user': u'root', u'vts_ncs': {u'username': u'admin', u'host': None, u'password': u'secret', u'port': 22}, u'traffic_generator': {u'tg_gateway_ip_addrs': [u'1.1.0.100', u'2.2.0.100'], u'ip_addrs_step': u'0.0.0.1', u'step_mac': None, u'generator_profile': [{u'intf_speed': u'10Gbps', u'interfaces': [{u'pci': u'0a:00.0', u'port': 0, u'vlan': 1998, u'switch_port': None},
445
446     ...
447
448     [root@sjc04-pod3-mgmt ~]#
449
450 The http interface is used unless --use-socketio is defined.
451
452 Example of invocation using Websocket/SocketIO, execute NFVbench using the default configuration but with a duration of 5 seconds and a fixed rate run of 5kpps.
453
454 .. code-block:: bash
455
456     [root@sjc04-pod3-mgmt ~]# docker exec -it nfvbench nfvbench_client -c '{"duration":5,"rate":"5kpps"}' --use-socketio  http://127.0.0.1:7555 >results.json
457
458
459
460
461
462
463