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
Showing
3 changed files
with
19 additions
and
5 deletions
... | @@ -80,9 +80,9 @@ public final class Bmv2ThriftClient implements Bmv2Client { | ... | @@ -80,9 +80,9 @@ public final class Bmv2ThriftClient implements Bmv2Client { |
80 | // Seconds after a client is expired (and connection closed) in the cache. | 80 | // Seconds after a client is expired (and connection closed) in the cache. |
81 | private static final int CLIENT_CACHE_TIMEOUT = 60; | 81 | private static final int CLIENT_CACHE_TIMEOUT = 60; |
82 | // Number of connection retries after a network error. | 82 | // Number of connection retries after a network error. |
83 | - private static final int NUM_CONNECTION_RETRIES = 10; | 83 | + private static final int NUM_CONNECTION_RETRIES = 3; |
84 | // Time between retries in milliseconds. | 84 | // Time between retries in milliseconds. |
85 | - private static final int TIME_BETWEEN_RETRIES = 200; | 85 | + private static final int TIME_BETWEEN_RETRIES = 300; |
86 | 86 | ||
87 | // Static client cache where clients are removed after a predefined timeout. | 87 | // Static client cache where clients are removed after a predefined timeout. |
88 | private static final LoadingCache<DeviceId, Bmv2ThriftClient> | 88 | private static final LoadingCache<DeviceId, Bmv2ThriftClient> |
... | @@ -125,6 +125,15 @@ public final class Bmv2ThriftClient implements Bmv2Client { | ... | @@ -125,6 +125,15 @@ public final class Bmv2ThriftClient implements Bmv2Client { |
125 | } | 125 | } |
126 | 126 | ||
127 | /** | 127 | /** |
128 | + * Force a close of the transport session (if one is open) with the given device. | ||
129 | + * | ||
130 | + * @param deviceId device id | ||
131 | + */ | ||
132 | + public static void forceDisconnectOf(DeviceId deviceId) { | ||
133 | + CLIENT_CACHE.invalidate(deviceId); | ||
134 | + } | ||
135 | + | ||
136 | + /** | ||
128 | * Pings the device. Returns true if the device is reachable, | 137 | * Pings the device. Returns true if the device is reachable, |
129 | * false otherwise. | 138 | * false otherwise. |
130 | * | 139 | * |
... | @@ -392,7 +401,7 @@ public final class Bmv2ThriftClient implements Bmv2Client { | ... | @@ -392,7 +401,7 @@ public final class Bmv2ThriftClient implements Bmv2Client { |
392 | LOG.debug("Packet transmission requested! > portNumber={}, packet={}", portNumber, packet); | 401 | LOG.debug("Packet transmission requested! > portNumber={}, packet={}", portNumber, packet); |
393 | } catch (TException e) { | 402 | } catch (TException e) { |
394 | LOG.debug("Exception while requesting packet transmission: {} > portNumber={}, packet={}", | 403 | LOG.debug("Exception while requesting packet transmission: {} > portNumber={}, packet={}", |
395 | - portNumber, packet); | 404 | + e, portNumber, packet); |
396 | throw new Bmv2RuntimeException(e.getMessage(), e); | 405 | throw new Bmv2RuntimeException(e.getMessage(), e); |
397 | } | 406 | } |
398 | } | 407 | } | ... | ... |
... | @@ -173,7 +173,12 @@ public final class SafeThriftClient { | ... | @@ -173,7 +173,12 @@ public final class SafeThriftClient { |
173 | private static void reconnectOrThrowException(TTransport transport, int maxRetries, long timeBetweenRetries) | 173 | private static void reconnectOrThrowException(TTransport transport, int maxRetries, long timeBetweenRetries) |
174 | throws TTransportException { | 174 | throws TTransportException { |
175 | int errors = 0; | 175 | int errors = 0; |
176 | - transport.close(); | 176 | + try { |
177 | + transport.close(); | ||
178 | + } catch (Exception e) { | ||
179 | + // Thrift seems to have a bug where if the transport is already closed a SocketException is thrown. | ||
180 | + // However, such an exception is not advertised by .close(), hence the general-purpose catch. | ||
181 | + } | ||
177 | 182 | ||
178 | while (errors < maxRetries) { | 183 | while (errors < maxRetries) { |
179 | try { | 184 | try { |
... | @@ -182,7 +187,7 @@ public final class SafeThriftClient { | ... | @@ -182,7 +187,7 @@ public final class SafeThriftClient { |
182 | LOG.debug("Reconnection successful"); | 187 | LOG.debug("Reconnection successful"); |
183 | break; | 188 | break; |
184 | } catch (TTransportException e) { | 189 | } catch (TTransportException e) { |
185 | - LOG.error("Error while reconnecting:", e); | 190 | + LOG.debug("Error while reconnecting:", e); |
186 | errors++; | 191 | errors++; |
187 | 192 | ||
188 | if (errors < maxRetries) { | 193 | if (errors < maxRetries) { | ... | ... |
This diff is collapsed. Click to expand it.
-
Please register or login to post a comment