Bug 1029: Remove dead code: samples/clustersession
[controller.git] / opendaylight / hosttracker_new / implementation / src / test / java / org / opendaylight / controller / hosttracker / test / MockDevice.java
1 /*
2  * Copyright (c) 2011,2012 Big Switch Networks, Inc.
3  *
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
7  *
8  *      http://www.eclipse.org/legal/epl-v10.html
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
13  * implied. See the License for the specific language governing
14  * permissions and limitations under the License.
15  *
16  * This file incorporates work covered by the following copyright and
17  * permission notice:
18  *
19  *    Originally created by David Erickson, Stanford University
20  *
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
24  *
25  *         http://www.apache.org/licenses/LICENSE-2.0
26  *
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.
32  */
33
34 package org.opendaylight.controller.hosttracker.test;
35
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;
41
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;
48
49 /**
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
52  */
53 public class MockDevice extends Device {
54
55     public MockDevice(DeviceManagerImpl deviceManager, Long deviceKey,
56             Entity entity, IEntityClass entityClass) {
57         super(deviceManager, deviceKey, entity, entityClass);
58     }
59
60     public MockDevice(Device device, Entity newEntity, int insertionpoint) {
61         super(device, newEntity, insertionpoint);
62     }
63
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,
68                 entityClass);
69     }
70
71     @Override
72     public Integer[] getIPv4Addresses() {
73         TreeSet<Integer> vals = new TreeSet<Integer>();
74         for (Entity e : entities) {
75             if (e.getIpv4Address() == null)
76                 continue;
77             vals.add(e.getIpv4Address());
78         }
79
80         return vals.toArray(new Integer[vals.size()]);
81     }
82
83     @Override
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());
90                 vals.add(sp);
91             }
92         }
93         return vals.toArray(new SwitchPort[vals.size()]);
94     }
95
96     @Override
97     public String toString() {
98         return "MockDevice [getEntityClass()=" + getEntityClass()
99                 + ", getEntities()=" + Arrays.toString(getEntities()) + "]";
100     }
101
102 }