blob: ecdcb31c61bf1fbf8112aedb442b2a4824ddc88c [file] [log] [blame]
Carmelo Casconef7aa3f92017-07-06 23:56:50 -04001/*
2 * Copyright 2017-present Open Networking Laboratory
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.p4runtime.api;
18
19import com.google.common.annotations.Beta;
20import io.grpc.ManagedChannelBuilder;
21import org.onosproject.event.ListenerService;
22import org.onosproject.net.DeviceId;
23
24/**
25 * Controller of P4Runtime devices.
26 */
27@Beta
28public interface P4RuntimeController extends ListenerService<P4RuntimeEvent, P4RuntimeEventListener> {
29
30 /**
31 * Instantiates a new client to operate on the device identified by the given information and reachable using the
32 * given gRPC channel builder. As a result of this method, a {@link P4RuntimeClient} can be later obtained by
33 * invoking {@link #getClient(DeviceId)}. Only one client can exist for the same device identifier. Returns true if
34 * the client was created and the channel to the device is open, false otherwise.
35 *
36 * @param deviceId device identifier
37 * @param p4DeviceId P4Runtime-specific device identifier
38 * @param channelBuilder gRPC channel builder pointing at the P4Runtime server in execution on the device
39 * @return true if the client was created and the channel to the device is open
40 * @throws IllegalStateException if a client already exists for the given device identifier
41 */
42 boolean createClient(DeviceId deviceId, int p4DeviceId, ManagedChannelBuilder channelBuilder);
43
44 /**
45 * Returns a client to operate on the given device.
46 *
47 * @param deviceId device identifier
48 * @return client instance
49 * @throws IllegalStateException if no client exists for the given device identifier
50 */
51 P4RuntimeClient getClient(DeviceId deviceId);
52
53 /**
54 * Removes the client for the given device. If no client exists for the given device identifier, the
55 * result is a no-op.
56 *
57 * @param deviceId device identifier
58 */
59 void removeClient(DeviceId deviceId);
60
61 /**
62 * Returns true if a client exists for the given device identifier, false otherwise.
63 *
64 * @param deviceId device identifier
65 * @return true if client exists, false otherwise.
66 */
67 boolean hasClient(DeviceId deviceId);
Carmelo Cascone59f57de2017-07-11 19:55:09 -040068
69 /**
70 * Returns true if the P4Runtime server running on the given device is reachable, i.e. the channel is open and the
71 * server is able to respond to RPCs, false otherwise. Reachability can be tested only if a client was previously
72 * created using {@link #createClient(DeviceId, int, ManagedChannelBuilder)}, otherwise this method returns false.
73 *
74 * @param deviceId device identifier.
75 * @return true if a client was created and is able to contact the P4Runtime server, false otherwise.
76 */
77 boolean isReacheable(DeviceId deviceId);
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040078}