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

The following examples show how to use org.onosproject.net.group.Group#type() . 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: OpenFlowGroupProvider.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Builds a list of failover Groups whose primary live bucket failed over
 * (i.e. bucket in use has changed).
 *
 * @param dpid    DPID of switch whose port's status changed
 * @param status  new status of port
 * @return        list of groups whose primary live bucket failed over
 */
private List<Group> checkFailoverGroups(Dpid dpid, OFPortStatus status) {
    List<Group> groupList = new ArrayList<>();
    OFPortDesc desc = status.getDesc();
    PortNumber portNumber = PortNumber.portNumber(desc.getPortNo().getPortNumber());
    DeviceId id = DeviceId.deviceId(Dpid.uri(dpid));
    if (desc.isEnabled()) {
        return groupList;
    }
    Iterator<Group> iterator = groupService.getGroups(id).iterator();
    while (iterator.hasNext()) {
        Group group = iterator.next();
        if (group.type() == GroupDescription.Type.FAILOVER &&
                checkFailoverGroup(group, id, portNumber)) {
            groupList.add(group);
        }
    }
return groupList;
}
 
Example 2
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 3
Source File: SpringOpenTTP.java    From onos with Apache License 2.0 5 votes vote down vote up
private void addBucketToGroup(NextObjective nextObjective) {
    log.debug("addBucketToGroup in {}: for next objective id {}",
              deviceId, nextObjective.id());
    Collection<TrafficTreatment> treatments = nextObjective.next();
    TrafficTreatment treatment = treatments.iterator().next();
    final GroupKey key = new DefaultGroupKey(
            appKryo.serialize(nextObjective
                    .id()));
    Group group = groupService.getGroup(deviceId, key);
    if (group == null) {
        log.warn("Group is not found in {} for {}", deviceId, key);
        return;
    }
    GroupBucket bucket;
    if (group.type() == GroupDescription.Type.INDIRECT) {
        bucket = DefaultGroupBucket.createIndirectGroupBucket(treatment);
    } else if (group.type() == GroupDescription.Type.SELECT) {
        bucket = DefaultGroupBucket.createSelectGroupBucket(treatment);
    } else if (group.type() == GroupDescription.Type.ALL) {
        bucket = DefaultGroupBucket.createAllGroupBucket(treatment);
    } else {
        log.warn("Unsupported Group type {}", group.type());
        return;
    }
    GroupBuckets bucketsToAdd = new GroupBuckets(Collections.singletonList(bucket));
    log.debug("Adding buckets to group id {} of next objective id {} in device {}",
              group.id(), nextObjective.id(), deviceId);
    groupService.addBucketsToGroup(deviceId, key, bucketsToAdd, key, appId);
}
 
Example 4
Source File: SpringOpenTTP.java    From onos with Apache License 2.0 5 votes vote down vote up
private void removeBucketFromGroup(NextObjective nextObjective) {
    log.debug("removeBucketFromGroup in {}: for next objective id {}",
              deviceId, nextObjective.id());
    NextGroup nextGroup = flowObjectiveStore.getNextGroup(nextObjective.id());
    if (nextGroup != null) {
        Collection<TrafficTreatment> treatments = nextObjective.next();
        TrafficTreatment treatment = treatments.iterator().next();
        final GroupKey key = new DefaultGroupKey(
                appKryo.serialize(nextObjective
                        .id()));
        Group group = groupService.getGroup(deviceId, key);
        if (group == null) {
            log.warn("Group is not found in {} for {}", deviceId, key);
            return;
        }
        GroupBucket bucket;
        if (group.type() == GroupDescription.Type.INDIRECT) {
            bucket = DefaultGroupBucket.createIndirectGroupBucket(treatment);
        } else if (group.type() == GroupDescription.Type.SELECT) {
            bucket = DefaultGroupBucket.createSelectGroupBucket(treatment);
        } else if (group.type() == GroupDescription.Type.ALL) {
            bucket = DefaultGroupBucket.createAllGroupBucket(treatment);
        } else {
            log.warn("Unsupported Group type {}", group.type());
            return;
        }
        GroupBuckets removeBuckets = new GroupBuckets(Collections.singletonList(bucket));
        log.debug("Removing buckets from group id {} of next objective id {} in device {}",
                  group.id(), nextObjective.id(), deviceId);
        groupService.removeBucketsFromGroup(deviceId, key, removeBuckets, key, appId);
    }
}
 
