Search in sources :

Example 1 with ObjectiveError

use of org.onosproject.net.flowobjective.ObjectiveError in project onos by opennetworkinglab.

the class VirtualNetworkPacketManager method removeRule.

/**
 * Removes packet intercept flow rules from the device.
 *
 * @param device  the device to remove the rules deom
 * @param request the packet request
 */
private void removeRule(Device device, PacketRequest request) {
    if (!device.type().equals(Device.Type.VIRTUAL)) {
        return;
    }
    ForwardingObjective forwarding = createBuilder(request).remove(new ObjectiveContext() {

        @Override
        public void onError(Objective objective, ObjectiveError error) {
            log.warn("Failed to withdraw packet request {} from {}: {}", request, device.id(), error);
        }
    });
    objectiveService.forward(device.id(), forwarding);
}
Also used : ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) Objective(org.onosproject.net.flowobjective.Objective) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) ObjectiveError(org.onosproject.net.flowobjective.ObjectiveError)

Example 2 with ObjectiveError

use of org.onosproject.net.flowobjective.ObjectiveError in project onos by opennetworkinglab.

the class InOrderFlowObjectiveManagerTest method forwardTimeout.

@Test
public void forwardTimeout() {
    final AtomicInteger counter = new AtomicInteger(0);
    ForwardingObjective fwdTimeout = buildFwdObjective(S1, NID2).add(new ObjectiveContext() {

        @Override
        public void onError(Objective objective, ObjectiveError error) {
            if (Objects.equals(ObjectiveError.INSTALLATIONTIMEOUT, error)) {
                counter.incrementAndGet();
            }
        }
    });
    List<ForwardingObjective> expectFwdObjsTimeout = Lists.newCopyOnWriteArrayList(Lists.newArrayList(fwdTimeout, FWD1, FWD2));
    // Reduce timeout so the unit test doesn't have to wait many seconds
    internalSetup(TIMEOUT_THRESH);
    expect(mgr.flowObjectiveStore.getNextGroup(NID1)).andReturn(NGRP1).times(1);
    expect(mgr.flowObjectiveStore.getNextGroup(NID2)).andReturn(NGRP2).times(2);
    replay(mgr.flowObjectiveStore);
    // Force this objective to time out
    offset = mgr.objectiveTimeoutMs * 3;
    expectFwdObjsTimeout.forEach(fwdObj -> mgr.forward(DEV1, fwdObj));
    // Wait for the pipeline operation to complete
    int expectedTime = (bound + offset) * 3;
    assertAfter(expectedTime, expectedTime * 5, () -> assertEquals(expectFwdObjsTimeout.size(), actualObjs.size()));
    assertAfter(expectedTime, expectedTime * 5, () -> assertTrue(counter.get() != 0));
    assertTrue(actualObjs.indexOf(fwdTimeout) < actualObjs.indexOf(FWD1));
    verify(mgr.flowObjectiveStore);
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) Objective(org.onosproject.net.flowobjective.Objective) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) ObjectiveError(org.onosproject.net.flowobjective.ObjectiveError) Test(org.junit.Test)

Example 3 with ObjectiveError

use of org.onosproject.net.flowobjective.ObjectiveError in project onos by opennetworkinglab.

the class Ofdpa2Pipeline method sendForwards.

// Builds the batch using the accumulated flow rules
private void sendForwards(List<Pair<ForwardingObjective, Collection<FlowRule>>> pairs) {
    FlowRuleOperations.Builder flowOpsBuilder = FlowRuleOperations.builder();
    log.debug("Sending {} fwd-objs", pairs.size());
    List<Objective> fwdObjs = Lists.newArrayList();
    // Iterates over all accumulated flow rules and then build an unique batch
    pairs.forEach(pair -> {
        ForwardingObjective fwd = pair.getLeft();
        Collection<FlowRule> rules = pair.getRight();
        switch(fwd.op()) {
            case ADD:
                rules.stream().filter(Objects::nonNull).forEach(flowOpsBuilder::add);
                log.debug("Applying a add fwd-obj {} to sw:{}", fwd.id(), deviceId);
                fwdObjs.add(fwd);
                break;
            case REMOVE:
                rules.stream().filter(Objects::nonNull).forEach(flowOpsBuilder::remove);
                log.debug("Deleting a flow rule to sw:{}", deviceId);
                fwdObjs.add(fwd);
                break;
            default:
                fail(fwd, ObjectiveError.UNKNOWN);
                log.warn("Unknown forwarding type {}", fwd.op());
        }
    });
    // Finally applies the operations
    flowRuleService.apply(flowOpsBuilder.build(new FlowRuleOperationsContext() {

        @Override
        public void onSuccess(FlowRuleOperations ops) {
            log.trace("Flow rule operations onSuccess {}", ops);
            fwdObjs.forEach(OfdpaPipelineUtility::pass);
        }

        @Override
        public void onError(FlowRuleOperations ops) {
            ObjectiveError error = ObjectiveError.FLOWINSTALLATIONFAILED;
            log.warn("Flow rule operations onError {}. Reason = {}", ops, error);
            fwdObjs.forEach(fwdObj -> fail(fwdObj, error));
        }
    }));
}
Also used : NextObjective(org.onosproject.net.flowobjective.NextObjective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) Objective(org.onosproject.net.flowobjective.Objective) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) OfdpaPipelineUtility(org.onosproject.driver.pipeline.ofdpa.OfdpaPipelineUtility) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) FlowRuleOperationsContext(org.onosproject.net.flow.FlowRuleOperationsContext) ObjectiveError(org.onosproject.net.flowobjective.ObjectiveError)

