Search in sources :

Example 6 with PiTableEntry

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

the class Up4NorthComponentTest method tunnelPeerInsertionTest.

// ------------------- INSERTION TESTS -------------------------------------
@Test
public void tunnelPeerInsertionTest() throws Exception {
    PiTableEntry entry = TestImplConstants.UP4_TUNNEL_PEER;
    insertionTest(entry);
    assertThat(mockUp4Service.readAll(UpfEntityType.TUNNEL_PEER).size(), equalTo(1));
}
Also used : PiTableEntry(org.onosproject.net.pi.runtime.PiTableEntry) Test(org.junit.Test)

Example 7 with PiTableEntry

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

the class PiFlowRuleTranslatorImpl method translate.

/**
 * Returns a PI table entry equivalent to the given flow rule, for the given
 * pipeconf and device.
 *
 * @param rule     flow rule
 * @param pipeconf pipeconf
 * @param device   device
 * @return PI table entry
 * @throws PiTranslationException if the flow rule cannot be translated
 */
static PiTableEntry translate(FlowRule rule, PiPipeconf pipeconf, Device device) throws PiTranslationException {
    PiPipelineModel pipelineModel = pipeconf.pipelineModel();
    // Retrieve interpreter, if any.
    final PiPipelineInterpreter interpreter = getInterpreterOrNull(device, pipeconf);
    // Get table model.
    final PiTableId piTableId = translateTableId(rule.table(), interpreter);
    final PiTableModel tableModel = getTableModel(piTableId, pipelineModel);
    // Translate selector.
    final PiMatchKey piMatchKey;
    final boolean needPriority;
    if (rule.selector().criteria().isEmpty()) {
        piMatchKey = PiMatchKey.EMPTY;
        needPriority = false;
    } else {
        final Collection<PiFieldMatch> fieldMatches = translateFieldMatches(interpreter, rule.selector(), tableModel);
        piMatchKey = PiMatchKey.builder().addFieldMatches(fieldMatches).build();
        // FIXME: P4Runtime limit
        // Need to ignore priority if no TCAM lookup match field
        needPriority = tableModel.matchFields().stream().anyMatch(match -> match.matchType() == PiMatchType.TERNARY || match.matchType() == PiMatchType.RANGE || match.matchType() == PiMatchType.OPTIONAL);
    }
    // Translate treatment.
    final PiTableAction piTableAction = translateTreatment(rule.treatment(), interpreter, piTableId, pipelineModel);
    // Build PI entry.
    final PiTableEntry.Builder tableEntryBuilder = PiTableEntry.builder();
    tableEntryBuilder.forTable(piTableId).withMatchKey(piMatchKey);
    if (piTableAction != null) {
        tableEntryBuilder.withAction(piTableAction);
    }
    if (needPriority) {
        // FIXME: move priority check to P4Runtime driver.
        final int newPriority;
        if (rule.priority() > MAX_PI_PRIORITY) {
            log.warn("Flow rule priority too big, setting translated priority to max value {}: {}", MAX_PI_PRIORITY, rule);
            newPriority = MAX_PI_PRIORITY;
        } else {
            newPriority = MIN_PI_PRIORITY + rule.priority();
        }
        tableEntryBuilder.withPriority(newPriority);
    }
    if (!rule.isPermanent()) {
        if (tableModel.supportsAging()) {
            tableEntryBuilder.withTimeout(rule.timeout());
        } else {
            log.debug("Flow rule is temporary, but table '{}' doesn't support " + "aging, translating to permanent.", tableModel.id());
        }
    }
    return tableEntryBuilder.build();
}
Also used : PiTableId(org.onosproject.net.pi.model.PiTableId) PiOptionalFieldMatch(org.onosproject.net.pi.runtime.PiOptionalFieldMatch) PiUtils.getInterpreterOrNull(org.onosproject.net.pi.impl.PiUtils.getInterpreterOrNull) PiPipeconf(org.onosproject.net.pi.model.PiPipeconf) ImmutableByteSequence(org.onlab.util.ImmutableByteSequence) LoggerFactory(org.slf4j.LoggerFactory) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) PiActionParamModel(org.onosproject.net.pi.model.PiActionParamModel) PiPipelineModel(org.onosproject.net.pi.model.PiPipelineModel) PiMatchKey(org.onosproject.net.pi.runtime.PiMatchKey) PiUtils.translateTableId(org.onosproject.net.pi.impl.PiUtils.translateTableId) ImmutableByteSequence.prefixOnes(org.onlab.util.ImmutableByteSequence.prefixOnes) TrafficSelector(org.onosproject.net.flow.TrafficSelector) PiInstruction(org.onosproject.net.flow.instructions.PiInstruction) PiTableModel(org.onosproject.net.pi.model.PiTableModel) PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) Map(java.util.Map) PiTranslationException(org.onosproject.net.pi.service.PiTranslationException) PiExactFieldMatch(org.onosproject.net.pi.runtime.PiExactFieldMatch) PiFieldMatch(org.onosproject.net.pi.runtime.PiFieldMatch) Criterion(org.onosproject.net.flow.criteria.Criterion) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PiTableAction(org.onosproject.net.pi.runtime.PiTableAction) PiPipelineInterpreter(org.onosproject.net.pi.model.PiPipelineInterpreter) Logger(org.slf4j.Logger) Device(org.onosproject.net.Device) PiActionModel(org.onosproject.net.pi.model.PiActionModel) Instruction(org.onosproject.net.flow.instructions.Instruction) PiMatchFieldModel(org.onosproject.net.pi.model.PiMatchFieldModel) Collection(java.util.Collection) PiRangeFieldMatch(org.onosproject.net.pi.runtime.PiRangeFieldMatch) Set(java.util.Set) PiMatchFieldId(org.onosproject.net.pi.model.PiMatchFieldId) Maps(com.google.common.collect.Maps) Sets(com.google.common.collect.Sets) PiMatchType(org.onosproject.net.pi.model.PiMatchType) String.format(java.lang.String.format) PiTernaryFieldMatch(org.onosproject.net.pi.runtime.PiTernaryFieldMatch) ByteSequenceTrimException(org.onlab.util.ImmutableByteSequence.ByteSequenceTrimException) PROTOCOL_INDEPENDENT(org.onosproject.net.flow.criteria.Criterion.Type.PROTOCOL_INDEPENDENT) PiAction(org.onosproject.net.pi.runtime.PiAction) PiTableEntry(org.onosproject.net.pi.runtime.PiTableEntry) CriterionTranslatorHelper.translateCriterion(org.onosproject.net.pi.impl.CriterionTranslatorHelper.translateCriterion) FlowRule(org.onosproject.net.flow.FlowRule) StringJoiner(java.util.StringJoiner) PiTableType(org.onosproject.net.pi.model.PiTableType) PiLpmFieldMatch(org.onosproject.net.pi.runtime.PiLpmFieldMatch) PiActionSet(org.onosproject.net.pi.runtime.PiActionSet) PiTableModel(org.onosproject.net.pi.model.PiTableModel) PiMatchKey(org.onosproject.net.pi.runtime.PiMatchKey) PiTableAction(org.onosproject.net.pi.runtime.PiTableAction) PiTableId(org.onosproject.net.pi.model.PiTableId) PiTableEntry(org.onosproject.net.pi.runtime.PiTableEntry) PiPipelineInterpreter(org.onosproject.net.pi.model.PiPipelineInterpreter) PiFieldMatch(org.onosproject.net.pi.runtime.PiFieldMatch) PiPipelineModel(org.onosproject.net.pi.model.PiPipelineModel)

