Deprecating PortDiscovery in favour of DeviceDescritpionDiscovery

Change-Id: Ie9cff7937412c62c8a5a3b75b87a43952017f146
This commit is contained in:
Andrea Campanella 2016-04-22 11:56:31 -07:00 committed by Gerrit Code Review
parent 569bbec710
commit 6c71a0500a
11 changed files with 100 additions and 37 deletions

View File

@ -26,12 +26,18 @@ import java.util.List;
/** /**
* Discovers the set of ports from a device through a device specific protocol. * Discovers the set of ports from a device through a device specific protocol.
* The returned ports are not retrieved from the information stored in ONOS. * The returned ports are not retrieved from the information stored in ONOS.
*
* @deprecated 1.6.0 Goldeneye. Use DeviceDescriptionDiscovery instead
*/ */
@Deprecated
public interface PortDiscovery extends HandlerBehaviour { public interface PortDiscovery extends HandlerBehaviour {
/** /**
* Retrieves the set of ports from a device. * Retrieves the set of ports from a device.
*
* @return a set of port descriptions. * @return a set of port descriptions.
* @deprecated 1.6.0 Goldeneye. Use DeviceDescriptionDiscovery instead
*/ */
@Deprecated
List<PortDescription> getPorts(); List<PortDescription> getPorts();
} }

View File

