Search in sources :

Example 1 with DefaultGroupDescription

use of org.onosproject.net.group.DefaultGroupDescription in project onos by opennetworkinglab.

the class K8sGroupRuleManager method setRule.

@Override
public void setRule(ApplicationId appId, DeviceId deviceId, int groupId, Type type, List<GroupBucket> buckets, boolean install) {
    if (install) {
        GroupDescription groupDesc = new DefaultGroupDescription(deviceId, type, new GroupBuckets(buckets), getGroupKey(groupId), groupId, appId);
        groupService.addGroup(groupDesc);
    } else {
        groupService.removeGroup(deviceId, getGroupKey(groupId), appId);
    }
}
Also used : DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) GroupBuckets(org.onosproject.net.group.GroupBuckets) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription)

Example 2 with DefaultGroupDescription

use of org.onosproject.net.group.DefaultGroupDescription in project onos by opennetworkinglab.

the class OpenstackVtapManager method createGroupTable.

private void createGroupTable(DeviceId deviceId, int groupId, List<Integer> tableIds, List<PortNumber> ports) {
    List<GroupBucket> buckets = Lists.newArrayList();
    if (tableIds != null) {
        tableIds.forEach(tableId -> {
            TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder().extension(buildResubmitExtension(deviceId, tableId), deviceId);
            GroupBucket bucket = DefaultGroupBucket.createAllGroupBucket(treatment.build());
            buckets.add(bucket);
        });
    }
    if (ports != null) {
        ports.forEach(port -> {
            TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder().setOutput(port);
            GroupBucket bucket = DefaultGroupBucket.createAllGroupBucket(treatment.build());
            buckets.add(bucket);
        });
    }
    GroupDescription groupDescription = new DefaultGroupDescription(deviceId, GroupDescription.Type.ALL, new GroupBuckets(buckets), getGroupKey(groupId), groupId, appId);
    groupService.addGroup(groupDescription);
}
Also used : GroupDescription(org.onosproject.net.group.GroupDescription) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) GroupBuckets(org.onosproject.net.group.GroupBuckets) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription)

Example 3 with DefaultGroupDescription

use of org.onosproject.net.group.DefaultGroupDescription in project onos by opennetworkinglab.

the class SimpleVirtualGroupStore method deviceInitialAuditCompleted.

@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);
            }
        }
    }
}
Also used : DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) DefaultGroup(org.onosproject.net.group.DefaultGroup) Group(org.onosproject.net.group.Group) DeviceId(org.onosproject.net.DeviceId) GroupKey(org.onosproject.net.group.GroupKey) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) StoredGroupEntry(org.onosproject.net.group.StoredGroupEntry)

Example 4 with DefaultGroupDescription

use of org.onosproject.net.group.DefaultGroupDescription in project onos by opennetworkinglab.

the class GroupCodec method decode.

