blob: bee8c51e9617eb1f89899cf61b5ead2d41904f31 [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;
ghj0504520ed7340c2018-10-26 13:06:35 -070020import org.onosproject.net.Annotations;
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -080021import org.onosproject.net.DeviceId;
22import org.onosproject.net.pi.runtime.PiEntity;
23import org.onosproject.net.pi.runtime.PiHandle;
Carmelo Cascone4c289b72019-01-22 15:30:45 -080024import org.onosproject.p4runtime.api.P4RuntimeWriteClient;
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -080025
26import 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
42public 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 Cascone50d195f2018-09-11 13:26:38 -070076
77 /**
ghj0504520ed7340c2018-10-26 13:06:35 -070078 * Stores the given annotations associating it to the given handle.
79 *
Carmelo Cascone99c59db2019-01-17 15:39:35 -080080 * @param handle handle
81 * @param annotations entry
ghj0504520ed7340c2018-10-26 13:06:35 -070082 */
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 Cascone4c289b72019-01-22 15:30:45 -080095 * Synchronizes the state of the given device ID with the given collection
96 * of PI entities.
97 * @param deviceId device ID
98 * @param entities collection of PI entities
Carmelo Cascone50d195f2018-09-11 13:26:38 -070099 */
Carmelo Cascone4c289b72019-01-22 15:30:45 -0800100 void sync(DeviceId deviceId, Collection<E> entities);
101
102 /**
103 * Uses the given P4Runtime write response to update the state of this
104 * mirror.
105 *
106 * @param response P4Runtime write response
107 */
108 void replayWriteResponse(P4RuntimeWriteClient.WriteResponse response);
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -0800109}