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
diff --git a/protocols/bmv2/src/main/java/org/onosproject/bmv2/ctl/Bmv2ThriftClient.java b/protocols/bmv2/src/main/java/org/onosproject/bmv2/ctl/Bmv2ThriftClient.java
index db0d5e2..f0e68f7 100644
--- a/protocols/bmv2/src/main/java/org/onosproject/bmv2/ctl/Bmv2ThriftClient.java
+++ b/protocols/bmv2/src/main/java/org/onosproject/bmv2/ctl/Bmv2ThriftClient.java
@@ -80,9 +80,9 @@
// 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 @@
}
/**
+ * 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 @@
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);
}
}
diff --git a/protocols/bmv2/src/main/java/org/onosproject/bmv2/ctl/SafeThriftClient.java b/protocols/bmv2/src/main/java/org/onosproject/bmv2/ctl/SafeThriftClient.java
index bbe0546..95a052a 100644
--- a/protocols/bmv2/src/main/java/org/onosproject/bmv2/ctl/SafeThriftClient.java
+++ b/protocols/bmv2/src/main/java/org/onosproject/bmv2/ctl/SafeThriftClient.java
@@ -173,7 +173,12 @@
private static void reconnectOrThrowException(TTransport transport, int maxRetries, long timeBetweenRetries)
throws TTransportException {
int errors = 0;
- transport.close();
+ 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 @@
LOG.debug("Reconnection successful");
break;
} catch (TTransportException e) {
- LOG.error("Error while reconnecting:", e);
+ LOG.debug("Error while reconnecting:", e);
errors++;
if (errors < maxRetries) {