2 * Copyright (c) 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.internal;
36 import java.util.Arrays;
37 import java.util.Iterator;
39 import org.opendaylight.controller.hosttracker.IEntityClass;
40 import org.opendaylight.controller.hosttracker.SwitchPort;
41 import org.opendaylight.controller.sal.core.NodeConnector;
42 import org.opendaylight.controller.sal.utils.FilterIterator;
45 * An iterator for handling device queries
47 public class DeviceIterator extends FilterIterator<Device> {
48 private IEntityClass[] entityClasses;
50 private Long macAddress;
52 private Integer ipv4Address;
53 private NodeConnector port;
56 * Construct a new device iterator over the key fields
59 * an iterator over the full data structure to scan
60 * @param entityClasses
61 * the entity classes to search for
73 public DeviceIterator(Iterator<Device> subIterator,
74 IEntityClass[] entityClasses, Long macAddress, Short vlan,
75 Integer ipv4Address, NodeConnector port) {
77 this.entityClasses = entityClasses;
78 this.subIterator = subIterator;
79 this.macAddress = macAddress;
81 this.ipv4Address = ipv4Address;
86 protected boolean matches(Device value) {
88 if (entityClasses != null) {
89 IEntityClass clazz = value.getEntityClass();
94 for (IEntityClass entityClass : entityClasses) {
95 if (clazz.equals(entityClass)) {
103 if (macAddress != null) {
104 if (macAddress.longValue() != value.getMACAddress())
108 Short[] vlans = value.getVlanId();
109 if (Arrays.binarySearch(vlans, vlan) < 0)
112 if (ipv4Address != null) {
113 Integer[] ipv4Addresses = value.getIPv4Addresses();
114 if (Arrays.binarySearch(ipv4Addresses, ipv4Address) < 0)
118 SwitchPort[] sps = value.getAttachmentPoints();
123 for (SwitchPort sp : sps) {
124 if (sp.getPort().equals(sp.getPort())) {