Search in sources :

Example 1 with NextTreatment

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

the class FabricPipeliner method getBucketToFlowMapping.

private Map<GroupBucket, FlowRule> getBucketToFlowMapping(NextObjective nextObjective) {
    Map<GroupBucket, FlowRule> mapping = Maps.newHashMap();
    NextObjective newNextObjective;
    ObjectiveTranslation result;
    FlowRule dummyFlow = getDummyFlow(nextObjective);
    FlowRule egFlow;
    GroupBucket groupBucket;
    GroupDescription group;
    for (NextTreatment nextTreatment : nextObjective.nextTreatments()) {
        newNextObjective = DefaultNextObjective.builder().withId(nextObjective.id()).withType(nextObjective.type()).fromApp(nextObjective.appId()).withMeta(nextObjective.meta()).addTreatment(nextTreatment).verify();
        result = nextTranslator.translate(newNextObjective);
        if ((result.groups().isEmpty() && result.flowRules().isEmpty()) || result.groups().size() > 1) {
            return Collections.emptyMap();
        }
        group = result.groups().iterator().next();
        egFlow = result.flowRules().stream().filter(flowRule -> flowRule.table().equals(FabricConstants.FABRIC_EGRESS_EGRESS_NEXT_EGRESS_VLAN)).findFirst().orElse(null);
        if (group.buckets().buckets().isEmpty() || group.buckets().buckets().size() > 1) {
            return Collections.emptyMap();
        }
        groupBucket = group.buckets().buckets().iterator().next();
        if (egFlow == null) {
            mapping.put(groupBucket, dummyFlow);
        } else {
            mapping.put(groupBucket, egFlow);
        }
    }
    return mapping;
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) GroupDescription(org.onosproject.net.group.GroupDescription) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) CoreService(org.onosproject.core.CoreService) PortNumber(org.onosproject.net.PortNumber) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ObjectiveError(org.onosproject.net.flowobjective.ObjectiveError) Ethernet(org.onlab.packet.Ethernet) FlowRuleService(org.onosproject.net.flow.FlowRuleService) SharedExecutors(org.onlab.util.SharedExecutors) PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) NextObjective(org.onosproject.net.flowobjective.NextObjective) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) PipelinerContext(org.onosproject.net.behaviour.PipelinerContext) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) Collection(java.util.Collection) PORT_TYPE_INTERNAL(org.onosproject.pipelines.fabric.impl.behaviour.Constants.PORT_TYPE_INTERNAL) Set(java.util.Set) FlowObjectiveStore(org.onosproject.net.flowobjective.FlowObjectiveStore) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) String.format(java.lang.String.format) Objects(java.util.Objects) List(java.util.List) FabricUtils.outputPort(org.onosproject.pipelines.fabric.impl.behaviour.FabricUtils.outputPort) FlowRule(org.onosproject.net.flow.FlowRule) GroupBuckets(org.onosproject.net.group.GroupBuckets) DeviceId(org.onosproject.net.DeviceId) GroupDescription(org.onosproject.net.group.GroupDescription) ONE(org.onosproject.pipelines.fabric.impl.behaviour.FabricInterpreter.ONE) Pipeliner(org.onosproject.net.behaviour.Pipeliner) FWD_IPV4_ROUTING(org.onosproject.pipelines.fabric.impl.behaviour.Constants.FWD_IPV4_ROUTING) NextTreatment(org.onosproject.net.flowobjective.NextTreatment) CompletableFuture(java.util.concurrent.CompletableFuture) DefaultGroup(org.onosproject.net.group.DefaultGroup) GroupBucket(org.onosproject.net.group.GroupBucket) KryoNamespace(org.onlab.util.KryoNamespace) NextGroup(org.onosproject.net.behaviour.NextGroup) GroupKey(org.onosproject.net.group.GroupKey) Group(org.onosproject.net.group.Group) ZERO(org.onosproject.pipelines.fabric.impl.behaviour.FabricInterpreter.ZERO) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ImmutableList(com.google.common.collect.ImmutableList) Criteria(org.onosproject.net.flow.criteria.Criteria) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) ExecutorService(java.util.concurrent.ExecutorService) FabricCapabilities(org.onosproject.pipelines.fabric.impl.behaviour.FabricCapabilities) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) SIMPLE(org.onosproject.net.flowobjective.NextObjective.Type.SIMPLE) FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) Logger(org.slf4j.Logger) GroupService(org.onosproject.net.group.GroupService) FabricConstants(org.onosproject.pipelines.fabric.FabricConstants) Maps(com.google.common.collect.Maps) IdNextTreatment(org.onosproject.net.flowobjective.IdNextTreatment) PiAction(org.onosproject.net.pi.runtime.PiAction) FabricPipeconfLoader(org.onosproject.pipelines.fabric.impl.FabricPipeconfLoader) AbstractFabricHandlerBehavior(org.onosproject.pipelines.fabric.impl.behaviour.AbstractFabricHandlerBehavior) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Objective(org.onosproject.net.flowobjective.Objective) Collections(java.util.Collections) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) NextTreatment(org.onosproject.net.flowobjective.NextTreatment) IdNextTreatment(org.onosproject.net.flowobjective.IdNextTreatment)

