blob: faed0d4016147080ce254122b02fa6b8f5c4975f [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.internal;
19
20import java.util.ArrayList;
21import java.util.Collection;
22import java.util.EnumSet;
23import java.util.HashMap;
24import java.util.Map;
25
26import net.floodlightcontroller.core.module.FloodlightModuleContext;
27import net.floodlightcontroller.core.module.FloodlightModuleException;
28import net.floodlightcontroller.core.module.IFloodlightModule;
29import net.floodlightcontroller.core.module.IFloodlightService;
30import net.floodlightcontroller.devicemanager.IDevice;
31import net.floodlightcontroller.devicemanager.IDeviceService;
32import net.floodlightcontroller.devicemanager.IDeviceService.DeviceField;
33import net.floodlightcontroller.devicemanager.IEntityClass;
34import net.floodlightcontroller.devicemanager.IEntityClassListener;
35import net.floodlightcontroller.devicemanager.IEntityClassifierService;
36
37/**
38 * This is a default entity classifier that simply classifies all
39 * entities into a fixed entity class, with key fields of MAC and VLAN.
40 * @author readams
41 */
42public class DefaultEntityClassifier implements
43 IEntityClassifierService,
44 IFloodlightModule
45{
46 /**
47 * A default fixed entity class
48 */
49 protected static class DefaultEntityClass implements IEntityClass {
50 String name;
51
52 public DefaultEntityClass(String name) {
53 this.name = name;
54 }
55
56 @Override
57 public EnumSet<IDeviceService.DeviceField> getKeyFields() {
58 return keyFields;
59 }
60
61 @Override
62 public String getName() {
63 return name;
64 }
65 }
66
67 protected static EnumSet<DeviceField> keyFields;
68 static {
69 keyFields = EnumSet.of(DeviceField.MAC, DeviceField.VLAN);
70 }
71 protected static DefaultEntityClass entityClass =
72 new DefaultEntityClass("DefaultEntityClass");
73
74 @Override
75 public IEntityClass classifyEntity(Entity entity) {
76 return entityClass;
77 }
78
79 @Override
80 public IEntityClass reclassifyEntity(IDevice curDevice,
81 Entity entity) {
82 return entityClass;
83 }
84
85 @Override
86 public void deviceUpdate(IDevice oldDevice,
87 Collection<? extends IDevice> newDevices) {
88 // no-op
89 }
90
91 @Override
92 public EnumSet<DeviceField> getKeyFields() {
93 return keyFields;
94 }
95
96 @Override
97 public Collection<Class<? extends IFloodlightService>> getModuleServices() {
98 Collection<Class<? extends IFloodlightService>> l =
99 new ArrayList<Class<? extends IFloodlightService>>();
100 l.add(IEntityClassifierService.class);
101 return l;
102 }
103
104 @Override
105 public Map<Class<? extends IFloodlightService>, IFloodlightService> getServiceImpls() {
106 Map<Class<? extends IFloodlightService>,
107 IFloodlightService> m =
108 new HashMap<Class<? extends IFloodlightService>,
109 IFloodlightService>();
110 // We are the class that implements the service
111 m.put(IEntityClassifierService.class, this);
112 return m;
113 }
114
115 @Override
116 public Collection<Class<? extends IFloodlightService>>
117 getModuleDependencies() {
118 // No dependencies
119 return null;
120 }
121
122 @Override
123 public void init(FloodlightModuleContext context)
124 throws FloodlightModuleException {
125 // no-op
126 }
127
128 @Override
129 public void startUp(FloodlightModuleContext context) {
130 // no-op
131 }
132
133 @Override
134 public void addListener(IEntityClassListener listener) {
135 // no-op
136
137 }
138}