Search in sources :

Example 1 with OpenFlowSwitch

use of org.onosproject.openflow.controller.OpenFlowSwitch 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 2 with OpenFlowSwitch

use of org.onosproject.openflow.controller.OpenFlowSwitch in project onos by opennetworkinglab.

the class OplinkPowerConfigUtil method getOpenFlowDevice.

/**
 * Returns current switch known to this OF controller.
 *
 * @return current switch
 */
private OpenFlowSwitch getOpenFlowDevice() {
    final DriverHandler handler = behaviour.handler();
    final OpenFlowController controller = handler.get(OpenFlowController.class);
    final Dpid dpid = Dpid.dpid(handler.data().deviceId().uri());
    OpenFlowSwitch sw = controller.getSwitch(dpid);
    if (sw == null || !sw.isConnected()) {
        log.warn("OpenFlow handshaker driver not found or device is not connected, dpid = {}", dpid);
        return null;
    }
    return sw;
}
Also used : Dpid(org.onosproject.openflow.controller.Dpid) OpenFlowSwitch(org.onosproject.openflow.controller.OpenFlowSwitch) DriverHandler(org.onosproject.net.driver.DriverHandler) OpenFlowController(org.onosproject.openflow.controller.OpenFlowController)

Example 3 with OpenFlowSwitch

use of org.onosproject.openflow.controller.OpenFlowSwitch 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 4 with OpenFlowSwitch

use of org.onosproject.openflow.controller.OpenFlowSwitch in project onos by opennetworkinglab.

the class OpenFlowPowerConfig method setPortTargetPower.

private boolean setPortTargetPower(PortNumber port, double power) {
    DeviceId deviceId = handler().data().deviceId();
    final Dpid dpid = dpid(deviceId.uri());
    OpenFlowSwitch sw = handler().get(OpenFlowController.class).getSwitch(dpid);
    if (sw == null || !sw.isConnected()) {
        log.error("Failed to change port on device {}", deviceId);
        return false;
    }
    boolean enable = false;
    for (OFPortDesc pd : getPortDescs()) {
        if (pd.getPortNo().getPortNumber() == port.toLong()) {
            enable = pd.getConfig().contains(OFPortConfig.PORT_DOWN);
            break;
        }
    }
    OFPortMod.Builder pmb = makePortMod(sw, port, enable);
    double configure = OFOpticalPortFeaturesSerializerVer14.TX_PWR_VAL;
    OFPortModPropOptical.Builder property = sw.factory().buildPortModPropOptical();
    property.setTxPwr((long) power);
    List<OFPortModProp> properties = new ArrayList<>();
    properties.add(property.build());
    pmb.setProperties(properties);
    sw.sendMsg(Collections.singletonList(pmb.build()));
    // TODO: We would need to report false in case of port mod failure.
    return true;
}
Also used : OFPortModPropOptical(org.projectfloodlight.openflow.protocol.OFPortModPropOptical) OFPortMod(org.projectfloodlight.openflow.protocol.OFPortMod) DeviceId(org.onosproject.net.DeviceId) Dpid(org.onosproject.openflow.controller.Dpid) OpenFlowController(org.onosproject.openflow.controller.OpenFlowController) ArrayList(java.util.ArrayList) OFPortModProp(org.projectfloodlight.openflow.protocol.OFPortModProp) OFPortDesc(org.projectfloodlight.openflow.protocol.OFPortDesc) OpenFlowSwitch(org.onosproject.openflow.controller.OpenFlowSwitch)

Example 5 with OpenFlowSwitch

use of org.onosproject.openflow.controller.OpenFlowSwitch in project onos by opennetworkinglab.

the class OpenFlowPowerConfig method getPortDescs.

private List<OFPortDesc> getPortDescs() {
    final Dpid dpid = dpid(handler().data().deviceId().uri());
    OpenFlowSwitch sw = handler().get(OpenFlowController.class).getSwitch(dpid);
    return sw.getPorts();
}
Also used : Dpid(org.onosproject.openflow.controller.Dpid) OpenFlowSwitch(org.onosproject.openflow.controller.OpenFlowSwitch) OpenFlowController(org.onosproject.openflow.controller.OpenFlowController)

Aggregations

OpenFlowSwitch (org.onosproject.openflow.controller.OpenFlowSwitch)29 Dpid (org.onosproject.openflow.controller.Dpid)17 OpenFlowController (org.onosproject.openflow.controller.OpenFlowController)5 DeviceId (org.onosproject.net.DeviceId)4 OFPortDesc (org.projectfloodlight.openflow.protocol.OFPortDesc)4 Test (org.junit.Test)3 OpenFlowSwitchListener (org.onosproject.openflow.controller.OpenFlowSwitchListener)3 ArrayList (java.util.ArrayList)2 Type (org.onosproject.net.Device.Type)2 ExtensionTreatmentType (org.onosproject.net.flow.instructions.ExtensionTreatmentType)2 PortDescPropertyType (org.onosproject.openflow.controller.PortDescPropertyType)2 OFFlowLightweightStatsReply (org.projectfloodlight.openflow.protocol.OFFlowLightweightStatsReply)2 OFFlowStatsReply (org.projectfloodlight.openflow.protocol.OFFlowStatsReply)2 OFTableStatsEntry (org.projectfloodlight.openflow.protocol.OFTableStatsEntry)2 OFTableStatsReply (org.projectfloodlight.openflow.protocol.OFTableStatsReply)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1 Cache (com.google.common.cache.Cache)1 CacheBuilder (com.google.common.cache.CacheBuilder)1 RemovalCause (com.google.common.cache.RemovalCause)1