Example 8 with PiTableEntry

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

the class TableEntryEncoderTest method testEncodeWithNoAction.

@Test
public void testEncodeWithNoAction() throws Exception {
    TableEntry tableEntryMsg = Codecs.CODECS.tableEntry().encode(piTableEntryWithoutAction, null, defaultPipeconf);
    PiTableEntry decodedPiTableEntry = Codecs.CODECS.tableEntry().decode(tableEntryMsg, null, defaultPipeconf);
    // Test equality for decoded entry.
    new EqualsTester().addEqualityGroup(piTableEntryWithoutAction, decodedPiTableEntry).testEquals();
    // Table ID.
    int p4InfoTableId = browser.tables().getByName(tableId.id()).getPreamble().getId();
    int encodedTableId = tableEntryMsg.getTableId();
    assertThat(encodedTableId, is(p4InfoTableId));
    // Ternary match.
    byte[] encodedTernaryMatchValue = tableEntryMsg.getMatch(0).getTernary().getValue().toByteArray();
    assertThat(encodedTernaryMatchValue, is(ethAddr.asArray()));
    // no action
    assertThat(tableEntryMsg.hasAction(), is(false));
    // Counter
    CounterData counterData = tableEntryMsg.getCounterData();
    PiCounterCellData encodedCounterData = new PiCounterCellData(counterData.getPacketCount(), counterData.getByteCount());
    assertThat(encodedCounterData, is(counterCellData));
// TODO: improve, assert other field match types (ternary, LPM)
}
Also used : TableEntry(p4.v1.P4RuntimeOuterClass.TableEntry) PiTableEntry(org.onosproject.net.pi.runtime.PiTableEntry) PiCounterCellData(org.onosproject.net.pi.runtime.PiCounterCellData) EqualsTester(com.google.common.testing.EqualsTester) PiTableEntry(org.onosproject.net.pi.runtime.PiTableEntry) CounterData(p4.v1.P4RuntimeOuterClass.CounterData) Test(org.junit.Test)

Example 9 with PiTableEntry

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

the class TableEntryEncoderTest method testTableEntryEncoderWithTranslations.

