Search in sources :

Example 16 with DefaultGroup

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

the class OpenFlowGroupProvider method buildGroupMetrics.

private Collection<Group> buildGroupMetrics(DeviceId deviceId, OFGroupStatsReply groupStatsReply, OFGroupDescStatsReply groupDescStatsReply) {
    Map<Integer, Group> groups = Maps.newHashMap();
    Dpid dpid = Dpid.dpid(deviceId.uri());
    for (OFGroupDescStatsEntry entry : groupDescStatsReply.getEntries()) {
        int id = entry.getGroup().getGroupNumber();
        GroupId groupId = new GroupId(id);
        GroupDescription.Type type = getGroupType(entry.getGroupType());
        GroupBuckets buckets = new GroupBucketEntryBuilder(dpid, entry.getBuckets(), entry.getGroupType(), driverService).build();
        DefaultGroup group = new DefaultGroup(groupId, deviceId, type, buckets);
        groups.put(id, group);
    }
    if (groupStatsReply == null) {
        return groups.values();
    }
    for (OFGroupStatsEntry entry : groupStatsReply.getEntries()) {
        int groupId = entry.getGroup().getGroupNumber();
        DefaultGroup group = (DefaultGroup) groups.get(groupId);
        if (group != null) {
            group.setBytes(entry.getByteCount().getValue());
            group.setLife(entry.getDurationSec());
            group.setPackets(entry.getPacketCount().getValue());
            group.setReferenceCount(entry.getRefCount());
            int bucketIndex = 0;
            for (OFBucketCounter bucketStats : entry.getBucketStats()) {
                ((StoredGroupBucketEntry) group.buckets().buckets().get(bucketIndex)).setPackets(bucketStats.getPacketCount().getValue());
                ((StoredGroupBucketEntry) group.buckets().buckets().get(bucketIndex)).setBytes(entry.getBucketStats().get(bucketIndex).getByteCount().getValue());
                bucketIndex++;
            }
        }
    }
    return groups.values();
}
Also used : DefaultGroup(org.onosproject.net.group.DefaultGroup) Group(org.onosproject.net.group.Group) OFGroupDescStatsEntry(org.projectfloodlight.openflow.protocol.OFGroupDescStatsEntry) Dpid(org.onosproject.openflow.controller.Dpid) DefaultGroup(org.onosproject.net.group.DefaultGroup) GroupBuckets(org.onosproject.net.group.GroupBuckets) GroupId(org.onosproject.core.GroupId) GroupDescription(org.onosproject.net.group.GroupDescription) OFGroupStatsEntry(org.projectfloodlight.openflow.protocol.OFGroupStatsEntry) OFBucketCounter(org.projectfloodlight.openflow.protocol.OFBucketCounter) StoredGroupBucketEntry(org.onosproject.net.group.StoredGroupBucketEntry)

Example 17 with DefaultGroup

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

the class NullGroupProvider method groupAdd.

private void groupAdd(DeviceId deviceId, GroupOperation go) {
    GroupId gid = go.groupId();
    DefaultGroup group = new DefaultGroup(gid, deviceId, go.groupType(), go.buckets());
    group.setState(Group.GroupState.ADDED);
    groupTables.get(deviceId).put(gid, group);
}
Also used : DefaultGroup(org.onosproject.net.group.DefaultGroup) GroupId(org.onosproject.core.GroupId)

Example 18 with DefaultGroup

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

the class P4RuntimeReplicationGroupProgrammable method addedGroup.

private Group addedGroup(Group original, long life) {
    final DefaultGroup forgedGroup = new DefaultGroup(original.id(), original);
    forgedGroup.setState(Group.GroupState.ADDED);
    forgedGroup.setLife(life);
    return forgedGroup;
}
Also used : DefaultGroup(org.onosproject.net.group.DefaultGroup)

Example 19 with DefaultGroup

use of org.onosproject.net.group.DefaultGroup in project fabric-tna by stratum.

the class FabricPipeliner method handleVerify.

