Search in sources :

Example 46 with GroupBucket

use of org.onosproject.net.group.GroupBucket in project onos by opennetworkinglab.

the class GroupJsonMatcher method matchesSafely.

@Override
public boolean matchesSafely(JsonNode jsonGroup, Description description) {
    // check id
    String jsonGroupId = jsonGroup.get("id").asText();
    String groupId = group.id().id().toString();
    if (!jsonGroupId.equals(groupId)) {
        description.appendText("group id was " + jsonGroupId);
        return false;
    }
    // check state
    String jsonState = jsonGroup.get("state").asText();
    String state = group.state().toString();
    if (!jsonState.equals(state)) {
        description.appendText("state was " + jsonState);
        return false;
    }
    // check life
    long jsonLife = jsonGroup.get("life").asLong();
    long life = group.life();
    if (life != jsonLife) {
        description.appendText("life was " + jsonLife);
        return false;
    }
    // check bytes
    long jsonBytes = jsonGroup.get("bytes").asLong();
    long bytes = group.bytes();
    if (bytes != jsonBytes) {
        description.appendText("bytes was " + jsonBytes);
        return false;
    }
    // check packets
    long jsonPackets = jsonGroup.get("packets").asLong();
    long packets = group.packets();
    if (packets != jsonPackets) {
        description.appendText("packets was " + jsonPackets);
        return false;
    }
    // check size of bucket array
    JsonNode jsonBuckets = jsonGroup.get("buckets");
    if (jsonBuckets.size() != group.buckets().buckets().size()) {
        description.appendText("buckets size was " + jsonBuckets.size());
        return false;
    }
    // Check buckets
    for (GroupBucket bucket : group.buckets().buckets()) {
        boolean bucketFound = false;
        for (int bucketIndex = 0; bucketIndex < jsonBuckets.size(); bucketIndex++) {
            GroupBucketJsonMatcher bucketMatcher = GroupBucketJsonMatcher.matchesGroupBucket(bucket);
            if (bucketMatcher.matches(jsonBuckets.get(bucketIndex))) {
                bucketFound = true;
                break;
            }
        }
        if (!bucketFound) {
            description.appendText("bucket not found " + bucket.toString());
            return false;
        }
    }
    return true;
}
Also used : GroupBucket(org.onosproject.net.group.GroupBucket) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 47 with GroupBucket

use of org.onosproject.net.group.GroupBucket 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 48 with GroupBucket

use of org.onosproject.net.group.GroupBucket in project onos by opennetworkinglab.

the class GroupBucketEntryBuilder method build.

/**
 * Builds a GroupBuckets.
 *
 * @return GroupBuckets object, a list of GroupBuckets
 */
public GroupBuckets build() {
    List<GroupBucket> bucketList = Lists.newArrayList();
    for (OFBucket bucket : ofBuckets) {
        TrafficTreatment treatment = buildTreatment(bucket.getActions());
        // TODO: Use GroupBucketEntry
        GroupBucket groupBucket = null;
        switch(type) {
            case INDIRECT:
                groupBucket = DefaultGroupBucket.createIndirectGroupBucket(treatment);
                break;
            case SELECT:
                groupBucket = DefaultGroupBucket.createSelectGroupBucket(treatment, (short) bucket.getWeight());
                break;
            case FF:
                PortNumber port = PortNumber.portNumber(bucket.getWatchPort().getPortNumber());
                GroupId groupId = new GroupId(bucket.getWatchGroup().getGroupNumber());
                groupBucket = DefaultGroupBucket.createFailoverGroupBucket(treatment, port, groupId);
                break;
            case ALL:
                groupBucket = DefaultGroupBucket.createAllGroupBucket(treatment);
                break;
            default:
                log.error("Unsupported Group type : {}", type);
        }
        if (groupBucket != null) {
            bucketList.add(groupBucket);
        }
    }
    return new GroupBuckets(bucketList);
}
Also used : OFBucket(org.projectfloodlight.openflow.protocol.OFBucket) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) PortNumber(org.onosproject.net.PortNumber) GroupBuckets(org.onosproject.net.group.GroupBuckets) GroupId(org.onosproject.core.GroupId)

