2 * Copyright (c) 2013 Big Switch Networks, Inc.
4 * Licensed under the Eclipse Public License, Version 1.0 (the
5 * "License"); you may not use this file except in compliance with the
6 * License. You may obtain a copy of the License at
8 * http://www.eclipse.org/legal/epl-v10.html
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
13 * implied. See the License for the specific language governing
14 * permissions and limitations under the License.
17 package org.opendaylight.controller.hosttracker.test;
19 import java.util.Collection;
20 import java.util.Date;
21 import java.util.List;
23 import org.opendaylight.controller.hosttracker.Entity;
24 import org.opendaylight.controller.hosttracker.IDevice;
25 import org.opendaylight.controller.hosttracker.IDeviceListener;
26 import org.opendaylight.controller.hosttracker.IEntityClass;
27 import org.opendaylight.controller.hosttracker.IEntityClassifierService;
28 import org.opendaylight.controller.hosttracker.internal.AttachmentPoint;
29 import org.opendaylight.controller.hosttracker.internal.Device;
30 import org.opendaylight.controller.hosttracker.internal.DeviceManagerImpl;
31 import org.opendaylight.controller.sal.core.NodeConnector;
34 * Mock device manager useful for unit tests
38 public class MockDeviceManager extends DeviceManagerImpl {
40 * Set a new IEntityClassifier Use this as a quick way to use a particular
41 * entity classifier in a single test without having to setup the full
42 * FloodlightModuleContext again.
46 public void setEntityClassifier(IEntityClassifierService ecs) {
47 this.entityClassifier = ecs;
48 // setSyncServiceIfNotSet(new MockSyncService());
53 * Learn a device using the given characteristics.
58 * the VLAN (can be null)
60 * the IP (can be null)
62 * the attachment point switch DPID (can be null)
64 * the attachment point switch port (can be null)
65 * @param processUpdates
66 * if false, will not send updates. Note that this method is not
67 * thread safe if this is false
68 * @return the device, either new or not
70 public IDevice learnEntity(long macAddress, Short vlan,
71 Integer ipv4Address, NodeConnector port, boolean processUpdates) {
72 List<IDeviceListener> listeners = deviceListeners.getOrderedListeners();
73 if (!processUpdates) {
74 deviceListeners.clearListeners();
77 if (vlan != null && vlan.shortValue() <= 0)
79 if (ipv4Address != null && ipv4Address == 0)
81 IDevice res = learnDeviceByEntity(new Entity(macAddress, vlan,
82 ipv4Address, port, new Date()));
84 if (listeners != null) {
85 for (IDeviceListener listener : listeners) {
86 deviceListeners.addListener("device", listener);
93 public void deleteDevice(Device device) {
94 super.deleteDevice(device);
98 * Learn a device using the given characteristics.
103 * the VLAN (can be null)
105 * the IP (can be null)
107 * the attachment point switch DPID (can be null)
109 * the attachment point switch port (can be null)
110 * @return the device, either new or not
112 public IDevice learnEntity(long macAddress, Short vlan,
113 Integer ipv4Address, NodeConnector port) {
114 return learnEntity(macAddress, vlan, ipv4Address, port, true);
118 protected Device allocateDevice(Long deviceKey, Entity entity,
119 IEntityClass entityClass) {
120 return new MockDevice(this, deviceKey, entity, entityClass);
124 protected Device allocateDevice(Long deviceKey, String dhcpClientName,
125 List<AttachmentPoint> aps, List<AttachmentPoint> trueAPs,
126 Collection<Entity> entities, IEntityClass entityClass) {
127 return new MockDevice(this, deviceKey, aps, trueAPs, entities,
132 protected Device allocateDevice(Device device, Entity entity,
133 int insertionpoint) {
134 return new MockDevice(device, entity, insertionpoint);