@Override public ObjectNode encode(Group group, CodecContext context) { checkNotNull(group, "Group cannot be null"); ObjectNode result = context.mapper().createObjectNode() .put(ID, group.id().id().toString()) .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) { result.put(GIVEN_GROUP_ID, group.givenGroupId().toString()); } 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; }
@Override public void addOrUpdateExtraneousGroupEntry(Group group) { ConcurrentMap<GroupId, Group> extraneousIdTable = getExtraneousGroupIdTable(group.deviceId()); extraneousIdTable.put(group.id(), group); // Check the reference counter if (group.referenceCount() == 0) { notifyDelegate(new GroupEvent(Type.GROUP_REMOVE_REQUESTED, group)); } }
private void printGroups(DeviceId deviceId, List<Group> groups) { print("deviceId=%s, groupCount=%s", deviceId, groups.size()); if (countOnly) { return; } for (Group group : groups) { print(FORMAT, Integer.toHexString(group.id().id()), group.state(), group.type(), group.bytes(), group.packets(), group.appId().name(), group.referenceCount()); int i = 0; for (GroupBucket bucket:group.buckets().buckets()) { print(BUCKET_FORMAT, Integer.toHexString(group.id().id()), ++i, bucket.bytes(), bucket.packets(), bucket.treatment().allInstructions()); } } } }
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()); 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);
group.deviceId()) != null) ? groupEntriesById.get(group.deviceId()).get(group.id()) : null; GroupEvent event = null; for (GroupBucket bucket:group.buckets().buckets()) { Optional<GroupBucket> matchingBucket = existing.buckets().buckets() existing.setLife(group.life()); existing.setPackets(group.packets()); existing.setBytes(group.bytes()); if (existing.state() == GroupState.PENDING_ADD) { existing.setState(GroupState.ADDED);
final Group group = event.subject(); GroupProvider groupProvider = getProvider(group.deviceId()); GroupOperations groupOps = null; switch (event.type()) { case GROUP_ADD_REQUESTED: log.debug("GROUP_ADD_REQUESTED for Group {} on device {}", group.id(), group.deviceId()); GroupOperation groupAddOp = GroupOperation. createAddGroupOperation(group.id(), group.type(), group.buckets()); groupOps = new GroupOperations( Collections.singletonList(groupAddOp)); groupProvider.performGroupOperation(group.deviceId(), groupOps); break; group.id(), group.deviceId()); GroupOperation groupModifyOp = GroupOperation. createModifyGroupOperation(group.id(), group.type(), group.buckets()); groupOps = new GroupOperations( Collections.singletonList(groupModifyOp)); groupProvider.performGroupOperation(group.deviceId(), groupOps); break; group.id(), group.deviceId()); GroupOperation groupDeleteOp = GroupOperation.
@Override public void run() { Set<GroupKey> keys = pendingGroups .asMap() .keySet() .stream() .filter(key -> groupService.getGroup(deviceId, key) != null) .collect(Collectors.toSet()); keys.stream() .forEach(key -> { NextObjective obj = pendingGroups .getIfPresent(key); if (obj == null) { return; } log.debug("Group verified: dev:{} gid:{} <<->> nextId:{}", deviceId, groupService.getGroup(deviceId, key).id(), obj.id()); pass(obj); pendingGroups.invalidate(key); flowObjectiveStore.putNextGroup( obj.id(), new SpringOpenGroup(key, null)); }); } }
throws PiTranslationException { if (!SUPPORTED_GROUP_TYPES.contains(group.type())) { throw new PiTranslationException(format( "group type %s not supported", group.type())); .withId(PiActionProfileGroupId.of(group.id().id())); if (!(group.appCookie() instanceof PiGroupKey)) { throw new PiTranslationException("group app cookie is not PI (class should be PiGroupKey)"); final PiGroupKey groupKey = (PiGroupKey) group.appCookie(); for (GroupBucket bucket : group.buckets().buckets()) { .putShort((short) (group.id().id() & 0xffff)) .putShort(bucketIdx); bb.rewind();
if (!group.type().equals(GroupDescription.Type.ALL)) { throw new PiTranslationException(format( "group type %s not supported", group.type())); final List<Instruction> instructions = group.buckets().buckets().stream() .flatMap(b -> b.treatment().allInstructions().stream()) .collect(Collectors.toList()); .anyMatch(i -> !i.type().equals(Instruction.Type.OUTPUT)); if (instructions.size() != group.buckets().buckets().size() || hasNonOutputInstr) { throw new PiTranslationException( .withGroupId(group.id().id()) .addReplicas(getReplicas(outInstructions, device)) .build();
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); }
private void groupMissing(Group group) { switch (group.state()) { case PENDING_DELETE: log.debug("Group {} delete confirmation from device {}", group, group.deviceId()); removeGroupEntry(group); break; case PENDING_UPDATE: log.debug("Group {} is in store but not on device {}", group, group.deviceId()); StoredGroupEntry existing = (groupEntriesById.get( group.deviceId()) != null) ? groupEntriesById.get(group.deviceId()).get(group.id()) : null; log.trace("groupMissing: group "
Stream<Group> groupStream = Lists.newArrayList(groupService.getGroups(d.id())).stream(); if (groupsState != null) { groupStream = groupStream.filter(g -> g.state().equals(groupsState)); groupStream = groupStream.filter(g -> g.referenceCount() != 0); g.type().equals(GroupDescription.Type.valueOf(type.toUpperCase())));
@Override public void event(GroupEvent event) { if (event.type() == GroupEvent.Type.GROUP_ADDED) { log.trace("InnerGroupListener: Group ADDED " + "event received in device {}", deviceId); GroupKey key = event.subject().appCookie(); NextObjective obj = pendingGroups.getIfPresent(key); if (obj != null) { log.debug("Group verified: dev:{} gid:{} <<->> nextId:{}", deviceId, event.subject().id(), obj.id()); flowObjectiveStore .putNextGroup(obj.id(), new SpringOpenGroup(key, null)); pass(obj); pendingGroups.invalidate(key); } } else if (event.type() == GroupEvent.Type.GROUP_ADD_FAILED) { log.warn("InnerGroupListener: Group ADD " + "failed event received in device {}", deviceId); } } }
private List<GroupBucket> getUpdatedBucketList(Group oldGroup, UpdateType type, GroupBuckets buckets) { GroupBuckets oldBuckets = oldGroup.buckets(); List<GroupBucket> newBucketList = new ArrayList<GroupBucket>( oldBuckets.buckets());
@Override public void event(GroupEvent event) { log.trace("received group event of type {}", event.type()); switch (event.type()) { case GROUP_ADDED: processPendingAddGroupsOrNextObjs(event.subject().appCookie(), true); break; case GROUP_REMOVED: processPendingRemoveNextObjs(event.subject().appCookie()); break; default: break; } } }
private void extraneousGroup(Group group) { log.debug("Group {} is on device {} but not in store.", group, group.deviceId()); addOrUpdateExtraneousGroupEntry(group); }