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;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.onlab.packet.ChassisId;
import org.onlab.packet.IpAddress;
import org.onosproject.net.DefaultAnnotations;
import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
......@@ -40,6 +41,7 @@ import org.onosproject.net.device.DeviceProviderService;
import org.onosproject.net.device.DeviceService;
import org.onosproject.net.provider.AbstractProvider;
import org.onosproject.net.provider.ProviderId;
import org.onosproject.ovsdb.controller.OvsdbClientService;
import org.onosproject.ovsdb.controller.OvsdbController;
import org.onosproject.ovsdb.controller.OvsdbNodeId;
import org.onosproject.ovsdb.controller.OvsdbNodeListener;
......@@ -98,7 +100,8 @@ public class OvsdbDeviceProvider extends AbstractProvider
@Override
public boolean isReachable(DeviceId deviceId) {
return true;
OvsdbClientService ovsdbClient = controller.getOvsdbClient(changeDeviceIdToNodeId(deviceId));
return !(ovsdbClient == null || !ovsdbClient.isConnected());
}
private class InnerOvsdbNodeListener implements OvsdbNodeListener {
......@@ -131,4 +134,12 @@ public class OvsdbDeviceProvider extends AbstractProvider
}
}
private OvsdbNodeId changeDeviceIdToNodeId(DeviceId deviceId) {
String[] strings = deviceId.toString().split(":");
if (strings.length < 1) {
return null;
}
return new OvsdbNodeId(IpAddress.valueOf(strings[1]), 0);
}
}
......