Search in sources :

Example 1 with OFOplinkPortPower

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;
}
Also used : OFOplinkPortPower(org.projectfloodlight.openflow.protocol.OFOplinkPortPower) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) HashMap(java.util.HashMap) Port(org.onosproject.net.Port) DeviceService(org.onosproject.net.device.DeviceService) ArrayList(java.util.ArrayList) PortDescription(org.onosproject.net.device.PortDescription) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 DefaultAnnotations (org.onosproject.net.DefaultAnnotations)1 Port (org.onosproject.net.Port)1 DefaultPortDescription (org.onosproject.net.device.DefaultPortDescription)1 DeviceService (org.onosproject.net.device.DeviceService)1 PortDescription (org.onosproject.net.device.PortDescription)1 OFOplinkPortPower (org.projectfloodlight.openflow.protocol.OFOplinkPortPower)1