blob: 2569a7df54ed892464810ca415b12a52d1ea76a7 [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;
19
20import java.util.Collection;
21import java.util.EnumSet;
22
23import net.floodlightcontroller.core.module.IFloodlightService;
24import net.floodlightcontroller.devicemanager.IDeviceService.DeviceField;
25import net.floodlightcontroller.devicemanager.internal.Entity;
26
27/**
28 * A component that wishes to participate in entity classification needs to
29 * implement the IEntityClassifier interface, and register with the Device
30 * Manager as an entity classifier. An entity is classified by the classifier
31 * into an {@link IEntityClass}
32 *
33 * @author readams
34 */
35public interface IEntityClassifierService extends IFloodlightService {
36 /**
37 * Classify the given entity into an IEntityClass. It is important
38 * that the key fields returned by {@link IEntityClassifierService#getKeyFields()}
39 * be sufficient for classifying entities. That is, if two entities are
40 * identical except for a field that is not a key field, they must be
41 * assigned the same class. Furthermore, entity classification must be
42 * transitive: For all entities x, y, z, if x and y belong to a class c, and
43 * y and z belong class c, then x and z must belong to class c.
44 *
45 * @param entity the entity to classify
46 * @return the IEntityClass resulting from the classification.
47 * @see IEntityClassifierService#getKeyFields()
48 */
49 IEntityClass classifyEntity(Entity entity);
50
51 /**
52 * Return the most general list of fields that should be used as key
53 * fields. If devices differ in any fields not listed here, they can
54 * never be considered a different device by any {@link IEntityClass}
55 * returned by {@link IEntityClassifierService#classifyEntity}. The key fields
56 * for an entity classifier must not change unless associated with a
57 * flush of all entity state. The list of key fields must be the union
58 * of all key fields that could be returned by
59 * {@link IEntityClass#getKeyFields()}.
60 *
61 * @return a set containing the fields that should not be
62 * wildcarded. May be null to indicate that all fields are key fields.
63 * @see {@link IEntityClass#getKeyFields()}
64 * @see {@link IEntityClassifierService#classifyEntity}
65 */
66 EnumSet<DeviceField> getKeyFields();
67
68 /**
69 * Reclassify the given entity into a class. When reclassifying entities,
70 * it can be helpful to take into account the current classification either
71 * as an optimization or to allow flushing any cached state tied to the key
72 * for that device. The entity will be assigned to a new device with a new
73 * object if the entity class returned is different from the entity class for
74 * curDevice.
75 *
76 * <p>Note that you must take steps to ensure you always return classes
77 * in some consistent ordering.
78
79 * @param curDevice the device currently associated with the entity
80 * @param entity the entity to reclassify
81 * @return the IEntityClass resulting from the classification
82 */
83 IEntityClass reclassifyEntity(IDevice curDevice,
84 Entity entity);
85
86 /**
87 * Once reclassification is complete for a device, this method will be
88 * called. If any entities within the device changed their classification,
89 * it will split into one or more new devices for each of the entities. If
90 * two devices are merged because of a reclassification, then this will be
91 * called on each of the devices, with the same device in the newDevices
92 * collection.
93 *
94 * @param oldDevice the original device object
95 * @param newDevices all the new devices derived from the entities of the
96 * old device. If null, the old device was unchanged.
97 */
98 void deviceUpdate(IDevice oldDevice,
99 Collection<? extends IDevice> newDevices);
100
101 /**
102 * Adds a listener to listen for IEntityClassifierServices notifications
103 *
104 * @param listener The listener that wants the notifications
105 */
106 public void addListener(IEntityClassListener listener);
107}
108