blob: ab18c9d5ab4742958ad20b43b0d88ce66abea75b [file] [log] [blame]
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -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.drivers.p4runtime.mirror;
18
19import com.google.common.annotations.Beta;
20import org.onosproject.net.DeviceId;
21import org.onosproject.net.pi.runtime.PiEntity;
22import org.onosproject.net.pi.runtime.PiHandle;
23
24import java.util.Collection;
25
26/**
27 * Service to keep track of the device state for a given class of PI entities.
28 * The need of this service comes from the fact that P4 Runtime makes a
29 * distinction between INSERT and MODIFY operations, while ONOS drivers use a
30 * more generic "APPLY" behaviour (i.e. ADD or UPDATE). When applying an entry,
31 * we need to know if another one with the same handle (e.g. table entry with
32 * same match key) is already on the device to decide between INSERT or MODIFY.
33 * Moreover, this service maintains a "timed" version of PI entities such that
34 * we can compute the life of the entity on the device.
35 *
36 * @param <H> Handle class
37 * @param <E> Entity class
38 */
39@Beta
40public interface P4RuntimeMirror
41 <H extends PiHandle, E extends PiEntity> {
42
43 /**
44 * Returns all entries for the given device ID.
45 *
46 * @param deviceId device ID
47 * @return collection of table entries
48 */
49 Collection<TimedEntry<E>> getAll(DeviceId deviceId);
50
51 /**
52 * Returns entry associated to the given handle, if present, otherwise
53 * null.
54 *
55 * @param handle handle
56 * @return PI table entry
57 */
58 TimedEntry<E> get(H handle);
59
60 /**
61 * Stores the given entry associating it to the given handle.
62 *
63 * @param handle handle
64 * @param entry entry
65 */
66 void put(H handle, E entry);
67
68 /**
69 * Removes the entry associated to the given handle.
70 *
71 * @param handle handle
72 */
73 void remove(H handle);
74}