use of org.onosproject.net.group.GroupDescription 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);
}
}
use of org.onosproject.net.group.GroupDescription 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);
}
use of org.onosproject.net.group.GroupDescription 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);
}
}
}
}
use of org.onosproject.net.group.GroupDescription 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);
}
use of org.onosproject.net.group.GroupDescription 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));
}
}
Aggregations