use of org.onosproject.net.flow.FlowId in project onos by opennetworkinglab.
the class RoadmCrossConnectCommand method addRule.
/**
* This method creates a XC on the device based on the parameters passed by the user.
* Takes as an input "global" parameters (passed by user through the console).
* @return - return the FlowId of the installed rule.
*/
protected FlowId addRule() {
// Preparing parameters
DeviceId device = DeviceId.deviceId(deviceId);
PortNumber inPort = PortNumber.portNumber(srcPort);
PortNumber outPort = PortNumber.portNumber(dstPort);
OchSignal signal = createOchSignal(freq, sw, gridType, channelSpacing);
if (inPort == null) {
print("[addRule] Not able to find srcPort in the ONOS database");
log.debug("[addRule] Not able to find srcPort in the ONOS database");
return null;
}
if (outPort == null) {
print("[addRule] Not able to find dstPort in the ONOS database");
log.debug("[addRule] Not able to find dstPort in the ONOS database");
return null;
}
if (signal == null) {
print("[addRule] Not able to compose an OchSignal with passed parameters. Double check them");
log.debug("[addRule] Not able to compose an OchSignal with passed parameters. Double check them");
return null;
}
RoadmService manager = AbstractShellCommand.get(RoadmService.class);
print("Adding XC for the device %s between port %s and port %s on frequency %s with bandwidth %s", deviceId, srcPort, dstPort, freq, sw);
log.info("[addRule] Adding XC for the device {} between port {} and port {} " + "on frequency {} with bandwidth {}", deviceId, srcPort, dstPort, freq, sw);
FlowId flow = manager.createConnection(device, 100, true, -1, inPort, outPort, signal);
if (flow != null) {
return flow;
} else {
return null;
}
}
use of org.onosproject.net.flow.FlowId in project onos by opennetworkinglab.
the class RoadmCrossConnectCommand method dropRule.
/**
* This function drops XC installed on the device, which is matching parsed criteria.
* Takes as an input "global" parameters (passed by user through the console).
* @return - returns number of the rules that were dropped.
*/
protected FlowId dropRule() {
// Preparing parameters
DeviceId device = DeviceId.deviceId(deviceId);
PortNumber inPort = PortNumber.portNumber(srcPort);
PortNumber outPort = PortNumber.portNumber(dstPort);
// Creating some variables
OchSignal ochSignal = null;
PortNumber inputPortNumber = null;
PortNumber outputPortNumber = null;
// Main idea: Go over all flow rules (read out from the storage) of current device and
// filter them based on input and output port with respect to OchSignal
FlowRuleService fr = AbstractShellCommand.get(FlowRuleService.class);
Iterable<FlowEntry> flowRules = fr.getFlowEntries(device);
FlowId flowId = null;
OchSignal referenceSignal = createOchSignal(freq, sw, gridType, channelSpacing);
for (FlowEntry flowRule : flowRules) {
// Taken from FlowRuleParser
for (Criterion c : flowRule.selector().criteria()) {
if (c instanceof OchSignalCriterion) {
ochSignal = ((OchSignalCriterion) c).lambda();
}
if (c instanceof PortCriterion) {
// obtain input port
inputPortNumber = ((PortCriterion) c).port();
}
}
for (Instruction i : flowRule.treatment().immediate()) {
if (i instanceof L0ModificationInstruction.ModOchSignalInstruction) {
ochSignal = ((L0ModificationInstruction.ModOchSignalInstruction) i).lambda();
}
if (i instanceof Instructions.OutputInstruction) {
// obtain output port
outputPortNumber = ((Instructions.OutputInstruction) i).port();
}
}
// If we found match, then let's delete this rule
if ((ochSignal.centralFrequency().equals(referenceSignal.centralFrequency())) & (ochSignal.slotWidth().equals(referenceSignal.slotWidth())) & (inputPortNumber.equals(inPort)) & (outputPortNumber.equals(outPort))) {
flowId = flowRule.id();
RoadmService manager = AbstractShellCommand.get(RoadmService.class);
manager.removeConnection(device, flowId);
print("Dropping existing XC from the device %s", deviceId);
return flowId;
}
}
return null;
}
use of org.onosproject.net.flow.FlowId in project onos by opennetworkinglab.
the class CienaRestDevice method fetchRule.
private FlowRule fetchRule(PortNumber port) {
Frequency frequency = getFrequency(port);
if (frequency == null) {
return null;
}
int channel = getChannelFromFrequency(frequency);
/*
* both inPort and outPort will be same as WaveServer only deal with same port ptp-indexes
* channel and spaceMultiplier are same.
* TODO: find a way to get both inPort and outPort for future when inPort may not be equal to outPort
*/
TrafficSelector selector = DefaultTrafficSelector.builder().matchInPort(port).add(Criteria.matchOchSignalType(OchSignalType.FIXED_GRID)).add(Criteria.matchLambda(OchSignal.newDwdmSlot(CHANNEL_SPACING, channel))).build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(port).build();
int hash = Objects.hash(deviceId, selector, treatment);
Pair<FlowId, Integer> lookup = crossConnectCache.get(hash);
if (lookup == null) {
return null;
}
return DefaultFlowRule.builder().forDevice(deviceId).makePermanent().withSelector(selector).withTreatment(treatment).withPriority(lookup.getRight()).withCookie(lookup.getLeft().value()).build();
}
Aggregations