Carmelo Cascone
Committed by Gerrit Code Review

ONOS-4422 Implemented device discovery in Bmv2 device provider and other

improvements

- Added listener for hello messages received from Bmv2 devices
- Added a periodic poller task to check device reachability and port
information updates
- Avoids periodically re-connecting the device if it is already
available in the core
- Fixed minor bug in Bmv2ThriftClient

Change-Id: I416d1880773e11b2ac6fa062d8be2b8f280786fb
......@@ -80,9 +80,9 @@ public final class Bmv2ThriftClient implements Bmv2Client {
// Seconds after a client is expired (and connection closed) in the cache.
private static final int CLIENT_CACHE_TIMEOUT = 60;
// Number of connection retries after a network error.
private static final int NUM_CONNECTION_RETRIES = 10;
private static final int NUM_CONNECTION_RETRIES = 3;
// Time between retries in milliseconds.
private static final int TIME_BETWEEN_RETRIES = 200;
private static final int TIME_BETWEEN_RETRIES = 300;
// Static client cache where clients are removed after a predefined timeout.
private static final LoadingCache<DeviceId, Bmv2ThriftClient>
......@@ -125,6 +125,15 @@ public final class Bmv2ThriftClient implements Bmv2Client {
}
/**
* Force a close of the transport session (if one is open) with the given device.
*
* @param deviceId device id
*/
public static void forceDisconnectOf(DeviceId deviceId) {
CLIENT_CACHE.invalidate(deviceId);
}
/**
* Pings the device. Returns true if the device is reachable,
* false otherwise.
*
......@@ -392,7 +401,7 @@ public final class Bmv2ThriftClient implements Bmv2Client {
LOG.debug("Packet transmission requested! > portNumber={}, packet={}", portNumber, packet);
} catch (TException e) {
LOG.debug("Exception while requesting packet transmission: {} > portNumber={}, packet={}",
portNumber, packet);
e, portNumber, packet);
throw new Bmv2RuntimeException(e.getMessage(), e);
}
}
......
......@@ -173,7 +173,12 @@ public final class SafeThriftClient {
private static void reconnectOrThrowException(TTransport transport, int maxRetries, long timeBetweenRetries)
throws TTransportException {
int errors = 0;
try {
transport.close();
} catch (Exception e) {
// Thrift seems to have a bug where if the transport is already closed a SocketException is thrown.
// However, such an exception is not advertised by .close(), hence the general-purpose catch.
}
while (errors < maxRetries) {
try {
......@@ -182,7 +187,7 @@ public final class SafeThriftClient {
LOG.debug("Reconnection successful");
break;
} catch (TTransportException e) {
LOG.error("Error while reconnecting:", e);
LOG.debug("Error while reconnecting:", e);
errors++;
if (errors < maxRetries) {
......