Search in sources :

Example 11 with PiActionId

use of org.onosproject.net.pi.model.PiActionId in project onos by opennetworkinglab.

the class InstructionCodecTest method piInstructionEncodingTest.

/**
 * Tests the encoding of protocol-independent instructions.
 */
@Test
public void piInstructionEncodingTest() {
    PiActionId actionId = PiActionId.of("set_egress_port");
    PiActionParamId actionParamId = PiActionParamId.of("port");
    PiActionParam actionParam = new PiActionParam(actionParamId, ImmutableByteSequence.copyFrom(10));
    PiTableAction action = PiAction.builder().withId(actionId).withParameter(actionParam).build();
    final PiInstruction actionInstruction = Instructions.piTableAction(action);
    final ObjectNode actionInstructionJson = instructionCodec.encode(actionInstruction, context);
    assertThat(actionInstructionJson, matchesInstruction(actionInstruction));
    PiTableAction actionGroupId = PiActionProfileGroupId.of(10);
    final PiInstruction actionGroupIdInstruction = Instructions.piTableAction(actionGroupId);
    final ObjectNode actionGroupIdInstructionJson = instructionCodec.encode(actionGroupIdInstruction, context);
    assertThat(actionGroupIdInstructionJson, matchesInstruction(actionGroupIdInstruction));
    PiTableAction actionProfileMemberId = PiActionProfileMemberId.of(10);
    final PiInstruction actionProfileMemberIdInstruction = Instructions.piTableAction(actionProfileMemberId);
    final ObjectNode actionProfileMemberIdInstructionJson = instructionCodec.encode(actionProfileMemberIdInstruction, context);
    assertThat(actionProfileMemberIdInstructionJson, matchesInstruction(actionProfileMemberIdInstruction));
}
Also used : PiActionId(org.onosproject.net.pi.model.PiActionId) PiActionParamId(org.onosproject.net.pi.model.PiActionParamId) PiTableAction(org.onosproject.net.pi.runtime.PiTableAction) PiInstruction(org.onosproject.net.flow.instructions.PiInstruction) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) Test(org.junit.Test)

Example 12 with PiActionId

use of org.onosproject.net.pi.model.PiActionId in project onos by opennetworkinglab.

the class MyTunnelApp method insertTunnelIngressRule.

/**
 * Generates and insert a flow rule to perform the tunnel INGRESS function
 * for the given switch, destination IP address and tunnel ID.
 *
 * @param switchId  switch ID
 * @param dstIpAddr IP address to forward inside the tunnel
 * @param tunId     tunnel ID
 */
private void insertTunnelIngressRule(DeviceId switchId, IpAddress dstIpAddr, int tunId) {
    PiTableId tunnelIngressTableId = PiTableId.of("c_ingress.t_tunnel_ingress");
    // Longest prefix match on IPv4 dest address.
    PiMatchFieldId ipDestMatchFieldId = PiMatchFieldId.of("hdr.ipv4.dst_addr");
    PiCriterion match = PiCriterion.builder().matchLpm(ipDestMatchFieldId, dstIpAddr.toOctets(), 32).build();
    PiActionParam tunIdParam = new PiActionParam(PiActionParamId.of("tun_id"), tunId);
    PiActionId ingressActionId = PiActionId.of("c_ingress.my_tunnel_ingress");
    PiAction action = PiAction.builder().withId(ingressActionId).withParameter(tunIdParam).build();
    log.info("Inserting INGRESS rule on switch {}: table={}, match={}, action={}", switchId, tunnelIngressTableId, match, action);
    insertPiFlowRule(switchId, tunnelIngressTableId, match, action);
}
Also used : PiActionId(org.onosproject.net.pi.model.PiActionId) PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) PiTableId(org.onosproject.net.pi.model.PiTableId) PiMatchFieldId(org.onosproject.net.pi.model.PiMatchFieldId) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) PiAction(org.onosproject.net.pi.runtime.PiAction)

Example 13 with PiActionId

