Search in sources :

Example 1 with NextObjective

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

the class FibInstallerTest method testRouteUpdate.

/**
 * Tests updating a route.
 *
 * We verify that the flowObjectiveService records the correct state and that the
 * correct flow is submitted to the flowObjectiveService.
 */
@Test
public void testRouteUpdate() {
    // Firstly add a route
    testRouteAdd();
    reset(flowObjectiveService);
    ResolvedRoute oldRoute = createRoute(PREFIX1, NEXT_HOP1, MAC1);
    ResolvedRoute route = createRoute(PREFIX1, NEXT_HOP2, MAC2);
    // Create the next objective
    NextObjective nextObjective = createNextObjective(MAC2, MAC2, SW1_ETH2.port(), VLAN1, true);
    flowObjectiveService.next(DEVICE_ID, nextObjective);
    // Create the flow objective
    ForwardingObjective fwd = createForwardingObjective(PREFIX1, true);
    flowObjectiveService.forward(DEVICE_ID, fwd);
    EasyMock.expectLastCall().once();
    setUpFlowObjectiveService();
    // Send in the update event
    routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_UPDATED, route, oldRoute));
    verify(flowObjectiveService);
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) RouteEvent(org.onosproject.routeservice.RouteEvent) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) ResolvedRoute(org.onosproject.routeservice.ResolvedRoute) Test(org.junit.Test)

Example 2 with NextObjective

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

the class PortLoadBalancerManager method onErrorHandler.

private void onErrorHandler(NextObjective nextObjective, PortLoadBalancerId portLoadBalancerId) {
    // There was a failure
    PortLoadBalancerData portLoadBalancerData = new PortLoadBalancerData(portLoadBalancerId);
    // send FAILED event;
    switch(nextObjective.op()) {
        case ADD:
            // If ADD is failing apps do not know the next id; let's update the store
            portLoadBalancerNextStore.remove(portLoadBalancerId);
            portLoadBalancerResStore.remove(portLoadBalancerId);
            portLoadBalancerStore.remove(portLoadBalancerId);
            post(new PortLoadBalancerEvent(PortLoadBalancerEvent.Type.FAILED, portLoadBalancerData, portLoadBalancerData));
            break;
        case ADD_TO_EXISTING:
            // If ADD_TO_EXISTING is failing let's remove the failed ports
            Collection<PortNumber> addedPorts = nextObjective.next().stream().flatMap(t -> t.allInstructions().stream()).filter(i -> i.type() == Instruction.Type.OUTPUT).map(i -> ((Instructions.OutputInstruction) i).port()).collect(Collectors.toList());
            portLoadBalancerStore.compute(portLoadBalancerId, (key, value) -> {
                if (value != null && value.ports() != null && !value.ports().isEmpty()) {
                    value.ports().removeAll(addedPorts);
                }
                return value;
            });
            portLoadBalancerData.setNextId(nextObjective.id());
            post(new PortLoadBalancerEvent(PortLoadBalancerEvent.Type.FAILED, portLoadBalancerData, portLoadBalancerData));
            break;
        case REMOVE_FROM_EXISTING:
            // If REMOVE_TO_EXISTING is failing let's re-add the failed ports
            Collection<PortNumber> removedPorts = nextObjective.next().stream().flatMap(t -> t.allInstructions().stream()).filter(i -> i.type() == Instruction.Type.OUTPUT).map(i -> ((Instructions.OutputInstruction) i).port()).collect(Collectors.toList());
            portLoadBalancerStore.compute(portLoadBalancerId, (key, value) -> {
                if (value != null && value.ports() != null) {
                    value.ports().addAll(removedPorts);
                }
                return value;
            });
            portLoadBalancerData.setNextId(nextObjective.id());
            post(new PortLoadBalancerEvent(PortLoadBalancerEvent.Type.FAILED, portLoadBalancerData, portLoadBalancerData));
            break;
        case VERIFY:
        case REMOVE:
            // If ADD/REMOVE_TO_EXISTING, REMOVE and VERIFY are failing let's send
            // also the info about the next id
            portLoadBalancerData.setNextId(nextObjective.id());
            post(new PortLoadBalancerEvent(PortLoadBalancerEvent.Type.FAILED, portLoadBalancerData, portLoadBalancerData));
            break;
        default:
            break;
    }
}
Also used : ConsistentMap(org.onosproject.store.service.ConsistentMap) CoreService(org.onosproject.core.CoreService) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ObjectiveError(org.onosproject.net.flowobjective.ObjectiveError) StorageService(org.onosproject.store.service.StorageService) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) NextObjective(org.onosproject.net.flowobjective.NextObjective) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) MastershipService(org.onosproject.mastership.MastershipService) NodeId(org.onosproject.cluster.NodeId) Serializer(org.onosproject.store.service.Serializer) ImmutableMap(com.google.common.collect.ImmutableMap) Deactivate(org.osgi.service.component.annotations.Deactivate) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Executors(java.util.concurrent.Executors) PortLoadBalancerId(org.onosproject.portloadbalancer.api.PortLoadBalancerId) Versioned(org.onosproject.store.service.Versioned) PortLoadBalancerData(org.onosproject.portloadbalancer.api.PortLoadBalancerData) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) DeviceEvent(org.onosproject.net.device.DeviceEvent) ClusterService(org.onosproject.cluster.ClusterService) DeviceId(org.onosproject.net.DeviceId) PortLoadBalancer(org.onosproject.portloadbalancer.api.PortLoadBalancer) PortLoadBalancerMode(org.onosproject.portloadbalancer.api.PortLoadBalancerMode) DefaultNextTreatment(org.onosproject.net.flowobjective.DefaultNextTreatment) PortLoadBalancerAdminService(org.onosproject.portloadbalancer.api.PortLoadBalancerAdminService) PortLoadBalancerService(org.onosproject.portloadbalancer.api.PortLoadBalancerService) KryoNamespace(org.onlab.util.KryoNamespace) MapEventListener(org.onosproject.store.service.MapEventListener) FlowObjectiveService(org.onosproject.net.flowobjective.FlowObjectiveService) Component(org.osgi.service.component.annotations.Component) TrafficSelector(org.onosproject.net.flow.TrafficSelector) Activate(org.osgi.service.component.annotations.Activate) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) ExecutorService(java.util.concurrent.ExecutorService) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) DeviceListener(org.onosproject.net.device.DeviceListener) Instructions(org.onosproject.net.flow.instructions.Instructions) Logger(org.slf4j.Logger) PortLoadBalancerEvent(org.onosproject.portloadbalancer.api.PortLoadBalancerEvent) Instruction(org.onosproject.net.flow.instructions.Instruction) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) PortLoadBalancerListener(org.onosproject.portloadbalancer.api.PortLoadBalancerListener) MapEvent(org.onosproject.store.service.MapEvent) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Objective(org.onosproject.net.flowobjective.Objective) Reference(org.osgi.service.component.annotations.Reference) LeadershipService(org.onosproject.cluster.LeadershipService) PortLoadBalancerData(org.onosproject.portloadbalancer.api.PortLoadBalancerData) PortLoadBalancerEvent(org.onosproject.portloadbalancer.api.PortLoadBalancerEvent) PortNumber(org.onosproject.net.PortNumber)

