Search in sources :

Example 16 with ObjectiveError

use of org.onosproject.net.flowobjective.ObjectiveError in project trellis-control by opennetworkinglab.

the class DefaultL2TunnelHandler method tearDownConnectionPoints.

/**
 * Tears down connection points of pseudowires. We can either tear down both connection points,
 * or each one of them.
 *
 * @param l2TunnelId The tunnel id for this pseudowire.
 * @param tearDownFirst Boolean, true if we want to tear down cp1
 * @param tearDownSecond Boolean, true if we want to tear down cp2
 * @param pending Boolean, if true remove only pseudowire from pending stores since no flows/groups
 *                in the network, else remove flows/groups in the devices also.
 * @return Result of tearing down the pseudowire, SUCCESS if everything was ok
 *         a descriptive error otherwise.
 */
private Result tearDownConnectionPoints(long l2TunnelId, boolean tearDownFirst, boolean tearDownSecond, boolean pending) {
    Result res;
    CompletableFuture<ObjectiveError> fwdInitNextFuture = new CompletableFuture<>();
    CompletableFuture<ObjectiveError> fwdTermNextFuture = new CompletableFuture<>();
    CompletableFuture<ObjectiveError> revInitNextFuture = new CompletableFuture<>();
    CompletableFuture<ObjectiveError> revTermNextFuture = new CompletableFuture<>();
    if (l2TunnelId == 0) {
        log.error("Removal process : Tunnel id cannot be 0");
        return Result.WRONG_PARAMETERS.appendError("Pseudowire id can not be 0.");
    }
    res = checkIfPwExists(l2TunnelId, pending);
    if (res != Result.SUCCESS) {
        return res;
    }
    // remove and get the tunnel and the policy from the appropriate store
    // if null, return error.
    Versioned<L2Tunnel> l2TunnelVersioned = pending ? pendingL2TunnelStore.remove(Long.toString(l2TunnelId)) : l2TunnelStore.remove(Long.toString(l2TunnelId));
    Versioned<L2TunnelPolicy> l2TunnelPolicyVersioned = pending ? pendingL2PolicyStore.remove(Long.toString(l2TunnelId)) : l2PolicyStore.remove(Long.toString(l2TunnelId));
    if ((l2TunnelVersioned == null) || (l2TunnelPolicyVersioned == null)) {
        log.warn("Removal process : Policy and/or tunnel missing for tunnel id {}", l2TunnelId);
        return Result.INTERNAL_ERROR.appendError("Policy and/or tunnel missing for pseudowire!");
    }
    L2TunnelDescription pwToRemove = new DefaultL2TunnelDescription(l2TunnelVersioned.value(), l2TunnelPolicyVersioned.value());
    if (pending) {
        // in pending state
        return Result.SUCCESS;
    }
    // remove flows/groups involving with this pseudowire
    if (tearDownFirst) {
        log.info("Removal process : Tearing down forward direction of pseudowire {}", l2TunnelId);
        VlanId egressVlan = determineEgressVlan(pwToRemove.l2TunnelPolicy().cP1OuterTag(), pwToRemove.l2TunnelPolicy().cP1InnerTag(), pwToRemove.l2TunnelPolicy().cP2OuterTag(), pwToRemove.l2TunnelPolicy().cP2InnerTag());
        deletePolicy(l2TunnelId, pwToRemove.l2TunnelPolicy().cP1(), pwToRemove.l2TunnelPolicy().cP1InnerTag(), pwToRemove.l2TunnelPolicy().cP1OuterTag(), egressVlan, fwdInitNextFuture, FWD);
        fwdInitNextFuture.thenAcceptAsync(status -> {
            if (status == null) {
                // Finally we will tear down the pseudo wire.
                tearDownPseudoWireInit(l2TunnelId, pwToRemove.l2TunnelPolicy().cP1(), fwdTermNextFuture, FWD);
            }
        });
        fwdTermNextFuture.thenAcceptAsync(status -> {
            if (status == null) {
                tearDownPseudoWireTerm(pwToRemove.l2Tunnel(), pwToRemove.l2TunnelPolicy().cP2(), null, FWD);
            }
        });
    }
    if (tearDownSecond) {
        log.info("Removal process : Tearing down reverse direction of pseudowire {}", l2TunnelId);
        VlanId egressVlan = determineEgressVlan(pwToRemove.l2TunnelPolicy().cP2OuterTag(), pwToRemove.l2TunnelPolicy().cP2InnerTag(), pwToRemove.l2TunnelPolicy().cP1OuterTag(), pwToRemove.l2TunnelPolicy().cP1InnerTag());
        // We do the same operations on the reverse side.
        deletePolicy(l2TunnelId, pwToRemove.l2TunnelPolicy().cP2(), pwToRemove.l2TunnelPolicy().cP2InnerTag(), pwToRemove.l2TunnelPolicy().cP2OuterTag(), egressVlan, revInitNextFuture, REV);
        revInitNextFuture.thenAcceptAsync(status -> {
            if (status == null) {
                tearDownPseudoWireInit(l2TunnelId, pwToRemove.l2TunnelPolicy().cP2(), revTermNextFuture, REV);
            }
        });
        revTermNextFuture.thenAcceptAsync(status -> {
            if (status == null) {
                tearDownPseudoWireTerm(pwToRemove.l2Tunnel(), pwToRemove.l2TunnelPolicy().cP1(), null, REV);
            }
        });
    }
    return Result.SUCCESS;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) ObjectiveError(org.onosproject.net.flowobjective.ObjectiveError) VlanId(org.onlab.packet.VlanId) Result(org.onosproject.segmentrouting.pwaas.L2TunnelHandler.Result)

