2 * Copyright (c) 2018 AT&T Intellectual Property. 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.spi;
10 import org.eclipse.jdt.annotation.NonNullByDefault;
11 import org.eclipse.jdt.annotation.Nullable;
12 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
13 import org.opendaylight.protocol.bgp.parser.BGPError;
14 import org.opendaylight.protocol.bgp.parser.BGPTreatAsWithdrawException;
17 * Enumeration of possible treatments an UPDATE message and attributes can get based on the configuration of a peer.
19 * @author Robert Varga
22 public enum RevisedErrorHandling {
24 * Do not use RFC7606 Revised Error Handling.
28 public BGPDocumentedException reportError(final BGPError error, final @Nullable Exception cause,
29 final String format, final Object... args) throws BGPDocumentedException {
30 throw new BGPDocumentedException(String.format(format, args), error, cause);
34 * Use RFC7606 Revised Error Handling, the peer is an internal neighbor.
38 * Use RFC7606 Revised Error Handling, the peer is an external neighbor.
43 * Determine Revised Error Handling from the contents of a {@link PeerSpecificParserConstraint}.
45 * @param constraint Peer-specific constraint
46 * @return Revised Error Handling treatment message/attributes should receive.
48 public static RevisedErrorHandling from(final @Nullable PeerSpecificParserConstraint constraint) {
49 return constraint == null ? NONE : constraint.getPeerConstraint(RevisedErrorHandlingSupport.class)
50 .map(support -> support.isExternalPeer() ? EXTERNAL : INTERNAL).orElse(NONE);
54 * Report a failure to parse an attribute resulting either in treat-as-withdraw if RFC7606 is in effect, or
55 * connection teardown if it is not.
57 * @param error {@link BGPError} to report in case of a session teardown
58 * @param cause Parsing failure cause
59 * @param format Message format string
60 * @param args Message format arguments
61 * @return This method does not return
62 * @throws BGPTreatAsWithdrawException if Revised Error Handling is in effect
63 * @throws BGPDocumentedException if Revised Error Handling is in not effect
65 public BGPDocumentedException reportError(final BGPError error, final @Nullable Exception cause,
66 final String format, final Object... args) throws BGPDocumentedException, BGPTreatAsWithdrawException {
67 throw new BGPTreatAsWithdrawException(error, cause, format, args);
71 * Report a failure to parse an attribute resulting either in treat-as-withdraw if RFC7606 is in effect, or
72 * connection teardown if it is not.
74 * @param error {@link BGPError} to report in case of a session teardown
75 * @param format Message format string
76 * @param args Message format arguments
77 * @return This method does not return
78 * @throws BGPTreatAsWithdrawException if Revised Error Handling is in effect
79 * @throws BGPDocumentedException if Revised Error Handling is in not effect
81 public BGPDocumentedException reportError(final BGPError error, final String format, final Object... args)
82 throws BGPDocumentedException, BGPTreatAsWithdrawException {
83 throw reportError(error, null, format, args);