private ObjectiveError handleVerify(NextObjective nextObjective) {
    Map<GroupBucket, FlowRule> bucketsToFlows = getBucketToFlowMapping(nextObjective);
    if (bucketsToFlows.isEmpty() && !nextObjective.nextTreatments().isEmpty()) {
        log.warn("VERIFY failed due to translation error, bucketsToFlows is empty");
        return ObjectiveError.BADPARAMS;
    }
    if (log.isTraceEnabled()) {
        log.trace("Mapping bucketsToFlows {} has been generated ", bucketsToFlows);
    }
    GroupKey groupKey = nextTranslator.getGroupKey(nextObjective);
    if (groupKey == null) {
        log.warn("VERIFY failed due to translation error, unable to determine group key");
        return ObjectiveError.BADPARAMS;
    }
    Group groupFromStore = groupService.getGroup(deviceId, groupKey);
    if (groupFromStore == null) {
        log.warn("VERIFY failed due to missing group in the store");
        return ObjectiveError.GROUPMISSING;
    }
    // Looking for duplicate buckets - remove them by using a set and comparing size after/before
    Set<GroupBucket> bucketsFromStore = Sets.newHashSet(groupFromStore.buckets().buckets());
    if (groupFromStore.buckets().buckets().size() > bucketsFromStore.size()) {
        log.warn("Duplicated buckets detected in device:{}, nextId:{}, before-size" + ":{} after-size:{} .. correcting", deviceId, nextObjective.id(), groupFromStore.buckets().buckets().size(), bucketsFromStore.size());
        final GroupBuckets bucketToSet = new GroupBuckets(Lists.newArrayList(bucketsFromStore));
        groupService.setBucketsForGroup(deviceId, groupKey, bucketToSet, groupKey, nextObjective.appId());
        // Forge temporary the group to avoid race condition with the store
        groupFromStore = new DefaultGroup(groupFromStore.id(), deviceId, groupFromStore.type(), bucketToSet);
    }
    // Looking for buckets missing in the group but defined in the next
    Map<GroupBucket, FlowRule> toAdd = Maps.newHashMap();
    for (Map.Entry<GroupBucket, FlowRule> entry : bucketsToFlows.entrySet()) {
        if (!groupFromStore.buckets().buckets().contains(entry.getKey())) {
            toAdd.put(entry.getKey(), entry.getValue());
        }
    }
    // Looking for buckets missing in the next but defined in the group
    // FIXME SDFAB-250 we cannot remove associated egress flows
    List<GroupBucket> toRemove = Lists.newArrayList();
    groupFromStore.buckets().buckets().forEach(bucket -> {
        if (!bucketsToFlows.containsKey(bucket)) {
            toRemove.add(bucket);
        }
    });
    if (!toAdd.isEmpty() || !toRemove.isEmpty()) {
        log.warn("Mismatch detected in device:{}, nextId:{}, groupFromTranslation-size:{} " + "groupFromStore-size:{} toAdd-size:{} toRemove-size: {} .. correcting", deviceId, nextObjective.id(), bucketsToFlows.size(), groupFromStore.buckets().buckets().size(), toAdd.size(), toRemove.size());
    }
    if (!toAdd.isEmpty()) {
        if (log.isTraceEnabled()) {
            log.trace("Adding missing buckets {} and flows {}", toAdd.keySet(), toAdd.values());
        }
        final FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
        final FlowRule dummyFlow = getDummyFlow(nextObjective);
        toAdd.values().stream().filter(flowRule -> !flowRule.equals(dummyFlow)).forEach(ops::add);
        final GroupBuckets bucketsToAdd = new GroupBuckets(Lists.newArrayList(toAdd.keySet()));
        groupService.addBucketsToGroup(deviceId, groupKey, bucketsToAdd, groupKey, nextObjective.appId());
        flowRuleService.apply(ops.build());
    }
    if (!toRemove.isEmpty()) {
        if (log.isTraceEnabled()) {
            log.trace("Removing stale buckets {}", toRemove);
        }
        final GroupBuckets bucketsToRemove = new GroupBuckets(toRemove);
        groupService.removeBucketsFromGroup(deviceId, groupKey, bucketsToRemove, groupKey, nextObjective.appId());
    }
    return null;
}
Also used : 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) FabricUtils.outputPort(org.stratumproject.fabric.tna.behaviour.FabricUtils.outputPort) 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) RECIRC_PORTS(org.stratumproject.fabric.tna.Constants.RECIRC_PORTS) V1MODEL_RECIRC_PORT(org.stratumproject.fabric.tna.Constants.V1MODEL_RECIRC_PORT) PipelinerContext(org.onosproject.net.behaviour.PipelinerContext) FabricCapabilities(org.stratumproject.fabric.tna.behaviour.FabricCapabilities) PKT_IN_MIRROR_SESSION_ID(org.stratumproject.fabric.tna.Constants.PKT_IN_MIRROR_SESSION_ID) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) Collection(java.util.Collection) Set(java.util.Set) FlowObjectiveStore(org.onosproject.net.flowobjective.FlowObjectiveStore) Constants(org.stratumproject.fabric.tna.Constants) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) String.format(java.lang.String.format) DEFAULT_VLAN(org.stratumproject.fabric.tna.Constants.DEFAULT_VLAN) PORT_TYPE_INTERNAL(org.stratumproject.fabric.tna.Constants.PORT_TYPE_INTERNAL) Objects(java.util.Objects) List(java.util.List) FlowRule(org.onosproject.net.flow.FlowRule) GroupBuckets(org.onosproject.net.group.GroupBuckets) DeviceId(org.onosproject.net.DeviceId) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) FWD_IPV4_ROUTING(org.stratumproject.fabric.tna.Constants.FWD_IPV4_ROUTING) Pipeliner(org.onosproject.net.behaviour.Pipeliner) NextTreatment(org.onosproject.net.flowobjective.NextTreatment) ZERO(org.stratumproject.fabric.tna.Constants.ZERO) CompletableFuture(java.util.concurrent.CompletableFuture) DefaultGroup(org.onosproject.net.group.DefaultGroup) GroupBucket(org.onosproject.net.group.GroupBucket) NextGroup(org.onosproject.net.behaviour.NextGroup) GroupKey(org.onosproject.net.group.GroupKey) P4InfoConstants(org.stratumproject.fabric.tna.behaviour.P4InfoConstants) Group(org.onosproject.net.group.Group) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultGroupBucket.createCloneGroupBucket(org.onosproject.net.group.DefaultGroupBucket.createCloneGroupBucket) ImmutableList(com.google.common.collect.ImmutableList) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) FWD_MPLS(org.stratumproject.fabric.tna.Constants.FWD_MPLS) Criteria(org.onosproject.net.flow.criteria.Criteria) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) ExecutorService(java.util.concurrent.ExecutorService) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) Logger(org.slf4j.Logger) GroupService(org.onosproject.net.group.GroupService) AbstractFabricHandlerBehavior(org.stratumproject.fabric.tna.behaviour.AbstractFabricHandlerBehavior) Maps(com.google.common.collect.Maps) IdNextTreatment(org.onosproject.net.flowobjective.IdNextTreatment) PiAction(org.onosproject.net.pi.runtime.PiAction) KRYO(org.stratumproject.fabric.tna.behaviour.FabricUtils.KRYO) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Objective(org.onosproject.net.flowobjective.Objective) Collections(java.util.Collections) ONE(org.stratumproject.fabric.tna.Constants.ONE) DefaultGroup(org.onosproject.net.group.DefaultGroup) NextGroup(org.onosproject.net.behaviour.NextGroup) Group(org.onosproject.net.group.Group) FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) GroupKey(org.onosproject.net.group.GroupKey) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) DefaultGroup(org.onosproject.net.group.DefaultGroup) GroupBuckets(org.onosproject.net.group.GroupBuckets) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultGroupBucket.createCloneGroupBucket(org.onosproject.net.group.DefaultGroupBucket.createCloneGroupBucket) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) Map(java.util.Map)

