Search in sources :

Example 6 with ObjectiveContext

use of org.onosproject.net.flowobjective.ObjectiveContext 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 7 with ObjectiveContext

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

the class AppConfigHandler method populateVRouter.

private void populateVRouter(DeviceId deviceId, Set<MacAddress> pendingAdd) {
    if (!isEdge(deviceId)) {
        return;
    }
    getVRouterFlowObjBuilders(pendingAdd).forEach(foBuilder -> {
        ObjectiveContext context = new DefaultObjectiveContext((objective) -> log.debug("vRouterMac filter for {} populated", pendingAdd), (objective, error) -> log.warn("Failed to populate vRouterMac filter for {}: {}", pendingAdd, error));
        srManager.flowObjectiveService.filter(deviceId, foBuilder.add(context));
    });
}
Also used : DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext)

Example 8 with ObjectiveContext

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

the class RoutingRulePopulator method updateDefaultRouteBlackhole.

private void updateDefaultRouteBlackhole(DeviceId deviceId, IpPrefix address, boolean install) {
    try {
        if (srManager.deviceConfiguration.isEdgeDevice(deviceId)) {
            TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder();
            if (address.isIp4()) {
                sbuilder.matchIPDst(address);
                sbuilder.matchEthType(EthType.EtherType.IPV4.ethType().toShort());
            } else {
                sbuilder.matchIPv6Dst(address);
                sbuilder.matchEthType(EthType.EtherType.IPV6.ethType().toShort());
            }
            TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
            tBuilder.wipeDeferred();
            ForwardingObjective.Builder fob = DefaultForwardingObjective.builder();
            fob.withFlag(Flag.SPECIFIC).withSelector(sbuilder.build()).withTreatment(tBuilder.build()).withPriority(getPriorityFromPrefix(address)).fromApp(srManager.appId).makePermanent();
            log.debug("{} blackhole forwarding objectives for dev: {}", install ? "Installing" : "Removing", deviceId);
            ObjectiveContext context = new DefaultObjectiveContext((objective) -> log.debug("Forward for {} {}", deviceId, install ? "installed" : "removed"), (objective, error) -> log.warn("Failed to {} forward for {}: {}", install ? "install" : "remove", deviceId, error));
            if (install) {
                srManager.flowObjectiveService.forward(deviceId, fob.add(context));
            } else {
                srManager.flowObjectiveService.forward(deviceId, fob.remove(context));
            }
        }
    } catch (DeviceConfigNotFoundException e) {
        log.info("Not populating blackhole for un-configured device {}", deviceId);
    }
}
Also used : DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Builder(org.onosproject.net.flowobjective.ForwardingObjective.Builder) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException)

Example 9 with ObjectiveContext

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

the class RoutingRulePopulator method revokeRoute.

/**
 * Removes IP rules for a route when the next hop is gone.
 * This method should not be invoked directly without going through DefaultRoutingHandler.
 *
 * @param deviceId device ID of the device that next hop attaches to
 * @param prefix IP prefix of the route
 * @param hostMac MAC address of the next hop
 * @param hostVlanId Vlan ID of the nexthop
 * @param outPort port that next hop attaches to
 * @param directHost host is of type direct or indirect
 * @return future that carries the flow objective if succeeded, null if otherwise
 */
CompletableFuture<Objective> revokeRoute(DeviceId deviceId, IpPrefix prefix, MacAddress hostMac, VlanId hostVlanId, PortNumber outPort, boolean directHost) {
    log.debug("Revoke IP table entry for route {} at {}:{}", prefix, deviceId, outPort);
    ForwardingObjective.Builder fwdBuilder;
    try {
        fwdBuilder = routingFwdObjBuilder(deviceId, prefix, hostMac, hostVlanId, outPort, null, null, directHost, true);
    } catch (DeviceConfigNotFoundException e) {
        log.warn(e.getMessage() + " Aborting revokeIpRuleForHost.");
        return CompletableFuture.completedFuture(null);
    }
    if (fwdBuilder == null) {
        log.warn("Aborting host routing table entries due " + "to error for dev:{} route:{}", deviceId, prefix);
        return CompletableFuture.completedFuture(null);
    }
    CompletableFuture<Objective> future = new CompletableFuture<>();
    ObjectiveContext context = new DefaultObjectiveContext((objective) -> {
        log.debug("IP rule for route {} revoked", prefix);
        future.complete(objective);
    }, (objective, error) -> {
        log.warn("Failed to revoke IP rule for route {}: {}", prefix, error);
        future.complete(null);
    });
    srManager.flowObjectiveService.forward(deviceId, fwdBuilder.remove(context));
    return future;
}
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) CompletableFuture(java.util.concurrent.CompletableFuture) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) Builder(org.onosproject.net.flowobjective.ForwardingObjective.Builder) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException)

Example 10 with ObjectiveContext

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

the class RoutingRulePopulator method populateBridging.

/**
 * Populate a bridging rule on given deviceId that matches given mac, given vlan and
 * output to given port.
 *
 * @param deviceId device ID
 * @param port port
 * @param mac mac address
 * @param vlanId VLAN ID
 * @return future that carries the flow objective if succeeded, null if otherwise
 */
CompletableFuture<Objective> populateBridging(DeviceId deviceId, PortNumber port, MacAddress mac, VlanId vlanId) {
    ForwardingObjective.Builder fob = bridgingFwdObjBuilder(deviceId, mac, vlanId, port, false);
    if (fob == null) {
        log.warn("Fail to build fwd obj for host {}/{}. Abort.", mac, vlanId);
        return CompletableFuture.completedFuture(null);
    }
    CompletableFuture<Objective> future = new CompletableFuture<>();
    ObjectiveContext context = new DefaultObjectiveContext((objective) -> {
        log.debug("Brigding rule for {}/{} populated", mac, vlanId);
        future.complete(objective);
    }, (objective, error) -> {
        log.warn("Failed to populate bridging rule for {}/{}: {}", mac, vlanId, error);
        future.complete(null);
    });
    srManager.flowObjectiveService.forward(deviceId, fob.add(context));
    return future;
}
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) CompletableFuture(java.util.concurrent.CompletableFuture) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) Builder(org.onosproject.net.flowobjective.ForwardingObjective.Builder) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective)

Aggregations

ObjectiveContext (org.onosproject.net.flowobjective.ObjectiveContext)69 DefaultObjectiveContext (org.onosproject.net.flowobjective.DefaultObjectiveContext)57 ForwardingObjective (org.onosproject.net.flowobjective.ForwardingObjective)45 DefaultForwardingObjective (org.onosproject.net.flowobjective.DefaultForwardingObjective)41 NextObjective (org.onosproject.net.flowobjective.NextObjective)41 DefaultNextObjective (org.onosproject.net.flowobjective.DefaultNextObjective)37 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)35 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)35 TrafficSelector (org.onosproject.net.flow.TrafficSelector)35 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)35 Objective (org.onosproject.net.flowobjective.Objective)34 ConnectPoint (org.onosproject.net.ConnectPoint)33 FilteringObjective (org.onosproject.net.flowobjective.FilteringObjective)27 DefaultFilteringObjective (org.onosproject.net.flowobjective.DefaultFilteringObjective)26 CompletableFuture (java.util.concurrent.CompletableFuture)21 MacAddress (org.onlab.packet.MacAddress)19 ObjectiveError (org.onosproject.net.flowobjective.ObjectiveError)19 DeviceId (org.onosproject.net.DeviceId)17 Set (java.util.Set)16 Lists (com.google.common.collect.Lists)15