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