use of org.onosproject.net.pi.runtime.PiActionParam in project fabric-tna by stratum.
the class FabricIntProgrammable method buildFilterConfigRule.
private FlowRule buildFilterConfigRule(int minFlowHopLatencyChangeNs) {
final long qmask = getSuitableQmaskForLatencyChange(minFlowHopLatencyChangeNs);
final PiActionParam hopLatencyMask = new PiActionParam(P4InfoConstants.HOP_LATENCY_MASK, qmask);
final PiActionParam timestampMask = new PiActionParam(P4InfoConstants.TIMESTAMP_MASK, DEFAULT_TIMESTAMP_MASK);
final PiAction action = PiAction.builder().withId(P4InfoConstants.FABRIC_EGRESS_INT_EGRESS_SET_CONFIG).withParameter(hopLatencyMask).withParameter(timestampMask).build();
final TrafficTreatment treatment = DefaultTrafficTreatment.builder().piTableAction(action).build();
return DefaultFlowRule.builder().forDevice(deviceId).makePermanent().withPriority(DEFAULT_PRIORITY).withTreatment(treatment).fromApp(appId).forTable(P4InfoConstants.FABRIC_EGRESS_INT_EGRESS_CONFIG).build();
}
use of org.onosproject.net.pi.runtime.PiActionParam in project fabric-tna by stratum.
the class FabricIntProgrammable method buildReportEntryWithType.
private FlowRule buildReportEntryWithType(SegmentRoutingDeviceConfig srCfg, IntReportConfig intCfg, short bridgedMdType, short reportType, short mirrorType) {
final Ip4Address srcIp = srCfg.routerIpv4();
final int switchId = srCfg.nodeSidIPv4();
if (srcIp == null) {
log.warn("Invalid switch IP, skip configuring the report table");
return null;
}
final PiActionParam srcIpParam = new PiActionParam(P4InfoConstants.SRC_IP, srcIp.toOctets());
final PiActionParam monIpParam = new PiActionParam(P4InfoConstants.MON_IP, intCfg.collectorIp().toOctets());
final PiActionParam monPortParam = new PiActionParam(P4InfoConstants.MON_PORT, intCfg.collectorPort().toInt());
final PiActionParam switchIdParam = new PiActionParam(P4InfoConstants.SWITCH_ID, switchId);
PiAction.Builder reportActionBuilder = PiAction.builder();
if (!srCfg.isEdgeRouter()) {
// If the device is a spine device, we need to find which
// switch is the INT collector attached to and find the SID of that device.
// TODO: replace this with SR API.
Optional<Integer> sid = getSidForCollector(intCfg.collectorIp());
if (sid.isEmpty()) {
// Error log will be shown in getSidForCollector method.
return null;
}
if ((reportType & (INT_REPORT_TYPE_FLOW | INT_REPORT_TYPE_QUEUE)) != 0) {
reportActionBuilder.withId(P4InfoConstants.FABRIC_EGRESS_INT_EGRESS_DO_LOCAL_REPORT_ENCAP_MPLS);
} else if (reportType == INT_REPORT_TYPE_DROP) {
reportActionBuilder.withId(P4InfoConstants.FABRIC_EGRESS_INT_EGRESS_DO_DROP_REPORT_ENCAP_MPLS);
} else {
// Invalid report type
log.warn("Invalid report type {}", reportType);
return null;
}
final PiActionParam monLabelParam = new PiActionParam(P4InfoConstants.MON_LABEL, sid.get());
reportActionBuilder.withParameter(monLabelParam);
} else {
if ((reportType & (INT_REPORT_TYPE_FLOW | INT_REPORT_TYPE_QUEUE)) != 0) {
reportActionBuilder.withId(P4InfoConstants.FABRIC_EGRESS_INT_EGRESS_DO_LOCAL_REPORT_ENCAP);
} else if (reportType == INT_REPORT_TYPE_DROP) {
reportActionBuilder.withId(P4InfoConstants.FABRIC_EGRESS_INT_EGRESS_DO_DROP_REPORT_ENCAP);
} else {
// Invalid report type
log.warn("Invalid report type {}", reportType);
return null;
}
}
reportActionBuilder.withParameter(srcIpParam).withParameter(monIpParam).withParameter(monPortParam).withParameter(switchIdParam);
final TrafficTreatment treatment = DefaultTrafficTreatment.builder().piTableAction(reportActionBuilder.build()).build();
final TrafficSelector selector = DefaultTrafficSelector.builder().matchPi(PiCriterion.builder().matchExact(P4InfoConstants.HDR_BMD_TYPE, bridgedMdType).matchExact(P4InfoConstants.HDR_MIRROR_TYPE, mirrorType).matchExact(P4InfoConstants.HDR_INT_REPORT_TYPE, reportType).build()).build();
return DefaultFlowRule.builder().withSelector(selector).withTreatment(treatment).fromApp(appId).withPriority(DEFAULT_PRIORITY).makePermanent().forDevice(this.data().deviceId()).forTable(P4InfoConstants.FABRIC_EGRESS_INT_EGRESS_REPORT).build();
}
use of org.onosproject.net.pi.runtime.PiActionParam in project onos by opennetworkinglab.
the class FabricPipelinerTest method testInitializePipeline.
@Test
public void testInitializePipeline() {
final Capture<FlowRule> capturedCpuIgVlanRule = newCapture(CaptureType.ALL);
final Capture<FlowRule> capturedCpuFwdClsRule = newCapture(CaptureType.ALL);
// ingress_port_vlan table for cpu port
final TrafficSelector cpuIgVlanSelector = DefaultTrafficSelector.builder().add(Criteria.matchInPort(PortNumber.portNumber(CPU_PORT))).add(PiCriterion.builder().matchExact(FabricConstants.HDR_VLAN_IS_VALID, ZERO).build()).build();
final TrafficTreatment cpuIgVlanTreatment = DefaultTrafficTreatment.builder().piTableAction(PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_FILTERING_PERMIT_WITH_INTERNAL_VLAN).withParameter(new PiActionParam(FabricConstants.VLAN_ID, DEFAULT_VLAN)).withParameter(new PiActionParam(FabricConstants.PORT_TYPE, PORT_TYPE_INTERNAL)).build()).build();
final FlowRule expectedCpuIgVlanRule = DefaultFlowRule.builder().withSelector(cpuIgVlanSelector).withTreatment(cpuIgVlanTreatment).forTable(FabricConstants.FABRIC_INGRESS_FILTERING_INGRESS_PORT_VLAN).makePermanent().withPriority(DEFAULT_FLOW_PRIORITY).forDevice(DEVICE_ID).fromApp(APP_ID).build();
final TrafficSelector cpuFwdClsSelector = DefaultTrafficSelector.builder().matchInPort(PortNumber.portNumber(CPU_PORT)).matchPi(PiCriterion.builder().matchExact(FabricConstants.HDR_IP_ETH_TYPE, Ethernet.TYPE_IPV4).build()).build();
final TrafficTreatment cpuFwdClsTreatment = DefaultTrafficTreatment.builder().piTableAction(PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_FILTERING_SET_FORWARDING_TYPE).withParameter(new PiActionParam(FabricConstants.FWD_TYPE, FWD_IPV4_ROUTING)).build()).build();
final FlowRule expectedCpuFwdClsRule = DefaultFlowRule.builder().withSelector(cpuFwdClsSelector).withTreatment(cpuFwdClsTreatment).forTable(FabricConstants.FABRIC_INGRESS_FILTERING_FWD_CLASSIFIER).makePermanent().withPriority(DEFAULT_FLOW_PRIORITY).forDevice(DEVICE_ID).fromApp(APP_ID).build();
flowRuleService.applyFlowRules(capture(capturedCpuIgVlanRule), capture(capturedCpuFwdClsRule));
replay(flowRuleService);
pipeliner.initializePipeline();
assertTrue(expectedCpuIgVlanRule.exactMatch(capturedCpuIgVlanRule.getValue()));
assertTrue(expectedCpuFwdClsRule.exactMatch(capturedCpuFwdClsRule.getValue()));
verify(flowRuleService);
reset(flowRuleService);
}
use of org.onosproject.net.pi.runtime.PiActionParam in project onos by opennetworkinglab.
the class FilteringObjectiveTranslatorTest method buildExpectedVlanInPortRule.
private FlowRule buildExpectedVlanInPortRule(PortNumber inPort, VlanId vlanId, VlanId innerVlanId, VlanId internalVlan, byte portType, TableId tableId) {
TrafficSelector.Builder selector = DefaultTrafficSelector.builder().matchInPort(inPort);
PiAction piAction;
selector.matchPi(buildPiCriterionVlan(vlanId, innerVlanId));
if (!vlanValid(vlanId)) {
piAction = PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_FILTERING_PERMIT_WITH_INTERNAL_VLAN).withParameter(new PiActionParam(FabricConstants.VLAN_ID, internalVlan.toShort())).withParameter(new PiActionParam(FabricConstants.PORT_TYPE, portType)).build();
} else {
selector.matchVlanId(vlanId);
if (vlanValid(innerVlanId)) {
selector.matchInnerVlanId(innerVlanId);
}
piAction = PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_FILTERING_PERMIT).withParameter(new PiActionParam(FabricConstants.PORT_TYPE, portType)).build();
}
return DefaultFlowRule.builder().withPriority(PRIORITY).withSelector(selector.build()).withTreatment(DefaultTrafficTreatment.builder().piTableAction(piAction).build()).fromApp(APP_ID).forDevice(DEVICE_ID).makePermanent().forTable(tableId).build();
}
use of org.onosproject.net.pi.runtime.PiActionParam in project onos by opennetworkinglab.
the class ForwardingObjectiveTranslatorTest method testAclArp.
/**
* Test versatile flag of forwarding objective with ARP match.
*/
@Test
public void testAclArp() {
TrafficTreatment treatment = DefaultTrafficTreatment.builder().punt().build();
// ARP
TrafficSelector selector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_ARP).build();
ForwardingObjective fwd = DefaultForwardingObjective.builder().withSelector(selector).withPriority(PRIORITY).fromApp(APP_ID).makePermanent().withFlag(ForwardingObjective.Flag.VERSATILE).withTreatment(treatment).add();
ObjectiveTranslation result = translator.translate(fwd);
List<FlowRule> flowRulesInstalled = (List<FlowRule>) result.flowRules();
List<GroupDescription> groupsInstalled = (List<GroupDescription>) result.groups();
assertEquals(1, flowRulesInstalled.size());
assertEquals(1, groupsInstalled.size());
FlowRule actualFlowRule = flowRulesInstalled.get(0);
PiAction piAction = PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_ACL_SET_CLONE_SESSION_ID).withParameter(new PiActionParam(FabricConstants.CLONE_ID, ForwardingObjectiveTranslator.CLONE_TO_CPU_ID)).build();
FlowRule expectedFlowRule = DefaultFlowRule.builder().forDevice(DEVICE_ID).forTable(FabricConstants.FABRIC_INGRESS_ACL_ACL).withPriority(PRIORITY).makePermanent().withSelector(selector).withTreatment(DefaultTrafficTreatment.builder().piTableAction(piAction).build()).fromApp(APP_ID).build();
GroupDescription actualCloneGroup = groupsInstalled.get(0);
TrafficTreatment cloneGroupTreatment = DefaultTrafficTreatment.builder().setOutput(PortNumber.CONTROLLER).build();
List<GroupBucket> cloneBuckets = ImmutableList.of(DefaultGroupBucket.createCloneGroupBucket(cloneGroupTreatment));
GroupBuckets cloneGroupBuckets = new GroupBuckets(cloneBuckets);
GroupKey cloneGroupKey = new DefaultGroupKey(FabricPipeliner.KRYO.serialize(ForwardingObjectiveTranslator.CLONE_TO_CPU_ID));
GroupDescription expectedCloneGroup = new DefaultGroupDescription(DEVICE_ID, GroupDescription.Type.CLONE, cloneGroupBuckets, cloneGroupKey, ForwardingObjectiveTranslator.CLONE_TO_CPU_ID, APP_ID);
assertTrue(expectedFlowRule.exactMatch(actualFlowRule));
assertTrue(expectedCloneGroup.equals(actualCloneGroup));
}
Aggregations