Example 3 with NextObjective

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

the class VirtualNetworkFlowObjectiveManagerTest method nextObjective.

/**
 * Tests adding a next objective.
 */
@Test
public void nextObjective() {
    TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
    NextObjective nextObjective = DefaultNextObjective.builder().withId(service1.allocateNextId()).fromApp(NetTestTools.APP_ID).addTreatment(treatment).withType(NextObjective.Type.BROADCAST).makePermanent().add(new ObjectiveContext() {

        @Override
        public void onSuccess(Objective objective) {
            assertEquals("1 next map entry expected", 1, service1.getNextMappings().size());
            assertEquals("0 next map entry expected", 0, service2.getNextMappings().size());
        }
    });
    service1.next(VDID1, nextObjective);
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) 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) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Test(org.junit.Test)

Example 4 with NextObjective

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

the class IntentFilter method getFlowEntries.

/**
 * Finds all flow entries created by FlowObjectiveIntent.
 *
 * @param intent FlowObjectiveIntent Object
 * @return set of flow entries created by FlowObjectiveIntent
 */
private List<FlowEntry> getFlowEntries(FlowObjectiveIntent intent) {
    List<FlowEntry> flowEntries = new ArrayList<>();
    Iterator<Objective> objectives = intent.objectives().iterator();
    Iterator<DeviceId> devices = intent.devices().iterator();
    DefaultNextObjective nextObjective = null;
    DefaultForwardingObjective forwardObjective;
    Objective objective;
    DeviceId deviceId;
    FlowEntry flowEntry;
    while (objectives.hasNext()) {
        objective = objectives.next();
        deviceId = devices.next();
        if (objective instanceof NextObjective) {
            nextObjective = (DefaultNextObjective) objective;
        } else if (objective instanceof ForwardingObjective) {
            forwardObjective = (DefaultForwardingObjective) objective;
            FlowRule.Builder builder = DefaultFlowRule.builder().forDevice(deviceId).withSelector(forwardObjective.selector()).withPriority(intent.priority()).fromApp(intent.appId()).makePermanent();
            if (nextObjective != null) {
                builder.withTreatment(nextObjective.next().iterator().next());
            }
            FlowRule flowRule = builder.build();
            flowEntry = getFlowEntry(flowRule);
            if (flowEntry != null) {
                flowEntries.add(flowEntry);
            }
        }
    }
    return flowEntries;
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) DeviceId(org.onosproject.net.DeviceId) ArrayList(java.util.ArrayList) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) Objective(org.onosproject.net.flowobjective.Objective) DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) FlowEntry(org.onosproject.net.flow.FlowEntry) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective)

