Search in sources :

Example 96 with Group

use of org.onosproject.net.group.Group 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)

Example 97 with Group

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

the class DistributedGroupStore method updateGroupEntryStatsInternal.

/**
 * Updates the stats of an existing group entry.
 *
 * @param group the new stats
 * @param existing the existing group
 */
private void updateGroupEntryStatsInternal(Group group, StoredGroupEntry existing) {
    for (GroupBucket bucket : group.buckets().buckets()) {
        Optional<GroupBucket> matchingBucket = existing.buckets().buckets().stream().filter((existingBucket) -> (existingBucket.equals(bucket))).findFirst();
        if (matchingBucket.isPresent()) {
            ((StoredGroupBucketEntry) matchingBucket.get()).setPackets(bucket.packets());
            ((StoredGroupBucketEntry) matchingBucket.get()).setBytes(bucket.bytes());
        } else {
            log.warn("updateGroupEntryStatsInternal: No matching bucket {}" + " to update stats for group {}", bucket, group.id());
        }
    }
    existing.setLife(group.life());
    existing.setPackets(group.packets());
    existing.setBytes(group.bytes());
    existing.setReferenceCount(group.referenceCount());
    existing.setFailedRetryCount(0);
}
Also used : ConsistentMap(org.onosproject.store.service.ConsistentMap) DeviceService(org.onosproject.net.device.DeviceService) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) GroupOperation(org.onosproject.net.group.GroupOperation) DriverService(org.onosproject.net.driver.DriverService) ALLOW_EXTRANEOUS_GROUPS(org.onosproject.store.OsgiPropertyConstants.ALLOW_EXTRANEOUS_GROUPS) Executors.newSingleThreadScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor) StorageService(org.onosproject.store.service.StorageService) FluentIterable(com.google.common.collect.FluentIterable) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) MastershipService(org.onosproject.mastership.MastershipService) NodeId(org.onosproject.cluster.NodeId) Serializer(org.onosproject.store.service.Serializer) Tools.get(org.onlab.util.Tools.get) ImmutableSet(com.google.common.collect.ImmutableSet) StoredGroupBucketEntry(org.onosproject.net.group.StoredGroupBucketEntry) Deactivate(org.osgi.service.component.annotations.Deactivate) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) GroupEvent(org.onosproject.net.group.GroupEvent) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Executors(java.util.concurrent.Executors) Objects(java.util.Objects) Versioned(org.onosproject.store.service.Versioned) List(java.util.List) GroupStoreDelegate(org.onosproject.net.group.GroupStoreDelegate) GARBAGE_COLLECT(org.onosproject.store.OsgiPropertyConstants.GARBAGE_COLLECT) GroupBuckets(org.onosproject.net.group.GroupBuckets) Type(org.onosproject.net.group.GroupEvent.Type) Entry(java.util.Map.Entry) ClusterCommunicationService(org.onosproject.store.cluster.messaging.ClusterCommunicationService) Optional(java.util.Optional) ClusterService(org.onosproject.cluster.ClusterService) DeviceId(org.onosproject.net.DeviceId) GARBAGE_COLLECT_THRESH_DEFAULT(org.onosproject.store.OsgiPropertyConstants.GARBAGE_COLLECT_THRESH_DEFAULT) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) Dictionary(java.util.Dictionary) Iterables(com.google.common.collect.Iterables) ComponentContext(org.osgi.service.component.ComponentContext) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) HashMap(java.util.HashMap) DefaultGroup(org.onosproject.net.group.DefaultGroup) GroupBucket(org.onosproject.net.group.GroupBucket) KryoNamespace(org.onlab.util.KryoNamespace) GroupKey(org.onosproject.net.group.GroupKey) Group(org.onosproject.net.group.Group) MapEventListener(org.onosproject.store.service.MapEventListener) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashSet(java.util.HashSet) GroupStore(org.onosproject.net.group.GroupStore) Component(org.osgi.service.component.annotations.Component) StoredGroupEntry(org.onosproject.net.group.StoredGroupEntry) GroupState(org.onosproject.net.group.Group.GroupState) ALLOW_EXTRANEOUS_GROUPS_DEFAULT(org.onosproject.store.OsgiPropertyConstants.ALLOW_EXTRANEOUS_GROUPS_DEFAULT) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Activate(org.osgi.service.component.annotations.Activate) ExecutorService(java.util.concurrent.ExecutorService) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) Logger(org.slf4j.Logger) Properties(java.util.Properties) Iterator(java.util.Iterator) GARBAGE_COLLECT_DEFAULT(org.onosproject.store.OsgiPropertyConstants.GARBAGE_COLLECT_DEFAULT) Topic(org.onosproject.store.service.Topic) MastershipRole(org.onosproject.net.MastershipRole) GARBAGE_COLLECT_THRESH(org.onosproject.store.OsgiPropertyConstants.GARBAGE_COLLECT_THRESH) Status(org.onosproject.store.service.DistributedPrimitive.Status) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) Consumer(java.util.function.Consumer) MultiValuedTimestamp(org.onosproject.store.service.MultiValuedTimestamp) GroupId(org.onosproject.core.GroupId) MapEvent(org.onosproject.store.service.MapEvent) AbstractStore(org.onosproject.store.AbstractStore) Modified(org.osgi.service.component.annotations.Modified) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Reference(org.osgi.service.component.annotations.Reference) Collections(java.util.Collections) GroupBucket(org.onosproject.net.group.GroupBucket) StoredGroupBucketEntry(org.onosproject.net.group.StoredGroupBucketEntry)

