Code clean up
[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 2010-09-24; }
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 "2013-09-19" {
23         description
24             "Initial revision.";
25         reference "RFC4271, RFC4760";
26     }
27
28     typedef bgp-origin {
29         reference "http://tools.ietf.org/html/rfc4271#section-5";
30         description "Values of BGP Origin Path Attribute.";
31         type enumeration {
32             enum igp {
33                 value 0;
34             }
35             enum egp {
36                 value 1;
37             }
38             enum incomplete {
39                 value 2;
40             }
41         }
42     }
43
44     identity address-family {
45         reference "http://www.iana.org/assignments/address-family-numbers/address-family-numbers.xhtml#address-family-numbers-2";
46     }
47
48     identity ipv4-address-family {
49         base address-family;
50     }
51
52     identity ipv6-address-family {
53         base address-family;
54     }
55
56     identity subsequent-address-family {
57         reference "http://tools.ietf.org/html/rfc4760#section-6";
58     }
59
60     identity unicast-subsequent-address-family {
61         reference "http://tools.ietf.org/html/rfc4760#section-6";
62
63         base subsequent-address-family;
64     }
65
66     identity mpls-labeled-vpn-subsequent-address-family {
67         reference "http://tools.ietf.org/html/rfc4760#section-6";
68
69         base subsequent-address-family;
70     }
71
72     typedef cluster-identifier {
73         reference "http://tools.ietf.org/html/rfc4456#section-8";
74         type inet:ipv4-address;
75     }
76
77     typedef short-as-number {
78         type inet:as-number {
79             range 0..65535;
80         }
81     }
82
83     typedef route-distinguisher {
84         reference "https://tools.ietf.org/html/rfc4364#section-4.2";
85         type union {
86             type rd-ipv4;
87             type rd-as;
88         }
89     }
90
91     typedef rd-ipv4 {
92         type string {
93             /* IPv4 : 2B number */
94             pattern '((([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}'
95                 + '([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]))'
96                 + ':'
97                 + '([0-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|'
98                 + '[1-5][0-9][0-9][0-9][0-9]|6[0-4][0-9][0-9][0-9]|'
99                 + '65[0-4][0-9][0-9]|655[0-2][0-9]|6553[0-5])';
100         }
101     }
102
103     typedef rd-as {
104         type string {
105             /* 4B AS : 2B number */
106             pattern '([0-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|'
107                 + '[1-9][0-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9][0-9]|'
108                 + '[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]|'
109                 + '[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]|'
110                 + '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]|'
111                 + '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]|'
112                 + '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]|'
113                 + '42949672[0-8][0-9]|429496729[0-5])'
114                 + ':'
115                 + '([0-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|'
116                 + '[1-5][0-9][0-9][0-9][0-9]|6[0-4][0-9][0-9][0-9]|'
117                 + '65[0-4][0-9][0-9]|655[0-2][0-9]|6553[0-5])';
118         }
119     }
120
121     grouping bgp-aggregator {
122         reference "http://tools.ietf.org/html/rfc4271#section-5.1.7";
123         description "BGP Path Attribute AGGREGATOR.";
124         leaf as-number {
125             // We are acting as a NEW speaker, so only four bytes are allowed
126             type inet:as-number;
127         }
128         leaf network-address {
129             type inet:ipv4-address;
130         }
131     }
132
133     grouping community {
134         reference "https://tools.ietf.org/html/rfc1997";
135         description "Community Path Attribute";
136         leaf as-number {
137             type inet:as-number;
138         }
139         leaf semantics {
140             type uint16;
141         }
142     }
143
144     grouping route-ipv4-extended-community {
145         reference "http://tools.ietf.org/html/rfc4360";
146         leaf global-administrator {
147             type inet:ipv4-address;
148         }
149         leaf local-administrator {
150             type uint16;
151         }
152     }
153
154     grouping link-bandwidth-extended-community {
155         reference "https://tools.ietf.org/html/draft-ietf-idr-link-bandwidth-06#section-2";
156         description
157             "The Link Bandwidth extended community is optional non-transitive";
158
159         leaf bandwidth {
160             description "Bandwidth of the link";
161             mandatory true;
162             type netc:bandwidth;
163             units "bytes per second";
164         }
165     }
166
167     grouping extended-community {
168         leaf transitive {
169             type boolean;
170         }
171         choice extended-community {
172             case as-specific-extended-community-case {
173                 container as-specific-extended-community {
174                     leaf global-administrator {
175                         type short-as-number;
176                     }
177                     leaf local-administrator {
178                         type binary {
179                             length "4";
180                         }
181                     }
182                 }
183             }
184             case inet4-specific-extended-community-case {
185                 container inet4-specific-extended-community {
186                     leaf global-administrator {
187                         type inet:ipv4-address;
188                     }
189                     leaf local-administrator {
190                         type binary {
191                             length "2";
192                         }
193                     }
194                 }
195             }
196             case opaque-extended-community-case {
197                 container opaque-extended-community {
198                     leaf value {
199                         type binary {
200                             length "6";
201                         }
202                     }
203                 }
204             }
205             case route-target-extended-community-case {
206                 container route-target-extended-community {
207                     leaf global-administrator {
208                         type short-as-number;
209                     }
210                     leaf local-administrator {
211                         type binary {
212                             length "4";
213                         }
214                     }
215                 }
216             }
217             case route-origin-extended-community-case {
218                 container route-origin-extended-community {
219                     leaf global-administrator {
220                         type short-as-number;
221                     }
222                     leaf local-administrator {
223                         type binary {
224                             length "4";
225                         }
226                     }
227                 }
228             }
229             case route-target-ipv4-case {
230                 container route-target-ipv4 {
231                     reference "http://tools.ietf.org/html/rfc4360#section-4";
232                     uses route-ipv4-extended-community;
233                 }
234             }
235             case route-origin-ipv4-case {
236                 container route-origin-ipv4 {
237                     reference "http://tools.ietf.org/html/rfc4360#section-5";
238                     uses route-ipv4-extended-community;
239                 }
240             }
241             case link-bandwidth-case {
242                 container link-bandwidth-extended-community {
243                     uses link-bandwidth-extended-community;
244                 }
245             }
246         }
247     }
248
249     grouping next-hop {
250         choice c-next-hop {
251             case ipv4-next-hop-case {
252                 container ipv4-next-hop {
253                     reference "http://tools.ietf.org/html/rfc4271#section-5.1.3";
254                     leaf global {
255                         type inet:ipv4-address;
256                     }
257                 }
258             }
259             case ipv6-next-hop-case {
260                 container ipv6-next-hop {
261                     reference "http://tools.ietf.org/html/rfc4760#section-3";
262                     leaf global {
263                         type inet:ipv6-address;
264                     }
265                     leaf link-local {
266                         type inet:ipv6-address;
267                     }
268                 }
269             }
270         }
271     }
272
273     grouping as-path-segment {
274         reference "http://tools.ietf.org/html/rfc4271#section-5.1.2";
275         leaf-list as-sequence {
276             type inet:as-number;
277             ordered-by user;
278             max-elements "255";
279         }
280         leaf-list as-set {
281             type inet:as-number;
282         }
283     }
284 }