Search in sources :

Example 61 with NextObjective

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

the class NextObjectiveCodecTest method getNextObjective.

/**
 * Reads in a nextObjective from the given resource and decodes it.
 *
 * @param resourceName resource to use to read the JSON for the rule
 * @return decoded nextObjective
 * @throws IOException if processing the resource fails
 */
private NextObjective getNextObjective(String resourceName) throws IOException {
    InputStream jsonStream = NextObjectiveCodecTest.class.getResourceAsStream(resourceName);
    JsonNode json = context.mapper().readTree(jsonStream);
    assertThat(json, notNullValue());
    NextObjective nextObjective = nextObjectiveCodec.decode((ObjectNode) json, context);
    assertThat(nextObjective, notNullValue());
    return nextObjective;
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) NextObjectiveJsonMatcher.matchesNextObjective(org.onosproject.codec.impl.NextObjectiveJsonMatcher.matchesNextObjective) InputStream(java.io.InputStream) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 62 with NextObjective

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

the class NextObjectiveCodecTest method testNextObjectiveEncode.

/**
 * Tests encoding of a NextObjective object.
 */
@Test
public void testNextObjectiveEncode() {
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
    NextTreatment nextTreatment = DefaultNextTreatment.of(treatment, 5);
    NextObjective nextObj = DefaultNextObjective.builder().makePermanent().withType(NextObjective.Type.HASHED).fromApp(APP_ID).withPriority(60).withId(5).addTreatment(nextTreatment).add();
    ObjectNode nextObjJson = nextObjectiveCodec.encode(nextObj, context);
    assertThat(nextObjJson, matchesNextObjective(nextObj));
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) NextObjectiveJsonMatcher.matchesNextObjective(org.onosproject.codec.impl.NextObjectiveJsonMatcher.matchesNextObjective) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) NextTreatment(org.onosproject.net.flowobjective.NextTreatment) DefaultNextTreatment(org.onosproject.net.flowobjective.DefaultNextTreatment) Test(org.junit.Test)

Example 63 with NextObjective

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

the class FlowObjectiveWebResource method createNextObjective.

/**
 * Creates and installs a new next objective for the specified device.
 *
 * @param appId    application identifier
 * @param deviceId device identifier
 * @param stream   next objective JSON
 * @return status of the request - CREATED if the JSON is correct,
 * BAD_REQUEST if the JSON is invalid
 * @onos.rsModel NextObjective
 */
@POST
@Path("{deviceId}/next")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createNextObjective(@QueryParam("appId") String appId, @PathParam("deviceId") String deviceId, InputStream stream) {
    try {
        UriBuilder locationBuilder = null;
        ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
        validateDeviceId(deviceId, jsonTree);
        if (appId != null) {
            jsonTree.put("appId", appId);
        }
        DeviceId did = DeviceId.deviceId(deviceId);
        NextObjective nextObjective = codec(NextObjective.class).decode(jsonTree, this);
        flowObjectiveService.next(did, nextObjective);
        locationBuilder = uriInfo.getBaseUriBuilder().path("flowobjectives").path(did.toString()).path("next").path(Integer.toString(nextObjective.id()));
        return Response.created(locationBuilder.build()).build();
    } catch (IOException e) {
        throw new IllegalArgumentException(e);
    }
}
Also used : NextObjective(org.onosproject.net.flowobjective.NextObjective) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DeviceId(org.onosproject.net.DeviceId) IOException(java.io.IOException) UriBuilder(javax.ws.rs.core.UriBuilder) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 64 with NextObjective

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

the class PortLoadBalancerManager method revokePortLoadBalancer.

private void revokePortLoadBalancer(PortLoadBalancer portLoadBalancer) {
    DeviceId deviceId = portLoadBalancer.portLoadBalancerId().deviceId();
    if (!isLocalLeader(deviceId)) {
        log.debug("Not the leader of {}. Skip revokePortLoadBalancer {}", deviceId, portLoadBalancer.portLoadBalancerId());
        return;
    }
    portLoadBalancerProvExecutor.execute(() -> {
        Integer nextid = Versioned.valueOrNull(portLoadBalancerNextStore.get(portLoadBalancer.portLoadBalancerId()));
        if (nextid != null) {
            // Build a new context and remove old next objective
            PortLoadBalancerObjectiveContext context = new PortLoadBalancerObjectiveContext(portLoadBalancer.portLoadBalancerId());
            NextObjective nextObj = nextObjBuilder(portLoadBalancer.portLoadBalancerId(), portLoadBalancer.ports(), nextid).remove(context);
            // Finally submit and invalidate the store
            flowObjService.next(deviceId, nextObj);
            portLoadBalancerNextStore.remove(portLoadBalancer.portLoadBalancerId());
        } else {
            log.info("NextObj for {} does not exist. Skip revokePortLoadBalancer", portLoadBalancer.portLoadBalancerId());
        }
    });
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) DeviceId(org.onosproject.net.DeviceId)

Example 65 with NextObjective

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

the class PortLoadBalancerManager method populatePortLoadBalancer.

private void populatePortLoadBalancer(PortLoadBalancer portLoadBalancer) {
    DeviceId deviceId = portLoadBalancer.portLoadBalancerId().deviceId();
    if (!isLocalLeader(deviceId)) {
        log.debug("Not the leader of {}. Skip populatePortLoadBalancer {}", deviceId, portLoadBalancer.portLoadBalancerId());
        return;
    }
    portLoadBalancerProvExecutor.execute(() -> {
        Integer nextid = Versioned.valueOrNull(portLoadBalancerNextStore.get(portLoadBalancer.portLoadBalancerId()));
        if (nextid == null) {
            // Build a new context and new next objective
            PortLoadBalancerObjectiveContext context = new PortLoadBalancerObjectiveContext(portLoadBalancer.portLoadBalancerId());
            NextObjective nextObj = nextObjBuilder(portLoadBalancer.portLoadBalancerId(), portLoadBalancer.ports(), nextid).add(context);
            // Finally submit, store, and register the resource
            flowObjService.next(deviceId, nextObj);
            portLoadBalancerNextStore.put(portLoadBalancer.portLoadBalancerId(), nextObj.id());
        } else {
            log.info("NextObj for {} already exists. Skip populatePortLoadBalancer", portLoadBalancer.portLoadBalancerId());
        }
    });
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) DeviceId(org.onosproject.net.DeviceId)

Aggregations

NextObjective (org.onosproject.net.flowobjective.NextObjective)83 DefaultNextObjective (org.onosproject.net.flowobjective.DefaultNextObjective)57 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)56 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)55 TrafficSelector (org.onosproject.net.flow.TrafficSelector)51 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)47 ForwardingObjective (org.onosproject.net.flowobjective.ForwardingObjective)36 Objective (org.onosproject.net.flowobjective.Objective)31 ObjectiveContext (org.onosproject.net.flowobjective.ObjectiveContext)30 DeviceId (org.onosproject.net.DeviceId)29 PortNumber (org.onosproject.net.PortNumber)24 FilteringObjective (org.onosproject.net.flowobjective.FilteringObjective)24 DefaultObjectiveContext (org.onosproject.net.flowobjective.DefaultObjectiveContext)23 Set (java.util.Set)22 Test (org.junit.Test)22 List (java.util.List)21 Collectors (java.util.stream.Collectors)20 GroupBucket (org.onosproject.net.group.GroupBucket)19 GroupBuckets (org.onosproject.net.group.GroupBuckets)19 Lists (com.google.common.collect.Lists)18