Example 98 with Group

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

the class DistributedGroupStore method updateGroupDescriptionInternal.

private void updateGroupDescriptionInternal(DeviceId deviceId, GroupKey oldAppCookie, UpdateType type, GroupBuckets newBuckets, GroupKey newAppCookie) {
    // Check if a group is existing with the provided key
    Group oldGroup = getGroup(deviceId, oldAppCookie);
    if (oldGroup == null) {
        log.warn("updateGroupDescriptionInternal: Group not found...strange. " + "GroupKey:{} DeviceId:{} newGroupKey:{}", oldAppCookie, deviceId, newAppCookie);
        return;
    }
    List<GroupBucket> newBucketList = getUpdatedBucketList(oldGroup, type, newBuckets);
    if (newBucketList != null) {
        // Create a new group object from the old group
        GroupBuckets updatedBuckets = new GroupBuckets(newBucketList);
        GroupKey newCookie = (newAppCookie != null) ? newAppCookie : oldAppCookie;
        GroupDescription updatedGroupDesc = new DefaultGroupDescription(oldGroup.deviceId(), oldGroup.type(), updatedBuckets, newCookie, oldGroup.givenGroupId(), oldGroup.appId());
        StoredGroupEntry newGroup = new DefaultGroup(oldGroup.id(), updatedGroupDesc);
        log.debug("updateGroupDescriptionInternal: group entry {} in device {} moving from {} to PENDING_UPDATE", oldGroup.id(), oldGroup.deviceId(), oldGroup.state());
        newGroup.setState(GroupState.PENDING_UPDATE);
        newGroup.setLife(oldGroup.life());
        newGroup.setPackets(oldGroup.packets());
        newGroup.setBytes(oldGroup.bytes());
        // Update the group entry in groupkey based map.
        // Update to groupid based map will happen in the
        // groupkey based map update listener
        log.debug("updateGroupDescriptionInternal with type {}: Group {} updated with buckets", type, newGroup.id());
        getGroupStoreKeyMap().put(new GroupStoreKeyMapKey(newGroup.deviceId(), newGroup.appCookie()), newGroup);
        notifyDelegate(new GroupEvent(Type.GROUP_UPDATE_REQUESTED, newGroup));
    } else {
        log.warn("updateGroupDescriptionInternal with type {}: Group {} No " + "change in the buckets in update", type, oldGroup.id());
    }
}
Also used : DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) DefaultGroup(org.onosproject.net.group.DefaultGroup) Group(org.onosproject.net.group.Group) GroupKey(org.onosproject.net.group.GroupKey) DefaultGroup(org.onosproject.net.group.DefaultGroup) GroupBucket(org.onosproject.net.group.GroupBucket) GroupBuckets(org.onosproject.net.group.GroupBuckets) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) StoredGroupEntry(org.onosproject.net.group.StoredGroupEntry) GroupEvent(org.onosproject.net.group.GroupEvent)

Example 99 with Group

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

the class DistributedGroupStoreTest method testRemoveGroupDescription.

/**
 * Tests adding and removing a group.
 */
@Test
public void testRemoveGroupDescription() throws Exception {
    groupStore.deviceInitialAuditCompleted(deviceId1, true);
    groupStore.storeGroupDescription(groupDescription1);
    groupStore.deleteGroupDescription(deviceId1, groupKey1);
    // Group should still be there, marked for removal
    assertThat(groupStore.getGroupCount(deviceId1), is(1));
    Group queriedGroup = groupStore.getGroup(deviceId1, groupId1);
    assertThat(queriedGroup.state(), is(Group.GroupState.PENDING_DELETE));
}
Also used : DefaultGroup(org.onosproject.net.group.DefaultGroup) Group(org.onosproject.net.group.Group) Test(org.junit.Test)

Example 100 with Group

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

the class DistributedGroupStoreTest method testGroupOperationFailedWithErrorCode.

/**
 * Tests group operation failed interface, with error codes for failures.
 */
