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

The following examples show how to use org.onosproject.net.group.Group#buckets() . 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: VirtualNetworkGroupManagerTest.java    From onos with Apache License 2.0 6 votes vote down vote up
private void testAuditWithConfirmedGroups(NetworkId networkId,
                                          DeviceId deviceId) {
    VirtualNetworkGroupManager groupManager;
    VirtualGroupProviderService providerService;
    TestGroupListener listener;

    if (networkId.id() == 1) {
        groupManager = groupManager1;
        providerService = providerService1;
        listener = listener1;
    } else {
        groupManager = groupManager2;
        providerService = providerService2;
        listener = listener2;
    }

    GroupKey key = new DefaultGroupKey("group1BeforeAudit".getBytes());
    Group createdGroup = groupManager.getGroup(deviceId, key);
    createdGroup = new DefaultGroup(createdGroup.id(),
                                    deviceId,
                                    Group.Type.SELECT,
                                    createdGroup.buckets());
    List<Group> groupEntries = Collections.singletonList(createdGroup);
    providerService.pushGroupMetrics(deviceId, groupEntries);
    listener.validateEvent(Collections.singletonList(GroupEvent.Type.GROUP_ADDED));
}
 
Example 2
Source File: SimpleGroupStoreTest.java    From onos with Apache License 2.0 6 votes vote down vote up
private void testRemoveGroupFromSB(GroupKey currKey) {
    Group existingGroup = simpleGroupStore.getGroup(D1, currKey);
    InternalGroupStoreDelegate removeGroupEntryDelegate =
            new InternalGroupStoreDelegate(currKey,
                                           existingGroup.buckets(),
                                           GroupEvent.Type.GROUP_REMOVED);
    simpleGroupStore.setDelegate(removeGroupEntryDelegate);
    simpleGroupStore.removeGroupEntry(existingGroup);

    // Testing getGroup operation
    existingGroup = simpleGroupStore.getGroup(D1, currKey);
    assertEquals(null, existingGroup);
    assertEquals(0, Iterables.size(simpleGroupStore.getGroups(D1)));
    assertEquals(0, simpleGroupStore.getGroupCount(D1));

    simpleGroupStore.unsetDelegate(removeGroupEntryDelegate);
}
 
Example 3
Source File: GroupsWebResource.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Create new group rule. Creates and installs a new group rule for the
 * specified device.
 *
 * @param deviceId device identifier
 * @param stream   group rule JSON
 * @return status of the request - CREATED if the JSON is correct,
 * BAD_REQUEST if the JSON is invalid
 * @onos.rsModel GroupsPost
 */
@POST
@Path("{deviceId}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createGroup(@PathParam("deviceId") String deviceId,
                            InputStream stream) {
    GroupService groupService = get(GroupService.class);
    try {

        ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
        JsonNode specifiedDeviceId = jsonTree.get("deviceId");

        if (specifiedDeviceId != null &&
                !specifiedDeviceId.asText().equals(deviceId)) {
            throw new IllegalArgumentException(DEVICE_INVALID);
        }
        jsonTree.put("deviceId", deviceId);
        Group group = codec(Group.class).decode(jsonTree, this);
        GroupDescription description = new DefaultGroupDescription(
                group.deviceId(), group.type(), group.buckets(),
                group.appCookie(), group.id().id(), group.appId());
        groupService.addGroup(description);
        UriBuilder locationBuilder = uriInfo.getBaseUriBuilder()
                .path("groups")
                .path(deviceId)
                .path(Long.toString(group.id().id()));
        return Response
                .created(locationBuilder.build())
                .build();
    } catch (IOException ex) {
        throw new IllegalArgumentException(ex);
    }
}
 
Example 4
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 5
Source File: GroupManagerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
private Group testAuditWithConfirmedGroups(DeviceId deviceId) {
    GroupKey key = new DefaultGroupKey("group1BeforeAudit".getBytes());
    Group createdGroup = groupService.getGroup(deviceId, key);
    createdGroup = new DefaultGroup(createdGroup.id(),
                                    deviceId,
                                    Group.Type.SELECT,
                                    createdGroup.buckets());
    List<Group> groupEntries = Collections.singletonList(createdGroup);
    providerService.pushGroupMetrics(deviceId, groupEntries);
    internalListener.validateEvent(Collections.singletonList(GroupEvent.Type.GROUP_ADDED));
    return createdGroup;
}
 
Example 6
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 7
Source File: SimpleGroupStoreTest.java    From onos with Apache License 2.0 5 votes vote down vote up
private void testAddGroupEntryFromSB(GroupKey currKey) {
    Group existingGroup = simpleGroupStore.getGroup(D1, currKey);

    InternalGroupStoreDelegate addGroupEntryDelegate =
            new InternalGroupStoreDelegate(currKey,
                                           existingGroup.buckets(),
                                           GroupEvent.Type.GROUP_ADDED);
    simpleGroupStore.setDelegate(addGroupEntryDelegate);
    simpleGroupStore.addOrUpdateGroupEntry(existingGroup);
    simpleGroupStore.unsetDelegate(addGroupEntryDelegate);
}
 
Example 8
Source File: SimpleGroupStoreTest.java    From onos with Apache License 2.0 5 votes vote down vote up
private void testDeleteGroup(GroupKey currKey) {
    Group existingGroup = simpleGroupStore.getGroup(D1, currKey);
    InternalGroupStoreDelegate deleteGroupDescDelegate =
            new InternalGroupStoreDelegate(currKey,
                                           existingGroup.buckets(),
                                           GroupEvent.Type.GROUP_REMOVE_REQUESTED);
    simpleGroupStore.setDelegate(deleteGroupDescDelegate);
    simpleGroupStore.deleteGroupDescription(D1, currKey);
    simpleGroupStore.unsetDelegate(deleteGroupDescDelegate);
}
 
Example 9
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);
            }
        }
    }
}