deviceUpdates = null;
// Look up the fully-qualified entity to see if it already
// exists in the primary entity index.
Long deviceKey = primaryIndex.findByEntity(entity);
IEntityClass entityClass = null;
if (deviceKey == null) {
// If the entity does not exist in the primary entity index,
// use the entity classifier for find the classes for the
// entity. Look up the entity in the returned class'
// class entity index.
entityClass = entityClassifier.classifyEntity(entity);
if (entityClass == null) {
// could not classify entity. No device
device = null;
break;
}
ClassState classState = getClassState(entityClass);
if (classState.classIndex != null) {
deviceKey =
classState.classIndex.findByEntity(entity);
}
}
if (deviceKey != null) {
// If the primary or secondary index contains the entity
// use resulting device key to look up the device in the
// device map, and use the referenced Device below.
device = deviceMap.get(deviceKey);
if (device == null) {
// This can happen due to concurrent modification
if (logger.isDebugEnabled()) {
logger.debug("No device for deviceKey {} while "
+ "while processing entity {}",
deviceKey, entity);
}
// if so, then try again till we don't even get the device key
// and so we recreate the device
continue;
}
} else {
// If the secondary index does not contain the entity,
// create a new Device object containing the entity, and
// generate a new device ID if the the entity is on an
// attachment point port. Otherwise ignore.
if (entity.hasSwitchPort() &&
!topology.isAttachmentPointPort(entity.getSwitchDPID(),
entity.getSwitchPort().shortValue())) {
cntDeviceOnInternalPortNotLearned.updateCounterNoFlush();
if (logger.isDebugEnabled()) {
logger.debug("Not learning new device on internal"
+ " link: {}", entity);
}
device = null;
break;
}
// Before we create the new device also check if
// the entity is allowed (e.g., for spoofing protection)
if (!isEntityAllowed(entity, entityClass)) {
cntPacketNotAllowed.updateCounterNoFlush();
if (logger.isDebugEnabled()) {
logger.debug("PacketIn is not allowed {} {}",
entityClass.getName(), entity);
}
device = null;
break;
}
deviceKey = deviceKeyCounter.getAndIncrement();