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

The following examples show how to use org.onosproject.net.group.Group#appCookie() . 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: 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 2
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 3
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 4
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 5
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 6
Source File: Ofdpa2GroupHandler.java    From onos with Apache License 2.0 4 votes vote down vote up
private void addBucketToL2HashGroup(NextObjective nextObjective,
                                      List<Deque<GroupKey>> allActiveKeys) {
    // storage for all group keys in the chain of groups created
    List<Deque<GroupKey>> allGroupKeys = new ArrayList<>();
    List<GroupInfo> unsentGroups = new ArrayList<>();
    List<GroupBucket> newBuckets;
    // Prepare the l2 unfiltered groups
    createL2HashBuckets(nextObjective, allGroupKeys, unsentGroups);
    // now we can create the buckets to add to the outermost L2 hash group
    newBuckets = generateNextGroupBuckets(unsentGroups, SELECT);
    // retrieve the original l2 load balance group
    Group l2hashGroup = retrieveTopLevelGroup(allActiveKeys, deviceId,
                                              groupService, nextObjective.id());
    if (l2hashGroup == null) {
        fail(nextObjective, ObjectiveError.GROUPMISSING);
        return;
    }
    GroupKey l2hashGroupKey = l2hashGroup.appCookie();
    int l2hashGroupId = l2hashGroup.id().id();
    GroupDescription l2hashGroupDesc = new DefaultGroupDescription(deviceId,
                                                                   SELECT,
                                                                   new GroupBuckets(newBuckets),
                                                                   l2hashGroupKey,
                                                                   l2hashGroupId,
                                                                   nextObjective.appId());
    GroupChainElem l2hashGce = new GroupChainElem(l2hashGroupDesc,
                                                  unsentGroups.size(),
                                                  true,
                                                  deviceId);
    // update new bucket-chains
    List<Deque<GroupKey>> addedKeys = new ArrayList<>();
    for (Deque<GroupKey> newBucketChain : allGroupKeys) {
        newBucketChain.addFirst(l2hashGroupKey);
        addedKeys.add(newBucketChain);
    }
    updatePendingNextObjective(l2hashGroupKey,
                               new OfdpaNextGroup(addedKeys, nextObjective));
    log.debug("Adding to L2HASH: device:{} gid:{} group key:{} nextId:{}",
              deviceId, Integer.toHexString(l2hashGroupId),
              l2hashGroupKey, nextObjective.id());
    unsentGroups.forEach(groupInfo -> {
        // send the innermost group
        log.debug("Sending innermost group {} in group chain on device {} ",
                  Integer.toHexString(groupInfo.innerMostGroupDesc().givenGroupId()),
                  deviceId);
        updatePendingGroups(groupInfo.nextGroupDesc().appCookie(), l2hashGce);
        groupService.addGroup(groupInfo.innerMostGroupDesc());
    });
}
 
Example 7
Source File: Ofdpa2GroupHandler.java    From onos with Apache License 2.0 4 votes vote down vote up
private void addBucketToEcmpHashGroup(NextObjective nextObjective,
                                  List<Deque<GroupKey>> allActiveKeys) {
    // storage for all group keys in the chain of groups created
    List<Deque<GroupKey>> allGroupKeys = new ArrayList<>();
    List<GroupInfo> unsentGroups = new ArrayList<>();
    List<GroupBucket> newBuckets;
    createEcmpHashBucketChains(nextObjective, allGroupKeys, unsentGroups);
    // now we can create the buckets to add to the outermost L3 ECMP group
    newBuckets = generateNextGroupBuckets(unsentGroups, SELECT);
    // retrieve the original L3 ECMP group
    Group l3ecmpGroup = retrieveTopLevelGroup(allActiveKeys, deviceId,
                                              groupService, nextObjective.id());
    if (l3ecmpGroup == null) {
        fail(nextObjective, ObjectiveError.GROUPMISSING);
        return;
    }
    GroupKey l3ecmpGroupKey = l3ecmpGroup.appCookie();
    int l3ecmpGroupId = l3ecmpGroup.id().id();
    // Although GroupDescriptions are not necessary for adding buckets to
    // existing groups, we still use one in the GroupChainElem. When the latter is
    // processed, the info will be extracted for the bucketAdd call to groupService
    GroupDescription l3ecmpGroupDesc =
            new DefaultGroupDescription(deviceId,
                                        SELECT,
                                        new GroupBuckets(newBuckets),
                                        l3ecmpGroupKey,
                                        l3ecmpGroupId,
                                        nextObjective.appId());
    GroupChainElem l3ecmpGce = new GroupChainElem(l3ecmpGroupDesc,
                                                  unsentGroups.size(),
                                                  true,
                                                  deviceId);

    // update new bucket-chains
    List<Deque<GroupKey>> addedKeys = new ArrayList<>();
    for (Deque<GroupKey> newBucketChain : allGroupKeys) {
        newBucketChain.addFirst(l3ecmpGroupKey);
        addedKeys.add(newBucketChain);
    }
    updatePendingNextObjective(l3ecmpGroupKey,
                               new OfdpaNextGroup(addedKeys, nextObjective));
    log.debug("Adding to L3ECMP: device:{} gid:{} group key:{} nextId:{}",
            deviceId, Integer.toHexString(l3ecmpGroupId),
            l3ecmpGroupKey, nextObjective.id());
    unsentGroups.forEach(groupInfo -> {
        // send the innermost group
        log.debug("Sending innermost group {} in group chain on device {} ",
                  Integer.toHexString(groupInfo.innerMostGroupDesc().givenGroupId()),
                  deviceId);
        updatePendingGroups(groupInfo.nextGroupDesc().appCookie(), l3ecmpGce);
        groupService.addGroup(groupInfo.innerMostGroupDesc());
    });
}
 
