blob: 499fdc5027c2b812b27ce6bf3cbf4ec774bba5f0 [file] [log] [blame]
Carmelo Cascone326ad2d2017-11-28 18:09:13 -08001/*
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
17package org.onosproject.net.pi.service;
18
19import com.google.common.annotations.Beta;
20import org.onosproject.net.pi.model.PiPipeconf;
21import org.onosproject.net.pi.runtime.PiEntity;
22import org.onosproject.net.pi.runtime.PiHandle;
23
24import 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
34public 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 Cascone4c289b72019-01-22 15:30:45 -080055 void learn(PiHandle handle, PiTranslatedEntity<T, E> entity);
Carmelo Cascone326ad2d2017-11-28 18:09:13 -080056
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 Cascone4c289b72019-01-22 15:30:45 -080067 Optional<PiTranslatedEntity<T, E>> lookup(PiHandle handle);
Carmelo Cascone326ad2d2017-11-28 18:09:13 -080068
69 /**
70 * Removes any mapping for the given PI entity handle.
71 *
72 * @param handle PI entity handle.
73 */
Carmelo Cascone4c289b72019-01-22 15:30:45 -080074 void forget(PiHandle handle);
Carmelo Cascone326ad2d2017-11-28 18:09:13 -080075}