Search in sources :

Example 11 with PiTernaryFieldMatch

use of org.onosproject.net.pi.runtime.PiTernaryFieldMatch in project onos by opennetworkinglab.

the class PiCriterionTranslatorsTest method testUdpPortCriterion.

@Test
public void testUdpPortCriterion() throws Exception {
    TpPort value1 = TpPort.tpPort(random.nextInt(65536));
    TpPort value2 = TpPort.tpPort(random.nextInt(65536));
    TpPort mask = TpPort.tpPort(random.nextInt(65536));
    int bitWidth = 16;
    UdpPortCriterion criterion = (UdpPortCriterion) Criteria.matchUdpDst(value1);
    PiExactFieldMatch exactMatch = (PiExactFieldMatch) translateCriterion(criterion, fieldId, EXACT, bitWidth);
    UdpPortCriterion maskedCriterion = (UdpPortCriterion) Criteria.matchUdpDstMasked(value2, mask);
    PiTernaryFieldMatch ternaryMatch = (PiTernaryFieldMatch) translateCriterion(maskedCriterion, fieldId, TERNARY, bitWidth);
    assertThat(exactMatch.value().asReadOnlyBuffer().getShort(), is((short) criterion.udpPort().toInt()));
    assertThat(ternaryMatch.value().asReadOnlyBuffer().getShort(), is((short) maskedCriterion.udpPort().toInt()));
    assertThat(ternaryMatch.mask().asReadOnlyBuffer().getShort(), is((short) maskedCriterion.mask().toInt()));
}
Also used : UdpPortCriterion(org.onosproject.net.flow.criteria.UdpPortCriterion) TpPort(org.onlab.packet.TpPort) PiExactFieldMatch(org.onosproject.net.pi.runtime.PiExactFieldMatch) PiTernaryFieldMatch(org.onosproject.net.pi.runtime.PiTernaryFieldMatch) Test(org.junit.Test)

Example 12 with PiTernaryFieldMatch

use of org.onosproject.net.pi.runtime.PiTernaryFieldMatch in project onos by opennetworkinglab.

the class PiCriterionTranslatorsTest method testEthCriterion.

@Test
public void testEthCriterion() throws Exception {
    MacAddress value1 = MacAddress.valueOf(random.nextLong());
    MacAddress value2 = MacAddress.valueOf(random.nextLong());
    MacAddress mask = MacAddress.valueOf(random.nextLong());
    int bitWidth = value1.toBytes().length * 8;
    EthCriterion criterion = (EthCriterion) Criteria.matchEthDst(value1);
    PiExactFieldMatch exactMatch = (PiExactFieldMatch) translateCriterion(criterion, fieldId, EXACT, bitWidth);
    EthCriterion maskedCriterion = (EthCriterion) Criteria.matchEthDstMasked(value2, mask);
    PiTernaryFieldMatch ternaryMatch = (PiTernaryFieldMatch) translateCriterion(maskedCriterion, fieldId, TERNARY, bitWidth);
    assertThat(exactMatch.value().asArray(), is(criterion.mac().toBytes()));
    assertThat(ternaryMatch.value().asArray(), is(maskedCriterion.mac().toBytes()));
    assertThat(ternaryMatch.mask().asArray(), is(maskedCriterion.mask().toBytes()));
}
Also used : EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) PiExactFieldMatch(org.onosproject.net.pi.runtime.PiExactFieldMatch) PiTernaryFieldMatch(org.onosproject.net.pi.runtime.PiTernaryFieldMatch) MacAddress(org.onlab.packet.MacAddress) Test(org.junit.Test)

Example 13 with PiTernaryFieldMatch

use of org.onosproject.net.pi.runtime.PiTernaryFieldMatch in project up4 by omec-project.

the class Up4TranslatorImpl method upfEntityToUp4TableEntry.