@ -28,7 +28,7 @@ import java.util.List;
public interface DeviceDescriptionDiscovery extends HandlerBehaviour { public interface DeviceDescriptionDiscovery extends HandlerBehaviour {
/** /**
* Returns device description appropriately annotated to support * Returns a device description appropriately annotated to support
* downstream model extension via projections of the resulting device, * downstream model extension via projections of the resulting device,
* as in the following example. * as in the following example.
* <pre> * <pre>
@ -40,7 +40,7 @@ public interface DeviceDescriptionDiscovery extends HandlerBehaviour {
DeviceDescription discoverDeviceDetails(); DeviceDescription discoverDeviceDetails();
/** /**
* Returns list of port descriptions appropriately annotated to support * Returns a list of port descriptions appropriately annotated to support
* downstream model extension via projections of their parent device, * downstream model extension via projections of their parent device,
* as in the following example. * as in the following example.
* <pre> * <pre>

View File

@ -22,6 +22,7 @@ import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference; import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality; import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onosproject.net.DeviceId; import org.onosproject.net.DeviceId;
import org.onosproject.net.device.DeviceDescription;
import org.onosproject.net.device.DeviceDescriptionDiscovery; import org.onosproject.net.device.DeviceDescriptionDiscovery;
import org.onosproject.net.device.DeviceProvider; import org.onosproject.net.device.DeviceProvider;
import org.onosproject.net.device.DeviceProviderRegistry; import org.onosproject.net.device.DeviceProviderRegistry;
@ -93,10 +94,15 @@ public abstract class AbstractDeviceProvider extends AbstractProvider
protected void discoverDevice(DriverHandler handler) { protected void discoverDevice(DriverHandler handler) {
DeviceId deviceId = handler.data().deviceId(); DeviceId deviceId = handler.data().deviceId();
DeviceDescriptionDiscovery discovery = handler.behaviour(DeviceDescriptionDiscovery.class); DeviceDescriptionDiscovery discovery = handler.behaviour(DeviceDescriptionDiscovery.class);
providerService.deviceConnected(deviceId, discovery.discoverDeviceDetails()); DeviceDescription description = discovery.discoverDeviceDetails();
if (description != null) {
providerService.deviceConnected(deviceId, description);
} else {
log.info("No other description given for device {}", deviceId);
}
providerService.updatePorts(deviceId, discovery.discoverPortDetails()); providerService.updatePorts(deviceId, discovery.discoverPortDetails());
}
}
// TODO: inspect NETCONF, SNMP, RESTSB device providers for additional common patterns // TODO: inspect NETCONF, SNMP, RESTSB device providers for additional common patterns
// TODO: provide base for port status update // TODO: provide base for port status update
// TODO: integrate with network config for learning about management addresses to probe // TODO: integrate with network config for learning about management addresses to probe

View File

@ -18,6 +18,7 @@
package org.onosproject.drivers.ciena; package org.onosproject.drivers.ciena;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import org.apache.commons.configuration.HierarchicalConfiguration; import org.apache.commons.configuration.HierarchicalConfiguration;
import org.onosproject.drivers.utilities.XmlConfigParser; import org.onosproject.drivers.utilities.XmlConfigParser;
@ -31,11 +32,13 @@ import org.onosproject.net.OchSignal;
import org.onosproject.net.OduSignalType; import org.onosproject.net.OduSignalType;
import org.onosproject.net.PortNumber; import org.onosproject.net.PortNumber;
import org.onosproject.net.SparseAnnotations; import org.onosproject.net.SparseAnnotations;
import org.onosproject.net.behaviour.PortDiscovery; import org.onosproject.net.device.DeviceDescription;
import org.onosproject.net.device.DeviceDescriptionDiscovery;
import org.onosproject.net.device.PortDescription; import org.onosproject.net.device.PortDescription;
import org.onosproject.net.driver.AbstractHandlerBehaviour; import org.onosproject.net.driver.AbstractHandlerBehaviour;
import org.onosproject.net.driver.DriverHandler; import org.onosproject.net.driver.DriverHandler;
import org.onosproject.protocol.rest.RestSBController; import org.onosproject.protocol.rest.RestSBController;
import org.slf4j.Logger;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -43,12 +46,15 @@ import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static org.onosproject.net.optical.device.OchPortHelper.ochPortDescription; import static org.onosproject.net.optical.device.OchPortHelper.ochPortDescription;
import static org.onosproject.net.optical.device.OduCltPortHelper.oduCltPortDescription; import static org.onosproject.net.optical.device.OduCltPortHelper.oduCltPortDescription;
import static org.slf4j.LoggerFactory.getLogger;
/** /**
* Discovers the ports from a Ciena WaveServer Rest device. * Discovers the ports from a Ciena WaveServer Rest device.
*/ */
public class PortDiscoveryCienaWaveserverImpl extends AbstractHandlerBehaviour public class CienaWaveserverDeviceDescription extends AbstractHandlerBehaviour
implements PortDiscovery { implements DeviceDescriptionDiscovery {
private final Logger log = getLogger(getClass());
private static final String SPEED = "speed"; private static final String SPEED = "speed";
private static final String GBPS = "Gbps"; private static final String GBPS = "Gbps";
@ -74,9 +80,19 @@ public class PortDiscoveryCienaWaveserverImpl extends AbstractHandlerBehaviour
// private static final String SPECIFIC_PORT_CONFIG = // private static final String SPECIFIC_PORT_CONFIG =
// "/ptp-config?config=true&format=xml&depth=unbounded"; // "/ptp-config?config=true&format=xml&depth=unbounded";
@Override
public DeviceDescription discoverDeviceDetails() {
log.info("No description to be added for device");
//TODO to be implemented if needed.
return null;
}
@Override @Override
public List<PortDescription> getPorts() { public List<PortDescription> discoverPortDetails() {
return getPorts();
}
private List<PortDescription> getPorts() {
List<PortDescription> ports = Lists.newArrayList(); List<PortDescription> ports = Lists.newArrayList();
DriverHandler handler = handler(); DriverHandler handler = handler();
RestSBController controller = checkNotNull(handler.get(RestSBController.class)); RestSBController controller = checkNotNull(handler.get(RestSBController.class));
@ -121,11 +137,11 @@ public class PortDiscoveryCienaWaveserverImpl extends AbstractHandlerBehaviour
.replace(" ", EMPTY_STRING))) == speed100GbpsinMbps ? .replace(" ", EMPTY_STRING))) == speed100GbpsinMbps ?
CltSignalType.CLT_100GBE : null; CltSignalType.CLT_100GBE : null;
ports.add(oduCltPortDescription(PortNumber.portNumber(sub.getLong(PORT_ID)), ports.add(oduCltPortDescription(PortNumber.portNumber(sub.getLong(PORT_ID)),
sub.getString(ADMIN_STATE).equals(ENABLED), sub.getString(ADMIN_STATE).equals(ENABLED),
cltType, annotations.build())); cltType, annotations.build()));
} }
}); });
return ports; return ImmutableList.copyOf(ports);
} }
public static List<HierarchicalConfiguration> parseWaveServerCienaPorts(HierarchicalConfiguration cfg) { public static List<HierarchicalConfiguration> parseWaveServerCienaPorts(HierarchicalConfiguration cfg) {
@ -156,7 +172,7 @@ public class PortDiscoveryCienaWaveserverImpl extends AbstractHandlerBehaviour
baseFrequency)) / toGbpsFromHz(chSpacing.frequency().asHz())); //FIXME is there a better way ? baseFrequency)) / toGbpsFromHz(chSpacing.frequency().asHz())); //FIXME is there a better way ?
return ochPortDescription(PortNumber.portNumber(portNumber), isEnabled, oduSignalType, isTunable, return ochPortDescription(PortNumber.portNumber(portNumber), isEnabled, oduSignalType, isTunable,
new OchSignal(gridType, chSpacing, spacingMult, 1), annotations); new OchSignal(gridType, chSpacing, spacingMult, 1), annotations);
} }
//FIXME remove when all optical types have two way information methods, see jira tickets //FIXME remove when all optical types have two way information methods, see jira tickets