use of org.onosproject.net.pi.model.PiActionId in project onos by opennetworkinglab.

the class MyTunnelApp method insertTunnelForwardRule.

/**
 * Generates and insert a flow rule to perform the tunnel FORWARD/EGRESS
 * function for the given switch, output port address and tunnel ID.
 *
 * @param switchId switch ID
 * @param outPort  output port where to forward tunneled packets
 * @param tunId    tunnel ID
 * @param isEgress if true, perform tunnel egress action, otherwise forward
 *                 packet as is to port
 */
private void insertTunnelForwardRule(DeviceId switchId, PortNumber outPort, int tunId, boolean isEgress) {
    PiTableId tunnelForwardTableId = PiTableId.of("c_ingress.t_tunnel_fwd");
    // Exact match on tun_id
    PiMatchFieldId tunIdMatchFieldId = PiMatchFieldId.of("hdr.my_tunnel.tun_id");
    PiCriterion match = PiCriterion.builder().matchExact(tunIdMatchFieldId, tunId).build();
    // Action depend on isEgress parameter.
    // if true, perform tunnel egress action on the given outPort, otherwise
    // simply forward packet as is (set_out_port action).
    PiActionParamId portParamId = PiActionParamId.of("port");
    PiActionParam portParam = new PiActionParam(portParamId, (short) outPort.toLong());
    final PiAction action;
    if (isEgress) {
        // Tunnel egress action.
        // Remove MyTunnel header and forward to outPort.
        PiActionId egressActionId = PiActionId.of("c_ingress.my_tunnel_egress");
        action = PiAction.builder().withId(egressActionId).withParameter(portParam).build();
    } else {
        // Tunnel transit action.
        // Forward the packet as is to outPort.
        /*
             * TODO EXERCISE: create action object for the transit case.
             * Look at the t_tunnel_fwd table in the P4 program. Which of the 3
             * actions can be used to simply set the output port? Get the full
             * action name from the P4Info file, and use that when creating the
             * PiActionId object. When creating the PiAction object, remember to
             * add all action parameters as defined in the P4 program.
             *
             * Hint: the code will be similar to the case when isEgress is true.
             */
        // Replace null with your solution.
        action = null;
    }
    log.info("Inserting {} rule on switch {}: table={}, match={}, action={}", isEgress ? "EGRESS" : "TRANSIT", switchId, tunnelForwardTableId, match, action);
    insertPiFlowRule(switchId, tunnelForwardTableId, match, action);
}
Also used : PiActionParamId(org.onosproject.net.pi.model.PiActionParamId) PiActionId(org.onosproject.net.pi.model.PiActionId) PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) PiTableId(org.onosproject.net.pi.model.PiTableId) PiMatchFieldId(org.onosproject.net.pi.model.PiMatchFieldId) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) PiAction(org.onosproject.net.pi.runtime.PiAction)

Example 14 with PiActionId

use of org.onosproject.net.pi.model.PiActionId in project fabric-tna by stratum.

the class FabricIntProgrammable method setUpIntWatchlistRules.