@Test
public void testGroupOperationFailedWithErrorCode() {
    TestDelegate delegate = new TestDelegate();
    groupStore.setDelegate(delegate);
    groupStore.deviceInitialAuditCompleted(deviceId1, true);
    groupStore.storeGroupDescription(groupDescription1);
    groupStore.deviceInitialAuditCompleted(deviceId2, true);
    groupStore.storeGroupDescription(groupDescription2);
    List<GroupEvent> eventsAfterAdds = delegate.eventsSeen();
    assertThat(eventsAfterAdds, hasSize(2));
    eventsAfterAdds.forEach(event -> assertThat(event.type(), is(GroupEvent.Type.GROUP_ADD_REQUESTED)));
    delegate.resetEvents();
    // test group exists
    GroupOperation opAdd = GroupOperation.createAddGroupOperation(groupId1, ALL, allGroupBuckets);
    GroupOperation addFailedExists = GroupOperation.createFailedGroupOperation(opAdd, GroupMsgErrorCode.GROUP_EXISTS);
    groupStore.groupOperationFailed(deviceId1, addFailedExists);
    List<GroupEvent> eventsAfterAddFailed = delegate.eventsSeen();
    assertThat(eventsAfterAddFailed, hasSize(2));
    assertThat(eventsAfterAddFailed.get(0).type(), is(GroupEvent.Type.GROUP_ADDED));
    assertThat(eventsAfterAddFailed.get(1).type(), is(GroupEvent.Type.GROUP_ADDED));
    Group g1 = groupStore.getGroup(deviceId1, groupId1);
    assertEquals(0, g1.failedRetryCount());
    delegate.resetEvents();
    // test invalid group
    Group g2 = groupStore.getGroup(deviceId2, groupId2);
    assertEquals(0, g2.failedRetryCount());
    assertEquals(GroupState.PENDING_ADD, g2.state());
    GroupOperation opAdd1 = GroupOperation.createAddGroupOperation(groupId2, INDIRECT, indirectGroupBuckets);
    GroupOperation addFailedInvalid = GroupOperation.createFailedGroupOperation(opAdd1, GroupMsgErrorCode.INVALID_GROUP);
    groupStore.groupOperationFailed(deviceId2, addFailedInvalid);
    groupStore.pushGroupMetrics(deviceId2, ImmutableList.of());
    List<GroupEvent> eventsAfterAddFailed1 = delegate.eventsSeen();
    assertThat(eventsAfterAddFailed1, hasSize(1));
    assertThat(eventsAfterAddFailed.get(0).type(), is(GroupEvent.Type.GROUP_ADD_REQUESTED));
    g2 = groupStore.getGroup(deviceId2, groupId2);
    assertEquals(1, g2.failedRetryCount());
    assertEquals(GroupState.PENDING_ADD_RETRY, g2.state());
    delegate.resetEvents();
    groupStore.groupOperationFailed(deviceId2, addFailedInvalid);
    groupStore.pushGroupMetrics(deviceId2, ImmutableList.of());
    List<GroupEvent> eventsAfterAddFailed2 = delegate.eventsSeen();
    assertThat(eventsAfterAddFailed2, hasSize(1));
    assertThat(eventsAfterAddFailed.get(0).type(), is(GroupEvent.Type.GROUP_ADD_REQUESTED));
    g2 = groupStore.getGroup(deviceId2, groupId2);
    assertEquals(2, g2.failedRetryCount());
    assertEquals(GroupState.PENDING_ADD_RETRY, g2.state());
    delegate.resetEvents();
    groupStore.groupOperationFailed(deviceId2, addFailedInvalid);
    groupStore.pushGroupMetrics(deviceId2, ImmutableList.of());
    List<GroupEvent> eventsAfterAddFailed3 = delegate.eventsSeen();
    assertThat(eventsAfterAddFailed3, hasSize(2));
    assertThat(eventsAfterAddFailed.get(0).type(), is(GroupEvent.Type.GROUP_ADD_FAILED));
    assertThat(eventsAfterAddFailed.get(1).type(), is(GroupEvent.Type.GROUP_REMOVED));
    g2 = groupStore.getGroup(deviceId2, groupId2);
    assertEquals(null, g2);
    delegate.resetEvents();
}
Also used : DefaultGroup(org.onosproject.net.group.DefaultGroup) Group(org.onosproject.net.group.Group) GroupEvent(org.onosproject.net.group.GroupEvent) GroupOperation(org.onosproject.net.group.GroupOperation) Test(org.junit.Test)

Aggregations

Group (org.onosproject.net.group.Group)117 DefaultGroup (org.onosproject.net.group.DefaultGroup)55 GroupKey (org.onosproject.net.group.GroupKey)54 DefaultGroupKey (org.onosproject.net.group.DefaultGroupKey)43 GroupBucket (org.onosproject.net.group.GroupBucket)42 GroupBuckets (org.onosproject.net.group.GroupBuckets)40 ArrayList (java.util.ArrayList)36 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)36 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)36 NextGroup (org.onosproject.net.behaviour.NextGroup)35 GroupDescription (org.onosproject.net.group.GroupDescription)34 DefaultGroupDescription (org.onosproject.net.group.DefaultGroupDescription)28 DefaultGroupBucket (org.onosproject.net.group.DefaultGroupBucket)26 PortNumber (org.onosproject.net.PortNumber)25 GroupId (org.onosproject.core.GroupId)23 DeviceId (org.onosproject.net.DeviceId)22 TrafficSelector (org.onosproject.net.flow.TrafficSelector)22 Instruction (org.onosproject.net.flow.instructions.Instruction)20 Deque (java.util.Deque)19 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)19