Example 8
Source File: Ofdpa2GroupHandler.java    From onos with Apache License 2.0 4 votes vote down vote up
private void addBucketToL2FloodGroup(NextObjective nextObj,
                                     List<Deque<GroupKey>> allActiveKeys,
                                     List<GroupInfo> groupInfos,
                                     VlanId assignedVlan) {
    Group l2FloodGroup = retrieveTopLevelGroup(allActiveKeys, deviceId,
                                               groupService, nextObj.id());

    if (l2FloodGroup == null) {
        log.warn("Can't find L2 flood group while adding bucket to it. NextObj = {}",
                 nextObj);
        fail(nextObj, ObjectiveError.GROUPMISSING);
        return;
    }

    GroupKey l2floodGroupKey = l2FloodGroup.appCookie();
    int l2floodGroupId = l2FloodGroup.id().id();
    List<GroupBucket> newBuckets = generateNextGroupBuckets(groupInfos, ALL);
    GroupDescription l2FloodGroupDescription =
            new DefaultGroupDescription(deviceId,
                                        ALL,
                                        new GroupBuckets(newBuckets),
                                        l2floodGroupKey,
                                        l2floodGroupId,
                                        nextObj.appId());
    GroupChainElem l2FloodGroupChainElement =
            new GroupChainElem(l2FloodGroupDescription,
                               groupInfos.size(),
                               true,
                               deviceId);


    //ensure assignedVlan applies to the chosen group
    VlanId floodGroupVlan = extractVlanIdFromGroupId(l2floodGroupId);
    if (!floodGroupVlan.equals(assignedVlan)) {
        log.warn("VLAN ID {} does not match Flood group {} to which bucket is "
                         + "being added, for next:{} in dev:{}. Abort.", assignedVlan,
                 Integer.toHexString(l2floodGroupId), nextObj.id(), deviceId);
        fail(nextObj, ObjectiveError.BADPARAMS);
        return;
    }
    List<Deque<GroupKey>> addedKeys = new ArrayList<>();
    groupInfos.forEach(groupInfo -> {
        // update original NextGroup with new bucket-chain
        Deque<GroupKey> newBucketChain = new ArrayDeque<>();
        newBucketChain.addFirst(groupInfo.nextGroupDesc().appCookie());
        newBucketChain.addFirst(l2floodGroupKey);
        addedKeys.add(newBucketChain);
        log.debug("Adding to L2FLOOD: device:{} gid:{} group key:{} nextId:{}",
                  deviceId, Integer.toHexString(l2floodGroupId),
                  l2floodGroupKey, nextObj.id());
        // send the innermost group
        log.debug("Sending innermost group {} in group chain on device {} ",
                  Integer.toHexString(groupInfo.innerMostGroupDesc().givenGroupId()),
                  deviceId);
        updatePendingGroups(groupInfo.nextGroupDesc().appCookie(), l2FloodGroupChainElement);

        DeviceId innerMostGroupDevice = groupInfo.innerMostGroupDesc().deviceId();
        GroupKey innerMostGroupKey = groupInfo.innerMostGroupDesc().appCookie();
        Group existsL2IGroup = groupService.getGroup(innerMostGroupDevice, innerMostGroupKey);

        if (existsL2IGroup != null) {
            // group already exist
            processPendingAddGroupsOrNextObjs(innerMostGroupKey, true);
        } else {
            groupService.addGroup(groupInfo.innerMostGroupDesc());
        }
    });

    updatePendingNextObjective(l2floodGroupKey,
                               new OfdpaNextGroup(addedKeys, nextObj));
}
 