View File

@ -20,6 +20,8 @@
impl="org.onosproject.drivers.ciena.PortDiscoveryCienaWaveserverImpl"/> impl="org.onosproject.drivers.ciena.PortDiscoveryCienaWaveserverImpl"/>
<behaviour api="org.onosproject.net.optical.OpticalDevice" <behaviour api="org.onosproject.net.optical.OpticalDevice"
impl="org.onosproject.net.optical.DefaultOpticalDevice"/> impl="org.onosproject.net.optical.DefaultOpticalDevice"/>
<behaviour api="org.onosproject.net.device.DeviceDescriptionDiscovery"
impl="org.onosproject.drivers.ciena.CienaWaveserverDeviceDescription"/>
</driver> </driver>
</drivers> </drivers>

View File

@ -16,6 +16,8 @@
package org.onosproject.drivers.fujitsu; package org.onosproject.drivers.fujitsu;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import org.apache.commons.configuration.HierarchicalConfiguration; import org.apache.commons.configuration.HierarchicalConfiguration;
import org.onosproject.drivers.utilities.XmlConfigParser; import org.onosproject.drivers.utilities.XmlConfigParser;
import org.onosproject.net.AnnotationKeys; import org.onosproject.net.AnnotationKeys;
@ -26,7 +28,8 @@ import org.onosproject.net.GridType;
import org.onosproject.net.OchSignal; import org.onosproject.net.OchSignal;
import org.onosproject.net.OduSignalType; import org.onosproject.net.OduSignalType;
import org.onosproject.net.PortNumber; import org.onosproject.net.PortNumber;
import org.onosproject.net.behaviour.PortDiscovery; import org.onosproject.net.device.DeviceDescription;
import org.onosproject.net.device.DeviceDescriptionDiscovery;
import org.onosproject.net.device.PortDescription; import org.onosproject.net.device.PortDescription;
import org.onosproject.net.driver.AbstractHandlerBehaviour; import org.onosproject.net.driver.AbstractHandlerBehaviour;
import org.onosproject.netconf.NetconfController; import org.onosproject.netconf.NetconfController;
@ -34,8 +37,6 @@ import org.onosproject.netconf.NetconfException;
import org.onosproject.netconf.NetconfSession; import org.onosproject.netconf.NetconfSession;
import org.slf4j.Logger; import org.slf4j.Logger;
import com.google.common.collect.Lists;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
@ -49,13 +50,20 @@ import static org.slf4j.LoggerFactory.getLogger;
/** /**
* Retrieves the ports from a Fujitsu T100 device via netconf. * Retrieves the ports from a Fujitsu T100 device via netconf.
*/ */
public class PortGetterFujitsuImpl extends AbstractHandlerBehaviour public class FujitsuT100DeviceDescription extends AbstractHandlerBehaviour
implements PortDiscovery { implements DeviceDescriptionDiscovery {
private final Logger log = getLogger(getClass()); private final Logger log = getLogger(getClass());
@Override @Override
public List<PortDescription> getPorts() { public DeviceDescription discoverDeviceDetails() {
log.info("No description to be added for device");
//TODO to be implemented if needed.
return null;
}
@Override
public List<PortDescription> discoverPortDetails() {
NetconfController controller = checkNotNull(handler().get(NetconfController.class)); NetconfController controller = checkNotNull(handler().get(NetconfController.class));
NetconfSession session = controller.getDevicesMap().get(handler().data().deviceId()).getSession(); NetconfSession session = controller.getDevicesMap().get(handler().data().deviceId()).getSession();
String reply; String reply;
@ -67,12 +75,13 @@ public class PortGetterFujitsuImpl extends AbstractHandlerBehaviour
List<PortDescription> descriptions = List<PortDescription> descriptions =
parseFujitsuT100Ports(XmlConfigParser. parseFujitsuT100Ports(XmlConfigParser.
loadXml(new ByteArrayInputStream(reply.getBytes()))); loadXml(new ByteArrayInputStream(reply.getBytes())));
return descriptions; return ImmutableList.copyOf(descriptions);
} }
/** /**
* Builds a request crafted to get the configuration required to create port * Builds a request crafted to get the configuration required to create port
* descriptions for the device. * descriptions for the device.
*
* @return The request string. * @return The request string.
*/ */
private String requestBuilder() { private String requestBuilder() {
@ -91,6 +100,7 @@ public class PortGetterFujitsuImpl extends AbstractHandlerBehaviour
/** /**
* Parses a configuration and returns a set of ports for the fujitsu T100. * Parses a configuration and returns a set of ports for the fujitsu T100.
*
* @param cfg a hierarchical configuration * @param cfg a hierarchical configuration
* @return a list of port descriptions * @return a list of port descriptions
*/ */

View File

@ -20,6 +20,8 @@
impl="org.onosproject.drivers.fujitsu.PortGetterFujitsuImpl"/> impl="org.onosproject.drivers.fujitsu.PortGetterFujitsuImpl"/>
<behaviour api="org.onosproject.net.optical.OpticalDevice" <behaviour api="org.onosproject.net.optical.OpticalDevice"
impl="org.onosproject.net.optical.DefaultOpticalDevice"/> impl="org.onosproject.net.optical.DefaultOpticalDevice"/>
<behaviour api="org.onosproject.net.device.DeviceDescriptionDiscovery"
impl="org.onosproject.drivers.fujitsu.FujitsuT100DeviceDescription"/>
</driver> </driver>
</drivers> </drivers>

View File

@ -16,6 +16,7 @@
package org.onosproject.drivers.lumentum; package org.onosproject.drivers.lumentum;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import org.onosproject.net.AnnotationKeys; import org.onosproject.net.AnnotationKeys;
import org.onosproject.net.DefaultAnnotations; import org.onosproject.net.DefaultAnnotations;
@ -45,7 +46,7 @@ import static org.slf4j.LoggerFactory.getLogger;
/** /**
* Device description behaviour for Lumentum Snmp devices. * Device description behaviour for Lumentum Snmp devices.
*/ */
public class LumentumRoadmDeviceDescription extends AbstractHandlerBehaviour implements DeviceDescriptionDiscovery { public class LumentumRoadmDeviceDescription extends AbstractHandlerBehaviour implements DeviceDescriptionDiscovery {
private final Logger log = getLogger(getClass()); private final Logger log = getLogger(getClass());
@ -66,7 +67,7 @@ public class LumentumRoadmDeviceDescription extends AbstractHandlerBehaviour imp
@Override @Override
public List<PortDescription> discoverPortDetails() { public List<PortDescription> discoverPortDetails() {
return this.getPorts(); return ImmutableList.copyOf(this.getPorts());
} }
private List<PortDescription> getPorts() { private List<PortDescription> getPorts() {

View File

@ -43,6 +43,7 @@ import org.onosproject.net.config.NetworkConfigListener;
import org.onosproject.net.config.NetworkConfigRegistry; import org.onosproject.net.config.NetworkConfigRegistry;
import org.onosproject.net.device.DefaultDeviceDescription; import org.onosproject.net.device.DefaultDeviceDescription;
import org.onosproject.net.device.DeviceDescription; import org.onosproject.net.device.DeviceDescription;
import org.onosproject.net.device.DeviceDescriptionDiscovery;
import org.onosproject.net.device.DeviceEvent; import org.onosproject.net.device.DeviceEvent;
import org.onosproject.net.device.DeviceListener; import org.onosproject.net.device.DeviceListener;
import org.onosproject.net.device.DeviceProvider; import org.onosproject.net.device.DeviceProvider;
@ -331,10 +332,17 @@ public class NetconfDeviceProvider extends AbstractProvider
private void discoverPorts(DeviceId deviceId) { private void discoverPorts(DeviceId deviceId) {
Device device = deviceService.getDevice(deviceId); Device device = deviceService.getDevice(deviceId);
//TODO remove when PortDiscovery is removed from master
if (device.is(PortDiscovery.class)) { if (device.is(PortDiscovery.class)) {
PortDiscovery portConfig = device.as(PortDiscovery.class); PortDiscovery portConfig = device.as(PortDiscovery.class);
providerService.updatePorts(deviceId, providerService.updatePorts(deviceId,
portConfig.getPorts()); portConfig.getPorts());
} else if (device.is(DeviceDescriptionDiscovery.class)) {
DeviceDescriptionDiscovery deviceDescriptionDiscovery =
device.as(DeviceDescriptionDiscovery.class);
providerService.updatePorts(deviceId,
deviceDescriptionDiscovery.discoverPortDetails());
} else { } else {
log.warn("No portGetter behaviour for device {}", deviceId); log.warn("No portGetter behaviour for device {}", deviceId);
} }
@ -343,7 +351,7 @@ public class NetconfDeviceProvider extends AbstractProvider
/** /**
* Return the DeviceId about the device containing the URI. * Return the DeviceId about the device containing the URI.
* *
* @param ip IP address * @param ip IP address
* @param port port number * @param port port number
* @return DeviceId * @return DeviceId
*/ */

View File

@ -40,11 +40,11 @@ import org.onosproject.net.config.NetworkConfigListener;
import org.onosproject.net.config.NetworkConfigRegistry; import org.onosproject.net.config.NetworkConfigRegistry;
import org.onosproject.net.device.DefaultDeviceDescription; import org.onosproject.net.device.DefaultDeviceDescription;
import org.onosproject.net.device.DeviceDescription; import org.onosproject.net.device.DeviceDescription;
import org.onosproject.net.device.DeviceDescriptionDiscovery;
import org.onosproject.net.device.DeviceProvider; import org.onosproject.net.device.DeviceProvider;
import org.onosproject.net.device.DeviceProviderRegistry; import org.onosproject.net.device.DeviceProviderRegistry;
import org.onosproject.net.device.DeviceProviderService; import org.onosproject.net.device.DeviceProviderService;
import org.onosproject.net.driver.DriverHandler; import org.onosproject.net.device.DeviceService;
import org.onosproject.net.driver.DriverService;
import org.onosproject.net.provider.AbstractProvider; import org.onosproject.net.provider.AbstractProvider;
import org.onosproject.net.provider.ProviderId; import org.onosproject.net.provider.ProviderId;
import org.onosproject.protocol.rest.RestSBController; import org.onosproject.protocol.rest.RestSBController;
@ -93,7 +93,7 @@ public class RestDeviceProvider extends AbstractProvider
protected CoreService coreService; protected CoreService coreService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected DriverService driverService; protected DeviceService deviceService;
private DeviceProviderService providerService; private DeviceProviderService providerService;
@ -219,19 +219,27 @@ public class RestDeviceProvider extends AbstractProvider
log.error("Configuration error {}", e); log.error("Configuration error {}", e);
} }
log.debug("REST Devices {}", controller.getDevices()); log.debug("REST Devices {}", controller.getDevices());
addedDevices.forEach(deviceId -> { addedDevices.forEach(this::discoverPorts);
DriverHandler h = driverService.createHandler(deviceId);
PortDiscovery portConfig = h.behaviour(PortDiscovery.class);
if (portConfig != null) {
providerService.updatePorts(deviceId, portConfig.getPorts());
} else {
log.warn("No portGetter behaviour for device {}", deviceId);
}
});
addedDevices.clear(); addedDevices.clear();
} }
private void discoverPorts(DeviceId deviceId) {
Device device = deviceService.getDevice(deviceId);
//TODO remove when PortDiscovery is removed from master
if (device.is(PortDiscovery.class)) {
PortDiscovery portConfig = device.as(PortDiscovery.class);
providerService.updatePorts(deviceId,
portConfig.getPorts());
} else if (device.is(DeviceDescriptionDiscovery.class)) {
DeviceDescriptionDiscovery deviceDescriptionDiscovery =
device.as(DeviceDescriptionDiscovery.class);
providerService.updatePorts(deviceId, deviceDescriptionDiscovery.discoverPortDetails());
} else {
log.warn("No portGetter behaviour for device {}", deviceId);
}
}
private boolean testDeviceConnection(RestSBDevice device) { private boolean testDeviceConnection(RestSBDevice device) {
try { try {
return controller.get(device.deviceId(), "", "json") != null; return controller.get(device.deviceId(), "", "json") != null;

View File

@ -287,9 +287,13 @@ public class SnmpDeviceProvider extends AbstractProvider
if (d.is(DeviceDescriptionDiscovery.class)) { if (d.is(DeviceDescriptionDiscovery.class)) {
DeviceDescriptionDiscovery descriptionDiscovery = d.as(DeviceDescriptionDiscovery.class); DeviceDescriptionDiscovery descriptionDiscovery = d.as(DeviceDescriptionDiscovery.class);
DeviceDescription description = descriptionDiscovery.discoverDeviceDetails(); DeviceDescription description = descriptionDiscovery.discoverDeviceDetails();
deviceStore.createOrUpdateDevice( if (description != null) {
new ProviderId("snmp", "org.onosproject.provider.device"), deviceStore.createOrUpdateDevice(
did, description); new ProviderId("snmp", "org.onosproject.provider.device"),
did, description);
} else {
log.info("No other description given for device {}", d.id());
}
providerService.updatePorts(did, descriptionDiscovery.discoverPortDetails()); providerService.updatePorts(did, descriptionDiscovery.discoverPortDetails());
} else { } else {
log.warn("No populate description and ports behaviour for device {}", did); log.warn("No populate description and ports behaviour for device {}", did);