Java Code Examples for org.onosproject.net.group.Group#givenGroupId()

The following examples show how to use org.onosproject.net.group.Group#givenGroupId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleVirtualGroupStore.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void deviceInitialAuditCompleted(NetworkId networkId, DeviceId deviceId,
                                        boolean completed) {
    deviceAuditStatus.computeIfAbsent(networkId, k -> new HashMap<>());

    HashMap<DeviceId, Boolean> deviceAuditStatusByNetwork =
            deviceAuditStatus.get(networkId);

    synchronized (deviceAuditStatusByNetwork) {
        if (completed) {
            log.debug("deviceInitialAuditCompleted: AUDIT "
                              + "completed for device {}", deviceId);
            deviceAuditStatusByNetwork.put(deviceId, true);
            // Execute all pending group requests
            ConcurrentMap<GroupKey, StoredGroupEntry> pendingGroupRequests =
                    getPendingGroupKeyTable(networkId, deviceId);
            for (Group group:pendingGroupRequests.values()) {
                GroupDescription tmp = new DefaultGroupDescription(
                        group.deviceId(),
                        group.type(),
                        group.buckets(),
                        group.appCookie(),
                        group.givenGroupId(),
                        group.appId());
                storeGroupDescriptionInternal(networkId, tmp);
            }
            getPendingGroupKeyTable(networkId, deviceId).clear();
        } else {
            if (deviceAuditStatusByNetwork.get(deviceId)) {
                log.debug("deviceInitialAuditCompleted: Clearing AUDIT "
                                  + "status for device {}", deviceId);
                deviceAuditStatusByNetwork.put(deviceId, false);
            }
        }
    }
}
 
Example 2
Source File: GroupCodec.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public ObjectNode encode(Group group, CodecContext context) {
    checkNotNull(group, "Group cannot be null");
    ObjectNode result = context.mapper().createObjectNode()
            // a Group id should be an unsigned integer
            .put(ID, Integer.toUnsignedLong(group.id().id()))
            .put(STATE, group.state().toString())
            .put(LIFE, group.life())
            .put(PACKETS, group.packets())
            .put(BYTES, group.bytes())
            .put(REFERENCE_COUNT, group.referenceCount())
            .put(TYPE, group.type().toString())
            .put(DEVICE_ID, group.deviceId().toString());

    if (group.appId() != null) {
        result.put(APP_ID, group.appId().name());
    }

    if (group.appCookie() != null) {
        result.put(APP_COOKIE, group.appCookie().toString());
    }

    if (group.givenGroupId() != null) {
        // a given Group id should be an unsigned integer
        result.put(GIVEN_GROUP_ID, Integer.toUnsignedLong(group.givenGroupId()));
    }

    ArrayNode buckets = context.mapper().createArrayNode();
    group.buckets().buckets().forEach(bucket -> {
        ObjectNode bucketJson = context.codec(GroupBucket.class).encode(bucket, context);
        buckets.add(bucketJson);
    });
    result.set(BUCKETS, buckets);
    return result;
}
 
Example 3
Source File: SimpleGroupStore.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void deviceInitialAuditCompleted(DeviceId deviceId,
                                        boolean completed) {
    synchronized (deviceAuditStatus) {
        if (completed) {
            log.debug("deviceInitialAuditCompleted: AUDIT "
                    + "completed for device {}", deviceId);
            deviceAuditStatus.put(deviceId, true);
            // Execute all pending group requests
            ConcurrentMap<GroupKey, StoredGroupEntry> pendingGroupRequests =
                    getPendingGroupKeyTable(deviceId);
            for (Group group:pendingGroupRequests.values()) {
                GroupDescription tmp = new DefaultGroupDescription(
                                                                   group.deviceId(),
                                                                   group.type(),
                                                                   group.buckets(),
                                                                   group.appCookie(),
                                                                   group.givenGroupId(),
                                                                   group.appId());
                storeGroupDescriptionInternal(tmp);
            }
            getPendingGroupKeyTable(deviceId).clear();
        } else {
           if (deviceAuditStatus.getOrDefault(deviceId, false)) {
                log.debug("deviceInitialAuditCompleted: Clearing AUDIT "
                        + "status for device {}", deviceId);
                deviceAuditStatus.put(deviceId, false);
            }
        }
    }
}
 
