use of org.onosproject.net.flow.criteria.PiCriterion in project fabric-tna by stratum.
the class FabricUpfTranslator method gtpTunnelPeerToFabricEntry.
/**
* Translate a UpfGtpTunnelPeer to two FlowRules to be inserted into the fabric.p4 pipeline.
*
* @param gtpTunnelPeer the GTP tunnel peer 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 FlowRules' priority
* @return a pair of FlowRules translated from GTP tunnel peer
* @throws UpfProgrammableException if the interface cannot be translated
*/
public Pair<FlowRule, FlowRule> gtpTunnelPeerToFabricEntry(UpfGtpTunnelPeer gtpTunnelPeer, DeviceId deviceId, ApplicationId appId, int priority) throws UpfProgrammableException {
FlowRule ingressEntry;
FlowRule egressEntry;
if (gtpTunnelPeer.src() == null || gtpTunnelPeer.dst() == null) {
throw new UpfProgrammableException("Not all action parameters present when translating " + "intermediate GTP tunnel peer to physical representation!");
}
PiCriterion match = PiCriterion.builder().matchExact(HDR_TUN_PEER_ID, gtpTunnelPeer.tunPeerId()).build();
FlowRule.Builder base = DefaultFlowRule.builder().forDevice(deviceId).fromApp(appId).makePermanent().withPriority(priority).withSelector(DefaultTrafficSelector.builder().matchPi(match).build());
PiAction ingressAction = PiAction.builder().withId(FABRIC_INGRESS_UPF_SET_ROUTING_IPV4_DST).withParameter(new PiActionParam(TUN_DST_ADDR, gtpTunnelPeer.dst().toInt())).build();
ingressEntry = base.forTable(FABRIC_INGRESS_UPF_IG_TUNNEL_PEERS).withTreatment(DefaultTrafficTreatment.builder().piTableAction(ingressAction).build()).build();
PiAction egressAction = PiAction.builder().withId(FABRIC_EGRESS_UPF_LOAD_TUNNEL_PARAMS).withParameters(Arrays.asList(new PiActionParam(TUNNEL_SRC_ADDR, gtpTunnelPeer.src().toInt()), new PiActionParam(TUNNEL_DST_ADDR, gtpTunnelPeer.dst().toInt()), new PiActionParam(TUNNEL_SRC_PORT, gtpTunnelPeer.srcPort()))).build();
egressEntry = base.forTable(FABRIC_EGRESS_UPF_EG_TUNNEL_PEERS).withTreatment(DefaultTrafficTreatment.builder().piTableAction(egressAction).build()).build();
return Pair.of(ingressEntry, egressEntry);
}
use of org.onosproject.net.flow.criteria.PiCriterion in project fabric-tna by stratum.
the class FabricUpfTranslator method fabricEntryToUpfTerminationUplink.
/**
* Translate a fabric.p4 termination table entry to a uplink UpfTermination instance for easier handling.
*
* @param entry the fabric.p4 entry to translate
* @return the corresponding UpfTerminationUplink
* @throws UpfProgrammableException if the entry cannot be translated
*/
public UpfTerminationUplink fabricEntryToUpfTerminationUplink(FlowRule entry) throws UpfProgrammableException {
assertTableId(entry, FABRIC_INGRESS_UPF_UPLINK_TERMINATIONS);
UpfTerminationUplink.Builder builder = UpfTerminationUplink.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 uplink 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_UPLINK_DROP)) {
builder.needsDropping(true);
} else {
builder.withAppMeterIdx(FabricUpfTranslatorUtil.getParamShort(action, APP_METER_IDX));
if (actionId.equals(FABRIC_INGRESS_UPF_APP_FWD)) {
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 FabricUpfTranslator method sessionDownlinkToFabricEntry.
/**
* Translate a downlink session to a FlowRule to be inserted into the fabric.p4 pipeline.
*
* @param ueSession The downlink 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 downlink ue session translated to a FlowRule
* @throws UpfProgrammableException if the UE session cannot be translated
*/
public FlowRule sessionDownlinkToFabricEntry(UpfSessionDownlink ueSession, DeviceId deviceId, ApplicationId appId, int priority) throws UpfProgrammableException {
final PiCriterion match;
final PiAction.Builder actionBuilder = PiAction.builder();
match = PiCriterion.builder().matchExact(HDR_UE_ADDR, ueSession.ueAddress().toOctets()).build();
if (ueSession.needsDropping() && ueSession.needsBuffering()) {
actionBuilder.withId(FABRIC_INGRESS_UPF_SET_DOWNLINK_SESSION_BUF_DROP);
} else if (ueSession.needsDropping()) {
actionBuilder.withId(FABRIC_INGRESS_UPF_SET_DOWNLINK_SESSION_DROP);
} else {
actionBuilder.withParameter(new PiActionParam(TUN_PEER_ID, ueSession.tunPeerId())).withParameter(new PiActionParam(SESSION_METER_IDX, (short) ueSession.sessionMeterIdx()));
if (ueSession.needsBuffering()) {
actionBuilder.withId(FABRIC_INGRESS_UPF_SET_DOWNLINK_SESSION_BUF);
} else {
actionBuilder.withId(FABRIC_INGRESS_UPF_SET_DOWNLINK_SESSION);
}
}
return DefaultFlowRule.builder().forDevice(deviceId).fromApp(appId).makePermanent().forTable(FABRIC_INGRESS_UPF_DOWNLINK_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 fabricEntryToUpfApplication.
public UpfApplication fabricEntryToUpfApplication(FlowRule entry) throws UpfProgrammableException {
assertTableId(entry, FABRIC_INGRESS_UPF_APPLICATIONS);
Pair<PiCriterion, PiTableAction> matchActionPair = FabricUpfTranslatorUtil.fabricEntryToPiPair(entry);
PiCriterion match = matchActionPair.getLeft();
PiAction action = (PiAction) matchActionPair.getRight();
UpfApplication.Builder appFilteringBuilder = UpfApplication.builder().withAppId(FabricUpfTranslatorUtil.getParamByte(action, APP_ID)).withSliceId(FabricUpfTranslatorUtil.getFieldInt(match, HDR_SLICE_ID)).withPriority(entry.priority());
if (FabricUpfTranslatorUtil.fieldIsPresent(match, HDR_APP_IPV4_ADDR)) {
appFilteringBuilder.withIp4Prefix(FabricUpfTranslatorUtil.getFieldPrefix(match, HDR_APP_IPV4_ADDR));
}
if (FabricUpfTranslatorUtil.fieldIsPresent(match, HDR_APP_L4_PORT)) {
appFilteringBuilder.withL4PortRange(FabricUpfTranslatorUtil.getFieldRangeShort(match, HDR_APP_L4_PORT));
}
if (FabricUpfTranslatorUtil.fieldIsPresent(match, HDR_APP_IP_PROTO)) {
appFilteringBuilder.withIpProto(FabricUpfTranslatorUtil.getFieldByte(match, HDR_APP_IP_PROTO));
}
return appFilteringBuilder.build();
}
use of org.onosproject.net.flow.criteria.PiCriterion in project fabric-tna by stratum.
the class FabricUpfTranslator method fabricEntryToUeSessionDownlink.
/**
* Translate a fabric.p4 session table entry to a UeSession instance for easier handling.
*
* @param entry the fabric.p4 entry to translate
* @return the corresponding UeSession
* @throws UpfProgrammableException if the entry cannot be translated
*/
public UpfSessionDownlink fabricEntryToUeSessionDownlink(FlowRule entry) throws UpfProgrammableException {
assertTableId(entry, FABRIC_INGRESS_UPF_DOWNLINK_SESSIONS);
UpfSessionDownlink.Builder builder = UpfSessionDownlink.builder();
Pair<PiCriterion, PiTableAction> matchActionPair = FabricUpfTranslatorUtil.fabricEntryToPiPair(entry);
PiCriterion match = matchActionPair.getLeft();
PiAction action = (PiAction) matchActionPair.getRight();
if (!FabricUpfTranslatorUtil.fieldIsPresent(match, HDR_UE_ADDR)) {
throw new UpfProgrammableException("Malformed downlink session from dataplane!: " + entry);
}
builder.withUeAddress(FabricUpfTranslatorUtil.getFieldAddress(match, HDR_UE_ADDR));
PiActionId actionId = action.id();
if (actionId.equals(FABRIC_INGRESS_UPF_SET_DOWNLINK_SESSION_DROP)) {
builder.needsDropping(true);
} else if (actionId.equals(FABRIC_INGRESS_UPF_SET_DOWNLINK_SESSION_BUF_DROP)) {
builder.needsDropping(true);
builder.needsBuffering(true);
} else {
builder.withGtpTunnelPeerId(FabricUpfTranslatorUtil.getParamByte(action, TUN_PEER_ID)).withSessionMeterIdx(FabricUpfTranslatorUtil.getParamShort(action, SESSION_METER_IDX));
if (actionId.equals(FABRIC_INGRESS_UPF_SET_DOWNLINK_SESSION_BUF)) {
builder.needsBuffering(true);
}
}
return builder.build();
}
Aggregations