Carmelo Cascone | 6a0b5a3 | 2017-11-20 23:08:32 -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.drivers.p4runtime.mirror; |
| 18 | |
| 19 | import com.google.common.annotations.Beta; |
| 20 | import org.onosproject.net.DeviceId; |
| 21 | import org.onosproject.net.pi.runtime.PiEntity; |
| 22 | import org.onosproject.net.pi.runtime.PiHandle; |
| 23 | |
| 24 | import 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 |
| 40 | public 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 | } |