Search in sources :

Example 1 with P4InfoBrowser

use of org.onosproject.p4runtime.ctl.utils.P4InfoBrowser in project up4 by omec-project.

the class Up4NorthComponent method setPhysicalSizes.

/**
 * Update the logical p4info with physical resource sizes.
 *
 * @param p4Info a logical UP4 switch's p4info
 * @return the same p4info, but with resource sizes set to the sizes from the physical switch
 */
@VisibleForTesting
P4InfoOuterClass.P4Info setPhysicalSizes(P4InfoOuterClass.P4Info p4Info) {
    var newP4InfoBuilder = P4InfoOuterClass.P4Info.newBuilder(p4Info).clearCounters().clearTables().clearMeters();
    long physicalCounterSize;
    long physicalSessionMeterSize;
    long physicalAppMeterSize;
    long physicalSessionsUlTableSize;
    long physicalSessionsDlTableSize;
    long physicalTerminationsUlTableSize;
    long physicalTerminationsDlTableSize;
    long physicalTunnelPeerTableSize;
    try {
        physicalCounterSize = up4Service.tableSize(UpfEntityType.COUNTER);
        physicalSessionMeterSize = up4Service.tableSize(UpfEntityType.SESSION_METER);
        physicalAppMeterSize = up4Service.tableSize(UpfEntityType.APPLICATION_METER);
        physicalSessionsUlTableSize = up4Service.tableSize(UpfEntityType.SESSION_UPLINK);
        physicalSessionsDlTableSize = up4Service.tableSize(UpfEntityType.SESSION_DOWNLINK);
        physicalTerminationsUlTableSize = up4Service.tableSize(UpfEntityType.TERMINATION_UPLINK);
        physicalTerminationsDlTableSize = up4Service.tableSize(UpfEntityType.TERMINATION_DOWNLINK);
        physicalTunnelPeerTableSize = up4Service.tableSize(UpfEntityType.TUNNEL_PEER);
    } catch (UpfProgrammableException e) {
        throw new IllegalStateException("Error while getting physical sizes! " + e.getMessage());
    }
    int ingressPdrCounterId;
    int egressPdrCounterId;
    int sessionMeterId;
    int appMeterId;
    int sessionsUlTable;
    int sessionsDlTable;
    int terminationsUlTable;
    int terminationsDlTable;
    int tunnelPeerTable;
    try {
        P4InfoBrowser browser = PipeconfHelper.getP4InfoBrowser(pipeconf);
        ingressPdrCounterId = browser.counters().getByName(PRE_QOS_PIPE_PRE_QOS_COUNTER.id()).getPreamble().getId();
        sessionMeterId = browser.meters().getByName(PRE_QOS_PIPE_SESSION_METER.id()).getPreamble().getId();
        appMeterId = browser.meters().getByName(PRE_QOS_PIPE_APP_METER.id()).getPreamble().getId();
        egressPdrCounterId = browser.counters().getByName(POST_QOS_PIPE_POST_QOS_COUNTER.id()).getPreamble().getId();
        sessionsUlTable = browser.tables().getByName(PRE_QOS_PIPE_SESSIONS_UPLINK.id()).getPreamble().getId();
        sessionsDlTable = browser.tables().getByName(PRE_QOS_PIPE_SESSIONS_DOWNLINK.id()).getPreamble().getId();
        terminationsUlTable = browser.tables().getByName(PRE_QOS_PIPE_TERMINATIONS_UPLINK.id()).getPreamble().getId();
        terminationsDlTable = browser.tables().getByName(PRE_QOS_PIPE_TERMINATIONS_DOWNLINK.id()).getPreamble().getId();
        tunnelPeerTable = browser.tables().getByName(PRE_QOS_PIPE_TUNNEL_PEERS.id()).getPreamble().getId();
    } catch (P4InfoBrowser.NotFoundException e) {
        throw new NoSuchElementException("A UP4 counter/table that should always exist does not exist.");
    }
    p4Info.getCountersList().forEach(counter -> {
        if (counter.getPreamble().getId() == ingressPdrCounterId || counter.getPreamble().getId() == egressPdrCounterId) {
            // Change the sizes of the PDR counters
            newP4InfoBuilder.addCounters(P4InfoOuterClass.Counter.newBuilder(counter).setSize(physicalCounterSize).build());
        } else {
            // Any other counters go unchanged (for now)
            newP4InfoBuilder.addCounters(counter);
        }
    });
    p4Info.getMetersList().forEach(meter -> {
        if (meter.getPreamble().getId() == sessionMeterId) {
            newP4InfoBuilder.addMeters(P4InfoOuterClass.Meter.newBuilder(meter).setSize(physicalSessionMeterSize)).build();
        } else if (meter.getPreamble().getId() == appMeterId) {
            newP4InfoBuilder.addMeters(P4InfoOuterClass.Meter.newBuilder(meter).setSize(physicalAppMeterSize)).build();
        } else {
            // Any other meters go unchanged
            newP4InfoBuilder.addMeters(meter);
        }
    });
    p4Info.getTablesList().forEach(table -> {
        if (table.getPreamble().getId() == sessionsUlTable) {
            newP4InfoBuilder.addTables(P4InfoOuterClass.Table.newBuilder(table).setSize(physicalSessionsUlTableSize).build());
        } else if (table.getPreamble().getId() == sessionsDlTable) {
            newP4InfoBuilder.addTables(P4InfoOuterClass.Table.newBuilder(table).setSize(physicalSessionsDlTableSize).build());
        } else if (table.getPreamble().getId() == terminationsUlTable) {
            newP4InfoBuilder.addTables(P4InfoOuterClass.Table.newBuilder(table).setSize(physicalTerminationsUlTableSize).build());
        } else if (table.getPreamble().getId() == terminationsDlTable) {
            newP4InfoBuilder.addTables(P4InfoOuterClass.Table.newBuilder(table).setSize(physicalTerminationsDlTableSize).build());
        } else if (table.getPreamble().getId() == tunnelPeerTable) {
            newP4InfoBuilder.addTables(P4InfoOuterClass.Table.newBuilder(table).setSize(physicalTunnelPeerTableSize).build());
        } else {
            // Any tables aside from the PDR and FAR tables go unchanged
            newP4InfoBuilder.addTables(table);
        }
    });
    return newP4InfoBuilder.build();
}
Also used : UpfProgrammableException(org.onosproject.net.behaviour.upf.UpfProgrammableException) P4InfoBrowser(org.onosproject.p4runtime.ctl.utils.P4InfoBrowser) NoSuchElementException(java.util.NoSuchElementException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with P4InfoBrowser

use of org.onosproject.p4runtime.ctl.utils.P4InfoBrowser in project onos by opennetworkinglab.

the class ActionCodec method decode.

@Override
protected PiAction decode(P4RuntimeOuterClass.Action message, Object ignored, PiPipeconf pipeconf, P4InfoBrowser browser) throws P4InfoBrowser.NotFoundException, CodecException {
    final P4InfoBrowser.EntityBrowser<P4InfoOuterClass.Action.Param> paramInfo = browser.actionParams(message.getActionId());
    final String actionName = browser.actions().getById(message.getActionId()).getPreamble().getName();
    final PiAction.Builder builder = PiAction.builder().withId(PiActionId.of(actionName));
    for (P4RuntimeOuterClass.Action.Param p : message.getParamsList()) {
        final P4InfoOuterClass.Action.Param actionParam = paramInfo.getById(p.getParamId());
        final ImmutableByteSequence value;
        if (browser.isTypeString(actionParam.getTypeName())) {
            value = copyFrom(new String(p.getValue().toByteArray()));
        } else {
            try {
                value = copyAndFit(p.getValue().asReadOnlyByteBuffer(), actionParam.getBitwidth());
            } catch (ImmutableByteSequence.ByteSequenceTrimException e) {
                throw new CodecException(e.getMessage());
            }
        }
        builder.withParameter(new PiActionParam(PiActionParamId.of(actionParam.getName()), value));
    }
    return builder.build();
}
Also used : PiAction(org.onosproject.net.pi.runtime.PiAction) ByteString(com.google.protobuf.ByteString) PiAction(org.onosproject.net.pi.runtime.PiAction) P4InfoOuterClass(p4.config.v1.P4InfoOuterClass) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) P4InfoBrowser(org.onosproject.p4runtime.ctl.utils.P4InfoBrowser) ImmutableByteSequence(org.onlab.util.ImmutableByteSequence)

