Search in sources :

Example 66 with PiCriterion

use of org.onosproject.net.flow.criteria.PiCriterion in project fabric-tna by stratum.

the class FabricUpfTranslator method sessionUplinkToFabricEntry.

/**
 * Translate a uplink session to a FlowRule to be inserted into the fabric.p4 pipeline.
 *
 * @param ueSession The uplink UE Session 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 uplink ue session translated to a FlowRule
 * @throws UpfProgrammableException if the UE session cannot be translated
 */
public FlowRule sessionUplinkToFabricEntry(UpfSessionUplink ueSession, DeviceId deviceId, ApplicationId appId, int priority) throws UpfProgrammableException {
    final PiCriterion match;
    final PiAction.Builder actionBuilder = PiAction.builder();
    match = PiCriterion.builder().matchExact(HDR_TEID, ueSession.teid()).matchExact(HDR_TUNNEL_IPV4_DST, ueSession.tunDstAddr().toOctets()).build();
    if (ueSession.needsDropping()) {
        actionBuilder.withId(FABRIC_INGRESS_UPF_SET_UPLINK_SESSION_DROP);
    } else {
        actionBuilder.withId(FABRIC_INGRESS_UPF_SET_UPLINK_SESSION);
        actionBuilder.withParameter(new PiActionParam(SESSION_METER_IDX, (short) ueSession.sessionMeterIdx()));
    }
    return DefaultFlowRule.builder().forDevice(deviceId).fromApp(appId).makePermanent().forTable(FABRIC_INGRESS_UPF_UPLINK_SESSIONS).withSelector(DefaultTrafficSelector.builder().matchPi(match).build()).withTreatment(DefaultTrafficTreatment.builder().piTableAction(actionBuilder.build()).build()).withPriority(priority).build();
}
Also used : PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) PiAction(org.onosproject.net.pi.runtime.PiAction)

Example 67 with PiCriterion

use of org.onosproject.net.flow.criteria.PiCriterion 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)

Example 68 with PiCriterion

use of org.onosproject.net.flow.criteria.PiCriterion in project fabric-tna by stratum.

the class FabricUpfTranslator method fabricEntryToUpfTerminationDownlink.

/**
 * Translate a fabric.p4 termination table entry to a downlink UpfTermination instance for easier handling.
 *
 * @param entry the fabric.p4 entry to translate
 * @return the corresponding UpfTerminationDownlink
 * @throws UpfProgrammableException if the entry cannot be translated
 */
public UpfTerminationDownlink fabricEntryToUpfTerminationDownlink(FlowRule entry) throws UpfProgrammableException {
    assertTableId(entry, FABRIC_INGRESS_UPF_DOWNLINK_TERMINATIONS);
    UpfTerminationDownlink.Builder builder = UpfTerminationDownlink.builder();
    Pair<PiCriterion, PiTableAction> matchActionPair = FabricUpfTranslatorUtil.fabricEntryToPiPair(entry);
    PiCriterion match = matchActionPair.getLeft();
    PiAction action = (PiAction) matchActionPair.getRight();
    if (!FabricUpfTranslatorUtil.fieldIsPresent(match, HDR_UE_SESSION_ID) || !FabricUpfTranslatorUtil.fieldIsPresent(match, HDR_APP_ID)) {
        throw new UpfProgrammableException("Malformed downlink termination from dataplane!: " + entry);
    }
    // Match keys
    Ip4Address ueSessionId = FabricUpfTranslatorUtil.getFieldAddress(match, HDR_UE_SESSION_ID);
    builder.withUeSessionId(ueSessionId);
    byte applicationId = FabricUpfTranslatorUtil.getFieldByte(match, HDR_APP_ID);
    builder.withApplicationId(applicationId);
    PiActionId actionId = action.id();
    builder.withCounterId(FabricUpfTranslatorUtil.getParamInt(action, CTR_ID));
    if (actionId.equals(FABRIC_INGRESS_UPF_DOWNLINK_DROP)) {
        builder.needsDropping(true);
    } else {
        builder.withTeid(FabricUpfTranslatorUtil.getParamInt(action, TEID)).withQfi(FabricUpfTranslatorUtil.getParamByte(action, QFI)).withAppMeterIdx(FabricUpfTranslatorUtil.getParamShort(action, APP_METER_IDX));
        if (actionId.equals(FABRIC_INGRESS_UPF_DOWNLINK_FWD_ENCAP)) {
            builder.withTrafficClass(FabricUpfTranslatorUtil.getParamByte(action, TC));
        }
    }
    return builder.build();
}
Also used : UpfProgrammableException(org.onosproject.net.behaviour.upf.UpfProgrammableException) PiActionId(org.onosproject.net.pi.model.PiActionId) UpfTerminationDownlink(org.onosproject.net.behaviour.upf.UpfTerminationDownlink) PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) PiTableAction(org.onosproject.net.pi.runtime.PiTableAction) Ip4Address(org.onlab.packet.Ip4Address) PiAction(org.onosproject.net.pi.runtime.PiAction)

Example 69 with PiCriterion

use of org.onosproject.net.flow.criteria.PiCriterion in project fabric-tna by stratum.

the class FabricUpfTranslatorUtil method fabricEntryToPiPair.

static Pair<PiCriterion, PiTableAction> fabricEntryToPiPair(FlowRule entry) {
    PiCriterion match = (PiCriterion) entry.selector().getCriterion(Criterion.Type.PROTOCOL_INDEPENDENT);
    PiTableAction action = null;
    for (Instruction instruction : entry.treatment().allInstructions()) {
        if (instruction.type() == Instruction.Type.PROTOCOL_INDEPENDENT) {
            PiInstruction piInstruction = (PiInstruction) instruction;
            action = piInstruction.action();
            break;
        }
    }
    return Pair.of(match, action);
}
Also used : PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) PiTableAction(org.onosproject.net.pi.runtime.PiTableAction) PiInstruction(org.onosproject.net.flow.instructions.PiInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) PiInstruction(org.onosproject.net.flow.instructions.PiInstruction)

Aggregations

PiCriterion (org.onosproject.net.flow.criteria.PiCriterion)69 PiAction (org.onosproject.net.pi.runtime.PiAction)45 PiActionParam (org.onosproject.net.pi.runtime.PiActionParam)31 TrafficSelector (org.onosproject.net.flow.TrafficSelector)29 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)28 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)27 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)26 FlowRule (org.onosproject.net.flow.FlowRule)25 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)16 PiTableAction (org.onosproject.net.pi.runtime.PiTableAction)13 Test (org.junit.Test)8 UpfProgrammableException (org.onosproject.net.behaviour.upf.UpfProgrammableException)8 DefaultNextObjective (org.onosproject.net.flowobjective.DefaultNextObjective)8 NextObjective (org.onosproject.net.flowobjective.NextObjective)8 PiActionId (org.onosproject.net.pi.model.PiActionId)7 DefaultGroupBucket (org.onosproject.net.group.DefaultGroupBucket)6 DefaultGroupDescription (org.onosproject.net.group.DefaultGroupDescription)6 GroupBucket (org.onosproject.net.group.GroupBucket)6 GroupBuckets (org.onosproject.net.group.GroupBuckets)6 GroupDescription (org.onosproject.net.group.GroupDescription)6