Carmelo Cascone | 326ad2d | 2017-11-28 18:09:13 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-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.pi.service; |
| 18 | |
| 19 | import com.google.common.annotations.Beta; |
| 20 | import org.onosproject.net.pi.model.PiPipeconf; |
| 21 | import org.onosproject.net.pi.runtime.PiEntity; |
| 22 | import org.onosproject.net.pi.runtime.PiHandle; |
| 23 | |
| 24 | import java.util.Optional; |
| 25 | |
| 26 | /** |
| 27 | * A translator of PI entities to equivalent PD ones which offer means to learn |
| 28 | * translated entities for later use. |
| 29 | * |
| 30 | * @param <T> PD entity class (translatable to PI) |
| 31 | * @param <E> PI entity class |
| 32 | */ |
| 33 | @Beta |
| 34 | public interface PiTranslator<T extends PiTranslatable, E extends PiEntity> { |
| 35 | |
| 36 | /** |
| 37 | * Translate the given PD entity (original) and returns a PI entity that is |
| 38 | * equivalent to he PD one for the given pipeconf. |
| 39 | * |
| 40 | * @param original PD entity |
| 41 | * @param pipeconf pipeconf |
| 42 | * @return PI entity |
| 43 | * @throws PiTranslationException if a translation is not possible (see |
| 44 | * message for an explanation) |
| 45 | */ |
| 46 | E translate(T original, PiPipeconf pipeconf) |
| 47 | throws PiTranslationException; |
| 48 | |
| 49 | /** |
| 50 | * Stores a mapping between the given translated entity and handle. |
| 51 | * |
| 52 | * @param handle PI entity handle |
| 53 | * @param entity PI translated entity |
| 54 | */ |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 55 | void learn(PiHandle handle, PiTranslatedEntity<T, E> entity); |
Carmelo Cascone | 326ad2d | 2017-11-28 18:09:13 -0800 | [diff] [blame] | 56 | |
| 57 | /** |
| 58 | * Returns a PI translated entity that was previously associated with the |
| 59 | * given handle, if present. If not present, it means a mapping between the |
| 60 | * two has not been learned by the system (via {@link #learn(PiHandle, |
| 61 | * PiTranslatedEntity)}) or that it has been removed (via {@link |
| 62 | * #forget(PiHandle)}). the |
| 63 | * |
| 64 | * @param handle PI entity handle |
| 65 | * @return optional PI translated entity |
| 66 | */ |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 67 | Optional<PiTranslatedEntity<T, E>> lookup(PiHandle handle); |
Carmelo Cascone | 326ad2d | 2017-11-28 18:09:13 -0800 | [diff] [blame] | 68 | |
| 69 | /** |
| 70 | * Removes any mapping for the given PI entity handle. |
| 71 | * |
| 72 | * @param handle PI entity handle. |
| 73 | */ |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 74 | void forget(PiHandle handle); |
Carmelo Cascone | 326ad2d | 2017-11-28 18:09:13 -0800 | [diff] [blame] | 75 | } |