Example 3 with P4InfoBrowser

use of org.onosproject.p4runtime.ctl.utils.P4InfoBrowser in project onos by opennetworkinglab.

the class TableEntryEncoderTest method testP4InfoBrowser.

@Test
public void testP4InfoBrowser() throws Exception {
    P4InfoBrowser browser = PipeconfHelper.getP4InfoBrowser(defaultPipeconf);
    assertThat(browser.tables().hasName(TABLE_0), is(true));
    assertThat(browser.actions().hasName(SET_EGRESS_PORT), is(true));
    int tableId = browser.tables().getByName(TABLE_0).getPreamble().getId();
    int actionId = browser.actions().getByName(SET_EGRESS_PORT).getPreamble().getId();
    assertThat(browser.matchFields(tableId).hasName(STANDARD_METADATA + DOT + INGRESS_PORT), is(true));
    assertThat(browser.actionParams(actionId).hasName(PORT), is(true));
// TODO: improve, assert browsing other entities (counters, meters, etc.)
}
Also used : P4InfoBrowser(org.onosproject.p4runtime.ctl.utils.P4InfoBrowser) Test(org.junit.Test)

Example 4 with P4InfoBrowser

use of org.onosproject.p4runtime.ctl.utils.P4InfoBrowser in project onos by opennetworkinglab.

the class AbstractCodec method browserOrFail.

/**
 * Returns a P4Info browser for the given pipeconf or throws a
 * CodecException if not possible.
 *
 * @param pipeconf pipeconf
 * @return P4Info browser
 * @throws CodecException if a P4Info browser cannot be obtained
 */
P4InfoBrowser browserOrFail(PiPipeconf pipeconf) throws CodecException {
    checkNotNull(pipeconf);
    final P4InfoBrowser browser = PipeconfHelper.getP4InfoBrowser(pipeconf);
    if (browser == null) {
        throw new CodecException(format("Unable to get P4InfoBrowser for pipeconf %s", pipeconf.id()));
    }
    return browser;
}
Also used : P4InfoBrowser(org.onosproject.p4runtime.ctl.utils.P4InfoBrowser)

Aggregations

P4InfoBrowser (org.onosproject.p4runtime.ctl.utils.P4InfoBrowser)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ByteString (com.google.protobuf.ByteString)1 NoSuchElementException (java.util.NoSuchElementException)1 Test (org.junit.Test)1 ImmutableByteSequence (org.onlab.util.ImmutableByteSequence)1 UpfProgrammableException (org.onosproject.net.behaviour.upf.UpfProgrammableException)1 PiAction (org.onosproject.net.pi.runtime.PiAction)1 PiActionParam (org.onosproject.net.pi.runtime.PiActionParam)1 P4InfoOuterClass (p4.config.v1.P4InfoOuterClass)1