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;
24 import java.util.HashMap;
27 import org.opendaylight.controller.hosttracker.Entity;
28 import org.opendaylight.controller.hosttracker.IDeviceService;
29 import org.opendaylight.controller.hosttracker.IDeviceService.DeviceField;
30 import org.opendaylight.controller.hosttracker.IEntityClass;
31 import org.opendaylight.controller.hosttracker.internal.DefaultEntityClassifier;
34 * Extension to simple entity classifier to help in unit tests to provide table
35 * based multiple entity classification mock for reclassification tests
38 public class MockFlexEntityClassifier extends DefaultEntityClassifier {
39 Map<Long, IEntityClass> switchEntities;
40 Map<Short, IEntityClass> vlanEntities;
42 public static class TestEntityClass implements IEntityClass {
45 public TestEntityClass(String name) {
50 public EnumSet<DeviceField> getKeyFields() {
51 return EnumSet.of(MAC);
55 public String getName() {
60 public static IEntityClass defaultClass = new TestEntityClass("default");
62 public MockFlexEntityClassifier() {
63 switchEntities = new HashMap<Long, IEntityClass>();
64 vlanEntities = new HashMap<Short, IEntityClass>();
67 public IEntityClass createTestEntityClass(String name) {
68 return new TestEntityClass(name);
71 public void addSwitchEntity(Long dpid, IEntityClass entityClass) {
72 switchEntities.put(dpid, entityClass);
75 public void removeSwitchEntity(Long dpid) {
76 switchEntities.remove(dpid);
79 public void addVlanEntities(Short vlan, IEntityClass entityClass) {
80 vlanEntities.put(vlan, entityClass);
83 public void removeVlanEntities(Short vlan) {
84 vlanEntities.remove(vlan);
88 public IEntityClass classifyEntity(Entity entity) {
89 if (switchEntities.containsKey((Long) entity.getPort().getNode()
92 .get((Long) entity.getPort().getNode().getID());
93 if (vlanEntities.containsKey(entity.getVlan()))
94 return vlanEntities.get(entity.getVlan());
99 public EnumSet<IDeviceService.DeviceField> getKeyFields() {
100 return EnumSet.of(MAC, VLAN, SWITCHPORT);