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

The following examples show how to use org.onosproject.net.group.Group#id() . 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: Bmv2PreGroupTranslatorImpl.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a BMv2 PRE group equivalent to given group.
 *
 * @param group group
 * @return a BMv2 PRE group
 */
public static Bmv2PreGroup translate(Group group) {
    if (!group.type().equals(GroupDescription.Type.ALL)) {
        throw new IllegalStateException("Unable to translate the group to BMv2 PRE group." +
                                           "A BMv2 PRE group is to be of ALL type. GroupId="
                                           + group.id());
    }

    Bmv2PreGroup.Bmv2PreGroupBuilder bmv2PreGroupBuilder = Bmv2PreGroup.builder();
    bmv2PreGroupBuilder.withGroupId(group.id().id());
    // RID is generated per an MG since L2 broadcast can be considered as a MG that have a single RID.
    // for simplicity RID will be assigned to zero for any node in an MG.
    int replicationId = 0;

    Set<PortNumber> outPorts = Sets.newHashSet();
    group.buckets().buckets().forEach(groupBucket -> {
        //get output instructions of the bucket
        Set<Instructions.OutputInstruction> outputInstructions = getOutputInstructions(groupBucket.treatment());
        //check validity of output instructions
        checkOutputInstructions(group.id(), outputInstructions);
        outPorts.add(outputInstructions.iterator().next().port());
    });
    validatePorts(outPorts);
    bmv2PreGroupBuilder.addNode(Bmv2PreNode.builder()
                                        .withRid(replicationId)
                                        .withPortMap(buildPortMap(outPorts))
                                        .build());
    return bmv2PreGroupBuilder.build();
}
 
Example 3
Source File: ScalableGatewayManager.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized GroupId getGatewayGroupId(DeviceId srcDeviceId) {
    GroupKey groupKey = selectGroupHandler.getGroupKey(srcDeviceId);
    Group group = groupService.getGroup(srcDeviceId, groupKey);
    if (group == null) {
        log.info("Created gateway group for {}", srcDeviceId);
        return selectGroupHandler.createGatewayGroup(srcDeviceId, getGatewayNodes());
    } else {
        return group.id();
    }
}
 
Example 4
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 5
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 6
Source File: P4RuntimeReplicationGroupProgrammable.java    From onos with Apache License 2.0 4 votes vote down vote up
private Group addedGroup(Group original, long life) {
    final DefaultGroup forgedGroup = new DefaultGroup(original.id(), original);
    forgedGroup.setState(Group.GroupState.ADDED);
    forgedGroup.setLife(life);
    return forgedGroup;
}
 
Example 7
Source File: P4RuntimeActionGroupProgrammable.java    From onos with Apache License 2.0 4 votes vote down vote up
private Group addedGroup(Group original, long life) {
    final DefaultGroup forgedGroup = new DefaultGroup(original.id(), original);
    forgedGroup.setState(Group.GroupState.ADDED);
    forgedGroup.setLife(life);
    return forgedGroup;
}
 
Example 8
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 9
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 10
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);
    }
}