use of org.onosproject.net.device.DeviceService in project onos by opennetworkinglab.
the class PeerConnectPointCompleter method choices.
@Override
protected List<String> choices() {
DeviceService deviceService = getService(DeviceService.class);
LinkService linkService = getService(LinkService.class);
Optional<ConnectPoint> port = Arrays.asList(commandLine.getArguments()).stream().filter(s -> s.contains(":") && s.contains("/")).map(s -> {
try {
return deviceConnectPoint(s);
} catch (IllegalArgumentException e) {
// silently ill-formed String
return null;
}
}).filter(Objects::nonNull).filter(cp -> deviceService.getPort(cp) != null).findFirst();
if (!port.isPresent()) {
// no candidate
return Collections.emptyList();
}
final ConnectPoint cp = port.get();
return linkService.getLinks(cp).stream().flatMap(l -> Stream.of(l.src(), l.dst())).filter(peer -> !cp.equals(peer)).distinct().map(ConnectPoint::toString).collect(Collectors.toList());
}
use of org.onosproject.net.device.DeviceService in project onos by opennetworkinglab.
the class OplinkHandshakerUtil method buildPortPowerDescriptions.
/**
* Creates port descriptions with current power.
*
* @param portPowers current power
* @return port descriptions
*/
public List<PortDescription> buildPortPowerDescriptions(List<OFOplinkPortPower> portPowers) {
DeviceService deviceService = driver.handler().get(DeviceService.class);
List<Port> ports = deviceService.getPorts(driver.data().deviceId());
HashMap<Long, OFOplinkPortPower> powerMap = new HashMap<>(portPowers.size());
// Get each port power value
portPowers.forEach(power -> powerMap.put((long) power.getPort(), power));
final List<PortDescription> portDescs = new ArrayList<>();
for (Port port : ports) {
DefaultAnnotations.Builder builder = DefaultAnnotations.builder();
builder.putAll(port.annotations());
OFOplinkPortPower power = powerMap.get(port.number().toLong());
if (power != null) {
// power value is actually signed-short value, down casting to recover sign bit.
builder.set(OpticalAnnotations.CURRENT_POWER, Short.toString((short) power.getPowerValue()));
}
portDescs.add(DefaultPortDescription.builder().withPortNumber(port.number()).isEnabled(port.isEnabled()).type(port.type()).portSpeed(port.portSpeed()).annotations(builder.build()).build());
}
return portDescs;
}
use of org.onosproject.net.device.DeviceService in project onos by opennetworkinglab.
the class OplinkSwitchHandshaker method buildPortDescriptions.
private List<PortDescription> buildPortDescriptions(List<OFCalientPortStatsEntry> entries) {
DeviceService deviceService = this.handler().get(DeviceService.class);
List<Port> ports = deviceService.getPorts(this.data().deviceId());
HashMap<Long, OFCalientPortStatsEntry> statsMap = new HashMap<>(entries.size());
entries.forEach(entry -> statsMap.put((long) entry.getPortNo().getPortNumber(), entry));
final List<PortDescription> portDescs = new ArrayList<>();
for (Port port : ports) {
DefaultAnnotations.Builder builder = DefaultAnnotations.builder();
builder.putAll(port.annotations());
// set fingerprint for the virtual port (port 0)
if (port.number().toLong() == PROTECTION_VIRTUAL_PORT) {
builder.set(ProtectionConfigBehaviour.FINGERPRINT, PROTECTION_FINGERPRINT);
}
OFCalientPortStatsEntry entry = statsMap.get(port.number().toLong());
if (entry == null) {
continue;
}
builder.set(CURRENT_POWER, entry.getInportPower());
builder.set(OUTPUT_POWER, entry.getOutportPower());
// We just use this code for a short term, and will modify in the future.
if (entry.getInOperStatus().isEmpty()) {
builder.set(INPUT_PORT_STATUS, STATUS_IN_SERVICE);
} else {
builder.set(INPUT_PORT_STATUS, STATUS_OUT_SERVICE);
}
if (entry.getOutOperStatus().isEmpty()) {
builder.set(OUTPUT_PORT_STATUS, STATUS_IN_SERVICE);
} else {
builder.set(OUTPUT_PORT_STATUS, STATUS_OUT_SERVICE);
}
portDescs.add(DefaultPortDescription.builder().withPortNumber(port.number()).isEnabled(port.isEnabled()).type(port.type()).portSpeed(port.portSpeed()).annotations(builder.build()).build());
}
return portDescs;
}
use of org.onosproject.net.device.DeviceService in project onos by opennetworkinglab.
the class OplinkPowerConfigUtil method getPortPower.
/**
* Find specified port power from port description.
*
* @param portNum the port number
* @param annotation annotation in port description
* @return power value in 0.01 dBm
*/
private Long getPortPower(PortNumber portNum, String annotation) {
// Check if switch is connected, otherwise do not return value in store, which is obsolete.
if (getOpenFlowDevice() == null) {
// Warning already exists in method getOpenFlowDevice()
return null;
}
final DriverHandler handler = behaviour.handler();
DeviceService deviceService = handler.get(DeviceService.class);
Port port = deviceService.getPort(handler.data().deviceId(), portNum);
if (port == null) {
log.warn("Unexpected port: {}", portNum);
return null;
}
String power = port.annotations().value(annotation);
if (power == null) {
// Do not need warning here for port polling.
log.debug("Cannot get {} from port {}.", annotation, portNum);
return null;
}
return Long.valueOf(power);
}
use of org.onosproject.net.device.DeviceService in project onos by opennetworkinglab.
the class OvsdbControllerConfig method getOvsdbClientService.
// Used for getting OvsdbClientService.
private OvsdbClientService getOvsdbClientService(DriverHandler handler) {
OvsdbController ovsController = handler.get(OvsdbController.class);
DeviceService deviceService = handler.get(DeviceService.class);
DeviceId ofDeviceId = handler.data().deviceId();
String[] mgmtAddress = deviceService.getDevice(ofDeviceId).annotations().value(AnnotationKeys.MANAGEMENT_ADDRESS).split(":");
String targetIp = mgmtAddress[0];
TpPort targetPort = null;
if (mgmtAddress.length > 1) {
targetPort = TpPort.tpPort(Integer.parseInt(mgmtAddress[1]));
}
List<OvsdbNodeId> nodeIds = ovsController.getNodeIds().stream().filter(nodeId -> nodeId.getIpAddress().equals(targetIp)).collect(Collectors.toList());
if (nodeIds.isEmpty()) {
// TODO decide what port?
ovsController.connect(IpAddress.valueOf(targetIp), targetPort == null ? TpPort.tpPort(OvsdbConstant.OVSDBPORT) : targetPort);
// FIXME... connect is async
delay(1000);
}
List<OvsdbClientService> clientServices = ovsController.getNodeIds().stream().filter(nodeId -> nodeId.getIpAddress().equals(targetIp)).map(ovsController::getOvsdbClient).filter(cs -> cs.getBridges().stream().anyMatch(b -> dpidMatches(b, ofDeviceId))).collect(Collectors.toList());
checkState(!clientServices.isEmpty(), "No clientServices found");
// FIXME add connection to management address if null --> done ?
return !clientServices.isEmpty() ? clientServices.get(0) : null;
}
Aggregations