Search in sources :

Example 1 with Type

use of org.onosproject.net.Device.Type 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 Type

use of org.onosproject.net.Device.Type in project onos by opennetworkinglab.

the class ECDeviceStore method composeDevice.

/**
 * Returns a Device, merging descriptions from multiple Providers.
 *
 * @param deviceId      device identifier
 * @return Device instance
 */
private Device composeDevice(DeviceId deviceId) {
    ProviderId primaryProviderId = getPrimaryProviderId(deviceId);
    DeviceDescription primaryDeviceDescription = deviceDescriptions.get(new DeviceKey(primaryProviderId, deviceId));
    Type type = primaryDeviceDescription.type();
    String manufacturer = primaryDeviceDescription.manufacturer();
    String hwVersion = primaryDeviceDescription.hwVersion();
    String swVersion = primaryDeviceDescription.swVersion();
    String serialNumber = primaryDeviceDescription.serialNumber();
    ChassisId chassisId = primaryDeviceDescription.chassisId();
    DefaultAnnotations annotations = mergeAnnotations(deviceId);
    return new DefaultDevice(primaryProviderId, deviceId, type, manufacturer, hwVersion, swVersion, serialNumber, chassisId, annotations);
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) DeviceDescription(org.onosproject.net.device.DeviceDescription) Type(org.onosproject.net.Device.Type) ChassisId(org.onlab.packet.ChassisId) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) DefaultDevice(org.onosproject.net.DefaultDevice)

Example 3 with Type

use of org.onosproject.net.Device.Type in project onos by opennetworkinglab.

the class OplinkPowerConfigUtil method getInputPortPowerRange.

/**
 * Returns the input port power range.
 *
 * @param portNum the port number
 * @return power range
 */
private Range<Long> getInputPortPowerRange(PortNumber portNum) {
    OpenFlowSwitch ofs = getOpenFlowDevice();
    if (ofs == null) {
        return null;
    }
    PortDescType portType = getPortDescType((OpenFlowOpticalSwitch) ofs, portNum);
    Type devType = ofs.deviceType();
    // The port type and power range will be obtained from physical device in the future.
    switch(devType) {
        case OPTICAL_AMPLIFIER:
            if (portType == PortDescType.PA_LINE_IN) {
                return Range.closed(EDFA_POWER_IN_WEST_LOW_THRES, EDFA_POWER_IN_WEST_HIGH_THRES);
            } else if (portType == PortDescType.BA_LINE_IN) {
                return Range.closed(EDFA_POWER_IN_EAST_LOW_THRES, EDFA_POWER_IN_EAST_HIGH_THRES);
            }
            break;
        case ROADM:
            if (portType == PortDescType.PA_LINE_IN) {
                return Range.closed(ROADM_POWER_LINE_IN_LOW_THRES, ROADM_POWER_LINE_IN_HIGH_THRES);
            } else if (portType == PortDescType.EXP_IN || portType == PortDescType.AUX_IN) {
                return Range.closed(ROADM_POWER_OTHER_IN_LOW_THRES, ROADM_POWER_OTHER_IN_HIGH_THRES);
            }
            break;
        case FIBER_SWITCH:
            return Range.closed(SWITCH_POWER_LOW_THRES, SWITCH_POWER_HIGH_THRES);
        default:
            log.warn("Unexpected device type: {}", devType);
            break;
    }
    // Unexpected port or device type. Do not need warning here for port polling.
    return null;
}
Also used : ExtensionTreatmentType(org.onosproject.net.flow.instructions.ExtensionTreatmentType) Type(org.onosproject.net.Device.Type) PortDescPropertyType(org.onosproject.openflow.controller.PortDescPropertyType) OpenFlowSwitch(org.onosproject.openflow.controller.OpenFlowSwitch)

Example 4 with Type

use of org.onosproject.net.Device.Type in project onos by opennetworkinglab.

the class OplinkPowerConfigUtil method getTargetPortPowerRange.

/**
 * Returns the target port power range.
 *
 * @param portNum the port number
 * @return power range
 */