Example 17 with ObjectiveError

use of org.onosproject.net.flowobjective.ObjectiveError in project trellis-control by opennetworkinglab.

the class DefaultL2TunnelHandler method deletePolicy.

/**
 * Deletes a given policy using the parameter supplied.
 *
 * @param tunnelId     the tunnel id
 * @param ingress      the ingress point
 * @param ingressInner the ingress inner vlan id
 * @param ingressOuter the ingress outer vlan id
 * @param future       to perform the async operation
 * @param direction    the direction: forward or reverse
 */
private void deletePolicy(long tunnelId, ConnectPoint ingress, VlanId ingressInner, VlanId ingressOuter, VlanId egressVlan, CompletableFuture<ObjectiveError> future, Direction direction) {
    String key = generateKey(tunnelId, direction);
    if (!l2InitiationNextObjStore.containsKey(key)) {
        log.error("Abort delete of policy for tunnel {}: next does not exist in the store", tunnelId);
        if (future != null) {
            future.complete(null);
        }
        return;
    }
    NextObjective nextObjective = l2InitiationNextObjStore.get(key).value();
    int nextId = nextObjective.id();
    List<Objective> objectives = Lists.newArrayList();
    // We create the forwarding objective.
    ForwardingObjective.Builder fwdBuilder = createInitFwdObjective(tunnelId, ingress.port(), nextId);
    ObjectiveContext context = new ObjectiveContext() {

        @Override
        public void onSuccess(Objective objective) {
            log.debug("Previous fwdObj for policy {} removed", tunnelId);
            if (future != null) {
                future.complete(null);
            }
        }

        @Override
        public void onError(Objective objective, ObjectiveError error) {
            log.error("Failed to remove previous fwdObj for policy {}: {}", tunnelId, error);
            if (future != null) {
                future.complete(error);
            }
        }
    };
    objectives.add(fwdBuilder.remove(context));
    // We create the filtering objective to define the
    // permit traffic in the switch
    FilteringObjective.Builder filtBuilder = createFiltObjective(ingress.port(), ingressInner, ingressOuter);
    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder().setTunnelId(tunnelId).setVlanId(egressVlan);
    filtBuilder.withMeta(treatment.build());
    context = new DefaultObjectiveContext((objective) -> log.debug("FilterObj for policy {} revoked", tunnelId), (objective, error) -> log.warn("Failed to revoke filterObj for policy {}", tunnelId, error));
    objectives.add(filtBuilder.remove(context));
    for (Objective objective : objectives) {
        if (objective instanceof ForwardingObjective) {
            srManager.flowObjectiveService.forward(ingress.deviceId(), (ForwardingObjective) objective);
        } else {
            srManager.flowObjectiveService.filter(ingress.deviceId(), (FilteringObjective) objective);
        }
    }
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException) ConsistentMap(org.onosproject.store.service.ConsistentMap) REV(org.onosproject.segmentrouting.pwaas.L2TunnelHandler.Direction.REV) PortNumber(org.onosproject.net.PortNumber) LoggerFactory(org.slf4j.LoggerFactory) DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) Link(org.onosproject.net.Link) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) PwaasUtil(org.onosproject.segmentrouting.pwaas.PwaasUtil) ObjectiveError(org.onosproject.net.flowobjective.ObjectiveError) Ethernet(org.onlab.packet.Ethernet) FWD(org.onosproject.segmentrouting.pwaas.L2TunnelHandler.Direction.FWD) NextObjective(org.onosproject.net.flowobjective.NextObjective) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) Result(org.onosproject.segmentrouting.pwaas.L2TunnelHandler.Result) DefaultLink(org.onosproject.net.DefaultLink) Serializer(org.onosproject.store.service.Serializer) ImmutableMap(com.google.common.collect.ImmutableMap) DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) SRLinkWeigher(org.onosproject.segmentrouting.SRLinkWeigher) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) Set(java.util.Set) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) Collectors(java.util.stream.Collectors) Versioned(org.onosproject.store.service.Versioned) List(java.util.List) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) Path(org.onosproject.net.Path) TERMINATION(org.onosproject.segmentrouting.pwaas.L2TunnelHandler.Pipeline.TERMINATION) DeviceId(org.onosproject.net.DeviceId) DistributedLock(org.onosproject.store.service.DistributedLock) RandomUtils(org.apache.commons.lang3.RandomUtils) Iterables(com.google.common.collect.Iterables) StorageException(org.onosproject.store.service.StorageException) CompletableFuture(java.util.concurrent.CompletableFuture) KryoNamespace(org.onlab.util.KryoNamespace) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SegmentRoutingService(org.onosproject.segmentrouting.SegmentRoutingService) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) VERSATILE(org.onosproject.net.flowobjective.ForwardingObjective.Flag.VERSATILE) Criteria(org.onosproject.net.flow.criteria.Criteria) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) SegmentRoutingManager(org.onosproject.segmentrouting.SegmentRoutingManager) Logger(org.slf4j.Logger) MplsLabel(org.onlab.packet.MplsLabel) INITIATION(org.onosproject.segmentrouting.pwaas.L2TunnelHandler.Pipeline.INITIATION) VlanId(org.onlab.packet.VlanId) Objective(org.onosproject.net.flowobjective.Objective) MacAddress(org.onlab.packet.MacAddress) LinkWeigher(org.onosproject.net.topology.LinkWeigher) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) ObjectiveError(org.onosproject.net.flowobjective.ObjectiveError) 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) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective)

