b19b1ded0e9a1903b267ace001f52c412be5b902
[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-extended-community-grouping {
305         container route-target-extended-community {
306             description "Type 0x00 / Subtype 0x02";
307             reference "http://tools.ietf.org/html/rfc4360#section-4";
308
309             leaf global-administrator {
310                 type short-as-number;
311             }
312             leaf local-administrator {
313                 type binary {
314                     length "4";
315                 }
316             }
317         }
318     }
319
320     grouping route-target-ipv4-grouping {
321         container route-target-ipv4 {
322             description "Type 0x01 / Subtype 0x02";
323             reference "http://tools.ietf.org/html/rfc4360#section-4";
324             uses route-ipv4-extended-community;
325         }
326     }
327
328     grouping as-4-route-target-extended-community-grouping {
329         container as-4-route-target-extended-community {
330             description "Type 0x02 / Subtype 0x02";
331             reference "https://tools.ietf.org/html/rfc5668";
332             uses as-4-spec-common;
333         }
334     }
335
336     grouping extended-community {
337         leaf transitive {
338             type boolean;
339         }
340         choice extended-community {
341             case as-specific-extended-community-case {
342                 container as-specific-extended-community {
343                     leaf global-administrator {
344                         type short-as-number;
345                     }
346                     leaf local-administrator {
347                         type binary {
348                             length "4";
349                         }
350                     }
351                 }
352             }
353             case inet4-specific-extended-community-case {
354                 container inet4-specific-extended-community {
355                     uses inet4-specific-extended-community-common;
356                     leaf global-administrator {
357                         status deprecated;
358                         type inet:ipv4-address;
359                     }
360                     leaf local-administrator {
361                         status deprecated;
362                         type binary {
363                             length "2";
364                         }
365                     }
366                 }
367             }
368             case opaque-extended-community-case {
369                 container opaque-extended-community {
370                     leaf value {
371                         type binary {
372                             length "6";
373                         }
374                     }
375                 }
376             }
377             case route-target-extended-community-case {
378                 uses route-target-extended-community-grouping;
379             }
380             case route-target-ipv4-case {
381                 uses route-target-ipv4-grouping;
382             }
383             case as-4-route-target-extended-community-case {
384                 uses as-4-route-target-extended-community-grouping;
385             }
386             case route-origin-extended-community-case {
387                 container route-origin-extended-community {
388                     leaf global-administrator {
389                         type short-as-number;
390                     }
391                     leaf local-administrator {
392                         type binary {
393                             length "4";
394                         }
395                     }
396                 }
397             }
398             case route-origin-ipv4-case {
399                 container route-origin-ipv4 {
400                     reference "http://tools.ietf.org/html/rfc4360#section-5";
401                     uses route-ipv4-extended-community;
402                 }
403             }
404             case link-bandwidth-case {
405                 container link-bandwidth-extended-community {
406                     uses link-bandwidth-extended-community;
407                 }
408             }
409             case as-4-generic-spec-extended-community-case {
410                 container as-4-generic-spec-extended-community {
411                     reference "https://www.ietf.org/archive/id/draft-ietf-idr-as4octet-extcomm-generic-subtype-08.txt";
412                     uses as-4-spec-common;
413                 }
414             }
415             case as-4-route-origin-extended-community-case {
416                 container as-4-route-origin-extended-community {
417                     reference "https://tools.ietf.org/html/rfc5668";
418                     uses as-4-spec-common;
419                 }
420             }
421             case encapsulation-case {
422                 container encapsulation-extended-community {
423                     uses encapsulation-extended-community;
424                 }
425             }
426             case vrf-route-import-extended-community-case {
427                 reference "https://tools.ietf.org/html/rfc6514#section-7";
428                 container vrf-route-import-extended-community {
429                     uses inet4-specific-extended-community-common;
430                 }
431             }
432             case source-as-4-extended-community-case {
433                 container source-as-4-extended-community {
434                     uses source-as-4-extended-community-grouping;
435                 }
436             }
437             case source-as-extended-community-case {
438                 container source-as-extended-community {
439                     uses source-as-extended-community-grouping;
440                 }
441             }
442         }
443     }
444
445     grouping next-hop {
446         choice c-next-hop {
447             default empty-next-hop-case;
448             case ipv4-next-hop-case {
449                 container ipv4-next-hop {
450                     reference "http://tools.ietf.org/html/rfc4271#section-5.1.3";
451                     leaf global {
452                         type inet:ipv4-address;
453                     }
454                 }
455             }
456             case ipv6-next-hop-case {
457                 container ipv6-next-hop {
458                     reference "http://tools.ietf.org/html/rfc4760#section-3";
459                     leaf global {
460                         type inet:ipv6-address;
461                     }
462                     leaf link-local {
463                         type inet:ipv6-address;
464                     }
465                 }
466             }
467             case empty-next-hop-case {
468                 leaf empty-next-hop {
469                     type empty;
470                 }
471             }
472         }
473     }
474
475     grouping as-path-segment {
476         reference "http://tools.ietf.org/html/rfc4271#section-5.1.2";
477         leaf-list as-sequence {
478             type inet:as-number;
479             ordered-by user;
480             max-elements "255";
481         }
482         leaf-list as-set {
483             type inet:as-number;
484         }
485     }
486
487     grouping route-distinguisher-grouping {
488         leaf route-distinguisher {
489             type route-distinguisher;
490             mandatory true;
491         }
492     }
493
494     grouping orig-route-ip-grouping {
495         leaf orig-route-ip {
496             type inet:ip-address;
497             mandatory true;
498         }
499     }
500 }