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);
}
}
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);
}
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;
}
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;
}
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);
}
Aggregations