use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.Buckets in project openflowplugin by opendaylight.
the class GroupDescStatsResponseConvertorTest method testSingleGroupDescStat.
/**
* Test single GroupDescStat conversion without buckets.
*/
@Test
public void testSingleGroupDescStat() {
GroupDescBuilder builder = new GroupDescBuilder();
builder.setType(GroupType.OFPGTALL);
builder.setGroupId(new GroupId(42L));
builder.setBucketsList(new ArrayList<>());
List<GroupDesc> groupDescStats = new ArrayList<>();
groupDescStats.add(builder.build());
VersionConvertorData data = new VersionConvertorData(OFConstants.OFP_VERSION_1_3);
List<GroupDescStats> statsList = convert(groupDescStats, data);
Assert.assertEquals("Wrong groupDesc stats size", 1, statsList.size());
GroupDescStats stat = statsList.get(0);
Assert.assertEquals("Wrong type", GroupTypes.GroupAll, stat.getGroupType());
Assert.assertEquals("Wrong group-id", 42, stat.getGroupId().getValue().intValue());
Assert.assertEquals("Wrong key", 42, stat.getKey().getGroupId().getValue().intValue());
Assert.assertEquals("Wrong buckets size", 0, stat.getBuckets().getBucket().size());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.Buckets in project openflowplugin by opendaylight.
the class ReconcileUtil method resolveAndDivideGroupDiffs.
/**
* Returns a list of safe synchronization steps.
*
* @param nodeId target node
* @param installedGroupsArg groups resent on device
* @param pendingGroups groups configured for device
* @param gatherUpdates check content of pending item if present on device (and create update task eventually)
* @return list of safe synchronization steps
*/
public static List<ItemSyncBox<Group>> resolveAndDivideGroupDiffs(final NodeId nodeId, final Map<Long, Group> installedGroupsArg, final Collection<Group> pendingGroups, final boolean gatherUpdates) {
final Map<Long, Group> installedGroups = new HashMap<>(installedGroupsArg);
final List<ItemSyncBox<Group>> plan = new ArrayList<>();
while (!Iterables.isEmpty(pendingGroups)) {
final ItemSyncBox<Group> stepPlan = new ItemSyncBox<>();
final Iterator<Group> iterator = pendingGroups.iterator();
final Map<Long, Group> installIncrement = new HashMap<>();
while (iterator.hasNext()) {
final Group group = iterator.next();
final Group existingGroup = installedGroups.get(group.getGroupId().getValue());
if (existingGroup != null) {
if (!gatherUpdates) {
iterator.remove();
} else {
// check buckets and eventually update
if (group.equals(existingGroup)) {
iterator.remove();
} else {
if (checkGroupPrecondition(installedGroups.keySet(), group)) {
iterator.remove();
LOG.trace("Group {} on device {} differs - planned for update", group.getGroupId(), nodeId);
stepPlan.getItemsToUpdate().add(new ItemSyncBox.ItemUpdateTuple<>(existingGroup, group));
}
}
}
} else if (checkGroupPrecondition(installedGroups.keySet(), group)) {
iterator.remove();
installIncrement.put(group.getGroupId().getValue(), group);
stepPlan.getItemsToPush().add(group);
}
}
if (!stepPlan.isEmpty()) {
// atomic update of installed flows in order to keep plan portions clean of local group dependencies
installedGroups.putAll(installIncrement);
plan.add(stepPlan);
} else if (!pendingGroups.isEmpty()) {
LOG.warn("Failed to resolve and divide groups into preconditions-match based ordered plan: {}, " + "resolving stuck at level {}", nodeId.getValue(), plan.size());
throw new IllegalStateException("Failed to resolve and divide groups when matching preconditions");
}
}
return plan;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.Buckets in project openflowplugin by opendaylight.
the class GroupMessageDeserializer method deserialize.
@Override
public GroupMessage deserialize(ByteBuf message) {
final GroupMessageBuilder builder = new GroupMessageBuilder().setVersion((short) EncodeConstants.OF13_VERSION_ID).setXid(message.readUnsignedInt()).setCommand(GroupModCommand.forValue(message.readUnsignedShort()));
builder.setGroupType(GroupTypes.forValue(message.readUnsignedByte()));
message.skipBytes(PADDING);
builder.setGroupId(new GroupId(message.readUnsignedInt()));
final List<Bucket> buckets = new ArrayList<>();
while (message.readableBytes() > 0) {
final int length = message.readUnsignedShort();
final BucketBuilder bucket = new BucketBuilder().setWeight(message.readUnsignedShort()).setWatchPort(message.readUnsignedInt()).setWatchGroup(message.readUnsignedInt());
message.skipBytes(PADDING_IN_BUCKETS_HEADER);
if (message.readableBytes() > 0) {
final List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> actions = new ArrayList<>();
final int startIndex = message.readerIndex();
final int bucketLength = length - BUCKETS_HEADER_LENGTH;
int offset = 0;
while (message.readerIndex() - startIndex < bucketLength) {
actions.add(new ActionBuilder().setKey(new ActionKey(offset)).setOrder(offset).setAction(ActionUtil.readAction(EncodeConstants.OF13_VERSION_ID, message, registry, ActionPath.GROUP_DESC_STATS_UPDATED_BUCKET_ACTION)).build());
offset++;
}
bucket.setAction(actions);
}
buckets.add(bucket.build());
}
buckets.sort(COMPARATOR);
return builder.setBuckets(new BucketsBuilder().setBucket(buckets).build()).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.Buckets in project openflowplugin by opendaylight.
the class GroupStatsResponseConvertor method toSALBuckets.
private Buckets toSALBuckets(List<BucketStats> bucketStats) {
BucketsBuilder salBuckets = new BucketsBuilder();
List<BucketCounter> allBucketStats = new ArrayList<>();
int bucketKey = 0;
for (BucketStats bucketStat : bucketStats) {
BucketCounterBuilder bucketCounter = new BucketCounterBuilder();
bucketCounter.setByteCount(new Counter64(bucketStat.getByteCount()));
bucketCounter.setPacketCount(new Counter64(bucketStat.getPacketCount()));
BucketId bucketId = new BucketId((long) bucketKey);
bucketCounter.setKey(new BucketCounterKey(bucketId));
bucketCounter.setBucketId(bucketId);
bucketKey++;
allBucketStats.add(bucketCounter.build());
}
salBuckets.setBucketCounter(allBucketStats);
return salBuckets.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.Buckets in project genius by opendaylight.
the class MDSALUtil method buildBuckets.
protected static Buckets buildBuckets(List<BucketInfo> listBucketInfo) {
long index = 0;
if (listBucketInfo != null) {
BucketsBuilder bucketsBuilder = new BucketsBuilder();
List<Bucket> bucketList = new ArrayList<>();
for (BucketInfo bucketInfo : listBucketInfo) {
BucketBuilder bucketBuilder = new BucketBuilder();
bucketBuilder.setAction(bucketInfo.buildActions());
bucketBuilder.setWeight(bucketInfo.getWeight());
bucketBuilder.setBucketId(new BucketId(index++));
bucketBuilder.setWeight(bucketInfo.getWeight()).setWatchPort(bucketInfo.getWatchPort()).setWatchGroup(bucketInfo.getWatchGroup());
bucketList.add(bucketBuilder.build());
}
bucketsBuilder.setBucket(bucketList);
return bucketsBuilder.build();
}
return EMPTY_BUCKETS;
}
Aggregations