blob: 96f8c85ea357612cd05e5eb9f20822e93bf9c7d7 [file] [log] [blame]
Daniele Moro5e66f982021-06-11 16:41:48 +02001/*
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
17package org.onosproject.net.behaviour.upf;
18
tosinski36ba33a2021-11-22 16:53:00 +010019import com.google.common.annotations.Beta;
20
21import java.util.Optional;
22
Daniele Moro5e66f982021-06-11 16:41:48 +020023/**
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 */
tosinski36ba33a2021-11-22 16:53:00 +010029@Beta
Daniele Moro5e66f982021-06-11 16:41:48 +020030public class UpfProgrammableException extends Exception {
31 private final Type type;
tosinski36ba33a2021-11-22 16:53:00 +010032 private final UpfEntityType entityType;
Daniele Moro5e66f982021-06-11 16:41:48 +020033
34 public enum Type {
35 /**
36 * The UpfProgrammable did not provide a specific exception type.
37 */
38 UNKNOWN,
39 /**
tosinski36ba33a2021-11-22 16:53:00 +010040 * The target entity is at capacity.
Daniele Moro5e66f982021-06-11 16:41:48 +020041 */
tosinski36ba33a2021-11-22 16:53:00 +010042 ENTITY_EXHAUSTED,
Daniele Moro5e66f982021-06-11 16:41:48 +020043 /**
tosinski36ba33a2021-11-22 16:53:00 +010044 * A provided index was out of range.
Daniele Moro5e66f982021-06-11 16:41:48 +020045 */
tosinski36ba33a2021-11-22 16:53:00 +010046 ENTITY_OUT_OF_RANGE,
Daniele Moro5e66f982021-06-11 16:41:48 +020047 /**
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;
tosinski36ba33a2021-11-22 16:53:00 +010061 this.entityType = null;
Daniele Moro5e66f982021-06-11 16:41:48 +020062 }
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;
tosinski36ba33a2021-11-22 16:53:00 +010073 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 Moro5e66f982021-06-11 16:41:48 +020087 }
88
89 /**
90 * Get the type of the exception.
91 *
92 * @return exception type
93 */
94 public Type getType() {
95 return type;
96 }
tosinski36ba33a2021-11-22 16:53:00 +010097
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 Moro5e66f982021-06-11 16:41:48 +0200106}