Search in sources :

Example 1 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)

Example 2 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 3 with FilteringObjective

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

the class FilteringObjectiveCodec method decode.

@Override
public FilteringObjective decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    CoreService coreService = context.getService(CoreService.class);
    final JsonCodec<Criterion> criterionCodec = context.codec(Criterion.class);
    final JsonCodec<TrafficTreatment> trafficTreatmentCodec = context.codec(TrafficTreatment.class);
    ObjectiveCodecHelper och = new ObjectiveCodecHelper();
    DefaultFilteringObjective.Builder baseBuilder = DefaultFilteringObjective.builder();
    final DefaultFilteringObjective.Builder builder = (DefaultFilteringObjective.Builder) och.decode(json, baseBuilder, context);
    // 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 "PERMIT":
            builder.permit();
            break;
        case "DENY":
            builder.deny();
            break;
        default:
            throw new IllegalArgumentException("The requested type " + typeStr + " is not defined for FilteringObjective.");
    }
    // decode key
    JsonNode keyJson = json.get(KEY);
    if (keyJson != null) {
        Criterion key = criterionCodec.decode((ObjectNode) keyJson, context);
        builder.withKey(key);
    }
    // decode conditions
    JsonNode conditionsJson = json.get(CONDITIONS);
    checkNotNull(conditionsJson);
    if (conditionsJson != null) {
        IntStream.range(0, conditionsJson.size()).forEach(i -> {
            ObjectNode conditionJson = get(conditionsJson, i);
            builder.addCondition(criterionCodec.decode(conditionJson, context));
        });
    }
    // decode meta
    JsonNode metaJson = json.get(META);
    if (metaJson != null) {
        TrafficTreatment trafficTreatment = trafficTreatmentCodec.decode((ObjectNode) metaJson, context);
        builder.withMeta(trafficTreatment);
    }
    // decode operation
    String opStr = nullIsIllegal(json.get(OPERATION), OPERATION + MISSING_MEMBER_MESSAGE).asText();
    FilteringObjective filteringObjective;
    switch(opStr) {
        case "ADD":
            filteringObjective = builder.add();
            break;
        case "REMOVE":
            filteringObjective = builder.remove();
            break;
        default:
            throw new IllegalArgumentException("The requested operation " + opStr + " is not defined for FilteringObjective.");
    }
    return filteringObjective;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CoreService(org.onosproject.core.CoreService) DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) JsonNode(com.fasterxml.jackson.databind.JsonNode) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Criterion(org.onosproject.net.flow.criteria.Criterion) DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective)

Example 4 with FilteringObjective

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

the class FilteringObjectiveCodecTest method testFilteringObjectiveEncode.

/**
 * Tests encoding of a FilteringObjective object.
 */
@Test
public void testFilteringObjectiveEncode() {
    Criterion condition1 = Criteria.matchVlanId(VlanId.ANY);
    Criterion condition2 = Criteria.matchEthType((short) 0x8844);
    FilteringObjective filteringObj = DefaultFilteringObjective.builder().makePermanent().permit().fromApp(APP_ID).withPriority(60).addCondition(condition1).addCondition(condition2).add();
    // TODO: need to add test case for TrafficTreatment (META in filteringObj)
    ObjectNode filteringObjJson = filteringObjectiveCodec.encode(filteringObj, context);
    assertThat(filteringObjJson, matchesFilteringObjective(filteringObj));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Criterion(org.onosproject.net.flow.criteria.Criterion) DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) FilteringObjectiveJsonMatcher.matchesFilteringObjective(org.onosproject.codec.impl.FilteringObjectiveJsonMatcher.matchesFilteringObjective) Test(org.junit.Test)

Example 5 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)

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