@Override
public PiTableEntry upfEntityToUp4TableEntry(UpfEntity entity) throws Up4TranslationException {
    PiTableEntry.Builder tableEntryBuilder = PiTableEntry.builder();
    PiAction.Builder actionBuilder = PiAction.builder();
    PiMatchKey.Builder matchBuilder = PiMatchKey.builder();
    switch(entity.type()) {
        case INTERFACE:
            tableEntryBuilder.forTable(PRE_QOS_PIPE_INTERFACES);
            UpfInterface upfIntf = (UpfInterface) entity;
            byte direction;
            byte srcIface;
            actionBuilder.withId(PRE_QOS_PIPE_SET_SOURCE_IFACE);
            if (upfIntf.isAccess()) {
                srcIface = IFACE_ACCESS;
                direction = DIRECTION_UPLINK;
            } else if (upfIntf.isCore()) {
                srcIface = IFACE_CORE;
                direction = DIRECTION_DOWNLINK;
            } else {
                throw new Up4TranslationException("UPF Interface is not Access nor CORE: " + upfIntf);
            }
            actionBuilder.withParameter(new PiActionParam(SRC_IFACE, srcIface)).withParameter(new PiActionParam(DIRECTION, direction)).withParameter(new PiActionParam(SLICE_ID, (byte) upfIntf.sliceId()));
            matchBuilder.addFieldMatch(new PiLpmFieldMatch(HDR_IPV4_DST_PREFIX, ImmutableByteSequence.copyFrom(upfIntf.prefix().address().toOctets()), upfIntf.prefix().prefixLength()));
            break;
        case SESSION_UPLINK:
            tableEntryBuilder.forTable(PRE_QOS_PIPE_SESSIONS_UPLINK);
            UpfSessionUplink sessionUplink = (UpfSessionUplink) entity;
            matchBuilder.addFieldMatch(new PiExactFieldMatch(HDR_N3_ADDRESS, ImmutableByteSequence.copyFrom(sessionUplink.tunDstAddr().toOctets()))).addFieldMatch(new PiExactFieldMatch(HDR_TEID, ImmutableByteSequence.copyFrom(sessionUplink.teid())));
            if (sessionUplink.needsDropping()) {
                actionBuilder.withId(PRE_QOS_PIPE_SET_SESSION_UPLINK_DROP);
            } else {
                actionBuilder.withId(PRE_QOS_PIPE_SET_SESSION_UPLINK);
                actionBuilder.withParameter(new PiActionParam(SESSION_METER_IDX, sessionUplink.sessionMeterIdx()));
            }
            break;
        case SESSION_DOWNLINK:
            tableEntryBuilder.forTable(PRE_QOS_PIPE_SESSIONS_DOWNLINK);
            UpfSessionDownlink sessionDownlink = (UpfSessionDownlink) entity;
            matchBuilder.addFieldMatch(new PiExactFieldMatch(HDR_UE_ADDRESS, ImmutableByteSequence.copyFrom(sessionDownlink.ueAddress().toOctets())));
            if (sessionDownlink.needsDropping() && sessionDownlink.needsBuffering()) {
                log.error("We don't support DROP + BUFF on the UP4 northbound! Defaulting to only BUFF");
                actionBuilder.withId(PRE_QOS_PIPE_SET_SESSION_DOWNLINK_BUFF);
                actionBuilder.withParameter(new PiActionParam(SESSION_METER_IDX, sessionDownlink.sessionMeterIdx()));
            } else if (sessionDownlink.needsDropping()) {
                actionBuilder.withId(PRE_QOS_PIPE_SET_SESSION_DOWNLINK_DROP);
            } else {
                actionBuilder.withParameter(new PiActionParam(SESSION_METER_IDX, sessionDownlink.sessionMeterIdx()));
                if (sessionDownlink.needsBuffering()) {
                    actionBuilder.withId(PRE_QOS_PIPE_SET_SESSION_DOWNLINK_BUFF);
                } else {
                    actionBuilder.withParameter(new PiActionParam(TUNNEL_PEER_ID, ImmutableByteSequence.copyFrom(sessionDownlink.tunPeerId())));
                    actionBuilder.withId(PRE_QOS_PIPE_SET_SESSION_DOWNLINK);
                }
            }
            break;
        case TERMINATION_UPLINK:
            tableEntryBuilder.forTable(PRE_QOS_PIPE_TERMINATIONS_UPLINK);
            UpfTerminationUplink upfTerminationUl = (UpfTerminationUplink) entity;
            matchBuilder.addFieldMatch(new PiExactFieldMatch(HDR_UE_ADDRESS, ImmutableByteSequence.copyFrom(upfTerminationUl.ueSessionId().toOctets()))).addFieldMatch(new PiExactFieldMatch(HDR_APP_ID, ImmutableByteSequence.copyFrom(upfTerminationUl.applicationId())));
            actionBuilder.withParameter(new PiActionParam(CTR_IDX, upfTerminationUl.counterId()));
            if (upfTerminationUl.needsDropping()) {
                actionBuilder.withId(PRE_QOS_PIPE_UPLINK_TERM_DROP);
            } else {
                actionBuilder.withId(PRE_QOS_PIPE_UPLINK_TERM_FWD).withParameter(new PiActionParam(TC, upfTerminationUl.trafficClass())).withParameter(new PiActionParam(APP_METER_IDX, upfTerminationUl.appMeterIdx()));
            }
            break;
        case TERMINATION_DOWNLINK:
            tableEntryBuilder.forTable(PRE_QOS_PIPE_TERMINATIONS_DOWNLINK);
            UpfTerminationDownlink upfTerminationDl = (UpfTerminationDownlink) entity;
            matchBuilder.addFieldMatch(new PiExactFieldMatch(HDR_UE_ADDRESS, ImmutableByteSequence.copyFrom(upfTerminationDl.ueSessionId().toOctets()))).addFieldMatch(new PiExactFieldMatch(HDR_APP_ID, ImmutableByteSequence.copyFrom(upfTerminationDl.applicationId())));
            actionBuilder.withParameter(new PiActionParam(CTR_IDX, upfTerminationDl.counterId()));
            if (upfTerminationDl.needsDropping()) {
                actionBuilder.withId(PRE_QOS_PIPE_DOWNLINK_TERM_DROP);
            } else {
                actionBuilder.withId(PRE_QOS_PIPE_DOWNLINK_TERM_FWD).withParameter(new PiActionParam(TEID, upfTerminationDl.teid())).withParameter(new PiActionParam(QFI, upfTerminationDl.qfi())).withParameter(new PiActionParam(TC, upfTerminationDl.trafficClass())).withParameter(new PiActionParam(APP_METER_IDX, upfTerminationDl.appMeterIdx()));
            }
            break;
        case TUNNEL_PEER:
            tableEntryBuilder.forTable(PRE_QOS_PIPE_TUNNEL_PEERS);
            UpfGtpTunnelPeer gtpTunnelPeer = (UpfGtpTunnelPeer) entity;
            matchBuilder.addFieldMatch(new PiExactFieldMatch(HDR_TUNNEL_PEER_ID, ImmutableByteSequence.copyFrom(gtpTunnelPeer.tunPeerId())));
            actionBuilder.withId(PRE_QOS_PIPE_LOAD_TUNNEL_PARAM).withParameter(new PiActionParam(SRC_ADDR, gtpTunnelPeer.src().toOctets())).withParameter(new PiActionParam(DST_ADDR, gtpTunnelPeer.dst().toOctets())).withParameter(new PiActionParam(SPORT, gtpTunnelPeer.srcPort()));
            break;
        case APPLICATION:
            tableEntryBuilder.forTable(PRE_QOS_PIPE_APPLICATIONS);
            UpfApplication application = (UpfApplication) entity;
            tableEntryBuilder.withPriority(application.priority());
            actionBuilder.withId(PRE_QOS_PIPE_SET_APP_ID).withParameter(new PiActionParam(APP_ID, application.appId()));
            matchBuilder.addFieldMatch(new PiExactFieldMatch(HDR_SLICE_ID, ImmutableByteSequence.copyFrom((byte) application.sliceId())));
            if (application.ip4Prefix().isPresent()) {
                Ip4Prefix ipPrefix = application.ip4Prefix().get();
                matchBuilder.addFieldMatch(new PiLpmFieldMatch(HDR_APP_IP_ADDR, ImmutableByteSequence.copyFrom(ipPrefix.address().toOctets()), ipPrefix.prefixLength()));
            }
            if (application.l4PortRange().isPresent()) {
                Range<Short> portRange = application.l4PortRange().get();
                matchBuilder.addFieldMatch(new PiRangeFieldMatch(HDR_APP_L4_PORT, ImmutableByteSequence.copyFrom(portRange.lowerEndpoint()), ImmutableByteSequence.copyFrom(portRange.upperEndpoint())));
            }
            if (application.ipProto().isPresent()) {
                byte ipProto = application.ipProto().get();
                matchBuilder.addFieldMatch(new PiTernaryFieldMatch(HDR_APP_IP_PROTO, ImmutableByteSequence.copyFrom(ipProto), ImmutableByteSequence.ofOnes(1)));
            }
            break;
        case SESSION_METER:
        case APPLICATION_METER:
        case SLICE_METER:
        case COUNTER:
        case INGRESS_COUNTER:
        case EGRESS_COUNTER:
        default:
            throw new Up4TranslationException("Attempting to translate an unsupported UPF entity to a table entry! " + entity);
    }
    return tableEntryBuilder.withMatchKey(matchBuilder.build()).withAction(actionBuilder.build()).build();
}
Also used : UpfSessionUplink(org.onosproject.net.behaviour.upf.UpfSessionUplink) PiMatchKey(org.onosproject.net.pi.runtime.PiMatchKey) UpfTerminationDownlink(org.onosproject.net.behaviour.upf.UpfTerminationDownlink) PiRangeFieldMatch(org.onosproject.net.pi.runtime.PiRangeFieldMatch) UpfSessionDownlink(org.onosproject.net.behaviour.upf.UpfSessionDownlink) UpfApplication(org.onosproject.net.behaviour.upf.UpfApplication) PiTernaryFieldMatch(org.onosproject.net.pi.runtime.PiTernaryFieldMatch) UpfGtpTunnelPeer(org.onosproject.net.behaviour.upf.UpfGtpTunnelPeer) UpfTerminationUplink(org.onosproject.net.behaviour.upf.UpfTerminationUplink) PiAction(org.onosproject.net.pi.runtime.PiAction) PiLpmFieldMatch(org.onosproject.net.pi.runtime.PiLpmFieldMatch) PiTableEntry(org.onosproject.net.pi.runtime.PiTableEntry) UpfInterface(org.onosproject.net.behaviour.upf.UpfInterface) PiExactFieldMatch(org.onosproject.net.pi.runtime.PiExactFieldMatch) Ip4Prefix(org.onlab.packet.Ip4Prefix) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam)

