2 * Copyright (c) 2011,2012 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.
16 * This file incorporates work covered by the following copyright and
19 * Originally created by David Erickson, Stanford University
21 * Licensed under the Apache License, Version 2.0 (the "License");
22 * you may not use this file except in compliance with the
23 * License. You may obtain a copy of the License at
25 * http://www.apache.org/licenses/LICENSE-2.0
27 * Unless required by applicable law or agreed to in writing,
28 * software distributed under the License is distributed on an "AS
29 * IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
30 * express or implied. See the License for the specific language
31 * governing permissions and limitations under the License.
34 package org.opendaylight.controller.hosttracker.test;
36 import java.util.ArrayList;
37 import java.util.Arrays;
38 import java.util.Collection;
39 import java.util.List;
40 import java.util.TreeSet;
42 import org.opendaylight.controller.hosttracker.Entity;
43 import org.opendaylight.controller.hosttracker.IEntityClass;
44 import org.opendaylight.controller.hosttracker.SwitchPort;
45 import org.opendaylight.controller.hosttracker.internal.AttachmentPoint;
46 import org.opendaylight.controller.hosttracker.internal.Device;
47 import org.opendaylight.controller.hosttracker.internal.DeviceManagerImpl;
50 * This mock device removes the dependency on topology and a parent device
51 * manager and simply assumes all its entities are current and correct
53 public class MockDevice extends Device {
55 public MockDevice(DeviceManagerImpl deviceManager, Long deviceKey,
56 Entity entity, IEntityClass entityClass) {
57 super(deviceManager, deviceKey, entity, entityClass);
60 public MockDevice(Device device, Entity newEntity, int insertionpoint) {
61 super(device, newEntity, insertionpoint);
64 public MockDevice(DeviceManagerImpl deviceManager, Long deviceKey,
65 List<AttachmentPoint> aps, List<AttachmentPoint> trueAPs,
66 Collection<Entity> entities, IEntityClass entityClass) {
67 super(deviceManager, deviceKey, null, aps, trueAPs, entities,
72 public Integer[] getIPv4Addresses() {
73 TreeSet<Integer> vals = new TreeSet<Integer>();
74 for (Entity e : entities) {
75 if (e.getIpv4Address() == null)
77 vals.add(e.getIpv4Address());
80 return vals.toArray(new Integer[vals.size()]);
84 public SwitchPort[] getAttachmentPoints() {
85 ArrayList<SwitchPort> vals = new ArrayList<SwitchPort>(entities.length);
86 for (Entity e : entities) {
87 if (e.getPort() != null
88 && deviceManager.isValidAttachmentPoint(e.getPort())) {
89 SwitchPort sp = new SwitchPort(e.getPort());
93 return vals.toArray(new SwitchPort[vals.size()]);
97 public String toString() {
98 return "MockDevice [getEntityClass()=" + getEntityClass()
99 + ", getEntities()=" + Arrays.toString(getEntities()) + "]";