use of org.onosproject.net.group.GroupDescription in project fabric-tna by stratum.
the class NextObjectiveTranslatorTest method testBroadcastOutput.
/**
* Test program output group for Broadcast table.
*/
@Test
public void testBroadcastOutput() throws FabricPipelinerException {
TrafficTreatment treatment1 = DefaultTrafficTreatment.builder().setOutput(PORT_1).build();
TrafficTreatment treatment2 = DefaultTrafficTreatment.builder().popVlan().setOutput(PORT_2).build();
NextObjective nextObjective = DefaultNextObjective.builder().withId(NEXT_ID_1).withPriority(PRIORITY).addTreatment(treatment1).addTreatment(treatment2).withMeta(VLAN_META).withType(NextObjective.Type.BROADCAST).makePermanent().fromApp(APP_ID).add();
ObjectiveTranslation actualTranslation = translatorHashed.doTranslate(nextObjective);
// Should generate 3 flows:
// - Multicast table flow that matches on next-id and set multicast group (1)
// - Egress VLAN pop handling for treatment2 (0)
// - Next VLAN flow (2)
// And 2 groups:
// - Multicast group
// Expected multicast table flow rule.
PiCriterion nextIdCriterion = PiCriterion.builder().matchExact(P4InfoConstants.HDR_NEXT_ID, NEXT_ID_1).build();
TrafficSelector nextIdSelector = DefaultTrafficSelector.builder().matchPi(nextIdCriterion).build();
PiAction setMcGroupAction = PiAction.builder().withId(P4InfoConstants.FABRIC_INGRESS_NEXT_SET_MCAST_GROUP_ID).withParameter(new PiActionParam(P4InfoConstants.GROUP_ID, NEXT_ID_1)).build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().piTableAction(setMcGroupAction).build();
FlowRule expectedHashedFlowRule = DefaultFlowRule.builder().forDevice(DEVICE_ID).fromApp(APP_ID).makePermanent().withPriority(nextObjective.priority()).forTable(P4InfoConstants.FABRIC_INGRESS_NEXT_MULTICAST).withSelector(nextIdSelector).withTreatment(treatment).build();
// Expected egress VLAN_PUSH flow rule.
PiCriterion egressVlanTableMatch = PiCriterion.builder().matchExact(P4InfoConstants.HDR_EG_PORT, PORT_1.toLong()).build();
TrafficSelector selectorForEgressVlan = DefaultTrafficSelector.builder().matchPi(egressVlanTableMatch).matchVlanId(VLAN_100).build();
PiAction piActionForEgressVlan = PiAction.builder().withId(P4InfoConstants.FABRIC_EGRESS_EGRESS_NEXT_PUSH_VLAN).build();
TrafficTreatment treatmentForEgressVlan = DefaultTrafficTreatment.builder().piTableAction(piActionForEgressVlan).build();
FlowRule expectedEgressVlanPushRule = DefaultFlowRule.builder().withSelector(selectorForEgressVlan).withTreatment(treatmentForEgressVlan).forTable(P4InfoConstants.FABRIC_EGRESS_EGRESS_NEXT_EGRESS_VLAN).makePermanent().withPriority(nextObjective.priority()).forDevice(DEVICE_ID).fromApp(APP_ID).build();
// Expected egress VLAN POP flow rule.
egressVlanTableMatch = PiCriterion.builder().matchExact(P4InfoConstants.HDR_EG_PORT, PORT_2.toLong()).build();
selectorForEgressVlan = DefaultTrafficSelector.builder().matchPi(egressVlanTableMatch).matchVlanId(VLAN_100).build();
piActionForEgressVlan = PiAction.builder().withId(P4InfoConstants.FABRIC_EGRESS_EGRESS_NEXT_POP_VLAN).build();
treatmentForEgressVlan = DefaultTrafficTreatment.builder().piTableAction(piActionForEgressVlan).build();
FlowRule expectedEgressVlanPopRule = DefaultFlowRule.builder().withSelector(selectorForEgressVlan).withTreatment(treatmentForEgressVlan).forTable(P4InfoConstants.FABRIC_EGRESS_EGRESS_NEXT_EGRESS_VLAN).makePermanent().withPriority(nextObjective.priority()).forDevice(DEVICE_ID).fromApp(APP_ID).build();
// Expected ALL group.
TrafficTreatment allGroupTreatment1 = DefaultTrafficTreatment.builder().setOutput(PORT_1).build();
TrafficTreatment allGroupTreatment2 = DefaultTrafficTreatment.builder().setOutput(PORT_2).build();
List<TrafficTreatment> allTreatments = ImmutableList.of(allGroupTreatment1, allGroupTreatment2);
List<GroupBucket> allBuckets = allTreatments.stream().map(DefaultGroupBucket::createAllGroupBucket).collect(Collectors.toList());
GroupBuckets allGroupBuckets = new GroupBuckets(allBuckets);
GroupKey allGroupKey = new DefaultGroupKey(FabricUtils.KRYO.serialize(NEXT_ID_1));
GroupDescription expectedAllGroup = new DefaultGroupDescription(DEVICE_ID, GroupDescription.Type.ALL, allGroupBuckets, allGroupKey, NEXT_ID_1, APP_ID);
ObjectiveTranslation expectedTranslation = ObjectiveTranslation.builder().addFlowRule(expectedHashedFlowRule).addFlowRule(vlanMetaFlowRule).addFlowRule(expectedEgressVlanPushRule).addFlowRule(expectedEgressVlanPopRule).addGroup(expectedAllGroup).build();
assertEquals(expectedTranslation, actualTranslation);
}
use of org.onosproject.net.group.GroupDescription in project fabric-tna by stratum.
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(P4InfoConstants.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(P4InfoConstants.FABRIC_INGRESS_NEXT_HASHED).withSelector(nextIdSelector).withTreatment(treatment).build();
// First egress rule - port1
PortNumber outPort = outputPort(treatment1);
PiCriterion egressVlanTableMatch = PiCriterion.builder().matchExact(P4InfoConstants.HDR_EG_PORT, outPort.toLong()).build();
TrafficSelector selectorForEgressVlan = DefaultTrafficSelector.builder().matchPi(egressVlanTableMatch).matchVlanId(VLAN_100).build();
PiAction piActionForEgressVlan = PiAction.builder().withId(P4InfoConstants.FABRIC_EGRESS_EGRESS_NEXT_POP_VLAN).build();
TrafficTreatment treatmentForEgressVlan = DefaultTrafficTreatment.builder().piTableAction(piActionForEgressVlan).build();
FlowRule expectedEgressVlanPopRule1 = DefaultFlowRule.builder().withSelector(selectorForEgressVlan).withTreatment(treatmentForEgressVlan).forTable(P4InfoConstants.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(P4InfoConstants.HDR_EG_PORT, outPort.toLong()).build();
selectorForEgressVlan = DefaultTrafficSelector.builder().matchPi(egressVlanTableMatch).matchVlanId(VLAN_100).build();
FlowRule expectedEgressVlanPopRule2 = DefaultFlowRule.builder().withSelector(selectorForEgressVlan).withTreatment(treatmentForEgressVlan).forTable(P4InfoConstants.FABRIC_EGRESS_EGRESS_NEXT_EGRESS_VLAN).makePermanent().withPriority(nextObjective.priority()).forDevice(DEVICE_ID).fromApp(APP_ID).build();
// Expected group
PiAction piAction1 = PiAction.builder().withId(P4InfoConstants.FABRIC_INGRESS_NEXT_ROUTING_HASHED).withParameter(new PiActionParam(P4InfoConstants.SMAC, ROUTER_MAC.toBytes())).withParameter(new PiActionParam(P4InfoConstants.DMAC, SPINE1_MAC.toBytes())).withParameter(new PiActionParam(P4InfoConstants.PORT_NUM, PORT_1.toLong())).build();
PiAction piAction2 = PiAction.builder().withId(P4InfoConstants.FABRIC_INGRESS_NEXT_ROUTING_HASHED).withParameter(new PiActionParam(P4InfoConstants.SMAC, ROUTER_MAC.toBytes())).withParameter(new PiActionParam(P4InfoConstants.DMAC, SPINE2_MAC.toBytes())).withParameter(new PiActionParam(P4InfoConstants.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(P4InfoConstants.FABRIC_INGRESS_NEXT_HASHED, P4InfoConstants.FABRIC_INGRESS_NEXT_HASHED_PROFILE, 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.GroupDescription in project fabric-tna by stratum.
the class FabricPipelinerTest method testInitializePipeline.
@Test
public void testInitializePipeline() {
final Capture<FlowRule> capturedSwitchInfoRule = newCapture(CaptureType.ALL);
final Capture<FlowRule> capturedCpuIgVlanRule = newCapture(CaptureType.ALL);
final Capture<FlowRule> capturedCpuFwdClsRule = newCapture(CaptureType.ALL);
final Capture<FlowRule> capturedIgPortVlanRule = newCapture(CaptureType.ALL);
final Capture<FlowRule> capturedEgVlanRule = newCapture(CaptureType.ALL);
final Capture<FlowRule> capturedFwdClsIpRules = newCapture(CaptureType.ALL);
final Capture<FlowRule> capturedFwdClsMplsRules = newCapture(CaptureType.ALL);
final Capture<GroupDescription> capturedCloneGroup = newCapture(CaptureType.FIRST);
final List<FlowRule> expectedIgPortVlanRules = Lists.newArrayList();
final List<FlowRule> expectedEgVlanRules = Lists.newArrayList();
final List<FlowRule> expectedFwdClsIpRules = Lists.newArrayList();
final List<FlowRule> expectedFwdClsMplsRules = Lists.newArrayList();
final FlowRule expectedSwitchInfoRule = switchInfoRule();
final FlowRule expectedCpuIgVlanRule = buildIngressVlanRule(CPU_PORT);
final FlowRule expectedCpuFwdClsRule = buildFwdClsRule(CPU_PORT, null, Ethernet.TYPE_IPV4, FWD_IPV4_ROUTING, DEFAULT_FLOW_PRIORITY);
final GroupDescription expectedPacketInCloneGroup = buildPacketInCloneGroup();
final List<Long> recircPorts = this.isArchV1model ? V1MODEL_RECIRC_PORT : RECIRC_PORTS;
flowRuleService.applyFlowRules(capture(capturedSwitchInfoRule), capture(capturedCpuIgVlanRule), capture(capturedCpuFwdClsRule));
groupService.addGroup(capture(capturedCloneGroup));
expectLastCall().once();
recircPorts.forEach(port -> {
expectedIgPortVlanRules.add(buildIngressVlanRule(port));
expectedEgVlanRules.add(buildEgressVlanRule(port));
expectedFwdClsIpRules.add(buildFwdClsRule(port, null, Ethernet.TYPE_IPV4, FWD_IPV4_ROUTING, DEFAULT_FLOW_PRIORITY));
expectedFwdClsMplsRules.add(buildFwdClsRule(port, Ethernet.MPLS_UNICAST, Ethernet.TYPE_IPV4, FWD_MPLS, DEFAULT_FLOW_PRIORITY + 10));
flowRuleService.applyFlowRules(capture(capturedIgPortVlanRule), capture(capturedEgVlanRule), capture(capturedFwdClsIpRules), capture(capturedFwdClsMplsRules));
});
replay(flowRuleService);
replay(groupService);
pipeliner.initializePipeline();
assertTrue(expectedSwitchInfoRule.exactMatch(capturedSwitchInfoRule.getValue()));
assertTrue(expectedCpuIgVlanRule.exactMatch(capturedCpuIgVlanRule.getValue()));
assertTrue(expectedCpuFwdClsRule.exactMatch(capturedCpuFwdClsRule.getValue()));
assertEquals(expectedPacketInCloneGroup, capturedCloneGroup.getValue());
for (int i = 0; i < recircPorts.size(); i++) {
FlowRule expectIgPortVlanRule = expectedIgPortVlanRules.get(i);
FlowRule actualIgPortVlanRule = capturedIgPortVlanRule.getValues().get(i);
FlowRule expectEgVlanRule = expectedEgVlanRules.get(i);
FlowRule actualEgVlanRule = capturedEgVlanRule.getValues().get(i);
FlowRule expectedFwdClsIpRule = expectedFwdClsIpRules.get(i);
FlowRule actualFwdClsIpRule = capturedFwdClsIpRules.getValues().get(i);
FlowRule expectedFwdClsMplsRule = expectedFwdClsMplsRules.get(i);
FlowRule actualFwdClsMplsRule = capturedFwdClsMplsRules.getValues().get(i);
assertTrue(expectIgPortVlanRule.exactMatch(actualIgPortVlanRule));
assertEquals(expectEgVlanRule, actualEgVlanRule);
assertTrue(expectEgVlanRule.exactMatch(actualEgVlanRule));
assertTrue(expectedFwdClsIpRule.exactMatch(actualFwdClsIpRule));
assertTrue(expectedFwdClsMplsRule.exactMatch(actualFwdClsMplsRule));
}
verify(flowRuleService);
reset(flowRuleService);
}
use of org.onosproject.net.group.GroupDescription in project fabric-tna by stratum.
the class FabricPipeliner method getBucketToFlowMapping.
private Map<GroupBucket, FlowRule> getBucketToFlowMapping(NextObjective nextObjective) {
Map<GroupBucket, FlowRule> mapping = Maps.newHashMap();
NextObjective newNextObjective;
ObjectiveTranslation result;
FlowRule dummyFlow = getDummyFlow(nextObjective);
FlowRule egFlow;
GroupBucket groupBucket;
GroupDescription group;
for (NextTreatment nextTreatment : nextObjective.nextTreatments()) {
newNextObjective = DefaultNextObjective.builder().withId(nextObjective.id()).withType(nextObjective.type()).fromApp(nextObjective.appId()).withMeta(nextObjective.meta()).addTreatment(nextTreatment).verify();
result = nextTranslator.translate(newNextObjective);
if ((result.groups().isEmpty() && result.flowRules().isEmpty()) || result.groups().size() > 1) {
return Collections.emptyMap();
}
group = result.groups().iterator().next();
egFlow = result.flowRules().stream().filter(flowRule -> flowRule.table().equals(P4InfoConstants.FABRIC_EGRESS_EGRESS_NEXT_EGRESS_VLAN)).findFirst().orElse(null);
if (group.buckets().buckets().isEmpty() || group.buckets().buckets().size() > 1) {
return Collections.emptyMap();
}
groupBucket = group.buckets().buckets().iterator().next();
if (egFlow == null) {
mapping.put(groupBucket, dummyFlow);
} else {
mapping.put(groupBucket, egFlow);
}
}
return mapping;
}
use of org.onosproject.net.group.GroupDescription in project onos by opennetworkinglab.
the class DistributedGroupStore method deviceInitialAuditCompleted.
@Override
public void deviceInitialAuditCompleted(DeviceId deviceId, boolean completed) {
synchronized (deviceAuditStatus) {
if (completed) {
log.debug("AUDIT completed for device {}", deviceId);
deviceAuditStatus.put(deviceId, true);
// Execute all pending group requests
List<StoredGroupEntry> pendingGroupRequests = getPendingGroupKeyTable().values().stream().filter(g -> g.deviceId().equals(deviceId)).collect(Collectors.toList());
if (log.isDebugEnabled()) {
List<String> pendingIds = pendingGroupRequests.stream().map(GroupDescription::givenGroupId).map(id -> id != null ? "0x" + Integer.toHexString(id) : "N/A").collect(Collectors.toList());
log.debug("processing pending group add requests for device {}: {}", deviceId, pendingIds);
}
NodeId master;
for (Group group : pendingGroupRequests) {
// Mastership change can occur during this iteration
if (!shouldHandle(deviceId)) {
log.warn("Tried to process pending groups while the node was not the master" + " or the device {} was not available", deviceId);
return;
}
GroupDescription tmp = new DefaultGroupDescription(group.deviceId(), group.type(), group.buckets(), group.appCookie(), group.givenGroupId(), group.appId());
storeGroupDescriptionInternal(tmp);
getPendingGroupKeyTable().remove(new GroupStoreKeyMapKey(deviceId, group.appCookie()));
}
} else {
Boolean audited = deviceAuditStatus.get(deviceId);
if (audited != null && audited) {
log.debug("Clearing AUDIT status for device {}", deviceId);
deviceAuditStatus.put(deviceId, false);
}
}
}
}
Aggregations