Example 4 with ObjectiveError

use of org.onosproject.net.flowobjective.ObjectiveError in project onos by opennetworkinglab.

the class FabricPipeliner method next.

@Override
public void next(NextObjective obj) {
    if (obj.op() == Objective.Operation.VERIFY) {
        if (obj.type() != NextObjective.Type.HASHED) {
            log.warn("VERIFY operation not yet supported for NextObjective {}, will return failure :(", obj.type());
            fail(obj, ObjectiveError.UNSUPPORTED);
            return;
        }
        if (log.isTraceEnabled()) {
            log.trace("Verify NextObjective {} in dev {}", obj, deviceId);
        }
        ObjectiveError error = handleVerify(obj);
        if (error == null) {
            success(obj);
        } else {
            fail(obj, error);
        }
        return;
    }
    if (obj.op() == Objective.Operation.MODIFY && obj.type() != SIMPLE) {
        log.warn("MODIFY operation not yet supported for NextObjective {}, will return failure :(", obj.type());
        if (log.isTraceEnabled()) {
            log.trace("Objective {}", obj);
        }
        fail(obj, ObjectiveError.UNSUPPORTED);
        return;
    }
    final ObjectiveTranslation result = nextTranslator.translate(obj);
    handleResult(obj, result);
}
Also used : ObjectiveError(org.onosproject.net.flowobjective.ObjectiveError)

Example 5 with ObjectiveError

use of org.onosproject.net.flowobjective.ObjectiveError in project onos by opennetworkinglab.

the class Dhcp4HandlerImpl method processIgnoreVlanRule.

/**
 * Process the ignore rules.
 *
 * @param deviceId the device id
 * @param vlanId the vlan to be ignored
 * @param op the operation, ADD to install; REMOVE to uninstall rules
 */
private void processIgnoreVlanRule(DeviceId deviceId, VlanId vlanId, Objective.Operation op) {
    AtomicInteger installedCount = new AtomicInteger(DHCP_SELECTORS.size());
    DHCP_SELECTORS.forEach(trafficSelector -> {
        TrafficSelector selector = DefaultTrafficSelector.builder(trafficSelector).matchVlanId(vlanId).build();
        ForwardingObjective.Builder builder = DefaultForwardingObjective.builder().withFlag(ForwardingObjective.Flag.VERSATILE).withSelector(selector).withPriority(IGNORE_CONTROL_PRIORITY).withTreatment(DefaultTrafficTreatment.emptyTreatment()).fromApp(appId);
        ObjectiveContext objectiveContext = new ObjectiveContext() {

            @Override
            public void onSuccess(Objective objective) {
                log.info("Ignore rule {} (Vlan id {}, device {}, selector {})", op, vlanId, deviceId, selector);
                int countDown = installedCount.decrementAndGet();
                if (countDown != 0) {
                    return;
                }
                switch(op) {
                    case ADD:
                        ignoredVlans.put(deviceId, vlanId);
                        break;
                    case REMOVE:
                        ignoredVlans.remove(deviceId, vlanId);
                        break;
                    default:
                        log.warn("Unsupported objective operation {}", op);
                        break;
                }
            }

            @Override
            public void onError(Objective objective, ObjectiveError error) {
                log.warn("Can't {} ignore rule (vlan id {}, selector {}, device {}) due to {}", op, vlanId, selector, deviceId, error);
            }
        };
        ForwardingObjective fwd;
        switch(op) {
            case ADD:
                fwd = builder.add(objectiveContext);
                break;
            case REMOVE:
                fwd = builder.remove(objectiveContext);
                break;
            default:
                log.warn("Unsupported objective operation {}", op);
                return;
        }
        Device device = deviceService.getDevice(deviceId);
        if (device == null || !device.is(Pipeliner.class)) {
            log.warn("Device {} is not available now, wait until device is available", deviceId);
            return;
        }
        flowObjectiveService.apply(deviceId, fwd);
    });
}
Also used : Objective(org.onosproject.net.flowobjective.Objective) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Device(org.onosproject.net.Device) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) ConnectPoint(org.onosproject.net.ConnectPoint) ObjectiveError(org.onosproject.net.flowobjective.ObjectiveError)

Aggregations

ObjectiveError (org.onosproject.net.flowobjective.ObjectiveError)11 ForwardingObjective (org.onosproject.net.flowobjective.ForwardingObjective)10 Objective (org.onosproject.net.flowobjective.Objective)10 ObjectiveContext (org.onosproject.net.flowobjective.ObjectiveContext)8 DefaultForwardingObjective (org.onosproject.net.flowobjective.DefaultForwardingObjective)7 FilteringObjective (org.onosproject.net.flowobjective.FilteringObjective)4 NextObjective (org.onosproject.net.flowobjective.NextObjective)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)3 TrafficSelector (org.onosproject.net.flow.TrafficSelector)3 List (java.util.List)2 Map (java.util.Map)2 Objects (java.util.Objects)2 Set (java.util.Set)2 ExecutorService (java.util.concurrent.ExecutorService)2 ConnectPoint (org.onosproject.net.ConnectPoint)2 Device (org.onosproject.net.Device)2 DeviceId (org.onosproject.net.DeviceId)2 Logger (org.slf4j.Logger)2 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1