Route Constrain policies
[bgpcep.git] / bgp / concepts / src / main / yang / bgp-types.yang
1 module bgp-types {
2     yang-version 1;
3     namespace "urn:opendaylight:params:xml:ns:yang:bgp-types";
4     prefix "bgp-t";
5
6     import ietf-inet-types { prefix inet; revision-date 2013-07-15; }
7     import network-concepts { prefix netc; revision-date 2013-11-25; }
8
9     organization "Cisco Systems, Inc.";
10     contact "Dana Kutenicsova <dkutenic@cisco.com>";
11
12     description
13         "This module contains the base concepts contained in RFC4271 and RFC4760.
14
15         Copyright (c)2013 Cisco Systems, Inc. All rights reserved.
16
17         This program and the accompanying materials are made available
18         under the terms of the Eclipse Public License v1.0 which
19         accompanies this distribution, and is available at
20         http://www.eclipse.org/legal/epl-v10.html";
21
22     revision "2018-03-29" {
23         description "RFC6514 Extended communities";
24         reference "https://tools.ietf.org/html/rfc6514";
25     }
26
27     revision "2013-09-19" {
28         description
29             "Initial revision.";
30         reference "RFC4271, RFC4760";
31     }
32
33     typedef bgp-origin {
34         reference "http://tools.ietf.org/html/rfc4271#section-5";
35         description "Values of BGP Origin Path Attribute.";
36         type enumeration {
37             enum igp {
38                 value 0;
39             }
40             enum egp {
41                 value 1;
42             }
43             enum incomplete {
44                 value 2;
45             }
46         }
47     }
48
49     typedef bgp-id {
50         description "BGP identifier";
51         type inet:ipv4-address;
52     }
53
54     identity address-family {
55         reference "http://www.iana.org/assignments/address-family-numbers/address-family-numbers.xhtml#address-family-numbers-2";
56     }
57
58     identity ipv4-address-family {
59         base address-family;
60     }
61
62     identity ipv6-address-family {
63         base address-family;
64     }
65
66     identity subsequent-address-family {
67         reference "http://tools.ietf.org/html/rfc4760#section-6";
68     }
69
70     identity unicast-subsequent-address-family {
71         reference "http://tools.ietf.org/html/rfc4760#section-6";
72
73         base subsequent-address-family;
74     }
75
76     identity mpls-labeled-vpn-subsequent-address-family {
77         reference "http://tools.ietf.org/html/rfc4760#section-6";
78
79         base subsequent-address-family;
80     }
81
82     typedef cluster-identifier {
83         reference "http://tools.ietf.org/html/rfc4456#section-8";
84         type inet:ipv4-address;
85     }
86
87     typedef short-as-number {
88         type inet:as-number {
89             range 0..65535;
90         }
91     }
92
93     typedef route-distinguisher {
94         reference "https://tools.ietf.org/html/rfc4364#section-4.2";
95         type union {
96             type rd-two-octet-as;
97             type rd-ipv4;
98             type rd-as;
99         }
100     }
101
102     typedef rd-two-octet-as {
103         type string {
104             /* 2B AS : 4B number */
105             pattern '0:'
106                 + '([0-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|'
107                 + '[1-5][0-9][0-9][0-9][0-9]|6[0-4][0-9][0-9][0-9]|'
108                 + '65[0-4][0-9][0-9]|655[0-2][0-9]|6553[0-5])'
109                 + ':'
110                 + '([0-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|'
111                 + '[1-9][0-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9][0-9]|'
112                 + '[1-9][0-9][0-9][0-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]|'
113                 + '[1-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]|[1-3][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]|'
114                 + '4[0-1][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]|42[0-8][0-9][0-9][0-9][0-9][0-9][0-9][0-9]|'
115                 + '429[0-3][0-9][0-9][0-9][0-9][0-9][0-9]|4294[0-8][0-9][0-9][0-9][0-9][0-9]|'
116                 + '42949[0-5][0-9][0-9][0-9][0-9]|429496[0-6][0-9][0-9][0-9]|4294967[0-1][0-9][0-9]|'
117                 + '42949672[0-8][0-9]|429496729[0-5])';
118         }
119     }
120
121     typedef rd-ipv4 {
122         type string {
123             /* IPv4 : 2B number */
124             pattern '((([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}'
125                 + '([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]))'
126                 + ':'
127                 + '([0-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|'
128                 + '[1-5][0-9][0-9][0-9][0-9]|6[0-4][0-9][0-9][0-9]|'
129                 + '65[0-4][0-9][0-9]|655[0-2][0-9]|6553[0-5])';
130         }
131     }
132
133     typedef rd-as {
134         type string {
135             /* 4B AS : 2B number */
136             pattern '([0-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|'
137                 + '[1-9][0-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9][0-9]|'
138                 + '[1-9][0-9][0-9][0-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]|'
139                 + '[1-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]|[1-3][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]|'
140                 + '4[0-1][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]|42[0-8][0-9][0-9][0-9][0-9][0-9][0-9][0-9]|'
141                 + '429[0-3][0-9][0-9][0-9][0-9][0-9][0-9]|4294[0-8][0-9][0-9][0-9][0-9][0-9]|'
142                 + '42949[0-5][0-9][0-9][0-9][0-9]|429496[0-6][0-9][0-9][0-9]|4294967[0-1][0-9][0-9]|'
143                 + '42949672[0-8][0-9]|429496729[0-5])'
144                 + ':'
145                 + '([0-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|'
146                 + '[1-5][0-9][0-9][0-9][0-9]|6[0-4][0-9][0-9][0-9]|'
147                 + '65[0-4][0-9][0-9]|655[0-2][0-9]|6553[0-5])';
148         }
149     }
150
151     typedef encapsulation-tunnel-type {
152         reference "http://www.iana.org/assignments/bgp-parameters/bgp-parameters.xhtml#tunnel-types";
153         type enumeration {
154             enum l2tpv3-over-ip {
155                 value 1;
156             }
157             enum gre {
158                 value 2;
159             }
160             enum transmit-tunnel-endpoint {
161                 value 3;
162             }
163             enum ipsec-tunnel-mode {
164                 value 4;
165             }
166             enum ip-in-ip-ipsec-transport-mode {
167                 value 5;
168             }
169             enum mpls-in-ip-tunnel-ipsec-transport-mode {
170                 value 6;
171             }
172             enum ip-in-ip {
173                 value 7;
174             }
175             enum vxlan {
176                 value 8;
177             }
178             enum nvgre {
179                 value 9;
180             }
181             enum mpls {
182                 value 10;
183             }
184             enum mpls-in-gre {
185                 value 11;
186             }
187             enum vxlan-gpe {
188                 value 12;
189             }
190             enum mpls-in-udp {
191                 value 13;
192             }
193             enum ipv6-tunnel {
194                 value 14;
195             }
196         }
197     }
198
199     grouping bgp-aggregator {
200         reference "http://tools.ietf.org/html/rfc4271#section-5.1.7";
201         description "BGP Path Attribute AGGREGATOR.";
202         leaf as-number {
203             // We are acting as a NEW speaker, so only four bytes are allowed
204             type inet:as-number;
205         }
206         leaf network-address {
207             type inet:ipv4-address;
208         }
209     }
210
211     grouping community {
212         reference "https://tools.ietf.org/html/rfc1997";
213         description "Community Path Attribute";
214         leaf as-number {
215             type inet:as-number;
216         }
217         leaf semantics {
218             type uint16;
219         }
220     }
221
222     grouping route-ipv4-extended-community {
223         reference "http://tools.ietf.org/html/rfc4360";
224         leaf global-administrator {
225             type inet:ipv4-address;
226         }
227         leaf local-administrator {
228             type uint16;
229         }
230     }
231
232     grouping link-bandwidth-extended-community {
233         reference "https://tools.ietf.org/html/draft-ietf-idr-link-bandwidth-06#section-2";
234         description
235             "The Link Bandwidth extended community is optional non-transitive";
236
237         leaf bandwidth {
238             description "Bandwidth of the link";
239             mandatory true;
240             type netc:bandwidth;
241             units "bytes per second";
242         }
243     }
244
245     grouping as-4-spec-common {
246         container as-4-specific-common {
247             leaf as-number {
248                 description "Carries a 4-octet Autonomous System (AS) number";
249                 reference "https://tools.ietf.org/html/rfc5668#section-2";
250
251                 mandatory true;
252                 type inet:as-number;
253             }
254
255             leaf local-administrator {
256                 type uint16;
257                 mandatory true;
258             }
259         }
260     }
261
262     grouping encapsulation-extended-community {
263         reference "https://tools.ietf.org/html/rfc5512#section-4.5";
264         description "BGP Encapsulation extended community";
265
266         leaf tunnel-type {
267             description "Tunnel type specifying the encapsulation protocol";
268             mandatory true;
269             type encapsulation-tunnel-type;
270         }
271     }
272
273     grouping inet4-specific-extended-community-common {
274         container inet4-specific-extended-community-common {
275             leaf global-administrator {
276                 type inet:ipv4-address;
277             }
278             leaf local-administrator {
279                 type binary {
280                     length "2";
281                 }
282             }
283         }
284     }
285
286     grouping source-as-4-extended-community-grouping {
287         reference "https://tools.ietf.org/html/rfc6514#section-6";
288         leaf global-administrator {
289             description "Carries a 4-octet Autonomous System (AS) number";
290             reference "https://tools.ietf.org/html/rfc5668#section-2";
291
292             mandatory true;
293             type inet:as-number;
294         }
295     }
296
297     grouping source-as-extended-community-grouping {
298         reference "https://tools.ietf.org/html/rfc6514#section-6";
299         leaf global-administrator {
300             type bgp-t:short-as-number;
301         }
302     }
303
304     grouping route-target {
305         description "Marker grouping for Route Target extended communities.";
306     }
307
308     grouping route-target-constrain-default-route-grouping {
309         container route-target-constrain-default-route {
310             uses route-target;
311             presence
312                 "The presence of this container indicates that the routes
313                 is a default route target";
314         }
315     }
316
317     grouping route-target-extended-community-grouping {
318         container route-target-extended-community {
319             description "Type 0x00 / Subtype 0x02";
320             reference "http://tools.ietf.org/html/rfc4360#section-4";
321             uses route-target;
322
323             leaf global-administrator {
324                 type short-as-number;
325             }
326             leaf local-administrator {
327                 type binary {
328                     length "4";
329                 }
330             }
331         }
332     }
333
334     grouping route-target-ipv4-grouping {
335         container route-target-ipv4 {
336             description "Type 0x01 / Subtype 0x02";
337             reference "http://tools.ietf.org/html/rfc4360#section-4";
338             uses route-target;
339             uses route-ipv4-extended-community;
340         }
341     }
342
343     grouping as-4-route-target-extended-community-grouping {
344         container as-4-route-target-extended-community {
345             description "Type 0x02 / Subtype 0x02";
346             reference "https://tools.ietf.org/html/rfc5668";
347             uses route-target;
348             uses as-4-spec-common;
349         }
350     }
351
352     grouping extended-community {
353         leaf transitive {
354             type boolean;
355         }
356         choice extended-community {
357             case as-specific-extended-community-case {
358                 container as-specific-extended-community {
359                     leaf global-administrator {
360                         type short-as-number;
361                     }
362                     leaf local-administrator {
363                         type binary {
364                             length "4";
365                         }
366                     }
367                 }
368             }
369             case inet4-specific-extended-community-case {
370                 container inet4-specific-extended-community {
371                     uses inet4-specific-extended-community-common;
372                     leaf global-administrator {
373                         status deprecated;
374                         type inet:ipv4-address;
375                     }
376                     leaf local-administrator {
377                         status deprecated;
378                         type binary {
379                             length "2";
380                         }
381                     }
382                 }
383             }
384             case opaque-extended-community-case {
385                 container opaque-extended-community {
386                     leaf value {
387                         type binary {
388                             length "6";
389                         }
390                     }
391                 }
392             }
393             case route-target-extended-community-case {
394                 uses route-target-extended-community-grouping;
395             }
396             case route-target-ipv4-case {
397                 uses route-target-ipv4-grouping;
398             }
399             case as-4-route-target-extended-community-case {
400                 uses as-4-route-target-extended-community-grouping;
401             }
402             case route-origin-extended-community-case {
403                 container route-origin-extended-community {
404                     leaf global-administrator {
405                         type short-as-number;
406                     }
407                     leaf local-administrator {
408                         type binary {
409                             length "4";
410                         }
411                     }
412                 }
413             }
414             case route-origin-ipv4-case {
415                 container route-origin-ipv4 {
416                     reference "http://tools.ietf.org/html/rfc4360#section-5";
417                     uses route-ipv4-extended-community;
418                 }
419             }
420             case link-bandwidth-case {
421                 container link-bandwidth-extended-community {
422                     uses link-bandwidth-extended-community;
423                 }
424             }
425             case as-4-generic-spec-extended-community-case {
426                 container as-4-generic-spec-extended-community {
427                     reference "https://www.ietf.org/archive/id/draft-ietf-idr-as4octet-extcomm-generic-subtype-08.txt";
428                     uses as-4-spec-common;
429                 }
430             }
431             case as-4-route-origin-extended-community-case {
432                 container as-4-route-origin-extended-community {
433                     reference "https://tools.ietf.org/html/rfc5668";
434                     uses as-4-spec-common;
435                 }
436             }
437             case encapsulation-case {
438                 container encapsulation-extended-community {
439                     uses encapsulation-extended-community;
440                 }
441             }
442             case vrf-route-import-extended-community-case {
443                 reference "https://tools.ietf.org/html/rfc6514#section-7";
444                 container vrf-route-import-extended-community {
445                     uses inet4-specific-extended-community-common;
446                 }
447             }
448             case source-as-4-extended-community-case {
449                 container source-as-4-extended-community {
450                     uses source-as-4-extended-community-grouping;
451                 }
452             }
453             case source-as-extended-community-case {
454                 container source-as-extended-community {
455                     uses source-as-extended-community-grouping;
456                 }
457             }
458         }
459     }
460
461     grouping next-hop {
462         choice c-next-hop {
463             default empty-next-hop-case;
464             case ipv4-next-hop-case {
465                 container ipv4-next-hop {
466                     reference "http://tools.ietf.org/html/rfc4271#section-5.1.3";
467                     leaf global {
468                         type inet:ipv4-address;
469                     }
470                 }
471             }
472             case ipv6-next-hop-case {
473                 container ipv6-next-hop {
474                     reference "http://tools.ietf.org/html/rfc4760#section-3";
475                     leaf global {
476                         type inet:ipv6-address;
477                     }
478                     leaf link-local {
479                         type inet:ipv6-address;
480                     }
481                 }
482             }
483             case empty-next-hop-case {
484                 leaf empty-next-hop {
485                     type empty;
486                 }
487             }
488         }
489     }
490
491     grouping as-path-segment {
492         reference "http://tools.ietf.org/html/rfc4271#section-5.1.2";
493         leaf-list as-sequence {
494             type inet:as-number;
495             ordered-by user;
496             max-elements "255";
497         }
498         leaf-list as-set {
499             type inet:as-number;
500         }
501     }
502
503     grouping route-distinguisher-grouping {
504         leaf route-distinguisher {
505             type route-distinguisher;
506             mandatory true;
507         }
508     }
509
510     grouping orig-route-ip-grouping {
511         leaf orig-route-ip {
512             type inet:ip-address;
513             mandatory true;
514         }
515     }
516 }