Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Foundation |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.device; |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 17 | |
Thomas Vachuska | 42e8cce | 2015-07-29 19:25:18 -0700 | [diff] [blame] | 18 | import org.onosproject.event.ListenerService; |
Yuta HIGUCHI | 22ba76d | 2016-11-11 16:56:24 -0800 | [diff] [blame] | 19 | import org.onosproject.net.ConnectPoint; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 20 | import org.onosproject.net.Device; |
| 21 | import org.onosproject.net.DeviceId; |
| 22 | import org.onosproject.net.MastershipRole; |
| 23 | import org.onosproject.net.Port; |
| 24 | import org.onosproject.net.PortNumber; |
tom | b36046e | 2014-08-27 00:22:24 -0700 | [diff] [blame] | 25 | |
| 26 | import java.util.List; |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 27 | |
| 28 | /** |
| 29 | * Service for interacting with the inventory of infrastructure devices. |
| 30 | */ |
Thomas Vachuska | 42e8cce | 2015-07-29 19:25:18 -0700 | [diff] [blame] | 31 | public interface DeviceService |
| 32 | extends ListenerService<DeviceEvent, DeviceListener> { |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 33 | |
| 34 | /** |
tom | ad2d209 | 2014-09-06 23:24:20 -0700 | [diff] [blame] | 35 | * Returns the number of infrastructure devices known to the system. |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 36 | * |
tom | ad2d209 | 2014-09-06 23:24:20 -0700 | [diff] [blame] | 37 | * @return number of infrastructure devices |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 38 | */ |
tom | ad2d209 | 2014-09-06 23:24:20 -0700 | [diff] [blame] | 39 | int getDeviceCount(); |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 40 | |
| 41 | /** |
mskala | 32000d3 | 2017-07-14 16:27:06 +0200 | [diff] [blame] | 42 | * Returns the number of currently available devices known to the system. |
| 43 | * |
| 44 | * @return number of available devices |
| 45 | */ |
| 46 | default int getAvailableDeviceCount() { |
| 47 | return getDeviceCount(); |
| 48 | } |
| 49 | |
| 50 | /** |
tom | edf06bb | 2014-08-27 16:22:15 -0700 | [diff] [blame] | 51 | * Returns a collection of the currently known infrastructure |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 52 | * devices. |
| 53 | * |
| 54 | * @return collection of devices |
| 55 | */ |
| 56 | Iterable<Device> getDevices(); |
| 57 | |
| 58 | /** |
samuel | 738dfaf | 2015-07-11 11:08:57 +0800 | [diff] [blame] | 59 | * Returns a collection of the currently known infrastructure |
| 60 | * devices by device type. |
| 61 | * |
| 62 | * @param type device type |
| 63 | * @return collection of devices |
| 64 | */ |
| 65 | Iterable<Device> getDevices(Device.Type type); |
| 66 | |
| 67 | /** |
Yuta HIGUCHI | f1f2ac0 | 2014-11-26 14:02:22 -0800 | [diff] [blame] | 68 | * Returns an iterable collection of all devices |
| 69 | * currently available to the system. |
| 70 | * |
| 71 | * @return device collection |
| 72 | */ |
| 73 | Iterable<Device> getAvailableDevices(); |
| 74 | |
| 75 | /** |
samuel | 738dfaf | 2015-07-11 11:08:57 +0800 | [diff] [blame] | 76 | * Returns an iterable collection of all devices currently available to the system by device type. |
| 77 | * |
| 78 | * @param type device type |
| 79 | * @return device collection |
| 80 | */ |
| 81 | Iterable<Device> getAvailableDevices(Device.Type type); |
| 82 | |
| 83 | /** |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 84 | * Returns the device with the specified identifier. |
| 85 | * |
| 86 | * @param deviceId device identifier |
| 87 | * @return device or null if one with the given identifier is not known |
| 88 | */ |
| 89 | Device getDevice(DeviceId deviceId); |
| 90 | |
tom | ad2d209 | 2014-09-06 23:24:20 -0700 | [diff] [blame] | 91 | /** |
| 92 | * Returns the current mastership role for the specified device. |
| 93 | * |
| 94 | * @param deviceId device identifier |
| 95 | * @return designated mastership role |
| 96 | */ |
Ayaka Koshibe | 25fd23a | 2014-10-03 15:50:43 -0700 | [diff] [blame] | 97 | //XXX do we want this method here when MastershipService already does? |
tom | ad2d209 | 2014-09-06 23:24:20 -0700 | [diff] [blame] | 98 | MastershipRole getRole(DeviceId deviceId); |
| 99 | |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 100 | |
tom | b36046e | 2014-08-27 00:22:24 -0700 | [diff] [blame] | 101 | /** |
| 102 | * Returns the list of ports associated with the device. |
| 103 | * |
| 104 | * @param deviceId device identifier |
| 105 | * @return list of ports |
| 106 | */ |
| 107 | List<Port> getPorts(DeviceId deviceId); |
| 108 | |
| 109 | /** |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 110 | * Returns the list of port statistics associated with the device. |
| 111 | * |
Sho SHIMIZU | ceb6f13 | 2015-08-24 11:46:25 -0700 | [diff] [blame] | 112 | * @param deviceId device identifier |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 113 | * @return list of port statistics |
| 114 | */ |
| 115 | List<PortStatistics> getPortStatistics(DeviceId deviceId); |
| 116 | |
| 117 | /** |
Dusan Pajin | 11ff4a8 | 2015-08-20 18:03:05 +0200 | [diff] [blame] | 118 | * Returns the list of port delta statistics associated with the device. |
| 119 | * |
Sho SHIMIZU | ceb6f13 | 2015-08-24 11:46:25 -0700 | [diff] [blame] | 120 | * @param deviceId device identifier |
Dusan Pajin | 11ff4a8 | 2015-08-20 18:03:05 +0200 | [diff] [blame] | 121 | * @return list of port statistics |
| 122 | */ |
| 123 | List<PortStatistics> getPortDeltaStatistics(DeviceId deviceId); |
| 124 | |
| 125 | /** |
Viswanath KSP | 22774cd | 2016-08-20 20:06:30 +0530 | [diff] [blame] | 126 | * Returns the port specific port statistics associated with the device and port. |
| 127 | * |
| 128 | * @param deviceId device identifier |
| 129 | * @param portNumber port identifier |
| 130 | * @return port statistics of specified port |
| 131 | */ |
| 132 | default PortStatistics getStatisticsForPort(DeviceId deviceId, PortNumber portNumber) { |
| 133 | return null; |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Returns the port specific port delta statistics associated with the device and port. |
| 138 | * |
| 139 | * @param deviceId device identifier |
| 140 | * @param portNumber port identifier |
| 141 | * @return port delta statistics of specified port |
| 142 | */ |
| 143 | default PortStatistics getDeltaStatisticsForPort(DeviceId deviceId, PortNumber portNumber) { |
| 144 | return null; |
| 145 | } |
| 146 | |
| 147 | /** |
tom | b36046e | 2014-08-27 00:22:24 -0700 | [diff] [blame] | 148 | * Returns the port with the specified number and hosted by the given device. |
tom | ff7eb7c | 2014-09-08 12:49:03 -0700 | [diff] [blame] | 149 | * |
| 150 | * @param deviceId device identifier |
tom | b36046e | 2014-08-27 00:22:24 -0700 | [diff] [blame] | 151 | * @param portNumber port number |
| 152 | * @return device port |
| 153 | */ |
| 154 | Port getPort(DeviceId deviceId, PortNumber portNumber); |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 155 | |
| 156 | /** |
Yuta HIGUCHI | 22ba76d | 2016-11-11 16:56:24 -0800 | [diff] [blame] | 157 | * Returns the port with the specified connect point. |
| 158 | * |
| 159 | * @param cp connect point |
| 160 | * @return device port |
| 161 | */ |
| 162 | default Port getPort(ConnectPoint cp) { |
| 163 | return getPort(cp.deviceId(), cp.port()); |
| 164 | } |
| 165 | |
| 166 | /** |
tom | ff7eb7c | 2014-09-08 12:49:03 -0700 | [diff] [blame] | 167 | * Indicates whether or not the device is presently online and available. |
Aaron Kruglikov | 8e0a08a | 2016-06-21 14:31:03 -0700 | [diff] [blame] | 168 | * Availability, unlike reachability, denotes whether ANY node in the |
| 169 | * cluster can discover that this device is in an operational state, |
| 170 | * this does not necessarily mean that there exists a node that can |
| 171 | * control this device. |
tom | ff7eb7c | 2014-09-08 12:49:03 -0700 | [diff] [blame] | 172 | * |
| 173 | * @param deviceId device identifier |
| 174 | * @return true if the device is available |
| 175 | */ |
| 176 | boolean isAvailable(DeviceId deviceId); |
| 177 | |
Saurav Das | d5ec9e9 | 2017-01-17 10:40:18 -0800 | [diff] [blame] | 178 | /** |
| 179 | * Indicates how long ago the device connected or disconnected from this |
| 180 | * controller instance. |
| 181 | * |
| 182 | * @param deviceId device identifier |
| 183 | * @return a human readable string indicating the time since the device |
| 184 | * connected-to or disconnected-from this controller instance. |
| 185 | */ |
| 186 | String localStatus(DeviceId deviceId); |
| 187 | |
Ray Milkey | 054e23d | 2018-03-22 13:37:11 -0700 | [diff] [blame] | 188 | |
| 189 | /** |
Saurav Das | 9a55429 | 2018-04-27 18:42:30 -0700 | [diff] [blame] | 190 | * Indicates the time at which the given device connected or disconnected |
| 191 | * from this controller instance. |
Ray Milkey | 054e23d | 2018-03-22 13:37:11 -0700 | [diff] [blame] | 192 | * |
| 193 | * @param deviceId device identifier |
Saurav Das | 9a55429 | 2018-04-27 18:42:30 -0700 | [diff] [blame] | 194 | * @return time offset in miliseconds from Epoch |
Ray Milkey | 054e23d | 2018-03-22 13:37:11 -0700 | [diff] [blame] | 195 | */ |
| 196 | long getLastUpdatedInstant(DeviceId deviceId); |
| 197 | |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 198 | } |