use of org.onosproject.net.group.GroupBuckets in project onos by opennetworkinglab.
the class OpenFlowGroupProvider method buildGroupMetrics.
private Collection<Group> buildGroupMetrics(DeviceId deviceId, OFGroupStatsReply groupStatsReply, OFGroupDescStatsReply groupDescStatsReply) {
Map<Integer, Group> groups = Maps.newHashMap();
Dpid dpid = Dpid.dpid(deviceId.uri());
for (OFGroupDescStatsEntry entry : groupDescStatsReply.getEntries()) {
int id = entry.getGroup().getGroupNumber();
GroupId groupId = new GroupId(id);
GroupDescription.Type type = getGroupType(entry.getGroupType());
GroupBuckets buckets = new GroupBucketEntryBuilder(dpid, entry.getBuckets(), entry.getGroupType(), driverService).build();
DefaultGroup group = new DefaultGroup(groupId, deviceId, type, buckets);
groups.put(id, group);
}
if (groupStatsReply == null) {
return groups.values();
}
for (OFGroupStatsEntry entry : groupStatsReply.getEntries()) {
int groupId = entry.getGroup().getGroupNumber();
DefaultGroup group = (DefaultGroup) groups.get(groupId);
if (group != null) {
group.setBytes(entry.getByteCount().getValue());
group.setLife(entry.getDurationSec());
group.setPackets(entry.getPacketCount().getValue());
group.setReferenceCount(entry.getRefCount());
int bucketIndex = 0;
for (OFBucketCounter bucketStats : entry.getBucketStats()) {
((StoredGroupBucketEntry) group.buckets().buckets().get(bucketIndex)).setPackets(bucketStats.getPacketCount().getValue());
((StoredGroupBucketEntry) group.buckets().buckets().get(bucketIndex)).setBytes(entry.getBucketStats().get(bucketIndex).getByteCount().getValue());
bucketIndex++;
}
}
}
return groups.values();
}
use of org.onosproject.net.group.GroupBuckets in project onos by opennetworkinglab.
the class OpenFlowGroupProviderTest method addGroup.
@Test
public void addGroup() {
GroupId groupId = new GroupId(1);
List<GroupBucket> bucketList = Lists.newArrayList();
TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
builder.setOutput(PortNumber.portNumber(1));
GroupBucket bucket = DefaultGroupBucket.createSelectGroupBucket(builder.build());
bucketList.add(bucket);
GroupBuckets buckets = new GroupBuckets(bucketList);
List<GroupOperation> operationList = Lists.newArrayList();
GroupOperation operation = GroupOperation.createAddGroupOperation(groupId, GroupDescription.Type.SELECT, buckets);
operationList.add(operation);
GroupOperations operations = new GroupOperations(operationList);
provider.performGroupOperation(deviceId, operations);
final Dpid dpid = Dpid.dpid(deviceId.uri());
TestOpenFlowSwitch sw = (TestOpenFlowSwitch) controller.getSwitch(dpid);
assertNotNull("Switch should not be nul", sw);
assertNotNull("OFGroupMsg should not be null", sw.msg);
}
use of org.onosproject.net.group.GroupBuckets in project onos by opennetworkinglab.
the class NextObjectiveTranslator method allGroup.
private int allGroup(NextObjective obj, ObjectiveTranslation.Builder resultBuilder) throws FabricPipelinerException {
final Collection<DefaultNextTreatment> defaultNextTreatments = defaultNextTreatments(obj.nextTreatments(), true);
// multicast entries is based solely on the output port.
for (DefaultNextTreatment t : defaultNextTreatments) {
handleEgress(obj, t.treatment(), resultBuilder, true);
}
// FIXME: this implementation supports only the case in which each
// switch interface is associated with only one VLAN, otherwise we would
// need to support replicating multiple times the same packet for the
// same port while setting different VLAN IDs. Hence, collect in a set.
final Set<PortNumber> outPorts = defaultNextTreatments.stream().map(DefaultNextTreatment::treatment).map(FabricUtils::outputPort).filter(Objects::nonNull).collect(Collectors.toSet());
if (outPorts.size() != defaultNextTreatments.size()) {
throw new FabricPipelinerException(format("Found BROADCAST NextObjective with %d treatments but " + "found only %d distinct OUTPUT port numbers, cannot " + "translate to ALL groups", defaultNextTreatments.size(), outPorts.size()), ObjectiveError.UNSUPPORTED);
}
final List<GroupBucket> bucketList = outPorts.stream().map(p -> DefaultTrafficTreatment.builder().setOutput(p).build()).map(DefaultGroupBucket::createAllGroupBucket).collect(Collectors.toList());
final int groupId = obj.id();
// Use DefaultGroupKey instead of PiGroupKey as we don't have any
// action profile to apply to the groups of ALL type.
final GroupKey groupKey = getGroupKey(obj);
resultBuilder.addGroup(new DefaultGroupDescription(deviceId, GroupDescription.Type.ALL, new GroupBuckets(bucketList), groupKey, groupId, obj.appId()));
return groupId;
}
use of org.onosproject.net.group.GroupBuckets in project onos by opennetworkinglab.
the class NextObjectiveTranslator method selectGroup.
private int selectGroup(NextObjective obj, ObjectiveTranslation.Builder resultBuilder) throws FabricPipelinerException {
final PiTableId hashedTableId = FabricConstants.FABRIC_INGRESS_NEXT_HASHED;
final List<DefaultNextTreatment> defaultNextTreatments = defaultNextTreatments(obj.nextTreatments(), true);
final List<TrafficTreatment> piTreatments = Lists.newArrayList();
for (DefaultNextTreatment t : defaultNextTreatments) {
// Map treatment to PI...
piTreatments.add(mapTreatmentToPiIfNeeded(t.treatment(), hashedTableId));
// ...and handle egress if necessary.
handleEgress(obj, t.treatment(), resultBuilder, false);
}
final List<GroupBucket> bucketList = piTreatments.stream().map(DefaultGroupBucket::createSelectGroupBucket).collect(Collectors.toList());
final int groupId = obj.id();
final PiGroupKey groupKey = (PiGroupKey) getGroupKey(obj);
resultBuilder.addGroup(new DefaultGroupDescription(deviceId, GroupDescription.Type.SELECT, new GroupBuckets(bucketList), groupKey, groupId, obj.appId()));
return groupId;
}
use of org.onosproject.net.group.GroupBuckets in project onos by opennetworkinglab.
the class NextObjectiveTranslator method indirectGroup.
private int indirectGroup(NextObjective obj, ObjectiveTranslation.Builder resultBuilder) throws FabricPipelinerException {
if (isGroupModifyOp(obj)) {
throw new FabricPipelinerException("Simple next objective does not support" + "*_TO_EXISTING operations");
}
final PiTableId hashedTableId = FabricConstants.FABRIC_INGRESS_NEXT_HASHED;
final List<DefaultNextTreatment> defaultNextTreatments = defaultNextTreatments(obj.nextTreatments(), true);
if (defaultNextTreatments.size() != 1) {
throw new FabricPipelinerException("Simple next objective must have a single" + " treatment");
}
final TrafficTreatment piTreatment;
final DefaultNextTreatment defaultNextTreatment = defaultNextTreatments.get(0);
piTreatment = mapTreatmentToPiIfNeeded(defaultNextTreatment.treatment(), hashedTableId);
handleEgress(obj, defaultNextTreatment.treatment(), resultBuilder, false);
final GroupBucket groupBucket = DefaultGroupBucket.createIndirectGroupBucket(piTreatment);
final int groupId = obj.id();
final PiGroupKey groupKey = (PiGroupKey) getGroupKey(obj);
resultBuilder.addGroup(new DefaultGroupDescription(deviceId, GroupDescription.Type.INDIRECT, new GroupBuckets(Collections.singletonList(groupBucket)), groupKey, groupId, obj.appId()));
return groupId;
}
Aggregations