Aggregations

PiTernaryFieldMatch (org.onosproject.net.pi.runtime.PiTernaryFieldMatch)13 PiExactFieldMatch (org.onosproject.net.pi.runtime.PiExactFieldMatch)10 Test (org.junit.Test)7 PiLpmFieldMatch (org.onosproject.net.pi.runtime.PiLpmFieldMatch)6 PiOptionalFieldMatch (org.onosproject.net.pi.runtime.PiOptionalFieldMatch)5 ImmutableByteSequence (org.onlab.util.ImmutableByteSequence)4 PiRangeFieldMatch (org.onosproject.net.pi.runtime.PiRangeFieldMatch)4 TpPort (org.onlab.packet.TpPort)3 PiFieldMatch (org.onosproject.net.pi.runtime.PiFieldMatch)3 ByteString (com.google.protobuf.ByteString)2 MacAddress (org.onlab.packet.MacAddress)2 ByteSequenceTrimException (org.onlab.util.ImmutableByteSequence.ByteSequenceTrimException)2 P4InfoOuterClass (p4.config.v1.P4InfoOuterClass)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 EqualsTester (com.google.common.testing.EqualsTester)1 Ip4Prefix (org.onlab.packet.Ip4Prefix)1 IpPrefix (org.onlab.packet.IpPrefix)1 ApplicationId (org.onosproject.core.ApplicationId)1 DefaultApplicationId (org.onosproject.core.DefaultApplicationId)1 UpfApplication (org.onosproject.net.behaviour.upf.UpfApplication)1