use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class FlowBucket method remove.
/**
* Removes the given flow rule from the bucket.
*
* @param rule the rule to remove
* @param term the term in which the change occurred
* @param clock the logical clock
* @return the removed flow entry
*/
public FlowEntry remove(FlowEntry rule, long term, LogicalClock clock) {
final AtomicReference<FlowEntry> removedRule = new AtomicReference<>();
flowBucket.computeIfPresent(rule.id(), (flowId, flowEntries) -> {
flowEntries.computeIfPresent((StoredFlowEntry) rule, (k, stored) -> {
if (rule instanceof DefaultFlowEntry) {
DefaultFlowEntry toRemove = (DefaultFlowEntry) rule;
if (stored instanceof DefaultFlowEntry) {
DefaultFlowEntry storedEntry = (DefaultFlowEntry) stored;
if (toRemove.created() < storedEntry.created()) {
LOGGER.debug("Trying to remove more recent flow entry {} (stored: {})", toRemove, stored);
// the key is not updated, removedRule remains null
return stored;
}
}
}
removedRule.set(stored);
return null;
});
return flowEntries.isEmpty() ? null : flowEntries;
});
if (removedRule.get() != null) {
recordUpdate(term, clock.getTimestamp());
return removedRule.get();
} else {
return null;
}
}
use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class PolatisOpticalUtility method toFlowRule.
/**
* Finds the FlowRule from flow rule store by the given ports and channel.
* Returns an extra flow to remove the flow by ONOS if not found.
* @param behaviour the parent driver handler
* @param inPort the input port
* @param outPort the output port
* @return the flow rule
*/
public static FlowRule toFlowRule(HandlerBehaviour behaviour, PortNumber inPort, PortNumber outPort) {
FlowRuleService service = behaviour.handler().get(FlowRuleService.class);
Iterable<FlowEntry> entries = service.getFlowEntries(behaviour.data().deviceId());
// Try to Find the flow from flow rule store.
for (FlowEntry entry : entries) {
Set<Criterion> criterions = entry.selector().criteria();
// input port
PortNumber ip = criterions.stream().filter(c -> c instanceof PortCriterion).map(c -> ((PortCriterion) c).port()).findAny().orElse(null);
// output port
PortNumber op = entry.treatment().immediate().stream().filter(c -> c instanceof Instructions.OutputInstruction).map(c -> ((Instructions.OutputInstruction) c).port()).findAny().orElse(null);
if (inPort.equals(ip) && outPort.equals(op)) {
// Find the flow.
return entry;
}
}
// Cannot find the flow from store. So report an extra flow to remove the flow by ONOS.
TrafficSelector selector = DefaultTrafficSelector.builder().matchInPort(inPort).build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(outPort).build();
return DefaultFlowRule.builder().forDevice(behaviour.data().deviceId()).withSelector(selector).withTreatment(treatment).makePermanent().withPriority(DEFAULT_PRIORITY).fromApp(behaviour.handler().get(CoreService.class).getAppId(DEFAULT_APP)).build();
}
use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class PolatisInternalConnectivity method getUsedPorts.
private Set<PortNumber> getUsedPorts() {
Set<PortNumber> usedPorts = new HashSet<PortNumber>();
Collection<FlowEntry> flowEntries = parseConnections(this);
for (FlowEntry flowEntry : flowEntries) {
usedPorts.add(((PortCriterion) flowEntry.selector().getCriterion(Criterion.Type.IN_PORT)).port());
usedPorts.add(((OutputInstruction) flowEntry.treatment().allInstructions().get(0)).port());
}
return usedPorts;
}
use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class PolatisInternalConnectivity method getOutputPorts.
/**
* Returns a set of possible output PortNumbers to which a given input port can be internally connected
* on a given device.
* <p>
* This is a callback method required by the InternalConnectivity behaviour.
* @param inputPortNum Input port number on device
* @return List of possible output ports
*/
@Override
public Set<PortNumber> getOutputPorts(PortNumber inputPortNum) {
// NOTE: in this implementation, inputPortNum is the supplied port number and
// can be an "input" port OR an "output" port
// This reflects the fact that reverse propagation is possible through a Polatis switch
// (output port -> input port)
Set<PortNumber> ports = new HashSet<PortNumber>();
Set<PortNumber> enabledPorts = new HashSet<PortNumber>();
Collection<FlowEntry> flowEntries = parseConnections(this);
// e.g. one selector (IN_PORT) and one action (set output port)
if (flowEntries.stream().map(flow -> ((PortCriterion) flow.selector().getCriterion(Criterion.Type.IN_PORT)).port()).collect(Collectors.toSet()).contains(inputPortNum) || flowEntries.stream().map(flow -> ((OutputInstruction) flow.treatment().allInstructions().get(0)).port()).collect(Collectors.toSet()).contains(inputPortNum)) {
log.warn("Queried port {} is already used in a cross-connect", inputPortNum);
return ports;
} else {
DeviceId deviceID = handler().data().deviceId();
DeviceService deviceService = checkNotNull(this.handler().get(DeviceService.class));
Port inputPort = deviceService.getPort(new ConnectPoint(deviceID, inputPortNum));
if (inputPort.annotations().value(KEY_PORTDIR).equals(VALUE_CC)) {
ports = deviceService.getPorts(deviceID).stream().filter(p -> !p.equals(inputPortNum)).map(p -> p.number()).collect(Collectors.toSet());
} else {
ports = deviceService.getPorts(deviceID).stream().filter((p) -> {
Port port = deviceService.getPort(new ConnectPoint(deviceID, p.number()));
return !port.annotations().value(KEY_PORTDIR).equals(inputPort.annotations().value(KEY_PORTDIR));
}).map(p -> p.number()).collect(Collectors.toSet());
}
// Remove disabled ports
enabledPorts = ports.stream().filter(p -> deviceService.getPort(new ConnectPoint(deviceID, p)).isEnabled()).collect(Collectors.toSet());
}
log.debug("Ports before filtering out used and disabled ones: " + ports);
return filterUsedPorts(enabledPorts, flowEntries);
}
use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class PolatisOpticalUtility method toFlowRule.
/**
* Finds the FlowRule from flow rule store by the given ports and channel.
* Returns an extra flow to remove the flow by ONOS if not found.
* @param behaviour the parent driver handler
* @param inPort the input port
* @param outPort the output port
* @return the flow rule
*/
public static FlowRule toFlowRule(HandlerBehaviour behaviour, PortNumber inPort, PortNumber outPort) {
FlowRuleService service = behaviour.handler().get(FlowRuleService.class);
Iterable<FlowEntry> entries = service.getFlowEntries(behaviour.data().deviceId());
// Try to Find the flow from flow rule store.
for (FlowEntry entry : entries) {
Set<Criterion> criterions = entry.selector().criteria();
// input port
PortNumber ip = criterions.stream().filter(c -> c instanceof PortCriterion).map(c -> ((PortCriterion) c).port()).findAny().orElse(null);
// output port
PortNumber op = entry.treatment().immediate().stream().filter(c -> c instanceof Instructions.OutputInstruction).map(c -> ((Instructions.OutputInstruction) c).port()).findAny().orElse(null);
if (inPort.equals(ip) && outPort.equals(op)) {
// Find the flow.
return entry;
}
}
// Cannot find the flow from store. So report an extra flow to remove the flow by ONOS.
TrafficSelector selector = DefaultTrafficSelector.builder().matchInPort(inPort).build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(outPort).build();
return DefaultFlowRule.builder().forDevice(behaviour.data().deviceId()).withSelector(selector).withTreatment(treatment).makePermanent().withPriority(DEFAULT_PRIORITY).fromApp(behaviour.handler().get(CoreService.class).getAppId(DEFAULT_APP)).build();
}
Aggregations