Search in sources :

Example 1 with BasicDeviceConfig

use of org.onosproject.net.config.basics.BasicDeviceConfig in project onos by opennetworkinglab.

the class DeviceInjectionConfigMonitor method injectDevice.

private void injectDevice(DeviceId did) {
    Optional<BasicDeviceConfig> basic = Optional.ofNullable(netcfgService.getConfig(did, BasicDeviceConfig.class));
    Optional<DeviceDescriptionDiscovery> discovery = basic.map(BasicDeviceConfig::driver).map(driverService::getDriver).filter(drvr -> drvr.hasBehaviour(DeviceDescriptionDiscovery.class)).map(drvr -> drvr.createBehaviour(new DefaultDriverHandler(new DefaultDriverData(drvr, did)), DeviceDescriptionDiscovery.class));
    if (discovery.isPresent()) {
        providerService.deviceConnected(did, discovery.get().discoverDeviceDetails());
        providerService.updatePorts(did, discovery.get().discoverPortDetails());
    } else {
        String unk = "UNKNOWN";
        DefaultDeviceDescription desc = new DefaultDeviceDescription(did.uri(), basic.map(BasicDeviceConfig::type).orElse(Type.SWITCH), basic.map(BasicDeviceConfig::manufacturer).orElse(unk), basic.map(BasicDeviceConfig::hwVersion).orElse(unk), basic.map(BasicDeviceConfig::swVersion).orElse(unk), basic.map(BasicDeviceConfig::serial).orElse(unk), new ChassisId(), true);
        providerService.deviceConnected(did, desc);
        Optional<DeviceInjectionConfig> inject = Optional.ofNullable(netcfgService.getConfig(did, DeviceInjectionConfig.class));
        String ports = inject.map(DeviceInjectionConfig::ports).orElse("0");
        int numPorts = Integer.parseInt(ports);
        List<PortDescription> portDescs = new ArrayList<>(numPorts);
        for (int i = 1; i <= numPorts; ++i) {
            // TODO inject port details if something like BasicPortConfig was created
            PortNumber number = portNumber(i);
            boolean isEnabled = true;
            portDescs.add(DefaultPortDescription.builder().withPortNumber(number).isEnabled(isEnabled).build());
        }
        providerService.updatePorts(did, portDescs);
    }
}
Also used : NetworkConfigService(org.onosproject.net.config.NetworkConfigService) NetworkConfigRegistry(org.onosproject.net.config.NetworkConfigRegistry) BasicDeviceConfig(org.onosproject.net.config.basics.BasicDeviceConfig) PortNumber.portNumber(org.onosproject.net.PortNumber.portNumber) PortNumber(org.onosproject.net.PortNumber) NetworkConfigEvent(org.onosproject.net.config.NetworkConfigEvent) DeviceService(org.onosproject.net.device.DeviceService) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) DeviceProviderRegistry(org.onosproject.net.device.DeviceProviderRegistry) DefaultDriverData(org.onosproject.net.driver.DefaultDriverData) DriverService(org.onosproject.net.driver.DriverService) ArrayList(java.util.ArrayList) Component(org.osgi.service.component.annotations.Component) ImmutableList(com.google.common.collect.ImmutableList) DEVICE_SUBJECT_FACTORY(org.onosproject.net.config.basics.SubjectFactories.DEVICE_SUBJECT_FACTORY) DefaultDriverHandler(org.onosproject.net.driver.DefaultDriverHandler) DeviceProvider(org.onosproject.net.device.DeviceProvider) PortDescription(org.onosproject.net.device.PortDescription) DeviceProviderService(org.onosproject.net.device.DeviceProviderService) Activate(org.osgi.service.component.annotations.Activate) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) EnumSet(java.util.EnumSet) ExecutorService(java.util.concurrent.ExecutorService) Type(org.onosproject.net.Device.Type) ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) MastershipRole(org.onosproject.net.MastershipRole) Deactivate(org.osgi.service.component.annotations.Deactivate) DeviceDescriptionDiscovery(org.onosproject.net.device.DeviceDescriptionDiscovery) Set(java.util.Set) ProviderId(org.onosproject.net.provider.ProviderId) Executors.newSingleThreadExecutor(java.util.concurrent.Executors.newSingleThreadExecutor) Beta(com.google.common.annotations.Beta) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) TimeUnit(java.util.concurrent.TimeUnit) ConfigFactory(org.onosproject.net.config.ConfigFactory) DeviceInjectionConfig(org.onosproject.net.config.inject.DeviceInjectionConfig) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription) List(java.util.List) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Optional(java.util.Optional) DeviceId(org.onosproject.net.DeviceId) Reference(org.osgi.service.component.annotations.Reference) NetworkConfigListener(org.onosproject.net.config.NetworkConfigListener) ChassisId(org.onlab.packet.ChassisId) ChassisId(org.onlab.packet.ChassisId) DefaultDriverHandler(org.onosproject.net.driver.DefaultDriverHandler) ArrayList(java.util.ArrayList) DeviceInjectionConfig(org.onosproject.net.config.inject.DeviceInjectionConfig) PortDescription(org.onosproject.net.device.PortDescription) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription) BasicDeviceConfig(org.onosproject.net.config.basics.BasicDeviceConfig) DeviceDescriptionDiscovery(org.onosproject.net.device.DeviceDescriptionDiscovery) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) PortNumber(org.onosproject.net.PortNumber) DefaultDriverData(org.onosproject.net.driver.DefaultDriverData)

