Skip to content
Snippets Groups Projects
Commit ae256e7b authored by Ananth Suryanarayana's avatar Ananth Suryanarayana
Browse files

Merge pull request #218 from rombie/master

BSC-1846 	Read address-space config from storage
parents 2cf47291 6a2a30c5
No related branches found
No related tags found
No related merge requests found
......@@ -189,17 +189,6 @@ public interface IDeviceService extends IFloodlightService {
*/
public void addListener(IDeviceListener listener);
/**
* Flush and/or reclassify all entities in a class
*
* @param entityClass the class to flush. If null, flush all classes
* @param reclassify if true, begin an asynchronous task to reclassify the
* flushed entities
*/
public void flushEntityCache(IEntityClass entityClass,
boolean reclassify);
/**
* Specify points in the network where attachment points are not to
* be learned.
......
/**
* Copyright 2011, Big Switch Networks, Inc.
* Originally created by David Erickson, Stanford University
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
**/
package net.floodlightcontroller.devicemanager;
import java.util.Set;
/**
* Implementors of this interface can receive updates from DeviceManager about
* the changes entity Classes.
*
* @author Ananth Suryanarayana (Ananth.Suryanarayana@bigswitch.com)
*/
public interface IEntityClassListener {
/**
* Process entity classes change event.
* @param entityClassNames Set of entity classes changed
*/
public void entityClassChanged(Set<String> entityClassNames);
}
......@@ -98,5 +98,11 @@ public interface IEntityClassifierService extends IFloodlightService {
void deviceUpdate(IDevice oldDevice,
Collection<? extends IDevice> newDevices);
/**
* Adds a listener to listen for IEntityClassifierServices notifications
*
* @param listener The listener that wants the notifications
*/
public void addListener(IEntityClassListener listener);
}
......@@ -31,6 +31,7 @@ import net.floodlightcontroller.devicemanager.IDevice;
import net.floodlightcontroller.devicemanager.IDeviceService;
import net.floodlightcontroller.devicemanager.IDeviceService.DeviceField;
import net.floodlightcontroller.devicemanager.IEntityClass;
import net.floodlightcontroller.devicemanager.IEntityClassListener;
import net.floodlightcontroller.devicemanager.IEntityClassifierService;
/**
......@@ -46,6 +47,12 @@ public class DefaultEntityClassifier implements
* A default fixed entity class
*/
protected static class DefaultEntityClass implements IEntityClass {
String name;
public DefaultEntityClass(String name) {
this.name = name;
}
@Override
public EnumSet<IDeviceService.DeviceField> getKeyFields() {
return keyFields;
......@@ -53,7 +60,11 @@ public class DefaultEntityClassifier implements
@Override
public String getName() {
return "DefaultEntityClass";
return name;
}
public void setName(String name) {
this.name = name;
}
}
......@@ -61,7 +72,16 @@ public class DefaultEntityClassifier implements
static {
keyFields = EnumSet.of(DeviceField.MAC, DeviceField.VLAN);
}
protected static IEntityClass entityClass = new DefaultEntityClass();
protected static DefaultEntityClass entityClass =
new DefaultEntityClass("DefaultEntityClass");
public void setClassifierName (String name) {
entityClass.setName(name);
}
public String getClassifierName (String name) {
return entityClass.getName();
}
@Override
public IEntityClass classifyEntity(Entity entity) {
......@@ -121,4 +141,10 @@ public class DefaultEntityClassifier implements
public void startUp(FloodlightModuleContext context) {
// no-op
}
@Override
public void addListener(IEntityClassListener listener) {
// no-op
}
}
......@@ -49,6 +49,7 @@ import net.floodlightcontroller.core.util.SingletonTask;
import net.floodlightcontroller.devicemanager.IDevice;
import net.floodlightcontroller.devicemanager.IDeviceService;
import net.floodlightcontroller.devicemanager.IEntityClass;
import net.floodlightcontroller.devicemanager.IEntityClassListener;
import net.floodlightcontroller.devicemanager.IEntityClassifierService;
import net.floodlightcontroller.devicemanager.IDeviceListener;
import net.floodlightcontroller.devicemanager.SwitchPort;
......@@ -86,7 +87,7 @@ import org.slf4j.LoggerFactory;
*/
public class DeviceManagerImpl implements
IDeviceService, IOFMessageListener,
IStorageSourceListener, IFloodlightModule,
IStorageSourceListener, IFloodlightModule, IEntityClassListener,
IFlowReconcileListener, IInfoProvider, IHAListener {
protected static Logger logger =
LoggerFactory.getLogger(DeviceManagerImpl.class);
......@@ -461,12 +462,6 @@ IFlowReconcileListener, IInfoProvider, IHAListener {
deviceListeners.add(listener);
}
@Override
public void flushEntityCache(IEntityClass entityClass,
boolean reclassify) {
// TODO Auto-generated method stub
}
// *************
// IInfoProvider
// *************
......@@ -639,11 +634,12 @@ IFlowReconcileListener, IInfoProvider, IHAListener {
floodlightProvider.addOFMessageListener(OFType.PACKET_IN, this);
floodlightProvider.addHAListener(this);
flowReconcileMgr.addFlowReconcileListener(this);
entityClassifier.addListener(this);
Runnable ecr = new Runnable() {
@Override
public void run() {
cleanupEntities();
cleanupEntities(null, false);
entityCleanupTask.reschedule(ENTITY_CLEANUP_INTERVAL,
TimeUnit.SECONDS);
}
......@@ -1286,10 +1282,46 @@ IFlowReconcileListener, IInfoProvider, IHAListener {
}
}
/**
* Flush and/or reclassify all entities in a class
*
* @param entityClass the class to flush. If null, flush all classes
* @param reclassify if true, begin an asynchronous task to reclassify the
* flushed entities
*/
private void flushEntityCache (Set<String> entityClassChangedSet,
boolean reclassify) {
if (reclassify) return; // TODO
/*
* TODO This can be running at the same time by timer thread. Check
* and make sure that this is thread safe.
*/
cleanupEntities(entityClassChangedSet, true);
}
// *********************
// IEntityClassListener
// *********************
@Override
public void entityClassChanged (Set<String> entityClassNames) {
/*
* Flush the entire device entity cache for now.
*/
flushEntityCache(entityClassNames, false);
return;
}
/**
* Clean up expired entities/devices
*
* @param[in] forceCleanup ForceCleanup of entities irrespective of age
* @param[in] specificEntities Cleanup only a specific set of entities
*/
protected void cleanupEntities() {
protected void cleanupEntities (Set<String> specificEntities,
boolean forceCleanup) {
Calendar c = Calendar.getInstance();
c.add(Calendar.MILLISECOND, -ENTITY_TIMEOUT);
Date cutoff = c.getTime();
......@@ -1304,13 +1336,23 @@ IFlowReconcileListener, IInfoProvider, IHAListener {
while (diter.hasNext()) {
Device d = diter.next();
/*
* If we are cleaning entities for a specific set of devices,
* skip if not applicable.
*/
if (specificEntities != null && d.getEntityClass() != null &&
!specificEntities.contains(d.getEntityClass().getName())) {
continue;
}
while (true) {
deviceUpdates.clear();
toRemove.clear();
toKeep.clear();
for (Entity e : d.getEntities()) {
if (e.getLastSeenTimestamp() != null &&
0 > e.getLastSeenTimestamp().compareTo(cutoff)) {
if (forceCleanup ||
(e.getLastSeenTimestamp() != null &&
0 > e.getLastSeenTimestamp().compareTo(cutoff))) {
// individual entity needs to be removed
toRemove.add(e);
} else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment