Search in sources :

Example 11 with FilteringObjective

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));
}
Also used : DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) FilteringObjectiveJsonMatcher.matchesFilteringObjective(org.onosproject.codec.impl.FilteringObjectiveJsonMatcher.matchesFilteringObjective) DefaultApplicationId(org.onosproject.core.DefaultApplicationId) ApplicationId(org.onosproject.core.ApplicationId) DefaultApplicationId(org.onosproject.core.DefaultApplicationId) Test(org.junit.Test)

Example 12 with FilteringObjective

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);
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DeviceId(org.onosproject.net.DeviceId) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) 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 13 with FilteringObjective

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);
}
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 14 with FilteringObjective

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);
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) DeviceId(org.onosproject.net.DeviceId) FlowObjectiveIntent(org.onosproject.net.intent.FlowObjectiveIntent) Intent(org.onosproject.net.intent.Intent) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) FlowObjectiveIntent(org.onosproject.net.intent.FlowObjectiveIntent) NetworkResource(org.onosproject.net.NetworkResource) 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) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective)

Example 15 with FilteringObjective

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

Aggregations

FilteringObjective (org.onosproject.net.flowobjective.FilteringObjective)36 DefaultFilteringObjective (org.onosproject.net.flowobjective.DefaultFilteringObjective)22 Test (org.junit.Test)21 ForwardingObjective (org.onosproject.net.flowobjective.ForwardingObjective)17 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)15 NextObjective (org.onosproject.net.flowobjective.NextObjective)15 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)14 Objective (org.onosproject.net.flowobjective.Objective)13 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)10 FlowRule (org.onosproject.net.flow.FlowRule)10 TrafficSelector (org.onosproject.net.flow.TrafficSelector)10 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)9 FlowObjectiveIntent (org.onosproject.net.intent.FlowObjectiveIntent)9 Intent (org.onosproject.net.intent.Intent)9 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)7 LinkCollectionIntent (org.onosproject.net.intent.LinkCollectionIntent)7 DefaultLink (org.onosproject.net.DefaultLink)6 DeviceId (org.onosproject.net.DeviceId)6 Link (org.onosproject.net.Link)6 PortCriterion (org.onosproject.net.flow.criteria.PortCriterion)6