Update l2 constaint in v3po.yang
[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 "2016-12-14" {
7     description
8       "This revision adds the following new features:
9        - ingress/egress ACLs support
10        - moved ACL definitions to vpp-acl module
11        - updated l2 container constraint (permit IP address on BVI interface)";
12   }
13
14   revision "2015-01-05" {
15     description "Initial revision of v3po model";
16   }
17
18   import iana-if-type {
19     prefix "ianaift";
20   }
21   import ietf-interfaces {
22     prefix "if";
23   }
24   import ietf-yang-types {
25     prefix "yang";
26   }
27   import ietf-inet-types {
28     prefix "inet";
29   }
30   import ietf-ip {
31     prefix "ip";
32   }
33   import yang-ext {
34     prefix "ext";
35   }
36   import vpp-acl {
37     prefix "vpp-acl";
38   }
39
40   typedef bridge-domain-ref {
41     type leafref {
42       path "/vpp/bridge-domains/bridge-domain/name";
43     }
44     description
45       "This type is used by to reference a bridge domain table";
46   }
47
48   typedef bridged-virtual-interface-ref {
49     type leafref {
50       path "/if:interfaces/if:interface/l2/bridged-virtual-interface";
51     }
52     description
53       "This type is used by to reference a bridged virtual interface";
54   }
55
56   identity vxlan-tunnel {
57     base if:interface-type;
58   }
59
60   identity gre-tunnel {
61     base if:interface-type;
62   }
63
64   identity vhost-user {
65     base if:interface-type;
66   }
67
68   identity tap {
69     base if:interface-type;
70   }
71
72   identity l2-fib-action {
73     description "Base identity for l2-fib actions";
74   }
75
76   identity l2-fib-forward {
77     base l2-fib-action;
78     description
79       "Forwards packet with configured mac address";
80   }
81
82   identity l2-fib-filter {
83     base l2-fib-action;
84     description
85       "Drops packet with configured mac address";
86   }
87
88   typedef l2-fib-action {
89     type identityref {
90       base "l2-fib-action";
91     }
92     description "Identifies a specific L2 FIB action";
93   }
94
95   typedef vxlan-vni {
96     // FIXME: should be in a vxlan-specific model
97     description "VNI used in a VXLAN tunnel";
98     type uint32 {
99       range "0..16777215";
100     }
101   }
102
103   typedef vhost-user-role {
104     type enumeration {
105       enum "server";
106       enum "client";
107     }
108   }
109
110   identity vxlan-gpe-tunnel {
111     base if:interface-type;
112   }
113
114   typedef vxlan-gpe-vni {
115     description "VNI used in a VXLAN-GPE tunnel";
116     type uint32 {
117       range "0..16777215";
118     }
119   }
120
121   typedef vxlan-gpe-next-protocol {
122     type enumeration {
123       enum "ipv4" {
124         value 1;
125       }
126       enum "ipv6" {
127         value 2;
128       }
129       enum "ethernet" {
130         value 3;
131       }
132       enum "nsh" {
133         value 4;
134       }
135     }
136   }
137
138   grouping bridge-domain-attributes {
139     leaf flood {
140       type boolean;
141       default true;
142       description
143       "Enable/disable L2 flooding.";
144     }
145     leaf forward {
146       type boolean;
147       default true;
148       description
149       "Enable/disable L2 forwarding.";
150     }
151     leaf learn {
152       type boolean;
153       default true;
154       description
155       "Enable/disable L2 learning.";
156     }
157     leaf unknown-unicast-flood {
158       type boolean;
159       default true;
160     }
161     leaf arp-termination {
162       type boolean;
163       default false;
164     }
165
166     container arp-termination-table {
167       when "../v3po:arp-termination = 'true'";
168
169       // TODO(HONEYCOMB-133): add support for read (after VPP-230 is done)
170       list arp-termination-table-entry {
171         key "ip-address phys-address";
172         leaf ip-address {
173           // FIXME: change to ip-address-no-zone after https://bugs.opendaylight.org/show_bug.cgi?id=6413 is resolved
174           type inet:ip-address;
175         }
176         leaf phys-address {
177           type yang:phys-address;
178         }
179       }
180     }
181   }
182
183   // TODO express constraints for L2 FIB entries in YANG if possible
184   grouping l2-fib-attributes {
185     container l2-fib-table {
186       list l2-fib-entry {
187         key "phys-address";
188
189         leaf phys-address {
190           type yang:phys-address;
191         }
192
193         leaf outgoing-interface {
194           type string;
195           // mandatory true;
196           // mandatory for forward action
197           // FIXME VPP's CLI does not require to set iface id for filter action
198           // VPP's binary api in constrast to CLI does some checks on the iface id value,
199           // so currently it has to be set for all actions
200           description
201             "One of interfaces assigned to the FIB table's bridge-domain.";
202         }
203         leaf static-config {
204           type boolean;
205           default false;
206           description
207             "Static entries cannot be overridden by mac learning.";
208         }
209         leaf action {
210           type l2-fib-action;
211           mandatory true;
212           description
213             "L2 FIB action. For filter action, entry must be configured as static.";
214         }
215         leaf bridged-virtual-interface {
216           when "../action = 'forward'";
217           type boolean;
218           config false; // FIXME setting bvi is currently not supported by VPP's binary api
219         }
220       }
221     }
222   }
223
224   grouping tap-interface-base-attributes {
225     leaf tap-name {
226       type string{
227         pattern "[a-zA-Z0-9\-;.+@$#^&*!_()=\[\]]*";
228       }
229     }
230   }
231
232   grouping tap-interface-config-attributes {
233     leaf mac {
234       type yang:phys-address;
235       mandatory false;
236       description "Mac address to be set for the tap interface. Random will be used if not configured";
237     }
238
239     leaf device-instance {
240       type uint32;
241       mandatory false;
242       description "Custom device instance. Autogenerated will be used if not configured";
243     }
244   }
245
246   grouping ethernet-base-attributes {
247     leaf mtu {
248       type uint16 {
249         range "64..9216";
250       }
251       units "octets";
252       default 9216;
253       description
254       "The size, in octets, of the largest packet that the
255        hardware interface will send and receive.";
256     }
257   }
258
259   grouping ethernet-state-attributes {
260     leaf manufacturer-description {
261       type string;
262       config false;
263     }
264     leaf duplex {
265       type enumeration {
266         enum "half";
267         enum "full";
268       }
269       config false;
270     }
271   }
272
273   grouping vhost-user-interface-base-attributes {
274     leaf socket {
275       type string {
276         length 1..255;
277       }
278     }
279     leaf role {
280       type vhost-user-role;
281       default "server";
282     }
283     description "vhost-user settings";
284   }
285
286   grouping vhost-user-interface-state-attributes {
287     leaf features {
288       type uint64;
289       config false;
290     }
291     leaf virtio-net-hdr-size {
292       type uint32;
293       config false;
294     }
295     leaf num-memory-regions {
296       type uint32;
297       config false;
298     }
299     leaf connect-error {
300       type string;
301       config false;
302     }
303   }
304
305   grouping vxlan-base-attributes {
306     // FIXME: this should be in an vxlan-specific extension
307     leaf src {
308       /*mandatory true;*/
309       type inet:ip-address;
310     }
311     leaf dst {
312       /*mandatory true;*/
313       type inet:ip-address;
314     }
315     leaf vni {
316       /*mandatory true;*/
317       type vxlan-vni;
318     }
319     leaf encap-vrf-id {
320       type uint32;
321     }
322   }
323
324   grouping gre-base-attributes {
325     leaf src {
326       /*mandatory true;*/
327       type inet:ip-address;
328     }
329     leaf dst {
330       /*mandatory true;*/
331       type inet:ip-address;
332     }
333     leaf outer-fib-id {
334       type uint32;
335     }
336   }
337
338   grouping vxlan-gpe-base-attributes {
339     leaf local {
340       /*mandatory true;*/
341       type inet:ip-address;
342     }
343     leaf remote {
344       /*mandatory true;*/
345       type inet:ip-address;
346     }
347     leaf vni {
348       /*mandatory true;*/
349       type vxlan-gpe-vni;
350     }
351     leaf next-protocol {
352       type vxlan-gpe-next-protocol;
353     }
354     leaf encap-vrf-id {
355       type uint32;
356     }
357     leaf decap-vrf-id {
358       type uint32;
359     }
360   }
361
362   grouping l2-base-attributes {
363       description
364       "Parameters for configuring Layer2 features on interfaces.";
365
366       choice interconnection {
367         case xconnect-based {
368           leaf xconnect-outgoing-interface {
369             /* Don't allow selection of this interface */
370             must "../../if:name != current()";
371             type if:interface-ref; // todo use interface-state-ref for operational data?
372             description
373               "L2 xconnect mode";
374           }
375         }
376         case bridge-based {
377           leaf bridge-domain {
378             type bridge-domain-ref;
379             mandatory true;
380             description
381               "Interfaces in a bridge-domain forward packets to other
382                interfaces in the same bridge-domain based on
383                destination mac address.";
384           }
385           leaf split-horizon-group {
386             when "../bridge-domain";
387             type uint8 {
388               range "0..255";
389             }
390             default 0; //no split horizon group
391             description
392               "Interface's split-horizon group. Interfaces in the same
393                bridge-domain and split-horizon group can not forward
394                packets between each other. ";
395           }
396           leaf bridged-virtual-interface {
397             when "../bridge-domain";
398             type boolean;
399             default false;
400             description
401               "Interface forward packets in the bridge-domain
402                associated with the BVI.";
403           }
404         }
405       }
406   }
407
408   grouping proxy-arp-attributes {
409         description
410         "Parameters for configuring Proxy ARP on interfaces.";
411
412       leaf vrf-id {
413         type uint32;
414         default 0;
415       }
416       leaf low-addr {
417           type inet:ipv4-address;
418       }
419       leaf high-addr {
420           type inet:ipv4-address;
421       }
422   }
423
424   augment /if:interfaces/if:interface {
425     ext:augment-identifier "vpp-interface-augmentation";
426
427     // FIXME using ietf-interfaces model for vpp interfaces makes it hard to implement because:
428     // 1. The link between interface type and this augmentation is unclear
429     // 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
430     // 3. The ietf-interfaces model does not define groupings which makes types reuse difficult
431
432     container tap {
433       when "../if:type = 'v3po:tap'";
434       uses tap-interface-base-attributes;
435       uses tap-interface-config-attributes;
436     }
437
438     container ethernet {
439       when "../if:type = 'ianaift:ethernetCsmacd'";
440       uses ethernet-base-attributes;
441     }
442
443     container routing {
444       leaf vrf-id { // todo no routing info for oper, is it possible to get it from the vpp?
445         type uint32;
446         default 0;
447       }
448     }
449
450     container vhost-user {
451       when "../if:type = 'v3po:vhost-user'";
452       uses vhost-user-interface-base-attributes;
453     }
454
455     container vxlan {
456       when "../if:type = 'v3po:vxlan-tunnel'";
457       uses vxlan-base-attributes;
458     }
459
460     container gre {
461       when "../if:type = 'v3po:gre-tunnel'";
462       uses gre-base-attributes;
463     }
464
465     container l2 {
466       must "bridged-virtual-interface = 'true' or " +
467            "(not (../if:ipv4[if:enabled = 'true']/if:address/if:ip) and " +
468            "not (../if:ipv6[if:enabled = 'true']/if:address/if:ip))";
469
470       uses l2-base-attributes;
471     }
472
473     container vxlan-gpe {
474       when "../if:type = 'v3po:vxlan-gpe-tunnel'";
475
476       uses vxlan-gpe-base-attributes;
477     }
478
479     container proxy-arp {
480       uses proxy-arp-attributes;
481     }
482
483     container acl {
484       container ingress {
485         uses vpp-acl:acl-base-attributes;
486       }
487       container egress {
488         uses vpp-acl:acl-base-attributes;
489       }
490     }
491
492     container ietf-acl {
493       container ingress {
494         uses vpp-acl:ietf-acl-base-attributes;
495       }
496       container egress {
497         uses vpp-acl:ietf-acl-base-attributes;
498       }
499     }
500   }
501
502   container vpp {
503     description
504     "VPP config data";
505
506     container bridge-domains {
507       list bridge-domain {
508         key "name";
509
510         leaf name {
511           type string;
512         }
513
514         uses bridge-domain-attributes;
515         uses l2-fib-attributes;
516
517         description
518           "bridge-domain configuration";
519       }
520     }
521   }
522
523   augment /if:interfaces-state/if:interface {
524     ext:augment-identifier "vpp-interface-state-augmentation";
525
526     leaf description {
527       type string;
528     }
529
530     container tap {
531       when "../if:type = 'v3po:tap'";
532       uses tap-interface-base-attributes;
533     }
534
535     container ethernet {
536       when "../if:type = 'ianaift:ethernetCsmacd'";
537       uses ethernet-base-attributes;
538       uses ethernet-state-attributes;
539     }
540
541     container vhost-user {
542       when "../if:type = 'v3po:vhost-user'";
543       uses vhost-user-interface-base-attributes;
544       uses vhost-user-interface-state-attributes;
545     }
546
547     container vxlan {
548       when "../if:type = 'v3po:vxlan-tunnel'";
549       uses vxlan-base-attributes;
550     }
551     container vxlan-gpe {
552       when "../if:type = 'v3po:vxlan-gpe-tunnel'";
553
554       uses vxlan-gpe-base-attributes;
555     }
556
557     container gre {
558       when "../if:type = 'gre-tunnel'";
559       uses gre-base-attributes;
560     }
561
562     container l2 {
563       must "bridged-virtual-interface = 'true' or " +
564            "(not (../if:ipv4[if:enabled = 'true']/if:address/if:ip) and " +
565            "not (../if:ipv6[if:enabled = 'true']/if:address/if:ip))";
566
567       uses l2-base-attributes;
568     }
569
570     container proxy-arp {
571       uses proxy-arp-attributes;
572     }
573
574     container acl {
575       container ingress {
576         uses vpp-acl:acl-base-attributes;
577       }
578       container egress {
579         uses vpp-acl:acl-base-attributes;
580       }
581     }
582
583     container ietf-acl {
584       container ingress {
585         uses vpp-acl:ietf-acl-base-attributes;
586       }
587       container egress {
588         uses vpp-acl:ietf-acl-base-attributes;
589       }
590     }
591   }
592
593   augment /if:interfaces-state/if:interface/if:statistics {
594     ext:augment-identifier "vpp-interface-statistics-augmentation";
595     leaf in-errors-no-buf {
596       type yang:counter64;
597     }
598     leaf in-errors-miss {
599       type yang:counter64;
600     }
601     leaf out-discards-fifo-full {
602       type yang:counter64;
603     }
604   }
605
606   container vpp-state {
607     config false;
608
609     description
610       "VPP operational data";
611
612     container bridge-domains {
613       // FIXME: Should this live in bridge-domain.yang in a modular fashion ?
614       list bridge-domain {
615
616         key "name";
617         leaf name {
618           type string;
619         }
620
621         uses bridge-domain-attributes;
622         uses l2-fib-attributes;
623
624         description
625           "bridge-domain operational data";
626       }
627     }
628
629     container version {
630       leaf name {
631         type string;
632       }
633       leaf build-directory {
634         type string;
635       }
636       leaf build-date {
637         type string;
638       }
639       leaf branch {
640         type string;
641       }
642       description
643       "vlib version info";
644     }
645   }
646
647   // VPP Notifications
648
649   typedef interface-status {
650     type enumeration {
651       enum up {
652         value 1;
653       }
654       enum down {
655         value 0;
656       }
657     }
658   }
659
660   typedef interface-name-or-index {
661     type union {
662       type string;
663       type uint32;
664     }
665   }
666
667   notification interface-state-change {
668     leaf name {
669         type interface-name-or-index;
670     }
671
672     leaf admin-status {
673         type interface-status;
674     }
675
676     leaf oper-status {
677         type interface-status;
678     }
679   }
680
681   notification interface-deleted {
682     leaf name {
683         type interface-name-or-index;
684     }
685   }
686 }