Example 4
Source File: DistributedGroupStore.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void deviceInitialAuditCompleted(DeviceId deviceId,
                                        boolean completed) {
    synchronized (deviceAuditStatus) {
        if (completed) {
            log.debug("AUDIT completed for device {}",
                      deviceId);
            deviceAuditStatus.put(deviceId, true);
            // Execute all pending group requests
            List<StoredGroupEntry> pendingGroupRequests =
                    getPendingGroupKeyTable().values()
                            .stream()
                            .filter(g -> g.deviceId().equals(deviceId))
                            .collect(Collectors.toList());
            log.debug("processing pending group add requests for device {} and number of pending requests {}",
                      deviceId,
                      pendingGroupRequests.size());
            for (Group group : pendingGroupRequests) {
                GroupDescription tmp = new DefaultGroupDescription(
                        group.deviceId(),
                        group.type(),
                        group.buckets(),
                        group.appCookie(),
                        group.givenGroupId(),
                        group.appId());
                storeGroupDescriptionInternal(tmp);
                getPendingGroupKeyTable().
                        remove(new GroupStoreKeyMapKey(deviceId, group.appCookie()));
            }
        } else {
            Boolean audited = deviceAuditStatus.get(deviceId);
            if (audited != null && audited) {
                log.debug("Clearing AUDIT status for device {}", deviceId);
                deviceAuditStatus.put(deviceId, false);
            }
        }
    }
}
 
Example 5
Source File: SimpleVirtualGroupStore.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public void updateGroupDescription(NetworkId networkId, DeviceId deviceId,
                                   GroupKey oldAppCookie, UpdateType type,
                                   GroupBuckets newBuckets, GroupKey newAppCookie) {
    // Check if a group is existing with the provided key
    Group oldGroup = getGroup(networkId, deviceId, oldAppCookie);
    if (oldGroup == null) {
        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);
        newGroup.setState(Group.GroupState.PENDING_UPDATE);
        newGroup.setLife(oldGroup.life());
        newGroup.setPackets(oldGroup.packets());
        newGroup.setBytes(oldGroup.bytes());

        // Remove the old entry from maps and add new entry using new key
        ConcurrentMap<GroupKey, StoredGroupEntry> keyTable =
                getGroupKeyTable(networkId, oldGroup.deviceId());
        ConcurrentMap<GroupId, StoredGroupEntry> idTable =
                getGroupIdTable(networkId, oldGroup.deviceId());
        keyTable.remove(oldGroup.appCookie());
        idTable.remove(oldGroup.id());
        keyTable.put(newGroup.appCookie(), newGroup);
        idTable.put(newGroup.id(), newGroup);
        notifyDelegate(networkId,
                       new GroupEvent(GroupEvent.Type.GROUP_UPDATE_REQUESTED,
                                      newGroup));
    }

}
 
Example 6
Source File: SimpleGroupStore.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Updates the existing group entry with the information
 * from group description.
 *
 * @param deviceId the device ID
 * @param oldAppCookie the current group key
 * @param type update type
 * @param newBuckets group buckets for updates
 * @param newAppCookie optional new group key
 */
@Override
public void updateGroupDescription(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) {
        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);
        newGroup.setState(GroupState.PENDING_UPDATE);
        newGroup.setLife(oldGroup.life());
        newGroup.setPackets(oldGroup.packets());
        newGroup.setBytes(oldGroup.bytes());
        // Remove the old entry from maps and add new entry using new key
        ConcurrentMap<GroupKey, StoredGroupEntry> keyTable =
                getGroupKeyTable(oldGroup.deviceId());
        ConcurrentMap<GroupId, StoredGroupEntry> idTable =
                getGroupIdTable(oldGroup.deviceId());
        keyTable.remove(oldGroup.appCookie());
        idTable.remove(oldGroup.id());
        keyTable.put(newGroup.appCookie(), newGroup);
        idTable.put(newGroup.id(), newGroup);
        notifyDelegate(new GroupEvent(Type.GROUP_UPDATE_REQUESTED, newGroup));
    }
}
 
Example 7
Source File: DistributedGroupStore.java    From onos with Apache License 2.0 4 votes vote down vote up
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:{}", oldAppCookie, deviceId);
        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);
        getGroupStoreKeyMap().
                put(new GroupStoreKeyMapKey(newGroup.deviceId(),
                                            newGroup.appCookie()), newGroup);
        notifyDelegate(new GroupEvent(Type.GROUP_UPDATE_REQUESTED, newGroup));
    } else {
        log.warn("updateGroupDescriptionInternal with type {}: No "
                         + "change in the buckets in update", type);
    }
}