During the device initialization process, if its encountered that the role for this node is slave
we cancel the txn which is built during the process.
Now since ping-pong txn does not have a cancel, we drop the txn and recreate it. This throws an exception
Since this is an expected exception, it would be advisable to catch and log it in debug.
Also when a node gets disconected from device, the EntityOwnershipService does send a notification. Which trigers a role change.
A check is made to check if the device is connected before moving ahead with the role change.
Change-Id: I76572f27274f5c5f08117fcfd1590d1042049735
Signed-off-by: Kamal Rameshan <kramesha@cisco.com>
if (deviceContext.getDeviceState().getRole() != OfpRole.BECOMESLAVE) {
((DeviceContextImpl) deviceContext).initialSubmitTransaction();
deviceContext.onPublished();
+
} else {
- ((DeviceContextImpl) deviceContext).cancelTransaction();
+ //if role = slave
+ try {
+ ((DeviceContextImpl) deviceContext).cancelTransaction();
+ } catch (Exception e) {
+ //TODO: how can we avoid it. pingpong does not have cancel
+ LOG.debug("Expected Exception: Cancel Txn exception thrown for slaves", e);
+ }
+
}
} catch (final Exception e) {
@Override
public void onRoleChanged(final OfpRole oldRole, final OfpRole newRole) {
- // called notification thread from md-sal
+ if (!isDeviceConnected()) {
+ // this can happen as after the disconnect, we still get a last messsage from EntityOwnershipService.
+ LOG.info("Device {} is disconnected from this node. Hence not attempting a role change.",
+ deviceContext.getPrimaryConnectionContext().getNodeId());
+ return;
+ }
LOG.debug("Role change received from ownership listener from {} to {} for device:{}", oldRole, newRole,
deviceContext.getPrimaryConnectionContext().getNodeId());
when(deviceState.getFeatures()).thenReturn(getFeaturesOutput);
when(getFeaturesOutput.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
when(deviceContext.getPrimaryConnectionContext().getFeatures()).thenReturn(featuresReply);
+ when(deviceContext.getPrimaryConnectionContext().getConnectionState()).thenReturn(ConnectionContext.CONNECTION_STATE.WORKING);
}
@Test