Get rid of JSR305 annotations
[bgpcep.git] / bgp / parser-spi / src / main / java / org / opendaylight / protocol / bgp / parser / spi / AttributeParser.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.bgp.parser.spi;
9
10 import io.netty.buffer.ByteBuf;
11 import org.eclipse.jdt.annotation.NonNull;
12 import org.eclipse.jdt.annotation.Nullable;
13 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
14 import org.opendaylight.protocol.bgp.parser.BGPError;
15 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
16 import org.opendaylight.protocol.bgp.parser.BGPTreatAsWithdrawException;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder;
18
19 /**
20  * Common interface for attribute parser implementation. Implementations should consider deriving from
21  * {@link AbstractAttributeParser} and provide an RFC7606-compliant interface.
22  */
23 public interface AttributeParser {
24     /**
25      * Parses attribute from ByteBuf buffer.
26      *
27      * @param buffer Encoded attribute body in ByteBuf.
28      * @param builder Path attributes builder. Guaranteed to contain all valid attributes whose type is numerically
29      *        lower than this attribute's type.
30      * @param constraint Peer specific constraints, may be null
31      * @throws BGPDocumentedException when an irrecoverable error occurred which has a {@link BGPError} assigned
32      * @throws BGPParsingException when a general unspecified parsing error occurs.
33      */
34     void parseAttribute(@NonNull ByteBuf buffer, @NonNull AttributesBuilder builder,
35             @Nullable PeerSpecificParserConstraint constraint) throws BGPDocumentedException, BGPParsingException;
36
37     /**
38      * Parses attribute from ByteBuf buffer with the specified {@link RevisedErrorHandling}. Default implementation
39      * ignores error handling and defers to
40      * {@link #parseAttribute(ByteBuf, AttributesBuilder, PeerSpecificParserConstraint)}.
41      *
42      * @param buffer Encoded attribute body in ByteBuf.
43      * @param builder Path attributes builder. Guaranteed to contain all valid attributes whose type is numerically
44      *        lower than this attribute's type.
45      * @param errorHandling RFC7606 error handling type
46      * @param constraint Peer specific constraints, may be null
47      * @throws BGPDocumentedException when an irrecoverable error occurred which has a {@link BGPError} assigned
48      * @throws BGPParsingException when a general unspecified parsing error occurs.
49      * @throws BGPTreatAsWithdrawException when parsing according to revised error handling indicates the
50      *                                              message should be treated as withdraw.
51      */
52     default void parseAttribute(final @NonNull ByteBuf buffer, final @NonNull AttributesBuilder builder,
53             final @NonNull RevisedErrorHandling errorHandling, final @Nullable PeerSpecificParserConstraint constraint)
54                     throws BGPDocumentedException, BGPParsingException, BGPTreatAsWithdrawException {
55         parseAttribute(buffer, builder, constraint);
56     }
57
58     /**
59      * Determine whether a duplicate attribute should be ignored or {@link BGPError#MALFORMED_ATTR_LIST} should be
60      * raised. This is useful for MP_REACH/MP_UNREACH attributes, which need to emit a Notification under RFC7606
61      * rules.
62      *
63      * @param errorHandling Revised error handling type
64      * @return True if the duplicate attribute should be ignored, false if a BGPError should be raised.
65      */
66     default boolean ignoreDuplicates(final @NonNull RevisedErrorHandling errorHandling) {
67         return true;
68     }
69 }