Andrea Campanella
Committed by Gerrit Code Review

Refactoring ID creation for netconf and REST

Change-Id: I4165ad53e19c86d9d9b304d09e24dcfeec2b9ddf
......@@ -40,6 +40,7 @@ public class NetconfDeviceInfo {
private IpAddress ipAddress;
private int port;
private File keyFile;
private DeviceId deviceId;
/**
......@@ -143,13 +144,14 @@ public class NetconfDeviceInfo {
* @return DeviceId
*/
public DeviceId getDeviceId() {
try {
return DeviceId.deviceId(new URI(this.toString()));
} catch (URISyntaxException e) {
log.debug("Unable to build deviceID for device {} ", this, e);
if (deviceId == null) {
try {
deviceId = DeviceId.deviceId(new URI("netconf", ipAddress.toString() + ":" + port, null));
} catch (URISyntaxException e) {
throw new IllegalArgumentException("Unable to build deviceID for device " + toString(), e);
}
}
return null;
return deviceId;
}
@Override
......
......@@ -81,8 +81,7 @@ public class NetconfControllerImpl implements NetconfController {
@Override
public NetconfDevice getNetconfDevice(IpAddress ip, int port) {
for (DeviceId info : netconfDeviceMap.keySet()) {
if (IpAddress.valueOf(info.uri().getHost()).equals(ip) &&
info.uri().getPort() == port) {
if (info.uri().getSchemeSpecificPart().equals(ip.toString() + ":" + port)) {
return netconfDeviceMap.get(info);
}
}
......@@ -102,7 +101,7 @@ public class NetconfControllerImpl implements NetconfController {
@Override
public void removeDevice(NetconfDeviceInfo deviceInfo) {
if (netconfDeviceMap.containsKey(deviceInfo.getDeviceId())) {
if (!netconfDeviceMap.containsKey(deviceInfo.getDeviceId())) {
log.warn("Device {} is not present", deviceInfo);
} else {
stopDevice(deviceInfo);
......
......@@ -22,6 +22,8 @@ import org.apache.commons.lang3.StringUtils;
import org.onlab.packet.IpAddress;
import org.onosproject.net.DeviceId;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Objects;
/**
......@@ -74,7 +76,13 @@ public class DefaultRestSBDevice implements RestSBDevice {
@Override
public DeviceId deviceId() {
return DeviceId.deviceId(REST + COLON + ip + COLON + port);
try {
return DeviceId.deviceId(new URI(REST, ip + COLON + port, null));
} catch (URISyntaxException e) {
throw new IllegalArgumentException("Cannot create deviceID " +
REST + COLON + ip +
COLON + port, e);
}
}
@Override
......
{
"devices":{
"netconf:mininet@10.1.9.24:830":{
"netconf:10.1.9.24:830":{
"basic":{
"driver":"ovs-netconf"
}
......