blob: 202636abe661a10cd41df15403c9fc420af68bb2 [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 */
55 void learn(PiHandle<E> handle, PiTranslatedEntity<T, E> entity);
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 */
67 Optional<PiTranslatedEntity<T, E>> lookup(PiHandle<E> handle);
68
69 /**
70 * Removes any mapping for the given PI entity handle.
71 *
72 * @param handle PI entity handle.
73 */
74 void forget(PiHandle<E> handle);
75}