private void setUpIntWatchlistRules(List<IpPrefix> watchSubnets) {
    FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
    final PiActionId reportActionId = P4InfoConstants.FABRIC_INGRESS_INT_WATCHLIST_MARK_TO_REPORT;
    Streams.stream(flowRuleService.getFlowEntriesById(appId)).filter(entry -> entry.deviceId().equals(deviceId)).filter(entry -> entryWithActionId(entry, reportActionId)).forEach(ops::remove);
    ops.newStage();
    for (IpPrefix subnet : watchSubnets) {
        if (subnet.prefixLength() == 0) {
            ops.add(buildWatchlistEntry(buildCollectorSelector(Collections.emptySet())));
            continue;
        }
        ops.add(buildWatchlistEntry(buildCollectorSelector(ImmutableSet.of(Criteria.matchIPSrc(subnet)))));
        ops.add(buildWatchlistEntry(buildCollectorSelector(ImmutableSet.of(Criteria.matchIPDst(subnet)))));
    }
    flowRuleService.apply(ops.build());
}
Also used : PiTableId(org.onosproject.net.pi.model.PiTableId) NetworkConfigService(org.onosproject.net.config.NetworkConfigService) HostLocation(org.onosproject.net.HostLocation) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) CoreService(org.onosproject.core.CoreService) PortNumber(org.onosproject.net.PortNumber) FlowEntry(org.onosproject.net.flow.FlowEntry) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) IPProtocolCriterion(org.onosproject.net.flow.criteria.IPProtocolCriterion) IntReportConfig(org.stratumproject.fabric.tna.inbandtelemetry.IntReportConfig) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) FlowRuleService(org.onosproject.net.flow.FlowRuleService) PiInstruction(org.onosproject.net.flow.instructions.PiInstruction) PiTableModel(org.onosproject.net.pi.model.PiTableModel) PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) V1MODEL_RECIRC_PORT(org.stratumproject.fabric.tna.Constants.V1MODEL_RECIRC_PORT) ImmutableSet(com.google.common.collect.ImmutableSet) Ip4Address(org.onlab.packet.Ip4Address) ImmutableMap(com.google.common.collect.ImmutableMap) FabricUtils.doCareRangeMatch(org.stratumproject.fabric.tna.behaviour.FabricUtils.doCareRangeMatch) PiMatchFieldModel(org.onosproject.net.pi.model.PiMatchFieldModel) Range(com.google.common.collect.Range) Set(java.util.Set) Streams(com.google.common.collect.Streams) Constants(org.stratumproject.fabric.tna.Constants) Sets(com.google.common.collect.Sets) String.format(java.lang.String.format) Objects(java.util.Objects) List(java.util.List) BoundType(com.google.common.collect.BoundType) FlowRule(org.onosproject.net.flow.FlowRule) GroupBuckets(org.onosproject.net.group.GroupBuckets) Optional(java.util.Optional) DeviceId(org.onosproject.net.DeviceId) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) IpPrefix(org.onlab.packet.IpPrefix) Host(org.onosproject.net.Host) ImmutableByteSequence(org.onlab.util.ImmutableByteSequence) TableId(org.onosproject.net.flow.TableId) SegmentRoutingDeviceConfig(org.onosproject.segmentrouting.config.SegmentRoutingDeviceConfig) GroupBucket(org.onosproject.net.group.GroupBucket) HostService(org.onosproject.net.host.HostService) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultGroupBucket.createCloneGroupBucket(org.onosproject.net.group.DefaultGroupBucket.createCloneGroupBucket) ImmutableList(com.google.common.collect.ImmutableList) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) TcpPortCriterion(org.onosproject.net.flow.criteria.TcpPortCriterion) StreamSupport(java.util.stream.StreamSupport) Criteria(org.onosproject.net.flow.criteria.Criteria) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Criterion(org.onosproject.net.flow.criteria.Criterion) IpAddress(org.onlab.packet.IpAddress) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) UdpPortCriterion(org.onosproject.net.flow.criteria.UdpPortCriterion) GroupService(org.onosproject.net.group.GroupService) V1MODEL_INT_REPORT_MIRROR_ID(org.stratumproject.fabric.tna.Constants.V1MODEL_INT_REPORT_MIRROR_ID) PiMatchFieldId(org.onosproject.net.pi.model.PiMatchFieldId) PiAction(org.onosproject.net.pi.runtime.PiAction) IPv4(org.onlab.packet.IPv4) HexString(org.onlab.util.HexString) KRYO(org.stratumproject.fabric.tna.behaviour.FabricUtils.KRYO) IntProgrammable(org.stratumproject.fabric.tna.inbandtelemetry.IntProgrammable) Collections(java.util.Collections) PiActionId(org.onosproject.net.pi.model.PiActionId) IpPrefix(org.onlab.packet.IpPrefix) PiActionId(org.onosproject.net.pi.model.PiActionId) FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations)

