blob: e7863b8b02d3fd8be800d3c8aef19c4827276b52 [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Thomas Vachuska781d18b2014-10-27 10:31:25 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
Thomas Vachuska781d18b2014-10-27 10:31:25 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
Thomas Vachuska781d18b2014-10-27 10:31:25 -070015 */
Jonathan Hartf4bd0482017-01-27 15:11:18 -080016
Jonathan Hart41349e92015-02-09 14:14:02 -080017package org.onosproject.routing.bgp;
Jonathan Hartab63aac2014-10-16 08:52:55 -070018
19/**
20 * BGP related constants.
21 */
22public final class BgpConstants {
23 /**
24 * Default constructor.
25 * <p>
26 * The constructor is private to prevent creating an instance of
27 * this utility class.
28 */
29 private BgpConstants() {
30 }
31
32 /** BGP port number (RFC 4271). */
33 public static final int BGP_PORT = 179;
34
35 /** BGP version. */
36 public static final int BGP_VERSION = 4;
37
38 /** BGP OPEN message type. */
39 public static final int BGP_TYPE_OPEN = 1;
40
41 /** BGP UPDATE message type. */
42 public static final int BGP_TYPE_UPDATE = 2;
43
44 /** BGP NOTIFICATION message type. */
45 public static final int BGP_TYPE_NOTIFICATION = 3;
46
47 /** BGP KEEPALIVE message type. */
48 public static final int BGP_TYPE_KEEPALIVE = 4;
49
50 /** BGP Header Marker field length. */
51 public static final int BGP_HEADER_MARKER_LENGTH = 16;
52
53 /** BGP Header length. */
54 public static final int BGP_HEADER_LENGTH = 19;
55
56 /** BGP message maximum length. */
57 public static final int BGP_MESSAGE_MAX_LENGTH = 4096;
58
59 /** BGP OPEN message minimum length (BGP Header included). */
60 public static final int BGP_OPEN_MIN_LENGTH = 29;
61
62 /** BGP UPDATE message minimum length (BGP Header included). */
63 public static final int BGP_UPDATE_MIN_LENGTH = 23;
64
65 /** BGP NOTIFICATION message minimum length (BGP Header included). */
66 public static final int BGP_NOTIFICATION_MIN_LENGTH = 21;
67
68 /** BGP KEEPALIVE message expected length (BGP Header included). */
69 public static final int BGP_KEEPALIVE_EXPECTED_LENGTH = 19;
70
71 /** BGP KEEPALIVE messages transmitted per Hold interval. */
72 public static final int BGP_KEEPALIVE_PER_HOLD_INTERVAL = 3;
73
74 /** BGP KEEPALIVE messages minimum Holdtime (in seconds). */
75 public static final int BGP_KEEPALIVE_MIN_HOLDTIME = 3;
76
77 /** BGP KEEPALIVE messages minimum transmission interval (in seconds). */
78 public static final int BGP_KEEPALIVE_MIN_INTERVAL = 1;
79
80 /** BGP AS 0 (zero) value. See draft-ietf-idr-as0-06.txt Internet Draft. */
81 public static final long BGP_AS_0 = 0;
82
83 /**
Pavlin Radoslavov278cdde2014-12-16 14:09:31 -080084 * BGP OPEN related constants.
85 */
86 public static final class Open {
87 /**
88 * Default constructor.
89 * <p>
90 * The constructor is private to prevent creating an instance of
91 * this utility class.
92 */
93 private Open() {
94 }
95
96 /**
97 * BGP OPEN: Optional Parameters related constants.
98 */
99 public static final class OptionalParameters {
100 }
101
102 /**
103 * BGP OPEN: Capabilities related constants (RFC 5492).
104 */
105 public static final class Capabilities {
106 /** BGP OPEN Optional Parameter Type: Capabilities. */
107 public static final int TYPE = 2;
108
109 /** BGP OPEN Optional Parameter minimum length. */
110 public static final int MIN_LENGTH = 2;
111
112 /**
113 * BGP OPEN: Multiprotocol Extensions Capabilities (RFC 4760).
114 */
115 public static final class MultiprotocolExtensions {
116 /** BGP OPEN Multiprotocol Extensions code. */
117 public static final int CODE = 1;
118
119 /** BGP OPEN Multiprotocol Extensions length. */
120 public static final int LENGTH = 4;
121
122 /** BGP OPEN Multiprotocol Extensions AFI: IPv4. */
123 public static final int AFI_IPV4 = 1;
124
125 /** BGP OPEN Multiprotocol Extensions AFI: IPv6. */
126 public static final int AFI_IPV6 = 2;
127
128 /** BGP OPEN Multiprotocol Extensions SAFI: unicast. */
129 public static final int SAFI_UNICAST = 1;
130
131 /** BGP OPEN Multiprotocol Extensions SAFI: multicast. */
132 public static final int SAFI_MULTICAST = 2;
133 }
134
135 /**
136 * BGP OPEN: Support for 4-octet AS Number Capability (RFC 6793).
137 */
138 public static final class As4Octet {
139 /** BGP OPEN Support for 4-octet AS Number Capability code. */
140 public static final int CODE = 65;
141
142 /** BGP OPEN 4-octet AS Number Capability length. */
143 public static final int LENGTH = 4;
144 }
145 }
146 }
147
148 /**
Jonathan Hartab63aac2014-10-16 08:52:55 -0700149 * BGP UPDATE related constants.
150 */
151 public static final class Update {
152 /**
153 * Default constructor.
154 * <p>
155 * The constructor is private to prevent creating an instance of
156 * this utility class.
157 */
158 private Update() {
159 }
160
Pavlin Radoslavova460e292015-03-17 18:04:56 -0700161 /** BGP AS length. */
162 public static final int AS_LENGTH = 2;
163
164 /** BGP 4 Octet AS length (RFC 6793). */
165 public static final int AS_4OCTET_LENGTH = 4;
166
Jonathan Hartab63aac2014-10-16 08:52:55 -0700167 /**
168 * BGP UPDATE: ORIGIN related constants.
169 */
170 public static final class Origin {
171 /**
172 * Default constructor.
173 * <p>
174 * The constructor is private to prevent creating an instance of
175 * this utility class.
176 */
177 private Origin() {
178 }
179
180 /** BGP UPDATE Attributes Type Code ORIGIN. */
181 public static final int TYPE = 1;
182
183 /** BGP UPDATE Attributes Type Code ORIGIN length. */
184 public static final int LENGTH = 1;
185
186 /** BGP UPDATE ORIGIN: IGP. */
187 public static final int IGP = 0;
188
189 /** BGP UPDATE ORIGIN: EGP. */
190 public static final int EGP = 1;
191
192 /** BGP UPDATE ORIGIN: INCOMPLETE. */
193 public static final int INCOMPLETE = 2;
Pavlin Radoslavov2ce1c522014-11-07 10:32:37 -0800194
195 /**
196 * Gets the BGP UPDATE origin type as a string.
197 *
198 * @param type the BGP UPDATE origin type
199 * @return the BGP UPDATE origin type as a string
200 */
201 public static String typeToString(int type) {
202 String typeString = "UNKNOWN";
203
204 switch (type) {
205 case IGP:
206 typeString = "IGP";
207 break;
208 case EGP:
209 typeString = "EGP";
210 break;
211 case INCOMPLETE:
212 typeString = "INCOMPLETE";
213 break;
214 default:
215 break;
216 }
217 return typeString;
218 }
Jonathan Hartab63aac2014-10-16 08:52:55 -0700219 }
220
221 /**
222 * BGP UPDATE: AS_PATH related constants.
223 */
224 public static final class AsPath {
225 /**
226 * Default constructor.
227 * <p>
228 * The constructor is private to prevent creating an instance of
229 * this utility class.
230 */
231 private AsPath() {
232 }
233
234 /** BGP UPDATE Attributes Type Code AS_PATH. */
235 public static final int TYPE = 2;
236
237 /** BGP UPDATE AS_PATH Type: AS_SET. */
238 public static final int AS_SET = 1;
239
240 /** BGP UPDATE AS_PATH Type: AS_SEQUENCE. */
241 public static final int AS_SEQUENCE = 2;
Pavlin Radoslavov2ce1c522014-11-07 10:32:37 -0800242
Pavlin Radoslavov49eb64d2014-11-10 17:03:19 -0800243 /** BGP UPDATE AS_PATH Type: AS_CONFED_SEQUENCE. */
244 public static final int AS_CONFED_SEQUENCE = 3;
245
246 /** BGP UPDATE AS_PATH Type: AS_CONFED_SET. */
247 public static final int AS_CONFED_SET = 4;
248
Pavlin Radoslavov2ce1c522014-11-07 10:32:37 -0800249 /**
250 * Gets the BGP AS_PATH type as a string.
251 *
252 * @param type the BGP AS_PATH type
253 * @return the BGP AS_PATH type as a string
254 */
255 public static String typeToString(int type) {
256 String typeString = "UNKNOWN";
257
258 switch (type) {
259 case AS_SET:
260 typeString = "AS_SET";
261 break;
262 case AS_SEQUENCE:
263 typeString = "AS_SEQUENCE";
264 break;
Pavlin Radoslavov49eb64d2014-11-10 17:03:19 -0800265 case AS_CONFED_SEQUENCE:
266 typeString = "AS_CONFED_SEQUENCE";
267 break;
268 case AS_CONFED_SET:
269 typeString = "AS_CONFED_SET";
270 break;
Pavlin Radoslavov2ce1c522014-11-07 10:32:37 -0800271 default:
272 break;
273 }
274 return typeString;
275 }
Jonathan Hartab63aac2014-10-16 08:52:55 -0700276 }
277
278 /**
279 * BGP UPDATE: NEXT_HOP related constants.
280 */
281 public static final class NextHop {
282 /**
283 * Default constructor.
284 * <p>
285 * The constructor is private to prevent creating an instance of
286 * this utility class.
287 */
288 private NextHop() {
289 }
290
291 /** BGP UPDATE Attributes Type Code NEXT_HOP. */
292 public static final int TYPE = 3;
293
294 /** BGP UPDATE Attributes Type Code NEXT_HOP length. */
295 public static final int LENGTH = 4;
296 }
297
298 /**
299 * BGP UPDATE: MULTI_EXIT_DISC related constants.
300 */
301 public static final class MultiExitDisc {
302 /**
303 * Default constructor.
304 * <p>
305 * The constructor is private to prevent creating an instance of
306 * this utility class.
307 */
308 private MultiExitDisc() {
309 }
310
311 /** BGP UPDATE Attributes Type Code MULTI_EXIT_DISC. */
312 public static final int TYPE = 4;
313
314 /** BGP UPDATE Attributes Type Code MULTI_EXIT_DISC length. */
315 public static final int LENGTH = 4;
316
317 /** BGP UPDATE Attributes lowest MULTI_EXIT_DISC value. */
318 public static final int LOWEST_MULTI_EXIT_DISC = 0;
319 }
320
321 /**
322 * BGP UPDATE: LOCAL_PREF related constants.
323 */
324 public static final class LocalPref {
325 /**
326 * Default constructor.
327 * <p>
328 * The constructor is private to prevent creating an instance of
329 * this utility class.
330 */
331 private LocalPref() {
332 }
333
334 /** BGP UPDATE Attributes Type Code LOCAL_PREF. */
335 public static final int TYPE = 5;
336
337 /** BGP UPDATE Attributes Type Code LOCAL_PREF length. */
338 public static final int LENGTH = 4;
339 }
340
341 /**
342 * BGP UPDATE: ATOMIC_AGGREGATE related constants.
343 */
344 public static final class AtomicAggregate {
345 /**
346 * Default constructor.
347 * <p>
348 * The constructor is private to prevent creating an instance of
349 * this utility class.
350 */
351 private AtomicAggregate() {
352 }
353
354 /** BGP UPDATE Attributes Type Code ATOMIC_AGGREGATE. */
355 public static final int TYPE = 6;
356
357 /** BGP UPDATE Attributes Type Code ATOMIC_AGGREGATE length. */
358 public static final int LENGTH = 0;
359 }
360
361 /**
362 * BGP UPDATE: AGGREGATOR related constants.
363 */
364 public static final class Aggregator {
365 /**
366 * Default constructor.
367 * <p>
368 * The constructor is private to prevent creating an instance of
369 * this utility class.
370 */
371 private Aggregator() {
372 }
373
374 /** BGP UPDATE Attributes Type Code AGGREGATOR. */
375 public static final int TYPE = 7;
376
Pavlin Radoslavova460e292015-03-17 18:04:56 -0700377 /** BGP UPDATE Attributes Type Code AGGREGATOR length: 2 octet AS. */
378 public static final int AS2_LENGTH = 6;
379
380 /** BGP UPDATE Attributes Type Code AGGREGATOR length: 4 octet AS. */
381 public static final int AS4_LENGTH = 8;
Jonathan Hartab63aac2014-10-16 08:52:55 -0700382 }
Pavlin Radoslavovc7648ee2014-12-19 16:20:33 -0800383
384 /**
385 * BGP UPDATE: MP_REACH_NLRI related constants.
386 */
387 public static final class MpReachNlri {
388 /**
389 * Default constructor.
390 * <p>
391 * The constructor is private to prevent creating an instance of
392 * this utility class.
393 */
394 private MpReachNlri() {
395 }
396
397 /** BGP UPDATE Attributes Type Code MP_REACH_NLRI. */
398 public static final int TYPE = 14;
399
400 /** BGP UPDATE Attributes Type Code MP_REACH_NLRI min length. */
401 public static final int MIN_LENGTH = 5;
402 }
403
404 /**
405 * BGP UPDATE: MP_UNREACH_NLRI related constants.
406 */
407 public static final class MpUnreachNlri {
408 /**
409 * Default constructor.
410 * <p>
411 * The constructor is private to prevent creating an instance of
412 * this utility class.
413 */
414 private MpUnreachNlri() {
415 }
416
417 /** BGP UPDATE Attributes Type Code MP_UNREACH_NLRI. */
418 public static final int TYPE = 15;
419
420 /** BGP UPDATE Attributes Type Code MP_UNREACH_NLRI min length. */
421 public static final int MIN_LENGTH = 3;
422 }
Jonathan Hartab63aac2014-10-16 08:52:55 -0700423 }
424
425 /**
426 * BGP NOTIFICATION related constants.
427 */
428 public static final class Notifications {
429 /**
430 * Default constructor.
431 * <p>
432 * The constructor is private to prevent creating an instance of
433 * this utility class.
434 */
435 private Notifications() {
436 }
437
438 /**
439 * BGP NOTIFICATION: Message Header Error constants.
440 */
441 public static final class MessageHeaderError {
442 /**
443 * Default constructor.
444 * <p>
445 * The constructor is private to prevent creating an instance of
446 * this utility class.
447 */
448 private MessageHeaderError() {
449 }
450
451 /** Message Header Error code. */
452 public static final int ERROR_CODE = 1;
453
454 /** Message Header Error subcode: Connection Not Synchronized. */
455 public static final int CONNECTION_NOT_SYNCHRONIZED = 1;
456
457 /** Message Header Error subcode: Bad Message Length. */
458 public static final int BAD_MESSAGE_LENGTH = 2;
459
460 /** Message Header Error subcode: Bad Message Type. */
461 public static final int BAD_MESSAGE_TYPE = 3;
462 }
463
464 /**
465 * BGP NOTIFICATION: OPEN Message Error constants.
466 */
467 public static final class OpenMessageError {
468 /**
469 * Default constructor.
470 * <p>
471 * The constructor is private to prevent creating an instance of
472 * this utility class.
473 */
474 private OpenMessageError() {
475 }
476
477 /** OPEN Message Error code. */
478 public static final int ERROR_CODE = 2;
479
480 /** OPEN Message Error subcode: Unsupported Version Number. */
481 public static final int UNSUPPORTED_VERSION_NUMBER = 1;
482
483 /** OPEN Message Error subcode: Bad PEER AS. */
484 public static final int BAD_PEER_AS = 2;
485
486 /** OPEN Message Error subcode: Unacceptable Hold Time. */
487 public static final int UNACCEPTABLE_HOLD_TIME = 6;
488 }
489
490 /**
491 * BGP NOTIFICATION: UPDATE Message Error constants.
492 */
493 public static final class UpdateMessageError {
494 /**
495 * Default constructor.
496 * <p>
497 * The constructor is private to prevent creating an instance of
498 * this utility class.
499 */
500 private UpdateMessageError() {
501 }
502
503 /** UPDATE Message Error code. */
504 public static final int ERROR_CODE = 3;
505
506 /** UPDATE Message Error subcode: Malformed Attribute List. */
507 public static final int MALFORMED_ATTRIBUTE_LIST = 1;
508
509 /** UPDATE Message Error subcode: Unrecognized Well-known Attribute. */
510 public static final int UNRECOGNIZED_WELL_KNOWN_ATTRIBUTE = 2;
511
512 /** UPDATE Message Error subcode: Missing Well-known Attribute. */
513 public static final int MISSING_WELL_KNOWN_ATTRIBUTE = 3;
514
515 /** UPDATE Message Error subcode: Attribute Flags Error. */
516 public static final int ATTRIBUTE_FLAGS_ERROR = 4;
517
518 /** UPDATE Message Error subcode: Attribute Length Error. */
519 public static final int ATTRIBUTE_LENGTH_ERROR = 5;
520
521 /** UPDATE Message Error subcode: Invalid ORIGIN Attribute. */
522 public static final int INVALID_ORIGIN_ATTRIBUTE = 6;
523
524 /** UPDATE Message Error subcode: Invalid NEXT_HOP Attribute. */
525 public static final int INVALID_NEXT_HOP_ATTRIBUTE = 8;
526
527 /** UPDATE Message Error subcode: Optional Attribute Error. Unused. */
528 public static final int OPTIONAL_ATTRIBUTE_ERROR = 9;
529
530 /** UPDATE Message Error subcode: Invalid Network Field. */
531 public static final int INVALID_NETWORK_FIELD = 10;
532
533 /** UPDATE Message Error subcode: Malformed AS_PATH. */
534 public static final int MALFORMED_AS_PATH = 11;
535 }
536
537 /**
538 * BGP NOTIFICATION: Hold Timer Expired constants.
539 */
540 public static final class HoldTimerExpired {
541 /**
542 * Default constructor.
543 * <p>
544 * The constructor is private to prevent creating an instance of
545 * this utility class.
546 */
547 private HoldTimerExpired() {
548 }
549
550 /** Hold Timer Expired code. */
551 public static final int ERROR_CODE = 4;
552 }
553
554 /** BGP NOTIFICATION message Error subcode: Unspecific. */
555 public static final int ERROR_SUBCODE_UNSPECIFIC = 0;
556 }
557}