Example 49 with GroupBucket

use of org.onosproject.net.group.GroupBucket in project onos by opennetworkinglab.

the class OpenFlowGroupProvider method checkFailoverGroup.

/**
 * Checks whether the first live port in the failover group's bucket
 * has failed over.
 *
 * @param group       failover group to be checked for failover
 * @param id          device ID of switch whose port's status changed
 * @param portNumber  port number of port that was disabled
 * @return            whether the failover group experienced failover
 */
private boolean checkFailoverGroup(Group group, DeviceId id, PortNumber portNumber) {
    boolean portReached = false;
    boolean portEnabled = false;
    Iterator<GroupBucket> bIterator = group.buckets().buckets().iterator();
    GroupBucket bucket;
    while (bIterator.hasNext() && !portReached) {
        bucket = bIterator.next();
        if (deviceService.getPort(id, bucket.watchPort()).isEnabled()) {
            portEnabled = true;
        }
        if (bucket.watchPort().equals(portNumber)) {
            portReached = true;
        }
    }
    return portReached && !portEnabled;
}
Also used : GroupBucket(org.onosproject.net.group.GroupBucket)

Example 50 with GroupBucket

use of org.onosproject.net.group.GroupBucket in project onos by opennetworkinglab.

the class OpenFlowGroupProviderTest method addGroup.

@Test
public void addGroup() {
    GroupId groupId = new GroupId(1);
    List<GroupBucket> bucketList = Lists.newArrayList();
    TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
    builder.setOutput(PortNumber.portNumber(1));
    GroupBucket bucket = DefaultGroupBucket.createSelectGroupBucket(builder.build());
    bucketList.add(bucket);
    GroupBuckets buckets = new GroupBuckets(bucketList);
    List<GroupOperation> operationList = Lists.newArrayList();
    GroupOperation operation = GroupOperation.createAddGroupOperation(groupId, GroupDescription.Type.SELECT, buckets);
    operationList.add(operation);
    GroupOperations operations = new GroupOperations(operationList);
    provider.performGroupOperation(deviceId, operations);
    final Dpid dpid = Dpid.dpid(deviceId.uri());
    TestOpenFlowSwitch sw = (TestOpenFlowSwitch) controller.getSwitch(dpid);
    assertNotNull("Switch should not be nul", sw);
    assertNotNull("OFGroupMsg should not be null", sw.msg);
}
Also used : GroupOperations(org.onosproject.net.group.GroupOperations) Dpid(org.onosproject.openflow.controller.Dpid) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) GroupBuckets(org.onosproject.net.group.GroupBuckets) GroupOperation(org.onosproject.net.group.GroupOperation) GroupId(org.onosproject.core.GroupId) Test(org.junit.Test)

Aggregations

GroupBucket (org.onosproject.net.group.GroupBucket)108 GroupBuckets (org.onosproject.net.group.GroupBuckets)87 DefaultGroupBucket (org.onosproject.net.group.DefaultGroupBucket)75 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)66 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)66 DefaultGroupDescription (org.onosproject.net.group.DefaultGroupDescription)62 GroupKey (org.onosproject.net.group.GroupKey)62 DefaultGroupKey (org.onosproject.net.group.DefaultGroupKey)56 GroupDescription (org.onosproject.net.group.GroupDescription)55 ArrayList (java.util.ArrayList)42 Group (org.onosproject.net.group.Group)40 GroupId (org.onosproject.core.GroupId)35 PortNumber (org.onosproject.net.PortNumber)32 DefaultGroup (org.onosproject.net.group.DefaultGroup)26 List (java.util.List)21 DeviceId (org.onosproject.net.DeviceId)20 TrafficSelector (org.onosproject.net.flow.TrafficSelector)20 OfdpaGroupHandlerUtility.l2MulticastGroupKey (org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility.l2MulticastGroupKey)17 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)16 ArrayDeque (java.util.ArrayDeque)15