blob: 836ed7aa2f461156af3e7d0116eb2e54b01b159e [file] [log] [blame]
Carmelo Casconef7aa3f92017-07-06 23:56:50 -04001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Carmelo Casconef7aa3f92017-07-06 23:56:50 -04003 *
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.p4runtime.api;
18
19import com.google.common.annotations.Beta;
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040020import org.onosproject.event.ListenerService;
21import org.onosproject.net.DeviceId;
Carmelo Casconee5b28722018-06-22 17:28:28 +020022import org.onosproject.net.device.DeviceAgentListener;
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040023
24/**
25 * Controller of P4Runtime devices.
26 */
27@Beta
Carmelo Casconee5b28722018-06-22 17:28:28 +020028public interface P4RuntimeController
29 extends ListenerService<P4RuntimeEvent, P4RuntimeEventListener> {
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040030
31 /**
Carmelo Cascone44448a52018-06-25 23:36:57 +020032 * Instantiates a new client to operate on a P4Runtime device identified by
33 * the given information. As a result of this method, a {@link
34 * P4RuntimeClient} can be later obtained by invoking {@link
35 * #getClient(DeviceId)}. Returns true if the client was created and the
36 * channel to the device is open, false otherwise.
37 * <p>
38 * Only one client can exist for the same device ID. Calls to this method
Carmelo Cascone158b8c42018-07-04 19:42:37 +020039 * are idempotent for the same [device ID, address, port, p4DeviceId]
40 * triplet, i.e. returns true if such client already exists but a new one is
41 * not created. Throws an {@link IllegalStateException} if a client for
42 * device ID already exists but for different [address, port, p4DeviceId].
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040043 *
Carmelo Cascone44448a52018-06-25 23:36:57 +020044 * @param deviceId device identifier
45 * @param serverAddr address of the P4Runtime server
46 * @param serverPort port of the P4Runtime server
47 * @param p4DeviceId P4Runtime-specific device identifier
48 * @return true if the client was created and the channel to the device is
49 * open
50 * @throws IllegalStateException if a client already exists for this device
51 * ID but for different [address, port,
Carmelo Cascone158b8c42018-07-04 19:42:37 +020052 * p4DeviceId] triplet.
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040053 */
Carmelo Cascone44448a52018-06-25 23:36:57 +020054 boolean createClient(DeviceId deviceId, String serverAddr, int serverPort,
55 long p4DeviceId);
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040056
57 /**
Carmelo Cascone158b8c42018-07-04 19:42:37 +020058 * Returns a client to operate on the given device, or null if a client for
59 * such device does not exist in this controller.
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040060 *
61 * @param deviceId device identifier
Carmelo Cascone158b8c42018-07-04 19:42:37 +020062 * @return client instance or null
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040063 */
64 P4RuntimeClient getClient(DeviceId deviceId);
65
66 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +020067 * Removes the client for the given device. If no client exists for the
68 * given device identifier, the result is a no-op.
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040069 *
70 * @param deviceId device identifier
71 */
72 void removeClient(DeviceId deviceId);
73
74 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +020075 * Returns true if a client exists for the given device identifier, false
76 * otherwise.
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040077 *
78 * @param deviceId device identifier
79 * @return true if client exists, false otherwise.
80 */
81 boolean hasClient(DeviceId deviceId);
Carmelo Cascone59f57de2017-07-11 19:55:09 -040082
83 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +020084 * Returns true if the P4Runtime server running on the given device is
85 * reachable, i.e. the channel is open and the server is able to respond to
86 * RPCs, false otherwise. Reachability can be tested only if a client was
87 * previously created using {@link #createClient(DeviceId, String, int,
88 * long)}, otherwise this method returns false.
Carmelo Cascone59f57de2017-07-11 19:55:09 -040089 *
90 * @param deviceId device identifier.
Carmelo Casconee5b28722018-06-22 17:28:28 +020091 * @return true if a client was created and is able to contact the P4Runtime
92 * server, false otherwise.
Carmelo Cascone59f57de2017-07-11 19:55:09 -040093 */
Carmelo Cascone158b8c42018-07-04 19:42:37 +020094 boolean isReachable(DeviceId deviceId);
Yi Tseng3e7f1452017-10-20 10:31:53 -070095
96 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +020097 * Adds a listener for device agent events.
Andrea Campanella1e573442018-05-17 17:07:13 +020098 *
99 * @param deviceId device identifier
Carmelo Casconee5b28722018-06-22 17:28:28 +0200100 * @param listener the device agent listener
Andrea Campanella1e573442018-05-17 17:07:13 +0200101 */
Carmelo Casconee5b28722018-06-22 17:28:28 +0200102 void addDeviceAgentListener(DeviceId deviceId, DeviceAgentListener listener);
Andrea Campanella1e573442018-05-17 17:07:13 +0200103
104 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +0200105 * Removes the listener for device agent events.
Andrea Campanella1e573442018-05-17 17:07:13 +0200106 *
107 * @param deviceId device identifier
Carmelo Casconee5b28722018-06-22 17:28:28 +0200108 * @param listener the device agent listener
Andrea Campanella1e573442018-05-17 17:07:13 +0200109 */
Carmelo Casconee5b28722018-06-22 17:28:28 +0200110 void removeDeviceAgentListener(DeviceId deviceId, DeviceAgentListener listener);
Carmelo Casconef7aa3f92017-07-06 23:56:50 -0400111}