Example 20 with DefaultGroup

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

the class DistributedGroupStore method storeGroupDescriptionInternal.

private void storeGroupDescriptionInternal(GroupDescription groupDesc) {
    // Check if a group is existing with the same key
    if (getGroup(groupDesc.deviceId(), groupDesc.appCookie()) != null) {
        return;
    }
    synchronized (deviceAuditStatus) {
        if (deviceAuditStatus.get(groupDesc.deviceId()) == null) {
            // Device group audit has not completed yet
            // Add this group description to pending group key table
            // Create a group entry object with Dummy Group ID
            log.debug("storeGroupDescriptionInternal: Device {} AUDIT pending...Queuing Group id {} ADD request", groupDesc.deviceId(), groupDesc.givenGroupId() != null ? "0x" + Integer.toHexString(groupDesc.givenGroupId()) : "N/A");
            StoredGroupEntry group = new DefaultGroup(dummyGroupId, groupDesc);
            group.setState(GroupState.WAITING_AUDIT_COMPLETE);
            Map<GroupStoreKeyMapKey, StoredGroupEntry> pendingKeyTable = getPendingGroupKeyTable();
            pendingKeyTable.put(new GroupStoreKeyMapKey(groupDesc.deviceId(), groupDesc.appCookie()), group);
            return;
        }
    }
    Group matchingExtraneousGroup = null;
    if (groupDesc.givenGroupId() != null) {
        // Check if there is a extraneous group existing with the same Id
        matchingExtraneousGroup = getMatchingExtraneousGroupbyId(groupDesc.deviceId(), groupDesc.givenGroupId());
        if (matchingExtraneousGroup != null) {
            log.debug("storeGroupDescriptionInternal: Matching extraneous group " + "found in Device {} for group id 0x{}", groupDesc.deviceId(), Integer.toHexString(groupDesc.givenGroupId()));
            // Check if the group buckets matches with user provided buckets
            if (matchingExtraneousGroup.buckets().equals(groupDesc.buckets())) {
                // Group is already existing with the same buckets and Id
                // Create a group entry object
                log.debug("storeGroupDescriptionInternal: Buckets also matching " + "in Device {} for group id 0x{}", groupDesc.deviceId(), Integer.toHexString(groupDesc.givenGroupId()));
                StoredGroupEntry group = new DefaultGroup(matchingExtraneousGroup.id(), groupDesc);
                // Insert the newly created group entry into key and id maps
                getGroupStoreKeyMap().put(new GroupStoreKeyMapKey(groupDesc.deviceId(), groupDesc.appCookie()), group);
                // Ensure it also inserted into group id based table to
                // avoid any chances of duplication in group id generation
                getGroupIdTable(groupDesc.deviceId()).put(matchingExtraneousGroup.id(), group);
                addOrUpdateGroupEntry(matchingExtraneousGroup);
                removeExtraneousGroupEntry(matchingExtraneousGroup);
                return;
            } else {
                // Group buckets are not matching. Update group
                // with user provided buckets.
                log.debug("storeGroupDescriptionInternal: Buckets are not " + "matching in Device {} for group id 0x{}", groupDesc.deviceId(), Integer.toHexString(groupDesc.givenGroupId()));
                StoredGroupEntry modifiedGroup = new DefaultGroup(matchingExtraneousGroup.id(), groupDesc);
                modifiedGroup.setState(GroupState.PENDING_UPDATE);
                getGroupStoreKeyMap().put(new GroupStoreKeyMapKey(groupDesc.deviceId(), groupDesc.appCookie()), modifiedGroup);
                // Ensure it also inserted into group id based table to
                // avoid any chances of duplication in group id generation
                getGroupIdTable(groupDesc.deviceId()).put(matchingExtraneousGroup.id(), modifiedGroup);
                removeExtraneousGroupEntry(matchingExtraneousGroup);
                log.debug("storeGroupDescriptionInternal: Triggering Group " + "UPDATE request for {} in device {}", matchingExtraneousGroup.id(), groupDesc.deviceId());
                notifyDelegate(new GroupEvent(Type.GROUP_UPDATE_REQUESTED, modifiedGroup));
                return;
            }
        }
    } else {
        // Check if there is an extraneous group with user provided buckets
        matchingExtraneousGroup = getMatchingExtraneousGroupbyBuckets(groupDesc.deviceId(), groupDesc.buckets());
        if (matchingExtraneousGroup != null) {
            // Group is already existing with the same buckets.
            // So reuse this group.
            log.debug("storeGroupDescriptionInternal: Matching extraneous group found in Device {}", groupDesc.deviceId());
            // Create a group entry object
            StoredGroupEntry group = new DefaultGroup(matchingExtraneousGroup.id(), groupDesc);
            // Insert the newly created group entry into key and id maps
            getGroupStoreKeyMap().put(new GroupStoreKeyMapKey(groupDesc.deviceId(), groupDesc.appCookie()), group);
            // Ensure it also inserted into group id based table to
            // avoid any chances of duplication in group id generation
            getGroupIdTable(groupDesc.deviceId()).put(matchingExtraneousGroup.id(), group);
            addOrUpdateGroupEntry(matchingExtraneousGroup);
            removeExtraneousGroupEntry(matchingExtraneousGroup);
            return;
        } else {
            // TODO: Check if there are any empty groups that can be used here
            log.debug("storeGroupDescriptionInternal: No matching extraneous groups found in Device {}", groupDesc.deviceId());
        }
    }
    GroupId id = null;
    if (groupDesc.givenGroupId() == null) {
        // Get a new group identifier
        id = new GroupId(getFreeGroupIdValue(groupDesc.deviceId()));
    } else {
        // we need to use the identifier passed in by caller, but check if
        // already used
        Group existing = getGroup(groupDesc.deviceId(), new GroupId(groupDesc.givenGroupId()));
        if (existing != null) {
            log.warn("Group already exists with the same id: 0x{} in dev:{} " + "but with different key: {} (request gkey: {})", Integer.toHexString(groupDesc.givenGroupId()), groupDesc.deviceId(), existing.appCookie(), groupDesc.appCookie());
            return;
        }
        id = new GroupId(groupDesc.givenGroupId());
    }
    // Create a group entry object
    StoredGroupEntry group = new DefaultGroup(id, groupDesc);
    // Insert the newly created group entry into key and id maps
    getGroupStoreKeyMap().put(new GroupStoreKeyMapKey(groupDesc.deviceId(), groupDesc.appCookie()), group);
    // Ensure it also inserted into group id based table to
    // avoid any chances of duplication in group id generation
    getGroupIdTable(groupDesc.deviceId()).put(id, group);
    log.debug("storeGroupDescriptionInternal: Processing Group ADD request for Id {} in device {}", id, groupDesc.deviceId());
    notifyDelegate(new GroupEvent(GroupEvent.Type.GROUP_ADD_REQUESTED, group));
}
Also used : DefaultGroup(org.onosproject.net.group.DefaultGroup) Group(org.onosproject.net.group.Group) DefaultGroup(org.onosproject.net.group.DefaultGroup) StoredGroupEntry(org.onosproject.net.group.StoredGroupEntry) GroupEvent(org.onosproject.net.group.GroupEvent) GroupId(org.onosproject.core.GroupId)

Aggregations

DefaultGroup (org.onosproject.net.group.DefaultGroup)26 Group (org.onosproject.net.group.Group)12 GroupBuckets (org.onosproject.net.group.GroupBuckets)12 GroupKey (org.onosproject.net.group.GroupKey)12 StoredGroupEntry (org.onosproject.net.group.StoredGroupEntry)11 GroupId (org.onosproject.core.GroupId)10 GroupBucket (org.onosproject.net.group.GroupBucket)10 GroupDescription (org.onosproject.net.group.GroupDescription)10 DefaultGroupDescription (org.onosproject.net.group.DefaultGroupDescription)8 GroupEvent (org.onosproject.net.group.GroupEvent)6 DefaultGroupKey (org.onosproject.net.group.DefaultGroupKey)5 ArrayList (java.util.ArrayList)4 PortNumber (org.onosproject.net.PortNumber)4 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)4 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)4 ApplicationId (org.onosproject.core.ApplicationId)3 CoreService (org.onosproject.core.CoreService)3 DeviceId (org.onosproject.net.DeviceId)3 DefaultGroupBucket (org.onosproject.net.group.DefaultGroupBucket)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2