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;
}
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));
}
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);
}
}
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());
}
});
}
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());
}
});
}
Aggregations