013e037295fb16550365ebb3f80b78a873544d0b
[bgpcep.git] / bgp / 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 2010-09-24; }
7     import bgp-message { prefix bgp-msg; revision-date 2013-09-19; }
8     import bgp-multiprotocol { prefix bgp-mp; revision-date 2013-09-19; }
9     import bgp-rib { prefix bgp-rib; revision-date 2013-09-25; }
10     import bgp-types { prefix bgp-t; revision-date 2013-09-19; }
11     import network-concepts { prefix netc; revision-date 2013-11-25; }
12     import bmp-monitor { prefix bmp-mon; revision-date 2015-05-12; }
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 "2015-08-07" {
29         description
30             "IPv6 support";
31         reference "https://tools.ietf.org/html/draft-ietf-idr-flow-spec-v6-06";
32     }
33
34     revision "2015-01-14" {
35         description
36             "Initial revision.";
37         reference "http://tools.ietf.org/html/rfc5575";
38     }
39
40     identity flowspec-subsequent-address-family {
41         description "SAFI 133 for dissemination of unicast flow specification rules.";
42         reference "http://tools.ietf.org/html/rfc5575#section-11";
43
44         base bgp-t:subsequent-address-family;
45     }
46
47     identity flowspec-l3vpn-subsequent-address-family {
48         description "SAFI 134 for dissemination of L3VPN flow specification rules";
49         reference "http://tools.ietf.org/html/rfc5575#section-11";
50
51         base bgp-t:subsequent-address-family;
52     }
53
54     typedef fragment {
55         reference "http://tools.ietf.org/html/rfc5575#section-4";
56         type bits {
57             bit last {
58                 position 4;
59             }
60             bit first {
61                 position 5;
62             }
63             bit is-a {
64                 position 6;
65             }
66             bit do-not {
67                 position 7;
68             }
69         }
70     }
71
72     typedef dscp {
73         reference "https://tools.ietf.org/html/rfc2474#section-3";
74         type uint8 {
75             range "0..63";
76         }
77     }
78
79     typedef numeric-operand {
80         reference "http://tools.ietf.org/html/rfc5575#section-4";
81         type bits {
82             bit end-of-list {
83                 position 0;
84             }
85             bit and-bit {
86                 position 1;
87             }
88             bit less-than {
89                 position 5;
90             }
91             bit greater-than {
92                 position 6;
93             }
94             bit equals {
95                 position 7;
96             }
97         }
98     }
99
100     typedef bitmask-operand {
101         reference "http://tools.ietf.org/html/rfc5575#section-4";
102         type bits {
103             bit end-of-list {
104                 position 0;
105             }
106             bit and-bit {
107                 position 1;
108             }
109             bit not {
110                 position 6;
111             }
112             bit match {
113                 position 7;
114             }
115         }
116     }
117
118     grouping numeric-two-byte-value {
119         reference "http://tools.ietf.org/html/rfc5575#section-4";
120         leaf op {
121             type numeric-operand;
122         }
123         leaf value {
124             type uint16;
125         }
126     }
127
128     grouping numeric-one-byte-value {
129         reference "http://tools.ietf.org/html/rfc5575#section-4";
130         leaf op {
131             type numeric-operand;
132         }
133         leaf value {
134             type uint8;
135         }
136     }
137
138     grouping bitmask-two-byte-value {
139         reference "http://tools.ietf.org/html/rfc5575#section-4";
140         leaf op {
141             type bitmask-operand;
142         }
143         leaf value {
144             type uint16;
145         }
146     }
147
148     grouping dscp-value {
149         reference "http://tools.ietf.org/html/rfc5575#section-4";
150         leaf op {
151             type numeric-operand;
152         }
153         leaf value {
154             type dscp;
155         }
156     }
157
158     grouping fragment-value {
159         reference "http://tools.ietf.org/html/rfc5575#section-4";
160         leaf op {
161             type bitmask-operand;
162         }
163         leaf value {
164             type fragment;
165         }
166     }
167
168     grouping flowspec-destination {
169         reference "http://tools.ietf.org/html/rfc5575#section-4";
170         list flowspec {
171             choice flowspec-type {
172                 case port-case {
173                     list ports {
174                         uses numeric-two-byte-value;
175                     }
176                 }
177                 case destination-port-case {
178                     list destination-ports {
179                         uses numeric-two-byte-value;
180                     }
181                 }
182                 case source-port-case {
183                     list source-ports {
184                         uses numeric-two-byte-value;
185                     }
186                 }
187                 case icmp-type-case {
188                     list types {
189                         uses numeric-one-byte-value;
190                     }
191                 }
192                 case icmp-code-case {
193                     list codes {
194                         uses numeric-one-byte-value;
195                     }
196                 }
197                 case tcp-flags-case {
198                     list tcp-flags {
199                         uses bitmask-two-byte-value;
200                     }
201                 }
202                 case packet-length-case {
203                     list packet-lengths {
204                         uses numeric-two-byte-value;
205                     }
206                 }
207                 case dscp-case {
208                     list dscps {
209                         uses dscp-value;
210                     }
211                 }
212                 case fragment-case {
213                     list fragments {
214                         uses fragment-value;
215                     }
216                 }
217             }
218         }
219         uses bgp-msg:path-id-grouping;
220     }
221
222     grouping flowspec-destination-group-ipv4 {
223         reference "http://tools.ietf.org/html/rfc5575#section-4";
224         uses flowspec-destination {
225             augment "flowspec/flowspec-type" {
226                 case destination-prefix-case {
227                     leaf destination-prefix {
228                         type inet:ipv4-prefix;
229                     }
230                 }
231                 case source-prefix-case {
232                     leaf source-prefix {
233                         type inet:ipv4-prefix;
234                     }
235                 }
236                 case protocol-ip-case {
237                     list protocol-ips {
238                         uses numeric-one-byte-value;
239                     }
240                 }
241             }
242         }
243     }
244
245     grouping flow-label-value {
246         reference "https://tools.ietf.org/html/draft-ietf-idr-flow-spec-v6-06#section-3";
247         leaf op {
248             type numeric-operand;
249         }
250         leaf value {
251             type uint32;
252         }
253     }
254
255     grouping flowspec-destination-group-ipv6 {
256         reference "https://tools.ietf.org/html/draft-ietf-idr-flow-spec-v6-06#section-3.1";
257         uses flowspec-destination {
258             augment "flowspec/flowspec-type" {
259                 case destination-ipv6-prefix-case {
260                     leaf destination-prefix {
261                         type inet:ipv6-prefix;
262                     }
263                 }
264                 case source-ipv6-prefix-case {
265                     leaf source-prefix {
266                         type inet:ipv6-prefix;
267                     }
268                 }
269                 case next-header-case {
270                     list next-headers {
271                         uses numeric-one-byte-value;
272                     }
273                 }
274                 case flow-label-case {
275                     list flow-label {
276                         uses flow-label-value;
277                     }
278                 }
279             }
280         }
281     }
282
283     grouping flowspec-destination-ipv4 {
284         container destination-flowspec {
285             uses flowspec-destination-group-ipv4;
286         }
287     }
288
289     grouping flowspec-destination-ipv6 {
290         container destination-flowspec {
291             uses flowspec-destination-group-ipv6;
292         }
293     }
294
295     grouping flowspec-l3vpn-rd {
296         reference "https://tools.ietf.org/html/rfc5575#section-8";
297         leaf route-distinguisher {
298             type bgp-t:route-distinguisher;
299         }
300     }
301
302     grouping flowspec-l3vpn-destination-ipv4 {
303         container destination-flowspec-l3vpn-ipv4 {
304             uses flowspec-l3vpn-rd;
305             uses flowspec-destination-group-ipv4;
306         }
307     }
308
309     grouping flowspec-l3vpn-destination-ipv6 {
310         container destination-flowspec-l3vpn-ipv6 {
311             uses flowspec-l3vpn-rd;
312             uses flowspec-destination-group-ipv6;
313         }
314     }
315
316     augment "/bgp-msg:update/bgp-msg:attributes/bgp-mp:mp-reach-nlri/bgp-mp:advertized-routes/bgp-mp:destination-type" {
317         case destination-flowspec-case {
318             uses flowspec-destination-ipv4;
319         }
320         case destination-flowspec-ipv6-case {
321             uses flowspec-destination-ipv6;
322         }
323         case destination-flowspec-l3vpn-ipv4-case {
324             uses flowspec-l3vpn-destination-ipv4;
325         }
326         case destination-flowspec-l3vpn-ipv6-case {
327             uses flowspec-l3vpn-destination-ipv6;
328         }
329     }
330
331     augment "/bgp-msg:update/bgp-msg:attributes/bgp-mp:mp-unreach-nlri/bgp-mp:withdrawn-routes/bgp-mp:destination-type" {
332         case destination-flowspec-case {
333             uses flowspec-destination-ipv4;
334         }
335         case destination-flowspec-ipv6-case {
336             uses flowspec-destination-ipv6;
337         }
338         case destination-flowspec-l3vpn-ipv4-case {
339             uses flowspec-l3vpn-destination-ipv4;
340         }
341         case destination-flowspec-l3vpn-ipv6-case {
342             uses flowspec-l3vpn-destination-ipv6;
343         }
344     }
345
346     grouping traffic-rate-extended-community {
347         container traffic-rate-extended-community {
348             leaf informative-as {
349                 type bgp-t:short-as-number;
350             }
351             leaf local-administrator {
352                 type netc:bandwidth;
353             }
354         }
355     }
356
357     grouping traffic-action-extended-community {
358         container traffic-action-extended-community {
359             leaf sample {
360                 type boolean;
361                 default false;
362             }
363             leaf terminal-action {
364                 type boolean;
365                 default false;
366             }
367         }
368     }
369
370     grouping redirect-extended-community {
371         container redirect-extended-community {
372             leaf global-administrator {
373                 type bgp-t:short-as-number;
374             }
375             leaf local-administrator {
376                 type binary {
377                     length "4";
378                 }
379             }
380         }
381     }
382
383     grouping redirect-ipv4-extended-community {
384         reference "http://tools.ietf.org/html/rfc7674";
385         container redirect-ipv4 {
386             uses bgp-t:route-ipv4-extended-community;
387         }
388     }
389
390     grouping redirect-ipv6-extended-community {
391         container redirect-ipv6 {
392             leaf global-administrator {
393                 type inet:ipv6-address;
394             }
395             leaf local-administrator {
396                 type uint16;
397             }
398         }
399     }
400
401     grouping redirect-as4-extended-community {
402         reference "http://tools.ietf.org/html/rfc7674";
403         container redirect-as4 {
404             leaf global-administrator {
405                 type inet:as-number;
406             }
407             leaf local-administrator {
408                 type uint16;
409             }
410         }
411     }
412
413     grouping traffic-marking-extended-community {
414         container traffic-marking-extended-community {
415             leaf global-administrator {
416                 type dscp;
417             }
418         }
419     }
420
421     grouping redirect-ip-nh-extended-community {
422         reference "https://tools.ietf.org/html/draft-ietf-idr-flowspec-redirect-ip-02";
423         container redirect-ip-nh-extended-community {
424             leaf next-hop-address {
425                 type inet:ip-address;
426             }
427             leaf copy {
428                 type boolean;
429             }
430         }
431     }
432
433     grouping bgp-rib-route {
434         uses bgp-rib:route {
435             augment "attributes/extended-communities/extended-community" {
436                 case traffic-rate-extended-community-case {
437                     uses traffic-rate-extended-community;
438                 }
439                 case traffic-action-extended-community-case {
440                     uses traffic-action-extended-community;
441                 }
442                 case redirect-extended-community-case {
443                     uses redirect-extended-community;
444                 }
445                 case traffic-marking-extended-community-case {
446                     uses traffic-marking-extended-community;
447                 }
448                 case redirect-ipv4-extended-community-case {
449                     uses redirect-ipv4-extended-community;
450                 }
451                 case redirect-ipv6-extended-community-case {
452                     uses redirect-ipv6-extended-community;
453                 }
454                 case redirect-as4-extended-community-case {
455                     uses redirect-as4-extended-community;
456                 }
457                 case redirect-ip-nh-extended-community-case {
458                     uses redirect-ip-nh-extended-community;
459                 }
460             }
461         }
462     }
463
464     grouping flowspec-ipv4-route {
465         list flowspec-route {
466             leaf route-key {
467                 description
468                     "The sole function of this leaf
469                     to act as the key in the list.
470                     Its format does not form the
471                     API contract of this model.";
472                 type string;
473             }
474             key "route-key path-id";
475
476             uses flowspec-destination-group-ipv4;
477
478             uses bgp-rib-route;
479         }
480     }
481
482     grouping flowspec-ipv6-route {
483         list flowspec-route {
484             leaf route-key {
485                 description
486                     "The sole function of this leaf
487                     to act as the key in the list.
488                     Its format does not form the
489                     API contract of this model.";
490                 type string;
491             }
492             key "route-key path-id";
493
494             uses flowspec-destination-group-ipv6;
495
496             uses bgp-rib-route;
497         }
498     }
499
500     grouping flowspec-routes {
501         container flowspec-routes {
502             uses flowspec-ipv4-route;
503         }
504     }
505
506     grouping flowspec-ipv6-routes {
507         container flowspec-ipv6-routes {
508             uses flowspec-ipv6-route;
509         }
510     }
511
512     grouping flowspec-l3vpn-ipv4-routes {
513         container flowspec-l3vpn-ipv4-routes {
514             uses flowspec-ipv4-route {
515                 augment "flowspec-route" {
516                     uses flowspec-l3vpn-rd;
517                 }
518             }
519         }
520     }
521
522     grouping flowspec-l3vpn-ipv6-routes {
523         container flowspec-l3vpn-ipv6-routes {
524             uses flowspec-ipv6-route {
525                 augment "flowspec-route" {
526                     uses flowspec-l3vpn-rd;
527                 }
528             }
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 }