Example 5 with NextObjective

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

the class NextObjectiveCodec method decode.

@Override
public NextObjective decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    CoreService coreService = context.getService(CoreService.class);
    final JsonCodec<TrafficSelector> trafficSelectorCodec = context.codec(TrafficSelector.class);
    final JsonCodec<TrafficTreatment> trafficTreatmentCodec = context.codec(TrafficTreatment.class);
    ObjectiveCodecHelper och = new ObjectiveCodecHelper();
    DefaultNextObjective.Builder baseBuilder = DefaultNextObjective.builder();
    final DefaultNextObjective.Builder builder = (DefaultNextObjective.Builder) och.decode(json, baseBuilder, context);
    // decode id
    JsonNode idJson = json.get(ID);
    checkNotNull(idJson);
    builder.withId(idJson.asInt());
    // decode application id
    JsonNode appIdJson = json.get(APP_ID);
    String appId = appIdJson != null ? appIdJson.asText() : REST_APP_ID;
    builder.fromApp(coreService.registerApplication(appId));
    // decode type
    String typeStr = nullIsIllegal(json.get(TYPE), TYPE + MISSING_MEMBER_MESSAGE).asText();
    switch(typeStr) {
        case "HASHED":
            builder.withType(NextObjective.Type.HASHED);
            break;
        case "BROADCAST":
            builder.withType(NextObjective.Type.BROADCAST);
            break;
        case "FAILOVER":
            builder.withType(NextObjective.Type.FAILOVER);
            break;
        case "SIMPLE":
            builder.withType(NextObjective.Type.SIMPLE);
            break;
        default:
            throw new IllegalArgumentException("The requested type " + typeStr + " is not defined for NextObjective.");
    }
    // decode treatments
    JsonNode treatmentsJson = json.get(TREATMENTS);
    checkNotNull(treatmentsJson);
    if (treatmentsJson != null) {
        IntStream.range(0, treatmentsJson.size()).forEach(i -> {
            ObjectNode treatmentJson = get(treatmentsJson, i);
            JsonNode weightJson = treatmentJson.get(WEIGHT);
            int weight = (weightJson != null) ? weightJson.asInt() : NextTreatment.DEFAULT_WEIGHT;
            builder.addTreatment(DefaultNextTreatment.of(trafficTreatmentCodec.decode(treatmentJson, context), weight));
        });
    }
    // decode meta
    JsonNode metaJson = json.get(META);
    if (metaJson != null) {
        TrafficSelector trafficSelector = trafficSelectorCodec.decode((ObjectNode) metaJson, context);
        builder.withMeta(trafficSelector);
    }
    // decode operation
    String opStr = nullIsIllegal(json.get(OPERATION), OPERATION + MISSING_MEMBER_MESSAGE).asText();
    NextObjective nextObjective;
    switch(opStr) {
        case "ADD":
            nextObjective = builder.add();
            break;
        case "REMOVE":
            nextObjective = builder.remove();
            break;
        default:
            throw new IllegalArgumentException("The requested operation " + opStr + " is not defined for NextObjective.");
    }
    return nextObjective;
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CoreService(org.onosproject.core.CoreService) JsonNode(com.fasterxml.jackson.databind.JsonNode) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) TrafficSelector(org.onosproject.net.flow.TrafficSelector)

Aggregations

NextObjective (org.onosproject.net.flowobjective.NextObjective)51 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)35 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)34 DefaultNextObjective (org.onosproject.net.flowobjective.DefaultNextObjective)32 TrafficSelector (org.onosproject.net.flow.TrafficSelector)29 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)25 ForwardingObjective (org.onosproject.net.flowobjective.ForwardingObjective)24 Objective (org.onosproject.net.flowobjective.Objective)21 Test (org.junit.Test)19 FilteringObjective (org.onosproject.net.flowobjective.FilteringObjective)19 DeviceId (org.onosproject.net.DeviceId)17 PortNumber (org.onosproject.net.PortNumber)12 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)12 FlowRule (org.onosproject.net.flow.FlowRule)12 GroupBucket (org.onosproject.net.group.GroupBucket)12 GroupBuckets (org.onosproject.net.group.GroupBuckets)12 DefaultForwardingObjective (org.onosproject.net.flowobjective.DefaultForwardingObjective)11 GroupDescription (org.onosproject.net.group.GroupDescription)11 List (java.util.List)10 Set (java.util.Set)10