Example 2 with BasicDeviceConfig

use of org.onosproject.net.config.basics.BasicDeviceConfig in project onos by opennetworkinglab.

the class DriverManager method getDriver.

@Override
public Driver getDriver(DeviceId deviceId) {
    checkPermission(DRIVER_READ);
    Driver driver;
    // Special processing for devices with pipeconf.
    if (pipeconfService.ofDevice(deviceId).isPresent()) {
        // Throws exception if pipeconf driver does not exist.
        return nullIsNotFound(getPipeconfMergedDriver(deviceId), "Device is pipeconf-capable but a " + "pipeconf-merged driver was not found");
    }
    // Primary source of driver configuration is the network config.
    BasicDeviceConfig cfg = networkConfigService.getConfig(deviceId, BasicDeviceConfig.class);
    driver = lookupDriver(cfg != null ? cfg.driver() : null);
    if (driver != null) {
        return driver;
    }
    // Secondary source of the driver selection is driver annotation.
    Device device = nullIsNotFound(deviceService.getDevice(deviceId), NO_DEVICE);
    driver = lookupDriver(device.annotations().value(DRIVER));
    if (driver != null) {
        return driver;
    }
    // obtained from the device.
    return nullIsNotFound(getDriver(device.manufacturer(), device.hwVersion(), device.swVersion()), NO_DRIVER);
}
Also used : Device(org.onosproject.net.Device) Driver(org.onosproject.net.driver.Driver) BasicDeviceConfig(org.onosproject.net.config.basics.BasicDeviceConfig)

Example 3 with BasicDeviceConfig

use of org.onosproject.net.config.basics.BasicDeviceConfig in project onos by opennetworkinglab.

the class PiPipeconfManager method getMergedDriver.

@Override
public String getMergedDriver(DeviceId deviceId, PiPipeconfId pipeconfId) {
    log.debug("Starting device driver merge of {} with {}...", deviceId, pipeconfId);
    final BasicDeviceConfig basicDeviceConfig = cfgService.getConfig(deviceId, BasicDeviceConfig.class);
    if (basicDeviceConfig == null) {
        log.warn("Unable to get basic device config for {}, " + "aborting pipeconf driver merge", deviceId);
        return null;
    }
    String baseDriverName = basicDeviceConfig.driver();
    if (baseDriverName == null) {
        log.warn("Missing driver from basic device config for {}, " + "cannot produce merged driver", deviceId);
        return null;
    }
    if (isMergedDriverName(baseDriverName)) {
        // The config already has driver name that is a merged one. We still
        // need to make sure an instance of that merged driver is present in
        // this node.
        log.debug("Base driver of {} ({}) is a merged one", deviceId, baseDriverName);
        baseDriverName = getBaseDriverNameFromMerged(baseDriverName);
    }
    return doMergeDriver(baseDriverName, pipeconfId);
}
Also used : HexString(org.onlab.util.HexString) BasicDeviceConfig(org.onosproject.net.config.basics.BasicDeviceConfig)

