blob: 1d173f6468550a6781affdc71379a276b9e746b4 [file] [log] [blame]
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -07001/*
2 * Copyright 2016-present Open Networking Foundation
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 */
16package org.onosproject.segmentrouting;
17
18import java.util.LinkedList;
19import java.util.List;
20import java.util.Set;
21
22import org.onosproject.net.ConnectPoint;
23import org.onosproject.net.DefaultPort;
24import org.onosproject.net.Port;
25import org.onosproject.net.device.DeviceListener;
26import org.onosproject.net.device.DeviceServiceAdapter;
27import org.onosproject.net.Device;
28import org.onosproject.net.DeviceId;
29
30/**
31 * Test fixture for the device service.
32 */
33public class MockDeviceService extends DeviceServiceAdapter {
34 private List<Device> devices = new LinkedList<>();
35 private DeviceListener listener;
36
37 public void addDevice(Device dev) {
38 devices.add(dev);
39 }
40
41 public void addMultipleDevices(Set<Device> devicesToAdd) {
42 devicesToAdd.forEach(dev -> devices.add(dev));
43 }
44
45 @Override
46 public Device getDevice(DeviceId deviceId) {
47 for (Device dev : devices) {
48 if (dev.id().equals(deviceId)) {
49 return dev;
50 }
51 }
52 return null;
53 }
54
55 @Override
56 public Port getPort(ConnectPoint cp) {
57 return new DefaultPort(null, null, false);
58 }
59
60 @Override
61 public Iterable<Device> getAvailableDevices() {
62 return devices;
63 }
64
65 @Override
66 public void addListener(DeviceListener listener) {
67 this.listener = listener;
68 }
69
70 /**
71 * Get the listener.
72 */
73 public DeviceListener getListener() {
74 return listener;
75 }
76
77}