Merge "Migrate ALTO user docs to rst"
[docs.git] / docs / user-guide / yang-ide-user-guide.rst
1 YANG IDE User Guide
2 ===================
3
4 Overview
5 --------
6
7 The YANG IDE project provides an Eclipse plugin that is used to create,
8 view, and edit Yang model files. It currently supports version 1.0 of
9 the Yang specification.
10
11 The YANG IDE project uses components from the OpenDaylight project for
12 parsing and verifying Yang model files. The "yangtools" parser in
13 OpenDaylight is generally used for generating Java code associated with
14 Yang models. If you are just using the YANG IDE to view and edit Yang
15 models, you do not need to know any more about this.
16
17 Although the YANG IDE plugin is used in Eclipse, it is not necessary to
18 be familiar with the Java programming language to use it effectively.
19
20 The YANG IDE also uses the Maven build tool, but you do not have to be a
21 Maven expert to use it, or even know that much about it. Very little
22 configuration of Maven files will have to be done by you. In fact, about
23 the only thing you will likely ever need to change can be done entirely
24 in the Eclipse GUI forms, without even seeing the internal structure of
25 the Maven POM file (Project Object Model).
26
27 The YANG IDE plugin provides features that are similar to other
28 programming language plugins in the Eclipse ecosystem.
29
30 For instance, you will find support for the following:
31
32 -  Immediate "as-you-type" display of syntactic and semantic errors
33
34 -  Intelligent completion of language tokens, limited to only choices
35    valid in the current scope and namespace
36
37 -  Consistent (and customizable) color-coding of syntactic and semantic
38    symbols
39
40 -  Provides access to remote Yang models by specifying dependency on
41    Maven artifact containing models (or by manual inclusion in project)
42
43 -  One-click navigation to referenced symbols in external files
44
45 -  Mouse hovers display descriptions of referenced components
46
47 -  Tools for refactoring or renaming components respect namespaces
48
49 -  Code templates can be entered for common conventions
50
51 Forthcoming sections of this manual will step through how to utilize
52 these features.
53
54 Creating a Yang Project
55 -----------------------
56
57 After the plugin is installed, the next thing you have to do is create a
58 Yang Project. This is done from the "File" menu, selecting "New", and
59 navigating to the "Yang" section and selecting "YANG Project", and then
60 clicking "Next" for more items to configure.
61
62 Some shortcuts for these steps are the following:
63
64 -  Typically, the key sequence "Ctrl+n" (press "n" while holding down
65    one of the "ctrl" keys) is bound to the "new" function
66
67 -  In the "New" wizard dialog, the initial focus is in the filter field,
68    where you can enter "yang" to limit the choices to only the functions
69    provided by the YANG IDE plugin
70
71 -  On the "New" wizard dialog, instead of clicking the "Next" button
72    with your mouse, you can press "Alt+n" (you will see a hint for this
73    with the "N" being underlined)
74
75 First Yang Project Wizard Page
76 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
77
78 After the "Next" button is pressed, it goes to the first wizard page
79 that is specific to creating Yang projects. you will see a subtitle on
80 this page of "YANG Tools Configuration". In almost all cases, you should
81 be able to click "Next" again on this page to go to the next wizard
82 page.
83
84 However, some information about the fields on this page would be
85 helpful.
86
87 You will see the following labeled fields and sections:
88
89 Yang Files Root Directory
90 ^^^^^^^^^^^^^^^^^^^^^^^^^
91
92 This defaults to "src/main/yang". Except when creating your first Yang
93 file, you, you do not even have to know this, as Eclipse presents the
94 same interface to view your Yang files no matter what you set this to.
95
96 Source Code Generators
97 ^^^^^^^^^^^^^^^^^^^^^^
98
99 If you do not know what this is, you do not need to know about it. The
100 "yangtools" Yang parser from OpenDaylight uses a "code generator"
101 component to generate specific kinds of Java classes from the Yang
102 models. Again, if you do not need to work with the generated Java code,
103 you do not need to change this.
104
105 Create Example YANG File
106 ^^^^^^^^^^^^^^^^^^^^^^^^
107
108 This is likely the only field you will ever have any reason to change.
109 If this checkbox is set, when the YANG IDE creates the Yang project, it
110 will create a sample "acme-system.yang" file which you can view and edit
111 to demonstrate the features of the tool to yourself. If you do not need
112 this file, then either delete it from the project or uncheck the
113 checkbox to prevent its creation.
114
115 When done with the fields on this page, click the "Next" button to go to
116 the next wizard page.
117
118 Second Yang Project Wizard Page
119 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
120
121 This page has a subtitle of "New Maven project". There are several
122 fields on this page, but you will only ever have to see and change the
123 setting of the first field, the "Create a simple project" checkbox. You
124 should always set this ON to avoid the selection of a Maven archetype,
125 which is something you do not need to do for creating a Yang project.
126
127 Click "Next" at the bottom of the page to move to the next wizard page.
128
129 Third Yang Project Wizard Page
130 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
131
132 This also has a subtitle of "New Maven project", but with different
133 fields to set. You will likely only ever set the first two fields, and
134 completely ignore everything else.
135
136 The first field is labeled "Group id" in the "Artifact" section. It
137 really does not matter what you set this to, but it does have to be set
138 to something. For consistency, you might set this to the name or
139 nickname of your organization. Otherwise, there are no constraints on
140 the value of this field.
141
142 The second field is labeled "Artifact id". The value of this field will
143 be used as the name of the project you create, so you will have to think
144 about what you want the project to be called. Also note that this name
145 has to be unique in the Eclipse workspace. You cannot have two projects
146 with the same name.
147
148 After you have set this field, you will notice that the "Next" button is
149 insensitive, but now the "Finish" button is sensitive. You can click
150 "Finish" now (or use the keyboard shortcut of "Alt+f"), and the Yang IDE
151 will finally create your project.
152
153 Creating a Yang File
154 --------------------
155
156 Now that you have created your project, it is time to create your first
157 Yang file.
158
159 When you created the Yang project, you might have noticed the other
160 option next to "YANG Project", which was "YANG File". That is what you
161 will select now. Click "Next" to go to the first wizard page.
162
163 First Yang File Wizard Page
164 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
165
166 This wizard page lets you specify where the new file will be located,
167 and its name.
168
169 You have to select the particular project you want the file to go into,
170 and it needs to go into the "src/main/yang" folder (or a different
171 location if you changed that field when creating the project).
172
173 You then enter the desired name of the file in the "File name". The file
174 name should have no spaces or "special characters" in it. You can
175 specify a ".yang" extent if you want. If you do not specify an extent,
176 the YANG IDE will create it with the ".yang" extent.
177
178 Click "Next" to go to the next wizard page.
179
180 Second Yang File Wizard Page
181 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
182
183 On this wizard page, you set some metadata about the module that is used
184 to initialize the contents of the Yang file.
185
186 It has the following fields:
187
188 Module Name
189 ^^^^^^^^^^^
190
191 This will default to the "base name" of the file name you created. For
192 instance, if the file name you created was "network-setup.yang", this
193 field will default to "network-setup". You should leave this value as
194 is. There is no good reason to define a model with a name different from
195 the file name.
196
197 Namespace
198 ^^^^^^^^^
199
200 This defaults to "urn:opendaylight:xxx", where "xxx" is the "base name"
201 of the file name you created. You should put a lot of thought into
202 designing a namespace naming scheme that is used throughout your
203 organization. It is quite common for this namespace value to look like a
204 "http" URL, but note that that is just a convention, and will not
205 necessarily imply that there is a web page residing at that HTTP
206 address.
207
208 Prefix
209 ^^^^^^
210
211 This defaults to the "base name" of the file name you created. It mostly
212 does not technically matter what you set this to, as long as it is not
213 empty. Conventionally, it should be a "nickname" that is used to refer
214 to the given namespace in an abbreviated form, when referenced in an
215 "import" statement in another Yang model file.
216
217 Revision
218 ^^^^^^^^
219
220 This has to be a date value in the form of "yyyy-mm-dd", representing
221 the last modified date of this Yang model. The value will default to the
222 current date.
223
224 Revision Description
225 ^^^^^^^^^^^^^^^^^^^^
226
227 This is just human-readable text, which will go into the "description"
228 field underneath the Yang "revision" field, which will describe what
229 went into this revision.
230
231 When all the fields have the content you want, click the "Finish" button
232 to set the YANG IDE create the file in the specified location. It will
233 then present the new file in the editor view for additional
234 modifications.
235
236 Accessing Artifacts for Yang Model Imports
237 ------------------------------------------
238
239 You might be working on Yang models that are "abstract" or are intended
240 to be imported by other Yang models. You might also, and more likely, be
241 working on Yang models that import other "abstract" Yang models.
242
243 Assuming you are in that latter more common group, you need to consider
244 for yourself, and for your organization, how you are going to get access
245 to those models that you import.
246
247 You could use a very simple and primitive approach of somehow obtaining
248 those models from some source as plain files and just copying them into
249 the "src/main/yang" folder of your project. For a simple demo or a
250 "one-off" very short project, that might be sufficient.
251
252 A more robust and maintainable approach would be to reference
253 "coordinates" of the artifacts containing Yang models to import. When
254 you specify unique coordinates associated with that artifact, the Yang
255 IDE can retrieve the artifact in the background and make it available
256 for your "import" statements.
257
258 Those "coordinates" that I speak of refer to the Maven concepts of
259 "group id", "artifact id", and "version". you may remember "group id"
260 and "artifact id" from the wizard page for creating a Yang project. It
261 is the same idea. If you ever produce Yang model artifacts that other
262 people are going to import, you will want to think more about what you
263 set those values to when you created the project.
264
265 For example, the OpenDaylight project produces several importable
266 artifacts that you can specify to get access to common Yang models.
267
268 Turning on Indexing for Maven Repositories
269 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
270
271 Before we talk about how to add dependencies to Maven artifacts with
272 Yang models for import, I need to explain how to make it easier to find
273 those artifacts.
274
275 In the Yang project that you have created, the "pom.xml" file (also
276 called a "POM file") is the file that Maven uses to specify
277 dependencies. We will talk about that in a minute, but first we need to
278 talk about "repositories". These are where artifacts are stored.
279
280 We are going to have Eclipse show us the "Maven Repositories" view. In
281 the main menu, select "Window" and then "Show View", and then "Other".
282 Like in the "New" dialog, you can enter "maven" in the filter field to
283 limit the list to views with "maven" in the name. Click on the "Maven
284 Repositories" entry and click OK.
285
286 This will usually create the view in the bottom panel of the window.
287
288 The view presents an outline view of four principal elements:
289
290 -  Local Repositories
291
292 -  Global Repositories
293
294 -  Project Repositories
295
296 -  Custom Repositories
297
298 For this purpose, the only section you care about is "Project
299 Repositories", being the repositories that are only specified in the POM
300 for the project. There should be a "right-pointing arrow" icon on the
301 line. Click that to expand the entry.
302
303 You should see two entries there:
304
305 -  opendaylight-release
306
307 -  opendaylight-snapshot
308
309 You will also see internet URLs associated with each of those
310 repositories.
311
312 For this purpose, you only care about the first one. Right-click on that
313 entry and select "Full Index Enabled". The first time you do this on the
314 first project you create, it will spend several minutes walking the
315 entire tree of artifacts available at that repository and "indexing" all
316 of those components. When this is done, searching for available
317 artifacts in that repository will go very quickly.
318
319 Adding Dependencies Containing Yang Models
320 ------------------------------------------
321
322 Double-click the "pom.xml" file in your project. Instead of just
323 bringing up the view of an XML file (although you can see that if you
324 like), it presents a GUI form editor with a handful of tabs.
325
326 The first tab, "Overview", shows things like the "Group Id", "Artifact
327 Id", and "Version", which represents the "Maven coordinate" of your
328 project, which I have mentioned before.
329
330 Now click on the "Dependencies" tab. You will now see two list
331 components, labeled "Dependencies" and "Dependency Management". You only
332 care about the "Dependencies" section.
333
334 In the "Dependencies" section, you should see one dependency for an
335 artifact called "yang-binding". This artifact is part of OpenDaylight,
336 but you do not need to know anything about it.
337
338 Now click the "Add" button.
339
340 This brings up a dialog titled "Select Dependency". It has three fields
341 at the top labeled "Group Id", "Artifact Id", and "Version", with a
342 "Scope" dropdown. You will never have a need to change the "Scope"
343 dropdown, so ignore it. Despite the fact that you will need to get
344 values into these fields, in general usage, you will never have to
345 manually enter values into them, but you will see values being inserted
346 into these fields by the next steps I describe.
347
348 Below those fields is a field labeled "Enter groupId, artifactId …".
349 This is effectively a "filter field", like on the "New" dialog, but
350 instead of limiting the list from a short list of choices, the value you
351 enter there will be matched against all of the artifacts that were
352 indexed in the "opendaylight-release" repository (and others). It will
353 match the string you enter as a substring of any groupId or artifactId.
354
355 For all of the entries that match that substring, it will list an entry
356 showing the groupId and artifactId, with an expansion arrow. If you open
357 it by clicking on the arrow, you will see individual entries
358 corresponding to each available version of that artifact, along with
359 some metadata about the artifacts between square brackets, mostly
360 indicating what "type" of artifact is.
361
362 For your purposes, you only ever want to use "bundle" or "jar"
363 artifacts.
364
365 Let us consider an example that many people will probably be using.
366
367 In the filter field, enter "ietf-yang-types". Depending on what versions
368 are available, you should see a small handful of "groupId, artifactId"
369 entries there. One of them should be groupId
370 "org.opendaylight.mdsal.model" and artifactId "ietf-yang-types". Click
371 on the expansion arrow to open that.
372
373 What you will see at this point depends on what versions are available.
374 You will likely want to select the newest one (most likely top of the
375 list) that is also either a "bundle" or "jar" type artifact.
376
377 If you click on that resulting version entry, you should notice at this
378 point that the "Group Id", "Artifact Id", and "Version" fields at the
379 top of the dialog are now filled in with the values corresponding to
380 this artifact and version.
381
382 If this is the version that you want, click OK and this artifact will be
383 added to the dependencies in the POM.
384
385 This will now make the Yang models found in that artifact available in
386 "import" statements in Yang models, not to mention the completion
387 choices for that "import" statement.
388