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();
}
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();
}
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();
}
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);
}
Aggregations