blob: 3cd81f263aed7592af10deb3e70a965e30c7bc7b [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;
Andrea Campanella1e573442018-05-17 17:07:13 +020022import org.onosproject.net.device.ChannelListener;
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040023
24/**
25 * Controller of P4Runtime devices.
26 */
27@Beta
28public interface P4RuntimeController extends ListenerService<P4RuntimeEvent, P4RuntimeEventListener> {
29
30 /**
Carmelo Cascone44448a52018-06-25 23:36:57 +020031 * Instantiates a new client to operate on a P4Runtime device identified by
32 * the given information. As a result of this method, a {@link
33 * P4RuntimeClient} can be later obtained by invoking {@link
34 * #getClient(DeviceId)}. Returns true if the client was created and the
35 * channel to the device is open, false otherwise.
36 * <p>
37 * Only one client can exist for the same device ID. Calls to this method
38 * are idempotent for the same [device ID, address, port, p4DeviceId] tuple,
39 * i.e. returns true if such client already exists but a new one is not
40 * created. Throws an {@link IllegalStateException} if a client for device
41 * ID already exists but for different [address, port, p4DeviceId].
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040042 *
Carmelo Cascone44448a52018-06-25 23:36:57 +020043 * @param deviceId device identifier
44 * @param serverAddr address of the P4Runtime server
45 * @param serverPort port of the P4Runtime server
46 * @param p4DeviceId P4Runtime-specific device identifier
47 * @return true if the client was created and the channel to the device is
48 * open
49 * @throws IllegalStateException if a client already exists for this device
50 * ID but for different [address, port,
51 * p4DeviceId].
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040052 */
Carmelo Cascone44448a52018-06-25 23:36:57 +020053 boolean createClient(DeviceId deviceId, String serverAddr, int serverPort,
54 long p4DeviceId);
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040055
56 /**
57 * Returns a client to operate on the given device.
58 *
59 * @param deviceId device identifier
60 * @return client instance
61 * @throws IllegalStateException if no client exists for the given device identifier
62 */
63 P4RuntimeClient getClient(DeviceId deviceId);
64
65 /**
66 * Removes the client for the given device. If no client exists for the given device identifier, the
67 * result is a no-op.
68 *
69 * @param deviceId device identifier
70 */
71 void removeClient(DeviceId deviceId);
72
73 /**
74 * Returns true if a client exists for the given device identifier, false otherwise.
75 *
76 * @param deviceId device identifier
77 * @return true if client exists, false otherwise.
78 */
79 boolean hasClient(DeviceId deviceId);
Carmelo Cascone59f57de2017-07-11 19:55:09 -040080
81 /**
82 * Returns true if the P4Runtime server running on the given device is reachable, i.e. the channel is open and the
83 * server is able to respond to RPCs, false otherwise. Reachability can be tested only if a client was previously
Carmelo Cascone44448a52018-06-25 23:36:57 +020084 * created using {@link #createClient(DeviceId, String, int, long)}, otherwise this method returns false.
Carmelo Cascone59f57de2017-07-11 19:55:09 -040085 *
86 * @param deviceId device identifier.
87 * @return true if a client was created and is able to contact the P4Runtime server, false otherwise.
88 */
89 boolean isReacheable(DeviceId deviceId);
Yi Tseng3e7f1452017-10-20 10:31:53 -070090
91 /**
92 * Gets new election id for device arbitration request.
93 *
94 * @return the election id
95 */
96 long getNewMasterElectionId();
Andrea Campanella1e573442018-05-17 17:07:13 +020097
98 /**
99 * Adds a listener for P4Runtime client-server channel events.
100 * If the channel for the device is not present and/or established the listener will get notified
101 * only after channel setup.
102 *
103 * @param deviceId device identifier
104 * @param listener the channel listener
105 */
106 void addChannelListener(DeviceId deviceId, ChannelListener listener);
107
108 /**
109 * Removes the listener for P4Runtime client-server channel events.
110 *
111 * @param deviceId device identifier
112 * @param listener the channel listener
113 */
114 void removeChannelListener(DeviceId deviceId, ChannelListener listener);
Carmelo Casconef7aa3f92017-07-06 23:56:50 -0400115}