BUG-2982 : moved path-attributes container to grouping
[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
13     organization "Cisco Systems, Inc.";
14     contact "Dana Kutenicsova <dkutenic@cisco.com>";
15
16     description
17         "This module contains the base data model of a BGP flow specification.
18         It rolls up the definitions contained in RFC5575.
19
20         Copyright (c)2015 Cisco Systems, Inc. All rights reserved.
21
22         This program and the accompanying materials are made available
23         under the terms of the Eclipse Public License v1.0 which
24         accompanies this distribution, and is available at
25         http://www.eclipse.org/legal/epl-v10.html";
26
27     revision "2015-01-14" {
28         description
29             "Initial revision.";
30         reference "http://tools.ietf.org/html/rfc5575";
31     }
32
33     identity flowspec-subsequent-address-family {
34         reference "http://tools.ietf.org/html/rfc5575#section-11";
35
36         base bgp-t:subsequent-address-family;
37     }
38
39     typedef component-type {
40         reference "http://tools.ietf.org/html/rfc5575#section-4";
41         type enumeration {
42             enum destination-prefix {
43                 value 1;
44             }
45             enum source-prefix {
46                 value 2;
47             }
48             enum protocol-ip {
49                 value 3;
50             }
51             enum port {
52                 value 4;
53             }
54             enum destination-port {
55                 value 5;
56             }
57             enum source-port {
58                 value 6;
59             }
60             enum icmp-type {
61                 value 7;
62             }
63             enum icmp-code {
64                 value 8;
65             }
66             enum tcp-flags {
67                 value 9;
68             }
69             enum packet-length {
70                 value 10;
71             }
72             enum dscp {
73                 value 11;
74             }
75             enum fragment {
76                 value 12;
77             }
78         }
79     }
80
81     typedef fragment {
82         reference "http://tools.ietf.org/html/rfc5575#section-4";
83         type bits {
84             bit last {
85                 position 4;
86             }
87             bit first {
88                 position 5;
89             }
90             bit is-a {
91                 position 6;
92             }
93             bit do-not {
94                 position 7;
95             }
96         }
97     }
98
99     typedef dscp {
100         reference "https://tools.ietf.org/html/rfc2474#section-3";
101         type uint8 {
102             range "0..63";
103         }
104     }
105
106     typedef numeric-operand {
107         reference "http://tools.ietf.org/html/rfc5575#section-4";
108         type bits {
109             bit end-of-list {
110                 position 0;
111             }
112             bit and-bit {
113                 position 1;
114             }
115             bit less-than {
116                 position 5;
117             }
118             bit greater-than {
119                 position 6;
120             }
121             bit equals {
122                 position 7;
123             }
124         }
125     }
126
127     typedef bitmask-operand {
128         reference "http://tools.ietf.org/html/rfc5575#section-4";
129         type bits {
130             bit end-of-list {
131                 position 0;
132             }
133             bit and-bit {
134                 position 1;
135             }
136             bit not {
137                 position 6;
138             }
139             bit match {
140                 position 7;
141             }
142         }
143     }
144
145     grouping numeric-two-byte-value {
146         reference "http://tools.ietf.org/html/rfc5575#section-4";
147         leaf op {
148             type numeric-operand;
149         }
150         leaf value {
151             type uint16;
152         }
153     }
154
155     grouping numeric-one-byte-value {
156         reference "http://tools.ietf.org/html/rfc5575#section-4";
157         leaf op {
158             type numeric-operand;
159         }
160         leaf value {
161             type uint8;
162         }
163     }
164
165     grouping bitmask-two-byte-value {
166         reference "http://tools.ietf.org/html/rfc5575#section-4";
167         leaf op {
168             type bitmask-operand;
169         }
170         leaf value {
171             type uint16;
172         }
173     }
174
175     grouping dscp-value {
176         reference "http://tools.ietf.org/html/rfc5575#section-4";
177         leaf op {
178             type numeric-operand;
179         }
180         leaf value {
181             type dscp;
182         }
183     }
184
185     grouping fragment-value {
186         reference "http://tools.ietf.org/html/rfc5575#section-4";
187         leaf op {
188             type bitmask-operand;
189         }
190         leaf value {
191             type fragment;
192         }
193     }
194
195     grouping flowspec-destination {
196         reference "http://tools.ietf.org/html/rfc5575#section-4";
197         list flowspec {
198             leaf component-type {
199                 type component-type;
200             }
201             choice flowspec-type {
202                 case destination-prefix-case {
203                     when "../component-type = destination-prefix";
204                     leaf destination-prefix {
205                         type inet:ipv4-prefix;
206                     }
207                 }
208                 case source-prefix-case {
209                     when "../component-type = source-prefix";
210                     leaf source-prefix {
211                         type inet:ipv4-prefix;
212                     }
213                 }
214                 case protocol-ip-case {
215                     when "../component-type = protocol-ip";
216                     list protocol-ips {
217                         uses numeric-two-byte-value;
218                     }
219                 }
220                 case port-case {
221                     when "../component-type = port";
222                     list ports {
223                         uses numeric-two-byte-value;
224                     }
225                 }
226                 case destination-port-case {
227                     when "../component-type = destination-port";
228                     list destination-ports {
229                         uses numeric-two-byte-value;
230                     }
231                 }
232                 case source-port-case {
233                     when "../component-type = source-port";
234                     list source-ports {
235                         uses numeric-two-byte-value;
236                     }
237                 }
238                 case icmp-type-case {
239                     when "../component-type = icmp-type";
240                     list types {
241                         uses numeric-one-byte-value;
242                     }
243                 }
244                 case icmp-code-case {
245                     when "../component-type = icmp-code";
246                     list codes {
247                         uses numeric-one-byte-value;
248                     }
249                 }
250                 case tcp-flags-case {
251                     when "../component-type = tcp-flags";
252                     list tcp-flags {
253                         uses bitmask-two-byte-value;
254                     }
255                 }
256                 case packet-length-case {
257                     when "../component-type = packet-length";
258                     list packet-lengths {
259                         uses numeric-two-byte-value;
260                     }
261                 }
262                 case dscp-case {
263                     when "../component-type = dscp";
264                     list dscps {
265                         uses dscp-value;
266                     }
267                 }
268                 case fragment-case {
269                     when "../component-type = fragment";
270                     list fragments {
271                         uses fragment-value;
272                     }
273                 }
274             }
275         }
276     }
277
278     augment "/bgp-msg:update/bgp-msg:attributes/bgp-mp:mp-reach-nlri/bgp-mp:advertized-routes/bgp-mp:destination-type" {
279         case destination-flowspec-case {
280             container destination-flowspec {
281                 uses flowspec-destination;
282             }
283         }
284     }
285
286     augment "/bgp-msg:update/bgp-msg:attributes/bgp-mp:mp-unreach-nlri/bgp-mp:withdrawn-routes/bgp-mp:destination-type" {
287         case destination-flowspec-case {
288             container destination-flowspec {
289                 uses flowspec-destination;
290             }
291         }
292     }
293
294     grouping flowspec-routes {
295         container flowspec-routes {
296             list flowspec-route {
297                 leaf route-key {
298                     description
299                         "The sole function of this leaf
300                         to act as the key in the list.
301                         Its format does not form the
302                         API contract of this model.";
303                     type string;
304                 }
305                 key "route-key";
306                 uses bgp-rib:route {
307                     augment bgp-msg:attributes {
308                         uses flowspec-destination;
309                     }
310                 }
311             }
312         }
313     }
314
315     augment "/bgp-msg:update/bgp-msg:attributes/bgp-msg:extended-communities/bgp-msg:extended-community" {
316         reference "https://tools.ietf.org/html/rfc5575#section-7";
317         case traffic-rate-extended-community-case {
318             container traffic-rate-extended-community {
319                 when "../comm-type = 128 and ../comm-sub-type = 6";
320                 leaf informative-as {
321                     type bgp-t:short-as-number;
322                 }
323                 leaf local-administrator {
324                     type netc:bandwidth;
325                 }
326             }
327         }
328         case traffic-action-extended-community-case {
329             container traffic-action-extended-community {
330                 when "../comm-type = 128 and ../comm-sub-type = 7";
331                 leaf sample {
332                     type boolean;
333                     default false;
334                 }
335                 leaf terminal-action {
336                     type boolean;
337                     default false;
338                 }
339             }
340         }
341         case redirect-extended-community-case {
342             container redirect-extended-community {
343                 when "../comm-type = 128 and ../comm-sub-type = 8";
344                 leaf global-administrator {
345                     type bgp-t:short-as-number;
346                 }
347                 leaf local-administrator {
348                     type binary {
349                         length "4";
350                     }
351                 }
352             }
353         }
354         case traffic-marking-extended-community-case {
355             container traffic-marking-extended-community {
356                 when "../comm-type = 128 and ../comm-sub-type = 9";
357                 leaf global-administrator {
358                     type dscp;
359                 }
360             }
361         }
362     }
363
364     augment "/bgp-rib:application-rib/bgp-rib:tables/bgp-rib:routes" {
365         case flowspec-routes-case {
366             uses flowspec-routes;
367         }
368     }
369
370     augment "/bgp-rib:bgp-rib/bgp-rib:rib/bgp-rib:loc-rib/bgp-rib:tables/bgp-rib:routes" {
371         case flowspec-routes-case {
372             uses flowspec-routes;
373         }
374     }
375 }