Replace supported admonitions with rst directives
[docs.git] / docs / developer-guide / ttp-model-developer-guide.rst
1 TTP Model Developer Guide
2 =========================
3
4 Overview
5 --------
6
7 Table Type Patterns are a specification developed by the `Open
8 Networking Foundation <https://www.opennetworking.org/>`__ to enable the
9 description and negotiation of subsets of the OpenFlow protocol. This is
10 particularly useful for hardware switches that support OpenFlow as it
11 enables the to describe what features they do (and thus also what
12 features they do not) support. More details can be found in the full
13 specification listed on the `OpenFlow specifications
14 page <https://www.opennetworking.org/sdn-resources/onf-specifications/openflow>`__.
15
16 TTP Model Architecture
17 ----------------------
18
19 The TTP Model provides a YANG-modeled type for a TTP and allows them to
20 be associated with a master list of known TTPs, as well as active and
21 supported TTPs with nodes in the MD-SAL inventory model.
22
23 Key APIs and Interfaces
24 -----------------------
25
26 The key API provided by the TTP Model feature is the ability to store a
27 set of TTPs in the MD-SAL as well as associate zero or one active TTPs
28 and zero or more supported TTPs along with a given node in the MD-SAL
29 inventory model.
30
31 API Reference Documentation
32 ---------------------------
33
34 RESTCONF
35 ~~~~~~~~
36
37 See the generated RESTCONF API documentation at:
38 http://localhost:8181/apidoc/explorer/index.html
39
40 Look for the onf-ttp module to expand and see the various RESTCONF APIs.
41
42 Java Bindings
43 ~~~~~~~~~~~~~
44
45 As stated above there are 3 locations where a Table Type Pattern can be
46 placed into the MD-SAL Data Store. They correspond to 3 different REST
47 API URIs:
48
49 1. ``restconf/config/onf-ttp:opendaylight-ttps/onf-ttp:table-type-patterns/``
50
51 2. ``restconf/config/opendaylight-inventory:nodes/node/{id}/ttp-inventory-node:active_ttp/``
52
53 3. ``restconf/config/opendaylight-inventory:nodes/node/{id}/ttp-inventory-node:supported_ttps/``
54
55 .. note::
56
57     Typically, these URIs are running on the machine the controller is
58     on at port 8181. If you are on the same machine they can thus be
59     accessed at ``http://localhost:8181/<uri>``
60
61 Using the TTP Model RESTCONF APIs
62 ---------------------------------
63
64 Setting REST HTTP Headers
65 ~~~~~~~~~~~~~~~~~~~~~~~~~
66
67 Authentication
68 ^^^^^^^^^^^^^^
69
70 The REST API calls require authentication by default. The default method
71 is to use basic auth with a user name and password of ‘admin’.
72
73 Content-Type and Accept
74 ^^^^^^^^^^^^^^^^^^^^^^^
75
76 RESTCONF supports both xml and json. This example focuses on JSON, but
77 xml can be used just as easily. When doing a PUT or POST be sure to
78 specify the appropriate ``Conetnt-Type`` header: either
79 ``application/json`` or ``application/xml``.
80
81 When doing a GET be sure to specify the appropriate ``Accept`` header:
82 again, either ``application/json`` or ``application/xml``.
83
84 Content
85 ~~~~~~~
86
87 The contents of a PUT or POST should be a OpenDaylight Table Type
88 Pattern. An example of one is provided below. The example can also be
89 found at `parser/sample-TTP-from-tests.ttp in the TTP git
90 repository <https://git.opendaylight.org/gerrit/gitweb?p=ttp.git;a=blob;f=parser/sample-TTP-from-tests.ttp;h=45130949b25c6f86b750959d27d04ec2208935fb;hb=HEAD>`__.
91
92 **Sample Table Type Pattern (json).**
93
94 ::
95
96     {
97         "table-type-patterns": {
98             "table-type-pattern": [
99                 {
100                     "security": {
101                         "doc": [
102                             "This TTP is not published for use by ONF. It is an example and for",
103                             "illustrative purposes only.",
104                             "If this TTP were published for use it would include",
105                             "guidance as to any security considerations in this doc member."
106                         ]
107                     },
108                     "NDM_metadata": {
109                         "authority": "org.opennetworking.fawg",
110                         "OF_protocol_version": "1.3.3",
111                         "version": "1.0.0",
112                         "type": "TTPv1",
113                         "doc": [
114                             "Example of a TTP supporting L2 (unicast, multicast, flooding), L3 (unicast only),",
115                             "and an ACL table."
116                         ],
117                         "name": "L2-L3-ACLs"
118                     },
119                     "identifiers": [
120                         {
121                             "doc": [
122                                 "The VLAN ID of a locally attached L2 subnet on a Router."
123                             ],
124                             "var": "<subnet_VID>"
125                         },
126                         {
127                             "doc": [
128                                 "An OpenFlow group identifier (integer) identifying a group table entry",
129                                 "of the type indicated by the variable name"
130                             ],
131                             "var": "<<group_entry_types/name>>"
132                         }
133                     ],
134                     "features": [
135                         {
136                             "doc": [
137                                 "Flow entry notification Extension – notification of changes in flow entries"
138                             ],
139                             "feature": "ext187"
140                         },
141                         {
142                             "doc": [
143                                 "Group notifications Extension – notification of changes in group or meter entries"
144                             ],
145                             "feature": "ext235"
146                         }
147                     ],
148                     "meter_table": {
149                         "meter_types": [
150                             {
151                                 "name": "ControllerMeterType",
152                                 "bands": [
153                                     {
154                                         "type": "DROP",
155                                         "rate": "1000..10000",
156                                         "burst": "50..200"
157                                     }
158                                 ]
159                             },
160                             {
161                                 "name": "TrafficMeter",
162                                 "bands": [
163                                     {
164                                         "type": "DSCP_REMARK",
165                                         "rate": "10000..500000",
166                                         "burst": "50..500"
167                                     },
168                                     {
169                                         "type": "DROP",
170                                         "rate": "10000..500000",
171                                         "burst": "50..500"
172                                     }
173                                 ]
174                             }
175                         ],
176                         "built_in_meters": [
177                             {
178                                 "name": "ControllerMeter",
179                                 "meter_id": 1,
180                                 "type": "ControllerMeterType",
181                                 "bands": [
182                                     {
183                                         "rate": 2000,
184                                         "burst": 75
185                                     }
186                                 ]
187                             },
188                             {
189                                 "name": "AllArpMeter",
190                                 "meter_id": 2,
191                                 "type": "ControllerMeterType",
192                                 "bands": [
193                                     {
194                                         "rate": 1000,
195                                         "burst": 50
196                                     }
197                                 ]
198                             }
199                         ]
200                     },
201                     "table_map": [
202                         {
203                             "name": "ControlFrame",
204                             "number": 0
205                         },
206                         {
207                             "name": "IngressVLAN",
208                             "number": 10
209                         },
210                         {
211                             "name": "MacLearning",
212                             "number": 20
213                         },
214                         {
215                             "name": "ACL",
216                             "number": 30
217                         },
218                         {
219                             "name": "L2",
220                             "number": 40
221                         },
222                         {
223                             "name": "ProtoFilter",
224                             "number": 50
225                         },
226                         {
227                             "name": "IPv4",
228                             "number": 60
229                         },
230                         {
231                             "name": "IPv6",
232                             "number": 80
233                         }
234                     ],
235                     "parameters": [
236                         {
237                             "doc": [
238                                 "documentation"
239                             ],
240                             "name": "Showing-curt-how-this-works",
241                             "type": "type1"
242                         }
243                     ],
244                     "flow_tables": [
245                         {
246                             "doc": [
247                                 "Filters L2 control reserved destination addresses and",
248                                 "may forward control packets to the controller.",
249                                 "Directs all other packets to the Ingress VLAN table."
250                             ],
251                             "name": "ControlFrame",
252                             "flow_mod_types": [
253                                 {
254                                     "doc": [
255                                         "This match/action pair allows for flow_mods that match on either",
256                                         "ETH_TYPE or ETH_DST (or both) and send the packet to the",
257                                         "controller, subject to metering."
258                                     ],
259                                     "name": "Frame-To-Controller",
260                                     "match_set": [
261                                         {
262                                             "field": "ETH_TYPE",
263                                             "match_type": "all_or_exact"
264                                         },
265                                         {
266                                             "field": "ETH_DST",
267                                             "match_type": "exact"
268                                         }
269                                     ],
270                                     "instruction_set": [
271                                         {
272                                             "doc": [
273                                                 "This meter may be used to limit the rate of PACKET_IN frames",
274                                                 "sent to the controller"
275                                             ],
276                                             "instruction": "METER",
277                                             "meter_name": "ControllerMeter"
278                                         },
279                                         {
280                                             "instruction": "APPLY_ACTIONS",
281                                             "actions": [
282                                                 {
283                                                     "action": "OUTPUT",
284                                                     "port": "CONTROLLER"
285                                                 }
286                                             ]
287                                         }
288                                     ]
289                                 }
290                             ],
291                             "built_in_flow_mods": [
292                                 {
293                                     "doc": [
294                                         "Mandatory filtering of control frames with C-VLAN Bridge reserved DA."
295                                     ],
296                                     "name": "Control-Frame-Filter",
297                                     "priority": "1",
298                                     "match_set": [
299                                         {
300                                             "field": "ETH_DST",
301                                             "mask": "0xfffffffffff0",
302                                             "value": "0x0180C2000000"
303                                         }
304                                     ]
305                                 },
306                                 {
307                                     "doc": [
308                                         "Mandatory miss flow_mod, sends packets to IngressVLAN table."
309                                     ],
310                                     "name": "Non-Control-Frame",
311                                     "priority": "0",
312                                     "instruction_set": [
313                                         {
314                                             "instruction": "GOTO_TABLE",
315                                             "table": "IngressVLAN"
316                                         }
317                                     ]
318                                 }
319                             ]
320                         }
321                     ],
322                     "group_entry_types": [
323                         {
324                             "doc": [
325                                 "Output to a port, removing VLAN tag if needed.",
326                                 "Entry per port, plus entry per untagged VID per port."
327                             ],
328                             "name": "EgressPort",
329                             "group_type": "INDIRECT",
330                             "bucket_types": [
331                                 {
332                                     "name": "OutputTagged",
333                                     "action_set": [
334                                         {
335                                             "action": "OUTPUT",
336                                             "port": "<port_no>"
337                                         }
338                                     ]
339                                 },
340                                 {
341                                     "name": "OutputUntagged",
342                                     "action_set": [
343                                         {
344                                             "action": "POP_VLAN"
345                                         },
346                                         {
347                                             "action": "OUTPUT",
348                                             "port": "<port_no>"
349                                         }
350                                     ]
351                                 },
352                                 {
353                                     "opt_tag": "VID-X",
354                                     "name": "OutputVIDTranslate",
355                                     "action_set": [
356                                         {
357                                             "action": "SET_FIELD",
358                                             "field": "VLAN_VID",
359                                             "value": "<local_vid>"
360                                         },
361                                         {
362                                             "action": "OUTPUT",
363                                             "port": "<port_no>"
364                                         }
365                                     ]
366                                 }
367                             ]
368                         }
369                     ],
370                     "flow_paths": [
371                         {
372                             "doc": [
373                                 "This object contains just a few examples of flow paths, it is not",
374                                 "a comprehensive list of the flow paths required for this TTP.  It is",
375                                 "intended that the flow paths array could include either a list of",
376                                 "required flow paths or a list of specific flow paths that are not",
377                                 "required (whichever is more concise or more useful."
378                             ],
379                             "name": "L2-2",
380                             "path": [
381                                 "Non-Control-Frame",
382                                 "IV-pass",
383                                 "Known-MAC",
384                                 "ACLskip",
385                                 "L2-Unicast",
386                                 "EgressPort"
387                             ]
388                         },
389                         {
390                             "name": "L2-3",
391                             "path": [
392                                 "Non-Control-Frame",
393                                 "IV-pass",
394                                 "Known-MAC",
395                                 "ACLskip",
396                                 "L2-Multicast",
397                                 "L2Mcast",
398                                 "[EgressPort]"
399                             ]
400                         },
401                         {
402                             "name": "L2-4",
403                             "path": [
404                                 "Non-Control-Frame",
405                                 "IV-pass",
406                                 "Known-MAC",
407                                 "ACL-skip",
408                                 "VID-flood",
409                                 "VIDflood",
410                                 "[EgressPort]"
411                             ]
412                         },
413                         {
414                             "name": "L2-5",
415                             "path": [
416                                 "Non-Control-Frame",
417                                 "IV-pass",
418                                 "Known-MAC",
419                                 "ACLskip",
420                                 "L2-Drop"
421                             ]
422                         },
423                         {
424                             "name": "v4-1",
425                             "path": [
426                                 "Non-Control-Frame",
427                                 "IV-pass",
428                                 "Known-MAC",
429                                 "ACLskip",
430                                 "L2-Router-MAC",
431                                 "IPv4",
432                                 "v4-Unicast",
433                                 "NextHop",
434                                 "EgressPort"
435                             ]
436                         },
437                         {
438                             "name": "v4-2",
439                             "path": [
440                                 "Non-Control-Frame",
441                                 "IV-pass",
442                                 "Known-MAC",
443                                 "ACLskip",
444                                 "L2-Router-MAC",
445                                 "IPv4",
446                                 "v4-Unicast-ECMP",
447                                 "L3ECMP",
448                                 "NextHop",
449                                 "EgressPort"
450                             ]
451                         }
452                     ]
453                 }
454             ]
455         }
456     }
457
458 Making a REST Call
459 ~~~~~~~~~~~~~~~~~~
460
461 In this example we’ll do a PUT to install the sample TTP from above into
462 OpenDaylight and then retrieve it both as json and as xml. We’ll use the
463 `Postman - REST
464 Client <https://chrome.google.com/webstore/detail/postman-rest-client/fdmmgilgnpjigdojojpjoooidkmcomcm>`__
465 for Chrome in the examples, but any method of accessing REST should
466 work.
467
468 First, we’ll fill in the basic information:
469
470 .. figure:: ./images/ttp-screen1-basic-auth.png
471    :alt: Filling in URL, content, Content-Type and basic auth
472
473    Filling in URL, content, Content-Type and basic auth
474
475 1. Set the URL to
476    ``http://localhost:8181/restconf/config/onf-ttp:opendaylight-ttps/onf-ttp:table-type-patterns/``
477
478 2. Set the action to ``PUT``
479
480 3. Click Headers and
481
482 4. Set a header for ``Content-Type`` to ``application/json``
483
484 5. Make sure the content is set to raw and
485
486 6. Copy the sample TTP from above into the content
487
488 7. Click the Basic Auth tab and
489
490 8. Set the username and password to admin
491
492 9. Click Refresh headers
493
494 .. figure:: ./images/ttp-screen2-applied-basic-auth.png
495    :alt: Refreshing basic auth headers
496
497    Refreshing basic auth headers
498
499 After clicking Refresh headers, we can see that a new header
500 (``Authorization``) has been created and this will allow us to
501 authenticate to make the REST call.
502
503 .. figure:: ./images/ttp-screen3-sent-put.png
504    :alt: PUTting a TTP
505
506    PUTting a TTP
507
508 At this point, clicking send should result in a Status response of ``200
509 OK`` indicating we’ve successfully PUT the TTP into OpenDaylight.
510
511 .. figure:: ./images/ttp-screen4-get-json.png
512    :alt: Retrieving the TTP as json via a GET
513
514    Retrieving the TTP as json via a GET
515
516 We can now retrieve the TTP by:
517
518 1. Changing the action to ``GET``
519
520 2. Setting an ``Accept`` header to ``application/json`` and
521
522 3. Pressing send
523
524 .. figure:: ./images/ttp-screen5-get-xml.png
525    :alt: Retrieving the TTP as xml via a GET
526
527    Retrieving the TTP as xml via a GET
528
529 The same process can retrieve the content as xml by setting the
530 ``Accept`` header to ``application/xml``.
531