Example 18 with ObjectiveError

use of org.onosproject.net.flowobjective.ObjectiveError in project trellis-control by opennetworkinglab.

the class XconnectManager method revokeFwd.

/**
 * Revokes bridging forwarding objectives for given XConnect.
 *
 * @param key       XConnect store key
 * @param nextId    next objective id
 * @param fwdFuture completable future for this forwarding objective operation
 */
private void revokeFwd(XconnectKey key, int nextId, CompletableFuture<ObjectiveError> fwdFuture) {
    ForwardingObjective.Builder fwdObjBuilder = fwdObjBuilder(key, nextId);
    ObjectiveContext context = new ObjectiveContext() {

        @Override
        public void onSuccess(Objective objective) {
            log.debug("Previous FwdObj for {} removed", key);
            if (fwdFuture != null) {
                fwdFuture.complete(null);
            }
        }

        @Override
        public void onError(Objective objective, ObjectiveError error) {
            log.warn("Failed to remove previous FwdObj for {}: {}", key, error);
            if (fwdFuture != null) {
                fwdFuture.complete(error);
            }
        }
    };
    flowObjectiveService.forward(key.deviceId(), fwdObjBuilder.remove(context));
}
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) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) ObjectiveError(org.onosproject.net.flowobjective.ObjectiveError)

Example 19 with ObjectiveError

use of org.onosproject.net.flowobjective.ObjectiveError in project trellis-control by opennetworkinglab.

the class RoutingRulePopulator method populateArpNdpPunts.

/**
 * Creates forwarding objectives to punt ARP and NDP packets, to the controller.
 * Furthermore, these are applied only by the master instance. Deferred actions
 * are not cleared such that packets can be flooded in the cross connect use case
 *
 * @param deviceId the switch dpid for the router
 */
