Refactoring ietf-interfaces and ietf-interfaces-state
[honeycomb.git] / v3po / api / src / main / yang / v3po.yang
1 module v3po {
2   yang-version 1;
3   namespace "urn:opendaylight:params:xml:ns:yang:v3po";
4   prefix "v3po";
5
6   revision "2015-01-05" {
7     description "Initial revision of v3po model";
8   }
9
10   import iana-if-type {
11     prefix "ianaift";
12   }
13   import ietf-interfaces {
14     prefix "if";
15   }
16   import ietf-yang-types {
17     prefix "yang";
18   }
19   import ietf-inet-types {
20     prefix "inet";
21   }
22   import ietf-ip {
23     prefix "ip";
24   }
25   import yang-ext {
26     prefix "ext";
27   }
28
29   typedef bridge-domain-ref {
30     type leafref {
31       path "/vpp/bridge-domains/bridge-domain/name";
32     }
33     description
34       "This type is used by to reference a bridge domain table";
35   }
36
37   typedef bridged-virtual-interface-ref {
38     type leafref {
39       path "/if:interfaces/if:interface/l2/bridged-virtual-interface";
40     }
41     description
42       "This type is used by to reference a bridged virtual interface";
43   }
44
45   typedef vlan-type {
46     type enumeration {
47       enum 802dot1q;
48       enum 802dot1ad;
49     }
50   }
51
52   typedef tag-rewrite-operation {
53     type enumeration {
54       enum disabled;
55       enum push-1;
56       enum push-2;
57       enum pop-1;
58       enum pop-2;
59       enum translate-1-to-1;
60       enum translate-1-to-2;
61       enum translate-2-to-1;
62       enum translate-2-to-2;
63     }
64   }
65
66   typedef vlan-tag {
67     type uint16 {
68       range "1..4094";
69     }
70   }
71
72   identity vxlan-tunnel {
73     base if:interface-type;
74   }
75
76   identity vhost-user {
77     base if:interface-type;
78   }
79
80   identity tap {
81     base if:interface-type;
82   }
83
84   identity sub-interface {
85     base if:interface-type;
86   }
87
88   typedef vxlan-vni {
89     // FIXME: should be in a vxlan-specific model
90     description "VNI used in a VXLAN tunnel";
91     type uint32 {
92       range "0..16777215";
93     }
94   }
95
96   typedef vhost-user-role {
97     type enumeration {
98       enum "server";
99       enum "client";
100     }
101   }
102
103   grouping bridge-domain-attributes {
104     leaf flood {
105       type boolean;
106       default true;
107       description
108       "Enable/disable L2 flooding.";
109     }
110     leaf forward {
111       type boolean;
112       default true;
113       description
114       "Enable/disable L2 forwarding.";
115     }
116     leaf learn {
117       type boolean;
118       default true;
119       description
120       "Enable/disable L2 learning.";
121     }
122     leaf unknown-unicast-flood {
123       type boolean;
124       default true;
125     }
126     leaf arp-termination {
127       type boolean;
128       default false;
129     }
130   }
131
132   grouping sub-interface-base-attributes {
133     leaf identifier {
134       type uint32;
135     }
136     leaf vlan-type {
137       type vlan-type;
138       default '802dot1q';
139     }
140     leaf number-of-tags {
141       type uint8 {
142         range "0..2";
143       }
144       default 1;
145     }
146     leaf outer-id {
147       type vlan-tag;
148     }
149     leaf inner-id {
150       type vlan-tag;
151     }
152     leaf match-any-outer-id {
153       type empty;
154     }
155     leaf match-any-inner-id {
156       type empty;
157     }
158     leaf exact-match {
159       type empty;
160     }
161     leaf default-subif {
162       type empty;
163     }
164   }
165
166   grouping tap-interface-base-attributes {
167     leaf tap-name {
168       type string;
169     }
170   }
171
172   grouping tap-interface-config-attributes {
173     leaf mac {
174       type yang:phys-address;
175       mandatory false;
176       description "Mac address to be set for the tap interface. Random will be used if not configured";
177     }
178
179     leaf device-instance {
180       type uint32;
181       mandatory false;
182       description "Custom device instance. Autogenerated will be used if not configured";
183     }
184   }
185
186   grouping ethernet-base-attributes {
187     leaf mtu {
188       type uint16 {
189         range "64..9216";
190       }
191       units "octets";
192       default 9216;
193       description
194       "The size, in octets, of the largest packet that the
195        hardware interface will send and receive.";
196     }
197   }
198
199   grouping ethernet-state-attributes {
200     leaf manufacturer-description {
201       type string;
202       config false;
203     }
204     leaf duplex {
205       type enumeration {
206         enum "half";
207         enum "full";
208       }
209       config false;
210     }
211   }
212
213   grouping vhost-user-interface-base-attributes {
214     leaf socket {
215       type string {
216         length 1..255;
217       }
218     }
219     leaf role {
220       type vhost-user-role;
221       default "server";
222     }
223     description "vhost-user settings";
224   }
225
226   grouping vhost-user-interface-state-attributes {
227     leaf features {
228       type uint64;
229       config false;
230     }
231     leaf virtio-net-hdr-size {
232       type uint32;
233       config false;
234     }
235     leaf num-memory-regions {
236       type uint32;
237       config false;
238     }
239     leaf connect-error {
240       type string;
241       config false;
242     }
243   }
244
245   grouping vxlan-base-attributes {
246     // FIXME: this should be in an vxlan-specific extension
247     leaf src {
248       /*mandatory true;*/
249       type inet:ip-address;
250     }
251     leaf dst {
252       /*mandatory true;*/
253       type inet:ip-address;
254     }
255     leaf vni {
256       /*mandatory true;*/
257       type vxlan-vni;
258     }
259     leaf encap-vrf-id {
260       type uint32;
261     }
262   }
263
264   grouping vlan-tag-rewrite-attributes {
265     leaf rewrite-operation {
266       type tag-rewrite-operation;
267       default 'disabled';
268     }
269     leaf first-pushed {
270       type vlan-type;
271       default '802dot1q';
272     }
273     leaf tag1 {
274       type vlan-tag;
275     }
276     leaf tag2 {
277       type vlan-tag;
278     }
279   }
280
281   grouping l2-attributes {
282       description
283       "Parameters for configuring Layer2 features on interfaces.";
284
285       choice interconnection {
286         case xconnect-based {
287           leaf xconnect-outgoing-interface {
288             /* Don't allow selection of this interface */
289             must "../../if:name != current()";
290             type if:interface-ref; // todo use interface-state-ref for operational data?
291             description
292               "L2 xconnect mode";
293           }
294         }
295         case bridge-based {
296           leaf bridge-domain {
297             type bridge-domain-ref;
298             description
299               "Interfaces in a bridge-domain forward packets to other
300                interfaces in the same bridge-domain based on
301                destination mac address.";
302           }
303           leaf split-horizon-group {
304             when "../bridge-domain";
305             type uint8 {
306               range "0..255";
307             }
308             default 0;
309             description
310               "Interface's split-horizon group. Interfaces in the same
311                bridge-domain and split-horizon group can not forward
312                packets between each other. ";
313           }
314           leaf bridged-virtual-interface {
315             when "../bridge-domain";
316             type boolean;
317             default false;
318             description
319               "Interface forward packets in the bridge-domain
320                associated with the BVI.";
321           }
322         }
323       }
324       container vlan-tag-rewrite { // todo valid only for sub-interfaces
325         uses vlan-tag-rewrite-attributes;
326       }
327   }
328
329   augment /if:interfaces/if:interface {
330     ext:augment-identifier "vpp-interface-augmentation";
331
332     // FIXME using ietf-interfaces model for vpp interfaces makes it hard to implement because:
333     // 1. The link between interface type and this augmentation is unclear
334     // 2. Only this augmentation with combination of ifc type is trigger to do something for vpp, what if user only configures base interface stuff ? + We need to get leaves defined by ietf-interfaces when we are processing this augment
335     // 3. The ietf-interfaces model does not define groupings which makes types reuse difficult
336
337     container sub-interface {
338       when "../if:type = 'v3po:sub-interface'";
339       leaf super-interface {
340         type if:interface-ref;
341       }
342       uses sub-interface-base-attributes;
343     }
344
345     container tap {
346       when "../if:type = 'v3po:tap'";
347       uses tap-interface-base-attributes;
348       uses tap-interface-config-attributes;
349     }
350
351     container ethernet {
352       when "../if:type = 'ianaift:ethernetCsmacd'";
353       uses ethernet-base-attributes;
354     }
355
356     container routing {
357       leaf vrf-id { // todo no routing info for oper, is it possible to get it from the vpp?
358         type uint32;
359         default 0;
360       }
361     }
362
363     container vhost-user {
364       when "../if:type = 'v3po:vhost-user'";
365       uses vhost-user-interface-base-attributes;
366     }
367
368     container vxlan {
369       when "../if:type = 'v3po:vxlan-tunnel'";
370       uses vxlan-base-attributes;
371     }
372
373     container l2 {
374       must "(not (../if:ipv4[if:enabled = 'true']/if:address/if:ip) and " +
375       "not (../if:ipv6[if:enabled = 'true']/if:address/if:ip))";
376
377       uses l2-attributes;
378     }
379   }
380
381   container vpp {
382     description
383     "VPP config data";
384
385     container bridge-domains {
386       list bridge-domain {
387         key "name";
388         // TODO: where does this come from?
389         max-elements 1024;
390
391         leaf name {
392           type string;
393         }
394
395         uses bridge-domain-attributes;
396
397         list l2-fib {
398           key "phys-address";
399
400           leaf phys-address {
401             type yang:phys-address;
402           }
403           leaf action {
404             type enumeration {
405               enum "forward";
406               enum "filter";
407             }
408             mandatory true;
409           }
410           leaf outgoing-interface {
411             type if:interface-ref;
412           }
413         }
414       }
415     }
416   }
417
418   augment /if:interfaces-state/if:interface {
419     ext:augment-identifier "vpp-interface-state-augmentation";
420
421     leaf description {
422       type string;
423     }
424
425     container sub-interface {
426       when "../if:type = 'v3po:sub-interface'";
427       leaf super-interface {
428         type if:interface-state-ref;
429       }
430       uses sub-interface-base-attributes;
431     }
432
433     container tap {
434       when "../if:type = 'v3po:tap'";
435       uses tap-interface-base-attributes;
436     }
437
438     container ethernet {
439       when "../if:type = 'ianaift:ethernetCsmacd'";
440       uses ethernet-base-attributes;
441       uses ethernet-state-attributes;
442     }
443
444     container vhost-user {
445       when "../if:type = 'v3po:vhost-user'";
446       uses vhost-user-interface-base-attributes;
447       uses vhost-user-interface-state-attributes;
448     }
449
450     container vxlan {
451       when "../if:type = 'v3po:vxlan-tunnel'";
452       uses vxlan-base-attributes;
453     }
454
455     container l2 {
456       must "(not (../if:ipv4[if:enabled = 'true']/if:address/if:ip) and " +
457       "not (../if:ipv6[if:enabled = 'true']/if:address/if:ip))";
458
459       uses l2-attributes;
460     }
461   }
462
463   augment /if:interfaces-state/if:interface/if:statistics {
464     ext:augment-identifier "vpp-interface-statistics-augmentation";
465     leaf in-errors-no-buf {
466       type yang:counter64;
467     }
468     leaf in-errors-miss {
469       type yang:counter64;
470     }
471     leaf out-discards-fifo-full {
472       type yang:counter64;
473     }
474   }
475
476   container vpp-state {
477     config false;
478
479     description
480       "VPP operational data";
481
482     container bridge-domains {
483       // FIXME: Should this live in bridge-domain.yang in a modular fashion ?
484       list bridge-domain {
485
486         key "name";
487         leaf name {
488           type string;
489         }
490
491         uses bridge-domain-attributes;
492
493         list interface {
494           key "name";
495
496           leaf name {
497             type if:interface-state-ref;
498           }
499
500           leaf split-horizon-group {
501             type uint8;
502           }
503
504           leaf bridged-virtual-interface {
505             type boolean;
506           }
507         }
508
509         list l2-fib {
510           key "phys-address";
511
512           leaf phys-address {
513             type yang:phys-address;
514           }
515           leaf static-config {
516             type boolean;
517           }
518           leaf outgoing-interface {
519             when "../v3po:action = 'forward'";
520             type if:interface-state-ref;
521           }
522           leaf action {
523             type enumeration {
524               enum "forward";
525               enum "filter";
526             }
527             mandatory true;
528           }
529           leaf bridged-virtual-interface {
530             when "../v3po:action = 'forward'";
531             type boolean;
532           }
533         }
534         description
535           "bridge-domain operational data";
536       }
537     }
538
539     container version {
540       leaf name {
541         type string;
542       }
543       leaf build-directory {
544         type string;
545       }
546       leaf build-date {
547         type string;
548       }
549       leaf branch {
550         type string;
551       }
552       description
553       "vlib version info";
554     }
555   }
556 }