blob: 5460ea3a91f42c22065ecaca793ba8b23ece87f8 [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001/**
2* Copyright 2011,2012 Big Switch Networks, Inc.
3* Originally created by David Erickson, Stanford University
4*
5* Licensed under the Apache License, Version 2.0 (the "License"); you may
6* not use this file except in compliance with the License. You may obtain
7* a copy of the License at
8*
9* http://www.apache.org/licenses/LICENSE-2.0
10*
11* Unless required by applicable law or agreed to in writing, software
12* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14* License for the specific language governing permissions and limitations
15* under the License.
16**/
17
18package net.floodlightcontroller.devicemanager.test;
19
20import java.util.ArrayList;
21import java.util.Collection;
22import java.util.List;
23import java.util.TreeSet;
24
25import net.floodlightcontroller.devicemanager.IEntityClass;
26import net.floodlightcontroller.devicemanager.SwitchPort;
27import net.floodlightcontroller.devicemanager.internal.AttachmentPoint;
28import net.floodlightcontroller.devicemanager.internal.Device;
29import net.floodlightcontroller.devicemanager.internal.DeviceManagerImpl;
30import net.floodlightcontroller.devicemanager.internal.Entity;
31
32/**
33 * This mock device removes the dependency on topology and a parent device
34 * manager and simply assumes all its entities are current and correct
35 */
36public class MockDevice extends Device {
37
38 public MockDevice(DeviceManagerImpl deviceManager,
39 Long deviceKey,
40 Entity entity,
41 IEntityClass entityClass) {
42 super(deviceManager, deviceKey, entity, entityClass);
43 }
44
45 public MockDevice(Device device, Entity newEntity) {
46 super(device, newEntity);
47 }
48
49 public MockDevice(DeviceManagerImpl deviceManager, Long deviceKey,
50 List<AttachmentPoint> aps,
51 List<AttachmentPoint> trueAPs,
52 Collection<Entity> entities,
53 IEntityClass entityClass) {
54 super(deviceManager, deviceKey, aps, trueAPs, entities, entityClass);
55 }
56
57 @Override
58 public Integer[] getIPv4Addresses() {
59 TreeSet<Integer> vals = new TreeSet<Integer>();
60 for (Entity e : entities) {
61 if (e.getIpv4Address() == null) continue;
62 vals.add(e.getIpv4Address());
63 }
64
65 return vals.toArray(new Integer[vals.size()]);
66 }
67
68 @Override
69 public SwitchPort[] getAttachmentPoints() {
70 ArrayList<SwitchPort> vals =
71 new ArrayList<SwitchPort>(entities.length);
72 for (Entity e : entities) {
73 if (e.getSwitchDPID() != null &&
74 e.getSwitchPort() != null &&
75 deviceManager.isValidAttachmentPoint(e.getSwitchDPID(), e.getSwitchPort())) {
76 SwitchPort sp = new SwitchPort(e.getSwitchDPID(),
77 e.getSwitchPort());
78 vals.add(sp);
79 }
80 }
81 return vals.toArray(new SwitchPort[vals.size()]);
82 }
83
84 @Override
85 public String toString() {
86 String rv = "MockDevice[entities=+";
87 rv += entities.toString();
88 rv += "]";
89 return rv;
90 }
91}