public class Devices extends OFModel implements IDeviceService
Modifier and Type | Class and Description |
---|---|
(package private) class |
Devices.AttachmentPointComparator
AttachmentPointComparator class compares two attachment points
and returns the latest one.
|
private static class |
Devices.DeviceUpdate
A device update event to be dispatched
|
(package private) class |
Devices.RESTAttachmentPoint
Class to convert Attachment Point information into JSON format
|
(package private) class |
Devices.RESTDevice
Class to convert Device information into JSON format
|
OFModel.RESTApi, OFModel.RESTWebUI
IDeviceService.DeviceField
Modifier and Type | Field and Description |
---|---|
Devices.AttachmentPointComparator |
apComparator |
private OFModel.RESTApi[] |
apis
Array of RESTApi objects.
|
IEntityClassifierService |
classifier |
private java.util.concurrent.ConcurrentHashMap<java.lang.Long,Device> |
deviceIdToDeviceMap
This is the master device map that maps device IDs to
Device
objects. |
private long |
deviceKeyCounter
Counter used to generate device keys
|
private java.lang.Object |
deviceKeyCounterLock
Lock for incrementing the device key counter
|
private java.util.Set<IDeviceListener> |
deviceListeners
Device manager event listeners
|
private static java.util.concurrent.atomic.AtomicReference<Devices> |
instanceRef |
private java.util.concurrent.ConcurrentHashMap<java.util.EnumSet<IDeviceService.DeviceField>,EntityToMultiDeviceIdIndex> |
multiIndices
Multi indices (from an Entity to a set of device IDs)
|
private EntityToSingleDeviceIdIndex |
primaryIndex
This is the primary entity index that contains all entities.
|
private java.util.concurrent.ConcurrentHashMap<java.util.EnumSet<IDeviceService.DeviceField>,EntityToSingleDeviceIdIndex> |
singleIndices
Single Indices (from an Entity to a device id).
|
private java.util.Set<SwitchPort> |
suppressedAPs
Switch ports where attachment points shouldn't be learned
|
ITopologyService |
topology |
Modifier | Constructor and Description |
---|---|
private |
Devices(ITopologyService topo,
IEntityClassifierService clf)
Constructor
|
Modifier and Type | Method and Description |
---|---|
void |
addIndex(boolean perClass,
java.util.EnumSet<IDeviceService.DeviceField> keyFields)
Creates an index over a set of fields.
|
void |
addListener(IDeviceListener listener)
Adds a listener to listen for IDeviceManagerServices notifications.
|
void |
addSuppressAPs(long swId,
short port)
Specifies points in the network where attachment points are not to
be learned.
|
private boolean |
allKeyFieldsPresent(Entity e,
java.util.EnumSet<IDeviceService.DeviceField> keyFields)
Checks if the entity e has all the keyFields set.
|
static Device |
allocateDevice(Device device,
Entity entity)
Returns a new device consisting of the entities from the old device
and an additional entity.
|
static Device |
allocateDevice(java.lang.Long deviceKey,
Entity entity,
IEntityClass entityClass)
Returns a new device.
|
static Device |
allocateDevice(java.lang.Long deviceKey,
java.util.List<AttachmentPoint> aps,
java.util.List<AttachmentPoint> trueAPs,
java.util.Collection<Entity> entities,
IEntityClass entityClass)
Returns a new device.
|
void |
cleanupEntities(java.util.Date cutoff)
Removes all entities of the device if the recent time observed
is after the cutoff argument.
|
private void |
deleteDevice(Device device)
Deletes the device from
deviceIdToDeviceMap and its entities. |
void |
deleteDevice(long datapathid)
delete all device attached to a given switch.
|
private java.util.EnumSet<IDeviceService.DeviceField> |
findChangedFields(Device device,
Entity newEntity)
Checks the changed
IDeviceService.DeviceField of the device. |
Device |
findDestByEntity(IDevice source,
Entity dstEntity)
Gets a destination device using entity fields that corresponds with
the given source device.
|
IDevice |
findDestDevice(IDevice source,
long macAddress,
java.lang.Short vlan,
java.lang.Integer ipv4Address)
Gets a destination device using entity fields that corresponds with
the given source device.
|
IDevice |
findDevice(long macAddress,
java.lang.Short vlan,
java.lang.Integer ipv4Address,
java.lang.Long switchDPID,
java.lang.Integer switchPort)
Searches for a device exactly matching the provided device fields.
|
private Device |
findDeviceByEntity(Entity entity)
|
java.util.Collection<? extends IDevice> |
getAllDevices()
Gets an unmodifiable collection view over all devices currently known.
|
OFModel.RESTApi[] |
getAllRestApi()
Returns the list of RESTApi objects.
|
IDevice |
getDevice(java.lang.Long deviceKey)
Gets the device with the given device key.
|
java.util.concurrent.ConcurrentHashMap<java.lang.Long,Device> |
getDeviceMap()
Returns the map of device and device key.
|
private java.util.EnumSet<IDeviceService.DeviceField> |
getEntityKeys(java.lang.Long macAddress,
java.lang.Short vlan,
java.lang.Integer ipv4Address,
java.lang.Long switchDPID,
java.lang.Integer switchPort)
Returns the key fields for each argument that is not null.
|
java.lang.String |
getHostDebugInfo()
Returns information of devices that have more than one attachment point.
|
static Devices |
getInstance()
Returns the instance of Devices class
|
static Devices |
getInstance(ITopologyService topo,
IEntityClassifierService clf)
Returns the instance of
Devices class. |
boolean |
isEntityAllowed(Entity entity,
IEntityClass entityClass)
Is this entity is allowed?
|
boolean |
isSuppressedAP(SwitchPort switchPort)
Is the switchPort argument contained to the set of switch ports
not to be learned?
|
boolean |
isValidAttachmentPoint(long switchDPID,
int switchPort)
Checks whether the given attachment point is valid given the current
topology.
|
Device |
learnDeviceByEntity(Entity entity)
|
private void |
processUpdates(java.util.Queue<Devices.DeviceUpdate> updates)
Sends update notifications to listeners.
|
java.util.Iterator<Device> |
queryClassByEntity(IEntityClass clazz,
java.util.EnumSet<IDeviceService.DeviceField> keyFields,
Entity entity)
Returns an iterator of devices that related to the entity argument.
|
java.util.Iterator<? extends IDevice> |
queryClassDevices(IDevice reference,
java.lang.Long macAddress,
java.lang.Short vlan,
java.lang.Integer ipv4Address,
java.lang.Long switchDPID,
java.lang.Integer switchPort)
Finds devices that match the provided query.
|
java.util.Iterator<? extends IDevice> |
queryDevices(java.lang.Long macAddress,
java.lang.Short vlan,
java.lang.Integer ipv4Address,
java.lang.Long switchDPID,
java.lang.Integer switchPort)
Finds devices that match the provided query.
|
void |
reclassify(java.util.Set<java.lang.String> entityClassNames)
Reclassifies a devices if the device entity is null or is contained a device.
|
private boolean |
reclassifyDevice(Device device)
This method will reclassify and reconcile a device - possibilities
are - create new device(s), remove entities from this device.
|
private void |
removeEntity(Entity removed,
IEntityClass entityClass,
java.lang.Long deviceKey,
java.util.Collection<Entity> others)
Removes the device of the deviceKey argument from the single and multi indices.
|
void |
removeSuppressAPs(long swId,
short port)
Removes setting of points in the network where attachment points
are not to be learned.
|
private void |
sendDeviceMovedNotification(Device d)
Sends update notifications to listeners.
|
int |
size()
Returns the size of
deviceIdToDeviceMap . |
void |
updateAttachmentPoints()
Updates attachment points of the device.
|
private boolean |
updateIndices(Device device,
java.lang.Long deviceId)
Updates both the primary and class indices for the provided device.
|
private void |
updateSecondaryIndices(Entity entity,
IEntityClass entityClass,
java.lang.Long deviceKey)
Updates the secondary indices for the given entity and associated
entity classes.
|
private java.util.LinkedList<Devices.DeviceUpdate> |
updateUpdates(java.util.LinkedList<Devices.DeviceUpdate> list,
Devices.DeviceUpdate update)
Inserts a new DeviceUpdate to the list of
Devices.DeviceUpdate s. |
public ITopologyService topology
public IEntityClassifierService classifier
public Devices.AttachmentPointComparator apComparator
private java.util.Set<IDeviceListener> deviceListeners
private java.util.concurrent.ConcurrentHashMap<java.lang.Long,Device> deviceIdToDeviceMap
Device
objects.private long deviceKeyCounter
private java.lang.Object deviceKeyCounterLock
private EntityToSingleDeviceIdIndex primaryIndex
private java.util.concurrent.ConcurrentHashMap<java.util.EnumSet<IDeviceService.DeviceField>,EntityToSingleDeviceIdIndex> singleIndices
private java.util.concurrent.ConcurrentHashMap<java.util.EnumSet<IDeviceService.DeviceField>,EntityToMultiDeviceIdIndex> multiIndices
private java.util.Set<SwitchPort> suppressedAPs
private static java.util.concurrent.atomic.AtomicReference<Devices> instanceRef
private OFModel.RESTApi[] apis
private Devices(ITopologyService topo, IEntityClassifierService clf)
topo
- the reference of topology service moduleclf
- the entity classifierpublic static Devices getInstance(ITopologyService topo, IEntityClassifierService clf)
Devices
class. If there is no instance,
creates a new instance.topo
- the reference of topology service moduleclf
- the entity classifierpublic static Devices getInstance()
public boolean isValidAttachmentPoint(long switchDPID, int switchPort)
switchDPID
- the switch dpidswitchPort
- the switch portpublic static Device allocateDevice(java.lang.Long deviceKey, Entity entity, IEntityClass entityClass)
deviceKey
- the unique identifier for this device objectentity
- the initial entity for the deviceentityClass
- the entity classes associated with the entitypublic static Device allocateDevice(java.lang.Long deviceKey, java.util.List<AttachmentPoint> aps, java.util.List<AttachmentPoint> trueAPs, java.util.Collection<Entity> entities, IEntityClass entityClass)
deviceKey
- the unique identifier for this device objectaps
- old attachment points for the devicetrueAPs
- current attachment points for the deviceentities
- the initial entities for the deviceentityClass
- the entity class associated with the entitiespublic static Device allocateDevice(Device device, Entity entity)
device
- the old device objectentity
- the entity to add. This must be have the same
entity class as devicepublic java.util.concurrent.ConcurrentHashMap<java.lang.Long,Device> getDeviceMap()
public int size()
deviceIdToDeviceMap
.public boolean isEntityAllowed(Entity entity, IEntityClass entityClass)
public void reclassify(java.util.Set<java.lang.String> entityClassNames)
entityClassNames
- a set of device entity namespublic void updateAttachmentPoints()
public void cleanupEntities(java.util.Date cutoff)
cutoff
- the time of threshold to delete entitiespublic Device findDestByEntity(IDevice source, Entity dstEntity)
source
- the source device. The returned destination will be
in the same entity class as the source.dstEntity
- the entity to look upDevice
or null if no device is foundpublic java.util.Iterator<Device> queryClassByEntity(IEntityClass clazz, java.util.EnumSet<IDeviceService.DeviceField> keyFields, Entity entity)
clazz
- the entity class for the entitykeyFields
- the key field to search forentity
- the entity class to search forDeviceIdIterator
otherwiseprivate boolean updateIndices(Device device, java.lang.Long deviceId)
device
- the device to updatedeviceId
- the device key for the deviceprivate void updateSecondaryIndices(Entity entity, IEntityClass entityClass, java.lang.Long deviceKey)
entity
- the entity to updateentityClass
- the entity class for the entitydeviceKey
- the device key to set upprivate java.util.LinkedList<Devices.DeviceUpdate> updateUpdates(java.util.LinkedList<Devices.DeviceUpdate> list, Devices.DeviceUpdate update)
Devices.DeviceUpdate
s.list
- the list of Devices.DeviceUpdate
s before updateupdate
- the Devices.DeviceUpdate
to updateDevices.DeviceUpdate
private java.util.EnumSet<IDeviceService.DeviceField> findChangedFields(Device device, Entity newEntity)
IDeviceService.DeviceField
of the device.device
- the device to check its entitiesnewEntity
- the entity to checkprivate void deleteDevice(Device device)
deviceIdToDeviceMap
and its entities.device
- the device to deletepublic void deleteDevice(long datapathid)
datapathid
- datapath id of the switch.private void removeEntity(Entity removed, IEntityClass entityClass, java.lang.Long deviceKey, java.util.Collection<Entity> others)
removed
- the entity to removeentityClass
- the entity class for the entitydeviceKey
- the device key to removeothers
- the others against which to checkprivate boolean reclassifyDevice(Device device)
device
- the device to reclassifyprivate void processUpdates(java.util.Queue<Devices.DeviceUpdate> updates)
updates
- the updates to process.private void sendDeviceMovedNotification(Device d)
d
- the device to updatesprivate boolean allKeyFieldsPresent(Entity e, java.util.EnumSet<IDeviceService.DeviceField> keyFields)
e
- entity to checkkeyFields
- the key fields to check e againstprivate Device findDeviceByEntity(Entity entity)
Device
based on the provided Entity
. We first
check the primary index. If we do not find an entry there we classify
the device into its IEntityClass
and query the classIndex.
This implies that all key field of the current IEntityClassifierService
must be present in the entity for the lookup to succeed!entity
- the entity to search forDevice
object if foundprivate java.util.EnumSet<IDeviceService.DeviceField> getEntityKeys(java.lang.Long macAddress, java.lang.Short vlan, java.lang.Integer ipv4Address, java.lang.Long switchDPID, java.lang.Integer switchPort)
macAddress
- MAC addressvlan
- VLAN IDipv4Address
- IPv4 addressswitchDPID
- the switch dpidswitchPort
- the switch portpublic IDevice getDevice(java.lang.Long deviceKey)
IDeviceService
getDevice
in interface IDeviceService
deviceKey
- the key to search forIDevice.getDeviceKey()
public IDevice findDevice(long macAddress, java.lang.Short vlan, java.lang.Integer ipv4Address, java.lang.Long switchDPID, java.lang.Integer switchPort) throws java.lang.IllegalArgumentException
IDeviceService
Only the key fields as defined by the IEntityClassifierService
will
be important in this search. All key fields MUST be supplied.
IDeviceService.queryDevices(java.lang.Long, java.lang.Short, java.lang.Integer, java.lang.Long, java.lang.Integer)
might be more appropriate!
findDevice
in interface IDeviceService
macAddress
- The MAC addressvlan
- the VLAN. Null means no VLAN and is valid even if VLAN is a key field.ipv4Address
- the ipv4 addressswitchDPID
- the switch dpidswitchPort
- the switch portIDevice
or null if no device is found.java.lang.IllegalArgumentException
- if not all key fields of the
current IEntityClassifierService
are specified.public IDevice findDestDevice(IDevice source, long macAddress, java.lang.Short vlan, java.lang.Integer ipv4Address) throws java.lang.IllegalArgumentException
IDeviceService
findDestDevice
in interface IDeviceService
source
- the source device. The returned destination will be
in the same entity class as the source.macAddress
- The MAC address for the destinationvlan
- the VLAN if availableipv4Address
- The IP address if available.IDevice
or null if no device is found.java.lang.IllegalArgumentException
- if not all key fields of the
source's IEntityClass
are specified.IDeviceService.findDevice(long, Short, Integer, Long, Integer)
public java.util.Collection<? extends IDevice> getAllDevices()
IDeviceService
getAllDevices
in interface IDeviceService
public void addIndex(boolean perClass, java.util.EnumSet<IDeviceService.DeviceField> keyFields)
IDeviceService
addIndex
in interface IDeviceService
perClass
- set to true if the index should be maintained for each
entity class separately.keyFields
- the set of fields on which to indexpublic java.util.Iterator<? extends IDevice> queryDevices(java.lang.Long macAddress, java.lang.Short vlan, java.lang.Integer ipv4Address, java.lang.Long switchDPID, java.lang.Integer switchPort)
IDeviceService
queryDevices
in interface IDeviceService
macAddress
- The MAC addressvlan
- the VLANipv4Address
- the ipv4 addressswitchDPID
- the switch dpidswitchPort
- the switch portpublic java.util.Iterator<? extends IDevice> queryClassDevices(IDevice reference, java.lang.Long macAddress, java.lang.Short vlan, java.lang.Integer ipv4Address, java.lang.Long switchDPID, java.lang.Integer switchPort)
IDeviceService
queryClassDevices
in interface IDeviceService
reference
- The reference device to refer to when finding
entity classes.macAddress
- The MAC addressvlan
- the VLANipv4Address
- the ipv4 addressswitchDPID
- the switch dpidswitchPort
- the switch portpublic void addListener(IDeviceListener listener)
IDeviceService
addListener
in interface IDeviceService
listener
- The listener that wants the notificationspublic void addSuppressAPs(long swId, short port)
IDeviceService
addSuppressAPs
in interface IDeviceService
swId
- a switchidport
- a port numberpublic void removeSuppressAPs(long swId, short port)
IDeviceService
removeSuppressAPs
in interface IDeviceService
swId
- a switchidport
- a port numberpublic boolean isSuppressedAP(SwitchPort switchPort)
switchPort
- the switch port to checkpublic java.lang.String getHostDebugInfo()
public OFModel.RESTApi[] getAllRestApi()
getAllRestApi
in class OFModel