use of org.projectfloodlight.openflow.protocol.OFOplinkPortPower 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;
}
Aggregations