Search in sources :

Example 26 with ObjectiveContext

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

the class DefaultL2TunnelHandler method deployPseudoWireTerm.

/**
 * Handles the tunnel termination, which consists in the creation
 * of a forwarding objective and a next objective.
 *
 * @param l2Tunnel   the tunnel to terminate
 * @param egress     the egress point
 * @param egressVlan the expected vlan at egress
 * @param direction  the direction
 * @return the result of the operation
 */
private Result deployPseudoWireTerm(L2Tunnel l2Tunnel, ConnectPoint egress, VlanId egressVlan, Direction direction, boolean oneHop) {
    log.debug("Started deploying termination objectives for pseudowire {} , direction {}.", l2Tunnel.tunnelId(), direction == FWD ? "forward" : "reverse");
    // We create the group relative to the termination.
    NextObjective.Builder nextObjectiveBuilder = createNextObjective(TERMINATION, egress, null, l2Tunnel, egress.deviceId(), oneHop, egressVlan);
    if (nextObjectiveBuilder == null) {
        return INTERNAL_ERROR;
    }
    TrafficSelector metadata = DefaultTrafficSelector.builder().matchVlanId(egressVlan).build();
    nextObjectiveBuilder.withMeta(metadata);
    int nextId = srManager.flowObjectiveService.allocateNextId();
    if (nextId < 0) {
        log.warn("Not able to allocate a next id for initiation");
        return INTERNAL_ERROR;
    }
    nextObjectiveBuilder.withId(nextId);
    String key = generateKey(l2Tunnel.tunnelId(), direction);
    l2TerminationNextObjStore.put(key, nextObjectiveBuilder.add());
    ObjectiveContext context = new DefaultObjectiveContext((objective) -> log.debug("Termination l2 tunnel rule for {} populated", l2Tunnel.tunnelId()), (objective, error) -> {
        log.warn("Failed to populate termination l2 tunnel rule for {}: {}", l2Tunnel.tunnelId(), error);
        srManager.invalidateNextObj(objective.id());
    });
    NextObjective nextObjective = nextObjectiveBuilder.add(context);
    srManager.flowObjectiveService.next(egress.deviceId(), nextObjective);
    log.debug("Termination next objective for {} not found. Creating new NextObj with id={}", l2Tunnel.tunnelId(), nextObjective.id());
    // We create the flow relative to the termination.
    ForwardingObjective.Builder fwdBuilder = createTermFwdObjective(l2Tunnel.pwLabel(), l2Tunnel.tunnelId(), egress.port(), nextObjective.id());
    context = new DefaultObjectiveContext((objective) -> log.debug("FwdObj for tunnel termination {} populated", l2Tunnel.tunnelId()), (objective, error) -> log.warn("Failed to populate fwdrObj" + " for tunnel termination {} : {}", l2Tunnel.tunnelId(), error));
    srManager.flowObjectiveService.forward(egress.deviceId(), fwdBuilder.add(context));
    log.debug("Creating new FwdObj for termination NextObj with id={} for tunnel {}", nextId, l2Tunnel.tunnelId());
    return SUCCESS;
}
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) 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) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 27 with ObjectiveContext

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

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

the class FibInstaller method sendFilteringObjective.

private void sendFilteringObjective(boolean install, FilteringObjective.Builder fob, Interface intf) {
    ObjectiveContext context = new DefaultObjectiveContext((objective) -> log.info("Installed filter for interface {}", intf), (objective, error) -> log.error("Failed to install filter for interface {}: {}", intf, error));
    FilteringObjective filter = install ? fob.add(context) : fob.remove(context);
    flowObjectiveService.filter(deviceId, filter);
}
Also used : 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 29 with ObjectiveContext

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

the class VirtualNetworkFlowObjectiveManagerTest method filteringObjective.

/**
 * Tests adding a filtering objective.
 */
@Test
public void filteringObjective() {
    TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
    FilteringObjective filter = DefaultFilteringObjective.builder().fromApp(NetTestTools.APP_ID).withMeta(treatment).makePermanent().deny().addCondition(Criteria.matchEthType(12)).add(new ObjectiveContext() {

        @Override
        public void onSuccess(Objective objective) {
            assertEquals("1 flowrule entry expected", 1, flowRuleStore.getFlowRuleCount(vnet1.id()));
            assertEquals("0 flowrule entry expected", 0, flowRuleStore.getFlowRuleCount(vnet2.id()));
        }
    });
    service1.filter(VDID1, filter);
}
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) DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Test(org.junit.Test)

Example 30 with ObjectiveContext

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

the class VirtualNetworkFlowObjectiveManagerTest method forwardingObjective.

/**
 * Tests adding a forwarding objective.
 */
@Test
public void forwardingObjective() {
    TrafficSelector selector = DefaultTrafficSelector.emptySelector();
    TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
    ForwardingObjective forward = DefaultForwardingObjective.builder().fromApp(NetTestTools.APP_ID).withFlag(ForwardingObjective.Flag.SPECIFIC).withSelector(selector).withTreatment(treatment).makePermanent().add(new ObjectiveContext() {

        @Override
        public void onSuccess(Objective objective) {
            assertEquals("1 flowrule entry expected", 1, flowRuleStore.getFlowRuleCount(vnet1.id()));
            assertEquals("0 flowrule entry expected", 0, flowRuleStore.getFlowRuleCount(vnet2.id()));
        }
    });
    service1.forward(VDID1, forward);
}
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) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Test(org.junit.Test)

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