Skip to content

Commit

Permalink
Use new refactored UPF entities and get slice ID from entities (#463)
Browse files Browse the repository at this point in the history
  • Loading branch information
daniele-moro authored Feb 2, 2022
1 parent 7c00a0e commit fe32c4a
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 63 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onos-dependencies</artifactId>
<version>2.5.6-SNAPSHOT</version>
<version>2.5.7-SNAPSHOT</version>
</parent>

<groupId>org.stratumproject</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import org.onosproject.core.CoreService;
import org.onosproject.drivers.p4runtime.AbstractP4RuntimeHandlerBehaviour;
import org.onosproject.net.PortNumber;
import org.onosproject.net.behaviour.upf.GtpTunnelPeer;
import org.onosproject.net.behaviour.upf.SessionDownlink;
import org.onosproject.net.behaviour.upf.SessionUplink;
import org.onosproject.net.behaviour.upf.UpfGtpTunnelPeer;
import org.onosproject.net.behaviour.upf.UpfSessionDownlink;
import org.onosproject.net.behaviour.upf.UpfSessionUplink;
import org.onosproject.net.behaviour.upf.UpfApplication;
import org.onosproject.net.behaviour.upf.UpfCounter;
import org.onosproject.net.behaviour.upf.UpfEntity;
Expand Down Expand Up @@ -603,10 +603,10 @@ public void apply(UpfEntity entity) throws UpfProgrammableException {
addInterface((UpfInterface) entity);
break;
case SESSION_UPLINK:
addUeSessionUplink((SessionUplink) entity);
addUeSessionUplink((UpfSessionUplink) entity);
break;
case SESSION_DOWNLINK:
addUeSessionDownlink((SessionDownlink) entity);
addUeSessionDownlink((UpfSessionDownlink) entity);
break;
case TERMINATION_UPLINK:
addUpfTerminationUplink((UpfTerminationUplink) entity);
Expand All @@ -615,7 +615,7 @@ public void apply(UpfEntity entity) throws UpfProgrammableException {
addUpfTerminationDownlink((UpfTerminationDownlink) entity);
break;
case TUNNEL_PEER:
addGtpTunnelPeer((GtpTunnelPeer) entity);
addGtpTunnelPeer((UpfGtpTunnelPeer) entity);
break;
case APPLICATION:
addUpfApplication((UpfApplication) entity);
Expand Down Expand Up @@ -646,7 +646,7 @@ private void addInterface(UpfInterface upfInterface) throws UpfProgrammableExcep
}
}

private void addGtpTunnelPeer(GtpTunnelPeer peer) throws UpfProgrammableException {
private void addGtpTunnelPeer(UpfGtpTunnelPeer peer) throws UpfProgrammableException {
Pair<FlowRule, FlowRule> fabricGtpTunnelPeers = upfTranslator.gtpTunnelPeerToFabricEntry(
peer, deviceId, appId, DEFAULT_PRIORITY);
log.info("Installing ingress and egress rules {}, {}",
Expand All @@ -656,15 +656,15 @@ private void addGtpTunnelPeer(GtpTunnelPeer peer) throws UpfProgrammableExceptio
fabricGtpTunnelPeers.getLeft().id().value(), fabricGtpTunnelPeers.getRight().id().value());
}

private void addUeSessionUplink(SessionUplink ueSession) throws UpfProgrammableException {
private void addUeSessionUplink(UpfSessionUplink ueSession) throws UpfProgrammableException {
FlowRule fabricUeSession = upfTranslator.sessionUplinkToFabricEntry(
ueSession, deviceId, appId, DEFAULT_PRIORITY);
log.info("Installing {}", ueSession.toString());
flowRuleService.applyFlowRules(fabricUeSession);
log.debug("Uplink UE session added with flowID {}", fabricUeSession.id().value());
}

private void addUeSessionDownlink(SessionDownlink ueSession) throws UpfProgrammableException {
private void addUeSessionDownlink(UpfSessionDownlink ueSession) throws UpfProgrammableException {
FlowRule fabricUeSession = upfTranslator.sessionDownlinkToFabricEntry(
ueSession, deviceId, appId, DEFAULT_PRIORITY);
log.info("Installing {}", ueSession.toString());
Expand Down Expand Up @@ -699,10 +699,10 @@ public void delete(UpfEntity entity) throws UpfProgrammableException {
removeInterface((UpfInterface) entity);
break;
case SESSION_UPLINK:
removeSessionUplink((SessionUplink) entity);
removeSessionUplink((UpfSessionUplink) entity);
break;
case SESSION_DOWNLINK:
removeSessionDownlink((SessionDownlink) entity);
removeSessionDownlink((UpfSessionDownlink) entity);
break;
case TERMINATION_UPLINK:
removeUpfTerminationUplink((UpfTerminationUplink) entity);
Expand All @@ -711,7 +711,7 @@ public void delete(UpfEntity entity) throws UpfProgrammableException {
removeUpfTerminationDownlink((UpfTerminationDownlink) entity);
break;
case TUNNEL_PEER:
removeGtpTunnelPeer((GtpTunnelPeer) entity);
removeGtpTunnelPeer((UpfGtpTunnelPeer) entity);
break;
case APPLICATION:
removeUpfApplication((UpfApplication) entity);
Expand Down Expand Up @@ -792,7 +792,7 @@ private void removeInterface(UpfInterface upfInterface) throws UpfProgrammableEx
removeEntry(match2, FABRIC_INGRESS_SPGW_INTERFACES, false);
}

private void removeSessionUplink(SessionUplink ueSession) throws UpfProgrammableException {
private void removeSessionUplink(UpfSessionUplink ueSession) throws UpfProgrammableException {
final PiCriterion match;

match = PiCriterion.builder()
Expand All @@ -803,7 +803,7 @@ private void removeSessionUplink(SessionUplink ueSession) throws UpfProgrammable
removeEntry(match, FABRIC_INGRESS_SPGW_UPLINK_SESSIONS, false);
}

private void removeSessionDownlink(SessionDownlink ueSession) throws UpfProgrammableException {
private void removeSessionDownlink(UpfSessionDownlink ueSession) throws UpfProgrammableException {
final PiCriterion match;

match = PiCriterion.builder()
Expand Down Expand Up @@ -836,7 +836,7 @@ private void removeUpfTerminationDownlink(UpfTerminationDownlink upfTermination)
removeEntry(match, FABRIC_INGRESS_SPGW_DOWNLINK_TERMINATIONS, false);
}

private void removeGtpTunnelPeer(GtpTunnelPeer peer) throws UpfProgrammableException {
private void removeGtpTunnelPeer(UpfGtpTunnelPeer peer) throws UpfProgrammableException {
PiCriterion match = PiCriterion.builder()
.matchExact(HDR_TUN_PEER_ID, peer.tunPeerId())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import org.onlab.packet.Ip4Prefix;
import org.onosproject.core.ApplicationId;
import org.onosproject.net.DeviceId;
import org.onosproject.net.behaviour.upf.GtpTunnelPeer;
import org.onosproject.net.behaviour.upf.SessionDownlink;
import org.onosproject.net.behaviour.upf.SessionUplink;
import org.onosproject.net.behaviour.upf.UpfGtpTunnelPeer;
import org.onosproject.net.behaviour.upf.UpfSessionDownlink;
import org.onosproject.net.behaviour.upf.UpfSessionUplink;
import org.onosproject.net.behaviour.upf.UpfApplication;
import org.onosproject.net.behaviour.upf.UpfInterface;
import org.onosproject.net.behaviour.upf.UpfProgrammableException;
Expand Down Expand Up @@ -95,9 +95,6 @@
*/
public class FabricUpfTranslator {

// FIXME: slice ID should come from UP4
private static final SliceId SLICE_MOBILE = SliceId.DEFAULT;

/**
* Returns true if the given table entry is a GTP tunnel peer rule from the
* physical fabric pipeline, and false otherwise.
Expand All @@ -107,7 +104,7 @@ public class FabricUpfTranslator {
*/
public boolean isFabricGtpTunnelPeer(FlowRule entry) {
// we return egress tunnel_peers table, because only this table
// contains all necessary information to create GtpTunnelPeer instance.
// contains all necessary information to create UpfGtpTunnelPeer instance.
return entry.table().equals(FABRIC_EGRESS_SPGW_EG_TUNNEL_PEERS);
}

Expand Down Expand Up @@ -186,16 +183,16 @@ private void assertTableId(FlowRule entry, PiTableId tableId) throws UpfProgramm
}

/**
* Translate a fabric.p4 GTP tunnel peer table entry to a GtpTunnelPeer instance for easier handling.
* Translate a fabric.p4 GTP tunnel peer table entry to a UpfGtpTunnelPeer instance for easier handling.
*
* @param entry the fabric.p4 entry to translate, the method expects FlowRule from eg_tunnel_peers table.
* @return the corresponding GtpTunnelPeer
* @return the corresponding UpfGtpTunnelPeer
* @throws UpfProgrammableException if the entry cannot be translated
*/
public GtpTunnelPeer fabricEntryToGtpTunnelPeer(FlowRule entry)
public UpfGtpTunnelPeer fabricEntryToGtpTunnelPeer(FlowRule entry)
throws UpfProgrammableException {
assertTableId(entry, FABRIC_EGRESS_SPGW_EG_TUNNEL_PEERS);
GtpTunnelPeer.Builder builder = GtpTunnelPeer.builder();
UpfGtpTunnelPeer.Builder builder = UpfGtpTunnelPeer.builder();

Pair<PiCriterion, PiTableAction> matchActionPair = FabricUpfTranslatorUtil.fabricEntryToPiPair(entry);
PiCriterion match = matchActionPair.getLeft();
Expand All @@ -204,7 +201,7 @@ public GtpTunnelPeer fabricEntryToGtpTunnelPeer(FlowRule entry)

if (!action.id().equals(FABRIC_EGRESS_SPGW_LOAD_TUNNEL_PARAMS)) {
throw new UpfProgrammableException(
"Invalid action provided, cannot build GtpTunnelPeer instance: " + action.id());
"Invalid action provided, cannot build UpfGtpTunnelPeer instance: " + action.id());
}

builder.withSrcAddr(FabricUpfTranslatorUtil.getParamAddress(action, TUNNEL_SRC_ADDR))
Expand All @@ -221,10 +218,10 @@ public GtpTunnelPeer fabricEntryToGtpTunnelPeer(FlowRule entry)
* @return the corresponding UeSession
* @throws UpfProgrammableException if the entry cannot be translated
*/
public SessionUplink fabricEntryToUeSessionUplink(FlowRule entry)
public UpfSessionUplink fabricEntryToUeSessionUplink(FlowRule entry)
throws UpfProgrammableException {
assertTableId(entry, FABRIC_INGRESS_SPGW_UPLINK_SESSIONS);
SessionUplink.Builder builder = SessionUplink.builder();
UpfSessionUplink.Builder builder = UpfSessionUplink.builder();

Pair<PiCriterion, PiTableAction> matchActionPair = FabricUpfTranslatorUtil.fabricEntryToPiPair(entry);
PiCriterion match = matchActionPair.getLeft();
Expand All @@ -250,10 +247,10 @@ public SessionUplink fabricEntryToUeSessionUplink(FlowRule entry)
* @return the corresponding UeSession
* @throws UpfProgrammableException if the entry cannot be translated
*/
public SessionDownlink fabricEntryToUeSessionDownlink(FlowRule entry)
public UpfSessionDownlink fabricEntryToUeSessionDownlink(FlowRule entry)
throws UpfProgrammableException {
assertTableId(entry, FABRIC_INGRESS_SPGW_DOWNLINK_SESSIONS);
SessionDownlink.Builder builder = SessionDownlink.builder();
UpfSessionDownlink.Builder builder = UpfSessionDownlink.builder();
Pair<PiCriterion, PiTableAction> matchActionPair = FabricUpfTranslatorUtil.fabricEntryToPiPair(entry);
PiCriterion match = matchActionPair.getLeft();
PiAction action = (PiAction) matchActionPair.getRight();
Expand Down Expand Up @@ -365,7 +362,8 @@ public UpfInterface fabricEntryToInterface(FlowRule entry)
PiAction action = (PiAction) matchActionPair.getRight();

var ifaceBuilder = UpfInterface.builder()
.setPrefix(FabricUpfTranslatorUtil.getFieldPrefix(match, HDR_IPV4_DST_ADDR));
.setPrefix(FabricUpfTranslatorUtil.getFieldPrefix(match, HDR_IPV4_DST_ADDR))
.setSliceId(FabricUpfTranslatorUtil.getParamByte(action, SLICE_ID));

if (action.id().equals(FABRIC_INGRESS_SPGW_IFACE_ACCESS)) {
ifaceBuilder.setAccess();
Expand All @@ -388,6 +386,7 @@ public UpfApplication fabricEntryToUpfApplication(FlowRule entry)
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));
Expand All @@ -402,7 +401,7 @@ public UpfApplication fabricEntryToUpfApplication(FlowRule entry)
}

/**
* Translate a GtpTunnelPeer to two FlowRules to be inserted into the fabric.p4 pipeline.
* 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
Expand All @@ -411,7 +410,7 @@ public UpfApplication fabricEntryToUpfApplication(FlowRule entry)
* @return a pair of FlowRules translated from GTP tunnel peer
* @throws UpfProgrammableException if the interface cannot be translated
*/
public Pair<FlowRule, FlowRule> gtpTunnelPeerToFabricEntry(GtpTunnelPeer gtpTunnelPeer, DeviceId deviceId,
public Pair<FlowRule, FlowRule> gtpTunnelPeerToFabricEntry(UpfGtpTunnelPeer gtpTunnelPeer, DeviceId deviceId,
ApplicationId appId, int priority)
throws UpfProgrammableException {
FlowRule ingressEntry;
Expand Down Expand Up @@ -465,7 +464,7 @@ public Pair<FlowRule, FlowRule> gtpTunnelPeerToFabricEntry(GtpTunnelPeer gtpTunn
* @return the uplink ue session translated to a FlowRule
* @throws UpfProgrammableException if the UE session cannot be translated
*/
public FlowRule sessionUplinkToFabricEntry(SessionUplink ueSession, DeviceId deviceId,
public FlowRule sessionUplinkToFabricEntry(UpfSessionUplink ueSession, DeviceId deviceId,
ApplicationId appId, int priority)
throws UpfProgrammableException {
final PiCriterion match;
Expand Down Expand Up @@ -501,7 +500,7 @@ public FlowRule sessionUplinkToFabricEntry(SessionUplink ueSession, DeviceId dev
* @return the downlink ue session translated to a FlowRule
* @throws UpfProgrammableException if the UE session cannot be translated
*/
public FlowRule sessionDownlinkToFabricEntry(SessionDownlink ueSession, DeviceId deviceId,
public FlowRule sessionDownlinkToFabricEntry(UpfSessionDownlink ueSession, DeviceId deviceId,
ApplicationId appId, int priority)
throws UpfProgrammableException {
final PiCriterion match;
Expand Down Expand Up @@ -662,7 +661,7 @@ public FlowRule interfaceToFabricEntry(UpfInterface upfInterface, DeviceId devic
.build();
PiAction action = PiAction.builder()
.withId(actionId)
.withParameter(new PiActionParam(SLICE_ID, SLICE_MOBILE.id()))
.withParameter(new PiActionParam(SLICE_ID, SliceId.of(upfInterface.sliceId()).id()))
.build();
return DefaultFlowRule.builder()
.forDevice(deviceId).fromApp(appId).makePermanent()
Expand Down Expand Up @@ -692,7 +691,7 @@ public FlowRule upfApplicationToFabricEntry(

public PiCriterion buildApplicationCriterion(UpfApplication appFilter) {
PiCriterion.Builder matchBuilder = PiCriterion.builder();
matchBuilder.matchExact(HDR_SLICE_ID, SLICE_MOBILE.id());
matchBuilder.matchExact(HDR_SLICE_ID, SliceId.of(appFilter.sliceId()).id());
if (appFilter.ip4Prefix().isPresent()) {
Ip4Prefix ip4Prefix = appFilter.ip4Prefix().get();
matchBuilder.matchLpm(HDR_APP_IPV4_ADDR, ip4Prefix.address().toOctets(), ip4Prefix.prefixLength());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import org.onosproject.core.CoreService;
import org.onosproject.net.DeviceId;
import org.onosproject.net.PortNumber;
import org.onosproject.net.behaviour.upf.SessionDownlink;
import org.onosproject.net.behaviour.upf.SessionUplink;
import org.onosproject.net.behaviour.upf.UpfSessionDownlink;
import org.onosproject.net.behaviour.upf.UpfSessionUplink;
import org.onosproject.net.behaviour.upf.UpfApplication;
import org.onosproject.net.behaviour.upf.UpfCounter;
import org.onosproject.net.behaviour.upf.UpfEntity;
Expand Down Expand Up @@ -160,7 +160,7 @@ public void setUp() throws Exception {
@Test
public void testUplinkUeSession() throws Exception {
assertTrue(upfProgrammable.readAll(UpfEntityType.SESSION_UPLINK).isEmpty());
SessionUplink expectedUeSession = TestUpfConstants.UPLINK_UE_SESSION;
UpfSessionUplink expectedUeSession = TestUpfConstants.UPLINK_UE_SESSION;
upfProgrammable.apply(expectedUeSession);
Collection<? extends UpfEntity> installedUeSessions = upfProgrammable.readAll(UpfEntityType.SESSION_UPLINK);
assertThat(installedUeSessions.size(), equalTo(1));
Expand All @@ -174,7 +174,7 @@ public void testUplinkUeSession() throws Exception {
@Test
public void testDownlinkUeSession() throws Exception {
assertTrue(upfProgrammable.readAll(UpfEntityType.SESSION_DOWNLINK).isEmpty());
SessionDownlink expectedUeSession = TestUpfConstants.DOWNLINK_UE_SESSION;
UpfSessionDownlink expectedUeSession = TestUpfConstants.DOWNLINK_UE_SESSION;
upfProgrammable.apply(expectedUeSession);
Collection<? extends UpfEntity> installedUeSessions = upfProgrammable.readAll(UpfEntityType.SESSION_DOWNLINK);
assertThat(installedUeSessions.size(), equalTo(1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

import org.apache.commons.lang3.tuple.Pair;
import org.junit.Test;
import org.onosproject.net.behaviour.upf.GtpTunnelPeer;
import org.onosproject.net.behaviour.upf.SessionDownlink;
import org.onosproject.net.behaviour.upf.SessionUplink;
import org.onosproject.net.behaviour.upf.UpfGtpTunnelPeer;
import org.onosproject.net.behaviour.upf.UpfSessionDownlink;
import org.onosproject.net.behaviour.upf.UpfSessionUplink;
import org.onosproject.net.behaviour.upf.UpfApplication;
import org.onosproject.net.behaviour.upf.UpfInterface;
import org.onosproject.net.behaviour.upf.UpfProgrammableException;
Expand All @@ -23,8 +23,8 @@ public class FabricUpfTranslatorTest {

@Test
public void fabricEntryToGtpTunnelPeerTest() {
GtpTunnelPeer translated;
GtpTunnelPeer expected = TestUpfConstants.GTP_TUNNEL_PEER;
UpfGtpTunnelPeer translated;
UpfGtpTunnelPeer expected = TestUpfConstants.GTP_TUNNEL_PEER;
try {
translated = upfTranslator.fabricEntryToGtpTunnelPeer(TestUpfConstants.FABRIC_EGRESS_GTP_TUNNEL_PEER);
} catch (UpfProgrammableException e) {
Expand All @@ -37,8 +37,8 @@ public void fabricEntryToGtpTunnelPeerTest() {

@Test
public void fabricEntryToUplinkUeSessionTest() {
SessionUplink translated;
SessionUplink expected = TestUpfConstants.UPLINK_UE_SESSION;
UpfSessionUplink translated;
UpfSessionUplink expected = TestUpfConstants.UPLINK_UE_SESSION;
try {
translated = upfTranslator.fabricEntryToUeSessionUplink(TestUpfConstants.FABRIC_UPLINK_UE_SESSION);
} catch (UpfProgrammableException e) {
Expand All @@ -51,8 +51,8 @@ public void fabricEntryToUplinkUeSessionTest() {

@Test
public void fabricEntryToDownlinkUeSessionTest() {
SessionDownlink translated;
SessionDownlink expected = TestUpfConstants.DOWNLINK_UE_SESSION;
UpfSessionDownlink translated;
UpfSessionDownlink expected = TestUpfConstants.DOWNLINK_UE_SESSION;
try {
translated = upfTranslator.fabricEntryToUeSessionDownlink(TestUpfConstants.FABRIC_DOWNLINK_UE_SESSION);
} catch (UpfProgrammableException e) {
Expand All @@ -65,8 +65,8 @@ public void fabricEntryToDownlinkUeSessionTest() {

@Test
public void fabricEntryToDownlinkUeSessionDbufTest() {
SessionDownlink translated;
SessionDownlink expected = TestUpfConstants.DOWNLINK_UE_SESSION_DBUF;
UpfSessionDownlink translated;
UpfSessionDownlink expected = TestUpfConstants.DOWNLINK_UE_SESSION_DBUF;
try {
translated = upfTranslator.fabricEntryToUeSessionDownlink(TestUpfConstants.FABRIC_DOWNLINK_UE_SESSION_DBUF);
} catch (UpfProgrammableException e) {
Expand Down
Loading

0 comments on commit fe32c4a

Please sign in to comment.