Example 9
Source File: Ofdpa2GroupHandler.java    From onos with Apache License 2.0 4 votes vote down vote up
private void addBucketToL3MulticastGroup(NextObjective nextObj,
                                         List<Deque<GroupKey>> allActiveKeys,
                                         List<GroupInfo> groupInfos,
                                         VlanId assignedVlan) {
    // Create the buckets to add to the outermost L3 Multicast group
    List<GroupBucket> newBuckets = createL3MulticastBucket(groupInfos);

    // get the group being edited
    Group l3mcastGroup = retrieveTopLevelGroup(allActiveKeys, deviceId,
                                               groupService, nextObj.id());
    if (l3mcastGroup == null) {
        fail(nextObj, ObjectiveError.GROUPMISSING);
        return;
    }
    GroupKey l3mcastGroupKey = l3mcastGroup.appCookie();
    int l3mcastGroupId = l3mcastGroup.id().id();

    //ensure assignedVlan applies to the chosen group
    VlanId expectedVlan = extractVlanIdFromGroupId(l3mcastGroupId);
    if (!expectedVlan.equals(assignedVlan)) {
        log.warn("VLAN ID {} does not match L3 Mcast group {} to which bucket is "
                + "being added, for next:{} in dev:{}. Abort.", assignedVlan,
                Integer.toHexString(l3mcastGroupId), nextObj.id(), deviceId);
        fail(nextObj, ObjectiveError.BADPARAMS);
    }
    GroupDescription l3mcastGroupDescription =
            new DefaultGroupDescription(deviceId,
                                        ALL,
                                        new GroupBuckets(newBuckets),
                                        l3mcastGroupKey,
                                        l3mcastGroupId,
                                        nextObj.appId());
    GroupChainElem l3mcastGce = new GroupChainElem(l3mcastGroupDescription,
                                                   groupInfos.size(),
                                                   true,
                                                   deviceId);

    List<Deque<GroupKey>> addedKeys = new ArrayList<>();
    groupInfos.forEach(groupInfo -> {
        // update original NextGroup with new bucket-chain
        Deque<GroupKey> newBucketChain = new ArrayDeque<>();
        newBucketChain.addFirst(groupInfo.innerMostGroupDesc().appCookie());
        // Add L3 interface group to the chain if there is one.
        if (!groupInfo.nextGroupDesc().equals(groupInfo.innerMostGroupDesc())) {
            newBucketChain.addFirst(groupInfo.nextGroupDesc().appCookie());
        }
        newBucketChain.addFirst(l3mcastGroupKey);
        addedKeys.add(newBucketChain);

        updatePendingGroups(groupInfo.nextGroupDesc().appCookie(), l3mcastGce);
        // Point next group to inner-most group, if any
        if (!groupInfo.nextGroupDesc().equals(groupInfo.innerMostGroupDesc())) {
            GroupChainElem innerGce = new GroupChainElem(groupInfo.nextGroupDesc(),
                                                         1,
                                                         false,
                                                         deviceId);
            updatePendingGroups(groupInfo.innerMostGroupDesc().appCookie(), innerGce);
        }
        log.debug("Adding to L3MCAST: device:{} gid:{} group key:{} nextId:{}",
                  deviceId, Integer.toHexString(l3mcastGroupId),
                  l3mcastGroupKey, nextObj.id());
        // send the innermost group
        log.debug("Sending innermost group {} in group chain on device {} ",
                  Integer.toHexString(groupInfo.innerMostGroupDesc().givenGroupId()),
                  deviceId);
        groupService.addGroup(groupInfo.innerMostGroupDesc());

    });

    updatePendingNextObjective(l3mcastGroupKey,
                               new OfdpaNextGroup(addedKeys, nextObj));
}