Create common parent for extensions families
[bgpcep.git] / bgp / extensions / flowspec / src / main / yang / bgp-flowspec.yang
1 module bgp-flowspec {
2     yang-version 1;
3     namespace "urn:opendaylight:params:xml:ns:yang:bgp-flowspec";
4     prefix "bgp-fs";
5
6     import ietf-inet-types { prefix inet; revision-date 2013-07-15; }
7     import bgp-message { prefix bgp-msg; revision-date 2018-03-29; }
8     import bgp-multiprotocol { prefix bgp-mp; revision-date 2018-03-29; }
9     import bgp-rib { prefix bgp-rib; revision-date 2018-03-29; }
10     import bgp-types { prefix bgp-t; revision-date 2018-03-29; }
11     import network-concepts { prefix netc; revision-date 2013-11-25; }
12     import bmp-monitor { prefix bmp-mon; revision-date 2018-03-29; }
13
14     organization "Cisco Systems, Inc.";
15     contact "Dana Kutenicsova <dkutenic@cisco.com>";
16
17     description
18         "This module contains the base data model of a BGP flow specification.
19         It rolls up the definitions contained in RFC5575.
20
21         Copyright (c)2015 Cisco Systems, Inc. All rights reserved.
22
23         This program and the accompanying materials are made available
24         under the terms of the Eclipse Public License v1.0 which
25         accompanies this distribution, and is available at
26         http://www.eclipse.org/legal/epl-v10.html";
27
28     revision "2018-03-29" {
29         description "Add support for add-path for all afi/safi.";
30     }
31
32     revision "2017-12-07" {
33         description "Add support for add-path in base BGP NLRI.";
34     }
35
36     revision "2015-08-07" {
37         description
38             "IPv6 support";
39         reference "https://tools.ietf.org/html/draft-ietf-idr-flow-spec-v6-06";
40     }
41
42     revision "2015-01-14" {
43         description
44             "Initial revision.";
45         reference "http://tools.ietf.org/html/rfc5575";
46     }
47
48     identity flowspec-subsequent-address-family {
49         description "SAFI 133 for dissemination of unicast flow specification rules.";
50         reference "http://tools.ietf.org/html/rfc5575#section-11";
51
52         base bgp-t:subsequent-address-family;
53     }
54
55     identity flowspec-l3vpn-subsequent-address-family {
56         description "SAFI 134 for dissemination of L3VPN flow specification rules";
57         reference "http://tools.ietf.org/html/rfc5575#section-11";
58
59         base bgp-t:subsequent-address-family;
60     }
61
62     typedef fragment {
63         reference "http://tools.ietf.org/html/rfc5575#section-4";
64         type bits {
65             bit last {
66                 position 4;
67             }
68             bit first {
69                 position 5;
70             }
71             bit is-a {
72                 position 6;
73             }
74             bit do-not {
75                 position 7;
76             }
77         }
78     }
79
80     typedef dscp {
81         reference "https://tools.ietf.org/html/rfc2474#section-3";
82         type uint8 {
83             range "0..63";
84         }
85     }
86
87     typedef numeric-operand {
88         reference "http://tools.ietf.org/html/rfc5575#section-4";
89         type bits {
90             bit end-of-list {
91                 position 0;
92             }
93             bit and-bit {
94                 position 1;
95             }
96             bit less-than {
97                 position 5;
98             }
99             bit greater-than {
100                 position 6;
101             }
102             bit equals {
103                 position 7;
104             }
105         }
106     }
107
108     typedef bitmask-operand {
109         reference "http://tools.ietf.org/html/rfc5575#section-4";
110         type bits {
111             bit end-of-list {
112                 position 0;
113             }
114             bit and-bit {
115                 position 1;
116             }
117             bit not {
118                 position 6;
119             }
120             bit match {
121                 position 7;
122             }
123         }
124     }
125
126     grouping numeric-two-byte-value {
127         reference "http://tools.ietf.org/html/rfc5575#section-4";
128         leaf op {
129             type numeric-operand;
130         }
131         leaf value {
132             type uint16;
133         }
134     }
135
136     grouping numeric-one-byte-value {
137         reference "http://tools.ietf.org/html/rfc5575#section-4";
138         leaf op {
139             type numeric-operand;
140         }
141         leaf value {
142             type uint8;
143         }
144     }
145
146     grouping bitmask-two-byte-value {
147         reference "http://tools.ietf.org/html/rfc5575#section-4";
148         leaf op {
149             type bitmask-operand;
150         }
151         leaf value {
152             type uint16;
153         }
154     }
155
156     grouping dscp-value {
157         reference "http://tools.ietf.org/html/rfc5575#section-4";
158         leaf op {
159             type numeric-operand;
160         }
161         leaf value {
162             type dscp;
163         }
164     }
165
166     grouping fragment-value {
167         reference "http://tools.ietf.org/html/rfc5575#section-4";
168         leaf op {
169             type bitmask-operand;
170         }
171         leaf value {
172             type fragment;
173         }
174     }
175
176     grouping flowspec-destination {
177         reference "http://tools.ietf.org/html/rfc5575#section-4";
178         list flowspec {
179             choice flowspec-type {
180                 case port-case {
181                     list ports {
182                         uses numeric-two-byte-value;
183                     }
184                 }
185                 case destination-port-case {
186                     list destination-ports {
187                         uses numeric-two-byte-value;
188                     }
189                 }
190                 case source-port-case {
191                     list source-ports {
192                         uses numeric-two-byte-value;
193                     }
194                 }
195                 case icmp-type-case {
196                     list types {
197                         uses numeric-one-byte-value;
198                     }
199                 }
200                 case icmp-code-case {
201                     list codes {
202                         uses numeric-one-byte-value;
203                     }
204                 }
205                 case tcp-flags-case {
206                     list tcp-flags {
207                         uses bitmask-two-byte-value;
208                     }
209                 }
210                 case packet-length-case {
211                     list packet-lengths {
212                         uses numeric-two-byte-value;
213                     }
214                 }
215                 case dscp-case {
216                     list dscps {
217                         uses dscp-value;
218                     }
219                 }
220                 case fragment-case {
221                     list fragments {
222                         uses fragment-value;
223                     }
224                 }
225             }
226         }
227     }
228
229     grouping flowspec-destination-group-ipv4 {
230         reference "http://tools.ietf.org/html/rfc5575#section-4";
231         uses flowspec-destination {
232             augment "flowspec/flowspec-type" {
233                 case destination-prefix-case {
234                     leaf destination-prefix {
235                         type inet:ipv4-prefix;
236                     }
237                 }
238                 case source-prefix-case {
239                     leaf source-prefix {
240                         type inet:ipv4-prefix;
241                     }
242                 }
243                 case protocol-ip-case {
244                     list protocol-ips {
245                         uses numeric-one-byte-value;
246                     }
247                 }
248             }
249         }
250     }
251
252     grouping flow-label-value {
253         reference "https://tools.ietf.org/html/draft-ietf-idr-flow-spec-v6-06#section-3";
254         leaf op {
255             type numeric-operand;
256         }
257         leaf value {
258             type uint32;
259         }
260     }
261
262     grouping flowspec-destination-group-ipv6 {
263         reference "https://tools.ietf.org/html/draft-ietf-idr-flow-spec-v6-06#section-3.1";
264         uses flowspec-destination {
265             augment "flowspec/flowspec-type" {
266                 case destination-ipv6-prefix-case {
267                     leaf destination-prefix {
268                         type inet:ipv6-prefix;
269                     }
270                 }
271                 case source-ipv6-prefix-case {
272                     leaf source-prefix {
273                         type inet:ipv6-prefix;
274                     }
275                 }
276                 case next-header-case {
277                     list next-headers {
278                         uses numeric-one-byte-value;
279                     }
280                 }
281                 case flow-label-case {
282                     list flow-label {
283                         uses flow-label-value;
284                     }
285                 }
286             }
287         }
288     }
289
290     grouping flowspec-destination-ipv4 {
291         container destination-flowspec {
292             uses flowspec-destination-group-ipv4;
293             uses bgp-msg:path-id-grouping;
294         }
295     }
296
297     grouping flowspec-destination-ipv6 {
298         container destination-flowspec {
299             uses flowspec-destination-group-ipv6;
300             uses bgp-msg:path-id-grouping;
301         }
302     }
303
304     grouping flowspec-l3vpn-destination-ipv4 {
305         container destination-flowspec-l3vpn-ipv4 {
306             uses bgp-t:route-distinguisher-grouping;
307             uses flowspec-destination-group-ipv4;
308             uses bgp-msg:path-id-grouping;
309         }
310     }
311
312     grouping flowspec-l3vpn-destination-ipv6 {
313         container destination-flowspec-l3vpn-ipv6 {
314             uses bgp-t:route-distinguisher-grouping;
315             uses flowspec-destination-group-ipv6;
316             uses bgp-msg:path-id-grouping;
317         }
318     }
319
320     augment "/bgp-msg:update/bgp-msg:attributes/bgp-mp:mp-reach-nlri/bgp-mp:advertized-routes/bgp-mp:destination-type" {
321         case destination-flowspec-case {
322             uses flowspec-destination-ipv4;
323         }
324         case destination-flowspec-ipv6-case {
325             uses flowspec-destination-ipv6;
326         }
327         case destination-flowspec-l3vpn-ipv4-case {
328             uses flowspec-l3vpn-destination-ipv4;
329         }
330         case destination-flowspec-l3vpn-ipv6-case {
331             uses flowspec-l3vpn-destination-ipv6;
332         }
333     }
334
335     augment "/bgp-msg:update/bgp-msg:attributes/bgp-mp:mp-unreach-nlri/bgp-mp:withdrawn-routes/bgp-mp:destination-type" {
336         case destination-flowspec-case {
337             uses flowspec-destination-ipv4;
338         }
339         case destination-flowspec-ipv6-case {
340             uses flowspec-destination-ipv6;
341         }
342         case destination-flowspec-l3vpn-ipv4-case {
343             uses flowspec-l3vpn-destination-ipv4;
344         }
345         case destination-flowspec-l3vpn-ipv6-case {
346             uses flowspec-l3vpn-destination-ipv6;
347         }
348     }
349
350     grouping traffic-rate-extended-community {
351         container traffic-rate-extended-community {
352             leaf informative-as {
353                 type bgp-t:short-as-number;
354             }
355             leaf local-administrator {
356                 type netc:bandwidth;
357             }
358         }
359     }
360
361     grouping traffic-action-extended-community {
362         container traffic-action-extended-community {
363             leaf sample {
364                 type boolean;
365                 default false;
366             }
367             leaf terminal-action {
368                 type boolean;
369                 default false;
370             }
371         }
372     }
373
374     grouping redirect-extended-community {
375         container redirect-extended-community {
376             leaf global-administrator {
377                 type bgp-t:short-as-number;
378             }
379             leaf local-administrator {
380                 type binary {
381                     length "4";
382                 }
383             }
384         }
385     }
386
387     grouping redirect-ipv4-extended-community {
388         reference "http://tools.ietf.org/html/rfc7674";
389         container redirect-ipv4 {
390             uses bgp-t:route-ipv4-extended-community;
391         }
392     }
393
394     grouping redirect-ipv6-extended-community {
395         container redirect-ipv6 {
396             leaf global-administrator {
397                 type inet:ipv6-address;
398             }
399             leaf local-administrator {
400                 type uint16;
401             }
402         }
403     }
404
405     grouping redirect-as4-extended-community {
406         reference "http://tools.ietf.org/html/rfc7674";
407         container redirect-as4 {
408             leaf global-administrator {
409                 type inet:as-number;
410             }
411             leaf local-administrator {
412                 type uint16;
413             }
414         }
415     }
416
417     grouping traffic-marking-extended-community {
418         container traffic-marking-extended-community {
419             leaf global-administrator {
420                 type dscp;
421             }
422         }
423     }
424
425     grouping redirect-ip-nh-extended-community {
426         reference "https://tools.ietf.org/html/draft-ietf-idr-flowspec-redirect-ip-02";
427         container redirect-ip-nh-extended-community {
428             leaf next-hop-address {
429                 type inet:ip-address;
430             }
431             leaf copy {
432                 type boolean;
433             }
434         }
435     }
436
437     grouping bgp-rib-route {
438         uses bgp-rib:route {
439             augment "attributes/extended-communities/extended-community" {
440                 case traffic-rate-extended-community-case {
441                     uses traffic-rate-extended-community;
442                 }
443                 case traffic-action-extended-community-case {
444                     uses traffic-action-extended-community;
445                 }
446                 case redirect-extended-community-case {
447                     uses redirect-extended-community;
448                 }
449                 case traffic-marking-extended-community-case {
450                     uses traffic-marking-extended-community;
451                 }
452                 case redirect-ipv4-extended-community-case {
453                     uses redirect-ipv4-extended-community;
454                 }
455                 case redirect-ipv6-extended-community-case {
456                     uses redirect-ipv6-extended-community;
457                 }
458                 case redirect-as4-extended-community-case {
459                     uses redirect-as4-extended-community;
460                 }
461                 case redirect-ip-nh-extended-community-case {
462                     uses redirect-ip-nh-extended-community;
463                 }
464             }
465         }
466     }
467
468     grouping flowspec-ipv4-route-list {
469         uses flowspec-destination-group-ipv4;
470         uses bgp-rib-route;
471     }
472
473     grouping flowspec-ipv4-route {
474         list flowspec-route {
475             key "route-key path-id";
476             uses flowspec-ipv4-route-list;
477         }
478     }
479
480     grouping flowspec-l3vpn-ipv4-route {
481         list flowspec-l3vpn-route {
482             key "route-key path-id";
483             uses flowspec-ipv4-route-list;
484             uses bgp-t:route-distinguisher-grouping;
485         }
486     }
487
488     grouping flowspec-ipv6-route-list {
489         uses flowspec-destination-group-ipv6;
490         uses bgp-rib-route;
491     }
492
493     grouping flowspec-ipv6-route {
494         list flowspec-route {
495             key "route-key path-id";
496             uses flowspec-ipv6-route-list;
497         }
498     }
499
500     grouping flowspec-l3vpn-ipv6-route {
501         list flowspec-l3vpn-route {
502             key "route-key path-id";
503             uses flowspec-ipv6-route-list;
504             uses bgp-t:route-distinguisher-grouping;
505         }
506     }
507
508     grouping flowspec-routes {
509         container flowspec-routes {
510             uses flowspec-ipv4-route;
511         }
512     }
513
514     grouping flowspec-ipv6-routes {
515         container flowspec-ipv6-routes {
516             uses flowspec-ipv6-route;
517         }
518     }
519
520     grouping flowspec-l3vpn-ipv4-routes {
521         container flowspec-l3vpn-ipv4-routes {
522             uses flowspec-l3vpn-ipv4-route;
523         }
524     }
525
526     grouping flowspec-l3vpn-ipv6-routes {
527         container flowspec-l3vpn-ipv6-routes {
528             uses flowspec-l3vpn-ipv6-route;
529         }
530     }
531
532     augment "/bgp-msg:update/bgp-msg:attributes/bgp-msg:extended-communities/bgp-msg:extended-community" {
533         reference "https://tools.ietf.org/html/rfc5575#section-7";
534         case traffic-rate-extended-community-case {
535             uses traffic-rate-extended-community;
536         }
537         case traffic-action-extended-community-case {
538             uses traffic-action-extended-community;
539         }
540         case redirect-extended-community-case {
541             uses redirect-extended-community;
542         }
543         case traffic-marking-extended-community-case {
544             uses traffic-marking-extended-community;
545         }
546         case redirect-ipv4-extended-community-case {
547             uses redirect-ipv4-extended-community;
548         }
549         case redirect-ipv6-extended-community-case {
550             uses redirect-ipv6-extended-community;
551         }
552         case redirect-as4-extended-community-case {
553             uses redirect-as4-extended-community;
554         }
555         case redirect-ip-nh-extended-community-case {
556             uses redirect-ip-nh-extended-community;
557         }
558     }
559
560     augment "/bgp-rib:application-rib/bgp-rib:tables/bgp-rib:routes" {
561         case flowspec-routes-case {
562             uses flowspec-routes;
563         }
564         case flowspec-ipv6-routes-case {
565             uses flowspec-ipv6-routes;
566         }
567         case flowspec-l3vpn-ipv4-routes-case {
568             uses flowspec-l3vpn-ipv4-routes;
569         }
570         case flowspec-l3vpn-ipv6-routes-case {
571             uses flowspec-l3vpn-ipv6-routes;
572         }
573     }
574
575     augment "/bgp-rib:bgp-rib/bgp-rib:rib/bgp-rib:loc-rib/bgp-rib:tables/bgp-rib:routes" {
576         case flowspec-routes-case {
577             uses flowspec-routes;
578         }
579         case flowspec-ipv6-routes-case {
580             uses flowspec-ipv6-routes;
581         }
582         case flowspec-l3vpn-ipv4-routes-case {
583             uses flowspec-l3vpn-ipv4-routes;
584         }
585         case flowspec-l3vpn-ipv6-routes-case {
586             uses flowspec-l3vpn-ipv6-routes;
587         }
588     }
589
590     augment "/bgp-rib:bgp-rib/bgp-rib:rib/bgp-rib:peer/bgp-rib:adj-rib-in/bgp-rib:tables/bgp-rib:routes" {
591         case flowspec-routes-case {
592             uses flowspec-routes;
593         }
594         case flowspec-ipv6-routes-case {
595             uses flowspec-ipv6-routes;
596         }
597         case flowspec-l3vpn-ipv4-routes-case {
598             uses flowspec-l3vpn-ipv4-routes;
599         }
600         case flowspec-l3vpn-ipv6-routes-case {
601             uses flowspec-l3vpn-ipv6-routes;
602         }
603     }
604
605     augment "/bgp-rib:bgp-rib/bgp-rib:rib/bgp-rib:peer/bgp-rib:effective-rib-in/bgp-rib:tables/bgp-rib:routes" {
606         case flowspec-routes-case {
607             uses flowspec-routes;
608         }
609         case flowspec-ipv6-routes-case {
610             uses flowspec-ipv6-routes;
611         }
612         case flowspec-l3vpn-ipv4-routes-case {
613             uses flowspec-l3vpn-ipv4-routes;
614         }
615         case flowspec-l3vpn-ipv6-routes-case {
616             uses flowspec-l3vpn-ipv6-routes;
617         }
618     }
619
620     augment "/bgp-rib:bgp-rib/bgp-rib:rib/bgp-rib:peer/bgp-rib:adj-rib-out/bgp-rib:tables/bgp-rib:routes" {
621         case flowspec-routes-case {
622             uses flowspec-routes;
623         }
624         case flowspec-ipv6-routes-case {
625             uses flowspec-ipv6-routes;
626         }
627         case flowspec-l3vpn-ipv4-routes-case {
628             uses flowspec-l3vpn-ipv4-routes;
629         }
630         case flowspec-l3vpn-ipv6-routes-case {
631             uses flowspec-l3vpn-ipv6-routes;
632         }
633     }
634
635     augment "/bmp-mon:bmp-monitor/bmp-mon:monitor/bmp-mon:router/bmp-mon:peer/bmp-mon:pre-policy-rib/bmp-mon:tables/bmp-mon:routes" {
636         case flowspec-routes-case {
637             uses flowspec-routes;
638         }
639         case flowspec-ipv6-routes-case {
640             uses flowspec-ipv6-routes;
641         }
642         case flowspec-l3vpn-ipv4-routes-case {
643             uses flowspec-l3vpn-ipv4-routes;
644         }
645         case flowspec-l3vpn-ipv6-routes-case {
646             uses flowspec-l3vpn-ipv6-routes;
647         }
648     }
649
650     augment "/bmp-mon:bmp-monitor/bmp-mon:monitor/bmp-mon:router/bmp-mon:peer/bmp-mon:post-policy-rib/bmp-mon:tables/bmp-mon:routes" {
651         case flowspec-routes-case {
652             uses flowspec-routes;
653         }
654         case flowspec-ipv6-routes-case {
655             uses flowspec-ipv6-routes;
656         }
657         case flowspec-l3vpn-ipv4-routes-case {
658             uses flowspec-l3vpn-ipv4-routes;
659         }
660         case flowspec-l3vpn-ipv6-routes-case {
661             uses flowspec-l3vpn-ipv6-routes;
662         }
663     }
664
665 }