Search in sources :

Example 1 with DeviceConnection

use of org.onosproject.drivers.odtn.impl.DeviceConnection 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;
}
Also used : DeviceId(org.onosproject.net.DeviceId) RestSBController(org.onosproject.protocol.rest.RestSBController) ImmutableList(com.google.common.collect.ImmutableList) DeviceConnection(org.onosproject.drivers.odtn.impl.DeviceConnection) FlowRule(org.onosproject.net.flow.FlowRule)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 DeviceConnection (org.onosproject.drivers.odtn.impl.DeviceConnection)1 DeviceId (org.onosproject.net.DeviceId)1 FlowRule (org.onosproject.net.flow.FlowRule)1 RestSBController (org.onosproject.protocol.rest.RestSBController)1