2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.protocol.bgp.parser;
10 import com.google.common.base.Preconditions;
11 import com.google.common.primitives.UnsignedBytes;
12 import org.opendaylight.protocol.util.Values;
15 * There are several errors documented in RFC4271 or in draft, that have specific meaning for the BGP.
16 * This exception is used, when any of those errors occurs.
18 public final class BGPDocumentedException extends AbstractBGPException {
19 private static final long serialVersionUID = -6212702584439430736L;
22 * Used when an error occurred that is described in an RFC or a draft.
24 * @param error specific documented error
26 public BGPDocumentedException(final BGPError error) {
27 this(null, error, null, null);
31 * Used when an error occurred that is described in an RFC or a draft.
33 * @param message message bound with this exception
34 * @param error specific documented error
36 public BGPDocumentedException(final String message, final BGPError error) {
37 this(message, error, null, null);
41 * Used when an error occurred that is described in an RFC or a draft.
43 * @param message message bound with this exception
44 * @param error specific documented error
45 * @param cause cause for the error
47 public BGPDocumentedException(final String message, final BGPError error, final Exception cause) {
48 this(message, error, null, cause);
52 * Used when an error occurred that is described in an RFC or a draft.
54 * @param message message bound with this exception
55 * @param error specific documented error
56 * @param data data associated with the error
58 public BGPDocumentedException(final String message, final BGPError error, final byte[] data) {
59 this(message, error, data, null);
63 * Used when an error occurred that is described in an RFC or a draft.
65 * @param message message bound with this exception
66 * @param error specific documented error
67 * @param data data associated with the error
68 * @param cause cause for the error
70 public BGPDocumentedException(final String message, final BGPError error, final byte[] data,
71 final Exception cause) {
72 super(message, error, data, cause);
76 * Used when an error occurred that is described in an RFC or a draft.
78 * @param cause cause for the error
80 public BGPDocumentedException(final BGPTreatAsWithdrawException cause) {
81 this(cause.getMessage(), cause.getError(), cause.getData(), cause);
84 public static BGPDocumentedException badMessageLength(final String message, final int length) {
85 Preconditions.checkArgument(length >= 0 && length <= Values.UNSIGNED_SHORT_MAX_VALUE);
87 return new BGPDocumentedException(message, BGPError.BAD_MSG_LENGTH, new byte[] {
88 UnsignedBytes.checkedCast(length / (Values.UNSIGNED_BYTE_MAX_VALUE + 1)),
89 UnsignedBytes.checkedCast(length % (Values.UNSIGNED_BYTE_MAX_VALUE + 1)) });