Andrea Campanella
Committed by Gerrit Code Review

Deprecating PortDiscovery in favour of DeviceDescritpionDiscovery

Change-Id: Ie9cff7937412c62c8a5a3b75b87a43952017f146
...@@ -26,12 +26,18 @@ import java.util.List; ...@@ -26,12 +26,18 @@ import java.util.List;
26 /** 26 /**
27 * Discovers the set of ports from a device through a device specific protocol. 27 * Discovers the set of ports from a device through a device specific protocol.
28 * The returned ports are not retrieved from the information stored in ONOS. 28 * The returned ports are not retrieved from the information stored in ONOS.
29 + *
30 + * @deprecated 1.6.0 Goldeneye. Use DeviceDescriptionDiscovery instead
29 */ 31 */
32 +@Deprecated
30 public interface PortDiscovery extends HandlerBehaviour { 33 public interface PortDiscovery extends HandlerBehaviour {
31 34
32 /** 35 /**
33 * Retrieves the set of ports from a device. 36 * Retrieves the set of ports from a device.
37 + *
34 * @return a set of port descriptions. 38 * @return a set of port descriptions.
39 + * @deprecated 1.6.0 Goldeneye. Use DeviceDescriptionDiscovery instead
35 */ 40 */
41 + @Deprecated
36 List<PortDescription> getPorts(); 42 List<PortDescription> getPorts();
37 } 43 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -28,7 +28,7 @@ import java.util.List; ...@@ -28,7 +28,7 @@ import java.util.List;
28 public interface DeviceDescriptionDiscovery extends HandlerBehaviour { 28 public interface DeviceDescriptionDiscovery extends HandlerBehaviour {
29 29
30 /** 30 /**
31 - * Returns device description appropriately annotated to support 31 + * Returns a device description appropriately annotated to support
32 * downstream model extension via projections of the resulting device, 32 * downstream model extension via projections of the resulting device,
33 * as in the following example. 33 * as in the following example.
34 * <pre> 34 * <pre>
...@@ -40,7 +40,7 @@ public interface DeviceDescriptionDiscovery extends HandlerBehaviour { ...@@ -40,7 +40,7 @@ public interface DeviceDescriptionDiscovery extends HandlerBehaviour {
40 DeviceDescription discoverDeviceDetails(); 40 DeviceDescription discoverDeviceDetails();
41 41
42 /** 42 /**
43 - * Returns list of port descriptions appropriately annotated to support 43 + * Returns a list of port descriptions appropriately annotated to support
44 * downstream model extension via projections of their parent device, 44 * downstream model extension via projections of their parent device,
45 * as in the following example. 45 * as in the following example.
46 * <pre> 46 * <pre>
......
...@@ -22,6 +22,7 @@ import org.apache.felix.scr.annotations.Deactivate; ...@@ -22,6 +22,7 @@ import org.apache.felix.scr.annotations.Deactivate;
22 import org.apache.felix.scr.annotations.Reference; 22 import org.apache.felix.scr.annotations.Reference;
23 import org.apache.felix.scr.annotations.ReferenceCardinality; 23 import org.apache.felix.scr.annotations.ReferenceCardinality;
24 import org.onosproject.net.DeviceId; 24 import org.onosproject.net.DeviceId;
25 +import org.onosproject.net.device.DeviceDescription;
25 import org.onosproject.net.device.DeviceDescriptionDiscovery; 26 import org.onosproject.net.device.DeviceDescriptionDiscovery;
26 import org.onosproject.net.device.DeviceProvider; 27 import org.onosproject.net.device.DeviceProvider;
27 import org.onosproject.net.device.DeviceProviderRegistry; 28 import org.onosproject.net.device.DeviceProviderRegistry;
...@@ -93,10 +94,15 @@ public abstract class AbstractDeviceProvider extends AbstractProvider ...@@ -93,10 +94,15 @@ public abstract class AbstractDeviceProvider extends AbstractProvider
93 protected void discoverDevice(DriverHandler handler) { 94 protected void discoverDevice(DriverHandler handler) {
94 DeviceId deviceId = handler.data().deviceId(); 95 DeviceId deviceId = handler.data().deviceId();
95 DeviceDescriptionDiscovery discovery = handler.behaviour(DeviceDescriptionDiscovery.class); 96 DeviceDescriptionDiscovery discovery = handler.behaviour(DeviceDescriptionDiscovery.class);
96 - providerService.deviceConnected(deviceId, discovery.discoverDeviceDetails()); 97 + DeviceDescription description = discovery.discoverDeviceDetails();
98 + if (description != null) {
99 + providerService.deviceConnected(deviceId, description);
100 + } else {
101 + log.info("No other description given for device {}", deviceId);
102 + }
97 providerService.updatePorts(deviceId, discovery.discoverPortDetails()); 103 providerService.updatePorts(deviceId, discovery.discoverPortDetails());
98 - }
99 104
105 + }
100 // TODO: inspect NETCONF, SNMP, RESTSB device providers for additional common patterns 106 // TODO: inspect NETCONF, SNMP, RESTSB device providers for additional common patterns
101 // TODO: provide base for port status update 107 // TODO: provide base for port status update
102 // TODO: integrate with network config for learning about management addresses to probe 108 // TODO: integrate with network config for learning about management addresses to probe
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
18 18
19 package org.onosproject.drivers.ciena; 19 package org.onosproject.drivers.ciena;
20 20
21 +import com.google.common.collect.ImmutableList;
21 import com.google.common.collect.Lists; 22 import com.google.common.collect.Lists;
22 import org.apache.commons.configuration.HierarchicalConfiguration; 23 import org.apache.commons.configuration.HierarchicalConfiguration;
23 import org.onosproject.drivers.utilities.XmlConfigParser; 24 import org.onosproject.drivers.utilities.XmlConfigParser;
...@@ -31,11 +32,13 @@ import org.onosproject.net.OchSignal; ...@@ -31,11 +32,13 @@ import org.onosproject.net.OchSignal;
31 import org.onosproject.net.OduSignalType; 32 import org.onosproject.net.OduSignalType;
32 import org.onosproject.net.PortNumber; 33 import org.onosproject.net.PortNumber;
33 import org.onosproject.net.SparseAnnotations; 34 import org.onosproject.net.SparseAnnotations;
34 -import org.onosproject.net.behaviour.PortDiscovery; 35 +import org.onosproject.net.device.DeviceDescription;
36 +import org.onosproject.net.device.DeviceDescriptionDiscovery;
35 import org.onosproject.net.device.PortDescription; 37 import org.onosproject.net.device.PortDescription;
36 import org.onosproject.net.driver.AbstractHandlerBehaviour; 38 import org.onosproject.net.driver.AbstractHandlerBehaviour;
37 import org.onosproject.net.driver.DriverHandler; 39 import org.onosproject.net.driver.DriverHandler;
38 import org.onosproject.protocol.rest.RestSBController; 40 import org.onosproject.protocol.rest.RestSBController;
41 +import org.slf4j.Logger;
39 42
40 import java.util.ArrayList; 43 import java.util.ArrayList;
41 import java.util.List; 44 import java.util.List;
...@@ -43,12 +46,15 @@ import java.util.List; ...@@ -43,12 +46,15 @@ import java.util.List;
43 import static com.google.common.base.Preconditions.checkNotNull; 46 import static com.google.common.base.Preconditions.checkNotNull;
44 import static org.onosproject.net.optical.device.OchPortHelper.ochPortDescription; 47 import static org.onosproject.net.optical.device.OchPortHelper.ochPortDescription;
45 import static org.onosproject.net.optical.device.OduCltPortHelper.oduCltPortDescription; 48 import static org.onosproject.net.optical.device.OduCltPortHelper.oduCltPortDescription;
49 +import static org.slf4j.LoggerFactory.getLogger;
46 50
47 /** 51 /**
48 * Discovers the ports from a Ciena WaveServer Rest device. 52 * Discovers the ports from a Ciena WaveServer Rest device.
49 */ 53 */
50 -public class PortDiscoveryCienaWaveserverImpl extends AbstractHandlerBehaviour 54 +public class CienaWaveserverDeviceDescription extends AbstractHandlerBehaviour
51 - implements PortDiscovery { 55 + implements DeviceDescriptionDiscovery {
56 +
57 + private final Logger log = getLogger(getClass());
52 58
53 private static final String SPEED = "speed"; 59 private static final String SPEED = "speed";
54 private static final String GBPS = "Gbps"; 60 private static final String GBPS = "Gbps";
...@@ -74,9 +80,19 @@ public class PortDiscoveryCienaWaveserverImpl extends AbstractHandlerBehaviour ...@@ -74,9 +80,19 @@ public class PortDiscoveryCienaWaveserverImpl extends AbstractHandlerBehaviour
74 // private static final String SPECIFIC_PORT_CONFIG = 80 // private static final String SPECIFIC_PORT_CONFIG =
75 // "/ptp-config?config=true&format=xml&depth=unbounded"; 81 // "/ptp-config?config=true&format=xml&depth=unbounded";
76 82
83 + @Override
84 + public DeviceDescription discoverDeviceDetails() {
85 + log.info("No description to be added for device");
86 + //TODO to be implemented if needed.
87 + return null;
88 + }
77 89
78 @Override 90 @Override
79 - public List<PortDescription> getPorts() { 91 + public List<PortDescription> discoverPortDetails() {
92 + return getPorts();
93 + }
94 +
95 + private List<PortDescription> getPorts() {
80 List<PortDescription> ports = Lists.newArrayList(); 96 List<PortDescription> ports = Lists.newArrayList();
81 DriverHandler handler = handler(); 97 DriverHandler handler = handler();
82 RestSBController controller = checkNotNull(handler.get(RestSBController.class)); 98 RestSBController controller = checkNotNull(handler.get(RestSBController.class));
...@@ -121,11 +137,11 @@ public class PortDiscoveryCienaWaveserverImpl extends AbstractHandlerBehaviour ...@@ -121,11 +137,11 @@ public class PortDiscoveryCienaWaveserverImpl extends AbstractHandlerBehaviour
121 .replace(" ", EMPTY_STRING))) == speed100GbpsinMbps ? 137 .replace(" ", EMPTY_STRING))) == speed100GbpsinMbps ?
122 CltSignalType.CLT_100GBE : null; 138 CltSignalType.CLT_100GBE : null;
123 ports.add(oduCltPortDescription(PortNumber.portNumber(sub.getLong(PORT_ID)), 139 ports.add(oduCltPortDescription(PortNumber.portNumber(sub.getLong(PORT_ID)),
124 - sub.getString(ADMIN_STATE).equals(ENABLED), 140 + sub.getString(ADMIN_STATE).equals(ENABLED),
125 - cltType, annotations.build())); 141 + cltType, annotations.build()));
126 } 142 }
127 }); 143 });
128 - return ports; 144 + return ImmutableList.copyOf(ports);
129 } 145 }
130 146
131 public static List<HierarchicalConfiguration> parseWaveServerCienaPorts(HierarchicalConfiguration cfg) { 147 public static List<HierarchicalConfiguration> parseWaveServerCienaPorts(HierarchicalConfiguration cfg) {
...@@ -156,7 +172,7 @@ public class PortDiscoveryCienaWaveserverImpl extends AbstractHandlerBehaviour ...@@ -156,7 +172,7 @@ public class PortDiscoveryCienaWaveserverImpl extends AbstractHandlerBehaviour
156 baseFrequency)) / toGbpsFromHz(chSpacing.frequency().asHz())); //FIXME is there a better way ? 172 baseFrequency)) / toGbpsFromHz(chSpacing.frequency().asHz())); //FIXME is there a better way ?
157 173
158 return ochPortDescription(PortNumber.portNumber(portNumber), isEnabled, oduSignalType, isTunable, 174 return ochPortDescription(PortNumber.portNumber(portNumber), isEnabled, oduSignalType, isTunable,
159 - new OchSignal(gridType, chSpacing, spacingMult, 1), annotations); 175 + new OchSignal(gridType, chSpacing, spacingMult, 1), annotations);
160 } 176 }
161 177
162 //FIXME remove when all optical types have two way information methods, see jira tickets 178 //FIXME remove when all optical types have two way information methods, see jira tickets
......
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
20 impl="org.onosproject.drivers.ciena.PortDiscoveryCienaWaveserverImpl"/> 20 impl="org.onosproject.drivers.ciena.PortDiscoveryCienaWaveserverImpl"/>
21 <behaviour api="org.onosproject.net.optical.OpticalDevice" 21 <behaviour api="org.onosproject.net.optical.OpticalDevice"
22 impl="org.onosproject.net.optical.DefaultOpticalDevice"/> 22 impl="org.onosproject.net.optical.DefaultOpticalDevice"/>
23 + <behaviour api="org.onosproject.net.device.DeviceDescriptionDiscovery"
24 + impl="org.onosproject.drivers.ciena.CienaWaveserverDeviceDescription"/>
23 </driver> 25 </driver>
24 </drivers> 26 </drivers>
25 27
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
16 16
17 package org.onosproject.drivers.fujitsu; 17 package org.onosproject.drivers.fujitsu;
18 18
19 +import com.google.common.collect.ImmutableList;
20 +import com.google.common.collect.Lists;
19 import org.apache.commons.configuration.HierarchicalConfiguration; 21 import org.apache.commons.configuration.HierarchicalConfiguration;
20 import org.onosproject.drivers.utilities.XmlConfigParser; 22 import org.onosproject.drivers.utilities.XmlConfigParser;
21 import org.onosproject.net.AnnotationKeys; 23 import org.onosproject.net.AnnotationKeys;
...@@ -26,7 +28,8 @@ import org.onosproject.net.GridType; ...@@ -26,7 +28,8 @@ import org.onosproject.net.GridType;
26 import org.onosproject.net.OchSignal; 28 import org.onosproject.net.OchSignal;
27 import org.onosproject.net.OduSignalType; 29 import org.onosproject.net.OduSignalType;
28 import org.onosproject.net.PortNumber; 30 import org.onosproject.net.PortNumber;
29 -import org.onosproject.net.behaviour.PortDiscovery; 31 +import org.onosproject.net.device.DeviceDescription;
32 +import org.onosproject.net.device.DeviceDescriptionDiscovery;
30 import org.onosproject.net.device.PortDescription; 33 import org.onosproject.net.device.PortDescription;
31 import org.onosproject.net.driver.AbstractHandlerBehaviour; 34 import org.onosproject.net.driver.AbstractHandlerBehaviour;
32 import org.onosproject.netconf.NetconfController; 35 import org.onosproject.netconf.NetconfController;
...@@ -34,8 +37,6 @@ import org.onosproject.netconf.NetconfException; ...@@ -34,8 +37,6 @@ import org.onosproject.netconf.NetconfException;
34 import org.onosproject.netconf.NetconfSession; 37 import org.onosproject.netconf.NetconfSession;
35 import org.slf4j.Logger; 38 import org.slf4j.Logger;
36 39
37 -import com.google.common.collect.Lists;
38 -
39 import java.io.ByteArrayInputStream; 40 import java.io.ByteArrayInputStream;
40 import java.io.IOException; 41 import java.io.IOException;
41 import java.util.List; 42 import java.util.List;
...@@ -49,13 +50,20 @@ import static org.slf4j.LoggerFactory.getLogger; ...@@ -49,13 +50,20 @@ import static org.slf4j.LoggerFactory.getLogger;
49 /** 50 /**
50 * Retrieves the ports from a Fujitsu T100 device via netconf. 51 * Retrieves the ports from a Fujitsu T100 device via netconf.
51 */ 52 */
52 -public class PortGetterFujitsuImpl extends AbstractHandlerBehaviour 53 +public class FujitsuT100DeviceDescription extends AbstractHandlerBehaviour
53 - implements PortDiscovery { 54 + implements DeviceDescriptionDiscovery {
54 55
55 private final Logger log = getLogger(getClass()); 56 private final Logger log = getLogger(getClass());
56 57
57 @Override 58 @Override
58 - public List<PortDescription> getPorts() { 59 + public DeviceDescription discoverDeviceDetails() {
60 + log.info("No description to be added for device");
61 + //TODO to be implemented if needed.
62 + return null;
63 + }
64 +
65 + @Override
66 + public List<PortDescription> discoverPortDetails() {
59 NetconfController controller = checkNotNull(handler().get(NetconfController.class)); 67 NetconfController controller = checkNotNull(handler().get(NetconfController.class));
60 NetconfSession session = controller.getDevicesMap().get(handler().data().deviceId()).getSession(); 68 NetconfSession session = controller.getDevicesMap().get(handler().data().deviceId()).getSession();
61 String reply; 69 String reply;
...@@ -67,12 +75,13 @@ public class PortGetterFujitsuImpl extends AbstractHandlerBehaviour ...@@ -67,12 +75,13 @@ public class PortGetterFujitsuImpl extends AbstractHandlerBehaviour
67 List<PortDescription> descriptions = 75 List<PortDescription> descriptions =
68 parseFujitsuT100Ports(XmlConfigParser. 76 parseFujitsuT100Ports(XmlConfigParser.
69 loadXml(new ByteArrayInputStream(reply.getBytes()))); 77 loadXml(new ByteArrayInputStream(reply.getBytes())));
70 - return descriptions; 78 + return ImmutableList.copyOf(descriptions);
71 } 79 }
72 80
73 /** 81 /**
74 * Builds a request crafted to get the configuration required to create port 82 * Builds a request crafted to get the configuration required to create port
75 * descriptions for the device. 83 * descriptions for the device.
84 + *
76 * @return The request string. 85 * @return The request string.
77 */ 86 */
78 private String requestBuilder() { 87 private String requestBuilder() {
...@@ -91,6 +100,7 @@ public class PortGetterFujitsuImpl extends AbstractHandlerBehaviour ...@@ -91,6 +100,7 @@ public class PortGetterFujitsuImpl extends AbstractHandlerBehaviour
91 100
92 /** 101 /**
93 * Parses a configuration and returns a set of ports for the fujitsu T100. 102 * Parses a configuration and returns a set of ports for the fujitsu T100.
103 + *
94 * @param cfg a hierarchical configuration 104 * @param cfg a hierarchical configuration
95 * @return a list of port descriptions 105 * @return a list of port descriptions
96 */ 106 */
......
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
20 impl="org.onosproject.drivers.fujitsu.PortGetterFujitsuImpl"/> 20 impl="org.onosproject.drivers.fujitsu.PortGetterFujitsuImpl"/>
21 <behaviour api="org.onosproject.net.optical.OpticalDevice" 21 <behaviour api="org.onosproject.net.optical.OpticalDevice"
22 impl="org.onosproject.net.optical.DefaultOpticalDevice"/> 22 impl="org.onosproject.net.optical.DefaultOpticalDevice"/>
23 + <behaviour api="org.onosproject.net.device.DeviceDescriptionDiscovery"
24 + impl="org.onosproject.drivers.fujitsu.FujitsuT100DeviceDescription"/>
23 </driver> 25 </driver>
24 </drivers> 26 </drivers>
25 27
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 16
17 package org.onosproject.drivers.lumentum; 17 package org.onosproject.drivers.lumentum;
18 18
19 +import com.google.common.collect.ImmutableList;
19 import com.google.common.collect.Lists; 20 import com.google.common.collect.Lists;
20 import org.onosproject.net.AnnotationKeys; 21 import org.onosproject.net.AnnotationKeys;
21 import org.onosproject.net.DefaultAnnotations; 22 import org.onosproject.net.DefaultAnnotations;
...@@ -45,7 +46,7 @@ import static org.slf4j.LoggerFactory.getLogger; ...@@ -45,7 +46,7 @@ import static org.slf4j.LoggerFactory.getLogger;
45 /** 46 /**
46 * Device description behaviour for Lumentum Snmp devices. 47 * Device description behaviour for Lumentum Snmp devices.
47 */ 48 */
48 -public class LumentumRoadmDeviceDescription extends AbstractHandlerBehaviour implements DeviceDescriptionDiscovery { 49 +public class LumentumRoadmDeviceDescription extends AbstractHandlerBehaviour implements DeviceDescriptionDiscovery {
49 50
50 private final Logger log = getLogger(getClass()); 51 private final Logger log = getLogger(getClass());
51 52
...@@ -66,7 +67,7 @@ public class LumentumRoadmDeviceDescription extends AbstractHandlerBehaviour imp ...@@ -66,7 +67,7 @@ public class LumentumRoadmDeviceDescription extends AbstractHandlerBehaviour imp
66 67
67 @Override 68 @Override
68 public List<PortDescription> discoverPortDetails() { 69 public List<PortDescription> discoverPortDetails() {
69 - return this.getPorts(); 70 + return ImmutableList.copyOf(this.getPorts());
70 } 71 }
71 72
72 private List<PortDescription> getPorts() { 73 private List<PortDescription> getPorts() {
......
...@@ -43,6 +43,7 @@ import org.onosproject.net.config.NetworkConfigListener; ...@@ -43,6 +43,7 @@ import org.onosproject.net.config.NetworkConfigListener;
43 import org.onosproject.net.config.NetworkConfigRegistry; 43 import org.onosproject.net.config.NetworkConfigRegistry;
44 import org.onosproject.net.device.DefaultDeviceDescription; 44 import org.onosproject.net.device.DefaultDeviceDescription;
45 import org.onosproject.net.device.DeviceDescription; 45 import org.onosproject.net.device.DeviceDescription;
46 +import org.onosproject.net.device.DeviceDescriptionDiscovery;
46 import org.onosproject.net.device.DeviceEvent; 47 import org.onosproject.net.device.DeviceEvent;
47 import org.onosproject.net.device.DeviceListener; 48 import org.onosproject.net.device.DeviceListener;
48 import org.onosproject.net.device.DeviceProvider; 49 import org.onosproject.net.device.DeviceProvider;
...@@ -331,10 +332,17 @@ public class NetconfDeviceProvider extends AbstractProvider ...@@ -331,10 +332,17 @@ public class NetconfDeviceProvider extends AbstractProvider
331 332
332 private void discoverPorts(DeviceId deviceId) { 333 private void discoverPorts(DeviceId deviceId) {
333 Device device = deviceService.getDevice(deviceId); 334 Device device = deviceService.getDevice(deviceId);
335 + //TODO remove when PortDiscovery is removed from master
334 if (device.is(PortDiscovery.class)) { 336 if (device.is(PortDiscovery.class)) {
335 PortDiscovery portConfig = device.as(PortDiscovery.class); 337 PortDiscovery portConfig = device.as(PortDiscovery.class);
336 providerService.updatePorts(deviceId, 338 providerService.updatePorts(deviceId,
337 portConfig.getPorts()); 339 portConfig.getPorts());
340 + } else if (device.is(DeviceDescriptionDiscovery.class)) {
341 + DeviceDescriptionDiscovery deviceDescriptionDiscovery =
342 + device.as(DeviceDescriptionDiscovery.class);
343 + providerService.updatePorts(deviceId,
344 + deviceDescriptionDiscovery.discoverPortDetails());
345 +
338 } else { 346 } else {
339 log.warn("No portGetter behaviour for device {}", deviceId); 347 log.warn("No portGetter behaviour for device {}", deviceId);
340 } 348 }
...@@ -343,7 +351,7 @@ public class NetconfDeviceProvider extends AbstractProvider ...@@ -343,7 +351,7 @@ public class NetconfDeviceProvider extends AbstractProvider
343 /** 351 /**
344 * Return the DeviceId about the device containing the URI. 352 * Return the DeviceId about the device containing the URI.
345 * 353 *
346 - * @param ip IP address 354 + * @param ip IP address
347 * @param port port number 355 * @param port port number
348 * @return DeviceId 356 * @return DeviceId
349 */ 357 */
......
...@@ -40,11 +40,11 @@ import org.onosproject.net.config.NetworkConfigListener; ...@@ -40,11 +40,11 @@ import org.onosproject.net.config.NetworkConfigListener;
40 import org.onosproject.net.config.NetworkConfigRegistry; 40 import org.onosproject.net.config.NetworkConfigRegistry;
41 import org.onosproject.net.device.DefaultDeviceDescription; 41 import org.onosproject.net.device.DefaultDeviceDescription;
42 import org.onosproject.net.device.DeviceDescription; 42 import org.onosproject.net.device.DeviceDescription;
43 +import org.onosproject.net.device.DeviceDescriptionDiscovery;
43 import org.onosproject.net.device.DeviceProvider; 44 import org.onosproject.net.device.DeviceProvider;
44 import org.onosproject.net.device.DeviceProviderRegistry; 45 import org.onosproject.net.device.DeviceProviderRegistry;
45 import org.onosproject.net.device.DeviceProviderService; 46 import org.onosproject.net.device.DeviceProviderService;
46 -import org.onosproject.net.driver.DriverHandler; 47 +import org.onosproject.net.device.DeviceService;
47 -import org.onosproject.net.driver.DriverService;
48 import org.onosproject.net.provider.AbstractProvider; 48 import org.onosproject.net.provider.AbstractProvider;
49 import org.onosproject.net.provider.ProviderId; 49 import org.onosproject.net.provider.ProviderId;
50 import org.onosproject.protocol.rest.RestSBController; 50 import org.onosproject.protocol.rest.RestSBController;
...@@ -93,7 +93,7 @@ public class RestDeviceProvider extends AbstractProvider ...@@ -93,7 +93,7 @@ public class RestDeviceProvider extends AbstractProvider
93 protected CoreService coreService; 93 protected CoreService coreService;
94 94
95 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 95 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
96 - protected DriverService driverService; 96 + protected DeviceService deviceService;
97 97
98 98
99 private DeviceProviderService providerService; 99 private DeviceProviderService providerService;
...@@ -219,19 +219,27 @@ public class RestDeviceProvider extends AbstractProvider ...@@ -219,19 +219,27 @@ public class RestDeviceProvider extends AbstractProvider
219 log.error("Configuration error {}", e); 219 log.error("Configuration error {}", e);
220 } 220 }
221 log.debug("REST Devices {}", controller.getDevices()); 221 log.debug("REST Devices {}", controller.getDevices());
222 - addedDevices.forEach(deviceId -> { 222 + addedDevices.forEach(this::discoverPorts);
223 - DriverHandler h = driverService.createHandler(deviceId);
224 - PortDiscovery portConfig = h.behaviour(PortDiscovery.class);
225 - if (portConfig != null) {
226 - providerService.updatePorts(deviceId, portConfig.getPorts());
227 - } else {
228 - log.warn("No portGetter behaviour for device {}", deviceId);
229 - }
230 - });
231 addedDevices.clear(); 223 addedDevices.clear();
232 224
233 } 225 }
234 226
227 + private void discoverPorts(DeviceId deviceId) {
228 + Device device = deviceService.getDevice(deviceId);
229 + //TODO remove when PortDiscovery is removed from master
230 + if (device.is(PortDiscovery.class)) {
231 + PortDiscovery portConfig = device.as(PortDiscovery.class);
232 + providerService.updatePorts(deviceId,
233 + portConfig.getPorts());
234 + } else if (device.is(DeviceDescriptionDiscovery.class)) {
235 + DeviceDescriptionDiscovery deviceDescriptionDiscovery =
236 + device.as(DeviceDescriptionDiscovery.class);
237 + providerService.updatePorts(deviceId, deviceDescriptionDiscovery.discoverPortDetails());
238 + } else {
239 + log.warn("No portGetter behaviour for device {}", deviceId);
240 + }
241 + }
242 +
235 private boolean testDeviceConnection(RestSBDevice device) { 243 private boolean testDeviceConnection(RestSBDevice device) {
236 try { 244 try {
237 return controller.get(device.deviceId(), "", "json") != null; 245 return controller.get(device.deviceId(), "", "json") != null;
......
...@@ -287,9 +287,13 @@ public class SnmpDeviceProvider extends AbstractProvider ...@@ -287,9 +287,13 @@ public class SnmpDeviceProvider extends AbstractProvider
287 if (d.is(DeviceDescriptionDiscovery.class)) { 287 if (d.is(DeviceDescriptionDiscovery.class)) {
288 DeviceDescriptionDiscovery descriptionDiscovery = d.as(DeviceDescriptionDiscovery.class); 288 DeviceDescriptionDiscovery descriptionDiscovery = d.as(DeviceDescriptionDiscovery.class);
289 DeviceDescription description = descriptionDiscovery.discoverDeviceDetails(); 289 DeviceDescription description = descriptionDiscovery.discoverDeviceDetails();
290 - deviceStore.createOrUpdateDevice( 290 + if (description != null) {
291 - new ProviderId("snmp", "org.onosproject.provider.device"), 291 + deviceStore.createOrUpdateDevice(
292 - did, description); 292 + new ProviderId("snmp", "org.onosproject.provider.device"),
293 + did, description);
294 + } else {
295 + log.info("No other description given for device {}", d.id());
296 + }
293 providerService.updatePorts(did, descriptionDiscovery.discoverPortDetails()); 297 providerService.updatePorts(did, descriptionDiscovery.discoverPortDetails());
294 } else { 298 } else {
295 log.warn("No populate description and ports behaviour for device {}", did); 299 log.warn("No populate description and ports behaviour for device {}", did);
......