jiangrui
Committed by Gerrit Code Review

CORD-221 Resolve ovsdb device re-connect issue.

Change-Id: I51fae488ab5f6b3b638bc05a17f1f5438d3a4f71
...@@ -27,6 +27,7 @@ import org.apache.felix.scr.annotations.Reference; ...@@ -27,6 +27,7 @@ import org.apache.felix.scr.annotations.Reference;
27 import org.apache.felix.scr.annotations.ReferenceCardinality; 27 import org.apache.felix.scr.annotations.ReferenceCardinality;
28 import org.apache.felix.scr.annotations.Service; 28 import org.apache.felix.scr.annotations.Service;
29 import org.onlab.packet.ChassisId; 29 import org.onlab.packet.ChassisId;
30 +import org.onlab.packet.IpAddress;
30 import org.onosproject.net.DefaultAnnotations; 31 import org.onosproject.net.DefaultAnnotations;
31 import org.onosproject.net.Device; 32 import org.onosproject.net.Device;
32 import org.onosproject.net.DeviceId; 33 import org.onosproject.net.DeviceId;
...@@ -40,6 +41,7 @@ import org.onosproject.net.device.DeviceProviderService; ...@@ -40,6 +41,7 @@ import org.onosproject.net.device.DeviceProviderService;
40 import org.onosproject.net.device.DeviceService; 41 import org.onosproject.net.device.DeviceService;
41 import org.onosproject.net.provider.AbstractProvider; 42 import org.onosproject.net.provider.AbstractProvider;
42 import org.onosproject.net.provider.ProviderId; 43 import org.onosproject.net.provider.ProviderId;
44 +import org.onosproject.ovsdb.controller.OvsdbClientService;
43 import org.onosproject.ovsdb.controller.OvsdbController; 45 import org.onosproject.ovsdb.controller.OvsdbController;
44 import org.onosproject.ovsdb.controller.OvsdbNodeId; 46 import org.onosproject.ovsdb.controller.OvsdbNodeId;
45 import org.onosproject.ovsdb.controller.OvsdbNodeListener; 47 import org.onosproject.ovsdb.controller.OvsdbNodeListener;
...@@ -98,7 +100,8 @@ public class OvsdbDeviceProvider extends AbstractProvider ...@@ -98,7 +100,8 @@ public class OvsdbDeviceProvider extends AbstractProvider
98 100
99 @Override 101 @Override
100 public boolean isReachable(DeviceId deviceId) { 102 public boolean isReachable(DeviceId deviceId) {
101 - return true; 103 + OvsdbClientService ovsdbClient = controller.getOvsdbClient(changeDeviceIdToNodeId(deviceId));
104 + return !(ovsdbClient == null || !ovsdbClient.isConnected());
102 } 105 }
103 106
104 private class InnerOvsdbNodeListener implements OvsdbNodeListener { 107 private class InnerOvsdbNodeListener implements OvsdbNodeListener {
...@@ -131,4 +134,12 @@ public class OvsdbDeviceProvider extends AbstractProvider ...@@ -131,4 +134,12 @@ public class OvsdbDeviceProvider extends AbstractProvider
131 134
132 } 135 }
133 } 136 }
137 +
138 + private OvsdbNodeId changeDeviceIdToNodeId(DeviceId deviceId) {
139 + String[] strings = deviceId.toString().split(":");
140 + if (strings.length < 1) {
141 + return null;
142 + }
143 + return new OvsdbNodeId(IpAddress.valueOf(strings[1]), 0);
144 + }
134 } 145 }
......