use of org.onosproject.net.group.DefaultGroupBucket in project onos by opennetworkinglab.
the class SpringOpenTTP method addGroup.
private void addGroup(NextObjective nextObjective) {
log.debug("addGroup with type{} for nextObjective id {}", nextObjective.type(), nextObjective.id());
List<GroupBucket> buckets;
switch(nextObjective.type()) {
case SIMPLE:
Collection<TrafficTreatment> treatments = nextObjective.next();
if (treatments.size() == 1) {
// Spring Open TTP converts simple nextObjective to flow-actions
// in a dummy group
TrafficTreatment treatment = nextObjective.next().iterator().next();
log.debug("Converting SIMPLE group for next objective id {} " + "to {} flow-actions in device:{}", nextObjective.id(), treatment.allInstructions().size(), deviceId);
flowObjectiveStore.putNextGroup(nextObjective.id(), new SpringOpenGroup(null, treatment));
}
break;
case HASHED:
// we convert MPLS ECMP groups to flow-actions for a single
// bucket(output port).
boolean mplsEcmp = false;
if (nextObjective.meta() != null) {
for (Criterion c : nextObjective.meta().criteria()) {
if (c.type() == Type.MPLS_LABEL) {
mplsEcmp = true;
}
}
}
if (mplsEcmp) {
// covert to flow-actions in a dummy group by choosing the first bucket
log.debug("Converting HASHED group for next objective id {} " + "to flow-actions in device:{}", nextObjective.id(), deviceId);
TrafficTreatment treatment = nextObjective.next().iterator().next();
flowObjectiveStore.putNextGroup(nextObjective.id(), new SpringOpenGroup(null, treatment));
} else {
// process as ECMP group
buckets = nextObjective.next().stream().map(DefaultGroupBucket::createSelectGroupBucket).collect(Collectors.toList());
if (!buckets.isEmpty()) {
final GroupKey key = new DefaultGroupKey(appKryo.serialize(nextObjective.id()));
GroupDescription groupDescription = new DefaultGroupDescription(deviceId, GroupDescription.Type.SELECT, new GroupBuckets(buckets), key, null, nextObjective.appId());
log.debug("Creating HASHED group for next objective id {}" + " in dev:{}", nextObjective.id(), deviceId);
pendingGroups.put(key, nextObjective);
groupService.addGroup(groupDescription);
verifyPendingGroupLater();
}
}
break;
case BROADCAST:
buckets = nextObjective.next().stream().map(DefaultGroupBucket::createAllGroupBucket).collect(Collectors.toList());
if (!buckets.isEmpty()) {
final GroupKey key = new DefaultGroupKey(appKryo.serialize(nextObjective.id()));
GroupDescription groupDescription = new DefaultGroupDescription(deviceId, GroupDescription.Type.ALL, new GroupBuckets(buckets), key, null, nextObjective.appId());
log.debug("Creating BROADCAST group for next objective id {} " + "in device {}", nextObjective.id(), deviceId);
pendingGroups.put(key, nextObjective);
groupService.addGroup(groupDescription);
verifyPendingGroupLater();
}
break;
case FAILOVER:
log.debug("FAILOVER next objectives not supported");
fail(nextObjective, ObjectiveError.UNSUPPORTED);
log.warn("Unsupported next objective type {}", nextObjective.type());
break;
default:
fail(nextObjective, ObjectiveError.UNKNOWN);
log.warn("Unknown next objective type {}", nextObjective.type());
}
}
use of org.onosproject.net.group.DefaultGroupBucket 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.DefaultGroupBucket 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.DefaultGroupBucket 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);
}
use of org.onosproject.net.group.DefaultGroupBucket in project onos by opennetworkinglab.
the class NextObjectiveTranslatorTest method testHashedOutput.
/**
* Test program ecmp output group for Hashed table.
*/
@Test
public void testHashedOutput() throws Exception {
PiAction piAction1 = PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_NEXT_ROUTING_HASHED).withParameter(new PiActionParam(FabricConstants.SMAC, ROUTER_MAC.toBytes())).withParameter(new PiActionParam(FabricConstants.DMAC, HOST_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, HOST_MAC.toBytes())).withParameter(new PiActionParam(FabricConstants.PORT_NUM, PORT_1.toLong())).build();
TrafficTreatment treatment1 = DefaultTrafficTreatment.builder().piTableAction(piAction1).build();
TrafficTreatment treatment2 = DefaultTrafficTreatment.builder().piTableAction(piAction2).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();
// Expected group
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).addGroup(expectedGroup).build();
assertEquals(expectedTranslation, actualTranslation);
}
Aggregations