Example 15 with PiActionId

use of org.onosproject.net.pi.model.PiActionId in project fabric-tna by stratum.

the class FabricUpfTranslator method interfaceToFabricEntry.

/**
 * Translate a UpfInterface to a FlowRule to be inserted into the fabric.p4 pipeline.
 *
 * @param upfInterface The interface to be translated
 * @param deviceId     the ID of the device the FlowRule should be installed on
 * @param appId        the ID of the application that will insert the FlowRule
 * @param priority     the FlowRule's priority
 * @return the UPF interface translated to a FlowRule
 * @throws UpfProgrammableException if the interface cannot be translated
 */
public FlowRule interfaceToFabricEntry(UpfInterface upfInterface, DeviceId deviceId, ApplicationId appId, int priority) throws UpfProgrammableException {
    int gtpuValidity;
    PiActionId actionId;
    if (upfInterface.isDbufReceiver()) {
        actionId = FABRIC_INGRESS_UPF_IFACE_DBUF;
        gtpuValidity = 1;
    } else if (upfInterface.isAccess()) {
        actionId = FABRIC_INGRESS_UPF_IFACE_ACCESS;
        gtpuValidity = 1;
    } else if (upfInterface.isCore()) {
        actionId = FABRIC_INGRESS_UPF_IFACE_CORE;
        gtpuValidity = 0;
    } else {
        throw new UpfProgrammableException("Unknown interface type");
    }
    PiCriterion match = PiCriterion.builder().matchLpm(HDR_IPV4_DST_ADDR, upfInterface.prefix().address().toInt(), upfInterface.prefix().prefixLength()).matchExact(HDR_GTPU_IS_VALID, gtpuValidity).build();
    PiAction action = PiAction.builder().withId(actionId).withParameter(new PiActionParam(SLICE_ID, SliceId.of(upfInterface.sliceId()).id())).build();
    return DefaultFlowRule.builder().forDevice(deviceId).fromApp(appId).makePermanent().forTable(FABRIC_INGRESS_UPF_INTERFACES).withSelector(DefaultTrafficSelector.builder().matchPi(match).build()).withTreatment(DefaultTrafficTreatment.builder().piTableAction(action).build()).withPriority(priority).build();
}
Also used : PiActionId(org.onosproject.net.pi.model.PiActionId) UpfProgrammableException(org.onosproject.net.behaviour.upf.UpfProgrammableException) PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) PiAction(org.onosproject.net.pi.runtime.PiAction)

Aggregations

PiActionId (org.onosproject.net.pi.model.PiActionId)16 PiAction (org.onosproject.net.pi.runtime.PiAction)9 PiCriterion (org.onosproject.net.flow.criteria.PiCriterion)8 Test (org.junit.Test)6 PiTableId (org.onosproject.net.pi.model.PiTableId)6 PiActionParam (org.onosproject.net.pi.runtime.PiActionParam)6 UpfProgrammableException (org.onosproject.net.behaviour.upf.UpfProgrammableException)5 PiActionParamId (org.onosproject.net.pi.model.PiActionParamId)5 PiTableAction (org.onosproject.net.pi.runtime.PiTableAction)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 PiMatchFieldId (org.onosproject.net.pi.model.PiMatchFieldId)4 PiMatchFieldModel (org.onosproject.net.pi.model.PiMatchFieldModel)4 PiTableModel (org.onosproject.net.pi.model.PiTableModel)4 IOException (java.io.IOException)3 Ip4Address (org.onlab.packet.Ip4Address)3 PiActionModel (org.onosproject.net.pi.model.PiActionModel)3 ActionRef (p4.config.v1.P4InfoOuterClass.ActionRef)3 MatchField (p4.config.v1.P4InfoOuterClass.MatchField)3 P4Info (p4.config.v1.P4InfoOuterClass.P4Info)3 Table (p4.config.v1.P4InfoOuterClass.Table)3