Example 2 with NextTreatment

use of org.onosproject.net.flowobjective.NextTreatment 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));
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) NextObjectiveJsonMatcher.matchesNextObjective(org.onosproject.codec.impl.NextObjectiveJsonMatcher.matchesNextObjective) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) NextTreatment(org.onosproject.net.flowobjective.NextTreatment) DefaultNextTreatment(org.onosproject.net.flowobjective.DefaultNextTreatment) Test(org.junit.Test)

Example 3 with NextTreatment

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

the class NextObjectiveJsonMatcher method matchesSafely.

@Override
protected boolean matchesSafely(JsonNode jsonNextObj, Description description) {
    ObjectiveJsonMatcher.matchesObjective(nextObjective).matchesSafely(jsonNextObj);
    // check id
    int jsonId = jsonNextObj.get("id").asInt();
    int id = nextObjective.id();
    if (jsonId != id) {
        description.appendText("id was " + jsonId);
        return false;
    }
    // check type
    String jsonType = jsonNextObj.get("type").asText();
    String type = nextObjective.type().toString();
    if (!jsonType.equals(type)) {
        description.appendText("type was " + jsonType);
        return false;
    }
    // check size of treatment array
    JsonNode jsonTreatments = jsonNextObj.get("treatments");
    if (jsonTreatments.size() != nextObjective.next().size()) {
        description.appendText("treatments size was " + jsonTreatments.size());
        return false;
    }
    // check the weight
    boolean result = true;
    List<NextTreatment> nt = new ArrayList(nextObjective.nextTreatments());
    for (int i = 0; i < jsonTreatments.size(); i++) {
        ObjectNode jsonTreatment = jsonTreatments.path(i).isObject() && !jsonTreatments.path(i).isNull() ? (ObjectNode) jsonTreatments.path(i) : null;
        int jsonWeight = jsonTreatment.get("weight").asInt();
        if (jsonWeight != nt.get(i).weight()) {
            description.appendText("weight of NextTreatment with index " + i + " was " + jsonWeight);
            result = false;
        }
    }
    if (!result) {
        return false;
    }
    return true;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) NextTreatment(org.onosproject.net.flowobjective.NextTreatment)

Example 4 with NextTreatment

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

the class NextObjectiveTranslator method defaultNextTreatments.

private List<DefaultNextTreatment> defaultNextTreatments(Collection<NextTreatment> nextTreatments, boolean strict) throws FabricPipelinerException {
    final List<DefaultNextTreatment> defaultNextTreatments = Lists.newArrayList();
    final List<NextTreatment> unsupportedNextTreatments = Lists.newArrayList();
    for (NextTreatment n : nextTreatments) {
        if (n.type() == NextTreatment.Type.TREATMENT) {
            defaultNextTreatments.add((DefaultNextTreatment) n);
        } else {
            unsupportedNextTreatments.add(n);
        }
    }
    if (strict && !unsupportedNextTreatments.isEmpty()) {
        throw new FabricPipelinerException(format("Unsupported NextTreatments: %s", unsupportedNextTreatments));
    }
    return defaultNextTreatments;
}
Also used : DefaultNextTreatment(org.onosproject.net.flowobjective.DefaultNextTreatment) NextTreatment(org.onosproject.net.flowobjective.NextTreatment) DefaultNextTreatment(org.onosproject.net.flowobjective.DefaultNextTreatment)

Aggregations

NextTreatment (org.onosproject.net.flowobjective.NextTreatment)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)2 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)2 DefaultNextObjective (org.onosproject.net.flowobjective.DefaultNextObjective)2 DefaultNextTreatment (org.onosproject.net.flowobjective.DefaultNextTreatment)2 NextObjective (org.onosproject.net.flowobjective.NextObjective)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ImmutableList (com.google.common.collect.ImmutableList)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Sets (com.google.common.collect.Sets)1 String.format (java.lang.String.format)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Set (java.util.Set)1