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 | 61359e9 | 2014-09-16 15:50:27 -0700 | [diff] [blame] | 17 | |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 18 | import java.util.Collections; |
| 19 | import java.util.List; |
HIGUCHI Yuta | 5bb99a4 | 2015-03-19 16:52:15 -0700 | [diff] [blame] | 20 | |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 21 | import org.onosproject.net.Device; |
samuel | 738dfaf | 2015-07-11 11:08:57 +0800 | [diff] [blame] | 22 | import org.onosproject.net.Device.Type; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 23 | import org.onosproject.net.DeviceId; |
| 24 | import org.onosproject.net.MastershipRole; |
| 25 | import org.onosproject.net.Port; |
| 26 | import org.onosproject.net.PortNumber; |
tom | 61359e9 | 2014-09-16 15:50:27 -0700 | [diff] [blame] | 27 | |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 28 | import com.google.common.collect.FluentIterable; |
tom | 61359e9 | 2014-09-16 15:50:27 -0700 | [diff] [blame] | 29 | |
| 30 | /** |
| 31 | * Test adapter for device service. |
| 32 | */ |
| 33 | public class DeviceServiceAdapter implements DeviceService { |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 34 | |
| 35 | private List<Port> portList; |
| 36 | |
| 37 | /** |
| 38 | * Constructor with port list. |
| 39 | * |
| 40 | * @param portList port list |
| 41 | */ |
| 42 | public DeviceServiceAdapter(List<Port> portList) { |
| 43 | this.portList = portList; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Default constructor. |
| 48 | */ |
| 49 | public DeviceServiceAdapter() { |
| 50 | |
| 51 | } |
| 52 | |
tom | 61359e9 | 2014-09-16 15:50:27 -0700 | [diff] [blame] | 53 | @Override |
| 54 | public int getDeviceCount() { |
| 55 | return 0; |
| 56 | } |
| 57 | |
| 58 | @Override |
mskala | 32000d3 | 2017-07-14 16:27:06 +0200 | [diff] [blame] | 59 | public int getAvailableDeviceCount() { |
| 60 | return 0; |
| 61 | } |
| 62 | |
| 63 | @Override |
tom | 61359e9 | 2014-09-16 15:50:27 -0700 | [diff] [blame] | 64 | public Iterable<Device> getDevices() { |
HIGUCHI Yuta | 5bb99a4 | 2015-03-19 16:52:15 -0700 | [diff] [blame] | 65 | return Collections.emptyList(); |
tom | 61359e9 | 2014-09-16 15:50:27 -0700 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | @Override |
Yuta HIGUCHI | f1f2ac0 | 2014-11-26 14:02:22 -0800 | [diff] [blame] | 69 | public Iterable<Device> getAvailableDevices() { |
| 70 | return FluentIterable.from(getDevices()) |
Sho SHIMIZU | 7462641 | 2015-09-11 11:46:27 -0700 | [diff] [blame] | 71 | .filter(input -> isAvailable(input.id())); |
Yuta HIGUCHI | f1f2ac0 | 2014-11-26 14:02:22 -0800 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | @Override |
tom | 61359e9 | 2014-09-16 15:50:27 -0700 | [diff] [blame] | 75 | public Device getDevice(DeviceId deviceId) { |
| 76 | return null; |
| 77 | } |
| 78 | |
| 79 | @Override |
| 80 | public MastershipRole getRole(DeviceId deviceId) { |
HIGUCHI Yuta | 5bb99a4 | 2015-03-19 16:52:15 -0700 | [diff] [blame] | 81 | return MastershipRole.NONE; |
tom | 61359e9 | 2014-09-16 15:50:27 -0700 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | @Override |
| 85 | public List<Port> getPorts(DeviceId deviceId) { |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 86 | return portList; |
tom | 61359e9 | 2014-09-16 15:50:27 -0700 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | @Override |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 90 | public List<PortStatistics> getPortStatistics(DeviceId deviceId) { |
| 91 | return null; |
| 92 | } |
| 93 | |
| 94 | @Override |
Dusan Pajin | 11ff4a8 | 2015-08-20 18:03:05 +0200 | [diff] [blame] | 95 | public List<PortStatistics> getPortDeltaStatistics(DeviceId deviceId) { |
| 96 | return null; |
| 97 | } |
| 98 | |
| 99 | @Override |
Viswanath KSP | 22774cd | 2016-08-20 20:06:30 +0530 | [diff] [blame] | 100 | public PortStatistics getStatisticsForPort(DeviceId deviceId, PortNumber portNumber) { |
| 101 | return null; |
| 102 | } |
| 103 | |
| 104 | @Override |
| 105 | public PortStatistics getDeltaStatisticsForPort(DeviceId deviceId, PortNumber portNumber) { |
| 106 | return null; |
| 107 | } |
| 108 | |
| 109 | @Override |
tom | 61359e9 | 2014-09-16 15:50:27 -0700 | [diff] [blame] | 110 | public Port getPort(DeviceId deviceId, PortNumber portNumber) { |
Yuta HIGUCHI | 37dca33 | 2016-11-14 18:43:22 -0800 | [diff] [blame] | 111 | return getPorts(deviceId).stream() |
| 112 | .filter(port -> deviceId.equals(port.element().id())) |
| 113 | .filter(port -> portNumber.equals(port.number())) |
| 114 | .findFirst().orElse(null); |
tom | 61359e9 | 2014-09-16 15:50:27 -0700 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | @Override |
| 118 | public boolean isAvailable(DeviceId deviceId) { |
| 119 | return false; |
| 120 | } |
| 121 | |
| 122 | @Override |
| 123 | public void addListener(DeviceListener listener) { |
| 124 | } |
| 125 | |
| 126 | @Override |
| 127 | public void removeListener(DeviceListener listener) { |
| 128 | } |
| 129 | |
samuel | 738dfaf | 2015-07-11 11:08:57 +0800 | [diff] [blame] | 130 | @Override |
| 131 | public Iterable<Device> getDevices(Type type) { |
| 132 | return Collections.emptyList(); |
| 133 | } |
| 134 | |
| 135 | @Override |
| 136 | public Iterable<Device> getAvailableDevices(Type type) { |
| 137 | return Collections.emptyList(); |
| 138 | } |
| 139 | |
Saurav Das | d5ec9e9 | 2017-01-17 10:40:18 -0800 | [diff] [blame] | 140 | @Override |
| 141 | public String localStatus(DeviceId deviceId) { |
| 142 | return null; |
| 143 | } |
| 144 | |
Ray Milkey | 054e23d | 2018-03-22 13:37:11 -0700 | [diff] [blame] | 145 | @Override |
| 146 | public long getLastUpdatedInstant(DeviceId deviceId) { |
| 147 | return 0; |
| 148 | } |
| 149 | |
tom | 61359e9 | 2014-09-16 15:50:27 -0700 | [diff] [blame] | 150 | } |