void populateArpNdpPunts(DeviceId deviceId) {
    // We are not the master just skip.
    if (!srManager.shouldProgram(deviceId)) {
        log.debug("Not installing ARP/NDP punts - not handling programming for dev:{} ", deviceId);
        return;
    }
    ForwardingObjective fwdObj;
    // We punt all ARP packets towards the controller.
    fwdObj = arpFwdObjective(null, true, ARP_NDP_PRIORITY).add(new ObjectiveContext() {

        @Override
        public void onError(Objective objective, ObjectiveError error) {
            log.warn("Failed to install forwarding objective to punt ARP to {}: {}", deviceId, error);
        }
    });
    srManager.flowObjectiveService.forward(deviceId, fwdObj);
    if (isIpv6Configured(deviceId)) {
        // We punt all NDP packets towards the controller.
        ndpFwdObjective(null, true, ARP_NDP_PRIORITY).forEach(builder -> {
            ForwardingObjective obj = builder.add(new ObjectiveContext() {

                @Override
                public void onError(Objective objective, ObjectiveError error) {
                    log.warn("Failed to install forwarding objective to punt NDP to {}: {}", deviceId, error);
                }
            });
            srManager.flowObjectiveService.forward(deviceId, obj);
        });
    }
    srManager.getPairLocalPort(deviceId).ifPresent(port -> {
        ForwardingObjective pairFwdObj;
        // Do not punt ARP packets from pair port
        pairFwdObj = arpFwdObjective(port, false, PacketPriority.CONTROL.priorityValue() + 1).add(new ObjectiveContext() {

            @Override
            public void onError(Objective objective, ObjectiveError error) {
                log.warn("Failed to install forwarding objective to ignore ARP to {}: {}", deviceId, error);
            }
        });
        srManager.flowObjectiveService.forward(deviceId, pairFwdObj);
        if (isIpv6Configured(deviceId)) {
            // Do not punt NDP packets from pair port
            ndpFwdObjective(port, false, PacketPriority.CONTROL.priorityValue() + 1).forEach(builder -> {
                ForwardingObjective obj = builder.add(new ObjectiveContext() {

                    @Override
                    public void onError(Objective objective, ObjectiveError error) {
                        log.warn("Failed to install forwarding objective to ignore ARP to {}: {}", deviceId, error);
                    }
                });
                srManager.flowObjectiveService.forward(deviceId, obj);
            });
            // Do not forward DAD packets from pair port
            pairFwdObj = dad6FwdObjective(port, PacketPriority.CONTROL.priorityValue() + 2).add(new ObjectiveContext() {

                @Override
                public void onError(Objective objective, ObjectiveError error) {
                    log.warn("Failed to install forwarding objective to drop DAD to {}: {}", deviceId, error);
                }
            });
            srManager.flowObjectiveService.forward(deviceId, pairFwdObj);
        }
    });
}
Also used : ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) Objective(org.onosproject.net.flowobjective.Objective) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) ObjectiveError(org.onosproject.net.flowobjective.ObjectiveError)

Example 20 with ObjectiveError

use of org.onosproject.net.flowobjective.ObjectiveError in project fabric-tna by stratum.

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() != NextObjective.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)

Aggregations

ObjectiveError (org.onosproject.net.flowobjective.ObjectiveError)20 ForwardingObjective (org.onosproject.net.flowobjective.ForwardingObjective)17 Objective (org.onosproject.net.flowobjective.Objective)17 ObjectiveContext (org.onosproject.net.flowobjective.ObjectiveContext)14 DefaultForwardingObjective (org.onosproject.net.flowobjective.DefaultForwardingObjective)13 FilteringObjective (org.onosproject.net.flowobjective.FilteringObjective)11 NextObjective (org.onosproject.net.flowobjective.NextObjective)10 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)8 TrafficSelector (org.onosproject.net.flow.TrafficSelector)8 DefaultNextObjective (org.onosproject.net.flowobjective.DefaultNextObjective)8 List (java.util.List)7 Set (java.util.Set)7 CompletableFuture (java.util.concurrent.CompletableFuture)7 DeviceId (org.onosproject.net.DeviceId)7 DefaultFilteringObjective (org.onosproject.net.flowobjective.DefaultFilteringObjective)7 Logger (org.slf4j.Logger)7 Lists (com.google.common.collect.Lists)6 ExecutorService (java.util.concurrent.ExecutorService)6 Collectors (java.util.stream.Collectors)6 Ethernet (org.onlab.packet.Ethernet)6