Daniele Moro | 5e66f98 | 2021-06-11 16:41:48 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2021-present Open Networking Foundation |
| 3 | * |
| 4 | * 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 |
| 7 | * |
| 8 | * 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. |
| 15 | */ |
| 16 | |
| 17 | package org.onosproject.net.behaviour.upf; |
| 18 | |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame^] | 19 | import com.google.common.annotations.Beta; |
| 20 | |
| 21 | import java.util.Optional; |
| 22 | |
Daniele Moro | 5e66f98 | 2021-06-11 16:41:48 +0200 | [diff] [blame] | 23 | /** |
| 24 | * An exception indicating a an error happened in the UPF programmable behaviour. |
| 25 | * Possible errors include the attempted insertion of a malformed flow rule, the |
| 26 | * reading or writing of an out-of-bounds counter cell, the deletion of a non-existent |
| 27 | * flow rule, and the attempted insertion of a flow rule into a full table. |
| 28 | */ |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame^] | 29 | @Beta |
Daniele Moro | 5e66f98 | 2021-06-11 16:41:48 +0200 | [diff] [blame] | 30 | public class UpfProgrammableException extends Exception { |
| 31 | private final Type type; |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame^] | 32 | private final UpfEntityType entityType; |
Daniele Moro | 5e66f98 | 2021-06-11 16:41:48 +0200 | [diff] [blame] | 33 | |
| 34 | public enum Type { |
| 35 | /** |
| 36 | * The UpfProgrammable did not provide a specific exception type. |
| 37 | */ |
| 38 | UNKNOWN, |
| 39 | /** |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame^] | 40 | * The target entity is at capacity. |
Daniele Moro | 5e66f98 | 2021-06-11 16:41:48 +0200 | [diff] [blame] | 41 | */ |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame^] | 42 | ENTITY_EXHAUSTED, |
Daniele Moro | 5e66f98 | 2021-06-11 16:41:48 +0200 | [diff] [blame] | 43 | /** |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame^] | 44 | * A provided index was out of range. |
Daniele Moro | 5e66f98 | 2021-06-11 16:41:48 +0200 | [diff] [blame] | 45 | */ |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame^] | 46 | ENTITY_OUT_OF_RANGE, |
Daniele Moro | 5e66f98 | 2021-06-11 16:41:48 +0200 | [diff] [blame] | 47 | /** |
| 48 | * The UpfProgrammable implementation doesn't support the operation. |
| 49 | */ |
| 50 | UNSUPPORTED_OPERATION |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Creates a new exception for the given message. |
| 55 | * |
| 56 | * @param message message |
| 57 | */ |
| 58 | public UpfProgrammableException(String message) { |
| 59 | super(message); |
| 60 | this.type = Type.UNKNOWN; |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame^] | 61 | this.entityType = null; |
Daniele Moro | 5e66f98 | 2021-06-11 16:41:48 +0200 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Creates a new exception for the given message and type. |
| 66 | * |
| 67 | * @param message exception message |
| 68 | * @param type exception type |
| 69 | */ |
| 70 | public UpfProgrammableException(String message, Type type) { |
| 71 | super(message); |
| 72 | this.type = type; |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame^] | 73 | this.entityType = null; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Creates a new exception for the given message, type and entity type. |
| 78 | * |
| 79 | * @param message exception message |
| 80 | * @param type exception type |
| 81 | * @param entityType entity type |
| 82 | */ |
| 83 | public UpfProgrammableException(String message, Type type, UpfEntityType entityType) { |
| 84 | super(message); |
| 85 | this.type = type; |
| 86 | this.entityType = entityType; |
Daniele Moro | 5e66f98 | 2021-06-11 16:41:48 +0200 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Get the type of the exception. |
| 91 | * |
| 92 | * @return exception type |
| 93 | */ |
| 94 | public Type getType() { |
| 95 | return type; |
| 96 | } |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame^] | 97 | |
| 98 | /** |
| 99 | * Get the type of the entity that generated the exception. |
| 100 | * |
| 101 | * @return entity type |
| 102 | */ |
| 103 | public Optional<UpfEntityType> getEntityType() { |
| 104 | return Optional.ofNullable(entityType); |
| 105 | } |
Daniele Moro | 5e66f98 | 2021-06-11 16:41:48 +0200 | [diff] [blame] | 106 | } |