Search in sources :

Example 46 with PiActionParam

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();
}
Also used : PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PiAction(org.onosproject.net.pi.runtime.PiAction)

Example 47 with PiActionParam

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();
}
Also used : Ip4Address(org.onlab.packet.Ip4Address) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PiAction(org.onosproject.net.pi.runtime.PiAction)

Example 48 with PiActionParam

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);
}
Also used : TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) Test(org.junit.Test)

Example 49 with PiActionParam

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();
}
Also used : TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) PiAction(org.onosproject.net.pi.runtime.PiAction)

Example 50 with PiActionParam

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));
}
Also used : GroupKey(org.onosproject.net.group.GroupKey) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) GroupBuckets(org.onosproject.net.group.GroupBuckets) PiAction(org.onosproject.net.pi.runtime.PiAction) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) Test(org.junit.Test)

Aggregations

PiActionParam (org.onosproject.net.pi.runtime.PiActionParam)102 PiAction (org.onosproject.net.pi.runtime.PiAction)90 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)50 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)50 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)39 TrafficSelector (org.onosproject.net.flow.TrafficSelector)39 PiCriterion (org.onosproject.net.flow.criteria.PiCriterion)39 Test (org.junit.Test)30 FlowRule (org.onosproject.net.flow.FlowRule)27 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)21 GroupDescription (org.onosproject.net.group.GroupDescription)11 DefaultGroupDescription (org.onosproject.net.group.DefaultGroupDescription)10 DefaultNextObjective (org.onosproject.net.flowobjective.DefaultNextObjective)8 NextObjective (org.onosproject.net.flowobjective.NextObjective)8 PortNumber (org.onosproject.net.PortNumber)7 DefaultGroupBucket (org.onosproject.net.group.DefaultGroupBucket)7 GroupBucket (org.onosproject.net.group.GroupBucket)7 GroupBuckets (org.onosproject.net.group.GroupBuckets)7 PiActionProfileGroupId (org.onosproject.net.pi.runtime.PiActionProfileGroupId)7 PiGroupKey (org.onosproject.net.pi.runtime.PiGroupKey)6