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 static org.opendaylight.controller.hosttracker.IDeviceService.DeviceField.MAC;
20 import static org.opendaylight.controller.hosttracker.IDeviceService.DeviceField.SWITCHPORT;
21 import static org.opendaylight.controller.hosttracker.IDeviceService.DeviceField.VLAN;
23 import java.util.EnumSet;
25 import org.opendaylight.controller.hosttracker.Entity;
26 import org.opendaylight.controller.hosttracker.IDeviceService;
27 import org.opendaylight.controller.hosttracker.IDeviceService.DeviceField;
28 import org.opendaylight.controller.hosttracker.IEntityClass;
29 import org.opendaylight.controller.hosttracker.internal.DefaultEntityClassifier;
32 * A simple IEntityClassifier. Useful for tests that need an IEntityClassifier
33 * with switch/port as key fields.
35 public class MockEntityClassifierMac extends DefaultEntityClassifier {
36 public static class TestEntityClassMac implements IEntityClass {
37 protected String name;
39 public TestEntityClassMac(String name) {
44 public EnumSet<DeviceField> getKeyFields() {
45 return EnumSet.of(MAC, VLAN);
49 public String getName() {
54 public static IEntityClass testECMac1 = new MockEntityClassifierMac.TestEntityClassMac(
56 public static IEntityClass testECMac2 = new MockEntityClassifierMac.TestEntityClassMac(
60 public IEntityClass classifyEntity(Entity entity) {
61 if (((Long) entity.getPort().getNode().getID()) == null) {
62 throw new IllegalArgumentException("Not all key fields specified."
63 + " Required fields: " + getKeyFields());
64 } else if (((Long) entity.getPort().getNode().getID()) == 1L) {
66 } else if (((Long) entity.getPort().getNode().getID()) == 2L) {
68 } else if (((Long) entity.getPort().getNode().getID()) == -1L) {
71 return DefaultEntityClassifier.entityClass;
75 public EnumSet<IDeviceService.DeviceField> getKeyFields() {
76 return EnumSet.of(MAC, VLAN, SWITCHPORT);