use of org.onosproject.net.flow.FlowRule in project onos by opennetworkinglab.
the class KryoSerializerTest method testFlowRuleBatchEntry.
@Test
public void testFlowRuleBatchEntry() {
final FlowRule rule1 = DefaultFlowRule.builder().forDevice(DID1).withSelector(DefaultTrafficSelector.emptySelector()).withTreatment(DefaultTrafficTreatment.emptyTreatment()).withPriority(0).fromApp(new DefaultApplicationId(1, "1")).makeTemporary(1).build();
final FlowRuleBatchEntry entry1 = new FlowRuleBatchEntry(FlowRuleBatchEntry.FlowRuleOperation.ADD, rule1);
final FlowRuleBatchEntry entry2 = new FlowRuleBatchEntry(FlowRuleBatchEntry.FlowRuleOperation.ADD, rule1, 100L);
testSerializedEquals(entry1);
testSerializedEquals(entry2);
}
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 getFlowsFromConnectivityServices.
// Currently uused because get is a blocking call on ADVA
private Collection<FlowEntry> getFlowsFromConnectivityServices(DeviceId deviceId) {
Set<String> uuids = getUuids(deviceId, handler());
if (uuids.isEmpty()) {
return ImmutableList.of();
}
DeviceConnectionCache cache = getConnectionCache();
if (cache.get(deviceId) == null) {
return ImmutableList.of();
}
List<FlowEntry> entries = new ArrayList<>();
uuids.forEach(uuid -> {
FlowRule rule = cache.get(deviceId, uuid);
if (rule != null) {
entries.add(new DefaultFlowEntry(rule, FlowEntry.FlowEntryState.ADDED, 0, 0, 0));
} else {
log.info("Non existing rule for uuid {}", uuid);
}
});
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;
}
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);
}
Aggregations