use of org.onosproject.driver.extensions.OplinkAttenuation in project onos by opennetworkinglab.
the class OplinkOpticalPowerConfig method setChannelTargetPower.
private boolean setChannelTargetPower(PortNumber port, OchSignal channel, long power) {
log.debug("Set port{} channel{} attenuation.", port, channel.channelSpacing());
FlowRuleService service = handler().get(FlowRuleService.class);
Iterable<FlowEntry> entries = service.getFlowEntries(data().deviceId());
for (FlowEntry entry : entries) {
OplinkCrossConnect crossConnect = OplinkOpticalUtility.fromFlowRule(this, entry);
// The channel port might be input port or output port.
if ((port.equals(crossConnect.getInPort()) || port.equals(crossConnect.getOutPort())) && channel.spacingMultiplier() == crossConnect.getChannel()) {
log.debug("Flow is found, modify the flow with attenuation.");
// Modify attenuation in treatment
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(crossConnect.getOutPort()).extension(new OplinkAttenuation((int) power), data().deviceId()).build();
// Apply the new flow rule
service.applyFlowRules(DefaultFlowRule.builder().forDevice(data().deviceId()).makePermanent().withSelector(entry.selector()).withTreatment(treatment).withPriority(entry.priority()).withCookie(entry.id().value()).build());
return true;
}
}
return false;
}
use of org.onosproject.driver.extensions.OplinkAttenuation in project onos by opennetworkinglab.
the class OplinkOpticalUtility method fromFlowRule.
/**
* Transforms a flow FlowRule object to an OplinkCrossConnect object.
* @param behaviour the parent driver handler
* @param rule FlowRule object
* @return cross connect object
*/
public static OplinkCrossConnect fromFlowRule(HandlerBehaviour behaviour, FlowRule rule) {
// TrafficSelector
Set<Criterion> criterions = rule.selector().criteria();
int channel = criterions.stream().filter(c -> c instanceof OchSignalCriterion).map(c -> ((OchSignalCriterion) c).lambda().spacingMultiplier()).findAny().orElse(null);
PortNumber inPort = criterions.stream().filter(c -> c instanceof PortCriterion).map(c -> ((PortCriterion) c).port()).findAny().orElse(null);
// TrafficTreatment
List<Instruction> instructions = rule.treatment().immediate();
PortNumber outPort = instructions.stream().filter(c -> c instanceof Instructions.OutputInstruction).map(c -> ((Instructions.OutputInstruction) c).port()).findAny().orElse(null);
int attenuation = instructions.stream().filter(c -> c instanceof Instructions.ExtensionInstructionWrapper).map(c -> ((Instructions.ExtensionInstructionWrapper) c).extensionInstruction()).filter(c -> c instanceof OplinkAttenuation).map(c -> ((OplinkAttenuation) c).getAttenuation()).findAny().orElse(DEFAULT_ATT);
return new OplinkCrossConnect(inPort, outPort, channel, attenuation);
}
use of org.onosproject.driver.extensions.OplinkAttenuation in project onos by opennetworkinglab.
the class OplinkPowerConfigUtil method setChannelAttenuation.
/**
* Sets specified channle attenuation.
*
* @param portNum the port number
* @param och channel signal
* @param power attenuation in 0.01 dB
*/
private void setChannelAttenuation(PortNumber portNum, OchSignal och, long power) {
FlowEntry flowEntry = findFlow(portNum, och);
if (flowEntry == null) {
log.warn("Target channel power not set");
return;
}
final DriverHandler handler = behaviour.handler();
for (Instruction ins : flowEntry.treatment().allInstructions()) {
if (ins.type() != Instruction.Type.EXTENSION) {
continue;
}
ExtensionTreatment ext = ((Instructions.ExtensionInstructionWrapper) ins).extensionInstruction();
if (ext.type() == ExtensionTreatmentType.ExtensionTreatmentTypes.OPLINK_ATTENUATION.type()) {
((OplinkAttenuation) ext).setAttenuation((int) power);
FlowRuleService service = handler.get(FlowRuleService.class);
service.applyFlowRules(flowEntry);
return;
}
}
addAttenuation(flowEntry, power);
}
use of org.onosproject.driver.extensions.OplinkAttenuation in project onos by opennetworkinglab.
the class OplinkPowerConfigUtil method addAttenuation.
/**
* Replace flow with new flow containing Oplink attenuation extension instruction. Also resets metrics.
*
* @param flowEntry flow entry
* @param power power value
*/
private void addAttenuation(FlowEntry flowEntry, long power) {
FlowRule.Builder flowBuilder = new DefaultFlowRule.Builder().withCookie(flowEntry.id().value()).withPriority(flowEntry.priority()).forDevice(flowEntry.deviceId()).forTable(flowEntry.tableId());
if (flowEntry.isPermanent()) {
flowBuilder.makePermanent();
} else {
flowBuilder.makeTemporary(flowEntry.timeout());
}
flowBuilder.withSelector(flowEntry.selector());
// Copy original instructions and add attenuation instruction
TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
flowEntry.treatment().allInstructions().forEach(ins -> treatmentBuilder.add(ins));
final DriverHandler handler = behaviour.handler();
treatmentBuilder.add(Instructions.extension(new OplinkAttenuation((int) power), handler.data().deviceId()));
flowBuilder.withTreatment(treatmentBuilder.build());
FlowRuleService service = handler.get(FlowRuleService.class);
service.applyFlowRules(flowBuilder.build());
}
Aggregations