Example 5
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 6
Source File: PiReplicationGroupTranslatorImpl.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a PI PRE entry equivalent to the given group, for the given
 * pipeconf and device.
 * <p>
 * The passed group is expected to have type {@link GroupDescription.Type#ALL}
 * or {@link GroupDescription.Type#CLONE}.
 *
 * @param group    group
 * @param pipeconf pipeconf
 * @param device   device
 * @return PI PRE entry
 * @throws PiTranslationException if the group cannot be translated
 */
static PiPreEntry translate(Group group, PiPipeconf pipeconf, Device device)
        throws PiTranslationException {

    checkNotNull(group);

    final List<Instruction> instructions = group.buckets().buckets().stream()
            .flatMap(b -> b.treatment().allInstructions().stream())
            .collect(Collectors.toList());

    final boolean hasNonOutputInstr = instructions.stream()
            .anyMatch(i -> !i.type().equals(Instruction.Type.OUTPUT));

    if (instructions.size() != group.buckets().buckets().size()
            || hasNonOutputInstr) {
        throw new PiTranslationException(
                "support only groups with just one OUTPUT instruction per bucket");
    }

    final List<OutputInstruction> outInstructions = instructions.stream()
            .map(i -> (OutputInstruction) i)
            .collect(Collectors.toList());

    switch (group.type()) {
        case ALL:
            return PiMulticastGroupEntry.builder()
                    .withGroupId(group.id().id())
                    .addReplicas(getReplicas(outInstructions, device))
                    .build();
        case CLONE:
            return PiCloneSessionEntry.builder()
                    .withSessionId(group.id().id())
                    .addReplicas(getReplicas(outInstructions, device))
                    .build();
        default:
            throw new PiTranslationException(format(
                    "group type %s not supported", group.type()));
    }
}
 
Example 7
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 8
Source File: SimpleGroupStoreTest.java    From onos with Apache License 2.0 5 votes vote down vote up
private void testUpdateGroupEntryFromSB(GroupKey currKey) {
    Group existingGroup = simpleGroupStore.getGroup(D1, currKey);
    int totalPkts = 0;
    int totalBytes = 0;
    List<GroupBucket> newBucketList = new ArrayList<>();
    for (GroupBucket bucket:existingGroup.buckets().buckets()) {
        StoredGroupBucketEntry newBucket =
                (StoredGroupBucketEntry)
                DefaultGroupBucket.createSelectGroupBucket(bucket.treatment());
        newBucket.setPackets(10);
        newBucket.setBytes(10 * 256 * 8);
        totalPkts += 10;
        totalBytes += 10 * 256 * 8;
        newBucketList.add(newBucket);
    }
    GroupBuckets updatedBuckets = new GroupBuckets(newBucketList);
    Group updatedGroup = new DefaultGroup(existingGroup.id(),
                                          existingGroup.deviceId(),
                                          existingGroup.type(),
                                          updatedBuckets);
    ((StoredGroupEntry) updatedGroup).setPackets(totalPkts);
    ((StoredGroupEntry) updatedGroup).setBytes(totalBytes);

    InternalGroupStoreDelegate updateGroupEntryDelegate =
            new InternalGroupStoreDelegate(currKey,
                                           updatedBuckets,
                                           GroupEvent.Type.GROUP_UPDATED);
    simpleGroupStore.setDelegate(updateGroupEntryDelegate);
    simpleGroupStore.addOrUpdateGroupEntry(updatedGroup);
    simpleGroupStore.unsetDelegate(updateGroupEntryDelegate);
}
 
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);
            }
        }
    }
}
 
Example 10
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 11
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 12
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);
    }
}