@Test
public void testTableEntryEncoderWithTranslations() throws Exception {
    TableEntry tableEntryMsg = Codecs.CODECS.tableEntry().encode(piTableEntry2, null, defaultPipeconf2);
    PiTableEntry decodedPiTableEntry = Codecs.CODECS.tableEntry().decode(tableEntryMsg, null, defaultPipeconf2);
    // Test equality for decoded entry.
    new EqualsTester().addEqualityGroup(piTableEntry2, decodedPiTableEntry).testEquals();
    // Check the exact match with string
    byte[] encodedExactMatchValueString = tableEntryMsg.getMatch(1).getExact().getValue().toByteArray();
    assertThat(encodedExactMatchValueString, is(ethAddrString.asArray()));
    Action actionMsg = tableEntryMsg.getAction().getAction();
    // Check action param value with string
    byte[] encodedActionParamString = actionMsg.getParams(0).getValue().toByteArray();
    assertThat(encodedActionParamString, is(portValueString.asArray()));
    TableEntry tableEntryMsg1 = Codecs.CODECS.tableEntry().encode(piTableEntry3, null, defaultPipeconf2);
    PiTableEntry decodedPiTableEntry1 = Codecs.CODECS.tableEntry().decode(tableEntryMsg1, null, defaultPipeconf2);
    // Test equality for decoded entry.
    new EqualsTester().addEqualityGroup(piTableEntry3, decodedPiTableEntry1).testEquals();
}
Also used : TableEntry(p4.v1.P4RuntimeOuterClass.TableEntry) PiTableEntry(org.onosproject.net.pi.runtime.PiTableEntry) Action(p4.v1.P4RuntimeOuterClass.Action) PiAction(org.onosproject.net.pi.runtime.PiAction) EqualsTester(com.google.common.testing.EqualsTester) PiTableEntry(org.onosproject.net.pi.runtime.PiTableEntry) Test(org.junit.Test)

Example 10 with PiTableEntry

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

the class TableEntryEncoderTest method testTableEntryEncoderWithoutOptionalField.

@Test
public void testTableEntryEncoderWithoutOptionalField() throws Exception {
    TableEntry tableEntryMsg = Codecs.CODECS.tableEntry().encode(piTableEntryWithoutOptionalField, null, defaultPipeconf2);
    PiTableEntry decodedPiTableEntry = Codecs.CODECS.tableEntry().decode(tableEntryMsg, null, defaultPipeconf2);
    // Table ID.
    int p4InfoTableId = browser2.tables().getByName(tableId.id()).getPreamble().getId();
    int encodedTableId = tableEntryMsg.getTableId();
    assertThat(encodedTableId, is(p4InfoTableId));
    // Test equality for decoded entry.
    new EqualsTester().addEqualityGroup(piTableEntryWithoutOptionalField, decodedPiTableEntry).testEquals();
    // no optional field
    assertThat(tableEntryMsg.getMatchCount(), is(3));
    assertThat(tableEntryMsg.getMatchList().stream().map(P4RuntimeOuterClass.FieldMatch::getFieldMatchTypeCase).collect(Collectors.toList()), not(hasItem(P4RuntimeOuterClass.FieldMatch.FieldMatchTypeCase.OPTIONAL)));
}
Also used : TableEntry(p4.v1.P4RuntimeOuterClass.TableEntry) PiTableEntry(org.onosproject.net.pi.runtime.PiTableEntry) EqualsTester(com.google.common.testing.EqualsTester) PiOptionalFieldMatch(org.onosproject.net.pi.runtime.PiOptionalFieldMatch) PiExactFieldMatch(org.onosproject.net.pi.runtime.PiExactFieldMatch) PiTernaryFieldMatch(org.onosproject.net.pi.runtime.PiTernaryFieldMatch) PiTableEntry(org.onosproject.net.pi.runtime.PiTableEntry) Test(org.junit.Test)

Aggregations

PiTableEntry (org.onosproject.net.pi.runtime.PiTableEntry)21 Test (org.junit.Test)13 EqualsTester (com.google.common.testing.EqualsTester)6 TableEntry (p4.v1.P4RuntimeOuterClass.TableEntry)5 PiAction (org.onosproject.net.pi.runtime.PiAction)4 PiTernaryFieldMatch (org.onosproject.net.pi.runtime.PiTernaryFieldMatch)4 FlowRule (org.onosproject.net.flow.FlowRule)3 PiCounterCellData (org.onosproject.net.pi.runtime.PiCounterCellData)3 PiExactFieldMatch (org.onosproject.net.pi.runtime.PiExactFieldMatch)3 PiTableEntryHandle (org.onosproject.net.pi.runtime.PiTableEntryHandle)3 Up4Translator (org.omecproject.up4.Up4Translator)2 TrafficSelector (org.onosproject.net.flow.TrafficSelector)2 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)2 PiOptionalFieldMatch (org.onosproject.net.pi.runtime.PiOptionalFieldMatch)2 ImmutableList (com.google.common.collect.ImmutableList)1 Maps (com.google.common.collect.Maps)1 Sets (com.google.common.collect.Sets)1 String.format (java.lang.String.format)1 Collection (java.util.Collection)1 Map (java.util.Map)1