private Range<Long> getTargetPortPowerRange(PortNumber portNum) {
    OpenFlowSwitch ofs = getOpenFlowDevice();
    if (ofs == null) {
        return null;
    }
    PortDescType portType = getPortDescType((OpenFlowOpticalSwitch) ofs, portNum);
    Type devType = ofs.deviceType();
    // The power range will be obtained from physical device in the future.
    switch(devType) {
        case OPTICAL_AMPLIFIER:
            if (portType == PortDescType.PA_LINE_OUT || portType == PortDescType.BA_LINE_OUT) {
                return Range.closed(EDFA_POWER_OUT_LOW_THRES, EDFA_POWER_OUT_HIGH_THRES);
            }
            break;
        case ROADM:
            if (portType == PortDescType.PA_LINE_OUT) {
                return Range.closed(ROADM_POWER_LINE_OUT_LOW_THRES, ROADM_POWER_LINE_OUT_HIGH_THRES);
            } else if (portType == PortDescType.EXP_OUT || portType == PortDescType.AUX_OUT) {
                return Range.closed(ROADM_POWER_OTHER_OUT_LOW_THRES, ROADM_POWER_OTHER_OUT_HIGH_THRES);
            }
            break;
        case FIBER_SWITCH:
            return Range.closed(SWITCH_POWER_LOW_THRES, SWITCH_POWER_HIGH_THRES);
        default:
            log.warn("Unexpected device type: {}", devType);
            break;
    }
    // Unexpected port or device type. Do not need warning here for port polling.
    return null;
}
Also used : ExtensionTreatmentType(org.onosproject.net.flow.instructions.ExtensionTreatmentType) Type(org.onosproject.net.Device.Type) PortDescPropertyType(org.onosproject.openflow.controller.PortDescPropertyType) OpenFlowSwitch(org.onosproject.openflow.controller.OpenFlowSwitch)

Example 5 with Type

use of org.onosproject.net.Device.Type in project onos by opennetworkinglab.

the class DeviceCodec method decode.

/**
 * {@inheritDoc}
 *
 * Note: ProviderId is not part of JSON representation.
 *       Returned object will have random ProviderId set.
 */
@Override
public Device decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    DeviceId id = deviceId(json.get(ID).asText());
    // TODO: add providerId to JSON if we need to recover them.
    ProviderId pid = new ProviderId(id.uri().getScheme(), "DeviceCodec");
    Type type = Type.valueOf(json.get(TYPE).asText());
    String mfr = json.get(MFR).asText();
    String hw = json.get(HW).asText();
    String sw = json.get(SW).asText();
    String serial = json.get(SERIAL).asText();
    ChassisId chassisId = new ChassisId(json.get(CHASSIS_ID).asText());
    Annotations annotations = extractAnnotations(json, context);
    return new DefaultDevice(pid, id, type, mfr, hw, sw, serial, chassisId, annotations);
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) Type(org.onosproject.net.Device.Type) ChassisId(org.onlab.packet.ChassisId) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Annotations(org.onosproject.net.Annotations) DeviceId(org.onosproject.net.DeviceId) DefaultDevice(org.onosproject.net.DefaultDevice)

Aggregations

Type (org.onosproject.net.Device.Type)8 ChassisId (org.onlab.packet.ChassisId)6 ProviderId (org.onosproject.net.provider.ProviderId)5 DefaultAnnotations (org.onosproject.net.DefaultAnnotations)4 DefaultDevice (org.onosproject.net.DefaultDevice)4 DefaultDeviceDescription (org.onosproject.net.device.DefaultDeviceDescription)3 DeviceDescription (org.onosproject.net.device.DeviceDescription)3 DeviceId (org.onosproject.net.DeviceId)2 ExtensionTreatmentType (org.onosproject.net.flow.instructions.ExtensionTreatmentType)2 OpenFlowSwitch (org.onosproject.openflow.controller.OpenFlowSwitch)2 PortDescPropertyType (org.onosproject.openflow.controller.PortDescPropertyType)2 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 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