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