use of org.onosproject.net.flow.FlowRule in project onos by opennetworkinglab.
the class FlowRuleDriverProvider method executeBatch.
@Override
public void executeBatch(FlowRuleBatchOperation batch) {
ImmutableList.Builder<FlowRule> toAdd = ImmutableList.builder();
ImmutableList.Builder<FlowRule> toRemove = ImmutableList.builder();
for (FlowRuleBatchEntry fbe : batch.getOperations()) {
if (fbe.operator() == ADD || fbe.operator() == MODIFY) {
toAdd.add(fbe.target());
} else if (fbe.operator() == REMOVE) {
toRemove.add(fbe.target());
}
}
ImmutableList<FlowRule> rulesToAdd = toAdd.build();
ImmutableList<FlowRule> rulesToRemove = toRemove.build();
Collection<FlowRule> added = ImmutableList.of();
if (!rulesToAdd.isEmpty()) {
added = applyFlowRules(batch.deviceId(), rulesToAdd);
}
Collection<FlowRule> removed = ImmutableList.of();
if (!rulesToRemove.isEmpty()) {
removed = removeFlowRules(batch.deviceId(), rulesToRemove);
}
Set<FlowRule> failedRules = Sets.union(Sets.difference(copyOf(rulesToAdd), copyOf(added)), Sets.difference(copyOf(rulesToRemove), copyOf(removed)));
CompletedBatchOperation status = new CompletedBatchOperation(failedRules.isEmpty(), failedRules, batch.deviceId());
providerService.batchOperationCompleted(batch.id(), status);
}
use of org.onosproject.net.flow.FlowRule in project onos by opennetworkinglab.
the class FlowRuleManager method getFlowRulesByGroupId.
@Override
public Iterable<FlowRule> getFlowRulesByGroupId(ApplicationId appId, short groupId) {
checkPermission(FLOWRULE_READ);
Set<FlowRule> matches = Sets.newHashSet();
long toLookUp = ((long) appId.id() << 16) | groupId;
for (Device d : deviceService.getDevices()) {
for (FlowEntry flowEntry : store.getFlowEntries(d.id())) {
if ((flowEntry.id().value() >>> 32) == toLookUp) {
matches.add(flowEntry);
}
}
}
return matches;
}
use of org.onosproject.net.flow.FlowRule 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.net.flow.FlowRule in project onos by opennetworkinglab.
the class TapiFlowRuleProgrammable method getFlowEntries.
@Override
public Collection<FlowEntry> getFlowEntries() {
DeviceId deviceId = did();
// TODO this is a blocking call on ADVA OLS, right now using cache.
// return getFlowsFromConnectivityServices(deviceId);
List<FlowEntry> entries = new ArrayList<>();
Set<FlowRule> rules = getConnectionCache().get(deviceId);
if (rules != null) {
rules.forEach(rule -> {
entries.add(new DefaultFlowEntry(rule, FlowEntry.FlowEntryState.ADDED, 0, 0, 0));
});
}
return entries;
}
use of org.onosproject.net.flow.FlowRule in project onos by opennetworkinglab.
the class TapiFlowRuleProgrammable method removeFlowRules.
@Override
public Collection<FlowRule> removeFlowRules(Collection<FlowRule> rules) {
DeviceId deviceId = handler().data().deviceId();
RestSBController controller = checkNotNull(handler().get(RestSBController.class));
ImmutableList.Builder<FlowRule> removed = ImmutableList.builder();
rules.forEach(flowRule -> {
DeviceConnection conn = getConnectionCache().get(deviceId, flowRule.id());
if (conn == null || conn.getId() == null) {
log.warn("Can't find associate device connection for flow {} and device {}", flowRule.id(), deviceId);
return;
}
CompletableFuture<Integer> flowRemoval = CompletableFuture.supplyAsync(() -> controller.delete(deviceId, CONN_REQ_REMOVE_DATA_API + conn.getId(), null, MediaType.APPLICATION_JSON_TYPE));
flowRemoval.thenApply(result -> {
if (result == HttpStatus.SC_NO_CONTENT) {
getConnectionCache().remove(deviceId, flowRule);
removed.add(flowRule);
} else {
log.error("Can't remove flow {}, result {}", flowRule, result);
}
return result;
});
});
// TODO workaround for blocking call on ADVA OLS shoudl return removed
return rules;
}
Aggregations