@Override
public Group decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    final JsonCodec<GroupBucket> groupBucketCodec = context.codec(GroupBucket.class);
    CoreService coreService = context.getService(CoreService.class);
    // parse uInt Group id from the ID field
    JsonNode idNode = json.get(ID);
    Long id = (null == idNode) ? // use GROUP_ID for the corresponding Group id if ID is not supplied
    nullIsIllegal(json.get(GROUP_ID), ID + MISSING_MEMBER_MESSAGE).asLong() : idNode.asLong();
    GroupId groupId = GroupId.valueOf(id.intValue());
    // parse uInt Group id given by caller. see the GroupDescription javadoc
    JsonNode givenGroupIdNode = json.get(GIVEN_GROUP_ID);
    // if GIVEN_GROUP_ID is not supplied, set null so the group subsystem
    // to choose the Group id (which is the value of ID indeed).
    // else, must be same with ID to show both originate from the same source
    Integer givenGroupIdInt = (null == givenGroupIdNode) ? null : new Long(json.get(GIVEN_GROUP_ID).asLong()).intValue();
    if (givenGroupIdInt != null && !givenGroupIdInt.equals(groupId.id())) {
        throw new IllegalArgumentException(GIVEN_GROUP_ID + " must be same with " + ID);
    }
    // parse group key (appCookie)
    String groupKeyStr = nullIsIllegal(json.get(APP_COOKIE), APP_COOKIE + MISSING_MEMBER_MESSAGE).asText();
    if (!groupKeyStr.startsWith("0x")) {
        throw new IllegalArgumentException("APP_COOKIE must be a hex string starts with 0x");
    }
    GroupKey groupKey = new DefaultGroupKey(HexString.fromHexString(groupKeyStr.split("0x")[1], ""));
    // parse device id
    DeviceId deviceId = DeviceId.deviceId(nullIsIllegal(json.get(DEVICE_ID), DEVICE_ID + MISSING_MEMBER_MESSAGE).asText());
    // application id
    ApplicationId appId = coreService.registerApplication(REST_APP_ID);
    // parse group type
    String type = nullIsIllegal(json.get(TYPE), TYPE + MISSING_MEMBER_MESSAGE).asText();
    GroupDescription.Type groupType = null;
    switch(type) {
        case "SELECT":
            groupType = Group.Type.SELECT;
            break;
        case "INDIRECT":
            groupType = Group.Type.INDIRECT;
            break;
        case "ALL":
            groupType = Group.Type.ALL;
            break;
        case "CLONE":
            groupType = Group.Type.CLONE;
            break;
        case "FAILOVER":
            groupType = Group.Type.FAILOVER;
            break;
        default:
            nullIsIllegal(groupType, "The requested group type " + type + " is not valid");
    }
    // parse group buckets
    GroupBuckets buckets = null;
    List<GroupBucket> groupBucketList = new ArrayList<>();
    JsonNode bucketsJson = json.get(BUCKETS);
    checkNotNull(bucketsJson);
    if (bucketsJson != null) {
        IntStream.range(0, bucketsJson.size()).forEach(i -> {
            ObjectNode bucketJson = get(bucketsJson, i);
            bucketJson.put("type", type);
            groupBucketList.add(groupBucketCodec.decode(bucketJson, context));
        });
        buckets = new GroupBuckets(groupBucketList);
    }
    GroupDescription groupDescription = new DefaultGroupDescription(deviceId, groupType, buckets, groupKey, givenGroupIdInt, appId);
    return new DefaultGroup(groupId, groupDescription);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DeviceId(org.onosproject.net.DeviceId) GroupKey(org.onosproject.net.group.GroupKey) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) ArrayList(java.util.ArrayList) DefaultGroup(org.onosproject.net.group.DefaultGroup) CoreService(org.onosproject.core.CoreService) JsonNode(com.fasterxml.jackson.databind.JsonNode) HexString(org.onlab.util.HexString) GroupBuckets(org.onosproject.net.group.GroupBuckets) GroupId(org.onosproject.core.GroupId) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) GroupBucket(org.onosproject.net.group.GroupBucket) ApplicationId(org.onosproject.core.ApplicationId) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription)

Example 5 with DefaultGroupDescription

use of org.onosproject.net.group.DefaultGroupDescription in project onos by opennetworkinglab.

the class SimpleGroupStore method updateGroupDescription.

/**
 * 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));
    }
}
Also used : DefaultGroup(org.onosproject.net.group.DefaultGroup) Group(org.onosproject.net.group.Group) GroupKey(org.onosproject.net.group.GroupKey) DefaultGroup(org.onosproject.net.group.DefaultGroup) GroupBuckets(org.onosproject.net.group.GroupBuckets) StoredGroupEntry(org.onosproject.net.group.StoredGroupEntry) GroupEvent(org.onosproject.net.group.GroupEvent) GroupId(org.onosproject.core.GroupId) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription)

Aggregations

DefaultGroupDescription (org.onosproject.net.group.DefaultGroupDescription)57 GroupBuckets (org.onosproject.net.group.GroupBuckets)51 GroupDescription (org.onosproject.net.group.GroupDescription)49 GroupBucket (org.onosproject.net.group.GroupBucket)46 GroupKey (org.onosproject.net.group.GroupKey)41 DefaultGroupBucket (org.onosproject.net.group.DefaultGroupBucket)39 DefaultGroupKey (org.onosproject.net.group.DefaultGroupKey)36 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)33 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)33 GroupId (org.onosproject.core.GroupId)21 Group (org.onosproject.net.group.Group)21 ArrayList (java.util.ArrayList)18 OfdpaGroupHandlerUtility.l2MulticastGroupKey (org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility.l2MulticastGroupKey)15 ArrayDeque (java.util.ArrayDeque)13 Deque (java.util.Deque)13 DefaultGroup (org.onosproject.net.group.DefaultGroup)13 PortNumber (org.onosproject.net.PortNumber)11 VlanId (org.onlab.packet.VlanId)10 TrafficSelector (org.onosproject.net.flow.TrafficSelector)10 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)9