Example 4 with BasicDeviceConfig

use of org.onosproject.net.config.basics.BasicDeviceConfig in project onos by opennetworkinglab.

the class ConfigOpticalDeviceDiscovery method discoverDeviceDetails.

@Override
public DeviceDescription discoverDeviceDetails() {
    NetworkConfigService netcfg = handler().get(NetworkConfigService.class);
    DeviceId did = data().deviceId();
    String unk = "UNKNOWN";
    Optional<DeviceInjectionConfig> inject = Optional.ofNullable(netcfg.getConfig(did, DeviceInjectionConfig.class));
    Optional<BasicDeviceConfig> basic = Optional.ofNullable(netcfg.getConfig(did, BasicDeviceConfig.class));
    Device.Type type = basic.map(BasicDeviceConfig::type).orElse(Device.Type.SWITCH);
    String manufacturer = basic.map(BasicDeviceConfig::manufacturer).orElse(unk);
    String hwVersion = basic.map(BasicDeviceConfig::hwVersion).orElse(unk);
    String swVersion = basic.map(BasicDeviceConfig::swVersion).orElse(unk);
    String serialNumber = basic.map(BasicDeviceConfig::serial).orElse(unk);
    ChassisId chassis = new ChassisId();
    // if inject is not specified, return default unavailable device
    boolean defaultAvailable = inject.isPresent();
    return new DefaultDeviceDescription(did.uri(), type, manufacturer, hwVersion, swVersion, serialNumber, chassis, defaultAvailable);
}
Also used : ChassisId(org.onlab.packet.ChassisId) NetworkConfigService(org.onosproject.net.config.NetworkConfigService) DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) DeviceInjectionConfig(org.onosproject.net.config.inject.DeviceInjectionConfig) BasicDeviceConfig(org.onosproject.net.config.basics.BasicDeviceConfig)

Example 5 with BasicDeviceConfig

use of org.onosproject.net.config.basics.BasicDeviceConfig in project onos by opennetworkinglab.

the class AbstractGrpcHandlerBehaviour method mgmtUriFromNetcfg.

protected URI mgmtUriFromNetcfg() {
    deviceId = handler().data().deviceId();
    final BasicDeviceConfig cfg = handler().get(NetworkConfigService.class).getConfig(deviceId, BasicDeviceConfig.class);
    if (cfg == null || Strings.isNullOrEmpty(cfg.managementAddress())) {
        log.error("Missing or invalid config for {}, cannot derive " + "gRPC server endpoints", deviceId);
        return null;
    }
    try {
        return new URI(cfg.managementAddress());
    } catch (URISyntaxException e) {
        log.error("Management address of {} is not a valid URI: {}", deviceId, cfg.managementAddress());
        return null;
    }
}
Also used : NetworkConfigService(org.onosproject.net.config.NetworkConfigService) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) BasicDeviceConfig(org.onosproject.net.config.basics.BasicDeviceConfig)

Aggregations

BasicDeviceConfig (org.onosproject.net.config.basics.BasicDeviceConfig)8 NetworkConfigService (org.onosproject.net.config.NetworkConfigService)5 Device (org.onosproject.net.Device)3 DeviceId (org.onosproject.net.DeviceId)3 ChassisId (org.onlab.packet.ChassisId)2 HexString (org.onlab.util.HexString)2 DeviceInjectionConfig (org.onosproject.net.config.inject.DeviceInjectionConfig)2 DefaultDeviceDescription (org.onosproject.net.device.DefaultDeviceDescription)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Beta (com.google.common.annotations.Beta)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 EnumSet (java.util.EnumSet)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 ExecutorService (java.util.concurrent.ExecutorService)1