use of org.onosproject.net.pi.runtime.PiGroupKey in project onos by opennetworkinglab.
the class PiGroupTranslatorImpl method translate.
/**
* Returns a PI action profile group equivalent to the given group, for the
* given pipeconf and device.
*
* @param group group
* @param pipeconf pipeconf
* @param device device
* @return PI action profile group
* @throws PiTranslationException if the group cannot be translated
*/
static PiActionProfileGroup translate(Group group, PiPipeconf pipeconf, Device device) throws PiTranslationException {
if (!SUPPORTED_GROUP_TYPES.contains(group.type())) {
throw new PiTranslationException(format("group type %s not supported", group.type()));
}
// TODO: define proper field in group class.
if (!(group.appCookie() instanceof PiGroupKey)) {
throw new PiTranslationException("group app cookie is not PI (class should be PiGroupKey)");
}
final PiGroupKey groupKey = (PiGroupKey) group.appCookie();
final PiActionProfileId actionProfileId = groupKey.actionProfileId();
// Check validity of action profile against pipeconf.
final PiActionProfileModel actionProfileModel = pipeconf.pipelineModel().actionProfiles(actionProfileId).orElseThrow(() -> new PiTranslationException(format("no such action profile '%s'", actionProfileId)));
if (!actionProfileModel.hasSelector()) {
throw new PiTranslationException(format("action profile '%s' does not support dynamic selection", actionProfileId));
}
// Check if the table associated with the action profile supports only
// one-shot action profile programming.
boolean isTableOneShot = actionProfileModel.tables().stream().map(tableId -> pipeconf.pipelineModel().table(tableId)).allMatch(piTableModel -> piTableModel.isPresent() && piTableModel.get().oneShotOnly());
if (isTableOneShot) {
throw new PiTranslationException(format("Table associated to action profile '%s' supports only one-shot action profile programming", actionProfileId));
}
// Check group validity.
if (actionProfileModel.maxGroupSize() > 0 && group.buckets().buckets().size() > actionProfileModel.maxGroupSize()) {
throw new PiTranslationException(format("too many buckets, max group size for action profile '%s' is %d", actionProfileId, actionProfileModel.maxGroupSize()));
}
// If not INDIRECT, we set the maximum group size as specified in the
// model, however this might be highly inefficient for some HW targets
// which pre-allocate resources for the whole group.
final int maxGroupSize = group.type() == GroupDescription.Type.INDIRECT ? 1 : actionProfileModel.maxGroupSize();
final PiActionProfileGroup.Builder piActionGroupBuilder = PiActionProfileGroup.builder().withId(PiActionProfileGroupId.of(group.id().id())).withActionProfileId(groupKey.actionProfileId()).withMaxSize(maxGroupSize);
// Translate group buckets to PI group members
final PiPipelineInterpreter interpreter = getInterpreterOrNull(device, pipeconf);
short bucketIdx = 0;
for (GroupBucket bucket : group.buckets().buckets()) {
/*
FIXME: the way member IDs are computed can cause collisions!
Problem: In P4Runtime action profile members, i.e. action buckets,
are associated to a numeric ID chosen at member insertion time. This
ID must be unique for the whole action profile (i.e. the group table
in OpenFlow). In ONOS, GroupBucket doesn't specify any ID.
Solutions:
- Change GroupBucket API to force application wanting to perform
group operations to specify a member id.
- Maintain state to dynamically allocate/deallocate member IDs, e.g.
in a dedicated service, or in a P4Runtime Group Provider.
Hack: Statically derive member ID by combining groupId and position
of the bucket in the list.
*/
final int memberId = Objects.hash(group.id(), bucketIdx);
if (memberId == 0) {
throw new PiTranslationException("GroupBucket produces PiActionProfileMember " + "with invalid ID 0");
}
bucketIdx++;
final PiTableAction tableAction = translateTreatment(bucket.treatment(), interpreter, groupKey.tableId(), pipeconf.pipelineModel());
if (tableAction == null) {
throw new PiTranslationException("bucket treatment translator returned null");
}
if (tableAction.type() != ACTION) {
throw new PiTranslationException(format("action of type '%s' cannot be used in action profile members", tableAction.type()));
}
final PiActionProfileMember member = PiActionProfileMember.builder().forActionProfile(groupKey.actionProfileId()).withId(PiActionProfileMemberId.of(memberId)).withAction((PiAction) tableAction).build();
// NOTE Indirect groups have weight set to -1 which is not supported
// by P4RT - setting to 1 to avoid problems with the p4rt server.
final int weight = group.type() == GroupDescription.Type.INDIRECT ? 1 : bucket.weight();
piActionGroupBuilder.addMember(member, weight);
}
return piActionGroupBuilder.build();
}
use of org.onosproject.net.pi.runtime.PiGroupKey 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.pi.runtime.PiGroupKey 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.pi.runtime.PiGroupKey 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;
}
use of org.onosproject.net.pi.runtime.PiGroupKey in project onos by opennetworkinglab.
the class NextObjectiveTranslatorTest method testMplsHashedOutput.
/**
* Test program mpls ecmp output group for Hashed table.
*/
@Test
public void testMplsHashedOutput() throws Exception {
TrafficTreatment treatment1 = DefaultTrafficTreatment.builder().setEthSrc(ROUTER_MAC).setEthDst(SPINE1_MAC).pushMpls().copyTtlOut().setMpls(MPLS_10).popVlan().setOutput(PORT_1).build();
TrafficTreatment treatment2 = DefaultTrafficTreatment.builder().setEthSrc(ROUTER_MAC).setEthDst(SPINE2_MAC).pushMpls().copyTtlOut().setMpls(MPLS_10).popVlan().setOutput(PORT_2).build();
NextObjective nextObjective = DefaultNextObjective.builder().withId(NEXT_ID_1).withPriority(PRIORITY).withMeta(VLAN_META).addTreatment(treatment1).addTreatment(treatment2).withType(NextObjective.Type.HASHED).makePermanent().fromApp(APP_ID).add();
ObjectiveTranslation actualTranslation = translatorHashed.doTranslate(nextObjective);
// Expected hashed table flow rule.
PiCriterion nextIdCriterion = PiCriterion.builder().matchExact(FabricConstants.HDR_NEXT_ID, NEXT_ID_1).build();
TrafficSelector nextIdSelector = DefaultTrafficSelector.builder().matchPi(nextIdCriterion).build();
PiActionProfileGroupId actionGroupId = PiActionProfileGroupId.of(NEXT_ID_1);
TrafficTreatment treatment = DefaultTrafficTreatment.builder().piTableAction(actionGroupId).build();
FlowRule expectedFlowRule = DefaultFlowRule.builder().forDevice(DEVICE_ID).fromApp(APP_ID).makePermanent().withPriority(0).forTable(FabricConstants.FABRIC_INGRESS_NEXT_HASHED).withSelector(nextIdSelector).withTreatment(treatment).build();
// First egress rule - port1
PortNumber outPort = outputPort(treatment1);
PiCriterion egressVlanTableMatch = PiCriterion.builder().matchExact(FabricConstants.HDR_EG_PORT, outPort.toLong()).build();
TrafficSelector selectorForEgressVlan = DefaultTrafficSelector.builder().matchPi(egressVlanTableMatch).matchVlanId(VLAN_100).build();
PiAction piActionForEgressVlan = PiAction.builder().withId(FabricConstants.FABRIC_EGRESS_EGRESS_NEXT_POP_VLAN).build();
TrafficTreatment treatmentForEgressVlan = DefaultTrafficTreatment.builder().piTableAction(piActionForEgressVlan).build();
FlowRule expectedEgressVlanPopRule1 = DefaultFlowRule.builder().withSelector(selectorForEgressVlan).withTreatment(treatmentForEgressVlan).forTable(FabricConstants.FABRIC_EGRESS_EGRESS_NEXT_EGRESS_VLAN).makePermanent().withPriority(nextObjective.priority()).forDevice(DEVICE_ID).fromApp(APP_ID).build();
// Second egress rule - port2
outPort = outputPort(treatment2);
egressVlanTableMatch = PiCriterion.builder().matchExact(FabricConstants.HDR_EG_PORT, outPort.toLong()).build();
selectorForEgressVlan = DefaultTrafficSelector.builder().matchPi(egressVlanTableMatch).matchVlanId(VLAN_100).build();
FlowRule expectedEgressVlanPopRule2 = DefaultFlowRule.builder().withSelector(selectorForEgressVlan).withTreatment(treatmentForEgressVlan).forTable(FabricConstants.FABRIC_EGRESS_EGRESS_NEXT_EGRESS_VLAN).makePermanent().withPriority(nextObjective.priority()).forDevice(DEVICE_ID).fromApp(APP_ID).build();
// Expected group
PiAction piAction1 = PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_NEXT_ROUTING_HASHED).withParameter(new PiActionParam(FabricConstants.SMAC, ROUTER_MAC.toBytes())).withParameter(new PiActionParam(FabricConstants.DMAC, SPINE1_MAC.toBytes())).withParameter(new PiActionParam(FabricConstants.PORT_NUM, PORT_1.toLong())).build();
PiAction piAction2 = PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_NEXT_ROUTING_HASHED).withParameter(new PiActionParam(FabricConstants.SMAC, ROUTER_MAC.toBytes())).withParameter(new PiActionParam(FabricConstants.DMAC, SPINE2_MAC.toBytes())).withParameter(new PiActionParam(FabricConstants.PORT_NUM, PORT_2.toLong())).build();
treatment1 = DefaultTrafficTreatment.builder().piTableAction(piAction1).build();
treatment2 = DefaultTrafficTreatment.builder().piTableAction(piAction2).build();
List<TrafficTreatment> treatments = ImmutableList.of(treatment1, treatment2);
List<GroupBucket> buckets = treatments.stream().map(DefaultGroupBucket::createSelectGroupBucket).collect(Collectors.toList());
GroupBuckets groupBuckets = new GroupBuckets(buckets);
PiGroupKey groupKey = new PiGroupKey(FabricConstants.FABRIC_INGRESS_NEXT_HASHED, FabricConstants.FABRIC_INGRESS_NEXT_HASHED_SELECTOR, NEXT_ID_1);
GroupDescription expectedGroup = new DefaultGroupDescription(DEVICE_ID, GroupDescription.Type.SELECT, groupBuckets, groupKey, NEXT_ID_1, APP_ID);
ObjectiveTranslation expectedTranslation = ObjectiveTranslation.builder().addFlowRule(expectedFlowRule).addFlowRule(vlanMetaFlowRule).addFlowRule(mplsFlowRule).addGroup(expectedGroup).addFlowRule(expectedEgressVlanPopRule1).addFlowRule(expectedEgressVlanPopRule2).build();
assertEquals(expectedTranslation, actualTranslation);
}
Aggregations