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; |
ghj0504520 | ed7340c | 2018-10-26 13:06:35 -0700 | [diff] [blame] | 20 | import org.onosproject.net.Annotations; |
Carmelo Cascone | 6a0b5a3 | 2017-11-20 23:08:32 -0800 | [diff] [blame] | 21 | import org.onosproject.net.DeviceId; |
| 22 | import org.onosproject.net.pi.runtime.PiEntity; |
| 23 | import org.onosproject.net.pi.runtime.PiHandle; |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 24 | import org.onosproject.p4runtime.api.P4RuntimeWriteClient; |
Carmelo Cascone | 6a0b5a3 | 2017-11-20 23:08:32 -0800 | [diff] [blame] | 25 | |
| 26 | import java.util.Collection; |
| 27 | |
| 28 | /** |
| 29 | * Service to keep track of the device state for a given class of PI entities. |
| 30 | * The need of this service comes from the fact that P4 Runtime makes a |
| 31 | * distinction between INSERT and MODIFY operations, while ONOS drivers use a |
| 32 | * more generic "APPLY" behaviour (i.e. ADD or UPDATE). When applying an entry, |
| 33 | * we need to know if another one with the same handle (e.g. table entry with |
| 34 | * same match key) is already on the device to decide between INSERT or MODIFY. |
| 35 | * Moreover, this service maintains a "timed" version of PI entities such that |
| 36 | * we can compute the life of the entity on the device. |
| 37 | * |
| 38 | * @param <H> Handle class |
| 39 | * @param <E> Entity class |
| 40 | */ |
| 41 | @Beta |
| 42 | public interface P4RuntimeMirror |
| 43 | <H extends PiHandle, E extends PiEntity> { |
| 44 | |
| 45 | /** |
| 46 | * Returns all entries for the given device ID. |
| 47 | * |
| 48 | * @param deviceId device ID |
| 49 | * @return collection of table entries |
| 50 | */ |
| 51 | Collection<TimedEntry<E>> getAll(DeviceId deviceId); |
| 52 | |
| 53 | /** |
| 54 | * Returns entry associated to the given handle, if present, otherwise |
| 55 | * null. |
| 56 | * |
| 57 | * @param handle handle |
| 58 | * @return PI table entry |
| 59 | */ |
| 60 | TimedEntry<E> get(H handle); |
| 61 | |
| 62 | /** |
| 63 | * Stores the given entry associating it to the given handle. |
| 64 | * |
| 65 | * @param handle handle |
| 66 | * @param entry entry |
| 67 | */ |
| 68 | void put(H handle, E entry); |
| 69 | |
| 70 | /** |
| 71 | * Removes the entry associated to the given handle. |
| 72 | * |
| 73 | * @param handle handle |
| 74 | */ |
| 75 | void remove(H handle); |
Carmelo Cascone | 50d195f | 2018-09-11 13:26:38 -0700 | [diff] [blame] | 76 | |
| 77 | /** |
ghj0504520 | ed7340c | 2018-10-26 13:06:35 -0700 | [diff] [blame] | 78 | * Stores the given annotations associating it to the given handle. |
| 79 | * |
Carmelo Cascone | 99c59db | 2019-01-17 15:39:35 -0800 | [diff] [blame] | 80 | * @param handle handle |
| 81 | * @param annotations entry |
ghj0504520 | ed7340c | 2018-10-26 13:06:35 -0700 | [diff] [blame] | 82 | */ |
| 83 | void putAnnotations(H handle, Annotations annotations); |
| 84 | |
| 85 | /** |
| 86 | * Returns annotations associated to the given handle, if present, otherwise |
| 87 | * null. |
| 88 | * |
| 89 | * @param handle handle |
| 90 | * @return PI table annotations |
| 91 | */ |
| 92 | Annotations annotations(H handle); |
| 93 | |
| 94 | /** |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 95 | * Synchronizes the state of the given device ID with the given collection |
| 96 | * of PI entities. |
Carmelo Cascone | 6146946 | 2019-03-05 23:59:11 -0800 | [diff] [blame^] | 97 | * |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 98 | * @param deviceId device ID |
| 99 | * @param entities collection of PI entities |
Carmelo Cascone | 50d195f | 2018-09-11 13:26:38 -0700 | [diff] [blame] | 100 | */ |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 101 | void sync(DeviceId deviceId, Collection<E> entities); |
| 102 | |
| 103 | /** |
Carmelo Cascone | 6146946 | 2019-03-05 23:59:11 -0800 | [diff] [blame^] | 104 | * Uses the given P4Runtime write request to update the state of this |
| 105 | * mirror by optimistically assuming that all updates in it will succeed. |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 106 | * |
Carmelo Cascone | 6146946 | 2019-03-05 23:59:11 -0800 | [diff] [blame^] | 107 | * @param request P4Runtime write request |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 108 | */ |
Carmelo Cascone | 6146946 | 2019-03-05 23:59:11 -0800 | [diff] [blame^] | 109 | void applyWriteRequest(P4RuntimeWriteClient.WriteRequest request); |
Carmelo Cascone | 6a0b5a3 | 2017-11-20 23:08:32 -0800 | [diff] [blame] | 110 | } |