use of org.onosproject.net.flowobjective.FilteringObjective in project onos by opennetworkinglab.
the class FilteringObjectiveCodecTest method testFilteringObjectiveDecode.
/**
* Test decoding of a FilteringObjective object.
*/
@Test
public void testFilteringObjectiveDecode() throws IOException {
ApplicationId appId = new DefaultApplicationId(0, SAMPLE_APP_ID);
expect(mockCoreService.registerApplication(SAMPLE_APP_ID)).andReturn(appId).anyTimes();
replay(mockCoreService);
FilteringObjective filteringObjective = getFilteringObjective("FilteringObjective.json");
assertThat(filteringObjective.type(), is(FilteringObjective.Type.PERMIT));
assertThat(filteringObjective.priority(), is(60));
assertThat(filteringObjective.timeout(), is(1));
assertThat(filteringObjective.op(), is(FilteringObjective.Operation.ADD));
assertThat(filteringObjective.permanent(), is(false));
}
use of org.onosproject.net.flowobjective.FilteringObjective in project onos by opennetworkinglab.
the class FlowObjectiveWebResource method createFilteringObjective.
/**
* Creates and installs a new filtering objective for the specified device.
*
* @param appId application identifier
* @param deviceId device identifier
* @param stream filtering objective JSON
* @return status of the request - CREATED if the JSON is correct,
* BAD_REQUEST if the JSON is invalid
* @onos.rsModel FilteringObjective
*/
@POST
@Path("{deviceId}/filter")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createFilteringObjective(@QueryParam("appId") String appId, @PathParam("deviceId") String deviceId, InputStream stream) {
try {
UriBuilder locationBuilder = null;
ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
validateDeviceId(deviceId, jsonTree);
if (appId != null) {
jsonTree.put("appId", appId);
}
DeviceId did = DeviceId.deviceId(deviceId);
FilteringObjective filteringObjective = codec(FilteringObjective.class).decode(jsonTree, this);
flowObjectiveService.filter(did, filteringObjective);
locationBuilder = uriInfo.getBaseUriBuilder().path("flowobjectives").path(did.toString()).path("filter").path(Integer.toString(filteringObjective.id()));
return Response.created(locationBuilder.build()).build();
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
}
use of org.onosproject.net.flowobjective.FilteringObjective 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);
}
use of org.onosproject.net.flowobjective.FilteringObjective in project onos by opennetworkinglab.
the class FlowObjectiveIntentInstallerTest method createFlowObjectiveIntents.
/**
* Creates flow objective Intents.
*
* @return the flow objective intents
*/
private List<Intent> createFlowObjectiveIntents() {
TrafficSelector selector = DefaultTrafficSelector.builder().matchInPort(CP1.port()).build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(CP2.port()).build();
FilteringObjective filt = DefaultFilteringObjective.builder().addCondition(selector.getCriterion(Criterion.Type.IN_PORT)).withPriority(DEFAULT_PRIORITY).fromApp(APP_ID).permit().add();
NextObjective next = DefaultNextObjective.builder().withMeta(selector).addTreatment(treatment).makePermanent().withPriority(DEFAULT_PRIORITY).fromApp(APP_ID).withType(NextObjective.Type.SIMPLE).withId(NEXT_ID_1).add();
ForwardingObjective fwd = DefaultForwardingObjective.builder().withSelector(selector).fromApp(APP_ID).withPriority(DEFAULT_PRIORITY).makePermanent().withFlag(ForwardingObjective.Flag.SPECIFIC).nextStep(NEXT_ID_1).add();
List<Objective> objectives = ImmutableList.of(filt, next, fwd);
List<DeviceId> deviceIds = ImmutableList.of(CP1.deviceId(), CP1.deviceId(), CP1.deviceId());
List<NetworkResource> resources = ImmutableList.of(CP1.deviceId());
Intent intent = new FlowObjectiveIntent(APP_ID, KEY1, deviceIds, objectives, resources, RG1);
return ImmutableList.of(intent);
}
use of org.onosproject.net.flowobjective.FilteringObjective 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);
}
Aggregations